Author: andrew
Date: Mon May 28 17:09:29 2018
New Revision: 334289
URL: https://svnweb.freebsd.org/changeset/base/334289

Log:
  Create a new function to walk the EFI memory table & run a callback for
  each entry. We can then use this to ensure the RunTime data is mapped in
  the DMAP, but not in phys_avail.
  
  Sponsored by: DARPA, AFRL

Modified:
  head/sys/arm64/arm64/machdep.c

Modified: head/sys/arm64/arm64/machdep.c
==============================================================================
--- head/sys/arm64/arm64/machdep.c      Mon May 28 17:08:37 2018        
(r334288)
+++ head/sys/arm64/arm64/machdep.c      Mon May 28 17:09:29 2018        
(r334289)
@@ -720,8 +720,10 @@ typedef struct {
        uint64_t attr;
 } EFI_MEMORY_DESCRIPTOR;
 
+typedef void (*efi_map_entry_cb)(struct efi_md *);
+
 static void
-add_efi_map_entries(struct efi_map_header *efihdr)
+foreach_efi_map_entry(struct efi_map_header *efihdr, efi_map_entry_cb cb)
 {
        struct efi_md *map, *p;
        const char *type;
@@ -797,25 +799,69 @@ add_efi_map_entries(struct efi_map_header *efihdr)
                        printf("\n");
                }
 
-               switch (p->md_type) {
-               case EFI_MD_TYPE_CODE:
-               case EFI_MD_TYPE_DATA:
-               case EFI_MD_TYPE_BS_CODE:
-               case EFI_MD_TYPE_BS_DATA:
-               case EFI_MD_TYPE_FREE:
-                       /*
-                        * We're allowed to use any entry with these types.
-                        */
-                       break;
-               default:
-                       continue;
-               }
+               cb(p);
+       }
+}
 
+static void
+exclude_efi_map_entry(struct efi_md *p)
+{
+
+       switch (p->md_type) {
+       case EFI_MD_TYPE_CODE:
+       case EFI_MD_TYPE_DATA:
+       case EFI_MD_TYPE_BS_CODE:
+       case EFI_MD_TYPE_BS_DATA:
+       case EFI_MD_TYPE_FREE:
+               /*
+                * We're allowed to use any entry with these types.
+                */
+               break;
+       default:
+               arm_physmem_exclude_region(p->md_phys, p->md_pages * PAGE_SIZE,
+                   EXFLAG_NOALLOC);
+       }
+}
+
+static void
+exclude_efi_map_entries(struct efi_map_header *efihdr)
+{
+
+       foreach_efi_map_entry(efihdr, exclude_efi_map_entry);
+}
+
+static void
+add_efi_map_entry(struct efi_md *p)
+{
+
+       switch (p->md_type) {
+       case EFI_MD_TYPE_RT_DATA:
+               /*
+                * Runtime data will be excluded after the DMAP
+                * region is created to stop it from being added
+                * to phys_avail.
+                */
+       case EFI_MD_TYPE_CODE:
+       case EFI_MD_TYPE_DATA:
+       case EFI_MD_TYPE_BS_CODE:
+       case EFI_MD_TYPE_BS_DATA:
+       case EFI_MD_TYPE_FREE:
+               /*
+                * We're allowed to use any entry with these types.
+                */
                arm_physmem_hardware_region(p->md_phys,
                    p->md_pages * PAGE_SIZE);
+               break;
        }
 }
 
+static void
+add_efi_map_entries(struct efi_map_header *efihdr)
+{
+
+       foreach_efi_map_entry(efihdr, add_efi_map_entry);
+}
+
 #ifdef FDT
 static void
 try_load_dtb(caddr_t kmdp)
@@ -1001,6 +1047,9 @@ initarm(struct arm64_bootparams *abp)
        /* Bootstrap enough of pmap  to enter the kernel proper */
        pmap_bootstrap(abp->kern_l0pt, abp->kern_l1pt,
            KERNBASE - abp->kern_delta, lastaddr - KERNBASE);
+       /* Exclude entries neexed in teh DMAP region, but not phys_avail */
+       if (efihdr != NULL)
+               exclude_efi_map_entries(efihdr);
        arm_physmem_init_kernel_globals();
 
        devmap_bootstrap(0, NULL);
_______________________________________________
[email protected] mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "[email protected]"

Reply via email to