4 #include "exec/hwaddr.h"
5 #include "standard-headers/linux/qemu_fw_cfg.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"
12 #define TYPE_FW_CFG_DATA_GENERATOR_INTERFACE "fw_cfg-data-generator"
14 #define FW_CFG(obj) OBJECT_CHECK(FWCfgState, (obj), TYPE_FW_CFG)
15 #define FW_CFG_IO(obj) OBJECT_CHECK(FWCfgIoState, (obj), TYPE_FW_CFG_IO)
16 #define FW_CFG_MEM(obj) OBJECT_CHECK(FWCfgMemState, (obj), TYPE_FW_CFG_MEM)
18 #define FW_CFG_DATA_GENERATOR_CLASS(class) \
19 OBJECT_CLASS_CHECK(FWCfgDataGeneratorClass, (class), \
20 TYPE_FW_CFG_DATA_GENERATOR_INTERFACE)
21 #define FW_CFG_DATA_GENERATOR_GET_CLASS(obj) \
22 OBJECT_GET_CLASS(FWCfgDataGeneratorClass, (obj), \
23 TYPE_FW_CFG_DATA_GENERATOR_INTERFACE)
25 typedef struct FWCfgDataGeneratorClass
{
27 InterfaceClass parent_class
;
32 * @obj: the object implementing this interface
33 * @errp: pointer to a NULL-initialized error object
35 * Returns: reference to a byte array containing the data on success,
38 * The caller should release the reference when no longer
41 GByteArray
*(*get_data
)(Object
*obj
, Error
**errp
);
42 } FWCfgDataGeneratorClass
;
44 typedef struct fw_cfg_file FWCfgFile
;
46 #define FW_CFG_ORDER_OVERRIDE_VGA 70
47 #define FW_CFG_ORDER_OVERRIDE_NIC 80
48 #define FW_CFG_ORDER_OVERRIDE_USER 100
49 #define FW_CFG_ORDER_OVERRIDE_DEVICE 110
51 void fw_cfg_set_order_override(FWCfgState
*fw_cfg
, int order
);
52 void fw_cfg_reset_order_override(FWCfgState
*fw_cfg
);
54 typedef struct FWCfgFiles
{
59 typedef struct fw_cfg_dma_access FWCfgDmaAccess
;
61 typedef void (*FWCfgCallback
)(void *opaque
);
62 typedef void (*FWCfgWriteCallback
)(void *opaque
, off_t start
, size_t len
);
66 SysBusDevice parent_obj
;
70 FWCfgEntry
*entries
[2];
75 Notifier machine_ready
;
77 int fw_cfg_order_override
;
82 MemoryRegion dma_iomem
;
84 /* restore during migration */
86 uint64_t table_mr_size
;
87 uint64_t linker_mr_size
;
88 uint64_t rsdp_mr_size
;
93 FWCfgState parent_obj
;
96 MemoryRegion comb_iomem
;
99 struct FWCfgMemState
{
101 FWCfgState parent_obj
;
104 MemoryRegion ctl_iomem
, data_iomem
;
106 MemoryRegionOps wide_data_ops
;
111 * @s: fw_cfg device being modified
112 * @key: selector key value for new fw_cfg item
113 * @data: pointer to start of item data
114 * @len: size of item data
116 * Add a new fw_cfg item, available by selecting the given key, as a raw
117 * "blob" of the given size. The data referenced by the starting pointer
118 * is only linked, NOT copied, into the data structure of the fw_cfg device.
120 void fw_cfg_add_bytes(FWCfgState
*s
, uint16_t key
, void *data
, size_t len
);
124 * @s: fw_cfg device being modified
125 * @key: selector key value for new fw_cfg item
126 * @value: NUL-terminated ascii string
128 * Add a new fw_cfg item, available by selecting the given key. The item
129 * data will consist of a dynamically allocated copy of the provided string,
130 * including its NUL terminator.
132 void fw_cfg_add_string(FWCfgState
*s
, uint16_t key
, const char *value
);
135 * fw_cfg_modify_string:
136 * @s: fw_cfg device being modified
137 * @key: selector key value for new fw_cfg item
138 * @value: NUL-terminated ascii string
140 * Replace the fw_cfg item available by selecting the given key. The new
141 * data will consist of a dynamically allocated copy of the provided string,
142 * including its NUL terminator. The data being replaced, assumed to have
143 * been dynamically allocated during an earlier call to either
144 * fw_cfg_add_string() or fw_cfg_modify_string(), is freed before returning.
146 void fw_cfg_modify_string(FWCfgState
*s
, uint16_t key
, const char *value
);
150 * @s: fw_cfg device being modified
151 * @key: selector key value for new fw_cfg item
152 * @value: 16-bit integer
154 * Add a new fw_cfg item, available by selecting the given key. The item
155 * data will consist of a dynamically allocated copy of the given 16-bit
156 * value, converted to little-endian representation.
158 void fw_cfg_add_i16(FWCfgState
*s
, uint16_t key
, uint16_t value
);
162 * @s: fw_cfg device being modified
163 * @key: selector key value for new fw_cfg item
164 * @value: 16-bit integer
166 * Replace the fw_cfg item available by selecting the given key. The new
167 * data will consist of a dynamically allocated copy of the given 16-bit
168 * value, converted to little-endian representation. The data being replaced,
169 * assumed to have been dynamically allocated during an earlier call to
170 * either fw_cfg_add_i16() or fw_cfg_modify_i16(), is freed before returning.
172 void fw_cfg_modify_i16(FWCfgState
*s
, uint16_t key
, uint16_t value
);
176 * @s: fw_cfg device being modified
177 * @key: selector key value for new fw_cfg item
178 * @value: 32-bit integer
180 * Add a new fw_cfg item, available by selecting the given key. The item
181 * data will consist of a dynamically allocated copy of the given 32-bit
182 * value, converted to little-endian representation.
184 void fw_cfg_add_i32(FWCfgState
*s
, uint16_t key
, uint32_t value
);
188 * @s: fw_cfg device being modified
189 * @key: selector key value for new fw_cfg item
190 * @value: 32-bit integer
192 * Replace the fw_cfg item available by selecting the given key. The new
193 * data will consist of a dynamically allocated copy of the given 32-bit
194 * value, converted to little-endian representation. The data being replaced,
195 * assumed to have been dynamically allocated during an earlier call to
196 * either fw_cfg_add_i32() or fw_cfg_modify_i32(), is freed before returning.
198 void fw_cfg_modify_i32(FWCfgState
*s
, uint16_t key
, uint32_t value
);
202 * @s: fw_cfg device being modified
203 * @key: selector key value for new fw_cfg item
204 * @value: 64-bit integer
206 * Add a new fw_cfg item, available by selecting the given key. The item
207 * data will consist of a dynamically allocated copy of the given 64-bit
208 * value, converted to little-endian representation.
210 void fw_cfg_add_i64(FWCfgState
*s
, uint16_t key
, uint64_t value
);
214 * @s: fw_cfg device being modified
215 * @key: selector key value for new fw_cfg item
216 * @value: 64-bit integer
218 * Replace the fw_cfg item available by selecting the given key. The new
219 * data will consist of a dynamically allocated copy of the given 64-bit
220 * value, converted to little-endian representation. The data being replaced,
221 * assumed to have been dynamically allocated during an earlier call to
222 * either fw_cfg_add_i64() or fw_cfg_modify_i64(), is freed before returning.
224 void fw_cfg_modify_i64(FWCfgState
*s
, uint16_t key
, uint64_t value
);
228 * @s: fw_cfg device being modified
229 * @filename: name of new fw_cfg file item
230 * @data: pointer to start of item data
231 * @len: size of item data
233 * Add a new NAMED fw_cfg item as a raw "blob" of the given size. The data
234 * referenced by the starting pointer is only linked, NOT copied, into the
235 * data structure of the fw_cfg device.
236 * The next available (unused) selector key starting at FW_CFG_FILE_FIRST
237 * will be used; also, a new entry will be added to the file directory
238 * structure residing at key value FW_CFG_FILE_DIR, containing the item name,
239 * data size, and assigned selector key value.
241 void fw_cfg_add_file(FWCfgState
*s
, const char *filename
, void *data
,
245 * fw_cfg_add_file_callback:
246 * @s: fw_cfg device being modified
247 * @filename: name of new fw_cfg file item
248 * @select_cb: callback function when selecting
249 * @write_cb: callback function after a write
250 * @callback_opaque: argument to be passed into callback function
251 * @data: pointer to start of item data
252 * @len: size of item data
253 * @read_only: is file read only
255 * Add a new NAMED fw_cfg item as a raw "blob" of the given size. The data
256 * referenced by the starting pointer is only linked, NOT copied, into the
257 * data structure of the fw_cfg device.
258 * The next available (unused) selector key starting at FW_CFG_FILE_FIRST
259 * will be used; also, a new entry will be added to the file directory
260 * structure residing at key value FW_CFG_FILE_DIR, containing the item name,
261 * data size, and assigned selector key value.
262 * Additionally, set a callback function (and argument) to be called each
263 * time this item is selected (by having its selector key either written to
264 * the fw_cfg control register, or passed to QEMU in FWCfgDmaAccess.control
265 * with FW_CFG_DMA_CTL_SELECT).
267 void fw_cfg_add_file_callback(FWCfgState
*s
, const char *filename
,
268 FWCfgCallback select_cb
,
269 FWCfgWriteCallback write_cb
,
270 void *callback_opaque
,
271 void *data
, size_t len
, bool read_only
);
274 * fw_cfg_modify_file:
275 * @s: fw_cfg device being modified
276 * @filename: name of new fw_cfg file item
277 * @data: pointer to start of item data
278 * @len: size of item data
280 * Replace a NAMED fw_cfg item. If an existing item is found, its callback
281 * information will be cleared, and a pointer to its data will be returned
282 * to the caller, so that it may be freed if necessary. If an existing item
283 * is not found, this call defaults to fw_cfg_add_file(), and NULL is
284 * returned to the caller.
285 * In either case, the new item data is only linked, NOT copied, into the
286 * data structure of the fw_cfg device.
288 * Returns: pointer to old item's data, or NULL if old item does not exist.
290 void *fw_cfg_modify_file(FWCfgState
*s
, const char *filename
, void *data
,
294 * fw_cfg_add_from_generator:
295 * @s: fw_cfg device being modified
296 * @filename: name of new fw_cfg file item
297 * @gen_id: name of object implementing FW_CFG_DATA_GENERATOR interface
298 * @errp: pointer to a NULL initialized error object
300 * Add a new NAMED fw_cfg item with the content generated from the
301 * @gen_id object. The data generated by the @gen_id object is copied
302 * into the data structure of the fw_cfg device.
303 * The next available (unused) selector key starting at FW_CFG_FILE_FIRST
304 * will be used; also, a new entry will be added to the file directory
305 * structure residing at key value FW_CFG_FILE_DIR, containing the item name,
306 * data size, and assigned selector key value.
308 * Returns: %true on success, %false on error.
310 bool fw_cfg_add_from_generator(FWCfgState
*s
, const char *filename
,
311 const char *gen_id
, Error
**errp
);
313 FWCfgState
*fw_cfg_init_io_dma(uint32_t iobase
, uint32_t dma_iobase
,
314 AddressSpace
*dma_as
);
315 FWCfgState
*fw_cfg_init_io(uint32_t iobase
);
316 FWCfgState
*fw_cfg_init_mem(hwaddr ctl_addr
, hwaddr data_addr
);
317 FWCfgState
*fw_cfg_init_mem_wide(hwaddr ctl_addr
,
318 hwaddr data_addr
, uint32_t data_width
,
319 hwaddr dma_addr
, AddressSpace
*dma_as
);
321 FWCfgState
*fw_cfg_find(void);
322 bool fw_cfg_dma_enabled(void *opaque
);
325 * fw_cfg_arch_key_name:
327 * @key: The uint16 selector key.
329 * The key is architecture-specific (the FW_CFG_ARCH_LOCAL mask is expected
330 * to be set in the key).
332 * Returns: The stringified architecture-specific name if the selector
333 * refers to a well-known numerically defined item, or NULL on
334 * key lookup failure.
336 const char *fw_cfg_arch_key_name(uint16_t key
);