public inbox for qemu-devel@nongnu.org
 help / color / mirror / Atom feed
* [PATCH V2] hw/loongarch: add rtc acpi table
@ 2026-03-12  2:13 Xianglai Li
  2026-03-12  3:55 ` gaosong
  2026-03-17  1:32 ` chen huacai
  0 siblings, 2 replies; 7+ messages in thread
From: Xianglai Li @ 2026-03-12  2:13 UTC (permalink / raw)
  To: qemu-devel, lixianglai; +Cc: Song Gao, Bibo Mao, Jiaxun Yang

Add the acpi table to the loongson rtc hardware so that the virtual machine
kernel can use the loongson RTC-related drivers.

Delete the interrupt information in the rtc fdt table.

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> 

change:
V1->V2:
1.Add a comment to explain why the acpi table no longer provides interrupt numbers
2.Delete the interrupt number from the rtc fdt table

 hw/loongarch/virt-acpi-build.c | 25 +++++++++++++++++++++++++
 hw/loongarch/virt-fdt-build.c  | 16 ++++++++--------
 2 files changed, 33 insertions(+), 8 deletions(-)

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);
diff --git a/hw/loongarch/virt-fdt-build.c b/hw/loongarch/virt-fdt-build.c
index 6c06b36fca..42f014a7bd 100644
--- a/hw/loongarch/virt-fdt-build.c
+++ b/hw/loongarch/virt-fdt-build.c
@@ -458,8 +458,7 @@ static void fdt_add_uart_node(LoongArchVirtMachineState *lvms,
     g_free(nodename);
 }
 
-static void fdt_add_rtc_node(LoongArchVirtMachineState *lvms,
-                             uint32_t *pch_pic_phandle)
+static void fdt_add_rtc_node(LoongArchVirtMachineState *lvms)
 {
     char *nodename;
     hwaddr base = VIRT_RTC_REG_BASE;
@@ -470,12 +469,13 @@ static void fdt_add_rtc_node(LoongArchVirtMachineState *lvms,
     qemu_fdt_add_subnode(ms->fdt, nodename);
     qemu_fdt_setprop_string(ms->fdt, nodename, "compatible",
                             "loongson,ls7a-rtc");
+    /*
+     * 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.
+     */
     qemu_fdt_setprop_sized_cells(ms->fdt, nodename, "reg", 2, base, 2, size);
-    qemu_fdt_setprop_cells(ms->fdt, nodename, "interrupts",
-                           VIRT_RTC_IRQ - VIRT_GSI_BASE ,
-                           FDT_IRQ_TYPE_LEVEL_HIGH);
-    qemu_fdt_setprop_cell(ms->fdt, nodename, "interrupt-parent",
-                          *pch_pic_phandle);
     g_free(nodename);
 }
 
@@ -550,7 +550,7 @@ void virt_fdt_setup(LoongArchVirtMachineState *lvms)
         fdt_add_uart_node(lvms, &pch_pic_phandle, base, irq, i == 0);
     }
 
-    fdt_add_rtc_node(lvms, &pch_pic_phandle);
+    fdt_add_rtc_node(lvms);
     fdt_add_ged_reset(lvms);
     platform_bus_add_all_fdt_nodes(machine->fdt, "/platic",
                                    VIRT_PLATFORM_BUS_BASEADDRESS,
-- 
2.39.1



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH V2] hw/loongarch: add rtc acpi table
  2026-03-12  2:13 [PATCH V2] hw/loongarch: add rtc acpi table Xianglai Li
