Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch/x86 x86: make btinfo_memmap from btinfo_efimemmap f...



details:   https://anonhg.NetBSD.org/src/rev/1d657c704db8
branches:  trunk
changeset: 821720:1d657c704db8
user:      nonaka <nonaka%NetBSD.org@localhost>
date:      Tue Feb 14 13:23:50 2017 +0000

description:
x86: make btinfo_memmap from btinfo_efimemmap for to reduce mem_cluster_cnt.

should fix PR/51953.

diffstat:

 sys/arch/x86/acpi/acpi_machdep.c |  76 +++++++++++------------------------
 sys/arch/x86/include/efi.h       |   5 +-
 sys/arch/x86/x86/efi.c           |  83 ++++++++++++++++++++++++++++++++++++++-
 sys/arch/x86/x86/x86_machdep.c   |  84 ++++++++++++++-------------------------
 4 files changed, 141 insertions(+), 107 deletions(-)

diffs (truncated from 369 to 300 lines):

diff -r 52afb2c4a06f -r 1d657c704db8 sys/arch/x86/acpi/acpi_machdep.c
--- a/sys/arch/x86/acpi/acpi_machdep.c  Tue Feb 14 09:59:16 2017 +0000
+++ b/sys/arch/x86/acpi/acpi_machdep.c  Tue Feb 14 13:23:50 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi_machdep.c,v 1.16 2017/02/09 11:56:40 nonaka Exp $ */
+/* $NetBSD: acpi_machdep.c,v 1.17 2017/02/14 13:23:50 nonaka Exp $ */
 
 /*
  * Copyright 2001 Wasabi Systems, Inc.
@@ -40,7 +40,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: acpi_machdep.c,v 1.16 2017/02/09 11:56:40 nonaka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_machdep.c,v 1.17 2017/02/14 13:23:50 nonaka Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -366,62 +366,36 @@
 static bool
 acpi_md_mcfg_validate(uint64_t addr, int bus_start, int *bus_end)
 {
-       union {
-               struct btinfo_common *common;
-               struct btinfo_memmap *bios;
-               struct btinfo_efimemmap *efi;
-       } bim;
+       struct btinfo_memmap *bim;
        uint64_t size, mapaddr, mapsize;
        uint32_t type;
-       int i, n, num;
-       bool efimemmap;
+       int i, n;
 
-       bim.common = lookup_bootinfo(BTINFO_EFIMEMMAP);
-       if (bim.common == NULL) {
-               bim.common = lookup_bootinfo(BTINFO_MEMMAP);
-               if (bim.common == NULL)
-                       return false;
-       }
-       efimemmap = bim.common->type == BTINFO_EFIMEMMAP;
-       num = efimemmap ? bim.efi->num : bim.bios->num;
+#ifndef XEN
+       if (lookup_bootinfo(BTINFO_EFIMEMMAP) != NULL)
+               bim = efi_get_e820memmap();
+       else
+#endif
+               bim = lookup_bootinfo(BTINFO_MEMMAP);
+       if (bim == NULL)
+               return false;
 
        size = *bus_end - bus_start + 1;
        size *= ACPIMCFG_SIZE_PER_BUS;
-       for (i = 0; i < num; i++) {
-#ifndef XEN
-               if (efimemmap) {
-                       struct efi_md *md = (struct efi_md *)
-                           (bim.efi->memmap + bim.efi->size * i);
-                       mapaddr = md->md_phys;
-                       mapsize = md->md_pages * EFI_PAGE_SIZE;
-                       type = efi_getbiosmemtype(md->md_type, md->md_attr);
+       for (i = 0; i < bim->num; i++) {
+               mapaddr = bim->entry[i].addr;
+               mapsize = bim->entry[i].size;
+               type = bim->entry[i].type;
 
-                       aprint_debug("MCFG: MEMMAP: "
-                           "p0x%016" PRIx64 "-0x%016" PRIx64
-                           ", v0x%016" PRIx64 "-0x%016" PRIx64
-                           ", size=0x%016" PRIx64 ", attr=0x%016" PRIx64
-                           ", type=%d(%s)\n",
-                           mapaddr, mapaddr + mapsize - 1,
-                           md->md_virt, md->md_virt + mapsize - 1,
-                           size, md->md_attr, md->md_type,
-                           efi_getmemtype_str(md->md_type));
-               } else
-#endif
-               {
-                       mapaddr = bim.bios->entry[i].addr;
-                       mapsize = bim.bios->entry[i].size;
-                       type = bim.bios->entry[i].type;
-
-                       aprint_debug("MCFG: MEMMAP: 0x%016" PRIx64
-                           "-0x%016" PRIx64 ", size=0x%016" PRIx64
-                           ", type=%d(%s)\n",
-                           mapaddr, mapaddr + mapsize - 1, mapsize, type,
-                           (type == BIM_Memory) ?  "Memory" :
-                           (type == BIM_Reserved) ?  "Reserved" :
-                           (type == BIM_ACPI) ? "ACPI" :
-                           (type == BIM_NVS) ? "NVS" :
-                           "unknown");
-               }
+               aprint_debug("MCFG: MEMMAP: 0x%016" PRIx64
+                   "-0x%016" PRIx64 ", size=0x%016" PRIx64
+                   ", type=%d(%s)\n",
+                   mapaddr, mapaddr + mapsize - 1, mapsize, type,
+                   (type == BIM_Memory) ?  "Memory" :
+                   (type == BIM_Reserved) ?  "Reserved" :
+                   (type == BIM_ACPI) ? "ACPI" :
+                   (type == BIM_NVS) ? "NVS" :
+                   "unknown");
 
                switch (type) {
                case BIM_ACPI:
diff -r 52afb2c4a06f -r 1d657c704db8 sys/arch/x86/include/efi.h
--- a/sys/arch/x86/include/efi.h        Tue Feb 14 09:59:16 2017 +0000
+++ b/sys/arch/x86/include/efi.h        Tue Feb 14 13:23:50 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: efi.h,v 1.3 2017/02/09 11:56:40 nonaka Exp $   */
+/*     $NetBSD: efi.h,v 1.4 2017/02/14 13:23:50 nonaka Exp $   */
 
 /*-
  * Copyright (c) 2004 Marcel Moolenaar
@@ -165,6 +165,9 @@
 void              *efi_getcfgtbl(const struct uuid*);
 int                efi_getbiosmemtype(uint32_t, uint64_t);
 const char        *efi_getmemtype_str(uint32_t);
+struct btinfo_memmap;
+struct btinfo_memmap *efi_get_e820memmap(void);
+
 /*
 void efi_boot_finish(void);
 int efi_boot_minimal(uint64_t);
diff -r 52afb2c4a06f -r 1d657c704db8 sys/arch/x86/x86/efi.c
--- a/sys/arch/x86/x86/efi.c    Tue Feb 14 09:59:16 2017 +0000
+++ b/sys/arch/x86/x86/efi.c    Tue Feb 14 13:23:50 2017 +0000
@@ -1,4 +1,5 @@
-/*     $NetBSD: efi.c,v 1.6 2017/01/26 01:35:51 nonaka Exp $   */
+/*     $NetBSD: efi.c,v 1.7 2017/02/14 13:23:50 nonaka Exp $   */
+
 /*-
  * Copyright (c) 2016 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -24,8 +25,10 @@
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  * POSSIBILITY OF SUCH DAMAGE.
  */
