summaryrefslogtreecommitdiff
path: root/drivers/misc/cros_ec.c
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2021-01-16 14:52:31 -0700
committerSimon Glass <sjg@chromium.org>2021-01-30 14:25:41 -0700
commit10f746591fba16a48f0e3d14641be09f01982807 (patch)
treec311e9e3063e1ca319a9952524ccbc3043c72ac3 /drivers/misc/cros_ec.c
parentd9ffaef6fe25e7a29e63911fe1af5d18c9d77a45 (diff)
cros_ec: Add vstore support
The EC can store small amounts of data for the benefit of the verified boot process. Since the EC is seldom reset, this can allow the AP to store data that survives a reboot or a suspend/resume cycle. Add support for this. Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'drivers/misc/cros_ec.c')
-rw-r--r--drivers/misc/cros_ec.c71
1 files changed, 71 insertions, 0 deletions
diff --git a/drivers/misc/cros_ec.c b/drivers/misc/cros_ec.c
index c22bb4b5b5..ebfa7c41c2 100644
--- a/drivers/misc/cros_ec.c
+++ b/drivers/misc/cros_ec.c
@@ -1557,6 +1557,77 @@ int cros_ec_set_lid_shutdown_mask(struct udevice *dev, int enable)
return 0;
}
+int cros_ec_vstore_supported(struct udevice *dev)
+{
+ return cros_ec_check_feature(dev, EC_FEATURE_VSTORE);
+}
+
+int cros_ec_vstore_info(struct udevice *dev, u32 *lockedp)
+{
+ struct ec_response_vstore_info *resp;
+
+ if (ec_command_inptr(dev, EC_CMD_VSTORE_INFO, 0, NULL, 0,
+ (uint8_t **)&resp, sizeof(*resp)) != sizeof(*resp))
+ return -EIO;
+
+ if (lockedp)
+ *lockedp = resp->slot_locked;
+
+ return resp->slot_count;
+}
+
+/*
+ * cros_ec_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 cros_ec_vstore_read(struct udevice *dev, int slot, uint8_t *data)
+{
+ struct ec_params_vstore_read req;
+ struct ec_response_vstore_read *resp;
+
+ req.slot = slot;
+ if (ec_command_inptr(dev, EC_CMD_VSTORE_READ, 0, &req, sizeof(req),
+ (uint8_t **)&resp, sizeof(*resp)) != sizeof(*resp))
+ return -EIO;
+
+ if (!data || req.slot >= EC_VSTORE_SLOT_MAX)
+ return -EINVAL;
+
+ memcpy(data, resp->data, sizeof(resp->data));
+
+ return 0;
+}
+
+/*
+ * cros_ec_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 cros_ec_vstore_write(struct udevice *dev, int slot, const uint8_t *data,
+ size_t size)
+{
+ struct ec_params_vstore_write req;
+
+ if (slot >= EC_VSTORE_SLOT_MAX || size > EC_VSTORE_SLOT_SIZE)
+ return -EINVAL;
+
+ req.slot = slot;
+ memcpy(req.data, data, size);
+
+ if (ec_command(dev, EC_CMD_VSTORE_WRITE, 0, &req, sizeof(req), NULL, 0))
+ return -EIO;
+
+ return 0;
+}
+
int cros_ec_get_switches(struct udevice *dev)
{
struct dm_cros_ec_ops *ops;