Path: blob/master/drivers/gpu/drm/r128/r128_ioc32.c
15112 views
/**1* \file r128_ioc32.c2*3* 32-bit ioctl compatibility routines for the R128 DRM.4*5* \author Dave Airlie <[email protected]> with code from patches by Egbert Eich6*7* Copyright (C) Paul Mackerras 20058* Copyright (C) Egbert Eich 2003,20049* Copyright (C) Dave Airlie 200510* All Rights Reserved.11*12* Permission is hereby granted, free of charge, to any person obtaining a13* copy of this software and associated documentation files (the "Software"),14* to deal in the Software without restriction, including without limitation15* the rights to use, copy, modify, merge, publish, distribute, sublicense,16* and/or sell copies of the Software, and to permit persons to whom the17* Software is furnished to do so, subject to the following conditions:18*19* The above copyright notice and this permission notice (including the next20* paragraph) shall be included in all copies or substantial portions of the21* Software.22*23* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR24* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,25* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL26* THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,27* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,28* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS29* IN THE SOFTWARE.30*/31#include <linux/compat.h>3233#include "drmP.h"34#include "drm.h"35#include "r128_drm.h"3637typedef struct drm_r128_init32 {38int func;39unsigned int sarea_priv_offset;40int is_pci;41int cce_mode;42int cce_secure;43int ring_size;44int usec_timeout;4546unsigned int fb_bpp;47unsigned int front_offset, front_pitch;48unsigned int back_offset, back_pitch;49unsigned int depth_bpp;50unsigned int depth_offset, depth_pitch;51unsigned int span_offset;5253unsigned int fb_offset;54unsigned int mmio_offset;55unsigned int ring_offset;56unsigned int ring_rptr_offset;57unsigned int buffers_offset;58unsigned int agp_textures_offset;59} drm_r128_init32_t;6061static int compat_r128_init(struct file *file, unsigned int cmd,62unsigned long arg)63{64drm_r128_init32_t init32;65drm_r128_init_t __user *init;6667if (copy_from_user(&init32, (void __user *)arg, sizeof(init32)))68return -EFAULT;6970init = compat_alloc_user_space(sizeof(*init));71if (!access_ok(VERIFY_WRITE, init, sizeof(*init))72|| __put_user(init32.func, &init->func)73|| __put_user(init32.sarea_priv_offset, &init->sarea_priv_offset)74|| __put_user(init32.is_pci, &init->is_pci)75|| __put_user(init32.cce_mode, &init->cce_mode)76|| __put_user(init32.cce_secure, &init->cce_secure)77|| __put_user(init32.ring_size, &init->ring_size)78|| __put_user(init32.usec_timeout, &init->usec_timeout)79|| __put_user(init32.fb_bpp, &init->fb_bpp)80|| __put_user(init32.front_offset, &init->front_offset)81|| __put_user(init32.front_pitch, &init->front_pitch)82|| __put_user(init32.back_offset, &init->back_offset)83|| __put_user(init32.back_pitch, &init->back_pitch)84|| __put_user(init32.depth_bpp, &init->depth_bpp)85|| __put_user(init32.depth_offset, &init->depth_offset)86|| __put_user(init32.depth_pitch, &init->depth_pitch)87|| __put_user(init32.span_offset, &init->span_offset)88|| __put_user(init32.fb_offset, &init->fb_offset)89|| __put_user(init32.mmio_offset, &init->mmio_offset)90|| __put_user(init32.ring_offset, &init->ring_offset)91|| __put_user(init32.ring_rptr_offset, &init->ring_rptr_offset)92|| __put_user(init32.buffers_offset, &init->buffers_offset)93|| __put_user(init32.agp_textures_offset,94&init->agp_textures_offset))95return -EFAULT;9697return drm_ioctl(file, DRM_IOCTL_R128_INIT, (unsigned long)init);98}99100typedef struct drm_r128_depth32 {101int func;102int n;103u32 x;104u32 y;105u32 buffer;106u32 mask;107} drm_r128_depth32_t;108109static int compat_r128_depth(struct file *file, unsigned int cmd,110unsigned long arg)111{112drm_r128_depth32_t depth32;113drm_r128_depth_t __user *depth;114115if (copy_from_user(&depth32, (void __user *)arg, sizeof(depth32)))116return -EFAULT;117118depth = compat_alloc_user_space(sizeof(*depth));119if (!access_ok(VERIFY_WRITE, depth, sizeof(*depth))120|| __put_user(depth32.func, &depth->func)121|| __put_user(depth32.n, &depth->n)122|| __put_user((int __user *)(unsigned long)depth32.x, &depth->x)123|| __put_user((int __user *)(unsigned long)depth32.y, &depth->y)124|| __put_user((unsigned int __user *)(unsigned long)depth32.buffer,125&depth->buffer)126|| __put_user((unsigned char __user *)(unsigned long)depth32.mask,127&depth->mask))128return -EFAULT;129130return drm_ioctl(file, DRM_IOCTL_R128_DEPTH, (unsigned long)depth);131132}133134typedef struct drm_r128_stipple32 {135u32 mask;136} drm_r128_stipple32_t;137138static int compat_r128_stipple(struct file *file, unsigned int cmd,139unsigned long arg)140{141drm_r128_stipple32_t stipple32;142drm_r128_stipple_t __user *stipple;143144if (copy_from_user(&stipple32, (void __user *)arg, sizeof(stipple32)))145return -EFAULT;146147stipple = compat_alloc_user_space(sizeof(*stipple));148if (!access_ok(VERIFY_WRITE, stipple, sizeof(*stipple))149|| __put_user((unsigned int __user *)(unsigned long)stipple32.mask,150&stipple->mask))151return -EFAULT;152153return drm_ioctl(file, DRM_IOCTL_R128_STIPPLE, (unsigned long)stipple);154}155156typedef struct drm_r128_getparam32 {157int param;158u32 value;159} drm_r128_getparam32_t;160161static int compat_r128_getparam(struct file *file, unsigned int cmd,162unsigned long arg)163{164drm_r128_getparam32_t getparam32;165drm_r128_getparam_t __user *getparam;166167if (copy_from_user(&getparam32, (void __user *)arg, sizeof(getparam32)))168return -EFAULT;169170getparam = compat_alloc_user_space(sizeof(*getparam));171if (!access_ok(VERIFY_WRITE, getparam, sizeof(*getparam))172|| __put_user(getparam32.param, &getparam->param)173|| __put_user((void __user *)(unsigned long)getparam32.value,174&getparam->value))175return -EFAULT;176177return drm_ioctl(file, DRM_IOCTL_R128_GETPARAM, (unsigned long)getparam);178}179180drm_ioctl_compat_t *r128_compat_ioctls[] = {181[DRM_R128_INIT] = compat_r128_init,182[DRM_R128_DEPTH] = compat_r128_depth,183[DRM_R128_STIPPLE] = compat_r128_stipple,184[DRM_R128_GETPARAM] = compat_r128_getparam,185};186187/**188* Called whenever a 32-bit process running under a 64-bit kernel189* performs an ioctl on /dev/dri/card<n>.190*191* \param filp file pointer.192* \param cmd command.193* \param arg user argument.194* \return zero on success or negative number on failure.195*/196long r128_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)197{198unsigned int nr = DRM_IOCTL_NR(cmd);199drm_ioctl_compat_t *fn = NULL;200int ret;201202if (nr < DRM_COMMAND_BASE)203return drm_compat_ioctl(filp, cmd, arg);204205if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls))206fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];207208if (fn != NULL)209ret = (*fn) (filp, cmd, arg);210else211ret = drm_ioctl(filp, cmd, arg);212213return ret;214}215216217