sync with OpenBSD -current
This commit is contained in:
parent
ee68147dcd
commit
1cefe29c7e
1651 changed files with 283292 additions and 68089 deletions
|
@ -42,6 +42,7 @@
|
|||
#include <drm/drm_client.h>
|
||||
#include <drm/drm_drv.h>
|
||||
#include <drm/drm_file.h>
|
||||
#include <drm/drm_gem.h>
|
||||
#include <drm/drm_print.h>
|
||||
|
||||
#include "drm_crtc_internal.h"
|
||||
|
@ -148,6 +149,7 @@ bool drm_dev_needs_global_mutex(struct drm_device *dev)
|
|||
*/
|
||||
struct drm_file *drm_file_alloc(struct drm_minor *minor)
|
||||
{
|
||||
static atomic64_t ident = ATOMIC64_INIT(0);
|
||||
struct drm_device *dev = minor->dev;
|
||||
struct drm_file *file;
|
||||
int ret;
|
||||
|
@ -156,8 +158,10 @@ struct drm_file *drm_file_alloc(struct drm_minor *minor)
|
|||
if (!file)
|
||||
return ERR_PTR(-ENOMEM);
|
||||
|
||||
/* Get a unique identifier for fdinfo: */
|
||||
file->client_id = atomic64_inc_return(&ident);
|
||||
#ifdef __linux__
|
||||
file->pid = get_pid(task_pid(current));
|
||||
rcu_assign_pointer(file->pid, get_pid(task_tgid(current)));
|
||||
#endif
|
||||
file->minor = minor;
|
||||
|
||||
|
@ -198,7 +202,7 @@ out_prime_destroy:
|
|||
drm_syncobj_release(file);
|
||||
if (drm_core_check_feature(dev, DRIVER_GEM))
|
||||
drm_gem_release(dev, file);
|
||||
put_pid(file->pid);
|
||||
put_pid(rcu_access_pointer(file->pid));
|
||||
kfree(file);
|
||||
|
||||
return ERR_PTR(ret);
|
||||
|
@ -248,14 +252,14 @@ void drm_file_free(struct drm_file *file)
|
|||
dev = file->minor->dev;
|
||||
|
||||
#ifdef __linux__
|
||||
DRM_DEBUG("comm=\"%s\", pid=%d, dev=0x%lx, open_count=%d\n",
|
||||
current->comm, task_pid_nr(current),
|
||||
(long)old_encode_dev(file->minor->kdev->devt),
|
||||
atomic_read(&dev->open_count));
|
||||
drm_dbg_core(dev, "comm=\"%s\", pid=%d, dev=0x%lx, open_count=%d\n",
|
||||
current->comm, task_pid_nr(current),
|
||||
(long)old_encode_dev(file->minor->kdev->devt),
|
||||
atomic_read(&dev->open_count));
|
||||
#else
|
||||
DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
|
||||
curproc->p_p->ps_pid, (long)&dev->dev,
|
||||
atomic_read(&dev->open_count));
|
||||
drm_dbg_core(dev, "pid=%d, dev=0x%lx, open_count=%d\n",
|
||||
curproc->p_p->ps_pid, (long)&dev->dev,
|
||||
atomic_read(&dev->open_count));
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_DRM_LEGACY
|
||||
|
@ -295,7 +299,7 @@ void drm_file_free(struct drm_file *file)
|
|||
|
||||
WARN_ON(!list_empty(&file->event_list));
|
||||
|
||||
put_pid(file->pid);
|
||||
put_pid(rcu_access_pointer(file->pid));
|
||||
kfree(file);
|
||||
}
|
||||
|
||||
|
@ -326,8 +330,6 @@ static int drm_cpu_valid(void)
|
|||
return 1;
|
||||
}
|
||||
|
||||
#endif /* __linux__ */
|
||||
|
||||
/*
|
||||
* Called whenever a process opens a drm node
|
||||
*
|
||||
|
@ -338,8 +340,7 @@ static int drm_cpu_valid(void)
|
|||
* Creates and initializes a drm_file structure for the file private data in \p
|
||||
* filp and add it into the double linked list in \p dev.
|
||||
*/
|
||||
#ifdef __linux__
|
||||
static int drm_open_helper(struct file *filp, struct drm_minor *minor)
|
||||
int drm_open_helper(struct file *filp, struct drm_minor *minor)
|
||||
{
|
||||
struct drm_device *dev = minor->dev;
|
||||
struct drm_file *priv;
|
||||
|
@ -353,8 +354,8 @@ static int drm_open_helper(struct file *filp, struct drm_minor *minor)
|
|||
dev->switch_power_state != DRM_SWITCH_POWER_DYNAMIC_OFF)
|
||||
return -EINVAL;
|
||||
|
||||
DRM_DEBUG("comm=\"%s\", pid=%d, minor=%d\n", current->comm,
|
||||
task_pid_nr(current), minor->index);
|
||||
drm_dbg_core(dev, "comm=\"%s\", pid=%d, minor=%d\n",
|
||||
current->comm, task_pid_nr(current), minor->index);
|
||||
|
||||
priv = drm_file_alloc(minor);
|
||||
if (IS_ERR(priv))
|
||||
|
@ -401,6 +402,7 @@ static int drm_open_helper(struct file *filp, struct drm_minor *minor)
|
|||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* __linux__ */
|
||||
|
||||
/**
|
||||
|
@ -466,11 +468,11 @@ EXPORT_SYMBOL(drm_open);
|
|||
|
||||
void drm_lastclose(struct drm_device * dev)
|
||||
{
|
||||
DRM_DEBUG("\n");
|
||||
drm_dbg_core(dev, "\n");
|
||||
|
||||
if (dev->driver->lastclose)
|
||||
dev->driver->lastclose(dev);
|
||||
DRM_DEBUG("driver lastclose completed\n");
|
||||
drm_dbg_core(dev, "driver lastclose completed\n");
|
||||
|
||||
if (drm_core_check_feature(dev, DRIVER_LEGACY))
|
||||
drm_legacy_dev_reinit(dev);
|
||||
|
@ -504,7 +506,7 @@ int drm_release(struct inode *inode, struct file *filp)
|
|||
if (drm_dev_needs_global_mutex(dev))
|
||||
mutex_lock(&drm_global_mutex);
|
||||
|
||||
DRM_DEBUG("open_count = %d\n", atomic_read(&dev->open_count));
|
||||
drm_dbg_core(dev, "open_count = %d\n", atomic_read(&dev->open_count));
|
||||
|
||||
drm_close_helper(filp);
|
||||
|
||||
|
@ -521,6 +523,45 @@ int drm_release(struct inode *inode, struct file *filp)
|
|||
}
|
||||
EXPORT_SYMBOL(drm_release);
|
||||
|
||||
void drm_file_update_pid(struct drm_file *filp)
|
||||
{
|
||||
#ifdef notyet
|
||||
struct drm_device *dev;
|
||||
struct pid *pid, *old;
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Master nodes need to keep the original ownership in order for
|
||||
* drm_master_check_perm to keep working correctly. (See comment in
|
||||
* drm_auth.c.)
|
||||
*/
|
||||
if (filp->was_master)
|
||||
return;
|
||||
|
||||
STUB();
|
||||
#ifdef notyet
|
||||
pid = task_tgid(current);
|
||||
|
||||
/*
|
||||
* Quick unlocked check since the model is a single handover followed by
|
||||
* exclusive repeated use.
|
||||
*/
|
||||
if (pid == rcu_access_pointer(filp->pid))
|
||||
return;
|
||||
|
||||
dev = filp->minor->dev;
|
||||
mutex_lock(&dev->filelist_mutex);
|
||||
old = rcu_replace_pointer(filp->pid, pid, 1);
|
||||
mutex_unlock(&dev->filelist_mutex);
|
||||
|
||||
if (pid != old) {
|
||||
get_pid(pid);
|
||||
synchronize_rcu();
|
||||
put_pid(old);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* drm_release_noglobal - release method for DRM file
|
||||
* @inode: device inode
|
||||
|
@ -901,6 +942,137 @@ void drm_send_event(struct drm_device *dev, struct drm_pending_event *e)
|
|||
}
|
||||
EXPORT_SYMBOL(drm_send_event);
|
||||
|
||||
static void print_size(struct drm_printer *p, const char *stat,
|
||||
const char *region, u64 sz)
|
||||
{
|
||||
const char *units[] = {"", " KiB", " MiB"};
|
||||
unsigned u;
|
||||
|
||||
for (u = 0; u < ARRAY_SIZE(units) - 1; u++) {
|
||||
if (sz < SZ_1K)
|
||||
break;
|
||||
sz = div_u64(sz, SZ_1K);
|
||||
}
|
||||
|
||||
drm_printf(p, "drm-%s-%s:\t%llu%s\n", stat, region, sz, units[u]);
|
||||
}
|
||||
|
||||
/**
|
||||
* drm_print_memory_stats - A helper to print memory stats
|
||||
* @p: The printer to print output to
|
||||
* @stats: The collected memory stats
|
||||
* @supported_status: Bitmask of optional stats which are available
|
||||
* @region: The memory region
|
||||
*
|
||||
*/
|
||||
void drm_print_memory_stats(struct drm_printer *p,
|
||||
const struct drm_memory_stats *stats,
|
||||
enum drm_gem_object_status supported_status,
|
||||
const char *region)
|
||||
{
|
||||
print_size(p, "total", region, stats->private + stats->shared);
|
||||
print_size(p, "shared", region, stats->shared);
|
||||
print_size(p, "active", region, stats->active);
|
||||
|
||||
if (supported_status & DRM_GEM_OBJECT_RESIDENT)
|
||||
print_size(p, "resident", region, stats->resident);
|
||||
|
||||
if (supported_status & DRM_GEM_OBJECT_PURGEABLE)
|
||||
print_size(p, "purgeable", region, stats->purgeable);
|
||||
}
|
||||
EXPORT_SYMBOL(drm_print_memory_stats);
|
||||
|
||||
/**
|
||||
* drm_show_memory_stats - Helper to collect and show standard fdinfo memory stats
|
||||
* @p: the printer to print output to
|
||||
* @file: the DRM file
|
||||
*
|
||||
* Helper to iterate over GEM objects with a handle allocated in the specified
|
||||
* file.
|
||||
*/
|
||||
void drm_show_memory_stats(struct drm_printer *p, struct drm_file *file)
|
||||
{
|
||||
struct drm_gem_object *obj;
|
||||
struct drm_memory_stats status = {};
|
||||
enum drm_gem_object_status supported_status;
|
||||
int id;
|
||||
|
||||
spin_lock(&file->table_lock);
|
||||
idr_for_each_entry (&file->object_idr, obj, id) {
|
||||
enum drm_gem_object_status s = 0;
|
||||
|
||||
if (obj->funcs && obj->funcs->status) {
|
||||
s = obj->funcs->status(obj);
|
||||
supported_status = DRM_GEM_OBJECT_RESIDENT |
|
||||
DRM_GEM_OBJECT_PURGEABLE;
|
||||
}
|
||||
|
||||
if (obj->handle_count > 1) {
|
||||
status.shared += obj->size;
|
||||
} else {
|
||||
status.private += obj->size;
|
||||
}
|
||||
|
||||
if (s & DRM_GEM_OBJECT_RESIDENT) {
|
||||
status.resident += obj->size;
|
||||
} else {
|
||||
/* If already purged or not yet backed by pages, don't
|
||||
* count it as purgeable:
|
||||
*/
|
||||
s &= ~DRM_GEM_OBJECT_PURGEABLE;
|
||||
}
|
||||
|
||||
if (!dma_resv_test_signaled(obj->resv, dma_resv_usage_rw(true))) {
|
||||
status.active += obj->size;
|
||||
|
||||
/* If still active, don't count as purgeable: */
|
||||
s &= ~DRM_GEM_OBJECT_PURGEABLE;
|
||||
}
|
||||
|
||||
if (s & DRM_GEM_OBJECT_PURGEABLE)
|
||||
status.purgeable += obj->size;
|
||||
}
|
||||
spin_unlock(&file->table_lock);
|
||||
|
||||
drm_print_memory_stats(p, &status, supported_status, "memory");
|
||||
}
|
||||
EXPORT_SYMBOL(drm_show_memory_stats);
|
||||
|
||||
/**
|
||||
* drm_show_fdinfo - helper for drm file fops
|
||||
* @m: output stream
|
||||
* @f: the device file instance
|
||||
*
|
||||
* Helper to implement fdinfo, for userspace to query usage stats, etc, of a
|
||||
* process using the GPU. See also &drm_driver.show_fdinfo.
|
||||
*
|
||||
* For text output format description please see Documentation/gpu/drm-usage-stats.rst
|
||||
*/
|
||||
void drm_show_fdinfo(struct seq_file *m, struct file *f)
|
||||
{
|
||||
STUB();
|
||||
#ifdef notyet
|
||||
struct drm_file *file = f->private_data;
|
||||
struct drm_device *dev = file->minor->dev;
|
||||
struct drm_printer p = drm_seq_file_printer(m);
|
||||
|
||||
drm_printf(&p, "drm-driver:\t%s\n", dev->driver->name);
|
||||
drm_printf(&p, "drm-client-id:\t%llu\n", file->client_id);
|
||||
|
||||
if (dev_is_pci(dev->dev)) {
|
||||
struct pci_dev *pdev = to_pci_dev(dev->dev);
|
||||
|
||||
drm_printf(&p, "drm-pdev:\t%04x:%02x:%02x.%d\n",
|
||||
pci_domain_nr(pdev->bus), pdev->bus->number,
|
||||
PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn));
|
||||
}
|
||||
|
||||
if (dev->driver->show_fdinfo)
|
||||
dev->driver->show_fdinfo(&p, file);
|
||||
#endif
|
||||
}
|
||||
EXPORT_SYMBOL(drm_show_fdinfo);
|
||||
|
||||
/**
|
||||
* mock_drm_getfile - Create a new struct file for the drm device
|
||||
* @minor: drm minor to wrap (e.g. #drm_device.primary)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue