drm_pci.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * Copyright 2003 José Fonseca.
  3. * Copyright 2003 Leif Delgass.
  4. * All Rights Reserved.
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a
  7. * copy of this software and associated documentation files (the "Software"),
  8. * to deal in the Software without restriction, including without limitation
  9. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  10. * and/or sell copies of the Software, and to permit persons to whom the
  11. * Software is furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice (including the next
  14. * paragraph) shall be included in all copies or substantial portions of the
  15. * Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  20. * AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  21. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  22. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  23. */
  24. #include <linux/dma-mapping.h>
  25. #include <linux/export.h>
  26. #include <linux/list.h>
  27. #include <linux/mutex.h>
  28. #include <linux/pci.h>
  29. #include <linux/slab.h>
  30. #include <drm/drm_auth.h>
  31. #include <drm/drm.h>
  32. #include <drm/drm_drv.h>
  33. #include <drm/drm_print.h>
  34. #include "drm_internal.h"
  35. static int drm_get_pci_domain(struct drm_device *dev)
  36. {
  37. #ifndef __alpha__
  38. /* For historical reasons, drm_get_pci_domain() is busticated
  39. * on most archs and has to remain so for userspace interface
  40. * < 1.4, except on alpha which was right from the beginning
  41. */
  42. if (dev->if_version < 0x10004)
  43. return 0;
  44. #endif /* __alpha__ */
  45. return pci_domain_nr(to_pci_dev(dev->dev)->bus);
  46. }
  47. int drm_pci_set_busid(struct drm_device *dev, struct drm_master *master)
  48. {
  49. struct pci_dev *pdev = to_pci_dev(dev->dev);
  50. master->unique = kasprintf(GFP_KERNEL, "pci:%04x:%02x:%02x.%d",
  51. drm_get_pci_domain(dev),
  52. pdev->bus->number,
  53. PCI_SLOT(pdev->devfn),
  54. PCI_FUNC(pdev->devfn));
  55. if (!master->unique)
  56. return -ENOMEM;
  57. master->unique_len = strlen(master->unique);
  58. return 0;
  59. }