+
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: efi.c,v 1.6 2017/01/26 01:35:51 nonaka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: efi.c,v 1.7 2017/02/14 13:23:50 nonaka Exp $");
+
 #include <sys/kmem.h>
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -65,6 +68,10 @@
 static bool efi_is32bit = false;
 static struct efi_systbl *efi_systbl_va = NULL;
 static struct efi_cfgtbl *efi_cfgtblhead_va = NULL;
+static struct efi_e820memmap {
+       struct btinfo_memmap bim;
+       struct bi_memmap_entry entry[VM_PHYSSEG_MAX - 1];
+} efi_e820memmap;
 
 /*
  * Map a physical address (PA) to a newly allocated virtual address (VA).
@@ -349,3 +356,75 @@
                return efimemtypes[type];
        return "unknown";
 }
+
+struct btinfo_memmap *
+efi_get_e820memmap(void)
+{
+       struct btinfo_efimemmap *efimm;
+       struct bi_memmap_entry *entry;
+       struct efi_md *md;
+       uint64_t addr, size;
+       uint64_t start_addr, end_addr;
+       uint32_t i;
+       int n, type, seg_type = -1;
+
+       if (efi_e820memmap.bim.common.type == BTINFO_MEMMAP)
+               return &efi_e820memmap.bim;
+
+       efimm = lookup_bootinfo(BTINFO_EFIMEMMAP);
+       if (efimm == NULL)
+               return NULL;
+
+       for (n = 0, i = 0; i < efimm->num; i++) {
+               md = (struct efi_md *)(efimm->memmap + efimm->size * i);
+               addr = md->md_phys;
+               size = md->md_pages * EFI_PAGE_SIZE;
+               type = efi_getbiosmemtype(md->md_type, md->md_attr);
+
+#ifdef DEBUG_MEMLOAD
+               printf("MEMMAP: p0x%016" PRIx64 "-0x%016" PRIx64
+                   ", v0x%016" PRIx64 "-0x%016" PRIx64
+                   ", size=0x%016" PRIx64 ", attr=0x%016" PRIx64
+                   ", type=%d(%s)\n",
+                   addr, addr + size - 1,
+                   md->md_virt, md->md_virt + size - 1,
+                   size, md->md_attr, md->md_type,
+                   efi_getmemtype_str(md->md_type));
+#endif
+
+               if (seg_type == -1) {
+                       /* first entry */
+               } else if (seg_type == type && end_addr == addr) {
+                       /* continuous region */
+                       end_addr = addr + size;
+                       continue;
+               } else {
+                       entry = &efi_e820memmap.bim.entry[n];
+                       entry->addr = start_addr;
+                       entry->size = end_addr - start_addr;
+                       entry->type = seg_type;
+                       if (++n == VM_PHYSSEG_MAX)
+                               break;
+               }
+
+               start_addr = addr;
+               end_addr = addr + size;
+               seg_type = type;
+       }
+       if (i > 0 && n < VM_PHYSSEG_MAX) {
+               entry = &efi_e820memmap.bim.entry[n];
+               entry->addr = start_addr;
+               entry->size = end_addr - start_addr;
+               entry->type = seg_type;
+               ++n;
+       } else if (n == VM_PHYSSEG_MAX) {
+               printf("WARNING: too many memory segments"
+                   "(increase VM_PHYSSEG_MAX)\n");
+       }
+
+       efi_e820memmap.bim.num = n;
+       efi_e820memmap.bim.common.len =
+           (intptr_t)&efi_e820memmap.bim.entry[n] - (intptr_t)&efi_e820memmap;
+       efi_e820memmap.bim.common.type = BTINFO_MEMMAP;
+       return &efi_e820memmap.bim;
+}
diff -r 52afb2c4a06f -r 1d657c704db8 sys/arch/x86/x86/x86_machdep.c
--- a/sys/arch/x86/x86/x86_machdep.c    Tue Feb 14 09:59:16 2017 +0000
+++ b/sys/arch/x86/x86/x86_machdep.c    Tue Feb 14 13:23:50 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: x86_machdep.c,v 1.87 2017/02/10 10:39:36 maxv Exp $    */
+/*     $NetBSD: x86_machdep.c,v 1.88 2017/02/14 13:23:50 nonaka Exp $  */
 
 /*-
  * Copyright (c) 2002, 2006, 2007 YAMAMOTO Takashi,
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: x86_machdep.c,v 1.87 2017/02/10 10:39:36 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: x86_machdep.c,v 1.88 2017/02/14 13:23:50 nonaka Exp $");
 
 #include "opt_modular.h"
 #include "opt_physmem.h"
@@ -630,62 +630,36 @@
 }
 
 static int
-x86_parse_clusters(struct btinfo_common *bi)
+x86_parse_clusters(struct btinfo_memmap *bim)
 {
-       union {
-               struct btinfo_common *common;
-               struct btinfo_memmap *bios;
-               struct btinfo_efimemmap *efi;
-       } bim;
        uint64_t seg_start, seg_end;
        uint64_t addr, size;
        uint32_t type;
-       int x, num;
-       bool efimemmap;
+       int x;
 
-       KASSERT(bi != NULL);
-       bim.common = bi;
-       efimemmap = bi->type == BTINFO_EFIMEMMAP;
-       num = efimemmap ? bim.efi->num : bim.bios->num;
-       KASSERT(num > 0);
+       KASSERT(bim != NULL);
+       KASSERT(bim->num > 0);
 
 #ifdef DEBUG_MEMLOAD
        printf("MEMMAP: %s MEMORY MAP (%d ENTRIES):\n",
-           efimemmap ? "UEFI" : "BIOS", num);
+           lookup_bootinfo(BTINFO_EFIMEMMAP) != NULL ? "UEFI" : "BIOS",
+           bim->num);
 #endif
 
-       for (x = 0; x < num; x++) {
-               if (efimemmap) {
-                       struct efi_md *md = (struct efi_md *)
-                           (bim.efi->memmap + bim.efi->size * x);
-                       addr = md->md_phys;
-                       size = md->md_pages * EFI_PAGE_SIZE;
-                       type = efi_getbiosmemtype(md->md_type, md->md_attr);
+       for (x = 0; x < bim->num; x++) {
+               addr = bim->entry[x].addr;
+               size = bim->entry[x].size;
+               type = bim->entry[x].type;
 #ifdef DEBUG_MEMLOAD
-                       printf("MEMMAP: p0x%016" PRIx64 "-0x%016" PRIx64
-                           ", v0x%016" PRIx64 "-0x%016" PRIx64
-                           ", size=0x%016" PRIx64 ", attr=0x%016" PRIx64
-                           ", type=%d(%s)\n",



Home | Main Index | Thread Index | Old Index