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}
v4.17
 1/*
 
 
 2 * 32-bit ioctl compatibility routines for the i915 DRM.
 3 *
 
 
 
 4 * Copyright (C) Paul Mackerras 2005
 5 * Copyright (C) Alan Hourihane 2005
 6 * All Rights Reserved.
 7 *
 8 * Permission is hereby granted, free of charge, to any person obtaining a
 9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice (including the next
16 * paragraph) shall be included in all copies or substantial portions of the
17 * Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
22 * THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
25 * IN THE SOFTWARE.
26 *
27 * Author: Alan Hourihane <alanh@fairlite.demon.co.uk>
28 */
29#include <linux/compat.h>
30
31#include <drm/drmP.h>
32#include <drm/i915_drm.h>
33#include "i915_drv.h"
34
35struct drm_i915_getparam32 {
36	s32 param;
37	/*
38	 * We screwed up the generic ioctl struct here and used a variable-sized
39	 * pointer. Use u32 in the compat struct to match the 32bit pointer
40	 * userspace expects.
41	 */
42	u32 value;
43};
44
45static int compat_i915_getparam(struct file *file, unsigned int cmd,
46				unsigned long arg)
47{
48	struct drm_i915_getparam32 req32;
49	drm_i915_getparam_t __user *request;
50
51	if (copy_from_user(&req32, (void __user *)arg, sizeof(req32)))
52		return -EFAULT;
53
54	request = compat_alloc_user_space(sizeof(*request));
55	if (!access_ok(VERIFY_WRITE, request, sizeof(*request)) ||
56	    __put_user(req32.param, &request->param) ||
57	    __put_user((void __user *)(unsigned long)req32.value,
58		       &request->value))
59		return -EFAULT;
60
61	return drm_ioctl(file, DRM_IOCTL_I915_GETPARAM,
62			 (unsigned long)request);
63}
64
65static drm_ioctl_compat_t *i915_compat_ioctls[] = {
66	[DRM_I915_GETPARAM] = compat_i915_getparam,
67};
68
69/**
70 * i915_compat_ioctl - handle the mistakes of the past
71 * @filp: the file pointer
72 * @cmd: the ioctl command (and encoded flags)
73 * @arg: the ioctl argument (from userspace)
74 *
75 * Called whenever a 32-bit process running under a 64-bit kernel
76 * performs an ioctl on /dev/dri/card<n>.
 
 
 
 
 
77 */
78long i915_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
79{
80	unsigned int nr = DRM_IOCTL_NR(cmd);
81	drm_ioctl_compat_t *fn = NULL;
82	int ret;
83
84	if (nr < DRM_COMMAND_BASE || nr >= DRM_COMMAND_END)
85		return drm_compat_ioctl(filp, cmd, arg);
86
87	if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(i915_compat_ioctls))
88		fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
89
90	if (fn != NULL)
91		ret = (*fn) (filp, cmd, arg);
92	else
93		ret = drm_ioctl(filp, cmd, arg);
94
95	return ret;
96}