RE: [PATCH v2 2/3] hw/acpi: Upgrade ACPI SPCR table to support SPCR table version 4 format

2024-05-14 Thread JeeHeng Sia



> -Original Message-
> From: Michael S. Tsirkin 
> Sent: Monday, May 13, 2024 2:31 PM
> To: JeeHeng Sia 
> Cc: qemu-...@nongnu.org; qemu-devel@nongnu.org; qemu-ri...@nongnu.org; 
> imamm...@redhat.com; anisi...@redhat.com;
> peter.mayd...@linaro.org; shannon.zha...@gmail.com; suni...@ventanamicro.com; 
> pal...@dabbelt.com; alistair.fran...@wdc.com;
> bin.m...@windriver.com; liwei1...@gmail.com; dbarb...@ventanamicro.com; 
> zhiwei_...@linux.alibaba.com
> Subject: Re: [PATCH v2 2/3] hw/acpi: Upgrade ACPI SPCR table to support SPCR 
> table version 4 format
> 
> On Mon, May 06, 2024 at 10:22:11PM -0700, Sia Jee Heng wrote:
> > Update the SPCR table to accommodate the SPCR Table version 4 [1].
> > The SPCR table has been modified to adhere to the version 4 format [2].
> >
> > [1]: 
> > https://learn.microsoft.com/en-us/windows-hardware/drivers/serports/serial-port-console-redirection-table
> > [2]: https://github.com/acpica/acpica/pull/931
> >
> > Signed-off-by: Sia Jee Heng 
> 
> What does this achieve? We don't normally change unless it gets
> us some useful feature.
The changes in Table 4 primarily include the addition of RISC-V support
and modifications to the Interrupt Type field. Additionally, new fields
added are Precise Baud Rate, NamespaceStringLength, NamespaceStringOffset,
and NamespaceString[].
> 
> 
> > ---
> >  hw/acpi/aml-build.c | 14 +++---
> >  hw/arm/virt-acpi-build.c| 10 --
> >  hw/riscv/virt-acpi-build.c  | 12 +---
> >  include/hw/acpi/acpi-defs.h |  7 +--
> >  include/hw/acpi/aml-build.h |  2 +-
> >  5 files changed, 34 insertions(+), 11 deletions(-)
> >
> > diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
> > index 6d4517cfbe..7c43573eef 100644
> > --- a/hw/acpi/aml-build.c
> > +++ b/hw/acpi/aml-build.c
> > @@ -1996,7 +1996,7 @@ static void build_processor_hierarchy_node(GArray 
> > *tbl, uint32_t flags,
> >
> >  void build_spcr(GArray *table_data, BIOSLinker *linker,
> >  const AcpiSpcrData *f, const uint8_t rev,
> > -const char *oem_id, const char *oem_table_id)
> > +const char *oem_id, const char *oem_table_id, const char 
> > *name)
> >  {
> >  AcpiTable table = { .sig = "SPCR", .rev = rev, .oem_id = oem_id,
> >  .oem_table_id = oem_table_id };
> > @@ -2042,8 +2042,16 @@ void build_spcr(GArray *table_data, BIOSLinker 
> > *linker,
> >  build_append_int_noprefix(table_data, f->pci_flags, 4);
> >  /* PCI Segment */
> >  build_append_int_noprefix(table_data, f->pci_segment, 1);
> > -/* Reserved */
> > -build_append_int_noprefix(table_data, 0, 4);
> > +/* UartClkFreq */
> > +build_append_int_noprefix(table_data, f->uart_clk_freq, 4);
> > +/* PreciseBaudrate */
> > +build_append_int_noprefix(table_data, f->precise_baudrate, 4);
> > +/* NameSpaceStringLength */
> > +build_append_int_noprefix(table_data, f->namespace_string_length, 2);
> > +/* NameSpaceStringOffset */
> > +build_append_int_noprefix(table_data, f->namespace_string_offset, 2);
> > +/* NamespaceString[] */
> > +g_array_append_vals(table_data, name, f->namespace_string_length);
> >
> >  acpi_table_end(linker, );
> >  }
> > diff --git a/hw/arm/virt-acpi-build.c b/hw/arm/virt-acpi-build.c
> > index 6a1bde61ce..cb345e8659 100644
> > --- a/hw/arm/virt-acpi-build.c
> > +++ b/hw/arm/virt-acpi-build.c
> > @@ -428,11 +428,12 @@ build_iort(GArray *table_data, BIOSLinker *linker, 
> > VirtMachineState *vms)
> >
> >  /*
> >   * Serial Port Console Redirection Table (SPCR)
> > - * Rev: 1.07
> > + * Rev: 1.10
> >   */
> >  static void
> >  spcr_setup(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms)
> >  {
> > +const char name[] = ".";
> >  AcpiSpcrData serial = {
> >  .interface_type = 3,   /* ARM PL011 UART */
> >  .base_addr.id = AML_AS_SYSTEM_MEMORY,
> > @@ -456,9 +457,14 @@ spcr_setup(GArray *table_data, BIOSLinker *linker, 
> > VirtMachineState *vms)
> >  .pci_function = 0,
> >  .pci_flags = 0,
> >  .pci_segment = 0,
> > +.uart_clk_freq = 0,
> > +.precise_baudrate = 0,
> > +.namespace_string_length = sizeof(name),
> > +.namespace_string_offset = 88,
> >  };
> >
> > -build_spcr(table_data, linker, , 2, vms->oem_id, 
> > vms->oem_tab

RE: [PATCH v2 2/3] hw/acpi: Upgrade ACPI SPCR table to support SPCR table version 4 format

2024-05-14 Thread JeeHeng Sia



> -Original Message-
> From: Sunil V L 
> Sent: Monday, May 13, 2024 1:16 PM
> To: JeeHeng Sia 
> Cc: qemu-...@nongnu.org; qemu-devel@nongnu.org; qemu-ri...@nongnu.org; 
> m...@redhat.com; imamm...@redhat.com;
> anisi...@redhat.com; peter.mayd...@linaro.org; shannon.zha...@gmail.com; 
> pal...@dabbelt.com; alistair.fran...@wdc.com;
> bin.m...@windriver.com; liwei1...@gmail.com; dbarb...@ventanamicro.com; 
> zhiwei_...@linux.alibaba.com
> Subject: Re: [PATCH v2 2/3] hw/acpi: Upgrade ACPI SPCR table to support SPCR 
> table version 4 format
> 
> Hi Sia Jee Heng,
> 
> On Mon, May 06, 2024 at 10:22:11PM -0700, Sia Jee Heng wrote:
> > Update the SPCR table to accommodate the SPCR Table version 4 [1].
> > The SPCR table has been modified to adhere to the version 4 format [2].
> >
> > [1]: 
> > https://learn.microsoft.com/en-us/windows-hardware/drivers/serports/serial-port-console-redirection-table
> > [2]: https://github.com/acpica/acpica/pull/931
> >
> > Signed-off-by: Sia Jee Heng 
> > ---
> >  hw/acpi/aml-build.c | 14 +++---
> >  hw/arm/virt-acpi-build.c| 10 --
> >  hw/riscv/virt-acpi-build.c  | 12 +---
> >  include/hw/acpi/acpi-defs.h |  7 +--
> >  include/hw/acpi/aml-build.h |  2 +-
> >  5 files changed, 34 insertions(+), 11 deletions(-)
> >
> > diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
> > index 6d4517cfbe..7c43573eef 100644
> > --- a/hw/acpi/aml-build.c
> > +++ b/hw/acpi/aml-build.c
> > @@ -1996,7 +1996,7 @@ static void build_processor_hierarchy_node(GArray 
> > *tbl, uint32_t flags,
> >
> >  void build_spcr(GArray *table_data, BIOSLinker *linker,
> >  const AcpiSpcrData *f, const uint8_t rev,
> > -const char *oem_id, const char *oem_table_id)
> > +const char *oem_id, const char *oem_table_id, const char 
> > *name)
> >  {
> >  AcpiTable table = { .sig = "SPCR", .rev = rev, .oem_id = oem_id,
> >  .oem_table_id = oem_table_id };
> > @@ -2042,8 +2042,16 @@ void build_spcr(GArray *table_data, BIOSLinker 
> > *linker,
> >  build_append_int_noprefix(table_data, f->pci_flags, 4);
> >  /* PCI Segment */
> >  build_append_int_noprefix(table_data, f->pci_segment, 1);
> > -/* Reserved */
> > -build_append_int_noprefix(table_data, 0, 4);
> > +/* UartClkFreq */
> > +build_append_int_noprefix(table_data, f->uart_clk_freq, 4);
> > +/* PreciseBaudrate */
> > +build_append_int_noprefix(table_data, f->precise_baudrate, 4);
> > +/* NameSpaceStringLength */
> > +build_append_int_noprefix(table_data, f->namespace_string_length, 2);
> > +/* NameSpaceStringOffset */
> > +build_append_int_noprefix(table_data, f->namespace_string_offset, 2);
> > +/* NamespaceString[] */
> > +g_array_append_vals(table_data, name, f->namespace_string_length);
> >
> Is it possible to check the revision here and add new fields only if the
> revision supports it? ARM maintainers are better to comment but IMO, we
> better keep ARM's SPCR in the same current version since I don't know
> how consumers like linux (and other OSs) react to the change.
Hi Sunil, there is only one prebuilt SPCR binary. By doing this, the qtest
will fail. I think I will let ARM maintainer to comment.
> 
> Thanks!
> Sunil
> >  acpi_table_end(linker, );
> >  }
> > diff --git a/hw/arm/virt-acpi-build.c b/hw/arm/virt-acpi-build.c
> > index 6a1bde61ce..cb345e8659 100644
> > --- a/hw/arm/virt-acpi-build.c
> > +++ b/hw/arm/virt-acpi-build.c
> > @@ -428,11 +428,12 @@ build_iort(GArray *table_data, BIOSLinker *linker, 
> > VirtMachineState *vms)
> >
> >  /*
> >   * Serial Port Console Redirection Table (SPCR)
> > - * Rev: 1.07
> > + * Rev: 1.10
> >   */
> >  static void
> >  spcr_setup(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms)
> >  {
> > +const char name[] = ".";
> >  AcpiSpcrData serial = {
> >  .interface_type = 3,   /* ARM PL011 UART */
> >  .base_addr.id = AML_AS_SYSTEM_MEMORY,
> > @@ -456,9 +457,14 @@ spcr_setup(GArray *table_data, BIOSLinker *linker, 
> > VirtMachineState *vms)
> >  .pci_function = 0,
> >  .pci_flags = 0,
> >  .pci_segment = 0,
> > +.uart_clk_freq = 0,
> > +.precise_baudrate = 0,
> > +.namespace_string_length = sizeof(name),
> > +.namespace_string_offset = 88,
> >  };
> &

Re: [PATCH v2 2/3] hw/acpi: Upgrade ACPI SPCR table to support SPCR table version 4 format

2024-05-13 Thread Michael S. Tsirkin
On Mon, May 06, 2024 at 10:22:11PM -0700, Sia Jee Heng wrote:
> Update the SPCR table to accommodate the SPCR Table version 4 [1].
> The SPCR table has been modified to adhere to the version 4 format [2].
> 
> [1]: 
> https://learn.microsoft.com/en-us/windows-hardware/drivers/serports/serial-port-console-redirection-table
> [2]: https://github.com/acpica/acpica/pull/931
> 
> Signed-off-by: Sia Jee Heng 

What does this achieve? We don't normally change unless it gets
us some useful feature.


> ---
>  hw/acpi/aml-build.c | 14 +++---
>  hw/arm/virt-acpi-build.c| 10 --
>  hw/riscv/virt-acpi-build.c  | 12 +---
>  include/hw/acpi/acpi-defs.h |  7 +--
>  include/hw/acpi/aml-build.h |  2 +-
>  5 files changed, 34 insertions(+), 11 deletions(-)
> 
> diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
> index 6d4517cfbe..7c43573eef 100644
> --- a/hw/acpi/aml-build.c
> +++ b/hw/acpi/aml-build.c
> @@ -1996,7 +1996,7 @@ static void build_processor_hierarchy_node(GArray *tbl, 
> uint32_t flags,
>  
>  void build_spcr(GArray *table_data, BIOSLinker *linker,
>  const AcpiSpcrData *f, const uint8_t rev,
> -const char *oem_id, const char *oem_table_id)
> +const char *oem_id, const char *oem_table_id, const char 
> *name)
>  {
>  AcpiTable table = { .sig = "SPCR", .rev = rev, .oem_id = oem_id,
>  .oem_table_id = oem_table_id };
> @@ -2042,8 +2042,16 @@ void build_spcr(GArray *table_data, BIOSLinker *linker,
>  build_append_int_noprefix(table_data, f->pci_flags, 4);
>  /* PCI Segment */
>  build_append_int_noprefix(table_data, f->pci_segment, 1);
> -/* Reserved */
> -build_append_int_noprefix(table_data, 0, 4);
> +/* UartClkFreq */
> +build_append_int_noprefix(table_data, f->uart_clk_freq, 4);
> +/* PreciseBaudrate */
> +build_append_int_noprefix(table_data, f->precise_baudrate, 4);
> +/* NameSpaceStringLength */
> +build_append_int_noprefix(table_data, f->namespace_string_length, 2);
> +/* NameSpaceStringOffset */
> +build_append_int_noprefix(table_data, f->namespace_string_offset, 2);
> +/* NamespaceString[] */
> +g_array_append_vals(table_data, name, f->namespace_string_length);
>  
>  acpi_table_end(linker, );
>  }
> diff --git a/hw/arm/virt-acpi-build.c b/hw/arm/virt-acpi-build.c
> index 6a1bde61ce..cb345e8659 100644
> --- a/hw/arm/virt-acpi-build.c
> +++ b/hw/arm/virt-acpi-build.c
> @@ -428,11 +428,12 @@ build_iort(GArray *table_data, BIOSLinker *linker, 
> VirtMachineState *vms)
>  
>  /*
>   * Serial Port Console Redirection Table (SPCR)
> - * Rev: 1.07
> + * Rev: 1.10
>   */
>  static void
>  spcr_setup(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms)
>  {
> +const char name[] = ".";
>  AcpiSpcrData serial = {
>  .interface_type = 3,   /* ARM PL011 UART */
>  .base_addr.id = AML_AS_SYSTEM_MEMORY,
> @@ -456,9 +457,14 @@ spcr_setup(GArray *table_data, BIOSLinker *linker, 
> VirtMachineState *vms)
>  .pci_function = 0,
>  .pci_flags = 0,
>  .pci_segment = 0,
> +.uart_clk_freq = 0,
> +.precise_baudrate = 0,
> +.namespace_string_length = sizeof(name),
> +.namespace_string_offset = 88,
>  };
>  
> -build_spcr(table_data, linker, , 2, vms->oem_id, 
> vms->oem_table_id);
> +build_spcr(table_data, linker, , 4, vms->oem_id, 
> vms->oem_table_id,
> +   name);
>  }
>  
>  /*
> diff --git a/hw/riscv/virt-acpi-build.c b/hw/riscv/virt-acpi-build.c
> index 0925528160..5fa3942491 100644
> --- a/hw/riscv/virt-acpi-build.c
> +++ b/hw/riscv/virt-acpi-build.c
> @@ -176,14 +176,15 @@ acpi_dsdt_add_uart(Aml *scope, const MemMapEntry 
> *uart_memmap,
>  
>  /*
>   * Serial Port Console Redirection Table (SPCR)
> - * Rev: 1.07
> + * Rev: 1.10
>   */
>  
>  static void
>  spcr_setup(GArray *table_data, BIOSLinker *linker, RISCVVirtState *s)
>  {
> +const char name[] = ".";
>  AcpiSpcrData serial = {
> -.interface_type = 0,   /* 16550 compatible */
> +.interface_type = 0x12,   /* 16550 compatible */
>  .base_addr.id = AML_AS_SYSTEM_MEMORY,
>  .base_addr.width = 32,
>  .base_addr.offset = 0,
> @@ -205,9 +206,14 @@ spcr_setup(GArray *table_data, BIOSLinker *linker, 
> RISCVVirtState *s)
>  .pci_function = 0,
>  .pci_flags = 0,
>  .pci_segment = 0,
> +.uart_clk_freq = 0,
> +.precise_baudrate = 0,
> +.namespace_string_length = sizeof(name),
> +.namespace_string_offset = 88,
>  };
>  
> -build_spcr(table_data, linker, , 2, s->oem_id, s->oem_table_id);
> +build_spcr(table_data, linker, , 4, s->oem_id, s->oem_table_id,
> +   name);
>  }
>  
>  /* RHCT Node[N] starts at offset 56 */
> diff --git a/include/hw/acpi/acpi-defs.h b/include/hw/acpi/acpi-defs.h
> index 0e6e82b339..2e6e341998 100644
> --- 

Re: [PATCH v2 2/3] hw/acpi: Upgrade ACPI SPCR table to support SPCR table version 4 format

2024-05-12 Thread Sunil V L
Hi Sia Jee Heng,

On Mon, May 06, 2024 at 10:22:11PM -0700, Sia Jee Heng wrote:
> Update the SPCR table to accommodate the SPCR Table version 4 [1].
> The SPCR table has been modified to adhere to the version 4 format [2].
> 
> [1]: 
> https://learn.microsoft.com/en-us/windows-hardware/drivers/serports/serial-port-console-redirection-table
> [2]: https://github.com/acpica/acpica/pull/931
> 
> Signed-off-by: Sia Jee Heng 
> ---
>  hw/acpi/aml-build.c | 14 +++---
>  hw/arm/virt-acpi-build.c| 10 --
>  hw/riscv/virt-acpi-build.c  | 12 +---
>  include/hw/acpi/acpi-defs.h |  7 +--
>  include/hw/acpi/aml-build.h |  2 +-
>  5 files changed, 34 insertions(+), 11 deletions(-)
> 
> diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
> index 6d4517cfbe..7c43573eef 100644
> --- a/hw/acpi/aml-build.c
> +++ b/hw/acpi/aml-build.c
> @@ -1996,7 +1996,7 @@ static void build_processor_hierarchy_node(GArray *tbl, 
> uint32_t flags,
>  
>  void build_spcr(GArray *table_data, BIOSLinker *linker,
>  const AcpiSpcrData *f, const uint8_t rev,
> -const char *oem_id, const char *oem_table_id)
> +const char *oem_id, const char *oem_table_id, const char 
> *name)
>  {
>  AcpiTable table = { .sig = "SPCR", .rev = rev, .oem_id = oem_id,
>  .oem_table_id = oem_table_id };
> @@ -2042,8 +2042,16 @@ void build_spcr(GArray *table_data, BIOSLinker *linker,
>  build_append_int_noprefix(table_data, f->pci_flags, 4);
>  /* PCI Segment */
>  build_append_int_noprefix(table_data, f->pci_segment, 1);
> -/* Reserved */
> -build_append_int_noprefix(table_data, 0, 4);
> +/* UartClkFreq */
> +build_append_int_noprefix(table_data, f->uart_clk_freq, 4);
> +/* PreciseBaudrate */
> +build_append_int_noprefix(table_data, f->precise_baudrate, 4);
> +/* NameSpaceStringLength */
> +build_append_int_noprefix(table_data, f->namespace_string_length, 2);
> +/* NameSpaceStringOffset */
> +build_append_int_noprefix(table_data, f->namespace_string_offset, 2);
> +/* NamespaceString[] */
> +g_array_append_vals(table_data, name, f->namespace_string_length);
>  
Is it possible to check the revision here and add new fields only if the
revision supports it? ARM maintainers are better to comment but IMO, we
better keep ARM's SPCR in the same current version since I don't know
how consumers like linux (and other OSs) react to the change.

Thanks!
Sunil
>  acpi_table_end(linker, );
>  }
> diff --git a/hw/arm/virt-acpi-build.c b/hw/arm/virt-acpi-build.c
> index 6a1bde61ce..cb345e8659 100644
> --- a/hw/arm/virt-acpi-build.c
> +++ b/hw/arm/virt-acpi-build.c
> @@ -428,11 +428,12 @@ build_iort(GArray *table_data, BIOSLinker *linker, 
> VirtMachineState *vms)
>  
>  /*
>   * Serial Port Console Redirection Table (SPCR)
> - * Rev: 1.07
> + * Rev: 1.10
>   */
>  static void
>  spcr_setup(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms)
>  {
> +const char name[] = ".";
>  AcpiSpcrData serial = {
>  .interface_type = 3,   /* ARM PL011 UART */
>  .base_addr.id = AML_AS_SYSTEM_MEMORY,
> @@ -456,9 +457,14 @@ spcr_setup(GArray *table_data, BIOSLinker *linker, 
> VirtMachineState *vms)
>  .pci_function = 0,
>  .pci_flags = 0,
>  .pci_segment = 0,
> +.uart_clk_freq = 0,
> +.precise_baudrate = 0,
> +.namespace_string_length = sizeof(name),
> +.namespace_string_offset = 88,
>  };
>  
> -build_spcr(table_data, linker, , 2, vms->oem_id, 
> vms->oem_table_id);
> +build_spcr(table_data, linker, , 4, vms->oem_id, 
> vms->oem_table_id,
> +   name);
>  }
>  
>  /*
> diff --git a/hw/riscv/virt-acpi-build.c b/hw/riscv/virt-acpi-build.c
> index 0925528160..5fa3942491 100644
> --- a/hw/riscv/virt-acpi-build.c
> +++ b/hw/riscv/virt-acpi-build.c
> @@ -176,14 +176,15 @@ acpi_dsdt_add_uart(Aml *scope, const MemMapEntry 
> *uart_memmap,
>  
>  /*
>   * Serial Port Console Redirection Table (SPCR)
> - * Rev: 1.07
> + * Rev: 1.10
>   */
>  
>  static void
>  spcr_setup(GArray *table_data, BIOSLinker *linker, RISCVVirtState *s)
>  {
> +const char name[] = ".";
>  AcpiSpcrData serial = {
> -.interface_type = 0,   /* 16550 compatible */
> +.interface_type = 0x12,   /* 16550 compatible */
>  .base_addr.id = AML_AS_SYSTEM_MEMORY,
>  .base_addr.width = 32,
>  .base_addr.offset = 0,
> @@ -205,9 +206,14 @@ spcr_setup(GArray *table_data, BIOSLinker *linker, 
> RISCVVirtState *s)
>  .pci_function = 0,
>  .pci_flags = 0,
>  .pci_segment = 0,
> +.uart_clk_freq = 0,
> +.precise_baudrate = 0,
> +.namespace_string_length = sizeof(name),
> +.namespace_string_offset = 88,
>  };
>  
> -build_spcr(table_data, linker, , 2, s->oem_id, s->oem_table_id);
> +build_spcr(table_data, linker, , 4, s->oem_id, 

Re: [PATCH v2 2/3] hw/acpi: Upgrade ACPI SPCR table to support SPCR table version 4 format

2024-05-12 Thread Alistair Francis
On Tue, May 7, 2024 at 3:24 PM Sia Jee Heng
 wrote:
>
> Update the SPCR table to accommodate the SPCR Table version 4 [1].
> The SPCR table has been modified to adhere to the version 4 format [2].
>
> [1]: 
> https://learn.microsoft.com/en-us/windows-hardware/drivers/serports/serial-port-console-redirection-table
> [2]: https://github.com/acpica/acpica/pull/931
>
> Signed-off-by: Sia Jee Heng 

Acked-by: Alistair Francis 

Alistair

> ---
>  hw/acpi/aml-build.c | 14 +++---
>  hw/arm/virt-acpi-build.c| 10 --
>  hw/riscv/virt-acpi-build.c  | 12 +---
>  include/hw/acpi/acpi-defs.h |  7 +--
>  include/hw/acpi/aml-build.h |  2 +-
>  5 files changed, 34 insertions(+), 11 deletions(-)
>
> diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
> index 6d4517cfbe..7c43573eef 100644
> --- a/hw/acpi/aml-build.c
> +++ b/hw/acpi/aml-build.c
> @@ -1996,7 +1996,7 @@ static void build_processor_hierarchy_node(GArray *tbl, 
> uint32_t flags,
>
>  void build_spcr(GArray *table_data, BIOSLinker *linker,
>  const AcpiSpcrData *f, const uint8_t rev,
> -const char *oem_id, const char *oem_table_id)
> +const char *oem_id, const char *oem_table_id, const char 
> *name)
>  {
>  AcpiTable table = { .sig = "SPCR", .rev = rev, .oem_id = oem_id,
>  .oem_table_id = oem_table_id };
> @@ -2042,8 +2042,16 @@ void build_spcr(GArray *table_data, BIOSLinker *linker,
>  build_append_int_noprefix(table_data, f->pci_flags, 4);
>  /* PCI Segment */
>  build_append_int_noprefix(table_data, f->pci_segment, 1);
> -/* Reserved */
> -build_append_int_noprefix(table_data, 0, 4);
> +/* UartClkFreq */
> +build_append_int_noprefix(table_data, f->uart_clk_freq, 4);
> +/* PreciseBaudrate */
> +build_append_int_noprefix(table_data, f->precise_baudrate, 4);
> +/* NameSpaceStringLength */
> +build_append_int_noprefix(table_data, f->namespace_string_length, 2);
> +/* NameSpaceStringOffset */
> +build_append_int_noprefix(table_data, f->namespace_string_offset, 2);
> +/* NamespaceString[] */
> +g_array_append_vals(table_data, name, f->namespace_string_length);
>
>  acpi_table_end(linker, );
>  }
> diff --git a/hw/arm/virt-acpi-build.c b/hw/arm/virt-acpi-build.c
> index 6a1bde61ce..cb345e8659 100644
> --- a/hw/arm/virt-acpi-build.c
> +++ b/hw/arm/virt-acpi-build.c
> @@ -428,11 +428,12 @@ build_iort(GArray *table_data, BIOSLinker *linker, 
> VirtMachineState *vms)
>
>  /*
>   * Serial Port Console Redirection Table (SPCR)
> - * Rev: 1.07
> + * Rev: 1.10
>   */
>  static void
>  spcr_setup(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms)
>  {
> +const char name[] = ".";
>  AcpiSpcrData serial = {
>  .interface_type = 3,   /* ARM PL011 UART */
>  .base_addr.id = AML_AS_SYSTEM_MEMORY,
> @@ -456,9 +457,14 @@ spcr_setup(GArray *table_data, BIOSLinker *linker, 
> VirtMachineState *vms)
>  .pci_function = 0,
>  .pci_flags = 0,
>  .pci_segment = 0,
> +.uart_clk_freq = 0,
> +.precise_baudrate = 0,
> +.namespace_string_length = sizeof(name),
> +.namespace_string_offset = 88,
>  };
>
> -build_spcr(table_data, linker, , 2, vms->oem_id, 
> vms->oem_table_id);
> +build_spcr(table_data, linker, , 4, vms->oem_id, 
> vms->oem_table_id,
> +   name);
>  }
>
>  /*
> diff --git a/hw/riscv/virt-acpi-build.c b/hw/riscv/virt-acpi-build.c
> index 0925528160..5fa3942491 100644
> --- a/hw/riscv/virt-acpi-build.c
> +++ b/hw/riscv/virt-acpi-build.c
> @@ -176,14 +176,15 @@ acpi_dsdt_add_uart(Aml *scope, const MemMapEntry 
> *uart_memmap,
>
>  /*
>   * Serial Port Console Redirection Table (SPCR)
> - * Rev: 1.07
> + * Rev: 1.10
>   */
>
>  static void
>  spcr_setup(GArray *table_data, BIOSLinker *linker, RISCVVirtState *s)
>  {
> +const char name[] = ".";
>  AcpiSpcrData serial = {
> -.interface_type = 0,   /* 16550 compatible */
> +.interface_type = 0x12,   /* 16550 compatible */
>  .base_addr.id = AML_AS_SYSTEM_MEMORY,
>  .base_addr.width = 32,
>  .base_addr.offset = 0,
> @@ -205,9 +206,14 @@ spcr_setup(GArray *table_data, BIOSLinker *linker, 
> RISCVVirtState *s)
>  .pci_function = 0,
>  .pci_flags = 0,
>  .pci_segment = 0,
> +.uart_clk_freq = 0,
> +.precise_baudrate = 0,
> +.namespace_string_length = sizeof(name),
> +.namespace_string_offset = 88,
>  };
>
> -build_spcr(table_data, linker, , 2, s->oem_id, s->oem_table_id);
> +build_spcr(table_data, linker, , 4, s->oem_id, s->oem_table_id,
> +   name);
>  }
>
>  /* RHCT Node[N] starts at offset 56 */
> diff --git a/include/hw/acpi/acpi-defs.h b/include/hw/acpi/acpi-defs.h
> index 0e6e82b339..2e6e341998 100644
> --- a/include/hw/acpi/acpi-defs.h
> +++ b/include/hw/acpi/acpi-defs.h
> @@ -112,7 +112,6 @@ typedef 

[PATCH v2 2/3] hw/acpi: Upgrade ACPI SPCR table to support SPCR table version 4 format

2024-05-06 Thread Sia Jee Heng
Update the SPCR table to accommodate the SPCR Table version 4 [1].
The SPCR table has been modified to adhere to the version 4 format [2].

[1]: 
https://learn.microsoft.com/en-us/windows-hardware/drivers/serports/serial-port-console-redirection-table
[2]: https://github.com/acpica/acpica/pull/931

Signed-off-by: Sia Jee Heng 
---
 hw/acpi/aml-build.c | 14 +++---
 hw/arm/virt-acpi-build.c| 10 --
 hw/riscv/virt-acpi-build.c  | 12 +---
 include/hw/acpi/acpi-defs.h |  7 +--
 include/hw/acpi/aml-build.h |  2 +-
 5 files changed, 34 insertions(+), 11 deletions(-)

diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index 6d4517cfbe..7c43573eef 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -1996,7 +1996,7 @@ static void build_processor_hierarchy_node(GArray *tbl, 
uint32_t flags,
 
 void build_spcr(GArray *table_data, BIOSLinker *linker,
 const AcpiSpcrData *f, const uint8_t rev,
-const char *oem_id, const char *oem_table_id)
+const char *oem_id, const char *oem_table_id, const char *name)
 {
 AcpiTable table = { .sig = "SPCR", .rev = rev, .oem_id = oem_id,
 .oem_table_id = oem_table_id };
@@ -2042,8 +2042,16 @@ void build_spcr(GArray *table_data, BIOSLinker *linker,
 build_append_int_noprefix(table_data, f->pci_flags, 4);
 /* PCI Segment */
 build_append_int_noprefix(table_data, f->pci_segment, 1);
-/* Reserved */
-build_append_int_noprefix(table_data, 0, 4);
+/* UartClkFreq */
+build_append_int_noprefix(table_data, f->uart_clk_freq, 4);
+/* PreciseBaudrate */
+build_append_int_noprefix(table_data, f->precise_baudrate, 4);
+/* NameSpaceStringLength */
+build_append_int_noprefix(table_data, f->namespace_string_length, 2);
+/* NameSpaceStringOffset */
+build_append_int_noprefix(table_data, f->namespace_string_offset, 2);
+/* NamespaceString[] */
+g_array_append_vals(table_data, name, f->namespace_string_length);
 
 acpi_table_end(linker, );
 }
diff --git a/hw/arm/virt-acpi-build.c b/hw/arm/virt-acpi-build.c
index 6a1bde61ce..cb345e8659 100644
--- a/hw/arm/virt-acpi-build.c
+++ b/hw/arm/virt-acpi-build.c
@@ -428,11 +428,12 @@ build_iort(GArray *table_data, BIOSLinker *linker, 
VirtMachineState *vms)
 
 /*
  * Serial Port Console Redirection Table (SPCR)
- * Rev: 1.07
+ * Rev: 1.10
  */
 static void
 spcr_setup(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms)
 {
+const char name[] = ".";
 AcpiSpcrData serial = {
 .interface_type = 3,   /* ARM PL011 UART */
 .base_addr.id = AML_AS_SYSTEM_MEMORY,
@@ -456,9 +457,14 @@ spcr_setup(GArray *table_data, BIOSLinker *linker, 
VirtMachineState *vms)
 .pci_function = 0,
 .pci_flags = 0,
 .pci_segment = 0,
+.uart_clk_freq = 0,
+.precise_baudrate = 0,
+.namespace_string_length = sizeof(name),
+.namespace_string_offset = 88,
 };
 
-build_spcr(table_data, linker, , 2, vms->oem_id, vms->oem_table_id);
+build_spcr(table_data, linker, , 4, vms->oem_id, vms->oem_table_id,
+   name);
 }
 
 /*
diff --git a/hw/riscv/virt-acpi-build.c b/hw/riscv/virt-acpi-build.c
index 0925528160..5fa3942491 100644
--- a/hw/riscv/virt-acpi-build.c
+++ b/hw/riscv/virt-acpi-build.c
@@ -176,14 +176,15 @@ acpi_dsdt_add_uart(Aml *scope, const MemMapEntry 
*uart_memmap,
 
 /*
  * Serial Port Console Redirection Table (SPCR)
- * Rev: 1.07
+ * Rev: 1.10
  */
 
 static void
 spcr_setup(GArray *table_data, BIOSLinker *linker, RISCVVirtState *s)
 {
+const char name[] = ".";
 AcpiSpcrData serial = {
-.interface_type = 0,   /* 16550 compatible */
+.interface_type = 0x12,   /* 16550 compatible */
 .base_addr.id = AML_AS_SYSTEM_MEMORY,
 .base_addr.width = 32,
 .base_addr.offset = 0,
@@ -205,9 +206,14 @@ spcr_setup(GArray *table_data, BIOSLinker *linker, 
RISCVVirtState *s)
 .pci_function = 0,
 .pci_flags = 0,
 .pci_segment = 0,
+.uart_clk_freq = 0,
+.precise_baudrate = 0,
+.namespace_string_length = sizeof(name),
+.namespace_string_offset = 88,
 };
 
-build_spcr(table_data, linker, , 2, s->oem_id, s->oem_table_id);
+build_spcr(table_data, linker, , 4, s->oem_id, s->oem_table_id,
+   name);
 }
 
 /* RHCT Node[N] starts at offset 56 */
diff --git a/include/hw/acpi/acpi-defs.h b/include/hw/acpi/acpi-defs.h
index 0e6e82b339..2e6e341998 100644
--- a/include/hw/acpi/acpi-defs.h
+++ b/include/hw/acpi/acpi-defs.h
@@ -112,7 +112,6 @@ typedef struct AcpiSpcrData {
 uint8_t flow_control;
 uint8_t terminal_type;
 uint8_t language;
-uint8_t reserved1;
 uint16_t pci_device_id;/* Must be 0x if not PCI device */
 uint16_t pci_vendor_id;/* Must be 0x if not PCI device */
 uint8_t pci_bus;
@@ -120,7 +119,11 @@ typedef struct AcpiSpcrData {