Re: [Qemu-devel] [ARM SMBIOS V3 PATCH 4/5] smbios: add smbios 3.0 support

2015-08-12 Thread Michael S. Tsirkin
On Tue, Aug 11, 2015 at 10:08:21PM -0400, Wei Huang wrote:
 This patch adds support for SMBIOS 3.0 entry point. When caller invokes
 smbios_set_defaults(), it can specify entry point as 2.1 or 3.0. Then
 smbios_get_tables() will return the entry point table in right format.
 
 Acked-by: Gabriel Somlo so...@cmu.edu
 Tested-by: Gabriel Somlo so...@cmu.edu
 Tested-by: Leif Lindholm leif.lindh...@linaro.org
 Signed-off-by: Wei Huang w...@redhat.com
 ---
  hw/i386/pc_piix.c  |  3 +-
  hw/i386/pc_q35.c   |  3 +-
  hw/smbios/smbios.c | 83 
 +-
  include/hw/smbios/smbios.h | 51 
  4 files changed, 101 insertions(+), 39 deletions(-)
 
 diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
 index 653c710..04636b1 100644
 --- a/hw/i386/pc_piix.c
 +++ b/hw/i386/pc_piix.c
 @@ -173,7 +173,8 @@ static void pc_init1(MachineState *machine)
  MachineClass *mc = MACHINE_GET_CLASS(machine);
  /* These values are guest ABI, do not change */
  smbios_set_defaults(QEMU, Standard PC (i440FX + PIIX, 1996),
 -mc-name, smbios_legacy_mode, 
 smbios_uuid_encoded);
 +mc-name, smbios_legacy_mode, 
 smbios_uuid_encoded,
 +SMBIOS_ENTRY_POINT_21);
  }
  
  /* allocate ram and load rom/bios */
 diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c
 index d83df14..061507d 100644
 --- a/hw/i386/pc_q35.c
 +++ b/hw/i386/pc_q35.c
 @@ -165,7 +165,8 @@ static void pc_q35_init(MachineState *machine)
  if (smbios_defaults) {
  /* These values are guest ABI, do not change */
  smbios_set_defaults(QEMU, Standard PC (Q35 + ICH9, 2009),
 -mc-name, smbios_legacy_mode, 
 smbios_uuid_encoded);
 +mc-name, smbios_legacy_mode, 
 smbios_uuid_encoded,
 +SMBIOS_ENTRY_POINT_21);
  }
  
  /* allocate ram and load rom/bios */
 diff --git a/hw/smbios/smbios.c b/hw/smbios/smbios.c
 index efdbb5d..de3cab5 100644
 --- a/hw/smbios/smbios.c
 +++ b/hw/smbios/smbios.c
 @@ -55,7 +55,10 @@ static uint8_t *smbios_tables;
  static size_t smbios_tables_len;
  static unsigned smbios_table_max;
  static unsigned smbios_table_cnt;
 -static struct smbios_entry_point ep;
 +static SmbiosEntryPointType smbios_ep_type = SMBIOS_ENTRY_POINT_21;
 +
 +static SmbiosEntryPoint ep;
 +static size_t ep_length;

