[coreboot-gerrit] New patch to review for coreboot: chromeos: Implement locating and decoding wifi sar data from VPD

Robbie Zhang (robbie.zhang@intel.com) gerrit at coreboot.org
Fri Dec 23 20:44:46 CET 2016


Robbie Zhang (robbie.zhang at intel.com) just uploaded a new patch set to gerrit, which you can find at https://review.coreboot.org/17958

-gerrit

commit 6f22b439e10c9ab791391a19148a65d5b67a4aaf
Author: Robbie Zhang <robbie.zhang at intel.com>
Date:   Fri Dec 23 11:43:07 2016 -0800

    chromeos: Implement locating and decoding wifi sar data from VPD
    
    A VPD entry "wifi_sar" needs to be created which contains a heximal
    encoded string in length of 40 bytes. wifi_sar_limits() function
    retrives and decodes the data from the VPD entry, returning pointer
    to an instance of the structure (array of 40 bytes (u8)), which
    would be later consumed by platform code needing this data.
    
    BUG=chrome-os-partner:60821
    TEST=Build and boot lars and reef
    
    Change-Id: I923b58a63dc1f8a7fdd685cf1c618b2fdf4e7061
    Signed-off-by: Robbie Zhang <robbie.zhang at intel.com>
---
 src/include/sar.h                           | 43 ++++++++++++++
 src/vendorcode/google/chromeos/Makefile.inc |  1 +
 src/vendorcode/google/chromeos/cros_vpd.h   |  1 +
 src/vendorcode/google/chromeos/sar.c        | 92 +++++++++++++++++++++++++++++
 4 files changed, 137 insertions(+)

diff --git a/src/include/sar.h b/src/include/sar.h
new file mode 100644
index 0000000..bf3e4a5
--- /dev/null
+++ b/src/include/sar.h
@@ -0,0 +1,43 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * Copyright (C) 2016 Intel Corp.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+#ifndef _SAR_H_
+#define _SAR_H_
+
+#include <stdint.h>
+
+/* WRDS Spec Revision */
+#define WRDS_REVISION 0x0
+
+/* EWRD Spec Revision */
+#define EWRD_REVISION 0x0
+
+/* WRDS Domain type */
+#define WRDS_DOMAIN_TYPE_WIFI 0x7
+
+/* EWRD Domain type */
+#define EWRD_DOMAIN_TYPE_WIFI 0x7
+
+/* Number of bytes for a SAR set */
+#define BYTES_OF_SAR_SET 10
+
+/* Wifi SAR limit table structure */
+struct wifi_sar_limit_t{
+	u8 sar_limit[40]; /* Total 4 SAR limit sets, each contains 10 bytes */
+};
+
+/* Retrieve the SAR limits data from VPD */
+struct wifi_sar_limit_t *wifi_sar_limits(void);
+
+#endif /* _SAR_H_ */
diff --git a/src/vendorcode/google/chromeos/Makefile.inc b/src/vendorcode/google/chromeos/Makefile.inc
index e84eb3d..878b068 100644
--- a/src/vendorcode/google/chromeos/Makefile.inc
+++ b/src/vendorcode/google/chromeos/Makefile.inc
@@ -25,6 +25,7 @@ ramstage-$(CONFIG_CHROMEOS_RAMOOPS) += ramoops.c
 romstage-y += vpd_decode.c
 ramstage-y += vpd_decode.c cros_vpd.c vpd_mac.c vpd_serialno.c vpd_calibration.c
 ramstage-$(CONFIG_HAVE_REGULATORY_DOMAIN) += wrdd.c
+ramstage-$(CONFIG_USE_SAR) += sar.c
 ifeq ($(CONFIG_ARCH_MIPS),)
 bootblock-y += watchdog.c
 ramstage-y += watchdog.c
