From 26c19bb8967b9d5b95181e1e615fc23574dad431 Mon Sep 17 00:00:00 2001 From: Oliver O'Halloran Date: Fri, 15 Sep 2017 15:40:56 +1000 Subject: hdata: Add xscom_to_pcrd() 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 Signed-off-by: Stewart Smith --- hdata/spira.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'hdata') diff --git a/hdata/spira.c b/hdata/spira.c index b58be7c..240f344 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 */ -- cgit v1.1