Huang, Ying | 5b83683 | 2008-01-30 13:31:19 +0100 | [diff] [blame] | 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 | |
Olof Johansson | e3cb3f5 | 2012-02-12 13:24:26 -0800 | [diff] [blame] | 29 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 30 | |
Huang, Ying | 5b83683 | 2008-01-30 13:31:19 +0100 | [diff] [blame] | 31 | #include <linux/kernel.h> |
| 32 | #include <linux/init.h> |
| 33 | #include <linux/efi.h> |
Josh Triplett | 2223af3 | 2012-09-28 17:57:05 -0700 | [diff] [blame] | 34 | #include <linux/efi-bgrt.h> |
Paul Gortmaker | 69c60c8 | 2011-05-26 12:22:53 -0400 | [diff] [blame] | 35 | #include <linux/export.h> |
Huang, Ying | 5b83683 | 2008-01-30 13:31:19 +0100 | [diff] [blame] | 36 | #include <linux/bootmem.h> |
David Howells | 0d01ff2 | 2013-04-11 23:51:01 +0100 | [diff] [blame] | 37 | #include <linux/slab.h> |
Yinghai Lu | a9ce6bc | 2010-08-25 13:39:17 -0700 | [diff] [blame] | 38 | #include <linux/memblock.h> |
Huang, Ying | 5b83683 | 2008-01-30 13:31:19 +0100 | [diff] [blame] | 39 | #include <linux/spinlock.h> |
| 40 | #include <linux/uaccess.h> |
| 41 | #include <linux/time.h> |
| 42 | #include <linux/io.h> |
| 43 | #include <linux/reboot.h> |
| 44 | #include <linux/bcd.h> |
| 45 | |
| 46 | #include <asm/setup.h> |
| 47 | #include <asm/efi.h> |
| 48 | #include <asm/time.h> |
Huang, Ying | a2172e2 | 2008-01-30 13:33:55 +0100 | [diff] [blame] | 49 | #include <asm/cacheflush.h> |
| 50 | #include <asm/tlbflush.h> |
Feng Tang | 7bd867d | 2009-09-10 10:48:56 +0800 | [diff] [blame] | 51 | #include <asm/x86_init.h> |
Prarit Bhargava | 3195ef5 | 2013-02-14 12:02:54 -0500 | [diff] [blame] | 52 | #include <asm/rtc.h> |
Huang, Ying | 5b83683 | 2008-01-30 13:31:19 +0100 | [diff] [blame] | 53 | |
| 54 | #define EFI_DEBUG 1 |
Huang, Ying | 5b83683 | 2008-01-30 13:31:19 +0100 | [diff] [blame] | 55 | |
Matthew Garrett | f8b8404 | 2013-06-01 16:06:20 -0400 | [diff] [blame] | 56 | #define EFI_MIN_RESERVE 5120 |
| 57 | |
| 58 | #define EFI_DUMMY_GUID \ |
| 59 | EFI_GUID(0x4424ac57, 0xbe4b, 0x47dd, 0x9e, 0x97, 0xed, 0x50, 0xf0, 0x9f, 0x92, 0xa9) |
| 60 | |
| 61 | static efi_char16_t efi_dummy_name[6] = { 'D', 'U', 'M', 'M', 'Y', 0 }; |
Matthew Garrett | 31ff2f2 | 2013-04-15 13:09:47 -0700 | [diff] [blame] | 62 | |
Huang, Ying | 5b83683 | 2008-01-30 13:31:19 +0100 | [diff] [blame] | 63 | struct efi_memory_map memmap; |
| 64 | |
Harvey Harrison | ecaea42 | 2008-02-13 13:26:13 -0800 | [diff] [blame] | 65 | static struct efi efi_phys __initdata; |
Huang, Ying | 5b83683 | 2008-01-30 13:31:19 +0100 | [diff] [blame] | 66 | static efi_system_table_t efi_systab __initdata; |
| 67 | |
Matt Fleming | 83e6818 | 2012-11-14 09:42:35 +0000 | [diff] [blame] | 68 | unsigned long x86_efi_facility; |
| 69 | |
Leif Lindholm | 272686b | 2013-09-05 11:34:54 +0100 | [diff] [blame^] | 70 | static __initdata efi_config_table_type_t arch_tables[] = { |
| 71 | #ifdef CONFIG_X86_UV |
| 72 | {UV_SYSTEM_TABLE_GUID, "UVsystab", &efi.uv_systab}, |
| 73 | #endif |
| 74 | {NULL_GUID, NULL, 0}, |
| 75 | }; |
| 76 | |
Matt Fleming | 83e6818 | 2012-11-14 09:42:35 +0000 | [diff] [blame] | 77 | /* |
| 78 | * Returns 1 if 'facility' is enabled, 0 otherwise. |
| 79 | */ |
| 80 | int efi_enabled(int facility) |
| 81 | { |
| 82 | return test_bit(facility, &x86_efi_facility) != 0; |
| 83 | } |
| 84 | EXPORT_SYMBOL(efi_enabled); |
| 85 | |
Matt Fleming | 058e7b5 | 2013-02-22 15:03:47 +0000 | [diff] [blame] | 86 | static bool __initdata disable_runtime = false; |
Huang, Ying | 8b2cb7a | 2008-01-30 13:32:11 +0100 | [diff] [blame] | 87 | static int __init setup_noefi(char *arg) |
| 88 | { |
Matt Fleming | fb834c7 | 2013-02-20 20:36:12 +0000 | [diff] [blame] | 89 | disable_runtime = true; |
Huang, Ying | 8b2cb7a | 2008-01-30 13:32:11 +0100 | [diff] [blame] | 90 | return 0; |
| 91 | } |
| 92 | early_param("noefi", setup_noefi); |
| 93 | |
Paul Jackson | 200001e | 2008-06-25 05:44:46 -0700 | [diff] [blame] | 94 | int add_efi_memmap; |
| 95 | EXPORT_SYMBOL(add_efi_memmap); |
| 96 | |
| 97 | static int __init setup_add_efi_memmap(char *arg) |
| 98 | { |
| 99 | add_efi_memmap = 1; |
| 100 | return 0; |
| 101 | } |
| 102 | early_param("add_efi_memmap", setup_add_efi_memmap); |
| 103 | |
Richard Weinberger | 8c58bf3 | 2013-04-17 01:00:53 +0200 | [diff] [blame] | 104 | static bool efi_no_storage_paranoia; |
| 105 | |
| 106 | static int __init setup_storage_paranoia(char *arg) |
| 107 | { |
| 108 | efi_no_storage_paranoia = true; |
| 109 | return 0; |
| 110 | } |
| 111 | early_param("efi_no_storage_paranoia", setup_storage_paranoia); |
| 112 | |
Paul Jackson | 200001e | 2008-06-25 05:44:46 -0700 | [diff] [blame] | 113 | |
Huang, Ying | 5b83683 | 2008-01-30 13:31:19 +0100 | [diff] [blame] | 114 | static efi_status_t virt_efi_get_time(efi_time_t *tm, efi_time_cap_t *tc) |
| 115 | { |
Jan Beulich | ef68c8f | 2011-07-19 11:53:07 +0100 | [diff] [blame] | 116 | unsigned long flags; |
| 117 | efi_status_t status; |
| 118 | |
| 119 | spin_lock_irqsave(&rtc_lock, flags); |
| 120 | status = efi_call_virt2(get_time, tm, tc); |
| 121 | spin_unlock_irqrestore(&rtc_lock, flags); |
| 122 | return status; |
Huang, Ying | 5b83683 | 2008-01-30 13:31:19 +0100 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | static efi_status_t virt_efi_set_time(efi_time_t *tm) |
| 126 | { |
Jan Beulich | ef68c8f | 2011-07-19 11:53:07 +0100 | [diff] [blame] | 127 | unsigned long flags; |
| 128 | efi_status_t status; |
| 129 | |
| 130 | spin_lock_irqsave(&rtc_lock, flags); |
| 131 | status = efi_call_virt1(set_time, tm); |
| 132 | spin_unlock_irqrestore(&rtc_lock, flags); |
| 133 | return status; |
Huang, Ying | 5b83683 | 2008-01-30 13:31:19 +0100 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | static efi_status_t virt_efi_get_wakeup_time(efi_bool_t *enabled, |
| 137 | efi_bool_t *pending, |
| 138 | efi_time_t *tm) |
| 139 | { |
Jan Beulich | ef68c8f | 2011-07-19 11:53:07 +0100 | [diff] [blame] | 140 | unsigned long flags; |
| 141 | efi_status_t status; |
| 142 | |
| 143 | spin_lock_irqsave(&rtc_lock, flags); |
| 144 | status = efi_call_virt3(get_wakeup_time, |
| 145 | enabled, pending, tm); |
| 146 | spin_unlock_irqrestore(&rtc_lock, flags); |
| 147 | return status; |
Huang, Ying | 5b83683 | 2008-01-30 13:31:19 +0100 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | static efi_status_t virt_efi_set_wakeup_time(efi_bool_t enabled, efi_time_t *tm) |
| 151 | { |
Jan Beulich | ef68c8f | 2011-07-19 11:53:07 +0100 | [diff] [blame] | 152 | unsigned long flags; |
| 153 | efi_status_t status; |
| 154 | |
| 155 | spin_lock_irqsave(&rtc_lock, flags); |
| 156 | status = efi_call_virt2(set_wakeup_time, |
| 157 | enabled, tm); |
| 158 | spin_unlock_irqrestore(&rtc_lock, flags); |
| 159 | return status; |
Huang, Ying | 5b83683 | 2008-01-30 13:31:19 +0100 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | static efi_status_t virt_efi_get_variable(efi_char16_t *name, |
| 163 | efi_guid_t *vendor, |
| 164 | u32 *attr, |
| 165 | unsigned long *data_size, |
| 166 | void *data) |
| 167 | { |
| 168 | return efi_call_virt5(get_variable, |
| 169 | name, vendor, attr, |
| 170 | data_size, data); |
| 171 | } |
| 172 | |
| 173 | static efi_status_t virt_efi_get_next_variable(unsigned long *name_size, |
| 174 | efi_char16_t *name, |
| 175 | efi_guid_t *vendor) |
| 176 | { |
Matthew Garrett | f8b8404 | 2013-06-01 16:06:20 -0400 | [diff] [blame] | 177 | return efi_call_virt3(get_next_variable, |
| 178 | name_size, name, vendor); |
Huang, Ying | 5b83683 | 2008-01-30 13:31:19 +0100 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | static efi_status_t virt_efi_set_variable(efi_char16_t *name, |
| 182 | efi_guid_t *vendor, |
Matthew Garrett | f7a2d73 | 2011-06-06 15:36:24 -0400 | [diff] [blame] | 183 | u32 attr, |
Huang, Ying | 5b83683 | 2008-01-30 13:31:19 +0100 | [diff] [blame] | 184 | unsigned long data_size, |
| 185 | void *data) |
| 186 | { |
Matthew Garrett | f8b8404 | 2013-06-01 16:06:20 -0400 | [diff] [blame] | 187 | return efi_call_virt5(set_variable, |
| 188 | name, vendor, attr, |
| 189 | data_size, data); |
Huang, Ying | 5b83683 | 2008-01-30 13:31:19 +0100 | [diff] [blame] | 190 | } |
| 191 | |
Matthew Garrett | 3b37023 | 2011-06-06 15:36:25 -0400 | [diff] [blame] | 192 | static efi_status_t virt_efi_query_variable_info(u32 attr, |
| 193 | u64 *storage_space, |
| 194 | u64 *remaining_space, |
| 195 | u64 *max_variable_size) |
| 196 | { |
| 197 | if (efi.runtime_version < EFI_2_00_SYSTEM_TABLE_REVISION) |
| 198 | return EFI_UNSUPPORTED; |
| 199 | |
| 200 | return efi_call_virt4(query_variable_info, attr, storage_space, |
| 201 | remaining_space, max_variable_size); |
| 202 | } |
| 203 | |
Huang, Ying | 5b83683 | 2008-01-30 13:31:19 +0100 | [diff] [blame] | 204 | static efi_status_t virt_efi_get_next_high_mono_count(u32 *count) |
| 205 | { |
| 206 | return efi_call_virt1(get_next_high_mono_count, count); |
| 207 | } |
| 208 | |
| 209 | static void virt_efi_reset_system(int reset_type, |
| 210 | efi_status_t status, |
| 211 | unsigned long data_size, |
| 212 | efi_char16_t *data) |
| 213 | { |
| 214 | efi_call_virt4(reset_system, reset_type, status, |
| 215 | data_size, data); |
| 216 | } |
| 217 | |
Matthew Garrett | 3b37023 | 2011-06-06 15:36:25 -0400 | [diff] [blame] | 218 | static efi_status_t virt_efi_update_capsule(efi_capsule_header_t **capsules, |
| 219 | unsigned long count, |
| 220 | unsigned long sg_list) |
| 221 | { |
| 222 | if (efi.runtime_version < EFI_2_00_SYSTEM_TABLE_REVISION) |
| 223 | return EFI_UNSUPPORTED; |
| 224 | |
| 225 | return efi_call_virt3(update_capsule, capsules, count, sg_list); |
| 226 | } |
| 227 | |
| 228 | static efi_status_t virt_efi_query_capsule_caps(efi_capsule_header_t **capsules, |
| 229 | unsigned long count, |
| 230 | u64 *max_size, |
| 231 | int *reset_type) |
| 232 | { |
| 233 | if (efi.runtime_version < EFI_2_00_SYSTEM_TABLE_REVISION) |
| 234 | return EFI_UNSUPPORTED; |
| 235 | |
| 236 | return efi_call_virt4(query_capsule_caps, capsules, count, max_size, |
| 237 | reset_type); |
| 238 | } |
| 239 | |
Huang, Ying | 5b83683 | 2008-01-30 13:31:19 +0100 | [diff] [blame] | 240 | static efi_status_t __init phys_efi_set_virtual_address_map( |
| 241 | unsigned long memory_map_size, |
| 242 | unsigned long descriptor_size, |
| 243 | u32 descriptor_version, |
| 244 | efi_memory_desc_t *virtual_map) |
| 245 | { |
| 246 | efi_status_t status; |
| 247 | |
| 248 | efi_call_phys_prelog(); |
| 249 | status = efi_call_phys4(efi_phys.set_virtual_address_map, |
| 250 | memory_map_size, descriptor_size, |
| 251 | descriptor_version, virtual_map); |
| 252 | efi_call_phys_epilog(); |
| 253 | return status; |
| 254 | } |
| 255 | |
Linus Torvalds | 11520e5 | 2012-12-15 15:15:24 -0800 | [diff] [blame] | 256 | static efi_status_t __init phys_efi_get_time(efi_time_t *tm, |
| 257 | efi_time_cap_t *tc) |
| 258 | { |
| 259 | unsigned long flags; |
| 260 | efi_status_t status; |
| 261 | |
| 262 | spin_lock_irqsave(&rtc_lock, flags); |
| 263 | efi_call_phys_prelog(); |
| 264 | status = efi_call_phys2(efi_phys.get_time, virt_to_phys(tm), |
| 265 | virt_to_phys(tc)); |
| 266 | efi_call_phys_epilog(); |
| 267 | spin_unlock_irqrestore(&rtc_lock, flags); |
| 268 | return status; |
| 269 | } |
| 270 | |
David Vrabel | 3565184 | 2013-05-13 18:56:06 +0100 | [diff] [blame] | 271 | int efi_set_rtc_mmss(const struct timespec *now) |
Huang, Ying | 5b83683 | 2008-01-30 13:31:19 +0100 | [diff] [blame] | 272 | { |
David Vrabel | 3565184 | 2013-05-13 18:56:06 +0100 | [diff] [blame] | 273 | unsigned long nowtime = now->tv_sec; |
Huang, Ying | 5b83683 | 2008-01-30 13:31:19 +0100 | [diff] [blame] | 274 | efi_status_t status; |
| 275 | efi_time_t eft; |
| 276 | efi_time_cap_t cap; |
Prarit Bhargava | 3195ef5 | 2013-02-14 12:02:54 -0500 | [diff] [blame] | 277 | struct rtc_time tm; |
Huang, Ying | 5b83683 | 2008-01-30 13:31:19 +0100 | [diff] [blame] | 278 | |
| 279 | status = efi.get_time(&eft, &cap); |
| 280 | if (status != EFI_SUCCESS) { |
Olof Johansson | e3cb3f5 | 2012-02-12 13:24:26 -0800 | [diff] [blame] | 281 | pr_err("Oops: efitime: can't read time!\n"); |
Huang, Ying | 5b83683 | 2008-01-30 13:31:19 +0100 | [diff] [blame] | 282 | return -1; |
| 283 | } |
| 284 | |
Prarit Bhargava | 3195ef5 | 2013-02-14 12:02:54 -0500 | [diff] [blame] | 285 | rtc_time_to_tm(nowtime, &tm); |
| 286 | if (!rtc_valid_tm(&tm)) { |
| 287 | eft.year = tm.tm_year + 1900; |
| 288 | eft.month = tm.tm_mon + 1; |
| 289 | eft.day = tm.tm_mday; |
| 290 | eft.minute = tm.tm_min; |
| 291 | eft.second = tm.tm_sec; |
| 292 | eft.nanosecond = 0; |
| 293 | } else { |
| 294 | printk(KERN_ERR |
| 295 | "%s: Invalid EFI RTC value: write of %lx to EFI RTC failed\n", |
| 296 | __FUNCTION__, nowtime); |
| 297 | return -1; |
| 298 | } |
Huang, Ying | 5b83683 | 2008-01-30 13:31:19 +0100 | [diff] [blame] | 299 | |
| 300 | status = efi.set_time(&eft); |
| 301 | if (status != EFI_SUCCESS) { |
Olof Johansson | e3cb3f5 | 2012-02-12 13:24:26 -0800 | [diff] [blame] | 302 | pr_err("Oops: efitime: can't write time!\n"); |
Huang, Ying | 5b83683 | 2008-01-30 13:31:19 +0100 | [diff] [blame] | 303 | return -1; |
| 304 | } |
| 305 | return 0; |
| 306 | } |
| 307 | |
David Vrabel | 3565184 | 2013-05-13 18:56:06 +0100 | [diff] [blame] | 308 | void efi_get_time(struct timespec *now) |
Huang, Ying | 5b83683 | 2008-01-30 13:31:19 +0100 | [diff] [blame] | 309 | { |
| 310 | efi_status_t status; |
| 311 | efi_time_t eft; |
| 312 | efi_time_cap_t cap; |
| 313 | |
| 314 | status = efi.get_time(&eft, &cap); |
| 315 | if (status != EFI_SUCCESS) |
Olof Johansson | e3cb3f5 | 2012-02-12 13:24:26 -0800 | [diff] [blame] | 316 | pr_err("Oops: efitime: can't read time!\n"); |
Huang, Ying | 5b83683 | 2008-01-30 13:31:19 +0100 | [diff] [blame] | 317 | |
David Vrabel | 3565184 | 2013-05-13 18:56:06 +0100 | [diff] [blame] | 318 | now->tv_sec = mktime(eft.year, eft.month, eft.day, eft.hour, |
| 319 | eft.minute, eft.second); |
| 320 | now->tv_nsec = 0; |
Huang, Ying | 5b83683 | 2008-01-30 13:31:19 +0100 | [diff] [blame] | 321 | } |
| 322 | |
Paul Jackson | 69c9189 | 2008-05-14 08:15:58 -0700 | [diff] [blame] | 323 | /* |
| 324 | * Tell the kernel about the EFI memory map. This might include |
| 325 | * more than the max 128 entries that can fit in the e820 legacy |
| 326 | * (zeropage) memory map. |
| 327 | */ |
| 328 | |
Paul Jackson | 200001e | 2008-06-25 05:44:46 -0700 | [diff] [blame] | 329 | static void __init do_add_efi_memmap(void) |
Paul Jackson | 69c9189 | 2008-05-14 08:15:58 -0700 | [diff] [blame] | 330 | { |
| 331 | void *p; |
| 332 | |
| 333 | for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) { |
| 334 | efi_memory_desc_t *md = p; |
| 335 | unsigned long long start = md->phys_addr; |
| 336 | unsigned long long size = md->num_pages << EFI_PAGE_SHIFT; |
| 337 | int e820_type; |
| 338 | |
Cliff Wickman | e2a7147 | 2009-06-16 16:43:40 -0500 | [diff] [blame] | 339 | switch (md->type) { |
| 340 | case EFI_LOADER_CODE: |
| 341 | case EFI_LOADER_DATA: |
| 342 | case EFI_BOOT_SERVICES_CODE: |
| 343 | case EFI_BOOT_SERVICES_DATA: |
| 344 | case EFI_CONVENTIONAL_MEMORY: |
| 345 | if (md->attribute & EFI_MEMORY_WB) |
| 346 | e820_type = E820_RAM; |
| 347 | else |
| 348 | e820_type = E820_RESERVED; |
| 349 | break; |
| 350 | case EFI_ACPI_RECLAIM_MEMORY: |
| 351 | e820_type = E820_ACPI; |
| 352 | break; |
| 353 | case EFI_ACPI_MEMORY_NVS: |
| 354 | e820_type = E820_NVS; |
| 355 | break; |
| 356 | case EFI_UNUSABLE_MEMORY: |
| 357 | e820_type = E820_UNUSABLE; |
| 358 | break; |
| 359 | default: |
| 360 | /* |
| 361 | * EFI_RESERVED_TYPE EFI_RUNTIME_SERVICES_CODE |
| 362 | * EFI_RUNTIME_SERVICES_DATA EFI_MEMORY_MAPPED_IO |
| 363 | * EFI_MEMORY_MAPPED_IO_PORT_SPACE EFI_PAL_CODE |
| 364 | */ |
Paul Jackson | 69c9189 | 2008-05-14 08:15:58 -0700 | [diff] [blame] | 365 | e820_type = E820_RESERVED; |
Cliff Wickman | e2a7147 | 2009-06-16 16:43:40 -0500 | [diff] [blame] | 366 | break; |
| 367 | } |
Yinghai Lu | d0be6bd | 2008-06-15 18:58:51 -0700 | [diff] [blame] | 368 | e820_add_region(start, size, e820_type); |
Paul Jackson | 69c9189 | 2008-05-14 08:15:58 -0700 | [diff] [blame] | 369 | } |
| 370 | sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map); |
| 371 | } |
| 372 | |
Olof Johansson | 1adbfa3 | 2012-02-12 13:24:29 -0800 | [diff] [blame] | 373 | int __init efi_memblock_x86_reserve_range(void) |
Huang, Ying | ecacf09 | 2008-06-02 14:26:21 +0800 | [diff] [blame] | 374 | { |
Borislav Petkov | 15b9c35 | 2013-03-01 17:07:44 +0100 | [diff] [blame] | 375 | struct efi_info *e = &boot_params.efi_info; |
Huang, Ying | ecacf09 | 2008-06-02 14:26:21 +0800 | [diff] [blame] | 376 | unsigned long pmap; |
| 377 | |
Paul Jackson | 05486fa | 2008-06-22 07:22:02 -0700 | [diff] [blame] | 378 | #ifdef CONFIG_X86_32 |
Olof Johansson | 1adbfa3 | 2012-02-12 13:24:29 -0800 | [diff] [blame] | 379 | /* Can't handle data above 4GB at this time */ |
Borislav Petkov | 15b9c35 | 2013-03-01 17:07:44 +0100 | [diff] [blame] | 380 | if (e->efi_memmap_hi) { |
Olof Johansson | 1adbfa3 | 2012-02-12 13:24:29 -0800 | [diff] [blame] | 381 | pr_err("Memory map is above 4GB, disabling EFI.\n"); |
| 382 | return -EINVAL; |
| 383 | } |
Borislav Petkov | 15b9c35 | 2013-03-01 17:07:44 +0100 | [diff] [blame] | 384 | pmap = e->efi_memmap; |
Paul Jackson | 05486fa | 2008-06-22 07:22:02 -0700 | [diff] [blame] | 385 | #else |
Borislav Petkov | 15b9c35 | 2013-03-01 17:07:44 +0100 | [diff] [blame] | 386 | pmap = (e->efi_memmap | ((__u64)e->efi_memmap_hi << 32)); |
Huang, Ying | ecacf09 | 2008-06-02 14:26:21 +0800 | [diff] [blame] | 387 | #endif |
Borislav Petkov | 15b9c35 | 2013-03-01 17:07:44 +0100 | [diff] [blame] | 388 | memmap.phys_map = (void *)pmap; |
| 389 | memmap.nr_map = e->efi_memmap_size / |
| 390 | e->efi_memdesc_size; |
| 391 | memmap.desc_size = e->efi_memdesc_size; |
| 392 | memmap.desc_version = e->efi_memdesc_version; |
| 393 | |
Tejun Heo | 24aa078 | 2011-07-12 11:16:06 +0200 | [diff] [blame] | 394 | memblock_reserve(pmap, memmap.nr_map * memmap.desc_size); |
Olof Johansson | 1adbfa3 | 2012-02-12 13:24:29 -0800 | [diff] [blame] | 395 | |
| 396 | return 0; |
Huang, Ying | ecacf09 | 2008-06-02 14:26:21 +0800 | [diff] [blame] | 397 | } |
| 398 | |
Huang, Ying | 5b83683 | 2008-01-30 13:31:19 +0100 | [diff] [blame] | 399 | #if EFI_DEBUG |
| 400 | static void __init print_efi_memmap(void) |
| 401 | { |
| 402 | efi_memory_desc_t *md; |
| 403 | void *p; |
| 404 | int i; |
| 405 | |
| 406 | for (p = memmap.map, i = 0; |
| 407 | p < memmap.map_end; |
| 408 | p += memmap.desc_size, i++) { |
| 409 | md = p; |
Olof Johansson | e3cb3f5 | 2012-02-12 13:24:26 -0800 | [diff] [blame] | 410 | pr_info("mem%02u: type=%u, attr=0x%llx, " |
Huang, Ying | 5b83683 | 2008-01-30 13:31:19 +0100 | [diff] [blame] | 411 | "range=[0x%016llx-0x%016llx) (%lluMB)\n", |
| 412 | i, md->type, md->attribute, md->phys_addr, |
| 413 | md->phys_addr + (md->num_pages << EFI_PAGE_SHIFT), |
| 414 | (md->num_pages >> (20 - EFI_PAGE_SHIFT))); |
| 415 | } |
| 416 | } |
| 417 | #endif /* EFI_DEBUG */ |
| 418 | |
Matthew Garrett | 916f676 | 2011-05-25 09:53:13 -0400 | [diff] [blame] | 419 | void __init efi_reserve_boot_services(void) |
| 420 | { |
| 421 | void *p; |
| 422 | |
| 423 | for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) { |
| 424 | efi_memory_desc_t *md = p; |
Maarten Lankhorst | 7d68dc3 | 2011-06-14 19:53:09 +0200 | [diff] [blame] | 425 | u64 start = md->phys_addr; |
| 426 | u64 size = md->num_pages << EFI_PAGE_SHIFT; |
Matthew Garrett | 916f676 | 2011-05-25 09:53:13 -0400 | [diff] [blame] | 427 | |
| 428 | if (md->type != EFI_BOOT_SERVICES_CODE && |
| 429 | md->type != EFI_BOOT_SERVICES_DATA) |
| 430 | continue; |
Maarten Lankhorst | 7d68dc3 | 2011-06-14 19:53:09 +0200 | [diff] [blame] | 431 | /* Only reserve where possible: |
| 432 | * - Not within any already allocated areas |
| 433 | * - Not over any memory area (really needed, if above?) |
| 434 | * - Not within any part of the kernel |
| 435 | * - Not the bios reserved area |
| 436 | */ |
Alexander Duyck | fc8d782 | 2012-11-16 13:57:13 -0800 | [diff] [blame] | 437 | if ((start+size >= __pa_symbol(_text) |
| 438 | && start <= __pa_symbol(_end)) || |
Maarten Lankhorst | 7d68dc3 | 2011-06-14 19:53:09 +0200 | [diff] [blame] | 439 | !e820_all_mapped(start, start+size, E820_RAM) || |
Tejun Heo | bf61549 | 2011-07-12 09:58:05 +0200 | [diff] [blame] | 440 | memblock_is_region_reserved(start, size)) { |
Maarten Lankhorst | 7d68dc3 | 2011-06-14 19:53:09 +0200 | [diff] [blame] | 441 | /* Could not reserve, skip it */ |
| 442 | md->num_pages = 0; |
Olof Johansson | e3cb3f5 | 2012-02-12 13:24:26 -0800 | [diff] [blame] | 443 | memblock_dbg("Could not reserve boot range " |
Maarten Lankhorst | 7d68dc3 | 2011-06-14 19:53:09 +0200 | [diff] [blame] | 444 | "[0x%010llx-0x%010llx]\n", |
| 445 | start, start+size-1); |
| 446 | } else |
Tejun Heo | 24aa078 | 2011-07-12 11:16:06 +0200 | [diff] [blame] | 447 | memblock_reserve(start, size); |
Matthew Garrett | 916f676 | 2011-05-25 09:53:13 -0400 | [diff] [blame] | 448 | } |
| 449 | } |
| 450 | |
Olof Johansson | 5189c2a | 2012-10-24 10:00:44 -0700 | [diff] [blame] | 451 | void __init efi_unmap_memmap(void) |
Josh Triplett | 7851079 | 2012-09-28 17:55:44 -0700 | [diff] [blame] | 452 | { |
Matt Fleming | 83e6818 | 2012-11-14 09:42:35 +0000 | [diff] [blame] | 453 | clear_bit(EFI_MEMMAP, &x86_efi_facility); |
Josh Triplett | 7851079 | 2012-09-28 17:55:44 -0700 | [diff] [blame] | 454 | if (memmap.map) { |
| 455 | early_iounmap(memmap.map, memmap.nr_map * memmap.desc_size); |
| 456 | memmap.map = NULL; |
| 457 | } |
| 458 | } |
| 459 | |
| 460 | void __init efi_free_boot_services(void) |
Matthew Garrett | 916f676 | 2011-05-25 09:53:13 -0400 | [diff] [blame] | 461 | { |
| 462 | void *p; |
| 463 | |
Olof Johansson | 5189c2a | 2012-10-24 10:00:44 -0700 | [diff] [blame] | 464 | if (!efi_is_native()) |
Josh Triplett | 7851079 | 2012-09-28 17:55:44 -0700 | [diff] [blame] | 465 | return; |
| 466 | |
Matthew Garrett | 916f676 | 2011-05-25 09:53:13 -0400 | [diff] [blame] | 467 | for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) { |
| 468 | efi_memory_desc_t *md = p; |
| 469 | unsigned long long start = md->phys_addr; |
| 470 | unsigned long long size = md->num_pages << EFI_PAGE_SHIFT; |
| 471 | |
| 472 | if (md->type != EFI_BOOT_SERVICES_CODE && |
| 473 | md->type != EFI_BOOT_SERVICES_DATA) |
| 474 | continue; |
| 475 | |
Maarten Lankhorst | 7d68dc3 | 2011-06-14 19:53:09 +0200 | [diff] [blame] | 476 | /* Could not reserve boot area */ |
| 477 | if (!size) |
| 478 | continue; |
| 479 | |
Matthew Garrett | 916f676 | 2011-05-25 09:53:13 -0400 | [diff] [blame] | 480 | free_bootmem_late(start, size); |
| 481 | } |
Josh Triplett | 7851079 | 2012-09-28 17:55:44 -0700 | [diff] [blame] | 482 | |
| 483 | efi_unmap_memmap(); |
Matthew Garrett | 916f676 | 2011-05-25 09:53:13 -0400 | [diff] [blame] | 484 | } |
| 485 | |
Olof Johansson | 140bf27 | 2012-02-12 13:24:28 -0800 | [diff] [blame] | 486 | static int __init efi_systab_init(void *phys) |
Huang, Ying | 5b83683 | 2008-01-30 13:31:19 +0100 | [diff] [blame] | 487 | { |
Matt Fleming | 83e6818 | 2012-11-14 09:42:35 +0000 | [diff] [blame] | 488 | if (efi_enabled(EFI_64BIT)) { |
Olof Johansson | 1adbfa3 | 2012-02-12 13:24:29 -0800 | [diff] [blame] | 489 | efi_system_table_64_t *systab64; |
| 490 | u64 tmp = 0; |
| 491 | |
| 492 | systab64 = early_ioremap((unsigned long)phys, |
| 493 | sizeof(*systab64)); |
| 494 | if (systab64 == NULL) { |
| 495 | pr_err("Couldn't map the system table!\n"); |
| 496 | return -ENOMEM; |
| 497 | } |
| 498 | |
| 499 | efi_systab.hdr = systab64->hdr; |
| 500 | efi_systab.fw_vendor = systab64->fw_vendor; |
| 501 | tmp |= systab64->fw_vendor; |
| 502 | efi_systab.fw_revision = systab64->fw_revision; |
| 503 | efi_systab.con_in_handle = systab64->con_in_handle; |
| 504 | tmp |= systab64->con_in_handle; |
| 505 | efi_systab.con_in = systab64->con_in; |
| 506 | tmp |= systab64->con_in; |
| 507 | efi_systab.con_out_handle = systab64->con_out_handle; |
| 508 | tmp |= systab64->con_out_handle; |
| 509 | efi_systab.con_out = systab64->con_out; |
| 510 | tmp |= systab64->con_out; |
| 511 | efi_systab.stderr_handle = systab64->stderr_handle; |
| 512 | tmp |= systab64->stderr_handle; |
| 513 | efi_systab.stderr = systab64->stderr; |
| 514 | tmp |= systab64->stderr; |
| 515 | efi_systab.runtime = (void *)(unsigned long)systab64->runtime; |
| 516 | tmp |= systab64->runtime; |
| 517 | efi_systab.boottime = (void *)(unsigned long)systab64->boottime; |
| 518 | tmp |= systab64->boottime; |
| 519 | efi_systab.nr_tables = systab64->nr_tables; |
| 520 | efi_systab.tables = systab64->tables; |
| 521 | tmp |= systab64->tables; |
| 522 | |
| 523 | early_iounmap(systab64, sizeof(*systab64)); |
| 524 | #ifdef CONFIG_X86_32 |
| 525 | if (tmp >> 32) { |
| 526 | pr_err("EFI data located above 4GB, disabling EFI.\n"); |
| 527 | return -EINVAL; |
| 528 | } |
| 529 | #endif |
| 530 | } else { |
| 531 | efi_system_table_32_t *systab32; |
| 532 | |
| 533 | systab32 = early_ioremap((unsigned long)phys, |
| 534 | sizeof(*systab32)); |
| 535 | if (systab32 == NULL) { |
| 536 | pr_err("Couldn't map the system table!\n"); |
| 537 | return -ENOMEM; |
| 538 | } |
| 539 | |
| 540 | efi_systab.hdr = systab32->hdr; |
| 541 | efi_systab.fw_vendor = systab32->fw_vendor; |
| 542 | efi_systab.fw_revision = systab32->fw_revision; |
| 543 | efi_systab.con_in_handle = systab32->con_in_handle; |
| 544 | efi_systab.con_in = systab32->con_in; |
| 545 | efi_systab.con_out_handle = systab32->con_out_handle; |
| 546 | efi_systab.con_out = systab32->con_out; |
| 547 | efi_systab.stderr_handle = systab32->stderr_handle; |
| 548 | efi_systab.stderr = systab32->stderr; |
| 549 | efi_systab.runtime = (void *)(unsigned long)systab32->runtime; |
| 550 | efi_systab.boottime = (void *)(unsigned long)systab32->boottime; |
| 551 | efi_systab.nr_tables = systab32->nr_tables; |
| 552 | efi_systab.tables = systab32->tables; |
| 553 | |
| 554 | early_iounmap(systab32, sizeof(*systab32)); |
Olof Johansson | 140bf27 | 2012-02-12 13:24:28 -0800 | [diff] [blame] | 555 | } |
Olof Johansson | 1adbfa3 | 2012-02-12 13:24:29 -0800 | [diff] [blame] | 556 | |
Huang, Ying | 5b83683 | 2008-01-30 13:31:19 +0100 | [diff] [blame] | 557 | efi.systab = &efi_systab; |
| 558 | |
| 559 | /* |
| 560 | * Verify the EFI Table |
| 561 | */ |
Olof Johansson | 140bf27 | 2012-02-12 13:24:28 -0800 | [diff] [blame] | 562 | if (efi.systab->hdr.signature != EFI_SYSTEM_TABLE_SIGNATURE) { |
Olof Johansson | e3cb3f5 | 2012-02-12 13:24:26 -0800 | [diff] [blame] | 563 | pr_err("System table signature incorrect!\n"); |
Olof Johansson | 140bf27 | 2012-02-12 13:24:28 -0800 | [diff] [blame] | 564 | return -EINVAL; |
| 565 | } |
Huang, Ying | 5b83683 | 2008-01-30 13:31:19 +0100 | [diff] [blame] | 566 | if ((efi.systab->hdr.revision >> 16) == 0) |
Olof Johansson | e3cb3f5 | 2012-02-12 13:24:26 -0800 | [diff] [blame] | 567 | pr_err("Warning: System table version " |
Huang, Ying | 5b83683 | 2008-01-30 13:31:19 +0100 | [diff] [blame] | 568 | "%d.%02d, expected 1.00 or greater!\n", |
| 569 | efi.systab->hdr.revision >> 16, |
| 570 | efi.systab->hdr.revision & 0xffff); |
Olof Johansson | 140bf27 | 2012-02-12 13:24:28 -0800 | [diff] [blame] | 571 | |
| 572 | return 0; |
Olof Johansson | 83e7ee6 | 2012-02-12 13:24:25 -0800 | [diff] [blame] | 573 | } |
Huang, Ying | 5b83683 | 2008-01-30 13:31:19 +0100 | [diff] [blame] | 574 | |
Olof Johansson | 140bf27 | 2012-02-12 13:24:28 -0800 | [diff] [blame] | 575 | static int __init efi_runtime_init(void) |
Olof Johansson | 83e7ee6 | 2012-02-12 13:24:25 -0800 | [diff] [blame] | 576 | { |
| 577 | efi_runtime_services_t *runtime; |
Huang, Ying | 5b83683 | 2008-01-30 13:31:19 +0100 | [diff] [blame] | 578 | |
| 579 | /* |
| 580 | * Check out the runtime services table. We need to map |
| 581 | * the runtime services table so that we can grab the physical |
| 582 | * address of several of the EFI runtime functions, needed to |
| 583 | * set the firmware into virtual mode. |
| 584 | */ |
Huang, Ying | beacfaa | 2008-01-30 13:33:44 +0100 | [diff] [blame] | 585 | runtime = early_ioremap((unsigned long)efi.systab->runtime, |
| 586 | sizeof(efi_runtime_services_t)); |
Olof Johansson | 140bf27 | 2012-02-12 13:24:28 -0800 | [diff] [blame] | 587 | if (!runtime) { |
Olof Johansson | e3cb3f5 | 2012-02-12 13:24:26 -0800 | [diff] [blame] | 588 | pr_err("Could not map the runtime service table!\n"); |
Olof Johansson | 140bf27 | 2012-02-12 13:24:28 -0800 | [diff] [blame] | 589 | return -ENOMEM; |
| 590 | } |
| 591 | /* |
| 592 | * We will only need *early* access to the following |
Linus Torvalds | 11520e5 | 2012-12-15 15:15:24 -0800 | [diff] [blame] | 593 | * two EFI runtime services before set_virtual_address_map |
Olof Johansson | 140bf27 | 2012-02-12 13:24:28 -0800 | [diff] [blame] | 594 | * is invoked. |
| 595 | */ |
Linus Torvalds | 11520e5 | 2012-12-15 15:15:24 -0800 | [diff] [blame] | 596 | efi_phys.get_time = (efi_get_time_t *)runtime->get_time; |
Olof Johansson | 140bf27 | 2012-02-12 13:24:28 -0800 | [diff] [blame] | 597 | efi_phys.set_virtual_address_map = |
| 598 | (efi_set_virtual_address_map_t *) |
| 599 | runtime->set_virtual_address_map; |
Linus Torvalds | 11520e5 | 2012-12-15 15:15:24 -0800 | [diff] [blame] | 600 | /* |
| 601 | * Make efi_get_time can be called before entering |
| 602 | * virtual mode. |
| 603 | */ |
| 604 | efi.get_time = phys_efi_get_time; |
Huang, Ying | beacfaa | 2008-01-30 13:33:44 +0100 | [diff] [blame] | 605 | early_iounmap(runtime, sizeof(efi_runtime_services_t)); |
Olof Johansson | 140bf27 | 2012-02-12 13:24:28 -0800 | [diff] [blame] | 606 | |
| 607 | return 0; |
Olof Johansson | 83e7ee6 | 2012-02-12 13:24:25 -0800 | [diff] [blame] | 608 | } |
Huang, Ying | 5b83683 | 2008-01-30 13:31:19 +0100 | [diff] [blame] | 609 | |
Olof Johansson | 140bf27 | 2012-02-12 13:24:28 -0800 | [diff] [blame] | 610 | static int __init efi_memmap_init(void) |
Olof Johansson | 83e7ee6 | 2012-02-12 13:24:25 -0800 | [diff] [blame] | 611 | { |
Huang, Ying | 5b83683 | 2008-01-30 13:31:19 +0100 | [diff] [blame] | 612 | /* Map the EFI memory map */ |
Huang, Ying | beacfaa | 2008-01-30 13:33:44 +0100 | [diff] [blame] | 613 | memmap.map = early_ioremap((unsigned long)memmap.phys_map, |
| 614 | memmap.nr_map * memmap.desc_size); |
Olof Johansson | 140bf27 | 2012-02-12 13:24:28 -0800 | [diff] [blame] | 615 | if (memmap.map == NULL) { |
Olof Johansson | e3cb3f5 | 2012-02-12 13:24:26 -0800 | [diff] [blame] | 616 | pr_err("Could not map the memory map!\n"); |
Olof Johansson | 140bf27 | 2012-02-12 13:24:28 -0800 | [diff] [blame] | 617 | return -ENOMEM; |
| 618 | } |
Huang, Ying | 5b83683 | 2008-01-30 13:31:19 +0100 | [diff] [blame] | 619 | memmap.map_end = memmap.map + (memmap.nr_map * memmap.desc_size); |
Russ Anderson | 175e438 | 2008-10-02 17:32:06 -0500 | [diff] [blame] | 620 | |
Paul Jackson | 200001e | 2008-06-25 05:44:46 -0700 | [diff] [blame] | 621 | if (add_efi_memmap) |
| 622 | do_add_efi_memmap(); |
Olof Johansson | 140bf27 | 2012-02-12 13:24:28 -0800 | [diff] [blame] | 623 | |
| 624 | return 0; |
Olof Johansson | 83e7ee6 | 2012-02-12 13:24:25 -0800 | [diff] [blame] | 625 | } |
| 626 | |
| 627 | void __init efi_init(void) |
| 628 | { |
| 629 | efi_char16_t *c16; |
| 630 | char vendor[100] = "unknown"; |
| 631 | int i = 0; |
| 632 | void *tmp; |
| 633 | |
| 634 | #ifdef CONFIG_X86_32 |
Olof Johansson | 1adbfa3 | 2012-02-12 13:24:29 -0800 | [diff] [blame] | 635 | if (boot_params.efi_info.efi_systab_hi || |
| 636 | boot_params.efi_info.efi_memmap_hi) { |
| 637 | pr_info("Table located above 4GB, disabling EFI.\n"); |
Olof Johansson | 1adbfa3 | 2012-02-12 13:24:29 -0800 | [diff] [blame] | 638 | return; |
| 639 | } |
Olof Johansson | 83e7ee6 | 2012-02-12 13:24:25 -0800 | [diff] [blame] | 640 | efi_phys.systab = (efi_system_table_t *)boot_params.efi_info.efi_systab; |
| 641 | #else |
| 642 | efi_phys.systab = (efi_system_table_t *) |
Olof Johansson | 1adbfa3 | 2012-02-12 13:24:29 -0800 | [diff] [blame] | 643 | (boot_params.efi_info.efi_systab | |
| 644 | ((__u64)boot_params.efi_info.efi_systab_hi<<32)); |
Olof Johansson | 83e7ee6 | 2012-02-12 13:24:25 -0800 | [diff] [blame] | 645 | #endif |
| 646 | |
Matt Fleming | 83e6818 | 2012-11-14 09:42:35 +0000 | [diff] [blame] | 647 | if (efi_systab_init(efi_phys.systab)) |
Olof Johansson | 140bf27 | 2012-02-12 13:24:28 -0800 | [diff] [blame] | 648 | return; |
Matt Fleming | 83e6818 | 2012-11-14 09:42:35 +0000 | [diff] [blame] | 649 | |
| 650 | set_bit(EFI_SYSTEM_TABLES, &x86_efi_facility); |
Olof Johansson | 83e7ee6 | 2012-02-12 13:24:25 -0800 | [diff] [blame] | 651 | |
| 652 | /* |
| 653 | * Show what we know for posterity |
| 654 | */ |
| 655 | c16 = tmp = early_ioremap(efi.systab->fw_vendor, 2); |
| 656 | if (c16) { |
| 657 | for (i = 0; i < sizeof(vendor) - 1 && *c16; ++i) |
| 658 | vendor[i] = *c16++; |
| 659 | vendor[i] = '\0'; |
| 660 | } else |
Olof Johansson | e3cb3f5 | 2012-02-12 13:24:26 -0800 | [diff] [blame] | 661 | pr_err("Could not map the firmware vendor!\n"); |
Olof Johansson | 83e7ee6 | 2012-02-12 13:24:25 -0800 | [diff] [blame] | 662 | early_iounmap(tmp, 2); |
| 663 | |
Olof Johansson | e3cb3f5 | 2012-02-12 13:24:26 -0800 | [diff] [blame] | 664 | pr_info("EFI v%u.%.02u by %s\n", |
| 665 | efi.systab->hdr.revision >> 16, |
| 666 | efi.systab->hdr.revision & 0xffff, vendor); |
Olof Johansson | 83e7ee6 | 2012-02-12 13:24:25 -0800 | [diff] [blame] | 667 | |
Leif Lindholm | 272686b | 2013-09-05 11:34:54 +0100 | [diff] [blame^] | 668 | if (efi_config_init(arch_tables)) |
Olof Johansson | 140bf27 | 2012-02-12 13:24:28 -0800 | [diff] [blame] | 669 | return; |
Matt Fleming | 83e6818 | 2012-11-14 09:42:35 +0000 | [diff] [blame] | 670 | |
| 671 | set_bit(EFI_CONFIG_TABLES, &x86_efi_facility); |
Olof Johansson | 83e7ee6 | 2012-02-12 13:24:25 -0800 | [diff] [blame] | 672 | |
Olof Johansson | 1adbfa3 | 2012-02-12 13:24:29 -0800 | [diff] [blame] | 673 | /* |
| 674 | * Note: We currently don't support runtime services on an EFI |
| 675 | * that doesn't match the kernel 32/64-bit mode. |
| 676 | */ |
| 677 | |
Olof Johansson | 5189c2a | 2012-10-24 10:00:44 -0700 | [diff] [blame] | 678 | if (!efi_is_native()) |
Olof Johansson | 1adbfa3 | 2012-02-12 13:24:29 -0800 | [diff] [blame] | 679 | pr_info("No EFI runtime due to 32/64-bit mismatch with kernel\n"); |
Matt Fleming | 83e6818 | 2012-11-14 09:42:35 +0000 | [diff] [blame] | 680 | else { |
Matt Fleming | fb834c7 | 2013-02-20 20:36:12 +0000 | [diff] [blame] | 681 | if (disable_runtime || efi_runtime_init()) |
Matt Fleming | 83e6818 | 2012-11-14 09:42:35 +0000 | [diff] [blame] | 682 | return; |
| 683 | set_bit(EFI_RUNTIME_SERVICES, &x86_efi_facility); |
Olof Johansson | 140bf27 | 2012-02-12 13:24:28 -0800 | [diff] [blame] | 684 | } |
Olof Johansson | 83e7ee6 | 2012-02-12 13:24:25 -0800 | [diff] [blame] | 685 | |
Matt Fleming | 83e6818 | 2012-11-14 09:42:35 +0000 | [diff] [blame] | 686 | if (efi_memmap_init()) |
Olof Johansson | 140bf27 | 2012-02-12 13:24:28 -0800 | [diff] [blame] | 687 | return; |
Matt Fleming | 83e6818 | 2012-11-14 09:42:35 +0000 | [diff] [blame] | 688 | |
| 689 | set_bit(EFI_MEMMAP, &x86_efi_facility); |
| 690 | |
Linus Torvalds | 11520e5 | 2012-12-15 15:15:24 -0800 | [diff] [blame] | 691 | #ifdef CONFIG_X86_32 |
Olof Johansson | 5189c2a | 2012-10-24 10:00:44 -0700 | [diff] [blame] | 692 | if (efi_is_native()) { |
Olof Johansson | 1adbfa3 | 2012-02-12 13:24:29 -0800 | [diff] [blame] | 693 | x86_platform.get_wallclock = efi_get_time; |
| 694 | x86_platform.set_wallclock = efi_set_rtc_mmss; |
| 695 | } |
Linus Torvalds | 11520e5 | 2012-12-15 15:15:24 -0800 | [diff] [blame] | 696 | #endif |
Feng Tang | 7bd867d | 2009-09-10 10:48:56 +0800 | [diff] [blame] | 697 | |
Huang, Ying | 5b83683 | 2008-01-30 13:31:19 +0100 | [diff] [blame] | 698 | #if EFI_DEBUG |
| 699 | print_efi_memmap(); |
| 700 | #endif |
| 701 | } |
| 702 | |
Josh Triplett | 2223af3 | 2012-09-28 17:57:05 -0700 | [diff] [blame] | 703 | void __init efi_late_init(void) |
| 704 | { |
| 705 | efi_bgrt_init(); |
| 706 | } |
| 707 | |
Matthew Garrett | 9cd2b07 | 2011-05-05 15:19:43 -0400 | [diff] [blame] | 708 | void __init efi_set_executable(efi_memory_desc_t *md, bool executable) |
| 709 | { |
| 710 | u64 addr, npages; |
| 711 | |
| 712 | addr = md->virt_addr; |
| 713 | npages = md->num_pages; |
| 714 | |
| 715 | memrange_efi_to_native(&addr, &npages); |
| 716 | |
| 717 | if (executable) |
| 718 | set_memory_x(addr, npages); |
| 719 | else |
| 720 | set_memory_nx(addr, npages); |
| 721 | } |
| 722 | |
Huang, Ying | a2172e2 | 2008-01-30 13:33:55 +0100 | [diff] [blame] | 723 | static void __init runtime_code_page_mkexec(void) |
| 724 | { |
| 725 | efi_memory_desc_t *md; |
Huang, Ying | a2172e2 | 2008-01-30 13:33:55 +0100 | [diff] [blame] | 726 | void *p; |
| 727 | |
Huang, Ying | a2172e2 | 2008-01-30 13:33:55 +0100 | [diff] [blame] | 728 | /* Make EFI runtime service code area executable */ |
| 729 | for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) { |
| 730 | md = p; |
Huang, Ying | 1c083eb | 2008-02-04 16:48:06 +0100 | [diff] [blame] | 731 | |
| 732 | if (md->type != EFI_RUNTIME_SERVICES_CODE) |
| 733 | continue; |
| 734 | |
Matthew Garrett | 9cd2b07 | 2011-05-05 15:19:43 -0400 | [diff] [blame] | 735 | efi_set_executable(md, true); |
Huang, Ying | a2172e2 | 2008-01-30 13:33:55 +0100 | [diff] [blame] | 736 | } |
Huang, Ying | a2172e2 | 2008-01-30 13:33:55 +0100 | [diff] [blame] | 737 | } |
Huang, Ying | a2172e2 | 2008-01-30 13:33:55 +0100 | [diff] [blame] | 738 | |
Huang, Ying | 5b83683 | 2008-01-30 13:31:19 +0100 | [diff] [blame] | 739 | /* |
Josh Triplett | 7bc90e01 | 2012-09-28 17:56:08 -0700 | [diff] [blame] | 740 | * We can't ioremap data in EFI boot services RAM, because we've already mapped |
| 741 | * it as RAM. So, look it up in the existing EFI memory map instead. Only |
| 742 | * callable after efi_enter_virtual_mode and before efi_free_boot_services. |
| 743 | */ |
| 744 | void __iomem *efi_lookup_mapped_addr(u64 phys_addr) |
| 745 | { |
| 746 | void *p; |
| 747 | if (WARN_ON(!memmap.map)) |
| 748 | return NULL; |
| 749 | for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) { |
| 750 | efi_memory_desc_t *md = p; |
| 751 | u64 size = md->num_pages << EFI_PAGE_SHIFT; |
| 752 | u64 end = md->phys_addr + size; |
| 753 | if (!(md->attribute & EFI_MEMORY_RUNTIME) && |
| 754 | md->type != EFI_BOOT_SERVICES_CODE && |
| 755 | md->type != EFI_BOOT_SERVICES_DATA) |
| 756 | continue; |
| 757 | if (!md->virt_addr) |
| 758 | continue; |
| 759 | if (phys_addr >= md->phys_addr && phys_addr < end) { |
| 760 | phys_addr += md->virt_addr - md->phys_addr; |
| 761 | return (__force void __iomem *)(unsigned long)phys_addr; |
| 762 | } |
| 763 | } |
| 764 | return NULL; |
| 765 | } |
| 766 | |
Matt Fleming | 3e8fa26 | 2012-10-19 13:25:46 +0100 | [diff] [blame] | 767 | void efi_memory_uc(u64 addr, unsigned long size) |
| 768 | { |
| 769 | unsigned long page_shift = 1UL << EFI_PAGE_SHIFT; |
| 770 | u64 npages; |
| 771 | |
| 772 | npages = round_up(size, page_shift) / page_shift; |
| 773 | memrange_efi_to_native(&addr, &npages); |
| 774 | set_memory_uc(addr, npages); |
| 775 | } |
| 776 | |
Josh Triplett | 7bc90e01 | 2012-09-28 17:56:08 -0700 | [diff] [blame] | 777 | /* |
Huang, Ying | 5b83683 | 2008-01-30 13:31:19 +0100 | [diff] [blame] | 778 | * This function will switch the EFI runtime services to virtual mode. |
| 779 | * Essentially, look through the EFI memmap and map every region that |
| 780 | * has the runtime attribute bit set in its memory descriptor and update |
| 781 | * that memory descriptor with the virtual address obtained from ioremap(). |
| 782 | * This enables the runtime services to be called without having to |
| 783 | * thunk back into physical mode for every invocation. |
| 784 | */ |
| 785 | void __init efi_enter_virtual_mode(void) |
| 786 | { |
Matthew Garrett | 202f9d0 | 2011-05-05 15:19:44 -0400 | [diff] [blame] | 787 | efi_memory_desc_t *md, *prev_md = NULL; |
Huang, Ying | 5b83683 | 2008-01-30 13:31:19 +0100 | [diff] [blame] | 788 | efi_status_t status; |
Huang, Ying | 1c083eb | 2008-02-04 16:48:06 +0100 | [diff] [blame] | 789 | unsigned long size; |
Jacob Shin | dda56e1 | 2012-11-16 19:38:48 -0800 | [diff] [blame] | 790 | u64 end, systab, start_pfn, end_pfn; |
Matthew Garrett | 7cb00b7 | 2011-05-05 15:19:45 -0400 | [diff] [blame] | 791 | void *p, *va, *new_memmap = NULL; |
| 792 | int count = 0; |
Huang, Ying | 5b83683 | 2008-01-30 13:31:19 +0100 | [diff] [blame] | 793 | |
| 794 | efi.systab = NULL; |
Matthew Garrett | 202f9d0 | 2011-05-05 15:19:44 -0400 | [diff] [blame] | 795 | |
Olof Johansson | 1adbfa3 | 2012-02-12 13:24:29 -0800 | [diff] [blame] | 796 | /* |
| 797 | * We don't do virtual mode, since we don't do runtime services, on |
| 798 | * non-native EFI |
| 799 | */ |
| 800 | |
Olof Johansson | 5189c2a | 2012-10-24 10:00:44 -0700 | [diff] [blame] | 801 | if (!efi_is_native()) { |
Josh Triplett | 7851079 | 2012-09-28 17:55:44 -0700 | [diff] [blame] | 802 | efi_unmap_memmap(); |
| 803 | return; |
| 804 | } |
Olof Johansson | 1adbfa3 | 2012-02-12 13:24:29 -0800 | [diff] [blame] | 805 | |
Matthew Garrett | 202f9d0 | 2011-05-05 15:19:44 -0400 | [diff] [blame] | 806 | /* Merge contiguous regions of the same type and attribute */ |
| 807 | for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) { |
| 808 | u64 prev_size; |
| 809 | md = p; |
| 810 | |
| 811 | if (!prev_md) { |
| 812 | prev_md = md; |
| 813 | continue; |
| 814 | } |
| 815 | |
| 816 | if (prev_md->type != md->type || |
| 817 | prev_md->attribute != md->attribute) { |
| 818 | prev_md = md; |
| 819 | continue; |
| 820 | } |
| 821 | |
| 822 | prev_size = prev_md->num_pages << EFI_PAGE_SHIFT; |
| 823 | |
| 824 | if (md->phys_addr == (prev_md->phys_addr + prev_size)) { |
| 825 | prev_md->num_pages += md->num_pages; |
| 826 | md->type = EFI_RESERVED_TYPE; |
| 827 | md->attribute = 0; |
| 828 | continue; |
| 829 | } |
| 830 | prev_md = md; |
| 831 | } |
| 832 | |
Huang, Ying | 5b83683 | 2008-01-30 13:31:19 +0100 | [diff] [blame] | 833 | for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) { |
| 834 | md = p; |
Matthew Garrett | 916f676 | 2011-05-25 09:53:13 -0400 | [diff] [blame] | 835 | if (!(md->attribute & EFI_MEMORY_RUNTIME) && |
| 836 | md->type != EFI_BOOT_SERVICES_CODE && |
| 837 | md->type != EFI_BOOT_SERVICES_DATA) |
Huang, Ying | 5b83683 | 2008-01-30 13:31:19 +0100 | [diff] [blame] | 838 | continue; |
Huang, Ying | 1c083eb | 2008-02-04 16:48:06 +0100 | [diff] [blame] | 839 | |
| 840 | size = md->num_pages << EFI_PAGE_SHIFT; |
| 841 | end = md->phys_addr + size; |
| 842 | |
Jacob Shin | dda56e1 | 2012-11-16 19:38:48 -0800 | [diff] [blame] | 843 | start_pfn = PFN_DOWN(md->phys_addr); |
Huang Ying | dd39ecf | 2009-03-04 10:58:33 +0800 | [diff] [blame] | 844 | end_pfn = PFN_UP(end); |
Jacob Shin | dda56e1 | 2012-11-16 19:38:48 -0800 | [diff] [blame] | 845 | if (pfn_range_is_mapped(start_pfn, end_pfn)) { |
Huang, Ying | 1c083eb | 2008-02-04 16:48:06 +0100 | [diff] [blame] | 846 | va = __va(md->phys_addr); |
Matt Fleming | 3e8fa26 | 2012-10-19 13:25:46 +0100 | [diff] [blame] | 847 | |
| 848 | if (!(md->attribute & EFI_MEMORY_WB)) |
| 849 | efi_memory_uc((u64)(unsigned long)va, size); |
| 850 | } else |
| 851 | va = efi_ioremap(md->phys_addr, size, |
| 852 | md->type, md->attribute); |
Huang, Ying | 1c083eb | 2008-02-04 16:48:06 +0100 | [diff] [blame] | 853 | |
Huang, Ying | 1c083eb | 2008-02-04 16:48:06 +0100 | [diff] [blame] | 854 | md->virt_addr = (u64) (unsigned long) va; |
| 855 | |
| 856 | if (!va) { |
Olof Johansson | e3cb3f5 | 2012-02-12 13:24:26 -0800 | [diff] [blame] | 857 | pr_err("ioremap of 0x%llX failed!\n", |
Huang, Ying | 5b83683 | 2008-01-30 13:31:19 +0100 | [diff] [blame] | 858 | (unsigned long long)md->phys_addr); |
Huang, Ying | 1c083eb | 2008-02-04 16:48:06 +0100 | [diff] [blame] | 859 | continue; |
| 860 | } |
| 861 | |
| 862 | systab = (u64) (unsigned long) efi_phys.systab; |
| 863 | if (md->phys_addr <= systab && systab < end) { |
| 864 | systab += md->virt_addr - md->phys_addr; |
| 865 | efi.systab = (efi_system_table_t *) (unsigned long) systab; |
| 866 | } |
Matthew Garrett | 7cb00b7 | 2011-05-05 15:19:45 -0400 | [diff] [blame] | 867 | new_memmap = krealloc(new_memmap, |
| 868 | (count + 1) * memmap.desc_size, |
| 869 | GFP_KERNEL); |
| 870 | memcpy(new_memmap + (count * memmap.desc_size), md, |
| 871 | memmap.desc_size); |
| 872 | count++; |
Huang, Ying | 5b83683 | 2008-01-30 13:31:19 +0100 | [diff] [blame] | 873 | } |
| 874 | |
| 875 | BUG_ON(!efi.systab); |
| 876 | |
| 877 | status = phys_efi_set_virtual_address_map( |
Matthew Garrett | 7cb00b7 | 2011-05-05 15:19:45 -0400 | [diff] [blame] | 878 | memmap.desc_size * count, |
Huang, Ying | 5b83683 | 2008-01-30 13:31:19 +0100 | [diff] [blame] | 879 | memmap.desc_size, |
| 880 | memmap.desc_version, |
Matthew Garrett | 7cb00b7 | 2011-05-05 15:19:45 -0400 | [diff] [blame] | 881 | (efi_memory_desc_t *)__pa(new_memmap)); |
Huang, Ying | 5b83683 | 2008-01-30 13:31:19 +0100 | [diff] [blame] | 882 | |
| 883 | if (status != EFI_SUCCESS) { |
Olof Johansson | e3cb3f5 | 2012-02-12 13:24:26 -0800 | [diff] [blame] | 884 | pr_alert("Unable to switch EFI into virtual mode " |
| 885 | "(status=%lx)!\n", status); |
Huang, Ying | 5b83683 | 2008-01-30 13:31:19 +0100 | [diff] [blame] | 886 | panic("EFI call to SetVirtualAddressMap() failed!"); |
| 887 | } |
| 888 | |
| 889 | /* |
| 890 | * Now that EFI is in virtual mode, update the function |
| 891 | * pointers in the runtime service table to the new virtual addresses. |
| 892 | * |
| 893 | * Call EFI services through wrapper functions. |
| 894 | */ |
Matt Fleming | 712ba9e | 2013-01-25 10:07:25 +0000 | [diff] [blame] | 895 | efi.runtime_version = efi_systab.hdr.revision; |
Huang, Ying | 5b83683 | 2008-01-30 13:31:19 +0100 | [diff] [blame] | 896 | efi.get_time = virt_efi_get_time; |
| 897 | efi.set_time = virt_efi_set_time; |
| 898 | efi.get_wakeup_time = virt_efi_get_wakeup_time; |
| 899 | efi.set_wakeup_time = virt_efi_set_wakeup_time; |
| 900 | efi.get_variable = virt_efi_get_variable; |
| 901 | efi.get_next_variable = virt_efi_get_next_variable; |
| 902 | efi.set_variable = virt_efi_set_variable; |
| 903 | efi.get_next_high_mono_count = virt_efi_get_next_high_mono_count; |
| 904 | efi.reset_system = virt_efi_reset_system; |
Matthew Garrett | 2b5e8ef | 2011-05-05 15:19:42 -0400 | [diff] [blame] | 905 | efi.set_virtual_address_map = NULL; |
Matthew Garrett | 3b37023 | 2011-06-06 15:36:25 -0400 | [diff] [blame] | 906 | efi.query_variable_info = virt_efi_query_variable_info; |
| 907 | efi.update_capsule = virt_efi_update_capsule; |
| 908 | efi.query_capsule_caps = virt_efi_query_capsule_caps; |
Huang, Ying | 4de0d4a | 2008-02-13 17:22:41 +0800 | [diff] [blame] | 909 | if (__supported_pte_mask & _PAGE_NX) |
| 910 | runtime_code_page_mkexec(); |
Olof Johansson | 1adbfa3 | 2012-02-12 13:24:29 -0800 | [diff] [blame] | 911 | |
Matthew Garrett | 7cb00b7 | 2011-05-05 15:19:45 -0400 | [diff] [blame] | 912 | kfree(new_memmap); |
Matthew Garrett | f8b8404 | 2013-06-01 16:06:20 -0400 | [diff] [blame] | 913 | |
| 914 | /* clean DUMMY object */ |
| 915 | efi.set_variable(efi_dummy_name, &EFI_DUMMY_GUID, |
| 916 | EFI_VARIABLE_NON_VOLATILE | |
| 917 | EFI_VARIABLE_BOOTSERVICE_ACCESS | |
| 918 | EFI_VARIABLE_RUNTIME_ACCESS, |
| 919 | 0, NULL); |
Huang, Ying | 5b83683 | 2008-01-30 13:31:19 +0100 | [diff] [blame] | 920 | } |
| 921 | |
| 922 | /* |
| 923 | * Convenience functions to obtain memory types and attributes |
| 924 | */ |
| 925 | u32 efi_mem_type(unsigned long phys_addr) |
| 926 | { |
| 927 | efi_memory_desc_t *md; |
| 928 | void *p; |
| 929 | |
Matt Fleming | 83e6818 | 2012-11-14 09:42:35 +0000 | [diff] [blame] | 930 | if (!efi_enabled(EFI_MEMMAP)) |
| 931 | return 0; |
| 932 | |
Huang, Ying | 5b83683 | 2008-01-30 13:31:19 +0100 | [diff] [blame] | 933 | for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) { |
| 934 | md = p; |
| 935 | if ((md->phys_addr <= phys_addr) && |
| 936 | (phys_addr < (md->phys_addr + |
| 937 | (md->num_pages << EFI_PAGE_SHIFT)))) |
| 938 | return md->type; |
| 939 | } |
| 940 | return 0; |
| 941 | } |
| 942 | |
| 943 | u64 efi_mem_attributes(unsigned long phys_addr) |
| 944 | { |
| 945 | efi_memory_desc_t *md; |
| 946 | void *p; |
| 947 | |
| 948 | for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) { |
| 949 | md = p; |
| 950 | if ((md->phys_addr <= phys_addr) && |
| 951 | (phys_addr < (md->phys_addr + |
| 952 | (md->num_pages << EFI_PAGE_SHIFT)))) |
| 953 | return md->attribute; |
| 954 | } |
| 955 | return 0; |
| 956 | } |
Matt Fleming | a6e4d5a | 2013-03-25 09:14:30 +0000 | [diff] [blame] | 957 | |
| 958 | /* |
| 959 | * Some firmware has serious problems when using more than 50% of the EFI |
| 960 | * variable store, i.e. it triggers bugs that can brick machines. Ensure that |
| 961 | * we never use more than this safe limit. |
| 962 | * |
| 963 | * Return EFI_SUCCESS if it is safe to write 'size' bytes to the variable |
| 964 | * store. |
| 965 | */ |
| 966 | efi_status_t efi_query_variable_store(u32 attributes, unsigned long size) |
| 967 | { |
| 968 | efi_status_t status; |
| 969 | u64 storage_size, remaining_size, max_size; |
| 970 | |
Matthew Garrett | f8b8404 | 2013-06-01 16:06:20 -0400 | [diff] [blame] | 971 | if (!(attributes & EFI_VARIABLE_NON_VOLATILE)) |
| 972 | return 0; |
| 973 | |
Matt Fleming | a6e4d5a | 2013-03-25 09:14:30 +0000 | [diff] [blame] | 974 | status = efi.query_variable_info(attributes, &storage_size, |
| 975 | &remaining_size, &max_size); |
| 976 | if (status != EFI_SUCCESS) |
| 977 | return status; |
| 978 | |
Matthew Garrett | 31ff2f2 | 2013-04-15 13:09:47 -0700 | [diff] [blame] | 979 | /* |
| 980 | * Some firmware implementations refuse to boot if there's insufficient |
| 981 | * space in the variable store. We account for that by refusing the |
| 982 | * write if permitting it would reduce the available space to under |
Matthew Garrett | f8b8404 | 2013-06-01 16:06:20 -0400 | [diff] [blame] | 983 | * 5KB. This figure was provided by Samsung, so should be safe. |
Matthew Garrett | 31ff2f2 | 2013-04-15 13:09:47 -0700 | [diff] [blame] | 984 | */ |
Matthew Garrett | f8b8404 | 2013-06-01 16:06:20 -0400 | [diff] [blame] | 985 | if ((remaining_size - size < EFI_MIN_RESERVE) && |
| 986 | !efi_no_storage_paranoia) { |
Richard Weinberger | 7791c84 | 2013-04-10 10:59:34 +0200 | [diff] [blame] | 987 | |
Matthew Garrett | f8b8404 | 2013-06-01 16:06:20 -0400 | [diff] [blame] | 988 | /* |
| 989 | * Triggering garbage collection may require that the firmware |
| 990 | * generate a real EFI_OUT_OF_RESOURCES error. We can force |
| 991 | * that by attempting to use more space than is available. |
| 992 | */ |
| 993 | unsigned long dummy_size = remaining_size + 1024; |
Ben Hutchings | b8cb62f | 2013-06-16 21:27:12 +0100 | [diff] [blame] | 994 | void *dummy = kzalloc(dummy_size, GFP_ATOMIC); |
| 995 | |
| 996 | if (!dummy) |
| 997 | return EFI_OUT_OF_RESOURCES; |
Richard Weinberger | 8c58bf3 | 2013-04-17 01:00:53 +0200 | [diff] [blame] | 998 | |
Matthew Garrett | f8b8404 | 2013-06-01 16:06:20 -0400 | [diff] [blame] | 999 | status = efi.set_variable(efi_dummy_name, &EFI_DUMMY_GUID, |
| 1000 | EFI_VARIABLE_NON_VOLATILE | |
| 1001 | EFI_VARIABLE_BOOTSERVICE_ACCESS | |
| 1002 | EFI_VARIABLE_RUNTIME_ACCESS, |
| 1003 | dummy_size, dummy); |
| 1004 | |
| 1005 | if (status == EFI_SUCCESS) { |
| 1006 | /* |
| 1007 | * This should have failed, so if it didn't make sure |
| 1008 | * that we delete it... |
| 1009 | */ |
| 1010 | efi.set_variable(efi_dummy_name, &EFI_DUMMY_GUID, |
| 1011 | EFI_VARIABLE_NON_VOLATILE | |
| 1012 | EFI_VARIABLE_BOOTSERVICE_ACCESS | |
| 1013 | EFI_VARIABLE_RUNTIME_ACCESS, |
| 1014 | 0, dummy); |
| 1015 | } |
| 1016 | |
Ben Hutchings | b8cb62f | 2013-06-16 21:27:12 +0100 | [diff] [blame] | 1017 | kfree(dummy); |
| 1018 | |
Matthew Garrett | f8b8404 | 2013-06-01 16:06:20 -0400 | [diff] [blame] | 1019 | /* |
| 1020 | * The runtime code may now have triggered a garbage collection |
| 1021 | * run, so check the variable info again |
| 1022 | */ |
| 1023 | status = efi.query_variable_info(attributes, &storage_size, |
| 1024 | &remaining_size, &max_size); |
| 1025 | |
| 1026 | if (status != EFI_SUCCESS) |
| 1027 | return status; |
| 1028 | |
| 1029 | /* |
| 1030 | * There still isn't enough room, so return an error |
| 1031 | */ |
| 1032 | if (remaining_size - size < EFI_MIN_RESERVE) |
| 1033 | return EFI_OUT_OF_RESOURCES; |
| 1034 | } |
Matt Fleming | a6e4d5a | 2013-03-25 09:14:30 +0000 | [diff] [blame] | 1035 | |
| 1036 | return EFI_SUCCESS; |
| 1037 | } |
Sergey Vlasov | 3668011 | 2013-04-16 18:31:09 +0400 | [diff] [blame] | 1038 | EXPORT_SYMBOL_GPL(efi_query_variable_store); |