Re: New DRM driver model - gets rid of DRM() macros!

Jon Smirl
2004-09-30T18:12:04Z

[-- Attachment #1: Type: text/plain, Size: 662 bytes --]

Patch removes DRM flush, poll, read functions. It leave the fops entry
null so that the OS default function will be used.

The fops table is converted to be one per driver instead of a global.
This fixes the module open ref count problem. It also simplifies
i810/830 by allow them to directly patch their mmap function into the
fops table.

I spent two days looking for a bug in DRM with multiple drivers under
X. I don't think DRM has problems. I see now that X also fails if two
older DRM drivers are loaded. The first problem seems to be the X's
DRM lock refcount varibale is a static. That won't work for two DRM
drivers.

--
Jon Smirl
jonsmirl@gmail.com

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: open.patch --]
[-- Type: text/x-patch; name="open.patch", Size: 14070 bytes --]

===== linux-core/drmP.h 1.2 vs edited =====
--- 1.2/linux-core/drmP.h 2004-09-28 18:26:13 -04:00
+++ edited/linux-core/drmP.h 2004-09-30 13:34:40 -04:00
@@ -523,11 +523,6 @@
struct drm_device;

struct drm_driver_fn {
- u32 driver_features;
- int dev_priv_size;
- int permanent_maps;
- drm_ioctl_desc_t *ioctls;
- int num_ioctls;
int (*preinit)(struct drm_device *, unsigned long flags);
void (*prerelease)(struct drm_device *, struct file *filp);
void (*pretakedown)(struct drm_device *);
@@ -558,6 +553,13 @@
unsigned long (*get_reg_ofs)(struct drm_device *dev);
void (*set_version)(struct drm_device *dev, drm_set_version_t *sv);
int (*version)(drm_version_t *version);
+/* variables */
+ u32 driver_features;
+ int dev_priv_size;
+ int permanent_maps;
+ drm_ioctl_desc_t *ioctls;
+ int num_ioctls;
+ struct file_operations fops;
};

@@ -691,8 +693,6 @@
drm_sigdata_t sigdata; /**< For block_all_signals */
sigset_t sigmask;

- struct file_operations *fops; /**< file operations */
-
struct drm_driver_fn *fn_tbl;
drm_local_map_t *agp_buffer_map;
} drm_device_t;
@@ -757,13 +757,11 @@
extern int drm_fill_in_dev(drm_device_t *dev, struct pci_dev *pdev,
const struct pci_device_id *ent, struct drm_driver_fn *driver_fn);
extern int drm_fb_loaded;
-extern struct file_operations drm_fops;

/* Device support (drm_fops.h) */
extern int drm_open_helper(struct inode *inode, struct file *filp,
drm_device_t *dev);
-extern int drm_flush(struct file *filp);
-extern int drm_fasync(int fd, struct file *filp, int on);
+extern int drm_fasync(int fd, struct file *filp, int on);

/* Mapping support (drm_vm.h) */
extern void drm_vm_open(struct vm_area_struct *vma);
@@ -772,8 +770,6 @@
extern int drm_mmap_dma(struct file *filp,
struct vm_area_struct *vma);
extern int drm_mmap(struct file *filp, struct vm_area_struct *vma);
-extern unsigned int drm_poll(struct file *filp, struct poll_table_struct *wait);
-extern ssize_t drm_read(struct file *filp, char __user *buf, size_t count, loff_t *off);

/* Memory management support (drm_memory.h) */
#include "drm_memory.h"
===== linux-core/drm_drv.c 1.2 vs edited =====
--- 1.2/linux-core/drm_drv.c 2004-09-28 18:26:13 -04:00
+++ edited/linux-core/drm_drv.c 2004-09-30 13:34:40 -04:00
@@ -76,18 +76,6 @@

int drm_fb_loaded = 0;

