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
12 #include "qemu/osdep.h"
13 #include "hw/sysbus.h"
14 #include "hw/qdev-properties.h"
15 #include "hw/misc/empty_slot.h"
18 #define TYPE_EMPTY_SLOT "empty_slot"
19 #define EMPTY_SLOT(obj) OBJECT_CHECK(EmptySlot, (obj), TYPE_EMPTY_SLOT)
21 typedef struct EmptySlot
{
22 SysBusDevice parent_obj
;
29 static uint64_t empty_slot_read(void *opaque
, hwaddr addr
,
32 EmptySlot
*s
= EMPTY_SLOT(opaque
);
34 trace_empty_slot_write(addr
, size
<< 1, 0, size
, s
->name
);
39 static void empty_slot_write(void *opaque
, hwaddr addr
,
40 uint64_t val
, unsigned size
)
42 EmptySlot
*s
= EMPTY_SLOT(opaque
);
44 trace_empty_slot_write(addr
, size
<< 1, val
, size
, s
->name
);
47 static const MemoryRegionOps empty_slot_ops
= {
48 .read
= empty_slot_read
,
49 .write
= empty_slot_write
,
50 .endianness
= DEVICE_NATIVE_ENDIAN
,
53 void empty_slot_init(hwaddr addr
, uint64_t slot_size
)
56 /* Only empty slots larger than 0 byte need handling. */
59 dev
= qdev_create(NULL
, TYPE_EMPTY_SLOT
);
61 qdev_prop_set_uint64(dev
, "size", slot_size
);
62 qdev_init_nofail(dev
);
64 sysbus_mmio_map_overlap(SYS_BUS_DEVICE(dev
), 0, addr
, -10000);
68 static void empty_slot_realize(DeviceState
*dev
, Error
**errp
)
70 EmptySlot
*s
= EMPTY_SLOT(dev
);
72 if (s
->name
== NULL
) {
73 s
->name
= g_strdup("empty-slot");
75 memory_region_init_io(&s
->iomem
, OBJECT(s
), &empty_slot_ops
, s
,
77 sysbus_init_mmio(SYS_BUS_DEVICE(dev
), &s
->iomem
);
80 static Property empty_slot_properties
[] = {
81 DEFINE_PROP_UINT64("size", EmptySlot
, size
, 0),
82 DEFINE_PROP_STRING("name", EmptySlot
, name
),
83 DEFINE_PROP_END_OF_LIST(),
86 static void empty_slot_class_init(ObjectClass
*klass
, void *data
)
88 DeviceClass
*dc
= DEVICE_CLASS(klass
);
90 dc
->realize
= empty_slot_realize
;
91 device_class_set_props(dc
, empty_slot_properties
);
92 set_bit(DEVICE_CATEGORY_MISC
, dc
->categories
);
95 static const TypeInfo empty_slot_info
= {
96 .name
= TYPE_EMPTY_SLOT
,
97 .parent
= TYPE_SYS_BUS_DEVICE
,
98 .instance_size
= sizeof(EmptySlot
),
99 .class_init
= empty_slot_class_init
,
102 static void empty_slot_register_types(void)
104 type_register_static(&empty_slot_info
);
107 type_init(empty_slot_register_types
)