drm_ioctl.h
上传用户:lgb322
上传日期:2013-02-24
资源大小:30529k
文件大小:6k
源码类别:

嵌入式Linux

开发平台:

Unix_Linux

  1. /* drm_ioctl.h -- IOCTL processing for DRM -*- linux-c -*-
  2.  * Created: Fri Jan  8 09:01:26 1999 by faith@valinux.com
  3.  *
  4.  * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
  5.  * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
  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.  * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
  23.  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  24.  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  25.  * OTHER DEALINGS IN THE SOFTWARE.
  26.  *
  27.  * Authors:
  28.  *    Rickard E. (Rik) Faith <faith@valinux.com>
  29.  *    Gareth Hughes <gareth@valinux.com>
  30.  */
  31. #define __NO_VERSION__
  32. #include "drmP.h"
  33. int DRM(irq_busid)(struct inode *inode, struct file *filp,
  34.    unsigned int cmd, unsigned long arg)
  35. {
  36. drm_irq_busid_t p;
  37. struct pci_dev *dev;
  38. if (copy_from_user(&p, (drm_irq_busid_t *)arg, sizeof(p)))
  39. return -EFAULT;
  40. dev = pci_find_slot(p.busnum, PCI_DEVFN(p.devnum, p.funcnum));
  41. if (dev) p.irq = dev->irq;
  42. else  p.irq = 0;
  43. DRM_DEBUG("%d:%d:%d => IRQ %dn",
  44.   p.busnum, p.devnum, p.funcnum, p.irq);
  45. if (copy_to_user((drm_irq_busid_t *)arg, &p, sizeof(p)))
  46. return -EFAULT;
  47. return 0;
  48. }
  49. int DRM(getunique)(struct inode *inode, struct file *filp,
  50.    unsigned int cmd, unsigned long arg)
  51. {
  52. drm_file_t  *priv  = filp->private_data;
  53. drm_device_t  *dev  = priv->dev;
  54. drm_unique_t  u;
  55. if (copy_from_user(&u, (drm_unique_t *)arg, sizeof(u)))
  56. return -EFAULT;
  57. if (u.unique_len >= dev->unique_len) {
  58. if (copy_to_user(u.unique, dev->unique, dev->unique_len))
  59. return -EFAULT;
  60. }
  61. u.unique_len = dev->unique_len;
  62. if (copy_to_user((drm_unique_t *)arg, &u, sizeof(u)))
  63. return -EFAULT;
  64. return 0;
  65. }
  66. int DRM(setunique)(struct inode *inode, struct file *filp,
  67.    unsigned int cmd, unsigned long arg)
  68. {
  69. drm_file_t  *priv  = filp->private_data;
  70. drm_device_t  *dev  = priv->dev;
  71. drm_unique_t  u;
  72. if (dev->unique_len || dev->unique) return -EBUSY;
  73. if (copy_from_user(&u, (drm_unique_t *)arg, sizeof(u))) return -EFAULT;
  74. if (!u.unique_len || u.unique_len > 1024) return -EINVAL;
  75. dev->unique_len = u.unique_len;
  76. dev->unique = DRM(alloc)(u.unique_len + 1, DRM_MEM_DRIVER);
  77. if(!dev->unique) return -ENOMEM;
  78. if (copy_from_user(dev->unique, u.unique, dev->unique_len))
  79. return -EFAULT;
  80. dev->unique[dev->unique_len] = '';
  81. dev->devname = DRM(alloc)(strlen(dev->name) + strlen(dev->unique) + 2,
  82.   DRM_MEM_DRIVER);
  83. if(!dev->devname) {
  84. DRM(free)(dev->devname, sizeof(*dev->devname), DRM_MEM_DRIVER);
  85. return -ENOMEM;
  86. }
  87. sprintf(dev->devname, "%s@%s", dev->name, dev->unique);
  88. do {
  89. struct pci_dev *pci_dev;
  90.                 int b, d, f;
  91.                 char *p;
  92.  
  93.                 for(p = dev->unique; p && *p && *p != ':'; p++);
  94.                 if (!p || !*p) break;
  95.                 b = (int)simple_strtoul(p+1, &p, 10);
  96.                 if (*p != ':') break;
  97.                 d = (int)simple_strtoul(p+1, &p, 10);
  98.                 if (*p != ':') break;
  99.                 f = (int)simple_strtoul(p+1, &p, 10);
  100.                 if (*p) break;
  101.  
  102.                 pci_dev = pci_find_slot(b, PCI_DEVFN(d,f));
  103.                 if (pci_dev) {
  104. dev->pdev = pci_dev;
  105. #ifdef __alpha__
  106. dev->hose = pci_dev->sysdata;
  107. #endif
  108. }
  109.         } while(0);
  110. return 0;
  111. }
  112. int DRM(getmap)( struct inode *inode, struct file *filp,
  113.  unsigned int cmd, unsigned long arg )
  114. {
  115. drm_file_t   *priv = filp->private_data;
  116. drm_device_t *dev  = priv->dev;
  117. drm_map_t    map;
  118. drm_map_list_t *r_list = NULL;
  119. struct list_head *list;
  120. int          idx;
  121. int      i;
  122. if (copy_from_user(&map, (drm_map_t *)arg, sizeof(map)))
  123. return -EFAULT;
  124. idx = map.offset;
  125. down(&dev->struct_sem);
  126. if (idx < 0 || idx >= dev->map_count) {
  127. up(&dev->struct_sem);
  128. return -EINVAL;
  129. }
  130. i = 0;
  131. list_for_each(list, &dev->maplist->head) {
  132. if(i == idx) {
  133. r_list = (drm_map_list_t *)list;
  134. break;
  135. }
  136. i++;
  137. }
  138. if(!r_list || !r_list->map) {
  139. up(&dev->struct_sem);
  140. return -EINVAL;
  141. }
  142. map.offset = r_list->map->offset;
  143. map.size   = r_list->map->size;
  144. map.type   = r_list->map->type;
  145. map.flags  = r_list->map->flags;
  146. map.handle = r_list->map->handle;
  147. map.mtrr   = r_list->map->mtrr;
  148. up(&dev->struct_sem);
  149. if (copy_to_user((drm_map_t *)arg, &map, sizeof(map))) return -EFAULT;
  150. return 0;
  151. }
  152. int DRM(getclient)( struct inode *inode, struct file *filp,
  153.     unsigned int cmd, unsigned long arg )
  154. {
  155. drm_file_t   *priv = filp->private_data;
  156. drm_device_t *dev  = priv->dev;
  157. drm_client_t client;
  158. drm_file_t   *pt;
  159. int          idx;
  160. int          i;
  161. if (copy_from_user(&client, (drm_client_t *)arg, sizeof(client)))
  162. return -EFAULT;
  163. idx = client.idx;
  164. down(&dev->struct_sem);
  165. for (i = 0, pt = dev->file_first; i < idx && pt; i++, pt = pt->next)
  166. ;
  167. if (!pt) {
  168. up(&dev->struct_sem);
  169. return -EINVAL;
  170. }
  171. client.auth  = pt->authenticated;
  172. client.pid   = pt->pid;
  173. client.uid   = pt->uid;
  174. client.magic = pt->magic;
  175. client.iocs  = pt->ioctl_count;
  176. up(&dev->struct_sem);
  177. if (copy_to_user((drm_client_t *)arg, &client, sizeof(client)))
  178. return -EFAULT;
  179. return 0;
  180. }
  181. int DRM(getstats)( struct inode *inode, struct file *filp,
  182.    unsigned int cmd, unsigned long arg )
  183. {
  184. drm_file_t   *priv = filp->private_data;
  185. drm_device_t *dev  = priv->dev;
  186. drm_stats_t  stats;
  187. int          i;
  188. memset(&stats, 0, sizeof(stats));
  189. down(&dev->struct_sem);
  190. for (i = 0; i < dev->counters; i++) {
  191. if (dev->types[i] == _DRM_STAT_LOCK)
  192. stats.data[i].value
  193. = (dev->lock.hw_lock
  194.    ? dev->lock.hw_lock->lock : 0);
  195. else 
  196. stats.data[i].value = atomic_read(&dev->counts[i]);
  197. stats.data[i].type  = dev->types[i];
  198. }
  199. stats.count = dev->counters;
  200. up(&dev->struct_sem);
  201. if (copy_to_user((drm_stats_t *)arg, &stats, sizeof(stats)))
  202. return -EFAULT;
  203. return 0;
  204. }