drivers/uart: Replace 'unsigned long int' by 'unsigned long'
[coreboot2.git] / src / ec / google / chromeec / vstore.c
blob2a33a3fc91e7fc190f496f5ded0ae28700f6f185
1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <stdint.h>
4 #include <string.h>
5 #include "ec.h"
6 #include "ec_commands.h"
8 /*
9 * google_chromeec_vstore_supported - Check if vstore is supported
11 int google_chromeec_vstore_supported(void)
13 return google_chromeec_check_feature(EC_FEATURE_VSTORE);
17 * google_chromeec_vstore_info - Query EC for vstore information
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.
22 int google_chromeec_vstore_info(uint32_t *locked)
24 struct ec_response_vstore_info info;
25 struct chromeec_command cmd = {
26 .cmd_code = EC_CMD_VSTORE_INFO,
27 .cmd_size_out = sizeof(info),
28 .cmd_data_out = &info,
31 if (google_chromeec_command(&cmd) != 0)
32 return 0;
34 if (locked)
35 *locked = info.slot_locked;
36 return info.slot_count;
40 * google_chromeec_vstore_read - Read data from EC vstore slot
42 * @slot: vstore slot to read from
43 * @data: buffer to store read data, must be EC_VSTORE_SLOT_SIZE bytes
45 int google_chromeec_vstore_read(int slot, uint8_t *data)
47 struct ec_params_vstore_read req = {
48 .slot = slot,
50 struct chromeec_command cmd = {
51 .cmd_code = EC_CMD_VSTORE_READ,
52 .cmd_size_in = sizeof(req),
53 .cmd_data_in = &req,
54 .cmd_size_out = EC_VSTORE_SLOT_SIZE,
55 .cmd_data_out = data,
58 if (!data || req.slot >= EC_VSTORE_SLOT_MAX)
59 return -1;
61 return google_chromeec_command(&cmd);
65 * google_chromeec_vstore_write - Save data into EC vstore slot
67 * @slot: vstore slot to write into
68 * @data: data to write
69 * @size: size of data in bytes
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.
75 int google_chromeec_vstore_write(int slot, uint8_t *data, size_t size)
77 struct ec_params_vstore_write req = {
78 .slot = slot,
80 struct chromeec_command cmd = {
81 .cmd_code = EC_CMD_VSTORE_WRITE,
82 .cmd_size_in = sizeof(req),
83 .cmd_data_in = &req,
86 if (req.slot >= EC_VSTORE_SLOT_MAX || size > EC_VSTORE_SLOT_SIZE)
87 return -1;
89 memcpy(req.data, data, size);
91 return google_chromeec_command(&cmd);