Commit e891becd authored by Niklas Cassel's avatar Niklas Cassel Committed by Manivannan Sadhasivam

PCI: endpoint: Refactor pci_epf_alloc_space() API

Refactor pci_epf_alloc_space() API to accept "epc_features" as a parameter.
This is a preparatory work to make the API more robust.
Reviewed-by: default avatarFrank Li <Frank.Li@nxp.com>
Reviewed-by: default avatarManivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Signed-off-by: default avatarNiklas Cassel <cassel@kernel.org>
Link: https://lore.kernel.org/r/20240207213922.1796533-2-cassel@kernel.org
[mani: reworded commit message]
Signed-off-by: default avatarManivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
parent b91da730
...@@ -1067,7 +1067,7 @@ static int epf_ntb_config_spad_bar_alloc(struct epf_ntb *ntb, ...@@ -1067,7 +1067,7 @@ static int epf_ntb_config_spad_bar_alloc(struct epf_ntb *ntb,
else if (size < ctrl_size + spad_size) else if (size < ctrl_size + spad_size)
return -EINVAL; return -EINVAL;
base = pci_epf_alloc_space(epf, size, barno, align, type); base = pci_epf_alloc_space(epf, size, barno, epc_features, type);
if (!base) { if (!base) {
dev_err(dev, "%s intf: Config/Status/SPAD alloc region fail\n", dev_err(dev, "%s intf: Config/Status/SPAD alloc region fail\n",
pci_epc_interface_string(type)); pci_epc_interface_string(type));
......
...@@ -848,7 +848,7 @@ static int pci_epf_test_alloc_space(struct pci_epf *epf) ...@@ -848,7 +848,7 @@ static int pci_epf_test_alloc_space(struct pci_epf *epf)
} }
base = pci_epf_alloc_space(epf, test_reg_size, test_reg_bar, base = pci_epf_alloc_space(epf, test_reg_size, test_reg_bar,
epc_features->align, PRIMARY_INTERFACE); epc_features, PRIMARY_INTERFACE);
if (!base) { if (!base) {
dev_err(dev, "Failed to allocated register space\n"); dev_err(dev, "Failed to allocated register space\n");
return -ENOMEM; return -ENOMEM;
...@@ -866,8 +866,7 @@ static int pci_epf_test_alloc_space(struct pci_epf *epf) ...@@ -866,8 +866,7 @@ static int pci_epf_test_alloc_space(struct pci_epf *epf)
continue; continue;
base = pci_epf_alloc_space(epf, bar_size[bar], bar, base = pci_epf_alloc_space(epf, bar_size[bar], bar,
epc_features->align, epc_features, PRIMARY_INTERFACE);
PRIMARY_INTERFACE);
if (!base) if (!base)
dev_err(dev, "Failed to allocate space for BAR%d\n", dev_err(dev, "Failed to allocate space for BAR%d\n",
bar); bar);
......
...@@ -446,7 +446,7 @@ static int epf_ntb_config_spad_bar_alloc(struct epf_ntb *ntb) ...@@ -446,7 +446,7 @@ static int epf_ntb_config_spad_bar_alloc(struct epf_ntb *ntb)
else if (size < ctrl_size + spad_size) else if (size < ctrl_size + spad_size)
return -EINVAL; return -EINVAL;
base = pci_epf_alloc_space(epf, size, barno, align, 0); base = pci_epf_alloc_space(epf, size, barno, epc_features, 0);
if (!base) { if (!base) {
dev_err(dev, "Config/Status/SPAD alloc region fail\n"); dev_err(dev, "Config/Status/SPAD alloc region fail\n");
return -ENOMEM; return -ENOMEM;
...@@ -550,7 +550,7 @@ static int epf_ntb_db_bar_init(struct epf_ntb *ntb) ...@@ -550,7 +550,7 @@ static int epf_ntb_db_bar_init(struct epf_ntb *ntb)
barno = ntb->epf_ntb_bar[BAR_DB]; barno = ntb->epf_ntb_bar[BAR_DB];
mw_addr = pci_epf_alloc_space(ntb->epf, size, barno, align, 0); mw_addr = pci_epf_alloc_space(ntb->epf, size, barno, epc_features, 0);
if (!mw_addr) { if (!mw_addr) {
dev_err(dev, "Failed to allocate OB address\n"); dev_err(dev, "Failed to allocate OB address\n");
return -ENOMEM; return -ENOMEM;
......
...@@ -251,14 +251,16 @@ EXPORT_SYMBOL_GPL(pci_epf_free_space); ...@@ -251,14 +251,16 @@ EXPORT_SYMBOL_GPL(pci_epf_free_space);
* @epf: the EPF device to whom allocate the memory * @epf: the EPF device to whom allocate the memory
* @size: the size of the memory that has to be allocated * @size: the size of the memory that has to be allocated
* @bar: the BAR number corresponding to the allocated register space * @bar: the BAR number corresponding to the allocated register space
* @align: alignment size for the allocation region * @epc_features: the features provided by the EPC specific to this EPF
* @type: Identifies if the allocation is for primary EPC or secondary EPC * @type: Identifies if the allocation is for primary EPC or secondary EPC
* *
* Invoke to allocate memory for the PCI EPF register space. * Invoke to allocate memory for the PCI EPF register space.
*/ */
void *pci_epf_alloc_space(struct pci_epf *epf, size_t size, enum pci_barno bar, void *pci_epf_alloc_space(struct pci_epf *epf, size_t size, enum pci_barno bar,
size_t align, enum pci_epc_interface_type type) const struct pci_epc_features *epc_features,
enum pci_epc_interface_type type)
{ {
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;
struct pci_epc *epc; struct pci_epc *epc;
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include <linux/pci.h> #include <linux/pci.h>
struct pci_epf; struct pci_epf;
struct pci_epc_features;
enum pci_epc_interface_type; enum pci_epc_interface_type;
enum pci_barno { enum pci_barno {
...@@ -216,7 +217,8 @@ int __pci_epf_register_driver(struct pci_epf_driver *driver, ...@@ -216,7 +217,8 @@ int __pci_epf_register_driver(struct pci_epf_driver *driver,
struct module *owner); struct module *owner);
void pci_epf_unregister_driver(struct pci_epf_driver *driver); void pci_epf_unregister_driver(struct pci_epf_driver *driver);
void *pci_epf_alloc_space(struct pci_epf *epf, size_t size, enum pci_barno bar, void *pci_epf_alloc_space(struct pci_epf *epf, size_t size, enum pci_barno bar,
size_t align, enum pci_epc_interface_type type); const struct pci_epc_features *epc_features,
enum pci_epc_interface_type type);
void pci_epf_free_space(struct pci_epf *epf, void *addr, enum pci_barno bar, void pci_epf_free_space(struct pci_epf *epf, void *addr, enum pci_barno bar,
enum pci_epc_interface_type type); enum pci_epc_interface_type type);
int pci_epf_bind(struct pci_epf *epf); int pci_epf_bind(struct pci_epf *epf);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment