Skip to content

Commit

Permalink
PCI: endpoint: Make *_get_first_free_bar() take into account 64 bit BAR
Browse files Browse the repository at this point in the history
[ Upstream commit 959a48d ]

pci_epc_get_first_free_bar() uses only "reserved_bar" member in
epc_features to get the first unreserved BAR. However if the reserved BAR
is also a 64-bit BAR, then the next BAR shouldn't be returned (since 64-bit
BAR uses two BARs).

Make pci_epc_get_first_free_bar() take into account 64 bit BAR while
returning the first free unreserved BAR.

Link: https://lore.kernel.org/r/20210201195809.7342-3-kishon@ti.com
Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
kishon authored and gregkh committed May 19, 2021
1 parent 8c8f7c4 commit 5974766
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions drivers/pci/endpoint/pci-epc-core.c
Expand Up @@ -93,12 +93,20 @@ EXPORT_SYMBOL_GPL(pci_epc_get);
unsigned int pci_epc_get_first_free_bar(const struct pci_epc_features
*epc_features)
{
int free_bar;
unsigned long free_bar;

if (!epc_features)
return 0;

free_bar = ffz(epc_features->reserved_bar);
/* Find if the reserved BAR is also a 64-bit BAR */
free_bar = epc_features->reserved_bar & epc_features->bar_fixed_64bit;

/* Set the adjacent bit if the reserved BAR is also a 64-bit BAR */
free_bar <<= 1;
free_bar |= epc_features->reserved_bar;

/* Now find the free BAR */
free_bar = ffz(free_bar);
if (free_bar > 5)
return 0;

Expand Down

0 comments on commit 5974766

Please sign in to comment.