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