Linux Audio

Check our new training course

Loading...
v4.6
 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
34#include <drm/drmP.h>
35#include <drm/i915_drm.h>
 
36#include "i915_drv.h"
37
38struct drm_i915_getparam32 {
39	s32 param;
40	/*
41	 * We screwed up the generic ioctl struct here and used a variable-sized
42	 * pointer. Use u32 in the compat struct to match the 32bit pointer
43	 * userspace expects.
44	 */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45	u32 value;
46};
47
48static int compat_i915_getparam(struct file *file, unsigned int cmd,
49				unsigned long arg)
50{
51	struct drm_i915_getparam32 req32;
52	drm_i915_getparam_t __user *request;
53
54	if (copy_from_user(&req32, (void __user *)arg, sizeof(req32)))
55		return -EFAULT;
56
57	request = compat_alloc_user_space(sizeof(*request));
58	if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
59	    || __put_user(req32.param, &request->param)
60	    || __put_user((void __user *)(unsigned long)req32.value,
61			  &request->value))
62		return -EFAULT;
63
64	return drm_ioctl(file, DRM_IOCTL_I915_GETPARAM,
65			 (unsigned long)request);
66}
67
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
68static drm_ioctl_compat_t *i915_compat_ioctls[] = {
 
 
69	[DRM_I915_GETPARAM] = compat_i915_getparam,
 
 
70};
71
 
