4 * Copyright (c) 2013-2018 Laurent Vivier <laurent@vivier.eu>
6 * This work is licensed under the terms of the GNU GPL, version 2 or later.
7 * See the COPYING file in the top-level directory.
11 #include "qemu/osdep.h"
12 #include "qemu/datadir.h"
14 #include "hw/loader.h"
15 #include "hw/nubus/nubus.h"
16 #include "qapi/error.h"
17 #include "qemu/error-report.h"
20 void nubus_set_irq(NubusDevice
*nd
, int level
)
22 NubusBus
*nubus
= NUBUS_BUS(qdev_get_parent_bus(DEVICE(nd
)));
24 qemu_set_irq(nubus
->irqs
[nd
->slot
], level
);
27 static void nubus_device_realize(DeviceState
*dev
, Error
**errp
)
29 NubusBus
*nubus
= NUBUS_BUS(qdev_get_parent_bus(dev
));
30 NubusDevice
*nd
= NUBUS_DEVICE(dev
);
37 slot_offset
= nd
->slot
* NUBUS_SUPER_SLOT_SIZE
;
39 name
= g_strdup_printf("nubus-super-slot-%x", nd
->slot
);
40 memory_region_init(&nd
->super_slot_mem
, OBJECT(dev
), name
,
41 NUBUS_SUPER_SLOT_SIZE
);
42 memory_region_add_subregion(&nubus
->super_slot_io
, slot_offset
,
47 slot_offset
= nd
->slot
* NUBUS_SLOT_SIZE
;
49 name
= g_strdup_printf("nubus-slot-%x", nd
->slot
);
50 memory_region_init(&nd
->slot_mem
, OBJECT(dev
), name
, NUBUS_SLOT_SIZE
);
51 memory_region_add_subregion(&nubus
->slot_io
, slot_offset
,
56 if (nd
->romfile
!= NULL
) {
57 path
= qemu_find_file(QEMU_FILE_TYPE_BIOS
, nd
->romfile
);
59 path
= g_strdup(nd
->romfile
);
62 size
= get_image_size(path
);
64 error_setg(errp
, "failed to find romfile \"%s\"", nd
->romfile
);
67 } else if (size
== 0) {
68 error_setg(errp
, "romfile \"%s\" is empty", nd
->romfile
);
71 } else if (size
> NUBUS_DECL_ROM_MAX_SIZE
) {
72 error_setg(errp
, "romfile \"%s\" too large (maximum size 128K)",
78 name
= g_strdup_printf("nubus-slot-%x-declaration-rom", nd
->slot
);
79 memory_region_init_rom(&nd
->decl_rom
, OBJECT(dev
), name
, size
,
81 ret
= load_image_mr(path
, &nd
->decl_rom
);
84 error_setg(errp
, "could not load romfile \"%s\"", nd
->romfile
);
87 memory_region_add_subregion(&nd
->slot_mem
, NUBUS_SLOT_SIZE
- size
,
92 static Property nubus_device_properties
[] = {
93 DEFINE_PROP_INT32("slot", NubusDevice
, slot
, -1),
94 DEFINE_PROP_STRING("romfile", NubusDevice
, romfile
),
95 DEFINE_PROP_END_OF_LIST()
98 static void nubus_device_class_init(ObjectClass
*oc
, void *data
)
100 DeviceClass
*dc
= DEVICE_CLASS(oc
);
102 dc
->realize
= nubus_device_realize
;
103 dc
->bus_type
= TYPE_NUBUS_BUS
;
104 device_class_set_props(dc
, nubus_device_properties
);
107 static const TypeInfo nubus_device_type_info
= {
108 .name
= TYPE_NUBUS_DEVICE
,
109 .parent
= TYPE_DEVICE
,
111 .instance_size
= sizeof(NubusDevice
),
112 .class_init
= nubus_device_class_init
,
115 static void nubus_register_types(void)
117 type_register_static(&nubus_device_type_info
);
120 type_init(nubus_register_types
)