@ 2026-03-12  3:55 ` gaosong
  2026-03-12  8:19   ` lixianglai
  2026-03-17  1:32 ` chen huacai
  1 sibling, 1 reply; 7+ messages in thread
From: gaosong @ 2026-03-12  3:55 UTC (permalink / raw)
  To: Xianglai Li, qemu-devel; +Cc: Bibo Mao, Jiaxun Yang

在 2026/3/12 上午10:13, Xianglai Li 写道:
> Add the acpi table to the loongson rtc hardware so that the virtual machine
> kernel can use the loongson RTC-related drivers.
>
> Delete the interrupt information in the rtc fdt table.
>
> 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>
>
> change:
> V1->V2:
> 1.Add a comment to explain why the acpi table no longer provides interrupt numbers
> 2.Delete the interrupt number from the rtc fdt table

It would be better to move point 2 to the new patch.

Thanks.
Song Gao

>   hw/loongarch/virt-acpi-build.c | 25 +++++++++++++++++++++++++
>   hw/loongarch/virt-fdt-build.c  | 16 ++++++++--------
>   2 files changed, 33 insertions(+), 8 deletions(-)
>
> 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);
> diff --git a/hw/loongarch/virt-fdt-build.c b/hw/loongarch/virt-fdt-build.c
> index 6c06b36fca..42f014a7bd 100644
> --- a/hw/loongarch/virt-fdt-build.c
> +++ b/hw/loongarch/virt-fdt-build.c
> @@ -458,8 +458,7 @@ static void fdt_add_uart_node(LoongArchVirtMachineState *lvms,
>       g_free(nodename);
>   }
>   
> -static void fdt_add_rtc_node(LoongArchVirtMachineState *lvms,
> -                             uint32_t *pch_pic_phandle)
> +static void fdt_add_rtc_node(LoongArchVirtMachineState *lvms)
>   {
>       char *nodename;
>       hwaddr base = VIRT_RTC_REG_BASE;
> @@ -470,12 +469,13 @@ static void fdt_add_rtc_node(LoongArchVirtMachineState *lvms,
>       qemu_fdt_add_subnode(ms->fdt, nodename);
>       qemu_fdt_setprop_string(ms->fdt, nodename, "compatible",
>                               "loongson,ls7a-rtc");
> +    /*
> +     * 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.
> +     */
>       qemu_fdt_setprop_sized_cells(ms->fdt, nodename, "reg", 2, base, 2, size);
> -    qemu_fdt_setprop_cells(ms->fdt, nodename, "interrupts",
> -                           VIRT_RTC_IRQ - VIRT_GSI_BASE ,
> -                           FDT_IRQ_TYPE_LEVEL_HIGH);
> -    qemu_fdt_setprop_cell(ms->fdt, nodename, "interrupt-parent",
> -                          *pch_pic_phandle);
>       g_free(nodename);
>   }
>   
> @@ -550,7 +550,7 @@ void virt_fdt_setup(LoongArchVirtMachineState *lvms)
>           fdt_add_uart_node(lvms, &pch_pic_phandle, base, irq, i == 0);
>       }
>   
> -    fdt_add_rtc_node(lvms, &pch_pic_phandle);
> +    fdt_add_rtc_node(lvms);
>       fdt_add_ged_reset(lvms);
>       platform_bus_add_all_fdt_nodes(machine->fdt, "/platic",
>                                      VIRT_PLATFORM_BUS_BASEADDRESS,



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH V2] hw/loongarch: add rtc acpi table
  2026-03-12  3:55 ` gaosong
@ 2026-03-12  8:19   ` lixianglai
  0 siblings, 0 replies; 7+ messages in thread
From: lixianglai @ 2026-03-12  8:19 UTC (permalink / raw)
  To: gaosong, qemu-devel; +Cc: Bibo Mao, Jiaxun Yang

Hi gaosong:
> 在 2026/3/12 上午10:13, Xianglai Li 写道:
>> Add the acpi table to the loongson rtc hardware so that the virtual 
>> machine
>> kernel can use the loongson RTC-related drivers.
>>
>> Delete the interrupt information in the rtc fdt table.
>>
>> 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>
>>
>> change:
>> V1->V2:
>> 1.Add a comment to explain why the acpi table no longer provides 
>> interrupt numbers
>> 2.Delete the interrupt number from the rtc fdt table
>
> It would be better to move point 2 to the new patch.
>
Ok!!!

> Thanks.
> Song Gao
>
>>   hw/loongarch/virt-acpi-build.c | 25 +++++++++++++++++++++++++
>>   hw/loongarch/virt-fdt-build.c  | 16 ++++++++--------
>>   2 files changed, 33 insertions(+), 8 deletions(-)
>>
>> 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);
>> diff --git a/hw/loongarch/virt-fdt-build.c 
>> b/hw/loongarch/virt-fdt-build.c
>> index 6c06b36fca..42f014a7bd 100644
>> --- a/hw/loongarch/virt-fdt-build.c
>> +++ b/hw/loongarch/virt-fdt-build.c
>> @@ -458,8 +458,7 @@ static void 
>> fdt_add_uart_node(LoongArchVirtMachineState *lvms,
>>       g_free(nodename);
>>   }
>>   -static void fdt_add_rtc_node(LoongArchVirtMachineState *lvms,
>> -                             uint32_t *pch_pic_phandle)
>> +static void fdt_add_rtc_node(LoongArchVirtMachineState *lvms)
>>   {
>>       char *nodename;
>>       hwaddr base = VIRT_RTC_REG_BASE;
>> @@ -470,12 +469,13 @@ static void 
>> fdt_add_rtc_node(LoongArchVirtMachineState *lvms,
>>       qemu_fdt_add_subnode(ms->fdt, nodename);
>>       qemu_fdt_setprop_string(ms->fdt, nodename, "compatible",
>>                               "loongson,ls7a-rtc");
>> +    /*
>> +     * 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.
>> +     */
>>       qemu_fdt_setprop_sized_cells(ms->fdt, nodename, "reg", 2, base, 
>> 2, size);
>> -    qemu_fdt_setprop_cells(ms->fdt, nodename, "interrupts",
>> -                           VIRT_RTC_IRQ - VIRT_GSI_BASE ,
>> -                           FDT_IRQ_TYPE_LEVEL_HIGH);
>> -    qemu_fdt_setprop_cell(ms->fdt, nodename, "interrupt-parent",
>> -                          *pch_pic_phandle);
>>       g_free(nodename);
>>   }
>>   @@ -550,7 +550,7 @@ void virt_fdt_setup(LoongArchVirtMachineState 
>> *lvms)
>>           fdt_add_uart_node(lvms, &pch_pic_phandle, base, irq, i == 0);
>>       }
>>   -    fdt_add_rtc_node(lvms, &pch_pic_phandle);
>> +    fdt_add_rtc_node(lvms);
>>       fdt_add_ged_reset(lvms);
>>       platform_bus_add_all_fdt_nodes(machine->fdt, "/platic",
>> VIRT_PLATFORM_BUS_BASEADDRESS,



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH V2] hw/loongarch: add rtc acpi table
  2026-03-12  2:13 [PATCH V2] hw/loongarch: add rtc acpi table Xianglai Li
  2026-03-12  3:55 ` gaosong
@ 2026-03-17  1:32 ` chen huacai
  2026-03-19  2:27   ` lixianglai
  1 sibling, 1 reply; 7+ messages in thread
From: chen huacai @ 2026-03-17  1:32 UTC (permalink / raw)
  To: Xianglai Li; +Cc: qemu-devel, Song Gao, Bibo Mao, Jiaxun Yang

Hi, Xianglai,

On Thu, Mar 12, 2026 at 10:40 AM 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.
>
> Delete the interrupt information in the rtc fdt table.
Why not use virtio-rtc? In this way we don't need to modify the ls7a rtc driver.

Huacai

