xref: /qemu/include/hw/nvram/fw_cfg.h (revision 9c4a5c55f5c6c63c24c29e5a3b57ddbc1e550303)
13cce6243Sblueswir1 #ifndef FW_CFG_H
23cce6243Sblueswir1 #define FW_CFG_H
33cce6243Sblueswir1 
41dfe5057SHu Tao #ifndef NO_QEMU_PROTOS
51dfe5057SHu Tao #include <stdint.h>
61dfe5057SHu Tao #include <stddef.h>
71dfe5057SHu Tao 
81dfe5057SHu Tao #include "exec/hwaddr.h"
945936c8bSMichael S. Tsirkin #include "qemu/typedefs.h"
101dfe5057SHu Tao #endif
111dfe5057SHu Tao 
123cce6243Sblueswir1 #define FW_CFG_SIGNATURE        0x00
133cce6243Sblueswir1 #define FW_CFG_ID               0x01
14084a197aSblueswir1 #define FW_CFG_UUID             0x02
15905fdcb5Sblueswir1 #define FW_CFG_RAM_SIZE         0x03
16905fdcb5Sblueswir1 #define FW_CFG_NOGRAPHIC        0x04
17905fdcb5Sblueswir1 #define FW_CFG_NB_CPUS          0x05
18905fdcb5Sblueswir1 #define FW_CFG_MACHINE_ID       0x06
197e12f656Sblueswir1 #define FW_CFG_KERNEL_ADDR      0x07
207e12f656Sblueswir1 #define FW_CFG_KERNEL_SIZE      0x08
217e12f656Sblueswir1 #define FW_CFG_KERNEL_CMDLINE   0x09
227e12f656Sblueswir1 #define FW_CFG_INITRD_ADDR      0x0a
237e12f656Sblueswir1 #define FW_CFG_INITRD_SIZE      0x0b
247e12f656Sblueswir1 #define FW_CFG_BOOT_DEVICE      0x0c
2511c2fd3eSaliguori #define FW_CFG_NUMA             0x0d
2695387491SJan Kiszka #define FW_CFG_BOOT_MENU        0x0e
276be68d7eSJes Sorensen #define FW_CFG_MAX_CPUS         0x0f
2877873196SAlexander Graf #define FW_CFG_KERNEL_ENTRY     0x10
2977873196SAlexander Graf #define FW_CFG_KERNEL_DATA      0x11
3077873196SAlexander Graf #define FW_CFG_INITRD_DATA      0x12
3157a46d05SAlexander Graf #define FW_CFG_CMDLINE_ADDR     0x13
3257a46d05SAlexander Graf #define FW_CFG_CMDLINE_SIZE     0x14
3357a46d05SAlexander Graf #define FW_CFG_CMDLINE_DATA     0x15
3457a46d05SAlexander Graf #define FW_CFG_SETUP_ADDR       0x16
3557a46d05SAlexander Graf #define FW_CFG_SETUP_SIZE       0x17
3657a46d05SAlexander Graf #define FW_CFG_SETUP_DATA       0x18
37abe147e0SGerd Hoffmann #define FW_CFG_FILE_DIR         0x19
38abe147e0SGerd Hoffmann 
39abe147e0SGerd Hoffmann #define FW_CFG_FILE_FIRST       0x20
40abe147e0SGerd Hoffmann #define FW_CFG_FILE_SLOTS       0x10
41abe147e0SGerd Hoffmann #define FW_CFG_MAX_ENTRY        (FW_CFG_FILE_FIRST+FW_CFG_FILE_SLOTS)
423cce6243Sblueswir1 
433cce6243Sblueswir1 #define FW_CFG_WRITE_CHANNEL    0x4000
443cce6243Sblueswir1 #define FW_CFG_ARCH_LOCAL       0x8000
453cce6243Sblueswir1 #define FW_CFG_ENTRY_MASK       ~(FW_CFG_WRITE_CHANNEL | FW_CFG_ARCH_LOCAL)
463cce6243Sblueswir1 
473cce6243Sblueswir1 #define FW_CFG_INVALID          0xffff
483cce6243Sblueswir1 
4935c12e60SMichael S. Tsirkin #define FW_CFG_MAX_FILE_PATH    56
5035c12e60SMichael S. Tsirkin 
513cce6243Sblueswir1 #ifndef NO_QEMU_PROTOS
52abe147e0SGerd Hoffmann typedef struct FWCfgFile {
53abe147e0SGerd Hoffmann     uint32_t  size;        /* file size */
54abe147e0SGerd Hoffmann     uint16_t  select;      /* write this to 0x510 to read it */
55abe147e0SGerd Hoffmann     uint16_t  reserved;
5635c12e60SMichael S. Tsirkin     char      name[FW_CFG_MAX_FILE_PATH];
57abe147e0SGerd Hoffmann } FWCfgFile;
58abe147e0SGerd Hoffmann 
59abe147e0SGerd Hoffmann typedef struct FWCfgFiles {
60abe147e0SGerd Hoffmann     uint32_t  count;
61abe147e0SGerd Hoffmann     FWCfgFile f[];
62abe147e0SGerd Hoffmann } FWCfgFiles;
63abe147e0SGerd Hoffmann 
64a4c0d1deSMarc Marí /* Control as first field allows for different structures selected by this
65a4c0d1deSMarc Marí  * field, which might be useful in the future
66a4c0d1deSMarc Marí  */
67a4c0d1deSMarc Marí typedef struct FWCfgDmaAccess {
68a4c0d1deSMarc Marí     uint32_t control;
69a4c0d1deSMarc Marí     uint32_t length;
70a4c0d1deSMarc Marí     uint64_t address;
71a4c0d1deSMarc Marí } QEMU_PACKED FWCfgDmaAccess;
72a4c0d1deSMarc Marí 
733cce6243Sblueswir1 typedef void (*FWCfgCallback)(void *opaque, uint8_t *data);
74d87072ceSMichael S. Tsirkin typedef void (*FWCfgReadCallback)(void *opaque, uint32_t offset);
753cce6243Sblueswir1 
76*9c4a5c55SGabriel L. Somlo /**
77*9c4a5c55SGabriel L. Somlo  * fw_cfg_add_bytes:
78*9c4a5c55SGabriel L. Somlo  * @s: fw_cfg device being modified
79*9c4a5c55SGabriel L. Somlo  * @key: selector key value for new fw_cfg item
80*9c4a5c55SGabriel L. Somlo  * @data: pointer to start of item data
81*9c4a5c55SGabriel L. Somlo  * @len: size of item data
82*9c4a5c55SGabriel L. Somlo  *
83*9c4a5c55SGabriel L. Somlo  * Add a new fw_cfg item, available by selecting the given key, as a raw
84*9c4a5c55SGabriel L. Somlo  * "blob" of the given size. The data referenced by the starting pointer
85*9c4a5c55SGabriel L. Somlo  * is only linked, NOT copied, into the data structure of the fw_cfg device.
86*9c4a5c55SGabriel L. Somlo  */
87089da572SMarkus Armbruster void fw_cfg_add_bytes(FWCfgState *s, uint16_t key, void *data, size_t len);
88*9c4a5c55SGabriel L. Somlo 
89*9c4a5c55SGabriel L. Somlo /**
90*9c4a5c55SGabriel L. Somlo  * fw_cfg_add_string:
91*9c4a5c55SGabriel L. Somlo  * @s: fw_cfg device being modified
92*9c4a5c55SGabriel L. Somlo  * @key: selector key value for new fw_cfg item
93*9c4a5c55SGabriel L. Somlo  * @value: NUL-terminated ascii string
94*9c4a5c55SGabriel L. Somlo  *
95*9c4a5c55SGabriel L. Somlo  * Add a new fw_cfg item, available by selecting the given key. The item
96*9c4a5c55SGabriel L. Somlo  * data will consist of a dynamically allocated copy of the provided string,
97*9c4a5c55SGabriel L. Somlo  * including its NUL terminator.
98*9c4a5c55SGabriel L. Somlo  */
9944687f75SMarkus Armbruster void fw_cfg_add_string(FWCfgState *s, uint16_t key, const char *value);
100*9c4a5c55SGabriel L. Somlo 
101*9c4a5c55SGabriel L. Somlo /**
102*9c4a5c55SGabriel L. Somlo  * fw_cfg_add_i16:
103*9c4a5c55SGabriel L. Somlo  * @s: fw_cfg device being modified
104*9c4a5c55SGabriel L. Somlo  * @key: selector key value for new fw_cfg item
105*9c4a5c55SGabriel L. Somlo  * @value: 16-bit integer
106*9c4a5c55SGabriel L. Somlo  *
107*9c4a5c55SGabriel L. Somlo  * Add a new fw_cfg item, available by selecting the given key. The item
108*9c4a5c55SGabriel L. Somlo  * data will consist of a dynamically allocated copy of the given 16-bit
109*9c4a5c55SGabriel L. Somlo  * value, converted to little-endian representation.
110*9c4a5c55SGabriel L. Somlo  */
1114cad3867SMarkus Armbruster void fw_cfg_add_i16(FWCfgState *s, uint16_t key, uint16_t value);
112*9c4a5c55SGabriel L. Somlo 
113*9c4a5c55SGabriel L. Somlo /**
114*9c4a5c55SGabriel L. Somlo  * fw_cfg_modify_i16:
115*9c4a5c55SGabriel L. Somlo  * @s: fw_cfg device being modified
116*9c4a5c55SGabriel L. Somlo  * @key: selector key value for new fw_cfg item
117*9c4a5c55SGabriel L. Somlo  * @value: 16-bit integer
118*9c4a5c55SGabriel L. Somlo  *
119*9c4a5c55SGabriel L. Somlo  * Replace the fw_cfg item available by selecting the given key. The new
120*9c4a5c55SGabriel L. Somlo  * data will consist of a dynamically allocated copy of the given 16-bit
121*9c4a5c55SGabriel L. Somlo  * value, converted to little-endian representation. The data being replaced,
122*9c4a5c55SGabriel L. Somlo  * assumed to have been dynamically allocated during an earlier call to
123*9c4a5c55SGabriel L. Somlo  * either fw_cfg_add_i16() or fw_cfg_modify_i16(), is freed before returning.
124*9c4a5c55SGabriel L. Somlo  */
1251edd34b6SGabriel L. Somlo void fw_cfg_modify_i16(FWCfgState *s, uint16_t key, uint16_t value);
126*9c4a5c55SGabriel L. Somlo 
127*9c4a5c55SGabriel L. Somlo /**
128*9c4a5c55SGabriel L. Somlo  * fw_cfg_add_i32:
129*9c4a5c55SGabriel L. Somlo  * @s: fw_cfg device being modified
130*9c4a5c55SGabriel L. Somlo  * @key: selector key value for new fw_cfg item
131*9c4a5c55SGabriel L. Somlo  * @value: 32-bit integer
132*9c4a5c55SGabriel L. Somlo  *
133*9c4a5c55SGabriel L. Somlo  * Add a new fw_cfg item, available by selecting the given key. The item
134*9c4a5c55SGabriel L. Somlo  * data will consist of a dynamically allocated copy of the given 32-bit
135*9c4a5c55SGabriel L. Somlo  * value, converted to little-endian representation.
136*9c4a5c55SGabriel L. Somlo  */
1374cad3867SMarkus Armbruster void fw_cfg_add_i32(FWCfgState *s, uint16_t key, uint32_t value);
138*9c4a5c55SGabriel L. Somlo 
139*9c4a5c55SGabriel L. Somlo /**
140*9c4a5c55SGabriel L. Somlo  * fw_cfg_add_i64:
141*9c4a5c55SGabriel L. Somlo  * @s: fw_cfg device being modified
142*9c4a5c55SGabriel L. Somlo  * @key: selector key value for new fw_cfg item
143*9c4a5c55SGabriel L. Somlo  * @value: 64-bit integer
144*9c4a5c55SGabriel L. Somlo  *
145*9c4a5c55SGabriel L. Somlo  * Add a new fw_cfg item, available by selecting the given key. The item
146*9c4a5c55SGabriel L. Somlo  * data will consist of a dynamically allocated copy of the given 64-bit
147*9c4a5c55SGabriel L. Somlo  * value, converted to little-endian representation.
148*9c4a5c55SGabriel L. Somlo  */
1494cad3867SMarkus Armbruster void fw_cfg_add_i64(FWCfgState *s, uint16_t key, uint64_t value);
150*9c4a5c55SGabriel L. Somlo 
151*9c4a5c55SGabriel L. Somlo /**
152*9c4a5c55SGabriel L. Somlo  * fw_cfg_add_file:
153*9c4a5c55SGabriel L. Somlo  * @s: fw_cfg device being modified
154*9c4a5c55SGabriel L. Somlo  * @filename: name of new fw_cfg file item
155*9c4a5c55SGabriel L. Somlo  * @data: pointer to start of item data
156*9c4a5c55SGabriel L. Somlo  * @len: size of item data
157*9c4a5c55SGabriel L. Somlo  *
158*9c4a5c55SGabriel L. Somlo  * Add a new NAMED fw_cfg item as a raw "blob" of the given size. The data
159*9c4a5c55SGabriel L. Somlo  * referenced by the starting pointer is only linked, NOT copied, into the
160*9c4a5c55SGabriel L. Somlo  * data structure of the fw_cfg device.
161*9c4a5c55SGabriel L. Somlo  * The next available (unused) selector key starting at FW_CFG_FILE_FIRST
162*9c4a5c55SGabriel L. Somlo  * will be used; also, a new entry will be added to the file directory
163*9c4a5c55SGabriel L. Somlo  * structure residing at key value FW_CFG_FILE_DIR, containing the item name,
164*9c4a5c55SGabriel L. Somlo  * data size, and assigned selector key value.
165*9c4a5c55SGabriel L. Somlo  */
166089da572SMarkus Armbruster void fw_cfg_add_file(FWCfgState *s, const char *filename, void *data,
167089da572SMarkus Armbruster                      size_t len);
168*9c4a5c55SGabriel L. Somlo 
169*9c4a5c55SGabriel L. Somlo /**
170*9c4a5c55SGabriel L. Somlo  * fw_cfg_add_file_callback:
171*9c4a5c55SGabriel L. Somlo  * @s: fw_cfg device being modified
172*9c4a5c55SGabriel L. Somlo  * @filename: name of new fw_cfg file item
173*9c4a5c55SGabriel L. Somlo  * @callback: callback function
174*9c4a5c55SGabriel L. Somlo  * @callback_opaque: argument to be passed into callback function
175*9c4a5c55SGabriel L. Somlo  * @data: pointer to start of item data
176*9c4a5c55SGabriel L. Somlo  * @len: size of item data
177*9c4a5c55SGabriel L. Somlo  *
178*9c4a5c55SGabriel L. Somlo  * Add a new NAMED fw_cfg item as a raw "blob" of the given size. The data
179*9c4a5c55SGabriel L. Somlo  * referenced by the starting pointer is only linked, NOT copied, into the
180*9c4a5c55SGabriel L. Somlo  * data structure of the fw_cfg device.
181*9c4a5c55SGabriel L. Somlo  * The next available (unused) selector key starting at FW_CFG_FILE_FIRST
182*9c4a5c55SGabriel L. Somlo  * will be used; also, a new entry will be added to the file directory
183*9c4a5c55SGabriel L. Somlo  * structure residing at key value FW_CFG_FILE_DIR, containing the item name,
184*9c4a5c55SGabriel L. Somlo  * data size, and assigned selector key value.
185*9c4a5c55SGabriel L. Somlo  * Additionally, set a callback function (and argument) to be called each
186*9c4a5c55SGabriel L. Somlo  * time a byte is read by the guest from this particular item, or, in the
187*9c4a5c55SGabriel L. Somlo  * case of DMA, each time a read or skip request overlaps with the valid
188*9c4a5c55SGabriel L. Somlo  * offset range of the item.
189*9c4a5c55SGabriel L. Somlo  * NOTE: In addition to the opaque argument set here, the callback function
190*9c4a5c55SGabriel L. Somlo  * takes the current data offset as an additional argument, allowing it the
191*9c4a5c55SGabriel L. Somlo  * option of only acting upon specific offset values (e.g., 0, before the
192*9c4a5c55SGabriel L. Somlo  * first data byte of the selected item is returned to the guest).
193*9c4a5c55SGabriel L. Somlo  */
194d87072ceSMichael S. Tsirkin void fw_cfg_add_file_callback(FWCfgState *s, const char *filename,
195d87072ceSMichael S. Tsirkin                               FWCfgReadCallback callback, void *callback_opaque,
196d87072ceSMichael S. Tsirkin                               void *data, size_t len);
197*9c4a5c55SGabriel L. Somlo 
198*9c4a5c55SGabriel L. Somlo /**
199*9c4a5c55SGabriel L. Somlo  * fw_cfg_modify_file:
200*9c4a5c55SGabriel L. Somlo  * @s: fw_cfg device being modified
201*9c4a5c55SGabriel L. Somlo  * @filename: name of new fw_cfg file item
202*9c4a5c55SGabriel L. Somlo  * @data: pointer to start of item data
203*9c4a5c55SGabriel L. Somlo  * @len: size of item data
204*9c4a5c55SGabriel L. Somlo  *
205*9c4a5c55SGabriel L. Somlo  * Replace a NAMED fw_cfg item. If an existing item is found, its callback
206*9c4a5c55SGabriel L. Somlo  * information will be cleared, and a pointer to its data will be returned
207*9c4a5c55SGabriel L. Somlo  * to the caller, so that it may be freed if necessary. If an existing item
208*9c4a5c55SGabriel L. Somlo  * is not found, this call defaults to fw_cfg_add_file(), and NULL is
209*9c4a5c55SGabriel L. Somlo  * returned to the caller.
210*9c4a5c55SGabriel L. Somlo  * In either case, the new item data is only linked, NOT copied, into the
211*9c4a5c55SGabriel L. Somlo  * data structure of the fw_cfg device.
212*9c4a5c55SGabriel L. Somlo  *
213*9c4a5c55SGabriel L. Somlo  * Returns: pointer to old item's data, or NULL if old item does not exist.
214*9c4a5c55SGabriel L. Somlo  */
215bdbb5b17SGonglei void *fw_cfg_modify_file(FWCfgState *s, const char *filename, void *data,
216bdbb5b17SGonglei                          size_t len);
217*9c4a5c55SGabriel L. Somlo 
218a4c0d1deSMarc Marí FWCfgState *fw_cfg_init_io_dma(uint32_t iobase, uint32_t dma_iobase,
219a4c0d1deSMarc Marí                                 AddressSpace *dma_as);
2205712db6aSLaszlo Ersek FWCfgState *fw_cfg_init_io(uint32_t iobase);
2215712db6aSLaszlo Ersek FWCfgState *fw_cfg_init_mem(hwaddr ctl_addr, hwaddr data_addr);
222a4c0d1deSMarc Marí FWCfgState *fw_cfg_init_mem_wide(hwaddr ctl_addr,
223a4c0d1deSMarc Marí                                  hwaddr data_addr, uint32_t data_width,
224a4c0d1deSMarc Marí                                  hwaddr dma_addr, AddressSpace *dma_as);
2253cce6243Sblueswir1 
226600c60b7SMichael S. Tsirkin FWCfgState *fw_cfg_find(void);
227600c60b7SMichael S. Tsirkin 
2283cce6243Sblueswir1 #endif /* NO_QEMU_PROTOS */
2293cce6243Sblueswir1 
2303cce6243Sblueswir1 #endif
231