Skip to contentSkip to conversation

hw/arm/nrf51: Extend tracing

PATCH In review Philippe Mathieu-Daudé 3 participants 12 messages May 4, 2020 – May 11, 2020

lore
Share & tools
lore
#0 lore raw

cover hw/arm/nrf51: Extend tracing

Few patches while playing with the Zephyr Project.

- better display of unimplemented peripheral accesses,
- better display of timers use.

Philippe Mathieu-Daudé (4):
hw/arm/nrf51: Add NRF51_PERIPHERAL_SIZE definition hw/arm/nrf51_soc: Mark some peripherals as unimplemented hw/timer/nrf51_timer: Display timer ID in trace events hw/timer/nrf51_timer: Add trace event of counter value update

 include/hw/arm/nrf51.h         |  7 +++++--
 include/hw/i2c/microbit_i2c.h  |  2 +-
 include/hw/timer/nrf51_timer.h |  1 +
 hw/arm/nrf51_soc.c             | 20 ++++++++++++++++++--
 hw/i2c/microbit_i2c.c          |  2 +-
 hw/timer/nrf51_timer.c         | 14 +++++++++++---
 hw/timer/trace-events          |  5 +++--
 7 files changed, 40 insertions(+), 11 deletions(-)
Signature · 1 line
2.21.3
#1 lore raw

PATCH 1/4 hw/arm/nrf51: Add NRF51_PERIPHERAL_SIZE definition

On the NRF51 series, all peripherals have a fixed I/O size of 4KiB. Define NRF51_PERIPHERAL_SIZE and use it.

---
 include/hw/arm/nrf51.h        | 3 +--
 include/hw/i2c/microbit_i2c.h | 2 +-
 hw/arm/nrf51_soc.c            | 4 ++--
 hw/i2c/microbit_i2c.c         | 2 +-
 hw/timer/nrf51_timer.c        | 2 +-
 5 files changed, 6 insertions(+), 7 deletions(-)
include/hw/arm/nrf51.h +1 -2
index 1008fee6c9..de836beaa4 100644
@@ -24,11 +24,10 @@
 #define NRF51_IOMEM_BASE      0x40000000
 #define NRF51_IOMEM_SIZE      0x20000000
 
+#define NRF51_PERIPHERAL_SIZE 0x00001000
 #define NRF51_UART_BASE       0x40002000
 #define NRF51_TWI_BASE        0x40003000
-#define NRF51_TWI_SIZE        0x00001000
 #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
include/hw/i2c/microbit_i2c.h +1 -1
index aad636127e..2bff36680c 100644
@@ -29,7 +29,7 @@
 #define MICROBIT_I2C(obj) \
     OBJECT_CHECK(MicrobitI2CState, (obj), TYPE_MICROBIT_I2C)
 
-#define MICROBIT_I2C_NREGS (NRF51_TWI_SIZE / sizeof(uint32_t))
+#define MICROBIT_I2C_NREGS (NRF51_PERIPHERAL_SIZE / sizeof(uint32_t))
 
 typedef struct {
     SysBusDevice parent_obj;
hw/arm/nrf51_soc.c +2 -2
index 57eff63f0d..e50473fd19 100644
@@ -156,7 +156,7 @@ static void nrf51_soc_realize(DeviceState *dev_soc, Error **errp)
             return;
         }
 
-        base_addr = NRF51_TIMER_BASE + i * NRF51_TIMER_SIZE;
+        base_addr = NRF51_TIMER_BASE + i * NRF51_PERIPHERAL_SIZE;
 
         sysbus_mmio_map(SYS_BUS_DEVICE(&s->timer[i]), 0, base_addr);
         sysbus_connect_irq(SYS_BUS_DEVICE(&s->timer[i]), 0,
@@ -166,7 +166,7 @@ static void nrf51_soc_realize(DeviceState *dev_soc, Error **errp)
 
     /* STUB Peripherals */
     memory_region_init_io(&s->clock, OBJECT(dev_soc), &clock_ops, NULL,
-                          "nrf51_soc.clock", 0x1000);
+                          "nrf51_soc.clock", NRF51_PERIPHERAL_SIZE);
     memory_region_add_subregion_overlap(&s->container,
                                         NRF51_IOMEM_BASE, &s->clock, -1);
 
