xref: /qemu/hw/misc/empty_slot.c (revision 07ddf5cbe2e9499cc2d238e5c864ac3f5bdd25ce)
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 "qemu/module.h"
15 #include "hw/qdev-properties.h"
16 #include "hw/empty_slot.h"
17 
18 //#define DEBUG_EMPTY_SLOT
19 
20 #ifdef DEBUG_EMPTY_SLOT
21 #define DPRINTF(fmt, ...)                                       \
22     do { printf("empty_slot: " fmt , ## __VA_ARGS__); } while (0)
23 #else
24 #define DPRINTF(fmt, ...) do {} while (0)
25 #endif
26 
27 #define TYPE_EMPTY_SLOT "empty_slot"
28 #define EMPTY_SLOT(obj) OBJECT_CHECK(EmptySlot, (obj), TYPE_EMPTY_SLOT)
29 
30 typedef struct EmptySlot {
31     SysBusDevice parent_obj;
32 
33     MemoryRegion iomem;
34     char *name;
35     uint64_t size;
36 } EmptySlot;
37 
38 static uint64_t empty_slot_read(void *opaque, hwaddr addr,
39                                 unsigned size)
40 {
41     DPRINTF("read from " TARGET_FMT_plx "\n", addr);
42     return 0;
43 }
44 
45 static void empty_slot_write(void *opaque, hwaddr addr,
46                              uint64_t val, unsigned size)
47 {
48     DPRINTF("write 0x%x to " TARGET_FMT_plx "\n", (unsigned)val, addr);
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(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_create(NULL, TYPE_EMPTY_SLOT);
64 
65         qdev_prop_set_uint64(dev, "size", slot_size);
66         qdev_init_nofail(dev);
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 }
97 
98 static const TypeInfo empty_slot_info = {
99     .name          = TYPE_EMPTY_SLOT,
100     .parent        = TYPE_SYS_BUS_DEVICE,
101     .instance_size = sizeof(EmptySlot),
102     .class_init    = empty_slot_class_init,
103 };
104 
105 static void empty_slot_register_types(void)
106 {
107     type_register_static(&empty_slot_info);
108 }
109 
110 type_init(empty_slot_register_types)
111