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 "hw/nubus/nubus.h"
13 #include "hw/sysbus.h"
14 #include "qapi/error.h"
17 static NubusBus
*nubus_find(void)
19 /* Returns NULL unless there is exactly one nubus device */
20 return NUBUS_BUS(object_resolve_path_type("", TYPE_NUBUS_BUS
, NULL
));
23 static void nubus_slot_write(void *opaque
, hwaddr addr
, uint64_t val
,
30 static uint64_t nubus_slot_read(void *opaque
, hwaddr addr
,
36 static const MemoryRegionOps nubus_slot_ops
= {
37 .read
= nubus_slot_read
,
38 .write
= nubus_slot_write
,
39 .endianness
= DEVICE_BIG_ENDIAN
,
46 static void nubus_super_slot_write(void *opaque
, hwaddr addr
, uint64_t val
,
52 static uint64_t nubus_super_slot_read(void *opaque
, hwaddr addr
,
58 static const MemoryRegionOps nubus_super_slot_ops
= {
59 .read
= nubus_super_slot_read
,
60 .write
= nubus_super_slot_write
,
61 .endianness
= DEVICE_BIG_ENDIAN
,
68 static void nubus_realize(BusState
*bus
, Error
**errp
)
71 error_setg(errp
, "at most one %s device is permitted", TYPE_NUBUS_BUS
);
76 static void nubus_init(Object
*obj
)
78 NubusBus
*nubus
= NUBUS_BUS(obj
);
80 memory_region_init_io(&nubus
->super_slot_io
, obj
, &nubus_super_slot_ops
,
81 nubus
, "nubus-super-slots",
82 NUBUS_SUPER_SLOT_NB
* NUBUS_SUPER_SLOT_SIZE
);
84 memory_region_init_io(&nubus
->slot_io
, obj
, &nubus_slot_ops
,
86 NUBUS_SLOT_NB
* NUBUS_SLOT_SIZE
);
88 nubus
->current_slot
= NUBUS_FIRST_SLOT
;
91 static void nubus_class_init(ObjectClass
*oc
, void *data
)
93 BusClass
*bc
= BUS_CLASS(oc
);
95 bc
->realize
= nubus_realize
;
98 static const TypeInfo nubus_bus_info
= {
99 .name
= TYPE_NUBUS_BUS
,
101 .instance_size
= sizeof(NubusBus
),
102 .instance_init
= nubus_init
,
103 .class_init
= nubus_class_init
,
106 static void nubus_register_types(void)
108 type_register_static(&nubus_bus_info
);
111 type_init(nubus_register_types
)