1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33#include <linux/compat.h>
34
35#include <drm/drmP.h>
36#include <drm/mga_drm.h>
37#include "mga_drv.h"
38
39typedef struct drm32_mga_init {
40 int func;
41 u32 sarea_priv_offset;
42 int chipset;
43 int sgram;
44 unsigned int maccess;
45 unsigned int fb_cpp;
46 unsigned int front_offset, front_pitch;
47 unsigned int back_offset, back_pitch;
48 unsigned int depth_cpp;
49 unsigned int depth_offset, depth_pitch;
50 unsigned int texture_offset[MGA_NR_TEX_HEAPS];
51 unsigned int texture_size[MGA_NR_TEX_HEAPS];
52 u32 fb_offset;
53 u32 mmio_offset;
54 u32 status_offset;
55 u32 warp_offset;
56 u32 primary_offset;
57 u32 buffers_offset;
58} drm_mga_init32_t;
59
60static int compat_mga_init(struct file *file, unsigned int cmd,
61 unsigned long arg)
62{
63 drm_mga_init32_t init32;
64 drm_mga_init_t init;
65
66 if (copy_from_user(&init32, (void __user *)arg, sizeof(init32)))
67 return -EFAULT;
68
69 init.func = init32.func;
70 init.sarea_priv_offset = init32.sarea_priv_offset;
71 memcpy(&init.chipset, &init32.chipset,
72 offsetof(drm_mga_init_t, fb_offset) -
73 offsetof(drm_mga_init_t, chipset));
74 init.fb_offset = init32.fb_offset;
75 init.mmio_offset = init32.mmio_offset;
76 init.status_offset = init32.status_offset;
77 init.warp_offset = init32.warp_offset;
78 init.primary_offset = init32.primary_offset;
79 init.buffers_offset = init32.buffers_offset;
80
81 return drm_ioctl_kernel(file, mga_dma_init, &init,
82 DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY);
83}
84
85typedef struct drm_mga_getparam32 {
86 int param;
87 u32 value;
88} drm_mga_getparam32_t;
89
90static int compat_mga_getparam(struct file *file, unsigned int cmd,
91 unsigned long arg)
92{
93 drm_mga_getparam32_t getparam32;
94 drm_mga_getparam_t getparam;
95
96 if (copy_from_user(&getparam32, (void __user *)arg, sizeof(getparam32)))
97 return -EFAULT;
98
99 getparam.param = getparam32.param;
100 getparam.value = compat_ptr(getparam32.value);
101 return drm_ioctl_kernel(file, mga_getparam, &getparam, DRM_AUTH);
102}
103
104typedef struct drm_mga_drm_bootstrap32 {
105 u32 texture_handle;
106 u32 texture_size;
107 u32 primary_size;
108 u32 secondary_bin_count;
109 u32 secondary_bin_size;
110 u32 agp_mode;
111 u8 agp_size;
112} drm_mga_dma_bootstrap32_t;
113
114static int compat_mga_dma_bootstrap(struct file *file, unsigned int cmd,
115 unsigned long arg)
116{
117 drm_mga_dma_bootstrap32_t dma_bootstrap32;
118 drm_mga_dma_bootstrap_t dma_bootstrap;
119 int err;
120
121 if (copy_from_user(&dma_bootstrap32, (void __user *)arg,
122 sizeof(dma_bootstrap32)))
123 return -EFAULT;
124
125 dma_bootstrap.texture_handle = dma_bootstrap32.texture_handle;
126 dma_bootstrap.texture_size = dma_bootstrap32.texture_size;
127 dma_bootstrap.primary_size = dma_bootstrap32.primary_size;
128 dma_bootstrap.secondary_bin_count = dma_bootstrap32.secondary_bin_count;
129 dma_bootstrap.secondary_bin_size = dma_bootstrap32.secondary_bin_size;
130 dma_bootstrap.agp_mode = dma_bootstrap32.agp_mode;
131 dma_bootstrap.agp_size = dma_bootstrap32.agp_size;
132
133 err = drm_ioctl_kernel(file, mga_dma_bootstrap, &dma_bootstrap,
134 DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY);
135 if (err)
136 return err;
137
138 dma_bootstrap32.texture_handle = dma_bootstrap.texture_handle;
139 dma_bootstrap32.texture_size = dma_bootstrap.texture_size;
140 dma_bootstrap32.primary_size = dma_bootstrap.primary_size;
141 dma_bootstrap32.secondary_bin_count = dma_bootstrap.secondary_bin_count;
142 dma_bootstrap32.secondary_bin_size = dma_bootstrap.secondary_bin_size;
143 dma_bootstrap32.agp_mode = dma_bootstrap.agp_mode;
144 dma_bootstrap32.agp_size = dma_bootstrap.agp_size;
145 if (copy_to_user((void __user *)arg, &dma_bootstrap32,
146 sizeof(dma_bootstrap32)))
147 return -EFAULT;
148
149 return 0;
150}
151
152static struct {
153 drm_ioctl_compat_t *fn;
154 char *name;
155} mga_compat_ioctls[] = {
156#define DRM_IOCTL32_DEF(n, f)[DRM_##n] = {.fn = f, .name = #n}
157 DRM_IOCTL32_DEF(MGA_INIT, compat_mga_init),
158 DRM_IOCTL32_DEF(MGA_GETPARAM, compat_mga_getparam),
159 DRM_IOCTL32_DEF(MGA_DMA_BOOTSTRAP, compat_mga_dma_bootstrap),
160};
161
162
163
164
165
166
167
168
169
170
171long mga_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
172{
173 unsigned int nr = DRM_IOCTL_NR(cmd);
174 struct drm_file *file_priv = filp->private_data;
175 drm_ioctl_compat_t *fn = NULL;
176 int ret;
177
178 if (nr < DRM_COMMAND_BASE)
179 return drm_compat_ioctl(filp, cmd, arg);
180
181 if (nr >= DRM_COMMAND_BASE + ARRAY_SIZE(mga_compat_ioctls))
182 return drm_ioctl(filp, cmd, arg);
183
184 fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE].fn;
185 if (!fn)
186 return drm_ioctl(filp, cmd, arg);
187
188 DRM_DEBUG("pid=%d, dev=0x%lx, auth=%d, %s\n",
189 task_pid_nr(current),
190 (long)old_encode_dev(file_priv->minor->kdev->devt),
191 file_priv->authenticated,
192 mga_compat_ioctls[nr - DRM_COMMAND_BASE].name);
193 ret = (*fn) (filp, cmd, arg);
194 if (ret)
195 DRM_DEBUG("ret = %d\n", ret);
196 return ret;
197}
198