"unimplemented" device for debug logging
cover "unimplemented" device for debug logging
This patchset implements an "unimplemented" sysbus device, which is a dummy device which accepts and logs all accesses. It's useful for stubbing out regions of an SoC or board map which correspond to devices that have not yet been implemented. This is often sufficient to placate initial guest device driver probing such that the system will come up.
Since QEMU's default behaviour for accesses to bits of the memory map with nothing there is to RAZ/WI them, instantiating this device somewhere doesn't actually change behaviour, and so the benefits here are really:
* provide helpful debug logging of which things the guest is actually trying to talk to, so we know which things are most useful to implement next
* allow stubbing out of devices on architectures which implement the CPU unassigned_access hook to actually throw a guest exception like real hardware does
* allow somebody reading board model code to easily see that some things have not yet been implemented
Patch 2 is the actual "unimp" device; patches 1 and 3 are to the stellaris board as an example of usage, but the short usage example is that you can just do:
create_unimplemented_device("PWM", 0x40028000, 0x1000);in your board model. If you're writing an SoC container object that maps things into another memory region rather than doing direct mapping into the system memory address space, you can create, configure, instantiate and map the thing by hand (as with all the other devices you're creating).
Resulting debug trace looks like this if you turn on -d unimp:
PWM: unimplemented device read (size 4, offset 0x40)
PWM: unimplemented device write (size 4, value 0x316a, offset 0x50)
thanks
-- PMM
Peter Maydell (3):
stellaris: Document memory map and which SoC devices are unimplemented hw/misc: New "unimplemented" sysbus device
stellaris: Use the 'unimplemented' device for parts we don't implement
hw/misc/Makefile.objs | 2 + include/hw/misc/unimp.h | 39 ++++++++++++++++++ hw/arm/stellaris.c | 45 ++++++++++++++++++++ hw/misc/unimp.c | 107 ++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 193 insertions(+) create mode 100644 include/hw/misc/unimp.h create mode 100644 hw/misc/unimp.c
Signature · 1 line
2.7.4
PATCH 1/3 stellaris: Document memory map and which SoC devices are unimplemented
Add a comment documenting the memory map of the SoC devices and which are not implemented.
--- hw/arm/stellaris.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+)
hw/arm/stellaris.c +31 -0
@@ -1220,6 +1220,37 @@ static void stellaris_init(const char *kernel_filename, const char *cpu_model, 0x40024000, 0x40025000, 0x40026000};static const int gpio_irq[7 ] = {0 ,1 ,2 ,3 ,4 ,30 ,31 }; +/* Memory map of SoC devices: +* 40000000 wdtimer (unimplemented) +* 40002000 i2c (unimplemented) +* 40004000 GPIO +* 40005000 GPIO +* 40006000 GPIO +* 40007000 GPIO +* 40008000 SSI +* 4000c000 UART +* 4000d000 UART +* 4000e000 UART +* 40020000 i2c +* 40021000 i2c (unimplemented) +* 40024000 GPIO +* 40025000 GPIO +* 40026000 GPIO +* 40028000 PWM (unimplemented) +* 4002c000 QEI (unimplemented) +* 4002d000 QEI (unimplemented) +* 40030000 gptimer +* 40031000 gptimer +* 40032000 gptimer +* 40033000 gptimer +* 40038000 ADC +* 4003c000 analogue comparator (unimplemented) +* 40048000 ethernet +* 400fc000 hibernation module (unimplemented) +* 400fd000 flash memory control (unimplemented) +* 400fe000 system control +*/ +DeviceState *gpio_dev[7 ], *nvic;qemu_irq gpio_in[7 ][8 ];qemu_irq gpio_out[7 ][8 ];
Signature · 1 line
2.7.4
Re: [Qemu-devel] [PATCH 1/3] stellaris: Document memory map and which SoC devices are unimplemented
Quoted 13 lines · Peter Maydell
Add a comment documenting the memory map of the SoC devices and which are not implemented.
Signed-off-by Peter Maydell <[email protected]>--- hw/arm/stellaris.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+)hw/arm/stellaris.c +0
-0
hw/arm/stellaris.c static void stellaris_init(const char *kernel_filename, const char *cpu_model, · line 1223
Quoted 4 lines
hw/arm/stellaris.c +1
-0@@ -1220,6 +1220,37 @@ static void stellaris_init(const char *kernel_filename, const char *cpu_model, 0x40024000, 0x40025000, 0x40026000};static const int gpio_irq[7 ] = {0 ,1 ,2 ,3 ,4 ,30 ,31 }; +/* Memory map of SoC devices:
Can we at least have the title of the document these came from for future reference?
Quoted 23 lines
hw/arm/stellaris.c +23
-0+* 40000000 wdtimer (unimplemented) +* 40002000 i2c (unimplemented) +* 40004000 GPIO +* 40005000 GPIO +* 40006000 GPIO +* 40007000 GPIO +* 40008000 SSI +* 4000c000 UART +* 4000d000 UART +* 4000e000 UART +* 40020000 i2c +* 40021000 i2c (unimplemented) +* 40024000 GPIO +* 40025000 GPIO +* 40026000 GPIO +* 40028000 PWM (unimplemented) +* 4002c000 QEI (unimplemented) +* 4002d000 QEI (unimplemented) +* 40030000 gptimer +* 40031000 gptimer +* 40032000 gptimer +* 40033000 gptimer +* 40038000 ADC
hw/arm/stellaris.c static void stellaris_init(const char *kernel_filename, const char *cpu_model, · line 1256
Quoted 10 lines
hw/arm/stellaris.c +7
-0+* 4003c000 analogue comparator (unimplemented) +* 40048000 ethernet +* 400fc000 hibernation module (unimplemented) +* 400fd000 flash memory control (unimplemented) +* 400fe000 system control +*/ +DeviceState *gpio_dev[7 ], *nvic;qemu_irq gpio_in[7 ][8 ];qemu_irq gpio_out[7 ][8 ];
--
Alex Bennée
Re: [Qemu-devel] [PATCH 1/3] stellaris: Document memory map and which SoC devices are unimplemented
Quoted 19 lines · Alex Bennée
Quoted 16 lines · Peter Maydell
Add a comment documenting the memory map of the SoC devices and which are not implemented.
Signed-off-by Peter Maydell <[email protected]>--- hw/arm/stellaris.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+)hw/arm/stellaris.c +0
-0@@ -1220,6 +1220,37 @@ static void stellaris_init(const char *kernel_filename, const char *cpu_model, 0x40024000, 0x40025000, 0x40026000};static const int gpio_irq[7 ] = {0 ,1 ,2 ,3 ,4 ,30 ,31 };
Quoted 4 lines
hw/arm/stellaris.c static void stellaris_init(const char *kernel_filename, const char *cpu_model, · line 1223
Quoted 1 line
hw/arm/stellaris.c +1
-0+/* Memory map of SoC devices: Can we at least have the title of the document these came from for future reference?
Good idea; it's
Stellaris LM3S6965 Microcontroller Data Sheet (rev H)
thanks
-- PMM
Re: [Qemu-devel] [PATCH 1/3] stellaris: Document memory map and which SoC devices are unimplemented
Quoted 8 lines · Peter Maydell
Quoted 4 lines · Alex Bennée
Peter Maydell <[email protected]> writes:
Can we at least have the title of the document these came from for future reference?Good idea; it's
Stellaris LM3S6965 Microcontroller Data Sheet (rev H)
Added these lines to the comment:
+ /* Memory map of SoC devices, from
+ * Stellaris LM3S6965 Microcontroller Data Sheet (rev I) + * http://www.ti.com/lit/ds/symlink/lm3s6965.pdf + *
I've put the series into target-arm.next, since that seems trivial enough not to merit a respin.
thanks
-- PMM
PATCH 2/3 hw/misc: New "unimplemented" sysbus device
In reply to Peter MaydellCreate a new "unimplemented" sysbus device, which simply accepts all read and write accesses, and implements them as read-as-zero, write-ignored, with logging of the access as LOG_UNIMP.
This is useful for stubbing out bits of an SoC or board model which haven't been written yet.
--- hw/misc/Makefile.objs | 2 + include/hw/misc/unimp.h | 39 ++++++++++++++++++ hw/misc/unimp.c | 107 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 148 insertions(+) create mode 100644 include/hw/misc/unimp.h create mode 100644 hw/misc/unimp.c
hw/misc/Makefile.objs +2 -0
@@ -6,6 +6,8 @@ common-obj-$(CONFIG_SGA) += sga.o common-obj-$(CONFIG_ISA_TESTDEV) += pc-testdev.o common-obj-$(CONFIG_PCI_TESTDEV) += pci-testdev.o +common-obj-y += unimp.o + obj-$(CONFIG_VMPORT) += vmport.o # ARM devices
include/hw/misc/unimp.h new file +39 -0
@@ -0,0 +1,39 @@ +/* +* "Unimplemented" device +* +* Copyright Linaro Limited, 2017 +* Written by Peter Maydell +*/ + +#ifndef HW_MISC_UNIMP_H +#define HW_MISC_UNIMP_H + +#define TYPE_UNIMPLEMENTED_DEVICE "unimplemented-device" + +/** +* create_unimplemented_device: create and map a dummy device +* @name: name of the device for debug logging +* @base: base address of the device's MMIO region +* @size: size of the device's MMIO region +* +* This utility function creates and maps an instance of unimplemented-device, +* which is a dummy device which simply logs all guest accesses to +* it via the qemu_log LOG_UNIMP debug log. +* The device is mapped at priority -1000, which means that you can +* use it to cover a large region and then map other devices on top of it +* if necessary. +*/ +static inline void create_unimplemented_device (const char *name, +hwaddr base, +hwaddr size) +{ +DeviceState *dev =qdev_create (NULL ,TYPE_UNIMPLEMENTED_DEVICE ); + +qdev_prop_set_string (dev,"name" , name); +qdev_prop_set_uint64 (dev,"size" , size); +qdev_init_nofail (dev); + +sysbus_mmio_map_overlap (SYS_BUS_DEVICE (dev),0 , base,-1000 ); +} + +#endif
hw/misc/unimp.c new file +107 -0
107 lines not on this page · raw message
Signature · 1 line
2.7.4
Re: [Qemu-devel] [PATCH 2/3] hw/misc: New "unimplemented" sysbus device
Quoted 8 lines · Peter Maydell
Create a new "unimplemented" sysbus device, which simply accepts all read and write accesses, and implements them as read-as-zero, write-ignored, with logging of the access as
LOG_UNIMP.This is useful for stubbing out bits of an SoC or board model which haven't been written yet.
Signed-off-by Peter Maydell <[email protected]>
This looks good:
Is there any millage at being able to define areas on the command line or would we expect every usage of this to be from a board file in the source?
It would be useful to link to this somewhere from the docs/wiki as a good example of a modern QDEV device boilerplate. It would make a change from telling people to "find a recent device and use it as a template" on IRC ;-)
Paolo,
Would this be in docs/ or on somewhere else?
Quoted 169 lines
--- hw/misc/Makefile.objs | 2 + include/hw/misc/unimp.h | 39 ++++++++++++++++++ hw/misc/unimp.c | 107 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 148 insertions(+) create mode 100644 include/hw/misc/unimp.h create mode 100644 hw/misc/unimp.chw/misc/Makefile.objs +2
-0@@ -6,6 +6,8 @@ common-obj-$(CONFIG_SGA) += sga.o common-obj-$(CONFIG_ISA_TESTDEV) += pc-testdev.o common-obj-$(CONFIG_PCI_TESTDEV) += pci-testdev.o +common-obj-y += unimp.o + obj-$(CONFIG_VMPORT) += vmport.o # ARM devicesinclude/hw/misc/unimp.h new file +39
-0@@ -0,0 +1,39 @@ +/* +* "Unimplemented" device +* +* Copyright Linaro Limited, 2017 +* Written by Peter Maydell +*/ + +#ifndef HW_MISC_UNIMP_H +#define HW_MISC_UNIMP_H + +#define TYPE_UNIMPLEMENTED_DEVICE "unimplemented-device" + +/** +* create_unimplemented_device: create and map a dummy device +* @name: name of the device for debug logging +* @base: base address of the device's MMIO region +* @size: size of the device's MMIO region +* +* This utility function creates and maps an instance of unimplemented-device, +* which is a dummy device which simply logs all guest accesses to +* it via the qemu_log LOG_UNIMP debug log. +* The device is mapped at priority -1000, which means that you can +* use it to cover a large region and then map other devices on top of it +* if necessary. +*/ +static inline void create_unimplemented_device (const char *name, +hwaddr base, +hwaddr size) +{ +DeviceState *dev =qdev_create (NULL ,TYPE_UNIMPLEMENTED_DEVICE ); + +qdev_prop_set_string (dev,"name" , name); +qdev_prop_set_uint64 (dev,"size" , size); +qdev_init_nofail (dev); + +sysbus_mmio_map_overlap (SYS_BUS_DEVICE (dev),0 , base,-1000 ); +} + +#endif hw/misc/unimp.c new file +97
-0@@ -0,0 +1,107 @@ +/* "Unimplemented" device +* +* This is a dummy device which accepts and logs all accesses. +* It's useful for stubbing out regions of an SoC or board +* map which correspond to devices that have not yet been +* implemented. This is often sufficient to placate initial +* guest device driver probing such that the system will +* come up. +* +* Copyright Linaro Limited, 2017 +* Written by Peter Maydell +*/ + +#include "qemu/osdep.h" +#include "hw/hw.h" +#include "hw/sysbus.h" +#include "hw/misc/unimp.h" +#include "qemu/log.h" +#include "qapi/error.h" + +#define UNIMPLEMENTED_DEVICE (obj) \ + OBJECT_CHECK(UnimplementedDeviceState, (obj), TYPE_UNIMPLEMENTED_DEVICE) + +typedef struct { +SysBusDevice parent_obj; +MemoryRegion iomem; +char *name; +uint64_t size; +}UnimplementedDeviceState ; + +static uint64_t unimp_read (void *opaque,hwaddr offset,unsigned size) +{ +UnimplementedDeviceState *s =UNIMPLEMENTED_DEVICE (opaque); + +qemu_log_mask (LOG_UNIMP ,"%s: unimplemented device read " +"(size %d, offset 0x%" HWADDR_PRIx")\n" , + s->name, size, offset); +return 0 ; +} + +static void unimp_write (void *opaque,hwaddr offset, +uint64_t value,unsigned size) +{ +UnimplementedDeviceState *s =UNIMPLEMENTED_DEVICE (opaque); + +qemu_log_mask (LOG_UNIMP ,"%s: unimplemented device write " +"(size %d, value 0x%" PRIx64 +", offset 0x%" HWADDR_PRIx")\n" , + s->name, size, value, offset); +} + +static const MemoryRegionOps unimp_ops = { + .read = unimp_read, + .write = unimp_write, + .impl.min_access_size =1 , + .impl.max_access_size =8 , + .valid.min_access_size =1 , + .valid.max_access_size =8 , + .endianness =DEVICE_NATIVE_ENDIAN , +}; + +static void unimp_realize (DeviceState *dev,Error **errp) +{ +UnimplementedDeviceState *s =UNIMPLEMENTED_DEVICE (dev); + +if (s->size ==0 ) { +error_setg (errp,"property 'size' not specified or zero" ); +return ; + } + +if (s->name ==NULL ) { +error_setg (errp,"property 'name' not specified" ); +return ; + } + +memory_region_init_io (&s->iomem,OBJECT (s), &unimp_ops, s, + s->name, s->size); +sysbus_init_mmio (SYS_BUS_DEVICE (s), &s->iomem); +} + +static Property unimp_properties[] = { +DEFINE_PROP_UINT64 ("size" , UnimplementedDeviceState, size,0 ), +DEFINE_PROP_STRING ("name" , UnimplementedDeviceState, name), +DEFINE_PROP_END_OF_LIST (), +}; + +static void unimp_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); + + dc->realize = unimp_realize; + dc->props = unimp_properties; +} + +static const TypeInfo unimp_info = { + .name =TYPE_UNIMPLEMENTED_DEVICE , + .parent =TYPE_SYS_BUS_DEVICE ,
hw/misc/unimp.c line 107
Quoted 10 lines
hw/misc/unimp.c new file +10
-0+ .instance_size = sizeof(UnimplementedDeviceState), + .class_init = unimp_class_init, +}; + +static void unimp_register_types (void ) +{ +type_register_static (&unimp_info); +} + +type_init (unimp_register_types)
--
Alex Bennée
Re: [Qemu-devel] [PATCH 2/3] hw/misc: New "unimplemented" sysbus device
Quoted 3 lines · Alex Bennée
Is there any millage at being able to define areas on the command line or would we expect every usage of this to be from a board file in the source?
Command line syntax is for life, not just for Christmas, so I'd rather we didn't add any until somebody comes up with a genuine use case for it.
thanks
-- PMM
PATCH 3/3 stellaris: Use the 'unimplemented' device for parts we don't implement
In reply to Peter MaydellUse the 'unimplemented' dummy device to cover regions of the SoC device memory map which we don't have proper device implementations for yet.
--- hw/arm/stellaris.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
hw/arm/stellaris.c +14 -0
@@ -21,6 +21,7 @@#include "exec/address-spaces.h" #include "sysemu/sysemu.h" #include "hw/char/pl011.h" +#include "hw/misc/unimp.h" #define GPIO_A 0#define GPIO_B 1
@@ -1401,6 +1402,19 @@ static void stellaris_init(const char *kernel_filename, const char *cpu_model, } } } + +/* Add dummy regions for the devices we don't implement yet, +* so guest accesses don't cause unlogged crashes. +*/ +create_unimplemented_device ("wdtimer" ,0x40000000 ,0x1000 ); +create_unimplemented_device ("i2c-0" ,0x40002000 ,0x1000 ); +create_unimplemented_device ("i2c-2" ,0x40021000 ,0x1000 ); +create_unimplemented_device ("PWM" ,0x40028000 ,0x1000 ); +create_unimplemented_device ("QEI-0" ,0x4002c000 ,0x1000 ); +create_unimplemented_device ("QEI-1" ,0x4002d000 ,0x1000 ); +create_unimplemented_device ("analogue-comparator" ,0x4003c000 ,0x1000 ); +create_unimplemented_device ("hibernation" ,0x400fc000 ,0x1000 ); +create_unimplemented_device ("flash-control" ,0x400fd000 ,0x1000 ); }/* FIXME: Figure out how to generate these from stellaris_boards. */
Signature · 1 line
2.7.4
Re: [Qemu-devel] [PATCH 3/3] stellaris: Use the 'unimplemented' device for parts we don't implement
Quoted 5 lines · Peter Maydell
Use the 'unimplemented' dummy device to cover regions of the SoC device memory map which we don't have proper device implementations for yet.
Signed-off-by Peter Maydell <[email protected]>
Looks good although I couldn't find any Stellaris images to test with so I take the actual behaviour on trust ;-)
Quoted 26 lines
--- hw/arm/stellaris.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)hw/arm/stellaris.c +7
-0@@ -21,6 +21,7 @@#include "exec/address-spaces.h" #include "sysemu/sysemu.h" #include "hw/char/pl011.h" +#include "hw/misc/unimp.h" #define GPIO_A 0#define GPIO_B 1@@ -1401,6 +1402,19 @@ static void stellaris_init(const char *kernel_filename, const char *cpu_model, } } } + +/* Add dummy regions for the devices we don't implement yet, +* so guest accesses don't cause unlogged crashes. +*/ +create_unimplemented_device ("wdtimer" ,0x40000000 ,0x1000 ); +create_unimplemented_device ("i2c-0" ,0x40002000 ,0x1000 );
hw/arm/stellaris.c static void stellaris_init(const char *kernel_filename, const char *cpu_model, · line 1420
Quoted 10 lines
hw/arm/stellaris.c +7
-0+create_unimplemented_device ("i2c-2" ,0x40021000 ,0x1000 ); +create_unimplemented_device ("PWM" ,0x40028000 ,0x1000 ); +create_unimplemented_device ("QEI-0" ,0x4002c000 ,0x1000 ); +create_unimplemented_device ("QEI-1" ,0x4002d000 ,0x1000 ); +create_unimplemented_device ("analogue-comparator" ,0x4003c000 ,0x1000 ); +create_unimplemented_device ("hibernation" ,0x400fc000 ,0x1000 ); +create_unimplemented_device ("flash-control" ,0x400fd000 ,0x1000 ); }/* FIXME: Figure out how to generate these from stellaris_boards. */
--
Alex Bennée