sd/milkymist-memcard: Fix format string
[qemu/armbru.git] / hw / nvram / fw_cfg.c
blobf3a4728288eb217e466e619b3985c6154cd53633
1 /*
2 * QEMU Firmware configuration device emulation
4 * Copyright (c) 2008 Gleb Natapov
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:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
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.
25 #include "qemu/osdep.h"
26 #include "qemu-common.h"
27 #include "sysemu/sysemu.h"
28 #include "sysemu/dma.h"
29 #include "sysemu/reset.h"
30 #include "hw/boards.h"
31 #include "hw/nvram/fw_cfg.h"
32 #include "hw/qdev-properties.h"
33 #include "hw/sysbus.h"
34 #include "migration/qemu-file-types.h"
35 #include "migration/vmstate.h"
36 #include "trace.h"
37 #include "qemu/error-report.h"
38 #include "qemu/option.h"
39 #include "qemu/config-file.h"
40 #include "qemu/cutils.h"
41 #include "qapi/error.h"
42 #include "hw/acpi/aml-build.h"
44 #define FW_CFG_FILE_SLOTS_DFLT 0x20
46 /* FW_CFG_VERSION bits */
47 #define FW_CFG_VERSION 0x01
48 #define FW_CFG_VERSION_DMA 0x02
50 /* FW_CFG_DMA_CONTROL bits */
51 #define FW_CFG_DMA_CTL_ERROR 0x01
52 #define FW_CFG_DMA_CTL_READ 0x02
53 #define FW_CFG_DMA_CTL_SKIP 0x04
54 #define FW_CFG_DMA_CTL_SELECT 0x08
55 #define FW_CFG_DMA_CTL_WRITE 0x10
57 #define FW_CFG_DMA_SIGNATURE 0x51454d5520434647ULL /* "QEMU CFG" */
59 struct FWCfgEntry {
60 uint32_t len;
61 bool allow_write;
62 uint8_t *data;
63 void *callback_opaque;
64 FWCfgCallback select_cb;
65 FWCfgWriteCallback write_cb;
68 /**
69 * key_name:
71 * @key: The uint16 selector key.
73 * Returns: The stringified name if the selector refers to a well-known
74 * numerically defined item, or NULL on key lookup failure.
76 static const char *key_name(uint16_t key)
78 static const char *fw_cfg_wellknown_keys[FW_CFG_FILE_FIRST] = {
79 [FW_CFG_SIGNATURE] = "signature",
80 [FW_CFG_ID] = "id",
81 [FW_CFG_UUID] = "uuid",
82 [FW_CFG_RAM_SIZE] = "ram_size",
83 [FW_CFG_NOGRAPHIC] = "nographic",
84 [FW_CFG_NB_CPUS] = "nb_cpus",
85 [FW_CFG_MACHINE_ID] = "machine_id",
86 [FW_CFG_KERNEL_ADDR] = "kernel_addr",
87 [FW_CFG_KERNEL_SIZE] = "kernel_size",
88 [FW_CFG_KERNEL_CMDLINE] = "kernel_cmdline",
89 [FW_CFG_INITRD_ADDR] = "initrd_addr",
90 [FW_CFG_INITRD_SIZE] = "initdr_size",
91 [FW_CFG_BOOT_DEVICE] = "boot_device",
92 [FW_CFG_NUMA] = "numa",
93 [FW_CFG_BOOT_MENU] = "boot_menu",
94 [FW_CFG_MAX_CPUS] = "max_cpus",
95 [FW_CFG_KERNEL_ENTRY] = "kernel_entry",
96 [FW_CFG_KERNEL_DATA] = "kernel_data",
97 [FW_CFG_INITRD_DATA] = "initrd_data",
98 [FW_CFG_CMDLINE_ADDR] = "cmdline_addr",
99 [FW_CFG_CMDLINE_SIZE] = "cmdline_size",
100 [FW_CFG_CMDLINE_DATA] = "cmdline_data",
101 [FW_CFG_SETUP_ADDR] = "setup_addr",
102 [FW_CFG_SETUP_SIZE] = "setup_size",
103 [FW_CFG_SETUP_DATA] = "setup_data",
104 [FW_CFG_FILE_DIR] = "file_dir",
107 if (key & FW_CFG_ARCH_LOCAL) {
108 return fw_cfg_arch_key_name(key);
110 if (key < FW_CFG_FILE_FIRST) {
111 return fw_cfg_wellknown_keys[key];
114 return NULL;
117 static inline const char *trace_key_name(uint16_t key)
119 const char *name = key_name(key);
121 return name ? name : "unknown";
124 #define JPG_FILE 0
125 #define BMP_FILE 1
127 static char *read_splashfile(char *filename, gsize *file_sizep,
128 int *file_typep)
130 GError *err = NULL;
131 gchar *content;
132 int file_type;
133 unsigned int filehead;
134 int bmp_bpp;
136 if (!g_file_get_contents(filename, &content, file_sizep, &err)) {
137 error_report("failed to read splash file '%s': %s",
138 filename, err->message);
139 g_error_free(err);
140 return NULL;
143 /* check file size */
144 if (*file_sizep < 30) {
145 goto error;
148 /* check magic ID */
149 filehead = lduw_le_p(content);
150 if (filehead == 0xd8ff) {
151 file_type = JPG_FILE;
152 } else if (filehead == 0x4d42) {
153 file_type = BMP_FILE;
154 } else {
155 goto error;
158 /* check BMP bpp */
159 if (file_type == BMP_FILE) {
160 bmp_bpp = lduw_le_p(&content[28]);
161 if (bmp_bpp != 24) {
162 goto error;
166 /* return values */
167 *file_typep = file_type;
169 return content;
171 error:
172 error_report("splash file '%s' format not recognized; must be JPEG "
173 "or 24 bit BMP", filename);
174 g_free(content);
175 return NULL;
178 static void fw_cfg_bootsplash(FWCfgState *s)
180 const char *boot_splash_filename = NULL;
181 const char *boot_splash_time = NULL;
182 char *filename, *file_data;
183 gsize file_size;
184 int file_type;
186 /* get user configuration */
187 QemuOptsList *plist = qemu_find_opts("boot-opts");
188 QemuOpts *opts = QTAILQ_FIRST(&plist->head);
189 boot_splash_filename = qemu_opt_get(opts, "splash");
190 boot_splash_time = qemu_opt_get(opts, "splash-time");
192 /* insert splash time if user configurated */
193 if (boot_splash_time) {
194 int64_t bst_val = qemu_opt_get_number(opts, "splash-time", -1);
195 uint16_t bst_le16;
197 /* validate the input */
198 if (bst_val < 0 || bst_val > 0xffff) {
199 error_report("splash-time is invalid,"
200 "it should be a value between 0 and 65535");
201 exit(1);
203 /* use little endian format */
204 bst_le16 = cpu_to_le16(bst_val);
205 fw_cfg_add_file(s, "etc/boot-menu-wait",
206 g_memdup(&bst_le16, sizeof bst_le16), sizeof bst_le16);
209 /* insert splash file if user configurated */
210 if (boot_splash_filename) {
211 filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, boot_splash_filename);
212 if (filename == NULL) {
213 error_report("failed to find file '%s'", boot_splash_filename);
214 return;
217 /* loading file data */
218 file_data = read_splashfile(filename, &file_size, &file_type);
219 if (file_data == NULL) {
220 g_free(filename);
221 return;
223 g_free(boot_splash_filedata);
224 boot_splash_filedata = (uint8_t *)file_data;
226 /* insert data */
227 if (file_type == JPG_FILE) {
228 fw_cfg_add_file(s, "bootsplash.jpg",
229 boot_splash_filedata, file_size);
230 } else {
231 fw_cfg_add_file(s, "bootsplash.bmp",
232 boot_splash_filedata, file_size);
234 g_free(filename);
238 static void fw_cfg_reboot(FWCfgState *s)
240 const char *reboot_timeout = NULL;
241 uint64_t rt_val = -1;
242 uint32_t rt_le32;
244 /* get user configuration */
245 QemuOptsList *plist = qemu_find_opts("boot-opts");
246 QemuOpts *opts = QTAILQ_FIRST(&plist->head);
247 reboot_timeout = qemu_opt_get(opts, "reboot-timeout");
249 if (reboot_timeout) {
250 rt_val = qemu_opt_get_number(opts, "reboot-timeout", -1);
252 /* validate the input */
253 if (rt_val > 0xffff && rt_val != (uint64_t)-1) {
254 error_report("reboot timeout is invalid,"
255 "it should be a value between -1 and 65535");
256 exit(1);
260 rt_le32 = cpu_to_le32(rt_val);
261 fw_cfg_add_file(s, "etc/boot-fail-wait", g_memdup(&rt_le32, 4), 4);
264 static void fw_cfg_write(FWCfgState *s, uint8_t value)
266 /* nothing, write support removed in QEMU v2.4+ */
269 static inline uint16_t fw_cfg_file_slots(const FWCfgState *s)
271 return s->file_slots;
274 /* Note: this function returns an exclusive limit. */
275 static inline uint32_t fw_cfg_max_entry(const FWCfgState *s)
277 return FW_CFG_FILE_FIRST + fw_cfg_file_slots(s);
280 static int fw_cfg_select(FWCfgState *s, uint16_t key)
282 int arch, ret;
283 FWCfgEntry *e;
285 s->cur_offset = 0;
286 if ((key & FW_CFG_ENTRY_MASK) >= fw_cfg_max_entry(s)) {
287 s->cur_entry = FW_CFG_INVALID;
288 ret = 0;
289 } else {
290 s->cur_entry = key;
291 ret = 1;
292 /* entry successfully selected, now run callback if present */
293 arch = !!(key & FW_CFG_ARCH_LOCAL);
294 e = &s->entries[arch][key & FW_CFG_ENTRY_MASK];
295 if (e->select_cb) {
296 e->select_cb(e->callback_opaque);
300 trace_fw_cfg_select(s, key, trace_key_name(key), ret);
301 return ret;
304 static uint64_t fw_cfg_data_read(void *opaque, hwaddr addr, unsigned size)
306 FWCfgState *s = opaque;
307 int arch = !!(s->cur_entry & FW_CFG_ARCH_LOCAL);
308 FWCfgEntry *e = (s->cur_entry == FW_CFG_INVALID) ? NULL :
309 &s->entries[arch][s->cur_entry & FW_CFG_ENTRY_MASK];
310 uint64_t value = 0;
312 assert(size > 0 && size <= sizeof(value));
313 if (s->cur_entry != FW_CFG_INVALID && e->data && s->cur_offset < e->len) {
314 /* The least significant 'size' bytes of the return value are
315 * expected to contain a string preserving portion of the item
316 * data, padded with zeros on the right in case we run out early.
317 * In technical terms, we're composing the host-endian representation
318 * of the big endian interpretation of the fw_cfg string.
320 do {
321 value = (value << 8) | e->data[s->cur_offset++];
322 } while (--size && s->cur_offset < e->len);
323 /* If size is still not zero, we *did* run out early, so continue
324 * left-shifting, to add the appropriate number of padding zeros
325 * on the right.
327 value <<= 8 * size;
330 trace_fw_cfg_read(s, value);
331 return value;
334 static void fw_cfg_data_mem_write(void *opaque, hwaddr addr,
335 uint64_t value, unsigned size)
337 FWCfgState *s = opaque;
338 unsigned i = size;
340 do {
341 fw_cfg_write(s, value >> (8 * --i));
342 } while (i);
345 static void fw_cfg_dma_transfer(FWCfgState *s)
347 dma_addr_t len;
348 FWCfgDmaAccess dma;
349 int arch;
350 FWCfgEntry *e;
351 int read = 0, write = 0;
352 dma_addr_t dma_addr;
354 /* Reset the address before the next access */
355 dma_addr = s->dma_addr;
356 s->dma_addr = 0;
358 if (dma_memory_read(s->dma_as, dma_addr, &dma, sizeof(dma))) {
359 stl_be_dma(s->dma_as, dma_addr + offsetof(FWCfgDmaAccess, control),
360 FW_CFG_DMA_CTL_ERROR);
361 return;
364 dma.address = be64_to_cpu(dma.address);
365 dma.length = be32_to_cpu(dma.length);
366 dma.control = be32_to_cpu(dma.control);
368 if (dma.control & FW_CFG_DMA_CTL_SELECT) {
369 fw_cfg_select(s, dma.control >> 16);
372 arch = !!(s->cur_entry & FW_CFG_ARCH_LOCAL);
373 e = (s->cur_entry == FW_CFG_INVALID) ? NULL :
374 &s->entries[arch][s->cur_entry & FW_CFG_ENTRY_MASK];
376 if (dma.control & FW_CFG_DMA_CTL_READ) {
377 read = 1;
378 write = 0;
379 } else if (dma.control & FW_CFG_DMA_CTL_WRITE) {
380 read = 0;
381 write = 1;
382 } else if (dma.control & FW_CFG_DMA_CTL_SKIP) {
383 read = 0;
384 write = 0;
385 } else {
386 dma.length = 0;
389 dma.control = 0;
391 while (dma.length > 0 && !(dma.control & FW_CFG_DMA_CTL_ERROR)) {
392 if (s->cur_entry == FW_CFG_INVALID || !e->data ||
393 s->cur_offset >= e->len) {
394 len = dma.length;
396 /* If the access is not a read access, it will be a skip access,
397 * tested before.
399 if (read) {
400 if (dma_memory_set(s->dma_as, dma.address, 0, len)) {
401 dma.control |= FW_CFG_DMA_CTL_ERROR;
404 if (write) {
405 dma.control |= FW_CFG_DMA_CTL_ERROR;
407 } else {
408 if (dma.length <= (e->len - s->cur_offset)) {
409 len = dma.length;
410 } else {
411 len = (e->len - s->cur_offset);
414 /* If the access is not a read access, it will be a skip access,
415 * tested before.
417 if (read) {
418 if (dma_memory_write(s->dma_as, dma.address,
419 &e->data[s->cur_offset], len)) {
420 dma.control |= FW_CFG_DMA_CTL_ERROR;
423 if (write) {
424 if (!e->allow_write ||
425 len != dma.length ||
426 dma_memory_read(s->dma_as, dma.address,
427 &e->data[s->cur_offset], len)) {
428 dma.control |= FW_CFG_DMA_CTL_ERROR;
429 } else if (e->write_cb) {
430 e->write_cb(e->callback_opaque, s->cur_offset, len);
434 s->cur_offset += len;
437 dma.address += len;
438 dma.length -= len;
442 stl_be_dma(s->dma_as, dma_addr + offsetof(FWCfgDmaAccess, control),
443 dma.control);
445 trace_fw_cfg_read(s, 0);
448 static uint64_t fw_cfg_dma_mem_read(void *opaque, hwaddr addr,
449 unsigned size)
451 /* Return a signature value (and handle various read sizes) */
452 return extract64(FW_CFG_DMA_SIGNATURE, (8 - addr - size) * 8, size * 8);
455 static void fw_cfg_dma_mem_write(void *opaque, hwaddr addr,
456 uint64_t value, unsigned size)
458 FWCfgState *s = opaque;
460 if (size == 4) {
461 if (addr == 0) {
462 /* FWCfgDmaAccess high address */
463 s->dma_addr = value << 32;
464 } else if (addr == 4) {
465 /* FWCfgDmaAccess low address */
466 s->dma_addr |= value;
467 fw_cfg_dma_transfer(s);
469 } else if (size == 8 && addr == 0) {
470 s->dma_addr = value;
471 fw_cfg_dma_transfer(s);
475 static bool fw_cfg_dma_mem_valid(void *opaque, hwaddr addr,
476 unsigned size, bool is_write,
477 MemTxAttrs attrs)
479 return !is_write || ((size == 4 && (addr == 0 || addr == 4)) ||
480 (size == 8 && addr == 0));
483 static bool fw_cfg_data_mem_valid(void *opaque, hwaddr addr,
484 unsigned size, bool is_write,
485 MemTxAttrs attrs)
487 return addr == 0;
490 static uint64_t fw_cfg_ctl_mem_read(void *opaque, hwaddr addr, unsigned size)
492 return 0;
495 static void fw_cfg_ctl_mem_write(void *opaque, hwaddr addr,
496 uint64_t value, unsigned size)
498 fw_cfg_select(opaque, (uint16_t)value);
501 static bool fw_cfg_ctl_mem_valid(void *opaque, hwaddr addr,
502 unsigned size, bool is_write,
503 MemTxAttrs attrs)
505 return is_write && size == 2;
508 static void fw_cfg_comb_write(void *opaque, hwaddr addr,
509 uint64_t value, unsigned size)
511 switch (size) {
512 case 1:
513 fw_cfg_write(opaque, (uint8_t)value);
514 break;
515 case 2:
516 fw_cfg_select(opaque, (uint16_t)value);
517 break;
521 static bool fw_cfg_comb_valid(void *opaque, hwaddr addr,
522 unsigned size, bool is_write,
523 MemTxAttrs attrs)
525 return (size == 1) || (is_write && size == 2);
528 static const MemoryRegionOps fw_cfg_ctl_mem_ops = {
529 .read = fw_cfg_ctl_mem_read,
530 .write = fw_cfg_ctl_mem_write,
531 .endianness = DEVICE_BIG_ENDIAN,
532 .valid.accepts = fw_cfg_ctl_mem_valid,
535 static const MemoryRegionOps fw_cfg_data_mem_ops = {
536 .read = fw_cfg_data_read,
537 .write = fw_cfg_data_mem_write,
538 .endianness = DEVICE_BIG_ENDIAN,
539 .valid = {
540 .min_access_size = 1,
541 .max_access_size = 1,
542 .accepts = fw_cfg_data_mem_valid,
546 static const MemoryRegionOps fw_cfg_comb_mem_ops = {
547 .read = fw_cfg_data_read,
548 .write = fw_cfg_comb_write,
549 .endianness = DEVICE_LITTLE_ENDIAN,
550 .valid.accepts = fw_cfg_comb_valid,
553 static const MemoryRegionOps fw_cfg_dma_mem_ops = {
554 .read = fw_cfg_dma_mem_read,
555 .write = fw_cfg_dma_mem_write,
556 .endianness = DEVICE_BIG_ENDIAN,
557 .valid.accepts = fw_cfg_dma_mem_valid,
558 .valid.max_access_size = 8,
559 .impl.max_access_size = 8,
562 static void fw_cfg_reset(DeviceState *d)
564 FWCfgState *s = FW_CFG(d);
566 /* we never register a read callback for FW_CFG_SIGNATURE */
567 fw_cfg_select(s, FW_CFG_SIGNATURE);
570 /* Save restore 32 bit int as uint16_t
571 This is a Big hack, but it is how the old state did it.
572 Or we broke compatibility in the state, or we can't use struct tm
575 static int get_uint32_as_uint16(QEMUFile *f, void *pv, size_t size,
576 const VMStateField *field)
578 uint32_t *v = pv;
579 *v = qemu_get_be16(f);
580 return 0;
583 static int put_unused(QEMUFile *f, void *pv, size_t size,
584 const VMStateField *field, QJSON *vmdesc)
586 fprintf(stderr, "uint32_as_uint16 is only used for backward compatibility.\n");
587 fprintf(stderr, "This functions shouldn't be called.\n");
589 return 0;
592 static const VMStateInfo vmstate_hack_uint32_as_uint16 = {
593 .name = "int32_as_uint16",
594 .get = get_uint32_as_uint16,
595 .put = put_unused,
598 #define VMSTATE_UINT16_HACK(_f, _s, _t) \
599 VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_hack_uint32_as_uint16, uint32_t)
602 static bool is_version_1(void *opaque, int version_id)
604 return version_id == 1;
607 bool fw_cfg_dma_enabled(void *opaque)
609 FWCfgState *s = opaque;
611 return s->dma_enabled;
614 static bool fw_cfg_acpi_mr_restore(void *opaque)
616 FWCfgState *s = opaque;
617 bool mr_aligned;
619 mr_aligned = QEMU_IS_ALIGNED(s->table_mr_size, qemu_real_host_page_size) &&
620 QEMU_IS_ALIGNED(s->linker_mr_size, qemu_real_host_page_size) &&
621 QEMU_IS_ALIGNED(s->rsdp_mr_size, qemu_real_host_page_size);
622 return s->acpi_mr_restore && !mr_aligned;
625 static void fw_cfg_update_mr(FWCfgState *s, uint16_t key, size_t size)
627 MemoryRegion *mr;
628 ram_addr_t offset;
629 int arch = !!(key & FW_CFG_ARCH_LOCAL);
630 void *ptr;
632 key &= FW_CFG_ENTRY_MASK;
633 assert(key < fw_cfg_max_entry(s));
635 ptr = s->entries[arch][key].data;
636 mr = memory_region_from_host(ptr, &offset);
638 memory_region_ram_resize(mr, size, &error_abort);
641 static int fw_cfg_acpi_mr_restore_post_load(void *opaque, int version_id)
643 FWCfgState *s = opaque;
644 int i, index;
646 assert(s->files);
648 index = be32_to_cpu(s->files->count);
650 for (i = 0; i < index; i++) {
651 if (!strcmp(s->files->f[i].name, ACPI_BUILD_TABLE_FILE)) {
652 fw_cfg_update_mr(s, FW_CFG_FILE_FIRST + i, s->table_mr_size);
653 } else if (!strcmp(s->files->f[i].name, ACPI_BUILD_LOADER_FILE)) {
654 fw_cfg_update_mr(s, FW_CFG_FILE_FIRST + i, s->linker_mr_size);
655 } else if (!strcmp(s->files->f[i].name, ACPI_BUILD_RSDP_FILE)) {
656 fw_cfg_update_mr(s, FW_CFG_FILE_FIRST + i, s->rsdp_mr_size);
660 return 0;
663 static const VMStateDescription vmstate_fw_cfg_dma = {
664 .name = "fw_cfg/dma",
665 .needed = fw_cfg_dma_enabled,
666 .fields = (VMStateField[]) {
667 VMSTATE_UINT64(dma_addr, FWCfgState),
668 VMSTATE_END_OF_LIST()
672 static const VMStateDescription vmstate_fw_cfg_acpi_mr = {
673 .name = "fw_cfg/acpi_mr",
674 .version_id = 1,
675 .minimum_version_id = 1,
676 .needed = fw_cfg_acpi_mr_restore,
677 .post_load = fw_cfg_acpi_mr_restore_post_load,
678 .fields = (VMStateField[]) {
679 VMSTATE_UINT64(table_mr_size, FWCfgState),
680 VMSTATE_UINT64(linker_mr_size, FWCfgState),
681 VMSTATE_UINT64(rsdp_mr_size, FWCfgState),
682 VMSTATE_END_OF_LIST()
686 static const VMStateDescription vmstate_fw_cfg = {
687 .name = "fw_cfg",
688 .version_id = 2,
689 .minimum_version_id = 1,
690 .fields = (VMStateField[]) {
691 VMSTATE_UINT16(cur_entry, FWCfgState),
692 VMSTATE_UINT16_HACK(cur_offset, FWCfgState, is_version_1),
693 VMSTATE_UINT32_V(cur_offset, FWCfgState, 2),
694 VMSTATE_END_OF_LIST()
696 .subsections = (const VMStateDescription*[]) {
697 &vmstate_fw_cfg_dma,
698 &vmstate_fw_cfg_acpi_mr,
699 NULL,
703 static void fw_cfg_add_bytes_callback(FWCfgState *s, uint16_t key,
704 FWCfgCallback select_cb,
705 FWCfgWriteCallback write_cb,
706 void *callback_opaque,
707 void *data, size_t len,
708 bool read_only)
710 int arch = !!(key & FW_CFG_ARCH_LOCAL);
712 key &= FW_CFG_ENTRY_MASK;
714 assert(key < fw_cfg_max_entry(s) && len < UINT32_MAX);
715 assert(s->entries[arch][key].data == NULL); /* avoid key conflict */
717 s->entries[arch][key].data = data;
718 s->entries[arch][key].len = (uint32_t)len;
719 s->entries[arch][key].select_cb = select_cb;
720 s->entries[arch][key].write_cb = write_cb;
721 s->entries[arch][key].callback_opaque = callback_opaque;
722 s->entries[arch][key].allow_write = !read_only;
725 static void *fw_cfg_modify_bytes_read(FWCfgState *s, uint16_t key,
726 void *data, size_t len)
728 void *ptr;
729 int arch = !!(key & FW_CFG_ARCH_LOCAL);
731 key &= FW_CFG_ENTRY_MASK;
733 assert(key < fw_cfg_max_entry(s) && len < UINT32_MAX);
735 /* return the old data to the function caller, avoid memory leak */
736 ptr = s->entries[arch][key].data;
737 s->entries[arch][key].data = data;
738 s->entries[arch][key].len = len;
739 s->entries[arch][key].callback_opaque = NULL;
740 s->entries[arch][key].allow_write = false;
742 return ptr;
745 void fw_cfg_add_bytes(FWCfgState *s, uint16_t key, void *data, size_t len)
747 trace_fw_cfg_add_bytes(key, trace_key_name(key), len);
748 fw_cfg_add_bytes_callback(s, key, NULL, NULL, NULL, data, len, true);
751 void fw_cfg_add_string(FWCfgState *s, uint16_t key, const char *value)
753 size_t sz = strlen(value) + 1;
755 trace_fw_cfg_add_string(key, trace_key_name(key), value);
756 fw_cfg_add_bytes(s, key, g_memdup(value, sz), sz);
759 void fw_cfg_modify_string(FWCfgState *s, uint16_t key, const char *value)
761 size_t sz = strlen(value) + 1;
762 char *old;
764 old = fw_cfg_modify_bytes_read(s, key, g_memdup(value, sz), sz);
765 g_free(old);
768 void fw_cfg_add_i16(FWCfgState *s, uint16_t key, uint16_t value)
770 uint16_t *copy;
772 copy = g_malloc(sizeof(value));
773 *copy = cpu_to_le16(value);
774 trace_fw_cfg_add_i16(key, trace_key_name(key), value);
775 fw_cfg_add_bytes(s, key, copy, sizeof(value));
778 void fw_cfg_modify_i16(FWCfgState *s, uint16_t key, uint16_t value)
780 uint16_t *copy, *old;
782 copy = g_malloc(sizeof(value));
783 *copy = cpu_to_le16(value);
784 old = fw_cfg_modify_bytes_read(s, key, copy, sizeof(value));
785 g_free(old);
788 void fw_cfg_add_i32(FWCfgState *s, uint16_t key, uint32_t value)
790 uint32_t *copy;
792 copy = g_malloc(sizeof(value));
793 *copy = cpu_to_le32(value);
794 trace_fw_cfg_add_i32(key, trace_key_name(key), value);
795 fw_cfg_add_bytes(s, key, copy, sizeof(value));
798 void fw_cfg_modify_i32(FWCfgState *s, uint16_t key, uint32_t value)
800 uint32_t *copy, *old;
802 copy = g_malloc(sizeof(value));
803 *copy = cpu_to_le32(value);
804 old = fw_cfg_modify_bytes_read(s, key, copy, sizeof(value));
805 g_free(old);
808 void fw_cfg_add_i64(FWCfgState *s, uint16_t key, uint64_t value)
810 uint64_t *copy;
812 copy = g_malloc(sizeof(value));
813 *copy = cpu_to_le64(value);
814 trace_fw_cfg_add_i64(key, trace_key_name(key), value);
815 fw_cfg_add_bytes(s, key, copy, sizeof(value));
818 void fw_cfg_modify_i64(FWCfgState *s, uint16_t key, uint64_t value)
820 uint64_t *copy, *old;
822 copy = g_malloc(sizeof(value));
823 *copy = cpu_to_le64(value);
824 old = fw_cfg_modify_bytes_read(s, key, copy, sizeof(value));
825 g_free(old);
828 void fw_cfg_set_order_override(FWCfgState *s, int order)
830 assert(s->fw_cfg_order_override == 0);
831 s->fw_cfg_order_override = order;
834 void fw_cfg_reset_order_override(FWCfgState *s)
836 assert(s->fw_cfg_order_override != 0);
837 s->fw_cfg_order_override = 0;
841 * This is the legacy order list. For legacy systems, files are in
842 * the fw_cfg in the order defined below, by the "order" value. Note
843 * that some entries (VGA ROMs, NIC option ROMS, etc.) go into a
844 * specific area, but there may be more than one and they occur in the
845 * order that the user specifies them on the command line. Those are
846 * handled in a special manner, using the order override above.
848 * For non-legacy, the files are sorted by filename to avoid this kind
849 * of complexity in the future.
851 * This is only for x86, other arches don't implement versioning so
852 * they won't set legacy mode.
854 static struct {
855 const char *name;
856 int order;
857 } fw_cfg_order[] = {
858 { "etc/boot-menu-wait", 10 },
859 { "bootsplash.jpg", 11 },
860 { "bootsplash.bmp", 12 },
861 { "etc/boot-fail-wait", 15 },
862 { "etc/smbios/smbios-tables", 20 },
863 { "etc/smbios/smbios-anchor", 30 },
864 { "etc/e820", 40 },
865 { "etc/reserved-memory-end", 50 },
866 { "genroms/kvmvapic.bin", 55 },
867 { "genroms/linuxboot.bin", 60 },
868 { }, /* VGA ROMs from pc_vga_init come here, 70. */
869 { }, /* NIC option ROMs from pc_nic_init come here, 80. */
870 { "etc/system-states", 90 },
871 { }, /* User ROMs come here, 100. */
872 { }, /* Device FW comes here, 110. */
873 { "etc/extra-pci-roots", 120 },
874 { "etc/acpi/tables", 130 },
875 { "etc/table-loader", 140 },
876 { "etc/tpm/log", 150 },
877 { "etc/acpi/rsdp", 160 },
878 { "bootorder", 170 },
880 #define FW_CFG_ORDER_OVERRIDE_LAST 200
884 * Any sub-page size update to these table MRs will be lost during migration,
885 * as we use aligned size in ram_load_precopy() -> qemu_ram_resize() path.
886 * In order to avoid the inconsistency in sizes save them seperately and
887 * migrate over in vmstate post_load().
889 static void fw_cfg_acpi_mr_save(FWCfgState *s, const char *filename, size_t len)
891 if (!strcmp(filename, ACPI_BUILD_TABLE_FILE)) {
892 s->table_mr_size = len;
893 } else if (!strcmp(filename, ACPI_BUILD_LOADER_FILE)) {
894 s->linker_mr_size = len;
895 } else if (!strcmp(filename, ACPI_BUILD_RSDP_FILE)) {
896 s->rsdp_mr_size = len;
900 static int get_fw_cfg_order(FWCfgState *s, const char *name)
902 int i;
904 if (s->fw_cfg_order_override > 0) {
905 return s->fw_cfg_order_override;
908 for (i = 0; i < ARRAY_SIZE(fw_cfg_order); i++) {
909 if (fw_cfg_order[i].name == NULL) {
910 continue;
913 if (strcmp(name, fw_cfg_order[i].name) == 0) {
914 return fw_cfg_order[i].order;
918 /* Stick unknown stuff at the end. */
919 warn_report("Unknown firmware file in legacy mode: %s", name);
920 return FW_CFG_ORDER_OVERRIDE_LAST;
923 void fw_cfg_add_file_callback(FWCfgState *s, const char *filename,
924 FWCfgCallback select_cb,
925 FWCfgWriteCallback write_cb,
926 void *callback_opaque,
927 void *data, size_t len, bool read_only)
929 int i, index, count;
930 size_t dsize;
931 MachineClass *mc = MACHINE_GET_CLASS(qdev_get_machine());
932 int order = 0;
934 if (!s->files) {
935 dsize = sizeof(uint32_t) + sizeof(FWCfgFile) * fw_cfg_file_slots(s);
936 s->files = g_malloc0(dsize);
937 fw_cfg_add_bytes(s, FW_CFG_FILE_DIR, s->files, dsize);
940 count = be32_to_cpu(s->files->count);
941 assert(count < fw_cfg_file_slots(s));
943 /* Find the insertion point. */
944 if (mc->legacy_fw_cfg_order) {
946 * Sort by order. For files with the same order, we keep them
947 * in the sequence in which they were added.
949 order = get_fw_cfg_order(s, filename);
950 for (index = count;
951 index > 0 && order < s->entry_order[index - 1];
952 index--);
953 } else {
954 /* Sort by file name. */
955 for (index = count;
956 index > 0 && strcmp(filename, s->files->f[index - 1].name) < 0;
957 index--);
961 * Move all the entries from the index point and after down one
962 * to create a slot for the new entry. Because calculations are
963 * being done with the index, make it so that "i" is the current
964 * index and "i - 1" is the one being copied from, thus the
965 * unusual start and end in the for statement.
967 for (i = count; i > index; i--) {
968 s->files->f[i] = s->files->f[i - 1];
969 s->files->f[i].select = cpu_to_be16(FW_CFG_FILE_FIRST + i);
970 s->entries[0][FW_CFG_FILE_FIRST + i] =
971 s->entries[0][FW_CFG_FILE_FIRST + i - 1];
972 s->entry_order[i] = s->entry_order[i - 1];
975 memset(&s->files->f[index], 0, sizeof(FWCfgFile));
976 memset(&s->entries[0][FW_CFG_FILE_FIRST + index], 0, sizeof(FWCfgEntry));
978 pstrcpy(s->files->f[index].name, sizeof(s->files->f[index].name), filename);
979 for (i = 0; i <= count; i++) {
980 if (i != index &&
981 strcmp(s->files->f[index].name, s->files->f[i].name) == 0) {
982 error_report("duplicate fw_cfg file name: %s",
983 s->files->f[index].name);
984 exit(1);
988 fw_cfg_add_bytes_callback(s, FW_CFG_FILE_FIRST + index,
989 select_cb, write_cb,
990 callback_opaque, data, len,
991 read_only);
993 s->files->f[index].size = cpu_to_be32(len);
994 s->files->f[index].select = cpu_to_be16(FW_CFG_FILE_FIRST + index);
995 s->entry_order[index] = order;
996 trace_fw_cfg_add_file(s, index, s->files->f[index].name, len);
998 s->files->count = cpu_to_be32(count+1);
999 fw_cfg_acpi_mr_save(s, filename, len);
1002 void fw_cfg_add_file(FWCfgState *s, const char *filename,
1003 void *data, size_t len)
1005 fw_cfg_add_file_callback(s, filename, NULL, NULL, NULL, data, len, true);
1008 void *fw_cfg_modify_file(FWCfgState *s, const char *filename,
1009 void *data, size_t len)
1011 int i, index;
1012 void *ptr = NULL;
1014 assert(s->files);
1016 index = be32_to_cpu(s->files->count);
1018 for (i = 0; i < index; i++) {
1019 if (strcmp(filename, s->files->f[i].name) == 0) {
1020 ptr = fw_cfg_modify_bytes_read(s, FW_CFG_FILE_FIRST + i,
1021 data, len);
1022 s->files->f[i].size = cpu_to_be32(len);
1023 fw_cfg_acpi_mr_save(s, filename, len);
1024 return ptr;
1028 assert(index < fw_cfg_file_slots(s));
1030 /* add new one */
1031 fw_cfg_add_file_callback(s, filename, NULL, NULL, NULL, data, len, true);
1032 return NULL;
1035 bool fw_cfg_add_from_generator(FWCfgState *s, const char *filename,
1036 const char *gen_id, Error **errp)
1038 FWCfgDataGeneratorClass *klass;
1039 GByteArray *array;
1040 Object *obj;
1041 gsize size;
1043 obj = object_resolve_path_component(object_get_objects_root(), gen_id);
1044 if (!obj) {
1045 error_setg(errp, "Cannot find object ID '%s'", gen_id);
1046 return false;
1048 if (!object_dynamic_cast(obj, TYPE_FW_CFG_DATA_GENERATOR_INTERFACE)) {
1049 error_setg(errp, "Object ID '%s' is not a '%s' subclass",
1050 gen_id, TYPE_FW_CFG_DATA_GENERATOR_INTERFACE);
1051 return false;
1053 klass = FW_CFG_DATA_GENERATOR_GET_CLASS(obj);
1054 array = klass->get_data(obj, errp);
1055 if (!array) {
1056 return false;
1058 size = array->len;
1059 fw_cfg_add_file(s, filename, g_byte_array_free(array, TRUE), size);
1061 return true;
1064 static void fw_cfg_machine_reset(void *opaque)
1066 MachineClass *mc = MACHINE_GET_CLASS(qdev_get_machine());
1067 FWCfgState *s = opaque;
1068 void *ptr;
1069 size_t len;
1070 char *buf;
1072 buf = get_boot_devices_list(&len);
1073 ptr = fw_cfg_modify_file(s, "bootorder", (uint8_t *)buf, len);
1074 g_free(ptr);
1076 if (!mc->legacy_fw_cfg_order) {
1077 buf = get_boot_devices_lchs_list(&len);
1078 ptr = fw_cfg_modify_file(s, "bios-geometry", (uint8_t *)buf, len);
1079 g_free(ptr);
1083 static void fw_cfg_machine_ready(struct Notifier *n, void *data)
1085 FWCfgState *s = container_of(n, FWCfgState, machine_ready);
1086 qemu_register_reset(fw_cfg_machine_reset, s);
1089 static Property fw_cfg_properties[] = {
1090 DEFINE_PROP_BOOL("acpi-mr-restore", FWCfgState, acpi_mr_restore, true),
1091 DEFINE_PROP_END_OF_LIST(),
1094 static void fw_cfg_common_realize(DeviceState *dev, Error **errp)
1096 FWCfgState *s = FW_CFG(dev);
1097 MachineState *machine = MACHINE(qdev_get_machine());
1098 uint32_t version = FW_CFG_VERSION;
1100 if (!fw_cfg_find()) {
1101 error_setg(errp, "at most one %s device is permitted", TYPE_FW_CFG);
1102 return;
1105 fw_cfg_add_bytes(s, FW_CFG_SIGNATURE, (char *)"QEMU", 4);
1106 fw_cfg_add_bytes(s, FW_CFG_UUID, &qemu_uuid, 16);
1107 fw_cfg_add_i16(s, FW_CFG_NOGRAPHIC, (uint16_t)!machine->enable_graphics);
1108 fw_cfg_add_i16(s, FW_CFG_BOOT_MENU, (uint16_t)boot_menu);
1109 fw_cfg_bootsplash(s);
1110 fw_cfg_reboot(s);
1112 if (s->dma_enabled) {
1113 version |= FW_CFG_VERSION_DMA;
1116 fw_cfg_add_i32(s, FW_CFG_ID, version);
1118 s->machine_ready.notify = fw_cfg_machine_ready;
1119 qemu_add_machine_init_done_notifier(&s->machine_ready);
1122 FWCfgState *fw_cfg_init_io_dma(uint32_t iobase, uint32_t dma_iobase,
1123 AddressSpace *dma_as)
1125 DeviceState *dev;
1126 SysBusDevice *sbd;
1127 FWCfgIoState *ios;
1128 FWCfgState *s;
1129 bool dma_requested = dma_iobase && dma_as;
1131 dev = qdev_new(TYPE_FW_CFG_IO);
1132 if (!dma_requested) {
1133 qdev_prop_set_bit(dev, "dma_enabled", false);
1136 object_property_add_child(OBJECT(qdev_get_machine()), TYPE_FW_CFG,
1137 OBJECT(dev));
1139 sbd = SYS_BUS_DEVICE(dev);
1140 sysbus_realize_and_unref(sbd, &error_fatal);
1141 ios = FW_CFG_IO(dev);
1142 sysbus_add_io(sbd, iobase, &ios->comb_iomem);
1144 s = FW_CFG(dev);
1146 if (s->dma_enabled) {
1147 /* 64 bits for the address field */
1148 s->dma_as = dma_as;
1149 s->dma_addr = 0;
1150 sysbus_add_io(sbd, dma_iobase, &s->dma_iomem);
1153 return s;
1156 FWCfgState *fw_cfg_init_io(uint32_t iobase)
1158 return fw_cfg_init_io_dma(iobase, 0, NULL);
1161 FWCfgState *fw_cfg_init_mem_wide(hwaddr ctl_addr,
1162 hwaddr data_addr, uint32_t data_width,
1163 hwaddr dma_addr, AddressSpace *dma_as)
1165 DeviceState *dev;
1166 SysBusDevice *sbd;
1167 FWCfgState *s;
1168 bool dma_requested = dma_addr && dma_as;
1170 dev = qdev_new(TYPE_FW_CFG_MEM);
1171 qdev_prop_set_uint32(dev, "data_width", data_width);
1172 if (!dma_requested) {
1173 qdev_prop_set_bit(dev, "dma_enabled", false);
1176 object_property_add_child(OBJECT(qdev_get_machine()), TYPE_FW_CFG,
1177 OBJECT(dev));
1179 sbd = SYS_BUS_DEVICE(dev);
1180 sysbus_realize_and_unref(sbd, &error_fatal);
1181 sysbus_mmio_map(sbd, 0, ctl_addr);
1182 sysbus_mmio_map(sbd, 1, data_addr);
1184 s = FW_CFG(dev);
1186 if (s->dma_enabled) {
1187 s->dma_as = dma_as;
1188 s->dma_addr = 0;
1189 sysbus_mmio_map(sbd, 2, dma_addr);
1192 return s;
1195 FWCfgState *fw_cfg_init_mem(hwaddr ctl_addr, hwaddr data_addr)
1197 return fw_cfg_init_mem_wide(ctl_addr, data_addr,
1198 fw_cfg_data_mem_ops.valid.max_access_size,
1199 0, NULL);
1203 FWCfgState *fw_cfg_find(void)
1205 /* Returns NULL unless there is exactly one fw_cfg device */
1206 return FW_CFG(object_resolve_path_type("", TYPE_FW_CFG, NULL));
1210 static void fw_cfg_class_init(ObjectClass *klass, void *data)
1212 DeviceClass *dc = DEVICE_CLASS(klass);
1214 dc->reset = fw_cfg_reset;
1215 dc->vmsd = &vmstate_fw_cfg;
1217 device_class_set_props(dc, fw_cfg_properties);
1220 static const TypeInfo fw_cfg_info = {
1221 .name = TYPE_FW_CFG,
1222 .parent = TYPE_SYS_BUS_DEVICE,
1223 .abstract = true,
1224 .instance_size = sizeof(FWCfgState),
1225 .class_init = fw_cfg_class_init,
1228 static void fw_cfg_file_slots_allocate(FWCfgState *s, Error **errp)
1230 uint16_t file_slots_max;
1232 if (fw_cfg_file_slots(s) < FW_CFG_FILE_SLOTS_MIN) {
1233 error_setg(errp, "\"file_slots\" must be at least 0x%x",
1234 FW_CFG_FILE_SLOTS_MIN);
1235 return;
1238 /* (UINT16_MAX & FW_CFG_ENTRY_MASK) is the highest inclusive selector value
1239 * that we permit. The actual (exclusive) value coming from the
1240 * configuration is (FW_CFG_FILE_FIRST + fw_cfg_file_slots(s)). */
1241 file_slots_max = (UINT16_MAX & FW_CFG_ENTRY_MASK) - FW_CFG_FILE_FIRST + 1;
1242 if (fw_cfg_file_slots(s) > file_slots_max) {
1243 error_setg(errp, "\"file_slots\" must not exceed 0x%" PRIx16,
1244 file_slots_max);
1245 return;
1248 s->entries[0] = g_new0(FWCfgEntry, fw_cfg_max_entry(s));
1249 s->entries[1] = g_new0(FWCfgEntry, fw_cfg_max_entry(s));
1250 s->entry_order = g_new0(int, fw_cfg_max_entry(s));
1253 static Property fw_cfg_io_properties[] = {
1254 DEFINE_PROP_BOOL("dma_enabled", FWCfgIoState, parent_obj.dma_enabled,
1255 true),
1256 DEFINE_PROP_UINT16("x-file-slots", FWCfgIoState, parent_obj.file_slots,
1257 FW_CFG_FILE_SLOTS_DFLT),
1258 DEFINE_PROP_END_OF_LIST(),
1261 static void fw_cfg_io_realize(DeviceState *dev, Error **errp)
1263 ERRP_GUARD();
1264 FWCfgIoState *s = FW_CFG_IO(dev);
1266 fw_cfg_file_slots_allocate(FW_CFG(s), errp);
1267 if (*errp) {
1268 return;
1271 /* when using port i/o, the 8-bit data register ALWAYS overlaps
1272 * with half of the 16-bit control register. Hence, the total size
1273 * of the i/o region used is FW_CFG_CTL_SIZE */
1274 memory_region_init_io(&s->comb_iomem, OBJECT(s), &fw_cfg_comb_mem_ops,
1275 FW_CFG(s), "fwcfg", FW_CFG_CTL_SIZE);
1277 if (FW_CFG(s)->dma_enabled) {
1278 memory_region_init_io(&FW_CFG(s)->dma_iomem, OBJECT(s),
1279 &fw_cfg_dma_mem_ops, FW_CFG(s), "fwcfg.dma",
1280 sizeof(dma_addr_t));
1283 fw_cfg_common_realize(dev, errp);
1286 static void fw_cfg_io_class_init(ObjectClass *klass, void *data)
1288 DeviceClass *dc = DEVICE_CLASS(klass);
1290 dc->realize = fw_cfg_io_realize;
1291 device_class_set_props(dc, fw_cfg_io_properties);
1294 static const TypeInfo fw_cfg_io_info = {
1295 .name = TYPE_FW_CFG_IO,
1296 .parent = TYPE_FW_CFG,
1297 .instance_size = sizeof(FWCfgIoState),
1298 .class_init = fw_cfg_io_class_init,
1302 static Property fw_cfg_mem_properties[] = {
1303 DEFINE_PROP_UINT32("data_width", FWCfgMemState, data_width, -1),
1304 DEFINE_PROP_BOOL("dma_enabled", FWCfgMemState, parent_obj.dma_enabled,
1305 true),
1306 DEFINE_PROP_UINT16("x-file-slots", FWCfgMemState, parent_obj.file_slots,
1307 FW_CFG_FILE_SLOTS_DFLT),
1308 DEFINE_PROP_END_OF_LIST(),
1311 static void fw_cfg_mem_realize(DeviceState *dev, Error **errp)
1313 ERRP_GUARD();
1314 FWCfgMemState *s = FW_CFG_MEM(dev);
1315 SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
1316 const MemoryRegionOps *data_ops = &fw_cfg_data_mem_ops;
1318 fw_cfg_file_slots_allocate(FW_CFG(s), errp);
1319 if (*errp) {
1320 return;
1323 memory_region_init_io(&s->ctl_iomem, OBJECT(s), &fw_cfg_ctl_mem_ops,
1324 FW_CFG(s), "fwcfg.ctl", FW_CFG_CTL_SIZE);
1325 sysbus_init_mmio(sbd, &s->ctl_iomem);
1327 if (s->data_width > data_ops->valid.max_access_size) {
1328 s->wide_data_ops = *data_ops;
1330 s->wide_data_ops.valid.max_access_size = s->data_width;
1331 s->wide_data_ops.impl.max_access_size = s->data_width;
1332 data_ops = &s->wide_data_ops;
1334 memory_region_init_io(&s->data_iomem, OBJECT(s), data_ops, FW_CFG(s),
1335 "fwcfg.data", data_ops->valid.max_access_size);
1336 sysbus_init_mmio(sbd, &s->data_iomem);
1338 if (FW_CFG(s)->dma_enabled) {
1339 memory_region_init_io(&FW_CFG(s)->dma_iomem, OBJECT(s),
1340 &fw_cfg_dma_mem_ops, FW_CFG(s), "fwcfg.dma",
1341 sizeof(dma_addr_t));
1342 sysbus_init_mmio(sbd, &FW_CFG(s)->dma_iomem);
1345 fw_cfg_common_realize(dev, errp);
1348 static void fw_cfg_mem_class_init(ObjectClass *klass, void *data)
1350 DeviceClass *dc = DEVICE_CLASS(klass);
1352 dc->realize = fw_cfg_mem_realize;
1353 device_class_set_props(dc, fw_cfg_mem_properties);
1356 static const TypeInfo fw_cfg_mem_info = {
1357 .name = TYPE_FW_CFG_MEM,
1358 .parent = TYPE_FW_CFG,
1359 .instance_size = sizeof(FWCfgMemState),
1360 .class_init = fw_cfg_mem_class_init,
1363 static const TypeInfo fw_cfg_data_generator_interface_info = {
1364 .parent = TYPE_INTERFACE,
1365 .name = TYPE_FW_CFG_DATA_GENERATOR_INTERFACE,
1366 .class_size = sizeof(FWCfgDataGeneratorClass),
1369 static void fw_cfg_register_types(void)
1371 type_register_static(&fw_cfg_info);
1372 type_register_static(&fw_cfg_io_info);
1373 type_register_static(&fw_cfg_mem_info);
1374 type_register_static(&fw_cfg_data_generator_interface_info);
1377 type_init(fw_cfg_register_types)