xref: /qemu/include/hw/nvram/fw_cfg.h (revision bab47d9a75a33de747420e6b74fd157b708c890b)
13cce6243Sblueswir1 #ifndef FW_CFG_H
23cce6243Sblueswir1 #define FW_CFG_H
33cce6243Sblueswir1 
41dfe5057SHu Tao #include "exec/hwaddr.h"
56f061ea1SMarkus Armbruster #include "hw/nvram/fw_cfg_keys.h"
61dfe5057SHu Tao 
7abe147e0SGerd Hoffmann typedef struct FWCfgFile {
8abe147e0SGerd Hoffmann     uint32_t  size;        /* file size */
9abe147e0SGerd Hoffmann     uint16_t  select;      /* write this to 0x510 to read it */
10abe147e0SGerd Hoffmann     uint16_t  reserved;
1135c12e60SMichael S. Tsirkin     char      name[FW_CFG_MAX_FILE_PATH];
12abe147e0SGerd Hoffmann } FWCfgFile;
13abe147e0SGerd Hoffmann 
14*bab47d9aSGerd Hoffmann #define FW_CFG_ORDER_OVERRIDE_VGA    70
15*bab47d9aSGerd Hoffmann #define FW_CFG_ORDER_OVERRIDE_NIC    80
16*bab47d9aSGerd Hoffmann #define FW_CFG_ORDER_OVERRIDE_USER   100
17*bab47d9aSGerd Hoffmann #define FW_CFG_ORDER_OVERRIDE_DEVICE 110
18*bab47d9aSGerd Hoffmann 
19*bab47d9aSGerd Hoffmann void fw_cfg_set_order_override(FWCfgState *fw_cfg, int order);
20*bab47d9aSGerd Hoffmann void fw_cfg_reset_order_override(FWCfgState *fw_cfg);
21*bab47d9aSGerd Hoffmann 
22abe147e0SGerd Hoffmann typedef struct FWCfgFiles {
23abe147e0SGerd Hoffmann     uint32_t  count;
24abe147e0SGerd Hoffmann     FWCfgFile f[];
25abe147e0SGerd Hoffmann } FWCfgFiles;
26abe147e0SGerd Hoffmann 
27a4c0d1deSMarc Marí /* Control as first field allows for different structures selected by this
28a4c0d1deSMarc Marí  * field, which might be useful in the future
29a4c0d1deSMarc Marí  */
30a4c0d1deSMarc Marí typedef struct FWCfgDmaAccess {
31a4c0d1deSMarc Marí     uint32_t control;
32a4c0d1deSMarc Marí     uint32_t length;
33a4c0d1deSMarc Marí     uint64_t address;
34a4c0d1deSMarc Marí } QEMU_PACKED FWCfgDmaAccess;
35a4c0d1deSMarc Marí 
363f8752b4SGabriel L. Somlo typedef void (*FWCfgReadCallback)(void *opaque);
373cce6243Sblueswir1 
389c4a5c55SGabriel L. Somlo /**
399c4a5c55SGabriel L. Somlo  * fw_cfg_add_bytes:
409c4a5c55SGabriel L. Somlo  * @s: fw_cfg device being modified
419c4a5c55SGabriel L. Somlo  * @key: selector key value for new fw_cfg item
429c4a5c55SGabriel L. Somlo  * @data: pointer to start of item data
439c4a5c55SGabriel L. Somlo  * @len: size of item data
449c4a5c55SGabriel L. Somlo  *
459c4a5c55SGabriel L. Somlo  * Add a new fw_cfg item, available by selecting the given key, as a raw
469c4a5c55SGabriel L. Somlo  * "blob" of the given size. The data referenced by the starting pointer
479c4a5c55SGabriel L. Somlo  * is only linked, NOT copied, into the data structure of the fw_cfg device.
489c4a5c55SGabriel L. Somlo  */
49089da572SMarkus Armbruster void fw_cfg_add_bytes(FWCfgState *s, uint16_t key, void *data, size_t len);
509c4a5c55SGabriel L. Somlo 
519c4a5c55SGabriel L. Somlo /**
529c4a5c55SGabriel L. Somlo  * fw_cfg_add_string:
539c4a5c55SGabriel L. Somlo  * @s: fw_cfg device being modified
549c4a5c55SGabriel L. Somlo  * @key: selector key value for new fw_cfg item
559c4a5c55SGabriel L. Somlo  * @value: NUL-terminated ascii string
569c4a5c55SGabriel L. Somlo  *
579c4a5c55SGabriel L. Somlo  * Add a new fw_cfg item, available by selecting the given key. The item
589c4a5c55SGabriel L. Somlo  * data will consist of a dynamically allocated copy of the provided string,
599c4a5c55SGabriel L. Somlo  * including its NUL terminator.
609c4a5c55SGabriel L. Somlo  */
6144687f75SMarkus Armbruster void fw_cfg_add_string(FWCfgState *s, uint16_t key, const char *value);
629c4a5c55SGabriel L. Somlo 
639c4a5c55SGabriel L. Somlo /**
649c4a5c55SGabriel L. Somlo  * fw_cfg_add_i16:
659c4a5c55SGabriel L. Somlo  * @s: fw_cfg device being modified
669c4a5c55SGabriel L. Somlo  * @key: selector key value for new fw_cfg item
679c4a5c55SGabriel L. Somlo  * @value: 16-bit integer
689c4a5c55SGabriel L. Somlo  *
699c4a5c55SGabriel L. Somlo  * Add a new fw_cfg item, available by selecting the given key. The item
709c4a5c55SGabriel L. Somlo  * data will consist of a dynamically allocated copy of the given 16-bit
719c4a5c55SGabriel L. Somlo  * value, converted to little-endian representation.
729c4a5c55SGabriel L. Somlo  */
734cad3867SMarkus Armbruster void fw_cfg_add_i16(FWCfgState *s, uint16_t key, uint16_t value);
749c4a5c55SGabriel L. Somlo 
759c4a5c55SGabriel L. Somlo /**
769c4a5c55SGabriel L. Somlo  * fw_cfg_modify_i16:
779c4a5c55SGabriel L. Somlo  * @s: fw_cfg device being modified
789c4a5c55SGabriel L. Somlo  * @key: selector key value for new fw_cfg item
799c4a5c55SGabriel L. Somlo  * @value: 16-bit integer
809c4a5c55SGabriel L. Somlo  *
819c4a5c55SGabriel L. Somlo  * Replace the fw_cfg item available by selecting the given key. The new
829c4a5c55SGabriel L. Somlo  * data will consist of a dynamically allocated copy of the given 16-bit
839c4a5c55SGabriel L. Somlo  * value, converted to little-endian representation. The data being replaced,
849c4a5c55SGabriel L. Somlo  * assumed to have been dynamically allocated during an earlier call to
859c4a5c55SGabriel L. Somlo  * either fw_cfg_add_i16() or fw_cfg_modify_i16(), is freed before returning.
869c4a5c55SGabriel L. Somlo  */
871edd34b6SGabriel L. Somlo void fw_cfg_modify_i16(FWCfgState *s, uint16_t key, uint16_t value);
889c4a5c55SGabriel L. Somlo 
899c4a5c55SGabriel L. Somlo /**
909c4a5c55SGabriel L. Somlo  * fw_cfg_add_i32:
919c4a5c55SGabriel L. Somlo  * @s: fw_cfg device being modified
929c4a5c55SGabriel L. Somlo  * @key: selector key value for new fw_cfg item
939c4a5c55SGabriel L. Somlo  * @value: 32-bit integer
949c4a5c55SGabriel L. Somlo  *
959c4a5c55SGabriel L. Somlo  * Add a new fw_cfg item, available by selecting the given key. The item
969c4a5c55SGabriel L. Somlo  * data will consist of a dynamically allocated copy of the given 32-bit
979c4a5c55SGabriel L. Somlo  * value, converted to little-endian representation.
989c4a5c55SGabriel L. Somlo  */
994cad3867SMarkus Armbruster void fw_cfg_add_i32(FWCfgState *s, uint16_t key, uint32_t value);
1009c4a5c55SGabriel L. Somlo 
1019c4a5c55SGabriel L. Somlo /**
1029c4a5c55SGabriel L. Somlo  * fw_cfg_add_i64:
1039c4a5c55SGabriel L. Somlo  * @s: fw_cfg device being modified
1049c4a5c55SGabriel L. Somlo  * @key: selector key value for new fw_cfg item
1059c4a5c55SGabriel L. Somlo  * @value: 64-bit integer
1069c4a5c55SGabriel L. Somlo  *
1079c4a5c55SGabriel L. Somlo  * Add a new fw_cfg item, available by selecting the given key. The item
1089c4a5c55SGabriel L. Somlo  * data will consist of a dynamically allocated copy of the given 64-bit
1099c4a5c55SGabriel L. Somlo  * value, converted to little-endian representation.
1109c4a5c55SGabriel L. Somlo  */
1114cad3867SMarkus Armbruster void fw_cfg_add_i64(FWCfgState *s, uint16_t key, uint64_t value);
1129c4a5c55SGabriel L. Somlo 
1139c4a5c55SGabriel L. Somlo /**
1149c4a5c55SGabriel L. Somlo  * fw_cfg_add_file:
1159c4a5c55SGabriel L. Somlo  * @s: fw_cfg device being modified
1169c4a5c55SGabriel L. Somlo  * @filename: name of new fw_cfg file item
1179c4a5c55SGabriel L. Somlo  * @data: pointer to start of item data
1189c4a5c55SGabriel L. Somlo  * @len: size of item data
1199c4a5c55SGabriel L. Somlo  *
1209c4a5c55SGabriel L. Somlo  * Add a new NAMED fw_cfg item as a raw "blob" of the given size. The data
1219c4a5c55SGabriel L. Somlo  * referenced by the starting pointer is only linked, NOT copied, into the
1229c4a5c55SGabriel L. Somlo  * data structure of the fw_cfg device.
1239c4a5c55SGabriel L. Somlo  * The next available (unused) selector key starting at FW_CFG_FILE_FIRST
1249c4a5c55SGabriel L. Somlo  * will be used; also, a new entry will be added to the file directory
1259c4a5c55SGabriel L. Somlo  * structure residing at key value FW_CFG_FILE_DIR, containing the item name,
1269c4a5c55SGabriel L. Somlo  * data size, and assigned selector key value.
1279c4a5c55SGabriel L. Somlo  */
128089da572SMarkus Armbruster void fw_cfg_add_file(FWCfgState *s, const char *filename, void *data,
129089da572SMarkus Armbruster                      size_t len);
1309c4a5c55SGabriel L. Somlo 
1319c4a5c55SGabriel L. Somlo /**
1329c4a5c55SGabriel L. Somlo  * fw_cfg_add_file_callback:
1339c4a5c55SGabriel L. Somlo  * @s: fw_cfg device being modified
1349c4a5c55SGabriel L. Somlo  * @filename: name of new fw_cfg file item
1359c4a5c55SGabriel L. Somlo  * @callback: callback function
1369c4a5c55SGabriel L. Somlo  * @callback_opaque: argument to be passed into callback function
1379c4a5c55SGabriel L. Somlo  * @data: pointer to start of item data
1389c4a5c55SGabriel L. Somlo  * @len: size of item data
1399c4a5c55SGabriel L. Somlo  *
1409c4a5c55SGabriel L. Somlo  * Add a new NAMED fw_cfg item as a raw "blob" of the given size. The data
1419c4a5c55SGabriel L. Somlo  * referenced by the starting pointer is only linked, NOT copied, into the
1429c4a5c55SGabriel L. Somlo  * data structure of the fw_cfg device.
1439c4a5c55SGabriel L. Somlo  * The next available (unused) selector key starting at FW_CFG_FILE_FIRST
1449c4a5c55SGabriel L. Somlo  * will be used; also, a new entry will be added to the file directory
1459c4a5c55SGabriel L. Somlo  * structure residing at key value FW_CFG_FILE_DIR, containing the item name,
1469c4a5c55SGabriel L. Somlo  * data size, and assigned selector key value.
1479c4a5c55SGabriel L. Somlo  * Additionally, set a callback function (and argument) to be called each
1483bef7e8aSGabriel L. Somlo  * time this item is selected (by having its selector key either written to
1493bef7e8aSGabriel L. Somlo  * the fw_cfg control register, or passed to QEMU in FWCfgDmaAccess.control
1503bef7e8aSGabriel L. Somlo  * with FW_CFG_DMA_CTL_SELECT).
1519c4a5c55SGabriel L. Somlo  */
152d87072ceSMichael S. Tsirkin void fw_cfg_add_file_callback(FWCfgState *s, const char *filename,
153d87072ceSMichael S. Tsirkin                               FWCfgReadCallback callback, void *callback_opaque,
154d87072ceSMichael S. Tsirkin                               void *data, size_t len);
1559c4a5c55SGabriel L. Somlo 
1569c4a5c55SGabriel L. Somlo /**
1579c4a5c55SGabriel L. Somlo  * fw_cfg_modify_file:
1589c4a5c55SGabriel L. Somlo  * @s: fw_cfg device being modified
1599c4a5c55SGabriel L. Somlo  * @filename: name of new fw_cfg file item
1609c4a5c55SGabriel L. Somlo  * @data: pointer to start of item data
1619c4a5c55SGabriel L. Somlo  * @len: size of item data
1629c4a5c55SGabriel L. Somlo  *
1639c4a5c55SGabriel L. Somlo  * Replace a NAMED fw_cfg item. If an existing item is found, its callback
1649c4a5c55SGabriel L. Somlo  * information will be cleared, and a pointer to its data will be returned
1659c4a5c55SGabriel L. Somlo  * to the caller, so that it may be freed if necessary. If an existing item
1669c4a5c55SGabriel L. Somlo  * is not found, this call defaults to fw_cfg_add_file(), and NULL is
1679c4a5c55SGabriel L. Somlo  * returned to the caller.
1689c4a5c55SGabriel L. Somlo  * In either case, the new item data is only linked, NOT copied, into the
1699c4a5c55SGabriel L. Somlo  * data structure of the fw_cfg device.
1709c4a5c55SGabriel L. Somlo  *
1719c4a5c55SGabriel L. Somlo  * Returns: pointer to old item's data, or NULL if old item does not exist.
1729c4a5c55SGabriel L. Somlo  */
173bdbb5b17SGonglei void *fw_cfg_modify_file(FWCfgState *s, const char *filename, void *data,
174bdbb5b17SGonglei                          size_t len);
1759c4a5c55SGabriel L. Somlo 
176a4c0d1deSMarc Marí FWCfgState *fw_cfg_init_io_dma(uint32_t iobase, uint32_t dma_iobase,
177a4c0d1deSMarc Marí                                 AddressSpace *dma_as);
1785712db6aSLaszlo Ersek FWCfgState *fw_cfg_init_io(uint32_t iobase);
1795712db6aSLaszlo Ersek FWCfgState *fw_cfg_init_mem(hwaddr ctl_addr, hwaddr data_addr);
180a4c0d1deSMarc Marí FWCfgState *fw_cfg_init_mem_wide(hwaddr ctl_addr,
181a4c0d1deSMarc Marí                                  hwaddr data_addr, uint32_t data_width,
182a4c0d1deSMarc Marí                                  hwaddr dma_addr, AddressSpace *dma_as);
1833cce6243Sblueswir1 
184600c60b7SMichael S. Tsirkin FWCfgState *fw_cfg_find(void);
185600c60b7SMichael S. Tsirkin 
1863cce6243Sblueswir1 #endif
187