[PATCH 11/19] PCI: endpoint: Add helper API to populate header with values from DT

From: Kishon Vijay Abraham I
Date: Thu May 14 2020 - 11:02:18 EST


Add helper API pci_epc_of_parse_header() to populate header with
values from device tree. These values will be written to the
configuration space header in the endpoint controller.

Signed-off-by: Kishon Vijay Abraham I <kishon@xxxxxx>
---
drivers/pci/endpoint/pci-epc-core.c | 24 ++++++++++++++++++++++++
include/linux/pci-epc.h | 2 ++
2 files changed, 26 insertions(+)

diff --git a/drivers/pci/endpoint/pci-epc-core.c b/drivers/pci/endpoint/pci-epc-core.c
index df8789fee01e..31a82af397a3 100644
--- a/drivers/pci/endpoint/pci-epc-core.c
+++ b/drivers/pci/endpoint/pci-epc-core.c
@@ -31,6 +31,30 @@ static int devm_pci_epc_match(struct device *dev, void *res, void *match_data)
return *epc == match_data;
}

+/**
+ * pci_epc_of_parse_header() - parse the device tree to get PCI config space
+ * header
+ * @node: The device tree node (of endpoint function) which has the PCI config
+ * space header values
+ * @header: standard configuration space header fields that has to be populated
+ *
+ * Invoke to populate *header* with the PCI configuration space values populated
+ * in device tree.
+ */
+void pci_epc_of_parse_header(struct device_node *node,
+ struct pci_epf_header *header)
+{
+ of_property_read_u16(node, "epf,vendor-id", &header->vendorid);
+ of_property_read_u16(node, "epf,device-id", &header->deviceid);
+ of_property_read_u8(node, "epf,baseclass-code",
+ &header->baseclass_code);
+ of_property_read_u8(node, "epf,subclass-code", &header->subclass_code);
+ of_property_read_u16(node, "epf,subsys-vendor-id",
+ &header->subsys_vendor_id);
+ of_property_read_u16(node, "epf,subsys-id", &header->subsys_id);
+}
+EXPORT_SYMBOL_GPL(pci_epc_of_parse_header);
+
/**
* pci_epc_put() - release the PCI endpoint controller
* @epc: epc returned by pci_epc_get()
diff --git a/include/linux/pci-epc.h b/include/linux/pci-epc.h
index 463586889453..490a9077df52 100644
--- a/include/linux/pci-epc.h
+++ b/include/linux/pci-epc.h
@@ -199,6 +199,8 @@ int pci_epc_raise_irq(struct pci_epc *epc, u8 func_no,
enum pci_epc_irq_type type, u16 interrupt_num);
int pci_epc_start(struct pci_epc *epc);
void pci_epc_stop(struct pci_epc *epc);
+void pci_epc_of_parse_header(struct device_node *node,
+ struct pci_epf_header *header);
const struct pci_epc_features *pci_epc_get_features(struct pci_epc *epc,
u8 func_no);
enum pci_barno
--
2.17.1