Commit 9a186645 authored by Dave Airlie's avatar Dave Airlie Committed by Dave Airlie

drm: 32/64-bit DRM ioctl compatibility patch

The patch is against a 2.6.11 kernel tree.  I am running this with a
32-bit X server (compiled up from X.org CVS as of a couple of weeks
ago) and 32-bit DRI libraries and clients.  All the userland stuff is
identical to what I am using under a 32-bit kernel on my G4 powerbook
(which is a 32-bit machine of course).  I haven't tried compiling up a
64-bit X server or clients yet.

In the compatibility routines I have assumed that the kernel can
safely access user addresses after set_fs(KERNEL_DS).  That is, where
an ioctl argument structure contains pointers to other structures, and
those other structures are already compatible between the 32-bit and
64-bit ABIs (i.e. they only contain things like chars, shorts or
ints), I just check the address with access_ok() and then pass it
through to the 64-bit ioctl code.  I believe this approach may not
work on sparc64, but it does work on ppc64 and x86_64 at least.

One tricky area which may need to be revisited is the question of how
to handle the handles which we pass back to userspace to identify
mappings.  These handles are generated in the ADDMAP ioctl and then
passed in as the offset value to mmap.  However, offset values for
mmap seem to be generated in other ways as well, particularly for AGP
mappings.

The approach I have ended up with is to generate a fake 32-bit handle
only for _DRM_SHM mappings.  The handles for other mappings (AGP, REG,
FB) are physical addresses which are already limited to 32 bits, and
generating fake handles for them created all sorts of problems in the
mmap/nopage code.

This patch has been updated to use the new compatibility ioctls.

