xref: /openbmc/qemu/include/hw/nvram/fw_cfg.h (revision 9c4a5c55f5c6c63c24c29e5a3b57ddbc1e550303)
1 #ifndef FW_CFG_H
2 #define FW_CFG_H
3 
4 #ifndef NO_QEMU_PROTOS
5 #include <stdint.h>
6 #include <stddef.h>
7 
8 #include "exec/hwaddr.h"
9 #include "qemu/typedefs.h"
10 #endif
11 
12 #define FW_CFG_SIGNATURE        0x00
13 #define FW_CFG_ID               0x01
14 #define FW_CFG_UUID             0x02
15 #define FW_CFG_RAM_SIZE         0x03
16 #define FW_CFG_NOGRAPHIC        0x04
17 #define FW_CFG_NB_CPUS          0x05
18 #define FW_CFG_MACHINE_ID       0x06
19 #define FW_CFG_KERNEL_ADDR      0x07
20 #define FW_CFG_KERNEL_SIZE      0x08
21 #define FW_CFG_KERNEL_CMDLINE   0x09
22 #define FW_CFG_INITRD_ADDR      0x0a
23 #define FW_CFG_INITRD_SIZE      0x0b
24 #define FW_CFG_BOOT_DEVICE      0x0c
25 #define FW_CFG_NUMA             0x0d
26 #define FW_CFG_BOOT_MENU        0x0e
27 #define FW_CFG_MAX_CPUS         0x0f
28 #define FW_CFG_KERNEL_ENTRY     0x10
29 #define FW_CFG_KERNEL_DATA      0x11
30 #define FW_CFG_INITRD_DATA      0x12
31 #define FW_CFG_CMDLINE_ADDR     0x13
32 #define FW_CFG_CMDLINE_SIZE     0x14
33 #define FW_CFG_CMDLINE_DATA     0x15
34 #define FW_CFG_SETUP_ADDR       0x16
35 #define FW_CFG_SETUP_SIZE       0x17
36 #define FW_CFG_SETUP_DATA       0x18
37 #define FW_CFG_FILE_DIR         0x19
38 
39 #define FW_CFG_FILE_FIRST       0x20
40 #define FW_CFG_FILE_SLOTS       0x10
41 #define FW_CFG_MAX_ENTRY        (FW_CFG_FILE_FIRST+FW_CFG_FILE_SLOTS)
42 
43 #define FW_CFG_WRITE_CHANNEL    0x4000
44 #define FW_CFG_ARCH_LOCAL       0x8000
45 #define FW_CFG_ENTRY_MASK       ~(FW_CFG_WRITE_CHANNEL | FW_CFG_ARCH_LOCAL)
46 
47 #define FW_CFG_INVALID          0xffff
48 
49 #define FW_CFG_MAX_FILE_PATH    56
50 
51 #ifndef NO_QEMU_PROTOS
52 typedef struct FWCfgFile {
53     uint32_t  size;        /* file size */
54     uint16_t  select;      /* write this to 0x510 to read it */
55     uint16_t  reserved;
56     char      name[FW_CFG_MAX_FILE_PATH];
57 } FWCfgFile;
58 
59 typedef struct FWCfgFiles {
60     uint32_t  count;
61     FWCfgFile f[];
62 } FWCfgFiles;
63 
64 /* Control as first field allows for different structures selected by this
65  * field, which might be useful in the future
66  */
67 typedef struct FWCfgDmaAccess {
68     uint32_t control;
69     uint32_t length;
70     uint64_t address;
71 } QEMU_PACKED FWCfgDmaAccess;
72 
73 typedef void (*FWCfgCallback)(void *opaque, uint8_t *data);
74 typedef void (*FWCfgReadCallback)(void *opaque, uint32_t offset);
75 
76 /**
77  * fw_cfg_add_bytes:
78  * @s: fw_cfg device being modified
79  * @key: selector key value for new fw_cfg item
80  * @data: pointer to start of item data
81  * @len: size of item data
82  *
83  * Add a new fw_cfg item, available by selecting the given key, as a raw
84  * "blob" of the given size. The data referenced by the starting pointer
85  * is only linked, NOT copied, into the data structure of the fw_cfg device.
86  */
87 void fw_cfg_add_bytes(FWCfgState *s, uint16_t key, void *data, size_t len);
88 
89 /**
90  * fw_cfg_add_string:
91  * @s: fw_cfg device being modified
92  * @key: selector key value for new fw_cfg item
93  * @value: NUL-terminated ascii string
94  *
95  * Add a new fw_cfg item, available by selecting the given key. The item
96  * data will consist of a dynamically allocated copy of the provided string,
97  * including its NUL terminator.
98  */
99 void fw_cfg_add_string(FWCfgState *s, uint16_t key, const char *value);
100 
101 /**
102  * fw_cfg_add_i16:
103  * @s: fw_cfg device being modified
104  * @key: selector key value for new fw_cfg item
105  * @value: 16-bit integer
106  *
107  * Add a new fw_cfg item, available by selecting the given key. The item
108  * data will consist of a dynamically allocated copy of the given 16-bit
109  * value, converted to little-endian representation.
110  */
111 void fw_cfg_add_i16(FWCfgState *s, uint16_t key, uint16_t value);
112 
113 /**
114  * fw_cfg_modify_i16:
115  * @s: fw_cfg device being modified
116  * @key: selector key value for new fw_cfg item
117  * @value: 16-bit integer
118  *
119  * Replace the fw_cfg item available by selecting the given key. The new
120  * data will consist of a dynamically allocated copy of the given 16-bit
121  * value, converted to little-endian representation. The data being replaced,
122  * assumed to have been dynamically allocated during an earlier call to
123  * either fw_cfg_add_i16() or fw_cfg_modify_i16(), is freed before returning.
124  */
125 void fw_cfg_modify_i16(FWCfgState *s, uint16_t key, uint16_t value);
126 
127 /**
128  * fw_cfg_add_i32:
129  * @s: fw_cfg device being modified
130  * @key: selector key value for new fw_cfg item
131  * @value: 32-bit integer
132  *
133  * Add a new fw_cfg item, available by selecting the given key. The item
134  * data will consist of a dynamically allocated copy of the given 32-bit
135  * value, converted to little-endian representation.
136  */
137 void fw_cfg_add_i32(FWCfgState *s, uint16_t key, uint32_t value);
138 
139 /**
140  * fw_cfg_add_i64:
141  * @s: fw_cfg device being modified
142  * @key: selector key value for new fw_cfg item
143  * @value: 64-bit integer
144  *
145  * Add a new fw_cfg item, available by selecting the given key. The item
146  * data will consist of a dynamically allocated copy of the given 64-bit
147  * value, converted to little-endian representation.
148  */
149 void fw_cfg_add_i64(FWCfgState *s, uint16_t key, uint64_t value);
150 
151 /**
152  * fw_cfg_add_file:
153  * @s: fw_cfg device being modified
154  * @filename: name of new fw_cfg file item
155  * @data: pointer to start of item data
156  * @len: size of item data
157  *
158  * Add a new NAMED fw_cfg item as a raw "blob" of the given size. The data
159  * referenced by the starting pointer is only linked, NOT copied, into the
160  * data structure of the fw_cfg device.
161  * The next available (unused) selector key starting at FW_CFG_FILE_FIRST
162  * will be used; also, a new entry will be added to the file directory
163  * structure residing at key value FW_CFG_FILE_DIR, containing the item name,
164  * data size, and assigned selector key value.
165  */
166 void fw_cfg_add_file(FWCfgState *s, const char *filename, void *data,
167                      size_t len);
168 
169 /**
170  * fw_cfg_add_file_callback:
171  * @s: fw_cfg device being modified
172  * @filename: name of new fw_cfg file item
173  * @callback: callback function
174  * @callback_opaque: argument to be passed into callback function
175  * @data: pointer to start of item data
176  * @len: size of item data
177  *
178  * Add a new NAMED fw_cfg item as a raw "blob" of the given size. The data
179  * referenced by the starting pointer is only linked, NOT copied, into the
180  * data structure of the fw_cfg device.
181  * The next available (unused) selector key starting at FW_CFG_FILE_FIRST
182  * will be used; also, a new entry will be added to the file directory
183  * structure residing at key value FW_CFG_FILE_DIR, containing the item name,
184  * data size, and assigned selector key value.
185  * Additionally, set a callback function (and argument) to be called each
186  * time a byte is read by the guest from this particular item, or, in the
187  * case of DMA, each time a read or skip request overlaps with the valid
188  * offset range of the item.
189  * NOTE: In addition to the opaque argument set here, the callback function
190  * takes the current data offset as an additional argument, allowing it the
191  * option of only acting upon specific offset values (e.g., 0, before the
192  * first data byte of the selected item is returned to the guest).
193  */
194 void fw_cfg_add_file_callback(FWCfgState *s, const char *filename,
195                               FWCfgReadCallback callback, void *callback_opaque,
196                               void *data, size_t len);
197 
198 /**
199  * fw_cfg_modify_file:
200  * @s: fw_cfg device being modified
201  * @filename: name of new fw_cfg file item
202  * @data: pointer to start of item data
203  * @len: size of item data
204  *
205  * Replace a NAMED fw_cfg item. If an existing item is found, its callback
206  * information will be cleared, and a pointer to its data will be returned
207  * to the caller, so that it may be freed if necessary. If an existing item
208  * is not found, this call defaults to fw_cfg_add_file(), and NULL is
209  * returned to the caller.
210  * In either case, the new item data is only linked, NOT copied, into the
211  * data structure of the fw_cfg device.
212  *
213  * Returns: pointer to old item's data, or NULL if old item does not exist.
214  */
215 void *fw_cfg_modify_file(FWCfgState *s, const char *filename, void *data,
216                          size_t len);
217 
218 FWCfgState *fw_cfg_init_io_dma(uint32_t iobase, uint32_t dma_iobase,
219                                 AddressSpace *dma_as);
220 FWCfgState *fw_cfg_init_io(uint32_t iobase);
221 FWCfgState *fw_cfg_init_mem(hwaddr ctl_addr, hwaddr data_addr);
222 FWCfgState *fw_cfg_init_mem_wide(hwaddr ctl_addr,
223                                  hwaddr data_addr, uint32_t data_width,
224                                  hwaddr dma_addr, AddressSpace *dma_as);
225 
226 FWCfgState *fw_cfg_find(void);
227 
228 #endif /* NO_QEMU_PROTOS */
229 
230 #endif
231