[U-Boot] [PATCH 06/25] dm: pci: Add a function to read a PCI BAR

Bin Meng bmeng.cn at gmail.com
Wed Nov 18 05:27:07 CET 2015


On Tue, Nov 17, 2015 at 11:53 AM, Simon Glass <sjg at chromium.org> wrote:
> Add a driver-model function for reading the PCI BAR from a device.
>
> Signed-off-by: Simon Glass <sjg at chromium.org>
> ---
>
>  drivers/pci/pci-uclass.c | 13 +++++++++++++
>  include/pci.h            |  9 +++++++++
>  2 files changed, 22 insertions(+)
>
> diff --git a/drivers/pci/pci-uclass.c b/drivers/pci/pci-uclass.c
> index 929d772..4e37972 100644
> --- a/drivers/pci/pci-uclass.c
> +++ b/drivers/pci/pci-uclass.c
> @@ -1053,6 +1053,19 @@ int pci_get_regions(struct udevice *dev, struct pci_region **iop,
>         return (*iop != NULL) + (*memp != NULL) + (*prefp != NULL);
>  }
>
> +u32 dm_pci_read_bar32(struct udevice *dev, int barnum)
> +{
> +       u32 addr;
> +       int bar;
> +
> +       bar = PCI_BASE_ADDRESS_0 + barnum * 4;
> +       dm_pci_read_config32(dev, bar, &addr);
> +       if (addr & PCI_BASE_ADDRESS_SPACE_IO)
> +               return addr & PCI_BASE_ADDRESS_IO_MASK;
> +       else
> +               return addr & PCI_BASE_ADDRESS_MEM_MASK;
> +}
> +
>  UCLASS_DRIVER(pci) = {
>         .id             = UCLASS_PCI,
>         .name           = "pci",
> diff --git a/include/pci.h b/include/pci.h
> index d4f6e02..f1c0d71 100644
> --- a/include/pci.h
> +++ b/include/pci.h
> @@ -1174,6 +1174,15 @@ int dm_pciauto_config_device(struct udevice *dev);
>  void dm_pciauto_region_init(struct pci_region *res);
>
>  /**
> + * dm_pci_read_bar32() - read a base address register from a device
> + *
> + * @dev:       Device to check
> + * @barnum:    Bar number to read (numbered from 0)
> + * @return: value of BAR
> + */
> +u32 dm_pci_read_bar32(struct udevice *dev, int barnum);
> +
> +/**
>   * dm_pci_find_device() - find a device by vendor/device ID
>   *
>   * @vendor:    Vendor ID
> --

Reviewed-by: Bin Meng <bmeng.cn at gmail.com>


More information about the U-Boot mailing list