diff options
author | Kishon Vijay Abraham I <kishon@ti.com> | 2019-01-14 12:15:05 +0100 |
---|---|---|
committer | Lorenzo Pieralisi <lorenzo.pieralisi@arm.com> | 2019-02-15 10:59:40 +0100 |
commit | 1e9efe6c9976552e88c6e6feaca3a78b8cf5aaf6 (patch) | |
tree | 8bb476c19c32d9ae36a7a4d06fdbec23488d583b /drivers/pci | |
parent | PCI: cadence: Populate ->get_features() cdns_pcie_epc_ops (diff) | |
download | linux-1e9efe6c9976552e88c6e6feaca3a78b8cf5aaf6.tar.xz linux-1e9efe6c9976552e88c6e6feaca3a78b8cf5aaf6.zip |
PCI: endpoint: Add helper to get first unreserved BAR
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>
Diffstat (limited to 'drivers/pci')
-rw-r--r-- | drivers/pci/endpoint/pci-epc-core.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/drivers/pci/endpoint/pci-epc-core.c b/drivers/pci/endpoint/pci-epc-core.c index 5a099479d9ab..e4712a0f249c 100644 --- a/drivers/pci/endpoint/pci-epc-core.c +++ b/drivers/pci/endpoint/pci-epc-core.c @@ -84,6 +84,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 * @func_no: the features supported by the EPC device specific to the |