hw/i2c/microbit_i2c.c +1 -1
index 4661f05253..8024739820 100644
@@ -100,7 +100,7 @@ static void microbit_i2c_realize(DeviceState *dev, Error **errp)
     MicrobitI2CState *s = MICROBIT_I2C(dev);
 
     memory_region_init_io(&s->iomem, OBJECT(s), &microbit_i2c_ops, s,
-                          "microbit.twi", NRF51_TWI_SIZE);
+                          "microbit.twi", NRF51_PERIPHERAL_SIZE);
     sysbus_init_mmio(sbd, &s->iomem);
 }
 
hw/timer/nrf51_timer.c +1 -1
index e04046eb15..bc82c85a6f 100644
@@ -313,7 +313,7 @@ static void nrf51_timer_init(Object *obj)
     SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
 
     memory_region_init_io(&s->iomem, obj, &rng_ops, s,
-            TYPE_NRF51_TIMER, NRF51_TIMER_SIZE);
+                          TYPE_NRF51_TIMER, NRF51_PERIPHERAL_SIZE);
     sysbus_init_mmio(sbd, &s->iomem);
     sysbus_init_irq(sbd, &s->irq);
 
Signature · 1 line
2.21.3
Reviewed-by on v1 1/4
#2 lore raw

Re: [PATCH 1/4] hw/arm/nrf51: Add NRF51_PERIPHERAL_SIZE definition

Quoted 11 lines · Philippe Mathieu-Daudé

On the NRF51 series, all peripherals have a fixed I/O size of 4KiB. Define NRF51_PERIPHERAL_SIZE and use it.

---
 include/hw/arm/nrf51.h        | 3 +--
 include/hw/i2c/microbit_i2c.h | 2 +-
 hw/arm/nrf51_soc.c            | 4 ++--
 hw/i2c/microbit_i2c.c         | 2 +-
 hw/timer/nrf51_timer.c        | 2 +-
 5 files changed, 6 insertions(+), 7 deletions(-)

r~

#3 lore raw

PATCH 2/4 hw/arm/nrf51_soc: Mark some peripherals as unimplemented

In reply to Philippe Mathieu-Daudé

Map some peripherals used by Zephyr Project:

https://github.com/zephyrproject-rtos/zephyr/blob/zephyr-v2.2.0/dts/arm/nordic/nrf51822.dtsi

---
 include/hw/arm/nrf51.h |  4 ++++
 hw/arm/nrf51_soc.c     | 11 +++++++++++
 2 files changed, 15 insertions(+)
include/hw/arm/nrf51.h +4 -0
index de836beaa4..46d0cfc7a1 100644
@@ -25,11 +25,15 @@
 #define NRF51_IOMEM_SIZE      0x20000000
 
 #define NRF51_PERIPHERAL_SIZE 0x00001000
+#define NRF51_RADIO_BASE      0x40001000
 #define NRF51_UART_BASE       0x40002000
 #define NRF51_TWI_BASE        0x40003000
+#define NRF51_GPIOTE_BASE     0x40006000
 #define NRF51_TIMER_BASE      0x40008000
+#define NRF51_TEMP_BASE       0x4000c000
 #define NRF51_RNG_BASE        0x4000D000
 #define NRF51_NVMC_BASE       0x4001E000
+#define NRF51_PPI_BASE        0x4001f000
 #define NRF51_GPIO_BASE       0x50000000
 
 #define NRF51_PRIVATE_BASE    0xF0000000
hw/arm/nrf51_soc.c +11 -0
index e50473fd19..6212c5cb53 100644
@@ -170,6 +170,17 @@ static void nrf51_soc_realize(DeviceState *dev_soc, Error **errp)
     memory_region_add_subregion_overlap(&s->container,
                                         NRF51_IOMEM_BASE, &s->clock, -1);
 
