Skip to contentSkip to conversation

hw/arm/stellaris: Fix overwritten IRQs and cleanups

PATCH In review Philippe Mathieu-Daudé 2 participants 22 messages Jan 10, 2025 – Jan 27, 2025

lore
Share & tools
lore
#0 lore raw

cover hw/arm/stellaris: Fix overwritten IRQs and cleanups

- Remove invalid unimplemented I2C#0
- Add DEVCAP() macro to check DeviceCapability registers
- Check DEVCAP() before creating devices
- Use 4 inputs for ADC, wire each timer output properly
- Improve documentation

Philippe Mathieu-Daudé (9):
hw/arm/stellaris: Link each board schematic hw/arm/stellaris: Constify read-only arrays hw/arm/stellaris: Remove incorrect unimplemented i2c-0 at 0x40002000 hw/arm/stellaris: Replace magic numbers by definitions hw/arm/stellaris: Use DEVCAP macro to access DeviceCapability
registers
hw/arm/stellaris: Map both I2C controllers hw/arm/stellaris: Only create MPU when available hw/arm/stellaris: Only map existing devices as unimplemented hw/arm/stellaris: Wire GPTM[#n] output to ADC input #n

 hw/arm/stellaris.c | 146 +++++++++++++++++++++++++++++++--------------
 1 file changed, 102 insertions(+), 44 deletions(-)
Signature · 1 line
2.47.1
#1 lore raw

PATCH 1/9 hw/arm/stellaris: Link each board schematic

Board schematic is useful to corroborate GPIOs/IRQs wiring.

---
 hw/arm/stellaris.c | 8 ++++++++
 1 file changed, 8 insertions(+)
hw/arm/stellaris.c +8 -0
index 1bba96df14e..9b414ff9069 100644
@@ -1379,6 +1379,10 @@ static void lm3s6965evb_init(MachineState *machine)
     stellaris_init(machine, &stellaris_boards[1]);
 }
 
