acpi: add aml_local() term
[qemu/ar7.git] / hw / nvram / fw_cfg.c
blob78a37be42b38da405870661f6a561923b19e2064
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.
24 #include "hw/hw.h"
25 #include "sysemu/sysemu.h"
26 #include "hw/isa/isa.h"
27 #include "hw/nvram/fw_cfg.h"
28 #include "hw/sysbus.h"
29 #include "trace.h"
30 #include "qemu/error-report.h"
31 #include "qemu/config-file.h"
33 #define FW_CFG_SIZE 2
34 #define FW_CFG_NAME "fw_cfg"
35 #define FW_CFG_PATH "/machine/" FW_CFG_NAME
37 #define TYPE_FW_CFG "fw_cfg"
38 #define TYPE_FW_CFG_IO "fw_cfg_io"
39 #define TYPE_FW_CFG_MEM "fw_cfg_mem"
41 #define FW_CFG(obj) OBJECT_CHECK(FWCfgState, (obj), TYPE_FW_CFG)
42 #define FW_CFG_IO(obj) OBJECT_CHECK(FWCfgIoState, (obj), TYPE_FW_CFG_IO)
43 #define FW_CFG_MEM(obj) OBJECT_CHECK(FWCfgMemState, (obj), TYPE_FW_CFG_MEM)
45 typedef struct FWCfgEntry {
46 uint32_t len;
47 uint8_t *data;
48 void *callback_opaque;
49 FWCfgCallback callback;
50 FWCfgReadCallback read_callback;
51 } FWCfgEntry;
53 struct FWCfgState {
54 /*< private >*/
55 SysBusDevice parent_obj;
56 /*< public >*/
58 FWCfgEntry entries[2][FW_CFG_MAX_ENTRY];
59 FWCfgFiles *files;
60 uint16_t cur_entry;
61 uint32_t cur_offset;
62 Notifier machine_ready;
65 struct FWCfgIoState {
66 /*< private >*/
67 FWCfgState parent_obj;
68 /*< public >*/
70 MemoryRegion comb_iomem;
71 uint32_t iobase;
74 struct FWCfgMemState {
75 /*< private >*/
76 FWCfgState parent_obj;
77 /*< public >*/
79 MemoryRegion ctl_iomem, data_iomem;
80 uint32_t data_width;
81 MemoryRegionOps wide_data_ops;
84 #define JPG_FILE 0
85 #define BMP_FILE 1
87 static char *read_splashfile(char *filename, gsize *file_sizep,
88 int *file_typep)
90 GError *err = NULL;
91 gboolean res;
92 gchar *content;
93 int file_type;
94 unsigned int filehead;
95 int bmp_bpp;
97 res = g_file_get_contents(filename, &content, file_sizep, &err);
98 if (res == FALSE) {
99 error_report("failed to read splash file '%s'", filename);
100 g_error_free(err);
101 return NULL;
104 /* check file size */
105 if (*file_sizep < 30) {
106 goto error;
109 /* check magic ID */
110 filehead = ((content[0] & 0xff) + (content[1] << 8)) & 0xffff;
111 if (filehead == 0xd8ff) {
112 file_type = JPG_FILE;
113 } else if (filehead == 0x4d42) {
114 file_type = BMP_FILE;
115 } else {
116 goto error;
119 /* check BMP bpp */
120 if (file_type == BMP_FILE) {
121 bmp_bpp = (content[28] + (content[29] << 8)) & 0xffff;
122 if (bmp_bpp != 24) {
123 goto error;
127 /* return values */
128 *file_typep = file_type;
130 return content;
132 error:
133 error_report("splash file '%s' format not recognized; must be JPEG "
134 "or 24 bit BMP", filename);
135 g_free(content);
136 return NULL;
139 static void fw_cfg_bootsplash(FWCfgState *s)
141 int boot_splash_time = -1;
142 const char *boot_splash_filename = NULL;
143 char *p;
144 char *filename, *file_data;
145 gsize file_size;
146 int file_type;
147 const char *temp;
149 /* get user configuration */
150 QemuOptsList *plist = qemu_find_opts("boot-opts");
151 QemuOpts *opts = QTAILQ_FIRST(&plist->head);
152 if (opts != NULL) {
153 temp = qemu_opt_get(opts, "splash");
154 if (temp != NULL) {
155 boot_splash_filename = temp;
157 temp = qemu_opt_get(opts, "splash-time");
158 if (temp != NULL) {
159 p = (char *)temp;
160 boot_splash_time = strtol(p, (char **)&p, 10);
164 /* insert splash time if user configurated */
165 if (boot_splash_time >= 0) {
166 /* validate the input */
167 if (boot_splash_time > 0xffff) {
168 error_report("splash time is big than 65535, force it to 65535.");
169 boot_splash_time = 0xffff;
171 /* use little endian format */
172 qemu_extra_params_fw[0] = (uint8_t)(boot_splash_time & 0xff);
173 qemu_extra_params_fw[1] = (uint8_t)((boot_splash_time >> 8) & 0xff);
174 fw_cfg_add_file(s, "etc/boot-menu-wait", qemu_extra_params_fw, 2);
177 /* insert splash file if user configurated */
178 if (boot_splash_filename != NULL) {
179 filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, boot_splash_filename);
180 if (filename == NULL) {
181 error_report("failed to find file '%s'.", boot_splash_filename);
182 return;
185 /* loading file data */
186 file_data = read_splashfile(filename, &file_size, &file_type);
187 if (file_data == NULL) {
188 g_free(filename);
189 return;
191 if (boot_splash_filedata != NULL) {
192 g_free(boot_splash_filedata);
194 boot_splash_filedata = (uint8_t *)file_data;
195 boot_splash_filedata_size = file_size;
197 /* insert data */
198 if (file_type == JPG_FILE) {
199 fw_cfg_add_file(s, "bootsplash.jpg",
200 boot_splash_filedata, boot_splash_filedata_size);
201 } else {
202 fw_cfg_add_file(s, "bootsplash.bmp",
203 boot_splash_filedata, boot_splash_filedata_size);
205 g_free(filename);
209 static void fw_cfg_reboot(FWCfgState *s)
211 int reboot_timeout = -1;
212 char *p;
213 const char *temp;
215 /* get user configuration */
216 QemuOptsList *plist = qemu_find_opts("boot-opts");
217 QemuOpts *opts = QTAILQ_FIRST(&plist->head);
218 if (opts != NULL) {
219 temp = qemu_opt_get(opts, "reboot-timeout");
220 if (temp != NULL) {
221 p = (char *)temp;
222 reboot_timeout = strtol(p, (char **)&p, 10);
225 /* validate the input */
226 if (reboot_timeout > 0xffff) {
227 error_report("reboot timeout is larger than 65535, force it to 65535.");
228 reboot_timeout = 0xffff;
230 fw_cfg_add_file(s, "etc/boot-fail-wait", g_memdup(&reboot_timeout, 4), 4);
233 static void fw_cfg_write(FWCfgState *s, uint8_t value)
235 int arch = !!(s->cur_entry & FW_CFG_ARCH_LOCAL);
236 FWCfgEntry *e = &s->entries[arch][s->cur_entry & FW_CFG_ENTRY_MASK];
238 trace_fw_cfg_write(s, value);
240 if (s->cur_entry & FW_CFG_WRITE_CHANNEL && e->callback &&
241 s->cur_offset < e->len) {
242 e->data[s->cur_offset++] = value;
243 if (s->cur_offset == e->len) {
244 e->callback(e->callback_opaque, e->data);
245 s->cur_offset = 0;
250 static int fw_cfg_select(FWCfgState *s, uint16_t key)
252 int ret;
254 s->cur_offset = 0;
255 if ((key & FW_CFG_ENTRY_MASK) >= FW_CFG_MAX_ENTRY) {
256 s->cur_entry = FW_CFG_INVALID;
257 ret = 0;
258 } else {
259 s->cur_entry = key;
260 ret = 1;
263 trace_fw_cfg_select(s, key, ret);
264 return ret;
267 static uint8_t fw_cfg_read(FWCfgState *s)
269 int arch = !!(s->cur_entry & FW_CFG_ARCH_LOCAL);
270 FWCfgEntry *e = &s->entries[arch][s->cur_entry & FW_CFG_ENTRY_MASK];
271 uint8_t ret;
273 if (s->cur_entry == FW_CFG_INVALID || !e->data || s->cur_offset >= e->len)
274 ret = 0;
275 else {
276 if (e->read_callback) {
277 e->read_callback(e->callback_opaque, s->cur_offset);
279 ret = e->data[s->cur_offset++];
282 trace_fw_cfg_read(s, ret);
283 return ret;
286 static uint64_t fw_cfg_data_mem_read(void *opaque, hwaddr addr,
287 unsigned size)
289 FWCfgState *s = opaque;
290 uint64_t value = 0;
291 unsigned i;
293 for (i = 0; i < size; ++i) {
294 value = (value << 8) | fw_cfg_read(s);
296 return value;
299 static void fw_cfg_data_mem_write(void *opaque, hwaddr addr,
300 uint64_t value, unsigned size)
302 FWCfgState *s = opaque;
303 unsigned i = size;
305 do {
306 fw_cfg_write(s, value >> (8 * --i));
307 } while (i);
310 static bool fw_cfg_data_mem_valid(void *opaque, hwaddr addr,
311 unsigned size, bool is_write)
313 return addr == 0;
316 static void fw_cfg_ctl_mem_write(void *opaque, hwaddr addr,
317 uint64_t value, unsigned size)
319 fw_cfg_select(opaque, (uint16_t)value);
322 static bool fw_cfg_ctl_mem_valid(void *opaque, hwaddr addr,
323 unsigned size, bool is_write)
325 return is_write && size == 2;
328 static uint64_t fw_cfg_comb_read(void *opaque, hwaddr addr,
329 unsigned size)
331 return fw_cfg_read(opaque);
334 static void fw_cfg_comb_write(void *opaque, hwaddr addr,
335 uint64_t value, unsigned size)
337 switch (size) {
338 case 1:
339 fw_cfg_write(opaque, (uint8_t)value);
340 break;
341 case 2:
342 fw_cfg_select(opaque, (uint16_t)value);
343 break;
347 static bool fw_cfg_comb_valid(void *opaque, hwaddr addr,
348 unsigned size, bool is_write)
350 return (size == 1) || (is_write && size == 2);
353 static const MemoryRegionOps fw_cfg_ctl_mem_ops = {
354 .write = fw_cfg_ctl_mem_write,
355 .endianness = DEVICE_BIG_ENDIAN,
356 .valid.accepts = fw_cfg_ctl_mem_valid,
359 static const MemoryRegionOps fw_cfg_data_mem_ops = {
360 .read = fw_cfg_data_mem_read,
361 .write = fw_cfg_data_mem_write,
362 .endianness = DEVICE_BIG_ENDIAN,
363 .valid = {
364 .min_access_size = 1,
365 .max_access_size = 1,
366 .accepts = fw_cfg_data_mem_valid,
370 static const MemoryRegionOps fw_cfg_comb_mem_ops = {
371 .read = fw_cfg_comb_read,
372 .write = fw_cfg_comb_write,
373 .endianness = DEVICE_LITTLE_ENDIAN,
374 .valid.accepts = fw_cfg_comb_valid,
377 static void fw_cfg_reset(DeviceState *d)
379 FWCfgState *s = FW_CFG(d);
381 fw_cfg_select(s, 0);
384 /* Save restore 32 bit int as uint16_t
385 This is a Big hack, but it is how the old state did it.
386 Or we broke compatibility in the state, or we can't use struct tm
389 static int get_uint32_as_uint16(QEMUFile *f, void *pv, size_t size)
391 uint32_t *v = pv;
392 *v = qemu_get_be16(f);
393 return 0;
396 static void put_unused(QEMUFile *f, void *pv, size_t size)
398 fprintf(stderr, "uint32_as_uint16 is only used for backward compatibility.\n");
399 fprintf(stderr, "This functions shouldn't be called.\n");
402 static const VMStateInfo vmstate_hack_uint32_as_uint16 = {
403 .name = "int32_as_uint16",
404 .get = get_uint32_as_uint16,
405 .put = put_unused,
408 #define VMSTATE_UINT16_HACK(_f, _s, _t) \
409 VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_hack_uint32_as_uint16, uint32_t)
412 static bool is_version_1(void *opaque, int version_id)
414 return version_id == 1;
417 static const VMStateDescription vmstate_fw_cfg = {
418 .name = "fw_cfg",
419 .version_id = 2,
420 .minimum_version_id = 1,
421 .fields = (VMStateField[]) {
422 VMSTATE_UINT16(cur_entry, FWCfgState),
423 VMSTATE_UINT16_HACK(cur_offset, FWCfgState, is_version_1),
424 VMSTATE_UINT32_V(cur_offset, FWCfgState, 2),
425 VMSTATE_END_OF_LIST()
429 static void fw_cfg_add_bytes_read_callback(FWCfgState *s, uint16_t key,
430 FWCfgReadCallback callback,
431 void *callback_opaque,
432 void *data, size_t len)
434 int arch = !!(key & FW_CFG_ARCH_LOCAL);
436 key &= FW_CFG_ENTRY_MASK;
438 assert(key < FW_CFG_MAX_ENTRY && len < UINT32_MAX);
440 s->entries[arch][key].data = data;
441 s->entries[arch][key].len = (uint32_t)len;
442 s->entries[arch][key].read_callback = callback;
443 s->entries[arch][key].callback_opaque = callback_opaque;
446 static void *fw_cfg_modify_bytes_read(FWCfgState *s, uint16_t key,
447 void *data, size_t len)
449 void *ptr;
450 int arch = !!(key & FW_CFG_ARCH_LOCAL);
452 key &= FW_CFG_ENTRY_MASK;
454 assert(key < FW_CFG_MAX_ENTRY && len < UINT32_MAX);
456 /* return the old data to the function caller, avoid memory leak */
457 ptr = s->entries[arch][key].data;
458 s->entries[arch][key].data = data;
459 s->entries[arch][key].len = len;
460 s->entries[arch][key].callback_opaque = NULL;
461 s->entries[arch][key].callback = NULL;
463 return ptr;
466 void fw_cfg_add_bytes(FWCfgState *s, uint16_t key, void *data, size_t len)
468 fw_cfg_add_bytes_read_callback(s, key, NULL, NULL, data, len);
471 void fw_cfg_add_string(FWCfgState *s, uint16_t key, const char *value)
473 size_t sz = strlen(value) + 1;
475 return fw_cfg_add_bytes(s, key, g_memdup(value, sz), sz);
478 void fw_cfg_add_i16(FWCfgState *s, uint16_t key, uint16_t value)
480 uint16_t *copy;
482 copy = g_malloc(sizeof(value));
483 *copy = cpu_to_le16(value);
484 fw_cfg_add_bytes(s, key, copy, sizeof(value));
487 void fw_cfg_add_i32(FWCfgState *s, uint16_t key, uint32_t value)
489 uint32_t *copy;
491 copy = g_malloc(sizeof(value));
492 *copy = cpu_to_le32(value);
493 fw_cfg_add_bytes(s, key, copy, sizeof(value));
496 void fw_cfg_add_i64(FWCfgState *s, uint16_t key, uint64_t value)
498 uint64_t *copy;
500 copy = g_malloc(sizeof(value));
501 *copy = cpu_to_le64(value);
502 fw_cfg_add_bytes(s, key, copy, sizeof(value));
505 void fw_cfg_add_callback(FWCfgState *s, uint16_t key, FWCfgCallback callback,
506 void *callback_opaque, void *data, size_t len)
508 int arch = !!(key & FW_CFG_ARCH_LOCAL);
510 assert(key & FW_CFG_WRITE_CHANNEL);
512 key &= FW_CFG_ENTRY_MASK;
514 assert(key < FW_CFG_MAX_ENTRY && len <= UINT32_MAX);
516 s->entries[arch][key].data = data;
517 s->entries[arch][key].len = (uint32_t)len;
518 s->entries[arch][key].callback_opaque = callback_opaque;
519 s->entries[arch][key].callback = callback;
522 void fw_cfg_add_file_callback(FWCfgState *s, const char *filename,
523 FWCfgReadCallback callback, void *callback_opaque,
524 void *data, size_t len)
526 int i, index;
527 size_t dsize;
529 if (!s->files) {
530 dsize = sizeof(uint32_t) + sizeof(FWCfgFile) * FW_CFG_FILE_SLOTS;
531 s->files = g_malloc0(dsize);
532 fw_cfg_add_bytes(s, FW_CFG_FILE_DIR, s->files, dsize);
535 index = be32_to_cpu(s->files->count);
536 assert(index < FW_CFG_FILE_SLOTS);
538 fw_cfg_add_bytes_read_callback(s, FW_CFG_FILE_FIRST + index,
539 callback, callback_opaque, data, len);
541 pstrcpy(s->files->f[index].name, sizeof(s->files->f[index].name),
542 filename);
543 for (i = 0; i < index; i++) {
544 if (strcmp(s->files->f[index].name, s->files->f[i].name) == 0) {
545 trace_fw_cfg_add_file_dupe(s, s->files->f[index].name);
546 return;
550 s->files->f[index].size = cpu_to_be32(len);
551 s->files->f[index].select = cpu_to_be16(FW_CFG_FILE_FIRST + index);
552 trace_fw_cfg_add_file(s, index, s->files->f[index].name, len);
554 s->files->count = cpu_to_be32(index+1);
557 void fw_cfg_add_file(FWCfgState *s, const char *filename,
558 void *data, size_t len)
560 fw_cfg_add_file_callback(s, filename, NULL, NULL, data, len);
563 void *fw_cfg_modify_file(FWCfgState *s, const char *filename,
564 void *data, size_t len)
566 int i, index;
567 void *ptr = NULL;
569 assert(s->files);
571 index = be32_to_cpu(s->files->count);
572 assert(index < FW_CFG_FILE_SLOTS);
574 for (i = 0; i < index; i++) {
575 if (strcmp(filename, s->files->f[i].name) == 0) {
576 ptr = fw_cfg_modify_bytes_read(s, FW_CFG_FILE_FIRST + i,
577 data, len);
578 s->files->f[i].size = cpu_to_be32(len);
579 return ptr;
582 /* add new one */
583 fw_cfg_add_file_callback(s, filename, NULL, NULL, data, len);
584 return NULL;
587 static void fw_cfg_machine_reset(void *opaque)
589 void *ptr;
590 size_t len;
591 FWCfgState *s = opaque;
592 char *bootindex = get_boot_devices_list(&len, false);
594 ptr = fw_cfg_modify_file(s, "bootorder", (uint8_t *)bootindex, len);
595 g_free(ptr);
598 static void fw_cfg_machine_ready(struct Notifier *n, void *data)
600 FWCfgState *s = container_of(n, FWCfgState, machine_ready);
601 qemu_register_reset(fw_cfg_machine_reset, s);
606 static void fw_cfg_init1(DeviceState *dev)
608 FWCfgState *s = FW_CFG(dev);
610 assert(!object_resolve_path(FW_CFG_PATH, NULL));
612 object_property_add_child(qdev_get_machine(), FW_CFG_NAME, OBJECT(s), NULL);
614 qdev_init_nofail(dev);
616 fw_cfg_add_bytes(s, FW_CFG_SIGNATURE, (char *)"QEMU", 4);
617 fw_cfg_add_bytes(s, FW_CFG_UUID, qemu_uuid, 16);
618 fw_cfg_add_i16(s, FW_CFG_NOGRAPHIC, (uint16_t)(display_type == DT_NOGRAPHIC));
619 fw_cfg_add_i16(s, FW_CFG_NB_CPUS, (uint16_t)smp_cpus);
620 fw_cfg_add_i16(s, FW_CFG_BOOT_MENU, (uint16_t)boot_menu);
621 fw_cfg_bootsplash(s);
622 fw_cfg_reboot(s);
624 s->machine_ready.notify = fw_cfg_machine_ready;
625 qemu_add_machine_init_done_notifier(&s->machine_ready);
628 FWCfgState *fw_cfg_init_io(uint32_t iobase)
630 DeviceState *dev;
632 dev = qdev_create(NULL, TYPE_FW_CFG_IO);
633 qdev_prop_set_uint32(dev, "iobase", iobase);
634 fw_cfg_init1(dev);
636 return FW_CFG(dev);
639 FWCfgState *fw_cfg_init_mem_wide(hwaddr ctl_addr, hwaddr data_addr,
640 uint32_t data_width)
642 DeviceState *dev;
643 SysBusDevice *sbd;
645 dev = qdev_create(NULL, TYPE_FW_CFG_MEM);
646 qdev_prop_set_uint32(dev, "data_width", data_width);
648 fw_cfg_init1(dev);
650 sbd = SYS_BUS_DEVICE(dev);
651 sysbus_mmio_map(sbd, 0, ctl_addr);
652 sysbus_mmio_map(sbd, 1, data_addr);
654 return FW_CFG(dev);
657 FWCfgState *fw_cfg_init_mem(hwaddr ctl_addr, hwaddr data_addr)
659 return fw_cfg_init_mem_wide(ctl_addr, data_addr,
660 fw_cfg_data_mem_ops.valid.max_access_size);
664 FWCfgState *fw_cfg_find(void)
666 return FW_CFG(object_resolve_path(FW_CFG_PATH, NULL));
669 static void fw_cfg_class_init(ObjectClass *klass, void *data)
671 DeviceClass *dc = DEVICE_CLASS(klass);
673 dc->reset = fw_cfg_reset;
674 dc->vmsd = &vmstate_fw_cfg;
677 static const TypeInfo fw_cfg_info = {
678 .name = TYPE_FW_CFG,
679 .parent = TYPE_SYS_BUS_DEVICE,
680 .instance_size = sizeof(FWCfgState),
681 .class_init = fw_cfg_class_init,
685 static Property fw_cfg_io_properties[] = {
686 DEFINE_PROP_UINT32("iobase", FWCfgIoState, iobase, -1),
687 DEFINE_PROP_END_OF_LIST(),
690 static void fw_cfg_io_realize(DeviceState *dev, Error **errp)
692 FWCfgIoState *s = FW_CFG_IO(dev);
693 SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
695 memory_region_init_io(&s->comb_iomem, OBJECT(s), &fw_cfg_comb_mem_ops,
696 FW_CFG(s), "fwcfg", FW_CFG_SIZE);
697 sysbus_add_io(sbd, s->iobase, &s->comb_iomem);
700 static void fw_cfg_io_class_init(ObjectClass *klass, void *data)
702 DeviceClass *dc = DEVICE_CLASS(klass);
704 dc->realize = fw_cfg_io_realize;
705 dc->props = fw_cfg_io_properties;
708 static const TypeInfo fw_cfg_io_info = {
709 .name = TYPE_FW_CFG_IO,
710 .parent = TYPE_FW_CFG,
711 .instance_size = sizeof(FWCfgIoState),
712 .class_init = fw_cfg_io_class_init,
716 static Property fw_cfg_mem_properties[] = {
717 DEFINE_PROP_UINT32("data_width", FWCfgMemState, data_width, -1),
718 DEFINE_PROP_END_OF_LIST(),
721 static void fw_cfg_mem_realize(DeviceState *dev, Error **errp)
723 FWCfgMemState *s = FW_CFG_MEM(dev);
724 SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
725 const MemoryRegionOps *data_ops = &fw_cfg_data_mem_ops;
727 memory_region_init_io(&s->ctl_iomem, OBJECT(s), &fw_cfg_ctl_mem_ops,
728 FW_CFG(s), "fwcfg.ctl", FW_CFG_SIZE);
729 sysbus_init_mmio(sbd, &s->ctl_iomem);
731 if (s->data_width > data_ops->valid.max_access_size) {
732 /* memberwise copy because the "old_mmio" member is const */
733 s->wide_data_ops.read = data_ops->read;
734 s->wide_data_ops.write = data_ops->write;
735 s->wide_data_ops.endianness = data_ops->endianness;
736 s->wide_data_ops.valid = data_ops->valid;
737 s->wide_data_ops.impl = data_ops->impl;
739 s->wide_data_ops.valid.max_access_size = s->data_width;
740 s->wide_data_ops.impl.max_access_size = s->data_width;
741 data_ops = &s->wide_data_ops;
743 memory_region_init_io(&s->data_iomem, OBJECT(s), data_ops, FW_CFG(s),
744 "fwcfg.data", data_ops->valid.max_access_size);
745 sysbus_init_mmio(sbd, &s->data_iomem);
748 static void fw_cfg_mem_class_init(ObjectClass *klass, void *data)
750 DeviceClass *dc = DEVICE_CLASS(klass);
752 dc->realize = fw_cfg_mem_realize;
753 dc->props = fw_cfg_mem_properties;
756 static const TypeInfo fw_cfg_mem_info = {
757 .name = TYPE_FW_CFG_MEM,
758 .parent = TYPE_FW_CFG,
759 .instance_size = sizeof(FWCfgMemState),
760 .class_init = fw_cfg_mem_class_init,
764 static void fw_cfg_register_types(void)
766 type_register_static(&fw_cfg_info);
767 type_register_static(&fw_cfg_io_info);
768 type_register_static(&fw_cfg_mem_info);
771 type_init(fw_cfg_register_types)