1 /* SPDX-License-Identifier: GPL-2.0-only */
6 #include "ec_commands.h"
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)
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
= {
50 struct chromeec_command cmd
= {
51 .cmd_code
= EC_CMD_VSTORE_READ
,
52 .cmd_size_in
= sizeof(req
),
54 .cmd_size_out
= EC_VSTORE_SLOT_SIZE
,
58 if (!data
|| req
.slot
>= EC_VSTORE_SLOT_MAX
)
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
= {
80 struct chromeec_command cmd
= {
81 .cmd_code
= EC_CMD_VSTORE_WRITE
,
82 .cmd_size_in
= sizeof(req
),
86 if (req
.slot
>= EC_VSTORE_SLOT_MAX
|| size
> EC_VSTORE_SLOT_SIZE
)
89 memcpy(req
.data
, data
, size
);
91 return google_chromeec_command(&cmd
);