PCI: endpoint: Improve pci_epf_alloc_space() API
pci_epf_alloc_space() already performs checks on the requested BAR size, and will allocate and set epf_bar->size to a size higher than the requested BAR size if some constraint deems it necessary. However, there are additional checks done in the function drivers like pci-epf-test.c, other than the existing checks in this API. And similar checks are proposed to other endpoint function drivers, see: https://lore.kernel.org/linux-pci/20240108151015.2030469-1-Frank.Li@nxp.com Having these checks scattered over different locations in multiple EPF drivers is not maintainable and makes the code hard to follow. Since pci_epf_alloc_space() already performs roundups and some checks, let's move the additional checks from pci-epf-test.c to pci_epf_alloc_space(). This makes the API more robust and also offloads the checks from the function drivers. Signed-off-by: Niklas Cassel <cassel@kernel.org> Reviewed-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org> Reviewed-by: Frank Li <Frank.Li@nxp.com> Link: https://lore.kernel.org/r/20240207213922.1796533-3-cassel@kernel.org [mani: reworded commit message and fixed uninitialized 'dev' pointer issue] Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
This commit is contained in:
parent
e891becdcc
commit
84b51a6bae
1 changed files with 9 additions and 0 deletions
|
@ -260,6 +260,7 @@ void *pci_epf_alloc_space(struct pci_epf *epf, size_t size, enum pci_barno bar,
|
||||||
const struct pci_epc_features *epc_features,
|
const struct pci_epc_features *epc_features,
|
||||||
enum pci_epc_interface_type type)
|
enum pci_epc_interface_type type)
|
||||||
{
|
{
|
||||||
|
u64 bar_fixed_size = epc_features->bar_fixed_size[bar];
|
||||||
size_t align = epc_features->align;
|
size_t align = epc_features->align;
|
||||||
struct pci_epf_bar *epf_bar;
|
struct pci_epf_bar *epf_bar;
|
||||||
dma_addr_t phys_addr;
|
dma_addr_t phys_addr;
|
||||||
|
@ -270,6 +271,14 @@ void *pci_epf_alloc_space(struct pci_epf *epf, size_t size, enum pci_barno bar,
|
||||||
if (size < 128)
|
if (size < 128)
|
||||||
size = 128;
|
size = 128;
|
||||||
|
|
||||||
|
if (bar_fixed_size && size > bar_fixed_size) {
|
||||||
|
dev_err(&epf->dev, "requested BAR size is larger than fixed size\n");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bar_fixed_size)
|
||||||
|
size = bar_fixed_size;
|
||||||
|
|
||||||
if (align)
|
if (align)
|
||||||
size = ALIGN(size, align);
|
size = ALIGN(size, align);
|
||||||
else
|
else
|
||||||
|
|
Loading…
Add table
Reference in a new issue