[PATCH V3 1/2] hw/loongarch: add rtc acpi table

Xianglai Li posted 2 patches 2 days, 13 hours ago
Maintainers: Song Gao <gaosong@loongson.cn>, Bibo Mao <maobibo@loongson.cn>, Jiaxun Yang <jiaxun.yang@flygoat.com>
[PATCH V3 1/2] hw/loongarch: add rtc acpi table
Posted by Xianglai Li 2 days, 13 hours ago
Add the acpi table to the loongson rtc hardware so that the virtual machine
kernel can use the loongson RTC-related drivers.

Signed-off-by: Xianglai Li <lixianglai@loongson.cn>
---
Cc: Song Gao <gaosong@loongson.cn> 
Cc: Bibo Mao <maobibo@loongson.cn> 
Cc: Jiaxun Yang <jiaxun.yang@flygoat.com> 
Cc: Huacai Chen <zltjiangshi@gmail.com>

 hw/loongarch/virt-acpi-build.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/hw/loongarch/virt-acpi-build.c b/hw/loongarch/virt-acpi-build.c
index 3e34bedcd6..42820001d7 100644
--- a/hw/loongarch/virt-acpi-build.c
+++ b/hw/loongarch/virt-acpi-build.c
@@ -460,6 +460,30 @@ static void acpi_dsdt_add_tpm(Aml *scope, LoongArchVirtMachineState *vms)
 }
 #endif
 
+static void acpi_dsdt_add_rtc(Aml *scope)
+{
+    Aml *dev = aml_device("RTC");
+
+    aml_append(dev, aml_name_decl("_HID", aml_string("LOON0001")));
+    aml_append(dev, aml_name_decl("_UID", aml_int(0)));
+
+    Aml *crs = aml_resource_template();
+    aml_append(crs,
+        aml_qword_memory(AML_POS_DECODE, AML_MIN_FIXED, AML_MAX_FIXED,
+                         AML_NON_CACHEABLE, AML_READ_WRITE,
+                         0, VIRT_RTC_REG_BASE,
+                         VIRT_RTC_REG_BASE + VIRT_RTC_LEN - 1,
+                         0, VIRT_RTC_LEN));
+    /*
+     * The virtual machine model does not support suspend and wake-up,
+     * and rtc is no longer the wake-up source. Therefore, the current
+     * rtc table no longer provides the rtc alarm interrupt number to
+     * avoid the software initializing alarm.
+     */
+    aml_append(dev, aml_name_decl("_CRS", crs));
+    aml_append(scope, dev);
+}
+
 /* build DSDT */
 static void
 build_dsdt(GArray *table_data, BIOSLinker *linker, MachineState *machine)
@@ -475,6 +499,7 @@ build_dsdt(GArray *table_data, BIOSLinker *linker, MachineState *machine)
     for (i = 0; i < VIRT_UART_COUNT; i++) {
         build_uart_device_aml(dsdt, i);
     }
+    acpi_dsdt_add_rtc(dsdt);
     build_pci_device_aml(dsdt, lvms);
     build_la_ged_aml(dsdt, machine);
     build_flash_aml(dsdt, lvms);
-- 
2.39.1
Re: [PATCH V3 1/2] hw/loongarch: add rtc acpi table
Posted by Jonathan Cameron via qemu development 2 days, 4 hours ago
On Fri, 20 Mar 2026 08:36:52 +0800
Xianglai Li <lixianglai@loongson.cn> wrote:

> Add the acpi table to the loongson rtc hardware so that the virtual machine
> kernel can use the loongson RTC-related drivers.
> 
> Signed-off-by: Xianglai Li <lixianglai@loongson.cn>

Hi

No data updates for

tests/dta/acpi/loongarch64/virt?

