soc/intel/alderlake: Add ADL-P 4+4 with 28W TDP
[coreboot.git] / src / drivers / smmstore / smi.c
blob6ea447ffe6efc3c6cb026e214a2dae4b0383a8de
1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <console/console.h>
4 #include <commonlib/region.h>
5 #include <cpu/x86/smm.h>
6 #include <smmstore.h>
7 #include <stddef.h>
8 #include <stdint.h>
11 * Check that the given range is legal.
13 * Legal means:
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))
21 return -1;
23 return 0;
26 static uint32_t smmstorev1_exec(uint8_t command, void *param)
28 uint32_t ret = SMMSTORE_RET_FAILURE;
30 switch (command) {
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)
36 break;
38 if (range_check(params->buf, params->bufsize) != 0)
39 break;
41 if (smmstore_read_region(params->buf, &params->bufsize) == 0)
42 ret = SMMSTORE_RET_SUCCESS;
43 break;
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)
51 break;
52 if (range_check(params->key, params->keysize) != 0)
53 break;
54 if (range_check(params->val, params->valsize) != 0)
55 break;
57 if (smmstore_append_data(params->key, params->keysize,
58 params->val, params->valsize) == 0)
59 ret = SMMSTORE_RET_SUCCESS;
60 break;
63 case SMMSTORE_CMD_CLEAR: {
64 if (smmstore_clear_region() == 0)
65 ret = SMMSTORE_RET_SUCCESS;
66 break;
68 default:
69 printk(BIOS_DEBUG,
70 "Unknown SMM store v1 command: 0x%02x\n", command);
71 ret = SMMSTORE_RET_UNSUPPORTED;
72 break;
75 return ret;
78 static uint32_t smmstorev2_exec(uint8_t command, void *param)
80 uint32_t ret = SMMSTORE_RET_FAILURE;
82 switch (command) {
83 case SMMSTORE_CMD_INIT: {
84 printk(BIOS_DEBUG, "Init SMM store\n");
85 struct smmstore_params_init *params = param;
87 if (range_check(params, sizeof(*params)) != 0)
88 break;
90 void *buf = (void *)(uintptr_t)params->com_buffer;
92 if (range_check(buf, params->com_buffer_size) != 0)
93 break;
95 if (smmstore_init(buf, params->com_buffer_size) == 0)
96 ret = SMMSTORE_RET_SUCCESS;
97 break;
99 case SMMSTORE_CMD_RAW_READ: {
100 printk(BIOS_DEBUG, "Raw read from SMM store, param = %p\n", param);
101 struct smmstore_params_raw_read *params = param;
103 if (range_check(params, sizeof(*params)) != 0)
104 break;
106 if (smmstore_rawread_region(params->block_id, params->bufoffset,
107 params->bufsize) == 0)
108 ret = SMMSTORE_RET_SUCCESS;
109 break;
111 case SMMSTORE_CMD_RAW_WRITE: {
112 printk(BIOS_DEBUG, "Raw write to SMM store, param = %p\n", param);
113 struct smmstore_params_raw_write *params = param;
115 if (range_check(params, sizeof(*params)) != 0)
116 break;
118 if (smmstore_rawwrite_region(params->block_id, params->bufoffset,
119 params->bufsize) == 0)
120 ret = SMMSTORE_RET_SUCCESS;
121 break;
123 case SMMSTORE_CMD_RAW_CLEAR: {
124 printk(BIOS_DEBUG, "Raw clear SMM store, param = %p\n", param);
125 struct smmstore_params_raw_clear *params = param;
127 if (range_check(params, sizeof(*params)) != 0)
128 break;
130 if (smmstore_rawclear_region(params->block_id) == 0)
131 ret = SMMSTORE_RET_SUCCESS;
132 break;
134 default:
135 printk(BIOS_DEBUG,
136 "Unknown SMM store v2 command: 0x%02x\n", command);
137 ret = SMMSTORE_RET_UNSUPPORTED;
138 break;
141 return ret;
144 uint32_t smmstore_exec(uint8_t command, void *param)
146 if (command != SMMSTORE_CMD_CLEAR && !param)
147 return SMMSTORE_RET_FAILURE;
149 if (CONFIG(SMMSTORE_V2))
150 return smmstorev2_exec(command, param);
151 else
152 return smmstorev1_exec(command, param);