blob: 709e90db8c4087dfcb782a51deab776271a7feb0 [file] [log] [blame]
Dave Airlie8ca7c1d2005-07-07 21:51:26 +10001/**
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>
Dave Airlie8ca7c1d2005-07-07 21:51:26 +100034
David Howells760285e2012-10-02 18:01:07 +010035#include <drm/drmP.h>
36#include <drm/mga_drm.h>
Dave Airlie8ca7c1d2005-07-07 21:51:26 +100037
38typedef struct drm32_mga_init {
39 int func;
Dave Airlieb5e89ed2005-09-25 14:28:13 +100040 u32 sarea_priv_offset;
Dave Airlie8ca7c1d2005-07-07 21:51:26 +100041 int chipset;
Dave Airlieb5e89ed2005-09-25 14:28:13 +100042 int sgram;
Dave Airlie8ca7c1d2005-07-07 21:51:26 +100043 unsigned int maccess;
Dave Airlieb5e89ed2005-09-25 14:28:13 +100044 unsigned int fb_cpp;
Dave Airlie8ca7c1d2005-07-07 21:51:26 +100045 unsigned int front_offset, front_pitch;
Dave Airlieb5e89ed2005-09-25 14:28:13 +100046 unsigned int back_offset, back_pitch;
47 unsigned int depth_cpp;
48 unsigned int depth_offset, depth_pitch;
49 unsigned int texture_offset[MGA_NR_TEX_HEAPS];
50 unsigned int texture_size[MGA_NR_TEX_HEAPS];
Dave Airlie8ca7c1d2005-07-07 21:51:26 +100051 u32 fb_offset;
52 u32 mmio_offset;
53 u32 status_offset;
54 u32 warp_offset;
55 u32 primary_offset;
56 u32 buffers_offset;
57} drm_mga_init32_t;
58
59static int compat_mga_init(struct file *file, unsigned int cmd,
60 unsigned long arg)
61{
62 drm_mga_init32_t init32;
63 drm_mga_init_t __user *init;
64 int err = 0, i;
Dave Airlieb5e89ed2005-09-25 14:28:13 +100065
Dave Airlie8ca7c1d2005-07-07 21:51:26 +100066 if (copy_from_user(&init32, (void __user *)arg, sizeof(init32)))
67 return -EFAULT;
Dave Airlieb5e89ed2005-09-25 14:28:13 +100068
Dave Airlie8ca7c1d2005-07-07 21:51:26 +100069 init = compat_alloc_user_space(sizeof(*init));
70 if (!access_ok(VERIFY_WRITE, init, sizeof(*init))
71 || __put_user(init32.func, &init->func)
72 || __put_user(init32.sarea_priv_offset, &init->sarea_priv_offset)
73 || __put_user(init32.chipset, &init->chipset)
74 || __put_user(init32.sgram, &init->sgram)
75 || __put_user(init32.maccess, &init->maccess)
76 || __put_user(init32.fb_cpp, &init->fb_cpp)
77 || __put_user(init32.front_offset, &init->front_offset)
78 || __put_user(init32.front_pitch, &init->front_pitch)
79 || __put_user(init32.back_offset, &init->back_offset)
80 || __put_user(init32.back_pitch, &init->back_pitch)
81 || __put_user(init32.depth_cpp, &init->depth_cpp)
82 || __put_user(init32.depth_offset, &init->depth_offset)
83 || __put_user(init32.depth_pitch, &init->depth_pitch)
84 || __put_user(init32.fb_offset, &init->fb_offset)
85 || __put_user(init32.mmio_offset, &init->mmio_offset)
86 || __put_user(init32.status_offset, &init->status_offset)
87 || __put_user(init32.warp_offset, &init->warp_offset)
88 || __put_user(init32.primary_offset, &init->primary_offset)
89 || __put_user(init32.buffers_offset, &init->buffers_offset))
90 return -EFAULT;
Dave Airlieb5e89ed2005-09-25 14:28:13 +100091
92 for (i = 0; i < MGA_NR_TEX_HEAPS; i++) {
93 err |=
94 __put_user(init32.texture_offset[i],
95 &init->texture_offset[i]);
96 err |=
97 __put_user(init32.texture_size[i], &init->texture_size[i]);
Dave Airlie8ca7c1d2005-07-07 21:51:26 +100098 }
99 if (err)
100 return -EFAULT;
Dave Airlie8ca7c1d2005-07-07 21:51:26 +1000101
Arnd Bergmanned8b6702009-12-16 22:17:09 +0000102 return drm_ioctl(file, DRM_IOCTL_MGA_INIT, (unsigned long)init);
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000103}
Dave Airlie8ca7c1d2005-07-07 21:51:26 +1000104
105typedef struct drm_mga_getparam32 {
106 int param;
107 u32 value;
108} drm_mga_getparam32_t;
109
Dave Airlie8ca7c1d2005-07-07 21:51:26 +1000110static int compat_mga_getparam(struct file *file, unsigned int cmd,
111 unsigned long arg)
112{
113 drm_mga_getparam32_t getparam32;
114 drm_mga_getparam_t __user *getparam;
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000115
Dave Airlie8ca7c1d2005-07-07 21:51:26 +1000116 if (copy_from_user(&getparam32, (void __user *)arg, sizeof(getparam32)))
117 return -EFAULT;
118
119 getparam = compat_alloc_user_space(sizeof(*getparam));
120 if (!access_ok(VERIFY_WRITE, getparam, sizeof(*getparam))
121 || __put_user(getparam32.param, &getparam->param)
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000122 || __put_user((void __user *)(unsigned long)getparam32.value,
123 &getparam->value))
Dave Airlie8ca7c1d2005-07-07 21:51:26 +1000124 return -EFAULT;
125
Arnd Bergmanned8b6702009-12-16 22:17:09 +0000126 return drm_ioctl(file, DRM_IOCTL_MGA_GETPARAM, (unsigned long)getparam);
Dave Airlie8ca7c1d2005-07-07 21:51:26 +1000127}
128
Dave Airlied1f2b552005-08-05 22:11:22 +1000129typedef struct drm_mga_drm_bootstrap32 {
130 u32 texture_handle;
131 u32 texture_size;
132 u32 primary_size;
133 u32 secondary_bin_count;
134 u32 secondary_bin_size;
135 u32 agp_mode;
136 u8 agp_size;
137} drm_mga_dma_bootstrap32_t;
138
139static int compat_mga_dma_bootstrap(struct file *file, unsigned int cmd,
140 unsigned long arg)
141{
142 drm_mga_dma_bootstrap32_t dma_bootstrap32;
143 drm_mga_dma_bootstrap_t __user *dma_bootstrap;
144 int err;
145
146 if (copy_from_user(&dma_bootstrap32, (void __user *)arg,
147 sizeof(dma_bootstrap32)))
148 return -EFAULT;
149
150 dma_bootstrap = compat_alloc_user_space(sizeof(*dma_bootstrap));
151 if (!access_ok(VERIFY_WRITE, dma_bootstrap, sizeof(*dma_bootstrap))
152 || __put_user(dma_bootstrap32.texture_handle,
153 &dma_bootstrap->texture_handle)
154 || __put_user(dma_bootstrap32.texture_size,
155 &dma_bootstrap->texture_size)
156 || __put_user(dma_bootstrap32.primary_size,
157 &dma_bootstrap->primary_size)
158 || __put_user(dma_bootstrap32.secondary_bin_count,
159 &dma_bootstrap->secondary_bin_count)
160 || __put_user(dma_bootstrap32.secondary_bin_size,
161 &dma_bootstrap->secondary_bin_size)
162 || __put_user(dma_bootstrap32.agp_mode, &dma_bootstrap->agp_mode)
163 || __put_user(dma_bootstrap32.agp_size, &dma_bootstrap->agp_size))
164 return -EFAULT;
165
Arnd Bergmanned8b6702009-12-16 22:17:09 +0000166 err = drm_ioctl(file, DRM_IOCTL_MGA_DMA_BOOTSTRAP,
Dave Airlied1f2b552005-08-05 22:11:22 +1000167 (unsigned long)dma_bootstrap);
168 if (err)
169 return err;
170
171 if (__get_user(dma_bootstrap32.texture_handle,
172 &dma_bootstrap->texture_handle)
173 || __get_user(dma_bootstrap32.texture_size,
174 &dma_bootstrap->texture_size)
175 || __get_user(dma_bootstrap32.primary_size,
176 &dma_bootstrap->primary_size)
177 || __get_user(dma_bootstrap32.secondary_bin_count,
178 &dma_bootstrap->secondary_bin_count)
179 || __get_user(dma_bootstrap32.secondary_bin_size,
180 &dma_bootstrap->secondary_bin_size)
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000181 || __get_user(dma_bootstrap32.agp_mode, &dma_bootstrap->agp_mode)
182 || __get_user(dma_bootstrap32.agp_size, &dma_bootstrap->agp_size))
Dave Airlied1f2b552005-08-05 22:11:22 +1000183 return -EFAULT;
184
185 if (copy_to_user((void __user *)arg, &dma_bootstrap32,
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000186 sizeof(dma_bootstrap32)))
Dave Airlied1f2b552005-08-05 22:11:22 +1000187 return -EFAULT;
188
189 return 0;
190}
191
Dave Airlie8ca7c1d2005-07-07 21:51:26 +1000192drm_ioctl_compat_t *mga_compat_ioctls[] = {
193 [DRM_MGA_INIT] = compat_mga_init,
194 [DRM_MGA_GETPARAM] = compat_mga_getparam,
Dave Airlied1f2b552005-08-05 22:11:22 +1000195 [DRM_MGA_DMA_BOOTSTRAP] = compat_mga_dma_bootstrap,
Dave Airlie8ca7c1d2005-07-07 21:51:26 +1000196};
197
198/**
199 * Called whenever a 32-bit process running under a 64-bit kernel
200 * performs an ioctl on /dev/dri/card<n>.
201 *
202 * \param filp file pointer.
203 * \param cmd command.
204 * \param arg user argument.
205 * \return zero on success or negative number on failure.
206 */
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000207long mga_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
Dave Airlie8ca7c1d2005-07-07 21:51:26 +1000208{
209 unsigned int nr = DRM_IOCTL_NR(cmd);
210 drm_ioctl_compat_t *fn = NULL;
211 int ret;
212
213 if (nr < DRM_COMMAND_BASE)
214 return drm_compat_ioctl(filp, cmd, arg);
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000215
Dave Airlie8ca7c1d2005-07-07 21:51:26 +1000216 if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls))
217 fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
218
Dave Airlie8ca7c1d2005-07-07 21:51:26 +1000219 if (fn != NULL)
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000220 ret = (*fn) (filp, cmd, arg);
Dave Airlie8ca7c1d2005-07-07 21:51:26 +1000221 else
Arnd Bergmanned8b6702009-12-16 22:17:09 +0000222 ret = drm_ioctl(filp, cmd, arg);
Dave Airlie8ca7c1d2005-07-07 21:51:26 +1000223
224 return ret;
225}