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