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 /* 12 * References: 13 * Nubus Specification (TI) 14 * http://www.bitsavers.org/pdf/ti/nubus/2242825-0001_NuBus_Spec1983.pdf 15 * 16 * Designing Cards and Drivers for the Macintosh Family (Apple) 17 */ 18 19 #include "qemu/osdep.h" 20 #include "hw/nubus/nubus.h" 21 #include "qapi/error.h" 22 23 24 static NubusBus *nubus_find(void) 25 { 26 /* Returns NULL unless there is exactly one nubus device */ 27 return NUBUS_BUS(object_resolve_path_type("", TYPE_NUBUS_BUS, NULL)); 28 } 29 30 static void nubus_slot_write(void *opaque, hwaddr addr, uint64_t val, 31 unsigned int size) 32 { 33 /* read only */ 34 } 35 36 37 static uint64_t nubus_slot_read(void *opaque, hwaddr addr, 38 unsigned int size) 39 { 40 return 0; 41 } 42 43 static const MemoryRegionOps nubus_slot_ops = { 44 .read = nubus_slot_read, 45 .write = nubus_slot_write, 46 .endianness = DEVICE_BIG_ENDIAN, 47 .valid = { 48 .min_access_size = 1, 49 .max_access_size = 1, 50 }, 51 }; 52 53 static void nubus_super_slot_write(void *opaque, hwaddr addr, uint64_t val, 54 unsigned int size) 55 { 56 /* read only */ 57 } 58 59 static uint64_t nubus_super_slot_read(void *opaque, hwaddr addr, 60 unsigned int size) 61 { 62 return 0; 63 } 64 65 static const MemoryRegionOps nubus_super_slot_ops = { 66 .read = nubus_super_slot_read, 67 .write = nubus_super_slot_write, 68 .endianness = DEVICE_BIG_ENDIAN, 69 .valid = { 70 .min_access_size = 1, 71 .max_access_size = 1, 72 }, 73 }; 74 75 static void nubus_realize(BusState *bus, Error **errp) 76 { 77 if (!nubus_find()) { 78 error_setg(errp, "at most one %s device is permitted", TYPE_NUBUS_BUS); 79 return; 80 } 81 } 82 83 static void nubus_init(Object *obj) 84 { 85 NubusBus *nubus = NUBUS_BUS(obj); 86 87 memory_region_init_io(&nubus->super_slot_io, obj, &nubus_super_slot_ops, 88 nubus, "nubus-super-slots", 89 (NUBUS_SUPER_SLOT_NB + 1) * NUBUS_SUPER_SLOT_SIZE); 90 91 memory_region_init_io(&nubus->slot_io, obj, &nubus_slot_ops, 92 nubus, "nubus-slots", 93 NUBUS_SLOT_NB * NUBUS_SLOT_SIZE); 94 95 nubus->slot_available_mask = MAKE_64BIT_MASK(NUBUS_FIRST_SLOT, 96 NUBUS_SLOT_NB); 97 } 98 99 static void nubus_class_init(ObjectClass *oc, void *data) 100 { 101 BusClass *bc = BUS_CLASS(oc); 102 103 bc->realize = nubus_realize; 104 } 105 106 static const TypeInfo nubus_bus_info = { 107 .name = TYPE_NUBUS_BUS, 108 .parent = TYPE_BUS, 109 .instance_size = sizeof(NubusBus), 110 .instance_init = nubus_init, 111 .class_init = nubus_class_init, 112 }; 113 114 static void nubus_register_types(void) 115 { 116 type_register_static(&nubus_bus_info); 117 } 118 119 type_init(nubus_register_types) 120