hw/nvram/fw_cfg: Add the FW_CFG_DATA_GENERATOR interface
[qemu/ar7.git] / include / hw / nvram / fw_cfg.h
blob11feae317748c1e2f186f220595f9b38f71f14e8
1 #ifndef FW_CFG_H
2 #define FW_CFG_H
4 #include "exec/hwaddr.h"
5 #include "standard-headers/linux/qemu_fw_cfg.h"
6 #include "hw/sysbus.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 {
26 /*< private >*/
27 InterfaceClass parent_class;
28 /*< public >*/
30 /**
31 * get_data:
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.
36 * The caller should release the reference when no longer
37 * required.
39 GByteArray *(*get_data)(Object *obj, Error **errp);
40 } FWCfgDataGeneratorClass;
42 typedef struct fw_cfg_file FWCfgFile;
44 #define FW_CFG_ORDER_OVERRIDE_VGA 70
45 #define FW_CFG_ORDER_OVERRIDE_NIC 80
46 #define FW_CFG_ORDER_OVERRIDE_USER 100
47 #define FW_CFG_ORDER_OVERRIDE_DEVICE 110
49 void fw_cfg_set_order_override(FWCfgState *fw_cfg, int order);
50 void fw_cfg_reset_order_override(FWCfgState *fw_cfg);
52 typedef struct FWCfgFiles {
53 uint32_t count;
54 FWCfgFile f[];
55 } FWCfgFiles;
57 typedef struct fw_cfg_dma_access FWCfgDmaAccess;
59 typedef void (*FWCfgCallback)(void *opaque);
60 typedef void (*FWCfgWriteCallback)(void *opaque, off_t start, size_t len);
62 struct FWCfgState {
63 /*< private >*/
64 SysBusDevice parent_obj;
65 /*< public >*/
67 uint16_t file_slots;
68 FWCfgEntry *entries[2];
69 int *entry_order;
70 FWCfgFiles *files;
71 uint16_t cur_entry;
72 uint32_t cur_offset;
73 Notifier machine_ready;
75 int fw_cfg_order_override;
77 bool dma_enabled;
78 dma_addr_t dma_addr;
79 AddressSpace *dma_as;
80 MemoryRegion dma_iomem;
82 /* restore during migration */
83 bool acpi_mr_restore;
84 uint64_t table_mr_size;
85 uint64_t linker_mr_size;
86 uint64_t rsdp_mr_size;
89 struct FWCfgIoState {
90 /*< private >*/
91 FWCfgState parent_obj;
92 /*< public >*/
94 MemoryRegion comb_iomem;
97 struct FWCfgMemState {
98 /*< private >*/
99 FWCfgState parent_obj;
100 /*< public >*/
102 MemoryRegion ctl_iomem, data_iomem;
103 uint32_t data_width;
104 MemoryRegionOps wide_data_ops;
108 * fw_cfg_add_bytes:
109 * @s: fw_cfg device being modified
110 * @key: selector key value for new fw_cfg item
111 * @data: pointer to start of item data
112 * @len: size of item data
114 * Add a new fw_cfg item, available by selecting the given key, as a raw
115 * "blob" of the given size. The data referenced by the starting pointer
116 * is only linked, NOT copied, into the data structure of the fw_cfg device.
118 void fw_cfg_add_bytes(FWCfgState *s, uint16_t key, void *data, size_t len);
121 * fw_cfg_add_string:
122 * @s: fw_cfg device being modified
123 * @key: selector key value for new fw_cfg item
124 * @value: NUL-terminated ascii string
126 * Add a new fw_cfg item, available by selecting the given key. The item
127 * data will consist of a dynamically allocated copy of the provided string,
128 * including its NUL terminator.
130 void fw_cfg_add_string(FWCfgState *s, uint16_t key, const char *value);
133 * fw_cfg_modify_string:
134 * @s: fw_cfg device being modified
135 * @key: selector key value for new fw_cfg item
136 * @value: NUL-terminated ascii string
138 * Replace the fw_cfg item available by selecting the given key. The new
139 * data will consist of a dynamically allocated copy of the provided string,
140 * including its NUL terminator. The data being replaced, assumed to have
141 * been dynamically allocated during an earlier call to either
142 * fw_cfg_add_string() or fw_cfg_modify_string(), is freed before returning.
144 void fw_cfg_modify_string(FWCfgState *s, uint16_t key, const char *value);
147 * fw_cfg_add_i16:
148 * @s: fw_cfg device being modified
149 * @key: selector key value for new fw_cfg item
150 * @value: 16-bit integer
152 * Add a new fw_cfg item, available by selecting the given key. The item
153 * data will consist of a dynamically allocated copy of the given 16-bit
154 * value, converted to little-endian representation.
156 void fw_cfg_add_i16(FWCfgState *s, uint16_t key, uint16_t value);
159 * fw_cfg_modify_i16:
160 * @s: fw_cfg device being modified
161 * @key: selector key value for new fw_cfg item
162 * @value: 16-bit integer
164 * Replace the fw_cfg item available by selecting the given key. The new
165 * data will consist of a dynamically allocated copy of the given 16-bit
166 * value, converted to little-endian representation. The data being replaced,
167 * assumed to have been dynamically allocated during an earlier call to
168 * either fw_cfg_add_i16() or fw_cfg_modify_i16(), is freed before returning.
170 void fw_cfg_modify_i16(FWCfgState *s, uint16_t key, uint16_t value);
173 * fw_cfg_add_i32:
174 * @s: fw_cfg device being modified
175 * @key: selector key value for new fw_cfg item
176 * @value: 32-bit integer
178 * Add a new fw_cfg item, available by selecting the given key. The item
179 * data will consist of a dynamically allocated copy of the given 32-bit
180 * value, converted to little-endian representation.
182 void fw_cfg_add_i32(FWCfgState *s, uint16_t key, uint32_t value);
185 * fw_cfg_modify_i32:
186 * @s: fw_cfg device being modified
187 * @key: selector key value for new fw_cfg item
188 * @value: 32-bit integer
190 * Replace the fw_cfg item available by selecting the given key. The new
191 * data will consist of a dynamically allocated copy of the given 32-bit
192 * value, converted to little-endian representation. The data being replaced,
193 * assumed to have been dynamically allocated during an earlier call to
194 * either fw_cfg_add_i32() or fw_cfg_modify_i32(), is freed before returning.
196 void fw_cfg_modify_i32(FWCfgState *s, uint16_t key, uint32_t value);
199 * fw_cfg_add_i64:
200 * @s: fw_cfg device being modified
201 * @key: selector key value for new fw_cfg item
202 * @value: 64-bit integer
204 * Add a new fw_cfg item, available by selecting the given key. The item
205 * data will consist of a dynamically allocated copy of the given 64-bit
206 * value, converted to little-endian representation.
208 void fw_cfg_add_i64(FWCfgState *s, uint16_t key, uint64_t value);
211 * fw_cfg_modify_i64:
212 * @s: fw_cfg device being modified
213 * @key: selector key value for new fw_cfg item
214 * @value: 64-bit integer
216 * Replace the fw_cfg item available by selecting the given key. The new
217 * data will consist of a dynamically allocated copy of the given 64-bit
218 * value, converted to little-endian representation. The data being replaced,
219 * assumed to have been dynamically allocated during an earlier call to
220 * either fw_cfg_add_i64() or fw_cfg_modify_i64(), is freed before returning.
222 void fw_cfg_modify_i64(FWCfgState *s, uint16_t key, uint64_t value);
225 * fw_cfg_add_file:
226 * @s: fw_cfg device being modified
227 * @filename: name of new fw_cfg file item
228 * @data: pointer to start of item data
229 * @len: size of item data
231 * Add a new NAMED fw_cfg item as a raw "blob" of the given size. The data
232 * referenced by the starting pointer is only linked, NOT copied, into the
233 * data structure of the fw_cfg device.
234 * The next available (unused) selector key starting at FW_CFG_FILE_FIRST
235 * will be used; also, a new entry will be added to the file directory
236 * structure residing at key value FW_CFG_FILE_DIR, containing the item name,
237 * data size, and assigned selector key value.
239 void fw_cfg_add_file(FWCfgState *s, const char *filename, void *data,
240 size_t len);
243 * fw_cfg_add_file_callback:
244 * @s: fw_cfg device being modified
245 * @filename: name of new fw_cfg file item
246 * @select_cb: callback function when selecting
247 * @write_cb: callback function after a write
248 * @callback_opaque: argument to be passed into callback function
249 * @data: pointer to start of item data
250 * @len: size of item data
251 * @read_only: is file read only
253 * Add a new NAMED fw_cfg item as a raw "blob" of the given size. The data
254 * referenced by the starting pointer is only linked, NOT copied, into the
255 * data structure of the fw_cfg device.
256 * The next available (unused) selector key starting at FW_CFG_FILE_FIRST
257 * will be used; also, a new entry will be added to the file directory
258 * structure residing at key value FW_CFG_FILE_DIR, containing the item name,
259 * data size, and assigned selector key value.
260 * Additionally, set a callback function (and argument) to be called each
261 * time this item is selected (by having its selector key either written to
262 * the fw_cfg control register, or passed to QEMU in FWCfgDmaAccess.control
263 * with FW_CFG_DMA_CTL_SELECT).
265 void fw_cfg_add_file_callback(FWCfgState *s, const char *filename,
266 FWCfgCallback select_cb,
267 FWCfgWriteCallback write_cb,
268 void *callback_opaque,
269 void *data, size_t len, bool read_only);
272 * fw_cfg_modify_file:
273 * @s: fw_cfg device being modified
274 * @filename: name of new fw_cfg file item
275 * @data: pointer to start of item data
276 * @len: size of item data
278 * Replace a NAMED fw_cfg item. If an existing item is found, its callback
279 * information will be cleared, and a pointer to its data will be returned
280 * to the caller, so that it may be freed if necessary. If an existing item
281 * is not found, this call defaults to fw_cfg_add_file(), and NULL is
282 * returned to the caller.
283 * In either case, the new item data is only linked, NOT copied, into the
284 * data structure of the fw_cfg device.
286 * Returns: pointer to old item's data, or NULL if old item does not exist.
288 void *fw_cfg_modify_file(FWCfgState *s, const char *filename, void *data,
289 size_t len);
292 * fw_cfg_add_from_generator:
293 * @s: fw_cfg device being modified
294 * @filename: name of new fw_cfg file item
295 * @gen_id: name of object implementing FW_CFG_DATA_GENERATOR interface
296 * @errp: pointer to a NULL initialized error object
298 * Add a new NAMED fw_cfg item with the content generated from the
299 * @gen_id object. The data generated by the @gen_id object is copied
300 * into the data structure of the fw_cfg device.
301 * The next available (unused) selector key starting at FW_CFG_FILE_FIRST
302 * will be used; also, a new entry will be added to the file directory
303 * structure residing at key value FW_CFG_FILE_DIR, containing the item name,
304 * data size, and assigned selector key value.
306 void fw_cfg_add_from_generator(FWCfgState *s, const char *filename,
307 const char *gen_id, Error **errp);
309 FWCfgState *fw_cfg_init_io_dma(uint32_t iobase, uint32_t dma_iobase,
310 AddressSpace *dma_as);
311 FWCfgState *fw_cfg_init_io(uint32_t iobase);
312 FWCfgState *fw_cfg_init_mem(hwaddr ctl_addr, hwaddr data_addr);
313 FWCfgState *fw_cfg_init_mem_wide(hwaddr ctl_addr,
314 hwaddr data_addr, uint32_t data_width,
315 hwaddr dma_addr, AddressSpace *dma_as);
317 FWCfgState *fw_cfg_find(void);
318 bool fw_cfg_dma_enabled(void *opaque);
321 * fw_cfg_arch_key_name:
323 * @key: The uint16 selector key.
325 * The key is architecture-specific (the FW_CFG_ARCH_LOCAL mask is expected
326 * to be set in the key).
328 * Returns: The stringified architecture-specific name if the selector
329 * refers to a well-known numerically defined item, or NULL on
330 * key lookup failure.
332 const char *fw_cfg_arch_key_name(uint16_t key);
334 #endif