-struct file_operations drm_fops = {
- .owner = THIS_MODULE,
- .open = drm_open,
- .flush = drm_flush,
- .release = drm_release,
- .ioctl = drm_ioctl,
- .mmap = drm_mmap,
- .fasync = drm_fasync,
- .poll = drm_poll,
- .read = drm_read,
-};
-
/** Ioctl table */
drm_ioctl_desc_t drm_ioctls[] = {
[DRM_IOCTL_NR(DRM_IOCTL_VERSION)] = { drm_version, 0, 0 },
@@ -384,7 +372,6 @@
sema_init( &dev->ctxlist_sem, 1 );

dev->name = DRIVER_NAME;
- dev->fops = &drm_fops;
dev->pdev = pdev;

#ifdef __alpha__
@@ -630,7 +617,7 @@
minor = &drm_minors[i];
dev = minor->dev;
DRM_DEBUG("fb loaded release minor %d\n", dev->minor);
- if ((minor->class == DRM_MINOR_PRIMARY) && (dev->fops == &drm_fops)) {
+ if (minor->class == DRM_MINOR_PRIMARY) {
/* release the pci driver */
if (dev->pdev)
pci_dev_put(dev->pdev);
===== linux-core/drm_fops.c 1.1 vs edited =====
--- 1.1/linux-core/drm_fops.c 2004-09-28 13:03:33 -04:00
+++ edited/linux-core/drm_fops.c 2004-09-30 13:56:18 -04:00
@@ -116,18 +116,6 @@
}

/** No-op. */
-int drm_flush(struct file *filp)
-{
- drm_file_t *priv = filp->private_data;
- drm_device_t *dev = priv->dev;
-
- DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
- current->pid, (long)old_encode_dev(dev->device), dev->open_count);
- return 0;
-}
-EXPORT_SYMBOL(drm_flush);
-
-/** No-op. */
int drm_fasync(int fd, struct file *filp, int on)
{
drm_file_t *priv = filp->private_data;
@@ -140,16 +128,3 @@
return 0;
}
EXPORT_SYMBOL(drm_fasync);
-
-/** No-op. */
-unsigned int drm_poll(struct file *filp, struct poll_table_struct *wait)
-{
- return 0;
-}
-
-
-/** No-op. */
-ssize_t drm_read(struct file *filp, char __user *buf, size_t count, loff_t *off)
-{
- return 0;
-}
===== linux-core/drm_stub.c 1.1 vs edited =====
--- 1.1/linux-core/drm_stub.c 2004-09-28 13:03:33 -04:00
+++ edited/linux-core/drm_stub.c 2004-09-30 13:13:25 -04:00
@@ -77,7 +77,7 @@
return -ENODEV;

old_fops = filp->f_op;
- filp->f_op = fops_get(dev->fops);
+ filp->f_op = fops_get(&dev->fn_tbl->fops);
if (filp->f_op->open && (err = filp->f_op->open(inode, filp))) {
fops_put(filp->f_op);
filp->f_op = fops_get(old_fops);
===== linux-core/drm_vm.c 1.1 vs edited =====
--- 1.1/linux-core/drm_vm.c 2004-09-28 13:03:33 -04:00
+++ edited/linux-core/drm_vm.c 2004-09-30 13:17:13 -04:00
@@ -670,3 +670,4 @@
drm_vm_open(vma);
return 0;
}
+EXPORT_SYMBOL(drm_mmap);
===== linux-core/ffb_drv.c 1.1 vs edited =====
--- 1.1/linux-core/ffb_drv.c 2004-09-28 13:03:33 -04:00
+++ edited/linux-core/ffb_drv.c 2004-09-30 13:34:41 -04:00
@@ -321,6 +321,14 @@
.reclaim_buffers = drm_core_reclaim_buffers,
.postinit = postinit,
.version = version,
+ fops = {
+ .owner = THIS_MODULE,
+ .open = drm_open,
+ .release = drm_release,
+ .ioctl = drm_ioctl,
+ .mmap = drm_mmap,
+ .fasync = drm_fasync,
+ },
};

static int probe(struct pci_dev *pdev, const struct pci_device_id *ent)
===== linux-core/i810_dma.c 1.1 vs edited =====
--- 1.1/linux-core/i810_dma.c 2004-09-28 13:03:33 -04:00
+++ edited/linux-core/i810_dma.c 2004-09-30 13:19:46 -04:00
@@ -109,15 +109,6 @@
return 0;
}

-static struct file_operations i810_buffer_fops = {
- .open = drm_open,
- .flush = drm_flush,
- .release = drm_release,
- .ioctl = drm_ioctl,
- .mmap = i810_mmap_buffers,
- .fasync = drm_fasync,
-};
-
int i810_mmap_buffers(struct file *filp, struct vm_area_struct *vma)
{
drm_file_t *priv = filp->private_data;
@@ -151,22 +142,19 @@
drm_device_t *dev = priv->dev;
drm_i810_buf_priv_t *buf_priv = buf->dev_private;
drm_i810_private_t *dev_priv = dev->dev_private;
- struct file_operations *old_fops;
int retcode = 0;

if (buf_priv->currently_mapped == I810_BUF_MAPPED)
return -EINVAL;

down_write( &current->mm->mmap_sem );
- old_fops = filp->f_op;
- filp->f_op = &i810_buffer_fops;
dev_priv->mmap_buffer = buf;
buf_priv->virtual = (void *)do_mmap(filp, 0, buf->total,
PROT_READ|PROT_WRITE,
MAP_SHARED,
buf->bus_address);
dev_priv->mmap_buffer = NULL;
- filp->f_op = old_fops;
+
if ((unsigned long)buf_priv->virtual > -1024UL) {
/* Real error */
DRM_ERROR("mmap error\n");
===== linux-core/i810_drv.c 1.1 vs edited =====
--- 1.1/linux-core/i810_drv.c 2004-09-28 13:03:33 -04:00
+++ edited/linux-core/i810_drv.c 2004-09-30 13:34:40 -04:00
@@ -107,6 +107,14 @@
.version = version,
.ioctls = ioctls,
.num_ioctls = DRM_ARRAY_SIZE(ioctls),
+ .fops = {
+ .owner = THIS_MODULE,
+ .open = drm_open,
+ .release = drm_release,
+ .ioctl = drm_ioctl,
+ .mmap = i810_mmap_buffers,
+ .fasync = drm_fasync,
+ },
};

static int probe(struct pci_dev *pdev, const struct pci_device_id *ent)
===== linux-core/i830_dma.c 1.1 vs edited =====
--- 1.1/linux-core/i830_dma.c 2004-09-28 13:03:33 -04:00
+++ edited/linux-core/i830_dma.c 2004-09-30 13:20:41 -04:00
@@ -110,15 +110,6 @@
return 0;
}

