summaryrefslogtreecommitdiff
path: root/linux-core
diff options
context:
space:
mode:
Diffstat (limited to 'linux-core')
-rw-r--r--linux-core/drmP.h16
-rw-r--r--linux-core/drm_drv.c17
-rw-r--r--linux-core/drm_ioctl.c174
-rw-r--r--linux-core/drm_irq.c69
-rw-r--r--linux-core/i810_dma.c2
-rw-r--r--linux-core/i830_dma.c4
6 files changed, 121 insertions, 161 deletions
diff --git a/linux-core/drmP.h b/linux-core/drmP.h
index f0fc64d4..1fe9c72c 100644
--- a/linux-core/drmP.h
+++ b/linux-core/drmP.h
@@ -353,6 +353,7 @@ do { \
#define DRM_BUFCOUNT(x) ((x)->count - DRM_LEFTCOUNT(x))
#define DRM_WAITCOUNT(dev,idx) DRM_BUFCOUNT(&dev->queuelist[idx]->waitlist)
+#define DRM_IF_VERSION(maj, min) (maj << 16 | min)
/**
* Get the private SAREA mapping.
*
@@ -658,6 +659,7 @@ typedef struct drm_device {
dev_t device; /**< Device number for mknod */
char *devname; /**< For /proc/interrupts */
int minor; /**< Minor device number */
+ int if_version; /**< Highest interface version set */
int blocked; /**< Blocked due to VC switch? */
struct proc_dir_entry *root; /**< Root for this device's entries */
@@ -715,6 +717,7 @@ typedef struct drm_device {
/** \name Context support */
/*@{*/
int irq; /**< Interrupt used by board */
+ int irq_enabled; /**< True if irq handler is enabled */
__volatile__ long context_flag; /**< Context swapping flag */
__volatile__ long interrupt_flag; /**< Interruption handler flag */
__volatile__ long dma_flag; /**< DMA dispatch flag */
@@ -754,7 +757,12 @@ typedef struct drm_device {
#if __REALLY_HAVE_AGP
drm_agp_head_t *agp; /**< AGP data */
#endif
- struct pci_dev *pdev; /**< PCI device structure */
+
+ struct pci_dev *pdev; /**< PCI device structure */
+ int pci_domain; /**< PCI bus domain number */
+ int pci_bus; /**< PCI bus number */
+ int pci_slot; /**< PCI slot number */
+ int pci_func; /**< PCI function number */
#ifdef __alpha__
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,3)
struct pci_controler *hose;
@@ -844,8 +852,8 @@ extern int DRM(unbind_agp)(DRM_AGP_MEM *handle);
#endif
/* Misc. IOCTL support (drm_ioctl.h) */
-extern int DRM(irq_busid)(struct inode *inode, struct file *filp,
- unsigned int cmd, unsigned long arg);
+extern int DRM(irq_by_busid)(struct inode *inode, struct file *filp,
+ unsigned int cmd, unsigned long arg);
extern int DRM(getunique)(struct inode *inode, struct file *filp,
unsigned int cmd, unsigned long arg);
extern int DRM(setunique)(struct inode *inode, struct file *filp,
@@ -950,7 +958,7 @@ extern int DRM(control)( struct inode *inode, struct file *filp,
unsigned int cmd, unsigned long arg );
#endif
#if __HAVE_IRQ
-extern int DRM(irq_install)( drm_device_t *dev, int irq );
+extern int DRM(irq_install)( drm_device_t *dev );
extern int DRM(irq_uninstall)( drm_device_t *dev );
extern irqreturn_t DRM(irq_handler)( DRM_IRQ_ARGS );
extern void DRM(driver_irq_preinstall)( drm_device_t *dev );
diff --git a/linux-core/drm_drv.c b/linux-core/drm_drv.c
index e472dc33..d0dceaab 100644
--- a/linux-core/drm_drv.c
+++ b/linux-core/drm_drv.c
@@ -173,7 +173,9 @@ static drm_ioctl_desc_t DRM(ioctls)[] = {
[DRM_IOCTL_NR(DRM_IOCTL_VERSION)] = { DRM(version), 0, 0 },
[DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE)] = { DRM(getunique), 0, 0 },
[DRM_IOCTL_NR(DRM_IOCTL_GET_MAGIC)] = { DRM(getmagic), 0, 0 },
- [DRM_IOCTL_NR(DRM_IOCTL_IRQ_BUSID)] = { DRM(irq_busid), 0, 1 },
+#if __HAVE_IRQ
+ [DRM_IOCTL_NR(DRM_IOCTL_IRQ_BUSID)] = { DRM(irq_by_busid), 0, 1 },
+#endif
[DRM_IOCTL_NR(DRM_IOCTL_GET_MAP)] = { DRM(getmap), 0, 0 },
[DRM_IOCTL_NR(DRM_IOCTL_GET_CLIENT)] = { DRM(getclient), 0, 0 },
[DRM_IOCTL_NR(DRM_IOCTL_GET_STATS)] = { DRM(getstats), 0, 0 },
@@ -334,7 +336,7 @@ static int DRM(setup)( drm_device_t *dev )
dev->queue_reserved = 0;
dev->queue_slots = 0;
dev->queuelist = NULL;
- dev->irq = 0;
+ dev->irq_enabled = 0;
dev->context_flag = 0;
dev->interrupt_flag = 0;
dev->dma_flag = 0;
@@ -342,6 +344,7 @@ static int DRM(setup)( drm_device_t *dev )
dev->last_switch = 0;
dev->last_checked = 0;
init_waitqueue_head( &dev->context_wait );
+ dev->if_version = 0;
dev->ctx_start = 0;
dev->lck_start = 0;
@@ -389,7 +392,7 @@ static int DRM(takedown)( drm_device_t *dev )
DRIVER_PRETAKEDOWN();
#if __HAVE_IRQ
- if ( dev->irq ) DRM(irq_uninstall)( dev );
+ if ( dev->irq_enabled ) DRM(irq_uninstall)( dev );
#endif
down( &dev->struct_sem );
@@ -569,10 +572,18 @@ static int DRM(probe)(struct pci_dev *pdev)
return -EPERM;
dev->device = MKDEV(DRM_MAJOR, dev->minor );
dev->name = DRIVER_NAME;
+
dev->pdev = pdev;
#ifdef __alpha__
dev->hose = pdev->sysdata;
+ dev->pci_domain = dev->hose->bus->number;
+#else
+ dev->pci_domain = 0;
#endif
+ dev->pci_bus = pdev->bus->number;
+ dev->pci_slot = PCI_SLOT(pdev->devfn);
+ dev->pci_func = PCI_FUNC(pdev->devfn);
+ dev->irq = pdev->irq;
DRIVER_PREINIT();
diff --git a/linux-core/drm_ioctl.c b/linux-core/drm_ioctl.c
index ac54cae9..f6dea331 100644
--- a/linux-core/drm_ioctl.c
+++ b/linux-core/drm_ioctl.c
@@ -39,69 +39,6 @@
#include "linux/pci.h"
/**
- * Get interrupt from bus id.
- *
- * \param inode device inode.
- * \param filp file pointer.
- * \param cmd command.
- * \param arg user argument, pointing to a drm_irq_busid structure.
- * \return zero on success or a negative number on failure.
- *
- * Finds the PCI device with the specified bus id and gets its IRQ number.
- */
-int DRM(irq_busid)(struct inode *inode, struct file *filp,
- unsigned int cmd, unsigned long arg)
-{
- drm_irq_busid_t p;
- struct pci_dev *dev;
-
- if (copy_from_user(&p, (drm_irq_busid_t *)arg, sizeof(p)))
- return -EFAULT;
-#ifdef __alpha__
- {
- int domain = p.busnum >> 8;
- p.busnum &= 0xff;
-
- /*
- * Find the hose the device is on (the domain number is the
- * hose index) and offset the bus by the root bus of that
- * hose.
- */
- for(dev = pci_find_device(PCI_ANY_ID,PCI_ANY_ID,NULL);
- dev;
- dev = pci_find_device(PCI_ANY_ID,PCI_ANY_ID,dev)) {
- struct pci_controller *hose = dev->sysdata;
-
- if (hose->index == domain) {
- p.busnum += hose->bus->number;
- break;
- }
- }
- }
-#endif
- dev = pci_find_slot(p.busnum, PCI_DEVFN(p.devnum, p.funcnum));
- if (!dev) {
- DRM_ERROR("pci_find_slot failed for %d:%d:%d\n",
- p.busnum, p.devnum, p.funcnum);
- p.irq = 0;
- goto out;
- }
- if (pci_enable_device(dev) != 0) {
- DRM_ERROR("pci_enable_device failed for %d:%d:%d\n",
- p.busnum, p.devnum, p.funcnum);
- p.irq = 0;
- goto out;
- }
- p.irq = dev->irq;
- out:
- DRM_DEBUG("%d:%d:%d => IRQ %d\n",
- p.busnum, p.devnum, p.funcnum, p.irq);
- if (copy_to_user((drm_irq_busid_t *)arg, &p, sizeof(p)))
- return -EFAULT;
- return 0;
-}
-
-/**
* Get the bus id.
*
* \param inode device inode.
@@ -140,9 +77,9 @@ int DRM(getunique)(struct inode *inode, struct file *filp,
* \param arg user argument, pointing to a drm_unique structure.
* \return zero on success or a negative number on failure.
*
- * Copies the bus id from userspace into drm_device::unique, and searches for
- * the respective PCI device, updating drm_device::pdev. Deprecated in
- * interface version 1.1 and will return EBUSY when setversion has requested
+ * Copies the bus id from userspace into drm_device::unique, and verifies that
+ * it matches the device this DRM is attached to (EINVAL otherwise). Deprecated
+ * in interface version 1.1 and will return EBUSY when setversion has requested
* version 1.1 or greater.
*/
int DRM(setunique)(struct inode *inode, struct file *filp,
@@ -151,6 +88,7 @@ int DRM(setunique)(struct inode *inode, struct file *filp,
drm_file_t *priv = filp->private_data;
drm_device_t *dev = priv->dev;
drm_unique_t u;
+ int domain, bus, slot, func, ret;
if (dev->unique_len || dev->unique) return -EBUSY;
@@ -168,55 +106,25 @@ int DRM(setunique)(struct inode *inode, struct file *filp,
dev->devname = DRM(alloc)(strlen(dev->name) + strlen(dev->unique) + 2,
DRM_MEM_DRIVER);
- if(!dev->devname) {
- DRM(free)(dev->devname, sizeof(*dev->devname), DRM_MEM_DRIVER);
+ if (!dev->devname)
return -ENOMEM;
- }
- sprintf(dev->devname, "%s@%s", dev->name, dev->unique);
- do {
- struct pci_dev *pci_dev;
- int domain, b, d, f;
- char *p;
-
- for(p = dev->unique; p && *p && *p != ':'; p++);
- if (!p || !*p) break;
- b = (int)simple_strtoul(p+1, &p, 10);
- if (*p != ':') break;
- d = (int)simple_strtoul(p+1, &p, 10);
- if (*p != ':') break;
- f = (int)simple_strtoul(p+1, &p, 10);
- if (*p) break;
-
- domain = b >> 8;
- b &= 0xff;
-
-#ifdef __alpha__
- /*
- * Find the hose the device is on (the domain number is the
- * hose index) and offset the bus by the root bus of that
- * hose.
- */
- for(pci_dev = pci_find_device(PCI_ANY_ID,PCI_ANY_ID,NULL);
- pci_dev;
- pci_dev = pci_find_device(PCI_ANY_ID,PCI_ANY_ID,pci_dev)) {
- struct pci_controller *hose = pci_dev->sysdata;
-
- if (hose->index == domain) {
- b += hose->bus->number;
- break;
- }
- }
-#endif
+ sprintf(dev->devname, "%s@%s", dev->name, dev->unique);
- pci_dev = pci_find_slot(b, PCI_DEVFN(d,f));
- if (pci_dev) {
- dev->pdev = pci_dev;
-#ifdef __alpha__
- dev->hose = pci_dev->sysdata;
-#endif
- }
- } while(0);
+ /* Return error if the busid submitted doesn't match the device's actual
+ * busid.
+ */
+ ret = sscanf(dev->unique, "PCI:%d:%d:%d", &bus, &slot, &func);
+ if (ret != 3)
+ return DRM_ERR(EINVAL);
+ domain = bus >> 8;
+ bus &= 0xff;
+
+ if ((domain != dev->pci_domain) ||
+ (bus != dev->pci_bus) ||
+ (slot != dev->pci_slot) ||
+ (func != dev->pci_func))
+ return -EINVAL;
return 0;
}
@@ -232,21 +140,8 @@ DRM(set_busid)(drm_device_t *dev)
if (dev->unique == NULL)
return ENOMEM;
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,74)
- snprintf(dev->unique, dev->unique_len, "pci:%s", pci_name(dev->pdev));
-#else
- {
- int domain = 0;
-#ifdef __alpha__
- struct pci_controller *hose = pci_dev->sysdata;
-
- domain = hose->bus->number;
-#endif
- snprintf(dev->unique, dev->unique_len, "pci:%04x:%02x:%02x.%d",
- domain, dev->pdev->bus->number,
- PCI_SLOT(dev->pdev->devfn), PCI_FUNC(dev->pdev->devfn));
- }
-#endif
+ snprintf(dev->unique, dev->unique_len, "pci:%04x:%02x:%02x.%d",
+ dev->pci_domain, dev->pci_bus, dev->pci_slot, dev->pci_func);
return 0;
}
@@ -398,26 +293,31 @@ int DRM(getstats)( struct inode *inode, struct file *filp,
return 0;
}
+#define DRM_IF_MAJOR 1
+#define DRM_IF_MINOR 2
+
int DRM(setversion)(DRM_IOCTL_ARGS)
{
DRM_DEVICE;
drm_set_version_t sv;
drm_set_version_t retv;
+ int if_version;
DRM_COPY_FROM_USER_IOCTL(sv, (drm_set_version_t *)data, sizeof(sv));
- retv.drm_di_major = 1;
- retv.drm_di_minor = 1;
+ retv.drm_di_major = DRM_IF_MAJOR;
+ retv.drm_di_minor = DRM_IF_MINOR;
retv.drm_dd_major = DRIVER_MAJOR;
retv.drm_dd_minor = DRIVER_MINOR;
-
+
DRM_COPY_TO_USER_IOCTL((drm_set_version_t *)data, retv, sizeof(sv));
if (sv.drm_di_major != -1) {
- if (sv.drm_di_major != 1 || sv.drm_di_minor < 0)
- return EINVAL;
- if (sv.drm_di_minor > 1)
+ if (sv.drm_di_major != DRM_IF_MAJOR ||
+ sv.drm_di_minor < 0 || sv.drm_di_minor > DRM_IF_MINOR)
return EINVAL;
+ if_version = DRM_IF_VERSION(sv.drm_di_major, sv.drm_dd_minor);
+ dev->if_version = DRM_MAX(if_version, dev->if_version);
if (sv.drm_di_minor >= 1) {
/*
* Version 1.1 includes tying of DRM to specific device
@@ -427,13 +327,13 @@ int DRM(setversion)(DRM_IOCTL_ARGS)
}
if (sv.drm_dd_major != -1) {
- if (sv.drm_dd_major != DRIVER_MAJOR || sv.drm_dd_minor < 0)
- return EINVAL;
- if (sv.drm_dd_minor > DRIVER_MINOR)
+ if (sv.drm_dd_major != DRIVER_MAJOR ||
+ sv.drm_dd_minor < 0 || sv.drm_dd_minor > DRIVER_MINOR)
return EINVAL;
#ifdef DRIVER_SETVERSION
- DRIVER_SETVERSION(dev, sv);
+ DRIVER_SETVERSION(dev, &sv);
#endif
}
return 0;
}
+
diff --git a/linux-core/drm_irq.c b/linux-core/drm_irq.c
index 322e5717..837e6951 100644
--- a/linux-core/drm_irq.c
+++ b/linux-core/drm_irq.c
@@ -48,6 +48,44 @@
#define DRM_IRQ_TYPE 0
#endif
+/**
+ * Get interrupt from bus id.
+ *
+ * \param inode device inode.
+ * \param filp file pointer.
+ * \param cmd command.
+ * \param arg user argument, pointing to a drm_irq_busid structure.
+ * \return zero on success or a negative number on failure.
+ *
+ * Finds the PCI device with the specified bus id and gets its IRQ number.
+ * This IOCTL is deprecated, and will now return EINVAL for any busid not equal
+ * to that of the device that this DRM instance attached to.
+ */
+int DRM(irq_by_busid)(struct inode *inode, struct file *filp,
+ unsigned int cmd, unsigned long arg)
+{
+ drm_file_t *priv = filp->private_data;
+ drm_device_t *dev = priv->dev;
+ drm_irq_busid_t p;
+
+ if (copy_from_user(&p, (drm_irq_busid_t *)arg, sizeof(p)))
+ return -EFAULT;
+
+ if ((p.busnum >> 8) != dev->pci_domain ||
+ (p.busnum & 0xff) != dev->pci_bus ||
+ p.devnum != dev->pci_slot ||
+ p.funcnum != dev->pci_func)
+ return -EINVAL;
+
+ p.irq = dev->irq;
+
+ DRM_DEBUG("%d:%d:%d => IRQ %d\n",
+ p.busnum, p.devnum, p.funcnum, p.irq);
+ if (copy_to_user((drm_irq_busid_t *)arg, &p, sizeof(p)))
+ return -EFAULT;
+ return 0;
+}
+
#if __HAVE_IRQ
/**
@@ -60,11 +98,11 @@
* \c DRM(driver_irq_preinstall)() and \c DRM(driver_irq_postinstall)() functions
* before and after the installation.
*/
-int DRM(irq_install)( drm_device_t *dev, int irq )
+int DRM(irq_install)( drm_device_t *dev )
{
int ret;
-
- if ( !irq )
+
+ if ( dev->irq == 0 )
return -EINVAL;
down( &dev->struct_sem );
@@ -75,14 +113,14 @@ int DRM(irq_install)( drm_device_t *dev, int irq )
return -EINVAL;
}
- if ( dev->irq ) {
+ if ( dev->irq_enabled ) {
up( &dev->struct_sem );
return -EBUSY;
}
- dev->irq = irq;
+ dev->irq_enabled = 1;
up( &dev->struct_sem );
- DRM_DEBUG( "%s: irq=%d\n", __FUNCTION__, irq );
+ DRM_DEBUG( "%s: irq=%d\n", __FUNCTION__, dev->irq );
dev->context_flag = 0;
dev->interrupt_flag = 0;
@@ -121,7 +159,7 @@ int DRM(irq_install)( drm_device_t *dev, int irq )
DRM_IRQ_TYPE, dev->devname, dev );
if ( ret < 0 ) {
down( &dev->struct_sem );
- dev->irq = 0;
+ dev->irq_enabled = 0;
up( &dev->struct_sem );
return ret;
}
@@ -141,21 +179,21 @@ int DRM(irq_install)( drm_device_t *dev, int irq )
*/
int DRM(irq_uninstall)( drm_device_t *dev )
{
- int irq;
+ int irq_enabled;
down( &dev->struct_sem );
- irq = dev->irq;
- dev->irq = 0;
+ irq_enabled = dev->irq_enabled;
+ dev->irq_enabled = 0;
up( &dev->struct_sem );
- if ( !irq )
+ if ( !irq_enabled )
return -EINVAL;
- DRM_DEBUG( "%s: irq=%d\n", __FUNCTION__, irq );
+ DRM_DEBUG( "%s: irq=%d\n", __FUNCTION__, dev->irq );
DRM(driver_irq_uninstall)( dev );
- free_irq( irq, dev );
+ free_irq( dev->irq, dev );
return 0;
}
@@ -183,7 +221,10 @@ int DRM(control)( struct inode *inode, struct file *filp,
switch ( ctl.func ) {
case DRM_INST_HANDLER:
- return DRM(irq_install)( dev, ctl.irq );
+ if (dev->if_version < DRM_IF_VERSION(1, 2) &&
+ ctl.irq != dev->irq)
+ return -EINVAL;
+ return DRM(irq_install)( dev );
case DRM_UNINST_HANDLER:
return DRM(irq_uninstall)( dev );
default:
diff --git a/linux-core/i810_dma.c b/linux-core/i810_dma.c
index 1eeb4a3f..b46c3a39 100644
--- a/linux-core/i810_dma.c
+++ b/linux-core/i810_dma.c
@@ -244,7 +244,7 @@ int i810_dma_cleanup(drm_device_t *dev)
* may not have been called from userspace and after dev_private
* is freed, it's too late.
*/
- if (dev->irq) DRM(irq_uninstall)(dev);
+ if (dev->irq_enabled) DRM(irq_uninstall)(dev);
#endif
if (dev->dev_private) {
diff --git a/linux-core/i830_dma.c b/linux-core/i830_dma.c
index 422f3ad5..626f84be 100644
--- a/linux-core/i830_dma.c
+++ b/linux-core/i830_dma.c
@@ -243,7 +243,7 @@ int i830_dma_cleanup(drm_device_t *dev)
* may not have been called from userspace and after dev_private
* is freed, it's too late.
*/
- if (dev->irq) DRM(irq_uninstall)(dev);
+ if (dev->irq_enabled) DRM(irq_uninstall)(dev);
#endif
if (dev->dev_private) {
@@ -1546,7 +1546,7 @@ int i830_getparam( struct inode *inode, struct file *filp, unsigned int cmd,
switch( param.param ) {
case I830_PARAM_IRQ_ACTIVE:
- value = dev->irq ? 1 : 0;
+ value = dev->irq_enabled;
break;
default:
return -EINVAL;