1 // SPDX-License-Identifier: GPL-2.0
3 * Author: Yun Liu <liuyun@loongson.cn>
4 * Huacai Chen <chenhuacai@loongson.cn>
5 * Copyright (C) 2020-2022 Loongson Technology Corporation Limited
9 #include <asm/addrspace.h>
12 typedef void __noreturn (*kernel_entry_t)(bool efi, unsigned long cmdline,
13 unsigned long systab);
15 efi_status_t check_platform_features(void)
20 struct exit_boot_struct {
21 efi_memory_desc_t *runtime_map;
22 int runtime_entry_count;
25 static efi_status_t exit_boot_func(struct efi_boot_memmap *map, void *priv)
27 struct exit_boot_struct *p = priv;
30 * Update the memory map with virtual addresses. The function will also
31 * populate @runtime_map with copies of just the EFI_MEMORY_RUNTIME
32 * entries so that we can pass it straight to SetVirtualAddressMap()
34 efi_get_virtmap(map->map, map->map_size, map->desc_size,
35 p->runtime_map, &p->runtime_entry_count);
40 unsigned long __weak kernel_entry_address(void)
42 return *(unsigned long *)(PHYSADDR(VMLINUX_LOAD_ADDRESS) + 8);
45 efi_status_t efi_boot_kernel(void *handle, efi_loaded_image_t *image,
46 unsigned long kernel_addr, char *cmdline_ptr)
48 kernel_entry_t real_kernel_entry;
49 struct exit_boot_struct priv;
50 unsigned long desc_size;
54 status = efi_alloc_virtmap(&priv.runtime_map, &desc_size, &desc_ver);
55 if (status != EFI_SUCCESS) {
56 efi_err("Unable to retrieve UEFI memory map.\n");
60 efi_info("Exiting boot services\n");
63 status = efi_exit_boot_services(handle, &priv, exit_boot_func);
64 if (status != EFI_SUCCESS)
67 /* Install the new virtual address map */
68 efi_rt_call(set_virtual_address_map,
69 priv.runtime_entry_count * desc_size, desc_size,
70 desc_ver, priv.runtime_map);
72 /* Config Direct Mapping */
73 csr_write64(CSR_DMW0_INIT, LOONGARCH_CSR_DMWIN0);
74 csr_write64(CSR_DMW1_INIT, LOONGARCH_CSR_DMWIN1);
76 real_kernel_entry = (void *)kernel_entry_address();
78 real_kernel_entry(true, (unsigned long)cmdline_ptr,
79 (unsigned long)efi_system_table);