diff options
author | Dave Airlie <airlied@starflyer.(none)> | 2005-07-07 07:51:26 -0400 |
---|---|---|
committer | Dave Airlie <airlied@linux.ie> | 2005-07-07 07:51:26 -0400 |
commit | 8ca7c1df08210fd35fccf1559837c92baaa4da8f (patch) | |
tree | 06d09b81f0718bd12b7a0fe8985f4aa13d7d2bc7 /drivers/char/drm | |
parent | c101f3136cc98a003d0d16be6fab7d0d950581a6 (diff) |
drm: add 32/64 support for MGA/R128/i915
This adds compatiblity ioctls for mga/r128 and i915 DRM drivers.
From: Paul Mackerras, David Airlie, Alan Hourihane, Egbert Eich.
Signed-off-by: David Airlie <airlied@linux.ie>
Diffstat (limited to 'drivers/char/drm')
-rw-r--r-- | drivers/char/drm/Makefile | 3 | ||||
-rw-r--r-- | drivers/char/drm/i915_drv.c | 3 | ||||
-rw-r--r-- | drivers/char/drm/i915_drv.h | 4 | ||||
-rw-r--r-- | drivers/char/drm/i915_ioc32.c | 221 | ||||
-rw-r--r-- | drivers/char/drm/mga_drv.c | 3 | ||||
-rw-r--r-- | drivers/char/drm/mga_drv.h | 2 | ||||
-rw-r--r-- | drivers/char/drm/mga_ioc32.c | 167 | ||||
-rw-r--r-- | drivers/char/drm/r128_drv.c | 3 | ||||
-rw-r--r-- | drivers/char/drm/r128_drv.h | 3 | ||||
-rw-r--r-- | drivers/char/drm/r128_ioc32.c | 219 |
10 files changed, 628 insertions, 0 deletions
diff --git a/drivers/char/drm/Makefile b/drivers/char/drm/Makefile index 7444dec40b94..b36b0158582e 100644 --- a/drivers/char/drm/Makefile +++ b/drivers/char/drm/Makefile | |||
@@ -22,6 +22,9 @@ sis-objs := sis_drv.o sis_ds.o sis_mm.o | |||
22 | ifeq ($(CONFIG_COMPAT),y) | 22 | ifeq ($(CONFIG_COMPAT),y) |
23 | drm-objs += drm_ioc32.o | 23 | drm-objs += drm_ioc32.o |
24 | radeon-objs += radeon_ioc32.o | 24 | radeon-objs += radeon_ioc32.o |
25 | mga-objs += mga_ioc32.o | ||
26 | r128-objs += r128_ioc32.o | ||
27 | i915-objs += i915_ioc32.o | ||
25 | endif | 28 | endif |
26 | 29 | ||
27 | obj-$(CONFIG_DRM) += drm.o | 30 | obj-$(CONFIG_DRM) += drm.o |
diff --git a/drivers/char/drm/i915_drv.c b/drivers/char/drm/i915_drv.c index e6a9e1d1d283..6a6cc3c0c4c3 100644 --- a/drivers/char/drm/i915_drv.c +++ b/drivers/char/drm/i915_drv.c | |||
@@ -97,6 +97,9 @@ static struct drm_driver driver = { | |||
97 | .mmap = drm_mmap, | 97 | .mmap = drm_mmap, |
98 | .poll = drm_poll, | 98 | .poll = drm_poll, |
99 | .fasync = drm_fasync, | 99 | .fasync = drm_fasync, |
100 | #ifdef CONFIG_COMPAT | ||
101 | .compat_ioctl = i915_compat_ioctl, | ||
102 | #endif | ||
100 | }, | 103 | }, |
101 | .pci_driver = { | 104 | .pci_driver = { |
102 | .name = DRIVER_NAME, | 105 | .name = DRIVER_NAME, |
diff --git a/drivers/char/drm/i915_drv.h b/drivers/char/drm/i915_drv.h index fa940d64b85d..3a21223267cb 100644 --- a/drivers/char/drm/i915_drv.h +++ b/drivers/char/drm/i915_drv.h | |||
@@ -130,6 +130,10 @@ extern void i915_mem_takedown(struct mem_block **heap); | |||
130 | extern void i915_mem_release(drm_device_t * dev, | 130 | extern void i915_mem_release(drm_device_t * dev, |
131 | DRMFILE filp, struct mem_block *heap); | 131 | DRMFILE filp, struct mem_block *heap); |
132 | 132 | ||
133 | extern long i915_compat_ioctl(struct file *filp, unsigned int cmd, | ||
134 | unsigned long arg) | ||
135 | |||
136 | |||
133 | #define I915_READ(reg) DRM_READ32(dev_priv->mmio_map, reg) | 137 | #define I915_READ(reg) DRM_READ32(dev_priv->mmio_map, reg) |
134 | #define I915_WRITE(reg,val) DRM_WRITE32(dev_priv->mmio_map, reg, val) | 138 | #define I915_WRITE(reg,val) DRM_WRITE32(dev_priv->mmio_map, reg, val) |
135 | #define I915_READ16(reg) DRM_READ16(dev_priv->mmio_map, reg) | 139 | #define I915_READ16(reg) DRM_READ16(dev_priv->mmio_map, reg) |
diff --git a/drivers/char/drm/i915_ioc32.c b/drivers/char/drm/i915_ioc32.c new file mode 100644 index 000000000000..fe009e1b3a3f --- /dev/null +++ b/drivers/char/drm/i915_ioc32.c | |||
@@ -0,0 +1,221 @@ | |||
1 | /** | ||
2 | * \file i915_ioc32.c | ||
3 | * | ||
4 | * 32-bit ioctl compatibility routines for the i915 DRM. | ||
5 | * | ||
6 | * \author Alan Hourihane <alanh@fairlite.demon.co.uk> | ||
7 | * | ||
8 | * | ||
9 | * Copyright (C) Paul Mackerras 2005 | ||
10 | * Copyright (C) Alan Hourihane 2005 | ||
11 | * All Rights Reserved. | ||
12 | * | ||
13 | * Permission is hereby granted, free of charge, to any person obtaining a | ||
14 | * copy of this software and associated documentation files (the "Software"), | ||
15 | * to deal in the Software without restriction, including without limitation | ||
16 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
17 | * and/or sell copies of the Software, and to permit persons to whom the | ||
18 | * Software is furnished to do so, subject to the following conditions: | ||
19 | * | ||
20 | * The above copyright notice and this permission notice (including the next | ||
21 | * paragraph) shall be included in all copies or substantial portions of the | ||
22 | * Software. | ||
23 | * | ||
24 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
25 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
26 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
27 | * THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
28 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
29 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | ||
30 | * IN THE SOFTWARE. | ||
31 | */ | ||
32 | #include <linux/compat.h> | ||
33 | #include <linux/ioctl32.h> | ||
34 | |||
35 | #include "drmP.h" | ||
36 | #include "drm.h" | ||
37 | #include "i915_drm.h" | ||
38 | |||
39 | typedef struct _drm_i915_batchbuffer32 { | ||
40 | int start; /* agp offset */ | ||
41 | int used; /* nr bytes in use */ | ||
42 | int DR1; /* hw flags for GFX_OP_DRAWRECT_INFO */ | ||
43 | int DR4; /* window origin for GFX_OP_DRAWRECT_INFO */ | ||
44 | int num_cliprects; /* mulitpass with multiple cliprects? */ | ||
45 | u32 cliprects; /* pointer to userspace cliprects */ | ||
46 | } drm_i915_batchbuffer32_t; | ||
47 | |||
48 | static int compat_i915_batchbuffer(struct file *file, unsigned int cmd, | ||
49 | unsigned long arg) | ||
50 | { | ||
51 | drm_i915_batchbuffer32_t batchbuffer32; | ||
52 | drm_i915_batchbuffer_t __user *batchbuffer; | ||
53 | |||
54 | if (copy_from_user(&batchbuffer32, (void __user *)arg, sizeof(batchbuffer32))) | ||
55 | return -EFAULT; | ||
56 | |||
57 | batchbuffer = compat_alloc_user_space(sizeof(*batchbuffer)); | ||
58 | if (!access_ok(VERIFY_WRITE, batchbuffer, sizeof(*batchbuffer)) | ||
59 | || __put_user(batchbuffer32.start, &batchbuffer->start) | ||
60 | || __put_user(batchbuffer32.used, &batchbuffer->used) | ||
61 | || __put_user(batchbuffer32.DR1, &batchbuffer->DR1) | ||
62 | || __put_user(batchbuffer32.DR4, &batchbuffer->DR4) | ||
63 | || __put_user(batchbuffer32.num_cliprects, &batchbuffer->num_cliprects) | ||
64 | || __put_user((int __user *)(unsigned long)batchbuffer32.cliprects, | ||
65 | &batchbuffer->cliprects)) | ||
66 | return -EFAULT; | ||
67 | |||
68 | return drm_ioctl(file->f_dentry->d_inode, file, | ||
69 | DRM_IOCTL_I915_BATCHBUFFER, (unsigned long) batchbuffer); | ||
70 | } | ||
71 | |||
72 | typedef struct _drm_i915_cmdbuffer32 { | ||
73 | u32 buf; /* pointer to userspace command buffer */ | ||
74 | int sz; /* nr bytes in buf */ | ||
75 | int DR1; /* hw flags for GFX_OP_DRAWRECT_INFO */ | ||
76 | int DR4; /* window origin for GFX_OP_DRAWRECT_INFO */ | ||
77 | int num_cliprects; /* mulitpass with multiple cliprects? */ | ||
78 | u32 cliprects; /* pointer to userspace cliprects */ | ||
79 | } drm_i915_cmdbuffer32_t; | ||
80 | |||
81 | static int compat_i915_cmdbuffer(struct file *file, unsigned int cmd, | ||
82 | unsigned long arg) | ||
83 | { | ||
84 | drm_i915_cmdbuffer32_t cmdbuffer32; | ||
85 | drm_i915_cmdbuffer_t __user *cmdbuffer; | ||
86 | |||
87 | if (copy_from_user(&cmdbuffer32, (void __user *)arg, sizeof(cmdbuffer32))) | ||
88 | return -EFAULT; | ||
89 | |||
90 | cmdbuffer = compat_alloc_user_space(sizeof(*cmdbuffer)); | ||
91 | if (!access_ok(VERIFY_WRITE, cmdbuffer, sizeof(*cmdbuffer)) | ||
92 | || __put_user((int __user *)(unsigned long)cmdbuffer32.buf, | ||
93 | &cmdbuffer->buf) | ||
94 | || __put_user(cmdbuffer32.sz, &cmdbuffer->sz) | ||
95 | || __put_user(cmdbuffer32.DR1, &cmdbuffer->DR1) | ||
96 | || __put_user(cmdbuffer32.DR4, &cmdbuffer->DR4) | ||
97 | || __put_user(cmdbuffer32.num_cliprects, &cmdbuffer->num_cliprects) | ||
98 | || __put_user((int __user *)(unsigned long)cmdbuffer32.cliprects, | ||
99 | &cmdbuffer->cliprects)) | ||
100 | return -EFAULT; | ||
101 | |||
102 | return drm_ioctl(file->f_dentry->d_inode, file, | ||
103 | DRM_IOCTL_I915_CMDBUFFER, (unsigned long) cmdbuffer); | ||
104 | } | ||
105 | |||
106 | typedef struct drm_i915_irq_emit32 { | ||
107 | u32 irq_seq; | ||
108 | } drm_i915_irq_emit32_t; | ||
109 | |||
110 | static int compat_i915_irq_emit(struct file *file, unsigned int cmd, | ||
111 | unsigned long arg) | ||
112 | { | ||
113 | drm_i915_irq_emit32_t req32; | ||
114 | drm_i915_irq_emit_t __user *request; | ||
115 | |||
116 | if (copy_from_user(&req32, (void __user *) arg, sizeof(req32))) | ||
117 | return -EFAULT; | ||
118 | |||
119 | request = compat_alloc_user_space(sizeof(*request)); | ||
120 | if (!access_ok(VERIFY_WRITE, request, sizeof(*request)) | ||
121 | || __put_user((int __user *)(unsigned long)req32.irq_seq, | ||
122 | &request->irq_seq)) | ||
123 | return -EFAULT; | ||
124 | |||
125 | return drm_ioctl(file->f_dentry->d_inode, file, | ||
126 | DRM_IOCTL_I915_IRQ_EMIT, (unsigned long) request); | ||
127 | } | ||
128 | typedef struct drm_i915_getparam32 { | ||
129 | int param; | ||
130 | u32 value; | ||
131 | } drm_i915_getparam32_t; | ||
132 | |||
133 | static int compat_i915_getparam(struct file *file, unsigned int cmd, | ||
134 | unsigned long arg) | ||
135 | { | ||
136 | drm_i915_getparam32_t req32; | ||
137 | drm_i915_getparam_t __user *request; | ||
138 | |||
139 | if (copy_from_user(&req32, (void __user *) arg, sizeof(req32))) | ||
140 | return -EFAULT; | ||
141 | |||
142 | request = compat_alloc_user_space(sizeof(*request)); | ||
143 | if (!access_ok(VERIFY_WRITE, request, sizeof(*request)) | ||
144 | || __put_user(req32.param, &request->param) | ||
145 | || __put_user((void __user *)(unsigned long)req32.value, | ||
146 | &request->value)) | ||
147 | return -EFAULT; | ||
148 | |||
149 | return drm_ioctl(file->f_dentry->d_inode, file, | ||
150 | DRM_IOCTL_I915_GETPARAM, (unsigned long) request); | ||
151 | } | ||
152 | |||
153 | typedef struct drm_i915_mem_alloc32 { | ||
154 | int region; | ||
155 | int alignment; | ||
156 | int size; | ||
157 | u32 region_offset; /* offset from start of fb or agp */ | ||
158 | } drm_i915_mem_alloc32_t; | ||
159 | |||
160 | static int compat_i915_alloc(struct file *file, unsigned int cmd, | ||
161 | unsigned long arg) | ||
162 | { | ||
163 | drm_i915_mem_alloc32_t req32; | ||
164 | drm_i915_mem_alloc_t __user *request; | ||
165 | |||
166 | if (copy_from_user(&req32, (void __user *) arg, sizeof(req32))) | ||
167 | return -EFAULT; | ||
168 | |||
169 | request = compat_alloc_user_space(sizeof(*request)); | ||
170 | if (!access_ok(VERIFY_WRITE, request, sizeof(*request)) | ||
171 | || __put_user(req32.region, &request->region) | ||
172 | || __put_user(req32.alignment, &request->alignment) | ||
173 | || __put_user(req32.size, &request->size) | ||
174 | || __put_user((void __user *)(unsigned long)req32.region_offset, | ||
175 | &request->region_offset)) | ||
176 | return -EFAULT; | ||
177 | |||
178 | return drm_ioctl(file->f_dentry->d_inode, file, | ||
179 | DRM_IOCTL_I915_ALLOC, (unsigned long) request); | ||
180 | } | ||
181 | |||
182 | |||
183 | drm_ioctl_compat_t *i915_compat_ioctls[] = { | ||
184 | [DRM_I915_BATCHBUFFER] = compat_i915_batchbuffer, | ||
185 | [DRM_I915_CMDBUFFER] = compat_i915_cmdbuffer, | ||
186 | [DRM_I915_GETPARAM] = compat_i915_getparam, | ||
187 | [DRM_I915_IRQ_EMIT] = compat_i915_irq_emit, | ||
188 | [DRM_I915_ALLOC] = compat_i915_alloc | ||
189 | }; | ||
190 | |||
191 | /** | ||
192 | * Called whenever a 32-bit process running under a 64-bit kernel | ||
193 | * performs an ioctl on /dev/dri/card<n>. | ||
194 | * | ||
195 | * \param filp file pointer. | ||
196 | * \param cmd command. | ||
197 | * \param arg user argument. | ||
198 | * \return zero on success or negative number on failure. | ||
199 | */ | ||
200 | long i915_compat_ioctl(struct file *filp, unsigned int cmd, | ||
201 | unsigned long arg) | ||
202 | { | ||
203 | unsigned int nr = DRM_IOCTL_NR(cmd); | ||
204 | drm_ioctl_compat_t *fn = NULL; | ||
205 | int ret; | ||
206 | |||
207 | if (nr < DRM_COMMAND_BASE) | ||
208 | return drm_compat_ioctl(filp, cmd, arg); | ||
209 | |||
210 | if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls)) | ||
211 | fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE]; | ||
212 | |||
213 | lock_kernel(); /* XXX for now */ | ||
214 | if (fn != NULL) | ||
215 | ret = (*fn)(filp, cmd, arg); | ||
216 | else | ||
217 | ret = drm_ioctl(filp->f_dentry->d_inode, filp, cmd, arg); | ||
218 | unlock_kernel(); | ||
219 | |||
220 | return ret; | ||
221 | } | ||
diff --git a/drivers/char/drm/mga_drv.c b/drivers/char/drm/mga_drv.c index 22dab3e9d92a..844cca9cb29d 100644 --- a/drivers/char/drm/mga_drv.c +++ b/drivers/char/drm/mga_drv.c | |||
@@ -101,6 +101,9 @@ static struct drm_driver driver = { | |||
101 | .mmap = drm_mmap, | 101 | .mmap = drm_mmap, |
102 | .poll = drm_poll, | 102 | .poll = drm_poll, |
103 | .fasync = drm_fasync, | 103 | .fasync = drm_fasync, |
104 | #ifdef CONFIG_COMPAT | ||
105 | .compat_ioctl = mga_compat_ioctl, | ||
106 | #endif | ||
104 | }, | 107 | }, |
105 | .pci_driver = { | 108 | .pci_driver = { |
106 | .name = DRIVER_NAME, | 109 | .name = DRIVER_NAME, |
diff --git a/drivers/char/drm/mga_drv.h b/drivers/char/drm/mga_drv.h index 1d84a1eb34db..9412e2816eb7 100644 --- a/drivers/char/drm/mga_drv.h +++ b/drivers/char/drm/mga_drv.h | |||
@@ -137,6 +137,8 @@ extern irqreturn_t mga_driver_irq_handler( DRM_IRQ_ARGS ); | |||
137 | extern void mga_driver_irq_preinstall( drm_device_t *dev ); | 137 | extern void mga_driver_irq_preinstall( drm_device_t *dev ); |
138 | extern void mga_driver_irq_postinstall( drm_device_t *dev ); | 138 | extern void mga_driver_irq_postinstall( drm_device_t *dev ); |
139 | extern void mga_driver_irq_uninstall( drm_device_t *dev ); | 139 | extern void mga_driver_irq_uninstall( drm_device_t *dev ); |
140 | extern long mga_compat_ioctl(struct file *filp, unsigned int cmd, | ||
141 | unsigned long arg); | ||
140 | 142 | ||
141 | #define mga_flush_write_combine() DRM_WRITEMEMORYBARRIER() | 143 | #define mga_flush_write_combine() DRM_WRITEMEMORYBARRIER() |
142 | 144 | ||
diff --git a/drivers/char/drm/mga_ioc32.c b/drivers/char/drm/mga_ioc32.c new file mode 100644 index 000000000000..bc745cfa2095 --- /dev/null +++ b/drivers/char/drm/mga_ioc32.c | |||
@@ -0,0 +1,167 @@ | |||
1 | /** | ||
2 | * \file mga_ioc32.c | ||
3 | * | ||
4 | * 32-bit ioctl compatibility routines for the MGA DRM. | ||
5 | * | ||
6 | * \author Dave Airlie <airlied@linux.ie> with code from patches by Egbert Eich | ||
7 | * | ||
8 | * | ||
9 | * Copyright (C) Paul Mackerras 2005 | ||
10 | * Copyright (C) Egbert Eich 2003,2004 | ||
11 | * Copyright (C) Dave Airlie 2005 | ||
12 | * All Rights Reserved. | ||
13 | * | ||
14 | * Permission is hereby granted, free of charge, to any person obtaining a | ||
15 | * copy of this software and associated documentation files (the "Software"), | ||
16 | * to deal in the Software without restriction, including without limitation | ||
17 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
18 | * and/or sell copies of the Software, and to permit persons to whom the | ||
19 | * Software is furnished to do so, subject to the following conditions: | ||
20 | * | ||
21 | * The above copyright notice and this permission notice (including the next | ||
22 | * paragraph) shall be included in all copies or substantial portions of the | ||
23 | * Software. | ||
24 | * | ||
25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
26 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
27 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
28 | * THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
29 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
30 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | ||
31 | * IN THE SOFTWARE. | ||
32 | */ | ||
33 | #include <linux/compat.h> | ||
34 | #include <linux/ioctl32.h> | ||
35 | |||
36 | #include "drmP.h" | ||
37 | #include "drm.h" | ||
38 | #include "mga_drm.h" | ||
39 | |||
40 | typedef struct drm32_mga_init { | ||
41 | int func; | ||
42 | u32 sarea_priv_offset; | ||
43 | int chipset; | ||
44 | int sgram; | ||
45 | unsigned int maccess; | ||
46 | unsigned int fb_cpp; | ||
47 | unsigned int front_offset, front_pitch; | ||
48 | unsigned int back_offset, back_pitch; | ||
49 | unsigned int depth_cpp; | ||
50 | unsigned int depth_offset, depth_pitch; | ||
51 | unsigned int texture_offset[MGA_NR_TEX_HEAPS]; | ||
52 | unsigned int texture_size[MGA_NR_TEX_HEAPS]; | ||
53 | u32 fb_offset; | ||
54 | u32 mmio_offset; | ||
55 | u32 status_offset; | ||
56 | u32 warp_offset; | ||
57 | u32 primary_offset; | ||
58 | u32 buffers_offset; | ||
59 | } drm_mga_init32_t; | ||
60 | |||
61 | static int compat_mga_init(struct file *file, unsigned int cmd, | ||
62 | unsigned long arg) | ||
63 | { | ||
64 | drm_mga_init32_t init32; | ||
65 | drm_mga_init_t __user *init; | ||
66 | int err = 0, i; | ||
67 | |||
68 | if (copy_from_user(&init32, (void __user *)arg, sizeof(init32))) | ||
69 | return -EFAULT; | ||
70 | |||
71 | init = compat_alloc_user_space(sizeof(*init)); | ||
72 | if (!access_ok(VERIFY_WRITE, init, sizeof(*init)) | ||
73 | || __put_user(init32.func, &init->func) | ||
74 | || __put_user(init32.sarea_priv_offset, &init->sarea_priv_offset) | ||
75 | || __put_user(init32.chipset, &init->chipset) | ||
76 | || __put_user(init32.sgram, &init->sgram) | ||
77 | || __put_user(init32.maccess, &init->maccess) | ||
78 | || __put_user(init32.fb_cpp, &init->fb_cpp) | ||
79 | || __put_user(init32.front_offset, &init->front_offset) | ||
80 | || __put_user(init32.front_pitch, &init->front_pitch) | ||
81 | || __put_user(init32.back_offset, &init->back_offset) | ||
82 | || __put_user(init32.back_pitch, &init->back_pitch) | ||
83 | || __put_user(init32.depth_cpp, &init->depth_cpp) | ||
84 | || __put_user(init32.depth_offset, &init->depth_offset) | ||
85 | || __put_user(init32.depth_pitch, &init->depth_pitch) | ||
86 | || __put_user(init32.fb_offset, &init->fb_offset) | ||
87 | || __put_user(init32.mmio_offset, &init->mmio_offset) | ||
88 | || __put_user(init32.status_offset, &init->status_offset) | ||
89 | || __put_user(init32.warp_offset, &init->warp_offset) | ||
90 | || __put_user(init32.primary_offset, &init->primary_offset) | ||
91 | || __put_user(init32.buffers_offset, &init->buffers_offset)) | ||
92 | return -EFAULT; | ||
93 | |||
94 | for (i=0; i<MGA_NR_TEX_HEAPS; i++) | ||
95 | { | ||
96 | err |= __put_user(init32.texture_offset[i], &init->texture_offset[i]); | ||
97 | err |= __put_user(init32.texture_size[i], &init->texture_size[i]); | ||
98 | } | ||
99 | if (err) | ||
100 | return -EFAULT; | ||
101 | |||
102 | return drm_ioctl(file->f_dentry->d_inode, file, | ||
103 | DRM_IOCTL_MGA_INIT, (unsigned long) init); | ||
104 | } | ||
105 | |||
106 | |||
107 | typedef struct drm_mga_getparam32 { | ||
108 | int param; | ||
109 | u32 value; | ||
110 | } drm_mga_getparam32_t; | ||
111 | |||
112 | |||
113 | static int compat_mga_getparam(struct file *file, unsigned int cmd, | ||
114 | unsigned long arg) | ||
115 | { | ||
116 | drm_mga_getparam32_t getparam32; | ||
117 | drm_mga_getparam_t __user *getparam; | ||
118 | |||
119 | if (copy_from_user(&getparam32, (void __user *)arg, sizeof(getparam32))) | ||
120 | return -EFAULT; | ||
121 | |||
122 | getparam = compat_alloc_user_space(sizeof(*getparam)); | ||
123 | if (!access_ok(VERIFY_WRITE, getparam, sizeof(*getparam)) | ||
124 | || __put_user(getparam32.param, &getparam->param) | ||
125 | || __put_user((void __user *)(unsigned long)getparam32.value, &getparam->value)) | ||
126 | return -EFAULT; | ||
127 | |||
128 | return drm_ioctl(file->f_dentry->d_inode, file, | ||
129 | DRM_IOCTL_MGA_GETPARAM, (unsigned long)getparam); | ||
130 | } | ||
131 | |||
132 | drm_ioctl_compat_t *mga_compat_ioctls[] = { | ||
133 | [DRM_MGA_INIT] = compat_mga_init, | ||
134 | [DRM_MGA_GETPARAM] = compat_mga_getparam, | ||
135 | }; | ||
136 | |||
137 | /** | ||
138 | * Called whenever a 32-bit process running under a 64-bit kernel | ||
139 | * performs an ioctl on /dev/dri/card<n>. | ||
140 | * | ||
141 | * \param filp file pointer. | ||
142 | * \param cmd command. | ||
143 | * \param arg user argument. | ||
144 | * \return zero on success or negative number on failure. | ||
145 | */ | ||
146 | long mga_compat_ioctl(struct file *filp, unsigned int cmd, | ||
147 | unsigned long arg) | ||
148 | { | ||
149 | unsigned int nr = DRM_IOCTL_NR(cmd); | ||
150 | drm_ioctl_compat_t *fn = NULL; | ||
151 | int ret; | ||
152 | |||
153 | if (nr < DRM_COMMAND_BASE) | ||
154 | return drm_compat_ioctl(filp, cmd, arg); | ||
155 | |||
156 | if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls)) | ||
157 | fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE]; | ||
158 | |||
159 | lock_kernel(); /* XXX for now */ | ||
160 | if (fn != NULL) | ||
161 | ret = (*fn)(filp, cmd, arg); | ||
162 | else | ||
163 | ret = drm_ioctl(filp->f_dentry->d_inode, filp, cmd, arg); | ||
164 | unlock_kernel(); | ||
165 | |||
166 | return ret; | ||
167 | } | ||
diff --git a/drivers/char/drm/r128_drv.c b/drivers/char/drm/r128_drv.c index ced63810237b..bc446da1b210 100644 --- a/drivers/char/drm/r128_drv.c +++ b/drivers/char/drm/r128_drv.c | |||
@@ -96,6 +96,9 @@ static struct drm_driver driver = { | |||
96 | .mmap = drm_mmap, | 96 | .mmap = drm_mmap, |
97 | .poll = drm_poll, | 97 | .poll = drm_poll, |
98 | .fasync = drm_fasync, | 98 | .fasync = drm_fasync, |
99 | #ifdef CONFIG_COMPAT | ||
100 | .compat_ioctl = r128_compat_ioctl, | ||
101 | #endif | ||
99 | }, | 102 | }, |
100 | .pci_driver = { | 103 | .pci_driver = { |
101 | .name = DRIVER_NAME, | 104 | .name = DRIVER_NAME, |
diff --git a/drivers/char/drm/r128_drv.h b/drivers/char/drm/r128_drv.h index cf1aa5df459e..0fb687c9505e 100644 --- a/drivers/char/drm/r128_drv.h +++ b/drivers/char/drm/r128_drv.h | |||
@@ -156,6 +156,9 @@ extern void r128_driver_irq_uninstall( drm_device_t *dev ); | |||
156 | extern void r128_driver_pretakedown(drm_device_t *dev); | 156 | extern void r128_driver_pretakedown(drm_device_t *dev); |
157 | extern void r128_driver_prerelease(drm_device_t *dev, DRMFILE filp); | 157 | extern void r128_driver_prerelease(drm_device_t *dev, DRMFILE filp); |
158 | 158 | ||
159 | extern long r128_compat_ioctl(struct file *filp, unsigned int cmd, | ||
160 | unsigned long arg); | ||
161 | |||
159 | /* Register definitions, register access macros and drmAddMap constants | 162 | /* Register definitions, register access macros and drmAddMap constants |
160 | * for Rage 128 kernel driver. | 163 | * for Rage 128 kernel driver. |
161 | */ | 164 | */ |
diff --git a/drivers/char/drm/r128_ioc32.c b/drivers/char/drm/r128_ioc32.c new file mode 100644 index 000000000000..60598ef9475a --- /dev/null +++ b/drivers/char/drm/r128_ioc32.c | |||
@@ -0,0 +1,219 @@ | |||
1 | /** | ||
2 | * \file r128_ioc32.c | ||
3 | * | ||
4 | * 32-bit ioctl compatibility routines for the R128 DRM. | ||
5 | * | ||
6 | * \author Dave Airlie <airlied@linux.ie> with code from patches by Egbert Eich | ||
7 | * | ||
8 | * Copyright (C) Paul Mackerras 2005 | ||
9 | * Copyright (C) Egbert Eich 2003,2004 | ||
10 | * Copyright (C) Dave Airlie 2005 | ||
11 | * All Rights Reserved. | ||
12 | * | ||
13 | * Permission is hereby granted, free of charge, to any person obtaining a | ||
14 | * copy of this software and associated documentation files (the "Software"), | ||
15 | * to deal in the Software without restriction, including without limitation | ||
16 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
17 | * and/or sell copies of the Software, and to permit persons to whom the | ||
18 | * Software is furnished to do so, subject to the following conditions: | ||
19 | * | ||
20 | * The above copyright notice and this permission notice (including the next | ||
21 | * paragraph) shall be included in all copies or substantial portions of the | ||
22 | * Software. | ||
23 | * | ||
24 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
25 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
26 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
27 | * THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
28 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
29 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | ||
30 | * IN THE SOFTWARE. | ||
31 | */ | ||
32 | #include <linux/compat.h> | ||
33 | #include <linux/ioctl32.h> | ||
34 | |||
35 | #include "drmP.h" | ||
36 | #include "drm.h" | ||
37 | #include "r128_drm.h" | ||
38 | |||
39 | typedef struct drm_r128_init32 { | ||
40 | int func; | ||
41 | unsigned int sarea_priv_offset; | ||
42 | int is_pci; | ||
43 | int cce_mode; | ||
44 | int cce_secure; | ||
45 | int ring_size; | ||
46 | int usec_timeout; | ||
47 | |||
48 | unsigned int fb_bpp; | ||
49 | unsigned int front_offset, front_pitch; | ||
50 | unsigned int back_offset, back_pitch; | ||
51 | unsigned int depth_bpp; | ||
52 | unsigned int depth_offset, depth_pitch; | ||
53 | unsigned int span_offset; | ||
54 | |||
55 | unsigned int fb_offset; | ||
56 | unsigned int mmio_offset; | ||
57 | unsigned int ring_offset; | ||
58 | unsigned int ring_rptr_offset; | ||
59 | unsigned int buffers_offset; | ||
60 | unsigned int agp_textures_offset; | ||
61 | } drm_r128_init32_t; | ||
62 | |||
63 | static int compat_r128_init(struct file *file, unsigned int cmd, | ||
64 | unsigned long arg) | ||
65 | { | ||
66 | drm_r128_init32_t init32; | ||
67 | drm_r128_init_t __user *init; | ||
68 | |||
69 | if (copy_from_user(&init32, (void __user *)arg, sizeof(init32))) | ||
70 | return -EFAULT; | ||
71 | |||
72 | init = compat_alloc_user_space(sizeof(*init)); | ||
73 | if (!access_ok(VERIFY_WRITE, init, sizeof(*init)) | ||
74 | || __put_user(init32.func, &init->func) | ||
75 | || __put_user(init32.sarea_priv_offset, &init->sarea_priv_offset) | ||
76 | || __put_user(init32.is_pci, &init->is_pci) | ||
77 | || __put_user(init32.cce_mode, &init->cce_mode) | ||
78 | || __put_user(init32.cce_secure, &init->cce_secure) | ||
79 | || __put_user(init32.ring_size, &init->ring_size) | ||
80 | || __put_user(init32.usec_timeout, &init->usec_timeout) | ||
81 | || __put_user(init32.fb_bpp, &init->fb_bpp) | ||
82 | || __put_user(init32.front_offset, &init->front_offset) | ||
83 | || __put_user(init32.front_pitch, &init->front_pitch) | ||
84 | || __put_user(init32.back_offset, &init->back_offset) | ||
85 | || __put_user(init32.back_pitch, &init->back_pitch) | ||
86 | || __put_user(init32.depth_bpp, &init->depth_bpp) | ||
87 | || __put_user(init32.depth_offset, &init->depth_offset) | ||
88 | || __put_user(init32.depth_pitch, &init->depth_pitch) | ||
89 | || __put_user(init32.span_offset, &init->span_offset) | ||
90 | || __put_user(init32.fb_offset, &init->fb_offset) | ||
91 | || __put_user(init32.mmio_offset, &init->mmio_offset) | ||
92 | || __put_user(init32.ring_offset, &init->ring_offset) | ||
93 | || __put_user(init32.ring_rptr_offset, &init->ring_rptr_offset) | ||
94 | || __put_user(init32.buffers_offset, &init->buffers_offset) | ||
95 | || __put_user(init32.agp_textures_offset, &init->agp_textures_offset)) | ||
96 | return -EFAULT; | ||
97 | |||
98 | return drm_ioctl(file->f_dentry->d_inode, file, | ||
99 | DRM_IOCTL_R128_INIT, (unsigned long)init); | ||
100 | } | ||
101 | |||
102 | |||
103 | typedef struct drm_r128_depth32 { | ||
104 | int func; | ||
105 | int n; | ||
106 | u32 x; | ||
107 | u32 y; | ||
108 | u32 buffer; | ||
109 | u32 mask; | ||
110 | } drm_r128_depth32_t; | ||
111 | |||
112 | static int compat_r128_depth(struct file *file, unsigned int cmd, | ||
113 | unsigned long arg) | ||
114 | { | ||
115 | drm_r128_depth32_t depth32; | ||
116 | drm_r128_depth_t __user *depth; | ||
117 | |||
118 | if (copy_from_user(&depth32, (void __user *)arg, sizeof(depth32))) | ||
119 | return -EFAULT; | ||
120 | |||
121 | depth = compat_alloc_user_space(sizeof(*depth)); | ||
122 | if (!access_ok(VERIFY_WRITE, depth, sizeof(*depth)) | ||
123 | || __put_user(depth32.func, &depth->func) | ||
124 | || __put_user(depth32.n, &depth->n) | ||
125 | || __put_user((int __user *)(unsigned long)depth32.x, &depth->x) | ||
126 | || __put_user((int __user *)(unsigned long)depth32.y, &depth->y) | ||
127 | || __put_user((unsigned int __user *)(unsigned long)depth32.buffer, &depth->buffer) | ||
128 | || __put_user((unsigned char __user *)(unsigned long)depth32.mask, &depth->mask)) | ||
129 | return -EFAULT; | ||
130 | |||
131 | return drm_ioctl(file->f_dentry->d_inode, file, | ||
132 | DRM_IOCTL_R128_DEPTH, (unsigned long)depth); | ||
133 | |||
134 | } | ||
135 | |||
136 | typedef struct drm_r128_stipple32 { | ||
137 | u32 mask; | ||
138 | } drm_r128_stipple32_t; | ||
139 | |||
140 | static int compat_r128_stipple(struct file *file, unsigned int cmd, | ||
141 | unsigned long arg) | ||
142 | { | ||
143 | drm_r128_stipple32_t stipple32; | ||
144 | drm_r128_stipple_t __user *stipple; | ||
145 | |||
146 | if (copy_from_user(&stipple32, (void __user *)arg, sizeof(stipple32))) | ||
147 | return -EFAULT; | ||
148 | |||
149 | stipple = compat_alloc_user_space(sizeof(*stipple)); | ||
150 | if (!access_ok(VERIFY_WRITE, stipple, sizeof(*stipple)) | ||
151 | || __put_user((unsigned int __user *)(unsigned long)stipple32.mask, &stipple->mask)) | ||
152 | return -EFAULT; | ||
153 | |||
154 | return drm_ioctl(file->f_dentry->d_inode, file, | ||
155 | DRM_IOCTL_R128_STIPPLE, (unsigned long)stipple); | ||
156 | } | ||
157 | |||
158 | typedef struct drm_r128_getparam32 { | ||
159 | int param; | ||
160 | u32 value; | ||
161 | } drm_r128_getparam32_t; | ||
162 | |||
163 | static int compat_r128_getparam(struct file *file, unsigned int cmd, | ||
164 | unsigned long arg) | ||
165 | { | ||
166 | drm_r128_getparam32_t getparam32; | ||
167 | drm_r128_getparam_t __user *getparam; | ||
168 | |||
169 | if (copy_from_user(&getparam32, (void __user *)arg, sizeof(getparam32))) | ||
170 | return -EFAULT; | ||
171 | |||
172 | getparam = compat_alloc_user_space(sizeof(*getparam)); | ||
173 | if (!access_ok(VERIFY_WRITE, getparam, sizeof(*getparam)) | ||
174 | || __put_user(getparam32.param, &getparam->param) | ||
175 | || __put_user((void __user *)(unsigned long)getparam32.value, &getparam->value)) | ||
176 | return -EFAULT; | ||
177 | |||
178 | return drm_ioctl(file->f_dentry->d_inode, file, | ||
179 | DRM_IOCTL_R128_GETPARAM, (unsigned long)getparam); | ||
180 | } | ||
181 | |||
182 | drm_ioctl_compat_t *r128_compat_ioctls[] = { | ||
183 | [DRM_R128_INIT] = compat_r128_init, | ||
184 | [DRM_R128_DEPTH] = compat_r128_depth, | ||
185 | [DRM_R128_STIPPLE] = compat_r128_stipple, | ||
186 | [DRM_R128_GETPARAM] = compat_r128_getparam, | ||
187 | }; | ||
188 | |||
189 | /** | ||
190 | * Called whenever a 32-bit process running under a 64-bit kernel | ||
191 | * performs an ioctl on /dev/dri/card<n>. | ||
192 | * | ||
193 | * \param filp file pointer. | ||
194 | * \param cmd command. | ||
195 | * \param arg user argument. | ||
196 | * \return zero on success or negative number on failure. | ||
197 | */ | ||
198 | long r128_compat_ioctl(struct file *filp, unsigned int cmd, | ||
199 | unsigned long arg) | ||
200 | { | ||
201 | unsigned int nr = DRM_IOCTL_NR(cmd); | ||
202 | drm_ioctl_compat_t *fn = NULL; | ||
203 | int ret; | ||
204 | |||
205 | if (nr < DRM_COMMAND_BASE) | ||
206 | return drm_compat_ioctl(filp, cmd, arg); | ||
207 | |||
208 | if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls)) | ||
209 | fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE]; | ||
210 | |||
211 | lock_kernel(); /* XXX for now */ | ||
212 | if (fn != NULL) | ||
213 | ret = (*fn)(filp, cmd, arg); | ||
214 | else | ||
215 | ret = drm_ioctl(filp->f_dentry->d_inode, filp, cmd, arg); | ||
216 | unlock_kernel(); | ||
217 | |||
218 | return ret; | ||
219 | } | ||