blob: d8985a54ce717904fb338b686462b73c16ae38f3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
// SPDX-License-Identifier: GPL-2.0
#include <linux/pci.h>
#include <linux/screen_info.h>
static struct pci_dev *__screen_info_pci_dev(struct resource *res)
{
struct pci_dev *pdev = NULL;
const struct resource *r = NULL;
if (!(res->flags & IORESOURCE_MEM))
return NULL;
while (!r && (pdev = pci_get_base_class(PCI_BASE_CLASS_DISPLAY, pdev))) {
r = pci_find_resource(pdev, res);
}
return pdev;
}
/**
* screen_info_pci_dev() - Return PCI parent device that contains screen_info's framebuffer
* @si: the screen_info
*
* Returns:
* The screen_info's parent device or NULL on success, or a pointer-encoded
* errno value otherwise. The value NULL is not an error. It signals that no
* PCI device has been found.
*/
struct pci_dev *screen_info_pci_dev(const struct screen_info *si)
{
struct resource res[SCREEN_INFO_MAX_RESOURCES];
ssize_t i, numres;
numres = screen_info_resources(si, res, ARRAY_SIZE(res));
if (numres < 0)
return ERR_PTR(numres);
for (i = 0; i < numres; ++i) {
struct pci_dev *pdev = __screen_info_pci_dev(&res[i]);
if (pdev)
return pdev;
}
return NULL;
}
EXPORT_SYMBOL(screen_info_pci_dev);
|