+/*
+ * Stellaris LM3S811 Evaluation Board Schematics:
+ * http://www.ti.com/lit/ug/symlink/spmu030.pdf
+ */
 static void lm3s811evb_class_init(ObjectClass *oc, void *data)
 {
     MachineClass *mc = MACHINE_CLASS(oc);
@@ -1395,6 +1399,10 @@ static const TypeInfo lm3s811evb_type = {
     .class_init = lm3s811evb_class_init,
 };
 
+/*
+ * Stellaris: LM3S6965 Evaluation Board Schematics:
+ * http://www.ti.com/lit/ug/symlink/spmu029.pdf
+ */
 static void lm3s6965evb_class_init(ObjectClass *oc, void *data)
 {
     MachineClass *mc = MACHINE_CLASS(oc);
Signature · 1 line
2.47.1
Reviewed-by on v1 1/9
#2 lore raw

Re: [PATCH 1/9] hw/arm/stellaris: Link each board schematic

Quoted 24 lines · Philippe Mathieu-Daudé

Board schematic is useful to corroborate GPIOs/IRQs wiring.

---
 hw/arm/stellaris.c | 8 ++++++++
 1 file changed, 8 insertions(+)
hw/arm/stellaris.c +4 -0
index 1bba96df14e..9b414ff9069 100644
@@ -1379,6 +1379,10 @@ static void lm3s6965evb_init(MachineState *machine)
     stellaris_init(machine, &stellaris_boards[1]);
 }
 
+/*
+ * Stellaris LM3S811 Evaluation Board Schematics:
+ * http://www.ti.com/lit/ug/symlink/spmu030.pdf
+ */
 static void lm3s811evb_class_init(ObjectClass *oc, void *data)
 {
     MachineClass *mc = MACHINE_CLASS(oc);

hw/arm/stellaris.c static const TypeInfo lm3s811evb_type = { · line 1405

Quoted 7 lines
hw/arm/stellaris.c +4 -0
@@ -1395,6 +1399,10 @@ static const TypeInfo lm3s811evb_type = {
     .class_init = lm3s811evb_class_init,
 };
 
+/*
+ * Stellaris: LM3S6965 Evaluation Board Schematics:
+ * http://www.ti.com/lit/ug/symlink/spmu029.pdf
+ */

I think we should prefer https:// (I checked, and both work); otherwise

thanks
-- PMM

#3 lore raw

PATCH 2/9 hw/arm/stellaris: Constify read-only arrays

In reply to Philippe Mathieu-Daudé
---
 hw/arm/stellaris.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
hw/arm/stellaris.c +3 -3
index 9b414ff9069..7c9e7e6c15b 100644
@@ -101,7 +101,7 @@ static void ssys_update(ssys_state *s)
   qemu_set_irq(s->irq, (s->int_status & s->int_mask) != 0);
 }
 
-static uint32_t pllcfg_sandstorm[16] = {
+static const uint32_t pllcfg_sandstorm[16] = {
     0x31c0, /* 1 Mhz */
     0x1ae0, /* 1.8432 Mhz */
     0x18c0, /* 2 Mhz */
@@ -120,7 +120,7 @@ static uint32_t pllcfg_sandstorm[16] = {
     0x585b /* 8.192 Mhz */
 };
 
-static uint32_t pllcfg_fury[16] = {
+static const uint32_t pllcfg_fury[16] = {
     0x3200, /* 1 Mhz */
     0x1b20, /* 1.8432 Mhz */
     0x1900, /* 2 Mhz */
@@ -964,7 +964,7 @@ static void stellaris_adc_init(Object *obj)
 }
 
 /* Board init.  */
-static stellaris_board_info stellaris_boards[] = {
+static const stellaris_board_info stellaris_boards[] = {
   { "LM3S811EVB",
     0,
     0x0032000e,
Signature · 1 line
2.47.1
#5 lore raw

PATCH 3/9 hw/arm/stellaris: Remove incorrect unimplemented i2c-0 at 0x40002000

In reply to Philippe Mathieu-Daudé

There is nothing mapped at 0x40002000.

I2C#0 is already mapped at 0x40021000.

Remove the invalid mapping added in commits aecfbbc97a2 & 394c8bbfb7a.

---
 hw/arm/stellaris.c | 2 --
 1 file changed, 2 deletions(-)
hw/arm/stellaris.c +0 -2
index 7c9e7e6c15b..254f7a234bf 100644
@@ -1001,7 +1001,6 @@ static void stellaris_init(MachineState *ms, stellaris_board_info *board)
      * http://www.ti.com/lit/ds/symlink/lm3s6965.pdf
      *
      * 40000000 wdtimer
-     * 40002000 i2c (unimplemented)
      * 40004000 GPIO
      * 40005000 GPIO
      * 40006000 GPIO
@@ -1356,7 +1355,6 @@ static void stellaris_init(MachineState *ms, stellaris_board_info *board)
     /* Add dummy regions for the devices we don't implement yet,
      * so guest accesses don't cause unlogged crashes.
      */
-    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);
Signature · 1 line
2.47.1
Reviewed-by on v1 3/9
#6 lore raw

Re: [PATCH 3/9] hw/arm/stellaris: Remove incorrect unimplemented i2c-0 at 0x40002000

Quoted 6 lines · Philippe Mathieu-Daudé

There is nothing mapped at 0x40002000.

I2C#0 is already mapped at 0x40021000.

Remove the invalid mapping added in commits aecfbbc97a2 & 394c8bbfb7a.

I wonder why I thought there was something at 0x40002000 ? The data sheet per the URL in commit 394c8bbfb7 certainly doesn't list anything there. Maybe I misread 0x40020000 at some point...

thanks
-- PMM

#7 lore raw

PATCH 4/9 hw/arm/stellaris: Replace magic numbers by definitions

In reply to Philippe Mathieu-Daudé

Add definitions for the number of controllers.

---
 hw/arm/stellaris.c | 25 +++++++++++++++----------
 1 file changed, 15 insertions(+), 10 deletions(-)
hw/arm/stellaris.c +15 -10
index 254f7a234bf..b4c3412c490 100644
@@ -49,6 +49,11 @@
 #define NUM_IRQ_LINES 64
 #define NUM_PRIO_BITS 3
 
+#define NUM_GPIO    7
+#define NUM_UART    4
+#define NUM_GPTM    4
+#define NUM_I2C     2
+
 typedef const struct {
     const char *name;
     uint32_t did0;
@@ -989,12 +994,12 @@ static const stellaris_board_info stellaris_boards[] = {
 
 static void stellaris_init(MachineState *ms, stellaris_board_info *board)
 {
-    static const int uart_irq[] = {5, 6, 33, 34};
-    static const int timer_irq[] = {19, 21, 23, 35};
-    static const uint32_t gpio_addr[7] =
+    static const int uart_irq[NUM_UART] = {5, 6, 33, 34};
+    static const int timer_irq[NUM_GPTM] = {19, 21, 23, 35};
+    static const uint32_t gpio_addr[NUM_GPIO] =
       { 0x40004000, 0x40005000, 0x40006000, 0x40007000,
         0x40024000, 0x40025000, 0x40026000};
-    static const int gpio_irq[7] = {0, 1, 2, 3, 4, 30, 31};
+    static const int gpio_irq[NUM_GPIO] = {0, 1, 2, 3, 4, 30, 31};
 
     /* Memory map of SoC devices, from
      * Stellaris LM3S6965 Microcontroller Data Sheet (rev I)
@@ -1030,9 +1035,9 @@ static void stellaris_init(MachineState *ms, stellaris_board_info *board)
      */
 
     Object *soc_container;
-    DeviceState *gpio_dev[7], *nvic;
-    qemu_irq gpio_in[7][8];
-    qemu_irq gpio_out[7][8];
+    DeviceState *gpio_dev[NUM_GPIO], *nvic;
+    qemu_irq gpio_in[NUM_GPIO][8];
+    qemu_irq gpio_out[NUM_GPIO][8];
     qemu_irq adc;
     int sram_size;
     int flash_size;
@@ -1123,7 +1128,7 @@ static void stellaris_init(MachineState *ms, stellaris_board_info *board)
     } else {
         adc = NULL;
     }
-    for (i = 0; i < 4; i++) {
+    for (i = 0; i < NUM_GPTM; i++) {
         if (board->dc2 & (0x10000 << i)) {
             SysBusDevice *sbd;
 
@@ -1157,7 +1162,7 @@ static void stellaris_init(MachineState *ms, stellaris_board_info *board)
     }
 
 
-    for (i = 0; i < 7; i++) {
+    for (i = 0; i < NUM_GPIO; i++) {
         if (board->dc4 & (1 << i)) {
             gpio_dev[i] = sysbus_create_simple("pl061_luminary", gpio_addr[i],
                                                qdev_get_gpio_in(nvic,
@@ -1178,7 +1183,7 @@ static void stellaris_init(MachineState *ms, stellaris_board_info *board)
         }
     }
 
-    for (i = 0; i < 4; i++) {
+    for (i = 0; i < NUM_UART; i++) {
         if (board->dc2 & (1 << i)) {
             SysBusDevice *sbd;
 
Signature · 1 line
2.47.1
#9 lore raw

PATCH 5/9 hw/arm/stellaris: Use DEVCAP macro to access DeviceCapability registers

In reply to Philippe Mathieu-Daudé

Add definitions (DCx_periph) for the DeviceCapability bits, replace direct bitmask checks with the DEV_CAP() macro, which use the extract/deposit API.

---
 hw/arm/stellaris.c | 37 +++++++++++++++++++++++++++++--------
 1 file changed, 29 insertions(+), 8 deletions(-)
hw/arm/stellaris.c +29 -8
index b4c3412c490..64e6797553a 100644
@@ -8,6 +8,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/bitops.h"
 #include "qapi/error.h"
 #include "hw/core/split-irq.h"
 #include "hw/sysbus.h"
@@ -54,6 +55,26 @@
 #define NUM_GPTM    4
 #define NUM_I2C     2
 
+/*
+ * See Stellaris Data Sheet chapter 5.2.5 "System Control",
+ * Register 13 .. 17: Device Capabilities 0 .. 4 (DC0 .. DC4).
+ */
+#define DC1_WDT          3
+#define DC1_HIB          6
+#define DC1_MPU          7
+#define DC1_ADC          16
+#define DC1_PWM          20
+#define DC2_UART(n)     (n)
+#define DC2_SSI          4
+#define DC2_QEI(n)      (8 + n)
+#define DC2_I2C(n)      (12 + 2 * n)
+#define DC2_GPTM(n)     (16 + n)
+#define DC2_COMP(n)     (24 + n)
+#define DC4_GPIO(n)     (n)
+#define DC4_EMAC         28
+
+#define DEV_CAP(_dc, _cap) extract32(board->dc##_dc, DC##_dc##_##_cap, 1)
+
 typedef const struct {
     const char *name;
     uint32_t did0;
@@ -1117,7 +1138,7 @@ static void stellaris_init(MachineState *ms, stellaris_board_info *board)
     sysbus_mmio_map(SYS_BUS_DEVICE(ssys_dev), 0, 0x400fe000);
     sysbus_connect_irq(SYS_BUS_DEVICE(ssys_dev), 0, qdev_get_gpio_in(nvic, 28));
 
-    if (board->dc1 & (1 << 16)) {
+    if (DEV_CAP(1, ADC)) {
         dev = sysbus_create_varargs(TYPE_STELLARIS_ADC, 0x40038000,
                                     qdev_get_gpio_in(nvic, 14),
                                     qdev_get_gpio_in(nvic, 15),
@@ -1129,7 +1150,7 @@ static void stellaris_init(MachineState *ms, stellaris_board_info *board)
         adc = NULL;
     }
     for (i = 0; i < NUM_GPTM; i++) {
-        if (board->dc2 & (0x10000 << i)) {
+        if (DEV_CAP(2, GPTM(i))) {
             SysBusDevice *sbd;
 
             dev = qdev_new(TYPE_STELLARIS_GPTM);
@@ -1146,7 +1167,7 @@ static void stellaris_init(MachineState *ms, stellaris_board_info *board)
         }
     }
 
-    if (board->dc1 & (1 << 3)) { /* watchdog present */
+    if (DEV_CAP(1, WDT)) {
         dev = qdev_new(TYPE_LUMINARY_WATCHDOG);
         object_property_add_child(soc_container, "wdg", OBJECT(dev));
         qdev_connect_clock_in(dev, "WDOGCLK",
@@ -1163,7 +1184,7 @@ static void stellaris_init(MachineState *ms, stellaris_board_info *board)
 
 
     for (i = 0; i < NUM_GPIO; i++) {
-        if (board->dc4 & (1 << i)) {
+        if (DEV_CAP(4, GPIO(i))) {
             gpio_dev[i] = sysbus_create_simple("pl061_luminary", gpio_addr[i],
                                                qdev_get_gpio_in(nvic,
                                                                 gpio_irq[i]));
@@ -1174,7 +1195,7 @@ static void stellaris_init(MachineState *ms, stellaris_board_info *board)
         }
     }
 
-    if (board->dc2 & (1 << 12)) {
+    if (DEV_CAP(2, I2C(0))) {
         dev = sysbus_create_simple(TYPE_STELLARIS_I2C, 0x40020000,
                                    qdev_get_gpio_in(nvic, 8));
         i2c = (I2CBus *)qdev_get_child_bus(dev, "i2c");
@@ -1184,7 +1205,7 @@ static void stellaris_init(MachineState *ms, stellaris_board_info *board)
     }
 
     for (i = 0; i < NUM_UART; i++) {
-        if (board->dc2 & (1 << i)) {
+        if (DEV_CAP(2, UART(i))) {
             SysBusDevice *sbd;
 
             dev = qdev_new("pl011_luminary");
@@ -1196,7 +1217,7 @@ static void stellaris_init(MachineState *ms, stellaris_board_info *board)
             sysbus_connect_irq(sbd, 0, qdev_get_gpio_in(nvic, uart_irq[i]));
         }
     }
-    if (board->dc2 & (1 << 4)) {
+    if (DEV_CAP(2, SSI)) {
         dev = sysbus_create_simple("pl022", 0x40008000,
                                    qdev_get_gpio_in(nvic, 7));
         if (board->peripherals & BP_OLED_SSI) {
@@ -1305,7 +1326,7 @@ static void stellaris_init(MachineState *ms, stellaris_board_info *board)
             qemu_irq_raise(gpio_out[GPIO_D][0]);
         }
     }
-    if (board->dc4 & (1 << 28)) {
+    if (DEV_CAP(4, EMAC)) {
         DeviceState *enet;
 
         enet = qdev_new("stellaris_enet");
Signature · 1 line
2.47.1
Reviewed-by on v1 5/9
#10 lore raw

Re: [PATCH 5/9] hw/arm/stellaris: Use DEVCAP macro to access DeviceCapability registers

Quoted 10 lines · Philippe Mathieu-Daudé

Add definitions (DCx_periph) for the DeviceCapability bits, replace direct bitmask checks with the DEV_CAP() macro, which use the extract/deposit API.

---
 hw/arm/stellaris.c | 37 +++++++++++++++++++++++++++++--------
 1 file changed, 29 insertions(+), 8 deletions(-)

thanks
-- PMM

#11 lore raw

PATCH 6/9 hw/arm/stellaris: Map both I2C controllers

In reply to Philippe Mathieu-Daudé

There are 2 I2C controllers, map them both, removing the unimplemented one. Keep the OLED controller on the first I2C bus.

---
 hw/arm/stellaris.c | 21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)
hw/arm/stellaris.c +13 -8
index 64e6797553a..655bf85e89e 100644
@@ -1021,6 +1021,8 @@ static void stellaris_init(MachineState *ms, stellaris_board_info *board)
       { 0x40004000, 0x40005000, 0x40006000, 0x40007000,
         0x40024000, 0x40025000, 0x40026000};
     static const int gpio_irq[NUM_GPIO] = {0, 1, 2, 3, 4, 30, 31};
+    static const uint32_t i2c_addr[NUM_I2C] = {0x40020000, 0x40021000};
+    static const int i2c_irq[NUM_I2C] = {8, 37};
 
     /* Memory map of SoC devices, from
      * Stellaris LM3S6965 Microcontroller Data Sheet (rev I)
@@ -1062,7 +1064,7 @@ static void stellaris_init(MachineState *ms, stellaris_board_info *board)
     qemu_irq adc;
     int sram_size;
     int flash_size;
-    I2CBus *i2c;
+    DeviceState *i2c_dev[NUM_I2C];
     DeviceState *dev;
     DeviceState *ssys_dev;
     int i;
@@ -1195,14 +1197,18 @@ static void stellaris_init(MachineState *ms, stellaris_board_info *board)
         }
     }
 
-    if (DEV_CAP(2, I2C(0))) {
-        dev = sysbus_create_simple(TYPE_STELLARIS_I2C, 0x40020000,
-                                   qdev_get_gpio_in(nvic, 8));
-        i2c = (I2CBus *)qdev_get_child_bus(dev, "i2c");
-        if (board->peripherals & BP_OLED_I2C) {
-            i2c_slave_create_simple(i2c, "ssd0303", 0x3d);
+    for (i = 0; i < NUM_I2C; i++) {
+        if (DEV_CAP(2, I2C(i))) {
+            i2c_dev[i] = sysbus_create_simple(TYPE_STELLARIS_I2C, i2c_addr[i],
+                                              qdev_get_gpio_in(nvic,
+                                                               i2c_irq[i]));
         }
     }
+    if (board->peripherals & BP_OLED_I2C) {
+        I2CBus *bus = (I2CBus *)qdev_get_child_bus(i2c_dev[0], "i2c");
+
+        i2c_slave_create_simple(bus, "ssd0303", 0x3d);
+    }
 
     for (i = 0; i < NUM_UART; i++) {
         if (DEV_CAP(2, UART(i))) {
@@ -1381,7 +1387,6 @@ static void stellaris_init(MachineState *ms, stellaris_board_info *board)
     /* Add dummy regions for the devices we don't implement yet,
      * so guest accesses don't cause unlogged crashes.
      */
-    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);
Signature · 1 line
2.47.1
#13 lore raw

PATCH 7/9 hw/arm/stellaris: Only create MPU when available

In reply to Philippe Mathieu-Daudé
---
 hw/arm/stellaris.c | 3 +++
 1 file changed, 3 insertions(+)
hw/arm/stellaris.c +3 -0
index 655bf85e89e..d87587225c2 100644
@@ -1128,6 +1128,9 @@ static void stellaris_init(MachineState *ms, stellaris_board_info *board)
     qdev_prop_set_uint8(nvic, "num-prio-bits", NUM_PRIO_BITS);
     qdev_prop_set_string(nvic, "cpu-type", ms->cpu_type);
     qdev_prop_set_bit(nvic, "enable-bitband", true);
+    if (!DEV_CAP(1, MPU)) {
+        qdev_prop_set_uint32(nvic, "mpu-ns-regions", 0); /* Disable MPU */
+    }
     qdev_connect_clock_in(nvic, "cpuclk",
                           qdev_get_clock_out(ssys_dev, "SYSCLK"));
     /* This SoC does not connect the systick reference clock */
Signature · 1 line
2.47.1
Reviewed-by on v1 7/9
#14 lore raw

Re: [PATCH 7/9] hw/arm/stellaris: Only create MPU when available

Quoted 11 lines · Philippe Mathieu-Daudé
---
 hw/arm/stellaris.c | 3 +++
 1 file changed, 3 insertions(+)
hw/arm/stellaris.c +0 -0
index 655bf85e89e..d87587225c2 100644

hw/arm/stellaris.c static void stellaris_init(MachineState *ms, stellaris_board_info *board)

Quoted 10 lines
hw/arm/stellaris.c +3 -1
@@ -1128,6 +1128,9 @@ static void stellaris_init(MachineState *ms, stellaris_board_info *board)
     qdev_prop_set_uint8(nvic, "num-prio-bits", NUM_PRIO_BITS);
     qdev_prop_set_string(nvic, "cpu-type", ms->cpu_type);
     qdev_prop_set_bit(nvic, "enable-bitband", true);
+    if (!DEV_CAP(1, MPU)) {
+        qdev_prop_set_uint32(nvic, "mpu-ns-regions", 0); /* Disable MPU */
+    }
     qdev_connect_clock_in(nvic, "cpuclk",
                           qdev_get_clock_out(ssys_dev, "SYSCLK"));
     /* This SoC does not connect the systick reference clock */
--

This isn't actually a behaviour change, right? Both our boards set bit 7 in dc1 in their stellaris_board_info array.

With the commit message updated to mention that:

thanks
-- PMM

#15 lore raw

PATCH 8/9 hw/arm/stellaris: Only map existing devices as unimplemented

In reply to Philippe Mathieu-Daudé
---
 hw/arm/stellaris.c | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)
hw/arm/stellaris.c +15 -5
index d87587225c2..c89522332e2 100644
@@ -1390,11 +1390,21 @@ static void stellaris_init(MachineState *ms, stellaris_board_info *board)
     /* Add dummy regions for the devices we don't implement yet,
      * so guest accesses don't cause unlogged crashes.
      */
-    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);
+    if (DEV_CAP(1, PWM)) {
+        create_unimplemented_device("PWM", 0x40028000, 0x1000);
+    }
+    if (DEV_CAP(2, QEI(0))) {
+        create_unimplemented_device("QEI-0", 0x4002c000, 0x1000);
+    }
+    if (DEV_CAP(2, QEI(0))) {
+        create_unimplemented_device("QEI-1", 0x4002d000, 0x1000);
+    }
+    if (DEV_CAP(2, COMP(0))) {
+        create_unimplemented_device("analogue-comparator", 0x4003c000, 0x1000);
+    }
+    if (DEV_CAP(1, HIB)) {
+        create_unimplemented_device("hibernation", 0x400fc000, 0x1000);
+    }
     create_unimplemented_device("flash-control", 0x400fd000, 0x1000);
 
     armv7m_load_kernel(ARM_CPU(first_cpu), ms->kernel_filename, 0, flash_size);
Signature · 1 line
2.47.1
#16 lore raw

Re: [PATCH 8/9] hw/arm/stellaris: Only map existing devices as unimplemented

Quoted 16 lines · Philippe Mathieu-Daudé
---
 hw/arm/stellaris.c | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)
hw/arm/stellaris.c +0 -2
index d87587225c2..c89522332e2 100644
@@ -1390,11 +1390,21 @@ static void stellaris_init(MachineState *ms, stellaris_board_info *board)
     /* Add dummy regions for the devices we don't implement yet,
      * so guest accesses don't cause unlogged crashes.
      */
-    create_unimplemented_device("PWM", 0x40028000, 0x1000);
-    create_unimplemented_device("QEI-0", 0x4002c000, 0x1000);

hw/arm/stellaris.c static void stellaris_init(MachineState *ms, stellaris_board_info *board) · line 1399

Quoted 10 lines
hw/arm/stellaris.c +7 -3
-    create_unimplemented_device("QEI-1", 0x4002d000, 0x1000);
-    create_unimplemented_device("analogue-comparator", 0x4003c000, 0x1000);
-    create_unimplemented_device("hibernation", 0x400fc000, 0x1000);
+    if (DEV_CAP(1, PWM)) {
+        create_unimplemented_device("PWM", 0x40028000, 0x1000);
+    }
+    if (DEV_CAP(2, QEI(0))) {
+        create_unimplemented_device("QEI-0", 0x4002c000, 0x1000);
+    }
+    if (DEV_CAP(2, QEI(0))) {

Should be QEI(1), I guess.

hw/arm/stellaris.c static void stellaris_init(MachineState *ms, stellaris_board_info *board) · line 1407

Quoted 8 lines
hw/arm/stellaris.c +8 -0
+        create_unimplemented_device("QEI-1", 0x4002d000, 0x1000);
+    }
+    if (DEV_CAP(2, COMP(0))) {
+        create_unimplemented_device("analogue-comparator", 0x4003c000, 0x1000);
+    }
+    if (DEV_CAP(1, HIB)) {
+        create_unimplemented_device("hibernation", 0x400fc000, 0x1000);
+    }

Again, it would be helpful to flag up the behaviour changes here. I think:

* both boards have the PWM bit set : no change
* both boards have COMP(0) set : no change
* both boards have HIB set : no change
* LM3S6965EVB sets QEI(0) and QEI(1), but LM3S811EVB does not:
so we are (correctly) removing the unimplemented-device regions on that board type.

thanks
-- PMM

#17 lore raw

PATCH 9/9 hw/arm/stellaris: Wire GPTM[#n] output to ADC input #n

In reply to Philippe Mathieu-Daudé

The ADC model is very simple, and only consider the 4 GPTM IRQs as trigger. Currently they are all wired to the same input IRQ. This is a QDev design mistake. We could use a OR_IRQ, but the ADC actually really has one input for each GPTM, so have the ADC create 4 inputs and wire each GPTM output to them.

---
 hw/arm/stellaris.c | 26 +++++++++++++++++---------
 1 file changed, 17 insertions(+), 9 deletions(-)
hw/arm/stellaris.c +17 -9
index c89522332e2..446d6595a6d 100644
@@ -701,8 +701,16 @@ static void stellaris_i2c_init(Object *obj)
     sysbus_init_mmio(sbd, &s->iomem);
 }
 
-/* Analogue to Digital Converter.  This is only partially implemented,
-   enough for applications that use a combined ADC and timer tick.  */
+/*
+ * Analogue to Digital Converter.
+ *
+ * Each of the 4 trigger inputs has a MUX for 5 inputs
+ * (see Stellaris Data Sheet Figure 11-1: "ADC Module Block Diagram").
+ *
+ * This model only consider the GPTM inputs, thus MUX is not implemented.
+ */
+
+#define STELLARIS_ADC_TRIGGERS      4
 
 #define STELLARIS_ADC_EM_CONTROLLER 0
 #define STELLARIS_ADC_EM_COMP       1
@@ -986,7 +994,7 @@ static void stellaris_adc_init(Object *obj)
     memory_region_init_io(&s->iomem, obj, &stellaris_adc_ops, s,
                           "adc", 0x1000);
     sysbus_init_mmio(sbd, &s->iomem);
-    qdev_init_gpio_in(dev, stellaris_adc_trigger, 1);
+    qdev_init_gpio_in(dev, stellaris_adc_trigger, STELLARIS_ADC_TRIGGERS);
 }
 
 /* Board init.  */
@@ -1061,7 +1069,7 @@ static void stellaris_init(MachineState *ms, stellaris_board_info *board)
     DeviceState *gpio_dev[NUM_GPIO], *nvic;
     qemu_irq gpio_in[NUM_GPIO][8];
     qemu_irq gpio_out[NUM_GPIO][8];
-    qemu_irq adc;
+    DeviceState *adc;
     int sram_size;
     int flash_size;
     DeviceState *i2c_dev[NUM_I2C];
@@ -1144,15 +1152,12 @@ static void stellaris_init(MachineState *ms, stellaris_board_info *board)
     sysbus_connect_irq(SYS_BUS_DEVICE(ssys_dev), 0, qdev_get_gpio_in(nvic, 28));
 
     if (DEV_CAP(1, ADC)) {
-        dev = sysbus_create_varargs(TYPE_STELLARIS_ADC, 0x40038000,
+        adc = sysbus_create_varargs(TYPE_STELLARIS_ADC, 0x40038000,
                                     qdev_get_gpio_in(nvic, 14),
                                     qdev_get_gpio_in(nvic, 15),
                                     qdev_get_gpio_in(nvic, 16),
                                     qdev_get_gpio_in(nvic, 17),
                                     NULL);
-        adc = qdev_get_gpio_in(dev, 0);
-    } else {
-        adc = NULL;
     }
     for (i = 0; i < NUM_GPTM; i++) {
         if (DEV_CAP(2, GPTM(i))) {
@@ -1166,9 +1171,12 @@ static void stellaris_init(MachineState *ms, stellaris_board_info *board)
             sysbus_realize_and_unref(sbd, &error_fatal);
             sysbus_mmio_map(sbd, 0, 0x40030000 + i * 0x1000);
             sysbus_connect_irq(sbd, 0, qdev_get_gpio_in(nvic, timer_irq[i]));
+
             /* TODO: This is incorrect, but we get away with it because
                the ADC output is only ever pulsed.  */
-            qdev_connect_gpio_out(dev, 0, adc);
+            if (adc) {
+                qdev_connect_gpio_out(dev, 0, qdev_get_gpio_in(adc, i));
+            }
         }
     }
 
Signature · 1 line
2.47.1
#18 lore raw

Re: [PATCH 9/9] hw/arm/stellaris: Wire GPTM[#n] output to ADC input #n

Quoted 59 lines · Philippe Mathieu-Daudé

The ADC model is very simple, and only consider the 4 GPTM IRQs as trigger. Currently they are all wired to the same input IRQ. This is a QDev design mistake. We could use a OR_IRQ, but the ADC actually really has one input for each GPTM, so have the ADC create 4 inputs and wire each GPTM output to them.

---
 hw/arm/stellaris.c | 26 +++++++++++++++++---------
 1 file changed, 17 insertions(+), 9 deletions(-)
hw/arm/stellaris.c +12 -5
index c89522332e2..446d6595a6d 100644
@@ -701,8 +701,16 @@ static void stellaris_i2c_init(Object *obj)
     sysbus_init_mmio(sbd, &s->iomem);
 }
 
-/* Analogue to Digital Converter.  This is only partially implemented,
-   enough for applications that use a combined ADC and timer tick.  */
+/*
+ * Analogue to Digital Converter.
+ *
+ * Each of the 4 trigger inputs has a MUX for 5 inputs
+ * (see Stellaris Data Sheet Figure 11-1: "ADC Module Block Diagram").
+ *
+ * This model only consider the GPTM inputs, thus MUX is not implemented.
+ */
+
+#define STELLARIS_ADC_TRIGGERS      4
 
 #define STELLARIS_ADC_EM_CONTROLLER 0
 #define STELLARIS_ADC_EM_COMP       1
@@ -986,7 +994,7 @@ static void stellaris_adc_init(Object *obj)
     memory_region_init_io(&s->iomem, obj, &stellaris_adc_ops, s,
                           "adc", 0x1000);
     sysbus_init_mmio(sbd, &s->iomem);
-    qdev_init_gpio_in(dev, stellaris_adc_trigger, 1);
+    qdev_init_gpio_in(dev, stellaris_adc_trigger, STELLARIS_ADC_TRIGGERS);
 }
 
 /* Board init.  */
@@ -1061,7 +1069,7 @@ static void stellaris_init(MachineState *ms, stellaris_board_info *board)
     DeviceState *gpio_dev[NUM_GPIO], *nvic;
     qemu_irq gpio_in[NUM_GPIO][8];
     qemu_irq gpio_out[NUM_GPIO][8];
-    qemu_irq adc;
+    DeviceState *adc;
     int sram_size;
     int flash_size;
     DeviceState *i2c_dev[NUM_I2C];
@@ -1144,15 +1152,12 @@ static void stellaris_init(MachineState *ms, stellaris_board_info *board)
     sysbus_connect_irq(SYS_BUS_DEVICE(ssys_dev), 0, qdev_get_gpio_in(nvic, 28));
 
     if (DEV_CAP(1, ADC)) {
-        dev = sysbus_create_varargs(TYPE_STELLARIS_ADC, 0x40038000,

hw/arm/stellaris.c static void stellaris_init(MachineState *ms, stellaris_board_info *board) · line 1161

Quoted 10 lines
hw/arm/stellaris.c +1 -3
+        adc = sysbus_create_varargs(TYPE_STELLARIS_ADC, 0x40038000,
                                     qdev_get_gpio_in(nvic, 14),
                                     qdev_get_gpio_in(nvic, 15),
                                     qdev_get_gpio_in(nvic, 16),
                                     qdev_get_gpio_in(nvic, 17),
                                     NULL);
-        adc = qdev_get_gpio_in(dev, 0);
-    } else {
-        adc = NULL;
     }

Here you remove the code path that initializes adc to NULL if the device doesn't have an ADC...

hw/arm/stellaris.c static void stellaris_init(MachineState *ms, stellaris_board_info *board) · line 1179

Quoted 13 lines
hw/arm/stellaris.c +4 -1
     for (i = 0; i < NUM_GPTM; i++) {
         if (DEV_CAP(2, GPTM(i))) {
@@ -1166,9 +1171,12 @@ static void stellaris_init(MachineState *ms, stellaris_board_info *board)
             sysbus_realize_and_unref(sbd, &error_fatal);
             sysbus_mmio_map(sbd, 0, 0x40030000 + i * 0x1000);
             sysbus_connect_irq(sbd, 0, qdev_get_gpio_in(nvic, timer_irq[i]));
+
             /* TODO: This is incorrect, but we get away with it because
                the ADC output is only ever pulsed.  */
-            qdev_connect_gpio_out(dev, 0, adc);
+            if (adc) {
+                qdev_connect_gpio_out(dev, 0, qdev_get_gpio_in(adc, i));
+            }

...but here you add a test on whether adc is set or not.

hw/arm/stellaris.c static void stellaris_init(MachineState *ms, stellaris_board_info *board) · line 1181

Quoted 2 lines
hw/arm/stellaris.c +0 -0
         }
     }

thanks
-- PMM

#19 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 7 lines · Philippe Mathieu-Daudé

- Remove invalid unimplemented I2C#0
- Add DEVCAP() macro to check DeviceCapability registers
- Check DEVCAP() before creating devices
- Use 4 inputs for ADC, wire each timer output properly
- Improve documentation

Quoted 11 lines

Philippe Mathieu-Daudé (9):
hw/arm/stellaris: Link each board schematic hw/arm/stellaris: Constify read-only arrays hw/arm/stellaris: Remove incorrect unimplemented i2c-0 at 0x40002000 hw/arm/stellaris: Replace magic numbers by definitions hw/arm/stellaris: Use DEVCAP macro to access DeviceCapability
registers
hw/arm/stellaris: Map both I2C controllers hw/arm/stellaris: Only create MPU when available hw/arm/stellaris: Only map existing devices as unimplemented hw/arm/stellaris: Wire GPTM[#n] output to ADC input #n

Applied 1-6 to target-arm.next; left review comments on the others.

thanks
-- PMM

#20 lore raw
Quoted 3 lines · Peter Maydell

On Fri, 10 Jan 2025 at 16:02, Philippe Mathieu-Daudé <[email protected]> wrote:

Applied 1-6 to target-arm.next; left review comments on the others.

Thanks, could you s/http/https/ in patch #1 or should I post a patch on top?

Regards,

Phil.

#21 lore raw
Quoted 8 lines · Philippe Mathieu-Daudé
Quoted 3 lines · Peter Maydell

On Fri, 10 Jan 2025 at 16:02, Philippe Mathieu-Daudé <[email protected]> wrote:

Applied 1-6 to target-arm.next; left review comments on the others.

Thanks, could you s/http/https/ in patch #1 or should I post a patch on top?

Yeah, I made that fixup when I applied the patches.

-- PMM