>
> 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>
>
> change:
> V1->V2:
> 1.Add a comment to explain why the acpi table no longer provides interrupt numbers
> 2.Delete the interrupt number from the rtc fdt table
>
>  hw/loongarch/virt-acpi-build.c | 25 +++++++++++++++++++++++++
>  hw/loongarch/virt-fdt-build.c  | 16 ++++++++--------
>  2 files changed, 33 insertions(+), 8 deletions(-)
>
> 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);
> diff --git a/hw/loongarch/virt-fdt-build.c b/hw/loongarch/virt-fdt-build.c
> index 6c06b36fca..42f014a7bd 100644
> --- a/hw/loongarch/virt-fdt-build.c
> +++ b/hw/loongarch/virt-fdt-build.c
> @@ -458,8 +458,7 @@ static void fdt_add_uart_node(LoongArchVirtMachineState *lvms,
>      g_free(nodename);
>  }
>
> -static void fdt_add_rtc_node(LoongArchVirtMachineState *lvms,
> -                             uint32_t *pch_pic_phandle)
> +static void fdt_add_rtc_node(LoongArchVirtMachineState *lvms)
>  {
>      char *nodename;
>      hwaddr base = VIRT_RTC_REG_BASE;
> @@ -470,12 +469,13 @@ static void fdt_add_rtc_node(LoongArchVirtMachineState *lvms,
>      qemu_fdt_add_subnode(ms->fdt, nodename);
>      qemu_fdt_setprop_string(ms->fdt, nodename, "compatible",
>                              "loongson,ls7a-rtc");
> +    /*
> +     * 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.
> +     */
>      qemu_fdt_setprop_sized_cells(ms->fdt, nodename, "reg", 2, base, 2, size);
> -    qemu_fdt_setprop_cells(ms->fdt, nodename, "interrupts",
> -                           VIRT_RTC_IRQ - VIRT_GSI_BASE ,
> -                           FDT_IRQ_TYPE_LEVEL_HIGH);
> -    qemu_fdt_setprop_cell(ms->fdt, nodename, "interrupt-parent",
> -                          *pch_pic_phandle);
>      g_free(nodename);
>  }
>
> @@ -550,7 +550,7 @@ void virt_fdt_setup(LoongArchVirtMachineState *lvms)
>          fdt_add_uart_node(lvms, &pch_pic_phandle, base, irq, i == 0);
>      }
>
> -    fdt_add_rtc_node(lvms, &pch_pic_phandle);
> +    fdt_add_rtc_node(lvms);
>      fdt_add_ged_reset(lvms);
>      platform_bus_add_all_fdt_nodes(machine->fdt, "/platic",
>                                     VIRT_PLATFORM_BUS_BASEADDRESS,
> --
> 2.39.1
>
>


-- 
Huacai Chen


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH V2] hw/loongarch: add rtc acpi table
  2026-03-17  1:32 ` chen huacai
@ 2026-03-19  2:27   ` lixianglai
  2026-03-21  4:02     ` chen huacai
  0 siblings, 1 reply; 7+ messages in thread
From: lixianglai @ 2026-03-19  2:27 UTC (permalink / raw)
  To: chen huacai; +Cc: qemu-devel, Song Gao, Bibo Mao, Jiaxun Yang

Hi huacai :
> Hi, Xianglai,
>
> On Thu, Mar 12, 2026 at 10:40 AM 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.
>>
>> Delete the interrupt information in the rtc fdt table.
> Why not use virtio-rtc? In this way we don't need to modify the ls7a rtc driver.
Sorry for the late reply.
However, I did not find the device simulation model of virtio-rtc under 
the hw/rtc directory.

But, there is a simulation model for the ls7a rtc device, which is 
strongly related to
the virtualization of our loongarch platform.

So it makes perfect sense to use the ls7a rtc here. Otherwise, no 
platform would need to use the ls7a rtc,
and changing the simulation model of the rtc device at this stage,
our bios would also need to be modified accordingly. This would result 
in a very high cost of modification.

Thanks!
Xianglai.

> Huacai
>
>> 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>
>>
>> change:
>> V1->V2:
>> 1.Add a comment to explain why the acpi table no longer provides interrupt numbers
>> 2.Delete the interrupt number from the rtc fdt table
>>
>>   hw/loongarch/virt-acpi-build.c | 25 +++++++++++++++++++++++++
>>   hw/loongarch/virt-fdt-build.c  | 16 ++++++++--------
>>   2 files changed, 33 insertions(+), 8 deletions(-)
>>
>> 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);
>> diff --git a/hw/loongarch/virt-fdt-build.c b/hw/loongarch/virt-fdt-build.c
>> index 6c06b36fca..42f014a7bd 100644
>> --- a/hw/loongarch/virt-fdt-build.c
>> +++ b/hw/loongarch/virt-fdt-build.c
>> @@ -458,8 +458,7 @@ static void fdt_add_uart_node(LoongArchVirtMachineState *lvms,
>>       g_free(nodename);
>>   }
>>
>> -static void fdt_add_rtc_node(LoongArchVirtMachineState *lvms,
>> -                             uint32_t *pch_pic_phandle)
>> +static void fdt_add_rtc_node(LoongArchVirtMachineState *lvms)
>>   {
>>       char *nodename;
>>       hwaddr base = VIRT_RTC_REG_BASE;
>> @@ -470,12 +469,13 @@ static void fdt_add_rtc_node(LoongArchVirtMachineState *lvms,
>>       qemu_fdt_add_subnode(ms->fdt, nodename);
>>       qemu_fdt_setprop_string(ms->fdt, nodename, "compatible",
>>                               "loongson,ls7a-rtc");
>> +    /*
>> +     * 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.
>> +     */
>>       qemu_fdt_setprop_sized_cells(ms->fdt, nodename, "reg", 2, base, 2, size);
>> -    qemu_fdt_setprop_cells(ms->fdt, nodename, "interrupts",
>> -                           VIRT_RTC_IRQ - VIRT_GSI_BASE ,
>> -                           FDT_IRQ_TYPE_LEVEL_HIGH);
>> -    qemu_fdt_setprop_cell(ms->fdt, nodename, "interrupt-parent",
>> -                          *pch_pic_phandle);
>>       g_free(nodename);
>>   }
>>
>> @@ -550,7 +550,7 @@ void virt_fdt_setup(LoongArchVirtMachineState *lvms)
>>           fdt_add_uart_node(lvms, &pch_pic_phandle, base, irq, i == 0);
>>       }
>>
>> -    fdt_add_rtc_node(lvms, &pch_pic_phandle);
>> +    fdt_add_rtc_node(lvms);
>>       fdt_add_ged_reset(lvms);
>>       platform_bus_add_all_fdt_nodes(machine->fdt, "/platic",
>>                                      VIRT_PLATFORM_BUS_BASEADDRESS,
>> --
>> 2.39.1
>>
>>
>



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH V2] hw/loongarch: add rtc acpi table
  2026-03-19  2:27   ` lixianglai
