aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Herrmann <dh.herrmann@gmail.com>2013-10-02 05:23:34 -0400
committerDave Airlie <airlied@redhat.com>2013-10-09 00:38:15 -0400
commit1bb72532ac260a2d3982b40bdd4c936d779d0d16 (patch)
treef0ec6e8d7d68fe8dff496f0226ac3837fb3aac3d
parent16eb5f4379b2097438a224381be3b4d9e56ac979 (diff)
drm: add drm_dev_alloc() helper
Instead of managing device allocation+initialization in each bus-driver, we should do that in a central place. drm_fill_in_dev() already does most of it, but also requires the global drm lock for partial AGP device registration. Split both apart so we have a clean device initialization/allocation phase, and a registration phase. Signed-off-by: David Herrmann <dh.herrmann@gmail.com> Signed-off-by: Dave Airlie <airlied@redhat.com>
-rw-r--r--drivers/gpu/drm/drm_pci.c4
-rw-r--r--drivers/gpu/drm/drm_platform.c3
-rw-r--r--drivers/gpu/drm/drm_stub.c121
-rw-r--r--drivers/gpu/drm/drm_usb.c7
-rw-r--r--include/drm/drmP.h2
5 files changed, 80 insertions, 57 deletions
diff --git a/drivers/gpu/drm/drm_pci.c b/drivers/gpu/drm/drm_pci.c
index 1f96cee6eee8..d2758be37a93 100644
--- a/drivers/gpu/drm/drm_pci.c
+++ b/drivers/gpu/drm/drm_pci.c
@@ -322,7 +322,7 @@ int drm_get_pci_dev(struct pci_dev *pdev, const struct pci_device_id *ent,
322 322
323 DRM_DEBUG("\n"); 323 DRM_DEBUG("\n");
324 324
325 dev = kzalloc(sizeof(*dev), GFP_KERNEL); 325 dev = drm_dev_alloc(driver, &pdev->dev);
326 if (!dev) 326 if (!dev)
327 return -ENOMEM; 327 return -ENOMEM;
328 328
@@ -331,8 +331,6 @@ int drm_get_pci_dev(struct pci_dev *pdev, const struct pci_device_id *ent,
331 goto err_g1; 331 goto err_g1;
332 332
333 dev->pdev = pdev; 333 dev->pdev = pdev;
334 dev->dev = &pdev->dev;
335
336 dev->pci_device = pdev->device; 334 dev->pci_device = pdev->device;
337 dev->pci_vendor = pdev->vendor; 335 dev->pci_vendor = pdev->vendor;
338 336
diff --git a/drivers/gpu/drm/drm_platform.c b/drivers/gpu/drm/drm_platform.c
index f7a18c6ba4c4..fb2721738a8a 100644
--- a/drivers/gpu/drm/drm_platform.c
+++ b/drivers/gpu/drm/drm_platform.c
@@ -47,12 +47,11 @@ static int drm_get_platform_dev(struct platform_device *platdev,
47 47
48 DRM_DEBUG("\n"); 48 DRM_DEBUG("\n");
49 49
50 dev = kzalloc(sizeof(*dev), GFP_KERNEL); 50 dev = drm_dev_alloc(driver, &platdev->dev);
51 if (!dev) 51 if (!dev)
52 return -ENOMEM; 52 return -ENOMEM;
53 53
54 dev->platformdev = platdev; 54 dev->platformdev = platdev;
55 dev->dev = &platdev->dev;
56 55
57 mutex_lock(&drm_global_mutex); 56 mutex_lock(&drm_global_mutex);
58 57
diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
index 39d864576be4..64bd52f13199 100644
--- a/drivers/gpu/drm/drm_stub.c
+++ b/drivers/gpu/drm/drm_stub.c
@@ -260,60 +260,15 @@ int drm_fill_in_dev(struct drm_device *dev,
260{ 260{
261 int retcode; 261 int retcode;
262 262
263 INIT_LIST_HEAD(&dev->filelist);
264 INIT_LIST_HEAD(&dev->ctxlist);
265 INIT_LIST_HEAD(&dev->vmalist);
266 INIT_LIST_HEAD(&dev->maplist);
267 INIT_LIST_HEAD(&dev->vblank_event_list);
268
269 spin_lock_init(&dev->count_lock);
270 spin_lock_init(&dev->event_lock);
271 mutex_init(&dev->struct_mutex);
272 mutex_init(&dev->ctxlist_mutex);
273
274 if (drm_ht_create(&dev->map_hash, 12)) {
275 return -ENOMEM;
276 }
277
278 /* the DRM has 6 basic counters */
279 dev->counters = 6;
280 dev->types[0] = _DRM_STAT_LOCK;
281 dev->types[1] = _DRM_STAT_OPENS;
282 dev->types[2] = _DRM_STAT_CLOSES;
283 dev->types[3] = _DRM_STAT_IOCTLS;
284 dev->types[4] = _DRM_STAT_LOCKS;
285 dev->types[5] = _DRM_STAT_UNLOCKS;
286
287 dev->driver = driver;
288
289 if (dev->driver->bus->agp_init) { 263 if (dev->driver->bus->agp_init) {
290 retcode = dev->driver->bus->agp_init(dev); 264 retcode = dev->driver->bus->agp_init(dev);
291 if (retcode)
292 goto error_out_unreg;
293 }
294
295
296
297 retcode = drm_ctxbitmap_init(dev);
298 if (retcode) {
299 DRM_ERROR("Cannot allocate memory for context bitmap.\n");
300 goto error_out_unreg;
301 }
302
303 if (driver->driver_features & DRIVER_GEM) {
304 retcode = drm_gem_init(dev);
305 if (retcode) { 265 if (retcode) {
306 DRM_ERROR("Cannot initialize graphics execution " 266 drm_lastclose(dev);
307 "manager (GEM)\n"); 267 return retcode;
308 goto error_out_unreg;
309 } 268 }
310 } 269 }
311 270
312 return 0; 271 return 0;
313
314 error_out_unreg:
315 drm_lastclose(dev);
316 return retcode;
317} 272}
318EXPORT_SYMBOL(drm_fill_in_dev); 273EXPORT_SYMBOL(drm_fill_in_dev);
319 274
@@ -490,3 +445,75 @@ void drm_unplug_dev(struct drm_device *dev)
490 mutex_unlock(&drm_global_mutex); 445 mutex_unlock(&drm_global_mutex);
491} 446}
492EXPORT_SYMBOL(drm_unplug_dev); 447EXPORT_SYMBOL(drm_unplug_dev);
448
449/**
450 * drm_dev_alloc - Allocate new drm device
451 * @driver: DRM driver to allocate device for
452 * @parent: Parent device object
453 *
454 * Allocate and initialize a new DRM device. No device registration is done.
455 *
456 * RETURNS:
457 * Pointer to new DRM device, or NULL if out of memory.
458 */
459struct drm_device *drm_dev_alloc(struct drm_driver *driver,
460 struct device *parent)
461{
462 struct drm_device *dev;
463 int ret;
464
465 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
466 if (!dev)
467 return NULL;
468
469 dev->dev = parent;
470 dev->driver = driver;
471
472 INIT_LIST_HEAD(&dev->filelist);
473 INIT_LIST_HEAD(&dev->ctxlist);
474 INIT_LIST_HEAD(&dev->vmalist);
475 INIT_LIST_HEAD(&dev->maplist);
476 INIT_LIST_HEAD(&dev->vblank_event_list);
477
478 spin_lock_init(&dev->count_lock);
479 spin_lock_init(&dev->event_lock);
480 mutex_init(&dev->struct_mutex);
481 mutex_init(&dev->ctxlist_mutex);
482
483 /* the DRM has 6 basic counters */
484 dev->counters = 6;
485 dev->types[0] = _DRM_STAT_LOCK;
486 dev->types[1] = _DRM_STAT_OPENS;
487 dev->types[2] = _DRM_STAT_CLOSES;
488 dev->types[3] = _DRM_STAT_IOCTLS;
489 dev->types[4] = _DRM_STAT_LOCKS;
490 dev->types[5] = _DRM_STAT_UNLOCKS;
491
492 if (drm_ht_create(&dev->map_hash, 12))
493 goto err_free;
494
495 ret = drm_ctxbitmap_init(dev);
496 if (ret) {
497 DRM_ERROR("Cannot allocate memory for context bitmap.\n");
498 goto err_ht;
499 }
500
501 if (driver->driver_features & DRIVER_GEM) {
502 ret = drm_gem_init(dev);
503 if (ret) {
504 DRM_ERROR("Cannot initialize graphics execution manager (GEM)\n");
505 goto err_ctxbitmap;
506 }
507 }
508
509 return dev;
510
511err_ctxbitmap:
512 drm_ctxbitmap_cleanup(dev);
513err_ht:
514 drm_ht_remove(&dev->map_hash);
515err_free:
516 kfree(dev);
517 return NULL;
518}
519EXPORT_SYMBOL(drm_dev_alloc);
diff --git a/drivers/gpu/drm/drm_usb.c b/drivers/gpu/drm/drm_usb.c
index 87664723b9ce..34ad8edfe806 100644
--- a/drivers/gpu/drm/drm_usb.c
+++ b/drivers/gpu/drm/drm_usb.c
@@ -7,18 +7,15 @@ int drm_get_usb_dev(struct usb_interface *interface,
7 struct drm_driver *driver) 7 struct drm_driver *driver)
8{ 8{
9 struct drm_device *dev; 9 struct drm_device *dev;
10 struct usb_device *usbdev;
11 int ret; 10 int ret;
12 11
13 DRM_DEBUG("\n"); 12 DRM_DEBUG("\n");
14 13
15 dev = kzalloc(sizeof(*dev), GFP_KERNEL); 14 dev = drm_dev_alloc(driver, &interface->dev);
16 if (!dev) 15 if (!dev)
17 return -ENOMEM; 16 return -ENOMEM;
18 17
19 usbdev = interface_to_usbdev(interface); 18 dev->usbdev = interface_to_usbdev(interface);
20 dev->usbdev = usbdev;
21 dev->dev = &interface->dev;
22 19
23 mutex_lock(&drm_global_mutex); 20 mutex_lock(&drm_global_mutex);
24 21
diff --git a/include/drm/drmP.h b/include/drm/drmP.h
index 69dd5fd5b215..ea545b5ad467 100644
--- a/include/drm/drmP.h
+++ b/include/drm/drmP.h
@@ -1643,6 +1643,8 @@ static __inline__ void drm_core_dropmap(struct drm_local_map *map)
1643extern int drm_fill_in_dev(struct drm_device *dev, 1643extern int drm_fill_in_dev(struct drm_device *dev,
1644 const struct pci_device_id *ent, 1644 const struct pci_device_id *ent,
1645 struct drm_driver *driver); 1645 struct drm_driver *driver);
1646struct drm_device *drm_dev_alloc(struct drm_driver *driver,
1647 struct device *parent);
1646int drm_get_minor(struct drm_device *dev, struct drm_minor **minor, int type); 1648int drm_get_minor(struct drm_device *dev, struct drm_minor **minor, int type);
1647/*@}*/ 1649/*@}*/
1648 1650