4 #include "exec/hwaddr.h"
5 #include "hw/nvram/fw_cfg_keys.h"
7 #include "sysemu/dma.h"
9 #define TYPE_FW_CFG "fw_cfg"
10 #define TYPE_FW_CFG_IO "fw_cfg_io"
11 #define TYPE_FW_CFG_MEM "fw_cfg_mem"
13 #define FW_CFG(obj) OBJECT_CHECK(FWCfgState, (obj), TYPE_FW_CFG)
14 #define FW_CFG_IO(obj) OBJECT_CHECK(FWCfgIoState, (obj), TYPE_FW_CFG_IO)
15 #define FW_CFG_MEM(obj) OBJECT_CHECK(FWCfgMemState, (obj), TYPE_FW_CFG_MEM)
17 typedef struct FWCfgFile
{
18 uint32_t size
; /* file size */
19 uint16_t select
; /* write this to 0x510 to read it */
21 char name
[FW_CFG_MAX_FILE_PATH
];
24 #define FW_CFG_ORDER_OVERRIDE_VGA 70
25 #define FW_CFG_ORDER_OVERRIDE_NIC 80
26 #define FW_CFG_ORDER_OVERRIDE_USER 100
27 #define FW_CFG_ORDER_OVERRIDE_DEVICE 110
29 void fw_cfg_set_order_override(FWCfgState
*fw_cfg
, int order
);
30 void fw_cfg_reset_order_override(FWCfgState
*fw_cfg
);
32 typedef struct FWCfgFiles
{
37 /* Control as first field allows for different structures selected by this
38 * field, which might be useful in the future
40 typedef struct FWCfgDmaAccess
{
44 } QEMU_PACKED FWCfgDmaAccess
;
46 typedef void (*FWCfgCallback
)(void *opaque
);
47 typedef void (*FWCfgWriteCallback
)(void *opaque
, off_t start
, size_t len
);
51 SysBusDevice parent_obj
;
55 FWCfgEntry
*entries
[2];
60 Notifier machine_ready
;
62 int fw_cfg_order_override
;
67 MemoryRegion dma_iomem
;
72 FWCfgState parent_obj
;
75 MemoryRegion comb_iomem
;
78 struct FWCfgMemState
{
80 FWCfgState parent_obj
;
83 MemoryRegion ctl_iomem
, data_iomem
;
85 MemoryRegionOps wide_data_ops
;
90 * @s: fw_cfg device being modified
91 * @key: selector key value for new fw_cfg item
92 * @data: pointer to start of item data
93 * @len: size of item data
95 * Add a new fw_cfg item, available by selecting the given key, as a raw
96 * "blob" of the given size. The data referenced by the starting pointer
97 * is only linked, NOT copied, into the data structure of the fw_cfg device.
99 void fw_cfg_add_bytes(FWCfgState
*s
, uint16_t key
, void *data
, size_t len
);
103 * @s: fw_cfg device being modified
104 * @key: selector key value for new fw_cfg item
105 * @value: NUL-terminated ascii string
107 * Add a new fw_cfg item, available by selecting the given key. The item
108 * data will consist of a dynamically allocated copy of the provided string,
109 * including its NUL terminator.
111 void fw_cfg_add_string(FWCfgState
*s
, uint16_t key
, const char *value
);
115 * @s: fw_cfg device being modified
116 * @key: selector key value for new fw_cfg item
117 * @value: 16-bit integer
119 * Add a new fw_cfg item, available by selecting the given key. The item
120 * data will consist of a dynamically allocated copy of the given 16-bit
121 * value, converted to little-endian representation.
123 void fw_cfg_add_i16(FWCfgState
*s
, uint16_t key
, uint16_t value
);
127 * @s: fw_cfg device being modified
128 * @key: selector key value for new fw_cfg item
129 * @value: 16-bit integer
131 * Replace the fw_cfg item available by selecting the given key. The new
132 * data will consist of a dynamically allocated copy of the given 16-bit
133 * value, converted to little-endian representation. The data being replaced,
134 * assumed to have been dynamically allocated during an earlier call to
135 * either fw_cfg_add_i16() or fw_cfg_modify_i16(), is freed before returning.
137 void fw_cfg_modify_i16(FWCfgState
*s
, uint16_t key
, uint16_t value
);
141 * @s: fw_cfg device being modified
142 * @key: selector key value for new fw_cfg item
143 * @value: 32-bit integer
145 * Add a new fw_cfg item, available by selecting the given key. The item
146 * data will consist of a dynamically allocated copy of the given 32-bit
147 * value, converted to little-endian representation.
149 void fw_cfg_add_i32(FWCfgState
*s
, uint16_t key
, uint32_t value
);
153 * @s: fw_cfg device being modified
154 * @key: selector key value for new fw_cfg item
155 * @value: 64-bit integer
157 * Add a new fw_cfg item, available by selecting the given key. The item
158 * data will consist of a dynamically allocated copy of the given 64-bit
159 * value, converted to little-endian representation.
161 void fw_cfg_add_i64(FWCfgState
*s
, uint16_t key
, uint64_t value
);
165 * @s: fw_cfg device being modified
166 * @filename: name of new fw_cfg file item
167 * @data: pointer to start of item data
168 * @len: size of item data
170 * Add a new NAMED fw_cfg item as a raw "blob" of the given size. The data
171 * referenced by the starting pointer is only linked, NOT copied, into the
172 * data structure of the fw_cfg device.
173 * The next available (unused) selector key starting at FW_CFG_FILE_FIRST
174 * will be used; also, a new entry will be added to the file directory
175 * structure residing at key value FW_CFG_FILE_DIR, containing the item name,
176 * data size, and assigned selector key value.
178 void fw_cfg_add_file(FWCfgState
*s
, const char *filename
, void *data
,
182 * fw_cfg_add_file_callback:
183 * @s: fw_cfg device being modified
184 * @filename: name of new fw_cfg file item
185 * @select_cb: callback function when selecting
186 * @write_cb: callback function after a write
187 * @callback_opaque: argument to be passed into callback function
188 * @data: pointer to start of item data
189 * @len: size of item data
190 * @read_only: is file read only
192 * Add a new NAMED fw_cfg item as a raw "blob" of the given size. The data
193 * referenced by the starting pointer is only linked, NOT copied, into the
194 * data structure of the fw_cfg device.
195 * The next available (unused) selector key starting at FW_CFG_FILE_FIRST
196 * will be used; also, a new entry will be added to the file directory
197 * structure residing at key value FW_CFG_FILE_DIR, containing the item name,
198 * data size, and assigned selector key value.
199 * Additionally, set a callback function (and argument) to be called each
200 * time this item is selected (by having its selector key either written to
201 * the fw_cfg control register, or passed to QEMU in FWCfgDmaAccess.control
202 * with FW_CFG_DMA_CTL_SELECT).
204 void fw_cfg_add_file_callback(FWCfgState
*s
, const char *filename
,
205 FWCfgCallback select_cb
,
206 FWCfgWriteCallback write_cb
,
207 void *callback_opaque
,
208 void *data
, size_t len
, bool read_only
);
211 * fw_cfg_modify_file:
212 * @s: fw_cfg device being modified
213 * @filename: name of new fw_cfg file item
214 * @data: pointer to start of item data
215 * @len: size of item data
217 * Replace a NAMED fw_cfg item. If an existing item is found, its callback
218 * information will be cleared, and a pointer to its data will be returned
219 * to the caller, so that it may be freed if necessary. If an existing item
220 * is not found, this call defaults to fw_cfg_add_file(), and NULL is
221 * returned to the caller.
222 * In either case, the new item data is only linked, NOT copied, into the
223 * data structure of the fw_cfg device.
225 * Returns: pointer to old item's data, or NULL if old item does not exist.
227 void *fw_cfg_modify_file(FWCfgState
*s
, const char *filename
, void *data
,
230 FWCfgState
*fw_cfg_init_io_dma(uint32_t iobase
, uint32_t dma_iobase
,
231 AddressSpace
*dma_as
);
232 FWCfgState
*fw_cfg_init_io(uint32_t iobase
);
233 FWCfgState
*fw_cfg_init_mem(hwaddr ctl_addr
, hwaddr data_addr
);
234 FWCfgState
*fw_cfg_init_mem_wide(hwaddr ctl_addr
,
235 hwaddr data_addr
, uint32_t data_width
,
236 hwaddr dma_addr
, AddressSpace
*dma_as
);
238 FWCfgState
*fw_cfg_find(void);
239 bool fw_cfg_dma_enabled(void *opaque
);