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