]>
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 | 14 | |
8063396b EH |
15 | OBJECT_DECLARE_SIMPLE_TYPE(FWCfgState, FW_CFG) |
16 | OBJECT_DECLARE_SIMPLE_TYPE(FWCfgIoState, FW_CFG_IO) | |
17 | OBJECT_DECLARE_SIMPLE_TYPE(FWCfgMemState, FW_CFG_MEM) | |
1dfe5057 | 18 | |
db1015e9 | 19 | typedef struct FWCfgDataGeneratorClass FWCfgDataGeneratorClass; |
8110fa1d | 20 | DECLARE_CLASS_CHECKERS(FWCfgDataGeneratorClass, FW_CFG_DATA_GENERATOR, |
32031489 | 21 | TYPE_FW_CFG_DATA_GENERATOR_INTERFACE) |
32031489 | 22 | |
db1015e9 | 23 | struct FWCfgDataGeneratorClass { |
32031489 PMD |
24 | /*< private >*/ |
25 | InterfaceClass parent_class; | |
26 | /*< public >*/ | |
27 | ||
28 | /** | |
29 | * get_data: | |
30 | * @obj: the object implementing this interface | |
31 | * @errp: pointer to a NULL-initialized error object | |
32 | * | |
a3ad5834 PMD |
33 | * Returns: reference to a byte array containing the data on success, |
34 | * or NULL on error. | |
35 | * | |
32031489 PMD |
36 | * The caller should release the reference when no longer |
37 | * required. | |
38 | */ | |
39 | GByteArray *(*get_data)(Object *obj, Error **errp); | |
db1015e9 | 40 | }; |
32031489 | 41 | |
5be5df72 | 42 | typedef struct fw_cfg_file FWCfgFile; |
abe147e0 | 43 | |
bab47d9a GH |
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 | |
48 | ||
49 | void fw_cfg_set_order_override(FWCfgState *fw_cfg, int order); | |
50 | void fw_cfg_reset_order_override(FWCfgState *fw_cfg); | |
51 | ||
abe147e0 GH |
52 | typedef struct FWCfgFiles { |
53 | uint32_t count; | |
54 | FWCfgFile f[]; | |
55 | } FWCfgFiles; | |
56 | ||
5be5df72 | 57 | typedef struct fw_cfg_dma_access FWCfgDmaAccess; |
a4c0d1de | 58 | |
6f6f4aec | 59 | typedef void (*FWCfgCallback)(void *opaque); |
5f9252f7 | 60 | typedef void (*FWCfgWriteCallback)(void *opaque, off_t start, size_t len); |
3cce6243 | 61 | |
39736e18 MCA |
62 | struct FWCfgState { |
63 | /*< private >*/ | |
64 | SysBusDevice parent_obj; | |
65 | /*< public >*/ | |
66 | ||
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; | |
74 | ||
75 | int fw_cfg_order_override; | |
76 | ||
77 | bool dma_enabled; | |
78 | dma_addr_t dma_addr; | |
79 | AddressSpace *dma_as; | |
80 | MemoryRegion dma_iomem; | |
394f0f72 SK |
81 | |
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; | |
39736e18 MCA |
87 | }; |
88 | ||
89 | struct FWCfgIoState { | |
90 | /*< private >*/ | |
91 | FWCfgState parent_obj; | |
92 | /*< public >*/ | |
93 | ||
94 | MemoryRegion comb_iomem; | |
95 | }; | |
96 | ||
97 | struct FWCfgMemState { | |
98 | /*< private >*/ | |
99 | FWCfgState parent_obj; | |
100 | /*< public >*/ | |
101 | ||
102 | MemoryRegion ctl_iomem, data_iomem; | |
103 | uint32_t data_width; | |
104 | MemoryRegionOps wide_data_ops; | |
105 | }; | |
106 | ||
9c4a5c55 GS |
107 | /** |
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 | |
113 | * | |
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. | |
117 | */ | |
089da572 | 118 | void fw_cfg_add_bytes(FWCfgState *s, uint16_t key, void *data, size_t len); |
9c4a5c55 GS |
119 | |
120 | /** | |
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 | |
125 | * | |
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. | |
129 | */ | |
44687f75 | 130 | void fw_cfg_add_string(FWCfgState *s, uint16_t key, const char *value); |
9c4a5c55 | 131 | |
e5f6aa31 SL |
132 | /** |
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 | |
137 | * | |
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. | |
143 | */ | |
144 | void fw_cfg_modify_string(FWCfgState *s, uint16_t key, const char *value); | |
145 | ||
9c4a5c55 GS |
146 | /** |
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 | |
151 | * | |
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. | |
155 | */ | |
4cad3867 | 156 | void fw_cfg_add_i16(FWCfgState *s, uint16_t key, uint16_t value); |
9c4a5c55 GS |
157 | |
158 | /** | |
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 | |
163 | * | |
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. | |
169 | */ | |
1edd34b6 | 170 | void fw_cfg_modify_i16(FWCfgState *s, uint16_t key, uint16_t value); |
9c4a5c55 GS |
171 | |
172 | /** | |
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 | |
177 | * | |
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. | |
181 | */ | |
4cad3867 | 182 | void fw_cfg_add_i32(FWCfgState *s, uint16_t key, uint32_t value); |
9c4a5c55 | 183 | |
e5f6aa31 SL |
184 | /** |
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 | |
189 | * | |
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. | |
195 | */ | |
196 | void fw_cfg_modify_i32(FWCfgState *s, uint16_t key, uint32_t value); | |
197 | ||
9c4a5c55 GS |
198 | /** |
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 | |
203 | * | |
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. | |
207 | */ | |
4cad3867 | 208 | void fw_cfg_add_i64(FWCfgState *s, uint16_t key, uint64_t value); |
9c4a5c55 | 209 | |
e5f6aa31 SL |
210 | /** |
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 | |
215 | * | |
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. | |
221 | */ | |
222 | void fw_cfg_modify_i64(FWCfgState *s, uint16_t key, uint64_t value); | |
223 | ||
9c4a5c55 GS |
224 | /** |
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 | |
230 | * | |
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. | |
238 | */ | |
089da572 MA |
239 | void fw_cfg_add_file(FWCfgState *s, const char *filename, void *data, |
240 | size_t len); | |
9c4a5c55 GS |
241 | |
242 | /** | |
243 | * fw_cfg_add_file_callback: | |
244 | * @s: fw_cfg device being modified | |
245 | * @filename: name of new fw_cfg file item | |
6f6f4aec | 246 | * @select_cb: callback function when selecting |
5f9252f7 | 247 | * @write_cb: callback function after a write |
9c4a5c55 GS |
248 | * @callback_opaque: argument to be passed into callback function |
249 | * @data: pointer to start of item data | |
250 | * @len: size of item data | |
baf2d5bf | 251 | * @read_only: is file read only |
9c4a5c55 GS |
252 | * |
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 | |
3bef7e8a GS |
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). | |
9c4a5c55 | 264 | */ |
d87072ce | 265 | void fw_cfg_add_file_callback(FWCfgState *s, const char *filename, |
6f6f4aec | 266 | FWCfgCallback select_cb, |
5f9252f7 | 267 | FWCfgWriteCallback write_cb, |
6f6f4aec | 268 | void *callback_opaque, |
baf2d5bf | 269 | void *data, size_t len, bool read_only); |
9c4a5c55 GS |
270 | |
271 | /** | |
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 | |
277 | * | |
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. | |
285 | * | |
286 | * Returns: pointer to old item's data, or NULL if old item does not exist. | |
287 | */ | |
bdbb5b17 GA |
288 | void *fw_cfg_modify_file(FWCfgState *s, const char *filename, void *data, |
289 | size_t len); | |
9c4a5c55 | 290 | |
32031489 PMD |
291 | /** |
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 | |
297 | * | |
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. | |
07719518 PMD |
305 | * |
306 | * Returns: %true on success, %false on error. | |
32031489 | 307 | */ |
07719518 | 308 | bool fw_cfg_add_from_generator(FWCfgState *s, const char *filename, |
32031489 PMD |
309 | const char *gen_id, Error **errp); |
310 | ||
a4c0d1de MM |
311 | FWCfgState *fw_cfg_init_io_dma(uint32_t iobase, uint32_t dma_iobase, |
312 | AddressSpace *dma_as); | |
5712db6a LE |
313 | FWCfgState *fw_cfg_init_io(uint32_t iobase); |
314 | FWCfgState *fw_cfg_init_mem(hwaddr ctl_addr, hwaddr data_addr); | |
a4c0d1de MM |
315 | FWCfgState *fw_cfg_init_mem_wide(hwaddr ctl_addr, |
316 | hwaddr data_addr, uint32_t data_width, | |
317 | hwaddr dma_addr, AddressSpace *dma_as); | |
3cce6243 | 318 | |
600c60b7 | 319 | FWCfgState *fw_cfg_find(void); |
b2a575a1 | 320 | bool fw_cfg_dma_enabled(void *opaque); |
600c60b7 | 321 | |
b15c0f7d PMD |
322 | /** |
323 | * fw_cfg_arch_key_name: | |
324 | * | |
325 | * @key: The uint16 selector key. | |
326 | * | |
327 | * The key is architecture-specific (the FW_CFG_ARCH_LOCAL mask is expected | |
328 | * to be set in the key). | |
329 | * | |
330 | * Returns: The stringified architecture-specific name if the selector | |
331 | * refers to a well-known numerically defined item, or NULL on | |
332 | * key lookup failure. | |
333 | */ | |
334 | const char *fw_cfg_arch_key_name(uint16_t key); | |
335 | ||
3cce6243 | 336 | #endif |