Rev 4560 | Rev 6084 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
3031 | serge | 1 | /* |
2 | * Created: Fri Jan 19 10:48:35 2001 by faith@acm.org |
||
3 | * |
||
4 | * Copyright 2001 VA Linux Systems, Inc., Sunnyvale, California. |
||
5 | * All Rights Reserved. |
||
6 | * |
||
5060 | serge | 7 | * Author Rickard E. (Rik) Faith |
8 | * |
||
3031 | serge | 9 | * Permission is hereby granted, free of charge, to any person obtaining a |
10 | * copy of this software and associated documentation files (the "Software"), |
||
11 | * to deal in the Software without restriction, including without limitation |
||
12 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||
13 | * and/or sell copies of the Software, and to permit persons to whom the |
||
14 | * Software is furnished to do so, subject to the following conditions: |
||
15 | * |
||
16 | * The above copyright notice and this permission notice (including the next |
||
17 | * paragraph) shall be included in all copies or substantial portions of the |
||
18 | * Software. |
||
19 | * |
||
20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||
21 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||
22 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||
23 | * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR |
||
24 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
||
25 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||
26 | * DEALINGS IN THE SOFTWARE. |
||
27 | */ |
||
28 | |||
5060 | serge | 29 | #include |
3031 | serge | 30 | #include |
4560 | Serge | 31 | #include |
3031 | serge | 32 | #include |
33 | #include |
||
4104 | Serge | 34 | #include |
3031 | serge | 35 | |
36 | struct va_format { |
||
37 | const char *fmt; |
||
38 | va_list *va; |
||
39 | }; |
||
40 | |||
41 | unsigned int drm_debug = 0; /* 1 to enable debug output */ |
||
42 | EXPORT_SYMBOL(drm_debug); |
||
43 | |||
4104 | Serge | 44 | unsigned int drm_rnodes = 0; /* 1 to enable experimental render nodes API */ |
45 | EXPORT_SYMBOL(drm_rnodes); |
||
46 | |||
5060 | serge | 47 | /* 1 to allow user space to request universal planes (experimental) */ |
48 | unsigned int drm_universal_planes = 0; |
||
49 | EXPORT_SYMBOL(drm_universal_planes); |
||
50 | |||
3031 | serge | 51 | unsigned int drm_vblank_offdelay = 5000; /* Default to 5000 msecs. */ |
52 | EXPORT_SYMBOL(drm_vblank_offdelay); |
||
53 | |||
54 | unsigned int drm_timestamp_precision = 20; /* Default to 20 usecs. */ |
||
55 | EXPORT_SYMBOL(drm_timestamp_precision); |
||
56 | |||
5060 | serge | 57 | /* |
58 | * Default to use monotonic timestamps for wait-for-vblank and page-flip |
||
59 | * complete events. |
||
60 | */ |
||
61 | unsigned int drm_timestamp_monotonic = 1; |
||
62 | |||
4104 | Serge | 63 | struct idr drm_minors_idr; |
3031 | serge | 64 | int drm_err(const char *func, const char *format, ...) |
65 | { |
||
66 | struct va_format vaf; |
||
67 | va_list args; |
||
68 | int r; |
||
69 | |||
70 | va_start(args, format); |
||
71 | |||
72 | vaf.fmt = format; |
||
73 | vaf.va = &args; |
||
74 | |||
75 | r = printk(KERN_ERR "[" DRM_NAME ":%s] *ERROR* %pV", func, &vaf); |
||
76 | |||
77 | va_end(args); |
||
78 | |||
79 | return r; |
||
80 | } |
||
81 | EXPORT_SYMBOL(drm_err); |
||
82 | |||
5060 | serge | 83 | void drm_ut_debug_printk(const char *function_name, const char *format, ...) |
3031 | serge | 84 | { |
4560 | Serge | 85 | struct va_format vaf; |
3031 | serge | 86 | va_list args; |
87 | |||
88 | // if (drm_debug & request_level) { |
||
89 | // if (function_name) |
||
90 | // printk(KERN_DEBUG "[%s:%s], ", prefix, function_name); |
||
91 | // va_start(args, format); |
||
92 | // vprintk(format, args); |
||
93 | // va_end(args); |
||
94 | // } |
||
95 | } |
||
96 | EXPORT_SYMBOL(drm_ut_debug_printk); |
||
97 | |||
5060 | serge | 98 | #if 0 |
99 | struct drm_master *drm_master_create(struct drm_minor *minor) |
||
100 | { |
||
101 | struct drm_master *master; |
||
102 | |||
103 | master = kzalloc(sizeof(*master), GFP_KERNEL); |
||
104 | if (!master) |
||
105 | return NULL; |
||
106 | |||
107 | kref_init(&master->refcount); |
||
108 | spin_lock_init(&master->lock.spinlock); |
||
109 | init_waitqueue_head(&master->lock.lock_queue); |
||
110 | if (drm_ht_create(&master->magiclist, DRM_MAGIC_HASH_ORDER)) { |
||
111 | kfree(master); |
||
112 | return NULL; |
||
113 | } |
||
114 | INIT_LIST_HEAD(&master->magicfree); |
||
115 | master->minor = minor; |
||
116 | |||
117 | return master; |
||
118 | } |
||
119 | |||
120 | struct drm_master *drm_master_get(struct drm_master *master) |
||
121 | { |
||
122 | kref_get(&master->refcount); |
||
123 | return master; |
||
124 | } |
||
125 | EXPORT_SYMBOL(drm_master_get); |
||
126 | |||
127 | static void drm_master_destroy(struct kref *kref) |
||
128 | { |
||
129 | struct drm_master *master = container_of(kref, struct drm_master, refcount); |
||
130 | struct drm_magic_entry *pt, *next; |
||
131 | struct drm_device *dev = master->minor->dev; |
||
132 | struct drm_map_list *r_list, *list_temp; |
||
133 | |||
134 | mutex_lock(&dev->struct_mutex); |
||
135 | if (dev->driver->master_destroy) |
||
136 | dev->driver->master_destroy(dev, master); |
||
137 | |||
138 | list_for_each_entry_safe(r_list, list_temp, &dev->maplist, head) { |
||
139 | if (r_list->master == master) { |
||
140 | drm_rmmap_locked(dev, r_list->map); |
||
141 | r_list = NULL; |
||
142 | } |
||
143 | } |
||
144 | |||
145 | if (master->unique) { |
||
146 | kfree(master->unique); |
||
147 | master->unique = NULL; |
||
148 | master->unique_len = 0; |
||
149 | } |
||
150 | |||
151 | list_for_each_entry_safe(pt, next, &master->magicfree, head) { |
||
152 | list_del(&pt->head); |
||
153 | drm_ht_remove_item(&master->magiclist, &pt->hash_item); |
||
154 | kfree(pt); |
||
155 | } |
||
156 | |||
157 | drm_ht_remove(&master->magiclist); |
||
158 | |||
159 | mutex_unlock(&dev->struct_mutex); |
||
160 | kfree(master); |
||
161 | } |
||
162 | |||
163 | void drm_master_put(struct drm_master **master) |
||
164 | { |
||
165 | kref_put(&(*master)->refcount, drm_master_destroy); |
||
166 | *master = NULL; |
||
167 | } |
||
168 | EXPORT_SYMBOL(drm_master_put); |
||
169 | |||
170 | int drm_setmaster_ioctl(struct drm_device *dev, void *data, |
||
171 | struct drm_file *file_priv) |
||
172 | { |
||
173 | int ret = 0; |
||
174 | |||
175 | mutex_lock(&dev->master_mutex); |
||
176 | if (file_priv->is_master) |
||
177 | goto out_unlock; |
||
178 | |||
179 | if (file_priv->minor->master) { |
||
180 | ret = -EINVAL; |
||
181 | goto out_unlock; |
||
182 | } |
||
183 | |||
184 | if (!file_priv->master) { |
||
185 | ret = -EINVAL; |
||
186 | goto out_unlock; |
||
187 | } |
||
188 | |||
189 | file_priv->minor->master = drm_master_get(file_priv->master); |
||
190 | file_priv->is_master = 1; |
||
191 | if (dev->driver->master_set) { |
||
192 | ret = dev->driver->master_set(dev, file_priv, false); |
||
193 | if (unlikely(ret != 0)) { |
||
194 | file_priv->is_master = 0; |
||
195 | drm_master_put(&file_priv->minor->master); |
||
196 | } |
||
197 | } |
||
198 | |||
199 | out_unlock: |
||
200 | mutex_unlock(&dev->master_mutex); |
||
201 | return ret; |
||
202 | } |
||
203 | |||
204 | int drm_dropmaster_ioctl(struct drm_device *dev, void *data, |
||
205 | struct drm_file *file_priv) |
||
206 | { |
||
207 | int ret = -EINVAL; |
||
208 | |||
209 | mutex_lock(&dev->master_mutex); |
||
210 | if (!file_priv->is_master) |
||
211 | goto out_unlock; |
||
212 | |||
213 | if (!file_priv->minor->master) |
||
214 | goto out_unlock; |
||
215 | |||
216 | ret = 0; |
||
217 | if (dev->driver->master_drop) |
||
218 | dev->driver->master_drop(dev, file_priv, false); |
||
219 | drm_master_put(&file_priv->minor->master); |
||
220 | file_priv->is_master = 0; |
||
221 | |||
222 | out_unlock: |
||
223 | mutex_unlock(&dev->master_mutex); |
||
224 | return ret; |
||
225 | } |
||
226 | |||
227 | /* |
||
228 | * DRM Minors |
||
229 | * A DRM device can provide several char-dev interfaces on the DRM-Major. Each |
||
230 | * of them is represented by a drm_minor object. Depending on the capabilities |
||
231 | * of the device-driver, different interfaces are registered. |
||
232 | * |
||
233 | * Minors can be accessed via dev->$minor_name. This pointer is either |
||
234 | * NULL or a valid drm_minor pointer and stays valid as long as the device is |
||
235 | * valid. This means, DRM minors have the same life-time as the underlying |
||
236 | * device. However, this doesn't mean that the minor is active. Minors are |
||
237 | * registered and unregistered dynamically according to device-state. |
||
238 | */ |
||
239 | |||
240 | static struct drm_minor **drm_minor_get_slot(struct drm_device *dev, |
||
241 | unsigned int type) |
||
242 | { |
||
243 | switch (type) { |
||
244 | case DRM_MINOR_LEGACY: |
||
245 | return &dev->primary; |
||
246 | case DRM_MINOR_RENDER: |
||
247 | return &dev->render; |
||
248 | case DRM_MINOR_CONTROL: |
||
249 | return &dev->control; |
||
250 | default: |
||
251 | return NULL; |
||
252 | } |
||
253 | } |
||
254 | |||
255 | static int drm_minor_alloc(struct drm_device *dev, unsigned int type) |
||
256 | { |
||
257 | struct drm_minor *minor; |
||
258 | |||
259 |