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

Xianglai Li posted 2 patches 5 months ago
Maintainers: Song Gao <gaosong@loongson.cn>, Bibo Mao <maobibo@loongson.cn>, Jiaxun Yang <jiaxun.yang@flygoat.com>
[PATCH V1 2/2] hw/loongarch: add rtc acpi table
Posted by Xianglai Li 5 months 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: Bibo Mao <maobibo@loongson.cn>
Cc: Song Gao <gaosong@loongson.cn>
Cc: Jiaxun Yang <jiaxun.yang@flygoat.com>
Cc: Xianglai Li <lixianglai@loongson.cn>

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

diff --git a/hw/loongarch/virt-acpi-build.c b/hw/loongarch/virt-acpi-build.c
index 2cd2d9d842..2cfc5421c5 100644
--- a/hw/loongarch/virt-acpi-build.c
+++ b/hw/loongarch/virt-acpi-build.c
@@ -473,6 +473,29 @@ static void acpi_dsdt_add_tpm(Aml *scope, LoongArchVirtMachineState *vms)
 }
 #endif
 
+static void acpi_dsdt_add_rtc(Aml *scope)
+{
+    uint32_t rtc_irq = VIRT_RTC_IRQ;
+    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));
+    aml_append(crs,
+               aml_interrupt(AML_CONSUMER, AML_EDGE, AML_ACTIVE_HIGH,
+                             AML_EXCLUSIVE, &rtc_irq, 1));
+
+    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)
@@ -488,6 +511,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 V1 2/2] hw/loongarch: add rtc acpi table
Posted by Bibo Mao 5 months ago

On 2025/6/13 上午9:31, Xianglai Li 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>
> ---
> Cc: Bibo Mao <maobibo@loongson.cn>
> Cc: Song Gao <gaosong@loongson.cn>
> Cc: Jiaxun Yang <jiaxun.yang@flygoat.com>
> Cc: Xianglai Li <lixianglai@loongson.cn>
> 
>   hw/loongarch/virt-acpi-build.c | 24 ++++++++++++++++++++++++
>   1 file changed, 24 insertions(+)
> 
> diff --git a/hw/loongarch/virt-acpi-build.c b/hw/loongarch/virt-acpi-build.c
> index 2cd2d9d842..2cfc5421c5 100644
> --- a/hw/loongarch/virt-acpi-build.c
> +++ b/hw/loongarch/virt-acpi-build.c
> @@ -473,6 +473,29 @@ static void acpi_dsdt_add_tpm(Aml *scope, LoongArchVirtMachineState *vms)
>   }
>   #endif
>   
> +static void acpi_dsdt_add_rtc(Aml *scope)
> +{
> +    uint32_t rtc_irq = VIRT_RTC_IRQ;
> +    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));
> +    aml_append(crs,
> +               aml_interrupt(AML_CONSUMER, AML_EDGE, AML_ACTIVE_HIGH,
> +                             AML_EXCLUSIVE, &rtc_irq, 1));
> +
> +    aml_append(dev, aml_name_decl("_CRS", crs));
> +    aml_append(scope, dev);
> +}
> +
The rtc loongson driver drivers/rtc/rtc-loongson.c is bond with acpi pm1 
device since rtc device is wake-up source on physical machine, however 
acpi ged device rather than pm1 device is used on virt machine.

I think firstly we should submit patch to rtc loongson driver 
drivers/rtc/rtc-loongson.c so that it supports non acpi pm1 device, then 
submit rtc acpi dsdt table.

Regards
Bibo Mao
>   /* build DSDT */
>   static void
>   build_dsdt(GArray *table_data, BIOSLinker *linker, MachineState *machine)
> @@ -488,6 +511,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 V1 2/2] hw/loongarch: add rtc acpi table
Posted by Bibo Mao 5 months ago
Xianglai,

On 2025/6/13 上午9:31, Xianglai Li wrote:
> Add the acpi table to the loongson rtc hardware
> so that the virtual machine kernel can use the
> loongson RTC-related drivers.
One line of the comments is no more than 75 bytes, it seems that it is 
far less than 75 bytes.

> 
> Signed-off-by: Xianglai Li <lixianglai@loongson.cn>
> ---
> Cc: Bibo Mao <maobibo@loongson.cn>
> Cc: Song Gao <gaosong@loongson.cn>
> Cc: Jiaxun Yang <jiaxun.yang@flygoat.com>
> Cc: Xianglai Li <lixianglai@loongson.cn>
> 
>   hw/loongarch/virt-acpi-build.c | 24 ++++++++++++++++++++++++
>   1 file changed, 24 insertions(+)
> 
> diff --git a/hw/loongarch/virt-acpi-build.c b/hw/loongarch/virt-acpi-build.c
> index 2cd2d9d842..2cfc5421c5 100644
> --- a/hw/loongarch/virt-acpi-build.c
> +++ b/hw/loongarch/virt-acpi-build.c
> @@ -473,6 +473,29 @@ static void acpi_dsdt_add_tpm(Aml *scope, LoongArchVirtMachineState *vms)
>   }
>   #endif
>   
> +static void acpi_dsdt_add_rtc(Aml *scope)
> +{
> +    uint32_t rtc_irq = VIRT_RTC_IRQ;
> +    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));
> +    aml_append(crs,
> +               aml_interrupt(AML_CONSUMER, AML_EDGE, AML_ACTIVE_HIGH,
> +                             AML_EXCLUSIVE, &rtc_irq, 1));
> +
> +    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)
> @@ -488,6 +511,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);
> 
Otherwise looks good to me except comments alignment.

Reviewed-by: Bibo Mao <maobibo@loongson.cn>