> ---
> Cc: Song Gao <gaosong@loongson.cn> 
> Cc: Bibo Mao <maobibo@loongson.cn> 
> Cc: Jiaxun Yang <jiaxun.yang@flygoat.com> 
> Cc: Huacai Chen <zltjiangshi@gmail.com>
> 
>  hw/loongarch/virt-acpi-build.c | 25 +++++++++++++++++++++++++
>  1 file changed, 25 insertions(+)
> 
> diff --git a/hw/loongarch/virt-acpi-build.c b/hw/loongarch/virt-acpi-build.c
> index 3e34bedcd6..42820001d7 100644
> --- a/hw/loongarch/virt-acpi-build.c
> +++ b/hw/loongarch/virt-acpi-build.c
> @@ -460,6 +460,30 @@ static void acpi_dsdt_add_tpm(Aml *scope, LoongArchVirtMachineState *vms)
>  }
>  #endif
>  
> +static void acpi_dsdt_add_rtc(Aml *scope)
> +{
> +    Aml *dev = aml_device("RTC");
> +
> +    aml_append(dev, aml_name_decl("_HID", aml_string("LOON0001")));
> +    aml_append(dev, aml_name_decl("_UID", aml_int(0)));
> +
> +    Aml *crs = aml_resource_template();
> +    aml_append(crs,
> +        aml_qword_memory(AML_POS_DECODE, AML_MIN_FIXED, AML_MAX_FIXED,
> +                         AML_NON_CACHEABLE, AML_READ_WRITE,
> +                         0, VIRT_RTC_REG_BASE,
> +                         VIRT_RTC_REG_BASE + VIRT_RTC_LEN - 1,
> +                         0, VIRT_RTC_LEN));
> +    /*
> +     * The virtual machine model does not support suspend and wake-up,
> +     * and rtc is no longer the wake-up source. Therefore, the current
> +     * rtc table no longer provides the rtc alarm interrupt number to
> +     * avoid the software initializing alarm.
> +     */
> +    aml_append(dev, aml_name_decl("_CRS", crs));
> +    aml_append(scope, dev);
> +}
> +
>  /* build DSDT */
>  static void
>  build_dsdt(GArray *table_data, BIOSLinker *linker, MachineState *machine)
> @@ -475,6 +499,7 @@ build_dsdt(GArray *table_data, BIOSLinker *linker, MachineState *machine)
>      for (i = 0; i < VIRT_UART_COUNT; i++) {
>          build_uart_device_aml(dsdt, i);
>      }
> +    acpi_dsdt_add_rtc(dsdt);
>      build_pci_device_aml(dsdt, lvms);
>      build_la_ged_aml(dsdt, machine);
>      build_flash_aml(dsdt, lvms);
Re: [PATCH V3 1/2] hw/loongarch: add rtc acpi table
Posted by lixianglai 2 days, 4 hours ago
Hi Jonathan Cameron :
> On Fri, 20 Mar 2026 08:36:52 +0800
> Xianglai Li <lixianglai@loongson.cn> wrote:
>
>> Add the acpi table to the loongson rtc hardware so that the virtual machine
>> kernel can use the loongson RTC-related drivers.
>>
>> Signed-off-by: Xianglai Li <lixianglai@loongson.cn>
> Hi
>
> No data updates for
>
> tests/dta/acpi/loongarch64/virt?
Oh! I missed it. I will fix it in the next patch.

Thanks!
Xianglai.

>> ---
>> Cc: Song Gao <gaosong@loongson.cn>
>> Cc: Bibo Mao <maobibo@loongson.cn>
>> Cc: Jiaxun Yang <jiaxun.yang@flygoat.com>
>> Cc: Huacai Chen <zltjiangshi@gmail.com>
>>
>>   hw/loongarch/virt-acpi-build.c | 25 +++++++++++++++++++++++++
>>   1 file changed, 25 insertions(+)
>>
>> diff --git a/hw/loongarch/virt-acpi-build.c b/hw/loongarch/virt-acpi-build.c
>> index 3e34bedcd6..42820001d7 100644
>> --- a/hw/loongarch/virt-acpi-build.c
>> +++ b/hw/loongarch/virt-acpi-build.c
>> @@ -460,6 +460,30 @@ static void acpi_dsdt_add_tpm(Aml *scope, LoongArchVirtMachineState *vms)
>>   }
>>   #endif
>>   
>> +static void acpi_dsdt_add_rtc(Aml *scope)
>> +{
>> +    Aml *dev = aml_device("RTC");
>> +
>> +    aml_append(dev, aml_name_decl("_HID", aml_string("LOON0001")));
>> +    aml_append(dev, aml_name_decl("_UID", aml_int(0)));
>> +
>> +    Aml *crs = aml_resource_template();
>> +    aml_append(crs,
>> +        aml_qword_memory(AML_POS_DECODE, AML_MIN_FIXED, AML_MAX_FIXED,
>> +                         AML_NON_CACHEABLE, AML_READ_WRITE,
>> +                         0, VIRT_RTC_REG_BASE,
>> +                         VIRT_RTC_REG_BASE + VIRT_RTC_LEN - 1,
>> +                         0, VIRT_RTC_LEN));
>> +    /*
>> +     * The virtual machine model does not support suspend and wake-up,
>> +     * and rtc is no longer the wake-up source. Therefore, the current
>> +     * rtc table no longer provides the rtc alarm interrupt number to
>> +     * avoid the software initializing alarm.
>> +     */
>> +    aml_append(dev, aml_name_decl("_CRS", crs));
>> +    aml_append(scope, dev);
>> +}
>> +
>>   /* build DSDT */
>>   static void
>>   build_dsdt(GArray *table_data, BIOSLinker *linker, MachineState *machine)
>> @@ -475,6 +499,7 @@ build_dsdt(GArray *table_data, BIOSLinker *linker, MachineState *machine)
>>       for (i = 0; i < VIRT_UART_COUNT; i++) {
>>           build_uart_device_aml(dsdt, i);
>>       }
>> +    acpi_dsdt_add_rtc(dsdt);
>>       build_pci_device_aml(dsdt, lvms);
>>       build_la_ged_aml(dsdt, machine);
>>       build_flash_aml(dsdt, lvms);