@ 2026-03-21  4:02     ` chen huacai
  2026-03-26  8:41       ` lixianglai
  0 siblings, 1 reply; 7+ messages in thread
From: chen huacai @ 2026-03-21  4:02 UTC (permalink / raw)
  To: lixianglai; +Cc: qemu-devel, Song Gao, Bibo Mao, Jiaxun Yang

On Thu, Mar 19, 2026 at 10:35 AM lixianglai <lixianglai@loongson.cn> wrote:
>
> Hi huacai :
> > Hi, Xianglai,
> >
> > On Thu, Mar 12, 2026 at 10:40 AM 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.
> >>
> >> Delete the interrupt information in the rtc fdt table.
> > Why not use virtio-rtc? In this way we don't need to modify the ls7a rtc driver.
> Sorry for the late reply.
> However, I did not find the device simulation model of virtio-rtc under
> the hw/rtc directory.
virtio-rtc was added to the Linux kernel some time ago, it is very
new. But goldfish_rtc is another virtual rtc which is widely used and
has a long time in QEMU, you can consider it.

>
> But, there is a simulation model for the ls7a rtc device, which is
> strongly related to
> the virtualization of our loongarch platform.
>
> So it makes perfect sense to use the ls7a rtc here. Otherwise, no
> platform would need to use the ls7a rtc,
> and changing the simulation model of the rtc device at this stage,
> our bios would also need to be modified accordingly. This would result
> in a very high cost of modification.
I don't strongly object to ls7a rtc, but if you use it please try your
best to make it the same as real hardware. It is unacceptable to
modify the kernel driver to adapt the virtual ls7a rtc.

Huacai

