Commit 036105e3 authored by Thomas Zimmermann's avatar Thomas Zimmermann

video: Provide screen_info_get_pci_dev() to find screen_info's PCI device

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: default avatarThomas Zimmermann <tzimmermann@suse.de>
Reviewed-by: default avatarJavier Martinez Canillas <javierm@redhat.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20240212090736.11464-3-tzimmermann@suse.de
parent 75fa9b7e
...@@ -8,6 +8,7 @@ obj-$(CONFIG_VIDEO) += cmdline.o nomodeset.o ...@@ -8,6 +8,7 @@ obj-$(CONFIG_VIDEO) += cmdline.o nomodeset.o
obj-$(CONFIG_HDMI) += hdmi.o obj-$(CONFIG_HDMI) += hdmi.o
screen_info-y := screen_info_generic.o screen_info-y := screen_info_generic.o
screen_info-$(CONFIG_PCI) += screen_info_pci.o
obj-$(CONFIG_VT) += console/ obj-$(CONFIG_VT) += console/
obj-$(CONFIG_FB_STI) += console/ obj-$(CONFIG_FB_STI) += console/
......
// 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);
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
*/ */
#define SCREEN_INFO_MAX_RESOURCES 3 #define SCREEN_INFO_MAX_RESOURCES 3
struct pci_dev;
struct resource; struct resource;
static inline bool __screen_info_has_lfb(unsigned int type) 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) ...@@ -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); 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; extern struct screen_info screen_info;
#endif /* _SCREEN_INFO_H */ #endif /* _SCREEN_INFO_H */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment