On Thu, May 12, 2022 at 07:31:24PM +0530, Manivannan Sadhasivam wrote: > On Wed, May 04, 2022 at 12:46:32AM +0300, Serge Semin wrote: > > From maintainability and scalability points of view it has been wrong to > > use different iATU inbound and outbound regions accessors for the viewport > > and unrolled versions of the iATU CSRs mapping. Seeing the particular iATU > > region-wise registers layout is almost fully compatible for different > > IP-core versions, there were no much points in splitting the code up that > > way since it was possible to implement a common windows setup methods for > > both viewport and unrolled iATU CSRs spaces. While what we can observe in > > the current driver implementation of these methods, is a lot of code > > duplication, which consequently worsen the code readability, > > maintainability and scalability. Note the current implementation is a bit > > more performant than the one suggested in this commit since it implies > > having less MMIO accesses. But the gain just doesn't worth having the > > denoted difficulties especially seeing the iATU setup methods are mainly > > called on the DW PCIe controller and peripheral devices initialization > > stage. > > > > Here we suggest to move the iATU viewport and unrolled CSR access > > specifics in the dw_pcie_readl_atu() and dw_pcie_writel_atu() method, and > > convert the dw_pcie_prog_outbound_atu() and > > dw_pcie_prog_{ep_}inbound_atu() functions to being generic instead of > > having a different methods for each viewport and unrolled types of iATU > > CSRs mapping. Nothing complex really. First of all the dw_pcie_readl_atu() > > and dw_pcie_writel_atu() are converted to accept relative iATU CSRs > > address together with the iATU region direction (inbound or outbound) and > > region index. If DW PCIe controller doesn't have the unrolled iATU CSRs > > space, then the accessors will need to activate a iATU viewport based on > > the specified direction and index, otherwise a base address for the > > corresponding region CSRs will be calculated by means of the > > PCIE_ATU_UNROLL_BASE() macro. The CSRs macro have been modified in > > accordance with that logic in the pcie-designware.h header file. > > > > The rest of the changes in this commit just concern converting the iATU > > in-/out-bound setup methods and iATU regions detection procedure to be > > compatible with the new accessors semantics. As a result we've dropped the > > no more required dw_pcie_prog_outbound_atu_unroll(), > > dw_pcie_prog_inbound_atu_unroll() and dw_pcie_iatu_detect_regions_unroll() > > methods. > > > > Note aside with the denoted code improvements, there is an additional > > positive side effect of this change. If at some point an atomic iATU > > configs setup procedure is required, it will be possible to be done with > > no much effort just by adding the synchronization into the > > dw_pcie_readl_atu() and dw_pcie_writel_atu() accessors. > > > > Signed-off-by: Serge Semin <Sergey.Semin@xxxxxxxxxxxxxxxxxxxx> > > > > --- > > > > Changelog v2: > > - Move the iATU region selection procedure into a helper function (@Rob). > > - Simplify the iATU region selection procedure by recalculating the base > > address only if the space is unrolled. The iATU viewport base address > > is saved in the pci->atu_base field from now. > > --- > > drivers/pci/controller/dwc/pcie-designware.c | 293 ++++++------------- > > drivers/pci/controller/dwc/pcie-designware.h | 48 ++- > > In this patch, you also need to fix "pcie-tegra194-acpi.c" driver that makes > use of the removed macros. Right. I've missed the ACPI part since it isn't available on my platform. Thanks for noticing that. -Sergey > > Thanks, > Mani > > -- > மணிவண்ணன் சதாசிவம்