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"
13 #include "exec/target_page.h"
15 #include "hw/loader.h"
16 #include "hw/nubus/nubus.h"
17 #include "qapi/error.h"
18 #include "qemu/error-report.h"
21 void nubus_set_irq(NubusDevice
*nd
, int level
)
23 NubusBus
*nubus
= NUBUS_BUS(qdev_get_parent_bus(DEVICE(nd
)));
25 qemu_set_irq(nubus
->irqs
[nd
->slot
], level
);
28 static void nubus_device_realize(DeviceState
*dev
, Error
**errp
)
30 NubusBus
*nubus
= NUBUS_BUS(qdev_get_parent_bus(dev
));
31 NubusDevice
*nd
= NUBUS_DEVICE(dev
);
34 int64_t size
, align_size
;
39 slot_offset
= nd
->slot
* NUBUS_SUPER_SLOT_SIZE
;
41 name
= g_strdup_printf("nubus-super-slot-%x", nd
->slot
);
42 memory_region_init(&nd
->super_slot_mem
, OBJECT(dev
), name
,
43 NUBUS_SUPER_SLOT_SIZE
);
44 memory_region_add_subregion(&nubus
->super_slot_io
, slot_offset
,
49 slot_offset
= nd
->slot
* NUBUS_SLOT_SIZE
;
51 name
= g_strdup_printf("nubus-slot-%x", nd
->slot
);
52 memory_region_init(&nd
->slot_mem
, OBJECT(dev
), name
, NUBUS_SLOT_SIZE
);
53 memory_region_add_subregion(&nubus
->slot_io
, slot_offset
,
58 if (nd
->romfile
!= NULL
) {
59 path
= qemu_find_file(QEMU_FILE_TYPE_BIOS
, nd
->romfile
);
61 path
= g_strdup(nd
->romfile
);
64 size
= get_image_size(path
);
66 error_setg(errp
, "failed to find romfile \"%s\"", nd
->romfile
);
69 } else if (size
== 0) {
70 error_setg(errp
, "romfile \"%s\" is empty", nd
->romfile
);
73 } else if (size
> NUBUS_DECL_ROM_MAX_SIZE
) {
74 error_setg(errp
, "romfile \"%s\" too large (maximum size 128K)",
80 name
= g_strdup_printf("nubus-slot-%x-declaration-rom", nd
->slot
);
83 * Ensure ROM memory region is aligned to target page size regardless
84 * of the size of the Declaration ROM image
86 align_size
= ROUND_UP(size
, qemu_target_page_size());
87 memory_region_init_rom(&nd
->decl_rom
, OBJECT(dev
), name
, align_size
,
89 rom_ptr
= memory_region_get_ram_ptr(&nd
->decl_rom
);
90 ret
= load_image_size(path
, rom_ptr
+ (uintptr_t)(align_size
- size
),
95 error_setg(errp
, "could not load romfile \"%s\"", nd
->romfile
);
98 memory_region_add_subregion(&nd
->slot_mem
, NUBUS_SLOT_SIZE
- align_size
,
103 static Property nubus_device_properties
[] = {
104 DEFINE_PROP_INT32("slot", NubusDevice
, slot
, -1),
105 DEFINE_PROP_STRING("romfile", NubusDevice
, romfile
),
106 DEFINE_PROP_END_OF_LIST()
109 static void nubus_device_class_init(ObjectClass
*oc
, void *data
)
111 DeviceClass
*dc
= DEVICE_CLASS(oc
);
113 dc
->realize
= nubus_device_realize
;
114 dc
->bus_type
= TYPE_NUBUS_BUS
;
115 device_class_set_props(dc
, nubus_device_properties
);
118 static const TypeInfo nubus_device_type_info
= {
119 .name
= TYPE_NUBUS_DEVICE
,
120 .parent
= TYPE_DEVICE
,
122 .instance_size
= sizeof(NubusDevice
),
123 .class_init
= nubus_device_class_init
,
126 static void nubus_register_types(void)
128 type_register_static(&nubus_device_type_info
);
131 type_init(nubus_register_types
)