Rev 6660 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 6660 | Rev 6935 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Created: Fri Jan 19 10:48:35 2001 by faith@acm.org |
2 | * Created: Fri Jan 19 10:48:35 2001 by faith@acm.org |
3 | * |
3 | * |
4 | * Copyright 2001 VA Linux Systems, Inc., Sunnyvale, California. |
4 | * Copyright 2001 VA Linux Systems, Inc., Sunnyvale, California. |
5 | * All Rights Reserved. |
5 | * All Rights Reserved. |
6 | * |
6 | * |
7 | * Author Rickard E. (Rik) Faith |
7 | * Author Rickard E. (Rik) Faith |
8 | * |
8 | * |
9 | * Permission is hereby granted, free of charge, to any person obtaining a |
9 | * Permission is hereby granted, free of charge, to any person obtaining a |
10 | * copy of this software and associated documentation files (the "Software"), |
10 | * copy of this software and associated documentation files (the "Software"), |
11 | * to deal in the Software without restriction, including without limitation |
11 | * to deal in the Software without restriction, including without limitation |
12 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
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 |
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: |
14 | * Software is furnished to do so, subject to the following conditions: |
15 | * |
15 | * |
16 | * The above copyright notice and this permission notice (including the next |
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 |
17 | * paragraph) shall be included in all copies or substantial portions of the |
18 | * Software. |
18 | * Software. |
19 | * |
19 | * |
20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
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, |
21 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
22 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
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 |
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, |
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 |
25 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
26 | * DEALINGS IN THE SOFTWARE. |
26 | * DEALINGS IN THE SOFTWARE. |
27 | */ |
27 | */ |
28 | 28 | ||
29 | #include |
29 | #include |
30 | #include |
30 | #include |
31 | #include |
31 | #include |
32 | #include |
32 | #include |
33 | #include |
33 | #include |
34 | #include |
34 | #include |
35 | #include "drm_internal.h" |
35 | #include "drm_internal.h" |
36 | 36 | ||
37 | unsigned int drm_debug = 0; /* 1 to enable debug output */ |
37 | unsigned int drm_debug = 0; /* 1 to enable debug output */ |
38 | EXPORT_SYMBOL(drm_debug); |
38 | EXPORT_SYMBOL(drm_debug); |
39 | 39 | ||
40 | unsigned int drm_rnodes = 0; /* 1 to enable experimental render nodes API */ |
40 | unsigned int drm_rnodes = 0; /* 1 to enable experimental render nodes API */ |
41 | EXPORT_SYMBOL(drm_rnodes); |
41 | EXPORT_SYMBOL(drm_rnodes); |
42 | 42 | ||
43 | /* 1 to allow user space to request universal planes (experimental) */ |
43 | /* 1 to allow user space to request universal planes (experimental) */ |
44 | unsigned int drm_universal_planes = 0; |
44 | unsigned int drm_universal_planes = 0; |
45 | EXPORT_SYMBOL(drm_universal_planes); |
45 | EXPORT_SYMBOL(drm_universal_planes); |
46 | 46 | ||
47 | unsigned int drm_vblank_offdelay = 5000; /* Default to 5000 msecs. */ |
47 | unsigned int drm_vblank_offdelay = 5000; /* Default to 5000 msecs. */ |
48 | EXPORT_SYMBOL(drm_vblank_offdelay); |
48 | EXPORT_SYMBOL(drm_vblank_offdelay); |
49 | 49 | ||
50 | unsigned int drm_timestamp_precision = 20; /* Default to 20 usecs. */ |
50 | unsigned int drm_timestamp_precision = 20; /* Default to 20 usecs. */ |
51 | EXPORT_SYMBOL(drm_timestamp_precision); |
51 | EXPORT_SYMBOL(drm_timestamp_precision); |
52 | 52 | ||
53 | struct idr drm_minors_idr; |
53 | struct idr drm_minors_idr; |
54 | 54 | ||
55 | void drm_err(const char *format, ...) |
55 | void drm_err(const char *format, ...) |
56 | { |
56 | { |
57 | struct va_format vaf; |
57 | struct va_format vaf; |
58 | va_list args; |
58 | va_list args; |
59 | 59 | ||
60 | va_start(args, format); |
60 | va_start(args, format); |
61 | 61 | ||
62 | vaf.fmt = format; |
62 | vaf.fmt = format; |
63 | vaf.va = &args; |
63 | vaf.va = &args; |
64 | 64 | ||
65 | printk(KERN_ERR "[" DRM_NAME ":%pf] *ERROR* %pV", |
65 | printk(KERN_ERR "[" DRM_NAME ":%pf] *ERROR* %pV", |
66 | __builtin_return_address(0), &vaf); |
66 | __builtin_return_address(0), &vaf); |
67 | 67 | ||
68 | va_end(args); |
68 | va_end(args); |
69 | } |
69 | } |
70 | EXPORT_SYMBOL(drm_err); |
70 | EXPORT_SYMBOL(drm_err); |
71 | 71 | ||
72 | void drm_ut_debug_printk(const char *function_name, const char *format, ...) |
72 | void drm_ut_debug_printk(const char *function_name, const char *format, ...) |
73 | { |
73 | { |
74 | struct va_format vaf; |
74 | struct va_format vaf; |
75 | va_list args; |
75 | va_list args; |
76 | 76 | ||
77 | // if (drm_debug & request_level) { |
77 | // if (drm_debug & request_level) { |
78 | // if (function_name) |
78 | // if (function_name) |
79 | // printk(KERN_DEBUG "[%s:%s], ", prefix, function_name); |
79 | // printk(KERN_DEBUG "[%s:%s], ", prefix, function_name); |
80 | // va_start(args, format); |
80 | // va_start(args, format); |
81 | // vprintk(format, args); |
81 | // vprintk(format, args); |
82 | // va_end(args); |
82 | // va_end(args); |
83 | // } |
83 | // } |
84 | } |
84 | } |
85 | EXPORT_SYMBOL(drm_ut_debug_printk); |
85 | EXPORT_SYMBOL(drm_ut_debug_printk); |
86 | 86 | ||
87 | #if 0 |
87 | #if 0 |
88 | struct drm_master *drm_master_create(struct drm_minor *minor) |
88 | struct drm_master *drm_master_create(struct drm_minor *minor) |
89 | { |
89 | { |
90 | struct drm_master *master; |
90 | struct drm_master *master; |
91 | 91 | ||
92 | master = kzalloc(sizeof(*master), GFP_KERNEL); |
92 | master = kzalloc(sizeof(*master), GFP_KERNEL); |
93 | if (!master) |
93 | if (!master) |
94 | return NULL; |
94 | return NULL; |
95 | 95 | ||
96 | kref_init(&master->refcount); |
96 | kref_init(&master->refcount); |
97 | spin_lock_init(&master->lock.spinlock); |
97 | spin_lock_init(&master->lock.spinlock); |
98 | init_waitqueue_head(&master->lock.lock_queue); |
98 | init_waitqueue_head(&master->lock.lock_queue); |
99 | if (drm_ht_create(&master->magiclist, DRM_MAGIC_HASH_ORDER)) { |
99 | if (drm_ht_create(&master->magiclist, DRM_MAGIC_HASH_ORDER)) { |
100 | kfree(master); |
100 | kfree(master); |
101 | return NULL; |
101 | return NULL; |
102 | } |
102 | } |
103 | INIT_LIST_HEAD(&master->magicfree); |
103 | INIT_LIST_HEAD(&master->magicfree); |
104 | master->minor = minor; |
104 | master->minor = minor; |
105 | 105 | ||
106 | return master; |
106 | return master; |
107 | } |
107 | } |
108 | 108 | ||
109 | struct drm_master *drm_master_get(struct drm_master *master) |
109 | struct drm_master *drm_master_get(struct drm_master *master) |
110 | { |
110 | { |
111 | kref_get(&master->refcount); |
111 | kref_get(&master->refcount); |
112 | return master; |
112 | return master; |
113 | } |
113 | } |
114 | EXPORT_SYMBOL(drm_master_get); |
114 | EXPORT_SYMBOL(drm_master_get); |
115 | 115 | ||
116 | static void drm_master_destroy(struct kref *kref) |
116 | static void drm_master_destroy(struct kref *kref) |
117 | { |
117 | { |
118 | struct drm_master *master = container_of(kref, struct drm_master, refcount); |
118 | struct drm_master *master = container_of(kref, struct drm_master, refcount); |
119 | struct drm_magic_entry *pt, *next; |
119 | struct drm_magic_entry *pt, *next; |
120 | struct drm_device *dev = master->minor->dev; |
120 | struct drm_device *dev = master->minor->dev; |
121 | struct drm_map_list *r_list, *list_temp; |
121 | struct drm_map_list *r_list, *list_temp; |
122 | 122 | ||
123 | mutex_lock(&dev->struct_mutex); |
123 | mutex_lock(&dev->struct_mutex); |
124 | if (dev->driver->master_destroy) |
124 | if (dev->driver->master_destroy) |
125 | dev->driver->master_destroy(dev, master); |
125 | dev->driver->master_destroy(dev, master); |
126 | 126 | ||
127 | list_for_each_entry_safe(r_list, list_temp, &dev->maplist, head) { |
127 | list_for_each_entry_safe(r_list, list_temp, &dev->maplist, head) { |
128 | if (r_list->master == master) { |
128 | if (r_list->master == master) { |
129 | drm_rmmap_locked(dev, r_list->map); |
129 | drm_rmmap_locked(dev, r_list->map); |
130 | r_list = NULL; |
130 | r_list = NULL; |
131 | } |
131 | } |
132 | } |
132 | } |
133 | 133 | ||
134 | if (master->unique) { |
134 | if (master->unique) { |
135 | kfree(master->unique); |
135 | kfree(master->unique); |
136 | master->unique = NULL; |
136 | master->unique = NULL; |
137 | master->unique_len = 0; |
137 | master->unique_len = 0; |
138 | } |
138 | } |
139 | 139 | ||
140 | list_for_each_entry_safe(pt, next, &master->magicfree, head) { |
140 | list_for_each_entry_safe(pt, next, &master->magicfree, head) { |
141 | list_del(&pt->head); |
141 | list_del(&pt->head); |
142 | drm_ht_remove_item(&master->magiclist, &pt->hash_item); |
142 | drm_ht_remove_item(&master->magiclist, &pt->hash_item); |
143 | kfree(pt); |
143 | kfree(pt); |
144 | } |
144 | } |
145 | 145 | ||
146 | drm_ht_remove(&master->magiclist); |
146 | drm_ht_remove(&master->magiclist); |
147 | 147 | ||
148 | mutex_unlock(&dev->struct_mutex); |
148 | mutex_unlock(&dev->struct_mutex); |
149 | kfree(master); |
149 | kfree(master); |
150 | } |
150 | } |
151 | 151 | ||
152 | void drm_master_put(struct drm_master **master) |
152 | void drm_master_put(struct drm_master **master) |
153 | { |
153 | { |
154 | kref_put(&(*master)->refcount, drm_master_destroy); |
154 | kref_put(&(*master)->refcount, drm_master_destroy); |
155 | *master = NULL; |
155 | *master = NULL; |
156 | } |
156 | } |
157 | EXPORT_SYMBOL(drm_master_put); |
157 | EXPORT_SYMBOL(drm_master_put); |
158 | 158 | ||
159 | int drm_setmaster_ioctl(struct drm_device *dev, void *data, |
159 | int drm_setmaster_ioctl(struct drm_device *dev, void *data, |
160 | struct drm_file *file_priv) |
160 | struct drm_file *file_priv) |
161 | { |
161 | { |
162 | int ret = 0; |
162 | int ret = 0; |
163 | 163 | ||
164 | mutex_lock(&dev->master_mutex); |
164 | mutex_lock(&dev->master_mutex); |
165 | if (file_priv->is_master) |
165 | if (file_priv->is_master) |
166 | goto out_unlock; |
166 | goto out_unlock; |
167 | 167 | ||
168 | if (file_priv->minor->master) { |
168 | if (file_priv->minor->master) { |
169 | ret = -EINVAL; |
169 | ret = -EINVAL; |
170 | goto out_unlock; |
170 | goto out_unlock; |
171 | } |
171 | } |
172 | 172 | ||
173 | if (!file_priv->master) { |
173 | if (!file_priv->master) { |
174 | ret = -EINVAL; |
174 | ret = -EINVAL; |
175 | goto out_unlock; |
175 | goto out_unlock; |
176 | } |
176 | } |
177 | 177 | ||
178 | file_priv->minor->master = drm_master_get(file_priv->master); |
178 | file_priv->minor->master = drm_master_get(file_priv->master); |
179 | file_priv->is_master = 1; |
179 | file_priv->is_master = 1; |
180 | if (dev->driver->master_set) { |
180 | if (dev->driver->master_set) { |
181 | ret = dev->driver->master_set(dev, file_priv, false); |
181 | ret = dev->driver->master_set(dev, file_priv, false); |
182 | if (unlikely(ret != 0)) { |
182 | if (unlikely(ret != 0)) { |
183 | file_priv->is_master = 0; |
183 | file_priv->is_master = 0; |
184 | drm_master_put(&file_priv->minor->master); |
184 | drm_master_put(&file_priv->minor->master); |
185 | } |
185 | } |
186 | } |
186 | } |
187 | 187 | ||
188 | out_unlock: |
188 | out_unlock: |
189 | mutex_unlock(&dev->master_mutex); |
189 | mutex_unlock(&dev->master_mutex); |
190 | return ret; |
190 | return ret; |
191 | } |
191 | } |
192 | 192 | ||
193 | int drm_dropmaster_ioctl(struct drm_device *dev, void *data, |
193 | int drm_dropmaster_ioctl(struct drm_device *dev, void *data, |
194 | struct drm_file *file_priv) |
194 | struct drm_file *file_priv) |
195 | { |
195 | { |
196 | int ret = -EINVAL; |
196 | int ret = -EINVAL; |
197 | 197 | ||
198 | mutex_lock(&dev->master_mutex); |
198 | mutex_lock(&dev->master_mutex); |
199 | if (!file_priv->is_master) |
199 | if (!file_priv->is_master) |
200 | goto out_unlock; |
200 | goto out_unlock; |
201 | 201 | ||
202 | if (!file_priv->minor->master) |
202 | if (!file_priv->minor->master) |
203 | goto out_unlock; |
203 | goto out_unlock; |
204 | 204 | ||
205 | ret = 0; |
205 | ret = 0; |
206 | if (dev->driver->master_drop) |
206 | if (dev->driver->master_drop) |
207 | dev->driver->master_drop(dev, file_priv, false); |
207 | dev->driver->master_drop(dev, file_priv, false); |
208 | drm_master_put(&file_priv->minor->master); |
208 | drm_master_put(&file_priv->minor->master); |
209 | file_priv->is_master = 0; |
209 | file_priv->is_master = 0; |
210 | 210 | ||
211 | out_unlock: |
211 | out_unlock: |
212 | mutex_unlock(&dev->master_mutex); |
212 | mutex_unlock(&dev->master_mutex); |
213 | return ret; |
213 | return ret; |
214 | } |
214 | } |
215 | 215 | ||
216 | /* |
216 | /* |
217 | * DRM Minors |
217 | * DRM Minors |
218 | * A DRM device can provide several char-dev interfaces on the DRM-Major. Each |
218 | * A DRM device can provide several char-dev interfaces on the DRM-Major. Each |
219 | * of them is represented by a drm_minor object. Depending on the capabilities |
219 | * of them is represented by a drm_minor object. Depending on the capabilities |
220 | * of the device-driver, different interfaces are registered. |
220 | * of the device-driver, different interfaces are registered. |
221 | * |
221 | * |
222 | * Minors can be accessed via dev->$minor_name. This pointer is either |
222 | * Minors can be accessed via dev->$minor_name. This pointer is either |
223 | * NULL or a valid drm_minor pointer and stays valid as long as the device is |
223 | * NULL or a valid drm_minor pointer and stays valid as long as the device is |
224 | * valid. This means, DRM minors have the same life-time as the underlying |
224 | * valid. This means, DRM minors have the same life-time as the underlying |
225 | * device. However, this doesn't mean that the minor is active. Minors are |
225 | * device. However, this doesn't mean that the minor is active. Minors are |
226 | * registered and unregistered dynamically according to device-state. |
226 | * registered and unregistered dynamically according to device-state. |
227 | */ |
227 | */ |
228 | 228 | ||
229 | static struct drm_minor **drm_minor_get_slot(struct drm_device *dev, |
229 | static struct drm_minor **drm_minor_get_slot(struct drm_device *dev, |
230 | unsigned int type) |
230 | unsigned int type) |
231 | { |
231 | { |
232 | switch (type) { |
232 | switch (type) { |
233 | case DRM_MINOR_LEGACY: |
233 | case DRM_MINOR_LEGACY: |
234 | return &dev->primary; |
234 | return &dev->primary; |
235 | case DRM_MINOR_RENDER: |
235 | case DRM_MINOR_RENDER: |
236 | return &dev->render; |
236 | return &dev->render; |
237 | case DRM_MINOR_CONTROL: |
237 | case DRM_MINOR_CONTROL: |
238 | return &dev->control; |
238 | return &dev->control; |
239 | default: |
239 | default: |
240 | return NULL; |
240 | return NULL; |
241 | } |
241 | } |
242 | } |
242 | } |
243 | 243 | ||
244 | static int drm_minor_alloc(struct drm_device *dev, unsigned int type) |
244 | static int drm_minor_alloc(struct drm_device *dev, unsigned int type) |
245 | { |
245 | { |
246 | struct drm_minor *minor; |
246 | struct drm_minor *minor; |
247 | 247 | ||
248 | minor = kzalloc(sizeof(*minor), GFP_KERNEL); |
248 | minor = kzalloc(sizeof(*minor), GFP_KERNEL); |
249 | if (!minor) |
249 | if (!minor) |
250 | return -ENOMEM; |
250 | return -ENOMEM; |
251 | 251 | ||
252 | minor->type = type; |
252 | minor->type = type; |
253 | minor->dev = dev; |
253 | minor->dev = dev; |
254 | 254 | ||
255 | *drm_minor_get_slot(dev, type) = minor; |
255 | *drm_minor_get_slot(dev, type) = minor; |
256 | return 0; |
256 | return 0; |
257 | } |
257 | } |
258 | 258 | ||
259 | static void drm_minor_free(struct drm_device *dev, unsigned int type) |
259 | static void drm_minor_free(struct drm_device *dev, unsigned int type) |
260 | { |
260 | { |
261 | struct drm_minor **slot; |
261 | struct drm_minor **slot; |
262 | 262 | ||
263 | slot = drm_minor_get_slot(dev, type); |
263 | slot = drm_minor_get_slot(dev, type); |
264 | if (*slot) { |
264 | if (*slot) { |
265 | drm_mode_group_destroy(&(*slot)->mode_group); |
265 | drm_mode_group_destroy(&(*slot)->mode_group); |
266 | kfree(*slot); |
266 | kfree(*slot); |
267 | *slot = NULL; |
267 | *slot = NULL; |
268 | } |
268 | } |
269 | } |
269 | } |
270 | 270 | ||
271 | static int drm_minor_register(struct drm_device *dev, unsigned int type) |
271 | static int drm_minor_register(struct drm_device *dev, unsigned int type) |
272 | { |
272 | { |
273 | struct drm_minor *new_minor; |
273 | struct drm_minor *new_minor; |
274 | unsigned long flags; |
274 | unsigned long flags; |
275 | int ret; |
275 | int ret; |
276 | int minor_id; |
276 | int minor_id; |
277 | 277 | ||
278 | DRM_DEBUG("\n"); |
278 | DRM_DEBUG("\n"); |
279 | 279 | ||
280 | new_minor = *drm_minor_get_slot(dev, type); |
280 | new_minor = *drm_minor_get_slot(dev, type); |
281 | if (!new_minor) |
281 | if (!new_minor) |
282 | return 0; |
282 | return 0; |
283 | 283 | ||
284 | idr_preload(GFP_KERNEL); |
284 | idr_preload(GFP_KERNEL); |
285 | spin_lock_irqsave(&drm_minor_lock, flags); |
285 | spin_lock_irqsave(&drm_minor_lock, flags); |
286 | minor_id = idr_alloc(&drm_minors_idr, |
286 | minor_id = idr_alloc(&drm_minors_idr, |
287 | NULL, |
287 | NULL, |
288 | 64 * type, |
288 | 64 * type, |
289 | 64 * (type + 1), |
289 | 64 * (type + 1), |
290 | GFP_NOWAIT); |
290 | GFP_NOWAIT); |
291 | spin_unlock_irqrestore(&drm_minor_lock, flags); |
291 | spin_unlock_irqrestore(&drm_minor_lock, flags); |
292 | idr_preload_end(); |
292 | idr_preload_end(); |
293 | 293 | ||
294 | if (minor_id < 0) |
294 | if (minor_id < 0) |
295 | return minor_id; |
295 | return minor_id; |
296 | 296 | ||
297 | new_minor->index = minor_id; |
297 | new_minor->index = minor_id; |
298 | 298 | ||
299 | ret = drm_debugfs_init(new_minor, minor_id, drm_debugfs_root); |
299 | ret = drm_debugfs_init(new_minor, minor_id, drm_debugfs_root); |
300 | if (ret) { |
300 | if (ret) { |
301 | DRM_ERROR("DRM: Failed to initialize /sys/kernel/debug/dri.\n"); |
301 | DRM_ERROR("DRM: Failed to initialize /sys/kernel/debug/dri.\n"); |
302 | goto err_id; |
302 | goto err_id; |
303 | } |
303 | } |
304 | 304 | ||
305 | ret = drm_sysfs_device_add(new_minor); |
305 | ret = drm_sysfs_device_add(new_minor); |
306 | if (ret) { |
306 | if (ret) { |
307 | DRM_ERROR("DRM: Error sysfs_device_add.\n"); |
307 | DRM_ERROR("DRM: Error sysfs_device_add.\n"); |
308 | goto err_debugfs; |
308 | goto err_debugfs; |
309 | } |
309 | } |
310 | 310 | ||
311 | /* replace NULL with @minor so lookups will succeed from now on */ |
311 | /* replace NULL with @minor so lookups will succeed from now on */ |
312 | spin_lock_irqsave(&drm_minor_lock, flags); |
312 | spin_lock_irqsave(&drm_minor_lock, flags); |
313 | idr_replace(&drm_minors_idr, new_minor, new_minor->index); |
313 | idr_replace(&drm_minors_idr, new_minor, new_minor->index); |
314 | spin_unlock_irqrestore(&drm_minor_lock, flags); |
314 | spin_unlock_irqrestore(&drm_minor_lock, flags); |
315 | 315 | ||
316 | DRM_DEBUG("new minor assigned %d\n", minor_id); |
316 | DRM_DEBUG("new minor assigned %d\n", minor_id); |
317 | return 0; |
317 | return 0; |
318 | 318 | ||
319 | err_debugfs: |
319 | err_debugfs: |
320 | drm_debugfs_cleanup(new_minor); |
320 | drm_debugfs_cleanup(new_minor); |
321 | err_id: |
321 | err_id: |
322 | spin_lock_irqsave(&drm_minor_lock, flags); |
322 | spin_lock_irqsave(&drm_minor_lock, flags); |
323 | idr_remove(&drm_minors_idr, minor_id); |
323 | idr_remove(&drm_minors_idr, minor_id); |
324 | spin_unlock_irqrestore(&drm_minor_lock, flags); |
324 | spin_unlock_irqrestore(&drm_minor_lock, flags); |
325 | new_minor->index = 0; |
325 | new_minor->index = 0; |
326 | return ret; |
326 | return ret; |
327 | } |
327 | } |
328 | 328 | ||
329 | static void drm_minor_unregister(struct drm_device *dev, unsigned int type) |
329 | static void drm_minor_unregister(struct drm_device *dev, unsigned int type) |
330 | { |
330 | { |
331 | struct drm_minor *minor; |
331 | struct drm_minor *minor; |
332 | unsigned long flags; |
332 | unsigned long flags; |
333 | 333 | ||
334 | minor = *drm_minor_get_slot(dev, type); |
334 | minor = *drm_minor_get_slot(dev, type); |
335 | if (!minor || !minor->kdev) |
335 | if (!minor || !minor->kdev) |
336 | return; |
336 | return; |
337 | 337 | ||
338 | spin_lock_irqsave(&drm_minor_lock, flags); |
338 | spin_lock_irqsave(&drm_minor_lock, flags); |
339 | idr_remove(&drm_minors_idr, minor->index); |
339 | idr_remove(&drm_minors_idr, minor->index); |
340 | spin_unlock_irqrestore(&drm_minor_lock, flags); |
340 | spin_unlock_irqrestore(&drm_minor_lock, flags); |
341 | minor->index = 0; |
341 | minor->index = 0; |
342 | 342 | ||
343 | drm_debugfs_cleanup(minor); |
343 | drm_debugfs_cleanup(minor); |
344 | drm_sysfs_device_remove(minor); |
344 | drm_sysfs_device_remove(minor); |
345 | } |
345 | } |
346 | 346 | ||
347 | /** |
347 | /** |
348 | * drm_minor_acquire - Acquire a DRM minor |
348 | * drm_minor_acquire - Acquire a DRM minor |
349 | * @minor_id: Minor ID of the DRM-minor |
349 | * @minor_id: Minor ID of the DRM-minor |
350 | * |
350 | * |
351 | * Looks up the given minor-ID and returns the respective DRM-minor object. The |
351 | * Looks up the given minor-ID and returns the respective DRM-minor object. The |
352 | * refence-count of the underlying device is increased so you must release this |
352 | * refence-count of the underlying device is increased so you must release this |
353 | * object with drm_minor_release(). |
353 | * object with drm_minor_release(). |
354 | * |
354 | * |
355 | * As long as you hold this minor, it is guaranteed that the object and the |
355 | * As long as you hold this minor, it is guaranteed that the object and the |
356 | * minor->dev pointer will stay valid! However, the device may get unplugged and |
356 | * minor->dev pointer will stay valid! However, the device may get unplugged and |
357 | * unregistered while you hold the minor. |
357 | * unregistered while you hold the minor. |
358 | * |
358 | * |
359 | * Returns: |
359 | * Returns: |
360 | * Pointer to minor-object with increased device-refcount, or PTR_ERR on |
360 | * Pointer to minor-object with increased device-refcount, or PTR_ERR on |
361 | * failure. |
361 | * failure. |
362 | */ |
362 | */ |
363 | struct drm_minor *drm_minor_acquire(unsigned int minor_id) |
363 | struct drm_minor *drm_minor_acquire(unsigned int minor_id) |
364 | { |
364 | { |
365 | struct drm_minor *minor; |
365 | struct drm_minor *minor; |
366 | unsigned long flags; |
366 | unsigned long flags; |
367 | 367 | ||
368 | spin_lock_irqsave(&drm_minor_lock, flags); |
368 | spin_lock_irqsave(&drm_minor_lock, flags); |
369 | minor = idr_find(&drm_minors_idr, minor_id); |
369 | minor = idr_find(&drm_minors_idr, minor_id); |
370 | if (minor) |
370 | if (minor) |
371 | drm_dev_ref(minor->dev); |
371 | drm_dev_ref(minor->dev); |
372 | spin_unlock_irqrestore(&drm_minor_lock, flags); |
372 | spin_unlock_irqrestore(&drm_minor_lock, flags); |
373 | 373 | ||
374 | if (!minor) { |
374 | if (!minor) { |
375 | return ERR_PTR(-ENODEV); |
375 | return ERR_PTR(-ENODEV); |
376 | } else if (drm_device_is_unplugged(minor->dev)) { |
376 | } else if (drm_device_is_unplugged(minor->dev)) { |
377 | drm_dev_unref(minor->dev); |
377 | drm_dev_unref(minor->dev); |
378 | return ERR_PTR(-ENODEV); |
378 | return ERR_PTR(-ENODEV); |
379 | } |
379 | } |
380 | 380 | ||
381 | return minor; |
381 | return minor; |
382 | } |
382 | } |
383 | 383 | ||
384 | /** |
384 | /** |
385 | * drm_minor_release - Release DRM minor |
385 | * drm_minor_release - Release DRM minor |
386 | * @minor: Pointer to DRM minor object |
386 | * @minor: Pointer to DRM minor object |
387 | * |
387 | * |
388 | * Release a minor that was previously acquired via drm_minor_acquire(). |
388 | * Release a minor that was previously acquired via drm_minor_acquire(). |
389 | */ |
389 | */ |
390 | void drm_minor_release(struct drm_minor *minor) |
390 | void drm_minor_release(struct drm_minor *minor) |
391 | { |
391 | { |
392 | drm_dev_unref(minor->dev); |
392 | drm_dev_unref(minor->dev); |
393 | } |
393 | } |
394 | 394 | ||
395 | /** |
395 | /** |
396 | * drm_put_dev - Unregister and release a DRM device |
396 | * drm_put_dev - Unregister and release a DRM device |
397 | * @dev: DRM device |
397 | * @dev: DRM device |
398 | * |
398 | * |
399 | * Called at module unload time or when a PCI device is unplugged. |
399 | * Called at module unload time or when a PCI device is unplugged. |
400 | * |
400 | * |
401 | * Use of this function is discouraged. It will eventually go away completely. |
401 | * Use of this function is discouraged. It will eventually go away completely. |
402 | * Please use drm_dev_unregister() and drm_dev_unref() explicitly instead. |
402 | * Please use drm_dev_unregister() and drm_dev_unref() explicitly instead. |
403 | * |
403 | * |
404 | * Cleans up all DRM device, calling drm_lastclose(). |
404 | * Cleans up all DRM device, calling drm_lastclose(). |
405 | */ |
405 | */ |
406 | void drm_put_dev(struct drm_device *dev) |
406 | void drm_put_dev(struct drm_device *dev) |
407 | { |
407 | { |
408 | DRM_DEBUG("\n"); |
408 | DRM_DEBUG("\n"); |
409 | 409 | ||
410 | if (!dev) { |
410 | if (!dev) { |
411 | DRM_ERROR("cleanup called no dev\n"); |
411 | DRM_ERROR("cleanup called no dev\n"); |
412 | return; |
412 | return; |
413 | } |
413 | } |
414 | 414 | ||
415 | drm_dev_unregister(dev); |
415 | drm_dev_unregister(dev); |
416 | drm_dev_unref(dev); |
416 | drm_dev_unref(dev); |
417 | } |
417 | } |
418 | EXPORT_SYMBOL(drm_put_dev); |
418 | EXPORT_SYMBOL(drm_put_dev); |
419 | 419 | ||
420 | void drm_unplug_dev(struct drm_device *dev) |
420 | void drm_unplug_dev(struct drm_device *dev) |
421 | { |
421 | { |
422 | /* for a USB device */ |
422 | /* for a USB device */ |
423 | drm_minor_unregister(dev, DRM_MINOR_LEGACY); |
423 | drm_minor_unregister(dev, DRM_MINOR_LEGACY); |
424 | drm_minor_unregister(dev, DRM_MINOR_RENDER); |
424 | drm_minor_unregister(dev, DRM_MINOR_RENDER); |
425 | drm_minor_unregister(dev, DRM_MINOR_CONTROL); |
425 | drm_minor_unregister(dev, DRM_MINOR_CONTROL); |
426 | 426 | ||
427 | mutex_lock(&drm_global_mutex); |
427 | mutex_lock(&drm_global_mutex); |
428 | 428 | ||
429 | drm_device_set_unplugged(dev); |
429 | drm_device_set_unplugged(dev); |
430 | 430 | ||
431 | if (dev->open_count == 0) { |
431 | if (dev->open_count == 0) { |
432 | drm_put_dev(dev); |
432 | drm_put_dev(dev); |
433 | } |
433 | } |
434 | mutex_unlock(&drm_global_mutex); |
434 | mutex_unlock(&drm_global_mutex); |
435 | } |
435 | } |
436 | EXPORT_SYMBOL(drm_unplug_dev); |
436 | EXPORT_SYMBOL(drm_unplug_dev); |
437 | 437 | ||
438 | /* |
438 | /* |
439 | * DRM internal mount |
439 | * DRM internal mount |
440 | * We want to be able to allocate our own "struct address_space" to control |
440 | * We want to be able to allocate our own "struct address_space" to control |
441 | * memory-mappings in VRAM (or stolen RAM, ...). However, core MM does not allow |
441 | * memory-mappings in VRAM (or stolen RAM, ...). However, core MM does not allow |
442 | * stand-alone address_space objects, so we need an underlying inode. As there |
442 | * stand-alone address_space objects, so we need an underlying inode. As there |
443 | * is no way to allocate an independent inode easily, we need a fake internal |
443 | * is no way to allocate an independent inode easily, we need a fake internal |
444 | * VFS mount-point. |
444 | * VFS mount-point. |
445 | * |
445 | * |
446 | * The drm_fs_inode_new() function allocates a new inode, drm_fs_inode_free() |
446 | * The drm_fs_inode_new() function allocates a new inode, drm_fs_inode_free() |
447 | * frees it again. You are allowed to use iget() and iput() to get references to |
447 | * frees it again. You are allowed to use iget() and iput() to get references to |
448 | * the inode. But each drm_fs_inode_new() call must be paired with exactly one |
448 | * the inode. But each drm_fs_inode_new() call must be paired with exactly one |
449 | * drm_fs_inode_free() call (which does not have to be the last iput()). |
449 | * drm_fs_inode_free() call (which does not have to be the last iput()). |
450 | * We use drm_fs_inode_*() to manage our internal VFS mount-point and share it |
450 | * We use drm_fs_inode_*() to manage our internal VFS mount-point and share it |
451 | * between multiple inode-users. You could, technically, call |
451 | * between multiple inode-users. You could, technically, call |
452 | * iget() + drm_fs_inode_free() directly after alloc and sometime later do an |
452 | * iget() + drm_fs_inode_free() directly after alloc and sometime later do an |
453 | * iput(), but this way you'd end up with a new vfsmount for each inode. |
453 | * iput(), but this way you'd end up with a new vfsmount for each inode. |
454 | */ |
454 | */ |
455 | 455 | ||
456 | static int drm_fs_cnt; |
456 | static int drm_fs_cnt; |
457 | static struct vfsmount *drm_fs_mnt; |
457 | static struct vfsmount *drm_fs_mnt; |
458 | 458 | ||
459 | static const struct dentry_operations drm_fs_dops = { |
459 | static const struct dentry_operations drm_fs_dops = { |
460 | .d_dname = simple_dname, |
460 | .d_dname = simple_dname, |
461 | }; |
461 | }; |
462 | 462 | ||
463 | static const struct super_operations drm_fs_sops = { |
463 | static const struct super_operations drm_fs_sops = { |
464 | .statfs = simple_statfs, |
464 | .statfs = simple_statfs, |
465 | }; |
465 | }; |
466 | 466 | ||
467 | static struct dentry *drm_fs_mount(struct file_system_type *fs_type, int flags, |
467 | static struct dentry *drm_fs_mount(struct file_system_type *fs_type, int flags, |
468 | const char *dev_name, void *data) |
468 | const char *dev_name, void *data) |
469 | { |
469 | { |
470 | return mount_pseudo(fs_type, |
470 | return mount_pseudo(fs_type, |
471 | "drm:", |
471 | "drm:", |
472 | &drm_fs_sops, |
472 | &drm_fs_sops, |
473 | &drm_fs_dops, |
473 | &drm_fs_dops, |
474 | 0x010203ff); |
474 | 0x010203ff); |
475 | } |
475 | } |
476 | 476 | ||
477 | static struct file_system_type drm_fs_type = { |
477 | static struct file_system_type drm_fs_type = { |
478 | .name = "drm", |
478 | .name = "drm", |
479 | .owner = THIS_MODULE, |
479 | .owner = THIS_MODULE, |
480 | .mount = drm_fs_mount, |
480 | .mount = drm_fs_mount, |
481 | .kill_sb = kill_anon_super, |
481 | .kill_sb = kill_anon_super, |
482 | }; |
482 | }; |
483 | 483 | ||
484 | #endif |
484 | #endif |
485 | 485 | ||
486 | 486 | ||
487 | 487 | ||
488 | 488 | ||
489 | 489 | ||
490 | int drm_fill_in_dev(struct drm_device *dev, |
490 | int drm_fill_in_dev(struct drm_device *dev, |
491 | const struct pci_device_id *ent, |
491 | const struct pci_device_id *ent, |
492 | struct drm_driver *driver) |
492 | struct drm_driver *driver) |
493 | { |
493 | { |
494 | int ret; |
494 | int ret; |
495 | dev->driver = driver; |
495 | dev->driver = driver; |
496 | 496 | ||
497 | INIT_LIST_HEAD(&dev->filelist); |
497 | INIT_LIST_HEAD(&dev->filelist); |
498 | INIT_LIST_HEAD(&dev->ctxlist); |
498 | INIT_LIST_HEAD(&dev->ctxlist); |
499 | INIT_LIST_HEAD(&dev->vmalist); |
499 | INIT_LIST_HEAD(&dev->vmalist); |
500 | INIT_LIST_HEAD(&dev->maplist); |
500 | INIT_LIST_HEAD(&dev->maplist); |
501 | INIT_LIST_HEAD(&dev->vblank_event_list); |
501 | INIT_LIST_HEAD(&dev->vblank_event_list); |
502 | 502 | ||
503 | spin_lock_init(&dev->buf_lock); |
503 | spin_lock_init(&dev->buf_lock); |
504 | spin_lock_init(&dev->event_lock); |
504 | spin_lock_init(&dev->event_lock); |
505 | mutex_init(&dev->struct_mutex); |
505 | mutex_init(&dev->struct_mutex); |
506 | mutex_init(&dev->ctxlist_mutex); |
506 | mutex_init(&dev->ctxlist_mutex); |
507 | 507 | ||
508 | // if (drm_ht_create(&dev->map_hash, 12)) { |
508 | // if (drm_ht_create(&dev->map_hash, 12)) { |
509 | // return -ENOMEM; |
509 | // return -ENOMEM; |
510 | // } |
510 | // } |
511 | 511 | ||
512 | 512 | ||
513 | 513 | ||
514 | if (driver->driver_features & DRIVER_GEM) { |
514 | if (driver->driver_features & DRIVER_GEM) { |
515 | ret = drm_gem_init(dev); |
515 | ret = drm_gem_init(dev); |
516 | if (ret) { |
516 | if (ret) { |
517 | DRM_ERROR("Cannot initialize graphics execution manager (GEM)\n"); |
517 | DRM_ERROR("Cannot initialize graphics execution manager (GEM)\n"); |
518 | goto err_ctxbitmap; |
518 | goto err_ctxbitmap; |
519 | } |
519 | } |
520 | } |
520 | } |
521 | 521 | ||
522 | return 0; |
522 | return 0; |
523 | 523 | ||
524 | err_ctxbitmap: |
524 | err_ctxbitmap: |
525 | // drm_lastclose(dev); |
525 | // drm_lastclose(dev); |
526 | return ret; |
526 | return ret; |
527 | } |
527 | } |
528 | EXPORT_SYMBOL(drm_fill_in_dev); |
528 | EXPORT_SYMBOL(drm_fill_in_dev); |
529 | /** |
529 | /** |
530 | * Compute size order. Returns the exponent of the smaller power of two which |
530 | * Compute size order. Returns the exponent of the smaller power of two which |
531 | * is greater or equal to given number. |
531 | * is greater or equal to given number. |
532 | * |
532 | * |
533 | * \param size size. |
533 | * \param size size. |
534 | * \return order. |
534 | * \return order. |
535 | * |
535 | * |
536 | * \todo Can be made faster. |
536 | * \todo Can be made faster. |
537 | */ |
537 | */ |
538 | int drm_order(unsigned long size) |
538 | int drm_order(unsigned long size) |
539 | { |
539 | { |
540 | int order; |
540 | int order; |
541 | unsigned long tmp; |
541 | unsigned long tmp; |
542 | 542 | ||
543 | for (order = 0, tmp = size >> 1; tmp; tmp >>= 1, order++) ; |
543 | for (order = 0, tmp = size >> 1; tmp; tmp >>= 1, order++) ; |
544 | 544 | ||
545 | if (size & (size - 1)) |
545 | if (size & (size - 1)) |
546 | ++order; |
546 | ++order; |
547 | 547 | ||
548 | return order; |
548 | return order; |
549 | } |
549 | } |
550 | 550 | ||
551 | int drm_sysfs_connector_add(struct drm_connector *connector) |
551 | int drm_sysfs_connector_add(struct drm_connector *connector) |
552 | { |
552 | { |
553 | return 0; |
553 | return 0; |
554 | } |
554 | } |
555 | 555 | ||
556 | void drm_sysfs_connector_remove(struct drm_connector *connector) |
556 | void drm_sysfs_connector_remove(struct drm_connector *connector) |
557 | { } |
557 | { } |
558 | 558 | ||
559 | void drm_sysfs_hotplug_event(struct drm_device *dev) |
559 | void drm_sysfs_hotplug_event(struct drm_device *dev) |
560 | { |
560 | { |
561 | DRM_DEBUG("generating hotplug event\n"); |
561 | DRM_DEBUG("generating hotplug event\n"); |
562 | } |
562 | }> |
563 | - | ||
564 | u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder) |
- | |
565 | { |
- | |
566 | u32 high = divisor >> 32; |
- | |
567 | u64 quot; |
- | |
568 | - | ||
569 | if (high == 0) { |
- | |
570 | u32 rem32; |
- | |
571 | quot = div_u64_rem(dividend, divisor, &rem32); |
- | |
572 | *remainder = rem32; |
- | |
573 | } else { |
- | |
574 | int n = 1 + fls(high); |
- | |
575 | quot = div_u64(dividend >> n, divisor >> n); |
- | |
576 | - | ||
577 | if (quot != 0) |
- | |
578 | quot--; |
- | |
579 | - | ||
580 | *remainder = dividend - quot * divisor; |
- | |
581 | if (*remainder >= divisor) { |
- | |
582 | quot++; |
- | |
583 | *remainder -= divisor; |
- | |
584 | } |
- | |
585 | } |
- | |
586 | - | ||
587 | return quot; |
- | |
588 | } |
- | |
589 | - | ||
590 | u64 div64_u64(u64 dividend, u64 divisor) |
- | |
591 | { |
- | |
592 | u32 high, d; |
- | |
593 | - | ||
594 | high = divisor >> 32; |
- | |
595 | if (high) { |
- | |
596 | unsigned int shift = fls(high); |
- | |
597 | - | ||
598 | d = divisor >> shift; |
- | |
599 | dividend >>= shift; |
- | |
600 | } else |
- | |
601 | d = divisor; |
- | |
602 | - | ||
603 | return div_u64(dividend, d); |
- | |
604 | }> |
- |