qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Gabriel L. Somlo" <gsomlo@gmail.com>
To: qemu-devel@nongnu.org
Cc: kevin@koconnor.net, seabios@seabios.org, lersek@redhat.com,
	kraxel@redhat.com, agraf@suse.de
Subject: [Qemu-devel] [QEMU v5 PATCH 14/18] SMBIOS: Use e820 memory map to generate type 19 tables
Date: Fri, 11 Apr 2014 12:11:54 -0400	[thread overview]
Message-ID: <1397232718-15282-15-git-send-email-somlo@cmu.edu> (raw)
In-Reply-To: <1397232718-15282-1-git-send-email-somlo@cmu.edu>

Build type 19 (memory array mapped address, a.k.a. memory area)
tables by scanning the e820 map for E820_RAM entries. Since this
supercedes below_4g and above_4g ram amounts, we no longer need
them as arguments to smbios_set_defaults().

Signed-off-by: Gabriel Somlo <somlo@cmu.edu>
---
 hw/i386/pc.c             | 15 +++++++++++++++
 hw/i386/pc_piix.c        |  3 +--
 hw/i386/pc_q35.c         |  3 +--
 hw/i386/smbios.c         | 23 +++++++++++------------
 include/hw/i386/pc.h     |  2 ++
 include/hw/i386/smbios.h |  4 +---
 6 files changed, 31 insertions(+), 19 deletions(-)

diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index 6e3962e..ff353cf 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -612,6 +612,21 @@ int e820_add_entry(uint64_t address, uint64_t length, uint32_t type)
     return e820_entries;
 }
 
+int e820_get_num_entries(void)
+{
+    return e820_entries;
+}
+
+bool e820_get_entry(int idx, uint32_t type, uint64_t *address, uint64_t *length)
+{
+    if (idx < e820_entries && e820_table[idx].type == cpu_to_le32(type)) {
+        *address = le64_to_cpu(e820_table[idx].address);
+        *length = le64_to_cpu(e820_table[idx].length);
+        return true;
+    }
+    return false;
+}
+
 /* Calculates the limit to CPU APIC ID values
  *
  * This function returns the limit for the APIC ID value, so that all
diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
index db075eb..ba854eb 100644
--- a/hw/i386/pc_piix.c
+++ b/hw/i386/pc_piix.c
@@ -146,8 +146,7 @@ static void pc_init1(QEMUMachineInitArgs *args,
     if (smbios_defaults) {
         /* These values are guest ABI, do not change */
         smbios_set_defaults("QEMU", "Standard PC (i440FX + PIIX, 1996)",
-                             args->machine->name,
-                             below_4g_mem_size, above_4g_mem_size);
+                             args->machine->name);
     }
 
     /* allocate ram and load rom/bios */
diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c
index 3aaac7a..6d503ac 100644
--- a/hw/i386/pc_q35.c
+++ b/hw/i386/pc_q35.c
@@ -133,8 +133,7 @@ static void pc_q35_init(QEMUMachineInitArgs *args)
     if (smbios_defaults) {
         /* These values are guest ABI, do not change */
         smbios_set_defaults("QEMU", "Standard PC (Q35 + ICH9, 2009)",
-                             args->machine->name,
-                             below_4g_mem_size, above_4g_mem_size);
+                             args->machine->name);
     }
 
     /* allocate ram and load rom/bios */
diff --git a/hw/i386/smbios.c b/hw/i386/smbios.c
index 04a7f36..b98d7ba 100644
--- a/hw/i386/smbios.c
+++ b/hw/i386/smbios.c
@@ -18,6 +18,7 @@
 #include "qemu/config-file.h"
 #include "qemu/error-report.h"
 #include "sysemu/sysemu.h"
+#include "hw/i386/pc.h"
 #include "hw/i386/smbios.h"
 #include "hw/loader.h"
 