-static struct file_operations i830_buffer_fops = {
- .open = drm_open,
- .flush = drm_flush,
- .release = drm_release,
- .ioctl = drm_ioctl,
- .mmap = i830_mmap_buffers,
- .fasync = drm_fasync,
-};
-
int i830_mmap_buffers(struct file *filp, struct vm_area_struct *vma)
{
drm_file_t *priv = filp->private_data;
@@ -152,20 +143,17 @@
drm_device_t *dev = priv->dev;
drm_i830_buf_priv_t *buf_priv = buf->dev_private;
drm_i830_private_t *dev_priv = dev->dev_private;
- struct file_operations *old_fops;
unsigned long virtual;
int retcode = 0;

if(buf_priv->currently_mapped == I830_BUF_MAPPED) return -EINVAL;

down_write( &current->mm->mmap_sem );
- old_fops = filp->f_op;
- filp->f_op = &i830_buffer_fops;
dev_priv->mmap_buffer = buf;
virtual = do_mmap(filp, 0, buf->total, PROT_READ|PROT_WRITE,
MAP_SHARED, buf->bus_address);
dev_priv->mmap_buffer = NULL;
- filp->f_op = old_fops;
+
if (IS_ERR((void *)virtual)) { /* ugh */
/* Real error */
DRM_ERROR("mmap error\n");
===== linux-core/i830_drv.c 1.1 vs edited =====
--- 1.1/linux-core/i830_drv.c 2004-09-28 13:03:33 -04:00
+++ edited/linux-core/i830_drv.c 2004-09-30 13:34:40 -04:00
@@ -116,6 +116,14 @@
.version = version,
.ioctls = ioctls,
.num_ioctls = DRM_ARRAY_SIZE(ioctls),
+ .fops = {
+ .owner = THIS_MODULE,
+ .open = drm_open,
+ .release = drm_release,
+ .ioctl = drm_ioctl,
+ .mmap = i830_mmap_buffers,
+ .fasync = drm_fasync,
+ },
};

static int probe(struct pci_dev *pdev, const struct pci_device_id *ent)
===== linux-core/i915_drv.c 1.1 vs edited =====
--- 1.1/linux-core/i915_drv.c 2004-09-28 13:03:34 -04:00
+++ edited/linux-core/i915_drv.c 2004-09-30 13:34:40 -04:00
@@ -83,6 +83,14 @@
.version = version,
.ioctls = ioctls,
.num_ioctls = DRM_ARRAY_SIZE(ioctls),
+ .fops = {
+ .owner = THIS_MODULE,
+ .open = drm_open,
+ .release = drm_release,
+ .ioctl = drm_ioctl,
+ .mmap = drm_mmap,
+ .fasync = drm_fasync,
+ },
};

static int probe(struct pci_dev *pdev, const struct pci_device_id *ent)
===== linux-core/mach64_drv.c 1.1 vs edited =====
--- 1.1/linux-core/mach64_drv.c 2004-09-28 13:03:34 -04:00
+++ edited/linux-core/mach64_drv.c 2004-09-30 13:34:40 -04:00
@@ -99,6 +99,14 @@
.ioctls = ioctls,
.num_ioctls = DRM_ARRAY_SIZE(ioctls),
.dma_ioctl = mach64_dma_buffers,
+ .fops = {
+ .owner = THIS_MODULE,
+ .open = drm_open,
+ .release = drm_release,
+ .ioctl = drm_ioctl,
+ .mmap = drm_mmap,
+ .fasync = drm_fasync,
+ },
};

static int probe(struct pci_dev *pdev, const struct pci_device_id *ent)
===== linux-core/mga_drv.c 1.1 vs edited =====
--- 1.1/linux-core/mga_drv.c 2004-09-28 13:03:34 -04:00
+++ edited/linux-core/mga_drv.c 2004-09-30 13:34:40 -04:00
@@ -103,6 +103,14 @@
.ioctls = ioctls,
.num_ioctls = DRM_ARRAY_SIZE(ioctls),
.dma_ioctl = mga_dma_buffers,
+ .fops = {
+ .owner = THIS_MODULE,
+ .open = drm_open,
+ .release = drm_release,
+ .ioctl = drm_ioctl,
+ .mmap = drm_mmap,
+ .fasync = drm_fasync,
+ },
};

static int probe(struct pci_dev *pdev, const struct pci_device_id *ent)
===== linux-core/r128_drv.c 1.1 vs edited =====
--- 1.1/linux-core/r128_drv.c 2004-09-28 13:03:34 -04:00
+++ edited/linux-core/r128_drv.c 2004-09-30 13:34:40 -04:00
@@ -113,6 +113,14 @@
.ioctls = ioctls,
.num_ioctls = DRM_ARRAY_SIZE(ioctls),
.dma_ioctl = r128_cce_buffers,
+ .fops = {
+ .owner = THIS_MODULE,
+ .open = drm_open,
+ .release = drm_release,
+ .ioctl = drm_ioctl,
+ .mmap = drm_mmap,
+ .fasync = drm_fasync,
+ },
};

