]> xenbits.xensource.com Git - arm/linux.git/commitdiff
PCI: endpoint: Add helper to get first unreserved BAR
authorKishon Vijay Abraham I <kishon@ti.com>
Mon, 14 Jan 2019 11:15:05 +0000 (16:45 +0530)
committerLorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Fri, 15 Feb 2019 09:59:40 +0000 (09:59 +0000)
Add a helper function pci_epc_get_first_free_bar() to get the first
unreserved BAR that can be used for endpoint function.

Tested-by: Gustavo Pimentel <gustavo.pimentel@synopsys.com>
Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
drivers/pci/endpoint/pci-epc-core.c
include/linux/pci-epc.h

index 5a099479d9aba1ec5eea8db694c1e492c3a3ef52..e4712a0f249cb72c2d4a6c65a17ba96755e593cf 100644 (file)
@@ -83,6 +83,29 @@ err:
 }
 EXPORT_SYMBOL_GPL(pci_epc_get);
 
+/**
+ * pci_epc_get_first_free_bar() - helper to get first unreserved BAR
+ * @epc_features: pci_epc_features structure that holds the reserved bar bitmap
+ *
+ * Invoke to get the first unreserved BAR that can be used for endpoint
+ * function. For any incorrect value in reserved_bar return '0'.
+ */
+unsigned int pci_epc_get_first_free_bar(const struct pci_epc_features
+                                       *epc_features)
+{
+       int free_bar;
+
+       if (!epc_features)
+               return 0;
+
+       free_bar = ffz(epc_features->reserved_bar);
+       if (free_bar > 5)
+               return 0;
+
+       return free_bar;
+}
+EXPORT_SYMBOL_GPL(pci_epc_get_first_free_bar);
+
 /**
  * pci_epc_get_features() - get the features supported by EPC
  * @epc: the features supported by *this* EPC device will be returned
index 79fbcf94e14dfd9d95b84dd523fbdf037063a555..94e1ecff98ceb74e1d387fc2ae81a15186fe8f17 100644 (file)
@@ -180,6 +180,8 @@ int pci_epc_start(struct pci_epc *epc);
 void pci_epc_stop(struct pci_epc *epc);
 const struct pci_epc_features *pci_epc_get_features(struct pci_epc *epc,
                                                    u8 func_no);
+unsigned int pci_epc_get_first_free_bar(const struct pci_epc_features
+                                       *epc_features);
 struct pci_epc *pci_epc_get(const char *epc_name);
 void pci_epc_put(struct pci_epc *epc);