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