blob: 37b0ddfb02a90740d03cc75e86218d8f3549d8b6 [file] [log] [blame]
Artyom Tarasenkoda9fcfa2010-04-17 01:10:04 +02001/*
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
Peter Maydell18c86e22016-01-26 18:17:29 +000012#include "qemu/osdep.h"
Paolo Bonzini83c9f4c2013-02-04 15:40:22 +010013#include "hw/sysbus.h"
Philippe Mathieu-Daudé4bbadef2019-06-24 17:19:22 +020014#include "hw/qdev-properties.h"
Philippe Mathieu-Daudé60075232019-06-24 17:17:32 +020015#include "hw/misc/empty_slot.h"
Markus Armbruster3e80f692020-06-10 07:31:58 +020016#include "qapi/error.h"
Philippe Mathieu-Daudéc0e43082019-06-24 17:23:48 +020017#include "trace.h"
Eduardo Habkostdb1015e2020-09-03 16:43:22 -040018#include "qom/object.h"
Artyom Tarasenkoda9fcfa2010-04-17 01:10:04 +020019
Andreas Färber8df81c42013-07-24 23:48:30 +020020#define TYPE_EMPTY_SLOT "empty_slot"
Eduardo Habkost80633962020-09-16 14:25:19 -040021OBJECT_DECLARE_SIMPLE_TYPE(EmptySlot, EMPTY_SLOT)
Andreas Färber8df81c42013-07-24 23:48:30 +020022
Eduardo Habkostdb1015e2020-09-03 16:43:22 -040023struct EmptySlot {
Andreas Färber8df81c42013-07-24 23:48:30 +020024 SysBusDevice parent_obj;
25
Avi Kivityb0a941b2011-11-13 15:19:29 +020026 MemoryRegion iomem;
Philippe Mathieu-Daudé07ddf5c2019-06-24 17:23:31 +020027 char *name;
Artyom Tarasenkoda9fcfa2010-04-17 01:10:04 +020028 uint64_t size;
Eduardo Habkostdb1015e2020-09-03 16:43:22 -040029};
Artyom Tarasenkoda9fcfa2010-04-17 01:10:04 +020030
Avi Kivitya8170e52012-10-23 12:30:10 +020031static uint64_t empty_slot_read(void *opaque, hwaddr addr,
Avi Kivityb0a941b2011-11-13 15:19:29 +020032 unsigned size)
Artyom Tarasenkoda9fcfa2010-04-17 01:10:04 +020033{
Philippe Mathieu-Daudéc0e43082019-06-24 17:23:48 +020034 EmptySlot *s = EMPTY_SLOT(opaque);
35
36 trace_empty_slot_write(addr, size << 1, 0, size, s->name);
37
Artyom Tarasenkoda9fcfa2010-04-17 01:10:04 +020038 return 0;
39}
40
Avi Kivitya8170e52012-10-23 12:30:10 +020041static void empty_slot_write(void *opaque, hwaddr addr,
Avi Kivityb0a941b2011-11-13 15:19:29 +020042 uint64_t val, unsigned size)
Artyom Tarasenkoda9fcfa2010-04-17 01:10:04 +020043{
Philippe Mathieu-Daudéc0e43082019-06-24 17:23:48 +020044 EmptySlot *s = EMPTY_SLOT(opaque);
45
46 trace_empty_slot_write(addr, size << 1, val, size, s->name);
Artyom Tarasenkoda9fcfa2010-04-17 01:10:04 +020047}
48
Avi Kivityb0a941b2011-11-13 15:19:29 +020049static const MemoryRegionOps empty_slot_ops = {
50 .read = empty_slot_read,
51 .write = empty_slot_write,
52 .endianness = DEVICE_NATIVE_ENDIAN,
Artyom Tarasenkoda9fcfa2010-04-17 01:10:04 +020053};
54
Philippe Mathieu-Daudé28c78fe2019-06-24 18:55:47 +020055void empty_slot_init(const char *name, hwaddr addr, uint64_t slot_size)
Artyom Tarasenkoda9fcfa2010-04-17 01:10:04 +020056{
Stefan Weil1a002822011-04-14 19:19:00 +020057 if (slot_size > 0) {
58 /* Only empty slots larger than 0 byte need handling. */
59 DeviceState *dev;
Artyom Tarasenkoda9fcfa2010-04-17 01:10:04 +020060
Markus Armbruster3e80f692020-06-10 07:31:58 +020061 dev = qdev_new(TYPE_EMPTY_SLOT);
Artyom Tarasenkoda9fcfa2010-04-17 01:10:04 +020062
Philippe Mathieu-Daudé4bbadef2019-06-24 17:19:22 +020063 qdev_prop_set_uint64(dev, "size", slot_size);
Markus Armbruster3c6ef472020-06-10 07:32:34 +020064 sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
Artyom Tarasenkoda9fcfa2010-04-17 01:10:04 +020065
Philippe Mathieu-Daudé4bbadef2019-06-24 17:19:22 +020066 sysbus_mmio_map_overlap(SYS_BUS_DEVICE(dev), 0, addr, -10000);
Stefan Weil1a002822011-04-14 19:19:00 +020067 }
Artyom Tarasenkoda9fcfa2010-04-17 01:10:04 +020068}
69
Mao Zhongyi4dbf2092018-12-13 13:47:57 +000070static void empty_slot_realize(DeviceState *dev, Error **errp)
Artyom Tarasenkoda9fcfa2010-04-17 01:10:04 +020071{
Andreas Färber8df81c42013-07-24 23:48:30 +020072 EmptySlot *s = EMPTY_SLOT(dev);
Artyom Tarasenkoda9fcfa2010-04-17 01:10:04 +020073
Philippe Mathieu-Daudé07ddf5c2019-06-24 17:23:31 +020074 if (s->name == NULL) {
75 s->name = g_strdup("empty-slot");
76 }
Paolo Bonzini300b1fc2013-06-06 21:25:08 -040077 memory_region_init_io(&s->iomem, OBJECT(s), &empty_slot_ops, s,
Philippe Mathieu-Daudé07ddf5c2019-06-24 17:23:31 +020078 s->name, s->size);
Mao Zhongyi4dbf2092018-12-13 13:47:57 +000079 sysbus_init_mmio(SYS_BUS_DEVICE(dev), &s->iomem);
Artyom Tarasenkoda9fcfa2010-04-17 01:10:04 +020080}
81
Philippe Mathieu-Daudé4bbadef2019-06-24 17:19:22 +020082static Property empty_slot_properties[] = {
83 DEFINE_PROP_UINT64("size", EmptySlot, size, 0),
Philippe Mathieu-Daudé07ddf5c2019-06-24 17:23:31 +020084 DEFINE_PROP_STRING("name", EmptySlot, name),
Philippe Mathieu-Daudé4bbadef2019-06-24 17:19:22 +020085 DEFINE_PROP_END_OF_LIST(),
86};
87
Anthony Liguori999e12b2012-01-24 13:12:29 -060088static void empty_slot_class_init(ObjectClass *klass, void *data)
89{
Mao Zhongyi4dbf2092018-12-13 13:47:57 +000090 DeviceClass *dc = DEVICE_CLASS(klass);
Anthony Liguori999e12b2012-01-24 13:12:29 -060091
Mao Zhongyi4dbf2092018-12-13 13:47:57 +000092 dc->realize = empty_slot_realize;
Philippe Mathieu-Daudé4bbadef2019-06-24 17:19:22 +020093 device_class_set_props(dc, empty_slot_properties);
Philippe Mathieu-Daudé60075232019-06-24 17:17:32 +020094 set_bit(DEVICE_CATEGORY_MISC, dc->categories);
Anthony Liguori999e12b2012-01-24 13:12:29 -060095}
96
Andreas Färber8c43a6f2013-01-10 16:19:07 +010097static const TypeInfo empty_slot_info = {
Andreas Färber8df81c42013-07-24 23:48:30 +020098 .name = TYPE_EMPTY_SLOT,
Anthony Liguori39bffca2011-12-07 21:34:16 -060099 .parent = TYPE_SYS_BUS_DEVICE,
100 .instance_size = sizeof(EmptySlot),
101 .class_init = empty_slot_class_init,
Artyom Tarasenkoda9fcfa2010-04-17 01:10:04 +0200102};
103
Andreas Färber83f7d432012-02-09 15:20:55 +0100104static void empty_slot_register_types(void)
Artyom Tarasenkoda9fcfa2010-04-17 01:10:04 +0200105{
Anthony Liguori39bffca2011-12-07 21:34:16 -0600106 type_register_static(&empty_slot_info);
Artyom Tarasenkoda9fcfa2010-04-17 01:10:04 +0200107}
108
Andreas Färber83f7d432012-02-09 15:20:55 +0100109type_init(empty_slot_register_types)