drm_ioctl.h
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:6k
源码类别:

Linux/Unix编程

开发平台:

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. #include "drmP.h"
  32. int DRM(irq_busid)(struct inode *inode, struct file *filp,
  33.    unsigned int cmd, unsigned long arg)
  34. {
  35. drm_irq_busid_t p;
  36. struct pci_dev *dev;
  37. if (copy_from_user(&p, (drm_irq_busid_t *)arg, sizeof(p)))
  38. return -EFAULT;
  39. dev = pci_find_slot(p.busnum, PCI_DEVFN(p.devnum, p.funcnum));
  40. if (dev) p.irq = dev->irq;
  41. else  p.irq = 0;
  42. DRM_DEBUG("%d:%d:%d => IRQ %dn",
  43.   p.busnum, p.devnum, p.funcnum, p.irq);
  44. if (copy_to_user((drm_irq_busid_t *)arg, &p, sizeof(p)))
  45. return -EFAULT;
  46. return 0;
  47. }
  48. int DRM(getunique)(struct inode *inode, struct file *filp,
  49.    unsigned int cmd, unsigned long arg)
  50. {
  51. drm_file_t  *priv  = filp->private_data;
  52. drm_device_t  *dev  = priv->dev;
  53. drm_unique_t  u;
  54. if (copy_from_user(&u, (drm_unique_t *)arg, sizeof(u)))
  55. return -EFAULT;
  56. if (u.unique_len >= dev->unique_len) {
  57. if (copy_to_user(u.unique, dev->unique, dev->unique_len))
  58. return -EFAULT;
  59. }
  60. u.unique_len = dev->unique_len;
  61. if (copy_to_user((drm_unique_t *)arg, &u, sizeof(u)))
  62. return -EFAULT;
  63. return 0;
  64. }
  65. int DRM(setunique)(struct inode *inode, struct file *filp,
  66.    unsigned int cmd, unsigned long arg)
  67. {
  68. drm_file_t  *priv  = filp->private_data;
  69. drm_device_t  *dev  = priv->dev;
  70. drm_unique_t  u;
  71. if (dev->unique_len || dev->unique) return -EBUSY;
  72. if (copy_from_user(&u, (drm_unique_t *)arg, sizeof(u))) return -EFAULT;
  73. if (!u.unique_len || u.unique_len > 1024) return -EINVAL;
  74. dev->unique_len = u.unique_len;
  75. dev->unique = DRM(alloc)(u.unique_len + 1, DRM_MEM_DRIVER);
  76. if(!dev->unique) return -ENOMEM;
  77. if (copy_from_user(dev->unique, u.unique, dev->unique_len))
  78. return -EFAULT;
  79. dev->unique[dev->unique_len] = '';
  80. dev->devname = DRM(alloc)(strlen(dev->name) + strlen(dev->unique) + 2,
  81.   DRM_MEM_DRIVER);
  82. if(!dev->devname) {
  83. DRM(free)(dev->devname, sizeof(*dev->devname), DRM_MEM_DRIVER);
  84. return -ENOMEM;
  85. }
  86. sprintf(dev->devname, "%s@%s", dev->name, dev->unique);
  87. do {
  88. struct pci_dev *pci_dev;
  89.                 int b, d, f;
  90.                 char *p;
  91.  
  92.                 for(p = dev->unique; p && *p && *p != ':'; p++);
  93.                 if (!p || !*p) break;
  94.                 b = (int)simple_strtoul(p+1, &p, 10);
  95.                 if (*p != ':') break;
  96.                 d = (int)simple_strtoul(p+1, &p, 10);
  97.                 if (*p != ':') break;
  98.                 f = (int)simple_strtoul(p+1, &p, 10);
  99.                 if (*p) break;
  100.  
  101.                 pci_dev = pci_find_slot(b, PCI_DEVFN(d,f));
  102.                 if (pci_dev) {
  103. dev->pdev = pci_dev;
  104. #ifdef __alpha__
  105. dev->hose = pci_dev->sysdata;
  106. #endif
  107. }
  108.         } while(0);
  109. return 0;
  110. }
  111. int DRM(getmap)( struct inode *inode, struct file *filp,
  112.  unsigned int cmd, unsigned long arg )
  113. {
  114. drm_file_t   *priv = filp->private_data;
  115. drm_device_t *dev  = priv->dev;
  116. drm_map_t    map;
  117. drm_map_list_t *r_list = NULL;
  118. struct list_head *list;
  119. int          idx;
  120. int      i;
  121. if (copy_from_user(&map, (drm_map_t *)arg, sizeof(map)))
  122. return -EFAULT;
  123. idx = map.offset;
  124. down(&dev->struct_sem);
  125. if (idx < 0 || idx >= dev->map_count) {
  126. up(&dev->struct_sem);
  127. return -EINVAL;
  128. }
  129. i = 0;
  130. list_for_each(list, &dev->maplist->head) {
  131. if(i == idx) {
  132. r_list = (drm_map_list_t *)list;
  133. break;
  134. }
  135. i++;
  136. }
  137. if(!r_list || !r_list->map) {
  138. up(&dev->struct_sem);
  139. return -EINVAL;
  140. }
  141. map.offset = r_list->map->offset;
  142. map.size   = r_list->map->size;
  143. map.type   = r_list->map->type;
  144. map.flags  = r_list->map->flags;
  145. map.handle = r_list->map->handle;
  146. map.mtrr   = r_list->map->mtrr;
  147. up(&dev->struct_sem);
  148. if (copy_to_user((drm_map_t *)arg, &map, sizeof(map))) return -EFAULT;
  149. return 0;
  150. }
  151. int DRM(getclient)( struct inode *inode, struct file *filp,
  152.     unsigned int cmd, unsigned long arg )
  153. {
  154. drm_file_t   *priv = filp->private_data;
  155. drm_device_t *dev  = priv->dev;
  156. drm_client_t client;
  157. drm_file_t   *pt;
  158. int          idx;
  159. int          i;
  160. if (copy_from_user(&client, (drm_client_t *)arg, sizeof(client)))
  161. return -EFAULT;
  162. idx = client.idx;
  163. down(&dev->struct_sem);
  164. for (i = 0, pt = dev->file_first; i < idx && pt; i++, pt = pt->next)
  165. ;
  166. if (!pt) {
  167. up(&dev->struct_sem);
  168. return -EINVAL;
  169. }
  170. client.auth  = pt->authenticated;
  171. client.pid   = pt->pid;
  172. client.uid   = pt->uid;
  173. client.magic = pt->magic;
  174. client.iocs  = pt->ioctl_count;
  175. up(&dev->struct_sem);
  176. if (copy_to_user((drm_client_t *)arg, &client, sizeof(client)))
  177. return -EFAULT;
  178. return 0;
  179. }
  180. int DRM(getstats)( struct inode *inode, struct file *filp,
  181.    unsigned int cmd, unsigned long arg )
  182. {
  183. drm_file_t   *priv = filp->private_data;
  184. drm_device_t *dev  = priv->dev;
  185. drm_stats_t  stats;
  186. int          i;
  187. memset(&stats, 0, sizeof(stats));
  188. down(&dev->struct_sem);
  189. for (i = 0; i < dev->counters; i++) {
  190. if (dev->types[i] == _DRM_STAT_LOCK)
  191. stats.data[i].value
  192. = (dev->lock.hw_lock
  193.    ? dev->lock.hw_lock->lock : 0);
  194. else 
  195. stats.data[i].value = atomic_read(&dev->counts[i]);
  196. stats.data[i].type  = dev->types[i];
  197. }
  198. stats.count = dev->counters;
  199. up(&dev->struct_sem);
  200. if (copy_to_user((drm_stats_t *)arg, &stats, sizeof(stats)))
  201. return -EFAULT;
  202. return 0;
  203. }