From: Paul Mackerras <paulus@samba.org>
Signed-off-by: default avatarDave Airlie <airlied@linux.ie>
parent ee98689b
...@@ -19,6 +19,11 @@ radeon-objs := radeon_drv.o radeon_cp.o radeon_state.o radeon_mem.o radeon_irq.o ...@@ -19,6 +19,11 @@ radeon-objs := radeon_drv.o radeon_cp.o radeon_state.o radeon_mem.o radeon_irq.o
ffb-objs := ffb_drv.o ffb_context.o ffb-objs := ffb_drv.o ffb_context.o
sis-objs := sis_drv.o sis_ds.o sis_mm.o sis-objs := sis_drv.o sis_ds.o sis_mm.o
ifeq ($(CONFIG_COMPAT),y)
drm-objs += drm_ioc32.o
radeon-objs += radeon_ioc32.o
endif
obj-$(CONFIG_DRM) += drm.o obj-$(CONFIG_DRM) += drm.o
obj-$(CONFIG_DRM_GAMMA) += gamma.o obj-$(CONFIG_DRM_GAMMA) += gamma.o
obj-$(CONFIG_DRM_TDFX) += tdfx.o obj-$(CONFIG_DRM_TDFX) += tdfx.o
......
...@@ -316,6 +316,9 @@ do { \ ...@@ -316,6 +316,9 @@ do { \
typedef int drm_ioctl_t( struct inode *inode, struct file *filp, typedef int drm_ioctl_t( struct inode *inode, struct file *filp,
unsigned int cmd, unsigned long arg ); unsigned int cmd, unsigned long arg );
typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
unsigned long arg);
typedef struct drm_ioctl_desc { typedef struct drm_ioctl_desc {
drm_ioctl_t *func; drm_ioctl_t *func;
int auth_needed; int auth_needed;
...@@ -775,6 +778,8 @@ extern int drm_version(struct inode *inode, struct file *filp, ...@@ -775,6 +778,8 @@ extern int drm_version(struct inode *inode, struct file *filp,
unsigned int cmd, unsigned long arg); unsigned int cmd, unsigned long arg);
extern int drm_ioctl(struct inode *inode, struct file *filp, extern int drm_ioctl(struct inode *inode, struct file *filp,
unsigned int cmd, unsigned long arg); unsigned int cmd, unsigned long arg);
extern long drm_compat_ioctl(struct file *filp,
unsigned int cmd, unsigned long arg);
extern int drm_takedown(drm_device_t * dev); extern int drm_takedown(drm_device_t * dev);
/* Device support (drm_fops.h) */ /* Device support (drm_fops.h) */
......
...@@ -60,6 +60,15 @@ int drm_order( unsigned long size ) ...@@ -60,6 +60,15 @@ int drm_order( unsigned long size )
} }
EXPORT_SYMBOL(drm_order); EXPORT_SYMBOL(drm_order);
#ifdef CONFIG_COMPAT
/*
* Used to allocate 32-bit handles for _DRM_SHM regions
* The 0x10000000 value is chosen to be out of the way of
* FB/register and GART physical addresses.
*/
static unsigned int map32_handle = 0x10000000;
#endif
/** /**
* Ioctl to specify a range of memory that is available for mapping by a non-root process. * Ioctl to specify a range of memory that is available for mapping by a non-root process.
* *
...@@ -187,16 +196,18 @@ int drm_addmap( struct inode *inode, struct file *filp, ...@@ -187,16 +196,18 @@ int drm_addmap( struct inode *inode, struct file *filp,
down(&dev->struct_sem); down(&dev->struct_sem);
list_add(&list->head, &dev->maplist->head); list_add(&list->head, &dev->maplist->head);
#ifdef CONFIG_COMPAT
/* Assign a 32-bit handle for _DRM_SHM mappings */
/* We do it here so that dev->struct_sem protects the increment */
if (map->type == _DRM_SHM)
map->offset = map32_handle += PAGE_SIZE;
#endif
up(&dev->struct_sem); up(&dev->struct_sem);
if ( copy_to_user( argp, map, sizeof(*map) ) ) if ( copy_to_user( argp, map, sizeof(*map) ) )
return -EFAULT; return -EFAULT;
if ( map->type != _DRM_SHM ) { if (copy_to_user(&argp->handle, &map->offset, sizeof(map->offset)))
if ( copy_to_user( &argp->handle, return -EFAULT;
&map->offset,
sizeof(map->offset) ) )
return -EFAULT;
}
return 0; return 0;
} }
...@@ -240,7 +251,7 @@ int drm_rmmap(struct inode *inode, struct file *filp, ...@@ -240,7 +251,7 @@ int drm_rmmap(struct inode *inode, struct file *filp,
r_list = list_entry(list, drm_map_list_t, head); r_list = list_entry(list, drm_map_list_t, head);
if(r_list->map && if(r_list->map &&
r_list->map->handle == request.handle && r_list->map->offset == (unsigned long) request.handle &&
r_list->map->flags & _DRM_REMOVABLE) break; r_list->map->flags & _DRM_REMOVABLE) break;
} }
......
...@@ -225,7 +225,7 @@ int drm_getsareactx(struct inode *inode, struct file *filp, ...@@ -225,7 +225,7 @@ int drm_getsareactx(struct inode *inode, struct file *filp,
map = dev->context_sareas[request.ctx_id]; map = dev->context_sareas[request.ctx_id];
up(&dev->struct_sem); up(&dev->struct_sem);
request.handle = map->handle; request.handle = (void *) map->offset;
if (copy_to_user(argp, &request, sizeof(request))) if (copy_to_user(argp, &request, sizeof(request)))
return -EFAULT; return -EFAULT;
return 0; return 0;
...@@ -261,8 +261,8 @@ int drm_setsareactx(struct inode *inode, struct file *filp, ...@@ -261,8 +261,8 @@ int drm_setsareactx(struct inode *inode, struct file *filp,
down(&dev->struct_sem); down(&dev->struct_sem);
list_for_each(list, &dev->maplist->head) { list_for_each(list, &dev->maplist->head) {
r_list = list_entry(list, drm_map_list_t, head); r_list = list_entry(list, drm_map_list_t, head);
if(r_list->map && if (r_list->map
r_list->map->handle == request.handle) && r_list->map->offset == (unsigned long) request.handle)
goto found; goto found;
} }
bad: bad:
......
This diff is collapsed.
...@@ -101,6 +101,9 @@ static struct drm_driver driver = { ...@@ -101,6 +101,9 @@ static struct drm_driver driver = {
.mmap = drm_mmap, .mmap = drm_mmap,
.poll = drm_poll, .poll = drm_poll,
.fasync = drm_fasync, .fasync = drm_fasync,
#ifdef CONFIG_COMPAT
.compat_ioctl = radeon_compat_ioctl,
#endif
}, },
.pci_driver = { .pci_driver = {
.name = DRIVER_NAME, .name = DRIVER_NAME,
......
...@@ -317,6 +317,9 @@ extern int radeon_preinit( struct drm_device *dev, unsigned long flags ); ...@@ -317,6 +317,9 @@ extern int radeon_preinit( struct drm_device *dev, unsigned long flags );
extern int radeon_postinit( struct drm_device *dev, unsigned long flags ); extern int radeon_postinit( struct drm_device *dev, unsigned long flags );
extern int radeon_postcleanup( struct drm_device *dev ); extern int radeon_postcleanup( struct drm_device *dev );
extern long radeon_compat_ioctl(struct file *filp, unsigned int cmd,
unsigned long arg);
/* Flags for stats.boxes /* Flags for stats.boxes
*/ */
#define RADEON_BOX_DMA_IDLE 0x1 #define RADEON_BOX_DMA_IDLE 0x1
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment