]> Git Repo - qemu.git/blob - hw/misc/empty_slot.c
Move QOM typedefs and add missing includes
[qemu.git] / hw / misc / 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 "qemu/osdep.h"
13 #include "hw/sysbus.h"
14 #include "hw/qdev-properties.h"
15 #include "hw/misc/empty_slot.h"
16 #include "qapi/error.h"
17 #include "trace.h"
18 #include "qom/object.h"
19
20 #define TYPE_EMPTY_SLOT "empty_slot"
21 typedef struct EmptySlot EmptySlot;
22 #define EMPTY_SLOT(obj) OBJECT_CHECK(EmptySlot, (obj), TYPE_EMPTY_SLOT)
23
24 struct EmptySlot {
25     SysBusDevice parent_obj;
26
27     MemoryRegion iomem;
28     char *name;
29     uint64_t size;
30 };
31
32 static uint64_t empty_slot_read(void *opaque, hwaddr addr,
33                                 unsigned size)
34 {
35     EmptySlot *s = EMPTY_SLOT(opaque);
36
37     trace_empty_slot_write(addr, size << 1, 0, size, s->name);
38
39     return 0;
40 }
41
42 static void empty_slot_write(void *opaque, hwaddr addr,
43                              uint64_t val, unsigned size)
44 {
45     EmptySlot *s = EMPTY_SLOT(opaque);
46
47     trace_empty_slot_write(addr, size << 1, val, size, s->name);
48 }
49
50 static const MemoryRegionOps empty_slot_ops = {
51     .read = empty_slot_read,
52     .write = empty_slot_write,
53     .endianness = DEVICE_NATIVE_ENDIAN,
54 };
55
56 void empty_slot_init(const char *name, hwaddr addr, uint64_t slot_size)
57 {
58     if (slot_size > 0) {
59         /* Only empty slots larger than 0 byte need handling. */
60         DeviceState *dev;
61
62         dev = qdev_new(TYPE_EMPTY_SLOT);
63
64         qdev_prop_set_uint64(dev, "size", slot_size);
65         sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
66
67         sysbus_mmio_map_overlap(SYS_BUS_DEVICE(dev), 0, addr, -10000);
68     }
69 }
70
71 static void empty_slot_realize(DeviceState *dev, Error **errp)
72 {
73     EmptySlot *s = EMPTY_SLOT(dev);
74
75     if (s->name == NULL) {
76         s->name = g_strdup("empty-slot");
77     }
78     memory_region_init_io(&s->iomem, OBJECT(s), &empty_slot_ops, s,
79                           s->name, s->size);
80     sysbus_init_mmio(SYS_BUS_DEVICE(dev), &s->iomem);
81 }
82
83 static Property empty_slot_properties[] = {
84     DEFINE_PROP_UINT64("size", EmptySlot, size, 0),
85     DEFINE_PROP_STRING("name", EmptySlot, name),
86     DEFINE_PROP_END_OF_LIST(),
87 };
88
89 static void empty_slot_class_init(ObjectClass *klass, void *data)
90 {
91     DeviceClass *dc = DEVICE_CLASS(klass);
92
93     dc->realize = empty_slot_realize;
94     device_class_set_props(dc, empty_slot_properties);
95     set_bit(DEVICE_CATEGORY_MISC, dc->categories);
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)
This page took 0.030054 seconds and 4 git commands to generate.