xref: /qemu/hw/nubus/nubus-bus.c (revision abff1abf)
1 /*
2  * QEMU Macintosh Nubus
3  *
4  * Copyright (c) 2013-2018 Laurent Vivier <laurent@vivier.eu>
5  *
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.
8  *
9  */
10 
11 #include "qemu/osdep.h"
12 #include "hw/nubus/nubus.h"
13 #include "hw/sysbus.h"
14 #include "qapi/error.h"
15 
16 
17 static NubusBus *nubus_find(void)
18 {
19     /* Returns NULL unless there is exactly one nubus device */
20     return NUBUS_BUS(object_resolve_path_type("", TYPE_NUBUS_BUS, NULL));
21 }
22 
23 static void nubus_slot_write(void *opaque, hwaddr addr, uint64_t val,
24                              unsigned int size)
25 {
26     /* read only */
27 }
28 
29 
30 static uint64_t nubus_slot_read(void *opaque, hwaddr addr,
31                                 unsigned int size)
32 {
33     return 0;
34 }
35 
36 static const MemoryRegionOps nubus_slot_ops = {
37     .read  = nubus_slot_read,
38     .write = nubus_slot_write,
39     .endianness = DEVICE_BIG_ENDIAN,
40     .valid = {
41         .min_access_size = 1,
42         .max_access_size = 1,
43     },
44 };
45 
46 static void nubus_super_slot_write(void *opaque, hwaddr addr, uint64_t val,
47                                    unsigned int size)
48 {
49     /* read only */
50 }
51 
52 static uint64_t nubus_super_slot_read(void *opaque, hwaddr addr,
53                                       unsigned int size)
54 {
55     return 0;
56 }
57 
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,
62     .valid = {
63         .min_access_size = 1,
64         .max_access_size = 1,
65     },
66 };
67 
68 static void nubus_realize(BusState *bus, Error **errp)
69 {
70     if (!nubus_find()) {
71         error_setg(errp, "at most one %s device is permitted", TYPE_NUBUS_BUS);
72         return;
73     }
74 }
75 
76 static void nubus_init(Object *obj)
77 {
78     NubusBus *nubus = NUBUS_BUS(obj);
79 
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);
83 
84     memory_region_init_io(&nubus->slot_io, obj, &nubus_slot_ops,
85                           nubus, "nubus-slots",
86                           NUBUS_SLOT_NB * NUBUS_SLOT_SIZE);
87 
88     nubus->current_slot = NUBUS_FIRST_SLOT;
89 }
90 
91 static void nubus_class_init(ObjectClass *oc, void *data)
92 {
93     BusClass *bc = BUS_CLASS(oc);
94 
95     bc->realize = nubus_realize;
96 }
97 
98 static const TypeInfo nubus_bus_info = {
99     .name = TYPE_NUBUS_BUS,
100     .parent = TYPE_BUS,
101     .instance_size = sizeof(NubusBus),
102     .instance_init = nubus_init,
103     .class_init = nubus_class_init,
104 };
105 
106 static void nubus_register_types(void)
107 {
108     type_register_static(&nubus_bus_info);
109 }
110 
111 type_init(nubus_register_types)
112