bus.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * Copyright (C) 2013 NVIDIA Corporation
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. */
  8. #include "drm.h"
  9. static int drm_host1x_set_busid(struct drm_device *dev,
  10. struct drm_master *master)
  11. {
  12. const char *device = dev_name(dev->dev);
  13. const char *driver = dev->driver->name;
  14. const char *bus = dev->dev->bus->name;
  15. int length;
  16. master->unique_len = strlen(bus) + 1 + strlen(device);
  17. master->unique_size = master->unique_len;
  18. master->unique = kmalloc(master->unique_len + 1, GFP_KERNEL);
  19. if (!master->unique)
  20. return -ENOMEM;
  21. snprintf(master->unique, master->unique_len + 1, "%s:%s", bus, device);
  22. length = strlen(driver) + 1 + master->unique_len;
  23. dev->devname = kmalloc(length + 1, GFP_KERNEL);
  24. if (!dev->devname)
  25. return -ENOMEM;
  26. snprintf(dev->devname, length + 1, "%s@%s", driver, master->unique);
  27. return 0;
  28. }
  29. static struct drm_bus drm_host1x_bus = {
  30. .bus_type = DRIVER_BUS_HOST1X,
  31. .set_busid = drm_host1x_set_busid,
  32. };
  33. int drm_host1x_init(struct drm_driver *driver, struct host1x_device *device)
  34. {
  35. struct drm_device *drm;
  36. int ret;
  37. INIT_LIST_HEAD(&driver->device_list);
  38. driver->bus = &drm_host1x_bus;
  39. drm = drm_dev_alloc(driver, &device->dev);
  40. if (!drm)
  41. return -ENOMEM;
  42. ret = drm_dev_register(drm, 0);
  43. if (ret)
  44. goto err_free;
  45. DRM_INFO("Initialized %s %d.%d.%d %s on minor %d\n", driver->name,
  46. driver->major, driver->minor, driver->patchlevel,
  47. driver->date, drm->primary->index);
  48. return 0;
  49. err_free:
  50. drm_dev_free(drm);
  51. return ret;
  52. }
  53. void drm_host1x_exit(struct drm_driver *driver, struct host1x_device *device)
  54. {
  55. struct tegra_drm *tegra = dev_get_drvdata(&device->dev);
  56. drm_put_dev(tegra->drm);
  57. }