diff mbox

hvmloader, libxl: use the correct ACPI settings depending on device model

Message ID 1500499175-20541-1-git-send-email-igor.druzhinin@citrix.com (mailing list archive)
State New, archived
Headers show

Commit Message

Igor Druzhinin July 19, 2017, 9:19 p.m. UTC
We need to choose ACPI tables and ACPI IO port location
properly depending on the device model version we are running.
Previously, this decision was made by BIOS type specific
code in hvmloader, e.g. always load QEMU traditional specific
tables if it's ROMBIOS and always load QEMU Xen specific
tables if it's SeaBIOS.

This change saves this behavior but adds an additional way
(xenstore key) to specify the correct device model if we
happen to run a non-default one. Toolstack bit makes use of it.

Signed-off-by: Igor Druzhinin <igor.druzhinin@citrix.com>
---
 tools/firmware/hvmloader/hvmloader.c |  2 --
 tools/firmware/hvmloader/ovmf.c      |  2 ++
 tools/firmware/hvmloader/rombios.c   |  2 ++
 tools/firmware/hvmloader/seabios.c   |  3 +++
 tools/firmware/hvmloader/util.c      | 24 ++++++++++++++++++++++++
 tools/libxl/libxl_create.c           |  2 ++
 6 files changed, 33 insertions(+), 2 deletions(-)

Comments

Paul Durrant July 20, 2017, 10:46 a.m. UTC | #1
> -----Original Message-----

> From: Xen-devel [mailto:xen-devel-bounces@lists.xen.org] On Behalf Of

> Igor Druzhinin

> Sent: 19 July 2017 22:20

> To: xen-devel@lists.xen.org

> Cc: Igor Druzhinin <igor.druzhinin@citrix.com>; Ian Jackson

> <Ian.Jackson@citrix.com>; Wei Liu <wei.liu2@citrix.com>;

> jbeulich@suse.com; Andrew Cooper <Andrew.Cooper3@citrix.com>

> Subject: [Xen-devel] [PATCH] hvmloader, libxl: use the correct ACPI settings

> depending on device model

> 

> We need to choose ACPI tables and ACPI IO port location

> properly depending on the device model version we are running.

> Previously, this decision was made by BIOS type specific

> code in hvmloader, e.g. always load QEMU traditional specific

> tables if it's ROMBIOS and always load QEMU Xen specific

> tables if it's SeaBIOS.

> 

> This change saves this behavior but adds an additional way

> (xenstore key) to specify the correct device model if we

> happen to run a non-default one. Toolstack bit makes use of it.

> 

> Signed-off-by: Igor Druzhinin <igor.druzhinin@citrix.com>


Reviewed-by: Paul Durrant <paul.durrant@citrix.com>


> ---

>  tools/firmware/hvmloader/hvmloader.c |  2 --

>  tools/firmware/hvmloader/ovmf.c      |  2 ++

>  tools/firmware/hvmloader/rombios.c   |  2 ++

>  tools/firmware/hvmloader/seabios.c   |  3 +++

>  tools/firmware/hvmloader/util.c      | 24 ++++++++++++++++++++++++

>  tools/libxl/libxl_create.c           |  2 ++

>  6 files changed, 33 insertions(+), 2 deletions(-)

> 

> diff --git a/tools/firmware/hvmloader/hvmloader.c

> b/tools/firmware/hvmloader/hvmloader.c

> index f603f68..db11ab1 100644

> --- a/tools/firmware/hvmloader/hvmloader.c

> +++ b/tools/firmware/hvmloader/hvmloader.c

> @@ -405,8 +405,6 @@ int main(void)

>          }

> 

>          acpi_enable_sci();

> -

> -        hvm_param_set(HVM_PARAM_ACPI_IOPORTS_LOCATION, 1);

>      }

> 

>      init_vm86_tss();

> diff --git a/tools/firmware/hvmloader/ovmf.c

> b/tools/firmware/hvmloader/ovmf.c

> index 4ff7f1d..ebadc64 100644

> --- a/tools/firmware/hvmloader/ovmf.c

> +++ b/tools/firmware/hvmloader/ovmf.c

> @@ -127,6 +127,8 @@ static void ovmf_acpi_build_tables(void)

>          .dsdt_15cpu_len = 0

>      };

> 

> +    hvm_param_set(HVM_PARAM_ACPI_IOPORTS_LOCATION, 1);

> +

>      hvmloader_acpi_build_tables(&config, ACPI_PHYSICAL_ADDRESS);

>  }

> 

> diff --git a/tools/firmware/hvmloader/rombios.c

