1 // SPDX-License-Identifier: GPL-2.0 2 /* 3 * EFI initialization 4 * 5 * Author: Jianmin Lv <lvjianmin@loongson.cn> 6 * Huacai Chen <chenhuacai@loongson.cn> 7 * 8 * Copyright (C) 2020-2022 Loongson Technology Corporation Limited 9 */ 10 11 #include <linux/acpi.h> 12 #include <linux/efi.h> 13 #include <linux/efi-bgrt.h> 14 #include <linux/init.h> 15 #include <linux/kernel.h> 16 #include <linux/export.h> 17 #include <linux/io.h> 18 #include <linux/kobject.h> 19 #include <linux/memblock.h> 20 #include <linux/reboot.h> 21 #include <linux/uaccess.h> 22 23 #include <asm/early_ioremap.h> 24 #include <asm/efi.h> 25 #include <asm/loongson.h> 26 27 static unsigned long efi_nr_tables; 28 static unsigned long efi_config_table; 29 30 static unsigned long __initdata boot_memmap = EFI_INVALID_TABLE_ADDR; 31 32 static efi_system_table_t *efi_systab; 33 static efi_config_table_type_t arch_tables[] __initdata = { 34 {LINUX_EFI_BOOT_MEMMAP_GUID, &boot_memmap, "MEMMAP" }, 35 {}, 36 }; 37 38 void __init efi_runtime_init(void) 39 { 40 if (!efi_enabled(EFI_BOOT)) 41 return; 42 43 if (efi_runtime_disabled()) { 44 pr_info("EFI runtime services will be disabled.\n"); 45 return; 46 } 47 48 efi.runtime = (efi_runtime_services_t *)efi_systab->runtime; 49 efi.runtime_version = (unsigned int)efi.runtime->hdr.revision; 50 51 efi_native_runtime_setup(); 52 set_bit(EFI_RUNTIME_SERVICES, &efi.flags); 53 } 54 55 void __init efi_init(void) 56 { 57 int size; 58 void *config_tables; 59 struct efi_boot_memmap *tbl; 60 61 if (!efi_system_table) 62 return; 63 64 efi_systab = (efi_system_table_t *)early_memremap_ro(efi_system_table, sizeof(*efi_systab)); 65 if (!efi_systab) { 66 pr_err("Can't find EFI system table.\n"); 67 return; 68 } 69 70 efi_systab_report_header(&efi_systab->hdr, efi_systab->fw_vendor); 71 72 set_bit(EFI_64BIT, &efi.flags); 73 efi_nr_tables = efi_systab->nr_tables; 74 efi_config_table = (unsigned long)efi_systab->tables; 75 76 size = sizeof(efi_config_table_t); 77 config_tables = early_memremap(efi_config_table, efi_nr_tables * size); 78 efi_config_parse_tables(config_tables, efi_systab->nr_tables, arch_tables); 79 early_memunmap(config_tables, efi_nr_tables * size); 80 81 set_bit(EFI_CONFIG_TABLES, &efi.flags); 82 83 if (screen_info.orig_video_isVGA == VIDEO_TYPE_EFI) 84 memblock_reserve(screen_info.lfb_base, screen_info.lfb_size); 85 86 if (boot_memmap == EFI_INVALID_TABLE_ADDR) 87 return; 88 89 tbl = early_memremap_ro(boot_memmap, sizeof(*tbl)); 90 if (tbl) { 91 struct efi_memory_map_data data; 92 93 data.phys_map = boot_memmap + sizeof(*tbl); 94 data.size = tbl->map_size; 95 data.desc_size = tbl->desc_size; 96 data.desc_version = tbl->desc_ver; 97 98 if (efi_memmap_init_early(&data) < 0) 99 panic("Unable to map EFI memory map.\n"); 100 101 early_memunmap(tbl, sizeof(*tbl)); 102 } 103 } 104