drm_pci.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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/list.h>
  26. #include <linux/mutex.h>
  27. #include <linux/pci.h>
  28. #include <linux/slab.h>
  29. #include <drm/drm_auth.h>
  30. #include <drm/drm.h>
  31. #include <drm/drm_drv.h>
  32. #include <drm/drm_print.h>
  33. #include "drm_internal.h"
  34. static int drm_get_pci_domain(struct drm_device *dev)
  35. {
  36. #ifndef __alpha__
  37. /* For historical reasons, drm_get_pci_domain() is busticated
  38. * on most archs and has to remain so for userspace interface
  39. * < 1.4, except on alpha which was right from the beginning
  40. */
  41. if (dev->if_version < 0x10004)
  42. return 0;
  43. #endif /* __alpha__ */
  44. return pci_domain_nr(to_pci_dev(dev->dev)->bus);
  45. }
  46. int drm_pci_set_busid(struct drm_device *dev, struct drm_master *master)
  47. {
  48. struct pci_dev *pdev = to_pci_dev(dev->dev);
  49. master->unique = kasprintf(GFP_KERNEL, "pci:%04x:%02x:%02x.%d",
  50. drm_get_pci_domain(dev),
  51. pdev->bus->number,
  52. PCI_SLOT(pdev->devfn),
  53. PCI_FUNC(pdev->devfn));
  54. if (!master->unique)
  55. return -ENOMEM;
  56. master->unique_len = strlen(master->unique);
  57. return 0;
  58. }