+    create_unimplemented_device("nrf51_soc.radio", NRF51_RADIO_BASE,
+                                NRF51_PERIPHERAL_SIZE);
+    create_unimplemented_device("nrf51_soc.uarte", NRF51_UART_BASE,
+                                NRF51_PERIPHERAL_SIZE);
+    create_unimplemented_device("nrf51_soc.gpiote", NRF51_GPIOTE_BASE,
+                                NRF51_PERIPHERAL_SIZE);
+    create_unimplemented_device("nrf51_soc.temp", NRF51_TEMP_BASE,
+                                NRF51_PERIPHERAL_SIZE);
+    create_unimplemented_device("nrf51_soc.ppi", NRF51_PPI_BASE,
+                                NRF51_PERIPHERAL_SIZE);
+
     create_unimplemented_device("nrf51_soc.io", NRF51_IOMEM_BASE,
                                 NRF51_IOMEM_SIZE);
     create_unimplemented_device("nrf51_soc.private",
Signature · 1 line
2.21.3
#4 lore raw

Re: [PATCH 2/4] hw/arm/nrf51_soc: Mark some peripherals as unimplemented

Quoted 9 lines · Philippe Mathieu-Daudé

Map some peripherals used by Zephyr Project:

https://github.com/zephyrproject-rtos/zephyr/blob/zephyr-v2.2.0/dts/arm/nordic/nrf51822.dtsi

---
 include/hw/arm/nrf51.h |  4 ++++
 hw/arm/nrf51_soc.c     | 11 +++++++++++
 2 files changed, 15 insertions(+)

There's a fair few more devices listed in the manual, and not all of the ones that you add here are referenced in the dts files. So what criteria are you using to choose?

Perhaps it would be easier to add them all?

r~

#5 lore raw

Re: [PATCH 2/4] hw/arm/nrf51_soc: Mark some peripherals as unimplemented

+Ioannis

Quoted 11 lines · Richard Henderson
Quoted 9 lines · Philippe Mathieu-Daudé

Map some peripherals used by Zephyr Project:

https://github.com/zephyrproject-rtos/zephyr/blob/zephyr-v2.2.0/dts/arm/nordic/nrf51822.dtsi

---
  include/hw/arm/nrf51.h |  4 ++++
  hw/arm/nrf51_soc.c     | 11 +++++++++++
  2 files changed, 15 insertions(+)
Quoted 3 lines

There's a fair few more devices listed in the manual, and not all of the ones that you add here are referenced in the dts files. So what criteria are you using to choose?

Fair question :)

The board DTS [1] ends pulling in nrf51822.dtsi.

To be able to use the soft PWM declared in [2] and implemented in [3] (with timers and gpios), I added this commit on top:

https://gitlab.com/philmd/zephyr/-/commit/90b081cf79

But I won't send a pullrequest to Zephyr until the PPI is properly implemented in QEMU.

[1] https://github.com/zephyrproject-rtos/zephyr/blob/zephyr-v2.2.0/boards/arm/qemu_cortex_m0/qemu_cortex_m0.dts
[2] https://github.com/zephyrproject-rtos/zephyr/blob/zephyr-v2.2.0/dts/arm/nordic/nrf5_common.dtsi
[3] https://github.com/zephyrproject-rtos/zephyr/blob/zephyr-v2.2.0/drivers/pwm/pwm_nrf5_sw.c

Quoted 2 lines

Perhaps it would be easier to add them all?

Or better document this commit ;)

Quoted 6 lines

r~

#6 lore raw

PATCH 3/4 hw/timer/nrf51_timer: Display timer ID in trace events

In reply to Philippe Mathieu-Daudé

The NRF51 series SoC have 3 timer peripherals, each having 4 counters. To help differentiate which peripheral is accessed, display the timer ID in the trace events.

