Re: [PATCH v4 1/3] PCI: endpoint: Add helper function pci_epf_get_bar_required_size()

From: Niklas Cassel

Date: Mon Oct 06 2025 - 06:43:57 EST


On Tue, Sep 30, 2025 at 04:39:37PM -0400, Frank Li wrote:
> Introduce pci_epf_get_bar_required_size() to retrieve the required BAR
> size and memory size. Prepare for adding support to set an MMIO address to
> a specific BAR.
>
> Use two variables 'aligned_bar_size' and 'aligned_mem_size' to avoid
> confuse.

'aligned_bar_size' has been renamed, so this sentence should be updated.


(snip)

> @@ -308,7 +327,9 @@ void *pci_epf_alloc_space(struct pci_epf *epf, size_t size, enum pci_barno bar,
> }
>
> dev = epc->dev.parent;
> - space = dma_alloc_coherent(dev, aligned_size, &phys_addr, GFP_KERNEL);
> +
> + space = dma_alloc_coherent(dev, aligned_mem_size,
> + &phys_addr, GFP_KERNEL);
> if (!space) {
> dev_err(dev, "failed to allocate mem space\n");
> return NULL;
> @@ -317,7 +338,7 @@ void *pci_epf_alloc_space(struct pci_epf *epf, size_t size, enum pci_barno bar,
> epf_bar[bar].phys_addr = phys_addr;
> epf_bar[bar].addr = space;
> epf_bar[bar].size = size;
> - epf_bar[bar].aligned_size = aligned_size;
> + epf_bar[bar].aligned_size = aligned_mem_size;

I like that this local variable is now named aligned_mem_size
to more clearly highlight that it is the aligned _memory_ size.

Perhaps you could also rename the struct pci_epf_bar struct member
'aligned_size' to 'aligned_mem_size' or perhaps even better,
'backing_mem_size' or 'mem_size' ?


Kind regards,
Niklas