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