>
> Thanks!
> Xianglai.
>
> > Huacai
> >
> >> 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>
> >>
> >> change:
> >> V1->V2:
> >> 1.Add a comment to explain why the acpi table no longer provides interrupt numbers
> >> 2.Delete the interrupt number from the rtc fdt table
> >>
> >>   hw/loongarch/virt-acpi-build.c | 25 +++++++++++++++++++++++++
> >>   hw/loongarch/virt-fdt-build.c  | 16 ++++++++--------
> >>   2 files changed, 33 insertions(+), 8 deletions(-)
> >>
> >> 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);
> >> diff --git a/hw/loongarch/virt-fdt-build.c b/hw/loongarch/virt-fdt-build.c
> >> index 6c06b36fca..42f014a7bd 100644
> >> --- a/hw/loongarch/virt-fdt-build.c
> >> +++ b/hw/loongarch/virt-fdt-build.c
> >> @@ -458,8 +458,7 @@ static void fdt_add_uart_node(LoongArchVirtMachineState *lvms,
> >>       g_free(nodename);
> >>   }
> >>
> >> -static void fdt_add_rtc_node(LoongArchVirtMachineState *lvms,
> >> -                             uint32_t *pch_pic_phandle)
> >> +static void fdt_add_rtc_node(LoongArchVirtMachineState *lvms)
> >>   {
> >>       char *nodename;
> >>       hwaddr base = VIRT_RTC_REG_BASE;
> >> @@ -470,12 +469,13 @@ static void fdt_add_rtc_node(LoongArchVirtMachineState *lvms,
> >>       qemu_fdt_add_subnode(ms->fdt, nodename);
> >>       qemu_fdt_setprop_string(ms->fdt, nodename, "compatible",
> >>                               "loongson,ls7a-rtc");
> >> +    /*
> >> +     * 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.
> >> +     */
> >>       qemu_fdt_setprop_sized_cells(ms->fdt, nodename, "reg", 2, base, 2, size);
> >> -    qemu_fdt_setprop_cells(ms->fdt, nodename, "interrupts",
> >> -                           VIRT_RTC_IRQ - VIRT_GSI_BASE ,
> >> -                           FDT_IRQ_TYPE_LEVEL_HIGH);
> >> -    qemu_fdt_setprop_cell(ms->fdt, nodename, "interrupt-parent",
> >> -                          *pch_pic_phandle);
> >>       g_free(nodename);
> >>   }
> >>
> >> @@ -550,7 +550,7 @@ void virt_fdt_setup(LoongArchVirtMachineState *lvms)
> >>           fdt_add_uart_node(lvms, &pch_pic_phandle, base, irq, i == 0);
> >>       }
> >>
> >> -    fdt_add_rtc_node(lvms, &pch_pic_phandle);
> >> +    fdt_add_rtc_node(lvms);
> >>       fdt_add_ged_reset(lvms);
> >>       platform_bus_add_all_fdt_nodes(machine->fdt, "/platic",
> >>                                      VIRT_PLATFORM_BUS_BASEADDRESS,
> >> --
> >> 2.39.1
> >>
> >>
> >
>


-- 
Huacai Chen


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH V2] hw/loongarch: add rtc acpi table
  2026-03-21  4:02     ` chen huacai
@ 2026-03-26  8:41       ` lixianglai
  0 siblings, 0 replies; 7+ messages in thread
From: lixianglai @ 2026-03-26  8:41 UTC (permalink / raw)
  To: chen huacai; +Cc: qemu-devel, Song Gao, Bibo Mao, Jiaxun Yang

Hi huacai:
> On Thu, Mar 19, 2026 at 10:35 AM lixianglai <lixianglai@loongson.cn> wrote:
>> Hi huacai :
>>> Hi, Xianglai,
>>>
>>> On Thu, Mar 12, 2026 at 10:40 AM 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.
>>>>
>>>> Delete the interrupt information in the rtc fdt table.
>>> Why not use virtio-rtc? In this way we don't need to modify the ls7a rtc driver.
>> Sorry for the late reply.
>> However, I did not find the device simulation model of virtio-rtc under
>> the hw/rtc directory.
> virtio-rtc was added to the Linux kernel some time ago, it is very
> new. But goldfish_rtc is another virtual rtc which is widely used and
> has a long time in QEMU, you can consider it.


Oh, I found the virtio rtc driver in the kernel, but couldn't find the 
device simulation for virtio rtc
in the qemu source code. Finally, I found a patch in the qemu mailing list.

Of course, we can replace the rtc equipment model (e.g. goldfish_rtc), 
but we can't remove ls7a
rtc from the perspective of compatibility, and we need to consider the 
cost of bios and virtual
machine kernel modification after changing the rtc device model as I 
mentioned above,
I think we should hear from other community members about whether we 
should eventually change
the loongarch virt virtual machine rtc device model.

