coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
vstore.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <stdint.h>
4 #include <string.h>
5 #include "ec.h"
6 #include "ec_commands.h"
7 
8 /*
9  * google_chromeec_vstore_supported - Check if vstore is supported
10  */
12 {
14 }
15 
16 /*
17  * google_chromeec_vstore_info - Query EC for vstore information
18  *
19  * Returns the number of vstore slots supported by the EC, with the
20  * mask of locked slots saved into passed parameter if it is present.
21  */
23 {
25  struct chromeec_command cmd = {
27  .cmd_size_out = sizeof(info),
28  .cmd_data_out = &info,
29  };
30 
31  if (google_chromeec_command(&cmd) != 0)
32  return 0;
33 
34  if (locked)
35  *locked = info.slot_locked;
36  return info.slot_count;
37 }
38 
39 /*
40  * google_chromeec_vstore_read - Read data from EC vstore slot
41  *
42  * @slot: vstore slot to read from
43  * @data: buffer to store read data, must be EC_VSTORE_SLOT_SIZE bytes
44  */
46 {
47  struct ec_params_vstore_read req = {
48  .slot = slot,
49  };
50  struct chromeec_command cmd = {
52  .cmd_size_in = sizeof(req),
53  .cmd_data_in = &req,
55  .cmd_data_out = data,
56  };
57 
58  if (!data || req.slot >= EC_VSTORE_SLOT_MAX)
59  return -1;
60 
61  return google_chromeec_command(&cmd);
62 }
63 
64 /*
65  * google_chromeec_vstore_write - Save data into EC vstore slot
66  *
67  * @slot: vstore slot to write into
68  * @data: data to write
69  * @size: size of data in bytes
70  *
71  * Maximum size of data is EC_VSTORE_SLOT_SIZE. It is the callers
72  * responsibility to check the number of implemented slots by
73  * querying the vstore info.
74  */
75 int google_chromeec_vstore_write(int slot, uint8_t *data, size_t size)
76 {
77  struct ec_params_vstore_write req = {
78  .slot = slot,
79  };
80  struct chromeec_command cmd = {
82  .cmd_size_in = sizeof(req),
83  .cmd_data_in = &req,
84  };
85 
86  if (req.slot >= EC_VSTORE_SLOT_MAX || size > EC_VSTORE_SLOT_SIZE)
87  return -1;
88 
89  memcpy(req.data, data, size);
90 
91  return google_chromeec_command(&cmd);
92 }
void * memcpy(void *dest, const void *src, size_t n)
Definition: memcpy.c:7
static struct smmstore_params_info info
Definition: ramstage.c:12
int google_chromeec_check_feature(int feature)
Definition: ec.c:443
int google_chromeec_command(struct chromeec_command *cec_command)
Send a command to a CrOS EC.
Definition: ec_i2c.c:176
#define EC_CMD_VSTORE_READ
Definition: ec_commands.h:3393
#define EC_CMD_VSTORE_WRITE
Definition: ec_commands.h:3406
@ EC_FEATURE_VSTORE
Definition: ec_commands.h:1453
#define EC_VSTORE_SLOT_SIZE
Definition: ec_commands.h:3374
#define EC_VSTORE_SLOT_MAX
Definition: ec_commands.h:3377
#define EC_CMD_VSTORE_INFO
Definition: ec_commands.h:3380
unsigned int uint32_t
Definition: stdint.h:14
unsigned char uint8_t
Definition: stdint.h:8
void * cmd_data_out
Definition: ec.h:152
const void * cmd_data_in
Definition: ec.h:151
uint16_t cmd_size_out
Definition: ec.h:154
uint16_t cmd_code
Definition: ec.h:149
uint8_t data[EC_VSTORE_SLOT_SIZE]
Definition: ec_commands.h:3410
int google_chromeec_vstore_supported(void)
Definition: vstore.c:11
int google_chromeec_vstore_info(uint32_t *locked)
Definition: vstore.c:22
int google_chromeec_vstore_write(int slot, uint8_t *data, size_t size)
Definition: vstore.c:75
int google_chromeec_vstore_read(int slot, uint8_t *data)
Definition: vstore.c:45