xref: /linux/drivers/firmware/efi/libstub/loongarch-stub.c (revision 4b660dbd9ee2059850fd30e0df420ca7a38a1856)
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 #include "loongarch-stub.h"
12 
13 extern int kernel_asize;
14 extern int kernel_fsize;
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)image->image_base;
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 		efi_loaded_image_t *image)
40 {
41 	unsigned long base = (unsigned long)image->image_base;
42 
43 	return (unsigned long)&kernel_entry - base + kernel_addr;
44 }
45