I think it's better to drop ep_length and write a function that
retrieves length from ep, based on anchor string.  Don't duplicate
information.


  
  static int smbios_type4_count = 0;
  static bool smbios_immutable;
 @@ -771,11 +774,12 @@ void smbios_set_cpuid(uint32_t version, uint32_t 
 features)
  
  void smbios_set_defaults(const char *manufacturer, const char *product,
   const char *version, bool legacy_mode,
 - bool uuid_encoded)
 + bool uuid_encoded, SmbiosEntryPointType ep_type)
  {
  smbios_have_defaults = true;
  smbios_legacy = legacy_mode;
  smbios_uuid_encoded = uuid_encoded;
 +smbios_ep_type = ep_type;
  
  /* drop unwanted version of command-line file blob(s) */
  if (smbios_legacy) {
 @@ -808,26 +812,59 @@ void smbios_set_defaults(const char *manufacturer, 
 const char *product,
  
  static void smbios_entry_point_setup(void)
  {
 -memcpy(ep.anchor_string, _SM_, 4);
 -memcpy(ep.intermediate_anchor_string, _DMI_, 5);
 -ep.length = sizeof(struct smbios_entry_point);
 -ep.entry_point_revision = 0; /* formatted_area reserved, per spec v2.1+ 
 */
 -memset(ep.formatted_area, 0, 5);
 -
 -/* compliant with smbios spec v2.8 */
 -ep.smbios_major_version = 2;
 -ep.smbios_minor_version = 8;
 -ep.smbios_bcd_revision = 0x28;
 -
 -/* set during table construction, but BIOS may override: */
 -ep.structure_table_length = cpu_to_le16(smbios_tables_len);
 -ep.max_structure_size = cpu_to_le16(smbios_table_max);
 -ep.number_of_structures = cpu_to_le16(smbios_table_cnt);
 -
 -/* BIOS must recalculate: */
 -ep.checksum = 0;
 -ep.intermediate_checksum = 0;
 -ep.structure_table_address = cpu_to_le32(0);
 +switch (smbios_ep_type) {
 +case SMBIOS_ENTRY_POINT_21:
 +memcpy(ep.ep21.anchor_string, _SM_, 4);
 +memcpy(ep.ep21.intermediate_anchor_string, _DMI_, 5);
 +ep.ep21.length = sizeof(struct smbios_21_entry_point);
 +ep.ep21.entry_point_revision = 0; /* formatted_area reserved */
 +memset(ep.ep21.formatted_area, 0, 5);
 +
 +/* compliant with smbios spec v2.8 */
 +ep.ep21.smbios_major_version = 2;
 +ep.ep21.smbios_minor_version = 8;
 +ep.ep21.smbios_bcd_revision = 0x28;
 +
 +/* set during table construction, but BIOS may override: */
 +ep.ep21.structure_table_length = cpu_to_le16(smbios_tables_len);
 +

[Qemu-devel] [ARM SMBIOS V3 PATCH 4/5] smbios: add smbios 3.0 support

2015-08-11 Thread Wei Huang
This patch adds support for SMBIOS 3.0 entry point. When caller invokes
smbios_set_defaults(), it can specify entry point as 2.1 or 3.0. Then
smbios_get_tables() will return the entry point table in right format.

Acked-by: Gabriel Somlo so...@cmu.edu
Tested-by: Gabriel Somlo so...@cmu.edu
Tested-by: Leif Lindholm leif.lindh...@linaro.org
Signed-off-by: Wei Huang w...@redhat.com
---
 hw/i386/pc_piix.c  |  3 +-
 hw/i386/pc_q35.c   |  3 +-
 hw/smbios/smbios.c | 83 +-
 include/hw/smbios/smbios.h | 51 
 4 files changed, 101 insertions(+), 39 deletions(-)

diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
index 653c710..04636b1 100644
--- a/hw/i386/pc_piix.c
+++ b/hw/i386/pc_piix.c
@@ -173,7 +173,8 @@ static void pc_init1(MachineState *machine)
 MachineClass *mc = MACHINE_GET_CLASS(machine);
 /* These values are guest ABI, do not change */
 smbios_set_defaults(QEMU, Standard PC (i440FX + PIIX, 1996),
-mc-name, smbios_legacy_mode, smbios_uuid_encoded);
+mc-name, smbios_legacy_mode, smbios_uuid_encoded,
+SMBIOS_ENTRY_POINT_21);
 }
 
 /* allocate ram and load rom/bios */
diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c
index d83df14..061507d 100644
--- a/hw/i386/pc_q35.c
+++ b/hw/i386/pc_q35.c
@@ -165,7 +165,8 @@ static void pc_q35_init(MachineState *machine)
 if (smbios_defaults) {
 /* These values are guest ABI, do not change */
 smbios_set_defaults(QEMU, Standard PC (Q35 + ICH9, 2009),
-mc-name, smbios_legacy_mode, smbios_uuid_encoded);
+mc-name, smbios_legacy_mode, smbios_uuid_encoded,
+SMBIOS_ENTRY_POINT_21);
 }
 
 /* allocate ram and load rom/bios */
diff --git a/hw/smbios/smbios.c b/hw/smbios/smbios.c
index efdbb5d..de3cab5 100644
--- a/hw/smbios/smbios.c
+++ b/hw/smbios/smbios.c
@@ -55,7 +55,10 @@ static uint8_t *smbios_tables;
 static size_t smbios_tables_len;
 static unsigned smbios_table_max;
 static unsigned smbios_table_cnt;
-static struct smbios_entry_point ep;
+static SmbiosEntryPointType smbios_ep_type = SMBIOS_ENTRY_POINT_21;
+
+static SmbiosEntryPoint ep;
+static size_t ep_length;
 
 static int smbios_type4_count = 0;
 static bool smbios_immutable;
@@ -771,11 +774,12 @@ void smbios_set_cpuid(uint32_t version, uint32_t features)
 
 void smbios_set_defaults(const char *manufacturer, const char *product,
  const char *version, bool legacy_mode,
- bool uuid_encoded)
+ bool uuid_encoded, SmbiosEntryPointType ep_type)
 {
 smbios_have_defaults = true;
 smbios_legacy = legacy_mode;
 smbios_uuid_encoded = uuid_encoded;
+smbios_ep_type = ep_type;
 
 /* drop unwanted version of command-line file blob(s) */
 if (smbios_legacy) {
@@ -808,26 +812,59 @@ void smbios_set_defaults(const char *manufacturer, const 
char *product,
 
 static void smbios_entry_point_setup(void)
 {
-memcpy(ep.anchor_string, _SM_, 4);
-memcpy(ep.intermediate_anchor_string, _DMI_, 5);
-ep.length = sizeof(struct smbios_entry_point);
-ep.entry_point_revision = 0; /* formatted_area reserved, per spec v2.1+ */
-memset(ep.formatted_area, 0, 5);
-
-/* compliant with smbios spec v2.8 */
-ep.smbios_major_version = 2;
-ep.smbios_minor_version = 8;
-ep.smbios_bcd_revision = 0x28;
-
-/* set during table construction, but BIOS may override: */
-ep.structure_table_length = cpu_to_le16(smbios_tables_len);
-ep.max_structure_size = cpu_to_le16(smbios_table_max);
-ep.number_of_structures = cpu_to_le16(smbios_table_cnt);
-
-/* BIOS must recalculate: */
-ep.checksum = 0;
-ep.intermediate_checksum = 0;
-ep.structure_table_address = cpu_to_le32(0);
+switch (smbios_ep_type) {
+case SMBIOS_ENTRY_POINT_21:
+memcpy(ep.ep21.anchor_string, _SM_, 4);
+memcpy(ep.ep21.intermediate_anchor_string, _DMI_, 5);
+ep.ep21.length = sizeof(struct smbios_21_entry_point);
+ep.ep21.entry_point_revision = 0; /* formatted_area reserved */
+memset(ep.ep21.formatted_area, 0, 5);
+
+/* compliant with smbios spec v2.8 */
+ep.ep21.smbios_major_version = 2;
+ep.ep21.smbios_minor_version = 8;
+ep.ep21.smbios_bcd_revision = 0x28;
+
+/* set during table construction, but BIOS may override: */
+ep.ep21.structure_table_length = cpu_to_le16(smbios_tables_len);
+ep.ep21.max_structure_size = cpu_to_le16(smbios_table_max);
+ep.ep21.number_of_structures = cpu_to_le16(smbios_table_cnt);
+
+/* BIOS must recalculate */
+ep.ep21.checksum = 0;
+ep.ep21.intermediate_checksum = 0;
+ep.ep21.structure_table_address = cpu_to_le32(0);
+
+/* setup the anchor point length */
+