> b/tools/firmware/hvmloader/rombios.c

> index 56b39b7..31a7c65 100644

> --- a/tools/firmware/hvmloader/rombios.c

> +++ b/tools/firmware/hvmloader/rombios.c

> @@ -181,6 +181,8 @@ static void rombios_acpi_build_tables(void)

>          .dsdt_15cpu_len = dsdt_15cpu_len,

>      };

> 

> +    hvm_param_set(HVM_PARAM_ACPI_IOPORTS_LOCATION, 0);

> +

>      hvmloader_acpi_build_tables(&config, ACPI_PHYSICAL_ADDRESS);

>  }

> 

> diff --git a/tools/firmware/hvmloader/seabios.c

> b/tools/firmware/hvmloader/seabios.c

> index 870576a..5878eff 100644

> --- a/tools/firmware/hvmloader/seabios.c

> +++ b/tools/firmware/hvmloader/seabios.c

> @@ -28,6 +28,7 @@

> 

>  #include <acpi2_0.h>

>  #include <libacpi.h>

> +#include <xen/hvm/params.h>

> 

>  extern unsigned char dsdt_anycpu_qemu_xen[];

>  extern int dsdt_anycpu_qemu_xen_len;

> @@ -99,6 +100,8 @@ static void seabios_acpi_build_tables(void)

>          .dsdt_15cpu_len = 0,

>      };

> 

> +    hvm_param_set(HVM_PARAM_ACPI_IOPORTS_LOCATION, 1);

> +

>      hvmloader_acpi_build_tables(&config, rsdp);

>      add_table(rsdp);

>  }

> diff --git a/tools/firmware/hvmloader/util.c

> b/tools/firmware/hvmloader/util.c

> index db5f240..45b777c 100644

> --- a/tools/firmware/hvmloader/util.c

> +++ b/tools/firmware/hvmloader/util.c

> @@ -31,6 +31,9 @@

>  #include <xen/hvm/hvm_xs_strings.h>

>  #include <xen/hvm/params.h>

> 

> +extern unsigned char dsdt_anycpu_qemu_xen[], dsdt_anycpu[],

> dsdt_15cpu[];

> +extern int dsdt_anycpu_qemu_xen_len, dsdt_anycpu_len,

> dsdt_15cpu_len;

> +

>  /*

>   * Check whether there exists overlap in the specified memory range.

>   * Returns true if exists, else returns false.

> @@ -897,6 +900,27 @@ void hvmloader_acpi_build_tables(struct acpi_config

> *config,

>      /* Allocate and initialise the acpi info area. */

>      mem_hole_populate_ram(ACPI_INFO_PHYSICAL_ADDRESS >>

> PAGE_SHIFT, 1);

> 

> +    /* If the device model is specified switch to the corresponding tables */

> +    s = xenstore_read("platform/device-model", "");

> +    if ( !strncmp(s, "qemu_xen_traditional", 21) )

> +    {

> +        config->dsdt_anycpu = dsdt_anycpu;

> +        config->dsdt_anycpu_len = dsdt_anycpu_len;

> +        config->dsdt_15cpu = dsdt_15cpu;

> +        config->dsdt_15cpu_len = dsdt_15cpu_len;

> +

> +        hvm_param_set(HVM_PARAM_ACPI_IOPORTS_LOCATION, 0);

> +    }

> +    else if ( !strncmp(s, "qemu_xen", 10) )

> +    {

> +        config->dsdt_anycpu = dsdt_anycpu_qemu_xen;

> +        config->dsdt_anycpu_len = dsdt_anycpu_qemu_xen_len;

> +        config->dsdt_15cpu = NULL;

> +        config->dsdt_15cpu_len = 0;

> +

> +        hvm_param_set(HVM_PARAM_ACPI_IOPORTS_LOCATION, 1);

> +    }

> +

>      config->lapic_base_address = LAPIC_BASE_ADDRESS;

>      config->lapic_id = acpi_lapic_id;

>      config->ioapic_base_address = ioapic_base_address;

> diff --git a/tools/libxl/libxl_create.c b/tools/libxl/libxl_create.c

> index 1158303..8dc8186 100644

> --- a/tools/libxl/libxl_create.c

> +++ b/tools/libxl/libxl_create.c

> @@ -472,6 +472,8 @@ int libxl__domain_build(libxl__gc *gc,

>                                     info->u.hvm.mmio_hole_memkb << 10);

>              }

>          }

> +        localents[i++] = "platform/device-model";

> +        localents[i++] = (char *) libxl_device_model_version_to_string(info-

> >device_model_version);

> 

