Source-Changes-HG archive

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

[src/trunk]: src/sys/stand/efiboot Various clean ups



details:   https://anonhg.NetBSD.org/src/rev/4ce13d1e51a1
branches:  trunk
changeset: 979182:4ce13d1e51a1
user:      skrll <skrll%NetBSD.org@localhost>
date:      Sat Dec 19 08:09:31 2020 +0000

description:
Various clean ups
 - cache node where possible
 - remove a compiler warning
 - improve a comment (the round_page might not be needed)

diffstat:

 sys/stand/efiboot/efifdt.c |  42 +++++++++++++++++++++++++-----------------
 1 files changed, 25 insertions(+), 17 deletions(-)

diffs (88 lines):

diff -r 2f33ab979d70 -r 4ce13d1e51a1 sys/stand/efiboot/efifdt.c
--- a/sys/stand/efiboot/efifdt.c        Sat Dec 19 07:19:30 2020 +0000
+++ b/sys/stand/efiboot/efifdt.c        Sat Dec 19 08:09:31 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: efifdt.c,v 1.27 2020/10/22 09:28:30 jmcneill Exp $ */
+/* $NetBSD: efifdt.c,v 1.28 2020/12/19 08:09:31 skrll Exp $ */
 
 /*-
  * Copyright (c) 2019 Jason R. Thorpe
@@ -235,7 +235,7 @@
        EFI_MEMORY_DESCRIPTOR *md, *memmap;
        UINT32 descver;
        UINT64 phys_start, phys_size;
-       int n, memory, chosen;
+       int n, memory;
 
        memory = fdt_path_offset(fdt_data, FDT_MEMORY_NODE_PATH);
        if (memory < 0)
@@ -243,8 +243,6 @@
        if (memory < 0)
                panic("FDT: Failed to create " FDT_MEMORY_NODE_PATH " node");
 
-       chosen = efi_fdt_chosen();
-
        fdt_delprop(fdt_data, memory, "reg");
 
        const int address_cells = fdt_address_cells(fdt_data, fdt_path_offset(fdt_data, "/"));
@@ -252,10 +250,15 @@
 
        memmap = LibMemoryMap(&nentries, &mapkey, &descsize, &descver);
        for (n = 0, md = memmap; n < nentries; n++, md = NextMemoryDescriptor(md, descsize)) {
-               fdt_appendprop_u32(fdt_data, fdt_path_offset(fdt_data, FDT_CHOSEN_NODE_PATH), "netbsd,uefi-memmap", md->Type);
-               fdt_appendprop_u64(fdt_data, fdt_path_offset(fdt_data, FDT_CHOSEN_NODE_PATH), "netbsd,uefi-memmap", md->PhysicalStart);
-               fdt_appendprop_u64(fdt_data, fdt_path_offset(fdt_data, FDT_CHOSEN_NODE_PATH), "netbsd,uefi-memmap", md->NumberOfPages);
-               fdt_appendprop_u64(fdt_data, fdt_path_offset(fdt_data, FDT_CHOSEN_NODE_PATH), "netbsd,uefi-memmap", md->Attribute);
+               /*
+                * create / find the chosen node for each iteration as it might have changed
+                * when adding to the memory node
+                */
+               int chosen = efi_fdt_chosen();
+               fdt_appendprop_u32(fdt_data, chosen, "netbsd,uefi-memmap", md->Type);
+               fdt_appendprop_u64(fdt_data, chosen, "netbsd,uefi-memmap", md->PhysicalStart);
+               fdt_appendprop_u64(fdt_data, chosen, "netbsd,uefi-memmap", md->NumberOfPages);
+               fdt_appendprop_u64(fdt_data, chosen, "netbsd,uefi-memmap", md->Attribute);
 
                if ((md->Attribute & EFI_MEMORY_RUNTIME) != 0)
                        continue;
@@ -273,26 +276,31 @@
                phys_size = md->NumberOfPages * EFI_PAGE_SIZE;
 
                if (phys_start & EFI_PAGE_MASK) {
-                       /* UEFI spec says these should be 4KB aligned, but U-Boot doesn't always.. */
+                       /*
+                        * UEFI spec says these should be 4KB aligned, but
+                        * U-Boot doesn't always, so round up to the next
+                        * page.
+                        */
                        phys_start = (phys_start + EFI_PAGE_SIZE) & ~EFI_PAGE_MASK;
                        phys_size -= (EFI_PAGE_SIZE * 2);
                        if (phys_size == 0)
                                continue;
                }
 
+               memory = fdt_path_offset(fdt_data, FDT_MEMORY_NODE_PATH);
                if (address_cells == 1)
-                       fdt_appendprop_u32(fdt_data, fdt_path_offset(fdt_data, FDT_MEMORY_NODE_PATH),
-                           "reg", (uint32_t)phys_start);
+                       fdt_appendprop_u32(fdt_data, memory, "reg",
+                           (uint32_t)phys_start);
                else
-                       fdt_appendprop_u64(fdt_data, fdt_path_offset(fdt_data, FDT_MEMORY_NODE_PATH),
-                           "reg", phys_start);
+                       fdt_appendprop_u64(fdt_data, memory, "reg",
+                           phys_start);
 
                if (size_cells == 1)
-                       fdt_appendprop_u32(fdt_data, fdt_path_offset(fdt_data, FDT_MEMORY_NODE_PATH),
-                           "reg", (uint32_t)phys_size);
+                       fdt_appendprop_u32(fdt_data, memory, "reg",
+                           (uint32_t)phys_size);
                else
-                       fdt_appendprop_u64(fdt_data, fdt_path_offset(fdt_data, FDT_MEMORY_NODE_PATH),
-                           "reg", phys_size);
+                       fdt_appendprop_u64(fdt_data, memory, "reg",
+                           phys_size);
        }
 }
 



Home | Main Index | Thread Index | Old Index