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 * $FreeBSD$
32 */
33
34 #include "dev/drm/drmP.h"
35
36 /*
37 * Beginning in revision 1.1 of the DRM interface, getunique will return
38 * a unique in the form pci:oooo:bb:dd.f (o=domain, b=bus, d=device, f=function)
39 * before setunique has been called. The format for the bus-specific part of
40 * the unique is not defined for any other bus.
41 */
42 int DRM(getunique)( DRM_IOCTL_ARGS )
43 {
44 DRM_DEVICE;
45 drm_unique_t u;
46
47 DRM_COPY_FROM_USER_IOCTL( u, (drm_unique_t *)data, sizeof(u) );
48
49 if (u.unique_len >= dev->unique_len) {
50 if (DRM_COPY_TO_USER(u.unique, dev->unique, dev->unique_len))
51 return DRM_ERR(EFAULT);
52 }
53 u.unique_len = dev->unique_len;
54
55 DRM_COPY_TO_USER_IOCTL( (drm_unique_t *)data, u, sizeof(u) );
56
57 return 0;
58 }
59
60 /* Deprecated in DRM version 1.1, and will return EBUSY when setversion has
61 * requested version 1.1 or greater.
62 */
63 int DRM(setunique)( DRM_IOCTL_ARGS )
64 {
65 DRM_DEVICE;
66 drm_unique_t u;
67 int domain, bus, slot, func, ret;
68
69 if (dev->unique_len || dev->unique)
70 return DRM_ERR(EBUSY);
71
72 DRM_COPY_FROM_USER_IOCTL( u, (drm_unique_t *)data, sizeof(u) );
73
74 if (!u.unique_len || u.unique_len > 1024)
75 return DRM_ERR(EINVAL);
76
77 dev->unique_len = u.unique_len;
78 dev->unique = DRM(alloc)(u.unique_len + 1, DRM_MEM_DRIVER);
79
80 if (dev->unique == NULL)
81 return DRM_ERR(ENOMEM);
82
83 if (DRM_COPY_FROM_USER(dev->unique, u.unique, dev->unique_len))
84 return DRM_ERR(EFAULT);
85
86 dev->unique[dev->unique_len] = '\0';
87
88 /* Return error if the busid submitted doesn't match the device's actual
89 * busid.
90 */
91 ret = sscanf(dev->unique, "PCI:%d:%d:%d", &bus, &slot, &func);
92 if (ret != 3)
93 return DRM_ERR(EINVAL);
94 domain = bus >> 8;
95 bus &= 0xff;
96
97 if ((domain != dev->pci_domain) ||
98 (bus != dev->pci_bus) ||
99 (slot != dev->pci_slot) ||
100 (func != dev->pci_func))
101 return DRM_ERR(EINVAL);
102
103 return 0;
104 }
105
106
107 static int
108 DRM(set_busid)(drm_device_t *dev)
109 {
110
111 if (dev->unique != NULL)
112 return EBUSY;
113
114 dev->unique_len = 20;
115 dev->unique = DRM(alloc)(dev->unique_len + 1, DRM_MEM_DRIVER);
116 if (dev->unique == NULL)
117 return ENOMEM;
118
119 snprintf(dev->unique, dev->unique_len, "pci:%04x:%02x:%02x.%1x",
120 dev->pci_domain, dev->pci_bus, dev->pci_slot, dev->pci_func);
121
122 return 0;
123 }
124
125 int DRM(getmap)( DRM_IOCTL_ARGS )
126 {
127 DRM_DEVICE;
128 drm_map_t map;
129 drm_local_map_t *mapinlist;
130 drm_map_list_entry_t *list;
131 int idx;
132 int i = 0;
133
134 DRM_COPY_FROM_USER_IOCTL( map, (drm_map_t *)data, sizeof(map) );
135
136 idx = map.offset;
137
138 DRM_LOCK();
139 if (idx < 0) {
140 DRM_UNLOCK();
141 return DRM_ERR(EINVAL);
142 }
143
144 TAILQ_FOREACH(list, dev->maplist, link) {
145 mapinlist = list->map;
146 if (i==idx) {
147 map.offset = mapinlist->offset;
148 map.size = mapinlist->size;
149 map.type = mapinlist->type;
150 map.flags = mapinlist->flags;
151 map.handle = mapinlist->handle;
152 map.mtrr = mapinlist->mtrr;
153 break;
154 }
155 i++;
156 }
157
158 DRM_UNLOCK();
159
160 if (!list)
161 return EINVAL;
162
163 DRM_COPY_TO_USER_IOCTL( (drm_map_t *)data, map, sizeof(map) );
164
165 return 0;
166 }
167
168 int DRM(getclient)( DRM_IOCTL_ARGS )
169 {
170 DRM_DEVICE;
171 drm_client_t client;
172 drm_file_t *pt;
173 int idx;
174 int i = 0;
175
176 DRM_COPY_FROM_USER_IOCTL( client, (drm_client_t *)data, sizeof(client) );
177
178 idx = client.idx;
179 DRM_LOCK();
180 TAILQ_FOREACH(pt, &dev->files, link) {
181 if (i==idx)
182 {
183 client.auth = pt->authenticated;
184 client.pid = pt->pid;
185 client.uid = pt->uid;
186 client.magic = pt->magic;
187 client.iocs = pt->ioctl_count;
188 DRM_UNLOCK();
189
190 *(drm_client_t *)data = client;
191 return 0;
192 }
193 i++;
194 }
195 DRM_UNLOCK();
196
197 DRM_COPY_TO_USER_IOCTL( (drm_client_t *)data, client, sizeof(client) );
198
199 return 0;
200 }
201
202 int DRM(getstats)( DRM_IOCTL_ARGS )
203 {
204 DRM_DEVICE;
205 drm_stats_t stats;
206 int i;
207
208 memset(&stats, 0, sizeof(stats));
209
210 DRM_LOCK();
211
212 for (i = 0; i < dev->counters; i++) {
213 if (dev->types[i] == _DRM_STAT_LOCK)
214 stats.data[i].value
215 = (dev->lock.hw_lock
216 ? dev->lock.hw_lock->lock : 0);
217 else
218 stats.data[i].value = atomic_read(&dev->counts[i]);
219 stats.data[i].type = dev->types[i];
220 }
221
222 stats.count = dev->counters;
223
224 DRM_UNLOCK();
225
226 DRM_COPY_TO_USER_IOCTL( (drm_stats_t *)data, stats, sizeof(stats) );
227
228 return 0;
229 }
230
231 #define DRM_IF_MAJOR 1
232 #define DRM_IF_MINOR 2
233
234 int DRM(setversion)(DRM_IOCTL_ARGS)
235 {
236 DRM_DEVICE;
237 drm_set_version_t sv;
238 drm_set_version_t retv;
239 int if_version;
240
241 DRM_COPY_FROM_USER_IOCTL(sv, (drm_set_version_t *)data, sizeof(sv));
242
243 retv.drm_di_major = DRM_IF_MAJOR;
244 retv.drm_di_minor = DRM_IF_MINOR;
245 retv.drm_dd_major = DRIVER_MAJOR;
246 retv.drm_dd_minor = DRIVER_MINOR;
247
248 DRM_COPY_TO_USER_IOCTL((drm_set_version_t *)data, retv, sizeof(sv));
249
250 if (sv.drm_di_major != -1) {
251 if (sv.drm_di_major != DRM_IF_MAJOR ||
252 sv.drm_di_minor < 0 || sv.drm_di_minor > DRM_IF_MINOR)
253 return EINVAL;
254 if_version = DRM_IF_VERSION(sv.drm_di_major, sv.drm_dd_minor);
255 dev->if_version = DRM_MAX(if_version, dev->if_version);
256 if (sv.drm_di_minor >= 1) {
257 /*
258 * Version 1.1 includes tying of DRM to specific device
259 */
260 DRM(set_busid)(dev);
261 }
262 }
263
264 if (sv.drm_dd_major != -1) {
265 if (sv.drm_dd_major != DRIVER_MAJOR ||
266 sv.drm_dd_minor < 0 || sv.drm_dd_minor > DRIVER_MINOR)
267 return EINVAL;
268 #ifdef DRIVER_SETVERSION
269 DRIVER_SETVERSION(dev, &sv);
270 #endif
271 }
272 return 0;
273 }
274
275
276 int DRM(noop)(DRM_IOCTL_ARGS)
277 {
278 DRM_DEBUG("\n");
279 return 0;
280 }
Cache object: 0acd271657e8af4f34eaff128e154378
|