aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--arch/arm64/kernel/efi-stub.c29
-rw-r--r--arch/x86/boot/compressed/eboot.c13
-rw-r--r--drivers/firmware/efi/arm-stub.c32
-rw-r--r--drivers/firmware/efi/efi-stub-helper.c74
-rw-r--r--drivers/firmware/efi/efistub.h42
-rw-r--r--drivers/firmware/efi/fdt.c20
-rw-r--r--include/linux/efi.h42
7 files changed, 164 insertions, 88 deletions
diff --git a/arch/arm64/kernel/efi-stub.c b/arch/arm64/kernel/efi-stub.c
index 23cbde4324b1..e4999021b07d 100644
--- a/arch/arm64/kernel/efi-stub.c
+++ b/arch/arm64/kernel/efi-stub.c
@@ -11,36 +11,21 @@
11 */ 11 */
12#include <linux/efi.h> 12#include <linux/efi.h>
13#include <asm/efi.h> 13#include <asm/efi.h>
14#include <linux/libfdt.h>
15#include <asm/sections.h> 14#include <asm/sections.h>
16 15
17static void efi_char16_printk(efi_system_table_t *sys_table_arg,
18 efi_char16_t *str);
19
20static efi_status_t efi_open_volume(efi_system_table_t *sys_table,
21 void *__image, void **__fh);
22static efi_status_t efi_file_close(void *handle);
23
24static efi_status_t
25efi_file_read(void *handle, unsigned long *size, void *addr);
26
27static efi_status_t
28efi_file_size(efi_system_table_t *sys_table, void *__fh,
29 efi_char16_t *filename_16, void **handle, u64 *file_sz);
30
31/* Include shared EFI stub code */ 16/* Include shared EFI stub code */
32#include "../../../drivers/firmware/efi/efi-stub-helper.c" 17#include "../../../drivers/firmware/efi/efi-stub-helper.c"
33#include "../../../drivers/firmware/efi/fdt.c" 18#include "../../../drivers/firmware/efi/fdt.c"
34#include "../../../drivers/firmware/efi/arm-stub.c" 19#include "../../../drivers/firmware/efi/arm-stub.c"
35 20
36 21
37static efi_status_t handle_kernel_image(efi_system_table_t *sys_table, 22efi_status_t handle_kernel_image(efi_system_table_t *sys_table,
38 unsigned long *image_addr, 23 unsigned long *image_addr,
39 unsigned long *image_size, 24 unsigned long *image_size,
40 unsigned long *reserve_addr, 25 unsigned long *reserve_addr,
41 unsigned long *reserve_size, 26 unsigned long *reserve_size,
42 unsigned long dram_base, 27 unsigned long dram_base,
43 efi_loaded_image_t *image) 28 efi_loaded_image_t *image)
44{ 29{
45 efi_status_t status; 30 efi_status_t status;
46 unsigned long kernel_size, kernel_memsize = 0; 31 unsigned long kernel_size, kernel_memsize = 0;
diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
index c066bc4e3051..916bbdd7dd28 100644
--- a/arch/x86/boot/compressed/eboot.c
+++ b/arch/x86/boot/compressed/eboot.c
@@ -45,8 +45,7 @@ static void setup_boot_services##bits(struct efi_config *c) \
45BOOT_SERVICES(32); 45BOOT_SERVICES(32);
46BOOT_SERVICES(64); 46BOOT_SERVICES(64);
47 47
48static void efi_printk(efi_system_table_t *, char *); 48void efi_char16_printk(efi_system_table_t *, efi_char16_t *);
49static void efi_char16_printk(efi_system_table_t *, efi_char16_t *);
50 49
51static efi_status_t 50static efi_status_t
52__file_size32(void *__fh, efi_char16_t *filename_16, 51__file_size32(void *__fh, efi_char16_t *filename_16,
@@ -153,7 +152,7 @@ grow:
153 152
154 return status; 153 return status;
155} 154}
156static efi_status_t 155efi_status_t
157efi_file_size(efi_system_table_t *sys_table, void *__fh, 156efi_file_size(efi_system_table_t *sys_table, void *__fh,
158 efi_char16_t *filename_16, void **handle, u64 *file_sz) 157 efi_char16_t *filename_16, void **handle, u64 *file_sz)
159{ 158{
@@ -163,7 +162,7 @@ efi_file_size(efi_system_table_t *sys_table, void *__fh,
163 return __file_size32(__fh, filename_16, handle, file_sz); 162 return __file_size32(__fh, filename_16, handle, file_sz);
164} 163}
165 164
166static inline efi_status_t 165efi_status_t
167efi_file_read(void *handle, unsigned long *size, void *addr) 166efi_file_read(void *handle, unsigned long *size, void *addr)
168{ 167{
169 unsigned long func; 168 unsigned long func;
@@ -181,7 +180,7 @@ efi_file_read(void *handle, unsigned long *size, void *addr)
181 } 180 }
182} 181}
183 182
184static inline efi_status_t efi_file_close(void *handle) 183efi_status_t efi_file_close(void *handle)
185{ 184{
186 if (efi_early->is64) { 185 if (efi_early->is64) {
187 efi_file_handle_64_t *fh = handle; 186 efi_file_handle_64_t *fh = handle;
@@ -246,7 +245,7 @@ static inline efi_status_t __open_volume64(void *__image, void **__fh)
246 return status; 245 return status;
247} 246}
248 247
249static inline efi_status_t 248efi_status_t
250efi_open_volume(efi_system_table_t *sys_table, void *__image, void **__fh) 249efi_open_volume(efi_system_table_t *sys_table, void *__image, void **__fh)
251{ 250{
252 if (efi_early->is64) 251 if (efi_early->is64)
@@ -255,7 +254,7 @@ efi_open_volume(efi_system_table_t *sys_table, void *__image, void **__fh)
255 return __open_volume32(__image, __fh); 254 return __open_volume32(__image, __fh);
256} 255}
257 256
258static void efi_char16_printk(efi_system_table_t *table, efi_char16_t *str) 257void efi_char16_printk(efi_system_table_t *table, efi_char16_t *str)
259{ 258{
260 unsigned long output_string; 259 unsigned long output_string;
261 size_t offset; 260 size_t offset;
diff --git a/drivers/firmware/efi/arm-stub.c b/drivers/firmware/efi/arm-stub.c
index 41114ce03b01..480339b6b110 100644
--- a/drivers/firmware/efi/arm-stub.c
+++ b/drivers/firmware/efi/arm-stub.c
@@ -12,6 +12,11 @@
12 * 12 *
13 */ 13 */
14 14
15#include <linux/efi.h>
16#include <asm/efi.h>
17
18#include "efistub.h"
19
15static int __init efi_secureboot_enabled(efi_system_table_t *sys_table_arg) 20static int __init efi_secureboot_enabled(efi_system_table_t *sys_table_arg)
16{ 21{
17 static efi_guid_t const var_guid __initconst = EFI_GLOBAL_VARIABLE_GUID; 22 static efi_guid_t const var_guid __initconst = EFI_GLOBAL_VARIABLE_GUID;
@@ -36,8 +41,8 @@ static int __init efi_secureboot_enabled(efi_system_table_t *sys_table_arg)
36 } 41 }
37} 42}
38 43
39static efi_status_t efi_open_volume(efi_system_table_t *sys_table_arg, 44efi_status_t efi_open_volume(efi_system_table_t *sys_table_arg,
40 void *__image, void **__fh) 45 void *__image, void **__fh)
41{ 46{
42 efi_file_io_interface_t *io; 47 efi_file_io_interface_t *io;
43 efi_loaded_image_t *image = __image; 48 efi_loaded_image_t *image = __image;
@@ -60,14 +65,15 @@ static efi_status_t efi_open_volume(efi_system_table_t *sys_table_arg,
60 *__fh = fh; 65 *__fh = fh;
61 return status; 66 return status;
62} 67}
63static efi_status_t efi_file_close(void *handle) 68
69efi_status_t efi_file_close(void *handle)
64{ 70{
65 efi_file_handle_t *fh = handle; 71 efi_file_handle_t *fh = handle;
66 72
67 return fh->close(handle); 73 return fh->close(handle);
68} 74}
69 75
70static efi_status_t 76efi_status_t
71efi_file_read(void *handle, unsigned long *size, void *addr) 77efi_file_read(void *handle, unsigned long *size, void *addr)
72{ 78{
73 efi_file_handle_t *fh = handle; 79 efi_file_handle_t *fh = handle;
@@ -76,7 +82,7 @@ efi_file_read(void *handle, unsigned long *size, void *addr)
76} 82}
77 83
78 84
79static efi_status_t 85efi_status_t
80efi_file_size(efi_system_table_t *sys_table_arg, void *__fh, 86efi_file_size(efi_system_table_t *sys_table_arg, void *__fh,
81 efi_char16_t *filename_16, void **handle, u64 *file_sz) 87 efi_char16_t *filename_16, void **handle, u64 *file_sz)
82{ 88{
@@ -129,7 +135,7 @@ grow:
129 135
130 136
131 137
132static void efi_char16_printk(efi_system_table_t *sys_table_arg, 138void efi_char16_printk(efi_system_table_t *sys_table_arg,
133 efi_char16_t *str) 139 efi_char16_t *str)
134{ 140{
135 struct efi_simple_text_output_protocol *out; 141 struct efi_simple_text_output_protocol *out;
@@ -145,13 +151,13 @@ static void efi_char16_printk(efi_system_table_t *sys_table_arg,
145 * must be reserved. On failure it is required to free all 151 * must be reserved. On failure it is required to free all
146 * all allocations it has made. 152 * all allocations it has made.
147 */ 153 */
148static efi_status_t handle_kernel_image(efi_system_table_t *sys_table, 154efi_status_t handle_kernel_image(efi_system_table_t *sys_table,
149 unsigned long *image_addr, 155 unsigned long *image_addr,
150 unsigned long *image_size, 156 unsigned long *image_size,
151 unsigned long *reserve_addr, 157 unsigned long *reserve_addr,
152 unsigned long *reserve_size, 158 unsigned long *reserve_size,
153 unsigned long dram_base, 159 unsigned long dram_base,
154 efi_loaded_image_t *image); 160 efi_loaded_image_t *image);
155/* 161/*
156 * EFI entry point for the arm/arm64 EFI stubs. This is the entrypoint 162 * EFI entry point for the arm/arm64 EFI stubs. This is the entrypoint
157 * that is described in the PE/COFF header. Most of the code is the same 163 * that is described in the PE/COFF header. Most of the code is the same
diff --git a/drivers/firmware/efi/efi-stub-helper.c b/drivers/firmware/efi/efi-stub-helper.c
index eb6d4be9e722..32d5cca30f49 100644
--- a/drivers/firmware/efi/efi-stub-helper.c
+++ b/drivers/firmware/efi/efi-stub-helper.c
@@ -9,18 +9,20 @@
9 * under the terms of the GNU General Public License version 2. 9 * under the terms of the GNU General Public License version 2.
10 * 10 *
11 */ 11 */
12#define EFI_READ_CHUNK_SIZE (1024 * 1024)
13 12
14/* error code which can't be mistaken for valid address */ 13#include <linux/efi.h>
15#define EFI_ERROR (~0UL) 14#include <asm/efi.h>
15
16#include "efistub.h"
16 17
18#define EFI_READ_CHUNK_SIZE (1024 * 1024)
17 19
18struct file_info { 20struct file_info {
19 efi_file_handle_t *handle; 21 efi_file_handle_t *handle;
20 u64 size; 22 u64 size;
21}; 23};
22 24
23static void efi_printk(efi_system_table_t *sys_table_arg, char *str) 25void efi_printk(efi_system_table_t *sys_table_arg, char *str)
24{ 26{
25 char *s8; 27 char *s8;
26 28
@@ -37,16 +39,12 @@ static void efi_printk(efi_system_table_t *sys_table_arg, char *str)
37 } 39 }
38} 40}
39 41
40#define pr_efi(sys_table, msg) efi_printk(sys_table, "EFI stub: "msg) 42efi_status_t efi_get_memory_map(efi_system_table_t *sys_table_arg,
41#define pr_efi_err(sys_table, msg) efi_printk(sys_table, "EFI stub: ERROR: "msg) 43 efi_memory_desc_t **map,
42 44 unsigned long *map_size,
43 45 unsigned long *desc_size,
44static efi_status_t efi_get_memory_map(efi_system_table_t *sys_table_arg, 46 u32 *desc_ver,
45 efi_memory_desc_t **map, 47 unsigned long *key_ptr)
46 unsigned long *map_size,
47 unsigned long *desc_size,
48 u32 *desc_ver,
49 unsigned long *key_ptr)
50{ 48{
51 efi_memory_desc_t *m = NULL; 49 efi_memory_desc_t *m = NULL;
52 efi_status_t status; 50 efi_status_t status;
@@ -88,7 +86,7 @@ fail:
88} 86}
89 87
90 88
91static unsigned long __init get_dram_base(efi_system_table_t *sys_table_arg) 89unsigned long __init get_dram_base(efi_system_table_t *sys_table_arg)
92{ 90{
93 efi_status_t status; 91 efi_status_t status;
94 unsigned long map_size; 92 unsigned long map_size;
@@ -116,9 +114,9 @@ static unsigned long __init get_dram_base(efi_system_table_t *sys_table_arg)
116/* 114/*
117 * Allocate at the highest possible address that is not above 'max'. 115 * Allocate at the highest possible address that is not above 'max'.
118 */ 116 */
119static efi_status_t efi_high_alloc(efi_system_table_t *sys_table_arg, 117efi_status_t efi_high_alloc(efi_system_table_t *sys_table_arg,
120 unsigned long size, unsigned long align, 118 unsigned long size, unsigned long align,
121 unsigned long *addr, unsigned long max) 119 unsigned long *addr, unsigned long max)
122{ 120{
123 unsigned long map_size, desc_size; 121 unsigned long map_size, desc_size;
124 efi_memory_desc_t *map; 122 efi_memory_desc_t *map;
@@ -202,9 +200,9 @@ fail:
202/* 200/*
203 * Allocate at the lowest possible address. 201 * Allocate at the lowest possible address.
204 */ 202 */
205static efi_status_t efi_low_alloc(efi_system_table_t *sys_table_arg, 203efi_status_t efi_low_alloc(efi_system_table_t *sys_table_arg,
206 unsigned long size, unsigned long align, 204 unsigned long size, unsigned long align,
207 unsigned long *addr) 205 unsigned long *addr)
208{ 206{
209 unsigned long map_size, desc_size; 207 unsigned long map_size, desc_size;
210 efi_memory_desc_t *map; 208 efi_memory_desc_t *map;
@@ -271,8 +269,8 @@ fail:
271 return status; 269 return status;
272} 270}
273 271
274static void efi_free(efi_system_table_t *sys_table_arg, unsigned long size, 272void efi_free(efi_system_table_t *sys_table_arg, unsigned long size,
275 unsigned long addr) 273 unsigned long addr)
276{ 274{
277 unsigned long nr_pages; 275 unsigned long nr_pages;
278 276
@@ -290,12 +288,12 @@ static void efi_free(efi_system_table_t *sys_table_arg, unsigned long size,
290 * We only support loading a file from the same filesystem as 288 * We only support loading a file from the same filesystem as
291 * the kernel image. 289 * the kernel image.
292 */ 290 */
293static efi_status_t handle_cmdline_files(efi_system_table_t *sys_table_arg, 291efi_status_t handle_cmdline_files(efi_system_table_t *sys_table_arg,
294 efi_loaded_image_t *image, 292 efi_loaded_image_t *image,
295 char *cmd_line, char *option_string, 293 char *cmd_line, char *option_string,
296 unsigned long max_addr, 294 unsigned long max_addr,
297 unsigned long *load_addr, 295 unsigned long *load_addr,
298 unsigned long *load_size) 296 unsigned long *load_size)
299{ 297{
300 struct file_info *files; 298 struct file_info *files;
301 unsigned long file_addr; 299 unsigned long file_addr;
@@ -477,12 +475,12 @@ fail:
477 * address is not available the lowest available address will 475 * address is not available the lowest available address will
478 * be used. 476 * be used.
479 */ 477 */
480static efi_status_t efi_relocate_kernel(efi_system_table_t *sys_table_arg, 478efi_status_t efi_relocate_kernel(efi_system_table_t *sys_table_arg,
481 unsigned long *image_addr, 479 unsigned long *image_addr,
482 unsigned long image_size, 480 unsigned long image_size,
483 unsigned long alloc_size, 481 unsigned long alloc_size,
484 unsigned long preferred_addr, 482 unsigned long preferred_addr,
485 unsigned long alignment) 483 unsigned long alignment)
486{ 484{
487 unsigned long cur_image_addr; 485 unsigned long cur_image_addr;
488 unsigned long new_addr = 0; 486 unsigned long new_addr = 0;
@@ -589,9 +587,9 @@ static u8 *efi_utf16_to_utf8(u8 *dst, const u16 *src, int n)
589 * Size of memory allocated return in *cmd_line_len. 587 * Size of memory allocated return in *cmd_line_len.
590 * Returns NULL on error. 588 * Returns NULL on error.
591 */ 589 */
592static char *efi_convert_cmdline(efi_system_table_t *sys_table_arg, 590char *efi_convert_cmdline(efi_system_table_t *sys_table_arg,
593 efi_loaded_image_t *image, 591 efi_loaded_image_t *image,
594 int *cmd_line_len) 592 int *cmd_line_len)
595{ 593{
596 const u16 *s2; 594 const u16 *s2;
597 u8 *s1 = NULL; 595 u8 *s1 = NULL;
diff --git a/drivers/firmware/efi/efistub.h b/drivers/firmware/efi/efistub.h
new file mode 100644
index 000000000000..304ab295ca1a
--- /dev/null
+++ b/drivers/firmware/efi/efistub.h
@@ -0,0 +1,42 @@
1
2#ifndef _DRIVERS_FIRMWARE_EFI_EFISTUB_H
3#define _DRIVERS_FIRMWARE_EFI_EFISTUB_H
4
5/* error code which can't be mistaken for valid address */
6#define EFI_ERROR (~0UL)
7
8void efi_char16_printk(efi_system_table_t *, efi_char16_t *);
9
10efi_status_t efi_open_volume(efi_system_table_t *sys_table_arg, void *__image,
11 void **__fh);
12
13efi_status_t efi_file_size(efi_system_table_t *sys_table_arg, void *__fh,
14 efi_char16_t *filename_16, void **handle,
15 u64 *file_sz);
16
17efi_status_t efi_file_read(void *handle, unsigned long *size, void *addr);
18
19efi_status_t efi_file_close(void *handle);
20
21unsigned long get_dram_base(efi_system_table_t *sys_table_arg);
22
23efi_status_t update_fdt(efi_system_table_t *sys_table, void *orig_fdt,
24 unsigned long orig_fdt_size,
25 void *fdt, int new_fdt_size, char *cmdline_ptr,
26 u64 initrd_addr, u64 initrd_size,
27 efi_memory_desc_t *memory_map,
28 unsigned long map_size, unsigned long desc_size,
29 u32 desc_ver);
30
31efi_status_t allocate_new_fdt_and_exit_boot(efi_system_table_t *sys_table,
32 void *handle,
33 unsigned long *new_fdt_addr,
34 unsigned long max_addr,
35 u64 initrd_addr, u64 initrd_size,
36 char *cmdline_ptr,
37 unsigned long fdt_addr,
38 unsigned long fdt_size);
39
40void *get_fdt(efi_system_table_t *sys_table);
41
42#endif
diff --git a/drivers/firmware/efi/fdt.c b/drivers/firmware/efi/fdt.c
index 3aec36d7aae9..86d2934840e2 100644
--- a/drivers/firmware/efi/fdt.c
+++ b/drivers/firmware/efi/fdt.c
@@ -10,13 +10,17 @@
10 * 10 *
11 */ 11 */
12 12
13static efi_status_t update_fdt(efi_system_table_t *sys_table, void *orig_fdt, 13#include <linux/efi.h>
14 unsigned long orig_fdt_size, 14#include <linux/libfdt.h>
15 void *fdt, int new_fdt_size, char *cmdline_ptr, 15#include <asm/efi.h>
16 u64 initrd_addr, u64 initrd_size, 16
17 efi_memory_desc_t *memory_map, 17efi_status_t update_fdt(efi_system_table_t *sys_table, void *orig_fdt,
18 unsigned long map_size, unsigned long desc_size, 18 unsigned long orig_fdt_size,
19 u32 desc_ver) 19 void *fdt, int new_fdt_size, char *cmdline_ptr,
20 u64 initrd_addr, u64 initrd_size,
21 efi_memory_desc_t *memory_map,
22 unsigned long map_size, unsigned long desc_size,
23 u32 desc_ver)
20{ 24{
21 int node, prev; 25 int node, prev;
22 int status; 26 int status;
@@ -255,7 +259,7 @@ fail:
255 return EFI_LOAD_ERROR; 259 return EFI_LOAD_ERROR;
256} 260}
257 261
258static void *get_fdt(efi_system_table_t *sys_table) 262void *get_fdt(efi_system_table_t *sys_table)
259{ 263{
260 efi_guid_t fdt_guid = DEVICE_TREE_GUID; 264 efi_guid_t fdt_guid = DEVICE_TREE_GUID;
261 efi_config_table_t *tables; 265 efi_config_table_t *tables;
diff --git a/include/linux/efi.h b/include/linux/efi.h
index 0ceb816bdfc2..3a64f2f85821 100644
--- a/include/linux/efi.h
+++ b/include/linux/efi.h
@@ -1163,4 +1163,46 @@ static inline void
1163efi_runtime_map_setup(void *map, int nr_entries, u32 desc_size) {} 1163efi_runtime_map_setup(void *map, int nr_entries, u32 desc_size) {}
1164#endif 1164#endif
1165 1165
1166/* prototypes shared between arch specific and generic stub code */
1167
1168#define pr_efi(sys_table, msg) efi_printk(sys_table, "EFI stub: "msg)
1169#define pr_efi_err(sys_table, msg) efi_printk(sys_table, "EFI stub: ERROR: "msg)
1170
1171void efi_printk(efi_system_table_t *sys_table_arg, char *str);
1172
1173void efi_free(efi_system_table_t *sys_table_arg, unsigned long size,
1174 unsigned long addr);
1175
1176char *efi_convert_cmdline(efi_system_table_t *sys_table_arg,
1177 efi_loaded_image_t *image, int *cmd_line_len);
1178
1179efi_status_t efi_get_memory_map(efi_system_table_t *sys_table_arg,
1180 efi_memory_desc_t **map,
1181 unsigned long *map_size,
1182 unsigned long *desc_size,
1183 u32 *desc_ver,
1184 unsigned long *key_ptr);
1185
1186efi_status_t efi_low_alloc(efi_system_table_t *sys_table_arg,
1187 unsigned long size, unsigned long align,
1188 unsigned long *addr);
1189
1190efi_status_t efi_high_alloc(efi_system_table_t *sys_table_arg,
1191 unsigned long size, unsigned long align,
1192 unsigned long *addr, unsigned long max);
1193
1194efi_status_t efi_relocate_kernel(efi_system_table_t *sys_table_arg,
1195 unsigned long *image_addr,
1196 unsigned long image_size,
1197 unsigned long alloc_size,
1198 unsigned long preferred_addr,
1199 unsigned long alignment);
1200
1201efi_status_t handle_cmdline_files(efi_system_table_t *sys_table_arg,
1202 efi_loaded_image_t *image,
1203 char *cmd_line, char *option_string,
1204 unsigned long max_addr,
1205 unsigned long *load_addr,
1206 unsigned long *load_size);
1207
1166#endif /* _LINUX_EFI_H */ 1208#endif /* _LINUX_EFI_H */