xref: /openbmc/qemu/include/hw/misc/unimp.h (revision 8fa3b702)
1 /*
2  * "Unimplemented" device
3  *
4  * Copyright Linaro Limited, 2017
5  * Written by Peter Maydell
6  */
7 
8 #ifndef HW_MISC_UNIMP_H
9 #define HW_MISC_UNIMP_H
10 
11 #include "hw/qdev-properties.h"
12 #include "hw/sysbus.h"
13 #include "qapi/error.h"
14 #include "qom/object.h"
15 
16 #define TYPE_UNIMPLEMENTED_DEVICE "unimplemented-device"
17 
18 typedef struct UnimplementedDeviceState UnimplementedDeviceState;
19 DECLARE_INSTANCE_CHECKER(UnimplementedDeviceState, UNIMPLEMENTED_DEVICE,
20                          TYPE_UNIMPLEMENTED_DEVICE)
21 
22 struct UnimplementedDeviceState {
23     SysBusDevice parent_obj;
24     MemoryRegion iomem;
25     unsigned offset_fmt_width;
26     char *name;
27     uint64_t size;
28 };
29 
30 /**
31  * create_unimplemented_device: create and map a dummy device
32  * @name: name of the device for debug logging
33  * @base: base address of the device's MMIO region
34  * @size: size of the device's MMIO region
35  *
36  * This utility function creates and maps an instance of unimplemented-device,
37  * which is a dummy device which simply logs all guest accesses to
38  * it via the qemu_log LOG_UNIMP debug log.
39  * The device is mapped at priority -1000, which means that you can
40  * use it to cover a large region and then map other devices on top of it
41  * if necessary.
42  */
43 static inline void create_unimplemented_device(const char *name,
44                                                hwaddr base,
45                                                hwaddr size)
46 {
47     DeviceState *dev = qdev_new(TYPE_UNIMPLEMENTED_DEVICE);
48 
49     qdev_prop_set_string(dev, "name", name);
50     qdev_prop_set_uint64(dev, "size", size);
51     sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
52 
53     sysbus_mmio_map_overlap(SYS_BUS_DEVICE(dev), 0, base, -1000);
54 }
55 
56 #endif
57