>          break;

>      case LIBXL_DOMAIN_TYPE_PV:

> --

> 2.7.4

> 

> 

> _______________________________________________

> Xen-devel mailing list

> Xen-devel@lists.xen.org

> https://lists.xen.org/xen-devel
Wei Liu July 25, 2017, 2:33 p.m. UTC | #2
On Wed, Jul 19, 2017 at 10:19:35PM +0100, Igor Druzhinin wrote:
> diff --git a/tools/libxl/libxl_create.c b/tools/libxl/libxl_create.c
> index 1158303..8dc8186 100644
> --- a/tools/libxl/libxl_create.c
> +++ b/tools/libxl/libxl_create.c
> @@ -472,6 +472,8 @@ int libxl__domain_build(libxl__gc *gc,
>                                     info->u.hvm.mmio_hole_memkb << 10);
>              }
>          }
> +        localents[i++] = "platform/device-model";
> +        localents[i++] = (char *) libxl_device_model_version_to_string(info->device_model_version);

You probably want to enlarge localents array so that it can accommodate
the new elements.
Igor Druzhinin July 25, 2017, 2:53 p.m. UTC | #3
On 25/07/17 15:33, Wei Liu wrote:
> On Wed, Jul 19, 2017 at 10:19:35PM +0100, Igor Druzhinin wrote:
>> diff --git a/tools/libxl/libxl_create.c b/tools/libxl/libxl_create.c
>> index 1158303..8dc8186 100644
>> --- a/tools/libxl/libxl_create.c
>> +++ b/tools/libxl/libxl_create.c
>> @@ -472,6 +472,8 @@ int libxl__domain_build(libxl__gc *gc,
>>                                     info->u.hvm.mmio_hole_memkb << 10);
>>              }
>>          }
>> +        localents[i++] = "platform/device-model";
>> +        localents[i++] = (char *) libxl_device_model_version_to_string(info->device_model_version);
> 
> You probably want to enlarge localents array so that it can accommodate
> the new elements.
> 

Good catch, for some reason I thought it's already preallocated big
enough. It looks like somebody before me made the same mistake as it's
already small enough to hold all the items.

Igor
Wei Liu July 25, 2017, 2:56 p.m. UTC | #4
On Tue, Jul 25, 2017 at 03:53:14PM +0100, Igor Druzhinin wrote:
> On 25/07/17 15:33, Wei Liu wrote:
> > On Wed, Jul 19, 2017 at 10:19:35PM +0100, Igor Druzhinin wrote:
> >> diff --git a/tools/libxl/libxl_create.c b/tools/libxl/libxl_create.c
> >> index 1158303..8dc8186 100644
> >> --- a/tools/libxl/libxl_create.c
> >> +++ b/tools/libxl/libxl_create.c
> >> @@ -472,6 +472,8 @@ int libxl__domain_build(libxl__gc *gc,
> >>                                     info->u.hvm.mmio_hole_memkb << 10);
> >>              }
> >>          }
> >> +        localents[i++] = "platform/device-model";
> >> +        localents[i++] = (char *) libxl_device_model_version_to_string(info->device_model_version);
> > 
> > You probably want to enlarge localents array so that it can accommodate
> > the new elements.
> > 
> 
> Good catch, for some reason I thought it's already preallocated big
> enough. It looks like somebody before me made the same mistake as it's
> already small enough to hold all the items.
> 

Yeah, it is made smallest possible. You probably didn't write beyond the
boundary due to the fact that a few entries are written conditionally.
diff mbox

Patch

diff --git a/tools/firmware/hvmloader/hvmloader.c b/tools/firmware/hvmloader/hvmloader.c
index f603f68..db11ab1 100644
--- a/tools/firmware/hvmloader/hvmloader.c
+++ b/tools/firmware/hvmloader/hvmloader.c
@@ -405,8 +405,6 @@  int main(void)
         }
 
         acpi_enable_sci();
-
-        hvm_param_set(HVM_PARAM_ACPI_IOPORTS_LOCATION, 1);
     }
 
     init_vm86_tss();
diff --git a/tools/firmware/hvmloader/ovmf.c b/tools/firmware/hvmloader/ovmf.c
index 4ff7f1d..ebadc64 100644
--- a/tools/firmware/hvmloader/ovmf.c
+++ b/tools/firmware/hvmloader/ovmf.c
@@ -127,6 +127,8 @@  static void ovmf_acpi_build_tables(void)
         .dsdt_15cpu_len = 0
     };
 
