]>
Commit | Line | Data |
---|---|---|
3cce6243 BS |
1 | /* |
2 | * QEMU Firmware configuration device emulation | |
3 | * | |
4 | * Copyright (c) 2008 Gleb Natapov | |
5 | * | |
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy | |
7 | * of this software and associated documentation files (the "Software"), to deal | |
8 | * in the Software without restriction, including without limitation the rights | |
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
10 | * copies of the Software, and to permit persons to whom the Software is | |
11 | * furnished to do so, subject to the following conditions: | |
12 | * | |
13 | * The above copyright notice and this permission notice shall be included in | |
14 | * all copies or substantial portions of the Software. | |
15 | * | |
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |
19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
22 | * THE SOFTWARE. | |
23 | */ | |
24 | #include "hw.h" | |
9c17d615 | 25 | #include "sysemu/sysemu.h" |
3cce6243 BS |
26 | #include "isa.h" |
27 | #include "fw_cfg.h" | |
3a5c16fc | 28 | #include "sysbus.h" |
1de7afc9 PB |
29 | #include "qemu/error-report.h" |
30 | #include "qemu/config-file.h" | |
3cce6243 BS |
31 | |
32 | /* debug firmware config */ | |
33 | //#define DEBUG_FW_CFG | |
34 | ||
35 | #ifdef DEBUG_FW_CFG | |
001faf32 BS |
36 | #define FW_CFG_DPRINTF(fmt, ...) \ |
37 | do { printf("FW_CFG: " fmt , ## __VA_ARGS__); } while (0) | |
3cce6243 | 38 | #else |
001faf32 | 39 | #define FW_CFG_DPRINTF(fmt, ...) |
3cce6243 BS |
40 | #endif |
41 | ||
42 | #define FW_CFG_SIZE 2 | |
561e1827 | 43 | #define FW_CFG_DATA_SIZE 1 |
3cce6243 | 44 | |
b96ae2da | 45 | typedef struct FWCfgEntry { |
ff06108b | 46 | uint32_t len; |
3cce6243 BS |
47 | uint8_t *data; |
48 | void *callback_opaque; | |
49 | FWCfgCallback callback; | |
50 | } FWCfgEntry; | |
51 | ||
b96ae2da | 52 | struct FWCfgState { |
3a5c16fc | 53 | SysBusDevice busdev; |
561e1827 | 54 | MemoryRegion ctl_iomem, data_iomem, comb_iomem; |
3a5c16fc | 55 | uint32_t ctl_iobase, data_iobase; |
3cce6243 | 56 | FWCfgEntry entries[2][FW_CFG_MAX_ENTRY]; |
abe147e0 | 57 | FWCfgFiles *files; |
3cce6243 | 58 | uint16_t cur_entry; |
ff06108b | 59 | uint32_t cur_offset; |
962630f2 | 60 | Notifier machine_ready; |
c2b5bda4 | 61 | }; |
3cce6243 | 62 | |
3d3b8303 WX |
63 | #define JPG_FILE 0 |
64 | #define BMP_FILE 1 | |
65 | ||
9477c87e | 66 | static char *read_splashfile(char *filename, int *file_sizep, int *file_typep) |
3d3b8303 | 67 | { |
9477c87e PB |
68 | GError *err = NULL; |
69 | gboolean res; | |
70 | gchar *content; | |
3d3b8303 | 71 | int file_type = -1; |
9477c87e | 72 | unsigned int filehead = 0; |
3d3b8303 WX |
73 | int bmp_bpp; |
74 | ||
9477c87e PB |
75 | res = g_file_get_contents(filename, &content, (gsize *)file_sizep, &err); |
76 | if (res == FALSE) { | |
77 | error_report("failed to read splash file '%s'", filename); | |
78 | g_error_free(err); | |
79 | return NULL; | |
3d3b8303 | 80 | } |
9477c87e | 81 | |
3d3b8303 | 82 | /* check file size */ |
9477c87e PB |
83 | if (*file_sizep < 30) { |
84 | goto error; | |
3d3b8303 | 85 | } |
9477c87e | 86 | |
3d3b8303 | 87 | /* check magic ID */ |
9477c87e PB |
88 | filehead = ((content[0] & 0xff) + (content[1] << 8)) & 0xffff; |
89 | if (filehead == 0xd8ff) { | |
3d3b8303 | 90 | file_type = JPG_FILE; |
9477c87e PB |
91 | } else if (filehead == 0x4d42) { |
92 | file_type = BMP_FILE; | |
3d3b8303 | 93 | } else { |
9477c87e | 94 | goto error; |
3d3b8303 | 95 | } |
9477c87e | 96 | |
3d3b8303 WX |
97 | /* check BMP bpp */ |
98 | if (file_type == BMP_FILE) { | |
9477c87e | 99 | bmp_bpp = (content[28] + (content[29] << 8)) & 0xffff; |
3d3b8303 | 100 | if (bmp_bpp != 24) { |
9477c87e | 101 | goto error; |
3d3b8303 WX |
102 | } |
103 | } | |
9477c87e | 104 | |
3d3b8303 | 105 | /* return values */ |
3d3b8303 | 106 | *file_typep = file_type; |
9477c87e PB |
107 | |
108 | return content; | |
109 | ||
110 | error: | |
111 | error_report("splash file '%s' format not recognized; must be JPEG " | |
112 | "or 24 bit BMP", filename); | |
113 | g_free(content); | |
114 | return NULL; | |
3d3b8303 WX |
115 | } |
116 | ||
117 | static void fw_cfg_bootsplash(FWCfgState *s) | |
118 | { | |
119 | int boot_splash_time = -1; | |
120 | const char *boot_splash_filename = NULL; | |
121 | char *p; | |
9477c87e | 122 | char *filename, *file_data; |
3d3b8303 WX |
123 | int file_size; |
124 | int file_type = -1; | |
125 | const char *temp; | |
126 | ||
127 | /* get user configuration */ | |
128 | QemuOptsList *plist = qemu_find_opts("boot-opts"); | |
129 | QemuOpts *opts = QTAILQ_FIRST(&plist->head); | |
130 | if (opts != NULL) { | |
131 | temp = qemu_opt_get(opts, "splash"); | |
132 | if (temp != NULL) { | |
133 | boot_splash_filename = temp; | |
134 | } | |
135 | temp = qemu_opt_get(opts, "splash-time"); | |
136 | if (temp != NULL) { | |
137 | p = (char *)temp; | |
138 | boot_splash_time = strtol(p, (char **)&p, 10); | |
139 | } | |
140 | } | |
141 | ||
142 | /* insert splash time if user configurated */ | |
143 | if (boot_splash_time >= 0) { | |
144 | /* validate the input */ | |
145 | if (boot_splash_time > 0xffff) { | |
146 | error_report("splash time is big than 65535, force it to 65535."); | |
147 | boot_splash_time = 0xffff; | |
148 | } | |
149 | /* use little endian format */ | |
150 | qemu_extra_params_fw[0] = (uint8_t)(boot_splash_time & 0xff); | |
151 | qemu_extra_params_fw[1] = (uint8_t)((boot_splash_time >> 8) & 0xff); | |
152 | fw_cfg_add_file(s, "etc/boot-menu-wait", qemu_extra_params_fw, 2); | |
153 | } | |
154 | ||
155 | /* insert splash file if user configurated */ | |
156 | if (boot_splash_filename != NULL) { | |
157 | filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, boot_splash_filename); | |
158 | if (filename == NULL) { | |
159 | error_report("failed to find file '%s'.", boot_splash_filename); | |
160 | return; | |
161 | } | |
9477c87e PB |
162 | |
163 | /* loading file data */ | |
164 | file_data = read_splashfile(filename, &file_size, &file_type); | |
165 | if (file_data == NULL) { | |
7267c094 | 166 | g_free(filename); |
3d3b8303 WX |
167 | return; |
168 | } | |
3d3b8303 | 169 | if (boot_splash_filedata != NULL) { |
7267c094 | 170 | g_free(boot_splash_filedata); |
3d3b8303 | 171 | } |
9477c87e | 172 | boot_splash_filedata = (uint8_t *)file_data; |
3d3b8303 | 173 | boot_splash_filedata_size = file_size; |
9477c87e | 174 | |
3d3b8303 WX |
175 | /* insert data */ |
176 | if (file_type == JPG_FILE) { | |
177 | fw_cfg_add_file(s, "bootsplash.jpg", | |
178 | boot_splash_filedata, boot_splash_filedata_size); | |
179 | } else { | |
180 | fw_cfg_add_file(s, "bootsplash.bmp", | |
181 | boot_splash_filedata, boot_splash_filedata_size); | |
182 | } | |
7267c094 | 183 | g_free(filename); |
3d3b8303 WX |
184 | } |
185 | } | |
186 | ||
ac05f349 AK |
187 | static void fw_cfg_reboot(FWCfgState *s) |
188 | { | |
189 | int reboot_timeout = -1; | |
190 | char *p; | |
191 | const char *temp; | |
192 | ||
193 | /* get user configuration */ | |
194 | QemuOptsList *plist = qemu_find_opts("boot-opts"); | |
195 | QemuOpts *opts = QTAILQ_FIRST(&plist->head); | |
196 | if (opts != NULL) { | |
197 | temp = qemu_opt_get(opts, "reboot-timeout"); | |
198 | if (temp != NULL) { | |
199 | p = (char *)temp; | |
200 | reboot_timeout = strtol(p, (char **)&p, 10); | |
201 | } | |
202 | } | |
203 | /* validate the input */ | |
204 | if (reboot_timeout > 0xffff) { | |
205 | error_report("reboot timeout is larger than 65535, force it to 65535."); | |
206 | reboot_timeout = 0xffff; | |
207 | } | |
208 | fw_cfg_add_file(s, "etc/boot-fail-wait", g_memdup(&reboot_timeout, 4), 4); | |
209 | } | |
210 | ||
3cce6243 BS |
211 | static void fw_cfg_write(FWCfgState *s, uint8_t value) |
212 | { | |
213 | int arch = !!(s->cur_entry & FW_CFG_ARCH_LOCAL); | |
214 | FWCfgEntry *e = &s->entries[arch][s->cur_entry & FW_CFG_ENTRY_MASK]; | |
215 | ||
216 | FW_CFG_DPRINTF("write %d\n", value); | |
217 | ||
962d4b28 BS |
218 | if (s->cur_entry & FW_CFG_WRITE_CHANNEL && e->callback && |
219 | s->cur_offset < e->len) { | |
3cce6243 BS |
220 | e->data[s->cur_offset++] = value; |
221 | if (s->cur_offset == e->len) { | |
222 | e->callback(e->callback_opaque, e->data); | |
223 | s->cur_offset = 0; | |
224 | } | |
225 | } | |
226 | } | |
227 | ||
228 | static int fw_cfg_select(FWCfgState *s, uint16_t key) | |
229 | { | |
230 | int ret; | |
231 | ||
232 | s->cur_offset = 0; | |
233 | if ((key & FW_CFG_ENTRY_MASK) >= FW_CFG_MAX_ENTRY) { | |
234 | s->cur_entry = FW_CFG_INVALID; | |
235 | ret = 0; | |
236 | } else { | |
237 | s->cur_entry = key; | |
238 | ret = 1; | |
239 | } | |
240 | ||
241 | FW_CFG_DPRINTF("select key %d (%sfound)\n", key, ret ? "" : "not "); | |
242 | ||
243 | return ret; | |
244 | } | |
245 | ||
246 | static uint8_t fw_cfg_read(FWCfgState *s) | |
247 | { | |
248 | int arch = !!(s->cur_entry & FW_CFG_ARCH_LOCAL); | |
249 | FWCfgEntry *e = &s->entries[arch][s->cur_entry & FW_CFG_ENTRY_MASK]; | |
250 | uint8_t ret; | |
251 | ||
252 | if (s->cur_entry == FW_CFG_INVALID || !e->data || s->cur_offset >= e->len) | |
253 | ret = 0; | |
254 | else | |
255 | ret = e->data[s->cur_offset++]; | |
256 | ||
257 | FW_CFG_DPRINTF("read %d\n", ret); | |
258 | ||
259 | return ret; | |
260 | } | |
261 | ||
a8170e5e | 262 | static uint64_t fw_cfg_data_mem_read(void *opaque, hwaddr addr, |
561e1827 | 263 | unsigned size) |
3cce6243 BS |
264 | { |
265 | return fw_cfg_read(opaque); | |
266 | } | |
267 | ||
a8170e5e | 268 | static void fw_cfg_data_mem_write(void *opaque, hwaddr addr, |
561e1827 | 269 | uint64_t value, unsigned size) |
3cce6243 | 270 | { |
7442511c | 271 | fw_cfg_write(opaque, (uint8_t)value); |
3cce6243 BS |
272 | } |
273 | ||
a8170e5e | 274 | static void fw_cfg_ctl_mem_write(void *opaque, hwaddr addr, |
561e1827 | 275 | uint64_t value, unsigned size) |
3cce6243 BS |
276 | { |
277 | fw_cfg_select(opaque, (uint16_t)value); | |
278 | } | |
279 | ||
a8170e5e | 280 | static bool fw_cfg_ctl_mem_valid(void *opaque, hwaddr addr, |
561e1827 | 281 | unsigned size, bool is_write) |
3cce6243 | 282 | { |
561e1827 | 283 | return is_write && size == 2; |
3cce6243 BS |
284 | } |
285 | ||
a8170e5e | 286 | static uint64_t fw_cfg_comb_read(void *opaque, hwaddr addr, |
561e1827 | 287 | unsigned size) |
3cce6243 | 288 | { |
561e1827 | 289 | return fw_cfg_read(opaque); |
3cce6243 BS |
290 | } |
291 | ||
a8170e5e | 292 | static void fw_cfg_comb_write(void *opaque, hwaddr addr, |
561e1827 | 293 | uint64_t value, unsigned size) |
3cce6243 | 294 | { |
561e1827 AK |
295 | switch (size) { |
296 | case 1: | |
297 | fw_cfg_write(opaque, (uint8_t)value); | |
298 | break; | |
299 | case 2: | |
300 | fw_cfg_select(opaque, (uint16_t)value); | |
301 | break; | |
302 | } | |
3cce6243 BS |
303 | } |
304 | ||
a8170e5e | 305 | static bool fw_cfg_comb_valid(void *opaque, hwaddr addr, |
561e1827 AK |
306 | unsigned size, bool is_write) |
307 | { | |
308 | return (size == 1) || (is_write && size == 2); | |
309 | } | |
3cce6243 | 310 | |
561e1827 AK |
311 | static const MemoryRegionOps fw_cfg_ctl_mem_ops = { |
312 | .write = fw_cfg_ctl_mem_write, | |
313 | .endianness = DEVICE_NATIVE_ENDIAN, | |
314 | .valid.accepts = fw_cfg_ctl_mem_valid, | |
3cce6243 BS |
315 | }; |
316 | ||
561e1827 AK |
317 | static const MemoryRegionOps fw_cfg_data_mem_ops = { |
318 | .read = fw_cfg_data_mem_read, | |
319 | .write = fw_cfg_data_mem_write, | |
320 | .endianness = DEVICE_NATIVE_ENDIAN, | |
321 | .valid = { | |
322 | .min_access_size = 1, | |
323 | .max_access_size = 1, | |
324 | }, | |
3cce6243 BS |
325 | }; |
326 | ||
561e1827 AK |
327 | static const MemoryRegionOps fw_cfg_comb_mem_ops = { |
328 | .read = fw_cfg_comb_read, | |
329 | .write = fw_cfg_comb_write, | |
330 | .endianness = DEVICE_NATIVE_ENDIAN, | |
331 | .valid.accepts = fw_cfg_comb_valid, | |
3cce6243 BS |
332 | }; |
333 | ||
3a5c16fc | 334 | static void fw_cfg_reset(DeviceState *d) |
3cce6243 | 335 | { |
3a5c16fc | 336 | FWCfgState *s = DO_UPCAST(FWCfgState, busdev.qdev, d); |
3cce6243 BS |
337 | |
338 | fw_cfg_select(s, 0); | |
339 | } | |
340 | ||
ff06108b JQ |
341 | /* Save restore 32 bit int as uint16_t |
342 | This is a Big hack, but it is how the old state did it. | |
343 | Or we broke compatibility in the state, or we can't use struct tm | |
344 | */ | |
345 | ||
346 | static int get_uint32_as_uint16(QEMUFile *f, void *pv, size_t size) | |
347 | { | |
348 | uint32_t *v = pv; | |
349 | *v = qemu_get_be16(f); | |
350 | return 0; | |
351 | } | |
352 | ||
353 | static void put_unused(QEMUFile *f, void *pv, size_t size) | |
354 | { | |
66c80e75 | 355 | fprintf(stderr, "uint32_as_uint16 is only used for backward compatibility.\n"); |
ff06108b JQ |
356 | fprintf(stderr, "This functions shouldn't be called.\n"); |
357 | } | |
358 | ||
d05ac8fa | 359 | static const VMStateInfo vmstate_hack_uint32_as_uint16 = { |
ff06108b JQ |
360 | .name = "int32_as_uint16", |
361 | .get = get_uint32_as_uint16, | |
362 | .put = put_unused, | |
363 | }; | |
364 | ||
365 | #define VMSTATE_UINT16_HACK(_f, _s, _t) \ | |
366 | VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_hack_uint32_as_uint16, uint32_t) | |
367 | ||
368 | ||
369 | static bool is_version_1(void *opaque, int version_id) | |
370 | { | |
371 | return version_id == 1; | |
372 | } | |
373 | ||
7d2edd40 JQ |
374 | static const VMStateDescription vmstate_fw_cfg = { |
375 | .name = "fw_cfg", | |
ff06108b | 376 | .version_id = 2, |
7d2edd40 JQ |
377 | .minimum_version_id = 1, |
378 | .minimum_version_id_old = 1, | |
379 | .fields = (VMStateField []) { | |
380 | VMSTATE_UINT16(cur_entry, FWCfgState), | |
ff06108b JQ |
381 | VMSTATE_UINT16_HACK(cur_offset, FWCfgState, is_version_1), |
382 | VMSTATE_UINT32_V(cur_offset, FWCfgState, 2), | |
7d2edd40 JQ |
383 | VMSTATE_END_OF_LIST() |
384 | } | |
385 | }; | |
3cce6243 | 386 | |
c2b5bda4 | 387 | int fw_cfg_add_bytes(FWCfgState *s, uint16_t key, uint8_t *data, uint32_t len) |
3cce6243 | 388 | { |
3cce6243 BS |
389 | int arch = !!(key & FW_CFG_ARCH_LOCAL); |
390 | ||
391 | key &= FW_CFG_ENTRY_MASK; | |
392 | ||
393 | if (key >= FW_CFG_MAX_ENTRY) | |
394 | return 0; | |
395 | ||
396 | s->entries[arch][key].data = data; | |
397 | s->entries[arch][key].len = len; | |
398 | ||
399 | return 1; | |
400 | } | |
401 | ||
c2b5bda4 | 402 | int fw_cfg_add_i16(FWCfgState *s, uint16_t key, uint16_t value) |
3cce6243 BS |
403 | { |
404 | uint16_t *copy; | |
405 | ||
7267c094 | 406 | copy = g_malloc(sizeof(value)); |
3cce6243 | 407 | *copy = cpu_to_le16(value); |
c2b5bda4 | 408 | return fw_cfg_add_bytes(s, key, (uint8_t *)copy, sizeof(value)); |
3cce6243 BS |
409 | } |
410 | ||
c2b5bda4 | 411 | int fw_cfg_add_i32(FWCfgState *s, uint16_t key, uint32_t value) |
3cce6243 BS |
412 | { |
413 | uint32_t *copy; | |
414 | ||
7267c094 | 415 | copy = g_malloc(sizeof(value)); |
3cce6243 | 416 | *copy = cpu_to_le32(value); |
c2b5bda4 | 417 | return fw_cfg_add_bytes(s, key, (uint8_t *)copy, sizeof(value)); |
3cce6243 BS |
418 | } |
419 | ||
c2b5bda4 | 420 | int fw_cfg_add_i64(FWCfgState *s, uint16_t key, uint64_t value) |
3cce6243 BS |
421 | { |
422 | uint64_t *copy; | |
423 | ||
7267c094 | 424 | copy = g_malloc(sizeof(value)); |
3cce6243 | 425 | *copy = cpu_to_le64(value); |
c2b5bda4 | 426 | return fw_cfg_add_bytes(s, key, (uint8_t *)copy, sizeof(value)); |
3cce6243 BS |
427 | } |
428 | ||
c2b5bda4 | 429 | int fw_cfg_add_callback(FWCfgState *s, uint16_t key, FWCfgCallback callback, |
3cce6243 BS |
430 | void *callback_opaque, uint8_t *data, size_t len) |
431 | { | |
3cce6243 BS |
432 | int arch = !!(key & FW_CFG_ARCH_LOCAL); |
433 | ||
85df0de4 BS |
434 | if (!(key & FW_CFG_WRITE_CHANNEL)) |
435 | return 0; | |
436 | ||
3cce6243 BS |
437 | key &= FW_CFG_ENTRY_MASK; |
438 | ||
85df0de4 | 439 | if (key >= FW_CFG_MAX_ENTRY || len > 65535) |
3cce6243 BS |
440 | return 0; |
441 | ||
442 | s->entries[arch][key].data = data; | |
443 | s->entries[arch][key].len = len; | |
444 | s->entries[arch][key].callback_opaque = callback_opaque; | |
445 | s->entries[arch][key].callback = callback; | |
446 | ||
447 | return 1; | |
448 | } | |
449 | ||
de1f34cb GN |
450 | int fw_cfg_add_file(FWCfgState *s, const char *filename, uint8_t *data, |
451 | uint32_t len) | |
abe147e0 | 452 | { |
de9352bc | 453 | int i, index; |
abe147e0 GH |
454 | |
455 | if (!s->files) { | |
456 | int dsize = sizeof(uint32_t) + sizeof(FWCfgFile) * FW_CFG_FILE_SLOTS; | |
7267c094 | 457 | s->files = g_malloc0(dsize); |
abe147e0 GH |
458 | fw_cfg_add_bytes(s, FW_CFG_FILE_DIR, (uint8_t*)s->files, dsize); |
459 | } | |
460 | ||
461 | index = be32_to_cpu(s->files->count); | |
462 | if (index == FW_CFG_FILE_SLOTS) { | |
463 | fprintf(stderr, "fw_cfg: out of file slots\n"); | |
464 | return 0; | |
465 | } | |
466 | ||
467 | fw_cfg_add_bytes(s, FW_CFG_FILE_FIRST + index, data, len); | |
468 | ||
de1f34cb GN |
469 | pstrcpy(s->files->f[index].name, sizeof(s->files->f[index].name), |
470 | filename); | |
de9352bc GH |
471 | for (i = 0; i < index; i++) { |
472 | if (strcmp(s->files->f[index].name, s->files->f[i].name) == 0) { | |
473 | FW_CFG_DPRINTF("%s: skip duplicate: %s\n", __FUNCTION__, | |
474 | s->files->f[index].name); | |
475 | return 1; | |
476 | } | |
abe147e0 | 477 | } |
de9352bc | 478 | |
abe147e0 GH |
479 | s->files->f[index].size = cpu_to_be32(len); |
480 | s->files->f[index].select = cpu_to_be16(FW_CFG_FILE_FIRST + index); | |
481 | FW_CFG_DPRINTF("%s: #%d: %s (%d bytes)\n", __FUNCTION__, | |
482 | index, s->files->f[index].name, len); | |
483 | ||
484 | s->files->count = cpu_to_be32(index+1); | |
485 | return 1; | |
486 | } | |
487 | ||
9e8dd451 | 488 | static void fw_cfg_machine_ready(struct Notifier *n, void *data) |
962630f2 GN |
489 | { |
490 | uint32_t len; | |
491 | FWCfgState *s = container_of(n, FWCfgState, machine_ready); | |
492 | char *bootindex = get_boot_devices_list(&len); | |
493 | ||
494 | fw_cfg_add_file(s, "bootorder", (uint8_t*)bootindex, len); | |
495 | } | |
496 | ||
c2b5bda4 | 497 | FWCfgState *fw_cfg_init(uint32_t ctl_port, uint32_t data_port, |
a8170e5e | 498 | hwaddr ctl_addr, hwaddr data_addr) |
3cce6243 | 499 | { |
3a5c16fc BS |
500 | DeviceState *dev; |
501 | SysBusDevice *d; | |
3cce6243 | 502 | FWCfgState *s; |
3cce6243 | 503 | |
3a5c16fc BS |
504 | dev = qdev_create(NULL, "fw_cfg"); |
505 | qdev_prop_set_uint32(dev, "ctl_iobase", ctl_port); | |
506 | qdev_prop_set_uint32(dev, "data_iobase", data_port); | |
507 | qdev_init_nofail(dev); | |
508 | d = sysbus_from_qdev(dev); | |
509 | ||
510 | s = DO_UPCAST(FWCfgState, busdev.qdev, dev); | |
3cce6243 | 511 | |
3cce6243 | 512 | if (ctl_addr) { |
3a5c16fc | 513 | sysbus_mmio_map(d, 0, ctl_addr); |
3cce6243 BS |
514 | } |
515 | if (data_addr) { | |
3a5c16fc | 516 | sysbus_mmio_map(d, 1, data_addr); |
3cce6243 BS |
517 | } |
518 | fw_cfg_add_bytes(s, FW_CFG_SIGNATURE, (uint8_t *)"QEMU", 4); | |
084a197a | 519 | fw_cfg_add_bytes(s, FW_CFG_UUID, qemu_uuid, 16); |
993fbfdb | 520 | fw_cfg_add_i16(s, FW_CFG_NOGRAPHIC, (uint16_t)(display_type == DT_NOGRAPHIC)); |
905fdcb5 | 521 | fw_cfg_add_i16(s, FW_CFG_NB_CPUS, (uint16_t)smp_cpus); |
6be68d7e | 522 | fw_cfg_add_i16(s, FW_CFG_MAX_CPUS, (uint16_t)max_cpus); |
95387491 | 523 | fw_cfg_add_i16(s, FW_CFG_BOOT_MENU, (uint16_t)boot_menu); |
3d3b8303 | 524 | fw_cfg_bootsplash(s); |
ac05f349 | 525 | fw_cfg_reboot(s); |
962630f2 GN |
526 | |
527 | s->machine_ready.notify = fw_cfg_machine_ready; | |
528 | qemu_add_machine_init_done_notifier(&s->machine_ready); | |
529 | ||
3cce6243 BS |
530 | return s; |
531 | } | |
3a5c16fc BS |
532 | |
533 | static int fw_cfg_init1(SysBusDevice *dev) | |
534 | { | |
535 | FWCfgState *s = FROM_SYSBUS(FWCfgState, dev); | |
3a5c16fc | 536 | |
561e1827 AK |
537 | memory_region_init_io(&s->ctl_iomem, &fw_cfg_ctl_mem_ops, s, |
538 | "fwcfg.ctl", FW_CFG_SIZE); | |
750ecd44 | 539 | sysbus_init_mmio(dev, &s->ctl_iomem); |
561e1827 AK |
540 | memory_region_init_io(&s->data_iomem, &fw_cfg_data_mem_ops, s, |
541 | "fwcfg.data", FW_CFG_DATA_SIZE); | |
750ecd44 | 542 | sysbus_init_mmio(dev, &s->data_iomem); |
561e1827 AK |
543 | /* In case ctl and data overlap: */ |
544 | memory_region_init_io(&s->comb_iomem, &fw_cfg_comb_mem_ops, s, | |
545 | "fwcfg", FW_CFG_SIZE); | |
546 | ||
547 | if (s->ctl_iobase + 1 == s->data_iobase) { | |
548 | sysbus_add_io(dev, s->ctl_iobase, &s->comb_iomem); | |
549 | } else { | |
550 | if (s->ctl_iobase) { | |
551 | sysbus_add_io(dev, s->ctl_iobase, &s->ctl_iomem); | |
552 | } | |
553 | if (s->data_iobase) { | |
554 | sysbus_add_io(dev, s->data_iobase, &s->data_iomem); | |
555 | } | |
3a5c16fc BS |
556 | } |
557 | return 0; | |
558 | } | |
559 | ||
999e12bb AL |
560 | static Property fw_cfg_properties[] = { |
561 | DEFINE_PROP_HEX32("ctl_iobase", FWCfgState, ctl_iobase, -1), | |
562 | DEFINE_PROP_HEX32("data_iobase", FWCfgState, data_iobase, -1), | |
563 | DEFINE_PROP_END_OF_LIST(), | |
564 | }; | |
565 | ||
566 | static void fw_cfg_class_init(ObjectClass *klass, void *data) | |
567 | { | |
39bffca2 | 568 | DeviceClass *dc = DEVICE_CLASS(klass); |
999e12bb AL |
569 | SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass); |
570 | ||
571 | k->init = fw_cfg_init1; | |
39bffca2 AL |
572 | dc->no_user = 1; |
573 | dc->reset = fw_cfg_reset; | |
574 | dc->vmsd = &vmstate_fw_cfg; | |
575 | dc->props = fw_cfg_properties; | |
999e12bb AL |
576 | } |
577 | ||
8c43a6f0 | 578 | static const TypeInfo fw_cfg_info = { |
39bffca2 AL |
579 | .name = "fw_cfg", |
580 | .parent = TYPE_SYS_BUS_DEVICE, | |
581 | .instance_size = sizeof(FWCfgState), | |
582 | .class_init = fw_cfg_class_init, | |
3a5c16fc BS |
583 | }; |
584 | ||
83f7d43a | 585 | static void fw_cfg_register_types(void) |
3a5c16fc | 586 | { |
39bffca2 | 587 | type_register_static(&fw_cfg_info); |
3a5c16fc BS |
588 | } |
589 | ||
83f7d43a | 590 | type_init(fw_cfg_register_types) |