1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Author: Yun Liu <liuyun@loongson.cn>
4  *         Huacai Chen <chenhuacai@loongson.cn>
5  * Copyright (C) 2020-2022 Loongson Technology Corporation Limited
6  */
7 
8 #include <asm/efi.h>
9 #include <asm/addrspace.h>
10 #include "efistub.h"
11 
12 extern int kernel_asize;
13 extern int kernel_fsize;
14 extern int kernel_offset;
15 extern int kernel_entry;
16 
17 efi_status_t handle_kernel_image(unsigned long *image_addr,
18 				 unsigned long *image_size,
19 				 unsigned long *reserve_addr,
20 				 unsigned long *reserve_size,
21 				 efi_loaded_image_t *image,
22 				 efi_handle_t image_handle)
23 {
24 	efi_status_t status;
25 	unsigned long kernel_addr = 0;
26 
27 	kernel_addr = (unsigned long)&kernel_offset - kernel_offset;
28 
29 	status = efi_relocate_kernel(&kernel_addr, kernel_fsize, kernel_asize,
30 		     EFI_KIMG_PREFERRED_ADDRESS, efi_get_kimg_min_align(), 0x0);
31 
32 	*image_addr = kernel_addr;
33 	*image_size = kernel_asize;
34 
35 	return status;
36 }
37 
38 unsigned long kernel_entry_address(unsigned long kernel_addr)
39 {
40 	unsigned long base = (unsigned long)&kernel_offset - kernel_offset;
41 
42 	return (unsigned long)&kernel_entry - base + kernel_addr;
43 }
44