Edward O'Callaghan has uploaded this change for review.

View Change

ich_descriptor.c: Simplify get_density lookups by deduplicate sw

These two switch statements look up the same thing with only the
return type as different. Therefore deduce out the density encoding
lookup from the use-case logic.

TEST=`flashrom -p internal --flash-name` on Intel Kaby Lake U w/ iHDCP2.2 Prem.

Change-Id: Ieb4e9f19f4f06becd344fe08829dabe20c3c8de0
Signed-off-by: Edward O'Callaghan <quasisec@google.com>
---
M ich_descriptors.c
1 file changed, 50 insertions(+), 79 deletions(-)

git pull ssh://review.coreboot.org:29418/flashrom refs/changes/21/63321/1
diff --git a/ich_descriptors.c b/ich_descriptors.c
index 7c03499..ec8546c 100644
--- a/ich_descriptors.c
+++ b/ich_descriptors.c
@@ -161,26 +161,17 @@
msg_pdbg2("\n");
}

-static const char *pprint_density(enum ich_chipset cs, const struct ich_descriptors *desc, uint8_t idx)
+static int get_density(enum ich_chipset cs, const struct ich_descriptors *desc, uint8_t idx, uint8_t *size_enc, uint8_t *size_max)
{
+ *size_enc = 0;
+ *size_max = 0;
+
if (idx > 1) {
msg_perr("Only ICH SPI component index 0 or 1 are supported yet.\n");
- return NULL;
+ return -2;
}
-
if (desc->content.NC == 0 && idx > 0)
- return "unused";
-
- static const char * const size_str[] = {
- "512 kB", /* 0000 */
- "1 MB", /* 0001 */
- "2 MB", /* 0010 */
- "4 MB", /* 0011 */
- "8 MB", /* 0100 */
- "16 MB", /* 0101 */ /* Maximum up to Lynx Point (excl.) */
- "32 MB", /* 0110 */
- "64 MB", /* 0111 */
- };
+ return 0;

switch (cs) {
case CHIPSET_ICH8:
@@ -190,15 +181,13 @@
case CHIPSET_6_SERIES_COUGAR_POINT:
case CHIPSET_7_SERIES_PANTHER_POINT:
case CHIPSET_BAYTRAIL: {
- uint8_t size_enc;
if (idx == 0) {
- size_enc = desc->component.dens_old.comp1_density;
+ *size_enc = desc->component.dens_old.comp1_density;
} else {
- size_enc = desc->component.dens_old.comp2_density;
+ *size_enc = desc->component.dens_old.comp2_density;
}
- if (size_enc > 5)
- return "reserved";
- return size_str[size_enc];
+ *size_max = 5;
+ break;
}
case CHIPSET_8_SERIES_LYNX_POINT:
case CHIPSET_8_SERIES_LYNX_POINT_LP:
@@ -215,20 +204,48 @@
case CHIPSET_APOLLO_LAKE:
case CHIPSET_GEMINI_LAKE:
case CHIPSET_ELKHART_LAKE: {
- uint8_t size_enc;
if (idx == 0) {
- size_enc = desc->component.dens_new.comp1_density;
+ *size_enc = desc->component.dens_new.comp1_density;
} else {
- size_enc = desc->component.dens_new.comp2_density;
+ *size_enc = desc->component.dens_new.comp2_density;
}
- if (size_enc > 7)
- return "reserved";
- return size_str[size_enc];
+ *size_max = 7;
+ break;
}
case CHIPSET_ICH_UNKNOWN:
default:
- return "unknown";
+ msg_pwarn("Density encoding is unknown on this chipset.\n");
+ return -1;
}
+ return 1;
+}
+
+static const char *pprint_density(enum ich_chipset cs, const struct ich_descriptors *desc, uint8_t idx)
+{
+ static const char * const size_str[] = {
+ "512 kB", /* 0000 */
+ "1 MB", /* 0001 */
+ "2 MB", /* 0010 */
+ "4 MB", /* 0011 */
+ "8 MB", /* 0100 */
+ "16 MB", /* 0101 */ /* Maximum up to Lynx Point (excl.) */
+ "32 MB", /* 0110 */
+ "64 MB", /* 0111 */
+ };
+
+ uint8_t size_enc;
+ uint8_t size_max;
+
+ int ret = get_density(cs, desc, idx, &size_enc, &size_max);
+ if (ret == -2)
+ return NULL;
+ else if (ret == -1)
+ return "unknown";
+ else if (ret == 0)
+ return "unused";
+ else if (size_enc > size_max)
+ return "reserved";
+ return size_str[size_enc];
}

