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"
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 fw_cfg_file FWCfgFile;
19 #define FW_CFG_ORDER_OVERRIDE_VGA 70
20 #define FW_CFG_ORDER_OVERRIDE_NIC 80
21 #define FW_CFG_ORDER_OVERRIDE_USER 100
22 #define FW_CFG_ORDER_OVERRIDE_DEVICE 110
24 void fw_cfg_set_order_override(FWCfgState *fw_cfg, int order);
25 void fw_cfg_reset_order_override(FWCfgState *fw_cfg);
27 typedef struct FWCfgFiles {
32 typedef struct fw_cfg_dma_access FWCfgDmaAccess;
34 typedef void (*FWCfgCallback)(void *opaque);
35 typedef void (*FWCfgWriteCallback)(void *opaque, off_t start, size_t len);
39 SysBusDevice parent_obj;
43 FWCfgEntry *entries[2];
48 Notifier machine_ready;
50 int fw_cfg_order_override;
55 MemoryRegion dma_iomem;
60 FWCfgState parent_obj;
63 MemoryRegion comb_iomem;
66 struct FWCfgMemState {
68 FWCfgState parent_obj;
71 MemoryRegion ctl_iomem, data_iomem;
73 MemoryRegionOps wide_data_ops;
78 * @s: fw_cfg device being modified
79 * @key: selector key value for new fw_cfg item
80 * @data: pointer to start of item data
81 * @len: size of item data
83 * Add a new fw_cfg item, available by selecting the given key, as a raw
84 * "blob" of the given size. The data referenced by the starting pointer
85 * is only linked, NOT copied, into the data structure of the fw_cfg device.
87 void fw_cfg_add_bytes(FWCfgState *s, uint16_t key, void *data, size_t len);
91 * @s: fw_cfg device being modified
92 * @key: selector key value for new fw_cfg item
93 * @value: NUL-terminated ascii string
95 * Add a new fw_cfg item, available by selecting the given key. The item
96 * data will consist of a dynamically allocated copy of the provided string,
97 * including its NUL terminator.
99 void fw_cfg_add_string(FWCfgState *s, uint16_t key, const char *value);
102 * fw_cfg_modify_string:
103 * @s: fw_cfg device being modified
104 * @key: selector key value for new fw_cfg item
105 * @value: NUL-terminated ascii string
107 * Replace the fw_cfg item available by selecting the given key. The new
108 * data will consist of a dynamically allocated copy of the provided string,
109 * including its NUL terminator. The data being replaced, assumed to have
110 * been dynamically allocated during an earlier call to either
111 * fw_cfg_add_string() or fw_cfg_modify_string(), is freed before returning.
113 void fw_cfg_modify_string(FWCfgState *s, uint16_t key, const char *value);
117 * @s: fw_cfg device being modified
118 * @key: selector key value for new fw_cfg item
119 * @value: 16-bit integer
121 * Add a new fw_cfg item, available by selecting the given key. The item
122 * data will consist of a dynamically allocated copy of the given 16-bit
123 * value, converted to little-endian representation.
125 void fw_cfg_add_i16(FWCfgState *s, uint16_t key, uint16_t value);
129 * @s: fw_cfg device being modified
130 * @key: selector key value for new fw_cfg item
131 * @value: 16-bit integer
133 * Replace the fw_cfg item available by selecting the given key. The new
134 * data will consist of a dynamically allocated copy of the given 16-bit
135 * value, converted to little-endian representation. The data being replaced,
136 * assumed to have been dynamically allocated during an earlier call to
137 * either fw_cfg_add_i16() or fw_cfg_modify_i16(), is freed before returning.
139 void fw_cfg_modify_i16(FWCfgState *s, uint16_t key, uint16_t value);
143 * @s: fw_cfg device being modified
144 * @key: selector key value for new fw_cfg item
145 * @value: 32-bit integer
147 * Add a new fw_cfg item, available by selecting the given key. The item
148 * data will consist of a dynamically allocated copy of the given 32-bit
149 * value, converted to little-endian representation.
151 void fw_cfg_add_i32(FWCfgState *s, uint16_t key, uint32_t value);
155 * @s: fw_cfg device being modified
156 * @key: selector key value for new fw_cfg item
157 * @value: 32-bit integer
159 * Replace the fw_cfg item available by selecting the given key. The new
160 * data will consist of a dynamically allocated copy of the given 32-bit
161 * value, converted to little-endian representation. The data being replaced,
162 * assumed to have been dynamically allocated during an earlier call to
163 * either fw_cfg_add_i32() or fw_cfg_modify_i32(), is freed before returning.
165 void fw_cfg_modify_i32(FWCfgState *s, uint16_t key, uint32_t value);
169 * @s: fw_cfg device being modified
170 * @key: selector key value for new fw_cfg item
171 * @value: 64-bit integer
173 * Add a new fw_cfg item, available by selecting the given key. The item
174 * data will consist of a dynamically allocated copy of the given 64-bit
175 * value, converted to little-endian representation.
177 void fw_cfg_add_i64(FWCfgState *s, uint16_t key, uint64_t value);
181 * @s: fw_cfg device being modified
182 * @key: selector key value for new fw_cfg item
183 * @value: 64-bit integer
185 * Replace the fw_cfg item available by selecting the given key. The new
186 * data will consist of a dynamically allocated copy of the given 64-bit
187 * value, converted to little-endian representation. The data being replaced,
188 * assumed to have been dynamically allocated during an earlier call to
189 * either fw_cfg_add_i64() or fw_cfg_modify_i64(), is freed before returning.
191 void fw_cfg_modify_i64(FWCfgState *s, uint16_t key, uint64_t value);
195 * @s: fw_cfg device being modified
196 * @filename: name of new fw_cfg file item
197 * @data: pointer to start of item data
198 * @len: size of item data
200 * Add a new NAMED fw_cfg item as a raw "blob" of the given size. The data
201 * referenced by the starting pointer is only linked, NOT copied, into the
202 * data structure of the fw_cfg device.
203 * The next available (unused) selector key starting at FW_CFG_FILE_FIRST
204 * will be used; also, a new entry will be added to the file directory
205 * structure residing at key value FW_CFG_FILE_DIR, containing the item name,
206 * data size, and assigned selector key value.
208 void fw_cfg_add_file(FWCfgState *s, const char *filename, void *data,
212 * fw_cfg_add_file_callback:
213 * @s: fw_cfg device being modified
214 * @filename: name of new fw_cfg file item
215 * @select_cb: callback function when selecting
216 * @write_cb: callback function after a write
217 * @callback_opaque: argument to be passed into callback function
218 * @data: pointer to start of item data
219 * @len: size of item data
220 * @read_only: is file read only
222 * Add a new NAMED fw_cfg item as a raw "blob" of the given size. The data
223 * referenced by the starting pointer is only linked, NOT copied, into the
224 * data structure of the fw_cfg device.
225 * The next available (unused) selector key starting at FW_CFG_FILE_FIRST
226 * will be used; also, a new entry will be added to the file directory
227 * structure residing at key value FW_CFG_FILE_DIR, containing the item name,
228 * data size, and assigned selector key value.
229 * Additionally, set a callback function (and argument) to be called each
230 * time this item is selected (by having its selector key either written to
231 * the fw_cfg control register, or passed to QEMU in FWCfgDmaAccess.control
232 * with FW_CFG_DMA_CTL_SELECT).
234 void fw_cfg_add_file_callback(FWCfgState *s, const char *filename,
235 FWCfgCallback select_cb,
236 FWCfgWriteCallback write_cb,
237 void *callback_opaque,
238 void *data, size_t len, bool read_only);
241 * fw_cfg_modify_file:
242 * @s: fw_cfg device being modified
243 * @filename: name of new fw_cfg file item
244 * @data: pointer to start of item data
245 * @len: size of item data
247 * Replace a NAMED fw_cfg item. If an existing item is found, its callback
248 * information will be cleared, and a pointer to its data will be returned
249 * to the caller, so that it may be freed if necessary. If an existing item
250 * is not found, this call defaults to fw_cfg_add_file(), and NULL is
251 * returned to the caller.
252 * In either case, the new item data is only linked, NOT copied, into the
253 * data structure of the fw_cfg device.
255 * Returns: pointer to old item's data, or NULL if old item does not exist.
257 void *fw_cfg_modify_file(FWCfgState *s, const char *filename, void *data,
260 FWCfgState *fw_cfg_init_io_dma(uint32_t iobase, uint32_t dma_iobase,
261 AddressSpace *dma_as);
262 FWCfgState *fw_cfg_init_io(uint32_t iobase);
263 FWCfgState *fw_cfg_init_mem(hwaddr ctl_addr, hwaddr data_addr);
264 FWCfgState *fw_cfg_init_mem_wide(hwaddr ctl_addr,
265 hwaddr data_addr, uint32_t data_width,
266 hwaddr dma_addr, AddressSpace *dma_as);
268 FWCfgState *fw_cfg_find(void);
269 bool fw_cfg_dma_enabled(void *opaque);
272 * fw_cfg_arch_key_name:
274 * @key: The uint16 selector key.
276 * The key is architecture-specific (the FW_CFG_ARCH_LOCAL mask is expected
277 * to be set in the key).
279 * Returns: The stringified architecture-specific name if the selector
280 * refers to a well-known numerically defined item, or NULL on
281 * key lookup failure.
283 const char *fw_cfg_arch_key_name(uint16_t key);