diff options
Diffstat (limited to 'arch/x86/platform/efi')
-rw-r--r-- | arch/x86/platform/efi/Makefile | 1 | ||||
-rw-r--r-- | arch/x86/platform/efi/efi.c | 710 | ||||
-rw-r--r-- | arch/x86/platform/efi/efi_32.c | 112 | ||||
-rw-r--r-- | arch/x86/platform/efi/efi_64.c | 99 | ||||
-rw-r--r-- | arch/x86/platform/efi/efi_stub_32.S | 123 | ||||
-rw-r--r-- | arch/x86/platform/efi/efi_stub_64.S | 116 |
6 files changed, 1161 insertions, 0 deletions
diff --git a/arch/x86/platform/efi/Makefile b/arch/x86/platform/efi/Makefile new file mode 100644 index 000000000000..73b8be0f3675 --- /dev/null +++ b/arch/x86/platform/efi/Makefile | |||
@@ -0,0 +1 @@ | |||
obj-$(CONFIG_EFI) += efi.o efi_$(BITS).o efi_stub_$(BITS).o | |||
diff --git a/arch/x86/platform/efi/efi.c b/arch/x86/platform/efi/efi.c new file mode 100644 index 000000000000..899e393d8e73 --- /dev/null +++ b/arch/x86/platform/efi/efi.c | |||
@@ -0,0 +1,710 @@ | |||
1 | /* | ||
2 | * Common EFI (Extensible Firmware Interface) support functions | ||
3 | * Based on Extensible Firmware Interface Specification version 1.0 | ||
4 | * | ||
5 | * Copyright (C) 1999 VA Linux Systems | ||
6 | * Copyright (C) 1999 Walt Drummond <drummond@valinux.com> | ||
7 | * Copyright (C) 1999-2002 Hewlett-Packard Co. | ||
8 | * David Mosberger-Tang <davidm@hpl.hp.com> | ||
9 | * Stephane Eranian <eranian@hpl.hp.com> | ||
10 | * Copyright (C) 2005-2008 Intel Co. | ||
11 | * Fenghua Yu <fenghua.yu@intel.com> | ||
12 | * Bibo Mao <bibo.mao@intel.com> | ||
13 | * Chandramouli Narayanan <mouli@linux.intel.com> | ||
14 | * Huang Ying <ying.huang@intel.com> | ||
15 | * | ||
16 | * Copied from efi_32.c to eliminate the duplicated code between EFI | ||
17 | * 32/64 support code. --ying 2007-10-26 | ||
18 | * | ||
19 | * All EFI Runtime Services are not implemented yet as EFI only | ||
20 | * supports physical mode addressing on SoftSDV. This is to be fixed | ||
21 | * in a future version. --drummond 1999-07-20 | ||
22 | * | ||
23 | * Implemented EFI runtime services and virtual mode calls. --davidm | ||
24 | * | ||
25 | * Goutham Rao: <goutham.rao@intel.com> | ||
26 | * Skip non-WB memory and ignore empty memory ranges. | ||
27 | */ | ||
28 | |||
29 | #include <linux/kernel.h> | ||
30 | #include <linux/init.h> | ||
31 | #include <linux/efi.h> | ||
32 | #include <linux/bootmem.h> | ||
33 | #include <linux/memblock.h> | ||
34 | #include <linux/spinlock.h> | ||
35 | #include <linux/uaccess.h> | ||
36 | #include <linux/time.h> | ||
37 | #include <linux/io.h> | ||
38 | #include <linux/reboot.h> | ||
39 | #include <linux/bcd.h> | ||
40 | |||
41 | #include <asm/setup.h> | ||
42 | #include <asm/efi.h> | ||
43 | #include <asm/time.h> | ||
44 | #include <asm/cacheflush.h> | ||
45 | #include <asm/tlbflush.h> | ||
46 | #include <asm/x86_init.h> | ||
47 | |||
48 | #define EFI_DEBUG 1 | ||
49 | #define PFX "EFI: " | ||
50 | |||
51 | int efi_enabled; | ||
52 | EXPORT_SYMBOL(efi_enabled); | ||
53 | |||
54 | struct efi efi; | ||
55 | EXPORT_SYMBOL(efi); | ||
56 | |||
57 | struct efi_memory_map memmap; | ||
58 | |||
59 | static struct efi efi_phys __initdata; | ||
60 | static efi_system_table_t efi_systab __initdata; | ||
61 | |||
62 | static int __init setup_noefi(char *arg) | ||
63 | { | ||
64 | efi_enabled = 0; | ||
65 | return 0; | ||
66 | } | ||
67 | early_param("noefi", setup_noefi); | ||
68 | |||
69 | int add_efi_memmap; | ||
70 | EXPORT_SYMBOL(add_efi_memmap); | ||
71 | |||
72 | static int __init setup_add_efi_memmap(char *arg) | ||
73 | { | ||
74 | add_efi_memmap = 1; | ||
75 | return 0; | ||
76 | } | ||
77 | early_param("add_efi_memmap", setup_add_efi_memmap); | ||
78 | |||
79 | |||
80 | static efi_status_t virt_efi_get_time(efi_time_t *tm, efi_time_cap_t *tc) | ||
81 | { | ||
82 | return efi_call_virt2(get_time, tm, tc); | ||
83 | } | ||
84 | |||
85 | static efi_status_t virt_efi_set_time(efi_time_t *tm) | ||
86 | { | ||
87 | return efi_call_virt1(set_time, tm); | ||
88 | } | ||
89 | |||
90 | static efi_status_t virt_efi_get_wakeup_time(efi_bool_t *enabled, | ||
91 | efi_bool_t *pending, | ||
92 | efi_time_t *tm) | ||
93 | { | ||
94 | return efi_call_virt3(get_wakeup_time, | ||
95 | enabled, pending, tm); | ||
96 | } | ||
97 | |||
98 | static efi_status_t virt_efi_set_wakeup_time(efi_bool_t enabled, efi_time_t *tm) | ||
99 | { | ||
100 | return efi_call_virt2(set_wakeup_time, | ||
101 | enabled, tm); | ||
102 | } | ||
103 | |||
104 | static efi_status_t virt_efi_get_variable(efi_char16_t *name, | ||
105 | efi_guid_t *vendor, | ||
106 | u32 *attr, | ||
107 | unsigned long *data_size, | ||
108 | void *data) | ||
109 | { | ||
110 | return efi_call_virt5(get_variable, | ||
111 | name, vendor, attr, | ||
112 | data_size, data); | ||
113 | } | ||
114 | |||
115 | static efi_status_t virt_efi_get_next_variable(unsigned long *name_size, | ||
116 | efi_char16_t *name, | ||
117 | efi_guid_t *vendor) | ||
118 | { | ||
119 | return efi_call_virt3(get_next_variable, | ||
120 | name_size, name, vendor); | ||
121 | } | ||
122 | |||
123 | static efi_status_t virt_efi_set_variable(efi_char16_t *name, | ||
124 | efi_guid_t *vendor, | ||
125 | unsigned long attr, | ||
126 | unsigned long data_size, | ||
127 | void *data) | ||
128 | { | ||
129 | return efi_call_virt5(set_variable, | ||
130 | name, vendor, attr, | ||
131 | data_size, data); | ||
132 | } | ||
133 | |||
134 | static efi_status_t virt_efi_get_next_high_mono_count(u32 *count) | ||
135 | { | ||
136 | return efi_call_virt1(get_next_high_mono_count, count); | ||
137 | } | ||
138 | |||
139 | static void virt_efi_reset_system(int reset_type, | ||
140 | efi_status_t status, | ||
141 | unsigned long data_size, | ||
142 | efi_char16_t *data) | ||
143 | { | ||
144 | efi_call_virt4(reset_system, reset_type, status, | ||
145 | data_size, data); | ||
146 | } | ||
147 | |||
148 | static efi_status_t __init phys_efi_set_virtual_address_map( | ||
149 | unsigned long memory_map_size, | ||
150 | unsigned long descriptor_size, | ||
151 | u32 descriptor_version, | ||
152 | efi_memory_desc_t *virtual_map) | ||
153 | { | ||
154 | efi_status_t status; | ||
155 | |||
156 | efi_call_phys_prelog(); | ||
157 | status = efi_call_phys4(efi_phys.set_virtual_address_map, | ||
158 | memory_map_size, descriptor_size, | ||
159 | descriptor_version, virtual_map); | ||
160 | efi_call_phys_epilog(); | ||
161 | return status; | ||
162 | } | ||
163 | |||
164 | static efi_status_t __init phys_efi_get_time(efi_time_t *tm, | ||
165 | efi_time_cap_t *tc) | ||
166 | { | ||
167 | efi_status_t status; | ||
168 | |||
169 | efi_call_phys_prelog(); | ||
170 | status = efi_call_phys2(efi_phys.get_time, tm, tc); | ||
171 | efi_call_phys_epilog(); | ||
172 | return status; | ||
173 | } | ||
174 | |||
175 | int efi_set_rtc_mmss(unsigned long nowtime) | ||
176 | { | ||
177 | int real_seconds, real_minutes; | ||
178 | efi_status_t status; | ||
179 | efi_time_t eft; | ||
180 | efi_time_cap_t cap; | ||
181 | |||
182 | status = efi.get_time(&eft, &cap); | ||
183 | if (status != EFI_SUCCESS) { | ||
184 | printk(KERN_ERR "Oops: efitime: can't read time!\n"); | ||
185 | return -1; | ||
186 | } | ||
187 | |||
188 | real_seconds = nowtime % 60; | ||
189 | real_minutes = nowtime / 60; | ||
190 | if (((abs(real_minutes - eft.minute) + 15)/30) & 1) | ||
191 | real_minutes += 30; | ||
192 | real_minutes %= 60; | ||
193 | eft.minute = real_minutes; | ||
194 | eft.second = real_seconds; | ||
195 | |||
196 | status = efi.set_time(&eft); | ||
197 | if (status != EFI_SUCCESS) { | ||
198 | printk(KERN_ERR "Oops: efitime: can't write time!\n"); | ||
199 | return -1; | ||
200 | } | ||
201 | return 0; | ||
202 | } | ||
203 | |||
204 | unsigned long efi_get_time(void) | ||
205 | { | ||
206 | efi_status_t status; | ||
207 | efi_time_t eft; | ||
208 | efi_time_cap_t cap; | ||
209 | |||
210 | status = efi.get_time(&eft, &cap); | ||
211 | if (status != EFI_SUCCESS) | ||
212 | printk(KERN_ERR "Oops: efitime: can't read time!\n"); | ||
213 | |||
214 | return mktime(eft.year, eft.month, eft.day, eft.hour, | ||
215 | eft.minute, eft.second); | ||
216 | } | ||
217 | |||
218 | /* | ||
219 | * Tell the kernel about the EFI memory map. This might include | ||
220 | * more than the max 128 entries that can fit in the e820 legacy | ||
221 | * (zeropage) memory map. | ||
222 | */ | ||
223 | |||
224 | static void __init do_add_efi_memmap(void) | ||
225 | { | ||
226 | void *p; | ||
227 | |||
228 | for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) { | ||
229 | efi_memory_desc_t *md = p; | ||
230 | unsigned long long start = md->phys_addr; | ||
231 | unsigned long long size = md->num_pages << EFI_PAGE_SHIFT; | ||
232 | int e820_type; | ||
233 | |||
234 | switch (md->type) { | ||
235 | case EFI_LOADER_CODE: | ||
236 | case EFI_LOADER_DATA: | ||
237 | case EFI_BOOT_SERVICES_CODE: | ||
238 | case EFI_BOOT_SERVICES_DATA: | ||
239 | case EFI_CONVENTIONAL_MEMORY: | ||
240 | if (md->attribute & EFI_MEMORY_WB) | ||
241 | e820_type = E820_RAM; | ||
242 | else | ||
243 | e820_type = E820_RESERVED; | ||
244 | break; | ||
245 | case EFI_ACPI_RECLAIM_MEMORY: | ||
246 | e820_type = E820_ACPI; | ||
247 | break; | ||
248 | case EFI_ACPI_MEMORY_NVS: | ||
249 | e820_type = E820_NVS; | ||
250 | break; | ||
251 | case EFI_UNUSABLE_MEMORY: | ||
252 | e820_type = E820_UNUSABLE; | ||
253 | break; | ||
254 | default: | ||
255 | /* | ||
256 | * EFI_RESERVED_TYPE EFI_RUNTIME_SERVICES_CODE | ||
257 | * EFI_RUNTIME_SERVICES_DATA EFI_MEMORY_MAPPED_IO | ||
258 | * EFI_MEMORY_MAPPED_IO_PORT_SPACE EFI_PAL_CODE | ||
259 | */ | ||
260 | e820_type = E820_RESERVED; | ||
261 | break; | ||
262 | } | ||
263 | e820_add_region(start, size, e820_type); | ||
264 | } | ||
265 | sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map); | ||
266 | } | ||
267 | |||
268 | void __init efi_memblock_x86_reserve_range(void) | ||
269 | { | ||
270 | unsigned long pmap; | ||
271 | |||
272 | #ifdef CONFIG_X86_32 | ||
273 | pmap = boot_params.efi_info.efi_memmap; | ||
274 | #else | ||
275 | pmap = (boot_params.efi_info.efi_memmap | | ||
276 | ((__u64)boot_params.efi_info.efi_memmap_hi<<32)); | ||
277 | #endif | ||
278 | memmap.phys_map = (void *)pmap; | ||
279 | memmap.nr_map = boot_params.efi_info.efi_memmap_size / | ||
280 | boot_params.efi_info.efi_memdesc_size; | ||
281 | memmap.desc_version = boot_params.efi_info.efi_memdesc_version; | ||
282 | memmap.desc_size = boot_params.efi_info.efi_memdesc_size; | ||
283 | memblock_x86_reserve_range(pmap, pmap + memmap.nr_map * memmap.desc_size, | ||
284 | "EFI memmap"); | ||
285 | } | ||
286 | |||
287 | #if EFI_DEBUG | ||
288 | static void __init print_efi_memmap(void) | ||
289 | { | ||
290 | efi_memory_desc_t *md; | ||
291 | void *p; | ||
292 | int i; | ||
293 | |||
294 | for (p = memmap.map, i = 0; | ||
295 | p < memmap.map_end; | ||
296 | p += memmap.desc_size, i++) { | ||
297 | md = p; | ||
298 | printk(KERN_INFO PFX "mem%02u: type=%u, attr=0x%llx, " | ||
299 | "range=[0x%016llx-0x%016llx) (%lluMB)\n", | ||
300 | i, md->type, md->attribute, md->phys_addr, | ||
301 | md->phys_addr + (md->num_pages << EFI_PAGE_SHIFT), | ||
302 | (md->num_pages >> (20 - EFI_PAGE_SHIFT))); | ||
303 | } | ||
304 | } | ||
305 | #endif /* EFI_DEBUG */ | ||
306 | |||
307 | void __init efi_reserve_boot_services(void) | ||
308 | { | ||
309 | void *p; | ||
310 | |||
311 | for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) { | ||
312 | efi_memory_desc_t *md = p; | ||
313 | u64 start = md->phys_addr; | ||
314 | u64 size = md->num_pages << EFI_PAGE_SHIFT; | ||
315 | |||
316 | if (md->type != EFI_BOOT_SERVICES_CODE && | ||
317 | md->type != EFI_BOOT_SERVICES_DATA) | ||
318 | continue; | ||
319 | /* Only reserve where possible: | ||
320 | * - Not within any already allocated areas | ||
321 | * - Not over any memory area (really needed, if above?) | ||
322 | * - Not within any part of the kernel | ||
323 | * - Not the bios reserved area | ||
324 | */ | ||
325 | if ((start+size >= virt_to_phys(_text) | ||
326 | && start <= virt_to_phys(_end)) || | ||
327 | !e820_all_mapped(start, start+size, E820_RAM) || | ||
328 | memblock_x86_check_reserved_size(&start, &size, | ||
329 | 1<<EFI_PAGE_SHIFT)) { | ||
330 | /* Could not reserve, skip it */ | ||
331 | md->num_pages = 0; | ||
332 | memblock_dbg(PFX "Could not reserve boot range " | ||
333 | "[0x%010llx-0x%010llx]\n", | ||
334 | start, start+size-1); | ||
335 | } else | ||
336 | memblock_x86_reserve_range(start, start+size, | ||
337 | "EFI Boot"); | ||
338 | } | ||
339 | } | ||
340 | |||
341 | static void __init efi_free_boot_services(void) | ||
342 | { | ||
343 | void *p; | ||
344 | |||
345 | for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) { | ||
346 | efi_memory_desc_t *md = p; | ||
347 | unsigned long long start = md->phys_addr; | ||
348 | unsigned long long size = md->num_pages << EFI_PAGE_SHIFT; | ||
349 | |||
350 | if (md->type != EFI_BOOT_SERVICES_CODE && | ||
351 | md->type != EFI_BOOT_SERVICES_DATA) | ||
352 | continue; | ||
353 | |||
354 | /* Could not reserve boot area */ | ||
355 | if (!size) | ||
356 | continue; | ||
357 | |||
358 | free_bootmem_late(start, size); | ||
359 | } | ||
360 | } | ||
361 | |||
362 | void __init efi_init(void) | ||
363 | { | ||
364 | efi_config_table_t *config_tables; | ||
365 | efi_runtime_services_t *runtime; | ||
366 | efi_char16_t *c16; | ||
367 | char vendor[100] = "unknown"; | ||
368 | int i = 0; | ||
369 | void *tmp; | ||
370 | |||
371 | #ifdef CONFIG_X86_32 | ||
372 | efi_phys.systab = (efi_system_table_t *)boot_params.efi_info.efi_systab; | ||
373 | #else | ||
374 | efi_phys.systab = (efi_system_table_t *) | ||
375 | (boot_params.efi_info.efi_systab | | ||
376 | ((__u64)boot_params.efi_info.efi_systab_hi<<32)); | ||
377 | #endif | ||
378 | |||
379 | efi.systab = early_ioremap((unsigned long)efi_phys.systab, | ||
380 | sizeof(efi_system_table_t)); | ||
381 | if (efi.systab == NULL) | ||
382 | printk(KERN_ERR "Couldn't map the EFI system table!\n"); | ||
383 | memcpy(&efi_systab, efi.systab, sizeof(efi_system_table_t)); | ||
384 | early_iounmap(efi.systab, sizeof(efi_system_table_t)); | ||
385 | efi.systab = &efi_systab; | ||
386 | |||
387 | /* | ||
388 | * Verify the EFI Table | ||
389 | */ | ||
390 | if (efi.systab->hdr.signature != EFI_SYSTEM_TABLE_SIGNATURE) | ||
391 | printk(KERN_ERR "EFI system table signature incorrect!\n"); | ||
392 | if ((efi.systab->hdr.revision >> 16) == 0) | ||
393 | printk(KERN_ERR "Warning: EFI system table version " | ||
394 | "%d.%02d, expected 1.00 or greater!\n", | ||
395 | efi.systab->hdr.revision >> 16, | ||
396 | efi.systab->hdr.revision & 0xffff); | ||
397 | |||
398 | /* | ||
399 | * Show what we know for posterity | ||
400 | */ | ||
401 | c16 = tmp = early_ioremap(efi.systab->fw_vendor, 2); | ||
402 | if (c16) { | ||
403 | for (i = 0; i < sizeof(vendor) - 1 && *c16; ++i) | ||
404 | vendor[i] = *c16++; | ||
405 | vendor[i] = '\0'; | ||
406 | } else | ||
407 | printk(KERN_ERR PFX "Could not map the firmware vendor!\n"); | ||
408 | early_iounmap(tmp, 2); | ||
409 | |||
410 | printk(KERN_INFO "EFI v%u.%.02u by %s\n", | ||
411 | efi.systab->hdr.revision >> 16, | ||
412 | efi.systab->hdr.revision & 0xffff, vendor); | ||
413 | |||
414 | /* | ||
415 | * Let's see what config tables the firmware passed to us. | ||
416 | */ | ||
417 | config_tables = early_ioremap( | ||
418 | efi.systab->tables, | ||
419 | efi.systab->nr_tables * sizeof(efi_config_table_t)); | ||
420 | if (config_tables == NULL) | ||
421 | printk(KERN_ERR "Could not map EFI Configuration Table!\n"); | ||
422 | |||
423 | printk(KERN_INFO); | ||
424 | for (i = 0; i < efi.systab->nr_tables; i++) { | ||
425 | if (!efi_guidcmp(config_tables[i].guid, MPS_TABLE_GUID)) { | ||
426 | efi.mps = config_tables[i].table; | ||
427 | printk(" MPS=0x%lx ", config_tables[i].table); | ||
428 | } else if (!efi_guidcmp(config_tables[i].guid, | ||
429 | ACPI_20_TABLE_GUID)) { | ||
430 | efi.acpi20 = config_tables[i].table; | ||
431 | printk(" ACPI 2.0=0x%lx ", config_tables[i].table); | ||
432 | } else if (!efi_guidcmp(config_tables[i].guid, | ||
433 | ACPI_TABLE_GUID)) { | ||
434 | efi.acpi = config_tables[i].table; | ||
435 | printk(" ACPI=0x%lx ", config_tables[i].table); | ||
436 | } else if (!efi_guidcmp(config_tables[i].guid, | ||
437 | SMBIOS_TABLE_GUID)) { | ||
438 | efi.smbios = config_tables[i].table; | ||
439 | printk(" SMBIOS=0x%lx ", config_tables[i].table); | ||
440 | #ifdef CONFIG_X86_UV | ||
441 | } else if (!efi_guidcmp(config_tables[i].guid, | ||
442 | UV_SYSTEM_TABLE_GUID)) { | ||
443 | efi.uv_systab = config_tables[i].table; | ||
444 | printk(" UVsystab=0x%lx ", config_tables[i].table); | ||
445 | #endif | ||
446 | } else if (!efi_guidcmp(config_tables[i].guid, | ||
447 | HCDP_TABLE_GUID)) { | ||
448 | efi.hcdp = config_tables[i].table; | ||
449 | printk(" HCDP=0x%lx ", config_tables[i].table); | ||
450 | } else if (!efi_guidcmp(config_tables[i].guid, | ||
451 | UGA_IO_PROTOCOL_GUID)) { | ||
452 | efi.uga = config_tables[i].table; | ||
453 | printk(" UGA=0x%lx ", config_tables[i].table); | ||
454 | } | ||
455 | } | ||
456 | printk("\n"); | ||
457 | early_iounmap(config_tables, | ||
458 | efi.systab->nr_tables * sizeof(efi_config_table_t)); | ||
459 | |||
460 | /* | ||
461 | * Check out the runtime services table. We need to map | ||
462 | * the runtime services table so that we can grab the physical | ||
463 | * address of several of the EFI runtime functions, needed to | ||
464 | * set the firmware into virtual mode. | ||
465 | */ | ||
466 | runtime = early_ioremap((unsigned long)efi.systab->runtime, | ||
467 | sizeof(efi_runtime_services_t)); | ||
468 | if (runtime != NULL) { | ||
469 | /* | ||
470 | * We will only need *early* access to the following | ||
471 | * two EFI runtime services before set_virtual_address_map | ||
472 | * is invoked. | ||
473 | */ | ||
474 | efi_phys.get_time = (efi_get_time_t *)runtime->get_time; | ||
475 | efi_phys.set_virtual_address_map = | ||
476 | (efi_set_virtual_address_map_t *) | ||
477 | runtime->set_virtual_address_map; | ||
478 | /* | ||
479 | * Make efi_get_time can be called before entering | ||
480 | * virtual mode. | ||
481 | */ | ||
482 | efi.get_time = phys_efi_get_time; | ||
483 | } else | ||
484 | printk(KERN_ERR "Could not map the EFI runtime service " | ||
485 | "table!\n"); | ||
486 | early_iounmap(runtime, sizeof(efi_runtime_services_t)); | ||
487 | |||
488 | /* Map the EFI memory map */ | ||
489 | memmap.map = early_ioremap((unsigned long)memmap.phys_map, | ||
490 | memmap.nr_map * memmap.desc_size); | ||
491 | if (memmap.map == NULL) | ||
492 | printk(KERN_ERR "Could not map the EFI memory map!\n"); | ||
493 | memmap.map_end = memmap.map + (memmap.nr_map * memmap.desc_size); | ||
494 | |||
495 | if (memmap.desc_size != sizeof(efi_memory_desc_t)) | ||
496 | printk(KERN_WARNING | ||
497 | "Kernel-defined memdesc doesn't match the one from EFI!\n"); | ||
498 | |||
499 | if (add_efi_memmap) | ||
500 | do_add_efi_memmap(); | ||
501 | |||
502 | #ifdef CONFIG_X86_32 | ||
503 | x86_platform.get_wallclock = efi_get_time; | ||
504 | x86_platform.set_wallclock = efi_set_rtc_mmss; | ||
505 | #endif | ||
506 | |||
507 | #if EFI_DEBUG | ||
508 | print_efi_memmap(); | ||
509 | #endif | ||
510 | } | ||
511 | |||
512 | void __init efi_set_executable(efi_memory_desc_t *md, bool executable) | ||
513 | { | ||
514 | u64 addr, npages; | ||
515 | |||
516 | addr = md->virt_addr; | ||
517 | npages = md->num_pages; | ||
518 | |||
519 | memrange_efi_to_native(&addr, &npages); | ||
520 | |||
521 | if (executable) | ||
522 | set_memory_x(addr, npages); | ||
523 | else | ||
524 | set_memory_nx(addr, npages); | ||
525 | } | ||
526 | |||
527 | static void __init runtime_code_page_mkexec(void) | ||
528 | { | ||
529 | efi_memory_desc_t *md; | ||
530 | void *p; | ||
531 | |||
532 | /* Make EFI runtime service code area executable */ | ||
533 | for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) { | ||
534 | md = p; | ||
535 | |||
536 | if (md->type != EFI_RUNTIME_SERVICES_CODE) | ||
537 | continue; | ||
538 | |||
539 | efi_set_executable(md, true); | ||
540 | } | ||
541 | } | ||
542 | |||
543 | /* | ||
544 | * This function will switch the EFI runtime services to virtual mode. | ||
545 | * Essentially, look through the EFI memmap and map every region that | ||
546 | * has the runtime attribute bit set in its memory descriptor and update | ||
547 | * that memory descriptor with the virtual address obtained from ioremap(). | ||
548 | * This enables the runtime services to be called without having to | ||
549 | * thunk back into physical mode for every invocation. | ||
550 | */ | ||
551 | void __init efi_enter_virtual_mode(void) | ||
552 | { | ||
553 | efi_memory_desc_t *md, *prev_md = NULL; | ||
554 | efi_status_t status; | ||
555 | unsigned long size; | ||
556 | u64 end, systab, addr, npages, end_pfn; | ||
557 | void *p, *va, *new_memmap = NULL; | ||
558 | int count = 0; | ||
559 | |||
560 | efi.systab = NULL; | ||
561 | |||
562 | /* Merge contiguous regions of the same type and attribute */ | ||
563 | for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) { | ||
564 | u64 prev_size; | ||
565 | md = p; | ||
566 | |||
567 | if (!prev_md) { | ||
568 | prev_md = md; | ||
569 | continue; | ||
570 | } | ||
571 | |||
572 | if (prev_md->type != md->type || | ||
573 | prev_md->attribute != md->attribute) { | ||
574 | prev_md = md; | ||
575 | continue; | ||
576 | } | ||
577 | |||
578 | prev_size = prev_md->num_pages << EFI_PAGE_SHIFT; | ||
579 | |||
580 | if (md->phys_addr == (prev_md->phys_addr + prev_size)) { | ||
581 | prev_md->num_pages += md->num_pages; | ||
582 | md->type = EFI_RESERVED_TYPE; | ||
583 | md->attribute = 0; | ||
584 | continue; | ||
585 | } | ||
586 | prev_md = md; | ||
587 | } | ||
588 | |||
589 | for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) { | ||
590 | md = p; | ||
591 | if (!(md->attribute & EFI_MEMORY_RUNTIME) && | ||
592 | md->type != EFI_BOOT_SERVICES_CODE && | ||
593 | md->type != EFI_BOOT_SERVICES_DATA) | ||
594 | continue; | ||
595 | |||
596 | size = md->num_pages << EFI_PAGE_SHIFT; | ||
597 | end = md->phys_addr + size; | ||
598 | |||
599 | end_pfn = PFN_UP(end); | ||
600 | if (end_pfn <= max_low_pfn_mapped | ||
601 | || (end_pfn > (1UL << (32 - PAGE_SHIFT)) | ||
602 | && end_pfn <= max_pfn_mapped)) | ||
603 | va = __va(md->phys_addr); | ||
604 | else | ||
605 | va = efi_ioremap(md->phys_addr, size, md->type); | ||
606 | |||
607 | md->virt_addr = (u64) (unsigned long) va; | ||
608 | |||
609 | if (!va) { | ||
610 | printk(KERN_ERR PFX "ioremap of 0x%llX failed!\n", | ||
611 | (unsigned long long)md->phys_addr); | ||
612 | continue; | ||
613 | } | ||
614 | |||
615 | if (!(md->attribute & EFI_MEMORY_WB)) { | ||
616 | addr = md->virt_addr; | ||
617 | npages = md->num_pages; | ||
618 | memrange_efi_to_native(&addr, &npages); | ||
619 | set_memory_uc(addr, npages); | ||
620 | } | ||
621 | |||
622 | systab = (u64) (unsigned long) efi_phys.systab; | ||
623 | if (md->phys_addr <= systab && systab < end) { | ||
624 | systab += md->virt_addr - md->phys_addr; | ||
625 | efi.systab = (efi_system_table_t *) (unsigned long) systab; | ||
626 | } | ||
627 | new_memmap = krealloc(new_memmap, | ||
628 | (count + 1) * memmap.desc_size, | ||
629 | GFP_KERNEL); | ||
630 | memcpy(new_memmap + (count * memmap.desc_size), md, | ||
631 | memmap.desc_size); | ||
632 | count++; | ||
633 | } | ||
634 | |||
635 | BUG_ON(!efi.systab); | ||
636 | |||
637 | status = phys_efi_set_virtual_address_map( | ||
638 | memmap.desc_size * count, | ||
639 | memmap.desc_size, | ||
640 | memmap.desc_version, | ||
641 | (efi_memory_desc_t *)__pa(new_memmap)); | ||
642 | |||
643 | if (status != EFI_SUCCESS) { | ||
644 | printk(KERN_ALERT "Unable to switch EFI into virtual mode " | ||
645 | "(status=%lx)!\n", status); | ||
646 | panic("EFI call to SetVirtualAddressMap() failed!"); | ||
647 | } | ||
648 | |||
649 | /* | ||
650 | * Thankfully, it does seem that no runtime services other than | ||
651 | * SetVirtualAddressMap() will touch boot services code, so we can | ||
652 | * get rid of it all at this point | ||
653 | */ | ||
654 | efi_free_boot_services(); | ||
655 | |||
656 | /* | ||
657 | * Now that EFI is in virtual mode, update the function | ||
658 | * pointers in the runtime service table to the new virtual addresses. | ||
659 | * | ||
660 | * Call EFI services through wrapper functions. | ||
661 | */ | ||
662 | efi.get_time = virt_efi_get_time; | ||
663 | efi.set_time = virt_efi_set_time; | ||
664 | efi.get_wakeup_time = virt_efi_get_wakeup_time; | ||
665 | efi.set_wakeup_time = virt_efi_set_wakeup_time; | ||
666 | efi.get_variable = virt_efi_get_variable; | ||
667 | efi.get_next_variable = virt_efi_get_next_variable; | ||
668 | efi.set_variable = virt_efi_set_variable; | ||
669 | efi.get_next_high_mono_count = virt_efi_get_next_high_mono_count; | ||
670 | efi.reset_system = virt_efi_reset_system; | ||
671 | efi.set_virtual_address_map = NULL; | ||
672 | if (__supported_pte_mask & _PAGE_NX) | ||
673 | runtime_code_page_mkexec(); | ||
674 | early_iounmap(memmap.map, memmap.nr_map * memmap.desc_size); | ||
675 | memmap.map = NULL; | ||
676 | kfree(new_memmap); | ||
677 | } | ||
678 | |||
679 | /* | ||
680 | * Convenience functions to obtain memory types and attributes | ||
681 | */ | ||
682 | u32 efi_mem_type(unsigned long phys_addr) | ||
683 | { | ||
684 | efi_memory_desc_t *md; | ||
685 | void *p; | ||
686 | |||
687 | for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) { | ||
688 | md = p; | ||
689 | if ((md->phys_addr <= phys_addr) && | ||
690 | (phys_addr < (md->phys_addr + | ||
691 | (md->num_pages << EFI_PAGE_SHIFT)))) | ||
692 | return md->type; | ||
693 | } | ||
694 | return 0; | ||
695 | } | ||
696 | |||
697 | u64 efi_mem_attributes(unsigned long phys_addr) | ||
698 | { | ||
699 | efi_memory_desc_t *md; | ||
700 | void *p; | ||
701 | |||
702 | for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) { | ||
703 | md = p; | ||
704 | if ((md->phys_addr <= phys_addr) && | ||
705 | (phys_addr < (md->phys_addr + | ||
706 | (md->num_pages << EFI_PAGE_SHIFT)))) | ||
707 | return md->attribute; | ||
708 | } | ||
709 | return 0; | ||
710 | } | ||
diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c new file mode 100644 index 000000000000..5cab48ee61a4 --- /dev/null +++ b/arch/x86/platform/efi/efi_32.c | |||
@@ -0,0 +1,112 @@ | |||
1 | /* | ||
2 | * Extensible Firmware Interface | ||
3 | * | ||
4 | * Based on Extensible Firmware Interface Specification version 1.0 | ||
5 | * | ||
6 | * Copyright (C) 1999 VA Linux Systems | ||
7 | * Copyright (C) 1999 Walt Drummond <drummond@valinux.com> | ||
8 | * Copyright (C) 1999-2002 Hewlett-Packard Co. | ||
9 | * David Mosberger-Tang <davidm@hpl.hp.com> | ||
10 | * Stephane Eranian <eranian@hpl.hp.com> | ||
11 | * | ||
12 | * All EFI Runtime Services are not implemented yet as EFI only | ||
13 | * supports physical mode addressing on SoftSDV. This is to be fixed | ||
14 | * in a future version. --drummond 1999-07-20 | ||
15 | * | ||
16 | * Implemented EFI runtime services and virtual mode calls. --davidm | ||
17 | * | ||
18 | * Goutham Rao: <goutham.rao@intel.com> | ||
19 | * Skip non-WB memory and ignore empty memory ranges. | ||
20 | */ | ||
21 | |||
22 | #include <linux/kernel.h> | ||
23 | #include <linux/types.h> | ||
24 | #include <linux/ioport.h> | ||
25 | #include <linux/efi.h> | ||
26 | |||
27 | #include <asm/io.h> | ||
28 | #include <asm/page.h> | ||
29 | #include <asm/pgtable.h> | ||
30 | #include <asm/tlbflush.h> | ||
31 | #include <asm/efi.h> | ||
32 | |||
33 | /* | ||
34 | * To make EFI call EFI runtime service in physical addressing mode we need | ||
35 | * prelog/epilog before/after the invocation to disable interrupt, to | ||
36 | * claim EFI runtime service handler exclusively and to duplicate a memory in | ||
37 | * low memory space say 0 - 3G. | ||
38 | */ | ||
39 | |||
40 | static unsigned long efi_rt_eflags; | ||
41 | static pgd_t efi_bak_pg_dir_pointer[2]; | ||
42 | |||
43 | void efi_call_phys_prelog(void) | ||
44 | { | ||
45 | unsigned long cr4; | ||
46 | unsigned long temp; | ||
47 | struct desc_ptr gdt_descr; | ||
48 | |||
49 | local_irq_save(efi_rt_eflags); | ||
50 | |||
51 | /* | ||
52 | * If I don't have PAE, I should just duplicate two entries in page | ||
53 | * directory. If I have PAE, I just need to duplicate one entry in | ||
54 | * page directory. | ||
55 | */ | ||
56 | cr4 = read_cr4_safe(); | ||
57 | |||
58 | if (cr4 & X86_CR4_PAE) { | ||
59 | efi_bak_pg_dir_pointer[0].pgd = | ||
60 | swapper_pg_dir[pgd_index(0)].pgd; | ||
61 | swapper_pg_dir[0].pgd = | ||
62 | swapper_pg_dir[pgd_index(PAGE_OFFSET)].pgd; | ||
63 | } else { | ||
64 | efi_bak_pg_dir_pointer[0].pgd = | ||
65 | swapper_pg_dir[pgd_index(0)].pgd; | ||
66 | efi_bak_pg_dir_pointer[1].pgd = | ||
67 | swapper_pg_dir[pgd_index(0x400000)].pgd; | ||
68 | swapper_pg_dir[pgd_index(0)].pgd = | ||
69 | swapper_pg_dir[pgd_index(PAGE_OFFSET)].pgd; | ||
70 | temp = PAGE_OFFSET + 0x400000; | ||
71 | swapper_pg_dir[pgd_index(0x400000)].pgd = | ||
72 | swapper_pg_dir[pgd_index(temp)].pgd; | ||
73 | } | ||
74 | |||
75 | /* | ||
76 | * After the lock is released, the original page table is restored. | ||
77 | */ | ||
78 | __flush_tlb_all(); | ||
79 | |||
80 | gdt_descr.address = __pa(get_cpu_gdt_table(0)); | ||
81 | gdt_descr.size = GDT_SIZE - 1; | ||
82 | load_gdt(&gdt_descr); | ||
83 | } | ||
84 | |||
85 | void efi_call_phys_epilog(void) | ||
86 | { | ||
87 | unsigned long cr4; | ||
88 | struct desc_ptr gdt_descr; | ||
89 | |||
90 | gdt_descr.address = (unsigned long)get_cpu_gdt_table(0); | ||
91 | gdt_descr.size = GDT_SIZE - 1; | ||
92 | load_gdt(&gdt_descr); | ||
93 | |||
94 | cr4 = read_cr4_safe(); | ||
95 | |||
96 | if (cr4 & X86_CR4_PAE) { | ||
97 | swapper_pg_dir[pgd_index(0)].pgd = | ||
98 | efi_bak_pg_dir_pointer[0].pgd; | ||
99 | } else { | ||
100 | swapper_pg_dir[pgd_index(0)].pgd = | ||
101 | efi_bak_pg_dir_pointer[0].pgd; | ||
102 | swapper_pg_dir[pgd_index(0x400000)].pgd = | ||
103 | efi_bak_pg_dir_pointer[1].pgd; | ||
104 | } | ||
105 | |||
106 | /* | ||
107 | * After the lock is released, the original page table is restored. | ||
108 | */ | ||
109 | __flush_tlb_all(); | ||
110 | |||
111 | local_irq_restore(efi_rt_eflags); | ||
112 | } | ||
diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c new file mode 100644 index 000000000000..ac3aa54e2654 --- /dev/null +++ b/arch/x86/platform/efi/efi_64.c | |||
@@ -0,0 +1,99 @@ | |||
1 | /* | ||
2 | * x86_64 specific EFI support functions | ||
3 | * Based on Extensible Firmware Interface Specification version 1.0 | ||
4 | * | ||
5 | * Copyright (C) 2005-2008 Intel Co. | ||
6 | * Fenghua Yu <fenghua.yu@intel.com> | ||
7 | * Bibo Mao <bibo.mao@intel.com> | ||
8 | * Chandramouli Narayanan <mouli@linux.intel.com> | ||
9 | * Huang Ying <ying.huang@intel.com> | ||
10 | * | ||
11 | * Code to convert EFI to E820 map has been implemented in elilo bootloader | ||
12 | * based on a EFI patch by Edgar Hucek. Based on the E820 map, the page table | ||
13 | * is setup appropriately for EFI runtime code. | ||
14 | * - mouli 06/14/2007. | ||
15 | * | ||
16 | */ | ||
17 | |||
18 | #include <linux/kernel.h> | ||
19 | #include <linux/init.h> | ||
20 | #include <linux/mm.h> | ||
21 | #include <linux/types.h> | ||
22 | #include <linux/spinlock.h> | ||
23 | #include <linux/bootmem.h> | ||
24 | #include <linux/ioport.h> | ||
25 | #include <linux/module.h> | ||
26 | #include <linux/efi.h> | ||
27 | #include <linux/uaccess.h> | ||
28 | #include <linux/io.h> | ||
29 | #include <linux/reboot.h> | ||
30 | |||
31 | #include <asm/setup.h> | ||
32 | #include <asm/page.h> | ||
33 | #include <asm/e820.h> | ||
34 | #include <asm/pgtable.h> | ||
35 | #include <asm/tlbflush.h> | ||
36 | #include <asm/proto.h> | ||
37 | #include <asm/efi.h> | ||
38 | #include <asm/cacheflush.h> | ||
39 | #include <asm/fixmap.h> | ||
40 | |||
41 | static pgd_t save_pgd __initdata; | ||
42 | static unsigned long efi_flags __initdata; | ||
43 | |||
44 | static void __init early_code_mapping_set_exec(int executable) | ||
45 | { | ||
46 | efi_memory_desc_t *md; | ||
47 | void *p; | ||
48 | |||
49 | if (!(__supported_pte_mask & _PAGE_NX)) | ||
50 | return; | ||
51 | |||
52 | /* Make EFI service code area executable */ | ||
53 | for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) { | ||
54 | md = p; | ||
55 | if (md->type == EFI_RUNTIME_SERVICES_CODE || | ||
56 | md->type == EFI_BOOT_SERVICES_CODE) | ||
57 | efi_set_executable(md, executable); | ||
58 | } | ||
59 | } | ||
60 | |||
61 | void __init efi_call_phys_prelog(void) | ||
62 | { | ||
63 | unsigned long vaddress; | ||
64 | |||
65 | early_code_mapping_set_exec(1); | ||
66 | local_irq_save(efi_flags); | ||
67 | vaddress = (unsigned long)__va(0x0UL); | ||
68 | save_pgd = *pgd_offset_k(0x0UL); | ||
69 | set_pgd(pgd_offset_k(0x0UL), *pgd_offset_k(vaddress)); | ||
70 | __flush_tlb_all(); | ||
71 | } | ||
72 | |||
73 | void __init efi_call_phys_epilog(void) | ||
74 | { | ||
75 | /* | ||
76 | * After the lock is released, the original page table is restored. | ||
77 | */ | ||
78 | set_pgd(pgd_offset_k(0x0UL), save_pgd); | ||
79 | __flush_tlb_all(); | ||
80 | local_irq_restore(efi_flags); | ||
81 | early_code_mapping_set_exec(0); | ||
82 | } | ||
83 | |||
84 | void __iomem *__init efi_ioremap(unsigned long phys_addr, unsigned long size, | ||
85 | u32 type) | ||
86 | { | ||
87 | unsigned long last_map_pfn; | ||
88 | |||
89 | if (type == EFI_MEMORY_MAPPED_IO) | ||
90 | return ioremap(phys_addr, size); | ||
91 | |||
92 | last_map_pfn = init_memory_mapping(phys_addr, phys_addr + size); | ||
93 | if ((last_map_pfn << PAGE_SHIFT) < phys_addr + size) { | ||
94 | unsigned long top = last_map_pfn << PAGE_SHIFT; | ||
95 | efi_ioremap(top, size - (top - phys_addr), type); | ||
96 | } | ||
97 | |||
98 | return (void __iomem *)__va(phys_addr); | ||
99 | } | ||
diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S new file mode 100644 index 000000000000..fbe66e626c09 --- /dev/null +++ b/arch/x86/platform/efi/efi_stub_32.S | |||
@@ -0,0 +1,123 @@ | |||
1 | /* | ||
2 | * EFI call stub for IA32. | ||
3 | * | ||
4 | * This stub allows us to make EFI calls in physical mode with interrupts | ||
5 | * turned off. | ||
6 | */ | ||
7 | |||
8 | #include <linux/linkage.h> | ||
9 | #include <asm/page_types.h> | ||
10 | |||
11 | /* | ||
12 | * efi_call_phys(void *, ...) is a function with variable parameters. | ||
13 | * All the callers of this function assure that all the parameters are 4-bytes. | ||
14 | */ | ||
15 | |||
16 | /* | ||
17 | * In gcc calling convention, EBX, ESP, EBP, ESI and EDI are all callee save. | ||
18 | * So we'd better save all of them at the beginning of this function and restore | ||
19 | * at the end no matter how many we use, because we can not assure EFI runtime | ||
20 | * service functions will comply with gcc calling convention, too. | ||
21 | */ | ||
22 | |||
23 | .text | ||
24 | ENTRY(efi_call_phys) | ||
25 | /* | ||
26 | * 0. The function can only be called in Linux kernel. So CS has been | ||
27 | * set to 0x0010, DS and SS have been set to 0x0018. In EFI, I found | ||
28 | * the values of these registers are the same. And, the corresponding | ||
29 | * GDT entries are identical. So I will do nothing about segment reg | ||
30 | * and GDT, but change GDT base register in prelog and epilog. | ||
31 | */ | ||
32 | |||
33 | /* | ||
34 | * 1. Now I am running with EIP = <physical address> + PAGE_OFFSET. | ||
35 | * But to make it smoothly switch from virtual mode to flat mode. | ||
36 | * The mapping of lower virtual memory has been created in prelog and | ||
37 | * epilog. | ||
38 | */ | ||
39 | movl $1f, %edx | ||
40 | subl $__PAGE_OFFSET, %edx | ||
41 | jmp *%edx | ||
42 | 1: | ||
43 | |||
44 | /* | ||
45 | * 2. Now on the top of stack is the return | ||
46 | * address in the caller of efi_call_phys(), then parameter 1, | ||
47 | * parameter 2, ..., param n. To make things easy, we save the return | ||
48 | * address of efi_call_phys in a global variable. | ||
49 | */ | ||
50 | popl %edx | ||
51 | movl %edx, saved_return_addr | ||
52 | /* get the function pointer into ECX*/ | ||
53 | popl %ecx | ||
54 | movl %ecx, efi_rt_function_ptr | ||
55 | movl $2f, %edx | ||
56 | subl $__PAGE_OFFSET, %edx | ||
57 | pushl %edx | ||
58 | |||
59 | /* | ||
60 | * 3. Clear PG bit in %CR0. | ||
61 | */ | ||
62 | movl %cr0, %edx | ||
63 | andl $0x7fffffff, %edx | ||
64 | movl %edx, %cr0 | ||
65 | jmp 1f | ||
66 | 1: | ||
67 | |||
68 | /* | ||
69 | * 4. Adjust stack pointer. | ||
70 | */ | ||
71 | subl $__PAGE_OFFSET, %esp | ||
72 | |||
73 | /* | ||
74 | * 5. Call the physical function. | ||
75 | */ | ||
76 | jmp *%ecx | ||
77 | |||
78 | 2: | ||
79 | /* | ||
80 | * 6. After EFI runtime service returns, control will return to | ||
81 | * following instruction. We'd better readjust stack pointer first. | ||
82 | */ | ||
83 | addl $__PAGE_OFFSET, %esp | ||
84 | |||
85 | /* | ||
86 | * 7. Restore PG bit | ||
87 | */ | ||
88 | movl %cr0, %edx | ||
89 | orl $0x80000000, %edx | ||
90 | movl %edx, %cr0 | ||
91 | jmp 1f | ||
92 | 1: | ||
93 | /* | ||
94 | * 8. Now restore the virtual mode from flat mode by | ||
95 | * adding EIP with PAGE_OFFSET. | ||
96 | */ | ||
97 | movl $1f, %edx | ||
98 | jmp *%edx | ||
99 | 1: | ||
100 | |||
101 | /* | ||
102 | * 9. Balance the stack. And because EAX contain the return value, | ||
103 | * we'd better not clobber it. | ||
104 | */ | ||
105 | leal efi_rt_function_ptr, %edx | ||
106 | movl (%edx), %ecx | ||
107 | pushl %ecx | ||
108 | |||
109 | /* | ||
110 | * 10. Push the saved return address onto the stack and return. | ||
111 | */ | ||
112 | leal saved_return_addr, %edx | ||
113 | movl (%edx), %ecx | ||
114 | pushl %ecx | ||
115 | ret | ||
116 | ENDPROC(efi_call_phys) | ||
117 | .previous | ||
118 | |||
119 | .data | ||
120 | saved_return_addr: | ||
121 | .long 0 | ||
122 | efi_rt_function_ptr: | ||
123 | .long 0 | ||
diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S new file mode 100644 index 000000000000..4c07ccab8146 --- /dev/null +++ b/arch/x86/platform/efi/efi_stub_64.S | |||
@@ -0,0 +1,116 @@ | |||
1 | /* | ||
2 | * Function calling ABI conversion from Linux to EFI for x86_64 | ||
3 | * | ||
4 | * Copyright (C) 2007 Intel Corp | ||
5 | * Bibo Mao <bibo.mao@intel.com> | ||
6 | * Huang Ying <ying.huang@intel.com> | ||
7 | */ | ||
8 | |||
9 | #include <linux/linkage.h> | ||
10 | |||
11 | #define SAVE_XMM \ | ||
12 | mov %rsp, %rax; \ | ||
13 | subq $0x70, %rsp; \ | ||
14 | and $~0xf, %rsp; \ | ||
15 | mov %rax, (%rsp); \ | ||
16 | mov %cr0, %rax; \ | ||
17 | clts; \ | ||
18 | mov %rax, 0x8(%rsp); \ | ||
19 | movaps %xmm0, 0x60(%rsp); \ | ||
20 | movaps %xmm1, 0x50(%rsp); \ | ||
21 | movaps %xmm2, 0x40(%rsp); \ | ||
22 | movaps %xmm3, 0x30(%rsp); \ | ||
23 | movaps %xmm4, 0x20(%rsp); \ | ||
24 | movaps %xmm5, 0x10(%rsp) | ||
25 | |||
26 | #define RESTORE_XMM \ | ||
27 | movaps 0x60(%rsp), %xmm0; \ | ||
28 | movaps 0x50(%rsp), %xmm1; \ | ||
29 | movaps 0x40(%rsp), %xmm2; \ | ||
30 | movaps 0x30(%rsp), %xmm3; \ | ||
31 | movaps 0x20(%rsp), %xmm4; \ | ||
32 | movaps 0x10(%rsp), %xmm5; \ | ||
33 | mov 0x8(%rsp), %rsi; \ | ||
34 | mov %rsi, %cr0; \ | ||
35 | mov (%rsp), %rsp | ||
36 | |||
37 | ENTRY(efi_call0) | ||
38 | SAVE_XMM | ||
39 | subq $32, %rsp | ||
40 | call *%rdi | ||
41 | addq $32, %rsp | ||
42 | RESTORE_XMM | ||
43 | ret | ||
44 | ENDPROC(efi_call0) | ||
45 | |||
46 | ENTRY(efi_call1) | ||
47 | SAVE_XMM | ||
48 | subq $32, %rsp | ||
49 | mov %rsi, %rcx | ||
50 | call *%rdi | ||
51 | addq $32, %rsp | ||
52 | RESTORE_XMM | ||
53 | ret | ||
54 | ENDPROC(efi_call1) | ||
55 | |||
56 | ENTRY(efi_call2) | ||
57 | SAVE_XMM | ||
58 | subq $32, %rsp | ||
59 | mov %rsi, %rcx | ||
60 | call *%rdi | ||
61 | addq $32, %rsp | ||
62 | RESTORE_XMM | ||
63 | ret | ||
64 | ENDPROC(efi_call2) | ||
65 | |||
66 | ENTRY(efi_call3) | ||
67 | SAVE_XMM | ||
68 | subq $32, %rsp | ||
69 | mov %rcx, %r8 | ||
70 | mov %rsi, %rcx | ||
71 | call *%rdi | ||
72 | addq $32, %rsp | ||
73 | RESTORE_XMM | ||
74 | ret | ||
75 | ENDPROC(efi_call3) | ||
76 | |||
77 | ENTRY(efi_call4) | ||
78 | SAVE_XMM | ||
79 | subq $32, %rsp | ||
80 | mov %r8, %r9 | ||
81 | mov %rcx, %r8 | ||
82 | mov %rsi, %rcx | ||
83 | call *%rdi | ||
84 | addq $32, %rsp | ||
85 | RESTORE_XMM | ||
86 | ret | ||
87 | ENDPROC(efi_call4) | ||
88 | |||
89 | ENTRY(efi_call5) | ||
90 | SAVE_XMM | ||
91 | subq $48, %rsp | ||
92 | mov %r9, 32(%rsp) | ||
93 | mov %r8, %r9 | ||
94 | mov %rcx, %r8 | ||
95 | mov %rsi, %rcx | ||
96 | call *%rdi | ||
97 | addq $48, %rsp | ||
98 | RESTORE_XMM | ||
99 | ret | ||
100 | ENDPROC(efi_call5) | ||
101 | |||
102 | ENTRY(efi_call6) | ||
103 | SAVE_XMM | ||
104 | mov (%rsp), %rax | ||
105 | mov 8(%rax), %rax | ||
106 | subq $48, %rsp | ||
107 | mov %r9, 32(%rsp) | ||
108 | mov %rax, 40(%rsp) | ||
109 | mov %r8, %r9 | ||
110 | mov %rcx, %r8 | ||
111 | mov %rsi, %rcx | ||
112 | call *%rdi | ||
113 | addq $48, %rsp | ||
114 | RESTORE_XMM | ||
115 | ret | ||
116 | ENDPROC(efi_call6) | ||