summaryrefslogtreecommitdiff
path: root/src/drivers/vpd/vpd_cbmem.c
diff options
context:
space:
mode:
authorJonathan Zhang <jonzhang@fb.com>2019-07-16 14:37:23 -0700
committerPatrick Georgi <pgeorgi@google.com>2019-09-02 06:38:29 +0000
commitb5392f930d601c12db52d1f6428e1866fcfdcf86 (patch)
treeb4edc53430c85ac7050dfb7890039268feaff025 /src/drivers/vpd/vpd_cbmem.c
parent4d9d964276d7030f36b36df4b6ba6d1f48a6a260 (diff)
downloadcoreboot-b5392f930d601c12db52d1f6428e1866fcfdcf86.tar.xz
drivers/vpd: add framework to search VPD in romstage
Summary: Added a framework to search VPD in romstage before memory is avilable. vpd_cbmem.c and vpd_premem.c are added for code specific for premem environment and for environment that cbmem can be used. Since global variable is forbidden in romstage. A CAR_GLOBAL variable is defined in vpd.c. This variable holds VPD binary blobs' base address and size from memory mapped flash. The overall flow is: * The CAR variable g_vpd_blob is initialized if it was not, either at romstage (before FSP-M execution in case of FSP UPD customization), or at ramstage. * At ramstage, during CBMEM_INIT, the VPD binary blob contents are copied into CBMEM. * At vpd_find() which may be called at romstage or at ramstage, it sets storage for a local struct vpd_blob variable. * The variable gets contents duplicated from g_vpd_blob, if vpd_find() is called at romstage. * The variable gets contents obtained from CBMEM, if vpd_find() is called at ramstage. Added a call vpd_get_bool(). Given a key/value pair in VPD binary blob, and name of a bool type variable, set the variable value if there is a match. Several checks are in place: * The key/value length needs to be correct. * The key name needs to match. * THe value is either '1' or '0'. Test Plan: * Build an OCP MonoLake coreboot image, flash and run. Tags: Signed-off-by: Jonathan Zhang <jonzhang@fb.com> Change-Id: Iebdba59419a555147fc40391cf17cc6879d9e1b2 Reviewed-on: https://review.coreboot.org/c/coreboot/+/34634 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Hung-Te Lin <hungte@chromium.org>
Diffstat (limited to 'src/drivers/vpd/vpd_cbmem.c')
-rw-r--r--src/drivers/vpd/vpd_cbmem.c86
1 files changed, 86 insertions, 0 deletions
diff --git a/src/drivers/vpd/vpd_cbmem.c b/src/drivers/vpd/vpd_cbmem.c
new file mode 100644
index 0000000000..5b685069aa
--- /dev/null
+++ b/src/drivers/vpd/vpd_cbmem.c
@@ -0,0 +1,86 @@
+/*
+ * Copyright (c) 2014 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include <console/console.h>
+#include <cbmem.h>
+#include <fmap.h>
+#include <stdlib.h>
+#include <string.h>
+#include <timestamp.h>
+
+#include "vpd_tables.h"
+#include "vpd.h"
+
+/* Currently we only support Google VPD 2.0, which has a fixed offset. */
+enum {
+ CROSVPD_CBMEM_MAGIC = 0x43524f53,
+ CROSVPD_CBMEM_VERSION = 0x0001,
+};
+
+struct vpd_cbmem {
+ uint32_t magic;
+ uint32_t version;
+ uint32_t ro_size;
+ uint32_t rw_size;
+ uint8_t blob[0];
+ /* The blob contains both RO and RW data. It starts with RO (0 ..
+ * ro_size) and then RW (ro_size .. ro_size+rw_size).
+ */
+};
+
+static void cbmem_add_cros_vpd(int is_recovery)
+{
+ struct vpd_cbmem *cbmem;
+ const struct vpd_blob *blob;
+
+ timestamp_add_now(TS_START_COPYVPD);
+
+ blob = vpd_load_blob();
+
+ /* Return if no VPD at all */
+ if (blob->ro_size == 0 && blob->rw_size == 0)
+ return;
+
+ cbmem = cbmem_add(CBMEM_ID_VPD, sizeof(*cbmem) + blob->ro_size +
+ blob->rw_size);
+ if (!cbmem) {
+ printk(BIOS_ERR, "%s: Failed to allocate CBMEM (%u+%u).\n",
+ __func__, blob->ro_size, blob->rw_size);
+ return;
+ }
+
+ cbmem->magic = CROSVPD_CBMEM_MAGIC;
+ cbmem->version = CROSVPD_CBMEM_VERSION;
+ cbmem->ro_size = blob->ro_size;
+ cbmem->rw_size = blob->rw_size;
+
+ if (blob->ro_size) {
+ memcpy(cbmem->blob, blob->ro_base, blob->ro_size);
+ timestamp_add_now(TS_END_COPYVPD_RO);
+ }
+
+ if (blob->rw_size) {
+ memcpy(cbmem->blob + blob->ro_size, blob->rw_base,
+ blob->rw_size);
+ timestamp_add_now(TS_END_COPYVPD_RW);
+ }
+}
+
+void vpd_get_buffers(struct vpd_blob *blob)
+{
+ const struct vpd_cbmem *vpd;
+
+ vpd = cbmem_find(CBMEM_ID_VPD);
+ if (!vpd || !vpd->ro_size)
+ return;
+
+ blob->ro_base = (void *)vpd->blob;
+ blob->ro_size = vpd->ro_size;
+ blob->rw_base = (void *)vpd->blob + vpd->ro_size;
+ blob->rw_size = vpd->rw_size;
+}
+
+RAMSTAGE_CBMEM_INIT_HOOK(cbmem_add_cros_vpd)