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