Get memory ranges from FDT if no EFI API is available on ARM64

Obtained from:         Semihalf
Submitted by:          Michal Stanek <mst@semihalf.com>
Sponsored by:          Annapurna Labs
Approved by:           cognet (mentor)
Reviewed by:           andrew, wma
Differential revision: https://reviews.freebsd.org/D5408
This commit is contained in:
Wojciech Macek 2016-03-01 12:50:24 +00:00
parent 9636600cf2
commit a5d461a398

View File

@ -83,6 +83,7 @@ __FBSDID("$FreeBSD$");
#endif #endif
#ifdef FDT #ifdef FDT
#include <dev/fdt/fdt_common.h>
#include <dev/ofw/openfirm.h> #include <dev/ofw/openfirm.h>
#endif #endif
@ -668,6 +669,20 @@ add_physmap_entry(uint64_t base, uint64_t length, vm_paddr_t *physmap,
return (1); return (1);
} }
#ifdef FDT
static void
add_fdt_mem_regions(struct mem_region *mr, int mrcnt, vm_paddr_t *physmap,
u_int *physmap_idxp)
{
for (int i = 0; i < mrcnt; i++) {
if (!add_physmap_entry(mr[i].mr_start, mr[i].mr_size, physmap,
physmap_idxp))
break;
}
}
#endif
#define efi_next_descriptor(ptr, size) \ #define efi_next_descriptor(ptr, size) \
((struct efi_md *)(((uint8_t *) ptr) + size)) ((struct efi_md *)(((uint8_t *) ptr) + size))
@ -807,6 +822,10 @@ initarm(struct arm64_bootparams *abp)
{ {
struct efi_map_header *efihdr; struct efi_map_header *efihdr;
struct pcpu *pcpup; struct pcpu *pcpup;
#ifdef FDT
struct mem_region mem_regions[FDT_MEM_REGIONS];
int mem_regions_sz;
#endif
vm_offset_t lastaddr; vm_offset_t lastaddr;
caddr_t kmdp; caddr_t kmdp;
vm_paddr_t mem_len; vm_paddr_t mem_len;
@ -834,7 +853,18 @@ initarm(struct arm64_bootparams *abp)
physmap_idx = 0; physmap_idx = 0;
efihdr = (struct efi_map_header *)preload_search_info(kmdp, efihdr = (struct efi_map_header *)preload_search_info(kmdp,
MODINFO_METADATA | MODINFOMD_EFI_MAP); MODINFO_METADATA | MODINFOMD_EFI_MAP);
if (efihdr != NULL)
add_efi_map_entries(efihdr, physmap, &physmap_idx); add_efi_map_entries(efihdr, physmap, &physmap_idx);
#ifdef FDT
else {
/* Grab physical memory regions information from device tree. */
if (fdt_get_mem_regions(mem_regions, &mem_regions_sz,
NULL) != 0)
panic("Cannot get physical memory regions");
add_fdt_mem_regions(mem_regions, mem_regions_sz, physmap,
&physmap_idx);
}
#endif
/* Print the memory map */ /* Print the memory map */
mem_len = 0; mem_len = 0;