Angel Pons | 32859fc | 2020-04-02 23:48:27 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Patrick Georgi | 9360fea | 2018-03-14 21:11:21 +0100 | [diff] [blame] | 2 | |
| 3 | #ifndef _SMMSTORE_H_ |
| 4 | #define _SMMSTORE_H_ |
| 5 | |
| 6 | #include <stddef.h> |
| 7 | #include <stdint.h> |
| 8 | |
Patrick Georgi | 9360fea | 2018-03-14 21:11:21 +0100 | [diff] [blame] | 9 | #define SMMSTORE_RET_SUCCESS 0 |
| 10 | #define SMMSTORE_RET_FAILURE 1 |
| 11 | #define SMMSTORE_RET_UNSUPPORTED 2 |
| 12 | |
Patrick Rudolph | bc744f5 | 2020-04-17 16:16:49 +0200 | [diff] [blame] | 13 | /* Version 1 */ |
Patrick Georgi | 9360fea | 2018-03-14 21:11:21 +0100 | [diff] [blame] | 14 | #define SMMSTORE_CMD_CLEAR 1 |
| 15 | #define SMMSTORE_CMD_READ 2 |
| 16 | #define SMMSTORE_CMD_APPEND 3 |
| 17 | |
Patrick Rudolph | bc744f5 | 2020-04-17 16:16:49 +0200 | [diff] [blame] | 18 | /* 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 Georgi | 9360fea | 2018-03-14 21:11:21 +0100 | [diff] [blame] | 25 | struct smmstore_params_read { |
| 26 | void *buf; |
| 27 | ssize_t bufsize; |
| 28 | }; |
| 29 | |
| 30 | struct smmstore_params_append { |
| 31 | void *key; |
| 32 | size_t keysize; |
| 33 | void *val; |
| 34 | size_t valsize; |
| 35 | }; |
| 36 | |
Patrick Rudolph | bc744f5 | 2020-04-17 16:16:49 +0200 | [diff] [blame] | 37 | /* 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 | */ |
| 49 | struct 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. |
| 56 | * For EDK2 this should be at least two blocks with 64 KiB each. |
| 57 | * The mmap_addr is set the memory mapped physical address of the SMMSTORE. |
| 58 | */ |
| 59 | struct 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 | */ |
| 73 | struct 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 | */ |
| 86 | struct 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 | */ |
| 97 | struct smmstore_params_raw_clear { |
| 98 | uint32_t block_id; |
| 99 | } __packed; |
| 100 | |
| 101 | |
| 102 | /* SMM handler */ |
Patrick Georgi | 9360fea | 2018-03-14 21:11:21 +0100 | [diff] [blame] | 103 | uint32_t smmstore_exec(uint8_t command, void *param); |
| 104 | |
Patrick Rudolph | bc744f5 | 2020-04-17 16:16:49 +0200 | [diff] [blame] | 105 | /* Implementation of Version 1 */ |
Patrick Georgi | 9360fea | 2018-03-14 21:11:21 +0100 | [diff] [blame] | 106 | int smmstore_read_region(void *buf, ssize_t *bufsize); |
Patrick Rudolph | bc744f5 | 2020-04-17 16:16:49 +0200 | [diff] [blame] | 107 | int smmstore_append_data(void *key, uint32_t key_sz, void *value, uint32_t value_sz); |
Patrick Georgi | 9360fea | 2018-03-14 21:11:21 +0100 | [diff] [blame] | 108 | int smmstore_clear_region(void); |
Patrick Rudolph | bc744f5 | 2020-04-17 16:16:49 +0200 | [diff] [blame] | 109 | |
| 110 | /* Implementation of Version 2 */ |
| 111 | int smmstore_init(void *buf, size_t len); |
| 112 | int smmstore_rawread_region(uint32_t block_id, uint32_t offset, uint32_t bufsize); |
| 113 | int smmstore_rawwrite_region(uint32_t block_id, uint32_t offset, uint32_t bufsize); |
| 114 | int smmstore_rawclear_region(uint32_t block_id); |
| 115 | #if ENV_RAMSTAGE |
| 116 | int smmstore_get_info(struct smmstore_params_info *info); |
| 117 | #endif |
| 118 | |
| 119 | /* Advertise SMMSTORE v2 support */ |
| 120 | struct lb_header; |
| 121 | void lb_smmstorev2(struct lb_header *header); |
| 122 | |
Patrick Georgi | 9360fea | 2018-03-14 21:11:21 +0100 | [diff] [blame] | 123 | #endif |