xref: /qemu/include/hw/nvram/fw_cfg.h (revision 6f6f4aec749ba9a4fb58c7c20536a61b0381ff35)
13cce6243Sblueswir1 #ifndef FW_CFG_H
23cce6243Sblueswir1 #define FW_CFG_H
33cce6243Sblueswir1 
439736e18SMark Cave-Ayland #include "qemu/typedefs.h"
51dfe5057SHu Tao #include "exec/hwaddr.h"
66f061ea1SMarkus Armbruster #include "hw/nvram/fw_cfg_keys.h"
739736e18SMark Cave-Ayland #include "hw/sysbus.h"
839736e18SMark Cave-Ayland #include "sysemu/dma.h"
939736e18SMark Cave-Ayland 
1039736e18SMark Cave-Ayland #define TYPE_FW_CFG     "fw_cfg"
1139736e18SMark Cave-Ayland #define TYPE_FW_CFG_IO  "fw_cfg_io"
1239736e18SMark Cave-Ayland #define TYPE_FW_CFG_MEM "fw_cfg_mem"
1339736e18SMark Cave-Ayland 
1439736e18SMark Cave-Ayland #define FW_CFG(obj)     OBJECT_CHECK(FWCfgState,    (obj), TYPE_FW_CFG)
1539736e18SMark Cave-Ayland #define FW_CFG_IO(obj)  OBJECT_CHECK(FWCfgIoState,  (obj), TYPE_FW_CFG_IO)
1639736e18SMark Cave-Ayland #define FW_CFG_MEM(obj) OBJECT_CHECK(FWCfgMemState, (obj), TYPE_FW_CFG_MEM)
171dfe5057SHu Tao 
18abe147e0SGerd Hoffmann typedef struct FWCfgFile {
19abe147e0SGerd Hoffmann     uint32_t  size;        /* file size */
20abe147e0SGerd Hoffmann     uint16_t  select;      /* write this to 0x510 to read it */
21abe147e0SGerd Hoffmann     uint16_t  reserved;
2235c12e60SMichael S. Tsirkin     char      name[FW_CFG_MAX_FILE_PATH];
23abe147e0SGerd Hoffmann } FWCfgFile;
24abe147e0SGerd Hoffmann 
25bab47d9aSGerd Hoffmann #define FW_CFG_ORDER_OVERRIDE_VGA    70
26bab47d9aSGerd Hoffmann #define FW_CFG_ORDER_OVERRIDE_NIC    80
27bab47d9aSGerd Hoffmann #define FW_CFG_ORDER_OVERRIDE_USER   100
28bab47d9aSGerd Hoffmann #define FW_CFG_ORDER_OVERRIDE_DEVICE 110
29bab47d9aSGerd Hoffmann 
30bab47d9aSGerd Hoffmann void fw_cfg_set_order_override(FWCfgState *fw_cfg, int order);
31bab47d9aSGerd Hoffmann void fw_cfg_reset_order_override(FWCfgState *fw_cfg);
32bab47d9aSGerd Hoffmann 
33abe147e0SGerd Hoffmann typedef struct FWCfgFiles {
34abe147e0SGerd Hoffmann     uint32_t  count;
35abe147e0SGerd Hoffmann     FWCfgFile f[];
36abe147e0SGerd Hoffmann } FWCfgFiles;
37abe147e0SGerd Hoffmann 
38a4c0d1deSMarc Marí /* Control as first field allows for different structures selected by this
39a4c0d1deSMarc Marí  * field, which might be useful in the future
40a4c0d1deSMarc Marí  */
41a4c0d1deSMarc Marí typedef struct FWCfgDmaAccess {
42a4c0d1deSMarc Marí     uint32_t control;
43a4c0d1deSMarc Marí     uint32_t length;
44a4c0d1deSMarc Marí     uint64_t address;
45a4c0d1deSMarc Marí } QEMU_PACKED FWCfgDmaAccess;
46a4c0d1deSMarc Marí 
47*6f6f4aecSMarc-André Lureau typedef void (*FWCfgCallback)(void *opaque);
483cce6243Sblueswir1 
4939736e18SMark Cave-Ayland struct FWCfgState {
5039736e18SMark Cave-Ayland     /*< private >*/
5139736e18SMark Cave-Ayland     SysBusDevice parent_obj;
5239736e18SMark Cave-Ayland     /*< public >*/
5339736e18SMark Cave-Ayland 
5439736e18SMark Cave-Ayland     uint16_t file_slots;
5539736e18SMark Cave-Ayland     FWCfgEntry *entries[2];
5639736e18SMark Cave-Ayland     int *entry_order;
5739736e18SMark Cave-Ayland     FWCfgFiles *files;
5839736e18SMark Cave-Ayland     uint16_t cur_entry;
5939736e18SMark Cave-Ayland     uint32_t cur_offset;
6039736e18SMark Cave-Ayland     Notifier machine_ready;
6139736e18SMark Cave-Ayland 
6239736e18SMark Cave-Ayland     int fw_cfg_order_override;
6339736e18SMark Cave-Ayland 
6439736e18SMark Cave-Ayland     bool dma_enabled;
6539736e18SMark Cave-Ayland     dma_addr_t dma_addr;
6639736e18SMark Cave-Ayland     AddressSpace *dma_as;
6739736e18SMark Cave-Ayland     MemoryRegion dma_iomem;
6839736e18SMark Cave-Ayland };
6939736e18SMark Cave-Ayland 
7039736e18SMark Cave-Ayland struct FWCfgIoState {
7139736e18SMark Cave-Ayland     /*< private >*/
7239736e18SMark Cave-Ayland     FWCfgState parent_obj;
7339736e18SMark Cave-Ayland     /*< public >*/
7439736e18SMark Cave-Ayland 
7539736e18SMark Cave-Ayland     MemoryRegion comb_iomem;
7639736e18SMark Cave-Ayland };
7739736e18SMark Cave-Ayland 
7839736e18SMark Cave-Ayland struct FWCfgMemState {
7939736e18SMark Cave-Ayland     /*< private >*/
8039736e18SMark Cave-Ayland     FWCfgState parent_obj;
8139736e18SMark Cave-Ayland     /*< public >*/
8239736e18SMark Cave-Ayland 
8339736e18SMark Cave-Ayland     MemoryRegion ctl_iomem, data_iomem;
8439736e18SMark Cave-Ayland     uint32_t data_width;
8539736e18SMark Cave-Ayland     MemoryRegionOps wide_data_ops;
8639736e18SMark Cave-Ayland };
8739736e18SMark Cave-Ayland 
889c4a5c55SGabriel L. Somlo /**
899c4a5c55SGabriel L. Somlo  * fw_cfg_add_bytes:
909c4a5c55SGabriel L. Somlo  * @s: fw_cfg device being modified
919c4a5c55SGabriel L. Somlo  * @key: selector key value for new fw_cfg item
929c4a5c55SGabriel L. Somlo  * @data: pointer to start of item data
939c4a5c55SGabriel L. Somlo  * @len: size of item data
949c4a5c55SGabriel L. Somlo  *
959c4a5c55SGabriel L. Somlo  * Add a new fw_cfg item, available by selecting the given key, as a raw
969c4a5c55SGabriel L. Somlo  * "blob" of the given size. The data referenced by the starting pointer
979c4a5c55SGabriel L. Somlo  * is only linked, NOT copied, into the data structure of the fw_cfg device.
989c4a5c55SGabriel L. Somlo  */
99089da572SMarkus Armbruster void fw_cfg_add_bytes(FWCfgState *s, uint16_t key, void *data, size_t len);
1009c4a5c55SGabriel L. Somlo 
1019c4a5c55SGabriel L. Somlo /**
1029c4a5c55SGabriel L. Somlo  * fw_cfg_add_string:
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: NUL-terminated ascii string
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 provided string,
1099c4a5c55SGabriel L. Somlo  * including its NUL terminator.
1109c4a5c55SGabriel L. Somlo  */
11144687f75SMarkus Armbruster void fw_cfg_add_string(FWCfgState *s, uint16_t key, const char *value);
1129c4a5c55SGabriel L. Somlo 
1139c4a5c55SGabriel L. Somlo /**
1149c4a5c55SGabriel L. Somlo  * fw_cfg_add_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  * Add a new fw_cfg item, available by selecting the given key. The item
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.
1229c4a5c55SGabriel L. Somlo  */
1234cad3867SMarkus Armbruster void fw_cfg_add_i16(FWCfgState *s, uint16_t key, uint16_t value);
1249c4a5c55SGabriel L. Somlo 
1259c4a5c55SGabriel L. Somlo /**
1269c4a5c55SGabriel L. Somlo  * fw_cfg_modify_i16:
1279c4a5c55SGabriel L. Somlo  * @s: fw_cfg device being modified
1289c4a5c55SGabriel L. Somlo  * @key: selector key value for new fw_cfg item
1299c4a5c55SGabriel L. Somlo  * @value: 16-bit integer
1309c4a5c55SGabriel L. Somlo  *
1319c4a5c55SGabriel L. Somlo  * Replace the fw_cfg item available by selecting the given key. The new
1329c4a5c55SGabriel L. Somlo  * data will consist of a dynamically allocated copy of the given 16-bit
1339c4a5c55SGabriel L. Somlo  * value, converted to little-endian representation. The data being replaced,
1349c4a5c55SGabriel L. Somlo  * assumed to have been dynamically allocated during an earlier call to
1359c4a5c55SGabriel L. Somlo  * either fw_cfg_add_i16() or fw_cfg_modify_i16(), is freed before returning.
1369c4a5c55SGabriel L. Somlo  */
1371edd34b6SGabriel L. Somlo void fw_cfg_modify_i16(FWCfgState *s, uint16_t key, uint16_t value);
1389c4a5c55SGabriel L. Somlo 
1399c4a5c55SGabriel L. Somlo /**
1409c4a5c55SGabriel L. Somlo  * fw_cfg_add_i32:
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: 32-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 32-bit
1479c4a5c55SGabriel L. Somlo  * value, converted to little-endian representation.
1489c4a5c55SGabriel L. Somlo  */
1494cad3867SMarkus Armbruster void fw_cfg_add_i32(FWCfgState *s, uint16_t key, uint32_t value);
1509c4a5c55SGabriel L. Somlo 
1519c4a5c55SGabriel L. Somlo /**
1529c4a5c55SGabriel L. Somlo  * fw_cfg_add_i64:
1539c4a5c55SGabriel L. Somlo  * @s: fw_cfg device being modified
1549c4a5c55SGabriel L. Somlo  * @key: selector key value for new fw_cfg item
1559c4a5c55SGabriel L. Somlo  * @value: 64-bit integer
1569c4a5c55SGabriel L. Somlo  *
1579c4a5c55SGabriel L. Somlo  * Add a new fw_cfg item, available by selecting the given key. The item
1589c4a5c55SGabriel L. Somlo  * data will consist of a dynamically allocated copy of the given 64-bit
1599c4a5c55SGabriel L. Somlo  * value, converted to little-endian representation.
1609c4a5c55SGabriel L. Somlo  */
1614cad3867SMarkus Armbruster void fw_cfg_add_i64(FWCfgState *s, uint16_t key, uint64_t value);
1629c4a5c55SGabriel L. Somlo 
1639c4a5c55SGabriel L. Somlo /**
1649c4a5c55SGabriel L. Somlo  * fw_cfg_add_file:
1659c4a5c55SGabriel L. Somlo  * @s: fw_cfg device being modified
1669c4a5c55SGabriel L. Somlo  * @filename: name of new fw_cfg file item
1679c4a5c55SGabriel L. Somlo  * @data: pointer to start of item data
1689c4a5c55SGabriel L. Somlo  * @len: size of item data
1699c4a5c55SGabriel L. Somlo  *
1709c4a5c55SGabriel L. Somlo  * Add a new NAMED fw_cfg item as a raw "blob" of the given size. The data
1719c4a5c55SGabriel L. Somlo  * referenced by the starting pointer is only linked, NOT copied, into the
1729c4a5c55SGabriel L. Somlo  * data structure of the fw_cfg device.
1739c4a5c55SGabriel L. Somlo  * The next available (unused) selector key starting at FW_CFG_FILE_FIRST
1749c4a5c55SGabriel L. Somlo  * will be used; also, a new entry will be added to the file directory
1759c4a5c55SGabriel L. Somlo  * structure residing at key value FW_CFG_FILE_DIR, containing the item name,
1769c4a5c55SGabriel L. Somlo  * data size, and assigned selector key value.
1779c4a5c55SGabriel L. Somlo  */
178089da572SMarkus Armbruster void fw_cfg_add_file(FWCfgState *s, const char *filename, void *data,
179089da572SMarkus Armbruster                      size_t len);
1809c4a5c55SGabriel L. Somlo 
1819c4a5c55SGabriel L. Somlo /**
1829c4a5c55SGabriel L. Somlo  * fw_cfg_add_file_callback:
1839c4a5c55SGabriel L. Somlo  * @s: fw_cfg device being modified
1849c4a5c55SGabriel L. Somlo  * @filename: name of new fw_cfg file item
185*6f6f4aecSMarc-André Lureau  * @select_cb: callback function when selecting
1869c4a5c55SGabriel L. Somlo  * @callback_opaque: argument to be passed into callback function
1879c4a5c55SGabriel L. Somlo  * @data: pointer to start of item data
1889c4a5c55SGabriel L. Somlo  * @len: size of item data
189baf2d5bfSMichael S. Tsirkin  * @read_only: is file read only
1909c4a5c55SGabriel L. Somlo  *
1919c4a5c55SGabriel L. Somlo  * Add a new NAMED fw_cfg item as a raw "blob" of the given size. The data
1929c4a5c55SGabriel L. Somlo  * referenced by the starting pointer is only linked, NOT copied, into the
1939c4a5c55SGabriel L. Somlo  * data structure of the fw_cfg device.
1949c4a5c55SGabriel L. Somlo  * The next available (unused) selector key starting at FW_CFG_FILE_FIRST
1959c4a5c55SGabriel L. Somlo  * will be used; also, a new entry will be added to the file directory
1969c4a5c55SGabriel L. Somlo  * structure residing at key value FW_CFG_FILE_DIR, containing the item name,
1979c4a5c55SGabriel L. Somlo  * data size, and assigned selector key value.
1989c4a5c55SGabriel L. Somlo  * Additionally, set a callback function (and argument) to be called each
1993bef7e8aSGabriel L. Somlo  * time this item is selected (by having its selector key either written to
2003bef7e8aSGabriel L. Somlo  * the fw_cfg control register, or passed to QEMU in FWCfgDmaAccess.control
2013bef7e8aSGabriel L. Somlo  * with FW_CFG_DMA_CTL_SELECT).
2029c4a5c55SGabriel L. Somlo  */
203d87072ceSMichael S. Tsirkin void fw_cfg_add_file_callback(FWCfgState *s, const char *filename,
204*6f6f4aecSMarc-André Lureau                               FWCfgCallback select_cb,
205*6f6f4aecSMarc-André Lureau                               void *callback_opaque,
206baf2d5bfSMichael S. Tsirkin                               void *data, size_t len, bool read_only);
2079c4a5c55SGabriel L. Somlo 
2089c4a5c55SGabriel L. Somlo /**
2099c4a5c55SGabriel L. Somlo  * fw_cfg_modify_file:
2109c4a5c55SGabriel L. Somlo  * @s: fw_cfg device being modified
2119c4a5c55SGabriel L. Somlo  * @filename: name of new fw_cfg file item
2129c4a5c55SGabriel L. Somlo  * @data: pointer to start of item data
2139c4a5c55SGabriel L. Somlo  * @len: size of item data
2149c4a5c55SGabriel L. Somlo  *
2159c4a5c55SGabriel L. Somlo  * Replace a NAMED fw_cfg item. If an existing item is found, its callback
2169c4a5c55SGabriel L. Somlo  * information will be cleared, and a pointer to its data will be returned
2179c4a5c55SGabriel L. Somlo  * to the caller, so that it may be freed if necessary. If an existing item
2189c4a5c55SGabriel L. Somlo  * is not found, this call defaults to fw_cfg_add_file(), and NULL is
2199c4a5c55SGabriel L. Somlo  * returned to the caller.
2209c4a5c55SGabriel L. Somlo  * In either case, the new item data is only linked, NOT copied, into the
2219c4a5c55SGabriel L. Somlo  * data structure of the fw_cfg device.
2229c4a5c55SGabriel L. Somlo  *
2239c4a5c55SGabriel L. Somlo  * Returns: pointer to old item's data, or NULL if old item does not exist.
2249c4a5c55SGabriel L. Somlo  */
225bdbb5b17SGonglei void *fw_cfg_modify_file(FWCfgState *s, const char *filename, void *data,
226bdbb5b17SGonglei                          size_t len);
2279c4a5c55SGabriel L. Somlo 
228a4c0d1deSMarc Marí FWCfgState *fw_cfg_init_io_dma(uint32_t iobase, uint32_t dma_iobase,
229a4c0d1deSMarc Marí                                 AddressSpace *dma_as);
2305712db6aSLaszlo Ersek FWCfgState *fw_cfg_init_io(uint32_t iobase);
2315712db6aSLaszlo Ersek FWCfgState *fw_cfg_init_mem(hwaddr ctl_addr, hwaddr data_addr);
232a4c0d1deSMarc Marí FWCfgState *fw_cfg_init_mem_wide(hwaddr ctl_addr,
233a4c0d1deSMarc Marí                                  hwaddr data_addr, uint32_t data_width,
234a4c0d1deSMarc Marí                                  hwaddr dma_addr, AddressSpace *dma_as);
2353cce6243Sblueswir1 
236600c60b7SMichael S. Tsirkin FWCfgState *fw_cfg_find(void);
237b2a575a1SMarc Marí bool fw_cfg_dma_enabled(void *opaque);
238600c60b7SMichael S. Tsirkin 
2393cce6243Sblueswir1 #endif
240