PCI: dwc: Add API support to de-initialize host
PATCH v7 1/3 PCI: dwc: Add API support to de-initialize host
Add an API to group all the tasks to be done to de-initialize host which can then be called by any DesignWare core based driver implementations while adding .remove() support in their respective drivers.
---
Changes from v6:
* None
Changes from v5:
* None
Changes from v4:
* None
Changes from v3:
* Added check if (pci_msi_enabled() && !pp->ops->msi_host_init) before calling dw_pcie_free_msi() API to mimic init path
Changes from v2:
* Rebased on top of linux-next top of the tree branch
Changes from v1:
* s/Designware/DesignWare
drivers/pci/controller/dwc/pcie-designware-host.c | 8 ++++++++ drivers/pci/controller/dwc/pcie-designware.h | 5 +++++ 2 files changed, 13 insertions(+)
drivers/pci/controller/dwc/pcie-designware-host.c +8 -0
@@ -496,6 +496,14 @@ int dw_pcie_host_init(struct pcie_port *pp)return ret; } +void dw_pcie_host_deinit (struct pcie_port *pp) +{ +pci_stop_root_bus (pp->root_bus); +pci_remove_root_bus (pp->root_bus); +if (pci_msi_enabled () && !pp->ops->msi_host_init) +dw_pcie_free_msi (pp); +} +static int dw_pcie_access_other_conf (struct pcie_port *pp,struct pci_bus *bus,u32 devfn,int where,int size,u32 *val,bool write)
drivers/pci/controller/dwc/pcie-designware.h +5 -0
@@ -351,6 +351,7 @@ void dw_pcie_msi_init(struct pcie_port *pp);void dw_pcie_free_msi (struct pcie_port *pp);void dw_pcie_setup_rc (struct pcie_port *pp);int dw_pcie_host_init (struct pcie_port *pp); +void dw_pcie_host_deinit (struct pcie_port *pp);int dw_pcie_allocate_domains (struct pcie_port *pp);#else static inline irqreturn_t dw_handle_msi_irq (struct pcie_port *pp)
@@ -375,6 +376,10 @@ static inline int dw_pcie_host_init(struct pcie_port *pp)return 0 ; } +static inline void dw_pcie_host_deinit (struct pcie_port *pp) +{ +} +static inline int dw_pcie_allocate_domains (struct pcie_port *pp) {return 0 ;
Signature · 1 line
2.17.1
PATCH v7 2/3 PCI: dwc: Cleanup DBI,ATU read and write APIs
Cleanup DBI read and write APIs by removing "__" (underscore) from their names as there are no no-underscore versions and the underscore versions are already doing what no-underscore versions typically do. It also removes passing dbi/dbi2 base address as one of the arguments as the same can be derived with in read and write APIs. Since dw_pcie_{readl/writel}_dbi() APIs can't be used for ATU read/write as ATU base address could be different from DBI base address, this patch attempts to implement ATU read/write APIs using ATU base address without using dw_pcie_{readl/writel}_dbi() APIs.
---
Changes from v6:
* Modified ATU read/write APIs to use implementation specific DBI read/write APIs if present.
Changes from v5:
* Removed passing base address as one of the arguments as the same can be derived within the API itself.
* Modified ATU read/write APIs to call dw_pcie_{write/read}() API
Changes from v4:
* This is a new patch in this series
drivers/pci/controller/dwc/pcie-designware.c | 28 +++++------ drivers/pci/controller/dwc/pcie-designware.h | 51 +++++++++++++------- 2 files changed, 45 insertions(+), 34 deletions(-)
drivers/pci/controller/dwc/pcie-designware.c +12 -16
@@ -52,64 +52,60 @@ int dw_pcie_write(void __iomem *addr, int size, u32 val)return PCIBIOS_SUCCESSFUL ; } -u32 __dw_pcie_read_dbi (struct dw_pcie *pci,void __iomem *base,u32 reg, -size_t size) +u32 dw_pcie_read_dbi (struct dw_pcie *pci,u32 reg,size_t size) {int ret;u32 val;if (pci->ops->read_dbi) -return pci->ops->read_dbi (pci, base, reg, size); +return pci->ops->read_dbi (pci, pci->dbi_base, reg, size); - ret =dw_pcie_read (base + reg, size, &val); + ret =dw_pcie_read (pci->dbi_base + reg, size, &val);if (ret)dev_err (pci->dev,"Read DBI address failed\n" );return val; } -void __dw_pcie_write_dbi (struct dw_pcie *pci,void __iomem *base,u32 reg, -size_t size,u32 val) +void dw_pcie_write_dbi (struct dw_pcie *pci,u32 reg,size_t size,u32 val) {int ret;if (pci->ops->write_dbi) { - pci->ops->write_dbi (pci, base, reg, size, val); + pci->ops->write_dbi (pci, pci->dbi_base, reg, size, val);return ; } - ret =dw_pcie_write (base + reg, size, val); + ret =dw_pcie_write (pci->dbi_base + reg, size, val);if (ret)dev_err (pci->dev,"Write DBI address failed\n" ); } -u32 __dw_pcie_read_dbi2 (struct dw_pcie *pci,void __iomem *base,u32 reg, -size_t size) +u32 dw_pcie_read_dbi2 (struct dw_pcie *pci,u32 reg,size_t size) {int ret;u32 val;if (pci->ops->read_dbi2) -return pci->ops->read_dbi2 (pci, base, reg, size); +return pci->ops->read_dbi2 (pci, pci->dbi_base2, reg, size); - ret =dw_pcie_read (base + reg, size, &val); + ret =dw_pcie_read (pci->dbi_base2 + reg, size, &val);if (ret)dev_err (pci->dev,"read DBI address failed\n" );return val; } -void __dw_pcie_write_dbi2 (struct dw_pcie *pci,void __iomem *base,u32 reg, -size_t size,u32 val) +void dw_pcie_write_dbi2 (struct dw_pcie *pci,u32 reg,size_t size,u32 val) {int ret;if (pci->ops->write_dbi2) { - pci->ops->write_dbi2 (pci, base, reg, size, val); + pci->ops->write_dbi2 (pci, pci->dbi_base2, reg, size, val);return ; } - ret =dw_pcie_write (base + reg, size, val); + ret =dw_pcie_write (pci->dbi_base2 + reg, size, val);if (ret)dev_err (pci->dev,"write DBI address failed\n" ); }
drivers/pci/controller/dwc/pcie-designware.h +33 -18
99 lines not on this page · raw message
Signature · 1 line
2.17.1
Jingoo Han
maintainerRe: [PATCH V7 2/3] PCI: dwc: Cleanup DBI,ATU read and write APIs
Quoted 28 lines · Vidya Sagar
Cleanup DBI read and write APIs by removing "__" (underscore) from their names as there are no no-underscore versions and the underscore versions are already doing what no-underscore versions typically do. It also removes passing dbi/dbi2 base address as one of the arguments as the same can be derived with in read and write APIs. Since dw_pcie_{readl/writel}_dbi() APIs can't be used for ATU read/write as ATU base address could be different from DBI base address, this patch attempts to implement ATU read/write APIs using ATU base address without using dw_pcie_{readl/writel}_dbi() APIs.
Signed-off-by Vidya Sagar <[email protected]>---
Changes from v6:
* Modified ATU read/write APIs to use implementation specific DBI read/write APIs if present.Changes from v5:
* Removed passing base address as one of the arguments as the same can be derived within the API itself.
* Modified ATU read/write APIs to call dw_pcie_{write/read}() APIChanges from v4:
* This is a new patch in this seriesdrivers/pci/controller/dwc/pcie-designware.c | 28 +++++------ drivers/pci/controller/dwc/pcie-designware.h | 51 +++++++++++++------- 2 files changed, 45 insertions(+), 34 deletions(-)
.....
Quoted 20 lines
static inline void
dw_pcie_writel_atu(struct dw_pcie *pci, u32 reg, u32 val){drivers/pci/controller/dwc/pcie-designware.h +12
-2-__dw_pcie_write_dbi (pci, pci->atu_base, reg,0x4 , val); +int ret; + +if (pci->ops->write_dbi) { + pci->ops->write_dbi (pci, pci->atu_base, reg,0x4 , val); +return ; + } + + ret =dw_pcie_write (pci->atu_base + reg,0x4 , val); +if (ret) +dev_err (pci->dev,"Write ATU address failed\n" ); }static inline u32 dw_pcie_readl_atu (struct dw_pcie *pci,u32 reg) { -return __dw_pcie_read_dbi (pci, pci->atu_base, reg,0x4 ); +int ret; +u32 val;
drivers/pci/controller/dwc/pcie-designware.h void dw_pcie_setup(struct dw_pcie *pci); · line 339
Quoted 10 lines
drivers/pci/controller/dwc/pcie-designware.h +9
-0+ +if (pci->ops->read_dbi) +return pci->ops->read_dbi (pci, pci->atu_base, reg,0x4 ); + + ret =dw_pcie_read (pci->atu_base + reg,0x4 , &val); +if (ret) +dev_err (pci->dev,"Read ATU address failed\n" ); + +return val; }
Hmm. In cases of dbi and dbi2, readb/readw/readl and writeb/writew/writel are located in pcie-designware.h. These functions just call read/write which are located in pcie-designware.c. For readability, would you write the code as below?
1. For drivers/pci/controller/dwc/pcie-designware.h,
Just call dw_pcie_{write/read}_atu(), instead of implementing functions as below.
static inline void dw_pcie_writel_atu(struct dw_pcie *pci, u32 reg, u32 val)
{
return dw_pcie_write_atu(pci, reg, 0x4, val);
}
static inline u32 dw_pcie_readl_atu(struct dw_pcie *pci, u32 reg)
{
return dw_pcie_read_atu(pci, reg, 0x4);
}2. For drivers/pci/controller/dwc/pcie-designware.c,
Please add new dw_pcie_{write/read}_atu() as below.
void dw_pcie_write_atu(struct dw_pcie *pci, u32 reg, size_t size, u32 val)
{
int ret;
if (pci->ops->write_dbi) {
pci->ops->write_dbi(pci, pci->atu_base, reg, size, val);
return;
}
ret = dw_pcie_write(pci->atu_base + reg, size, val);
if (ret)
dev_err(pci->dev, "Write ATU address failed\n");
}
u32 dw_pcie_read_atu(struct dw_pcie *pci, u32 reg, size_t size)
{
int ret;
u32 val;
if (pci->ops->read_dbi)
return pci->ops->read_dbi(pci, pci->atu_base, reg, size);
ret = dw_pcie_read(pci->atu_base + reg, size, &val);
if (ret)
dev_err(pci->dev, "Read ATU address failed\n");
return val;
}Thank you.
Best regards,
Jingoo Han
Quoted 4 lines
static inline void
dw_pcie_dbi_ro_wr_en(struct dw_pcie *pci)Signature · 1 line
2.17.1
Re: [PATCH V7 2/3] PCI: dwc: Cleanup DBI,ATU read and write APIs
Quoted 112 lines · Jingoo Han
Quoted 28 lines · Vidya Sagar
Cleanup DBI read and write APIs by removing "__" (underscore) from their names as there are no no-underscore versions and the underscore versions are already doing what no-underscore versions typically do. It also removes passing dbi/dbi2 base address as one of the arguments as the same can be derived with in read and write APIs. Since dw_pcie_{readl/writel}_dbi() APIs can't be used for ATU read/write as ATU base address could be different from DBI base address, this patch attempts to implement ATU read/write APIs using ATU base address without using dw_pcie_{readl/writel}_dbi() APIs.
Signed-off-by Vidya Sagar <[email protected]>---
Changes from v6:
* Modified ATU read/write APIs to use implementation specific DBI read/write APIs if present.Changes from v5:
* Removed passing base address as one of the arguments as the same can be derived within the API itself.
* Modified ATU read/write APIs to call dw_pcie_{write/read}() APIChanges from v4:
* This is a new patch in this seriesdrivers/pci/controller/dwc/pcie-designware.c | 28 +++++------ drivers/pci/controller/dwc/pcie-designware.h | 51 +++++++++++++------- 2 files changed, 45 insertions(+), 34 deletions(-).....
Quoted 20 lines
static inline void dw_pcie_writel_atu(struct dw_pcie *pci, u32 reg, u32 val) {drivers/pci/controller/dwc/pcie-designware.h +12
-2-__dw_pcie_write_dbi (pci, pci->atu_base, reg,0x4 , val); +int ret; + +if (pci->ops->write_dbi) { + pci->ops->write_dbi (pci, pci->atu_base, reg,0x4 , val); +return ; + } + + ret =dw_pcie_write (pci->atu_base + reg,0x4 , val); +if (ret) +dev_err (pci->dev,"Write ATU address failed\n" ); }static inline u32 dw_pcie_readl_atu (struct dw_pcie *pci,u32 reg) { -return __dw_pcie_read_dbi (pci, pci->atu_base, reg,0x4 ); +int ret; +u32 val;drivers/pci/controller/dwc/pcie-designware.h void dw_pcie_setup(struct dw_pcie *pci); · line 339
Quoted 10 lines
drivers/pci/controller/dwc/pcie-designware.h +9
-0+ +if (pci->ops->read_dbi) +return pci->ops->read_dbi (pci, pci->atu_base, reg,0x4 ); + + ret =dw_pcie_read (pci->atu_base + reg,0x4 , &val); +if (ret) +dev_err (pci->dev,"Read ATU address failed\n" ); + +return val; }Hmm. In cases of dbi and dbi2, readb/readw/readl and writeb/writew/writel are located in
pcie-designware.h. These functions just call read/write which are located inpcie-designware.c. For readability, would you write the code as below?1. For
drivers/pci/controller/dwc/pcie-designware.h,Just call dw_pcie_{write/read}_atu(), instead of implementing functions as below. static inline void dw_pcie_writel_atu(struct dw_pcie *pci, u32 reg, u32 val) { return dw_pcie_write_atu(pci, reg, 0x4, val); } static inline u32 dw_pcie_readl_atu(struct dw_pcie *pci, u32 reg) { return dw_pcie_read_atu(pci, reg, 0x4); }2. For
drivers/pci/controller/dwc/pcie-designware.c,Please add new dw_pcie_{write/read}_atu() as below. void dw_pcie_write_atu(struct dw_pcie *pci, u32 reg, size_t size, u32 val) { int ret; if (pci->ops->write_dbi) { pci->ops->write_dbi(pci, pci->atu_base, reg, size, val); return; } ret = dw_pcie_write(pci->atu_base + reg, size, val); if (ret) dev_err(pci->dev, "Write ATU address failed\n"); } u32 dw_pcie_read_atu(struct dw_pcie *pci, u32 reg, size_t size) { int ret; u32 val; if (pci->ops->read_dbi) return pci->ops->read_dbi(pci, pci->atu_base, reg, size); ret = dw_pcie_read(pci->atu_base + reg, size, &val); if (ret) dev_err(pci->dev, "Read ATU address failed\n"); return val; }
Quoted 4 lines
Thank you.
Best regards,
Jingoo Han
Ok. I'll take care of it in next patch.
Quoted 6 lines
Quoted 5 lines
static inline void
dw_pcie_dbi_ro_wr_en(struct dw_pcie *pci)Signature · 1 line
2.17.1
PATCH v7 3/3 PCI: dwc: Export APIs to support .remove() implementation
In reply to Vidya SagarExport all configuration space access APIs and also other APIs to support host controller drivers of DesignWare core based implementations while adding support for .remove() hook to build their respective drivers as modules
---
Changes from v6:
* None
Changes from v5:
* None
Changes from v4:
* Removed __ (underscore) from dw_pcie_{write/read}_dbi API names
Changes from v3:
* Exported only __dw_pcie_{read/write}_dbi() APIs instead of dw_pcie_read{l/w/b}_dbi & dw_pcie_write{l/w/b}_dbi APIs.
Changes from v2:
* Rebased on top of linux-next top of the tree branch
Changes from v1:
* s/Designware/DesignWare
drivers/pci/controller/dwc/pcie-designware-host.c | 4 ++++ drivers/pci/controller/dwc/pcie-designware.c | 4 ++++ 2 files changed, 8 insertions(+)
drivers/pci/controller/dwc/pcie-designware-host.c +4 -0
@@ -311,6 +311,7 @@ void dw_pcie_msi_init(struct pcie_port *pp)dw_pcie_wr_own_conf (pp,PCIE_MSI_ADDR_HI ,4 ,upper_32_bits (msi_target)); } +EXPORT_SYMBOL_GPL (dw_pcie_msi_init);int dw_pcie_host_init (struct pcie_port *pp) {
@@ -495,6 +496,7 @@ int dw_pcie_host_init(struct pcie_port *pp)dw_pcie_free_msi (pp);return ret; } +EXPORT_SYMBOL_GPL (dw_pcie_host_init);void dw_pcie_host_deinit (struct pcie_port *pp) {
@@ -503,6 +505,7 @@ void dw_pcie_host_deinit(struct pcie_port *pp)if (pci_msi_enabled () && !pp->ops->msi_host_init)dw_pcie_free_msi (pp); } +EXPORT_SYMBOL_GPL (dw_pcie_host_deinit); static int dw_pcie_access_other_conf(struct pcie_port *pp, struct pci_bus *bus, u32 devfn, int where, int size, u32 *val,
@@ -695,3 +698,4 @@ void dw_pcie_setup_rc(struct pcie_port *pp) val |=PORT_LOGIC_SPEED_CHANGE ;dw_pcie_wr_own_conf (pp,PCIE_LINK_WIDTH_SPEED_CONTROL ,4 , val); } +EXPORT_SYMBOL_GPL (dw_pcie_setup_rc);
drivers/pci/controller/dwc/pcie-designware.c +4 -0
@@ -34,6 +34,7 @@ int dw_pcie_read(void __iomem *addr, int size, u32 *val)return PCIBIOS_SUCCESSFUL ; } +EXPORT_SYMBOL_GPL (dw_pcie_read);int dw_pcie_write (void __iomem *addr,int size,u32 val) {
@@ -51,6 +52,7 @@ int dw_pcie_write(void __iomem *addr, int size, u32 val)return PCIBIOS_SUCCESSFUL ; } +EXPORT_SYMBOL_GPL (dw_pcie_write);u32 dw_pcie_read_dbi (struct dw_pcie *pci,u32 reg,size_t size) {
@@ -66,6 +68,7 @@ u32 dw_pcie_read_dbi(struct dw_pcie *pci, u32 reg, size_t size)return val; } +EXPORT_SYMBOL_GPL (dw_pcie_read_dbi);void dw_pcie_write_dbi (struct dw_pcie *pci,u32 reg,size_t size,u32 val) {
@@ -80,6 +83,7 @@ void dw_pcie_write_dbi(struct dw_pcie *pci, u32 reg, size_t size, u32 val)if (ret)dev_err (pci->dev,"Write DBI address failed\n" ); } +EXPORT_SYMBOL_GPL (dw_pcie_write_dbi);u32 dw_pcie_read_dbi2 (struct dw_pcie *pci,u32 reg,size_t size) {
Signature · 1 line
2.17.1