Skip to contentSkip to conversation

hw: Mark architecture specific devices with specific endianness

PATCH In review Philippe Mathieu-Daudé 4 participants 20 messages Nov 6, 2024 – Dec 30, 2024

lore
Share & tools
lore
#0 lore raw

cover hw: Mark architecture specific devices with specific endianness

When a device is only built for an architecture built for a particular endianness, we can simplify the device to not use the "target native endianness" definition and directly use the proper target endianness.

Philippe Mathieu-Daudé (5):
hw/i386: Mark devices as little-endian
hw/tricore: Mark devices as little-endian
hw/m68k: Mark devices as big-endian
hw/openrisc: Mark devices as big-endian
hw/sparc: Mark devices as big-endian

 hw/i386/kvm/apic.c              | 2 +-
 hw/i386/pc.c                    | 4 ++--
 hw/i386/vapic.c                 | 2 +-
 hw/i386/xen/xen_apic.c          | 2 +-
 hw/i386/xen/xen_platform.c      | 2 +-
 hw/m68k/mcf5206.c               | 2 +-
 hw/m68k/mcf5208.c               | 6 +++---
 hw/m68k/mcf_intc.c              | 2 +-
 hw/m68k/next-kbd.c              | 2 +-
 hw/openrisc/openrisc_sim.c      | 2 +-
 hw/openrisc/virt.c              | 2 +-
 hw/sparc/sun4m_iommu.c          | 2 +-
 hw/sparc64/sun4u.c              | 2 +-
 hw/tricore/tricore_testdevice.c | 2 +-
 14 files changed, 17 insertions(+), 17 deletions(-)
Signature · 1 line
2.45.2
#1 lore raw

PATCH 1/5 hw/i386: Mark devices as little-endian

These devices are only used by the X86 targets, which are only built as little-endian. Therefore the DEVICE_NATIVE_ENDIAN definition expand to DEVICE_LITTLE_ENDIAN (besides, the DEVICE_BIG_ENDIAN case isn't tested). Simplify directly using DEVICE_LITTLE_ENDIAN.

---
 hw/i386/kvm/apic.c         | 2 +-
 hw/i386/pc.c               | 4 ++--
 hw/i386/vapic.c            | 2 +-
 hw/i386/xen/xen_apic.c     | 2 +-
 hw/i386/xen/xen_platform.c | 2 +-
 5 files changed, 6 insertions(+), 6 deletions(-)
hw/i386/kvm/apic.c +1 -1
index a72c28e8a7..3a5d69e8d0 100644
@@ -214,7 +214,7 @@ static void kvm_apic_mem_write(void *opaque, hwaddr addr,
 static const MemoryRegionOps kvm_apic_io_ops = {
     .read = kvm_apic_mem_read,
     .write = kvm_apic_mem_write,
-    .endianness = DEVICE_NATIVE_ENDIAN,
+    .endianness = DEVICE_LITTLE_ENDIAN,
 };
 
 static void kvm_apic_reset(APICCommonState *s)
hw/i386/pc.c +2 -2
index 830614d930..2259589e0d 100644
@@ -1064,7 +1064,7 @@ DeviceState *pc_vga_init(ISABus *isa_bus, PCIBus *pci_bus)
 static const MemoryRegionOps ioport80_io_ops = {
     .write = ioport80_write,
     .read = ioport80_read,
-    .endianness = DEVICE_NATIVE_ENDIAN,
+    .endianness = DEVICE_LITTLE_ENDIAN,
     .impl = {
         .min_access_size = 1,
         .max_access_size = 1,
@@ -1074,7 +1074,7 @@ static const MemoryRegionOps ioport80_io_ops = {
 static const MemoryRegionOps ioportF0_io_ops = {
     .write = ioportF0_write,
     .read = ioportF0_read,
-    .endianness = DEVICE_NATIVE_ENDIAN,
+    .endianness = DEVICE_LITTLE_ENDIAN,
     .impl = {
         .min_access_size = 1,
         .max_access_size = 1,
hw/i386/vapic.c +1 -1
index ef7f8b967f..fd906fdf78 100644
@@ -718,7 +718,7 @@ static uint64_t vapic_read(void *opaque, hwaddr addr, unsigned size)
 static const MemoryRegionOps vapic_ops = {
     .write = vapic_write,
     .read = vapic_read,
-    .endianness = DEVICE_NATIVE_ENDIAN,
+    .endianness = DEVICE_LITTLE_ENDIAN,
 };
 
 static void vapic_realize(DeviceState *dev, Error **errp)
hw/i386/xen/xen_apic.c +1 -1
index 101e16a766..a94e9005cb 100644
@@ -36,7 +36,7 @@ static void xen_apic_mem_write(void *opaque, hwaddr addr,
 static const MemoryRegionOps xen_apic_io_ops = {
     .read = xen_apic_mem_read,
     .write = xen_apic_mem_write,
-    .endianness = DEVICE_NATIVE_ENDIAN,
+    .endianness = DEVICE_LITTLE_ENDIAN,
 };
 
 static void xen_apic_realize(DeviceState *dev, Error **errp)
hw/i386/xen/xen_platform.c +1 -1
index ec0e536e85..3b3e745822 100644
@@ -514,7 +514,7 @@ static void platform_mmio_write(void *opaque, hwaddr addr,
 static const MemoryRegionOps platform_mmio_handler = {
     .read = &platform_mmio_read,
     .write = &platform_mmio_write,
-    .endianness = DEVICE_NATIVE_ENDIAN,
+    .endianness = DEVICE_LITTLE_ENDIAN,
 };
 
 static void platform_mmio_setup(PCIXenPlatformState *d)
Signature · 1 line
2.45.2
Reviewed-by on v1 1/5
#2 lore raw

Re: [PATCH 1/5] hw/i386: Mark devices as little-endian

Quoted 6 lines · Philippe Mathieu-Daudé

These devices are only used by the X86 targets, which are only built as little-endian. Therefore the DEVICE_NATIVE_ENDIAN definition expand to DEVICE_LITTLE_ENDIAN (besides, the DEVICE_BIG_ENDIAN case isn't tested). Simplify directly using DEVICE_LITTLE_ENDIAN.

Quoted 8 lines
---
  hw/i386/kvm/apic.c         | 2 +-
  hw/i386/pc.c               | 4 ++--
  hw/i386/vapic.c            | 2 +-
  hw/i386/xen/xen_apic.c     | 2 +-
  hw/i386/xen/xen_platform.c | 2 +-
  5 files changed, 6 insertions(+), 6 deletions(-)

r~

Reviewed-by on v1 1/5
#3 lore raw

Re: [PATCH 1/5] hw/i386: Mark devices as little-endian

In reply to Philippe Mathieu-Daudé

Am Wed, 6 Nov 2024 18:46:08 +0000
schrieb Philippe Mathieu-Daudé <[email protected]>:

Quoted 6 lines

These devices are only used by the X86 targets, which are only built as little-endian. Therefore the DEVICE_NATIVE_ENDIAN definition expand to DEVICE_LITTLE_ENDIAN (besides, the DEVICE_BIG_ENDIAN case isn't tested). Simplify directly using DEVICE_LITTLE_ENDIAN.

Quoted 8 lines
---
 hw/i386/kvm/apic.c         | 2 +-
 hw/i386/pc.c               | 4 ++--
 hw/i386/vapic.c            | 2 +-
 hw/i386/xen/xen_apic.c     | 2 +-
 hw/i386/xen/xen_platform.c | 2 +-
 5 files changed, 6 insertions(+), 6 deletions(-)
#4 lore raw

PATCH 2/5 hw/tricore: Mark devices as little-endian

In reply to Philippe Mathieu-Daudé

These devices are only used by the TriCore target, which is only built as little-endian. Therefore the DEVICE_NATIVE_ENDIAN definition expand to DEVICE_LITTLE_ENDIAN (besides, the DEVICE_BIG_ENDIAN case isn't tested). Simplify directly using DEVICE_LITTLE_ENDIAN.

---
 hw/tricore/tricore_testdevice.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/tricore/tricore_testdevice.c +1 -1
index ae95c49565..169f5907e9 100644
@@ -47,7 +47,7 @@ static const MemoryRegionOps tricore_testdevice_ops = {
         .min_access_size = 4,
         .max_access_size = 4,
     },
-    .endianness = DEVICE_NATIVE_ENDIAN,
+    .endianness = DEVICE_LITTLE_ENDIAN,
 };
 
 static void tricore_testdevice_init(Object *obj)
Signature · 1 line
2.45.2
Reviewed-by on v1 2/5
#5 lore raw

Re: [PATCH 2/5] hw/tricore: Mark devices as little-endian

Quoted 10 lines · Philippe Mathieu-Daudé

These devices are only used by the TriCore target, which is only built as little-endian. Therefore the DEVICE_NATIVE_ENDIAN definition expand to DEVICE_LITTLE_ENDIAN (besides, the DEVICE_BIG_ENDIAN case isn't tested). Simplify directly using DEVICE_LITTLE_ENDIAN.

---
  hw/tricore/tricore_testdevice.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

r~

Reviewed-by on v1 2/5
#6 lore raw

Re: [PATCH 2/5] hw/tricore: Mark devices as little-endian

In reply to Philippe Mathieu-Daudé

Am Wed, 6 Nov 2024 18:46:09 +0000
schrieb Philippe Mathieu-Daudé <[email protected]>:

Quoted 10 lines

These devices are only used by the TriCore target, which is only built as little-endian. Therefore the DEVICE_NATIVE_ENDIAN definition expand to DEVICE_LITTLE_ENDIAN (besides, the DEVICE_BIG_ENDIAN case isn't tested). Simplify directly using DEVICE_LITTLE_ENDIAN.

---
 hw/tricore/tricore_testdevice.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
#7 lore raw

PATCH 3/5 hw/m68k: Mark devices as big-endian

In reply to Philippe Mathieu-Daudé

These devices are only used by the M68K target, which is only built as big-endian. Therefore the DEVICE_NATIVE_ENDIAN definition expand to DEVICE_BIG_ENDIAN (besides, the DEVICE_LITTLE_ENDIAN case isn't tested). Simplify directly using DEVICE_BIG_ENDIAN.

---
 hw/m68k/mcf5206.c  | 2 +-
 hw/m68k/mcf5208.c  | 6 +++---
 hw/m68k/mcf_intc.c | 2 +-
 hw/m68k/next-kbd.c | 2 +-
 4 files changed, 6 insertions(+), 6 deletions(-)
hw/m68k/mcf5206.c +1 -1
index 7247cdbe5e..4892924fc2 100644
@@ -582,7 +582,7 @@ static const MemoryRegionOps m5206_mbar_ops = {
     .write = m5206_mbar_writefn,
     .valid.min_access_size = 1,
     .valid.max_access_size = 4,
-    .endianness = DEVICE_NATIVE_ENDIAN,
+    .endianness = DEVICE_BIG_ENDIAN,
 };
 
 static void mcf5206_mbar_realize(DeviceState *dev, Error **errp)
hw/m68k/mcf5208.c +3 -3
index e37cd50d18..4166877066 100644
@@ -155,7 +155,7 @@ static uint64_t m5208_timer_read(void *opaque, hwaddr addr,
 static const MemoryRegionOps m5208_timer_ops = {
     .read = m5208_timer_read,
     .write = m5208_timer_write,
-    .endianness = DEVICE_NATIVE_ENDIAN,
+    .endianness = DEVICE_BIG_ENDIAN,
 };
 
 static uint64_t m5208_sys_read(void *opaque, hwaddr addr,
@@ -192,7 +192,7 @@ static void m5208_sys_write(void *opaque, hwaddr addr,
 static const MemoryRegionOps m5208_sys_ops = {
     .read = m5208_sys_read,
     .write = m5208_sys_write,
-    .endianness = DEVICE_NATIVE_ENDIAN,
+    .endianness = DEVICE_BIG_ENDIAN,
 };
 
 static uint64_t m5208_rcm_read(void *opaque, hwaddr addr,
@@ -224,7 +224,7 @@ static void m5208_rcm_write(void *opaque, hwaddr addr,
 static const MemoryRegionOps m5208_rcm_ops = {
     .read = m5208_rcm_read,
     .write = m5208_rcm_write,
-    .endianness = DEVICE_NATIVE_ENDIAN,
+    .endianness = DEVICE_BIG_ENDIAN,
 };
 
 static void mcf5208_sys_init(MemoryRegion *address_space, qemu_irq *pic,
hw/m68k/mcf_intc.c +1 -1
index 9fc30b03ba..5f38c49077 100644
@@ -166,7 +166,7 @@ static void mcf_intc_reset(DeviceState *dev)
 static const MemoryRegionOps mcf_intc_ops = {
     .read = mcf_intc_read,
     .write = mcf_intc_write,
-    .endianness = DEVICE_NATIVE_ENDIAN,
+    .endianness = DEVICE_BIG_ENDIAN,
 };
 
 static void mcf_intc_instance_init(Object *obj)
hw/m68k/next-kbd.c +1 -1
index bc67810f31..4d87edc2de 100644
@@ -163,7 +163,7 @@ static const MemoryRegionOps kbd_ops = {
     .write = kbd_writefn,
     .valid.min_access_size = 1,
     .valid.max_access_size = 4,
-    .endianness = DEVICE_NATIVE_ENDIAN,
+    .endianness = DEVICE_BIG_ENDIAN,
 };
 
 static void nextkbd_event(void *opaque, int ch)
Signature · 1 line
2.45.2
Reviewed-by on v1 3/5
#8 lore raw

Re: [PATCH 3/5] hw/m68k: Mark devices as big-endian

Quoted 6 lines · Philippe Mathieu-Daudé

These devices are only used by the M68K target, which is only built as big-endian. Therefore the DEVICE_NATIVE_ENDIAN definition expand to DEVICE_BIG_ENDIAN (besides, the DEVICE_LITTLE_ENDIAN case isn't tested). Simplify directly using DEVICE_BIG_ENDIAN.

Quoted 7 lines
---
  hw/m68k/mcf5206.c  | 2 +-
  hw/m68k/mcf5208.c  | 6 +++---
  hw/m68k/mcf_intc.c | 2 +-
  hw/m68k/next-kbd.c | 2 +-
  4 files changed, 6 insertions(+), 6 deletions(-)

r~

Reviewed-by on v1 3/5
#9 lore raw

Re: [PATCH 3/5] hw/m68k: Mark devices as big-endian

In reply to Philippe Mathieu-Daudé

Am Wed, 6 Nov 2024 18:46:10 +0000
schrieb Philippe Mathieu-Daudé <[email protected]>:

Quoted 6 lines

These devices are only used by the M68K target, which is only built as big-endian. Therefore the DEVICE_NATIVE_ENDIAN definition expand to DEVICE_BIG_ENDIAN (besides, the DEVICE_LITTLE_ENDIAN case isn't tested). Simplify directly using DEVICE_BIG_ENDIAN.

Quoted 7 lines
---
 hw/m68k/mcf5206.c  | 2 +-
 hw/m68k/mcf5208.c  | 6 +++---
 hw/m68k/mcf_intc.c | 2 +-
 hw/m68k/next-kbd.c | 2 +-
 4 files changed, 6 insertions(+), 6 deletions(-)
#10 lore raw

PATCH 4/5 hw/openrisc: Mark devices as big-endian

In reply to Philippe Mathieu-Daudé

These devices are only used by the OpenRISC target, which is only built as big-endian. Therefore the DEVICE_NATIVE_ENDIAN definition expand to DEVICE_BIG_ENDIAN (besides, the DEVICE_LITTLE_ENDIAN case isn't tested). Simplify directly using DEVICE_BIG_ENDIAN.

---
 hw/openrisc/openrisc_sim.c | 2 +-
 hw/openrisc/virt.c         | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
hw/openrisc/openrisc_sim.c +1 -1
index 9fb63515ef..794c175bdb 100644
@@ -266,7 +266,7 @@ static void openrisc_sim_serial_init(Or1ksimState *state, hwaddr base,
     }
     serial_mm_init(get_system_memory(), base, 0, serial_irq, 115200,
                    serial_hd(OR1KSIM_UART_COUNT - uart_idx - 1),
-                   DEVICE_NATIVE_ENDIAN);
+                   DEVICE_BIG_ENDIAN);
 
     /* Add device tree node for serial. */
     nodename = g_strdup_printf("/serial@%" HWADDR_PRIx, base);
hw/openrisc/virt.c +1 -1
index 47d2c9bd3c..ede57fe391 100644
@@ -236,7 +236,7 @@ static void openrisc_virt_serial_init(OR1KVirtState *state, hwaddr base,
     qemu_irq serial_irq = get_per_cpu_irq(cpus, num_cpus, irq_pin);
 
     serial_mm_init(get_system_memory(), base, 0, serial_irq, 115200,
-                   serial_hd(0), DEVICE_NATIVE_ENDIAN);
+                   serial_hd(0), DEVICE_BIG_ENDIAN);
 
     /* Add device tree node for serial. */
     nodename = g_strdup_printf("/serial@%" HWADDR_PRIx, base);
Signature · 1 line
2.45.2
Reviewed-by on v1 4/5
#11 lore raw

Re: [PATCH 4/5] hw/openrisc: Mark devices as big-endian

Quoted 11 lines · Philippe Mathieu-Daudé

These devices are only used by the OpenRISC target, which is only built as big-endian. Therefore the DEVICE_NATIVE_ENDIAN definition expand to DEVICE_BIG_ENDIAN (besides, the DEVICE_LITTLE_ENDIAN case isn't tested). Simplify directly using DEVICE_BIG_ENDIAN.

---
  hw/openrisc/openrisc_sim.c | 2 +-
  hw/openrisc/virt.c         | 2 +-
  2 files changed, 2 insertions(+), 2 deletions(-)

r~

#12 lore raw

Re: [PATCH 4/5] hw/openrisc: Mark devices as big-endian

In reply to Philippe Mathieu-Daudé

Am Wed, 6 Nov 2024 18:46:11 +0000
schrieb Philippe Mathieu-Daudé <[email protected]>:

Quoted 30 lines

These devices are only used by the OpenRISC target, which is only built as big-endian. Therefore the DEVICE_NATIVE_ENDIAN definition expand to DEVICE_BIG_ENDIAN (besides, the DEVICE_LITTLE_ENDIAN case isn't tested). Simplify directly using DEVICE_BIG_ENDIAN.

---
 hw/openrisc/openrisc_sim.c | 2 +-
 hw/openrisc/virt.c         | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
hw/openrisc/openrisc_sim.c +1 -1
index 9fb63515ef..794c175bdb 100644
@@ -266,7 +266,7 @@ static void openrisc_sim_serial_init(Or1ksimState *state, hwaddr base,
     }
     serial_mm_init(get_system_memory(), base, 0, serial_irq, 115200,
                    serial_hd(OR1KSIM_UART_COUNT - uart_idx - 1),
-                   DEVICE_NATIVE_ENDIAN);
+                   DEVICE_BIG_ENDIAN);
 
     /* Add device tree node for serial. */
     nodename = g_strdup_printf("/serial@%" HWADDR_PRIx, base);
hw/openrisc/virt.c +0 -0
index 47d2c9bd3c..ede57fe391 100644

hw/openrisc/virt.c static void openrisc_virt_serial_init(OR1KVirtState *state, hwaddr base, · line 242

Quoted 8 lines
hw/openrisc/virt.c +1 -1
@@ -236,7 +236,7 @@ static void openrisc_virt_serial_init(OR1KVirtState *state, hwaddr base,
     qemu_irq serial_irq = get_per_cpu_irq(cpus, num_cpus, irq_pin);
 
     serial_mm_init(get_system_memory(), base, 0, serial_irq, 115200,
-                   serial_hd(0), DEVICE_NATIVE_ENDIAN);
+                   serial_hd(0), DEVICE_BIG_ENDIAN);
 
     /* Add device tree node for serial. */
     nodename = g_strdup_printf("/serial@%" HWADDR_PRIx, base);

According to https://openrisc.io/or1k.html the openrisc CPU could be implemented as little endian, too ... so would it make sense to use a runtime detected value here instead?

Thomas

#13 lore raw

Re: [PATCH 4/5] hw/openrisc: Mark devices as big-endian

Hi Thomas,

Quoted 27 lines · Thomas Huth

Am Wed, 6 Nov 2024 18:46:11 +0000
schrieb Philippe Mathieu-Daudé <[email protected]>:

Quoted 24 lines

These devices are only used by the OpenRISC target, which is only built as big-endian. Therefore the DEVICE_NATIVE_ENDIAN definition expand to DEVICE_BIG_ENDIAN (besides, the DEVICE_LITTLE_ENDIAN case isn't tested). Simplify directly using DEVICE_BIG_ENDIAN.

---
  hw/openrisc/openrisc_sim.c | 2 +-
  hw/openrisc/virt.c         | 2 +-
  2 files changed, 2 insertions(+), 2 deletions(-)
hw/openrisc/virt.c +1 -1
index 47d2c9bd3c..ede57fe391 100644
@@ -236,7 +236,7 @@ static void openrisc_virt_serial_init(OR1KVirtState *state, hwaddr base,
      qemu_irq serial_irq = get_per_cpu_irq(cpus, num_cpus, irq_pin);
 
      serial_mm_init(get_system_memory(), base, 0, serial_irq, 115200,
-                   serial_hd(0), DEVICE_NATIVE_ENDIAN);
+                   serial_hd(0), DEVICE_BIG_ENDIAN);
 
Quoted 6 lines

hw/openrisc/virt.c static void openrisc_virt_serial_init(OR1KVirtState *state, hwaddr base, · line 242

Quoted 2 lines
hw/openrisc/virt.c +0 -0
      /* Add device tree node for serial. */
      nodename = g_strdup_printf("/serial@%" HWADDR_PRIx, base);

According to https://openrisc.io/or1k.html the openrisc CPU could be implemented as little endian, too ... so would it make sense to use a runtime detected value here instead?

While this patch is a code change, it aims to not introduce any functional change. We are not building (nor testing) these devices in a little endian configuration:

$ git grep -l TARGET_BIG_ENDIAN configs/targets/*softmmu*
configs/targets/hppa-softmmu.mak
configs/targets/m68k-softmmu.mak
configs/targets/microblaze-softmmu.mak
configs/targets/mips-softmmu.mak
configs/targets/mips64-softmmu.mak
configs/targets/or1k-softmmu.mak
                ^^^^
configs/targets/ppc-softmmu.mak
configs/targets/ppc64-softmmu.mak
configs/targets/s390x-softmmu.mak
configs/targets/sh4eb-softmmu.mak
configs/targets/sparc-softmmu.mak
configs/targets/sparc64-softmmu.mak
configs/targets/xtensaeb-softmmu.mak
$ git grep -L TARGET_BIG_ENDIAN configs/targets/*softmmu*
configs/targets/aarch64-softmmu.mak
configs/targets/alpha-softmmu.mak
configs/targets/arm-softmmu.mak
configs/targets/avr-softmmu.mak
configs/targets/i386-softmmu.mak
configs/targets/loongarch64-softmmu.mak
configs/targets/microblazeel-softmmu.mak
configs/targets/mips64el-softmmu.mak
configs/targets/mipsel-softmmu.mak
configs/targets/riscv32-softmmu.mak
configs/targets/riscv64-softmmu.mak
configs/targets/rx-softmmu.mak
configs/targets/sh4-softmmu.mak
configs/targets/tricore-softmmu.mak
configs/targets/x86_64-softmmu.mak
configs/targets/xtensa-softmmu.mak

(no little-endian config here)

Having little-endian OpenRISC is certainly welcomed, but it has to be done separately, preferably adding test coverage.

Should I rework the commit description to be more precise?

Regards,

Phil.

#14 lore raw

Re: [PATCH 4/5] hw/openrisc: Mark devices as big-endian

Quoted 40 lines · Philippe Mathieu-Daudé

Hi Thomas,

Quoted 16 lines · Thomas Huth

Am Wed,  6 Nov 2024 18:46:11 +0000
schrieb Philippe Mathieu-Daudé <[email protected]>:

Quoted 11 lines

These devices are only used by the OpenRISC target, which is only built as big-endian. Therefore the DEVICE_NATIVE_ENDIAN definition expand to DEVICE_BIG_ENDIAN (besides, the DEVICE_LITTLE_ENDIAN case isn't tested). Simplify directly using DEVICE_BIG_ENDIAN.

---
  hw/openrisc/openrisc_sim.c | 2 +-
  hw/openrisc/virt.c         | 2 +-

  2 files changed, 2 insertions(+), 2 deletions(-)
Quoted 16 lines

hw/openrisc/virt.c static void openrisc_virt_serial_init(OR1KVirtState *state, hwaddr · line 241

Quoted 12 lines
hw/openrisc/virt.c +1 -1
index 47d2c9bd3c..ede57fe391 100644
@@ -236,7 +236,7 @@ static void openrisc_virt_serial_init(OR1KVirtState *state, hwaddr 
 base,
       qemu_irq serial_irq = get_per_cpu_irq(cpus, num_cpus, irq_pin);
       serial_mm_init(get_system_memory(), base, 0, serial_irq, 115200,
-                   serial_hd(0), DEVICE_NATIVE_ENDIAN);
+                   serial_hd(0), DEVICE_BIG_ENDIAN);
       /* Add device tree node for serial. */
       nodename = g_strdup_printf("/serial@%" HWADDR_PRIx, base);

According to https://openrisc.io/or1k.html the openrisc CPU could be implemented as little endian, too ... so would it make sense to use a runtime detected value here instead?

While this patch is a code change, it aims to not introduce any functional change. We are not building (nor testing) these devices in a little endian configuration:

Quoted 8 lines
$ git grep -l TARGET_BIG_ENDIAN configs/targets/*softmmu*
configs/targets/hppa-softmmu.mak
configs/targets/m68k-softmmu.mak
configs/targets/microblaze-softmmu.mak
configs/targets/mips-softmmu.mak
configs/targets/mips64-softmmu.mak
configs/targets/or1k-softmmu.mak
                 ^^^^

The openrisc little-endian control is in a control register: SR[LEE] (which we do not implement at present).

So any openrisc little-endian support would look like qemu-system-ppc64. I would not expect devices to switch endianness at all.

r~

Reviewed-by
#15 lore raw

Re: [PATCH 4/5] hw/openrisc: Mark devices as big-endian

Am Sat, 9 Nov 2024 10:08:16 -0800
schrieb Richard Henderson <[email protected]>:

Quoted 50 lines · Philippe Mathieu-Daudé
Quoted 40 lines

Hi Thomas,

Quoted 16 lines · Thomas Huth

Am Wed,  6 Nov 2024 18:46:11 +0000
schrieb Philippe Mathieu-Daudé <[email protected]>:

Quoted 11 lines

These devices are only used by the OpenRISC target, which is only built as big-endian. Therefore the DEVICE_NATIVE_ENDIAN definition expand to DEVICE_BIG_ENDIAN (besides, the DEVICE_LITTLE_ENDIAN case isn't tested). Simplify directly using DEVICE_BIG_ENDIAN.

---
  hw/openrisc/openrisc_sim.c | 2 +-
  hw/openrisc/virt.c         | 2 +-

  2 files changed, 2 insertions(+), 2 deletions(-)  
Quoted 16 lines

hw/openrisc/virt.c static void openrisc_virt_serial_init(OR1KVirtState *state, hwaddr · line 241

Quoted 12 lines
hw/openrisc/virt.c +1 -1
index 47d2c9bd3c..ede57fe391 100644
@@ -236,7 +236,7 @@ static void openrisc_virt_serial_init(OR1KVirtState *state, hwaddr 
 base,
       qemu_irq serial_irq = get_per_cpu_irq(cpus, num_cpus, irq_pin);
       serial_mm_init(get_system_memory(), base, 0, serial_irq, 115200,
-                   serial_hd(0), DEVICE_NATIVE_ENDIAN);
+                   serial_hd(0), DEVICE_BIG_ENDIAN);
       /* Add device tree node for serial. */
       nodename = g_strdup_printf("/serial@%" HWADDR_PRIx, base);  

According to https://openrisc.io/or1k.html the openrisc CPU could be implemented as little endian, too ... so would it make sense to use a runtime detected value here instead?

While this patch is a code change, it aims to not introduce any functional change. We are not building (nor testing) these devices in a little endian configuration:

Quoted 8 lines
$ git grep -l TARGET_BIG_ENDIAN configs/targets/*softmmu*
configs/targets/hppa-softmmu.mak
configs/targets/m68k-softmmu.mak
configs/targets/microblaze-softmmu.mak
configs/targets/mips-softmmu.mak
configs/targets/mips64-softmmu.mak
configs/targets/or1k-softmmu.mak
                 ^^^^  
Quoted 5 lines

The openrisc little-endian control is in a control register: SR[LEE] (which we do not implement at present).

So any openrisc little-endian support would look like qemu-system-ppc64. I would not expect devices to switch endianness at all.

Ok, thanks, in that case, I think the patch is fine.

FWIW:

#16 lore raw

PATCH 5/5 hw/sparc: Mark devices as big-endian

In reply to Philippe Mathieu-Daudé

These devices are only used by the SPARC targets, which are only built as big-endian. Therefore the DEVICE_NATIVE_ENDIAN definition expand to DEVICE_BIG_ENDIAN (besides, the DEVICE_LITTLE_ENDIAN case isn't tested). Simplify directly using DEVICE_BIG_ENDIAN.

---
 hw/sparc/sun4m_iommu.c | 2 +-
 hw/sparc64/sun4u.c     | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
hw/sparc/sun4m_iommu.c +1 -1
index 6f765e97e4..4486508e3b 100644
@@ -238,7 +238,7 @@ static void iommu_mem_write(void *opaque, hwaddr addr,
 static const MemoryRegionOps iommu_mem_ops = {
     .read = iommu_mem_read,
     .write = iommu_mem_write,
-    .endianness = DEVICE_NATIVE_ENDIAN,
+    .endianness = DEVICE_BIG_ENDIAN,
     .valid = {
         .min_access_size = 4,
         .max_access_size = 4,
hw/sparc64/sun4u.c +1 -1
index 541c7f74fa..9d7aebf632 100644
@@ -254,7 +254,7 @@ static void power_mem_write(void *opaque, hwaddr addr,
 static const MemoryRegionOps power_mem_ops = {
     .read = power_mem_read,
     .write = power_mem_write,
-    .endianness = DEVICE_NATIVE_ENDIAN,
+    .endianness = DEVICE_BIG_ENDIAN,
     .valid = {
         .min_access_size = 4,
         .max_access_size = 4,
Signature · 1 line
2.45.2
Reviewed-by on v1 5/5
#17 lore raw

Re: [PATCH 5/5] hw/sparc: Mark devices as big-endian

Quoted 30 lines · Philippe Mathieu-Daudé

These devices are only used by the SPARC targets, which are only built as big-endian. Therefore the DEVICE_NATIVE_ENDIAN definition expand to DEVICE_BIG_ENDIAN (besides, the DEVICE_LITTLE_ENDIAN case isn't tested). Simplify directly using DEVICE_BIG_ENDIAN.

---
  hw/sparc/sun4m_iommu.c | 2 +-
  hw/sparc64/sun4u.c     | 2 +-
  2 files changed, 2 insertions(+), 2 deletions(-)
hw/sparc/sun4m_iommu.c +1 -1
index 6f765e97e4..4486508e3b 100644
@@ -238,7 +238,7 @@ static void iommu_mem_write(void *opaque, hwaddr addr,
  static const MemoryRegionOps iommu_mem_ops = {
      .read = iommu_mem_read,
      .write = iommu_mem_write,
-    .endianness = DEVICE_NATIVE_ENDIAN,
+    .endianness = DEVICE_BIG_ENDIAN,
      .valid = {
          .min_access_size = 4,
          .max_access_size = 4,
hw/sparc64/sun4u.c +0 -0
index 541c7f74fa..9d7aebf632 100644

hw/sparc64/sun4u.c static void power_mem_write(void *opaque, hwaddr addr, · line 260

Quoted 8 lines
hw/sparc64/sun4u.c +1 -1
@@ -254,7 +254,7 @@ static void power_mem_write(void *opaque, hwaddr addr,
  static const MemoryRegionOps power_mem_ops = {
      .read = power_mem_read,
      .write = power_mem_write,
-    .endianness = DEVICE_NATIVE_ENDIAN,
+    .endianness = DEVICE_BIG_ENDIAN,
      .valid = {
          .min_access_size = 4,
          .max_access_size = 4,

ATB,

Mark.

Reviewed-by on v1 5/5
#18 lore raw

Re: [PATCH 5/5] hw/sparc: Mark devices as big-endian

In reply to Philippe Mathieu-Daudé
Quoted 11 lines · Philippe Mathieu-Daudé

These devices are only used by the SPARC targets, which are only built as big-endian. Therefore the DEVICE_NATIVE_ENDIAN definition expand to DEVICE_BIG_ENDIAN (besides, the DEVICE_LITTLE_ENDIAN case isn't tested). Simplify directly using DEVICE_BIG_ENDIAN.

---
  hw/sparc/sun4m_iommu.c | 2 +-
  hw/sparc64/sun4u.c     | 2 +-
  2 files changed, 2 insertions(+), 2 deletions(-)

r~

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

When a device is only built for an architecture built for a particular endianness, we can simplify the device to not use the "target native endianness" definition and directly use the proper target endianness.

Philippe Mathieu-Daudé (5):
hw/i386: Mark devices as little-endian
hw/tricore: Mark devices as little-endian
hw/m68k: Mark devices as big-endian
hw/openrisc: Mark devices as big-endian
hw/sparc: Mark devices as big-endian

I'm queuing this series, better to test it early in the dev cycle.