xref: /qemu/include/hw/nvram/fw_cfg.h (revision 6f061ea10f28c6cbe3ea588e84ef1f5fd27f0299)
13cce6243Sblueswir1 #ifndef FW_CFG_H
23cce6243Sblueswir1 #define FW_CFG_H
33cce6243Sblueswir1 
41dfe5057SHu Tao #include "exec/hwaddr.h"
5*6f061ea1SMarkus 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 
14abe147e0SGerd Hoffmann typedef struct FWCfgFiles {
15abe147e0SGerd Hoffmann     uint32_t  count;
16abe147e0SGerd Hoffmann     FWCfgFile f[];
17abe147e0SGerd Hoffmann } FWCfgFiles;
18abe147e0SGerd Hoffmann 
19a4c0d1deSMarc Marí /* Control as first field allows for different structures selected by this
20a4c0d1deSMarc Marí  * field, which might be useful in the future
21a4c0d1deSMarc Marí  */
22a4c0d1deSMarc Marí typedef struct FWCfgDmaAccess {
23a4c0d1deSMarc Marí     uint32_t control;
24a4c0d1deSMarc Marí     uint32_t length;
25a4c0d1deSMarc Marí     uint64_t address;
26a4c0d1deSMarc Marí } QEMU_PACKED FWCfgDmaAccess;
27a4c0d1deSMarc Marí 
283f8752b4SGabriel L. Somlo typedef void (*FWCfgReadCallback)(void *opaque);
293cce6243Sblueswir1 
309c4a5c55SGabriel L. Somlo /**
319c4a5c55SGabriel L. Somlo  * fw_cfg_add_bytes:
329c4a5c55SGabriel L. Somlo  * @s: fw_cfg device being modified
339c4a5c55SGabriel L. Somlo  * @key: selector key value for new fw_cfg item
349c4a5c55SGabriel L. Somlo  * @data: pointer to start of item data
359c4a5c55SGabriel L. Somlo  * @len: size of item data
369c4a5c55SGabriel L. Somlo  *
379c4a5c55SGabriel L. Somlo  * Add a new fw_cfg item, available by selecting the given key, as a raw
389c4a5c55SGabriel L. Somlo  * "blob" of the given size. The data referenced by the starting pointer
399c4a5c55SGabriel L. Somlo  * is only linked, NOT copied, into the data structure of the fw_cfg device.
409c4a5c55SGabriel L. Somlo  */
41089da572SMarkus Armbruster void fw_cfg_add_bytes(FWCfgState *s, uint16_t key, void *data, size_t len);
429c4a5c55SGabriel L. Somlo 
439c4a5c55SGabriel L. Somlo /**
449c4a5c55SGabriel L. Somlo  * fw_cfg_add_string:
459c4a5c55SGabriel L. Somlo  * @s: fw_cfg device being modified
469c4a5c55SGabriel L. Somlo  * @key: selector key value for new fw_cfg item
479c4a5c55SGabriel L. Somlo  * @value: NUL-terminated ascii string
489c4a5c55SGabriel L. Somlo  *
499c4a5c55SGabriel L. Somlo  * Add a new fw_cfg item, available by selecting the given key. The item
509c4a5c55SGabriel L. Somlo  * data will consist of a dynamically allocated copy of the provided string,
519c4a5c55SGabriel L. Somlo  * including its NUL terminator.
529c4a5c55SGabriel L. Somlo  */
5344687f75SMarkus Armbruster void fw_cfg_add_string(FWCfgState *s, uint16_t key, const char *value);
549c4a5c55SGabriel L. Somlo 
559c4a5c55SGabriel L. Somlo /**
569c4a5c55SGabriel L. Somlo  * fw_cfg_add_i16:
579c4a5c55SGabriel L. Somlo  * @s: fw_cfg device being modified
589c4a5c55SGabriel L. Somlo  * @key: selector key value for new fw_cfg item
599c4a5c55SGabriel L. Somlo  * @value: 16-bit integer
609c4a5c55SGabriel L. Somlo  *
619c4a5c55SGabriel L. Somlo  * Add a new fw_cfg item, available by selecting the given key. The item
629c4a5c55SGabriel L. Somlo  * data will consist of a dynamically allocated copy of the given 16-bit
639c4a5c55SGabriel L. Somlo  * value, converted to little-endian representation.
649c4a5c55SGabriel L. Somlo  */
654cad3867SMarkus Armbruster void fw_cfg_add_i16(FWCfgState *s, uint16_t key, uint16_t value);
669c4a5c55SGabriel L. Somlo 
679c4a5c55SGabriel L. Somlo /**
689c4a5c55SGabriel L. Somlo  * fw_cfg_modify_i16:
699c4a5c55SGabriel L. Somlo  * @s: fw_cfg device being modified
709c4a5c55SGabriel L. Somlo  * @key: selector key value for new fw_cfg item
719c4a5c55SGabriel L. Somlo  * @value: 16-bit integer
729c4a5c55SGabriel L. Somlo  *
739c4a5c55SGabriel L. Somlo  * Replace the fw_cfg item available by selecting the given key. The new
749c4a5c55SGabriel L. Somlo  * data will consist of a dynamically allocated copy of the given 16-bit
759c4a5c55SGabriel L. Somlo  * value, converted to little-endian representation. The data being replaced,
769c4a5c55SGabriel L. Somlo  * assumed to have been dynamically allocated during an earlier call to
779c4a5c55SGabriel L. Somlo  * either fw_cfg_add_i16() or fw_cfg_modify_i16(), is freed before returning.
789c4a5c55SGabriel L. Somlo  */
791edd34b6SGabriel L. Somlo void fw_cfg_modify_i16(FWCfgState *s, uint16_t key, uint16_t value);
809c4a5c55SGabriel L. Somlo 
819c4a5c55SGabriel L. Somlo /**
829c4a5c55SGabriel L. Somlo  * fw_cfg_add_i32:
839c4a5c55SGabriel L. Somlo  * @s: fw_cfg device being modified
849c4a5c55SGabriel L. Somlo  * @key: selector key value for new fw_cfg item
859c4a5c55SGabriel L. Somlo  * @value: 32-bit integer
869c4a5c55SGabriel L. Somlo  *
879c4a5c55SGabriel L. Somlo  * Add a new fw_cfg item, available by selecting the given key. The item
889c4a5c55SGabriel L. Somlo  * data will consist of a dynamically allocated copy of the given 32-bit
899c4a5c55SGabriel L. Somlo  * value, converted to little-endian representation.
909c4a5c55SGabriel L. Somlo  */
914cad3867SMarkus Armbruster void fw_cfg_add_i32(FWCfgState *s, uint16_t key, uint32_t value);
929c4a5c55SGabriel L. Somlo 
939c4a5c55SGabriel L. Somlo /**
949c4a5c55SGabriel L. Somlo  * fw_cfg_add_i64:
959c4a5c55SGabriel L. Somlo  * @s: fw_cfg device being modified
969c4a5c55SGabriel L. Somlo  * @key: selector key value for new fw_cfg item
979c4a5c55SGabriel L. Somlo  * @value: 64-bit integer
989c4a5c55SGabriel L. Somlo  *
999c4a5c55SGabriel L. Somlo  * Add a new fw_cfg item, available by selecting the given key. The item
1009c4a5c55SGabriel L. Somlo  * data will consist of a dynamically allocated copy of the given 64-bit
1019c4a5c55SGabriel L. Somlo  * value, converted to little-endian representation.
1029c4a5c55SGabriel L. Somlo  */
1034cad3867SMarkus Armbruster void fw_cfg_add_i64(FWCfgState *s, uint16_t key, uint64_t value);
1049c4a5c55SGabriel L. Somlo 
1059c4a5c55SGabriel L. Somlo /**
1069c4a5c55SGabriel L. Somlo  * fw_cfg_add_file:
1079c4a5c55SGabriel L. Somlo  * @s: fw_cfg device being modified
1089c4a5c55SGabriel L. Somlo  * @filename: name of new fw_cfg file item
1099c4a5c55SGabriel L. Somlo  * @data: pointer to start of item data
1109c4a5c55SGabriel L. Somlo  * @len: size of item data
1119c4a5c55SGabriel L. Somlo  *
1129c4a5c55SGabriel L. Somlo  * Add a new NAMED fw_cfg item as a raw "blob" of the given size. The data
1139c4a5c55SGabriel L. Somlo  * referenced by the starting pointer is only linked, NOT copied, into the
1149c4a5c55SGabriel L. Somlo  * data structure of the fw_cfg device.
1159c4a5c55SGabriel L. Somlo  * The next available (unused) selector key starting at FW_CFG_FILE_FIRST
1169c4a5c55SGabriel L. Somlo  * will be used; also, a new entry will be added to the file directory
1179c4a5c55SGabriel L. Somlo  * structure residing at key value FW_CFG_FILE_DIR, containing the item name,
1189c4a5c55SGabriel L. Somlo  * data size, and assigned selector key value.
1199c4a5c55SGabriel L. Somlo  */
120089da572SMarkus Armbruster void fw_cfg_add_file(FWCfgState *s, const char *filename, void *data,
121089da572SMarkus Armbruster                      size_t len);
1229c4a5c55SGabriel L. Somlo 
1239c4a5c55SGabriel L. Somlo /**
1249c4a5c55SGabriel L. Somlo  * fw_cfg_add_file_callback:
1259c4a5c55SGabriel L. Somlo  * @s: fw_cfg device being modified
1269c4a5c55SGabriel L. Somlo  * @filename: name of new fw_cfg file item
1279c4a5c55SGabriel L. Somlo  * @callback: callback function
1289c4a5c55SGabriel L. Somlo  * @callback_opaque: argument to be passed into callback function
1299c4a5c55SGabriel L. Somlo  * @data: pointer to start of item data
1309c4a5c55SGabriel L. Somlo  * @len: size of item data
1319c4a5c55SGabriel L. Somlo  *
1329c4a5c55SGabriel L. Somlo  * Add a new NAMED fw_cfg item as a raw "blob" of the given size. The data
1339c4a5c55SGabriel L. Somlo  * referenced by the starting pointer is only linked, NOT copied, into the
1349c4a5c55SGabriel L. Somlo  * data structure of the fw_cfg device.
1359c4a5c55SGabriel L. Somlo  * The next available (unused) selector key starting at FW_CFG_FILE_FIRST
1369c4a5c55SGabriel L. Somlo  * will be used; also, a new entry will be added to the file directory
1379c4a5c55SGabriel L. Somlo  * structure residing at key value FW_CFG_FILE_DIR, containing the item name,
1389c4a5c55SGabriel L. Somlo  * data size, and assigned selector key value.
1399c4a5c55SGabriel L. Somlo  * Additionally, set a callback function (and argument) to be called each
1403bef7e8aSGabriel L. Somlo  * time this item is selected (by having its selector key either written to
1413bef7e8aSGabriel L. Somlo  * the fw_cfg control register, or passed to QEMU in FWCfgDmaAccess.control
1423bef7e8aSGabriel L. Somlo  * with FW_CFG_DMA_CTL_SELECT).
1439c4a5c55SGabriel L. Somlo  */
144d87072ceSMichael S. Tsirkin void fw_cfg_add_file_callback(FWCfgState *s, const char *filename,
145d87072ceSMichael S. Tsirkin                               FWCfgReadCallback callback, void *callback_opaque,
146d87072ceSMichael S. Tsirkin                               void *data, size_t len);
1479c4a5c55SGabriel L. Somlo 
1489c4a5c55SGabriel L. Somlo /**
1499c4a5c55SGabriel L. Somlo  * fw_cfg_modify_file:
1509c4a5c55SGabriel L. Somlo  * @s: fw_cfg device being modified
1519c4a5c55SGabriel L. Somlo  * @filename: name of new fw_cfg file item
1529c4a5c55SGabriel L. Somlo  * @data: pointer to start of item data
1539c4a5c55SGabriel L. Somlo  * @len: size of item data
1549c4a5c55SGabriel L. Somlo  *
1559c4a5c55SGabriel L. Somlo  * Replace a NAMED fw_cfg item. If an existing item is found, its callback
1569c4a5c55SGabriel L. Somlo  * information will be cleared, and a pointer to its data will be returned
1579c4a5c55SGabriel L. Somlo  * to the caller, so that it may be freed if necessary. If an existing item
1589c4a5c55SGabriel L. Somlo  * is not found, this call defaults to fw_cfg_add_file(), and NULL is
1599c4a5c55SGabriel L. Somlo  * returned to the caller.
1609c4a5c55SGabriel L. Somlo  * In either case, the new item data is only linked, NOT copied, into the
1619c4a5c55SGabriel L. Somlo  * data structure of the fw_cfg device.
1629c4a5c55SGabriel L. Somlo  *
1639c4a5c55SGabriel L. Somlo  * Returns: pointer to old item's data, or NULL if old item does not exist.
1649c4a5c55SGabriel L. Somlo  */
165bdbb5b17SGonglei void *fw_cfg_modify_file(FWCfgState *s, const char *filename, void *data,
166bdbb5b17SGonglei                          size_t len);
1679c4a5c55SGabriel L. Somlo 
168a4c0d1deSMarc Marí FWCfgState *fw_cfg_init_io_dma(uint32_t iobase, uint32_t dma_iobase,
169a4c0d1deSMarc Marí                                 AddressSpace *dma_as);
1705712db6aSLaszlo Ersek FWCfgState *fw_cfg_init_io(uint32_t iobase);
1715712db6aSLaszlo Ersek FWCfgState *fw_cfg_init_mem(hwaddr ctl_addr, hwaddr data_addr);
172a4c0d1deSMarc Marí FWCfgState *fw_cfg_init_mem_wide(hwaddr ctl_addr,
173a4c0d1deSMarc Marí                                  hwaddr data_addr, uint32_t data_width,
174a4c0d1deSMarc Marí                                  hwaddr dma_addr, AddressSpace *dma_as);
1753cce6243Sblueswir1 
176600c60b7SMichael S. Tsirkin FWCfgState *fw_cfg_find(void);
177600c60b7SMichael S. Tsirkin 
1783cce6243Sblueswir1 #endif
179