1
2
3
4
5
6
7
8
9
10
11
12#include "qemu/osdep.h"
13#include "hw/hw.h"
14#include "hw/sysbus.h"
15#include "hw/empty_slot.h"
16
17
18
19#ifdef DEBUG_EMPTY_SLOT
20#define DPRINTF(fmt, ...) \
21 do { printf("empty_slot: " fmt , ## __VA_ARGS__); } while (0)
22#else
23#define DPRINTF(fmt, ...) do {} while (0)
24#endif
25
26#define TYPE_EMPTY_SLOT "empty_slot"
27#define EMPTY_SLOT(obj) OBJECT_CHECK(EmptySlot, (obj), TYPE_EMPTY_SLOT)
28
29typedef struct EmptySlot {
30 SysBusDevice parent_obj;
31
32 MemoryRegion iomem;
33 uint64_t size;
34} EmptySlot;
35
36static uint64_t empty_slot_read(void *opaque, hwaddr addr,
37 unsigned size)
38{
39 DPRINTF("read from " TARGET_FMT_plx "\n", addr);
40 return 0;
41}
42
43static void empty_slot_write(void *opaque, hwaddr addr,
44 uint64_t val, unsigned size)
45{
46 DPRINTF("write 0x%x to " TARGET_FMT_plx "\n", (unsigned)val, addr);
47}
48
49static const MemoryRegionOps empty_slot_ops = {
50 .read = empty_slot_read,
51 .write = empty_slot_write,
52 .endianness = DEVICE_NATIVE_ENDIAN,
53};
54
55void empty_slot_init(hwaddr addr, uint64_t slot_size)
56{
57 if (slot_size > 0) {
58
59 DeviceState *dev;
60 SysBusDevice *s;
61 EmptySlot *e;
62
63 dev = qdev_create(NULL, TYPE_EMPTY_SLOT);
64 s = SYS_BUS_DEVICE(dev);
65 e = EMPTY_SLOT(dev);
66 e->size = slot_size;
67
68 qdev_init_nofail(dev);
69
70 sysbus_mmio_map(s, 0, addr);
71 }
72}
73
74static int empty_slot_init1(SysBusDevice *dev)
75{
76 EmptySlot *s = EMPTY_SLOT(dev);
77
78 memory_region_init_io(&s->iomem, OBJECT(s), &empty_slot_ops, s,
79 "empty-slot", s->size);
80 sysbus_init_mmio(dev, &s->iomem);
81 return 0;
82}
83
84static void empty_slot_class_init(ObjectClass *klass, void *data)
85{
86 SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
87
88 k->init = empty_slot_init1;
89}
90
91static const TypeInfo empty_slot_info = {
92 .name = TYPE_EMPTY_SLOT,
93 .parent = TYPE_SYS_BUS_DEVICE,
94 .instance_size = sizeof(EmptySlot),
95 .class_init = empty_slot_class_init,
96};
97
98static void empty_slot_register_types(void)
99{
100 type_register_static(&empty_slot_info);
101}
102
103type_init(empty_slot_register_types)
104