[v2,2/8] video: Provide screen_info_get_pci_dev() to find screen_info's PCI device
Thomas Zimmermann
tzimmermann at suse.de
Mon Feb 5 08:14:27 UTC 2024
Hi
Am 02.02.24 um 17:31 schrieb Sui Jingfeng:
> Hi,
>
>
> On 2024/2/2 19:58, Thomas Zimmermann wrote:
>> 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)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_signature.asc
Type: application/pgp-signature
Size: 840 bytes
Desc: OpenPGP digital signature
URL: <https://lists.freedesktop.org/archives/dri-devel/attachments/20240205/b1db8310/attachment.sig>
More information about the dri-devel
mailing list