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