]> git.proxmox.com Git - mirror_qemu.git/blame - hw/misc/empty_slot.c
qdev: Convert uses of qdev_create() with Coccinelle
[mirror_qemu.git] / hw / misc / empty_slot.c
CommitLineData
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 13#include "hw/sysbus.h"
4bbadef0 14#include "hw/qdev-properties.h"
6007523a 15#include "hw/misc/empty_slot.h"
3e80f690 16#include "qapi/error.h"
c0e43084 17#include "trace.h"
da9fcfa5 18
8df81c4b
AF
19#define TYPE_EMPTY_SLOT "empty_slot"
20#define EMPTY_SLOT(obj) OBJECT_CHECK(EmptySlot, (obj), TYPE_EMPTY_SLOT)
21
da9fcfa5 22typedef struct EmptySlot {
8df81c4b
AF
23 SysBusDevice parent_obj;
24
b0a941b0 25 MemoryRegion iomem;
07ddf5cb 26 char *name;
da9fcfa5
AT
27 uint64_t size;
28} EmptySlot;
29
a8170e5e 30static uint64_t empty_slot_read(void *opaque, hwaddr addr,
b0a941b0 31 unsigned size)
da9fcfa5 32{
c0e43084
PMD
33 EmptySlot *s = EMPTY_SLOT(opaque);
34
35 trace_empty_slot_write(addr, size << 1, 0, size, s->name);
36
da9fcfa5
AT
37 return 0;
38}
39
a8170e5e 40static void empty_slot_write(void *opaque, hwaddr addr,
b0a941b0 41 uint64_t val, unsigned size)
da9fcfa5 42{
c0e43084
PMD
43 EmptySlot *s = EMPTY_SLOT(opaque);
44
45 trace_empty_slot_write(addr, size << 1, val, size, s->name);
da9fcfa5
AT
46}
47
b0a941b0
AK
48static const MemoryRegionOps empty_slot_ops = {
49 .read = empty_slot_read,
50 .write = empty_slot_write,
51 .endianness = DEVICE_NATIVE_ENDIAN,
da9fcfa5
AT
52};
53
28c78fe8 54void empty_slot_init(const char *name, hwaddr addr, uint64_t slot_size)
da9fcfa5 55{
1a00282a
SW
56 if (slot_size > 0) {
57 /* Only empty slots larger than 0 byte need handling. */
58 DeviceState *dev;
da9fcfa5 59
3e80f690 60 dev = qdev_new(TYPE_EMPTY_SLOT);
da9fcfa5 61
4bbadef0 62 qdev_prop_set_uint64(dev, "size", slot_size);
3e80f690 63 qdev_realize_and_unref(dev, NULL, &error_fatal);
da9fcfa5 64
4bbadef0 65 sysbus_mmio_map_overlap(SYS_BUS_DEVICE(dev), 0, addr, -10000);
1a00282a 66 }
da9fcfa5
AT
67}
68
4dbf209d 69static void empty_slot_realize(DeviceState *dev, Error **errp)
da9fcfa5 70{
8df81c4b 71 EmptySlot *s = EMPTY_SLOT(dev);
da9fcfa5 72
07ddf5cb
PMD
73 if (s->name == NULL) {
74 s->name = g_strdup("empty-slot");
75 }
300b1fc6 76 memory_region_init_io(&s->iomem, OBJECT(s), &empty_slot_ops, s,
07ddf5cb 77 s->name, s->size);
4dbf209d 78 sysbus_init_mmio(SYS_BUS_DEVICE(dev), &s->iomem);
da9fcfa5
AT
79}
80
4bbadef0
PMD
81static Property empty_slot_properties[] = {
82 DEFINE_PROP_UINT64("size", EmptySlot, size, 0),
07ddf5cb 83 DEFINE_PROP_STRING("name", EmptySlot, name),
4bbadef0
PMD
84 DEFINE_PROP_END_OF_LIST(),
85};
86
999e12bb
AL
87static void empty_slot_class_init(ObjectClass *klass, void *data)
88{
4dbf209d 89 DeviceClass *dc = DEVICE_CLASS(klass);
999e12bb 90
4dbf209d 91 dc->realize = empty_slot_realize;
4bbadef0 92 device_class_set_props(dc, empty_slot_properties);
6007523a 93 set_bit(DEVICE_CATEGORY_MISC, dc->categories);
999e12bb
AL
94}
95
8c43a6f0 96static const TypeInfo empty_slot_info = {
8df81c4b 97 .name = TYPE_EMPTY_SLOT,
39bffca2
AL
98 .parent = TYPE_SYS_BUS_DEVICE,
99 .instance_size = sizeof(EmptySlot),
100 .class_init = empty_slot_class_init,
da9fcfa5
AT
101};
102
83f7d43a 103static void empty_slot_register_types(void)
da9fcfa5 104{
39bffca2 105 type_register_static(&empty_slot_info);
da9fcfa5
AT
106}
107
83f7d43a 108type_init(empty_slot_register_types)