Hi, @Song and @Bibo Do you have any opinions on this? Looking forward to 
hearing your suggestions!!
>> But, there is a simulation model for the ls7a rtc device, which is
>> strongly related to
>> the virtualization of our loongarch platform.
>>
>> So it makes perfect sense to use the ls7a rtc here. Otherwise, no
>> platform would need to use the ls7a rtc,
>> and changing the simulation model of the rtc device at this stage,
>> our bios would also need to be modified accordingly. This would result
>> in a very high cost of modification.
> I don't strongly object to ls7a rtc, but if you use it please try your
> best to make it the same as real hardware. It is unacceptable to
> modify the kernel driver to adapt the virtual ls7a rtc.
Here, I would like to clarify that this patch merely achieves the 
purpose of disabling
the interrupt function of the RTC driver by modifying the RTC ACPI.
This patch does not require any corresponding modifications to the RTC 
driver in the kernel.

Thanks!
Xianglai.


>
> Huacai
>
>> Thanks!
>> Xianglai.
>>
>>> Huacai
>>>
>>>> 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>
>>>>
>>>> change:
>>>> V1->V2:
>>>> 1.Add a comment to explain why the acpi table no longer provides interrupt numbers
>>>> 2.Delete the interrupt number from the rtc fdt table
>>>>
>>>>    hw/loongarch/virt-acpi-build.c | 25 +++++++++++++++++++++++++
>>>>    hw/loongarch/virt-fdt-build.c  | 16 ++++++++--------
>>>>    2 files changed, 33 insertions(+), 8 deletions(-)
>>>>
>>>> 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);
>>>> diff --git a/hw/loongarch/virt-fdt-build.c b/hw/loongarch/virt-fdt-build.c
>>>> index 6c06b36fca..42f014a7bd 100644
>>>> --- a/hw/loongarch/virt-fdt-build.c
>>>> +++ b/hw/loongarch/virt-fdt-build.c
>>>> @@ -458,8 +458,7 @@ static void fdt_add_uart_node(LoongArchVirtMachineState *lvms,
>>>>        g_free(nodename);
>>>>    }
>>>>
>>>> -static void fdt_add_rtc_node(LoongArchVirtMachineState *lvms,
>>>> -                             uint32_t *pch_pic_phandle)
>>>> +static void fdt_add_rtc_node(LoongArchVirtMachineState *lvms)
>>>>    {
>>>>        char *nodename;
>>>>        hwaddr base = VIRT_RTC_REG_BASE;
>>>> @@ -470,12 +469,13 @@ static void fdt_add_rtc_node(LoongArchVirtMachineState *lvms,
>>>>        qemu_fdt_add_subnode(ms->fdt, nodename);
>>>>        qemu_fdt_setprop_string(ms->fdt, nodename, "compatible",
>>>>                                "loongson,ls7a-rtc");
>>>> +    /*
>>>> +     * 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.
>>>> +     */
>>>>        qemu_fdt_setprop_sized_cells(ms->fdt, nodename, "reg", 2, base, 2, size);
>>>> -    qemu_fdt_setprop_cells(ms->fdt, nodename, "interrupts",
>>>> -                           VIRT_RTC_IRQ - VIRT_GSI_BASE ,
>>>> -                           FDT_IRQ_TYPE_LEVEL_HIGH);
>>>> -    qemu_fdt_setprop_cell(ms->fdt, nodename, "interrupt-parent",
>>>> -                          *pch_pic_phandle);
>>>>        g_free(nodename);
>>>>    }
>>>>
>>>> @@ -550,7 +550,7 @@ void virt_fdt_setup(LoongArchVirtMachineState *lvms)
>>>>            fdt_add_uart_node(lvms, &pch_pic_phandle, base, irq, i == 0);
>>>>        }
>>>>
>>>> -    fdt_add_rtc_node(lvms, &pch_pic_phandle);
>>>> +    fdt_add_rtc_node(lvms);
>>>>        fdt_add_ged_reset(lvms);
>>>>        platform_bus_add_all_fdt_nodes(machine->fdt, "/platic",
>>>>                                       VIRT_PLATFORM_BUS_BASEADDRESS,
>>>> --
>>>> 2.39.1
>>>>
>>>>
>



^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-03-26  8:50 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-12  2:13 [PATCH V2] hw/loongarch: add rtc acpi table Xianglai Li
2026-03-12  3:55 ` gaosong
2026-03-12  8:19   ` lixianglai
2026-03-17  1:32 ` chen huacai
2026-03-19  2:27   ` lixianglai
2026-03-21  4:02     ` chen huacai
2026-03-26  8:41       ` lixianglai

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox