Artyom Tarasenko | da9fcfa | 2010-04-17 01:10:04 +0200 | [diff] [blame] | 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 | |
Peter Maydell | 18c86e2 | 2016-01-26 18:17:29 +0000 | [diff] [blame] | 12 | #include "qemu/osdep.h" |
Paolo Bonzini | 83c9f4c | 2013-02-04 15:40:22 +0100 | [diff] [blame] | 13 | #include "hw/sysbus.h" |
Philippe Mathieu-Daudé | 4bbadef | 2019-06-24 17:19:22 +0200 | [diff] [blame] | 14 | #include "hw/qdev-properties.h" |
Philippe Mathieu-Daudé | 6007523 | 2019-06-24 17:17:32 +0200 | [diff] [blame] | 15 | #include "hw/misc/empty_slot.h" |
Markus Armbruster | 3e80f69 | 2020-06-10 07:31:58 +0200 | [diff] [blame] | 16 | #include "qapi/error.h" |
Philippe Mathieu-Daudé | c0e4308 | 2019-06-24 17:23:48 +0200 | [diff] [blame] | 17 | #include "trace.h" |
Eduardo Habkost | db1015e | 2020-09-03 16:43:22 -0400 | [diff] [blame] | 18 | #include "qom/object.h" |
Artyom Tarasenko | da9fcfa | 2010-04-17 01:10:04 +0200 | [diff] [blame] | 19 | |
Andreas Färber | 8df81c4 | 2013-07-24 23:48:30 +0200 | [diff] [blame] | 20 | #define TYPE_EMPTY_SLOT "empty_slot" |
Eduardo Habkost | 8063396 | 2020-09-16 14:25:19 -0400 | [diff] [blame] | 21 | OBJECT_DECLARE_SIMPLE_TYPE(EmptySlot, EMPTY_SLOT) |
Andreas Färber | 8df81c4 | 2013-07-24 23:48:30 +0200 | [diff] [blame] | 22 | |
Eduardo Habkost | db1015e | 2020-09-03 16:43:22 -0400 | [diff] [blame] | 23 | struct EmptySlot { |
Andreas Färber | 8df81c4 | 2013-07-24 23:48:30 +0200 | [diff] [blame] | 24 | SysBusDevice parent_obj; |
| 25 | |
Avi Kivity | b0a941b | 2011-11-13 15:19:29 +0200 | [diff] [blame] | 26 | MemoryRegion iomem; |
Philippe Mathieu-Daudé | 07ddf5c | 2019-06-24 17:23:31 +0200 | [diff] [blame] | 27 | char *name; |
Artyom Tarasenko | da9fcfa | 2010-04-17 01:10:04 +0200 | [diff] [blame] | 28 | uint64_t size; |
Eduardo Habkost | db1015e | 2020-09-03 16:43:22 -0400 | [diff] [blame] | 29 | }; |
Artyom Tarasenko | da9fcfa | 2010-04-17 01:10:04 +0200 | [diff] [blame] | 30 | |
Avi Kivity | a8170e5 | 2012-10-23 12:30:10 +0200 | [diff] [blame] | 31 | static uint64_t empty_slot_read(void *opaque, hwaddr addr, |
Avi Kivity | b0a941b | 2011-11-13 15:19:29 +0200 | [diff] [blame] | 32 | unsigned size) |
Artyom Tarasenko | da9fcfa | 2010-04-17 01:10:04 +0200 | [diff] [blame] | 33 | { |
Philippe Mathieu-Daudé | c0e4308 | 2019-06-24 17:23:48 +0200 | [diff] [blame] | 34 | EmptySlot *s = EMPTY_SLOT(opaque); |
| 35 | |
| 36 | trace_empty_slot_write(addr, size << 1, 0, size, s->name); |
| 37 | |
Artyom Tarasenko | da9fcfa | 2010-04-17 01:10:04 +0200 | [diff] [blame] | 38 | return 0; |
| 39 | } |
| 40 | |
Avi Kivity | a8170e5 | 2012-10-23 12:30:10 +0200 | [diff] [blame] | 41 | static void empty_slot_write(void *opaque, hwaddr addr, |
Avi Kivity | b0a941b | 2011-11-13 15:19:29 +0200 | [diff] [blame] | 42 | uint64_t val, unsigned size) |
Artyom Tarasenko | da9fcfa | 2010-04-17 01:10:04 +0200 | [diff] [blame] | 43 | { |
Philippe Mathieu-Daudé | c0e4308 | 2019-06-24 17:23:48 +0200 | [diff] [blame] | 44 | EmptySlot *s = EMPTY_SLOT(opaque); |
| 45 | |
| 46 | trace_empty_slot_write(addr, size << 1, val, size, s->name); |
Artyom Tarasenko | da9fcfa | 2010-04-17 01:10:04 +0200 | [diff] [blame] | 47 | } |
| 48 | |
Avi Kivity | b0a941b | 2011-11-13 15:19:29 +0200 | [diff] [blame] | 49 | static const MemoryRegionOps empty_slot_ops = { |
| 50 | .read = empty_slot_read, |
| 51 | .write = empty_slot_write, |
| 52 | .endianness = DEVICE_NATIVE_ENDIAN, |
Artyom Tarasenko | da9fcfa | 2010-04-17 01:10:04 +0200 | [diff] [blame] | 53 | }; |
| 54 | |
Philippe Mathieu-Daudé | 28c78fe | 2019-06-24 18:55:47 +0200 | [diff] [blame] | 55 | void empty_slot_init(const char *name, hwaddr addr, uint64_t slot_size) |
Artyom Tarasenko | da9fcfa | 2010-04-17 01:10:04 +0200 | [diff] [blame] | 56 | { |
Stefan Weil | 1a00282 | 2011-04-14 19:19:00 +0200 | [diff] [blame] | 57 | if (slot_size > 0) { |
| 58 | /* Only empty slots larger than 0 byte need handling. */ |
| 59 | DeviceState *dev; |
Artyom Tarasenko | da9fcfa | 2010-04-17 01:10:04 +0200 | [diff] [blame] | 60 | |
Markus Armbruster | 3e80f69 | 2020-06-10 07:31:58 +0200 | [diff] [blame] | 61 | dev = qdev_new(TYPE_EMPTY_SLOT); |
Artyom Tarasenko | da9fcfa | 2010-04-17 01:10:04 +0200 | [diff] [blame] | 62 | |
Philippe Mathieu-Daudé | 4bbadef | 2019-06-24 17:19:22 +0200 | [diff] [blame] | 63 | qdev_prop_set_uint64(dev, "size", slot_size); |
Markus Armbruster | 3c6ef47 | 2020-06-10 07:32:34 +0200 | [diff] [blame] | 64 | sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal); |
Artyom Tarasenko | da9fcfa | 2010-04-17 01:10:04 +0200 | [diff] [blame] | 65 | |
Philippe Mathieu-Daudé | 4bbadef | 2019-06-24 17:19:22 +0200 | [diff] [blame] | 66 | sysbus_mmio_map_overlap(SYS_BUS_DEVICE(dev), 0, addr, -10000); |
Stefan Weil | 1a00282 | 2011-04-14 19:19:00 +0200 | [diff] [blame] | 67 | } |
Artyom Tarasenko | da9fcfa | 2010-04-17 01:10:04 +0200 | [diff] [blame] | 68 | } |
| 69 | |
Mao Zhongyi | 4dbf209 | 2018-12-13 13:47:57 +0000 | [diff] [blame] | 70 | static void empty_slot_realize(DeviceState *dev, Error **errp) |
Artyom Tarasenko | da9fcfa | 2010-04-17 01:10:04 +0200 | [diff] [blame] | 71 | { |
Andreas Färber | 8df81c4 | 2013-07-24 23:48:30 +0200 | [diff] [blame] | 72 | EmptySlot *s = EMPTY_SLOT(dev); |
Artyom Tarasenko | da9fcfa | 2010-04-17 01:10:04 +0200 | [diff] [blame] | 73 | |
Philippe Mathieu-Daudé | 07ddf5c | 2019-06-24 17:23:31 +0200 | [diff] [blame] | 74 | if (s->name == NULL) { |
| 75 | s->name = g_strdup("empty-slot"); |
| 76 | } |
Paolo Bonzini | 300b1fc | 2013-06-06 21:25:08 -0400 | [diff] [blame] | 77 | memory_region_init_io(&s->iomem, OBJECT(s), &empty_slot_ops, s, |
Philippe Mathieu-Daudé | 07ddf5c | 2019-06-24 17:23:31 +0200 | [diff] [blame] | 78 | s->name, s->size); |
Mao Zhongyi | 4dbf209 | 2018-12-13 13:47:57 +0000 | [diff] [blame] | 79 | sysbus_init_mmio(SYS_BUS_DEVICE(dev), &s->iomem); |
Artyom Tarasenko | da9fcfa | 2010-04-17 01:10:04 +0200 | [diff] [blame] | 80 | } |
| 81 | |
Philippe Mathieu-Daudé | 4bbadef | 2019-06-24 17:19:22 +0200 | [diff] [blame] | 82 | static Property empty_slot_properties[] = { |
| 83 | DEFINE_PROP_UINT64("size", EmptySlot, size, 0), |
Philippe Mathieu-Daudé | 07ddf5c | 2019-06-24 17:23:31 +0200 | [diff] [blame] | 84 | DEFINE_PROP_STRING("name", EmptySlot, name), |
Philippe Mathieu-Daudé | 4bbadef | 2019-06-24 17:19:22 +0200 | [diff] [blame] | 85 | DEFINE_PROP_END_OF_LIST(), |
| 86 | }; |
| 87 | |
Anthony Liguori | 999e12b | 2012-01-24 13:12:29 -0600 | [diff] [blame] | 88 | static void empty_slot_class_init(ObjectClass *klass, void *data) |
| 89 | { |
Mao Zhongyi | 4dbf209 | 2018-12-13 13:47:57 +0000 | [diff] [blame] | 90 | DeviceClass *dc = DEVICE_CLASS(klass); |
Anthony Liguori | 999e12b | 2012-01-24 13:12:29 -0600 | [diff] [blame] | 91 | |
Mao Zhongyi | 4dbf209 | 2018-12-13 13:47:57 +0000 | [diff] [blame] | 92 | dc->realize = empty_slot_realize; |
Philippe Mathieu-Daudé | 4bbadef | 2019-06-24 17:19:22 +0200 | [diff] [blame] | 93 | device_class_set_props(dc, empty_slot_properties); |
Philippe Mathieu-Daudé | 6007523 | 2019-06-24 17:17:32 +0200 | [diff] [blame] | 94 | set_bit(DEVICE_CATEGORY_MISC, dc->categories); |
Anthony Liguori | 999e12b | 2012-01-24 13:12:29 -0600 | [diff] [blame] | 95 | } |
| 96 | |
Andreas Färber | 8c43a6f | 2013-01-10 16:19:07 +0100 | [diff] [blame] | 97 | static const TypeInfo empty_slot_info = { |
Andreas Färber | 8df81c4 | 2013-07-24 23:48:30 +0200 | [diff] [blame] | 98 | .name = TYPE_EMPTY_SLOT, |
Anthony Liguori | 39bffca | 2011-12-07 21:34:16 -0600 | [diff] [blame] | 99 | .parent = TYPE_SYS_BUS_DEVICE, |
| 100 | .instance_size = sizeof(EmptySlot), |
| 101 | .class_init = empty_slot_class_init, |
Artyom Tarasenko | da9fcfa | 2010-04-17 01:10:04 +0200 | [diff] [blame] | 102 | }; |
| 103 | |
Andreas Färber | 83f7d43 | 2012-02-09 15:20:55 +0100 | [diff] [blame] | 104 | static void empty_slot_register_types(void) |
Artyom Tarasenko | da9fcfa | 2010-04-17 01:10:04 +0200 | [diff] [blame] | 105 | { |
Anthony Liguori | 39bffca | 2011-12-07 21:34:16 -0600 | [diff] [blame] | 106 | type_register_static(&empty_slot_info); |
Artyom Tarasenko | da9fcfa | 2010-04-17 01:10:04 +0200 | [diff] [blame] | 107 | } |
| 108 | |
Andreas Färber | 83f7d43 | 2012-02-09 15:20:55 +0100 | [diff] [blame] | 109 | type_init(empty_slot_register_types) |