72/**
73 * Called whenever a 32-bit process running under a 64-bit kernel
74 * performs an ioctl on /dev/dri/card<n>.
75 *
76 * \param filp file pointer.
77 * \param cmd command.
78 * \param arg user argument.
79 * \return zero on success or negative number on failure.
80 */
81long i915_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
82{
83	unsigned int nr = DRM_IOCTL_NR(cmd);
84	drm_ioctl_compat_t *fn = NULL;
85	int ret;
86
87	if (nr < DRM_COMMAND_BASE || nr >= DRM_COMMAND_END)
88		return drm_compat_ioctl(filp, cmd, arg);
89
90	if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(i915_compat_ioctls))
91		fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
92
93	if (fn != NULL)
94		ret = (*fn) (filp, cmd, arg);
95	else
96		ret = drm_ioctl(filp, cmd, arg);
97
98	return ret;
99}
v3.5.6
  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
 34#include "drmP.h"
 35#include "drm.h"
 36#include "i915_drm.h"
 37#include "i915_drv.h"
 38
 39typedef 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
 48static 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
 55	    (&batchbuffer32, (void __user *)arg, sizeof(batchbuffer32)))
 56		return -EFAULT;
 57
 58	batchbuffer = compat_alloc_user_space(sizeof(*batchbuffer));
 59	if (!access_ok(VERIFY_WRITE, batchbuffer, sizeof(*batchbuffer))
 60	    || __put_user(batchbuffer32.start, &batchbuffer->start)
 61	    || __put_user(batchbuffer32.used, &batchbuffer->used)
 62	    || __put_user(batchbuffer32.DR1, &batchbuffer->DR1)
 63	    || __put_user(batchbuffer32.DR4, &batchbuffer->DR4)
 64	    || __put_user(batchbuffer32.num_cliprects,
 65			  &batchbuffer->num_cliprects)
 66	    || __put_user((int __user *)(unsigned long)batchbuffer32.cliprects,
 67			  &batchbuffer->cliprects))
 68		return -EFAULT;
 69
 70	return drm_ioctl(file, DRM_IOCTL_I915_BATCHBUFFER,
 71			 (unsigned long)batchbuffer);
 72}
 73
 74typedef struct _drm_i915_cmdbuffer32 {
 75	u32 buf;		/* pointer to userspace command buffer */
 76	int sz;			/* nr bytes in buf */
 77	int DR1;		/* hw flags for GFX_OP_DRAWRECT_INFO */
 78	int DR4;		/* window origin for GFX_OP_DRAWRECT_INFO */
 79	int num_cliprects;	/* mulitpass with multiple cliprects? */
 80	u32 cliprects;		/* pointer to userspace cliprects */
 81} drm_i915_cmdbuffer32_t;
 82
 83static int compat_i915_cmdbuffer(struct file *file, unsigned int cmd,
 84				 unsigned long arg)
 85{
 86	drm_i915_cmdbuffer32_t cmdbuffer32;
 87	drm_i915_cmdbuffer_t __user *cmdbuffer;
 88
 89	if (copy_from_user
 90	    (&cmdbuffer32, (void __user *)arg, sizeof(cmdbuffer32)))
 91		return -EFAULT;
 92
 93	cmdbuffer = compat_alloc_user_space(sizeof(*cmdbuffer));
 94	if (!access_ok(VERIFY_WRITE, cmdbuffer, sizeof(*cmdbuffer))
 95	    || __put_user((int __user *)(unsigned long)cmdbuffer32.buf,
 96			  &cmdbuffer->buf)
 97	    || __put_user(cmdbuffer32.sz, &cmdbuffer->sz)
 98	    || __put_user(cmdbuffer32.DR1, &cmdbuffer->DR1)
 99	    || __put_user(cmdbuffer32.DR4, &cmdbuffer->DR4)
100	    || __put_user(cmdbuffer32.num_cliprects, &cmdbuffer->num_cliprects)
101	    || __put_user((int __user *)(unsigned long)cmdbuffer32.cliprects,
102			  &cmdbuffer->cliprects))
103		return -EFAULT;
104
105	return drm_ioctl(file, DRM_IOCTL_I915_CMDBUFFER,
106			 (unsigned long)cmdbuffer);
107}
108
109typedef struct drm_i915_irq_emit32 {
110	u32 irq_seq;
111} drm_i915_irq_emit32_t;
112
113static int compat_i915_irq_emit(struct file *file, unsigned int cmd,
114				unsigned long arg)
115{
116	drm_i915_irq_emit32_t req32;
117	drm_i915_irq_emit_t __user *request;
118
119	if (copy_from_user(&req32, (void __user *)arg, sizeof(req32)))
120		return -EFAULT;
121
122	request = compat_alloc_user_space(sizeof(*request));
123	if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
124	    || __put_user((int __user *)(unsigned long)req32.irq_seq,
125			  &request->irq_seq))
126		return -EFAULT;
127
128	return drm_ioctl(file, DRM_IOCTL_I915_IRQ_EMIT,
129			 (unsigned long)request);
130}
131typedef struct drm_i915_getparam32 {
132	int param;
133	u32 value;
134} drm_i915_getparam32_t;
135
136static int compat_i915_getparam(struct file *file, unsigned int cmd,
137				unsigned long arg)
138{
139	drm_i915_getparam32_t req32;
140	drm_i915_getparam_t __user *request;
141
142	if (copy_from_user(&req32, (void __user *)arg, sizeof(req32)))
143		return -EFAULT;
144
145	request = compat_alloc_user_space(sizeof(*request));
146	if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
147	    || __put_user(req32.param, &request->param)
148	    || __put_user((void __user *)(unsigned long)req32.value,
149			  &request->value))
150		return -EFAULT;
151
152	return drm_ioctl(file, DRM_IOCTL_I915_GETPARAM,
153			 (unsigned long)request);
154}
155
156typedef struct drm_i915_mem_alloc32 {
157	int region;
158	int alignment;
159	int size;
160	u32 region_offset;	/* offset from start of fb or agp */
161} drm_i915_mem_alloc32_t;
162
163static int compat_i915_alloc(struct file *file, unsigned int cmd,
164			     unsigned long arg)
165{
166	drm_i915_mem_alloc32_t req32;
167	drm_i915_mem_alloc_t __user *request;
168
169	if (copy_from_user(&req32, (void __user *)arg, sizeof(req32)))
170		return -EFAULT;
171
172	request = compat_alloc_user_space(sizeof(*request));
173	if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
174	    || __put_user(req32.region, &request->region)
175	    || __put_user(req32.alignment, &request->alignment)
176	    || __put_user(req32.size, &request->size)
177	    || __put_user((void __user *)(unsigned long)req32.region_offset,
178			  &request->region_offset))
179		return -EFAULT;
180
181	return drm_ioctl(file, DRM_IOCTL_I915_ALLOC,
182			 (unsigned long)request);
183}
184
185static drm_ioctl_compat_t *i915_compat_ioctls[] = {
186	[DRM_I915_BATCHBUFFER] = compat_i915_batchbuffer,
187	[DRM_I915_CMDBUFFER] = compat_i915_cmdbuffer,
188	[DRM_I915_GETPARAM] = compat_i915_getparam,
189	[DRM_I915_IRQ_EMIT] = compat_i915_irq_emit,
190	[DRM_I915_ALLOC] = compat_i915_alloc
191};
192
193#ifdef CONFIG_COMPAT
194/**
195 * Called whenever a 32-bit process running under a 64-bit kernel
196 * performs an ioctl on /dev/dri/card<n>.
197 *
198 * \param filp file pointer.
199 * \param cmd command.
200 * \param arg user argument.
201 * \return zero on success or negative number on failure.
202 */
203long i915_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
204{
205	unsigned int nr = DRM_IOCTL_NR(cmd);
206	drm_ioctl_compat_t *fn = NULL;
207	int ret;
208
209	if (nr < DRM_COMMAND_BASE)
210		return drm_compat_ioctl(filp, cmd, arg);
211
212	if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls))
213		fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
214
215	if (fn != NULL)
216		ret = (*fn) (filp, cmd, arg);
217	else
218		ret = drm_ioctl(filp, cmd, arg);
219
220	return ret;
221}
222#endif