Skip to content

Commit

Permalink
Merge branch 'remotes/lorenzo/pci/endpoint'
Browse files Browse the repository at this point in the history
  - Complete PCI endpoint removal so a subsequent add doesn't fail with
    -EBUSY (Alan Mikhak)

  - Pay attention to PCI endpoint fixed-size BARs (Alan Mikhak)

  - Fix PCI endpoint handling of 64bit BARs (Alan Mikhak)

  - Clear PCI endpoint BARs before freeing space (Alan Mikhak)

* remotes/lorenzo/pci/endpoint:
  PCI: endpoint: Clear BAR before freeing its space
  PCI: endpoint: Skip odd BAR when skipping 64bit BAR
  PCI: endpoint: Allocate enough space for fixed size BAR
  PCI: endpoint: Set endpoint controller pointer to NULL
  • Loading branch information
Bjorn Helgaas committed Jul 12, 2019
2 parents 916f12e + dbb7bbc commit 950cfbf
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
35 changes: 20 additions & 15 deletions drivers/pci/endpoint/functions/pci-epf-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -381,15 +381,15 @@ static void pci_epf_test_unbind(struct pci_epf *epf)
epf_bar = &epf->bar[bar];

if (epf_test->reg[bar]) {
pci_epf_free_space(epf, epf_test->reg[bar], bar);
pci_epc_clear_bar(epc, epf->func_no, epf_bar);
pci_epf_free_space(epf, epf_test->reg[bar], bar);
}
}
}

static int pci_epf_test_set_bar(struct pci_epf *epf)
{
int bar;
int bar, add;
int ret;
struct pci_epf_bar *epf_bar;
struct pci_epc *epc = epf->epc;
Expand All @@ -400,8 +400,14 @@ static int pci_epf_test_set_bar(struct pci_epf *epf)

epc_features = epf_test->epc_features;

for (bar = BAR_0; bar <= BAR_5; bar++) {
for (bar = BAR_0; bar <= BAR_5; bar += add) {
epf_bar = &epf->bar[bar];
/*
* pci_epc_set_bar() sets PCI_BASE_ADDRESS_MEM_TYPE_64
* if the specific implementation required a 64-bit BAR,
* even if we only requested a 32-bit BAR.
*/
add = (epf_bar->flags & PCI_BASE_ADDRESS_MEM_TYPE_64) ? 2 : 1;

if (!!(epc_features->reserved_bar & (1 << bar)))
continue;
Expand All @@ -413,13 +419,6 @@ static int pci_epf_test_set_bar(struct pci_epf *epf)
if (bar == test_reg_bar)
return ret;
}
/*
* pci_epc_set_bar() sets PCI_BASE_ADDRESS_MEM_TYPE_64
* if the specific implementation required a 64-bit BAR,
* even if we only requested a 32-bit BAR.
*/
if (epf_bar->flags & PCI_BASE_ADDRESS_MEM_TYPE_64)
bar++;
}

return 0;
Expand All @@ -431,22 +430,30 @@ static int pci_epf_test_alloc_space(struct pci_epf *epf)
struct device *dev = &epf->dev;
struct pci_epf_bar *epf_bar;
void *base;
int bar;
int bar, add;
enum pci_barno test_reg_bar = epf_test->test_reg_bar;
const struct pci_epc_features *epc_features;
size_t test_reg_size;

epc_features = epf_test->epc_features;

base = pci_epf_alloc_space(epf, sizeof(struct pci_epf_test_reg),
if (epc_features->bar_fixed_size[test_reg_bar])
test_reg_size = bar_size[test_reg_bar];
else
test_reg_size = sizeof(struct pci_epf_test_reg);

base = pci_epf_alloc_space(epf, test_reg_size,
test_reg_bar, epc_features->align);
if (!base) {
dev_err(dev, "Failed to allocated register space\n");
return -ENOMEM;
}
epf_test->reg[test_reg_bar] = base;

for (bar = BAR_0; bar <= BAR_5; bar++) {
for (bar = BAR_0; bar <= BAR_5; bar += add) {
epf_bar = &epf->bar[bar];
add = (epf_bar->flags & PCI_BASE_ADDRESS_MEM_TYPE_64) ? 2 : 1;

if (bar == test_reg_bar)
continue;

Expand All @@ -459,8 +466,6 @@ static int pci_epf_test_alloc_space(struct pci_epf *epf)
dev_err(dev, "Failed to allocate space for BAR%d\n",
bar);
epf_test->reg[bar] = base;
if (epf_bar->flags & PCI_BASE_ADDRESS_MEM_TYPE_64)
bar++;
}

return 0;
Expand Down
3 changes: 2 additions & 1 deletion drivers/pci/endpoint/pci-epc-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -519,11 +519,12 @@ void pci_epc_remove_epf(struct pci_epc *epc, struct pci_epf *epf)
{
unsigned long flags;

if (!epc || IS_ERR(epc))
if (!epc || IS_ERR(epc) || !epf)
return;

spin_lock_irqsave(&epc->lock, flags);
list_del(&epf->list);
epf->epc = NULL;
spin_unlock_irqrestore(&epc->lock, flags);
}
EXPORT_SYMBOL_GPL(pci_epc_remove_epf);
Expand Down

0 comments on commit 950cfbf

Please sign in to comment.