@@ -43,7 +44,6 @@ static int smbios_type4_count = 0;
 static bool smbios_immutable;
 static bool smbios_have_defaults;
 static uint32_t smbios_cpuid_version, smbios_cpuid_features; /* for type 4 */
-static ram_addr_t smbios_below_4g_ram, smbios_above_4g_ram; /* for type 19 */
 
 static DECLARE_BITMAP(have_binfile_bitmap, SMBIOS_MAX_TYPE+1);
 static DECLARE_BITMAP(have_fields_bitmap, SMBIOS_MAX_TYPE+1);
@@ -622,16 +622,10 @@ void smbios_set_cpuid(uint32_t version, uint32_t features)
 }
 
 void smbios_set_defaults(const char *manufacturer,
-                         const char *product, const char *version,
-                         ram_addr_t below_4g_mem_size,
-                         ram_addr_t above_4g_mem_size)
+                         const char *product, const char *version)
 {
     smbios_have_defaults = true;
 
-    assert(ram_size == below_4g_mem_size + above_4g_mem_size);
-    smbios_below_4g_ram = below_4g_mem_size;
-    smbios_above_4g_ram = above_4g_mem_size;
-
     SMBIOS_SET_DEFAULT(type0.vendor, manufacturer);
     SMBIOS_SET_DEFAULT(type0.version, version);
     SMBIOS_SET_DEFAULT(type0.date, "01/01/2014");
@@ -652,7 +646,7 @@ void smbios_set_defaults(const char *manufacturer,
 
 uint8_t *smbios_get_table(size_t *length)
 {
-    unsigned i, dimm_cnt;
+    unsigned i, dimm_cnt, instance;
 
     if (!smbios_immutable) {
         smbios_build_type_0_table();
@@ -667,13 +661,18 @@ uint8_t *smbios_get_table(size_t *length)
 #define GET_DIMM_SZ ((i < dimm_cnt - 1) ? MAX_DIMM_SZ : ram_size % MAX_DIMM_SZ)
 
         dimm_cnt = QEMU_ALIGN_UP(ram_size, MAX_DIMM_SZ) / MAX_DIMM_SZ;
+
         smbios_build_type_16_table(dimm_cnt);
+
         for (i = 0; i < dimm_cnt; i++) {
             smbios_build_type_17_table(i, GET_DIMM_SZ);
         }
-        smbios_build_type_19_table(0, 0, smbios_below_4g_ram);
-        if (smbios_above_4g_ram) {
-            smbios_build_type_19_table(1, 4 * ONE_GB, smbios_above_4g_ram);
+
+        for (i = 0, instance = 0; i < e820_get_num_entries(); i++) {
+            ram_addr_t address, length;
+            if (e820_get_entry(i, E820_RAM, &address, &length)) {
+                smbios_build_type_19_table(instance++, address, length);
+            }
         }
 
         smbios_build_type_32_table();
diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h
index 9010246..9f26e14 100644
--- a/include/hw/i386/pc.h
+++ b/include/hw/i386/pc.h
@@ -239,6 +239,8 @@ uint16_t pvpanic_port(void);
 #define E820_UNUSABLE   5
 
 int e820_add_entry(uint64_t, uint64_t, uint32_t);
+int e820_get_num_entries(void);
+bool e820_get_entry(int, uint32_t, uint64_t *, uint64_t *);
 
 #define PC_Q35_COMPAT_1_7 \
         PC_COMPAT_1_7, \
diff --git a/include/hw/i386/smbios.h b/include/hw/i386/smbios.h
index 6e59ed0..80e91b4 100644
--- a/include/hw/i386/smbios.h
+++ b/include/hw/i386/smbios.h
@@ -20,9 +20,7 @@
 void smbios_entry_add(QemuOpts *opts);
 void smbios_set_cpuid(uint32_t version, uint32_t features);
 void smbios_set_defaults(const char *manufacturer,
-                         const char *product, const char *version,
-                         ram_addr_t below_4g_mem_size,
-                         ram_addr_t above_4g_mem_size);
+                         const char *product, const char *version);
 uint8_t *smbios_get_table(size_t *length);
 
 /*
-- 
1.9.0

  parent reply	other threads:[~2014-04-11 16:12 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-04-11 16:11 [Qemu-devel] [QEMU v5 PATCH 00/18] SMBIOS: build full tables in QEMU Gabriel L. Somlo
2014-04-11 16:11 ` [Qemu-devel] [QEMU v5 PATCH 01/18] SMBIOS: Rename smbios_set_type1_defaults() for more general use Gabriel L. Somlo
2014-04-11 16:11 ` [Qemu-devel] [QEMU v5 PATCH 02/18] SMBIOS: Use macro to set smbios defaults Gabriel L. Somlo
2014-04-11 16:11 ` [Qemu-devel] [QEMU v5 PATCH 03/18] SMBIOS: Use bitmaps to check for smbios table collisions Gabriel L. Somlo
2014-04-11 16:11 ` [Qemu-devel] [QEMU v5 PATCH 04/18] SMBIOS: Add code to build full smbios tables; build type 2 table Gabriel L. Somlo
2014-04-11 16:11 ` [Qemu-devel] [QEMU v5 PATCH 05/18] SMBIOS: Build full tables for types 0 and 1 Gabriel L. Somlo
2014-04-11 16:11 ` [Qemu-devel] [QEMU v5 PATCH 06/18] SMBIOS: Remove unused code for passing individual fields to bios Gabriel L. Somlo
2014-04-11 16:11 ` [Qemu-devel] [QEMU v5 PATCH 07/18] SMBIOS: Build full type 3 table Gabriel L. Somlo
2014-04-11 16:11 ` [Qemu-devel] [QEMU v5 PATCH 08/18] SMBIOS: Build full type 4 tables Gabriel L. Somlo
2014-04-11 16:11 ` [Qemu-devel] [QEMU v5 PATCH 09/18] SMBIOS: Build full smbios memory tables (type 16, 17, 19, and 20) Gabriel L. Somlo
2014-04-11 16:11 ` [Qemu-devel] [QEMU v5 PATCH 10/18] SMBIOS: Build full tables for type 32 and 127 Gabriel L. Somlo
2014-04-11 16:11 ` [Qemu-devel] [QEMU v5 PATCH 11/18] SMBIOS: Update all table definitions to smbios spec v2.3 Gabriel L. Somlo
2014-04-11 16:11 ` [Qemu-devel] [QEMU v5 PATCH 12/18] SMBIOS: Remove SeaBIOS compatibility quirks Gabriel L. Somlo
2014-04-11 16:11 ` [Qemu-devel] [QEMU v5 PATCH 13/18] SMBIOS: Stop including type 20 tables Gabriel L. Somlo
2014-04-11 16:11 ` Gabriel L. Somlo [this message]
2014-04-11 16:11 ` [Qemu-devel] [QEMU v5 PATCH 15/18] SMBIOS: Update type 3 definition to smbios spec v2.7 Gabriel L. Somlo
2014-04-11 16:11 ` [Qemu-devel] [QEMU v5 PATCH 16/18] SMBIOS: Update type 4 definition to smbios spec v2.6 Gabriel L. Somlo
2014-04-11 16:11 ` [Qemu-devel] [QEMU v5 PATCH 17/18] SMBIOS: Update memory table types (16, 17, and 19) to smbios spec v2.8 Gabriel L. Somlo
2014-04-11 16:11 ` [Qemu-devel] [QEMU v5 PATCH 18/18] SMBIOS: Generate complete smbios tables, including entry point Gabriel L. Somlo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1397232718-15282-15-git-send-email-somlo@cmu.edu \
    --to=gsomlo@gmail.com \
    --cc=agraf@suse.de \
    --cc=kevin@koconnor.net \
    --cc=kraxel@redhat.com \
    --cc=lersek@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=seabios@seabios.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).