From: Thomas Zimmermann <tzimmermann@suse.de>
To: javierm@redhat.com, sui.jingfeng@linux.dev, pjones@redhat.com,
deller@gmx.de, ardb@kernel.org
Cc: dri-devel@lists.freedesktop.org, linux-fbdev@vger.kernel.org,
Thomas Zimmermann <tzimmermann@suse.de>
Subject: [PATCH v4 2/8] video: Provide screen_info_get_pci_dev() to find screen_info's PCI device
Date: Mon, 12 Feb 2024 10:06:10 +0100 [thread overview]
Message-ID: <20240212090736.11464-3-tzimmermann@suse.de> (raw)
In-Reply-To: <20240212090736.11464-1-tzimmermann@suse.de>
Add screen_info_get_pci_dev() to find the PCI device of an instance
of screen_info. Does nothing on systems without PCI bus.
v3:
* search PCI device with pci_get_base_class() (Sui)
v2:
* remove ret from screen_info_pci_dev() (Javier)
Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>
---
drivers/video/Makefile | 1 +
drivers/video/screen_info_pci.c | 48 +++++++++++++++++++++++++++++++++
include/linux/screen_info.h | 10 +++++++
3 files changed, 59 insertions(+)
create mode 100644 drivers/video/screen_info_pci.c
diff --git a/drivers/video/Makefile b/drivers/video/Makefile
index 117cbdbb58c2c..ffbac4387c670 100644
--- a/drivers/video/Makefile
+++ b/drivers/video/Makefile
@@ -8,6 +8,7 @@ obj-$(CONFIG_VIDEO) += cmdline.o nomodeset.o
obj-$(CONFIG_HDMI) += hdmi.o
screen_info-y := screen_info_generic.o
+screen_info-$(CONFIG_PCI) += screen_info_pci.o
obj-$(CONFIG_VT) += console/
obj-$(CONFIG_FB_STI) += console/
diff --git a/drivers/video/screen_info_pci.c b/drivers/video/screen_info_pci.c
new file mode 100644
index 0000000000000..d8985a54ce717
--- /dev/null
+++ b/drivers/video/screen_info_pci.c
@@ -0,0 +1,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);
diff --git a/include/linux/screen_info.h b/include/linux/screen_info.h
index e7a02c5609d12..0eae08e3c6f90 100644
--- a/include/linux/screen_info.h
+++ b/include/linux/screen_info.h
@@ -9,6 +9,7 @@
*/
#define SCREEN_INFO_MAX_RESOURCES 3
+struct pci_dev;
struct resource;
static inline bool __screen_info_has_lfb(unsigned int type)
@@ -104,6 +105,15 @@ static inline unsigned int screen_info_video_type(const struct screen_info *si)
ssize_t screen_info_resources(const struct screen_info *si, struct resource *r, size_t num);
+#if defined(CONFIG_PCI)
+struct pci_dev *screen_info_pci_dev(const struct screen_info *si);
+#else
+static inline struct pci_dev *screen_info_pci_dev(const struct screen_info *si)
+{
+ return NULL;
+}
+#endif
+
extern struct screen_info screen_info;
#endif /* _SCREEN_INFO_H */
--
2.43.0
next prev parent reply other threads:[~2024-02-12 9:07 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-12 9:06 [PATCH v4 0/8] firmware/sysfb: Track parent device for screen_info Thomas Zimmermann
2024-02-12 9:06 ` [PATCH v4 1/8] video: Add helpers for decoding screen_info Thomas Zimmermann
2024-02-12 9:06 ` Thomas Zimmermann [this message]
2024-02-12 9:06 ` [PATCH v4 3/8] firmware/sysfb: Set firmware-framebuffer parent device Thomas Zimmermann
2024-02-12 9:06 ` [PATCH v4 4/8] fbdev/efifb: Remove PM for " Thomas Zimmermann
2024-02-12 9:06 ` [PATCH v4 5/8] firmware/sysfb: Create firmware device only for enabled PCI devices Thomas Zimmermann
2024-02-12 9:06 ` [PATCH v4 6/8] fbdev/efifb: Do not track parent device status Thomas Zimmermann
2024-02-12 9:06 ` [PATCH v4 7/8] firmware/sysfb: Update screen_info for relocated EFI framebuffers Thomas Zimmermann
2024-02-12 9:06 ` [PATCH v4 8/8] fbdev/efifb: Remove framebuffer relocation tracking Thomas Zimmermann
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240212090736.11464-3-tzimmermann@suse.de \
--to=tzimmermann@suse.de \
--cc=ardb@kernel.org \
--cc=deller@gmx.de \
--cc=dri-devel@lists.freedesktop.org \
--cc=javierm@redhat.com \
--cc=linux-fbdev@vger.kernel.org \
--cc=pjones@redhat.com \
--cc=sui.jingfeng@linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).