On Mon, Jun 09, 2025 at 12:34:16PM GMT, Frank Li wrote:
Introduce the helper function pci_epf_align_inbound_addr() to adjust addresses according to PCI BAR alignment requirements, converting addresses into base and offset values.
Signed-off-by: Frank Li Frank.Li@nxp.com
Change from v15 to v16
- none
Change from v14 to v15
- change out address type to dma_addr_t to fix below build issue
| Reported-by: kernel test robot lkp@intel.com | Closes: https://lore.kernel.org/oe-kbuild-all/202502082311.G1hWGggF-lkp@intel.com/
All errors (new ones prefixed by >>):
drivers/pci/endpoint/functions/pci-epf-test.c: In function 'pci_epf_test_enable_doorbell':
drivers/pci/endpoint/functions/pci-epf-test.c:726:42: error: passing argument 4 of 'pci_epf_align_inbound_addr' from incompatible pointer type [-Werror=incompatible-pointer-types]
726 | &epf_test->db_bar.phys_addr, &offset); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~ | | | dma_addr_t * {aka unsigned int *}
In file included from include/linux/pci-epc.h:12,
Change form v9 to v14
- none
change from v8 to v9
- pci_epf_align_inbound_addr(), base and off must be not NULL
- rm pci_epf_align_inbound_addr_lo_hi()
change from v7 to v8
- change name to pci_epf_align_inbound_addr()
- update comment said only need for memory, which not allocated by
pci_epf_alloc_space().
change from v6 to v7
- new patch
drivers/pci/endpoint/pci-epf-core.c | 44 +++++++++++++++++++++++++++++++++++++ include/linux/pci-epf.h | 3 +++ 2 files changed, 47 insertions(+)
diff --git a/drivers/pci/endpoint/pci-epf-core.c b/drivers/pci/endpoint/pci-epf-core.c index 95fb3d7c1d45e..33e14a6b1549a 100644 --- a/drivers/pci/endpoint/pci-epf-core.c +++ b/drivers/pci/endpoint/pci-epf-core.c @@ -481,6 +481,50 @@ struct pci_epf *pci_epf_create(const char *name) } EXPORT_SYMBOL_GPL(pci_epf_create); +/**
- pci_epf_align_inbound_addr() - Get base address and offset that match BAR's
alignment requirement
'Align the given address based on the BAR alignment requirement'
- @epf: the EPF device
- @addr: the address of the memory
'inbound address to be aligned'
- @bar: the BAR number corresponding to map addr
s/map addr/the given addr
- @base: return base address, which match BAR's alignment requirement.
'base address matching the @bar alignment requirement'
- @off: return offset.
'offset to be added to the @base address'
- Helper function to convert input 'addr' to base and offset, which match
s/convert/align
- BAR's alignment requirement.
- The pci_epf_alloc_space() function already accounts for alignment. This is
- primarily intended for use with other memory regions not allocated by
- pci_epf_alloc_space(), such as peripheral register spaces or the trigger
- address for a platform MSI controller.
- */
+int pci_epf_align_inbound_addr(struct pci_epf *epf, enum pci_barno bar,
u64 addr, dma_addr_t *base, size_t *off)
+{
- const struct pci_epc_features *epc_features;
- u64 align;
- if (!base || !off)
return -EINVAL;
- epc_features = pci_epc_get_features(epf->epc, epf->func_no, epf->vfunc_no);
- if (!epc_features) {
dev_err(&epf->dev, "epc_features not implemented\n");
return -EOPNOTSUPP;
- }
- align = epc_features->align;
- align = align ? align : 128;
From where this 128 byte alignment comes from?
- Mani