diff --git a/src/vendorcode/google/chromeos/cros_vpd.h b/src/vendorcode/google/chromeos/cros_vpd.h
index 96ca8af..1fa56a4 100644
--- a/src/vendorcode/google/chromeos/cros_vpd.h
+++ b/src/vendorcode/google/chromeos/cros_vpd.h
@@ -8,6 +8,7 @@
 #define __CROS_VPD_H__
 
 #define CROS_VPD_REGION_NAME "region"
+#define CROS_VPD_WIFI_SAR_NAME "wifi_sar"
 
 /*
  * Reads VPD string value by key.
diff --git a/src/vendorcode/google/chromeos/sar.c b/src/vendorcode/google/chromeos/sar.c
new file mode 100644
index 0000000..24cf73b
--- /dev/null
+++ b/src/vendorcode/google/chromeos/sar.c
@@ -0,0 +1,92 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * Copyright (C) 2016 Intel Corp.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+#include <console/console.h>
+#include <types.h>
+#include <string.h>
+#include <sar.h>
+#include "cros_vpd.h"
+
+/*
+ * Decode string representation of the SAR limits (a string of hex symbols)
+ * into binary. 'key_name' is the name of the VPD field, it's used if
+ * it is necessary to report an input data format problem.
+ */
+static void decode_sar_limit(struct wifi_sar_limit_t *sar_limits,
+		       const char *sar_limit_str,
+		       const char *key_name)
+{
+	int i;
+	int size = sizeof(struct wifi_sar_limit_t) / sizeof(u8);
+
+	for (i = 0; i < size; i++) {
+		int j;
+		int n = 0;
+
+		for (j = 0; j < 2; j++) {
+			char c = sar_limit_str[i * 2 + j];
+			if (isxdigit(c)) {
+				if (isdigit(c))
+					c = c - '0';
+				else
+					c =  tolower(c) - 'a' + 10;
+			} else {
+				printk(BIOS_ERR, "%s: non hexadecimal symbol "
+				       "%#2.2x in the VPD field %s:%s\n",
+				       __func__, (uint8_t)c, key_name,
+				       sar_limit_str);
+			}
+			n <<= 4;
+			n |= c;
+		}
+		sar_limits->sar_limit[i] = n;
+	}
+}
+
+/*
+ * Retrieve the wifi SAR limits from VPD
+ * If the information is not found in the VPD, this function will
+ * return a NULL pointer.
+ */
+struct wifi_sar_limit_t *wifi_sar_limits(void)
+{
+	struct wifi_sar_limit_t *p;
+	const char *wifi_sar_limit_key = CROS_VPD_WIFI_SAR_NAME;
+	/*
+	 * cros_vpd_gets() reads in one less than size characters from the VPD
+	 * with a terminating null byte ('\0') stored as the last character into
+	 * the buffer, thus the increasing by 1 for buffer_size.
+	*/
+	int buffer_size = (sizeof(struct wifi_sar_limit_t) / sizeof(u8)) * 2 + 1;
+	char wifi_sar_limit_str[buffer_size];
+
+	p = malloc(sizeof(struct wifi_sar_limit_t));
+	if (!p) {
+		printk(BIOS_ERR, "Wifi SAR: Could not allocate memory\n");
+		return NULL;
+    }
+
+	/* Try to read the SAR limit entry from VPD */
+	if (!cros_vpd_gets(wifi_sar_limit_key, wifi_sar_limit_str,
+		ARRAY_SIZE(wifi_sar_limit_str))) {
+		printk(BIOS_DEBUG,
+		"Error: Could not locate '%s' in VPD\n", wifi_sar_limit_key);
+		return NULL;
+	}
+	printk(BIOS_ERR, "VPD wifi_sar = %s\n", wifi_sar_limit_str);
+
+	/* Decode the heximal encoded string to binary values */
+	decode_sar_limit(p, wifi_sar_limit_str, wifi_sar_limit_key);
+	return p;
+}



More information about the coreboot-gerrit mailing list