]>
Commit | Line | Data |
---|---|---|
da9fcfa5 AT |
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 | ||
18c86e2b | 12 | #include "qemu/osdep.h" |
83c9f4ca PB |
13 | #include "hw/hw.h" |
14 | #include "hw/sysbus.h" | |
15 | #include "hw/empty_slot.h" | |
da9fcfa5 AT |
16 | |
17 | //#define DEBUG_EMPTY_SLOT | |
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 | ||
8df81c4b AF |
26 | #define TYPE_EMPTY_SLOT "empty_slot" |
27 | #define EMPTY_SLOT(obj) OBJECT_CHECK(EmptySlot, (obj), TYPE_EMPTY_SLOT) | |
28 | ||
da9fcfa5 | 29 | typedef struct EmptySlot { |
8df81c4b AF |
30 | SysBusDevice parent_obj; |
31 | ||
b0a941b0 | 32 | MemoryRegion iomem; |
da9fcfa5 AT |
33 | uint64_t size; |
34 | } EmptySlot; | |
35 | ||
a8170e5e | 36 | static uint64_t empty_slot_read(void *opaque, hwaddr addr, |
b0a941b0 | 37 | unsigned size) |
da9fcfa5 AT |
38 | { |
39 | DPRINTF("read from " TARGET_FMT_plx "\n", addr); | |
40 | return 0; | |
41 | } | |
42 | ||
a8170e5e | 43 | static void empty_slot_write(void *opaque, hwaddr addr, |
b0a941b0 | 44 | uint64_t val, unsigned size) |
da9fcfa5 | 45 | { |
b0a941b0 | 46 | DPRINTF("write 0x%x to " TARGET_FMT_plx "\n", (unsigned)val, addr); |
da9fcfa5 AT |
47 | } |
48 | ||
b0a941b0 AK |
49 | static const MemoryRegionOps empty_slot_ops = { |
50 | .read = empty_slot_read, | |
51 | .write = empty_slot_write, | |
52 | .endianness = DEVICE_NATIVE_ENDIAN, | |
da9fcfa5 AT |
53 | }; |
54 | ||
a8170e5e | 55 | void empty_slot_init(hwaddr addr, uint64_t slot_size) |
da9fcfa5 | 56 | { |
1a00282a SW |
57 | if (slot_size > 0) { |
58 | /* Only empty slots larger than 0 byte need handling. */ | |
59 | DeviceState *dev; | |
60 | SysBusDevice *s; | |
61 | EmptySlot *e; | |
da9fcfa5 | 62 | |
8df81c4b | 63 | dev = qdev_create(NULL, TYPE_EMPTY_SLOT); |
1356b98d | 64 | s = SYS_BUS_DEVICE(dev); |
8df81c4b | 65 | e = EMPTY_SLOT(dev); |
1a00282a | 66 | e->size = slot_size; |
da9fcfa5 | 67 | |
1a00282a | 68 | qdev_init_nofail(dev); |
da9fcfa5 | 69 | |
1a00282a SW |
70 | sysbus_mmio_map(s, 0, addr); |
71 | } | |
da9fcfa5 AT |
72 | } |
73 | ||
74 | static int empty_slot_init1(SysBusDevice *dev) | |
75 | { | |
8df81c4b | 76 | EmptySlot *s = EMPTY_SLOT(dev); |
da9fcfa5 | 77 | |
300b1fc6 | 78 | memory_region_init_io(&s->iomem, OBJECT(s), &empty_slot_ops, s, |
b0a941b0 | 79 | "empty-slot", s->size); |
750ecd44 | 80 | sysbus_init_mmio(dev, &s->iomem); |
da9fcfa5 AT |
81 | return 0; |
82 | } | |
83 | ||
999e12bb AL |
84 | static 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 | ||
8c43a6f0 | 91 | static const TypeInfo empty_slot_info = { |
8df81c4b | 92 | .name = TYPE_EMPTY_SLOT, |
39bffca2 AL |
93 | .parent = TYPE_SYS_BUS_DEVICE, |
94 | .instance_size = sizeof(EmptySlot), | |
95 | .class_init = empty_slot_class_init, | |
da9fcfa5 AT |
96 | }; |
97 | ||
83f7d43a | 98 | static void empty_slot_register_types(void) |
da9fcfa5 | 99 | { |
39bffca2 | 100 | type_register_static(&empty_slot_info); |
da9fcfa5 AT |
101 | } |
102 | ||
83f7d43a | 103 | type_init(empty_slot_register_types) |