[U-Boot] [PATCH 03/25] dm: pci: Add a driver-model version of pci_find_device()
Bin Meng
bmeng.cn at gmail.com
Wed Nov 18 05:26:55 CET 2015
On Tue, Nov 17, 2015 at 11:53 AM, Simon Glass <sjg at chromium.org> wrote:
> Add a function which scans the driver model device information rather
> than scanning the PCI bus again.
>
> Signed-off-by: Simon Glass <sjg at chromium.org>
> ---
>
> drivers/pci/pci-uclass.c | 39 +++++++++++++++++++++++++++++++++++++++
> include/pci.h | 12 ++++++++++++
> 2 files changed, 51 insertions(+)
>
> diff --git a/drivers/pci/pci-uclass.c b/drivers/pci/pci-uclass.c
> index 8087e2d..6376e43 100644
> --- a/drivers/pci/pci-uclass.c
> +++ b/drivers/pci/pci-uclass.c
> @@ -194,6 +194,45 @@ int pci_find_device_id(struct pci_device_id *ids, int index,
> return -ENODEV;
> }
>
> +static int dm_pci_bus_find_device(struct udevice *bus, unsigned int vendor,
> + unsigned int device, int *indexp,
> + struct udevice **devp)
> +{
> + struct pci_child_platdata *pplat;
> + struct udevice *dev;
> +
> + for (device_find_first_child(bus, &dev);
> + dev;
> + device_find_next_child(&dev)) {
> + pplat = dev_get_parent_platdata(dev);
> + if (pplat->vendor == vendor && pplat->device == device) {
> + if (!(*indexp)--) {
> + *devp = dev;
> + return 0;
> + }
> + }
> + }
> +
> + return -ENODEV;
> +}
> +
> +int dm_pci_find_device(unsigned int vendor, unsigned int device, int index,
> + struct udevice **devp)
> +{
> + struct udevice *bus;
> +
> + /* Scan all known buses */
> + for (uclass_first_device(UCLASS_PCI, &bus);
> + bus;
> + uclass_next_device(&bus)) {
> + if (!dm_pci_bus_find_device(bus, vendor, device, &index, devp))
> + return device_probe(*devp);
> + }
> + *devp = NULL;
> +
> + return -ENODEV;
> +}
> +
> int pci_bus_write_config(struct udevice *bus, pci_dev_t bdf, int offset,
> unsigned long value, enum pci_size_t size)
> {
> diff --git a/include/pci.h b/include/pci.h
> index 8d56fdd..f29804f 100644
> --- a/include/pci.h
> +++ b/include/pci.h
> @@ -1174,6 +1174,18 @@ int dm_pciauto_config_device(struct udevice *dev);
> void dm_pciauto_region_init(struct pci_region *res);
>
> /**
> + * dm_pci_find_device() - find a device by vendor/device ID
> + *
> + * @vendor: Vendor ID
> + * @device: Device ID
> + * @index: 0 to find the first match, 1 for second, etc.
> + * @devp: Returns pointer to the device, if found
> + * @return 0 if found, -ve on error
> + */
> +int dm_pci_find_device(unsigned int vendor, unsigned int device, int index,
> + struct udevice **devp);
> +
> +/**
> * struct dm_pci_emul_ops - PCI device emulator operations
> */
> struct dm_pci_emul_ops {
> --
Reviewed-by: Bin Meng <bmeng.cn at gmail.com>
More information about the U-Boot
mailing list