aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArd Biesheuvel <ard.biesheuvel@linaro.org>2014-10-20 10:35:21 -0400
committerArd Biesheuvel <ard.biesheuvel@linaro.org>2015-01-12 11:29:31 -0500
commit3033b84596eaec0093b68c5711c265738eb0745d (patch)
treede81428f18201237aa8ce105821e57a127e2b9c9
parentf3cdfd239da56a4cea75a2920dc326f0f45f67e3 (diff)
arm64/efi: remove free_boot_services() and friends
Now that we are calling SetVirtualAddressMap() from the stub, there is no need to reserve boot-only memory regions, which implies that there is also no reason to free them again later. Acked-by: Leif Lindholm <leif.lindholm@linaro.org> Acked-by: Will Deacon <will.deacon@arm.com> Tested-by: Leif Lindholm <leif.lindholm@linaro.org> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
-rw-r--r--arch/arm64/kernel/efi.c123
1 files changed, 1 insertions, 122 deletions
diff --git a/arch/arm64/kernel/efi.c b/arch/arm64/kernel/efi.c
index 755e545144ea..4a5d7343dddd 100644
--- a/arch/arm64/kernel/efi.c
+++ b/arch/arm64/kernel/efi.c
@@ -199,9 +199,7 @@ static __init void reserve_regions(void)
199 if (is_normal_ram(md)) 199 if (is_normal_ram(md))
200 early_init_dt_add_memory_arch(paddr, size); 200 early_init_dt_add_memory_arch(paddr, size);
201 201
202 if (is_reserve_region(md) || 202 if (is_reserve_region(md)) {
203 md->type == EFI_BOOT_SERVICES_CODE ||
204 md->type == EFI_BOOT_SERVICES_DATA) {
205 memblock_reserve(paddr, size); 203 memblock_reserve(paddr, size);
206 if (uefi_debug) 204 if (uefi_debug)
207 pr_cont("*"); 205 pr_cont("*");
@@ -214,123 +212,6 @@ static __init void reserve_regions(void)
214 set_bit(EFI_MEMMAP, &efi.flags); 212 set_bit(EFI_MEMMAP, &efi.flags);
215} 213}
216 214
217
218static u64 __init free_one_region(u64 start, u64 end)
219{
220 u64 size = end - start;
221
222 if (uefi_debug)
223 pr_info(" EFI freeing: 0x%012llx-0x%012llx\n", start, end - 1);
224
225 free_bootmem_late(start, size);
226 return size;
227}
228
229static u64 __init free_region(u64 start, u64 end)
230{
231 u64 map_start, map_end, total = 0;
232
233 if (end <= start)
234 return total;
235
236 map_start = (u64)memmap.phys_map;
237 map_end = PAGE_ALIGN(map_start + (memmap.map_end - memmap.map));
238 map_start &= PAGE_MASK;
239
240 if (start < map_end && end > map_start) {
241 /* region overlaps UEFI memmap */
242 if (start < map_start)
243 total += free_one_region(start, map_start);
244
245 if (map_end < end)
246 total += free_one_region(map_end, end);
247 } else
248 total += free_one_region(start, end);
249
250 return total;
251}
252
253static void __init free_boot_services(void)
254{
255 u64 total_freed = 0;
256 u64 keep_end, free_start, free_end;
257 efi_memory_desc_t *md;
258
259 /*
260 * If kernel uses larger pages than UEFI, we have to be careful
261 * not to inadvertantly free memory we want to keep if there is
262 * overlap at the kernel page size alignment. We do not want to
263 * free is_reserve_region() memory nor the UEFI memmap itself.
264 *
265 * The memory map is sorted, so we keep track of the end of
266 * any previous region we want to keep, remember any region
267 * we want to free and defer freeing it until we encounter
268 * the next region we want to keep. This way, before freeing
269 * it, we can clip it as needed to avoid freeing memory we
270 * want to keep for UEFI.
271 */
272
273 keep_end = 0;
274 free_start = 0;
275
276 for_each_efi_memory_desc(&memmap, md) {
277 u64 paddr, npages, size;
278
279 if (is_reserve_region(md)) {
280 /*
281 * We don't want to free any memory from this region.
282 */
283 if (free_start) {
284 /* adjust free_end then free region */
285 if (free_end > md->phys_addr)
286 free_end -= PAGE_SIZE;
287 total_freed += free_region(free_start, free_end);
288 free_start = 0;
289 }
290 keep_end = md->phys_addr + (md->num_pages << EFI_PAGE_SHIFT);
291 continue;
292 }
293
294 if (md->type != EFI_BOOT_SERVICES_CODE &&
295 md->type != EFI_BOOT_SERVICES_DATA) {
296 /* no need to free this region */
297 continue;
298 }
299
300 /*
301 * We want to free memory from this region.
302 */
303 paddr = md->phys_addr;
304 npages = md->num_pages;
305 memrange_efi_to_native(&paddr, &npages);
306 size = npages << PAGE_SHIFT;
307
308 if (free_start) {
309 if (paddr <= free_end)
310 free_end = paddr + size;
311 else {
312 total_freed += free_region(free_start, free_end);
313 free_start = paddr;
314 free_end = paddr + size;
315 }
316 } else {
317 free_start = paddr;
318 free_end = paddr + size;
319 }
320 if (free_start < keep_end) {
321 free_start += PAGE_SIZE;
322 if (free_start >= free_end)
323 free_start = 0;
324 }
325 }
326 if (free_start)
327 total_freed += free_region(free_start, free_end);
328
329 if (total_freed)
330 pr_info("Freed 0x%llx bytes of EFI boot services memory",
331 total_freed);
332}
333
334void __init efi_init(void) 215void __init efi_init(void)
335{ 216{
336 struct efi_fdt_params params; 217 struct efi_fdt_params params;
@@ -402,8 +283,6 @@ static int __init arm64_enable_runtime_services(void)
402 } 283 }
403 set_bit(EFI_SYSTEM_TABLES, &efi.flags); 284 set_bit(EFI_SYSTEM_TABLES, &efi.flags);
404 285
405 free_boot_services();
406
407 if (!efi_enabled(EFI_VIRTMAP)) { 286 if (!efi_enabled(EFI_VIRTMAP)) {
408 pr_err("No UEFI virtual mapping was installed -- runtime services will not be available\n"); 287 pr_err("No UEFI virtual mapping was installed -- runtime services will not be available\n");
409 return -1; 288 return -1;