diff mbox series

[11/14] hdata: Add xscom_to_pcrd()

Message ID 20170915054059.32109-11-oohall@gmail.com
State Accepted
Headers show
Series [01/14] core/pci-dt-slot: Represent PCIe slots in the devicetree | expand

Commit Message

Oliver O'Halloran Sept. 15, 2017, 5:40 a.m. UTC
Iterating the SPPCRD structures (per chip data) is a fairly common
operation in the HDAT parser. Iterating the tuples directly is somewhat
irritating since we need to check for disabled chips, etc on every pass.
A better way to handle this is to iterate throught he xscom nodes
(generated from the SPPCRD data) and map from the xscom node to the
originating structure. This patch adds a function to do that.

Signed-off-by: Oliver O'Halloran <oohall@gmail.com>
---
 hdata/spira.c | 39 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)
diff mbox series

Patch

diff --git a/hdata/spira.c b/hdata/spira.c
index b58be7c1a009..240f344d8a41 100644
--- a/hdata/spira.c
+++ b/hdata/spira.c
@@ -290,6 +290,42 @@  static struct dt_node *add_xscom_node(uint64_t base, uint32_t hw_id,
 	return node;
 }
 
+/*
+ * Given a xscom@ node this will return a pointer into the SPPCRD
+ * structure corresponding to that node
+ */
+#define GET_HDIF_HDR -1
+static const void *xscom_to_pcrd(struct dt_node *xscom, int idata_index)
+{
+	struct spira_ntuple *t = &spira.ntuples.proc_chip;
+	const struct HDIF_common_hdr *hdif;
+	const void *idata;
+	unsigned int size;
+	uint32_t i;
+	void *base;
+
+	i = dt_prop_get_u32_def(xscom, DT_PRIVATE "sppcrd-index", 0xffffffff);
+	if (i == 0xffffffff)
+		return NULL;
+
+	base = get_hdif(t, "SPPCRD");
+	assert(base);
+	assert(i < be16_to_cpu(t->act_cnt));
+
+	hdif = base + i * be32_to_cpu(t->alloc_len);
+	if (!hdif)
+		return NULL;
+
+	if (idata_index == GET_HDIF_HDR)
+		return hdif;
+
+	idata = HDIF_get_idata(hdif, idata_index, &size);
+	if (!idata || !size)
+		return NULL;
+
+	return idata;
+}
+
 struct dt_node *find_xscom_for_chip(uint32_t chip_id)
 {
 	struct dt_node *node;
@@ -447,6 +483,9 @@  static bool add_xscom_sppcrd(uint64_t xscom_base)
 		if (!np)
 			continue;
 
+
+		dt_add_property_cells(np, DT_PRIVATE "sppcrd-index", i);
+
 		version = be16_to_cpu(hdif->version);
 
 		/* Version 0A has additional OCC related stuff */