1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <console/console.h>
4 #include <commonlib/region.h>
5 #include <cpu/x86/smm.h>
11 * Check that the given range is legal.
14 * - not pointing into SMRAM
16 * returns 0 on success, -1 on failure
18 static int range_check(void *start
, size_t size
)
20 if (smm_points_to_smram(start
, size
))
26 static uint32_t smmstorev1_exec(uint8_t command
, void *param
)
28 uint32_t ret
= SMMSTORE_RET_FAILURE
;
31 case SMMSTORE_CMD_READ
: {
32 printk(BIOS_DEBUG
, "Reading from SMM store\n");
33 struct smmstore_params_read
*params
= param
;
35 if (range_check(params
, sizeof(*params
)) != 0)
38 if (range_check(params
->buf
, params
->bufsize
) != 0)
41 if (smmstore_read_region(params
->buf
, ¶ms
->bufsize
) == 0)
42 ret
= SMMSTORE_RET_SUCCESS
;
46 case SMMSTORE_CMD_APPEND
: {
47 printk(BIOS_DEBUG
, "Appending into SMM store\n");
48 struct smmstore_params_append
*params
= param
;
50 if (range_check(params
, sizeof(*params
)) != 0)
52 if (range_check(params
->key
, params
->keysize
) != 0)
54 if (range_check(params
->val
, params
->valsize
) != 0)
57 if (smmstore_append_data(params
->key
, params
->keysize
,
58 params
->val
, params
->valsize
) == 0)
59 ret
= SMMSTORE_RET_SUCCESS
;
63 case SMMSTORE_CMD_CLEAR
: {
64 if (smmstore_clear_region() == 0)
65 ret
= SMMSTORE_RET_SUCCESS
;
70 "Unknown SMM store v1 command: 0x%02x\n", command
);
71 ret
= SMMSTORE_RET_UNSUPPORTED
;
78 static uint32_t smmstorev2_exec(uint8_t command
, void *param
)
80 uint32_t ret
= SMMSTORE_RET_FAILURE
;
81 static bool initialized
= false;
86 smm_get_smmstore_com_buffer(&base
, &size
);
88 if (smmstore_init((void *)base
, size
))
89 return SMMSTORE_RET_FAILURE
;
94 case SMMSTORE_CMD_RAW_READ
: {
95 printk(BIOS_DEBUG
, "Raw read from SMM store, param = %p\n", param
);
96 struct smmstore_params_raw_read
*params
= param
;
98 if (range_check(params
, sizeof(*params
)) != 0)
101 if (smmstore_rawread_region(params
->block_id
, params
->bufoffset
,
102 params
->bufsize
) == 0)
103 ret
= SMMSTORE_RET_SUCCESS
;
106 case SMMSTORE_CMD_RAW_WRITE
: {
107 printk(BIOS_DEBUG
, "Raw write to SMM store, param = %p\n", param
);
108 struct smmstore_params_raw_write
*params
= param
;
110 if (range_check(params
, sizeof(*params
)) != 0)
113 if (smmstore_rawwrite_region(params
->block_id
, params
->bufoffset
,
114 params
->bufsize
) == 0)
115 ret
= SMMSTORE_RET_SUCCESS
;
118 case SMMSTORE_CMD_RAW_CLEAR
: {
119 printk(BIOS_DEBUG
, "Raw clear SMM store, param = %p\n", param
);
120 struct smmstore_params_raw_clear
*params
= param
;
122 if (range_check(params
, sizeof(*params
)) != 0)
125 if (smmstore_rawclear_region(params
->block_id
) == 0)
126 ret
= SMMSTORE_RET_SUCCESS
;
131 "Unknown SMM store v2 command: 0x%02x\n", command
);
132 ret
= SMMSTORE_RET_UNSUPPORTED
;
139 uint32_t smmstore_exec(uint8_t command
, void *param
)
141 if (command
!= SMMSTORE_CMD_CLEAR
&& !param
)
142 return SMMSTORE_RET_FAILURE
;
144 if (CONFIG(SMMSTORE_V2
))
145 return smmstorev2_exec(command
, param
);
147 return smmstorev1_exec(command
, param
);