]> git.ipfire.org Git - thirdparty/qemu.git/blob - hw/misc/empty_slot.c
57dcdfbe149e2a8fca3fe36d180792d25d38070a
[thirdparty/qemu.git] / hw / misc / empty_slot.c
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
12 #include "qemu/osdep.h"
13 #include "hw/sysbus.h"
14 #include "hw/qdev-properties.h"
15 #include "hw/misc/empty_slot.h"
16 #include "qapi/error.h"
17 #include "trace.h"
18 #include "qom/object.h"
19
20 #define TYPE_EMPTY_SLOT "empty_slot"
21 typedef struct EmptySlot EmptySlot;
22 DECLARE_INSTANCE_CHECKER(EmptySlot, EMPTY_SLOT,
23 TYPE_EMPTY_SLOT)
24
25 struct EmptySlot {
26 SysBusDevice parent_obj;
27
28 MemoryRegion iomem;
29 char *name;
30 uint64_t size;
31 };
32
33 static uint64_t empty_slot_read(void *opaque, hwaddr addr,
34 unsigned size)
35 {
36 EmptySlot *s = EMPTY_SLOT(opaque);
37
38 trace_empty_slot_write(addr, size << 1, 0, size, s->name);
39
40 return 0;
41 }
42
43 static void empty_slot_write(void *opaque, hwaddr addr,
44 uint64_t val, unsigned size)
45 {
46 EmptySlot *s = EMPTY_SLOT(opaque);
47
48 trace_empty_slot_write(addr, size << 1, val, size, s->name);
49 }
50
51 static const MemoryRegionOps empty_slot_ops = {
52 .read = empty_slot_read,
53 .write = empty_slot_write,
54 .endianness = DEVICE_NATIVE_ENDIAN,
55 };
56
57 void empty_slot_init(const char *name, hwaddr addr, uint64_t slot_size)
58 {
59 if (slot_size > 0) {
60 /* Only empty slots larger than 0 byte need handling. */
61 DeviceState *dev;
62
63 dev = qdev_new(TYPE_EMPTY_SLOT);
64
65 qdev_prop_set_uint64(dev, "size", slot_size);
66 sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
67
68 sysbus_mmio_map_overlap(SYS_BUS_DEVICE(dev), 0, addr, -10000);
69 }
70 }
71
72 static void empty_slot_realize(DeviceState *dev, Error **errp)
73 {
74 EmptySlot *s = EMPTY_SLOT(dev);
75
76 if (s->name == NULL) {
77 s->name = g_strdup("empty-slot");
78 }
79 memory_region_init_io(&s->iomem, OBJECT(s), &empty_slot_ops, s,
80 s->name, s->size);
81 sysbus_init_mmio(SYS_BUS_DEVICE(dev), &s->iomem);
82 }
83
84 static Property empty_slot_properties[] = {
85 DEFINE_PROP_UINT64("size", EmptySlot, size, 0),
86 DEFINE_PROP_STRING("name", EmptySlot, name),
87 DEFINE_PROP_END_OF_LIST(),
88 };
89
90 static void empty_slot_class_init(ObjectClass *klass, void *data)
91 {
92 DeviceClass *dc = DEVICE_CLASS(klass);
93
94 dc->realize = empty_slot_realize;
95 device_class_set_props(dc, empty_slot_properties);
96 set_bit(DEVICE_CATEGORY_MISC, dc->categories);
97 }
98
99 static const TypeInfo empty_slot_info = {
100 .name = TYPE_EMPTY_SLOT,
101 .parent = TYPE_SYS_BUS_DEVICE,
102 .instance_size = sizeof(EmptySlot),
103 .class_init = empty_slot_class_init,
104 };
105
106 static void empty_slot_register_types(void)
107 {
108 type_register_static(&empty_slot_info);
109 }
110
111 type_init(empty_slot_register_types)