summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDuncan Laurie <dlaurie@chromium.org>2015-12-01 19:14:09 -0800
committerMartin Roth <martinroth@google.com>2016-02-04 17:21:04 +0100
commite2cea4f4582dad7f202a3f6d4fc884b01ec1d52d (patch)
treedf4f4315bc15d4c7ca54b4e712bdce5c16e15774 /src
parenteb31685bbba0b58aea0cd6900ed59eae76c80ad4 (diff)
google/chromeec: Add temporary storage interface
Add support functions for the Chrome EC temporary storage interface. BUG=chrome-os-partner:46049 BRANCH=none TEST=tested on glados with modified coreboot Change-Id: Id2bc46df9cb2d82b15e3309e78d07407a622b6f0 Signed-off-by: Patrick Georgi <pgeorgi@chromium.org> Original-Commit-Id: a7e6f693666b162e11eb0611715f10a8f465ad88 Original-Change-Id: Ieefabfc5bcb9d8a5064f0da967c46d0f377ca320 Original-Signed-off-by: Duncan Laurie <dlaurie@chromium.org> Original-Reviewed-on: https://chromium-review.googlesource.com/315217 Original-Commit-Ready: Aaron Durbin <adurbin@chromium.org> Original-Tested-by: Aaron Durbin <adurbin@chromium.org> Original-Reviewed-by: Aaron Durbin <adurbin@chromium.org> Reviewed-on: https://review.coreboot.org/13572 Tested-by: build bot (Jenkins) Reviewed-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
Diffstat (limited to 'src')
-rw-r--r--src/ec/google/chromeec/Makefile.inc8
-rw-r--r--src/ec/google/chromeec/ec.c21
-rw-r--r--src/ec/google/chromeec/ec.h8
-rw-r--r--src/ec/google/chromeec/vstore.c108
4 files changed, 141 insertions, 4 deletions
diff --git a/src/ec/google/chromeec/Makefile.inc b/src/ec/google/chromeec/Makefile.inc
index 89d64ca9ca..59758ca87c 100644
--- a/src/ec/google/chromeec/Makefile.inc
+++ b/src/ec/google/chromeec/Makefile.inc
@@ -1,21 +1,21 @@
ifeq ($(CONFIG_EC_GOOGLE_CHROMEEC),y)
-ramstage-y += ec.c crosec_proto.c
+ramstage-y += ec.c crosec_proto.c vstore.c
ramstage-$(CONFIG_EC_GOOGLE_CHROMEEC_I2C) += ec_i2c.c
ramstage-$(CONFIG_EC_GOOGLE_CHROMEEC_LPC) += ec_lpc.c
ramstage-$(CONFIG_EC_GOOGLE_CHROMEEC_MEC) += ec_mec.c
ramstage-$(CONFIG_EC_GOOGLE_CHROMEEC_SPI) += ec_spi.c
-smm-y += ec.c crosec_proto.c
+smm-y += ec.c crosec_proto.c vstore.c
smm-$(CONFIG_EC_GOOGLE_CHROMEEC_I2C) += ec_i2c.c
smm-$(CONFIG_EC_GOOGLE_CHROMEEC_LPC) += ec_lpc.c
smm-$(CONFIG_EC_GOOGLE_CHROMEEC_MEC) += ec_mec.c
smm-$(CONFIG_EC_GOOGLE_CHROMEEC_SPI) += ec_spi.c
-romstage-y += ec.c crosec_proto.c
+romstage-y += ec.c crosec_proto.c vstore.c
romstage-$(CONFIG_EC_GOOGLE_CHROMEEC_I2C) += ec_i2c.c
romstage-$(CONFIG_EC_GOOGLE_CHROMEEC_LPC) += ec_lpc.c
romstage-$(CONFIG_EC_GOOGLE_CHROMEEC_MEC) += ec_mec.c
romstage-$(CONFIG_EC_GOOGLE_CHROMEEC_SPI) += ec_spi.c
-verstage-y += ec.c crosec_proto.c
+verstage-y += ec.c crosec_proto.c vstore.c
verstage-$(CONFIG_EC_GOOGLE_CHROMEEC_I2C) += ec_i2c.c
verstage-$(CONFIG_EC_GOOGLE_CHROMEEC_LPC) += ec_lpc.c
verstage-$(CONFIG_EC_GOOGLE_CHROMEEC_MEC) += ec_mec.c
diff --git a/src/ec/google/chromeec/ec.c b/src/ec/google/chromeec/ec.c
index 5db387009e..87ab13acec 100644
--- a/src/ec/google/chromeec/ec.c
+++ b/src/ec/google/chromeec/ec.c
@@ -121,6 +121,27 @@ int google_chromeec_clear_events_b(u32 mask)
EC_CMD_HOST_EVENT_CLEAR_B, mask);
}
+int google_chromeec_check_feature(int feature)
+{
+ struct chromeec_command cmd;
+ struct ec_response_get_features r;
+
+ cmd.cmd_code = EC_CMD_GET_FEATURES;
+ cmd.cmd_version = 0;
+ cmd.cmd_size_in = 0;
+ cmd.cmd_data_out = &r;
+ cmd.cmd_size_out = sizeof(r);
+ cmd.cmd_dev_index = 0;
+
+ if (google_chromeec_command(&cmd) != 0)
+ return -1;
+
+ if (feature >= 8 * sizeof(r.flags))
+ return -1;
+
+ return r.flags[feature / 32] & EC_FEATURE_MASK_0(feature);
+}
+
#ifndef __SMM__
#ifdef __PRE_RAM__
void google_chromeec_check_ec_image(int expected_type)
diff --git a/src/ec/google/chromeec/ec.h b/src/ec/google/chromeec/ec.h
index 6693b3c6d1..7f52362f2d 100644
--- a/src/ec/google/chromeec/ec.h
+++ b/src/ec/google/chromeec/ec.h
@@ -19,6 +19,7 @@
#define _EC_GOOGLE_CHROMEEC_EC_H
#include <stddef.h>
#include <stdint.h>
+#include "ec_commands.h"
#ifndef __PRE_RAM__
int google_chromeec_i2c_xfer(uint8_t chip, uint8_t addr, int alen,
@@ -41,6 +42,7 @@ void google_chromeec_check_ec_image(int expected_type);
void google_chromeec_check_pd_image(int expected_type);
#endif
+int google_chromeec_check_feature(int feature);
uint8_t google_chromeec_calc_checksum(const uint8_t *data, int size);
u16 google_chromeec_get_board_version(void);
u32 google_chromeec_get_events_b(void);
@@ -51,6 +53,12 @@ void google_chromeec_log_events(u32 mask);
int google_chromeec_vbnv_context(int is_read, uint8_t *data, int len);
uint8_t google_chromeec_get_switches(void);
+/* Temporary secure storage commands */
+int google_chromeec_vstore_supported(void);
+int google_chromeec_vstore_info(uint32_t *locked);
+int google_chromeec_vstore_read(int slot, uint8_t *data);
+int google_chromeec_vstore_write(int slot, uint8_t *data, size_t size);
+
/* For MEC, access ranges 0x800 thru 0x9ff using EMI interface instead of LPC */
#define MEC_EMI_RANGE_START EC_HOST_CMD_REGION0
#define MEC_EMI_RANGE_END (EC_LPC_ADDR_MEMMAP + EC_MEMMAP_SIZE)
diff --git a/src/ec/google/chromeec/vstore.c b/src/ec/google/chromeec/vstore.c
new file mode 100644
index 0000000000..fd0a7e7366
--- /dev/null
+++ b/src/ec/google/chromeec/vstore.c
@@ -0,0 +1,108 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * Copyright (C) 2015 Google Inc.
+ *
+ * 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 <stdint.h>
+#include <string.h>
+#include <stdlib.h>
+#include "ec.h"
+#include "ec_commands.h"
+
+/*
+ * google_chromeec_vstore_supported - Check if vstore is supported
+ */
+int google_chromeec_vstore_supported(void)
+{
+ return google_chromeec_check_feature(EC_FEATURE_VSTORE);
+}
+
+/*
+ * google_chromeec_vstore_info - Query EC for vstore information
+ *
+ * Returns the number of vstore slots supported by the EC, with the
+ * mask of locked slots saved into passed parameter if it is present.
+ */
+int google_chromeec_vstore_info(uint32_t *locked)
+{
+ struct ec_response_vstore_info info;
+ struct chromeec_command cmd = {
+ .cmd_code = EC_CMD_VSTORE_INFO,
+ .cmd_size_out = sizeof(info),
+ .cmd_data_out = &info,
+ };
+
+ if (google_chromeec_command(&cmd) != 0)
+ return 0;
+
+ if (locked)
+ *locked = info.slot_locked;
+ return info.slot_count;
+}
+
+/*
+ * google_chromeec_vstore_read - Read data from EC vstore slot
+ *
+ * @slot: vstore slot to read from
+ * @data: buffer to store read data, must be EC_VSTORE_SLOT_SIZE bytes
+ */
+int google_chromeec_vstore_read(int slot, uint8_t *data)
+{
+ struct ec_params_vstore_read req = {
+ .slot = slot,
+ };
+ struct chromeec_command cmd = {
+ .cmd_code = EC_CMD_VSTORE_READ,
+ .cmd_size_in = sizeof(req),
+ .cmd_data_in = &req,
+ .cmd_size_out = EC_VSTORE_SLOT_SIZE,
+ .cmd_data_out = data,
+ };
+
+ if (!data || req.slot >= EC_VSTORE_SLOT_MAX)
+ return -1;
+
+ return google_chromeec_command(&cmd);
+}
+
+/*
+ * google_chromeec_vstore_write - Save data into EC vstore slot
+ *
+ * @slot: vstore slot to write into
+ * @data: data to write
+ * @size: size of data in bytes
+ *
+ * Maximum size of data is EC_VSTORE_SLOT_SIZE. It is the callers
+ * responsibility to check the number of implemented slots by
+ * querying the vstore info.
+ */
+int google_chromeec_vstore_write(int slot, uint8_t *data, size_t size)
+{
+ struct ec_params_vstore_write req = {
+ .slot = slot,
+ };
+ struct chromeec_command cmd = {
+ .cmd_code = EC_CMD_VSTORE_WRITE,
+ .cmd_size_in = sizeof(req),
+ .cmd_data_in = &req,
+ };
+
+ if (req.slot >= EC_VSTORE_SLOT_MAX || size > EC_VSTORE_SLOT_SIZE)
+ return -1;
+
+ memcpy(req.data, data, size);
+
+ return google_chromeec_command(&cmd);
+}