Message ID | 20171030124221.20690-5-niklas.cassel@axis.com (mailing list archive) |
---|---|
State | New, archived |
Delegated to: | Bjorn Helgaas |
Headers | show |
Hi Niklas, On Monday 30 October 2017 06:12 PM, Niklas Cassel wrote: > Certain SoCs need to map the MSI address in raise_irq. > To map an address, you first need to call pci_epc_mem_alloc_addr, > however, pci_epc_mem_alloc_addr calls ioremap (which can sleep). > > Since raise_irq is only called from atomic context, we can't call > pci_epc_mem_alloc_addr from raise_irq, instead we pre-allocate > a page in dw_pcie_ep_init, so this page can later be used to map/unmap > the MSI address in raise_irq. > > Signed-off-by: Niklas Cassel <niklas.cassel@axis.com> > --- > V2: > * No change. > > drivers/pci/dwc/pcie-designware-ep.c | 8 ++++++++ > drivers/pci/dwc/pcie-designware.h | 2 ++ > 2 files changed, 10 insertions(+) > > diff --git a/drivers/pci/dwc/pcie-designware-ep.c b/drivers/pci/dwc/pcie-designware-ep.c > index 3fb34be99715..c291da2a10ba 100644 > --- a/drivers/pci/dwc/pcie-designware-ep.c > +++ b/drivers/pci/dwc/pcie-designware-ep.c > @@ -286,6 +286,8 @@ void dw_pcie_ep_exit(struct dw_pcie_ep *ep) > { > struct pci_epc *epc = ep->epc; > > + pci_epc_mem_free_addr(epc, ep->msi_mem_phys, ep->msi_mem, PAGE_SIZE); > + > pci_epc_mem_exit(epc); > } > > @@ -341,6 +343,12 @@ int dw_pcie_ep_init(struct dw_pcie_ep *ep) > return ret; > } > > + ep->msi_mem = pci_epc_mem_alloc_addr(epc, &ep->msi_mem_phys, PAGE_SIZE); ep->page_size instead of PAGE_SIZE? Thanks Kishon
On 10/31/2017 07:01 AM, Kishon Vijay Abraham I wrote: > Hi Niklas, > > On Monday 30 October 2017 06:12 PM, Niklas Cassel wrote: >> Certain SoCs need to map the MSI address in raise_irq. >> To map an address, you first need to call pci_epc_mem_alloc_addr, >> however, pci_epc_mem_alloc_addr calls ioremap (which can sleep). >> >> Since raise_irq is only called from atomic context, we can't call >> pci_epc_mem_alloc_addr from raise_irq, instead we pre-allocate >> a page in dw_pcie_ep_init, so this page can later be used to map/unmap >> the MSI address in raise_irq. >> >> Signed-off-by: Niklas Cassel <niklas.cassel@axis.com> >> --- >> V2: >> * No change. >> >> drivers/pci/dwc/pcie-designware-ep.c | 8 ++++++++ >> drivers/pci/dwc/pcie-designware.h | 2 ++ >> 2 files changed, 10 insertions(+) >> >> diff --git a/drivers/pci/dwc/pcie-designware-ep.c b/drivers/pci/dwc/pcie-designware-ep.c >> index 3fb34be99715..c291da2a10ba 100644 >> --- a/drivers/pci/dwc/pcie-designware-ep.c >> +++ b/drivers/pci/dwc/pcie-designware-ep.c >> @@ -286,6 +286,8 @@ void dw_pcie_ep_exit(struct dw_pcie_ep *ep) >> { >> struct pci_epc *epc = ep->epc; >> >> + pci_epc_mem_free_addr(epc, ep->msi_mem_phys, ep->msi_mem, PAGE_SIZE); >> + >> pci_epc_mem_exit(epc); >> } >> >> @@ -341,6 +343,12 @@ int dw_pcie_ep_init(struct dw_pcie_ep *ep) >> return ret; >> } >> >> + ep->msi_mem = pci_epc_mem_alloc_addr(epc, &ep->msi_mem_phys, PAGE_SIZE); > > ep->page_size instead of PAGE_SIZE? Hello Kishon, Sure thing, will fix in V3. Regards, Niklas
On 10/31/2017 07:01 AM, Kishon Vijay Abraham I wrote: > Hi Niklas, > > On Monday 30 October 2017 06:12 PM, Niklas Cassel wrote: >> Certain SoCs need to map the MSI address in raise_irq. >> To map an address, you first need to call pci_epc_mem_alloc_addr, >> however, pci_epc_mem_alloc_addr calls ioremap (which can sleep). >> >> Since raise_irq is only called from atomic context, we can't call >> pci_epc_mem_alloc_addr from raise_irq, instead we pre-allocate >> a page in dw_pcie_ep_init, so this page can later be used to map/unmap >> the MSI address in raise_irq. >> >> Signed-off-by: Niklas Cassel <niklas.cassel@axis.com> >> --- >> V2: >> * No change. >> >> drivers/pci/dwc/pcie-designware-ep.c | 8 ++++++++ >> drivers/pci/dwc/pcie-designware.h | 2 ++ >> 2 files changed, 10 insertions(+) >> >> diff --git a/drivers/pci/dwc/pcie-designware-ep.c b/drivers/pci/dwc/pcie-designware-ep.c >> index 3fb34be99715..c291da2a10ba 100644 >> --- a/drivers/pci/dwc/pcie-designware-ep.c >> +++ b/drivers/pci/dwc/pcie-designware-ep.c >> @@ -286,6 +286,8 @@ void dw_pcie_ep_exit(struct dw_pcie_ep *ep) >> { >> struct pci_epc *epc = ep->epc; >> >> + pci_epc_mem_free_addr(epc, ep->msi_mem_phys, ep->msi_mem, PAGE_SIZE); >> + >> pci_epc_mem_exit(epc); >> } >> >> @@ -341,6 +343,12 @@ int dw_pcie_ep_init(struct dw_pcie_ep *ep) >> return ret; >> } >> >> + ep->msi_mem = pci_epc_mem_alloc_addr(epc, &ep->msi_mem_phys, PAGE_SIZE); > > ep->page_size instead of PAGE_SIZE? > It was a really good call of Bjorn not to stress this series, since I apparently did not properly test this... I'm sorry, it will not happen again. ep->page_size is by default set to 0. __pci_epc_mem_init basically does this: if ep->page_size < PAGE_SIZE: epc->mem->page_size = PAGE_SIZE else epc->mem->page_size = ep->page_size So __pci_epc_mem_init is safe to call with ep->page_size 0, however, the same thing is not true for pci_epc_mem_alloc_addr. I will need to do a v5 of this patch series. Kishon, what do you think about doing this instead? +++ b/drivers/pci/dwc/pcie-designware-ep.c @@ -321,7 +321,7 @@ void dw_pcie_ep_exit(struct dw_pcie_ep *ep) struct pci_epc *epc = ep->epc; pci_epc_mem_free_addr(epc, ep->msi_mem_phys, ep->msi_mem, - ep->page_size); + epc->mem->page_size); pci_epc_mem_exit(epc); } @@ -379,7 +379,7 @@ int dw_pcie_ep_init(struct dw_pcie_ep *ep) } ep->msi_mem = pci_epc_mem_alloc_addr(epc, &ep->msi_mem_phys, - ep->page_size); + epc->mem->page_size); if (!ep->msi_mem) { dev_err(dev, "Failed to reserve memory for MSI\n"); return -ENOMEM; Regards, Niklas
diff --git a/drivers/pci/dwc/pcie-designware-ep.c b/drivers/pci/dwc/pcie-designware-ep.c index 3fb34be99715..c291da2a10ba 100644 --- a/drivers/pci/dwc/pcie-designware-ep.c +++ b/drivers/pci/dwc/pcie-designware-ep.c @@ -286,6 +286,8 @@ void dw_pcie_ep_exit(struct dw_pcie_ep *ep) { struct pci_epc *epc = ep->epc; + pci_epc_mem_free_addr(epc, ep->msi_mem_phys, ep->msi_mem, PAGE_SIZE); + pci_epc_mem_exit(epc); } @@ -341,6 +343,12 @@ int dw_pcie_ep_init(struct dw_pcie_ep *ep) return ret; } + ep->msi_mem = pci_epc_mem_alloc_addr(epc, &ep->msi_mem_phys, PAGE_SIZE); + if (!ep->msi_mem) { + dev_err(dev, "Failed to reserve memory for MSI\n"); + return -ENOMEM; + } + ep->epc = epc; epc_set_drvdata(epc, ep); dw_pcie_setup(pci); diff --git a/drivers/pci/dwc/pcie-designware.h b/drivers/pci/dwc/pcie-designware.h index 9aaf0cd04dd6..5a1da459eda5 100644 --- a/drivers/pci/dwc/pcie-designware.h +++ b/drivers/pci/dwc/pcie-designware.h @@ -198,6 +198,8 @@ struct dw_pcie_ep { unsigned long ob_window_map; u32 num_ib_windows; u32 num_ob_windows; + void __iomem *msi_mem; + phys_addr_t msi_mem_phys; }; struct dw_pcie_ops {
Certain SoCs need to map the MSI address in raise_irq. To map an address, you first need to call pci_epc_mem_alloc_addr, however, pci_epc_mem_alloc_addr calls ioremap (which can sleep). Since raise_irq is only called from atomic context, we can't call pci_epc_mem_alloc_addr from raise_irq, instead we pre-allocate a page in dw_pcie_ep_init, so this page can later be used to map/unmap the MSI address in raise_irq. Signed-off-by: Niklas Cassel <niklas.cassel@axis.com> --- V2: * No change. drivers/pci/dwc/pcie-designware-ep.c | 8 ++++++++ drivers/pci/dwc/pcie-designware.h | 2 ++ 2 files changed, 10 insertions(+)