Commit 950cfbf0 authored by Bjorn Helgaas's avatar Bjorn Helgaas

Merge branch 'remotes/lorenzo/pci/endpoint'

  - 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
parents 916f12e4 dbb7bbcc
...@@ -381,15 +381,15 @@ static void pci_epf_test_unbind(struct pci_epf *epf) ...@@ -381,15 +381,15 @@ static void pci_epf_test_unbind(struct pci_epf *epf)
epf_bar = &epf->bar[bar]; epf_bar = &epf->bar[bar];
if (epf_test->reg[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_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) static int pci_epf_test_set_bar(struct pci_epf *epf)
{ {
int bar; int bar, add;
int ret; int ret;
struct pci_epf_bar *epf_bar; struct pci_epf_bar *epf_bar;
struct pci_epc *epc = epf->epc; struct pci_epc *epc = epf->epc;
...@@ -400,8 +400,14 @@ static int pci_epf_test_set_bar(struct pci_epf *epf) ...@@ -400,8 +400,14 @@ static int pci_epf_test_set_bar(struct pci_epf *epf)
epc_features = epf_test->epc_features; 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]; 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))) if (!!(epc_features->reserved_bar & (1 << bar)))
continue; continue;
...@@ -413,13 +419,6 @@ static int pci_epf_test_set_bar(struct pci_epf *epf) ...@@ -413,13 +419,6 @@ static int pci_epf_test_set_bar(struct pci_epf *epf)
if (bar == test_reg_bar) if (bar == test_reg_bar)
return ret; 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; return 0;
...@@ -431,13 +430,19 @@ static int pci_epf_test_alloc_space(struct pci_epf *epf) ...@@ -431,13 +430,19 @@ static int pci_epf_test_alloc_space(struct pci_epf *epf)
struct device *dev = &epf->dev; struct device *dev = &epf->dev;
struct pci_epf_bar *epf_bar; struct pci_epf_bar *epf_bar;
void *base; void *base;
int bar; int bar, add;
enum pci_barno test_reg_bar = epf_test->test_reg_bar; enum pci_barno test_reg_bar = epf_test->test_reg_bar;
const struct pci_epc_features *epc_features; const struct pci_epc_features *epc_features;
size_t test_reg_size;
epc_features = epf_test->epc_features; 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); test_reg_bar, epc_features->align);
if (!base) { if (!base) {
dev_err(dev, "Failed to allocated register space\n"); dev_err(dev, "Failed to allocated register space\n");
...@@ -445,8 +450,10 @@ static int pci_epf_test_alloc_space(struct pci_epf *epf) ...@@ -445,8 +450,10 @@ static int pci_epf_test_alloc_space(struct pci_epf *epf)
} }
epf_test->reg[test_reg_bar] = base; 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]; epf_bar = &epf->bar[bar];
add = (epf_bar->flags & PCI_BASE_ADDRESS_MEM_TYPE_64) ? 2 : 1;
if (bar == test_reg_bar) if (bar == test_reg_bar)
continue; continue;
...@@ -459,8 +466,6 @@ static int pci_epf_test_alloc_space(struct pci_epf *epf) ...@@ -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", dev_err(dev, "Failed to allocate space for BAR%d\n",
bar); bar);
epf_test->reg[bar] = base; epf_test->reg[bar] = base;
if (epf_bar->flags & PCI_BASE_ADDRESS_MEM_TYPE_64)
bar++;
} }
return 0; return 0;
......
...@@ -519,11 +519,12 @@ void pci_epc_remove_epf(struct pci_epc *epc, struct pci_epf *epf) ...@@ -519,11 +519,12 @@ void pci_epc_remove_epf(struct pci_epc *epc, struct pci_epf *epf)
{ {
unsigned long flags; unsigned long flags;
if (!epc || IS_ERR(epc)) if (!epc || IS_ERR(epc) || !epf)
return; return;
spin_lock_irqsave(&epc->lock, flags); spin_lock_irqsave(&epc->lock, flags);
list_del(&epf->list); list_del(&epf->list);
epf->epc = NULL;
spin_unlock_irqrestore(&epc->lock, flags); spin_unlock_irqrestore(&epc->lock, flags);
} }
EXPORT_SYMBOL_GPL(pci_epc_remove_epf); EXPORT_SYMBOL_GPL(pci_epc_remove_epf);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment