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>
11 #include "loongarch-stub.h"
13 typedef void __noreturn (*kernel_entry_t
)(bool efi
, unsigned long cmdline
,
14 unsigned long systab
);
16 efi_status_t
check_platform_features(void)
21 struct exit_boot_struct
{
22 efi_memory_desc_t
*runtime_map
;
23 int runtime_entry_count
;
26 static efi_status_t
exit_boot_func(struct efi_boot_memmap
*map
, void *priv
)
28 struct exit_boot_struct
*p
= priv
;
31 * Update the memory map with virtual addresses. The function will also
32 * populate @runtime_map with copies of just the EFI_MEMORY_RUNTIME
33 * entries so that we can pass it straight to SetVirtualAddressMap()
35 efi_get_virtmap(map
->map
, map
->map_size
, map
->desc_size
,
36 p
->runtime_map
, &p
->runtime_entry_count
);
41 unsigned long __weak
kernel_entry_address(unsigned long kernel_addr
,
42 efi_loaded_image_t
*image
)
44 return *(unsigned long *)(kernel_addr
+ 8) - PHYSADDR(VMLINUX_LOAD_ADDRESS
) + kernel_addr
;
47 efi_status_t
efi_boot_kernel(void *handle
, efi_loaded_image_t
*image
,
48 unsigned long kernel_addr
, char *cmdline_ptr
)
50 kernel_entry_t real_kernel_entry
;
51 struct exit_boot_struct priv
;
52 unsigned long desc_size
;
56 status
= efi_alloc_virtmap(&priv
.runtime_map
, &desc_size
, &desc_ver
);
57 if (status
!= EFI_SUCCESS
) {
58 efi_err("Unable to retrieve UEFI memory map.\n");
62 efi_info("Exiting boot services\n");
65 status
= efi_exit_boot_services(handle
, &priv
, exit_boot_func
);
66 if (status
!= EFI_SUCCESS
)
69 /* Install the new virtual address map */
70 efi_rt_call(set_virtual_address_map
,
71 priv
.runtime_entry_count
* desc_size
, desc_size
,
72 desc_ver
, priv
.runtime_map
);
74 /* Config Direct Mapping */
75 csr_write64(CSR_DMW0_INIT
, LOONGARCH_CSR_DMWIN0
);
76 csr_write64(CSR_DMW1_INIT
, LOONGARCH_CSR_DMWIN1
);
77 csr_write64(CSR_DMW2_INIT
, LOONGARCH_CSR_DMWIN2
);
78 csr_write64(CSR_DMW3_INIT
, LOONGARCH_CSR_DMWIN3
);
80 real_kernel_entry
= (void *)kernel_entry_address(kernel_addr
, image
);
82 real_kernel_entry(true, (unsigned long)cmdline_ptr
,
83 (unsigned long)efi_system_table
);