---
 include/hw/timer/nrf51_timer.h |  1 +
 hw/arm/nrf51_soc.c             |  5 +++++
 hw/timer/nrf51_timer.c         | 11 +++++++++--
 hw/timer/trace-events          |  4 ++--
 4 files changed, 17 insertions(+), 4 deletions(-)
include/hw/timer/nrf51_timer.h +1 -0
index 85cad2300d..eb6815f21d 100644
@@ -59,6 +59,7 @@ typedef struct NRF51TimerState {
     MemoryRegion iomem;
     qemu_irq irq;
 
+    uint8_t id;
     QEMUTimer timer;
     int64_t timer_start_ns;
     int64_t update_counter_ns;
hw/arm/nrf51_soc.c +5 -0
index 6212c5cb53..44b2624e8e 100644
@@ -150,6 +150,11 @@ static void nrf51_soc_realize(DeviceState *dev_soc, Error **errp)
 
     /* TIMER */
     for (i = 0; i < NRF51_NUM_TIMERS; i++) {
+        object_property_set_uint(OBJECT(&s->timer[i]), i, "id", &err);
+        if (err) {
+            error_propagate(errp, err);
+            return;
+        }
         object_property_set_bool(OBJECT(&s->timer[i]), true, "realized", &err);
         if (err) {
             error_propagate(errp, err);
hw/timer/nrf51_timer.c +9 -2
index bc82c85a6f..38cea0542e 100644
@@ -17,6 +17,7 @@
 #include "hw/arm/nrf51.h"
 #include "hw/irq.h"
 #include "hw/timer/nrf51_timer.h"
+#include "hw/qdev-properties.h"
 #include "migration/vmstate.h"
 #include "trace.h"
 
@@ -185,7 +186,7 @@ static uint64_t nrf51_timer_read(void *opaque, hwaddr offset, unsigned int size)
                       __func__, offset);
     }
 
-    trace_nrf51_timer_read(offset, r, size);
+    trace_nrf51_timer_read(s->id, offset, r, size);
 
     return r;
 }
