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