arm: Core nRF51 Devices and Microbit Support
cover arm: Core nRF51 Devices and Microbit Support
Steffen has been busy so I picked up "[PATCH v5 00/14] arm: nRF51 Devices and Microbit Support". This series includes the core devices needed to boot basic guest software on the "microbit" board.
This series includes Steffen's random number generator, GPIO, timer, and a stubbed clock. Also, this series adds the tests/microbit-test.c qtest.
Changes from Steffen's series:
* Made timer tickless [Peter]
* Dropped non-volatile memory controller. More work is needed there and I don't want to hold back other devices in this series that are ready for merge.
* Rebased and re-tested with make check and real micro:bit programs (requires out-of-tree -kernel and stub TWI device patches)
Steffen Görtz (11):
qtest: Add set_irq_in command to set IRQ/GPIO level
arm: Add header to host common definition for nRF51 SOC peripherals hw/misc/nrf51_rng: Add NRF51 random number generator peripheral
arm: Instantiate NRF51 random number generator hw/gpio/nrf51_gpio: Add nRF51 GPIO peripheral
arm: Instantiate NRF51 general purpose I/O tests/microbit-test: Add Tests for nRF51 GPIO hw/timer/nrf51_timer: Add nRF51 Timer peripheral
arm: Instantiate NRF51 Timers
tests/microbit-test: Add Tests for nRF51 Timer
arm: Add Clock peripheral stub to NRF51 SOC
Makefile.objs | 1 + hw/gpio/Makefile.objs | 1 + hw/misc/Makefile.objs | 1 + hw/timer/Makefile.objs | 1 + tests/Makefile.include | 2 + include/hw/arm/nrf51.h | 45 ++++ include/hw/arm/nrf51_soc.h | 9 + include/hw/char/nrf51_uart.h | 1 - include/hw/gpio/nrf51_gpio.h | 69 ++++++ include/hw/misc/nrf51_rng.h | 83 +++++++ include/hw/timer/nrf51_timer.h | 80 +++++++ tests/libqtest.h | 13 ++ hw/arm/nrf51_soc.c | 117 ++++++++-- hw/gpio/nrf51_gpio.c | 300 +++++++++++++++++++++++++ hw/misc/nrf51_rng.c | 262 ++++++++++++++++++++++ hw/timer/nrf51_timer.c | 393 +++++++++++++++++++++++++++++++++ qtest.c | 43 ++++ tests/libqtest.c | 10 + tests/microbit-test.c | 255 +++++++++++++++++++++ hw/gpio/trace-events | 7 + hw/timer/trace-events | 5 + 21 files changed, 1676 insertions(+), 22 deletions(-) create mode 100644 include/hw/arm/nrf51.h create mode 100644 include/hw/gpio/nrf51_gpio.h create mode 100644 include/hw/misc/nrf51_rng.h create mode 100644 include/hw/timer/nrf51_timer.h create mode 100644 hw/gpio/nrf51_gpio.c create mode 100644 hw/misc/nrf51_rng.c create mode 100644 hw/timer/nrf51_timer.c create mode 100644 tests/microbit-test.c create mode 100644 hw/gpio/trace-events
Signature · 1 line
2.19.2
PATCH 1/11 qtest: Add set_irq_in command to set IRQ/GPIO level
From: Steffen Görtz <[email protected]>
Adds a new qtest command "set_irq_in" which allows to set qemu gpio lines to a given level.
Based on https://lists.gnu.org/archive/html/qemu-devel/2012-12/msg02363.html
which never got merged.
--- tests/libqtest.h | 13 +++++++++++++ qtest.c | 43 +++++++++++++++++++++++++++++++++++++++++++ tests/libqtest.c | 10 ++++++++++ 3 files changed, 66 insertions(+)
tests/libqtest.h +13 -0
@@ -230,6 +230,19 @@ void qtest_irq_intercept_in(QTestState *s, const char *string);*/ void qtest_irq_intercept_out (QTestState *s,const char *string); +/** +* qtest_set_irq_in: +* @s: QTestState instance to operate on. +* @string: QOM path of a device +* @name: IRQ name +* @irq: IRQ number +* @level: IRQ level +* +* Force given device/irq GPIO-in pin to the given level. +*/ +void qtest_set_irq_in (QTestState *s,const char *string,const char *name, +int irq,int level); +/** * qtest_outb: * @s: #QTestState instance to operate on.
qtest.c +43 -0
56 lines not on this page · raw message
tests/libqtest.c +10 -0
@@ -753,6 +753,16 @@ void qtest_irq_intercept_in(QTestState *s, const char *qom_path)qtest_rsp (s,0 ); } +void qtest_set_irq_in (QTestState *s,const char *qom_path,const char *name, +int num,int level) +{ +if (!name) { + name ="unnamed-gpio-in" ; + } +qtest_sendf (s,"set_irq_in %s %s %d %d\n" , qom_path, name, num, level); +qtest_rsp (s,0 ); +} +static void qtest_out (QTestState *s,const char *cmd,uint16_t addr,uint32_t value) {qtest_sendf (s,"%s 0x%x 0x%x\n" , cmd, addr, value);
Signature · 1 line
2.19.2
PATCH 2/11 arm: Add header to host common definition for nRF51 SOC peripherals
In reply to Stefan HajnocziFrom: Steffen Görtz <[email protected]>
Adds a header that provides definitions that are used across nRF51 peripherals
--- include/hw/arm/nrf51.h | 45 ++++++++++++++++++++++++++++++++++++ include/hw/char/nrf51_uart.h | 1 - hw/arm/nrf51_soc.c | 33 ++++++++++---------------- 3 files changed, 57 insertions(+), 22 deletions(-) create mode 100644 include/hw/arm/nrf51.h
include/hw/arm/nrf51.h new file +45 -0
@@ -0,0 +1,45 @@ +/* +* Nordic Semiconductor nRF51 Series SOC Common Defines +* +* This file hosts generic defines used in various nRF51 peripheral devices. +* +* Reference Manual: http://infocenter.nordicsemi.com/pdf/nRF51_RM_v3.0.pdf +* Product Spec: http://infocenter.nordicsemi.com/pdf/nRF51822_PS_v3.1.pdf +* +* Copyright 2018 Steffen Görtz <[email protected]> +* +* This code is licensed under the GPL version 2 or later. See +* the COPYING file in the top-level directory. +*/ + +#ifndef NRF51_H +#define NRF51_H + +#define NRF51_FLASH_BASE 0x00000000 +#define NRF51_FICR_BASE 0x10000000 +#define NRF51_FICR_SIZE 0x00000100 +#define NRF51_UICR_BASE 0x10001000 +#define NRF51_SRAM_BASE 0x20000000 + +#define NRF51_IOMEM_BASE 0x40000000 +#define NRF51_IOMEM_SIZE 0x20000000 + +#define NRF51_UART_BASE 0x40002000 +#define NRF51_TIMER_BASE 0x40008000 +#define NRF51_TIMER_SIZE 0x00001000 +#define NRF51_RNG_BASE 0x4000D000 +#define NRF51_NVMC_BASE 0x4001E000 +#define NRF51_GPIO_BASE 0x50000000 + +#define NRF51_PRIVATE_BASE 0xF0000000 +#define NRF51_PRIVATE_SIZE 0x10000000 + +#define NRF51_PAGE_SIZE 1024 + +/* Trigger */ +#define NRF51_TRIGGER_TASK 0x01 + +/* Events */ +#define NRF51_EVENT_CLEAR 0x00 + +#endif
include/hw/char/nrf51_uart.h +0 -1
@@ -16,7 +16,6 @@#include "hw/registerfields.h" #define UART_FIFO_LENGTH 6 -#define UART_BASE 0x40002000#define UART_SIZE 0x1000#define TYPE_NRF51_UART "nrf51_soc.uart"
hw/arm/nrf51_soc.c +12 -21
@@ -21,27 +21,16 @@#include "qemu/log.h" #include "cpu.h" +#include "hw/arm/nrf51.h" #include "hw/arm/nrf51_soc.h" -#define IOMEM_BASE 0x40000000 -#define IOMEM_SIZE 0x20000000 - -#define FICR_BASE 0x10000000 -#define FICR_SIZE 0x000000fc - -#define FLASH_BASE 0x00000000 -#define SRAM_BASE 0x20000000 - -#define PRIVATE_BASE 0xF0000000 -#define PRIVATE_SIZE 0x10000000 -/* * The size and base is for the NRF51822 part. If other parts * are supported in the future, add a sub-class of NRF51SoC for * the specific variants */ -#define NRF51822_FLASH_SIZE (256 * 1024) -#define NRF51822_SRAM_SIZE (16 * 1024) +#define NRF51822_FLASH_SIZE (256 * NRF51_PAGE_SIZE) +#define NRF51822_SRAM_SIZE (16 * NRF51_PAGE_SIZE)#define BASE_TO_IRQ (base) ((base >> 12) & 0x1F)
@@ -76,14 +65,14 @@ static void nrf51_soc_realize(DeviceState *dev_soc, Error **errp)error_propagate (errp, err);return ; } -memory_region_add_subregion (&s->container,FLASH_BASE , &s->flash); +memory_region_add_subregion (&s->container,NRF51_FLASH_BASE , &s->flash);memory_region_init_ram (&s->sram,NULL ,"nrf51.sram" , s->sram_size, &err);if (err) {error_propagate (errp, err);return ; } -memory_region_add_subregion (&s->container,SRAM_BASE , &s->sram); +memory_region_add_subregion (&s->container,NRF51_SRAM_BASE , &s->sram);/* UART */ object_property_set_bool (OBJECT (&s->uart), true,"realized" , &err);
@@ -92,15 +81,17 @@ static void nrf51_soc_realize(DeviceState *dev_soc, Error **errp)return ; } mr =sysbus_mmio_get_region (SYS_BUS_DEVICE (&s->uart),0 ); -memory_region_add_subregion_overlap (&s->container,UART_BASE , mr,0 ); +memory_region_add_subregion_overlap (&s->container,NRF51_UART_BASE , mr,0 );sysbus_connect_irq (SYS_BUS_DEVICE (&s->uart),0 ,qdev_get_gpio_in (DEVICE (&s->cpu), -BASE_TO_IRQ (UART_BASE ))); +BASE_TO_IRQ (NRF51_UART_BASE ))); -create_unimplemented_device ("nrf51_soc.io" ,IOMEM_BASE ,IOMEM_SIZE ); -create_unimplemented_device ("nrf51_soc.ficr" ,FICR_BASE ,FICR_SIZE ); +create_unimplemented_device ("nrf51_soc.io" ,NRF51_IOMEM_BASE , +NRF51_IOMEM_SIZE ); +create_unimplemented_device ("nrf51_soc.ficr" ,NRF51_FICR_BASE , +NRF51_FICR_SIZE );create_unimplemented_device ("nrf51_soc.private" , -PRIVATE_BASE ,PRIVATE_SIZE ); +NRF51_PRIVATE_BASE ,NRF51_PRIVATE_SIZE ); }static void nrf51_soc_init (Object *obj)
Signature · 1 line
2.19.2
Re: [Qemu-arm] [Qemu-devel] [PATCH 02/11] arm: Add header to host common definition for nRF51 SOC peripherals
Quoted 49 lines · Stefan Hajnoczi
From: Steffen Görtz <[email protected]>
Adds a header that provides definitions that are used across nRF51 peripherals
Signed-off-by Steffen Görtz <[email protected]>Reviewed-by Stefan Hajnoczi <[email protected]>Reviewed-by Peter Maydell <[email protected]>Signed-off-by Stefan Hajnoczi <[email protected]>--- include/hw/arm/nrf51.h | 45 ++++++++++++++++++++++++++++++++++++ include/hw/char/nrf51_uart.h | 1 - hw/arm/nrf51_soc.c | 33 ++++++++++---------------- 3 files changed, 57 insertions(+), 22 deletions(-) create mode 100644 include/hw/arm/nrf51.hinclude/hw/arm/nrf51.h new file +27
-0@@ -0,0 +1,45 @@ +/* +* Nordic Semiconductor nRF51 Series SOC Common Defines +* +* This file hosts generic defines used in various nRF51 peripheral devices. +* +* Reference Manual: http://infocenter.nordicsemi.com/pdf/nRF51_RM_v3.0.pdf +* Product Spec: http://infocenter.nordicsemi.com/pdf/nRF51822_PS_v3.1.pdf +* +* Copyright 2018 Steffen Görtz <[email protected]> +* +* This code is licensed under the GPL version 2 or later. See +* the COPYING file in the top-level directory. +*/ + +#ifndef NRF51_H +#define NRF51_H + +#define NRF51_FLASH_BASE 0x00000000 +#define NRF51_FICR_BASE 0x10000000 +#define NRF51_FICR_SIZE 0x00000100 +#define NRF51_UICR_BASE 0x10001000 +#define NRF51_SRAM_BASE 0x20000000 + +#define NRF51_IOMEM_BASE 0x40000000 +#define NRF51_IOMEM_SIZE 0x20000000 + +#define NRF51_UART_BASE 0x40002000
include/hw/arm/nrf51.h line 37
Quoted 10 lines
include/hw/arm/nrf51.h new file +10
-0+#define NRF51_TIMER_BASE 0x40008000 +#define NRF51_TIMER_SIZE 0x00001000 +#define NRF51_RNG_BASE 0x4000D000 +#define NRF51_NVMC_BASE 0x4001E000 +#define NRF51_GPIO_BASE 0x50000000 + +#define NRF51_PRIVATE_BASE 0xF0000000 +#define NRF51_PRIVATE_SIZE 0x10000000 + +#define NRF51_PAGE_SIZE 1024
I'd keep this file in hw/arm (not include/...).
include/hw/arm/nrf51.h line 43
Quoted 6 lines
include/hw/arm/nrf51.h new file +6
-0+ +/* Trigger */ +#define NRF51_TRIGGER_TASK 0x01 + +/* Events */ +#define NRF51_EVENT_CLEAR 0x00
These definitions might be the only one used out of hw/arm/.
Quoted 90 lines
include/hw/arm/nrf51.h new file +2
-0+ +#endif include/hw/char/nrf51_uart.h +0
-1@@ -16,7 +16,6 @@#include "hw/registerfields.h" #define UART_FIFO_LENGTH 6 -#define UART_BASE 0x40002000#define UART_SIZE 0x1000#define TYPE_NRF51_UART "nrf51_soc.uart"hw/arm/nrf51_soc.c +12
-21@@ -21,27 +21,16 @@#include "qemu/log.h" #include "cpu.h" +#include "hw/arm/nrf51.h" #include "hw/arm/nrf51_soc.h" -#define IOMEM_BASE 0x40000000 -#define IOMEM_SIZE 0x20000000 - -#define FICR_BASE 0x10000000 -#define FICR_SIZE 0x000000fc - -#define FLASH_BASE 0x00000000 -#define SRAM_BASE 0x20000000 - -#define PRIVATE_BASE 0xF0000000 -#define PRIVATE_SIZE 0x10000000 -/* * The size and base is for the NRF51822 part. If other parts * are supported in the future, add a sub-class of NRF51SoC for * the specific variants */ -#define NRF51822_FLASH_SIZE (256 * 1024) -#define NRF51822_SRAM_SIZE (16 * 1024) +#define NRF51822_FLASH_SIZE (256 * NRF51_PAGE_SIZE) +#define NRF51822_SRAM_SIZE (16 * NRF51_PAGE_SIZE)#define BASE_TO_IRQ (base) ((base >> 12) & 0x1F)@@ -76,14 +65,14 @@ static void nrf51_soc_realize(DeviceState *dev_soc, Error **errp)error_propagate (errp, err);return ; } -memory_region_add_subregion (&s->container,FLASH_BASE , &s->flash); +memory_region_add_subregion (&s->container,NRF51_FLASH_BASE , &s->flash);memory_region_init_ram (&s->sram,NULL ,"nrf51.sram" , s->sram_size, &err);if (err) {error_propagate (errp, err);return ; } -memory_region_add_subregion (&s->container,SRAM_BASE , &s->sram); +memory_region_add_subregion (&s->container,NRF51_SRAM_BASE , &s->sram);/* UART */ object_property_set_bool (OBJECT (&s->uart), true,"realized" , &err);@@ -92,15 +81,17 @@ static void nrf51_soc_realize(DeviceState *dev_soc, Error **errp)return ; } mr =sysbus_mmio_get_region (SYS_BUS_DEVICE (&s->uart),0 ); -memory_region_add_subregion_overlap (&s->container,UART_BASE , mr,0 ); +memory_region_add_subregion_overlap (&s->container,NRF51_UART_BASE , mr,0 );sysbus_connect_irq (SYS_BUS_DEVICE (&s->uart),0 ,qdev_get_gpio_in (DEVICE (&s->cpu), -BASE_TO_IRQ (UART_BASE ))); +BASE_TO_IRQ (NRF51_UART_BASE ))); -create_unimplemented_device ("nrf51_soc.io" ,IOMEM_BASE ,IOMEM_SIZE ); -create_unimplemented_device ("nrf51_soc.ficr" ,FICR_BASE ,FICR_SIZE ); +create_unimplemented_device ("nrf51_soc.io" ,NRF51_IOMEM_BASE , +NRF51_IOMEM_SIZE ); +create_unimplemented_device ("nrf51_soc.ficr" ,NRF51_FICR_BASE , +NRF51_FICR_SIZE );create_unimplemented_device ("nrf51_soc.private" , -PRIVATE_BASE ,PRIVATE_SIZE ); +NRF51_PRIVATE_BASE ,NRF51_PRIVATE_SIZE ); }static void nrf51_soc_init (Object *obj)
Re: [Qemu-arm] [Qemu-devel] [PATCH 02/11] arm: Add header to host common definition for nRF51 SOC peripherals
Quoted 54 lines · Philippe Mathieu-Daudé
Quoted 53 lines · Stefan Hajnoczi
From: Steffen Görtz <[email protected]>
Adds a header that provides definitions that are used across nRF51 peripherals
Signed-off-by Steffen Görtz <[email protected]>Reviewed-by Stefan Hajnoczi <[email protected]>Reviewed-by Peter Maydell <[email protected]>Signed-off-by Stefan Hajnoczi <[email protected]>--- include/hw/arm/nrf51.h | 45 ++++++++++++++++++++++++++++++++++++ include/hw/char/nrf51_uart.h | 1 - hw/arm/nrf51_soc.c | 33 ++++++++++---------------- 3 files changed, 57 insertions(+), 22 deletions(-) create mode 100644 include/hw/arm/nrf51.hinclude/hw/arm/nrf51.h new file +31
-0@@ -0,0 +1,45 @@ +/* +* Nordic Semiconductor nRF51 Series SOC Common Defines +* +* This file hosts generic defines used in various nRF51 peripheral devices. +* +* Reference Manual: http://infocenter.nordicsemi.com/pdf/nRF51_RM_v3.0.pdf +* Product Spec: http://infocenter.nordicsemi.com/pdf/nRF51822_PS_v3.1.pdf +* +* Copyright 2018 Steffen Görtz <[email protected]> +* +* This code is licensed under the GPL version 2 or later. See +* the COPYING file in the top-level directory. +*/ + +#ifndef NRF51_H +#define NRF51_H + +#define NRF51_FLASH_BASE 0x00000000 +#define NRF51_FICR_BASE 0x10000000 +#define NRF51_FICR_SIZE 0x00000100 +#define NRF51_UICR_BASE 0x10001000 +#define NRF51_SRAM_BASE 0x20000000 + +#define NRF51_IOMEM_BASE 0x40000000 +#define NRF51_IOMEM_SIZE 0x20000000 + +#define NRF51_UART_BASE 0x40002000 +#define NRF51_TIMER_BASE 0x40008000 +#define NRF51_TIMER_SIZE 0x00001000 +#define NRF51_RNG_BASE 0x4000D000 +#define NRF51_NVMC_BASE 0x4001E000
Quoted 8 lines
include/hw/arm/nrf51.h line 37
Quoted 6 lines
include/hw/arm/nrf51.h new file +6
-0+#define NRF51_GPIO_BASE 0x50000000 + +#define NRF51_PRIVATE_BASE 0xF0000000 +#define NRF51_PRIVATE_SIZE 0x10000000 + +#define NRF51_PAGE_SIZE 1024I'd keep this file in hw/arm (not
include/...).
This header file avoids duplicating definitions in tests/microbit-test.c.
How would you structure it differently?
Stefan
PATCH 3/11 hw/misc/nrf51_rng: Add NRF51 random number generator peripheral
In reply to Stefan HajnocziFrom: Steffen Görtz <[email protected]>
Add a model of the NRF51 random number generator peripheral. This is a simple random generator that continuously generates new random values after startup.
Reference Manual: http://infocenter.nordicsemi.com/pdf/nRF51_RM_v3.0.pdf
--- hw/misc/Makefile.objs | 1 + include/hw/misc/nrf51_rng.h | 83 ++++++++++++ hw/misc/nrf51_rng.c | 262 ++++++++++++++++++++++++++++++++++++ 3 files changed, 346 insertions(+) create mode 100644 include/hw/misc/nrf51_rng.h create mode 100644 hw/misc/nrf51_rng.c
hw/misc/Makefile.objs +1 -0
@@ -74,3 +74,4 @@ obj-$(CONFIG_PVPANIC) += pvpanic.o obj-$(CONFIG_AUX) += auxbus.o obj-$(CONFIG_ASPEED_SOC) += aspeed_scu.o aspeed_sdmc.o obj-$(CONFIG_MSF2) += msf2-sysreg.o +obj-$(CONFIG_NRF51_SOC) += nrf51_rng.o
include/hw/misc/nrf51_rng.h new file +83 -0
83 lines not on this page · raw message
hw/misc/nrf51_rng.c new file +262 -0
262 lines not on this page · raw message
Signature · 1 line
2.19.2
PATCH 4/11 arm: Instantiate NRF51 random number generator
In reply to Stefan HajnocziFrom: Steffen Görtz <[email protected]>
Use RNG in SOC.
--- include/hw/arm/nrf51_soc.h | 2 ++ hw/arm/nrf51_soc.c | 16 ++++++++++++++++ 2 files changed, 18 insertions(+)
include/hw/arm/nrf51_soc.h +2 -0
@@ -13,6 +13,7 @@#include "hw/sysbus.h" #include "hw/arm/armv7m.h" #include "hw/char/nrf51_uart.h" +#include "hw/misc/nrf51_rng.h" #define TYPE_NRF51_SOC "nrf51-soc"#define NRF51_SOC (obj) \
@@ -26,6 +27,7 @@ typedef struct NRF51State {ARMv7MState cpu;NRF51UARTState uart; +NRF51RNGState rng;MemoryRegion iomem;MemoryRegion sram;
hw/arm/nrf51_soc.c +16 -0
@@ -86,6 +86,19 @@ static void nrf51_soc_realize(DeviceState *dev_soc, Error **errp)qdev_get_gpio_in (DEVICE (&s->cpu), BASE_TO_IRQ(NRF51_UART_BASE))); +/* RNG */ +object_property_set_bool (OBJECT (&s->rng), true,"realized" , &err); +if (err) { +error_propagate (errp, err); +return ; + } + + mr =sysbus_mmio_get_region (SYS_BUS_DEVICE (&s->rng),0 ); +memory_region_add_subregion_overlap (&s->container,NRF51_RNG_BASE , mr,0 ); +sysbus_connect_irq (SYS_BUS_DEVICE (&s->rng),0 , +qdev_get_gpio_in (DEVICE (&s->cpu), +BASE_TO_IRQ (NRF51_RNG_BASE ))); +create_unimplemented_device ("nrf51_soc.io" ,NRF51_IOMEM_BASE ,NRF51_IOMEM_SIZE ); create_unimplemented_device("nrf51_soc.ficr", NRF51_FICR_BASE,
@@ -110,6 +123,9 @@ static void nrf51_soc_init(Object *obj) TYPE_NRF51_UART);object_property_add_alias (obj,"serial0" ,OBJECT (&s->uart),"chardev" , &error_abort); + +sysbus_init_child_obj (obj,"rng" , &s->rng,sizeof (s->rng), +TYPE_NRF51_RNG ); }static Property nrf51_soc_properties[] = {
Signature · 1 line
2.19.2
PATCH 5/11 hw/gpio/nrf51_gpio: Add nRF51 GPIO peripheral
In reply to Stefan HajnocziFrom: Steffen Görtz <[email protected]>
This adds a model of the nRF51 GPIO peripheral.
Reference Manual: http://infocenter.nordicsemi.com/pdf/nRF51_RM_v3.0.pdf
The nRF51 series microcontrollers support up to 32 GPIO pins in various configurations. The pins can be used as input pins with pull-ups or pull-down. Furthermore, three different output driver modes per level are
available (disconnected, standard, high-current).
The GPIO-Peripheral has a mechanism for detecting level changes which is not featured in this model.
--- Makefile.objs | 1 + hw/gpio/Makefile.objs | 1 + include/hw/gpio/nrf51_gpio.h | 69 ++++++++ hw/gpio/nrf51_gpio.c | 300 +++++++++++++++++++++++++++++++++++ hw/gpio/trace-events | 7 + 5 files changed, 378 insertions(+) create mode 100644 include/hw/gpio/nrf51_gpio.h create mode 100644 hw/gpio/nrf51_gpio.c create mode 100644 hw/gpio/trace-events
Makefile.objs +1 -0
@@ -184,6 +184,7 @@ trace-events-subdirs += hw/vfio trace-events-subdirs += hw/virtio trace-events-subdirs += hw/watchdog trace-events-subdirs += hw/xen +trace-events-subdirs += hw/gpio trace-events-subdirs += io trace-events-subdirs += linux-user trace-events-subdirs += migration
hw/gpio/Makefile.objs +1 -0
@@ -8,3 +8,4 @@ common-obj-$(CONFIG_GPIO_KEY) += gpio_key.o obj-$(CONFIG_OMAP) += omap_gpio.o obj-$(CONFIG_IMX) += imx_gpio.o obj-$(CONFIG_RASPI) += bcm2835_gpio.o +obj-$(CONFIG_NRF51_SOC) += nrf51_gpio.o
include/hw/gpio/nrf51_gpio.h new file +69 -0
69 lines not on this page · raw message
hw/gpio/nrf51_gpio.c new file +300 -0
300 lines not on this page · raw message
hw/gpio/trace-events new file +7 -0
@@ -0,0 +1,7 @@ +# See docs/devel/tracing.txt for syntax documentation. + +# hw/gpio/nrf51_gpio.c +nrf51_gpio_read(uint64_t offset, uint64_t r) "offset 0x%" PRIx64 " value 0x%" PRIx64 +nrf51_gpio_write(uint64_t offset, uint64_t value) "offset 0x%" PRIx64 " value 0x%" PRIx64 +nrf51_gpio_set(int64_t line, int64_t value) "line %" PRIi64 " value %" PRIi64 +nrf51_gpio_update_output_irq(int64_t line, int64_t value) "line %" PRIi64 " value %" PRIi64
Signature · 1 line
2.19.2
PATCH 6/11 arm: Instantiate NRF51 general purpose I/O
In reply to Stefan HajnocziFrom: Steffen Görtz <[email protected]>
Instantiates GPIO peripheral model
--- include/hw/arm/nrf51_soc.h | 2 ++ hw/arm/nrf51_soc.c | 16 ++++++++++++++++ 2 files changed, 18 insertions(+)
include/hw/arm/nrf51_soc.h +2 -0
@@ -14,6 +14,7 @@#include "hw/arm/armv7m.h" #include "hw/char/nrf51_uart.h" #include "hw/misc/nrf51_rng.h" +#include "hw/gpio/nrf51_gpio.h" #define TYPE_NRF51_SOC "nrf51-soc"#define NRF51_SOC (obj) \
@@ -28,6 +29,7 @@ typedef struct NRF51State {NRF51UARTState uart;NRF51RNGState rng; +NRF51GPIOState gpio;MemoryRegion iomem;MemoryRegion sram;
hw/arm/nrf51_soc.c +16 -0
@@ -99,6 +99,19 @@ static void nrf51_soc_realize(DeviceState *dev_soc, Error **errp)qdev_get_gpio_in (DEVICE (&s->cpu), BASE_TO_IRQ(NRF51_RNG_BASE))); +/* GPIO */ +object_property_set_bool (OBJECT (&s->gpio), true,"realized" , &err); +if (err) { +error_propagate (errp, err); +return ; + } + + mr =sysbus_mmio_get_region (SYS_BUS_DEVICE (&s->gpio),0 ); +memory_region_add_subregion_overlap (&s->container,NRF51_GPIO_BASE , mr,0 ); + +/* Pass all GPIOs to the SOC layer so they are available to the board */ +qdev_pass_gpios (DEVICE (&s->gpio), dev_soc,NULL ); +create_unimplemented_device ("nrf51_soc.io" ,NRF51_IOMEM_BASE ,NRF51_IOMEM_SIZE ); create_unimplemented_device("nrf51_soc.ficr", NRF51_FICR_BASE,
@@ -126,6 +139,9 @@ static void nrf51_soc_init(Object *obj)sysbus_init_child_obj (obj,"rng" , &s->rng,sizeof (s->rng),TYPE_NRF51_RNG ); + +sysbus_init_child_obj (obj,"gpio" , &s->gpio,sizeof (s->gpio), +TYPE_NRF51_GPIO ); }static Property nrf51_soc_properties[] = {
Signature · 1 line
2.19.2
PATCH 7/11 tests/microbit-test: Add Tests for nRF51 GPIO
In reply to Stefan HajnocziFrom: Steffen Görtz <[email protected]>
The test suite for the nRF51 GPIO peripheral for now only tests initial state. Additionally a set of tests testing an implementation detail of the model are included.
--- tests/Makefile.include | 2 + tests/microbit-test.c | 160 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 162 insertions(+) create mode 100644 tests/microbit-test.c
tests/Makefile.include +2 -0
@@ -277,6 +277,7 @@ check-qtest-sparc64-y += tests/boot-serial-test$(EXESUF) check-qtest-arm-y += tests/tmp105-test$(EXESUF) check-qtest-arm-y += tests/pca9552-test$(EXESUF) check-qtest-arm-y += tests/ds1338-test$(EXESUF) +check-qtest-arm-y += tests/microbit-test$(EXESUF) check-qtest-arm-y += tests/m25p80-test$(EXESUF) check-qtest-arm-y += tests/virtio-blk-test$(EXESUF) check-qtest-arm-y += tests/test-arm-mptimer$(EXESUF)
@@ -708,6 +709,7 @@ tests/pxe-test$(EXESUF): tests/pxe-test.o tests/boot-sector.o $(libqos-obj-y) tests/tmp105-test$(EXESUF): tests/tmp105-test.o $(libqos-omap-obj-y) tests/pca9552-test$(EXESUF): tests/pca9552-test.o $(libqos-omap-obj-y) tests/ds1338-test$(EXESUF): tests/ds1338-test.o $(libqos-imx-obj-y) +tests/microbit-test$(EXESUF): tests/microbit-test.o tests/m25p80-test$(EXESUF): tests/m25p80-test.o tests/i440fx-test$(EXESUF): tests/i440fx-test.o $(libqos-pc-obj-y) tests/q35-test$(EXESUF): tests/q35-test.o $(libqos-pc-obj-y)
tests/microbit-test.c new file +160 -0
160 lines not on this page · raw message
Signature · 1 line
2.19.2
PATCH 8/11 hw/timer/nrf51_timer: Add nRF51 Timer peripheral
In reply to Stefan HajnocziFrom: Steffen Görtz <[email protected]>
This patch adds the model for the nRF51 timer peripheral. Currently, only the TIMER mode is implemented.
--- hw/timer/Makefile.objs | 1 + include/hw/timer/nrf51_timer.h | 80 +++++++ hw/timer/nrf51_timer.c | 393 +++++++++++++++++++++++++++++++++ hw/timer/trace-events | 5 + 4 files changed, 479 insertions(+) create mode 100644 include/hw/timer/nrf51_timer.h create mode 100644 hw/timer/nrf51_timer.c
hw/timer/Makefile.objs +1 -0
@@ -23,6 +23,7 @@ common-obj-$(CONFIG_IMX) += imx_gpt.o common-obj-$(CONFIG_LM32) += lm32_timer.o common-obj-$(CONFIG_MILKYMIST) += milkymist-sysctl.o common-obj-$(CONFIG_XLNX_ZYNQMP) += xlnx-zynqmp-rtc.o +common-obj-$(CONFIG_NRF51_SOC) += nrf51_timer.o obj-$(CONFIG_ALTERA_TIMER) += altera_timer.o obj-$(CONFIG_EXYNOS4) += exynos4210_mct.o
include/hw/timer/nrf51_timer.h new file +80 -0
80 lines not on this page · raw message
hw/timer/nrf51_timer.c new file +393 -0
393 lines not on this page · raw message
hw/timer/trace-events +5 -0
@@ -72,3 +72,8 @@ sun4v_rtc_write(uint64_t addr, uint64_t value) "write: addr 0x%" PRIx64 " value # hw/timer/xlnx-zynqmp-rtc.c xlnx_zynqmp_rtc_gettime(int year, int month, int day, int hour, int min, int sec) "Get time from host: %d-%d-%d %2d:%02d:%02d" + +# hw/timer/nrf51_timer.c +nrf51_timer_read(uint64_t addr, uint32_t value, unsigned size) "read addr 0x%" PRIx64 " data 0x%" PRIx32 " size %u" +nrf51_timer_write(uint64_t addr, uint32_t value, unsigned size) "write addr 0x%" PRIx64 " data 0x%" PRIx32 " size %u" +
Signature · 1 line
2.19.2
PATCH 9/11 arm: Instantiate NRF51 Timers
In reply to Stefan HajnocziFrom: Steffen Görtz <[email protected]>
Instantiates TIMER0 - TIMER2
--- include/hw/arm/nrf51_soc.h | 4 ++++ hw/arm/nrf51_soc.c | 26 ++++++++++++++++++++++++++ 2 files changed, 30 insertions(+)
include/hw/arm/nrf51_soc.h +4 -0
@@ -15,11 +15,14 @@#include "hw/char/nrf51_uart.h" #include "hw/misc/nrf51_rng.h" #include "hw/gpio/nrf51_gpio.h" +#include "hw/timer/nrf51_timer.h" #define TYPE_NRF51_SOC "nrf51-soc"#define NRF51_SOC (obj) \ OBJECT_CHECK(NRF51State, (obj), TYPE_NRF51_SOC) +#define NRF51_NUM_TIMERS 3 + typedef struct NRF51State { /*< private >*/ SysBusDevice parent_obj;
@@ -30,6 +33,7 @@ typedef struct NRF51State {NRF51UARTState uart;NRF51RNGState rng;NRF51GPIOState gpio; +NRF51TimerState timer[NRF51_NUM_TIMERS ];MemoryRegion iomem;MemoryRegion sram;
hw/arm/nrf51_soc.c +26 -0
@@ -39,6 +39,8 @@ static void nrf51_soc_realize(DeviceState *dev_soc, Error **errp)NRF51State *s =NRF51_SOC (dev_soc);MemoryRegion *mr;Error *err =NULL ; +uint8_t i =0 ; +hwaddr base_addr =0 ;if (!s->board_memory) {error_setg (errp,"memory property was not set" );
@@ -112,6 +114,22 @@ static void nrf51_soc_realize(DeviceState *dev_soc, Error **errp)/* Pass all GPIOs to the SOC layer so they are available to the board */ qdev_pass_gpios (DEVICE (&s->gpio), dev_soc,NULL ); +/* TIMER */ +for (i =0 ; i <NRF51_NUM_TIMERS ; i++) { +object_property_set_bool (OBJECT (&s->timer[i]), true,"realized" , &err); +if (err) { +error_propagate (errp, err); +return ; + } + + base_addr =NRF51_TIMER_BASE + i *NRF51_TIMER_SIZE ; + +sysbus_mmio_map (SYS_BUS_DEVICE (&s->timer[i]),0 , base_addr); +sysbus_connect_irq (SYS_BUS_DEVICE (&s->timer[i]),0 , +qdev_get_gpio_in (DEVICE (&s->cpu), +BASE_TO_IRQ (base_addr))); + } +create_unimplemented_device ("nrf51_soc.io" ,NRF51_IOMEM_BASE ,NRF51_IOMEM_SIZE ); create_unimplemented_device("nrf51_soc.ficr", NRF51_FICR_BASE,
@@ -122,6 +140,8 @@ static void nrf51_soc_realize(DeviceState *dev_soc, Error **errp)static void nrf51_soc_init (Object *obj) { +uint8_t i =0 ; +NRF51State *s =NRF51_SOC (obj);memory_region_init (&s->container, obj,"nrf51-container" ,UINT64_MAX );
@@ -142,6 +162,12 @@ static void nrf51_soc_init(Object *obj)sysbus_init_child_obj (obj,"gpio" , &s->gpio,sizeof (s->gpio),TYPE_NRF51_GPIO ); + +for (i =0 ; i <NRF51_NUM_TIMERS ; i++) { +sysbus_init_child_obj (obj,"timer[*]" , &s->timer[i], +sizeof (s->timer[i]),TYPE_NRF51_TIMER ); + + } }static Property nrf51_soc_properties[] = {
Signature · 1 line
2.19.2
PATCH 10/11 tests/microbit-test: Add Tests for nRF51 Timer
In reply to Stefan HajnocziFrom: Steffen Görtz <[email protected]>
Basic tests for nRF51 Timer Peripheral.
--- tests/microbit-test.c | 95 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+)
tests/microbit-test.c +95 -0
@@ -20,6 +20,7 @@#include "hw/arm/nrf51.h" #include "hw/gpio/nrf51_gpio.h" +#include "hw/timer/nrf51_timer.h" static void test_nrf51_gpio (void ) {
@@ -143,6 +144,99 @@ static void test_nrf51_gpio(void)qtest_set_irq_in (global_qtest,"/machine/nrf51" ,"unnamed-gpio-in" ,0 ,0 ); } +static void timer_task (hwaddr task) +{ +writel (NRF51_TIMER_BASE + task,NRF51_TRIGGER_TASK ); +} + +static void timer_clear_event (hwaddr event) +{ +writel (NRF51_TIMER_BASE + event,NRF51_EVENT_CLEAR ); +} + +static void timer_set_bitmode (uint8_t mode) +{ +writel (NRF51_TIMER_BASE +NRF51_TIMER_REG_BITMODE , mode); +} + +static void timer_set_prescaler (uint8_t prescaler) +{ +writel (NRF51_TIMER_BASE +NRF51_TIMER_REG_PRESCALER , prescaler); +} + +static void timer_set_cc (size_t idx,uint32_t value) +{ +writel (NRF51_TIMER_BASE +NRF51_TIMER_REG_CC0 + idx *4 , value); +} + +static void timer_assert_events (uint32_t ev0,uint32_t ev1,uint32_t ev2, +uint32_t ev3) +{ +g_assert (readl (NRF51_TIMER_BASE +NRF51_TIMER_EVENT_COMPARE_0 ) == ev0); +g_assert (readl (NRF51_TIMER_BASE +NRF51_TIMER_EVENT_COMPARE_1 ) == ev1); +g_assert (readl (NRF51_TIMER_BASE +NRF51_TIMER_EVENT_COMPARE_2 ) == ev2); +g_assert (readl (NRF51_TIMER_BASE +NRF51_TIMER_EVENT_COMPARE_3 ) == ev3); +} + +static void test_nrf51_timer (void ) +{ +uint32_t steps_to_overflow =408 ; + +/* Compare Match */ +timer_task (NRF51_TIMER_TASK_STOP ); +timer_task (NRF51_TIMER_TASK_CLEAR ); + +timer_clear_event (NRF51_TIMER_EVENT_COMPARE_0 ); +timer_clear_event (NRF51_TIMER_EVENT_COMPARE_1 ); +timer_clear_event (NRF51_TIMER_EVENT_COMPARE_2 ); +timer_clear_event (NRF51_TIMER_EVENT_COMPARE_3 ); + +timer_set_bitmode (NRF51_TIMER_WIDTH_16 );/* 16 MHz Timer */ +timer_set_prescaler (0 ); +/* Swept over in first step */ +timer_set_cc (0 ,2 ); +/* Barely miss on first step */ +timer_set_cc (1 ,162 ); +/* Spot on on third step */ +timer_set_cc (2 ,480 ); + +timer_assert_events (0 ,0 ,0 ,0 ); + +timer_task (NRF51_TIMER_TASK_START ); +clock_step (10000 ); +timer_assert_events (1 ,0 ,0 ,0 ); + +/* Swept over on first overflow */ +timer_set_cc (3 ,114 ); + +clock_step (10000 ); +timer_assert_events (1 ,1 ,0 ,0 ); + +clock_step (10000 ); +timer_assert_events (1 ,1 ,1 ,0 ); + +/* Wrap time until internal counter overflows */ +while (steps_to_overflow--) { +timer_assert_events (1 ,1 ,1 ,0 ); +clock_step (10000 ); + } + +timer_assert_events (1 ,1 ,1 ,1 ); + +timer_clear_event (NRF51_TIMER_EVENT_COMPARE_0 ); +timer_clear_event (NRF51_TIMER_EVENT_COMPARE_1 ); +timer_clear_event (NRF51_TIMER_EVENT_COMPARE_2 ); +timer_clear_event (NRF51_TIMER_EVENT_COMPARE_3 ); +timer_assert_events (0 ,0 ,0 ,0 ); + +timer_task (NRF51_TIMER_TASK_STOP ); + +/* Test Proposal: Stop/Shutdown */ +/* Test Proposal: Shortcut Compare -> Clear */ +/* Test Proposal: Shortcut Compare -> Stop */ +/* Test Proposal: Counter Mode */ +} +int main (int argc,char **argv) {int ret;
@@ -152,6 +246,7 @@ int main(int argc, char **argv) global_qtest =qtest_initf ("-machine microbit" );qtest_add_func ("/microbit/nrf51/gpio" , test_nrf51_gpio); +qtest_add_func ("/microbit/nrf51/timer" , test_nrf51_timer); ret =g_test_run ();
Signature · 1 line
2.19.2
PATCH 11/11 arm: Add Clock peripheral stub to NRF51 SOC
In reply to Stefan HajnocziFrom: Steffen Görtz <[email protected]>
This stubs enables the microbit-micropython firmware to run on the microbit machine.
--- include/hw/arm/nrf51_soc.h | 1 + hw/arm/nrf51_soc.c | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+)
include/hw/arm/nrf51_soc.h +1 -0
@@ -38,6 +38,7 @@ typedef struct NRF51State {MemoryRegion iomem;MemoryRegion sram;MemoryRegion flash; +MemoryRegion clock;uint32_t sram_size;uint32_t flash_size;
hw/arm/nrf51_soc.c +26 -0
@@ -34,6 +34,26 @@#define BASE_TO_IRQ (base) ((base >> 12) & 0x1F) +static uint64_t clock_read (void *opaque,hwaddr addr,unsigned int size) +{ +qemu_log_mask (LOG_UNIMP ,"%s: 0x%" HWADDR_PRIx" [%u]\n" , + __func__, addr, size); +return 1 ; +} + +static void clock_write (void *opaque,hwaddr addr,uint64_t data, +unsigned int size) +{ +qemu_log_mask (LOG_UNIMP ,"%s: 0x%" HWADDR_PRIx" <- 0x%" PRIx64" [%u]\n" , + __func__, addr, data, size); +} + +static const MemoryRegionOps clock_ops = { + .read = clock_read, + .write = clock_write +}; + +static void nrf51_soc_realize (DeviceState *dev_soc,Error **errp) {NRF51State *s =NRF51_SOC (dev_soc);
@@ -130,6 +150,12 @@ static void nrf51_soc_realize(DeviceState *dev_soc, Error **errp) BASE_TO_IRQ(base_addr))); } +/* STUB Peripherals */ +memory_region_init_io (&s->clock,NULL , &clock_ops,NULL , +"nrf51_soc.clock" ,0x1000 ); +memory_region_add_subregion_overlap (&s->container, +NRF51_IOMEM_BASE , &s->clock,-1 ); +create_unimplemented_device ("nrf51_soc.io" ,NRF51_IOMEM_BASE ,NRF51_IOMEM_SIZE ); create_unimplemented_device("nrf51_soc.ficr", NRF51_FICR_BASE,
Signature · 1 line
2.19.2
Peter Maydell
AppliedQuoted 8 lines · Stefan Hajnoczi
Steffen has been busy so I picked up "[PATCH v5 00/14] arm: nRF51 Devices and Microbit Support". This series includes the core devices needed to boot basic guest software on the "microbit" board.
This series includes Steffen's random number generator, GPIO, timer, and a stubbed clock. Also, this series adds the
tests/microbit-test.cqtest.
Quoted 7 lines
Changes from Steffen's series:
* Made timer tickless [Peter]
* Dropped non-volatile memory controller. More work is needed there and I don't want to hold back other devices in this series that are ready for merge.
* Rebased and re-tested with make check and real micro:bit programs (requires out-of-tree -kernel and stub TWI device patches)
Applied to target-arm.next, thanks.
-- PMM