]>
Commit | Line | Data |
---|---|---|
3cce6243 BS |
1 | #ifndef FW_CFG_H |
2 | #define FW_CFG_H | |
3 | ||
1dfe5057 | 4 | #include "exec/hwaddr.h" |
5be5df72 | 5 | #include "standard-headers/linux/qemu_fw_cfg.h" |
39736e18 MCA |
6 | #include "hw/sysbus.h" |
7 | #include "sysemu/dma.h" | |
db1015e9 | 8 | #include "qom/object.h" |
39736e18 MCA |
9 | |
10 | #define TYPE_FW_CFG "fw_cfg" | |
11 | #define TYPE_FW_CFG_IO "fw_cfg_io" | |
12 | #define TYPE_FW_CFG_MEM "fw_cfg_mem" | |
32031489 | 13 | #define TYPE_FW_CFG_DATA_GENERATOR_INTERFACE "fw_cfg-data-generator" |
39736e18 MCA |
14 | |
15 | #define FW_CFG(obj) OBJECT_CHECK(FWCfgState, (obj), TYPE_FW_CFG) | |
16 | #define FW_CFG_IO(obj) OBJECT_CHECK(FWCfgIoState, (obj), TYPE_FW_CFG_IO) | |
17 | #define FW_CFG_MEM(obj) OBJECT_CHECK(FWCfgMemState, (obj), TYPE_FW_CFG_MEM) | |
1dfe5057 | 18 | |
db1015e9 | 19 | typedef struct FWCfgDataGeneratorClass FWCfgDataGeneratorClass; |
32031489 PMD |
20 | #define FW_CFG_DATA_GENERATOR_CLASS(class) \ |
21 | OBJECT_CLASS_CHECK(FWCfgDataGeneratorClass, (class), \ | |
22 | TYPE_FW_CFG_DATA_GENERATOR_INTERFACE) | |
23 | #define FW_CFG_DATA_GENERATOR_GET_CLASS(obj) \ | |
24 | OBJECT_GET_CLASS(FWCfgDataGeneratorClass, (obj), \ | |
25 | TYPE_FW_CFG_DATA_GENERATOR_INTERFACE) | |
26 | ||
db1015e9 | 27 | struct FWCfgDataGeneratorClass { |
32031489 PMD |
28 | /*< private >*/ |
29 | InterfaceClass parent_class; | |
30 | /*< public >*/ | |
31 | ||
32 | /** | |
33 | * get_data: | |
34 | * @obj: the object implementing this interface | |
35 | * @errp: pointer to a NULL-initialized error object | |
36 | * | |
a3ad5834 PMD |
37 | * Returns: reference to a byte array containing the data on success, |
38 | * or NULL on error. | |
39 | * | |
32031489 PMD |
40 | * The caller should release the reference when no longer |
41 | * required. | |
42 | */ | |
43 | GByteArray *(*get_data)(Object *obj, Error **errp); | |
db1015e9 | 44 | }; |
32031489 | 45 | |
5be5df72 | 46 | typedef struct fw_cfg_file FWCfgFile; |
abe147e0 | 47 | |
bab47d9a GH |
48 | #define FW_CFG_ORDER_OVERRIDE_VGA 70 |
49 | #define FW_CFG_ORDER_OVERRIDE_NIC 80 | |
50 | #define FW_CFG_ORDER_OVERRIDE_USER 100 | |
51 | #define FW_CFG_ORDER_OVERRIDE_DEVICE 110 | |
52 | ||
53 | void fw_cfg_set_order_override(FWCfgState *fw_cfg, int order); | |
54 | void fw_cfg_reset_order_override(FWCfgState *fw_cfg); | |
55 | ||
abe147e0 GH |
56 | typedef struct FWCfgFiles { |
57 | uint32_t count; | |
58 | FWCfgFile f[]; | |
59 | } FWCfgFiles; | |
60 | ||
5be5df72 | 61 | typedef struct fw_cfg_dma_access FWCfgDmaAccess; |
a4c0d1de | 62 | |
6f6f4aec | 63 | typedef void (*FWCfgCallback)(void *opaque); |
5f9252f7 | 64 | typedef void (*FWCfgWriteCallback)(void *opaque, off_t start, size_t len); |
3cce6243 | 65 | |
39736e18 MCA |
66 | struct FWCfgState { |
67 | /*< private >*/ | |
68 | SysBusDevice parent_obj; | |
69 | /*< public >*/ | |
70 | ||
71 | uint16_t file_slots; | |
72 | FWCfgEntry *entries[2]; | |
73 | int *entry_order; | |
74 | FWCfgFiles *files; | |
75 | uint16_t cur_entry; | |
76 | uint32_t cur_offset; | |
77 | Notifier machine_ready; | |
78 | ||
79 | int fw_cfg_order_override; | |
80 | ||
81 | bool dma_enabled; | |
82 | dma_addr_t dma_addr; | |
83 | AddressSpace *dma_as; | |
84 | MemoryRegion dma_iomem; | |
394f0f72 SK |
85 | |
86 | /* restore during migration */ | |
87 | bool acpi_mr_restore; | |
88 | uint64_t table_mr_size; | |
89 | uint64_t linker_mr_size; | |
90 | uint64_t rsdp_mr_size; | |
39736e18 MCA |
91 | }; |
92 | ||
93 | struct FWCfgIoState { | |
94 | /*< private >*/ | |
95 | FWCfgState parent_obj; | |
96 | /*< public >*/ | |
97 | ||
98 | MemoryRegion comb_iomem; | |
99 | }; | |
100 | ||
101 | struct FWCfgMemState { | |
102 | /*< private >*/ | |
103 | FWCfgState parent_obj; | |
104 | /*< public >*/ | |
105 | ||
106 | MemoryRegion ctl_iomem, data_iomem; | |
107 | uint32_t data_width; | |
108 | MemoryRegionOps wide_data_ops; | |
109 | }; | |
110 | ||
9c4a5c55 GS |
111 | /** |
112 | * fw_cfg_add_bytes: | |
113 | * @s: fw_cfg device being modified | |
114 | * @key: selector key value for new fw_cfg item | |
115 | * @data: pointer to start of item data | |
116 | * @len: size of item data | |
117 | * | |
118 | * Add a new fw_cfg item, available by selecting the given key, as a raw | |
119 | * "blob" of the given size. The data referenced by the starting pointer | |
120 | * is only linked, NOT copied, into the data structure of the fw_cfg device. | |
121 | */ | |
089da572 | 122 | void fw_cfg_add_bytes(FWCfgState *s, uint16_t key, void *data, size_t len); |
9c4a5c55 GS |
123 | |
124 | /** | |
125 | * fw_cfg_add_string: | |
126 | * @s: fw_cfg device being modified | |
127 | * @key: selector key value for new fw_cfg item | |
128 | * @value: NUL-terminated ascii string | |
129 | * | |
130 | * Add a new fw_cfg item, available by selecting the given key. The item | |
131 | * data will consist of a dynamically allocated copy of the provided string, | |
132 | * including its NUL terminator. | |
133 | */ | |
44687f75 | 134 | void fw_cfg_add_string(FWCfgState *s, uint16_t key, const char *value); |
9c4a5c55 | 135 | |
e5f6aa31 SL |
136 | /** |
137 | * fw_cfg_modify_string: | |
138 | * @s: fw_cfg device being modified | |
139 | * @key: selector key value for new fw_cfg item | |
140 | * @value: NUL-terminated ascii string | |
141 | * | |
142 | * Replace the fw_cfg item available by selecting the given key. The new | |
143 | * data will consist of a dynamically allocated copy of the provided string, | |
144 | * including its NUL terminator. The data being replaced, assumed to have | |
145 | * been dynamically allocated during an earlier call to either | |
146 | * fw_cfg_add_string() or fw_cfg_modify_string(), is freed before returning. | |
147 | */ | |
148 | void fw_cfg_modify_string(FWCfgState *s, uint16_t key, const char *value); | |
149 | ||
9c4a5c55 GS |
150 | /** |
151 | * fw_cfg_add_i16: | |
152 | * @s: fw_cfg device being modified | |
153 | * @key: selector key value for new fw_cfg item | |
154 | * @value: 16-bit integer | |
155 | * | |
156 | * Add a new fw_cfg item, available by selecting the given key. The item | |
157 | * data will consist of a dynamically allocated copy of the given 16-bit | |
158 | * value, converted to little-endian representation. | |
159 | */ | |
4cad3867 | 160 | void fw_cfg_add_i16(FWCfgState *s, uint16_t key, uint16_t value); |
9c4a5c55 GS |
161 | |
162 | /** | |
163 | * fw_cfg_modify_i16: | |
164 | * @s: fw_cfg device being modified | |
165 | * @key: selector key value for new fw_cfg item | |
166 | * @value: 16-bit integer | |
167 | * | |
168 | * Replace the fw_cfg item available by selecting the given key. The new | |
169 | * data will consist of a dynamically allocated copy of the given 16-bit | |
170 | * value, converted to little-endian representation. The data being replaced, | |
171 | * assumed to have been dynamically allocated during an earlier call to | |
172 | * either fw_cfg_add_i16() or fw_cfg_modify_i16(), is freed before returning. | |
173 | */ | |
1edd34b6 | 174 | void fw_cfg_modify_i16(FWCfgState *s, uint16_t key, uint16_t value); |
9c4a5c55 GS |
175 | |
176 | /** | |
177 | * fw_cfg_add_i32: | |
178 | * @s: fw_cfg device being modified | |
179 | * @key: selector key value for new fw_cfg item | |
180 | * @value: 32-bit integer | |
181 | * | |
182 | * Add a new fw_cfg item, available by selecting the given key. The item | |
183 | * data will consist of a dynamically allocated copy of the given 32-bit | |
184 | * value, converted to little-endian representation. | |
185 | */ | |
4cad3867 | 186 | void fw_cfg_add_i32(FWCfgState *s, uint16_t key, uint32_t value); |
9c4a5c55 | 187 | |
e5f6aa31 SL |
188 | /** |
189 | * fw_cfg_modify_i32: | |
190 | * @s: fw_cfg device being modified | |
191 | * @key: selector key value for new fw_cfg item | |
192 | * @value: 32-bit integer | |
193 | * | |
194 | * Replace the fw_cfg item available by selecting the given key. The new | |
195 | * data will consist of a dynamically allocated copy of the given 32-bit | |
196 | * value, converted to little-endian representation. The data being replaced, | |
197 | * assumed to have been dynamically allocated during an earlier call to | |
198 | * either fw_cfg_add_i32() or fw_cfg_modify_i32(), is freed before returning. | |
199 | */ | |
200 | void fw_cfg_modify_i32(FWCfgState *s, uint16_t key, uint32_t value); | |
201 | ||
9c4a5c55 GS |
202 | /** |
203 | * fw_cfg_add_i64: | |
204 | * @s: fw_cfg device being modified | |
205 | * @key: selector key value for new fw_cfg item | |
206 | * @value: 64-bit integer | |
207 | * | |
208 | * Add a new fw_cfg item, available by selecting the given key. The item | |
209 | * data will consist of a dynamically allocated copy of the given 64-bit | |
210 | * value, converted to little-endian representation. | |
211 | */ | |
4cad3867 | 212 | void fw_cfg_add_i64(FWCfgState *s, uint16_t key, uint64_t value); |
9c4a5c55 | 213 | |
e5f6aa31 SL |
214 | /** |
215 | * fw_cfg_modify_i64: | |
216 | * @s: fw_cfg device being modified | |
217 | * @key: selector key value for new fw_cfg item | |
218 | * @value: 64-bit integer | |
219 | * | |
220 | * Replace the fw_cfg item available by selecting the given key. The new | |
221 | * data will consist of a dynamically allocated copy of the given 64-bit | |
222 | * value, converted to little-endian representation. The data being replaced, | |
223 | * assumed to have been dynamically allocated during an earlier call to | |
224 | * either fw_cfg_add_i64() or fw_cfg_modify_i64(), is freed before returning. | |
225 | */ | |
226 | void fw_cfg_modify_i64(FWCfgState *s, uint16_t key, uint64_t value); | |
227 | ||
9c4a5c55 GS |
228 | /** |
229 | * fw_cfg_add_file: | |
230 | * @s: fw_cfg device being modified | |
231 | * @filename: name of new fw_cfg file item | |
232 | * @data: pointer to start of item data | |
233 | * @len: size of item data | |
234 | * | |
235 | * Add a new NAMED fw_cfg item as a raw "blob" of the given size. The data | |
236 | * referenced by the starting pointer is only linked, NOT copied, into the | |
237 | * data structure of the fw_cfg device. | |
238 | * The next available (unused) selector key starting at FW_CFG_FILE_FIRST | |
239 | * will be used; also, a new entry will be added to the file directory | |
240 | * structure residing at key value FW_CFG_FILE_DIR, containing the item name, | |
241 | * data size, and assigned selector key value. | |
242 | */ | |
089da572 MA |
243 | void fw_cfg_add_file(FWCfgState *s, const char *filename, void *data, |
244 | size_t len); | |
9c4a5c55 GS |
245 | |
246 | /** | |
247 | * fw_cfg_add_file_callback: | |
248 | * @s: fw_cfg device being modified | |
249 | * @filename: name of new fw_cfg file item | |
6f6f4aec | 250 | * @select_cb: callback function when selecting |
5f9252f7 | 251 | * @write_cb: callback function after a write |
9c4a5c55 GS |
252 | * @callback_opaque: argument to be passed into callback function |
253 | * @data: pointer to start of item data | |
254 | * @len: size of item data | |
baf2d5bf | 255 | * @read_only: is file read only |
9c4a5c55 GS |
256 | * |
257 | * Add a new NAMED fw_cfg item as a raw "blob" of the given size. The data | |
258 | * referenced by the starting pointer is only linked, NOT copied, into the | |
259 | * data structure of the fw_cfg device. | |
260 | * The next available (unused) selector key starting at FW_CFG_FILE_FIRST | |
261 | * will be used; also, a new entry will be added to the file directory | |
262 | * structure residing at key value FW_CFG_FILE_DIR, containing the item name, | |
263 | * data size, and assigned selector key value. | |
264 | * Additionally, set a callback function (and argument) to be called each | |
3bef7e8a GS |
265 | * time this item is selected (by having its selector key either written to |
266 | * the fw_cfg control register, or passed to QEMU in FWCfgDmaAccess.control | |
267 | * with FW_CFG_DMA_CTL_SELECT). | |
9c4a5c55 | 268 | */ |
d87072ce | 269 | void fw_cfg_add_file_callback(FWCfgState *s, const char *filename, |
6f6f4aec | 270 | FWCfgCallback select_cb, |
5f9252f7 | 271 | FWCfgWriteCallback write_cb, |
6f6f4aec | 272 | void *callback_opaque, |
baf2d5bf | 273 | void *data, size_t len, bool read_only); |
9c4a5c55 GS |
274 | |
275 | /** | |
276 | * fw_cfg_modify_file: | |
277 | * @s: fw_cfg device being modified | |
278 | * @filename: name of new fw_cfg file item | |
279 | * @data: pointer to start of item data | |
280 | * @len: size of item data | |
281 | * | |
282 | * Replace a NAMED fw_cfg item. If an existing item is found, its callback | |
283 | * information will be cleared, and a pointer to its data will be returned | |
284 | * to the caller, so that it may be freed if necessary. If an existing item | |
285 | * is not found, this call defaults to fw_cfg_add_file(), and NULL is | |
286 | * returned to the caller. | |
287 | * In either case, the new item data is only linked, NOT copied, into the | |
288 | * data structure of the fw_cfg device. | |
289 | * | |
290 | * Returns: pointer to old item's data, or NULL if old item does not exist. | |
291 | */ | |
bdbb5b17 GA |
292 | void *fw_cfg_modify_file(FWCfgState *s, const char *filename, void *data, |
293 | size_t len); | |
9c4a5c55 | 294 | |
32031489 PMD |
295 | /** |
296 | * fw_cfg_add_from_generator: | |
297 | * @s: fw_cfg device being modified | |
298 | * @filename: name of new fw_cfg file item | |
299 | * @gen_id: name of object implementing FW_CFG_DATA_GENERATOR interface | |
300 | * @errp: pointer to a NULL initialized error object | |
301 | * | |
302 | * Add a new NAMED fw_cfg item with the content generated from the | |
303 | * @gen_id object. The data generated by the @gen_id object is copied | |
304 | * into the data structure of the fw_cfg device. | |
305 | * The next available (unused) selector key starting at FW_CFG_FILE_FIRST | |
306 | * will be used; also, a new entry will be added to the file directory | |
307 | * structure residing at key value FW_CFG_FILE_DIR, containing the item name, | |
308 | * data size, and assigned selector key value. | |
07719518 PMD |
309 | * |
310 | * Returns: %true on success, %false on error. | |
32031489 | 311 | */ |
07719518 | 312 | bool fw_cfg_add_from_generator(FWCfgState *s, const char *filename, |
32031489 PMD |
313 | const char *gen_id, Error **errp); |
314 | ||
a4c0d1de MM |
315 | FWCfgState *fw_cfg_init_io_dma(uint32_t iobase, uint32_t dma_iobase, |
316 | AddressSpace *dma_as); | |
5712db6a LE |
317 | FWCfgState *fw_cfg_init_io(uint32_t iobase); |
318 | FWCfgState *fw_cfg_init_mem(hwaddr ctl_addr, hwaddr data_addr); | |
a4c0d1de MM |
319 | FWCfgState *fw_cfg_init_mem_wide(hwaddr ctl_addr, |
320 | hwaddr data_addr, uint32_t data_width, | |
321 | hwaddr dma_addr, AddressSpace *dma_as); | |
3cce6243 | 322 | |
600c60b7 | 323 | FWCfgState *fw_cfg_find(void); |
b2a575a1 | 324 | bool fw_cfg_dma_enabled(void *opaque); |
600c60b7 | 325 | |
b15c0f7d PMD |
326 | /** |
327 | * fw_cfg_arch_key_name: | |
328 | * | |
329 | * @key: The uint16 selector key. | |
330 | * | |
331 | * The key is architecture-specific (the FW_CFG_ARCH_LOCAL mask is expected | |
332 | * to be set in the key). | |
333 | * | |
334 | * Returns: The stringified architecture-specific name if the selector | |
335 | * refers to a well-known numerically defined item, or NULL on | |
336 | * key lookup failure. | |
337 | */ | |
338 | const char *fw_cfg_arch_key_name(uint16_t key); | |
339 | ||
3cce6243 | 340 | #endif |