summaryrefslogtreecommitdiff
path: root/linux-core
diff options
context:
space:
mode:
Diffstat (limited to 'linux-core')
-rw-r--r--linux-core/drm_bufs.c19
-rw-r--r--linux-core/drm_dma.c11
-rw-r--r--linux-core/drm_drv.c15
-rw-r--r--linux-core/drm_ioctl.c2
-rw-r--r--linux-core/drm_vm.c18
-rw-r--r--linux-core/i810_dma.c11
-rw-r--r--linux-core/i810_drm.h5
-rw-r--r--linux-core/i810_drv.c26
-rw-r--r--linux-core/mga_drv.c21
-rw-r--r--linux-core/r128_drv.c26
-rw-r--r--linux-core/radeon_drv.c20
-rw-r--r--linux-core/sis_drv.c704
-rw-r--r--linux-core/tdfx_drv.c20
13 files changed, 204 insertions, 694 deletions
diff --git a/linux-core/drm_bufs.c b/linux-core/drm_bufs.c
index 16af7bd54..02502321b 100644
--- a/linux-core/drm_bufs.c
+++ b/linux-core/drm_bufs.c
@@ -332,6 +332,12 @@ int DRM(addbufs_agp)( struct inode *inode, struct file *filp,
return -ENOMEM; /* May only call once for each order */
}
+ if (count < 0 || count > 4096) {
+ up( &dev->struct_sem );
+ atomic_dec( &dev->buf_alloc );
+ return -EINVAL;
+ }
+
entry->buflist = DRM(alloc)( count * sizeof(*entry->buflist),
DRM_MEM_BUFS );
if ( !entry->buflist ) {
@@ -479,6 +485,12 @@ int DRM(addbufs_pci)( struct inode *inode, struct file *filp,
return -ENOMEM; /* May only call once for each order */
}
+ if (count < 0 || count > 4096) {
+ up( &dev->struct_sem );
+ atomic_dec( &dev->buf_alloc );
+ return -EINVAL;
+ }
+
entry->buflist = DRM(alloc)( count * sizeof(*entry->buflist),
DRM_MEM_BUFS );
if ( !entry->buflist ) {
@@ -581,6 +593,7 @@ int DRM(addbufs_pci)( struct inode *inode, struct file *filp,
atomic_dec( &dev->buf_alloc );
return 0;
+
}
#endif /* __HAVE_PCI_DMA */
@@ -650,6 +663,12 @@ int DRM(addbufs_sg)( struct inode *inode, struct file *filp,
return -ENOMEM; /* May only call once for each order */
}
+ if (count < 0 || count > 4096) {
+ up( &dev->struct_sem );
+ atomic_dec( &dev->buf_alloc );
+ return -EINVAL;
+ }
+
entry->buflist = DRM(alloc)( count * sizeof(*entry->buflist),
DRM_MEM_BUFS );
if ( !entry->buflist ) {
diff --git a/linux-core/drm_dma.c b/linux-core/drm_dma.c
index e715bd416..85fa14723 100644
--- a/linux-core/drm_dma.c
+++ b/linux-core/drm_dma.c
@@ -40,6 +40,15 @@
#ifndef __HAVE_DMA_RECLAIM
#define __HAVE_DMA_RECLAIM 0
#endif
+#ifndef __HAVE_SHARED_IRQ
+#define __HAVE_SHARED_IRQ 0
+#endif
+
+#if __HAVE_SHARED_IRQ
+#define DRM_IRQ_TYPE SA_SHIRQ
+#else
+#define DRM_IRQ_TYPE 0
+#endif
#if __HAVE_DMA
@@ -534,7 +543,7 @@ int DRM(irq_install)( drm_device_t *dev, int irq )
/* Install handler */
ret = request_irq( dev->irq, DRM(dma_service),
- 0, dev->devname, dev );
+ DRM_IRQ_TYPE, dev->devname, dev );
if ( ret < 0 ) {
down( &dev->struct_sem );
dev->irq = 0;
diff --git a/linux-core/drm_drv.c b/linux-core/drm_drv.c
index ea684f883..f969ec595 100644
--- a/linux-core/drm_drv.c
+++ b/linux-core/drm_drv.c
@@ -208,21 +208,6 @@ MODULE_AUTHOR( DRIVER_AUTHOR );
MODULE_DESCRIPTION( DRIVER_DESC );
MODULE_PARM( drm_opts, "s" );
-#ifndef MODULE
-/* DRM(options) is called by the kernel to parse command-line options
- * passed via the boot-loader (e.g., LILO). It calls the insmod option
- * routine, drm_parse_drm.
- */
-
-static int __init DRM(options)( char *str )
-{
- DRM(parse_options)( str );
- return 1;
-}
-
-__setup( DRIVER_NAME "=", DRM(options) );
-#endif
-
static int DRM(setup)( drm_device_t *dev )
{
int i;
diff --git a/linux-core/drm_ioctl.c b/linux-core/drm_ioctl.c
index 1cc8f31f0..c2761808a 100644
--- a/linux-core/drm_ioctl.c
+++ b/linux-core/drm_ioctl.c
@@ -82,7 +82,7 @@ int DRM(setunique)(struct inode *inode, struct file *filp,
if (copy_from_user(&u, (drm_unique_t *)arg, sizeof(u)))
return -EFAULT;
- if (!u.unique_len)
+ if (!u.unique_len || u.unique_len > 1024)
return -EINVAL;
dev->unique_len = u.unique_len;
diff --git a/linux-core/drm_vm.c b/linux-core/drm_vm.c
index 771c11bd2..4db521de3 100644
--- a/linux-core/drm_vm.c
+++ b/linux-core/drm_vm.c
@@ -32,25 +32,25 @@
#define __NO_VERSION__
#include "drmP.h"
-struct vm_operations_struct drm_vm_ops = {
+struct vm_operations_struct DRM(vm_ops) = {
nopage: DRM(vm_nopage),
open: DRM(vm_open),
close: DRM(vm_close),
};
-struct vm_operations_struct drm_vm_shm_ops = {
+struct vm_operations_struct DRM(vm_shm_ops) = {
nopage: DRM(vm_shm_nopage),
open: DRM(vm_open),
close: DRM(vm_shm_close),
};
-struct vm_operations_struct drm_vm_dma_ops = {
+struct vm_operations_struct DRM(vm_dma_ops) = {
nopage: DRM(vm_dma_nopage),
open: DRM(vm_open),
close: DRM(vm_close),
};
-struct vm_operations_struct drm_vm_sg_ops = {
+struct vm_operations_struct DRM(vm_sg_ops) = {
nopage: DRM(vm_sg_nopage),
open: DRM(vm_open),
close: DRM(vm_close),
@@ -352,7 +352,7 @@ int DRM(mmap_dma)(struct file *filp, struct vm_area_struct *vma)
}
unlock_kernel();
- vma->vm_ops = &drm_vm_dma_ops;
+ vma->vm_ops = &DRM(vm_dma_ops);
vma->vm_flags |= VM_LOCKED | VM_SHM; /* Don't swap */
#if LINUX_VERSION_CODE < 0x020203 /* KERNEL_VERSION(2,2,3) */
@@ -377,6 +377,8 @@ int DRM(mmap)(struct file *filp, struct vm_area_struct *vma)
DRM_DEBUG("start = 0x%lx, end = 0x%lx, offset = 0x%lx\n",
vma->vm_start, vma->vm_end, VM_OFFSET(vma));
+ if ( !priv->authenticated ) return -EACCES;
+
if (!VM_OFFSET(vma)) return DRM(mmap_dma)(filp, vma);
/* A sequential search of a linked list is
@@ -444,10 +446,10 @@ int DRM(mmap)(struct file *filp, struct vm_area_struct *vma)
" offset = 0x%lx\n",
map->type,
vma->vm_start, vma->vm_end, VM_OFFSET(vma) + offset);
- vma->vm_ops = &drm_vm_ops;
+ vma->vm_ops = &DRM(vm_ops);
break;
case _DRM_SHM:
- vma->vm_ops = &drm_vm_shm_ops;
+ vma->vm_ops = &DRM(vm_shm_ops);
#if LINUX_VERSION_CODE >= 0x020300
vma->vm_private_data = (void *)map;
#else
@@ -458,7 +460,7 @@ int DRM(mmap)(struct file *filp, struct vm_area_struct *vma)
vma->vm_flags |= VM_LOCKED;
break;
case _DRM_SCATTER_GATHER:
- vma->vm_ops = &drm_vm_sg_ops;
+ vma->vm_ops = &DRM(vm_sg_ops);
#if LINUX_VERSION_CODE >= 0x020300
vma->vm_private_data = (void *)map;
#else
diff --git a/linux-core/i810_dma.c b/linux-core/i810_dma.c
index 8a5503eaf..75be5d0cc 100644
--- a/linux-core/i810_dma.c
+++ b/linux-core/i810_dma.c
@@ -1094,6 +1094,8 @@ int i810_dma_vertex(struct inode *inode, struct file *filp,
DRM_DEBUG("i810 dma vertex, idx %d used %d discard %d\n",
vertex.idx, vertex.used, vertex.discard);
+ if(vertex.idx < 0 || vertex.idx > dma->buf_count) return -EINVAL;
+
i810_dma_dispatch_vertex( dev,
dma->buflist[ vertex.idx ],
vertex.discard, vertex.used );
@@ -1123,6 +1125,11 @@ int i810_clear_bufs(struct inode *inode, struct file *filp,
return -EINVAL;
}
+ /* GH: Someone's doing nasty things... */
+ if (!dev->dev_private) {
+ return -EINVAL;
+ }
+
i810_dma_dispatch_clear( dev, clear.flags,
clear.clear_color,
clear.clear_depth );
@@ -1217,11 +1224,13 @@ int i810_copybuf(struct inode *inode, struct file *filp, unsigned int cmd,
if (copy_from_user(&d, (drm_i810_copy_t *)arg, sizeof(d)))
return -EFAULT;
- if(d.idx > dma->buf_count) return -EINVAL;
+ if(d.idx < 0 || d.idx > dma->buf_count) return -EINVAL;
buf = dma->buflist[ d.idx ];
buf_priv = buf->dev_private;
if (buf_priv->currently_mapped != I810_BUF_MAPPED) return -EPERM;
+ if(d.used < 0 || d.used > buf->total) return -EINVAL;
+
if (copy_from_user(buf_priv->virtual, d.address, d.used))
return -EFAULT;
diff --git a/linux-core/i810_drm.h b/linux-core/i810_drm.h
index cee189b7b..5d47adda2 100644
--- a/linux-core/i810_drm.h
+++ b/linux-core/i810_drm.h
@@ -98,8 +98,13 @@ typedef struct _drm_i810_init {
I810_INIT_DMA = 0x01,
I810_CLEANUP_DMA = 0x02
} func;
+#if CONFIG_XFREE86_VERSION < XFREE86_VERSION(4,1,0,0)
+ int ring_map_idx;
+ int buffer_map_idx;
+#else
unsigned int mmio_offset;
unsigned int buffers_offset;
+#endif
int sarea_priv_offset;
unsigned int ring_start;
unsigned int ring_end;
diff --git a/linux-core/i810_drv.c b/linux-core/i810_drv.c
index 12a59dbf3..d21a19b7d 100644
--- a/linux-core/i810_drv.c
+++ b/linux-core/i810_drv.c
@@ -39,10 +39,10 @@
#define DRIVER_NAME "i810"
#define DRIVER_DESC "Intel i810"
-#define DRIVER_DATE "20010215"
+#define DRIVER_DATE "20010616"
-#define DRIVER_MAJOR 1
-#define DRIVER_MINOR 1
+#define DRIVER_MAJOR 2
+#define DRIVER_MINOR 0
#define DRIVER_PATCHLEVEL 0
#define DRIVER_IOCTLS \
@@ -71,6 +71,26 @@
#include "drm_dma.h"
#include "drm_drawable.h"
#include "drm_drv.h"
+
+#ifndef MODULE
+/* DRM(options) is called by the kernel to parse command-line options
+ * passed via the boot-loader (e.g., LILO). It calls the insmod option
+ * routine, drm_parse_drm.
+ */
+
+/* JH- We have to hand expand the string ourselves because of the cpp. If
+ * anyone can think of a way that we can fit into the __setup macro without
+ * changing it, then please send the solution my way.
+ */
+static int __init i810_options( char *str )
+{
+ DRM(parse_options)( str );
+ return 1;
+}
+
+__setup( DRIVER_NAME "=", i810_options );
+#endif
+
#include "drm_fops.h"
#include "drm_init.h"
#include "drm_ioctl.h"
diff --git a/linux-core/mga_drv.c b/linux-core/mga_drv.c
index bea65cfa6..91216d24f 100644
--- a/linux-core/mga_drv.c
+++ b/linux-core/mga_drv.c
@@ -70,6 +70,27 @@
#include "drm_dma.h"
#include "drm_drawable.h"
#include "drm_drv.h"
+
+#ifndef MODULE
+/* DRM(options) is called by the kernel to parse command-line options
+ * passed via the boot-loader (e.g., LILO). It calls the insmod option
+ * routine, drm_parse_drm.
+ */
+
+/* JH- We have to hand expand the string ourselves because of the cpp. If
+ * anyone can think of a way that we can fit into the __setup macro without
+ * changing it, then please send the solution my way.
+ */
+static int __init mga_options( char *str )
+{
+ DRM(parse_options)( str );
+ return 1;
+}
+
+__setup( DRIVER_NAME "=", mga_options );
+#endif
+
+
#include "drm_fops.h"
#include "drm_init.h"
#include "drm_ioctl.h"
diff --git a/linux-core/r128_drv.c b/linux-core/r128_drv.c
index 584cb29c3..4f0bb92b8 100644
--- a/linux-core/r128_drv.c
+++ b/linux-core/r128_drv.c
@@ -41,9 +41,9 @@
#define DRIVER_DESC "ATI Rage 128"
#define DRIVER_DATE "20010405"
-#define DRIVER_MAJOR 2
-#define DRIVER_MINOR 1
-#define DRIVER_PATCHLEVEL 6
+#define DRIVER_MAJOR 3
+#define DRIVER_MINOR 0
+#define DRIVER_PATCHLEVEL 0
#define DRIVER_IOCTLS \
[DRM_IOCTL_NR(DRM_IOCTL_DMA)] = { r128_cce_buffers, 1, 0 }, \
@@ -81,6 +81,26 @@
#include "drm_dma.h"
#include "drm_drawable.h"
#include "drm_drv.h"
+
+#ifndef MODULE
+/* DRM(options) is called by the kernel to parse command-line options
+ * passed via the boot-loader (e.g., LILO). It calls the insmod option
+ * routine, drm_parse_drm.
+ */
+
+/* JH- We have to hand expand the string ourselves because of the cpp. If
+ * anyone can think of a way that we can fit into the __setup macro without
+ * changing it, then please send the solution my way.
+ */
+static int __init r128_options( char *str )
+{
+ DRM(parse_options)( str );
+ return 1;
+}
+
+__setup( DRIVER_NAME "=", r128_options );
+#endif
+
#include "drm_fops.h"
#include "drm_init.h"
#include "drm_ioctl.h"
diff --git a/linux-core/radeon_drv.c b/linux-core/radeon_drv.c
index d76326676..49599bc82 100644
--- a/linux-core/radeon_drv.c
+++ b/linux-core/radeon_drv.c
@@ -78,6 +78,26 @@
#include "drm_dma.h"
#include "drm_drawable.h"
#include "drm_drv.h"
+
+#ifndef MODULE
+/* DRM(options) is called by the kernel to parse command-line options
+ * passed via the boot-loader (e.g., LILO). It calls the insmod option
+ * routine, drm_parse_drm.
+ */
+
+/* JH- We have to hand expand the string ourselves because of the cpp. If
+ * anyone can think of a way that we can fit into the __setup macro without
+ * changing it, then please send the solution my way.
+ */
+static int __init radeon_options( char *str )
+{
+ DRM(parse_options)( str );
+ return 1;
+}
+
+__setup( DRIVER_NAME "=", radeon_options );
+#endif
+
#include "drm_fops.h"
#include "drm_init.h"
#include "drm_ioctl.h"
diff --git a/linux-core/sis_drv.c b/linux-core/sis_drv.c
index 92ec32ddd..3dd83fd7e 100644
--- a/linux-core/sis_drv.c
+++ b/linux-core/sis_drv.c
@@ -26,669 +26,49 @@
*/
#include <linux/config.h>
+#include "sis.h"
#include "drmP.h"
#include "sis_drm.h"
#include "sis_drv.h"
-#define SIS_NAME "sis"
-#define SIS_DESC "SIS 300/630/540"
-#define SIS_DATE "20000831"
-#define SIS_MAJOR 1
-#define SIS_MINOR 0
-#define SIS_PATCHLEVEL 0
-
-static drm_device_t sis_device;
-drm_ctx_t sis_res_ctx;
-
-static struct file_operations sis_fops = {
-#if LINUX_VERSION_CODE >= 0x020400
- /* This started being used during 2.4.0-test */
- owner: THIS_MODULE,
-#endif
- open: sis_open,
- flush: drm_flush,
- release: sis_release,
- ioctl: sis_ioctl,
- mmap: drm_mmap,
- read: drm_read,
- fasync: drm_fasync,
- poll: drm_poll,
-};
-
-static struct miscdevice sis_misc = {
- minor: MISC_DYNAMIC_MINOR,
- name: SIS_NAME,
- fops: &sis_fops,
-};
-
-static drm_ioctl_desc_t sis_ioctls[] = {
- [DRM_IOCTL_NR(DRM_IOCTL_VERSION)] = { sis_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 },
-
- [DRM_IOCTL_NR(DRM_IOCTL_SET_UNIQUE)] = { drm_setunique, 1, 1 },
- [DRM_IOCTL_NR(DRM_IOCTL_BLOCK)] = { drm_block, 1, 1 },
- [DRM_IOCTL_NR(DRM_IOCTL_UNBLOCK)] = { drm_unblock, 1, 1 },
- [DRM_IOCTL_NR(DRM_IOCTL_AUTH_MAGIC)] = { drm_authmagic, 1, 1 },
- [DRM_IOCTL_NR(DRM_IOCTL_ADD_MAP)] = { drm_addmap, 1, 1 },
-
- [DRM_IOCTL_NR(DRM_IOCTL_ADD_CTX)] = { sis_addctx, 1, 1 },
- [DRM_IOCTL_NR(DRM_IOCTL_RM_CTX)] = { sis_rmctx, 1, 1 },
- [DRM_IOCTL_NR(DRM_IOCTL_MOD_CTX)] = { sis_modctx, 1, 1 },
- [DRM_IOCTL_NR(DRM_IOCTL_GET_CTX)] = { sis_getctx, 1, 0 },
- [DRM_IOCTL_NR(DRM_IOCTL_SWITCH_CTX)] = { sis_switchctx, 1, 1 },
- [DRM_IOCTL_NR(DRM_IOCTL_NEW_CTX)] = { sis_newctx, 1, 1 },
- [DRM_IOCTL_NR(DRM_IOCTL_RES_CTX)] = { sis_resctx, 1, 0 },
- [DRM_IOCTL_NR(DRM_IOCTL_ADD_DRAW)] = { drm_adddraw, 1, 1 },
- [DRM_IOCTL_NR(DRM_IOCTL_RM_DRAW)] = { drm_rmdraw, 1, 1 },
- [DRM_IOCTL_NR(DRM_IOCTL_LOCK)] = { sis_lock, 1, 0 },
- [DRM_IOCTL_NR(DRM_IOCTL_UNLOCK)] = { sis_unlock, 1, 0 },
- [DRM_IOCTL_NR(DRM_IOCTL_FINISH)] = { drm_finish, 1, 0 },
-#if defined(CONFIG_AGP) || defined(CONFIG_AGP_MODULE)
- [DRM_IOCTL_NR(DRM_IOCTL_AGP_ACQUIRE)] = {drm_agp_acquire, 1, 1},
- [DRM_IOCTL_NR(DRM_IOCTL_AGP_RELEASE)] = {drm_agp_release, 1, 1},
- [DRM_IOCTL_NR(DRM_IOCTL_AGP_ENABLE)] = {drm_agp_enable, 1, 1},
- [DRM_IOCTL_NR(DRM_IOCTL_AGP_INFO)] = {drm_agp_info, 1, 1},
- [DRM_IOCTL_NR(DRM_IOCTL_AGP_ALLOC)] = {drm_agp_alloc, 1, 1},
- [DRM_IOCTL_NR(DRM_IOCTL_AGP_FREE)] = {drm_agp_free, 1, 1},
- [DRM_IOCTL_NR(DRM_IOCTL_AGP_BIND)] = {drm_agp_bind, 1, 1},
- [DRM_IOCTL_NR(DRM_IOCTL_AGP_UNBIND)] = {drm_agp_unbind, 1, 1},
-#endif
- /* FB Memory Management */
- [DRM_IOCTL_NR(SIS_IOCTL_FB_ALLOC)] = { sis_fb_alloc, 1, 1 },
- [DRM_IOCTL_NR(SIS_IOCTL_FB_FREE)] = { sis_fb_free, 1, 1 },
-
- /* AGP Memory Management */
- [DRM_IOCTL_NR(SIS_IOCTL_AGP_INIT)] = { sis_agp_init, 1, 1 },
- [DRM_IOCTL_NR(SIS_IOCTL_AGP_ALLOC)] = { sis_agp_alloc, 1, 1 },
- [DRM_IOCTL_NR(SIS_IOCTL_AGP_FREE)] = { sis_agp_free, 1, 1 },
-
-#if defined(SIS_STEREO)
- [DRM_IOCTL_NR(DRM_IOCTL_CONTROL)] = { sis_control, 1, 1 },
- [DRM_IOCTL_NR(SIS_IOCTL_FLIP)] = { sis_flip, 1, 1 },
- [DRM_IOCTL_NR(SIS_IOCTL_FLIP_INIT)] = { sis_flip_init, 1, 1 },
- [DRM_IOCTL_NR(SIS_IOCTL_FLIP_FINAL)] = { sis_flip_final, 1, 1 },
-#endif
-};
-#define SIS_IOCTL_COUNT DRM_ARRAY_SIZE(sis_ioctls)
-
-#ifdef MODULE
-static char *sis = NULL;
-#endif
-
-MODULE_AUTHOR("VA Linux Systems, Inc.");
-MODULE_DESCRIPTION("sis");
-MODULE_PARM(sis, "s");
-
-#ifndef MODULE
-/* sis_options is called by the kernel to parse command-line options
- * passed via the boot-loader (e.g., LILO). It calls the insmod option
- * routine, drm_parse_drm.
- */
-
-static int __init sis_options(char *str)
-{
- drm_parse_options(str);
- return 1;
-}
-
-__setup("sis=", sis_options);
-#endif
-
-static int sis_setup(drm_device_t *dev)
-{
- int i;
-
- atomic_set(&dev->ioctl_count, 0);
- atomic_set(&dev->vma_count, 0);
- dev->buf_use = 0;
- atomic_set(&dev->buf_alloc, 0);
-
- atomic_set(&dev->total_open, 0);
- atomic_set(&dev->total_close, 0);
- atomic_set(&dev->total_ioctl, 0);
- atomic_set(&dev->total_irq, 0);
- atomic_set(&dev->total_ctx, 0);
- atomic_set(&dev->total_locks, 0);
- atomic_set(&dev->total_unlocks, 0);
- atomic_set(&dev->total_contends, 0);
- atomic_set(&dev->total_sleeps, 0);
-
- for (i = 0; i < DRM_HASH_SIZE; i++) {
- dev->magiclist[i].head = NULL;
- dev->magiclist[i].tail = NULL;
- }
- dev->maplist = NULL;
- dev->map_count = 0;
- dev->vmalist = NULL;
- dev->lock.hw_lock = NULL;
- init_waitqueue_head(&dev->lock.lock_queue);
- dev->queue_count = 0;
- dev->queue_reserved = 0;
- dev->queue_slots = 0;
- dev->queuelist = NULL;
- dev->irq = 0;
- dev->context_flag = 0;
- dev->interrupt_flag = 0;
- dev->dma = 0;
- dev->dma_flag = 0;
- dev->last_context = 0;
- dev->last_switch = 0;
- dev->last_checked = 0;
- init_timer(&dev->timer);
- init_waitqueue_head(&dev->context_wait);
-
- dev->ctx_start = 0;
- dev->lck_start = 0;
-
- dev->buf_rp = dev->buf;
- dev->buf_wp = dev->buf;
- dev->buf_end = dev->buf + DRM_BSZ;
- dev->buf_async = NULL;
- init_waitqueue_head(&dev->buf_readers);
- init_waitqueue_head(&dev->buf_writers);
-
- sis_res_ctx.handle=-1;
-
- DRM_DEBUG("\n");
-
- /* The kernel's context could be created here, but is now created
- in drm_dma_enqueue. This is more resource-efficient for
- hardware that does not do DMA, but may mean that
- drm_select_queue fails between the time the interrupt is
- initialized and the time the queues are initialized. */
-
- return 0;
-}
-
-
-static int sis_takedown(drm_device_t *dev)
-{
- int i;
- drm_magic_entry_t *pt, *next;
- drm_map_t *map;
- drm_vma_entry_t *vma, *vma_next;
-
- DRM_DEBUG("\n");
-
-#if defined(SIS_STEREO)
- if (dev->irq) sis_irq_uninstall(dev);
-#endif
-
- down(&dev->struct_sem);
- del_timer(&dev->timer);
-
- if (dev->devname) {
- drm_free(dev->devname, strlen(dev->devname)+1, DRM_MEM_DRIVER);
- dev->devname = NULL;
- }
-
- if (dev->unique) {
- drm_free(dev->unique, strlen(dev->unique)+1, DRM_MEM_DRIVER);
- dev->unique = NULL;
- dev->unique_len = 0;
- }
- /* Clear pid list */
- for (i = 0; i < DRM_HASH_SIZE; i++) {
- for (pt = dev->magiclist[i].head; pt; pt = next) {
- next = pt->next;
- drm_free(pt, sizeof(*pt), DRM_MEM_MAGIC);
- }
- dev->magiclist[i].head = dev->magiclist[i].tail = NULL;
- }
-#if defined(CONFIG_AGP) || defined(CONFIG_AGP_MODULE)
- /* Clear AGP information */
- if (dev->agp) {
- drm_agp_mem_t *temp;
- drm_agp_mem_t *temp_next;
-
- temp = dev->agp->memory;
- while(temp != NULL) {
- temp_next = temp->next;
- drm_free_agp(temp->memory, temp->pages);
- drm_free(temp, sizeof(*temp), DRM_MEM_AGPLISTS);
- temp = temp_next;
- }
- if (dev->agp->acquired) _drm_agp_release();
- }
-#endif
- /* Clear vma list (only built for debugging) */
- if (dev->vmalist) {
- for (vma = dev->vmalist; vma; vma = vma_next) {
- vma_next = vma->next;
- drm_free(vma, sizeof(*vma), DRM_MEM_VMAS);
- }
- dev->vmalist = NULL;
- }
-
- /* Clear map area and mtrr information */
- if (dev->maplist) {
- for (i = 0; i < dev->map_count; i++) {
- map = dev->maplist[i];
- switch (map->type) {
- case _DRM_REGISTERS:
- case _DRM_FRAME_BUFFER:
-#ifdef CONFIG_MTRR
- if (map->mtrr >= 0) {
- int retcode;
- retcode = mtrr_del(map->mtrr,
- map->offset,
- map->size);
- DRM_DEBUG("mtrr_del = %d\n", retcode);
- }
-#endif
- drm_ioremapfree(map->handle, map->size);
- break;
- case _DRM_SHM:
- drm_free_pages((unsigned long)map->handle,
- drm_order(map->size)
- - PAGE_SHIFT,
- DRM_MEM_SAREA);
- break;
- case _DRM_AGP:
- /* Do nothing here, because this is all
- handled in the AGP/GART driver. */
- break;
- }
- drm_free(map, sizeof(*map), DRM_MEM_MAPS);
- }
- drm_free(dev->maplist,
- dev->map_count * sizeof(*dev->maplist),
- DRM_MEM_MAPS);
- dev->maplist = NULL;
- dev->map_count = 0;
- }
-
- if (dev->lock.hw_lock) {
- dev->lock.hw_lock = NULL; /* SHM removed */
- dev->lock.pid = 0;
- wake_up_interruptible(&dev->lock.lock_queue);
- }
- up(&dev->struct_sem);
-
- return 0;
-}
-
-/* sis_init is called via init_module at module load time, or via
- * linux/init/main.c (this is not currently supported). */
-
-static int sis_init(void)
-{
- int retcode;
- drm_device_t *dev = &sis_device;
-
- DRM_DEBUG("\n");
-
- memset((void *)dev, 0, sizeof(*dev));
- dev->count_lock = SPIN_LOCK_UNLOCKED;
- sema_init(&dev->struct_sem, 1);
-
-#ifdef MODULE
- drm_parse_options(sis);
-#endif
-
- if ((retcode = misc_register(&sis_misc))) {
- DRM_ERROR("Cannot register \"%s\"\n", SIS_NAME);
- return retcode;
- }
- dev->device = MKDEV(MISC_MAJOR, sis_misc.minor);
- dev->name = SIS_NAME;
-
- drm_mem_init();
- drm_proc_init(dev);
-#if defined(CONFIG_AGP) || defined(CONFIG_AGP_MODULE)
- dev->agp = drm_agp_init();
-#endif
- if((retcode = drm_ctxbitmap_init(dev))) {
- DRM_ERROR("Cannot allocate memory for context bitmap.\n");
- drm_proc_cleanup();
- misc_deregister(&sis_misc);
- sis_takedown(dev);
- return retcode;
- }
-
- DRM_INFO("Initialized %s %d.%d.%d %s on minor %d\n",
- SIS_NAME,
- SIS_MAJOR,
- SIS_MINOR,
- SIS_PATCHLEVEL,
- SIS_DATE,
- sis_misc.minor);
-
- return 0;
-}
-
-/* sis_cleanup is called via cleanup_module at module unload time. */
-
-static void sis_cleanup(void)
-{
- drm_device_t *dev = &sis_device;
-
- DRM_DEBUG("\n");
-
- drm_proc_cleanup();
- if (misc_deregister(&sis_misc)) {
- DRM_ERROR("Cannot unload module\n");
- } else {
- DRM_INFO("Module unloaded\n");
- }
- drm_ctxbitmap_cleanup(dev);
- sis_takedown(dev);
-#if defined(CONFIG_AGP) || defined(CONFIG_AGP_MODULE)
- if (dev->agp) {
- drm_agp_uninit();
- drm_free(dev->agp, sizeof(*dev->agp), DRM_MEM_AGPLISTS);
- dev->agp = NULL;
- }
-#endif
-}
-
-module_init(sis_init);
-module_exit(sis_cleanup);
-
-
-int sis_version(struct inode *inode, struct file *filp, unsigned int cmd,
- unsigned long arg)
-{
- drm_version_t version;
- int len;
-
- if (copy_from_user(&version, (drm_version_t *)arg, sizeof(version)))
- return -EFAULT;
-
-#define DRM_COPY(name,value) \
- len = strlen(value); \
- if (len > name##_len) len = name##_len; \
- name##_len = strlen(value); \
- if (len && name) { \
- if (copy_to_user(name, value, len)) \
- return -EFAULT; \
- }
-
- version.version_major = SIS_MAJOR;
- version.version_minor = SIS_MINOR;
- version.version_patchlevel = SIS_PATCHLEVEL;
-
- DRM_COPY(version.name, SIS_NAME);
- DRM_COPY(version.date, SIS_DATE);
- DRM_COPY(version.desc, SIS_DESC);
-
- if (copy_to_user((drm_version_t *)arg, &version, sizeof(version)))
- return -EFAULT;
- return 0;
-}
-
-int sis_open(struct inode *inode, struct file *filp)
-{
- drm_device_t *dev = &sis_device;
- int retcode = 0;
-
- DRM_DEBUG("open_count = %d\n", dev->open_count);
- if (!(retcode = drm_open_helper(inode, filp, dev))) {
-#if LINUX_VERSION_CODE < 0x020333
- MOD_INC_USE_COUNT; /* Needed before Linux 2.3.51 */
-#endif
- atomic_inc(&dev->total_open);
- spin_lock(&dev->count_lock);
- if (!dev->open_count++) {
- spin_unlock(&dev->count_lock);
- return sis_setup(dev);
- }
- spin_unlock(&dev->count_lock);
- }
- return retcode;
-}
-
-int sis_release(struct inode *inode, struct file *filp)
-{
- drm_file_t *priv = filp->private_data;
- drm_device_t *dev;
- int retcode = 0;
-
- lock_kernel();
- dev = priv->dev;
-
- DRM_DEBUG("open_count = %d\n", dev->open_count);
- if (!(retcode = drm_release(inode, filp))) {
-#if LINUX_VERSION_CODE < 0x020333
- MOD_DEC_USE_COUNT; /* Needed before Linux 2.3.51 */
-#endif
- atomic_inc(&dev->total_close);
- spin_lock(&dev->count_lock);
- if (!--dev->open_count) {
- if (atomic_read(&dev->ioctl_count) || dev->blocked) {
- DRM_ERROR("Device busy: %d %d\n",
- atomic_read(&dev->ioctl_count),
- dev->blocked);
- spin_unlock(&dev->count_lock);
- unlock_kernel();
- return -EBUSY;
- }
- spin_unlock(&dev->count_lock);
- unlock_kernel();
- return sis_takedown(dev);
- }
- spin_unlock(&dev->count_lock);
- }
-
- unlock_kernel();
- return retcode;
-}
-
-/* sis_ioctl is called whenever a process performs an ioctl on /dev/drm. */
-
-int sis_ioctl(struct inode *inode, struct file *filp, unsigned int cmd,
- unsigned long arg)
-{
- int nr = DRM_IOCTL_NR(cmd);
- drm_file_t *priv = filp->private_data;
- drm_device_t *dev = priv->dev;
- int retcode = 0;
- drm_ioctl_desc_t *ioctl;
- drm_ioctl_t *func;
-
- atomic_inc(&dev->ioctl_count);
- atomic_inc(&dev->total_ioctl);
- ++priv->ioctl_count;
-
- DRM_DEBUG("pid = %d, cmd = 0x%02x, nr = 0x%02x, dev 0x%x, auth = %d\n",
- current->pid, cmd, nr, dev->device, priv->authenticated);
-
- if (nr >= SIS_IOCTL_COUNT) {
- retcode = -EINVAL;
- } else {
- ioctl = &sis_ioctls[nr];
- func = ioctl->func;
-
- if (!func) {
- DRM_DEBUG("no function\n");
- retcode = -EINVAL;
- } else if ((ioctl->root_only && !capable(CAP_SYS_ADMIN))
- || (ioctl->auth_needed && !priv->authenticated)) {
- retcode = -EACCES;
- } else {
- retcode = (func)(inode, filp, cmd, arg);
- }
- }
-
- atomic_dec(&dev->ioctl_count);
- return retcode;
-}
-
-int sis_lock(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;
- DECLARE_WAITQUEUE(entry, current);
- int ret = 0;
- drm_lock_t lock;
-#if DRM_DMA_HISTOGRAM
- cycles_t start;
-
- dev->lck_start = start = get_cycles();
-#endif
-
- if (copy_from_user(&lock, (drm_lock_t *)arg, sizeof(lock)))
- return -EFAULT;
-
- if (lock.context == DRM_KERNEL_CONTEXT) {
- DRM_ERROR("Process %d using kernel context %d\n",
- current->pid, lock.context);
- return -EINVAL;
- }
-
- DRM_DEBUG("%d (pid %d) requests lock (0x%08x), flags = 0x%08x\n",
- lock.context, current->pid, dev->lock.hw_lock->lock,
- lock.flags);
-
-#if 0
- /* dev->queue_count == 0 right now for
- sis. FIXME? */
- if (lock.context < 0 || lock.context >= dev->queue_count)
- return -EINVAL;
-#endif
-
- if (!ret) {
-#if 0
- if (_DRM_LOCKING_CONTEXT(dev->lock.hw_lock->lock)
- != lock.context) {
- long j = jiffies - dev->lock.lock_time;
-
- if (lock.context == sis_res_ctx.handle &&
- j >= 0 && j < DRM_LOCK_SLICE) {
- /* Can't take lock if we just had it and
- there is contention. */
- DRM_DEBUG("%d (pid %d) delayed j=%d dev=%d jiffies=%d\n",
- lock.context, current->pid, j,
- dev->lock.lock_time, jiffies);
- current->state = TASK_INTERRUPTIBLE;
- current->policy |= SCHED_YIELD;
- schedule_timeout(DRM_LOCK_SLICE-j);
- DRM_DEBUG("jiffies=%d\n", jiffies);
- }
- }
-#endif
- add_wait_queue(&dev->lock.lock_queue, &entry);
- for (;;) {
- current->state = TASK_INTERRUPTIBLE;
- if (!dev->lock.hw_lock) {
- /* Device has been unregistered */
- ret = -EINTR;
- break;
- }
- if (drm_lock_take(&dev->lock.hw_lock->lock,
- lock.context)) {
- dev->lock.pid = current->pid;
- dev->lock.lock_time = jiffies;
- atomic_inc(&dev->total_locks);
- break; /* Got lock */
- }
-
- /* Contention */
- atomic_inc(&dev->total_sleeps);
-#if 1
- current->policy |= SCHED_YIELD;
-#endif
- schedule();
- if (signal_pending(current)) {
- ret = -ERESTARTSYS;
- break;
- }
- }
- current->state = TASK_RUNNING;
- remove_wait_queue(&dev->lock.lock_queue, &entry);
- }
-
-#if 0
- if (!ret && dev->last_context != lock.context &&
- lock.context != sis_res_ctx.handle &&
- dev->last_context != sis_res_ctx.handle) {
- add_wait_queue(&dev->context_wait, &entry);
- current->state = TASK_INTERRUPTIBLE;
- /* PRE: dev->last_context != lock.context */
- sis_context_switch(dev, dev->last_context, lock.context);
- /* POST: we will wait for the context
- switch and will dispatch on a later call
- when dev->last_context == lock.context
- NOTE WE HOLD THE LOCK THROUGHOUT THIS
- TIME! */
- current->policy |= SCHED_YIELD;
- schedule();
- current->state = TASK_RUNNING;
- remove_wait_queue(&dev->context_wait, &entry);
- if (signal_pending(current)) {
- ret = -EINTR;
- } else if (dev->last_context != lock.context) {
- DRM_ERROR("Context mismatch: %d %d\n",
- dev->last_context, lock.context);
- }
- }
-#endif
-
- if (!ret) {
- sigemptyset(&dev->sigmask);
- sigaddset(&dev->sigmask, SIGSTOP);
- sigaddset(&dev->sigmask, SIGTSTP);
- sigaddset(&dev->sigmask, SIGTTIN);
- sigaddset(&dev->sigmask, SIGTTOU);
- dev->sigdata.context = lock.context;
- dev->sigdata.lock = dev->lock.hw_lock;
- block_all_signals(drm_notifier, &dev->sigdata, &dev->sigmask);
-
- if (lock.flags & _DRM_LOCK_READY) {
- /* Wait for space in DMA/FIFO */
- }
- if (lock.flags & _DRM_LOCK_QUIESCENT) {
- /* Make hardware quiescent */
-#if 0
- sis_quiescent(dev);
-#endif
- }
- }
-
- DRM_DEBUG("%d %s\n", lock.context, ret ? "interrupted" : "has lock");
-
-#if DRM_DMA_HISTOGRAM
- atomic_inc(&dev->histo.lacq[drm_histogram_slot(get_cycles() - start)]);
-#endif
-
- return ret;
-}
-
-
-int sis_unlock(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_lock_t lock;
-
- if (copy_from_user(&lock, (drm_lock_t *)arg, sizeof(lock)))
- return -EFAULT;
-
- if (lock.context == DRM_KERNEL_CONTEXT) {
- DRM_ERROR("Process %d using kernel context %d\n",
- current->pid, lock.context);
- return -EINVAL;
- }
-
- DRM_DEBUG("%d frees lock (%d holds)\n",
- lock.context,
- _DRM_LOCKING_CONTEXT(dev->lock.hw_lock->lock));
- atomic_inc(&dev->total_unlocks);
- if (_DRM_LOCK_IS_CONT(dev->lock.hw_lock->lock))
- atomic_inc(&dev->total_contends);
- drm_lock_transfer(dev, &dev->lock.hw_lock->lock, DRM_KERNEL_CONTEXT);
- /* FIXME: Try to send data to card here */
- if (!dev->context_flag) {
- if (drm_lock_free(dev, &dev->lock.hw_lock->lock,
- DRM_KERNEL_CONTEXT)) {
- DRM_ERROR("\n");
- }
- }
-
- unblock_all_signals();
- return 0;
-}
+#define DRIVER_AUTHOR "SIS"
+#define DRIVER_NAME "sis"
+#define DRIVER_DESC "SIS 300/630/540"
+#define DRIVER_DATE "20010503"
+#define DRIVER_MAJOR 1
+#define DRIVER_MINOR 0
+#define DRIVER_PATCHLEVEL 0
+
+#define DRIVER_IOCTLS \
+ [DRM_IOCTL_NR(SIS_IOCTL_FB_ALLOC)] = { sis_fb_alloc, 1, 1 }, \
+ [DRM_IOCTL_NR(SIS_IOCTL_FB_FREE)] = { sis_fb_free, 1, 1 }, \
+ /* AGP Memory Management */ \
+ [DRM_IOCTL_NR(SIS_IOCTL_AGP_INIT)] = { sisp_agp_init, 1, 1 }, \
+ [DRM_IOCTL_NR(SIS_IOCTL_AGP_ALLOC)] = { sisp_agp_alloc, 1, 1 }, \
+ [DRM_IOCTL_NR(SIS_IOCTL_AGP_FREE)] = { sisp_agp_free, 1, 1 }
+#if 0 /* these don't appear to be defined */
+ /* SIS Stereo */
+ [DRM_IOCTL_NR(DRM_IOCTL_CONTROL)] = { sis_control, 1, 1 },
+ [DRM_IOCTL_NR(SIS_IOCTL_FLIP)] = { sis_flip, 1, 1 },
+ [DRM_IOCTL_NR(SIS_IOCTL_FLIP_INIT)] = { sis_flip_init, 1, 1 },
+ [DRM_IOCTL_NR(SIS_IOCTL_FLIP_FINAL)] = { sis_flip_final, 1, 1 }
+#endif
+
+#define __HAVE_COUNTERS 5
+
+#include "drm_auth.h"
+#include "drm_agpsupport.h"
+#include "drm_bufs.h"
+#include "drm_context.h"
+#include "drm_dma.h"
+#include "drm_drawable.h"
+#include "drm_drv.h"
+#include "drm_fops.h"
+#include "drm_init.h"
+#include "drm_ioctl.h"
+#include "drm_lists.h"
+#include "drm_lock.h"
+#include "drm_memory.h"
+#include "drm_proc.h"
+#include "drm_vm.h"
+#include "drm_stub.h"
diff --git a/linux-core/tdfx_drv.c b/linux-core/tdfx_drv.c
index 6c1b7b52d..94e5d41c5 100644
--- a/linux-core/tdfx_drv.c
+++ b/linux-core/tdfx_drv.c
@@ -60,6 +60,26 @@ static u_int DRM(idlist)[] = {
#include "drm_dma.h"
#include "drm_drawable.h"
#include "drm_drv.h"
+
+#ifndef MODULE
+/* DRM(options) is called by the kernel to parse command-line options
+ * passed via the boot-loader (e.g., LILO). It calls the insmod option
+ * routine, drm_parse_drm.
+ */
+
+/* JH- We have to hand expand the string ourselves because of the cpp. If
+ * anyone can think of a way that we can fit into the __setup macro without
+ * changing it, then please send the solution my way.
+ */
+static int __init tdfx_options( char *str )
+{
+ DRM(parse_options)( str );
+ return 1;
+}
+
+__setup( DRIVER_NAME "=", tdfx_options );
+#endif
+
#include "drm_fops.h"
#include "drm_init.h"
#include "drm_ioctl.h"