summaryrefslogtreecommitdiff
path: root/bsd-core
diff options
context:
space:
mode:
authorRobert Noland <rnoland@2hip.net>2008-09-17 23:10:15 -0400
committerRobert Noland <rnoland@2hip.net>2008-09-17 23:15:08 -0400
commit8ca06eb492f861dbf049a2e104e4e2a5ba814c13 (patch)
treed8fcb83dc398ce6e6d9d9d574d7b64e6939651e3 /bsd-core
parentee6bcabc506e4d506fb65447c405f8514ab1f4e1 (diff)
[FreeBSD] Convert to using cdevpriv for file_priv tracking
Diffstat (limited to 'bsd-core')
-rw-r--r--bsd-core/drmP.h17
-rw-r--r--bsd-core/drm_auth.c6
-rw-r--r--bsd-core/drm_drv.c26
-rw-r--r--bsd-core/drm_fops.c78
-rw-r--r--bsd-core/drm_ioctl.c6
-rw-r--r--bsd-core/drm_sysctl.c4
-rw-r--r--bsd-core/drm_vm.c14
7 files changed, 62 insertions, 89 deletions
diff --git a/bsd-core/drmP.h b/bsd-core/drmP.h
index 8404df74..fcce9066 100644
--- a/bsd-core/drmP.h
+++ b/bsd-core/drmP.h
@@ -37,7 +37,7 @@
#if defined(_KERNEL) || defined(__KERNEL__)
struct drm_device;
-typedef struct drm_file drm_file_t;
+struct drm_file;
#include <sys/param.h>
#include <sys/queue.h>
@@ -412,12 +412,12 @@ typedef struct drm_buf_entry {
typedef TAILQ_HEAD(drm_file_list, drm_file) drm_file_list_t;
struct drm_file {
TAILQ_ENTRY(drm_file) link;
+ struct drm_device *dev;
int authenticated;
int master;
int minor;
pid_t pid;
uid_t uid;
- int refs;
drm_magic_t magic;
unsigned long ioctl_count;
void *driver_priv;
@@ -551,9 +551,9 @@ struct drm_ati_pcigart_info {
struct drm_driver_info {
int (*load)(struct drm_device *, unsigned long flags);
int (*firstopen)(struct drm_device *);
- int (*open)(struct drm_device *, drm_file_t *);
+ int (*open)(struct drm_device *, struct drm_file *);
void (*preclose)(struct drm_device *, struct drm_file *file_priv);
- void (*postclose)(struct drm_device *, drm_file_t *);
+ void (*postclose)(struct drm_device *, struct drm_file *);
void (*lastclose)(struct drm_device *);
int (*unload)(struct drm_device *);
void (*reclaim_buffers_locked)(struct drm_device *,
@@ -728,10 +728,10 @@ extern int drm_debug_flag;
/* Device setup support (drm_drv.c) */
int drm_probe(device_t nbdev, drm_pci_id_list_t *idlist);
int drm_attach(device_t nbdev, drm_pci_id_list_t *idlist);
+void drm_close(void *data);
int drm_detach(device_t nbdev);
d_ioctl_t drm_ioctl;
d_open_t drm_open;
-d_close_t drm_close;
d_read_t drm_read;
d_poll_t drm_poll;
d_mmap_t drm_mmap;
@@ -741,8 +741,6 @@ extern drm_local_map_t *drm_getsarea(struct drm_device *dev);
extern int drm_open_helper(struct cdev *kdev, int flags, int fmt,
DRM_STRUCTPROC *p,
struct drm_device *dev);
-extern drm_file_t *drm_find_file_by_proc(struct drm_device *dev,
- DRM_STRUCTPROC *p);
/* Memory management support (drm_memory.c) */
void drm_mem_init(void);
@@ -874,7 +872,7 @@ int drm_noop(struct drm_device *dev, void *data,
int drm_resctx(struct drm_device *dev, void *data,
struct drm_file *file_priv);
int drm_addctx(struct drm_device *dev, void *data,
-struct drm_file *file_priv);
+ struct drm_file *file_priv);
int drm_modctx(struct drm_device *dev, void *data,
struct drm_file *file_priv);
int drm_getctx(struct drm_device *dev, void *data,
@@ -929,7 +927,8 @@ int drm_mapbufs(struct drm_device *dev, void *data,
int drm_dma(struct drm_device *dev, void *data, struct drm_file *file_priv);
/* IRQ support (drm_irq.c) */
-int drm_control(struct drm_device *dev, void *data, struct drm_file *file_priv);
+int drm_control(struct drm_device *dev, void *data,
+ struct drm_file *file_priv);
int drm_wait_vblank(struct drm_device *dev, void *data,
struct drm_file *file_priv);
void drm_locked_tasklet(struct drm_device *dev,
diff --git a/bsd-core/drm_auth.c b/bsd-core/drm_auth.c
index 455a7164..b5fc5587 100644
--- a/bsd-core/drm_auth.c
+++ b/bsd-core/drm_auth.c
@@ -43,7 +43,7 @@ static int drm_hash_magic(drm_magic_t magic)
/**
* Returns the file private associated with the given magic number.
*/
-static drm_file_t *drm_find_file(struct drm_device *dev, drm_magic_t magic)
+static struct drm_file *drm_find_file(struct drm_device *dev, drm_magic_t magic)
{
drm_magic_entry_t *pt;
int hash = drm_hash_magic(magic);
@@ -63,7 +63,7 @@ static drm_file_t *drm_find_file(struct drm_device *dev, drm_magic_t magic)
* Inserts the given magic number into the hash table of used magic number
* lists.
*/
-static int drm_add_magic(struct drm_device *dev, drm_file_t *priv,
+static int drm_add_magic(struct drm_device *dev, struct drm_file *priv,
drm_magic_t magic)
{
int hash;
@@ -169,7 +169,7 @@ int drm_authmagic(struct drm_device *dev, void *data,
struct drm_file *file_priv)
{
struct drm_auth *auth = data;
- drm_file_t *priv;
+ struct drm_file *priv;
DRM_DEBUG("%u\n", auth->magic);
diff --git a/bsd-core/drm_drv.c b/bsd-core/drm_drv.c
index 57a2bbed..a35d60a7 100644
--- a/bsd-core/drm_drv.c
+++ b/bsd-core/drm_drv.c
@@ -123,7 +123,6 @@ static drm_ioctl_desc_t drm_ioctls[256] = {
static struct cdevsw drm_cdevsw = {
.d_version = D_VERSION,
.d_open = drm_open,
- .d_close = drm_close,
.d_read = drm_read,
.d_ioctl = drm_ioctl,
.d_poll = drm_poll,
@@ -553,26 +552,16 @@ int drm_open(struct cdev *kdev, int flags, int fmt, DRM_STRUCTPROC *p)
return retcode;
}
-int drm_close(struct cdev *kdev, int flags, int fmt, DRM_STRUCTPROC *p)
+void drm_close(void *data)
{
- struct drm_device *dev = drm_get_device_from_kdev(kdev);
- drm_file_t *file_priv;
+ struct drm_file *file_priv = data;
+ struct drm_device *dev = file_priv->dev;
int retcode = 0;
DRM_DEBUG("open_count = %d\n", dev->open_count);
DRM_LOCK();
- file_priv = drm_find_file_by_proc(dev, p);
- if (!file_priv) {
- DRM_UNLOCK();
- DRM_ERROR("can't find authenticator\n");
- return EINVAL;
- }
-
- if (--file_priv->refs != 0)
- goto done;
-
if (dev->driver->preclose != NULL)
dev->driver->preclose(dev, file_priv);
@@ -640,7 +629,6 @@ int drm_close(struct cdev *kdev, int flags, int fmt, DRM_STRUCTPROC *p)
* End inline drm_release
*/
-done:
atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
device_unbusy(dev->device);
if (--dev->open_count == 0) {
@@ -648,8 +636,6 @@ done:
}
DRM_UNLOCK();
-
- return retcode;
}
/* drm_ioctl is called whenever a process performs an ioctl on /dev/drm.
@@ -663,12 +649,12 @@ int drm_ioctl(struct cdev *kdev, u_long cmd, caddr_t data, int flags,
int (*func)(struct drm_device *dev, void *data, struct drm_file *file_priv);
int nr = DRM_IOCTL_NR(cmd);
int is_driver_ioctl = 0;
- drm_file_t *file_priv;
+ struct drm_file *file_priv;
DRM_LOCK();
- file_priv = drm_find_file_by_proc(dev, p);
+ retcode = devfs_get_cdevpriv((void **)&file_priv);
DRM_UNLOCK();
- if (file_priv == NULL) {
+ if (retcode != 0) {
DRM_ERROR("can't find authenticator\n");
return EINVAL;
}
diff --git a/bsd-core/drm_fops.c b/bsd-core/drm_fops.c
index a002d259..6850f489 100644
--- a/bsd-core/drm_fops.c
+++ b/bsd-core/drm_fops.c
@@ -36,26 +36,12 @@
#include "drmP.h"
-drm_file_t *drm_find_file_by_proc(struct drm_device *dev, DRM_STRUCTPROC *p)
-{
- uid_t uid = p->td_ucred->cr_svuid;
- pid_t pid = p->td_proc->p_pid;
- drm_file_t *priv;
-
- DRM_SPINLOCK_ASSERT(&dev->dev_lock);
-
- TAILQ_FOREACH(priv, &dev->files, link)
- if (priv->pid == pid && priv->uid == uid)
- return priv;
- return NULL;
-}
-
/* drm_open_helper is called whenever a process opens /dev/drm. */
int drm_open_helper(struct cdev *kdev, int flags, int fmt, DRM_STRUCTPROC *p,
struct drm_device *dev)
{
- int m = minor(kdev);
- drm_file_t *priv;
+ struct drm_file *priv;
+ int m = minor(kdev);
int retcode;
if (flags & O_EXCL)
@@ -64,40 +50,42 @@ int drm_open_helper(struct cdev *kdev, int flags, int fmt, DRM_STRUCTPROC *p,
DRM_DEBUG("pid = %d, minor = %d\n", DRM_CURRENTPID, m);
+ priv = malloc(sizeof(*priv), M_DRM, M_NOWAIT | M_ZERO);
+ if (priv == NULL) {
+ return ENOMEM;
+ }
+
+ retcode = devfs_set_cdevpriv(priv, drm_close);
+ if (retcode != 0) {
+ free(priv, M_DRM);
+ return retcode;
+ }
+
DRM_LOCK();
- priv = drm_find_file_by_proc(dev, p);
- if (priv) {
- priv->refs++;
- } else {
- priv = malloc(sizeof(*priv), M_DRM, M_NOWAIT | M_ZERO);
- if (priv == NULL) {
+ priv->dev = dev;
+ priv->uid = p->td_ucred->cr_svuid;
+ priv->pid = p->td_proc->p_pid;
+ priv->minor = m;
+ priv->ioctl_count = 0;
+
+ /* for compatibility root is always authenticated */
+ priv->authenticated = DRM_SUSER(p);
+
+ if (dev->driver->open) {
+ /* shared code returns -errno */
+ retcode = -dev->driver->open(dev, priv);
+ if (retcode != 0) {
+ devfs_clear_cdevpriv();
+ free(priv, M_DRM);
DRM_UNLOCK();
- return ENOMEM;
- }
- priv->uid = p->td_ucred->cr_svuid;
- priv->pid = p->td_proc->p_pid;
- priv->refs = 1;
- priv->minor = m;
- priv->ioctl_count = 0;
-
- /* for compatibility root is always authenticated */
- priv->authenticated = DRM_SUSER(p);
-
- if (dev->driver->open) {
- /* shared code returns -errno */
- retcode = -dev->driver->open(dev, priv);
- if (retcode != 0) {
- free(priv, M_DRM);
- DRM_UNLOCK();
- return retcode;
- }
+ return retcode;
}
+ }
- /* first opener automatically becomes master */
- priv->master = TAILQ_EMPTY(&dev->files);
+ /* first opener automatically becomes master */
+ priv->master = TAILQ_EMPTY(&dev->files);
- TAILQ_INSERT_TAIL(&dev->files, priv, link);
- }
+ TAILQ_INSERT_TAIL(&dev->files, priv, link);
DRM_UNLOCK();
kdev->si_drv1 = dev;
return 0;
diff --git a/bsd-core/drm_ioctl.c b/bsd-core/drm_ioctl.c
index ad6bd819..0523291e 100644
--- a/bsd-core/drm_ioctl.c
+++ b/bsd-core/drm_ioctl.c
@@ -179,9 +179,9 @@ int drm_getclient(struct drm_device *dev, void *data,
struct drm_file *file_priv)
{
struct drm_client *client = data;
- drm_file_t *pt;
- int idx;
- int i = 0;
+ struct drm_file *pt;
+ int idx;
+ int i = 0;
idx = client->idx;
DRM_LOCK();
diff --git a/bsd-core/drm_sysctl.c b/bsd-core/drm_sysctl.c
index 4c281fe3..f9cfd9cf 100644
--- a/bsd-core/drm_sysctl.c
+++ b/bsd-core/drm_sysctl.c
@@ -268,7 +268,7 @@ done:
static int drm_clients_info DRM_SYSCTL_HANDLER_ARGS
{
struct drm_device *dev = arg1;
- drm_file_t *priv, *tempprivs;
+ struct drm_file *priv, *tempprivs;
char buf[128];
int retcode;
int privcount, i;
@@ -279,7 +279,7 @@ static int drm_clients_info DRM_SYSCTL_HANDLER_ARGS
TAILQ_FOREACH(priv, &dev->files, link)
privcount++;
- tempprivs = malloc(sizeof(drm_file_t) * privcount, M_DRM, M_NOWAIT);
+ tempprivs = malloc(sizeof(struct drm_file) * privcount, M_DRM, M_NOWAIT);
if (tempprivs == NULL) {
DRM_UNLOCK();
return ENOMEM;
diff --git a/bsd-core/drm_vm.c b/bsd-core/drm_vm.c
index 7fa33c91..8ee49a28 100644
--- a/bsd-core/drm_vm.c
+++ b/bsd-core/drm_vm.c
@@ -32,20 +32,20 @@ int drm_mmap(struct cdev *kdev, vm_offset_t offset, vm_paddr_t *paddr,
int prot)
{
struct drm_device *dev = drm_get_device_from_kdev(kdev);
+ struct drm_file *file_priv;
drm_local_map_t *map;
- drm_file_t *priv;
enum drm_map_type type;
vm_paddr_t phys;
DRM_LOCK();
- priv = drm_find_file_by_proc(dev, DRM_CURPROC);
+ TAILQ_FOREACH(file_priv, &dev->files, link)
+ if (file_priv->pid == curthread->td_proc->p_pid &&
+ file_priv->uid == curthread->td_ucred->cr_svuid &&
+ file_priv->authenticated == 1)
+ break;
DRM_UNLOCK();
- if (priv == NULL) {
- DRM_ERROR("can't find authenticator\n");
- return EINVAL;
- }
- if (!priv->authenticated)
+ if (!file_priv)
return EACCES;
if (dev->dma && offset >= 0 && offset < ptoa(dev->dma->page_count)) {