@@ -197,7 +198,7 @@ static void nrf51_timer_write(void *opaque, hwaddr offset,
     uint64_t now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
     size_t idx;
 
-    trace_nrf51_timer_write(offset, value, size);
+    trace_nrf51_timer_write(s->id, offset, value, size);
 
     switch (offset) {
     case NRF51_TIMER_TASK_START:
@@ -372,12 +373,18 @@ static const VMStateDescription vmstate_nrf51_timer = {
     }
 };
 
+static Property nrf51_timer_properties[] = {
+    DEFINE_PROP_UINT8("id", NRF51TimerState, id, 0),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
 static void nrf51_timer_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
 
     dc->reset = nrf51_timer_reset;
     dc->vmsd = &vmstate_nrf51_timer;
+    device_class_set_props(dc, nrf51_timer_properties);
 }
 
 static const TypeInfo nrf51_timer_info = {
hw/timer/trace-events +2 -2
index 29fda7870e..43b605cc75 100644
@@ -67,8 +67,8 @@ cmsdk_apb_dualtimer_write(uint64_t offset, uint64_t data, unsigned size) "CMSDK
 cmsdk_apb_dualtimer_reset(void) "CMSDK APB dualtimer: reset"
 
 # 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"
+nrf51_timer_read(uint8_t timer_id, uint64_t addr, uint32_t value, unsigned size) "timer %u read addr 0x%" PRIx64 " data 0x%" PRIx32 " size %u"
+nrf51_timer_write(uint8_t timer_id, uint64_t addr, uint32_t value, unsigned size) "timer %u write addr 0x%" PRIx64 " data 0x%" PRIx32 " size %u"
 
 # bcm2835_systmr.c
 bcm2835_systmr_irq(bool enable) "timer irq state %u"
Signature · 1 line
2.21.3
Reviewed-by on v1 3/4
#7 lore raw

Re: [PATCH 3/4] hw/timer/nrf51_timer: Display timer ID in trace events

Quoted 11 lines · Philippe Mathieu-Daudé

The NRF51 series SoC have 3 timer peripherals, each having 4 counters. To help differentiate which peripheral is accessed, display the timer ID in the trace events.

---
 include/hw/timer/nrf51_timer.h |  1 +
 hw/arm/nrf51_soc.c             |  5 +++++
 hw/timer/nrf51_timer.c         | 11 +++++++++--
 hw/timer/trace-events          |  4 ++--
 4 files changed, 17 insertions(+), 4 deletions(-)

r~

#8 lore raw

PATCH 4/4 hw/timer/nrf51_timer: Add trace event of counter value update

In reply to Philippe Mathieu-Daudé

Add trace event to display timer's counter value updates.

---
 hw/timer/nrf51_timer.c | 1 +
 hw/timer/trace-events  | 1 +
 2 files changed, 2 insertions(+)
hw/timer/nrf51_timer.c +1 -0
index 38cea0542e..42be79c736 100644
@@ -240,6 +240,7 @@ static void nrf51_timer_write(void *opaque, hwaddr offset,
 
             idx = (offset - NRF51_TIMER_TASK_CAPTURE_0) / 4;
             s->cc[idx] = s->counter;
+            trace_nrf51_timer_set_count(s->id, idx, s->counter);
         }
         break;
     case NRF51_TIMER_EVENT_COMPARE_0 ... NRF51_TIMER_EVENT_COMPARE_3:
hw/timer/trace-events +1 -0
index 43b605cc75..80ea197594 100644
@@ -69,6 +69,7 @@ cmsdk_apb_dualtimer_reset(void) "CMSDK APB dualtimer: reset"
 # nrf51_timer.c
 nrf51_timer_read(uint8_t timer_id, uint64_t addr, uint32_t value, unsigned size) "timer %u read addr 0x%" PRIx64 " data 0x%" PRIx32 " size %u"
 nrf51_timer_write(uint8_t timer_id, uint64_t addr, uint32_t value, unsigned size) "timer %u write addr 0x%" PRIx64 " data 0x%" PRIx32 " size %u"
+nrf51_timer_set_count(uint8_t timer_id, uint8_t counter_id, uint32_t value) "timer %u counter %u count 0x%" PRIx32
 
 # bcm2835_systmr.c
 bcm2835_systmr_irq(bool enable) "timer irq state %u"
Signature · 1 line
2.21.3
#10 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 11 lines · Philippe Mathieu-Daudé

Few patches while playing with the Zephyr Project.

- better display of unimplemented peripheral accesses,
- better display of timers use.

Philippe Mathieu-Daudé (4):
hw/arm/nrf51: Add NRF51_PERIPHERAL_SIZE definition hw/arm/nrf51_soc: Mark some peripherals as unimplemented hw/timer/nrf51_timer: Display timer ID in trace events hw/timer/nrf51_timer: Add trace event of counter value update

Hi; I've put patches 1, 3 and 4 into target-arm.next as they have been reviewed and are independent of the unimp-peripherals patch.

thanks
-- PMM

#11 lore raw
Quoted 13 lines · Peter Maydell
Quoted 11 lines · Philippe Mathieu-Daudé

Few patches while playing with the Zephyr Project.

- better display of unimplemented peripheral accesses,
- better display of timers use.

Philippe Mathieu-Daudé (4):
hw/arm/nrf51: Add NRF51_PERIPHERAL_SIZE definition hw/arm/nrf51_soc: Mark some peripherals as unimplemented hw/timer/nrf51_timer: Display timer ID in trace events hw/timer/nrf51_timer: Add trace event of counter value update

Quoted 3 lines

Hi; I've put patches 1, 3 and 4 into target-arm.next as they have been reviewed and are independent of the unimp-peripherals patch.

Appreciated! I plan to respin the unimp-peripherals patch with better description once I've the PPI peripheral working.

Quoted 4 lines

thanks
-- PMM