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 "qapi/error.h"
16 static NubusBus
*nubus_find(void)
18 /* Returns NULL unless there is exactly one nubus device */
19 return NUBUS_BUS(object_resolve_path_type("", TYPE_NUBUS_BUS
, NULL
));
22 static void nubus_slot_write(void *opaque
, hwaddr addr
, uint64_t val
,
29 static uint64_t nubus_slot_read(void *opaque
, hwaddr addr
,
35 static const MemoryRegionOps nubus_slot_ops
= {
36 .read
= nubus_slot_read
,
37 .write
= nubus_slot_write
,
38 .endianness
= DEVICE_BIG_ENDIAN
,
45 static void nubus_super_slot_write(void *opaque
, hwaddr addr
, uint64_t val
,
51 static uint64_t nubus_super_slot_read(void *opaque
, hwaddr addr
,
57 static const MemoryRegionOps nubus_super_slot_ops
= {
58 .read
= nubus_super_slot_read
,
59 .write
= nubus_super_slot_write
,
60 .endianness
= DEVICE_BIG_ENDIAN
,
67 static void nubus_realize(BusState
*bus
, Error
**errp
)
70 error_setg(errp
, "at most one %s device is permitted", TYPE_NUBUS_BUS
);
75 static void nubus_init(Object
*obj
)
77 NubusBus
*nubus
= NUBUS_BUS(obj
);
79 memory_region_init_io(&nubus
->super_slot_io
, obj
, &nubus_super_slot_ops
,
80 nubus
, "nubus-super-slots",
81 NUBUS_SUPER_SLOT_NB
* NUBUS_SUPER_SLOT_SIZE
);
83 memory_region_init_io(&nubus
->slot_io
, obj
, &nubus_slot_ops
,
85 NUBUS_SLOT_NB
* NUBUS_SLOT_SIZE
);
87 nubus
->current_slot
= NUBUS_FIRST_SLOT
;
90 static void nubus_class_init(ObjectClass
*oc
, void *data
)
92 BusClass
*bc
= BUS_CLASS(oc
);
94 bc
->realize
= nubus_realize
;
97 static const TypeInfo nubus_bus_info
= {
98 .name
= TYPE_NUBUS_BUS
,
100 .instance_size
= sizeof(NubusBus
),
101 .instance_init
= nubus_init
,
102 .class_init
= nubus_class_init
,
105 static void nubus_register_types(void)
107 type_register_static(&nubus_bus_info
);
110 type_init(nubus_register_types
)