14febfb8dSArd Biesheuvel // SPDX-License-Identifier: GPL-2.0
2bf457786SArd Biesheuvel /*
3bf457786SArd Biesheuvel * Copyright (C) 2013, 2014 Linaro Ltd; <roy.franz@linaro.org>
4bf457786SArd Biesheuvel *
5bf457786SArd Biesheuvel * This file implements the EFI boot stub for the arm64 kernel.
6bf457786SArd Biesheuvel * Adapted from ARM version by Mark Salter <msalter@redhat.com>
7bf457786SArd Biesheuvel */
80426a4e6SArd Biesheuvel
90426a4e6SArd Biesheuvel
10bf457786SArd Biesheuvel #include <linux/efi.h>
11bf457786SArd Biesheuvel #include <asm/efi.h>
12170976bcSMark Rutland #include <asm/memory.h>
136f05106eSArd Biesheuvel #include <asm/sections.h>
14bf457786SArd Biesheuvel
152b5fe07aSArd Biesheuvel #include "efistub.h"
162b5fe07aSArd Biesheuvel
handle_kernel_image(unsigned long * image_addr,unsigned long * image_size,unsigned long * reserve_addr,unsigned long * reserve_size,efi_loaded_image_t * image,efi_handle_t image_handle)17cd33a5c1SArd Biesheuvel efi_status_t handle_kernel_image(unsigned long *image_addr,
18bf457786SArd Biesheuvel unsigned long *image_size,
19bf457786SArd Biesheuvel unsigned long *reserve_addr,
20bf457786SArd Biesheuvel unsigned long *reserve_size,
21416a9f84SArd Biesheuvel efi_loaded_image_t *image,
22416a9f84SArd Biesheuvel efi_handle_t image_handle)
23bf457786SArd Biesheuvel {
24bf457786SArd Biesheuvel efi_status_t status;
2561786170SArd Biesheuvel unsigned long kernel_size, kernel_codesize, kernel_memsize;
262dc10ad8SLinus Torvalds
27fc3608aaSArd Biesheuvel if (image->image_base != _text) {
28793473c2SArvind Sankar efi_err("FIRMWARE BUG: efi_loaded_image_t::image_base has bogus value\n");
29fc3608aaSArd Biesheuvel image->image_base = _text;
30fc3608aaSArd Biesheuvel }
31bf457786SArd Biesheuvel
32e9b7c3a4SMihai Carabas if (!IS_ALIGNED((u64)_text, SEGMENT_ALIGN))
33e9b7c3a4SMihai Carabas efi_err("FIRMWARE BUG: kernel image not aligned on %dk boundary\n",
34e9b7c3a4SMihai Carabas SEGMENT_ALIGN >> 10);
35c32ac11dSArd Biesheuvel
36bf457786SArd Biesheuvel kernel_size = _edata - _text;
3761786170SArd Biesheuvel kernel_codesize = __inittext_end - _text;
38bf457786SArd Biesheuvel kernel_memsize = kernel_size + (_end - _edata);
39120dc60dSArd Biesheuvel *reserve_size = kernel_memsize;
40*6b56beb5SAlexandre Ghiti *image_addr = (unsigned long)_text;
41bf457786SArd Biesheuvel
42*6b56beb5SAlexandre Ghiti status = efi_kaslr_relocate_kernel(image_addr,
43*6b56beb5SAlexandre Ghiti reserve_addr, reserve_size,
44*6b56beb5SAlexandre Ghiti kernel_size, kernel_codesize,
45*6b56beb5SAlexandre Ghiti kernel_memsize,
46*6b56beb5SAlexandre Ghiti efi_kaslr_get_phys_seed(image_handle));
47ff80ef5bSArd Biesheuvel if (status != EFI_SUCCESS)
48bf457786SArd Biesheuvel return status;
49aaeb3fc6SArd Biesheuvel
50bf457786SArd Biesheuvel return EFI_SUCCESS;
51bf457786SArd Biesheuvel }
5261786170SArd Biesheuvel
5361786170SArd Biesheuvel asmlinkage void primary_entry(void);
5461786170SArd Biesheuvel
primary_entry_offset(void)5561786170SArd Biesheuvel unsigned long primary_entry_offset(void)
5661786170SArd Biesheuvel {
5761786170SArd Biesheuvel /*
5861786170SArd Biesheuvel * When built as part of the kernel, the EFI stub cannot branch to the
5961786170SArd Biesheuvel * kernel proper via the image header, as the PE/COFF header is
6061786170SArd Biesheuvel * strictly not part of the in-memory presentation of the image, only
6161786170SArd Biesheuvel * of the file representation. So instead, we need to jump to the
6261786170SArd Biesheuvel * actual entrypoint in the .text region of the image.
6361786170SArd Biesheuvel */
6461786170SArd Biesheuvel return (char *)primary_entry - _text;
6561786170SArd Biesheuvel }
66*6b56beb5SAlexandre Ghiti
efi_icache_sync(unsigned long start,unsigned long end)67*6b56beb5SAlexandre Ghiti void efi_icache_sync(unsigned long start, unsigned long end)
68*6b56beb5SAlexandre Ghiti {
69*6b56beb5SAlexandre Ghiti caches_clean_inval_pou(start, end);
70*6b56beb5SAlexandre Ghiti }
71