1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright(c) 2019 Intel Corporation. All rights reserved. */
4 #include <asm/e820/api.h>
7 void __init
efi_fake_memmap_early(void)
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())
18 if (!efi_enabled(EFI_MEMMAP
) || !nr_fake_mem
)
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
;
35 if ((mem
->attribute
& EFI_MEMORY_SP
) == 0)
38 m_start
= mem
->range
.start
;
39 m_end
= mem
->range
.end
;
40 for_each_efi_memory_desc(md
) {
43 if (md
->type
!= EFI_CONVENTIONAL_MEMORY
)
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 */;
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
);
64 e820__range_update(start
, end
- start
+ 1, E820_TYPE_RAM
,
65 E820_TYPE_SOFT_RESERVED
);
66 e820__update_table(e820_table
);