diff options
Diffstat (limited to 'arch/x86/platform/efi/efi.c')
-rw-r--r-- | arch/x86/platform/efi/efi.c | 237 |
1 files changed, 2 insertions, 235 deletions
diff --git a/arch/x86/platform/efi/efi.c b/arch/x86/platform/efi/efi.c index 87fc96bcc13c..f8524434bf65 100644 --- a/arch/x86/platform/efi/efi.c +++ b/arch/x86/platform/efi/efi.c | |||
@@ -56,13 +56,6 @@ | |||
56 | 56 | ||
57 | #define EFI_DEBUG | 57 | #define EFI_DEBUG |
58 | 58 | ||
59 | #define EFI_MIN_RESERVE 5120 | ||
60 | |||
61 | #define EFI_DUMMY_GUID \ | ||
62 | EFI_GUID(0x4424ac57, 0xbe4b, 0x47dd, 0x9e, 0x97, 0xed, 0x50, 0xf0, 0x9f, 0x92, 0xa9) | ||
63 | |||
64 | static efi_char16_t efi_dummy_name[6] = { 'D', 'U', 'M', 'M', 'Y', 0 }; | ||
65 | |||
66 | struct efi_memory_map memmap; | 59 | struct efi_memory_map memmap; |
67 | 60 | ||
68 | static struct efi efi_phys __initdata; | 61 | static struct efi efi_phys __initdata; |
@@ -95,15 +88,6 @@ static int __init setup_add_efi_memmap(char *arg) | |||
95 | } | 88 | } |
96 | early_param("add_efi_memmap", setup_add_efi_memmap); | 89 | early_param("add_efi_memmap", setup_add_efi_memmap); |
97 | 90 | ||
98 | static bool efi_no_storage_paranoia; | ||
99 | |||
100 | static int __init setup_storage_paranoia(char *arg) | ||
101 | { | ||
102 | efi_no_storage_paranoia = true; | ||
103 | return 0; | ||
104 | } | ||
105 | early_param("efi_no_storage_paranoia", setup_storage_paranoia); | ||
106 | |||
107 | static efi_status_t virt_efi_get_time(efi_time_t *tm, efi_time_cap_t *tc) | 91 | static efi_status_t virt_efi_get_time(efi_time_t *tm, efi_time_cap_t *tc) |
108 | { | 92 | { |
109 | unsigned long flags; | 93 | unsigned long flags; |
@@ -392,37 +376,6 @@ static void __init print_efi_memmap(void) | |||
392 | #endif /* EFI_DEBUG */ | 376 | #endif /* EFI_DEBUG */ |
393 | } | 377 | } |
394 | 378 | ||
395 | void __init efi_reserve_boot_services(void) | ||
396 | { | ||
397 | void *p; | ||
398 | |||
399 | for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) { | ||
400 | efi_memory_desc_t *md = p; | ||
401 | u64 start = md->phys_addr; | ||
402 | u64 size = md->num_pages << EFI_PAGE_SHIFT; | ||
403 | |||
404 | if (md->type != EFI_BOOT_SERVICES_CODE && | ||
405 | md->type != EFI_BOOT_SERVICES_DATA) | ||
406 | continue; | ||
407 | /* Only reserve where possible: | ||
408 | * - Not within any already allocated areas | ||
409 | * - Not over any memory area (really needed, if above?) | ||
410 | * - Not within any part of the kernel | ||
411 | * - Not the bios reserved area | ||
412 | */ | ||
413 | if ((start + size > __pa_symbol(_text) | ||
414 | && start <= __pa_symbol(_end)) || | ||
415 | !e820_all_mapped(start, start+size, E820_RAM) || | ||
416 | memblock_is_region_reserved(start, size)) { | ||
417 | /* Could not reserve, skip it */ | ||
418 | md->num_pages = 0; | ||
419 | memblock_dbg("Could not reserve boot range [0x%010llx-0x%010llx]\n", | ||
420 | start, start+size-1); | ||
421 | } else | ||
422 | memblock_reserve(start, size); | ||
423 | } | ||
424 | } | ||
425 | |||
426 | void __init efi_unmap_memmap(void) | 379 | void __init efi_unmap_memmap(void) |
427 | { | 380 | { |
428 | clear_bit(EFI_MEMMAP, &efi.flags); | 381 | clear_bit(EFI_MEMMAP, &efi.flags); |
@@ -432,29 +385,6 @@ void __init efi_unmap_memmap(void) | |||
432 | } | 385 | } |
433 | } | 386 | } |
434 | 387 | ||
435 | void __init efi_free_boot_services(void) | ||
436 | { | ||
437 | void *p; | ||
438 | |||
439 | for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) { | ||
440 | efi_memory_desc_t *md = p; | ||
441 | unsigned long long start = md->phys_addr; | ||
442 | unsigned long long size = md->num_pages << EFI_PAGE_SHIFT; | ||
443 | |||
444 | if (md->type != EFI_BOOT_SERVICES_CODE && | ||
445 | md->type != EFI_BOOT_SERVICES_DATA) | ||
446 | continue; | ||
447 | |||
448 | /* Could not reserve boot area */ | ||
449 | if (!size) | ||
450 | continue; | ||
451 | |||
452 | free_bootmem_late(start, size); | ||
453 | } | ||
454 | |||
455 | efi_unmap_memmap(); | ||
456 | } | ||
457 | |||
458 | static int __init efi_systab_init(void *phys) | 388 | static int __init efi_systab_init(void *phys) |
459 | { | 389 | { |
460 | if (efi_enabled(EFI_64BIT)) { | 390 | if (efi_enabled(EFI_64BIT)) { |
@@ -649,62 +579,6 @@ static int __init efi_memmap_init(void) | |||
649 | return 0; | 579 | return 0; |
650 | } | 580 | } |
651 | 581 | ||
652 | /* | ||
653 | * A number of config table entries get remapped to virtual addresses | ||
654 | * after entering EFI virtual mode. However, the kexec kernel requires | ||
655 | * their physical addresses therefore we pass them via setup_data and | ||
656 | * correct those entries to their respective physical addresses here. | ||
657 | * | ||
658 | * Currently only handles smbios which is necessary for some firmware | ||
659 | * implementation. | ||
660 | */ | ||
661 | static int __init efi_reuse_config(u64 tables, int nr_tables) | ||
662 | { | ||
663 | int i, sz, ret = 0; | ||
664 | void *p, *tablep; | ||
665 | struct efi_setup_data *data; | ||
666 | |||
667 | if (!efi_setup) | ||
668 | return 0; | ||
669 | |||
670 | if (!efi_enabled(EFI_64BIT)) | ||
671 | return 0; | ||
672 | |||
673 | data = early_memremap(efi_setup, sizeof(*data)); | ||
674 | if (!data) { | ||
675 | ret = -ENOMEM; | ||
676 | goto out; | ||
677 | } | ||
678 | |||
679 | if (!data->smbios) | ||
680 | goto out_memremap; | ||
681 | |||
682 | sz = sizeof(efi_config_table_64_t); | ||
683 | |||
684 | p = tablep = early_memremap(tables, nr_tables * sz); | ||
685 | if (!p) { | ||
686 | pr_err("Could not map Configuration table!\n"); | ||
687 | ret = -ENOMEM; | ||
688 | goto out_memremap; | ||
689 | } | ||
690 | |||
691 | for (i = 0; i < efi.systab->nr_tables; i++) { | ||
692 | efi_guid_t guid; | ||
693 | |||
694 | guid = ((efi_config_table_64_t *)p)->guid; | ||
695 | |||
696 | if (!efi_guidcmp(guid, SMBIOS_TABLE_GUID)) | ||
697 | ((efi_config_table_64_t *)p)->table = data->smbios; | ||
698 | p += sz; | ||
699 | } | ||
700 | early_iounmap(tablep, nr_tables * sz); | ||
701 | |||
702 | out_memremap: | ||
703 | early_iounmap(data, sizeof(*data)); | ||
704 | out: | ||
705 | return ret; | ||
706 | } | ||
707 | |||
708 | void __init efi_init(void) | 582 | void __init efi_init(void) |
709 | { | 583 | { |
710 | efi_char16_t *c16; | 584 | efi_char16_t *c16; |
@@ -1057,11 +931,7 @@ static void __init kexec_enter_virtual_mode(void) | |||
1057 | runtime_code_page_mkexec(); | 931 | runtime_code_page_mkexec(); |
1058 | 932 | ||
1059 | /* clean DUMMY object */ | 933 | /* clean DUMMY object */ |
1060 | efi.set_variable(efi_dummy_name, &EFI_DUMMY_GUID, | 934 | efi_delete_dummy_variable(); |
1061 | EFI_VARIABLE_NON_VOLATILE | | ||
1062 | EFI_VARIABLE_BOOTSERVICE_ACCESS | | ||
1063 | EFI_VARIABLE_RUNTIME_ACCESS, | ||
1064 | 0, NULL); | ||
1065 | #endif | 935 | #endif |
1066 | } | 936 | } |
1067 | 937 | ||
@@ -1179,11 +1049,7 @@ static void __init __efi_enter_virtual_mode(void) | |||
1179 | free_pages((unsigned long)new_memmap, pg_shift); | 1049 | free_pages((unsigned long)new_memmap, pg_shift); |
1180 | 1050 | ||
1181 | /* clean DUMMY object */ | 1051 | /* clean DUMMY object */ |
1182 | efi.set_variable(efi_dummy_name, &EFI_DUMMY_GUID, | 1052 | efi_delete_dummy_variable(); |
1183 | EFI_VARIABLE_NON_VOLATILE | | ||
1184 | EFI_VARIABLE_BOOTSERVICE_ACCESS | | ||
1185 | EFI_VARIABLE_RUNTIME_ACCESS, | ||
1186 | 0, NULL); | ||
1187 | } | 1053 | } |
1188 | 1054 | ||
1189 | void __init efi_enter_virtual_mode(void) | 1055 | void __init efi_enter_virtual_mode(void) |
@@ -1230,86 +1096,6 @@ u64 efi_mem_attributes(unsigned long phys_addr) | |||
1230 | return 0; | 1096 | return 0; |
1231 | } | 1097 | } |
1232 | 1098 | ||
1233 | /* | ||
1234 | * Some firmware implementations refuse to boot if there's insufficient space | ||
1235 | * in the variable store. Ensure that we never use more than a safe limit. | ||
1236 | * | ||
1237 | * Return EFI_SUCCESS if it is safe to write 'size' bytes to the variable | ||
1238 | * store. | ||
1239 | */ | ||
1240 | efi_status_t efi_query_variable_store(u32 attributes, unsigned long size) | ||
1241 | { | ||
1242 | efi_status_t status; | ||
1243 | u64 storage_size, remaining_size, max_size; | ||
1244 | |||
1245 | if (!(attributes & EFI_VARIABLE_NON_VOLATILE)) | ||
1246 | return 0; | ||
1247 | |||
1248 | status = efi.query_variable_info(attributes, &storage_size, | ||
1249 | &remaining_size, &max_size); | ||
1250 | if (status != EFI_SUCCESS) | ||
1251 | return status; | ||
1252 | |||
1253 | /* | ||
1254 | * We account for that by refusing the write if permitting it would | ||
1255 | * reduce the available space to under 5KB. This figure was provided by | ||
1256 | * Samsung, so should be safe. | ||
1257 | */ | ||
1258 | if ((remaining_size - size < EFI_MIN_RESERVE) && | ||
1259 | !efi_no_storage_paranoia) { | ||
1260 | |||
1261 | /* | ||
1262 | * Triggering garbage collection may require that the firmware | ||
1263 | * generate a real EFI_OUT_OF_RESOURCES error. We can force | ||
1264 | * that by attempting to use more space than is available. | ||
1265 | */ | ||
1266 | unsigned long dummy_size = remaining_size + 1024; | ||
1267 | void *dummy = kzalloc(dummy_size, GFP_ATOMIC); | ||
1268 | |||
1269 | if (!dummy) | ||
1270 | return EFI_OUT_OF_RESOURCES; | ||
1271 | |||
1272 | status = efi.set_variable(efi_dummy_name, &EFI_DUMMY_GUID, | ||
1273 | EFI_VARIABLE_NON_VOLATILE | | ||
1274 | EFI_VARIABLE_BOOTSERVICE_ACCESS | | ||
1275 | EFI_VARIABLE_RUNTIME_ACCESS, | ||
1276 | dummy_size, dummy); | ||
1277 | |||
1278 | if (status == EFI_SUCCESS) { | ||
1279 | /* | ||
1280 | * This should have failed, so if it didn't make sure | ||
1281 | * that we delete it... | ||
1282 | */ | ||
1283 | efi.set_variable(efi_dummy_name, &EFI_DUMMY_GUID, | ||
1284 | EFI_VARIABLE_NON_VOLATILE | | ||
1285 | EFI_VARIABLE_BOOTSERVICE_ACCESS | | ||
1286 | EFI_VARIABLE_RUNTIME_ACCESS, | ||
1287 | 0, dummy); | ||
1288 | } | ||
1289 | |||
1290 | kfree(dummy); | ||
1291 | |||
1292 | /* | ||
1293 | * The runtime code may now have triggered a garbage collection | ||
1294 | * run, so check the variable info again | ||
1295 | */ | ||
1296 | status = efi.query_variable_info(attributes, &storage_size, | ||
1297 | &remaining_size, &max_size); | ||
1298 | |||
1299 | if (status != EFI_SUCCESS) | ||
1300 | return status; | ||
1301 | |||
1302 | /* | ||
1303 | * There still isn't enough room, so return an error | ||
1304 | */ | ||
1305 | if (remaining_size - size < EFI_MIN_RESERVE) | ||
1306 | return EFI_OUT_OF_RESOURCES; | ||
1307 | } | ||
1308 | |||
1309 | return EFI_SUCCESS; | ||
1310 | } | ||
1311 | EXPORT_SYMBOL_GPL(efi_query_variable_store); | ||
1312 | |||
1313 | static int __init parse_efi_cmdline(char *str) | 1099 | static int __init parse_efi_cmdline(char *str) |
1314 | { | 1100 | { |
1315 | if (*str == '=') | 1101 | if (*str == '=') |
@@ -1321,22 +1107,3 @@ static int __init parse_efi_cmdline(char *str) | |||
1321 | return 0; | 1107 | return 0; |
1322 | } | 1108 | } |
1323 | early_param("efi", parse_efi_cmdline); | 1109 | early_param("efi", parse_efi_cmdline); |
1324 | |||
1325 | void __init efi_apply_memmap_quirks(void) | ||
1326 | { | ||
1327 | /* | ||
1328 | * Once setup is done earlier, unmap the EFI memory map on mismatched | ||
1329 | * firmware/kernel architectures since there is no support for runtime | ||
1330 | * services. | ||
1331 | */ | ||
1332 | if (!efi_runtime_supported()) { | ||
1333 | pr_info("efi: Setup done, disabling due to 32/64-bit mismatch\n"); | ||
1334 | efi_unmap_memmap(); | ||
1335 | } | ||
1336 | |||
1337 | /* | ||
1338 | * UV doesn't support the new EFI pagetable mapping yet. | ||
1339 | */ | ||
1340 | if (is_uv_system()) | ||
1341 | set_bit(EFI_OLD_MEMMAP, &efi.flags); | ||
1342 | } | ||