Remove some duplicate FreeBSD CVS IDs, move some IDs to better places.
[dragonfly.git] / sys / dev / 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  * $FreeBSD: src/sys/dev/drm/drm_ioctl.h,v 1.4.2.1 2003/04/26 07:05:28 anholt Exp $
32  * $DragonFly: src/sys/dev/drm/Attic/drm_ioctl.h,v 1.3 2004/02/13 01:23:57 joerg Exp $
33  */
34
35 #include "dev/drm/drmP.h"
36
37 int DRM(irq_busid)( DRM_IOCTL_ARGS )
38 {
39 #if defined(__DragonFly__) || defined(__FreeBSD__)
40         drm_irq_busid_t id;
41         devclass_t pci;
42         device_t bus, dev;
43         device_t *kids;
44         int error, i, num_kids;
45
46         DRM_COPY_FROM_USER_IOCTL( id, (drm_irq_busid_t *)data, sizeof(id) );
47
48         pci = devclass_find("pci");
49         if (!pci)
50                 return ENOENT;
51         bus = devclass_get_device(pci, id.busnum);
52         if (!bus)
53                 return ENOENT;
54         error = device_get_children(bus, &kids, &num_kids);
55         if (error)
56                 return error;
57
58         dev = 0;
59         for (i = 0; i < num_kids; i++) {
60                 dev = kids[i];
61                 if (pci_get_slot(dev) == id.devnum
62                     && pci_get_function(dev) == id.funcnum)
63                         break;
64         }
65
66         free(kids, M_TEMP);
67
68         if (i != num_kids)
69                 id.irq = pci_get_irq(dev);
70         else
71                 id.irq = 0;
72         DRM_DEBUG("%d:%d:%d => IRQ %d\n",
73                   id.busnum, id.devnum, id.funcnum, id.irq);
74         
75         DRM_COPY_TO_USER_IOCTL( (drm_irq_busid_t *)data, id, sizeof(id) );
76
77         return 0;
78 #else
79         /* don't support interrupt-driven drivers on Net yet */
80         return ENOENT;
81 #endif
82 }
83
84 int DRM(getunique)( DRM_IOCTL_ARGS )
85 {
86         DRM_DEVICE;
87         drm_unique_t     u;
88
89         DRM_COPY_FROM_USER_IOCTL( u, (drm_unique_t *)data, sizeof(u) );
90
91         if (u.unique_len >= dev->unique_len) {
92                 if (DRM_COPY_TO_USER(u.unique, dev->unique, dev->unique_len))
93                         return DRM_ERR(EFAULT);
94         }
95         u.unique_len = dev->unique_len;
96
97         DRM_COPY_TO_USER_IOCTL( (drm_unique_t *)data, u, sizeof(u) );
98
99         return 0;
100 }
101
102 int DRM(setunique)( DRM_IOCTL_ARGS )
103 {
104         DRM_DEVICE;
105         drm_unique_t     u;
106
107         if (dev->unique_len || dev->unique)
108                 return DRM_ERR(EBUSY);
109
110         DRM_COPY_FROM_USER_IOCTL( u, (drm_unique_t *)data, sizeof(u) );
111
112         if (!u.unique_len || u.unique_len > 1024)
113                 return DRM_ERR(EINVAL);
114
115         dev->unique_len = u.unique_len;
116         dev->unique     = DRM(alloc)(u.unique_len + 1, DRM_MEM_DRIVER);
117
118         if(!dev->unique) return DRM_ERR(ENOMEM);
119
120         if (DRM_COPY_FROM_USER(dev->unique, u.unique, dev->unique_len))
121                 return DRM_ERR(EFAULT);
122
123         dev->unique[dev->unique_len] = '\0';
124
125         return 0;
126 }
127
128
129 int DRM(getmap)( DRM_IOCTL_ARGS )
130 {
131         DRM_DEVICE;
132         drm_map_t    map;
133         drm_local_map_t    *mapinlist;
134         drm_map_list_entry_t *list;
135         int          idx;
136         int          i = 0;
137
138         DRM_COPY_FROM_USER_IOCTL( map, (drm_map_t *)data, sizeof(map) );
139
140         idx = map.offset;
141
142         DRM_LOCK;
143         if (idx < 0) {
144                 DRM_UNLOCK;
145                 return DRM_ERR(EINVAL);
146         }
147
148         TAILQ_FOREACH(list, dev->maplist, link) {
149                 mapinlist = list->map;
150                 if (i==idx) {
151                         map.offset = mapinlist->offset;
152                         map.size   = mapinlist->size;
153                         map.type   = mapinlist->type;
154                         map.flags  = mapinlist->flags;
155                         map.handle = mapinlist->handle;
156                         map.mtrr   = mapinlist->mtrr;
157                         break;
158                 }
159                 i++;
160         }
161
162         DRM_UNLOCK;
163
164         if (!list)
165                 return EINVAL;
166
167         DRM_COPY_TO_USER_IOCTL( (drm_map_t *)data, map, sizeof(map) );
168
169         return 0;
170 }
171
172 int DRM(getclient)( DRM_IOCTL_ARGS )
173 {
174         DRM_DEVICE;
175         drm_client_t client;
176         drm_file_t   *pt;
177         int          idx;
178         int          i = 0;
179
180         DRM_COPY_FROM_USER_IOCTL( client, (drm_client_t *)data, sizeof(client) );
181
182         idx = client.idx;
183         DRM_LOCK;
184         TAILQ_FOREACH(pt, &dev->files, link) {
185                 if (i==idx)
186                 {
187                         client.auth  = pt->authenticated;
188                         client.pid   = pt->pid;
189                         client.uid   = pt->uid;
190                         client.magic = pt->magic;
191                         client.iocs  = pt->ioctl_count;
192                         DRM_UNLOCK;
193
194                         *(drm_client_t *)data = client;
195                         return 0;
196                 }
197                 i++;
198         }
199         DRM_UNLOCK;
200
201         DRM_COPY_TO_USER_IOCTL( (drm_client_t *)data, client, sizeof(client) );
202
203         return 0;
204 }
205
206 int DRM(getstats)( DRM_IOCTL_ARGS )
207 {
208         DRM_DEVICE;
209         drm_stats_t  stats;
210         int          i;
211
212         memset(&stats, 0, sizeof(stats));
213         
214         DRM_LOCK;
215
216         for (i = 0; i < dev->counters; i++) {
217                 if (dev->types[i] == _DRM_STAT_LOCK)
218                         stats.data[i].value
219                                 = (dev->lock.hw_lock
220                                    ? dev->lock.hw_lock->lock : 0);
221                 else 
222                         stats.data[i].value = atomic_read(&dev->counts[i]);
223                 stats.data[i].type  = dev->types[i];
224         }
225         
226         stats.count = dev->counters;
227
228         DRM_UNLOCK;
229
230         DRM_COPY_TO_USER_IOCTL( (drm_stats_t *)data, stats, sizeof(stats) );
231
232         return 0;
233 }
234
235 int DRM(noop)(DRM_IOCTL_ARGS)
236 {
237         DRM_DEBUG("\n");
238         return 0;
239 }