+    hvm_param_set(HVM_PARAM_ACPI_IOPORTS_LOCATION, 1);
+
     hvmloader_acpi_build_tables(&config, ACPI_PHYSICAL_ADDRESS);
 }
 
diff --git a/tools/firmware/hvmloader/rombios.c b/tools/firmware/hvmloader/rombios.c
index 56b39b7..31a7c65 100644
--- a/tools/firmware/hvmloader/rombios.c
+++ b/tools/firmware/hvmloader/rombios.c
@@ -181,6 +181,8 @@  static void rombios_acpi_build_tables(void)
         .dsdt_15cpu_len = dsdt_15cpu_len,
     };
 
+    hvm_param_set(HVM_PARAM_ACPI_IOPORTS_LOCATION, 0);
+
     hvmloader_acpi_build_tables(&config, ACPI_PHYSICAL_ADDRESS);
 }
 
diff --git a/tools/firmware/hvmloader/seabios.c b/tools/firmware/hvmloader/seabios.c
index 870576a..5878eff 100644
--- a/tools/firmware/hvmloader/seabios.c
+++ b/tools/firmware/hvmloader/seabios.c
@@ -28,6 +28,7 @@ 
 
 #include <acpi2_0.h>
 #include <libacpi.h>
+#include <xen/hvm/params.h>
 
 extern unsigned char dsdt_anycpu_qemu_xen[];
 extern int dsdt_anycpu_qemu_xen_len;
@@ -99,6 +100,8 @@  static void seabios_acpi_build_tables(void)
         .dsdt_15cpu_len = 0,
     };
 
+    hvm_param_set(HVM_PARAM_ACPI_IOPORTS_LOCATION, 1);
+
     hvmloader_acpi_build_tables(&config, rsdp);
     add_table(rsdp);
 }
diff --git a/tools/firmware/hvmloader/util.c b/tools/firmware/hvmloader/util.c
index db5f240..45b777c 100644
--- a/tools/firmware/hvmloader/util.c
+++ b/tools/firmware/hvmloader/util.c
@@ -31,6 +31,9 @@ 
 #include <xen/hvm/hvm_xs_strings.h>
 #include <xen/hvm/params.h>
 
+extern unsigned char dsdt_anycpu_qemu_xen[], dsdt_anycpu[], dsdt_15cpu[];
+extern int dsdt_anycpu_qemu_xen_len, dsdt_anycpu_len, dsdt_15cpu_len;
+
 /*
  * Check whether there exists overlap in the specified memory range.
  * Returns true if exists, else returns false.
@@ -897,6 +900,27 @@  void hvmloader_acpi_build_tables(struct acpi_config *config,
     /* Allocate and initialise the acpi info area. */
     mem_hole_populate_ram(ACPI_INFO_PHYSICAL_ADDRESS >> PAGE_SHIFT, 1);
 
+    /* If the device model is specified switch to the corresponding tables */
+    s = xenstore_read("platform/device-model", "");
+    if ( !strncmp(s, "qemu_xen_traditional", 21) )
+    {
+        config->dsdt_anycpu = dsdt_anycpu;
+        config->dsdt_anycpu_len = dsdt_anycpu_len;
+        config->dsdt_15cpu = dsdt_15cpu;
+        config->dsdt_15cpu_len = dsdt_15cpu_len;
+
+        hvm_param_set(HVM_PARAM_ACPI_IOPORTS_LOCATION, 0);
+    }
+    else if ( !strncmp(s, "qemu_xen", 10) )
+    {
+        config->dsdt_anycpu = dsdt_anycpu_qemu_xen;
+        config->dsdt_anycpu_len = dsdt_anycpu_qemu_xen_len;
+        config->dsdt_15cpu = NULL;
+        config->dsdt_15cpu_len = 0;
+
+        hvm_param_set(HVM_PARAM_ACPI_IOPORTS_LOCATION, 1);
+    }
+
     config->lapic_base_address = LAPIC_BASE_ADDRESS;
     config->lapic_id = acpi_lapic_id;
     config->ioapic_base_address = ioapic_base_address;
diff --git a/tools/libxl/libxl_create.c b/tools/libxl/libxl_create.c
index 1158303..8dc8186 100644
--- a/tools/libxl/libxl_create.c
+++ b/tools/libxl/libxl_create.c
@@ -472,6 +472,8 @@  int libxl__domain_build(libxl__gc *gc,
                                    info->u.hvm.mmio_hole_memkb << 10);
             }
         }
+        localents[i++] = "platform/device-model";
+        localents[i++] = (char *) libxl_device_model_version_to_string(info->device_model_version);
 
         break;
     case LIBXL_DOMAIN_TYPE_PV: