Skip to contentSkip to conversation

hw/loongarch/virt: Fix UART ACPI and FDT

PATCH Superseded pillow 2 participants 10 messages Oct 22

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

pillow

author
#0 lore raw

v4 cover hw/loongarch/virt: Fix UART ACPI and FDT

This series removes the UART _DSD clock property and _CCA, adds _STA = 0x0f, and updates the expected DSDT blobs.

It also changes the FDT clock-frequency from 100000000 to 1843200 Hz to match the emulated UART model. The FDT clock property is retained.

Changes since v3:
- Add a separate patch to correct the FDT UART clock frequency.
- Carry Bibo Mao's Reviewed-by for the ACPI change.
- Clarify the ACPI commit message.

Testing:
- All five LoongArch ACPI bios-tables-test subtests pass.
- The generated DTB reports clock-frequency = 1843200 for all four UART nodes.

pillow (4):
bios-tables-test-allowed-diff.h: Allow LoongArch DSDT.* hw/loongarch/virt-acpi-build: Drop UART _DSD clock and add _STA tests/data/acpi/loongarch64: Update expected DSDT.* hw/loongarch/virt: Fix UART clock frequency in FDT

 hw/loongarch/virt-acpi-build.c                |  12 +-----------
 hw/loongarch/virt-fdt-build.c                 |   2 +-
 tests/data/acpi/loongarch64/virt/DSDT         | Bin 4603 -> 4379 bytes
 tests/data/acpi/loongarch64/virt/DSDT.memhp   | Bin 5824 -> 5600 bytes
 tests/data/acpi/loongarch64/virt/DSDT.numamem | Bin 4609 -> 4385 bytes
 .../data/acpi/loongarch64/virt/DSDT.topology  | Bin 4905 -> 4681 bytes
 6 files changed, 2 insertions(+), 12 deletions(-)

base-commit: 8967b2fe1b2aaae3c29e207d85fab901d580a2dc

Signature · 1 line
2.56.0
author
#1 lore raw

PATCH v4 1/4 bios-tables-test-allowed-diff.h: Allow LoongArch DSDT.*

---
 tests/qtest/bios-tables-test-allowed-diff.h | 4 ++++
 1 file changed, 4 insertions(+)
tests/qtest/bios-tables-test-allowed-diff.h +4 -0
index dfb8523..2ed837f 100644
@@ -1 +1,5 @@
 /* List of comma-separated changed AML files to ignore */
+"tests/data/acpi/loongarch64/virt/DSDT",
+"tests/data/acpi/loongarch64/virt/DSDT.memhp",
+"tests/data/acpi/loongarch64/virt/DSDT.numamem",
+"tests/data/acpi/loongarch64/virt/DSDT.topology",
Signature · 1 line
2.56.0
author
#2 lore raw

PATCH v4 2/4 hw/loongarch/virt-acpi-build: Drop UART _DSD clock and add _STA

In reply to pillow

The UART _DSD clock property contains a typo ("clock-frenquency") and has its key/value order reversed. It also specifies a 100 MHz clock, which does not match the emulated UART.

QEMU's UART model uses baudbase = 115200, corresponding to a clock frequency of 1,843,200 Hz. The Linux 8250 PnP driver uses the same frequency by default when no clock is specified.

Since the default already matches the UART model, there is no need to provide an explicit clock property. Drop it from _DSD, consistent with the existing x86 ISA serial ACPI implementation.

Also remove _CCA because the emulated UART does not support DMA, and add _STA = 0x0f to indicate that the device is present, enabled, visible, and functioning.

---
 hw/loongarch/virt-acpi-build.c | 12 +-----------
 1 file changed, 1 insertion(+), 11 deletions(-)
hw/loongarch/virt-acpi-build.c +1 -11
index 54965f0..55c7641 100644
@@ -314,7 +314,6 @@ static void build_uart_device_aml(Aml *table, int index)
 {
     Aml *dev;
     Aml *crs;
-    Aml *pkg0, *pkg1, *pkg2;
     Aml *scope;
     uint32_t uart_irq;
     uint64_t base;
@@ -325,7 +324,7 @@ static void build_uart_device_aml(Aml *table, int index)
     dev = aml_device("COM%d", index);
     aml_append(dev, aml_name_decl("_HID", aml_string("PNP0501")));
     aml_append(dev, aml_name_decl("_UID", aml_int(index)));
-    aml_append(dev, aml_name_decl("_CCA", aml_int(1)));
+    aml_append(dev, aml_name_decl("_STA", aml_int(0x0f)));
     crs = aml_resource_template();
     aml_append(crs,
         aml_qword_memory(AML_POS_DECODE, AML_MIN_FIXED, AML_MAX_FIXED,
@@ -335,15 +334,6 @@ static void build_uart_device_aml(Aml *table, int index)
     aml_append(crs, aml_interrupt(AML_CONSUMER, AML_LEVEL, AML_ACTIVE_HIGH,
                                   AML_SHARED, &uart_irq, 1));
     aml_append(dev, aml_name_decl("_CRS", crs));
-    pkg0 = aml_package(0x2);
-    aml_append(pkg0, aml_int(0x05F5E100));
-    aml_append(pkg0, aml_string("clock-frenquency"));
-    pkg1 = aml_package(0x1);
-    aml_append(pkg1, pkg0);
-    pkg2 = aml_package(0x2);
-    aml_append(pkg2, aml_touuid("DAFFD814-6EBA-4D8C-8A91-BC9BBF4AA301"));
-    aml_append(pkg2, pkg1);
-    aml_append(dev, aml_name_decl("_DSD", pkg2));
     aml_append(scope, dev);
     aml_append(table, scope);
 }
Signature · 1 line
2.56.0
#3 lore raw

Re: [PATCH v4 2/4] hw/loongarch/virt-acpi-build: Drop UART _DSD clock and add _STA

Quoted 12 lines · On Thu, 22 Oct 2026 15:22:36 +0800 pillow <[email protected]> wrote:

The UART _DSD clock property contains a typo ("clock-frenquency") and has its key/value order reversed. It also specifies a 100 MHz clock, which does not match the emulated UART.

QEMU's UART model uses baudbase = 115200, corresponding to a clock frequency of 1,843,200 Hz. The Linux 8250 PnP driver uses the same frequency by default when no clock is specified.

Since the default already matches the UART model, there is no need to provide an explicit clock property. Drop it from _DSD, consistent with the existing x86 ISA serial ACPI implementation.

Quoted 6 lines

Also remove _CCA because the emulated UART does not support DMA, and add _STA = 0x0f to indicate that the device is present, enabled, visible, and functioning.

do not put several different changes together
split it up on several patches

Quoted 41 lines
---
 hw/loongarch/virt-acpi-build.c | 12 +-----------
 1 file changed, 1 insertion(+), 11 deletions(-)
hw/loongarch/virt-acpi-build.c +1 -11
index 54965f0..55c7641 100644
@@ -314,7 +314,6 @@ static void build_uart_device_aml(Aml *table, int index)
 {
     Aml *dev;
     Aml *crs;
-    Aml *pkg0, *pkg1, *pkg2;
     Aml *scope;
     uint32_t uart_irq;
     uint64_t base;
@@ -325,7 +324,7 @@ static void build_uart_device_aml(Aml *table, int index)
     dev = aml_device("COM%d", index);
     aml_append(dev, aml_name_decl("_HID", aml_string("PNP0501")));
     aml_append(dev, aml_name_decl("_UID", aml_int(index)));
-    aml_append(dev, aml_name_decl("_CCA", aml_int(1)));
+    aml_append(dev, aml_name_decl("_STA", aml_int(0x0f)));
     crs = aml_resource_template();
     aml_append(crs,
         aml_qword_memory(AML_POS_DECODE, AML_MIN_FIXED, AML_MAX_FIXED,
@@ -335,15 +334,6 @@ static void build_uart_device_aml(Aml *table, int index)
     aml_append(crs, aml_interrupt(AML_CONSUMER, AML_LEVEL, AML_ACTIVE_HIGH,
                                   AML_SHARED, &uart_irq, 1));
     aml_append(dev, aml_name_decl("_CRS", crs));
-    pkg0 = aml_package(0x2);
-    aml_append(pkg0, aml_int(0x05F5E100));
-    aml_append(pkg0, aml_string("clock-frenquency"));
-    pkg1 = aml_package(0x1);
-    aml_append(pkg1, pkg0);
-    pkg2 = aml_package(0x2);
-    aml_append(pkg2, aml_touuid("DAFFD814-6EBA-4D8C-8A91-BC9BBF4AA301"));
-    aml_append(pkg2, pkg1);
-    aml_append(dev, aml_name_decl("_DSD", pkg2));
     aml_append(scope, dev);
     aml_append(table, scope);
 }
#4 lore raw

Re: [PATCH v4 2/4] hw/loongarch/virt-acpi-build: Drop UART _DSD clock and add _STA

In reply to pillow

On Thu, 22 Oct 2026 15:22:36 +0800
pillow <[email protected]> wrote:

...

Quoted 1 line
(quoted diff) +0 -0
@@ -325,7 +324,7 @@ static void build_uart_device_aml(Aml *table, int index)

...

Quoted 1 line

+ aml_append(dev, aml_name_decl("_STA", aml_int(0x0f)));

also is it really necessary? Doesn't missing _STA imply 0xF already?

Quoted 3 lines

crs = aml_resource_template();
aml_append(crs,
aml_qword_memory(AML_POS_DECODE, AML_MIN_FIXED, AML_MAX_FIXED,

author
#5 lore raw

Re: [PATCH v4 2/4] hw/loongarch/virt-acpi-build: Drop UART _DSD clock and add _STA

Hi Igor,

The _STA method was added in response to Bibo's review comment on the original patch, where
he explicitly suggested adding _STA.

I understand your concern that omitting _STA already implies 0x0f. However, the two review
comments seem to suggest different approaches.

I'm happy to split the changes into separate patches as required. For _STA, though, I'd
appreciate it if we could first agree on whether it should be added or omitted, so I have a clear
direction for the next version.

Thanks,
pillow

Quoted 16 lines · Igor Mammedov

On Thu, 22 Oct 2026 15:22:36 +0800
pillow <[email protected]> wrote:

...

Review static void build_uart_device_aml(Aml *table, int

Quoted 1 line
(quoted diff) +0 -0
@@ -325,7 +324,7 @@ static void build_uart_device_aml(Aml *table, int

index)
...

hw/loongarch/virt-acpi-build.c static void build_uart_device_aml(Aml *table, int index) · line 327

Quoted 1 line
hw/loongarch/virt-acpi-build.c +1 -0
+    aml_append(dev, aml_name_decl("_STA", aml_int(0x0f)));

also is it really necessary? Doesn't missing _STA imply 0xF already?

Quoted 3 lines
hw/loongarch/virt-acpi-build.c +0 -0
     crs = aml_resource_template();
     aml_append(crs,
         aml_qword_memory(AML_POS_DECODE, AML_MIN_FIXED, AML_MAX_FIXED,
author
#6 lore raw

Re: [PATCH v4 2/4] hw/loongarch/virt-acpi-build: Drop UART _DSD clock and add _STA

Hi Igor,

One additional observation: QEMU's x86 ISA serial implementation explicitly defines _STA =
0x0f in serial_isa_build_aml(), rather than relying on the ACPI default:

https://github.com/qemu/qemu/blob/8967b2fe1b2aaae3c29e207d85fab901d580a2dc/hw/char/serial-isa.c#L101

I think following the same approach for LoongArch UART would be reasonable for consistency.

Thanks,
pillow

Quoted 37 lines · way sorry

Hi Igor,

The _STA method was added in response to Bibo's review comment on the original patch, where
he explicitly suggested adding _STA.

I understand your concern that omitting _STA already implies 0x0f. However, the two review
comments seem to suggest different approaches.

I'm happy to split the changes into separate patches as required. For _STA, though, I'd
appreciate it if we could first agree on whether it should be added or omitted, so I have a clear
direction for the next version.

Thanks,
pillow

Quoted 16 lines · Igor Mammedov

On Thu, 22 Oct 2026 15:22:36 +0800
pillow <[email protected]> wrote:

...

Review static void build_uart_device_aml(Aml *table, int

Quoted 1 line
(quoted diff) +0 -0
@@ -325,7 +324,7 @@ static void build_uart_device_aml(Aml *table, int

index)
...

hw/loongarch/virt-acpi-build.c static void build_uart_device_aml(Aml *table, int index) · line 327

Quoted 1 line
hw/loongarch/virt-acpi-build.c +1 -0
+    aml_append(dev, aml_name_decl("_STA", aml_int(0x0f)));

also is it really necessary? Doesn't missing _STA imply 0xF already?

Quoted 3 lines
hw/loongarch/virt-acpi-build.c +0 -0
     crs = aml_resource_template();
     aml_append(crs,
         aml_qword_memory(AML_POS_DECODE, AML_MIN_FIXED, AML_MAX_FIXED,
#7 lore raw

Re: [PATCH v4 2/4] hw/loongarch/virt-acpi-build: Drop UART _DSD clock and add _STA

Quoted 10 lines · On Thu, 22 Oct 2026 17:25:00 +0800 way sorry <[email protected]> wrote:

Hi Igor,

One additional observation: QEMU's x86 ISA serial implementation explicitly defines _STA =
0x0f in serial_isa_build_aml(), rather than relying on the ACPI default:

https://github.com/qemu/qemu/blob/8967b2fe1b2aaae3c29e207d85fab901d580a2dc/hw/char/serial-isa.c#L101

I think following the same approach for LoongArch UART would be reasonable for consistency.

preexisting code in this case is not a good example to follow.

if it works without adding unnecessary stuff, do not add it.

DSD and CCA changes are also unrelated => separate patches

Quoted 43 lines

Thanks,
pillow

Quoted 37 lines · way sorry

Hi Igor,

The _STA method was added in response to Bibo's review comment on the original patch, where
he explicitly suggested adding _STA.

I understand your concern that omitting _STA already implies 0x0f. However, the two review
comments seem to suggest different approaches.

I'm happy to split the changes into separate patches as required. For _STA, though, I'd
appreciate it if we could first agree on whether it should be added or omitted, so I have a clear
direction for the next version.

Thanks,
pillow

Quoted 16 lines · Igor Mammedov

On Thu, 22 Oct 2026 15:22:36 +0800
pillow <[email protected]> wrote:

...

Review static void build_uart_device_aml(Aml *table, int

Quoted 1 line
(quoted diff) +0 -0
@@ -325,7 +324,7 @@ static void build_uart_device_aml(Aml *table, int  

index)
...

hw/loongarch/virt-acpi-build.c static void build_uart_device_aml(Aml *table, int index) · line 327

Quoted 1 line
hw/loongarch/virt-acpi-build.c +1 -0
+    aml_append(dev, aml_name_decl("_STA", aml_int(0x0f)));  

also is it really necessary? Doesn't missing _STA imply 0xF already?

Quoted 3 lines
hw/loongarch/virt-acpi-build.c +0 -0
     crs = aml_resource_template();
     aml_append(crs,
         aml_qword_memory(AML_POS_DECODE, AML_MIN_FIXED, AML_MAX_FIXED,  
author
#8 lore raw

PATCH v4 3/4 tests/data/acpi/loongarch64: Update expected DSDT.*

In reply to pillow

--- tests/data/acpi/loongarch64/virt/DSDT (before)
+++ tests/data/acpi/loongarch64/virt/DSDT (after)
@@ -6,7 +6,7 @@
{
Name (_HID, "PNP0501" /* 16550A-compatible COM Serial Port */) // _HID: Hardware ID Name (_UID, Zero) // _UID: Unique ID
- Name (_CCA, One) // _CCA: Cache Coherency Attribute
+ Name (_STA, 0x0F) // _STA: Status
Name (_CRS, ResourceTemplate () // _CRS: Current Resource Settings
{
QWordMemory (ResourceProducer, PosDecode, MinFixed, MaxFixed, NonCacheable, ReadWrite,
@@ -21,18 +21,6 @@
0x00000042,
}
})
- Name (_DSD, Package (0x02) // _DSD: Device-Specific Data
- {
- ToUUID ("daffd814-6eba-4d8c-8a91-bc9bbf4aa301") /* Device Properties for _DSD */,
- Package (0x01)
- {
- Package (0x02)
- {
- 0x05F5E100,
- "clock-frenquency"
- }
- }
- })
}
}

@@ -42,7 +30,7 @@
{
Name (_HID, "PNP0501" /* 16550A-compatible COM Serial Port */) // _HID: Hardware ID Name (_UID, One) // _UID: Unique ID
- Name (_CCA, One) // _CCA: Cache Coherency Attribute
+ Name (_STA, 0x0F) // _STA: Status
Name (_CRS, ResourceTemplate () // _CRS: Current Resource Settings
{
QWordMemory (ResourceProducer, PosDecode, MinFixed, MaxFixed, NonCacheable, ReadWrite,
@@ -57,18 +45,6 @@
0x00000043,
}
})
- Name (_DSD, Package (0x02) // _DSD: Device-Specific Data
- {
- ToUUID ("daffd814-6eba-4d8c-8a91-bc9bbf4aa301") /* Device Properties for _DSD */,
- Package (0x01)
- {
- Package (0x02)
- {
- 0x05F5E100,
- "clock-frenquency"
- }
- }
- })
}
}

@@ -78,7 +54,7 @@
{
Name (_HID, "PNP0501" /* 16550A-compatible COM Serial Port */) // _HID: Hardware ID Name (_UID, 0x02) // _UID: Unique ID
- Name (_CCA, One) // _CCA: Cache Coherency Attribute
+ Name (_STA, 0x0F) // _STA: Status
Name (_CRS, ResourceTemplate () // _CRS: Current Resource Settings
{
QWordMemory (ResourceProducer, PosDecode, MinFixed, MaxFixed, NonCacheable, ReadWrite,
@@ -93,18 +69,6 @@
0x00000044,
}
})
- Name (_DSD, Package (0x02) // _DSD: Device-Specific Data
- {
- ToUUID ("daffd814-6eba-4d8c-8a91-bc9bbf4aa301") /* Device Properties for _DSD */,
- Package (0x01)
- {
- Package (0x02)
- {
- 0x05F5E100,
- "clock-frenquency"
- }
- }
- })
}
}

@@ -114,7 +78,7 @@
{
Name (_HID, "PNP0501" /* 16550A-compatible COM Serial Port */) // _HID: Hardware ID Name (_UID, 0x03) // _UID: Unique ID
- Name (_CCA, One) // _CCA: Cache Coherency Attribute
+ Name (_STA, 0x0F) // _STA: Status
Name (_CRS, ResourceTemplate () // _CRS: Current Resource Settings
{
QWordMemory (ResourceProducer, PosDecode, MinFixed, MaxFixed, NonCacheable, ReadWrite,
@@ -127,18 +91,6 @@
Interrupt (ResourceConsumer, Level, ActiveHigh, Shared, ,, )
{
0x00000045,
- }
- })
- Name (_DSD, Package (0x02) // _DSD: Device-Specific Data
- {
- ToUUID ("daffd814-6eba-4d8c-8a91-bc9bbf4aa301") /* Device Properties for _DSD */,
- Package (0x01)
- {
- Package (0x02)
- {
- 0x05F5E100,
- "clock-frenquency"
- }
}
})
}

---
 tests/data/acpi/loongarch64/virt/DSDT         | Bin 4603 -> 4379 bytes
 tests/data/acpi/loongarch64/virt/DSDT.memhp   | Bin 5824 -> 5600 bytes
 tests/data/acpi/loongarch64/virt/DSDT.numamem | Bin 4609 -> 4385 bytes
 .../data/acpi/loongarch64/virt/DSDT.topology  | Bin 4905 -> 4681 bytes
 tests/qtest/bios-tables-test-allowed-diff.h   |   4 ----
 5 files changed, 4 deletions(-)
tests/data/acpi/loongarch64/virt/DSDT binary +0 -0
index 09aa903c4e875f541223e36f59b28e101599df20..686d9078e4d61558d65bdcfec76a2428b83ef56d 100644
GIT binary patch
tests/data/acpi/loongarch64/virt/DSDT.memhp binary +0 -0
index a069d6878fb45fa6b0e6342eedb0eb3d25eb20da..fb2104170a134bdd414f9f5456f2e37e3489b749 100644
GIT binary patch
tests/data/acpi/loongarch64/virt/DSDT.numamem binary +0 -0
index 78ece52f57a383db128c7d1a08526e15ab911bb7..62374112f9e83ead0be549c8e17bdfe7941017e3 100644
GIT binary patch
tests/data/acpi/loongarch64/virt/DSDT.topology binary +0 -0
index 7ab23f47cc82dd7bc1975e17893a8cd61039e66d..9c37939f91334659662ec9f6dc1f941572029e7f 100644
GIT binary patch
tests/qtest/bios-tables-test-allowed-diff.h +0 -4
index 2ed837f..dfb8523 100644
@@ -1,5 +1 @@
 /* List of comma-separated changed AML files to ignore */
-"tests/data/acpi/loongarch64/virt/DSDT",
-"tests/data/acpi/loongarch64/virt/DSDT.memhp",
-"tests/data/acpi/loongarch64/virt/DSDT.numamem",
-"tests/data/acpi/loongarch64/virt/DSDT.topology",
Signature · 1 line
2.56.0
author
#9 lore raw

PATCH v4 4/4 hw/loongarch/virt: Fix UART clock frequency in FDT

In reply to pillow

The UART uses baudbase = 115200, corresponding to an input clock of 1843200 Hz. Update the FDT clock-frequency property to match the model.

---
 hw/loongarch/virt-fdt-build.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/loongarch/virt-fdt-build.c +1 -1
index c6f5d02..7be71e2 100644
@@ -474,7 +474,7 @@ static void fdt_add_uart_node(LoongArchVirtMachineState *lvms,
     qemu_fdt_add_subnode(ms->fdt, nodename);
     qemu_fdt_setprop_string(ms->fdt, nodename, "compatible", "ns16550a");
     qemu_fdt_setprop_cells(ms->fdt, nodename, "reg", 0x0, base, 0x0, size);
-    qemu_fdt_setprop_cell(ms->fdt, nodename, "clock-frequency", 100000000);
+    qemu_fdt_setprop_cell(ms->fdt, nodename, "clock-frequency", 1843200);
     if (chosen) {
         qemu_fdt_setprop_string(ms->fdt, "/chosen", "stdout-path", nodename);
     }
Signature · 1 line
2.56.0