static const char *pprint_freq(enum ich_chipset cs, uint8_t value)
@@ -1194,61 +1211,15 @@
\em idx in bytes or -1 if the correct size can not be determined. */
int getFCBA_component_density(enum ich_chipset cs, const struct ich_descriptors *desc, uint8_t idx)
{
- if (idx > 1) {
- msg_perr("Only ICH SPI component index 0 or 1 are supported yet.\n");
- return -1;
- }
-
- if (desc->content.NC == 0 && idx > 0)
- return 0;
-
uint8_t size_enc;
uint8_t size_max;

- switch (cs) {
- case CHIPSET_ICH8:
- case CHIPSET_ICH9:
- case CHIPSET_ICH10:
- case CHIPSET_5_SERIES_IBEX_PEAK:
- case CHIPSET_6_SERIES_COUGAR_POINT:
- case CHIPSET_7_SERIES_PANTHER_POINT:
- case CHIPSET_BAYTRAIL:
- if (idx == 0) {
- size_enc = desc->component.dens_old.comp1_density;
- } else {
- size_enc = desc->component.dens_old.comp2_density;
- }
- size_max = 5;
- break;
- case CHIPSET_8_SERIES_LYNX_POINT:
- case CHIPSET_8_SERIES_LYNX_POINT_LP:
- case CHIPSET_8_SERIES_WELLSBURG:
- case CHIPSET_9_SERIES_WILDCAT_POINT:
- case CHIPSET_9_SERIES_WILDCAT_POINT_LP:
- case CHIPSET_100_SERIES_SUNRISE_POINT:
- case CHIPSET_C620_SERIES_LEWISBURG:
- case CHIPSET_300_SERIES_CANNON_POINT:
- case CHIPSET_400_SERIES_COMET_POINT:
- case CHIPSET_500_SERIES_TIGER_POINT:
- case CHIPSET_600_SERIES_ALDER_POINT:
- case CHIPSET_METEOR_LAKE:
- case CHIPSET_APOLLO_LAKE:
- case CHIPSET_GEMINI_LAKE:
- case CHIPSET_ELKHART_LAKE:
- if (idx == 0) {
- size_enc = desc->component.dens_new.comp1_density;
- } else {
- size_enc = desc->component.dens_new.comp2_density;
- }
- size_max = 7;
- break;
- case CHIPSET_ICH_UNKNOWN:
- default:
- msg_pwarn("Density encoding is unknown on this chipset.\n");
+ int ret = get_density(cs, desc, idx, &size_enc, &size_max);
+ if (ret < 0)
return -1;
- }
-
- if (size_enc > size_max) {
+ else if (ret == 0)
+ return 0;
+ else if (size_enc > size_max) {
msg_perr("Density of ICH SPI component with index %d is invalid.\n"
"Encoded density is 0x%x while maximum allowed is 0x%x.\n",
idx, size_enc, size_max);

To view, visit change 63321. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: Ieb4e9f19f4f06becd344fe08829dabe20c3c8de0
Gerrit-Change-Number: 63321
Gerrit-PatchSet: 1
Gerrit-Owner: Edward O'Callaghan <quasisec@chromium.org>
Gerrit-MessageType: newchange