Merge tag 'asoc-v3.17-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie...
[sfrench/cifs-2.6.git] / arch / arm64 / kernel / efi-stub.c
1 /*
2  * Copyright (C) 2013, 2014 Linaro Ltd;  <roy.franz@linaro.org>
3  *
4  * This file implements the EFI boot stub for the arm64 kernel.
5  * Adapted from ARM version by Mark Salter <msalter@redhat.com>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License version 2 as
9  * published by the Free Software Foundation.
10  *
11  */
12 #include <linux/efi.h>
13 #include <asm/efi.h>
14 #include <asm/sections.h>
15
16 efi_status_t handle_kernel_image(efi_system_table_t *sys_table,
17                                  unsigned long *image_addr,
18                                  unsigned long *image_size,
19                                  unsigned long *reserve_addr,
20                                  unsigned long *reserve_size,
21                                  unsigned long dram_base,
22                                  efi_loaded_image_t *image)
23 {
24         efi_status_t status;
25         unsigned long kernel_size, kernel_memsize = 0;
26
27         /* Relocate the image, if required. */
28         kernel_size = _edata - _text;
29         if (*image_addr != (dram_base + TEXT_OFFSET)) {
30                 kernel_memsize = kernel_size + (_end - _edata);
31                 status = efi_relocate_kernel(sys_table, image_addr,
32                                              kernel_size, kernel_memsize,
33                                              dram_base + TEXT_OFFSET,
34                                              PAGE_SIZE);
35                 if (status != EFI_SUCCESS) {
36                         pr_efi_err(sys_table, "Failed to relocate kernel\n");
37                         return status;
38                 }
39                 if (*image_addr != (dram_base + TEXT_OFFSET)) {
40                         pr_efi_err(sys_table, "Failed to alloc kernel memory\n");
41                         efi_free(sys_table, kernel_memsize, *image_addr);
42                         return EFI_LOAD_ERROR;
43                 }
44                 *image_size = kernel_memsize;
45         }
46
47
48         return EFI_SUCCESS;
49 }