1 // SPDX-License-Identifier: GPL-2.0-or-later 2 /* 3 * Copyright (C) 2020-2022 Loongson Technology Corporation Limited 4 */ 5 #include <linux/efi.h> 6 #include <linux/initrd.h> 7 #include <linux/memblock.h> 8 9 #include <asm/bootinfo.h> 10 #include <asm/loongson.h> 11 #include <asm/sections.h> 12 13 void __init memblock_init(void) 14 { 15 u32 mem_type; 16 u64 mem_start, mem_end, mem_size; 17 efi_memory_desc_t *md; 18 19 /* Parse memory information */ 20 for_each_efi_memory_desc(md) { 21 mem_type = md->type; 22 mem_start = md->phys_addr; 23 mem_size = md->num_pages << EFI_PAGE_SHIFT; 24 mem_end = mem_start + mem_size; 25 26 switch (mem_type) { 27 case EFI_LOADER_CODE: 28 case EFI_LOADER_DATA: 29 case EFI_BOOT_SERVICES_CODE: 30 case EFI_BOOT_SERVICES_DATA: 31 case EFI_PERSISTENT_MEMORY: 32 case EFI_CONVENTIONAL_MEMORY: 33 memblock_add(mem_start, mem_size); 34 if (max_low_pfn < (mem_end >> PAGE_SHIFT)) 35 max_low_pfn = mem_end >> PAGE_SHIFT; 36 break; 37 case EFI_PAL_CODE: 38 case EFI_UNUSABLE_MEMORY: 39 case EFI_ACPI_RECLAIM_MEMORY: 40 memblock_add(mem_start, mem_size); 41 fallthrough; 42 case EFI_RESERVED_TYPE: 43 case EFI_RUNTIME_SERVICES_CODE: 44 case EFI_RUNTIME_SERVICES_DATA: 45 case EFI_MEMORY_MAPPED_IO: 46 case EFI_MEMORY_MAPPED_IO_PORT_SPACE: 47 memblock_reserve(mem_start, mem_size); 48 break; 49 } 50 } 51 52 memblock_set_current_limit(PFN_PHYS(max_low_pfn)); 53 memblock_set_node(0, PHYS_ADDR_MAX, &memblock.memory, 0); 54 55 /* Reserve the first 2MB */ 56 memblock_reserve(PHYS_OFFSET, 0x200000); 57 58 /* Reserve the kernel text/data/bss */ 59 memblock_reserve(__pa_symbol(&_text), 60 __pa_symbol(&_end) - __pa_symbol(&_text)); 61 62 /* Reserve the initrd */ 63 reserve_initrd_mem(); 64 } 65