diff mbox series

[RFC,1/3] capp: Add ability to fetch CAPP attribute override values from nvram

Message ID 20180909114140.9836-2-vaibhav@linux.ibm.com
State New, archived
Headers show
Series phb4/capp: Provide user tunable for STQ/DMA engine allocation | expand

Checks

Context Check Description
snowpatch_ozlabs/apply_patch success master/apply_patch Successfully applied

Commit Message

Vaibhav Jain Sept. 9, 2018, 11:41 a.m. UTC
This patch implements capp_get_override() that queries the nvram
'ibm,skiboot' partition for an attribute override 'attr' present and
return its value as an uint64_t. In case the the attribute-override
isn't present in nvram then the 'def_val' argument to the function is
returned.

The expected key-format for attribute override in nvram is:

chip<chip-id>.capp<0|1>.<attr>

chip-id	  : Chip-index of the CAPP.
capp<0|1> : CAPP index on the chip. There are max 2 CAPPs in a chip.
attr      : Attribute name as string.

For example to allocate 2 STQ engines to CAPP-1 on Chip-0 the nvram
config should be 'chip00.capp1.stq-engines=2' .

During CAPP initialization capp_get_override() will be called to fetch
override values for various CAPP initialization attributes and the
value returned from the function will be used. The function itself
wont parses nor understands the attr being requested and just checks
if an attribute override for the given CAPP exists and returns its
value.

Signed-off-by: Vaibhav Jain <vaibhav@linux.ibm.com>
---
 hw/capp.c      | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
 include/capp.h |  2 ++
 2 files changed, 52 insertions(+)
diff mbox series

Patch

diff --git a/hw/capp.c b/hw/capp.c
index eeaa4ac4..177a6f15 100644
--- a/hw/capp.c
+++ b/hw/capp.c
@@ -19,6 +19,11 @@ 
 #include <chip.h>
 #include <xscom.h>
 #include <capp.h>
+#include <pci.h>
+#include <phb3.h>
+#include <phb4.h>
+#include <phb4-capp.h>
+#include <nvram.h>
 
 #define PHBERR(opal_id, chip_id, index, fmt, a...) \
 	       prlog(PR_ERR, "PHB#%04x[%d:%d]: " fmt, \
@@ -240,3 +245,48 @@  int64_t capp_get_info(int chip_id, struct phb *phb, struct capp_info *info)
 
 	return OPAL_PARAMETER;
 }
+
+uint64_t capp_get_override(struct phb *phb, const char *attr, uint64_t def_val)
+{
+	char key_buffer[33];
+	const char *val;
+	uint64_t nval;
+	unsigned int chip_index, capp_index;
+
+	switch (phb->phb_type) {
+	case phb_type_pcie_v4:
+	{
+		struct phb4 *p = phb_to_phb4(phb);
+
+		chip_index = p->chip_id;
+		capp_index = PHB4_CAPP_REG_OFFSET(p) ? 1 : 0;
+	}
+	break;
+	case phb_type_pcie_v3:
+	{
+		struct phb3 *p = phb_to_phb3(phb);
+
+		chip_index = p->chip_id;
+		capp_index = PHB3_CAPP_REG_OFFSET(p) ? 1 : 0;
+	}
+	break;
+	default:
+		return def_val;
+	}
+
+	/* Construct the key based on chip and capp index */
+	snprintf(key_buffer, sizeof(key_buffer) - 1, "chip%02x.capp%01x.%s",
+		 chip_index, capp_index, attr);
+	key_buffer[sizeof(key_buffer) - 1] = 0;
+
+	/* Query the nvram for any override */
+	val = nvram_query(key_buffer);
+	if (val) {
+		nval = strtoul(val, NULL, 0);
+		prlog(PR_DEBUG, "CAPP Override: %s: 0x%016llX => 0x%016llX\n",
+		      key_buffer, def_val, nval);
+		return nval;
+	} else {
+		return def_val;
+	}
+}
diff --git a/include/capp.h b/include/capp.h
index 597401d5..14122b17 100644
--- a/include/capp.h
+++ b/include/capp.h
@@ -96,4 +96,6 @@  extern int64_t capp_load_ucode(unsigned int chip_id, uint32_t opal_id,
 extern int64_t capp_get_info(int chip_id, struct phb *phb,
 			     struct capp_info *info);
 
+uint64_t capp_get_override(struct phb *phb, const char *attr, uint64_t def_val);
+
 #endif /* __CAPP_H */