Merge remote-tracking branch 'remotes/kevin/tags/for-upstream' into staging
[qemu/ar7.git] / hw / core / empty_slot.c
blobc69453204691ad2a5f5a5178067b970fd6edc893
1 /*
2 * QEMU Empty Slot
4 * The empty_slot device emulates known to a bus but not connected devices.
6 * Copyright (c) 2010 Artyom Tarasenko
8 * This code is licensed under the GNU GPL v2 or (at your option) any later
9 * version.
12 #include "qemu/osdep.h"
13 #include "hw/hw.h"
14 #include "hw/sysbus.h"
15 #include "qemu/module.h"
16 #include "hw/empty_slot.h"
18 //#define DEBUG_EMPTY_SLOT
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
27 #define TYPE_EMPTY_SLOT "empty_slot"
28 #define EMPTY_SLOT(obj) OBJECT_CHECK(EmptySlot, (obj), TYPE_EMPTY_SLOT)
30 typedef struct EmptySlot {
31 SysBusDevice parent_obj;
33 MemoryRegion iomem;
34 uint64_t size;
35 } EmptySlot;
37 static uint64_t empty_slot_read(void *opaque, hwaddr addr,
38 unsigned size)
40 DPRINTF("read from " TARGET_FMT_plx "\n", addr);
41 return 0;
44 static void empty_slot_write(void *opaque, hwaddr addr,
45 uint64_t val, unsigned size)
47 DPRINTF("write 0x%x to " TARGET_FMT_plx "\n", (unsigned)val, addr);
50 static const MemoryRegionOps empty_slot_ops = {
51 .read = empty_slot_read,
52 .write = empty_slot_write,
53 .endianness = DEVICE_NATIVE_ENDIAN,
56 void empty_slot_init(hwaddr addr, uint64_t slot_size)
58 if (slot_size > 0) {
59 /* Only empty slots larger than 0 byte need handling. */
60 DeviceState *dev;
61 SysBusDevice *s;
62 EmptySlot *e;
64 dev = qdev_create(NULL, TYPE_EMPTY_SLOT);
65 s = SYS_BUS_DEVICE(dev);
66 e = EMPTY_SLOT(dev);
67 e->size = slot_size;
69 qdev_init_nofail(dev);
71 sysbus_mmio_map(s, 0, addr);
75 static void empty_slot_realize(DeviceState *dev, Error **errp)
77 EmptySlot *s = EMPTY_SLOT(dev);
79 memory_region_init_io(&s->iomem, OBJECT(s), &empty_slot_ops, s,
80 "empty-slot", s->size);
81 sysbus_init_mmio(SYS_BUS_DEVICE(dev), &s->iomem);
84 static void empty_slot_class_init(ObjectClass *klass, void *data)
86 DeviceClass *dc = DEVICE_CLASS(klass);
88 dc->realize = empty_slot_realize;
91 static 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,
98 static void empty_slot_register_types(void)
100 type_register_static(&empty_slot_info);
103 type_init(empty_slot_register_types)