xref: /qemu/include/hw/nvram/fw_cfg.h (revision 5be5df720e600502ff530cee51a7ac0622f62f6f)
13cce6243Sblueswir1 #ifndef FW_CFG_H
23cce6243Sblueswir1 #define FW_CFG_H
33cce6243Sblueswir1 
41dfe5057SHu Tao #include "exec/hwaddr.h"
5*5be5df72SMarc-André Lureau #include "standard-headers/linux/qemu_fw_cfg.h"
639736e18SMark Cave-Ayland #include "hw/sysbus.h"
739736e18SMark Cave-Ayland #include "sysemu/dma.h"
839736e18SMark Cave-Ayland 
939736e18SMark Cave-Ayland #define TYPE_FW_CFG     "fw_cfg"
1039736e18SMark Cave-Ayland #define TYPE_FW_CFG_IO  "fw_cfg_io"
1139736e18SMark Cave-Ayland #define TYPE_FW_CFG_MEM "fw_cfg_mem"
1239736e18SMark Cave-Ayland 
1339736e18SMark Cave-Ayland #define FW_CFG(obj)     OBJECT_CHECK(FWCfgState,    (obj), TYPE_FW_CFG)
1439736e18SMark Cave-Ayland #define FW_CFG_IO(obj)  OBJECT_CHECK(FWCfgIoState,  (obj), TYPE_FW_CFG_IO)
1539736e18SMark Cave-Ayland #define FW_CFG_MEM(obj) OBJECT_CHECK(FWCfgMemState, (obj), TYPE_FW_CFG_MEM)
161dfe5057SHu Tao 
17*5be5df72SMarc-André Lureau typedef struct fw_cfg_file FWCfgFile;
18abe147e0SGerd Hoffmann 
19bab47d9aSGerd Hoffmann #define FW_CFG_ORDER_OVERRIDE_VGA    70
20bab47d9aSGerd Hoffmann #define FW_CFG_ORDER_OVERRIDE_NIC    80
21bab47d9aSGerd Hoffmann #define FW_CFG_ORDER_OVERRIDE_USER   100
22bab47d9aSGerd Hoffmann #define FW_CFG_ORDER_OVERRIDE_DEVICE 110
23bab47d9aSGerd Hoffmann 
24bab47d9aSGerd Hoffmann void fw_cfg_set_order_override(FWCfgState *fw_cfg, int order);
25bab47d9aSGerd Hoffmann void fw_cfg_reset_order_override(FWCfgState *fw_cfg);
26bab47d9aSGerd Hoffmann 
27abe147e0SGerd Hoffmann typedef struct FWCfgFiles {
28abe147e0SGerd Hoffmann     uint32_t  count;
29abe147e0SGerd Hoffmann     FWCfgFile f[];
30abe147e0SGerd Hoffmann } FWCfgFiles;
31abe147e0SGerd Hoffmann 
32*5be5df72SMarc-André Lureau typedef struct fw_cfg_dma_access FWCfgDmaAccess;
33a4c0d1deSMarc Marí 
346f6f4aecSMarc-André Lureau typedef void (*FWCfgCallback)(void *opaque);
355f9252f7SMarc-André Lureau typedef void (*FWCfgWriteCallback)(void *opaque, off_t start, size_t len);
363cce6243Sblueswir1 
3739736e18SMark Cave-Ayland struct FWCfgState {
3839736e18SMark Cave-Ayland     /*< private >*/
3939736e18SMark Cave-Ayland     SysBusDevice parent_obj;
4039736e18SMark Cave-Ayland     /*< public >*/
4139736e18SMark Cave-Ayland 
4239736e18SMark Cave-Ayland     uint16_t file_slots;
4339736e18SMark Cave-Ayland     FWCfgEntry *entries[2];
4439736e18SMark Cave-Ayland     int *entry_order;
4539736e18SMark Cave-Ayland     FWCfgFiles *files;
4639736e18SMark Cave-Ayland     uint16_t cur_entry;
4739736e18SMark Cave-Ayland     uint32_t cur_offset;
4839736e18SMark Cave-Ayland     Notifier machine_ready;
4939736e18SMark Cave-Ayland 
5039736e18SMark Cave-Ayland     int fw_cfg_order_override;
5139736e18SMark Cave-Ayland 
5239736e18SMark Cave-Ayland     bool dma_enabled;
5339736e18SMark Cave-Ayland     dma_addr_t dma_addr;
5439736e18SMark Cave-Ayland     AddressSpace *dma_as;
5539736e18SMark Cave-Ayland     MemoryRegion dma_iomem;
5639736e18SMark Cave-Ayland };
5739736e18SMark Cave-Ayland 
5839736e18SMark Cave-Ayland struct FWCfgIoState {
5939736e18SMark Cave-Ayland     /*< private >*/
6039736e18SMark Cave-Ayland     FWCfgState parent_obj;
6139736e18SMark Cave-Ayland     /*< public >*/
6239736e18SMark Cave-Ayland 
6339736e18SMark Cave-Ayland     MemoryRegion comb_iomem;
6439736e18SMark Cave-Ayland };
6539736e18SMark Cave-Ayland 
6639736e18SMark Cave-Ayland struct FWCfgMemState {
6739736e18SMark Cave-Ayland     /*< private >*/
6839736e18SMark Cave-Ayland     FWCfgState parent_obj;
6939736e18SMark Cave-Ayland     /*< public >*/
7039736e18SMark Cave-Ayland 
7139736e18SMark Cave-Ayland     MemoryRegion ctl_iomem, data_iomem;
7239736e18SMark Cave-Ayland     uint32_t data_width;
7339736e18SMark Cave-Ayland     MemoryRegionOps wide_data_ops;
7439736e18SMark Cave-Ayland };
7539736e18SMark Cave-Ayland 
769c4a5c55SGabriel L. Somlo /**
779c4a5c55SGabriel L. Somlo  * fw_cfg_add_bytes:
789c4a5c55SGabriel L. Somlo  * @s: fw_cfg device being modified
799c4a5c55SGabriel L. Somlo  * @key: selector key value for new fw_cfg item
809c4a5c55SGabriel L. Somlo  * @data: pointer to start of item data
819c4a5c55SGabriel L. Somlo  * @len: size of item data
829c4a5c55SGabriel L. Somlo  *
839c4a5c55SGabriel L. Somlo  * Add a new fw_cfg item, available by selecting the given key, as a raw
849c4a5c55SGabriel L. Somlo  * "blob" of the given size. The data referenced by the starting pointer
859c4a5c55SGabriel L. Somlo  * is only linked, NOT copied, into the data structure of the fw_cfg device.
869c4a5c55SGabriel L. Somlo  */
87089da572SMarkus Armbruster void fw_cfg_add_bytes(FWCfgState *s, uint16_t key, void *data, size_t len);
889c4a5c55SGabriel L. Somlo 
899c4a5c55SGabriel L. Somlo /**
909c4a5c55SGabriel L. Somlo  * fw_cfg_add_string:
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: NUL-terminated ascii string
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 provided string,
979c4a5c55SGabriel L. Somlo  * including its NUL terminator.
989c4a5c55SGabriel L. Somlo  */
9944687f75SMarkus Armbruster void fw_cfg_add_string(FWCfgState *s, uint16_t key, const char *value);
1009c4a5c55SGabriel L. Somlo 
1019c4a5c55SGabriel L. Somlo /**
1029c4a5c55SGabriel L. Somlo  * fw_cfg_add_i16:
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: 16-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 16-bit
1099c4a5c55SGabriel L. Somlo  * value, converted to little-endian representation.
1109c4a5c55SGabriel L. Somlo  */
1114cad3867SMarkus Armbruster void fw_cfg_add_i16(FWCfgState *s, uint16_t key, uint16_t value);
1129c4a5c55SGabriel L. Somlo 
1139c4a5c55SGabriel L. Somlo /**
1149c4a5c55SGabriel L. Somlo  * fw_cfg_modify_i16:
1159c4a5c55SGabriel L. Somlo  * @s: fw_cfg device being modified
1169c4a5c55SGabriel L. Somlo  * @key: selector key value for new fw_cfg item
1179c4a5c55SGabriel L. Somlo  * @value: 16-bit integer
1189c4a5c55SGabriel L. Somlo  *
1199c4a5c55SGabriel L. Somlo  * Replace the fw_cfg item available by selecting the given key. The new
1209c4a5c55SGabriel L. Somlo  * data will consist of a dynamically allocated copy of the given 16-bit
1219c4a5c55SGabriel L. Somlo  * value, converted to little-endian representation. The data being replaced,
1229c4a5c55SGabriel L. Somlo  * assumed to have been dynamically allocated during an earlier call to
1239c4a5c55SGabriel L. Somlo  * either fw_cfg_add_i16() or fw_cfg_modify_i16(), is freed before returning.
1249c4a5c55SGabriel L. Somlo  */
1251edd34b6SGabriel L. Somlo void fw_cfg_modify_i16(FWCfgState *s, uint16_t key, uint16_t value);
1269c4a5c55SGabriel L. Somlo 
1279c4a5c55SGabriel L. Somlo /**
1289c4a5c55SGabriel L. Somlo  * fw_cfg_add_i32:
1299c4a5c55SGabriel L. Somlo  * @s: fw_cfg device being modified
1309c4a5c55SGabriel L. Somlo  * @key: selector key value for new fw_cfg item
1319c4a5c55SGabriel L. Somlo  * @value: 32-bit integer
1329c4a5c55SGabriel L. Somlo  *
1339c4a5c55SGabriel L. Somlo  * Add a new fw_cfg item, available by selecting the given key. The item
1349c4a5c55SGabriel L. Somlo  * data will consist of a dynamically allocated copy of the given 32-bit
1359c4a5c55SGabriel L. Somlo  * value, converted to little-endian representation.
1369c4a5c55SGabriel L. Somlo  */
1374cad3867SMarkus Armbruster void fw_cfg_add_i32(FWCfgState *s, uint16_t key, uint32_t value);
1389c4a5c55SGabriel L. Somlo 
1399c4a5c55SGabriel L. Somlo /**
1409c4a5c55SGabriel L. Somlo  * fw_cfg_add_i64:
1419c4a5c55SGabriel L. Somlo  * @s: fw_cfg device being modified
1429c4a5c55SGabriel L. Somlo  * @key: selector key value for new fw_cfg item
1439c4a5c55SGabriel L. Somlo  * @value: 64-bit integer
1449c4a5c55SGabriel L. Somlo  *
1459c4a5c55SGabriel L. Somlo  * Add a new fw_cfg item, available by selecting the given key. The item
1469c4a5c55SGabriel L. Somlo  * data will consist of a dynamically allocated copy of the given 64-bit
1479c4a5c55SGabriel L. Somlo  * value, converted to little-endian representation.
1489c4a5c55SGabriel L. Somlo  */
1494cad3867SMarkus Armbruster void fw_cfg_add_i64(FWCfgState *s, uint16_t key, uint64_t value);
1509c4a5c55SGabriel L. Somlo 
1519c4a5c55SGabriel L. Somlo /**
1529c4a5c55SGabriel L. Somlo  * fw_cfg_add_file:
1539c4a5c55SGabriel L. Somlo  * @s: fw_cfg device being modified
1549c4a5c55SGabriel L. Somlo  * @filename: name of new fw_cfg file item
1559c4a5c55SGabriel L. Somlo  * @data: pointer to start of item data
1569c4a5c55SGabriel L. Somlo  * @len: size of item data
1579c4a5c55SGabriel L. Somlo  *
1589c4a5c55SGabriel L. Somlo  * Add a new NAMED fw_cfg item as a raw "blob" of the given size. The data
1599c4a5c55SGabriel L. Somlo  * referenced by the starting pointer is only linked, NOT copied, into the
1609c4a5c55SGabriel L. Somlo  * data structure of the fw_cfg device.
1619c4a5c55SGabriel L. Somlo  * The next available (unused) selector key starting at FW_CFG_FILE_FIRST
1629c4a5c55SGabriel L. Somlo  * will be used; also, a new entry will be added to the file directory
1639c4a5c55SGabriel L. Somlo  * structure residing at key value FW_CFG_FILE_DIR, containing the item name,
1649c4a5c55SGabriel L. Somlo  * data size, and assigned selector key value.
1659c4a5c55SGabriel L. Somlo  */
166089da572SMarkus Armbruster void fw_cfg_add_file(FWCfgState *s, const char *filename, void *data,
167089da572SMarkus Armbruster                      size_t len);
1689c4a5c55SGabriel L. Somlo 
1699c4a5c55SGabriel L. Somlo /**
1709c4a5c55SGabriel L. Somlo  * fw_cfg_add_file_callback:
1719c4a5c55SGabriel L. Somlo  * @s: fw_cfg device being modified
1729c4a5c55SGabriel L. Somlo  * @filename: name of new fw_cfg file item
1736f6f4aecSMarc-André Lureau  * @select_cb: callback function when selecting
1745f9252f7SMarc-André Lureau  * @write_cb: callback function after a write
1759c4a5c55SGabriel L. Somlo  * @callback_opaque: argument to be passed into callback function
1769c4a5c55SGabriel L. Somlo  * @data: pointer to start of item data
1779c4a5c55SGabriel L. Somlo  * @len: size of item data
178baf2d5bfSMichael S. Tsirkin  * @read_only: is file read only
1799c4a5c55SGabriel L. Somlo  *
1809c4a5c55SGabriel L. Somlo  * Add a new NAMED fw_cfg item as a raw "blob" of the given size. The data
1819c4a5c55SGabriel L. Somlo  * referenced by the starting pointer is only linked, NOT copied, into the
1829c4a5c55SGabriel L. Somlo  * data structure of the fw_cfg device.
1839c4a5c55SGabriel L. Somlo  * The next available (unused) selector key starting at FW_CFG_FILE_FIRST
1849c4a5c55SGabriel L. Somlo  * will be used; also, a new entry will be added to the file directory
1859c4a5c55SGabriel L. Somlo  * structure residing at key value FW_CFG_FILE_DIR, containing the item name,
1869c4a5c55SGabriel L. Somlo  * data size, and assigned selector key value.
1879c4a5c55SGabriel L. Somlo  * Additionally, set a callback function (and argument) to be called each
1883bef7e8aSGabriel L. Somlo  * time this item is selected (by having its selector key either written to
1893bef7e8aSGabriel L. Somlo  * the fw_cfg control register, or passed to QEMU in FWCfgDmaAccess.control
1903bef7e8aSGabriel L. Somlo  * with FW_CFG_DMA_CTL_SELECT).
1919c4a5c55SGabriel L. Somlo  */
192d87072ceSMichael S. Tsirkin void fw_cfg_add_file_callback(FWCfgState *s, const char *filename,
1936f6f4aecSMarc-André Lureau                               FWCfgCallback select_cb,
1945f9252f7SMarc-André Lureau                               FWCfgWriteCallback write_cb,
1956f6f4aecSMarc-André Lureau                               void *callback_opaque,
196baf2d5bfSMichael S. Tsirkin                               void *data, size_t len, bool read_only);
1979c4a5c55SGabriel L. Somlo 
1989c4a5c55SGabriel L. Somlo /**
1999c4a5c55SGabriel L. Somlo  * fw_cfg_modify_file:
2009c4a5c55SGabriel L. Somlo  * @s: fw_cfg device being modified
2019c4a5c55SGabriel L. Somlo  * @filename: name of new fw_cfg file item
2029c4a5c55SGabriel L. Somlo  * @data: pointer to start of item data
2039c4a5c55SGabriel L. Somlo  * @len: size of item data
2049c4a5c55SGabriel L. Somlo  *
2059c4a5c55SGabriel L. Somlo  * Replace a NAMED fw_cfg item. If an existing item is found, its callback
2069c4a5c55SGabriel L. Somlo  * information will be cleared, and a pointer to its data will be returned
2079c4a5c55SGabriel L. Somlo  * to the caller, so that it may be freed if necessary. If an existing item
2089c4a5c55SGabriel L. Somlo  * is not found, this call defaults to fw_cfg_add_file(), and NULL is
2099c4a5c55SGabriel L. Somlo  * returned to the caller.
2109c4a5c55SGabriel L. Somlo  * In either case, the new item data is only linked, NOT copied, into the
2119c4a5c55SGabriel L. Somlo  * data structure of the fw_cfg device.
2129c4a5c55SGabriel L. Somlo  *
2139c4a5c55SGabriel L. Somlo  * Returns: pointer to old item's data, or NULL if old item does not exist.
2149c4a5c55SGabriel L. Somlo  */
215bdbb5b17SGonglei void *fw_cfg_modify_file(FWCfgState *s, const char *filename, void *data,
216bdbb5b17SGonglei                          size_t len);
2179c4a5c55SGabriel 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);
227b2a575a1SMarc Marí bool fw_cfg_dma_enabled(void *opaque);
228600c60b7SMichael S. Tsirkin 
2293cce6243Sblueswir1 #endif
230