staging: most: configfs: use strlcpy
[linux/fpc-iii.git] / drivers / firmware / efi / x86_fake_mem.c
blobe5d6d5a1b2401ce39c6fa5a94279e1aa6c6172a2
1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright(c) 2019 Intel Corporation. All rights reserved. */
3 #include <linux/efi.h>
4 #include <asm/e820/api.h>
5 #include "fake_mem.h"
7 void __init efi_fake_memmap_early(void)
9 int i;
12 * The late efi_fake_mem() call can handle all requests if
13 * EFI_MEMORY_SP support is disabled.
15 if (!efi_soft_reserve_enabled())
16 return;
18 if (!efi_enabled(EFI_MEMMAP) || !nr_fake_mem)
19 return;
22 * Given that efi_fake_memmap() needs to perform memblock
23 * allocations it needs to run after e820__memblock_setup().
24 * However, if efi_fake_mem specifies EFI_MEMORY_SP for a given
25 * address range that potentially needs to mark the memory as
26 * reserved prior to e820__memblock_setup(). Update e820
27 * directly if EFI_MEMORY_SP is specified for an
28 * EFI_CONVENTIONAL_MEMORY descriptor.
30 for (i = 0; i < nr_fake_mem; i++) {
31 struct efi_mem_range *mem = &efi_fake_mems[i];
32 efi_memory_desc_t *md;
33 u64 m_start, m_end;
35 if ((mem->attribute & EFI_MEMORY_SP) == 0)
36 continue;
38 m_start = mem->range.start;
39 m_end = mem->range.end;
40 for_each_efi_memory_desc(md) {
41 u64 start, end;
43 if (md->type != EFI_CONVENTIONAL_MEMORY)
44 continue;
46 start = md->phys_addr;
47 end = md->phys_addr + (md->num_pages << EFI_PAGE_SHIFT) - 1;
49 if (m_start <= end && m_end >= start)
50 /* fake range overlaps descriptor */;
51 else
52 continue;
55 * Trim the boundary of the e820 update to the
56 * descriptor in case the fake range overlaps
57 * !EFI_CONVENTIONAL_MEMORY
59 start = max(start, m_start);
60 end = min(end, m_end);
62 if (end <= start)
63 continue;
64 e820__range_update(start, end - start + 1, E820_TYPE_RAM,
65 E820_TYPE_SOFT_RESERVED);
66 e820__update_table(e820_table);