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 efi_system_table_t *efi_systab; 31 static efi_config_table_type_t arch_tables[] __initdata = {{},}; 32 33 void __init efi_runtime_init(void) 34 { 35 if (!efi_enabled(EFI_BOOT)) 36 return; 37 38 if (efi_runtime_disabled()) { 39 pr_info("EFI runtime services will be disabled.\n"); 40 return; 41 } 42 43 efi.runtime = (efi_runtime_services_t *)efi_systab->runtime; 44 efi.runtime_version = (unsigned int)efi.runtime->hdr.revision; 45 46 efi_native_runtime_setup(); 47 set_bit(EFI_RUNTIME_SERVICES, &efi.flags); 48 } 49 50 void __init efi_init(void) 51 { 52 int size; 53 void *config_tables; 54 55 if (!efi_system_table) 56 return; 57 58 efi_systab = (efi_system_table_t *)early_memremap_ro(efi_system_table, sizeof(*efi_systab)); 59 if (!efi_systab) { 60 pr_err("Can't find EFI system table.\n"); 61 return; 62 } 63 64 set_bit(EFI_64BIT, &efi.flags); 65 efi_nr_tables = efi_systab->nr_tables; 66 efi_config_table = (unsigned long)efi_systab->tables; 67 68 size = sizeof(efi_config_table_t); 69 config_tables = early_memremap(efi_config_table, efi_nr_tables * size); 70 efi_config_parse_tables(config_tables, efi_systab->nr_tables, arch_tables); 71 early_memunmap(config_tables, efi_nr_tables * size); 72 } 73