summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobbie Zhang <robbie.zhang@intel.com>2016-12-23 11:43:07 -0800
committerMartin Roth <martinroth@google.com>2017-01-09 18:16:10 +0100
commited840023a84915ece4bc63edffef979926107d55 (patch)
tree8a5c362b16aba0a47273bc35a802e93bb4e07c1c
parent23ceb7d240a16427d07746cc3c6b06a8418c9a1e (diff)
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. get_wifi_sar_limits() function retrieves and decodes the data from the VPD entry, which would later be consumed by platform code. BUG=chrome-os-partner:60821 TEST=Build and boot lars and reef Change-Id: I923b58a63dc1f8a7fdd685cf1c618b2fdf4e7061 Signed-off-by: Robbie Zhang <robbie.zhang@intel.com> Reviewed-on: https://review.coreboot.org/17958 Tested-by: build bot (Jenkins) Reviewed-by: Aaron Durbin <adurbin@chromium.org>
-rw-r--r--src/include/sar.h38
-rw-r--r--src/vendorcode/google/chromeos/Makefile.inc1
-rw-r--r--src/vendorcode/google/chromeos/cros_vpd.h1
-rw-r--r--src/vendorcode/google/chromeos/sar.c60
4 files changed, 100 insertions, 0 deletions
diff --git a/src/include/sar.h b/src/include/sar.h
new file mode 100644
index 0000000000..4653dd33ae
--- /dev/null
+++ b/src/include/sar.h
@@ -0,0 +1,38 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * Copyright (C) 2017 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>
+
+#define NUM_SAR_LIMITS 4
+#define BYTES_PER_SAR_LIMIT 10
+
+/* Wifi SAR limit table structure */
+struct wifi_sar_limits {
+ /* Total 4 SAR limit sets, each has 10 bytes */
+ uint8_t sar_limit[NUM_SAR_LIMITS][BYTES_PER_SAR_LIMIT];
+};
+
+/*
+ * Retrieve the SAR limits data from VPD and decode it.
+ * sar_limits: Pointer to wifi_sar_limits where the resulted data is stored
+ *
+ * Returns: 0 on success, -1 on errors (The VPD entry doesn't exist, or the
+ * VPD entry contains non-heximal value.)
+ */
+int get_wifi_sar_limits(struct wifi_sar_limits *sar_limits);
+
+#endif /* _SAR_H_ */
diff --git a/src/vendorcode/google/chromeos/Makefile.inc b/src/vendorcode/google/chromeos/Makefile.inc
index e84eb3d231..878b0684c0 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 96ca8af329..1fa56a4725 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 0000000000..2b61e223d5
--- /dev/null
+++ b/src/vendorcode/google/chromeos/sar.c
@@ -0,0 +1,60 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * Copyright (C) 2017 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"
+
+/* Retrieve the wifi SAR limits data from VPD and decode it */
+int get_wifi_sar_limits(struct wifi_sar_limits *sar_limits)
+{
+ 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.
+ */
+ const size_t buffer_size = (sizeof(struct wifi_sar_limits) /
+ sizeof(uint8_t)) * 2 + 1;
+ char wifi_sar_limit_str[buffer_size];
+ uint8_t bin_buffer[sizeof(struct wifi_sar_limits)];
+
+ /* 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_ERR,
+ "Error: Could not locate '%s' in VPD\n",
+ wifi_sar_limit_key);
+ return -1;
+ }
+ printk(BIOS_DEBUG, "VPD wifi_sar = %s\n", wifi_sar_limit_str);
+
+ /* Decode the heximal encoded string to binary values */
+ if (hexstrtobin(wifi_sar_limit_str, bin_buffer,
+ sizeof(struct wifi_sar_limits))
+ < sizeof(struct wifi_sar_limits)) {
+ printk(BIOS_ERR,
+ "Error: VPD wifi_sar contains non-heximal value!\n");
+ return -1;
+ }
+
+ /* Fill the sar_limits structure with the decoded data */
+ for (int i = 0; i < NUM_SAR_LIMITS; i++)
+ memcpy(sar_limits->sar_limit[i],
+ &bin_buffer[BYTES_PER_SAR_LIMIT * i],
+ BYTES_PER_SAR_LIMIT);
+ return 0;
+}