static int probe(struct pci_dev *pdev, const struct pci_device_id *ent)
===== linux-core/radeon_drv.c 1.1 vs edited =====
--- 1.1/linux-core/radeon_drv.c 2004-09-28 13:03:34 -04:00
+++ edited/linux-core/radeon_drv.c 2004-09-30 13:34:40 -04:00
@@ -154,6 +154,14 @@
.ioctls = ioctls,
.num_ioctls = DRM_ARRAY_SIZE(ioctls),
.dma_ioctl = radeon_cp_buffers,
+ .fops = {
+ .owner = THIS_MODULE,
+ .open = drm_open,
+ .release = drm_release,
+ .ioctl = drm_ioctl,
+ .mmap = drm_mmap,
+ .fasync = drm_fasync,
+ },
};

static int probe(struct pci_dev *pdev, const struct pci_device_id *ent)
===== linux-core/savage_drv.c 1.1 vs edited =====
--- 1.1/linux-core/savage_drv.c 2004-09-28 13:03:34 -04:00
+++ edited/linux-core/savage_drv.c 2004-09-30 13:34:41 -04:00
@@ -292,6 +292,14 @@
.version = version,
.ioctls = ioctls,
.num_ioctls = DRM_ARRAY_SIZE(ioctls),
+ .fops = {
+ .owner = THIS_MODULE,
+ .open = drm_open,
+ .release = drm_release,
+ .ioctl = drm_ioctl,
+ .mmap = drm_mmap,
+ .fasync = drm_fasync,
+ },
};

static int probe(struct pci_dev *pdev, const struct pci_device_id *ent)
===== linux-core/sis_drv.c 1.1 vs edited =====
--- 1.1/linux-core/sis_drv.c 2004-09-28 13:03:34 -04:00
+++ edited/linux-core/sis_drv.c 2004-09-30 13:34:41 -04:00
@@ -83,6 +83,14 @@
.version = version,
.ioctls = ioctls,
.num_ioctls = DRM_ARRAY_SIZE(ioctls),
+ .fops = {
+ .owner = THIS_MODULE,
+ .open = drm_open,
+ .release = drm_release,
+ .ioctl = drm_ioctl,
+ .mmap = drm_mmap,
+ .fasync = drm_fasync,
+ },
};

static int probe(struct pci_dev *pdev, const struct pci_device_id *ent)
===== linux-core/tdfx_drv.c 1.1 vs edited =====
--- 1.1/linux-core/tdfx_drv.c 2004-09-28 13:03:34 -04:00
+++ edited/linux-core/tdfx_drv.c 2004-09-30 13:34:41 -04:00
@@ -74,6 +74,14 @@
.get_reg_ofs = drm_core_get_reg_ofs,
.postinit = postinit,
.version = version,
+ .fops = {
+ .owner = THIS_MODULE,
+ .open = drm_open,
+ .release = drm_release,
+ .ioctl = drm_ioctl,
+ .mmap = drm_mmap,
+ .fasync = drm_fasync,
+ },
};

static int probe(struct pci_dev *pdev, const struct pci_device_id *ent)
===== shared-core/via_drv.c 1.1 vs edited =====
--- 1.1/shared-core/via_drv.c 2004-09-28 13:03:34 -04:00
+++ edited/shared-core/via_drv.c 2004-09-30 13:34:41 -04:00
@@ -99,6 +99,14 @@
.version = version,
.ioctls = ioctls,
.num_ioctls = DRM_ARRAY_SIZE(ioctls),
+ .fops = {
+ .owner = THIS_MODULE,
+ .open = drm_open,
+ .release = drm_release,
+ .ioctl = drm_ioctl,
+ .mmap = drm_mmap,
+ .fasync = drm_fasync,
+ },
};

static int probe(struct pci_dev *pdev, const struct pci_device_id *ent)