]>
Commit | Line | Data |
---|---|---|
da9fcfa5 AT |
1 | /* |
2 | * QEMU Empty Slot | |
3 | * | |
4 | * The empty_slot device emulates known to a bus but not connected devices. | |
5 | * | |
6 | * Copyright (c) 2010 Artyom Tarasenko | |
7 | * | |
8 | * This code is licensed under the GNU GPL v2 or (at your option) any later | |
9 | * version. | |
10 | */ | |
11 | ||
18c86e2b | 12 | #include "qemu/osdep.h" |
83c9f4ca | 13 | #include "hw/sysbus.h" |
4bbadef0 | 14 | #include "hw/qdev-properties.h" |
6007523a | 15 | #include "hw/misc/empty_slot.h" |
3e80f690 | 16 | #include "qapi/error.h" |
c0e43084 | 17 | #include "trace.h" |
db1015e9 | 18 | #include "qom/object.h" |
da9fcfa5 | 19 | |
8df81c4b | 20 | #define TYPE_EMPTY_SLOT "empty_slot" |
8063396b | 21 | OBJECT_DECLARE_SIMPLE_TYPE(EmptySlot, EMPTY_SLOT) |
8df81c4b | 22 | |
db1015e9 | 23 | struct EmptySlot { |
8df81c4b AF |
24 | SysBusDevice parent_obj; |
25 | ||
b0a941b0 | 26 | MemoryRegion iomem; |
07ddf5cb | 27 | char *name; |
da9fcfa5 | 28 | uint64_t size; |
db1015e9 | 29 | }; |
da9fcfa5 | 30 | |
a8170e5e | 31 | static uint64_t empty_slot_read(void *opaque, hwaddr addr, |
b0a941b0 | 32 | unsigned size) |
da9fcfa5 | 33 | { |
c0e43084 PMD |
34 | EmptySlot *s = EMPTY_SLOT(opaque); |
35 | ||
36 | trace_empty_slot_write(addr, size << 1, 0, size, s->name); | |
37 | ||
da9fcfa5 AT |
38 | return 0; |
39 | } | |
40 | ||
a8170e5e | 41 | static void empty_slot_write(void *opaque, hwaddr addr, |
b0a941b0 | 42 | uint64_t val, unsigned size) |
da9fcfa5 | 43 | { |
c0e43084 PMD |
44 | EmptySlot *s = EMPTY_SLOT(opaque); |
45 | ||
46 | trace_empty_slot_write(addr, size << 1, val, size, s->name); | |
da9fcfa5 AT |
47 | } |
48 | ||
b0a941b0 AK |
49 | static const MemoryRegionOps empty_slot_ops = { |
50 | .read = empty_slot_read, | |
51 | .write = empty_slot_write, | |
52 | .endianness = DEVICE_NATIVE_ENDIAN, | |
da9fcfa5 AT |
53 | }; |
54 | ||
28c78fe8 | 55 | void empty_slot_init(const char *name, hwaddr addr, uint64_t slot_size) |
da9fcfa5 | 56 | { |
1a00282a SW |
57 | if (slot_size > 0) { |
58 | /* Only empty slots larger than 0 byte need handling. */ | |
59 | DeviceState *dev; | |
da9fcfa5 | 60 | |
3e80f690 | 61 | dev = qdev_new(TYPE_EMPTY_SLOT); |
da9fcfa5 | 62 | |
4bbadef0 | 63 | qdev_prop_set_uint64(dev, "size", slot_size); |
3c6ef471 | 64 | sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal); |
da9fcfa5 | 65 | |
4bbadef0 | 66 | sysbus_mmio_map_overlap(SYS_BUS_DEVICE(dev), 0, addr, -10000); |
1a00282a | 67 | } |
da9fcfa5 AT |
68 | } |
69 | ||
4dbf209d | 70 | static void empty_slot_realize(DeviceState *dev, Error **errp) |
da9fcfa5 | 71 | { |
8df81c4b | 72 | EmptySlot *s = EMPTY_SLOT(dev); |
da9fcfa5 | 73 | |
07ddf5cb PMD |
74 | if (s->name == NULL) { |
75 | s->name = g_strdup("empty-slot"); | |
76 | } | |
300b1fc6 | 77 | memory_region_init_io(&s->iomem, OBJECT(s), &empty_slot_ops, s, |
07ddf5cb | 78 | s->name, s->size); |
4dbf209d | 79 | sysbus_init_mmio(SYS_BUS_DEVICE(dev), &s->iomem); |
da9fcfa5 AT |
80 | } |
81 | ||
4bbadef0 PMD |
82 | static Property empty_slot_properties[] = { |
83 | DEFINE_PROP_UINT64("size", EmptySlot, size, 0), | |
07ddf5cb | 84 | DEFINE_PROP_STRING("name", EmptySlot, name), |
4bbadef0 PMD |
85 | DEFINE_PROP_END_OF_LIST(), |
86 | }; | |
87 | ||
999e12bb AL |
88 | static void empty_slot_class_init(ObjectClass *klass, void *data) |
89 | { | |
4dbf209d | 90 | DeviceClass *dc = DEVICE_CLASS(klass); |
999e12bb | 91 | |
4dbf209d | 92 | dc->realize = empty_slot_realize; |
4bbadef0 | 93 | device_class_set_props(dc, empty_slot_properties); |
6007523a | 94 | set_bit(DEVICE_CATEGORY_MISC, dc->categories); |
999e12bb AL |
95 | } |
96 | ||
8c43a6f0 | 97 | static const TypeInfo empty_slot_info = { |
8df81c4b | 98 | .name = TYPE_EMPTY_SLOT, |
39bffca2 AL |
99 | .parent = TYPE_SYS_BUS_DEVICE, |
100 | .instance_size = sizeof(EmptySlot), | |
101 | .class_init = empty_slot_class_init, | |
da9fcfa5 AT |
102 | }; |
103 | ||
83f7d43a | 104 | static void empty_slot_register_types(void) |
da9fcfa5 | 105 | { |
39bffca2 | 106 | type_register_static(&empty_slot_info); |
da9fcfa5 AT |
107 | } |
108 | ||
83f7d43a | 109 | type_init(empty_slot_register_types) |