vfio: Sanity check maximum number of DMA mappings with RamDiscardManager
[qemu/kevin.git] / hw / nubus / nubus-bus.c
blob5c134523082e38207bd6d6138f30e66344baafbe
1 /*
2 * QEMU Macintosh Nubus
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.
9 */
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,
23 unsigned int size)
25 /* read only */
29 static uint64_t nubus_slot_read(void *opaque, hwaddr addr,
30 unsigned int size)
32 return 0;
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,
45 static void nubus_super_slot_write(void *opaque, hwaddr addr, uint64_t val,
46 unsigned int size)
48 /* read only */
51 static uint64_t nubus_super_slot_read(void *opaque, hwaddr addr,
52 unsigned int size)
54 return 0;
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,
67 static void nubus_realize(BusState *bus, Error **errp)
69 if (!nubus_find()) {
70 error_setg(errp, "at most one %s device is permitted", TYPE_NUBUS_BUS);
71 return;
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,
84 nubus, "nubus-slots",
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,
99 .parent = TYPE_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)