blob: d3940abc3f2fdc6115fcb900effc67efc8c9c75a [file] [log] [blame]
Angel Pons32859fc2020-04-02 23:48:27 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Patrick Georgi9360fea2018-03-14 21:11:21 +01002
3#ifndef _SMMSTORE_H_
4#define _SMMSTORE_H_
5
6#include <stddef.h>
7#include <stdint.h>
8
Patrick Georgi9360fea2018-03-14 21:11:21 +01009#define SMMSTORE_RET_SUCCESS 0
10#define SMMSTORE_RET_FAILURE 1
11#define SMMSTORE_RET_UNSUPPORTED 2
12
Patrick Rudolphbc744f52020-04-17 16:16:49 +020013/* Version 1 */
Patrick Georgi9360fea2018-03-14 21:11:21 +010014#define SMMSTORE_CMD_CLEAR 1
15#define SMMSTORE_CMD_READ 2
16#define SMMSTORE_CMD_APPEND 3
17
Patrick Rudolphbc744f52020-04-17 16:16:49 +020018/* Version 2 */
19#define SMMSTORE_CMD_INIT 4
20#define SMMSTORE_CMD_RAW_READ 5
21#define SMMSTORE_CMD_RAW_WRITE 6
22#define SMMSTORE_CMD_RAW_CLEAR 7
23
24/* Version 1 */
Patrick Georgi9360fea2018-03-14 21:11:21 +010025struct smmstore_params_read {
26 void *buf;
27 ssize_t bufsize;
28};
29
30struct smmstore_params_append {
31 void *key;
32 size_t keysize;
33 void *val;
34 size_t valsize;
35};
36
Patrick Rudolphbc744f52020-04-17 16:16:49 +020037/* Version 2 */
38/*
39 * The Version 2 protocol separates the SMMSTORE into 64KiB blocks, each
40 * of which can be read/written/cleared in an independent manner. The
41 * data format isn't specified. See documentation page for more details.
42 */
43
44#define SMM_BLOCK_SIZE (64 * KiB)
45
46/*
47 * Sets the communication buffer to use for read and write operations.
48 */
49struct smmstore_params_init {
50 uint32_t com_buffer;
51 uint32_t com_buffer_size;
52} __packed;
53
54/*
55 * Returns the number of blocks the SMMSTORE supports and their size.
Sean Rhodes38c99b52022-07-13 10:11:44 +010056 * For edk2 this should be at least two blocks with 64 KiB each.
Patrick Rudolphbc744f52020-04-17 16:16:49 +020057 * The mmap_addr is set the memory mapped physical address of the SMMSTORE.
58 */
59struct smmstore_params_info {
60 uint32_t num_blocks;
61 uint32_t block_size;
62 uint32_t mmap_addr;
63} __packed;
64
65/*
66 * Reads a chunk of raw data with size @bufsize from the block specified by
67 * @block_id starting at @bufoffset.
68 * The read data is placed in memory pointed to by @buf.
69 *
70 * @block_id must be less than num_blocks
71 * @bufoffset + @bufsize must be less than block_size
72 */
73struct smmstore_params_raw_write {
74 uint32_t bufsize;
75 uint32_t bufoffset;
76 uint32_t block_id;
77} __packed;
78
79/*
80 * Writes a chunk of raw data with size @bufsize to the block specified by
81 * @block_id starting at @bufoffset.
82 *
83 * @block_id must be less than num_blocks
84 * @bufoffset + @bufsize must be less than block_size
85 */
86struct smmstore_params_raw_read {
87 uint32_t bufsize;
88 uint32_t bufoffset;
89 uint32_t block_id;
90} __packed;
91
92/*
93 * Erases the specified block.
94 *
95 * @block_id must be less than num_blocks
96 */
97struct smmstore_params_raw_clear {
98 uint32_t block_id;
99} __packed;
100
101
102/* SMM handler */
Patrick Georgi9360fea2018-03-14 21:11:21 +0100103uint32_t smmstore_exec(uint8_t command, void *param);
104
Patrick Rudolphbc744f52020-04-17 16:16:49 +0200105/* Implementation of Version 1 */
Patrick Georgi9360fea2018-03-14 21:11:21 +0100106int smmstore_read_region(void *buf, ssize_t *bufsize);
Patrick Rudolphbc744f52020-04-17 16:16:49 +0200107int smmstore_append_data(void *key, uint32_t key_sz, void *value, uint32_t value_sz);
Patrick Georgi9360fea2018-03-14 21:11:21 +0100108int smmstore_clear_region(void);
Patrick Rudolphbc744f52020-04-17 16:16:49 +0200109
110/* Implementation of Version 2 */
111int smmstore_init(void *buf, size_t len);
112int smmstore_rawread_region(uint32_t block_id, uint32_t offset, uint32_t bufsize);
113int smmstore_rawwrite_region(uint32_t block_id, uint32_t offset, uint32_t bufsize);
114int smmstore_rawclear_region(uint32_t block_id);
115#if ENV_RAMSTAGE
116int smmstore_get_info(struct smmstore_params_info *info);
117#endif
Patrick Rudolph4e00f152022-02-16 07:51:36 +0100118struct region_device;
119int smmstore_lookup_region(struct region_device *rstore);
Patrick Rudolphbc744f52020-04-17 16:16:49 +0200120
121/* Advertise SMMSTORE v2 support */
122struct lb_header;
123void lb_smmstorev2(struct lb_header *header);
124
Patrick Georgi9360fea2018-03-14 21:11:21 +0100125#endif