From 679531e1669085115bac5f6fc982d54a4a9608e8 Mon Sep 17 00:00:00 2001 From: Rik Faith Date: Wed, 15 Nov 2000 15:47:51 +0000 Subject: [PATCH] Sync with Linux 2.4.0-test11-pre5 Provide backward compatibility tested against 2.2.18pre21 As usual, since all 2.4.0-test* kernels set LINUX_VERSION_CODE to the same value, if you are running a 2.4.0-test kernel, you MUST be running 2.4.0-test11-pre4 or later (although anything after 2.4.0-test11-pre1 should work fine -- I tested with pre4/pre5). I expect 2.2.x support to continue to work for all recent kernels, but I tested with 2.2.18pre21 -- we use the old intermodule symbol communication for 2.2.x kernels, so they should all continue to work. --- linux-core/drmP.h | 27 ++------- linux-core/i810_drv.c | 7 +-- linux-core/mga_drv.c | 7 +-- linux-core/r128_drv.c | 7 +-- linux-core/sis_drv.c | 23 ++++---- linux-core/tdfx_drv.c | 6 +- linux/agpsupport-pre24.h | 115 +++++++++++++++++++++++++++++++++++++ linux/agpsupport.c | 120 ++++++++++++++++----------------------- linux/compat-pre24.h | 4 ++ linux/drmP.h | 27 ++------- linux/gamma_drv.c | 4 +- linux/i810_drv.c | 7 +-- linux/memory.c | 64 +++++++++------------ linux/mga_bufs.c | 1 - linux/mga_drv.c | 7 +-- linux/r128_drm.h | 6 +- linux/r128_drv.c | 7 +-- linux/r128_drv.h | 2 +- linux/sis_context.c | 36 +++++++----- linux/sis_drv.c | 23 ++++---- linux/sis_mm.c | 19 ++++--- linux/tdfx_drv.c | 6 +- 22 files changed, 291 insertions(+), 234 deletions(-) create mode 100644 linux/agpsupport-pre24.h diff --git a/linux-core/drmP.h b/linux-core/drmP.h index 46e08e05..affeae70 100644 --- a/linux-core/drmP.h +++ b/linux-core/drmP.h @@ -59,15 +59,6 @@ #include #include #include - -#ifndef copy_to_user_ret -#define copy_to_user_ret(to,from,n,retval) ({ if (copy_to_user(to,from,n)) return retval; }) -#endif - -#ifndef copy_from_user_ret -#define copy_from_user_ret(to,from,n,retval) ({ if (copy_from_user(to,from,n)) return retval; }) -#endif - #ifdef CONFIG_MTRR #include #endif @@ -519,19 +510,6 @@ typedef struct drm_agp_head { unsigned long base; int agp_mtrr; } drm_agp_head_t; - -typedef struct { - void (*free_memory)(agp_memory *); - agp_memory *(*allocate_memory)(size_t, u32); - int (*bind_memory)(agp_memory *, off_t); - int (*unbind_memory)(agp_memory *); - void (*enable)(u32); - int (*acquire)(void); - void (*release)(void); - void (*copy_info)(agp_kern_info *); -} drm_agp_func_t; - -extern drm_agp_func_t drm_agp; #endif typedef struct drm_sigdata { @@ -833,6 +811,7 @@ extern drm_agp_head_t *drm_agp_init(void); extern void drm_agp_uninit(void); extern int drm_agp_acquire(struct inode *inode, struct file *filp, unsigned int cmd, unsigned long arg); +extern void _drm_agp_release(void); extern int drm_agp_release(struct inode *inode, struct file *filp, unsigned int cmd, unsigned long arg); extern int drm_agp_enable(struct inode *inode, struct file *filp, @@ -847,6 +826,10 @@ extern int drm_agp_unbind(struct inode *inode, struct file *filp, unsigned int cmd, unsigned long arg); extern int drm_agp_bind(struct inode *inode, struct file *filp, unsigned int cmd, unsigned long arg); +extern agp_memory *drm_agp_allocate_memory(size_t pages, u32 type); +extern int drm_agp_free_memory(agp_memory *handle); +extern int drm_agp_bind_memory(agp_memory *handle, off_t start); +extern int drm_agp_unbind_memory(agp_memory *handle); #endif #endif #endif diff --git a/linux-core/i810_drv.c b/linux-core/i810_drv.c index ed880c41..7152eac3 100644 --- a/linux-core/i810_drv.c +++ b/linux-core/i810_drv.c @@ -255,8 +255,7 @@ static int i810_takedown(drm_device_t *dev) } dev->agp->memory = NULL; - if (dev->agp->acquired && drm_agp.release) - (*drm_agp.release)(); + if (dev->agp->acquired) _drm_agp_release(); dev->agp->acquired = 0; dev->agp->enabled = 0; @@ -338,7 +337,7 @@ static int i810_takedown(drm_device_t *dev) /* i810_init is called via init_module at module load time, or via * linux/init/main.c (this is not currently supported). */ -static int i810_init(void) +static int __init i810_init(void) { int retcode; drm_device_t *dev = &i810_device; @@ -397,7 +396,7 @@ static int i810_init(void) /* i810_cleanup is called via cleanup_module at module unload time. */ -static void i810_cleanup(void) +static void __exit i810_cleanup(void) { drm_device_t *dev = &i810_device; diff --git a/linux-core/mga_drv.c b/linux-core/mga_drv.c index 4aaac625..883eb75c 100644 --- a/linux-core/mga_drv.c +++ b/linux-core/mga_drv.c @@ -255,8 +255,7 @@ static int mga_takedown(drm_device_t *dev) } dev->agp->memory = NULL; - if (dev->agp->acquired && drm_agp.release) - (*drm_agp.release)(); + if (dev->agp->acquired) _drm_agp_release(); dev->agp->acquired = 0; dev->agp->enabled = 0; @@ -338,7 +337,7 @@ static int mga_takedown(drm_device_t *dev) /* mga_init is called via init_module at module load time, or via * linux/init/main.c (this is not currently supported). */ -static int mga_init(void) +static int __init mga_init(void) { int retcode; drm_device_t *dev = &mga_device; @@ -398,7 +397,7 @@ static int mga_init(void) /* mga_cleanup is called via cleanup_module at module unload time. */ -static void mga_cleanup(void) +static void __exit mga_cleanup(void) { drm_device_t *dev = &mga_device; diff --git a/linux-core/r128_drv.c b/linux-core/r128_drv.c index 7ae49801..969ada93 100644 --- a/linux-core/r128_drv.c +++ b/linux-core/r128_drv.c @@ -252,8 +252,7 @@ static int r128_takedown(drm_device_t *dev) } dev->agp->memory = NULL; - if (dev->agp->acquired && drm_agp.release) - (*drm_agp.release)(); + if (dev->agp->acquired) _drm_agp_release(); dev->agp->acquired = 0; dev->agp->enabled = 0; @@ -323,7 +322,7 @@ static int r128_takedown(drm_device_t *dev) /* r128_init is called via init_module at module load time, or via * linux/init/main.c (this is not currently supported). */ -static int r128_init(void) +static int __init r128_init(void) { int retcode; drm_device_t *dev = &r128_device; @@ -387,7 +386,7 @@ static int r128_init(void) /* r128_cleanup is called via cleanup_module at module unload time. */ -static void r128_cleanup(void) +static void __exit r128_cleanup(void) { drm_device_t *dev = &r128_device; diff --git a/linux-core/sis_drv.c b/linux-core/sis_drv.c index 2f98e322..92ec32dd 100644 --- a/linux-core/sis_drv.c +++ b/linux-core/sis_drv.c @@ -250,7 +250,7 @@ static int sis_takedown(drm_device_t *dev) drm_free(temp, sizeof(*temp), DRM_MEM_AGPLISTS); temp = temp_next; } - if (dev->agp->acquired) (*drm_agp.release)(); + if (dev->agp->acquired) _drm_agp_release(); } #endif /* Clear vma list (only built for debugging) */ @@ -394,17 +394,16 @@ int sis_version(struct inode *inode, struct file *filp, unsigned int cmd, drm_version_t version; int len; - copy_from_user_ret(&version, - (drm_version_t *)arg, - sizeof(version), - -EFAULT); + 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) { \ - copy_to_user_ret(name, value, len, -EFAULT); \ + if (copy_to_user(name, value, len)) \ + return -EFAULT; \ } version.version_major = SIS_MAJOR; @@ -415,10 +414,8 @@ int sis_version(struct inode *inode, struct file *filp, unsigned int cmd, DRM_COPY(version.date, SIS_DATE); DRM_COPY(version.desc, SIS_DESC); - copy_to_user_ret((drm_version_t *)arg, - &version, - sizeof(version), - -EFAULT); + if (copy_to_user((drm_version_t *)arg, &version, sizeof(version))) + return -EFAULT; return 0; } @@ -533,7 +530,8 @@ int sis_lock(struct inode *inode, struct file *filp, unsigned int cmd, dev->lck_start = start = get_cycles(); #endif - copy_from_user_ret(&lock, (drm_lock_t *)arg, sizeof(lock), -EFAULT); + 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", @@ -667,7 +665,8 @@ int sis_unlock(struct inode *inode, struct file *filp, unsigned int cmd, drm_device_t *dev = priv->dev; drm_lock_t lock; - copy_from_user_ret(&lock, (drm_lock_t *)arg, sizeof(lock), -EFAULT); + 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", diff --git a/linux-core/tdfx_drv.c b/linux-core/tdfx_drv.c index 5f2c804a..7d79a013 100644 --- a/linux-core/tdfx_drv.c +++ b/linux-core/tdfx_drv.c @@ -235,7 +235,7 @@ static int tdfx_takedown(drm_device_t *dev) drm_free(temp, sizeof(*temp), DRM_MEM_AGPLISTS); temp = temp_next; } - if (dev->agp->acquired) (*drm_agp.release)(); + if (dev->agp->acquired) _drm_agp_release(); } #endif /* Clear vma list (only built for debugging) */ @@ -298,7 +298,7 @@ static int tdfx_takedown(drm_device_t *dev) /* tdfx_init is called via init_module at module load time, or via * linux/init/main.c (this is not currently supported). */ -static int tdfx_init(void) +static int __init tdfx_init(void) { int retcode; drm_device_t *dev = &tdfx_device; @@ -346,7 +346,7 @@ static int tdfx_init(void) /* tdfx_cleanup is called via cleanup_module at module unload time. */ -static void tdfx_cleanup(void) +static void __exit tdfx_cleanup(void) { drm_device_t *dev = &tdfx_device; diff --git a/linux/agpsupport-pre24.h b/linux/agpsupport-pre24.h new file mode 100644 index 00000000..abcf9f51 --- /dev/null +++ b/linux/agpsupport-pre24.h @@ -0,0 +1,115 @@ +/* agpsupport-pre24.h -- Support for pre-2.4.0 kernels -*- linux-c -*- + * Created: Mon Nov 13 10:54:15 2000 by faith@valinux.com + * + * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * Author: Rickard E. (Rik) Faith + * + */ + +#ifndef _AGPSUPPORT_PRE24_H_ +#define _AGPSUPPORT_PRE24_H_ +typedef struct { + void (*free_memory)(agp_memory *); + agp_memory *(*allocate_memory)(size_t, u32); + int (*bind_memory)(agp_memory *, off_t); + int (*unbind_memory)(agp_memory *); + void (*enable)(u32); + int (*acquire)(void); + void (*release)(void); + void (*copy_info)(agp_kern_info *); +} drm_agp_t; + +static drm_agp_t drm_agp_struct = { + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL +}; + +/* The C standard says that 'void *' is not guaranteed to hold a function + pointer, so we use this union to define a generic pointer that is + guaranteed to hold any of the function pointers we care about. */ +typedef union { + void (*free_memory)(agp_memory *); + agp_memory *(*allocate_memory)(size_t, u32); + int (*bind_memory)(agp_memory *, off_t); + int (*unbind_memory)(agp_memory *); + void (*enable)(u32); + int (*acquire)(void); + void (*release)(void); + void (*copy_info)(agp_kern_info *); + unsigned long address; +} drm_agp_func_u; + +typedef struct drm_agp_fill { + const char *name; + drm_agp_func_u *f; +} drm_agp_fill_t; + +static drm_agp_fill_t drm_agp_fill[] = { + { __MODULE_STRING(agp_free_memory), + (drm_agp_func_u *)&drm_agp_struct.free_memory }, + { __MODULE_STRING(agp_allocate_memory), + (drm_agp_func_u *)&drm_agp_struct.allocate_memory }, + { __MODULE_STRING(agp_bind_memory), + (drm_agp_func_u *)&drm_agp_struct.bind_memory }, + { __MODULE_STRING(agp_unbind_memory), + (drm_agp_func_u *)&drm_agp_struct.unbind_memory }, + { __MODULE_STRING(agp_enable), + (drm_agp_func_u *)&drm_agp_struct.enable }, + { __MODULE_STRING(agp_backend_acquire), + (drm_agp_func_u *)&drm_agp_struct.acquire }, + { __MODULE_STRING(agp_backend_release), + (drm_agp_func_u *)&drm_agp_struct.release }, + { __MODULE_STRING(agp_copy_info), + (drm_agp_func_u *)&drm_agp_struct.copy_info }, + { NULL, NULL } +}; + +#define DRM_AGP_GET _drm_agp_get() +#define DRM_AGP_PUT _drm_agp_put() + +static drm_agp_t *_drm_agp_get(void) +{ + drm_agp_fill_t *fill; + int agp_available = 1; + + for (fill = &drm_agp_fill[0]; fill->name; fill++) { + char *n = (char *)fill->name; + *fill->f = (drm_agp_func_u)get_module_symbol(NULL, n); + DRM_DEBUG("%s resolves to 0x%08lx\n", n, (*fill->f).address); + if (!(*fill->f).address) agp_available = 0; + } + return &drm_agp_struct; +} + +static void _drm_agp_put(void) +{ + drm_agp_fill_t *fill; + + for (fill = &drm_agp_fill[0]; fill->name; fill++) { +#if LINUX_VERSION_CODE >= 0x020400 + if ((*fill->f).address) put_module_symbol((*fill->f).address); +#endif + (*fill->f).address = 0; + } +} +#endif diff --git a/linux/agpsupport.c b/linux/agpsupport.c index 24fd59cd..c996df8f 100644 --- a/linux/agpsupport.c +++ b/linux/agpsupport.c @@ -31,48 +31,14 @@ #define __NO_VERSION__ #include "drmP.h" #include +#if LINUX_VERSION_CODE < 0x020400 +#include "agpsupport-pre24.h" +#else +#define DRM_AGP_GET (drm_agp_t *)inter_module_get("drm_agp") +#define DRM_AGP_PUT inter_module_put("drm_agp") +#endif -drm_agp_func_t drm_agp = { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }; - -/* The C standard says that 'void *' is not guaranteed to hold a function - pointer, so we use this union to define a generic pointer that is - guaranteed to hold any of the function pointers we care about. */ -typedef union { - void (*free_memory)(agp_memory *); - agp_memory *(*allocate_memory)(size_t, u32); - int (*bind_memory)(agp_memory *, off_t); - int (*unbind_memory)(agp_memory *); - void (*enable)(u32); - int (*acquire)(void); - void (*release)(void); - void (*copy_info)(agp_kern_info *); - unsigned long address; -} drm_agp_func_u; - -typedef struct drm_agp_fill { - const char *name; - drm_agp_func_u *f; -} drm_agp_fill_t; - -static drm_agp_fill_t drm_agp_fill[] = { - { __MODULE_STRING(agp_free_memory), - (drm_agp_func_u *)&drm_agp.free_memory }, - { __MODULE_STRING(agp_allocate_memory), - (drm_agp_func_u *)&drm_agp.allocate_memory }, - { __MODULE_STRING(agp_bind_memory), - (drm_agp_func_u *)&drm_agp.bind_memory }, - { __MODULE_STRING(agp_unbind_memory), - (drm_agp_func_u *)&drm_agp.unbind_memory }, - { __MODULE_STRING(agp_enable), - (drm_agp_func_u *)&drm_agp.enable }, - { __MODULE_STRING(agp_backend_acquire), - (drm_agp_func_u *)&drm_agp.acquire }, - { __MODULE_STRING(agp_backend_release), - (drm_agp_func_u *)&drm_agp.release }, - { __MODULE_STRING(agp_copy_info), - (drm_agp_func_u *)&drm_agp.copy_info }, - { NULL, NULL } -}; +static const drm_agp_t *drm_agp = NULL; int drm_agp_info(struct inode *inode, struct file *filp, unsigned int cmd, unsigned long arg) @@ -82,7 +48,7 @@ int drm_agp_info(struct inode *inode, struct file *filp, unsigned int cmd, agp_kern_info *kern; drm_agp_info_t info; - if (!dev->agp->acquired || !drm_agp.copy_info) return -EINVAL; + if (!dev->agp->acquired || !drm_agp->copy_info) return -EINVAL; kern = &dev->agp->agp_info; info.agp_version_major = kern->version.major; @@ -107,8 +73,8 @@ int drm_agp_acquire(struct inode *inode, struct file *filp, unsigned int cmd, drm_device_t *dev = priv->dev; int retcode; - if (dev->agp->acquired || !drm_agp.acquire) return -EINVAL; - if ((retcode = (*drm_agp.acquire)())) return retcode; + if (dev->agp->acquired || !drm_agp->acquire) return -EINVAL; + if ((retcode = drm_agp->acquire())) return retcode; dev->agp->acquired = 1; return 0; } @@ -119,13 +85,18 @@ int drm_agp_release(struct inode *inode, struct file *filp, unsigned int cmd, drm_file_t *priv = filp->private_data; drm_device_t *dev = priv->dev; - if (!dev->agp->acquired || !drm_agp.release) return -EINVAL; - (*drm_agp.release)(); + if (!dev->agp->acquired || !drm_agp->release) return -EINVAL; + drm_agp->release(); dev->agp->acquired = 0; return 0; } +void _drm_agp_release(void) +{ + if (drm_agp->release) drm_agp->release(); +} + int drm_agp_enable(struct inode *inode, struct file *filp, unsigned int cmd, unsigned long arg) { @@ -133,13 +104,13 @@ int drm_agp_enable(struct inode *inode, struct file *filp, unsigned int cmd, drm_device_t *dev = priv->dev; drm_agp_mode_t mode; - if (!dev->agp->acquired || !drm_agp.enable) return -EINVAL; + if (!dev->agp->acquired || !drm_agp->enable) return -EINVAL; if (copy_from_user(&mode, (drm_agp_mode_t *)arg, sizeof(mode))) return -EFAULT; dev->agp->mode = mode.mode; - (*drm_agp.enable)(mode.mode); + drm_agp->enable(mode.mode); dev->agp->base = dev->agp->agp_info.aper_base; dev->agp->enabled = 1; return 0; @@ -231,7 +202,7 @@ int drm_agp_bind(struct inode *inode, struct file *filp, unsigned int cmd, int retcode; int page; - if (!dev->agp->acquired || !drm_agp.bind_memory) return -EINVAL; + if (!dev->agp->acquired || !drm_agp->bind_memory) return -EINVAL; if (copy_from_user(&request, (drm_agp_binding_t *)arg, sizeof(request))) return -EFAULT; if (!(entry = drm_agp_lookup_entry(dev, request.handle))) @@ -270,24 +241,14 @@ int drm_agp_free(struct inode *inode, struct file *filp, unsigned int cmd, drm_agp_head_t *drm_agp_init(void) { - drm_agp_fill_t *fill; drm_agp_head_t *head = NULL; - int agp_available = 1; - for (fill = &drm_agp_fill[0]; fill->name; fill++) { - char *n = (char *)fill->name; - *fill->f = (drm_agp_func_u)get_module_symbol(NULL, n); - DRM_DEBUG("%s resolves to 0x%08lx\n", n, (*fill->f).address); - if (!(*fill->f).address) agp_available = 0; - } - - DRM_DEBUG("agp_available = %d\n", agp_available); - - if (agp_available) { + drm_agp = DRM_AGP_GET; + if (drm_agp) { if (!(head = drm_alloc(sizeof(*head), DRM_MEM_AGPLISTS))) return NULL; memset((void *)head, 0, sizeof(*head)); - (*drm_agp.copy_info)(&head->agp_info); + drm_agp->copy_info(&head->agp_info); if (head->agp_info.chipset == NOT_SUPPORTED) { drm_free(head, sizeof(*head), DRM_MEM_AGPLISTS); return NULL; @@ -337,12 +298,31 @@ drm_agp_head_t *drm_agp_init(void) void drm_agp_uninit(void) { - drm_agp_fill_t *fill; - - for (fill = &drm_agp_fill[0]; fill->name; fill++) { -#if LINUX_VERSION_CODE >= 0x020400 - if ((*fill->f).address) put_module_symbol((*fill->f).address); -#endif - (*fill->f).address = 0; - } + DRM_AGP_PUT; + drm_agp = NULL; +} + +agp_memory *drm_agp_allocate_memory(size_t pages, u32 type) +{ + if (!drm_agp->allocate_memory) return NULL; + return drm_agp->allocate_memory(pages, type); +} + +int drm_agp_free_memory(agp_memory *handle) +{ + if (!handle || !drm_agp->free_memory) return 0; + drm_agp->free_memory(handle); + return 1; +} + +int drm_agp_bind_memory(agp_memory *handle, off_t start) +{ + if (!handle || !drm_agp->bind_memory) return -EINVAL; + return drm_agp->bind_memory(handle, start); +} + +int drm_agp_unbind_memory(agp_memory *handle) +{ + if (!handle || !drm_agp->unbind_memory) return -EINVAL; + return drm_agp->unbind_memory(handle); } diff --git a/linux/compat-pre24.h b/linux/compat-pre24.h index 257baca1..77a2bee1 100644 --- a/linux/compat-pre24.h +++ b/linux/compat-pre24.h @@ -38,4 +38,8 @@ #define block_all_signals(a,b,c) #define unblock_all_signals() +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,0) +#define __exit +#endif + #endif diff --git a/linux/drmP.h b/linux/drmP.h index 46e08e05..affeae70 100644 --- a/linux/drmP.h +++ b/linux/drmP.h @@ -59,15 +59,6 @@ #include #include #include - -#ifndef copy_to_user_ret -#define copy_to_user_ret(to,from,n,retval) ({ if (copy_to_user(to,from,n)) return retval; }) -#endif - -#ifndef copy_from_user_ret -#define copy_from_user_ret(to,from,n,retval) ({ if (copy_from_user(to,from,n)) return retval; }) -#endif - #ifdef CONFIG_MTRR #include #endif @@ -519,19 +510,6 @@ typedef struct drm_agp_head { unsigned long base; int agp_mtrr; } drm_agp_head_t; - -typedef struct { - void (*free_memory)(agp_memory *); - agp_memory *(*allocate_memory)(size_t, u32); - int (*bind_memory)(agp_memory *, off_t); - int (*unbind_memory)(agp_memory *); - void (*enable)(u32); - int (*acquire)(void); - void (*release)(void); - void (*copy_info)(agp_kern_info *); -} drm_agp_func_t; - -extern drm_agp_func_t drm_agp; #endif typedef struct drm_sigdata { @@ -833,6 +811,7 @@ extern drm_agp_head_t *drm_agp_init(void); extern void drm_agp_uninit(void); extern int drm_agp_acquire(struct inode *inode, struct file *filp, unsigned int cmd, unsigned long arg); +extern void _drm_agp_release(void); extern int drm_agp_release(struct inode *inode, struct file *filp, unsigned int cmd, unsigned long arg); extern int drm_agp_enable(struct inode *inode, struct file *filp, @@ -847,6 +826,10 @@ extern int drm_agp_unbind(struct inode *inode, struct file *filp, unsigned int cmd, unsigned long arg); extern int drm_agp_bind(struct inode *inode, struct file *filp, unsigned int cmd, unsigned long arg); +extern agp_memory *drm_agp_allocate_memory(size_t pages, u32 type); +extern int drm_agp_free_memory(agp_memory *handle); +extern int drm_agp_bind_memory(agp_memory *handle, off_t start); +extern int drm_agp_unbind_memory(agp_memory *handle); #endif #endif #endif diff --git a/linux/gamma_drv.c b/linux/gamma_drv.c index dba974c2..a17bc1a9 100644 --- a/linux/gamma_drv.c +++ b/linux/gamma_drv.c @@ -339,7 +339,7 @@ int gamma_find_devices(void) /* gamma_init is called via init_module at module load time, or via * linux/init/main.c (this is not currently supported). */ -static int gamma_init(void) +static int __init gamma_init(void) { int retcode; drm_device_t *dev = &gamma_device; @@ -380,7 +380,7 @@ static int gamma_init(void) /* gamma_cleanup is called via cleanup_module at module unload time. */ -static void gamma_cleanup(void) +static void __exit gamma_cleanup(void) { drm_device_t *dev = &gamma_device; diff --git a/linux/i810_drv.c b/linux/i810_drv.c index ed880c41..7152eac3 100644 --- a/linux/i810_drv.c +++ b/linux/i810_drv.c @@ -255,8 +255,7 @@ static int i810_takedown(drm_device_t *dev) } dev->agp->memory = NULL; - if (dev->agp->acquired && drm_agp.release) - (*drm_agp.release)(); + if (dev->agp->acquired) _drm_agp_release(); dev->agp->acquired = 0; dev->agp->enabled = 0; @@ -338,7 +337,7 @@ static int i810_takedown(drm_device_t *dev) /* i810_init is called via init_module at module load time, or via * linux/init/main.c (this is not currently supported). */ -static int i810_init(void) +static int __init i810_init(void) { int retcode; drm_device_t *dev = &i810_device; @@ -397,7 +396,7 @@ static int i810_init(void) /* i810_cleanup is called via cleanup_module at module unload time. */ -static void i810_cleanup(void) +static void __exit i810_cleanup(void) { drm_device_t *dev = &i810_device; diff --git a/linux/memory.c b/linux/memory.c index 34d19b20..261fb34a 100644 --- a/linux/memory.c +++ b/linux/memory.c @@ -352,16 +352,13 @@ agp_memory *drm_alloc_agp(int pages, u32 type) return NULL; } - if (drm_agp.allocate_memory) { - if ((handle = (*drm_agp.allocate_memory)(pages, - type))) { - spin_lock(&drm_mem_lock); - ++drm_mem_stats[DRM_MEM_TOTALAGP].succeed_count; - drm_mem_stats[DRM_MEM_TOTALAGP].bytes_allocated - += pages << PAGE_SHIFT; - spin_unlock(&drm_mem_lock); - return handle; - } + if ((handle = drm_agp_allocate_memory(pages, type))) { + spin_lock(&drm_mem_lock); + ++drm_mem_stats[DRM_MEM_TOTALAGP].succeed_count; + drm_mem_stats[DRM_MEM_TOTALAGP].bytes_allocated + += pages << PAGE_SHIFT; + spin_unlock(&drm_mem_lock); + return handle; } spin_lock(&drm_mem_lock); ++drm_mem_stats[DRM_MEM_TOTALAGP].fail_count; @@ -381,8 +378,7 @@ int drm_free_agp(agp_memory *handle, int pages) return retval;; } - if (drm_agp.free_memory) { - (*drm_agp.free_memory)(handle); + if (drm_agp_free_memory(handle)) { spin_lock(&drm_mem_lock); free_count = ++drm_mem_stats[DRM_MEM_TOTALAGP].free_count; alloc_count = drm_mem_stats[DRM_MEM_TOTALAGP].succeed_count; @@ -403,24 +399,19 @@ int drm_bind_agp(agp_memory *handle, unsigned int start) { int retcode = -EINVAL; - DRM_DEBUG("drm_bind_agp called\n"); if (!handle) { DRM_MEM_ERROR(DRM_MEM_BOUNDAGP, "Attempt to bind NULL AGP handle\n"); return retcode; } - DRM_DEBUG("drm_agp.bind_memory : %p\n", drm_agp.bind_memory); - if (drm_agp.bind_memory) { - if (!(retcode = (*drm_agp.bind_memory)(handle, start))) { - spin_lock(&drm_mem_lock); - ++drm_mem_stats[DRM_MEM_BOUNDAGP].succeed_count; - drm_mem_stats[DRM_MEM_BOUNDAGP].bytes_allocated - += handle->page_count << PAGE_SHIFT; - spin_unlock(&drm_mem_lock); - DRM_DEBUG("drm_agp.bind_memory: retcode %d\n", retcode); - return retcode; - } + if (!(retcode = drm_agp_bind_memory(handle, start))) { + spin_lock(&drm_mem_lock); + ++drm_mem_stats[DRM_MEM_BOUNDAGP].succeed_count; + drm_mem_stats[DRM_MEM_BOUNDAGP].bytes_allocated + += handle->page_count << PAGE_SHIFT; + spin_unlock(&drm_mem_lock); + return retcode; } spin_lock(&drm_mem_lock); ++drm_mem_stats[DRM_MEM_BOUNDAGP].fail_count; @@ -440,20 +431,17 @@ int drm_unbind_agp(agp_memory *handle) return retcode; } - if (drm_agp.unbind_memory) { - int c = handle->page_count; - if ((retcode = (*drm_agp.unbind_memory)(handle))) - return retcode; - spin_lock(&drm_mem_lock); - free_count = ++drm_mem_stats[DRM_MEM_BOUNDAGP].free_count; - alloc_count = drm_mem_stats[DRM_MEM_BOUNDAGP].succeed_count; - drm_mem_stats[DRM_MEM_BOUNDAGP].bytes_freed += c << PAGE_SHIFT; - spin_unlock(&drm_mem_lock); - if (free_count > alloc_count) { - DRM_MEM_ERROR(DRM_MEM_BOUNDAGP, - "Excess frees: %d frees, %d allocs\n", - free_count, alloc_count); - } + if ((retcode = drm_agp_unbind_memory(handle))) return retcode; + spin_lock(&drm_mem_lock); + free_count = ++drm_mem_stats[DRM_MEM_BOUNDAGP].free_count; + alloc_count = drm_mem_stats[DRM_MEM_BOUNDAGP].succeed_count; + drm_mem_stats[DRM_MEM_BOUNDAGP].bytes_freed + += handle->page_count << PAGE_SHIFT; + spin_unlock(&drm_mem_lock); + if (free_count > alloc_count) { + DRM_MEM_ERROR(DRM_MEM_BOUNDAGP, + "Excess frees: %d frees, %d allocs\n", + free_count, alloc_count); } return retcode; } diff --git a/linux/mga_bufs.c b/linux/mga_bufs.c index 00c0ea7f..05d941b4 100644 --- a/linux/mga_bufs.c +++ b/linux/mga_bufs.c @@ -420,7 +420,6 @@ int mga_infobufs(struct inode *inode, struct file *filp, unsigned int cmd, sizeof(dma->bufs[0] .freelist.high_mark))) return -EFAULT; - ++count; } } diff --git a/linux/mga_drv.c b/linux/mga_drv.c index 4aaac625..883eb75c 100644 --- a/linux/mga_drv.c +++ b/linux/mga_drv.c @@ -255,8 +255,7 @@ static int mga_takedown(drm_device_t *dev) } dev->agp->memory = NULL; - if (dev->agp->acquired && drm_agp.release) - (*drm_agp.release)(); + if (dev->agp->acquired) _drm_agp_release(); dev->agp->acquired = 0; dev->agp->enabled = 0; @@ -338,7 +337,7 @@ static int mga_takedown(drm_device_t *dev) /* mga_init is called via init_module at module load time, or via * linux/init/main.c (this is not currently supported). */ -static int mga_init(void) +static int __init mga_init(void) { int retcode; drm_device_t *dev = &mga_device; @@ -398,7 +397,7 @@ static int mga_init(void) /* mga_cleanup is called via cleanup_module at module unload time. */ -static void mga_cleanup(void) +static void __exit mga_cleanup(void) { drm_device_t *dev = &mga_device; diff --git a/linux/r128_drm.h b/linux/r128_drm.h index 8a0cd196..8a4842cf 100644 --- a/linux/r128_drm.h +++ b/linux/r128_drm.h @@ -57,9 +57,9 @@ typedef struct drm_r128_init { } drm_r128_init_t; typedef struct drm_r128_packet { - void *buffer; - int count; - int flags; + unsigned int *buffer; + int count; + int flags; } drm_r128_packet_t; typedef enum drm_r128_prim { diff --git a/linux/r128_drv.c b/linux/r128_drv.c index 7ae49801..969ada93 100644 --- a/linux/r128_drv.c +++ b/linux/r128_drv.c @@ -252,8 +252,7 @@ static int r128_takedown(drm_device_t *dev) } dev->agp->memory = NULL; - if (dev->agp->acquired && drm_agp.release) - (*drm_agp.release)(); + if (dev->agp->acquired) _drm_agp_release(); dev->agp->acquired = 0; dev->agp->enabled = 0; @@ -323,7 +322,7 @@ static int r128_takedown(drm_device_t *dev) /* r128_init is called via init_module at module load time, or via * linux/init/main.c (this is not currently supported). */ -static int r128_init(void) +static int __init r128_init(void) { int retcode; drm_device_t *dev = &r128_device; @@ -387,7 +386,7 @@ static int r128_init(void) /* r128_cleanup is called via cleanup_module at module unload time. */ -static void r128_cleanup(void) +static void __exit r128_cleanup(void) { drm_device_t *dev = &r128_device; diff --git a/linux/r128_drv.h b/linux/r128_drv.h index da2f676d..63b98c72 100644 --- a/linux/r128_drv.h +++ b/linux/r128_drv.h @@ -197,7 +197,7 @@ extern int r128_context_switch_complete(drm_device_t *dev, int new); #define R128_MAX_USEC_TIMEOUT 100000 /* 100 ms */ -#define R128_BASE(reg) ((unsigned long)(dev_priv->mmio->handle)) +#define R128_BASE(reg) ((u32)(dev_priv->mmio->handle)) #define R128_ADDR(reg) (R128_BASE(reg) + reg) #define R128_DEREF(reg) *(__volatile__ int *)R128_ADDR(reg) diff --git a/linux/sis_context.c b/linux/sis_context.c index f2fdf6dd..accd789a 100644 --- a/linux/sis_context.c +++ b/linux/sis_context.c @@ -106,19 +106,19 @@ int sis_resctx(struct inode *inode, struct file *filp, unsigned int cmd, int i; DRM_DEBUG("%d\n", DRM_RESERVED_CONTEXTS); - copy_from_user_ret(&res, (drm_ctx_res_t *)arg, sizeof(res), -EFAULT); + if (copy_from_user(&res, (drm_ctx_res_t *)arg, sizeof(res))) + return -EFAULT; if (res.count >= DRM_RESERVED_CONTEXTS) { memset(&ctx, 0, sizeof(ctx)); for (i = 0; i < DRM_RESERVED_CONTEXTS; i++) { ctx.handle = i; - copy_to_user_ret(&res.contexts[i], - &i, - sizeof(i), - -EFAULT); + if (copy_to_user(&res.contexts[i], &i, sizeof(i))) + return -EFAULT; } } res.count = DRM_RESERVED_CONTEXTS; - copy_to_user_ret((drm_ctx_res_t *)arg, &res, sizeof(res), -EFAULT); + if (copy_to_user((drm_ctx_res_t *)arg, &res, sizeof(res))) + return -EFAULT; return 0; } @@ -130,7 +130,8 @@ int sis_addctx(struct inode *inode, struct file *filp, unsigned int cmd, drm_device_t *dev = priv->dev; drm_ctx_t ctx; - copy_from_user_ret(&ctx, (drm_ctx_t *)arg, sizeof(ctx), -EFAULT); + if (copy_from_user(&ctx, (drm_ctx_t *)arg, sizeof(ctx))) + return -EFAULT; if ((ctx.handle = sis_alloc_queue(dev)) == DRM_KERNEL_CONTEXT) { /* Skip kernel's context and get a new one. */ ctx.handle = sis_alloc_queue(dev); @@ -145,7 +146,8 @@ int sis_addctx(struct inode *inode, struct file *filp, unsigned int cmd, /* new added */ sis_init_context(ctx.handle); - copy_to_user_ret((drm_ctx_t *)arg, &ctx, sizeof(ctx), -EFAULT); + if (copy_to_user((drm_ctx_t *)arg, &ctx, sizeof(ctx))) + return -EFAULT; return 0; } @@ -154,7 +156,8 @@ int sis_modctx(struct inode *inode, struct file *filp, unsigned int cmd, { drm_ctx_t ctx; - copy_from_user_ret(&ctx, (drm_ctx_t*)arg, sizeof(ctx), -EFAULT); + if (copy_from_user(&ctx, (drm_ctx_t*)arg, sizeof(ctx))) + return -EFAULT; if (ctx.flags==_DRM_CONTEXT_PRESERVED) sis_res_ctx.handle=ctx.handle; return 0; @@ -165,10 +168,12 @@ int sis_getctx(struct inode *inode, struct file *filp, unsigned int cmd, { drm_ctx_t ctx; - copy_from_user_ret(&ctx, (drm_ctx_t*)arg, sizeof(ctx), -EFAULT); + if (copy_from_user(&ctx, (drm_ctx_t*)arg, sizeof(ctx))) + return -EFAULT; /* This is 0, because we don't hanlde any context flags */ ctx.flags = 0; - copy_to_user_ret((drm_ctx_t*)arg, &ctx, sizeof(ctx), -EFAULT); + if (copy_to_user((drm_ctx_t*)arg, &ctx, sizeof(ctx))) + return -EFAULT; return 0; } @@ -179,7 +184,8 @@ int sis_switchctx(struct inode *inode, struct file *filp, unsigned int cmd, drm_device_t *dev = priv->dev; drm_ctx_t ctx; - copy_from_user_ret(&ctx, (drm_ctx_t *)arg, sizeof(ctx), -EFAULT); + if (copy_from_user(&ctx, (drm_ctx_t *)arg, sizeof(ctx))) + return -EFAULT; DRM_DEBUG("%d\n", ctx.handle); return sis_context_switch(dev, dev->last_context, ctx.handle); } @@ -191,7 +197,8 @@ int sis_newctx(struct inode *inode, struct file *filp, unsigned int cmd, drm_device_t *dev = priv->dev; drm_ctx_t ctx; - copy_from_user_ret(&ctx, (drm_ctx_t *)arg, sizeof(ctx), -EFAULT); + if (copy_from_user(&ctx, (drm_ctx_t *)arg, sizeof(ctx))) + return -EFAULT; DRM_DEBUG("%d\n", ctx.handle); sis_context_switch_complete(dev, ctx.handle); @@ -205,7 +212,8 @@ int sis_rmctx(struct inode *inode, struct file *filp, unsigned int cmd, drm_device_t *dev = priv->dev; drm_ctx_t ctx; - copy_from_user_ret(&ctx, (drm_ctx_t *)arg, sizeof(ctx), -EFAULT); + if (copy_from_user(&ctx, (drm_ctx_t *)arg, sizeof(ctx))) + return -EFAULT; DRM_DEBUG("%d\n", ctx.handle); drm_ctxbitmap_free(dev, ctx.handle); diff --git a/linux/sis_drv.c b/linux/sis_drv.c index 2f98e322..92ec32dd 100644 --- a/linux/sis_drv.c +++ b/linux/sis_drv.c @@ -250,7 +250,7 @@ static int sis_takedown(drm_device_t *dev) drm_free(temp, sizeof(*temp), DRM_MEM_AGPLISTS); temp = temp_next; } - if (dev->agp->acquired) (*drm_agp.release)(); + if (dev->agp->acquired) _drm_agp_release(); } #endif /* Clear vma list (only built for debugging) */ @@ -394,17 +394,16 @@ int sis_version(struct inode *inode, struct file *filp, unsigned int cmd, drm_version_t version; int len; - copy_from_user_ret(&version, - (drm_version_t *)arg, - sizeof(version), - -EFAULT); + 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) { \ - copy_to_user_ret(name, value, len, -EFAULT); \ + if (copy_to_user(name, value, len)) \ + return -EFAULT; \ } version.version_major = SIS_MAJOR; @@ -415,10 +414,8 @@ int sis_version(struct inode *inode, struct file *filp, unsigned int cmd, DRM_COPY(version.date, SIS_DATE); DRM_COPY(version.desc, SIS_DESC); - copy_to_user_ret((drm_version_t *)arg, - &version, - sizeof(version), - -EFAULT); + if (copy_to_user((drm_version_t *)arg, &version, sizeof(version))) + return -EFAULT; return 0; } @@ -533,7 +530,8 @@ int sis_lock(struct inode *inode, struct file *filp, unsigned int cmd, dev->lck_start = start = get_cycles(); #endif - copy_from_user_ret(&lock, (drm_lock_t *)arg, sizeof(lock), -EFAULT); + 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", @@ -667,7 +665,8 @@ int sis_unlock(struct inode *inode, struct file *filp, unsigned int cmd, drm_device_t *dev = priv->dev; drm_lock_t lock; - copy_from_user_ret(&lock, (drm_lock_t *)arg, sizeof(lock), -EFAULT); + 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", diff --git a/linux/sis_mm.c b/linux/sis_mm.c index 9a8f83ea..4c2b5a6c 100644 --- a/linux/sis_mm.c +++ b/linux/sis_mm.c @@ -78,7 +78,8 @@ int sis_fb_alloc(struct inode *inode, struct file *filp, unsigned int cmd, struct sis_memreq req; int retval = 0; - copy_from_user_ret(&fb, (drm_sis_mem_t *)arg, sizeof(fb), -EFAULT); + if (copy_from_user(&fb, (drm_sis_mem_t *)arg, sizeof(fb))) + return -EFAULT; req.size = fb.size; sis_malloc(&req); @@ -98,7 +99,7 @@ int sis_fb_alloc(struct inode *inode, struct file *filp, unsigned int cmd, fb.free = 0; } - copy_to_user_ret((drm_sis_mem_t *)arg, &fb, sizeof(fb), -EFAULT); + if (copy_to_user((drm_sis_mem_t *)arg, &fb, sizeof(fb))) return -EFAULT; DRM_DEBUG("alloc fb, size = %d, offset = %ld\n", fb.size, req.offset); @@ -111,7 +112,8 @@ int sis_fb_free(struct inode *inode, struct file *filp, unsigned int cmd, drm_sis_mem_t fb; int retval = 0; - copy_from_user_ret(&fb, (drm_sis_mem_t *)arg, sizeof(fb), -EFAULT); + if (copy_from_user(&fb, (drm_sis_mem_t *)arg, sizeof(fb))) + return -EFAULT; if(!fb.free){ return -1; @@ -152,7 +154,8 @@ int sis_agp_init(struct inode *inode, struct file *filp, unsigned int cmd, { drm_sis_agp_t agp; - copy_from_user_ret(&agp, (drm_sis_agp_t *)arg, sizeof(agp), -EFAULT); + if (copy_from_user(&agp, (drm_sis_agp_t *)arg, sizeof(agp))) + return -EFAULT; AgpHeap = mmInit(agp.offset, agp.size); @@ -171,7 +174,8 @@ int sis_agp_alloc(struct inode *inode, struct file *filp, unsigned int cmd, if(!AgpHeap) return -1; - copy_from_user_ret(&agp, (drm_sis_mem_t *)arg, sizeof(agp), -EFAULT); + if (copy_from_user(&agp, (drm_sis_mem_t *)arg, sizeof(agp))) + return -EFAULT; block = mmAllocMem(AgpHeap, agp.size, 0, 0); if(block){ @@ -190,7 +194,7 @@ int sis_agp_alloc(struct inode *inode, struct file *filp, unsigned int cmd, agp.free = 0; } - copy_to_user_ret((drm_sis_mem_t *)arg, &agp, sizeof(agp), -EFAULT); + if (copy_to_user((drm_sis_mem_t *)arg, &agp, sizeof(agp))) return -EFAULT; DRM_DEBUG("alloc agp, size = %d, offset = %d\n", agp.size, agp.offset); @@ -206,7 +210,8 @@ int sis_agp_free(struct inode *inode, struct file *filp, unsigned int cmd, if(!AgpHeap) return -1; - copy_from_user_ret(&agp, (drm_sis_mem_t *)arg, sizeof(agp), -EFAULT); + if (copy_from_user(&agp, (drm_sis_mem_t *)arg, sizeof(agp))) + return -EFAULT; if(!agp.free){ return -1; diff --git a/linux/tdfx_drv.c b/linux/tdfx_drv.c index 5f2c804a..7d79a013 100644 --- a/linux/tdfx_drv.c +++ b/linux/tdfx_drv.c @@ -235,7 +235,7 @@ static int tdfx_takedown(drm_device_t *dev) drm_free(temp, sizeof(*temp), DRM_MEM_AGPLISTS); temp = temp_next; } - if (dev->agp->acquired) (*drm_agp.release)(); + if (dev->agp->acquired) _drm_agp_release(); } #endif /* Clear vma list (only built for debugging) */ @@ -298,7 +298,7 @@ static int tdfx_takedown(drm_device_t *dev) /* tdfx_init is called via init_module at module load time, or via * linux/init/main.c (this is not currently supported). */ -static int tdfx_init(void) +static int __init tdfx_init(void) { int retcode; drm_device_t *dev = &tdfx_device; @@ -346,7 +346,7 @@ static int tdfx_init(void) /* tdfx_cleanup is called via cleanup_module at module unload time. */ -static void tdfx_cleanup(void) +static void __exit tdfx_cleanup(void) { drm_device_t *dev = &tdfx_device;