Thread (29 messages) 29 messages, 3 authors, 2024-02-07

Re: [v2,2/8] video: Provide screen_info_get_pci_dev() to find screen_info's PCI device

From: Thomas Zimmermann <tzimmermann@suse.de>
Date: 2024-02-05 08:14:33
Also in: dri-devel

Hi

Am 02.02.24 um 17:31 schrieb Sui Jingfeng:
Hi,


On 2024/2/2 19:58, Thomas Zimmermann wrote:
quoted
diff --git a/drivers/video/screen_info_pci.c 
b/drivers/video/screen_info_pci.c
new file mode 100644
index 0000000000000..d959a4c6ba3d5
--- /dev/null
+++ b/drivers/video/screen_info_pci.c
@@ -0,0 +1,52 @@
+// 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;
+
+    if (!(res->flags & IORESOURCE_MEM))
+        return NULL;
+
+    for_each_pci_dev(pdev) {
+        const struct resource *r;
+
+        if ((pdev->class >> 16) != PCI_BASE_CLASS_DISPLAY)
+            continue;
+
+        r = pci_find_resource(pdev, res);
+        if (r)
+            return pdev;
+    }
+
+    return NULL;
+}

I recommend using the pci_get_base_class() or pci_get_class() helper 
function at here,
for example:
Good idea, I think I'll do that. Thanks!

Best regards
Thomas

static struct pci_dev *__screen_info_pci_dev(struct resource *res)
{
     struct pci_dev *pdev;

     if (!(res->flags & IORESOURCE_MEM))
         return NULL;

     while ((pdev = pci_get_base_class(PCI_BASE_CLASS_DISPLAY, pdev))) {
         if (pci_find_resource(pdev, res))
             return pdev;
     }

     return NULL;
}
-- 
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstrasse 146, 90461 Nuernberg, Germany
GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman
HRB 36809 (AG Nuernberg)

Attachments

Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help