]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
dm: pci: Add a function to find the regions for a PCI bus
authorSimon Glass <sjg@chromium.org>
Fri, 20 Nov 2015 03:27:01 +0000 (20:27 -0700)
committerSimon Glass <sjg@chromium.org>
Tue, 1 Dec 2015 13:26:36 +0000 (06:26 -0700)
This function looks up the controller and returns a pointer to each region
type.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Stephen Warren <swarren@nvidia.com>
Tested-by: Stephen Warren <swarren@nvidia.com>
drivers/pci/pci-uclass.c
include/pci.h

index f3f5f007c8e5a0eb3b1b53baa2ebd6d6d7eb95a7..5fe30723c243e0d7c8664c26c90cf8b5debce21e 100644 (file)
@@ -974,6 +974,36 @@ ulong pci_conv_size_to_32(ulong old, ulong value, uint offset,
        return value;
 }
 
+int pci_get_regions(struct udevice *dev, struct pci_region **iop,
+                   struct pci_region **memp, struct pci_region **prefp)
+{
+       struct udevice *bus = pci_get_controller(dev);
+       struct pci_controller *hose = dev_get_uclass_priv(bus);
+       int i;
+
+       *iop = NULL;
+       *memp = NULL;
+       *prefp = NULL;
+       for (i = 0; i < hose->region_count; i++) {
+               switch (hose->regions[i].flags) {
+               case PCI_REGION_IO:
+                       if (!*iop || (*iop)->size < hose->regions[i].size)
+                               *iop = hose->regions + i;
+                       break;
+               case PCI_REGION_MEM:
+                       if (!*memp || (*memp)->size < hose->regions[i].size)
+                               *memp = hose->regions + i;
+                       break;
+               case (PCI_REGION_MEM | PCI_REGION_PREFETCH):
+                       if (!*prefp || (*prefp)->size < hose->regions[i].size)
+                               *prefp = hose->regions + i;
+                       break;
+               }
+       }
+
+       return (*iop != NULL) + (*memp != NULL) + (*prefp != NULL);
+}
+
 UCLASS_DRIVER(pci) = {
        .id             = UCLASS_PCI,
        .name           = "pci",
index f3dda702f52f4328ca63ba0cd40ee1b0efeaa6a1..9c1948226fd3e1a4a0e0eb6bb38e50c3ff2f8e10 100644 (file)
@@ -1130,6 +1130,18 @@ ulong pci_conv_size_to_32(ulong old, ulong value, uint offset,
  */
 struct udevice *pci_get_controller(struct udevice *dev);
 
+/**
+ * pci_get_regions() - obtain pointers to all the region types
+ *
+ * @dev:       Device to check
+ * @iop:       Returns a pointer to the I/O region, or NULL if none
+ * @memp:      Returns a pointer to the memory region, or NULL if none
+ * @prefp:     Returns a pointer to the pre-fetch region, or NULL if none
+ * @return the number of non-NULL regions returned, normally 3
+ */
+int pci_get_regions(struct udevice *dev, struct pci_region **iop,
+                   struct pci_region **memp, struct pci_region **prefp);
+
 /**
  * struct dm_pci_emul_ops - PCI device emulator operations
  */