Skip to content

Commit 1ca854a

Browse files
committed
efi: Add efi_memmap_install() for installing new EFI memory maps
While efi_memmap_init_{early,late}() exist for architecture code to install memory maps from firmware data and for the virtual memory regions respectively, drivers don't care which stage of the boot we're at and just want to swap the existing memmap for a modified one. efi_memmap_install() abstracts the details of how the new memory map should be mapped and the existing one unmapped. Tested-by: Dave Young <dyoung@redhat.com> [kexec/kdump] Tested-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> [arm] Acked-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> Cc: Leif Lindholm <leif.lindholm@linaro.org> Cc: Peter Jones <pjones@redhat.com> Cc: Borislav Petkov <bp@alien8.de> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Taku Izumi <izumi.taku@jp.fujitsu.com> Signed-off-by: Matt Fleming <matt@codeblueprint.co.uk>
1 parent 7014d47 commit 1ca854a

File tree

3 files changed

+27
-7
lines changed

3 files changed

+27
-7
lines changed

drivers/firmware/efi/fake_mem.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ static int __init cmp_fake_mem(const void *x1, const void *x2)
5252

5353
void __init efi_fake_memmap(void)
5454
{
55-
struct efi_memory_map_data data;
5655
int new_nr_map = efi.memmap.nr_map;
5756
efi_memory_desc_t *md;
5857
phys_addr_t new_memmap_phy;
@@ -90,13 +89,8 @@ void __init efi_fake_memmap(void)
9089

9190
/* swap into new EFI memmap */
9291
early_memunmap(new_memmap, efi.memmap.desc_size * new_nr_map);
93-
efi_memmap_unmap();
9492

95-
data.phys_map = new_memmap_phy;
96-
data.size = efi.memmap.desc_size * new_nr_map;
97-
data.desc_version = efi.memmap.desc_version;
98-
data.desc_size = efi.memmap.desc_size;
99-
efi_memmap_init_early(&data);
93+
efi_memmap_install(new_memmap_phy, new_nr_map);
10094

10195
/* print new EFI memmap */
10296
efi_print_memmap();

drivers/firmware/efi/memmap.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,31 @@ int __init efi_memmap_init_late(phys_addr_t addr, unsigned long size)
139139
return __efi_memmap_init(&data, true);
140140
}
141141

142+
/**
143+
* efi_memmap_install - Install a new EFI memory map in efi.memmap
144+
* @addr: Physical address of the memory map
145+
* @nr_map: Number of entries in the memory map
146+
*
147+
* Unlike efi_memmap_init_*(), this function does not allow the caller
148+
* to switch from early to late mappings. It simply uses the existing
149+
* mapping function and installs the new memmap.
150+
*
151+
* Returns zero on success, a negative error code on failure.
152+
*/
153+
int __init efi_memmap_install(phys_addr_t addr, unsigned int nr_map)
154+
{
155+
struct efi_memory_map_data data;
156+
157+
efi_memmap_unmap();
158+
159+
data.phys_map = addr;
160+
data.size = efi.memmap.desc_size * nr_map;
161+
data.desc_version = efi.memmap.desc_version;
162+
data.desc_size = efi.memmap.desc_size;
163+
164+
return __efi_memmap_init(&data, efi.memmap.late);
165+
}
166+
142167
/**
143168
* efi_memmap_split_count - Count number of additional EFI memmap entries
144169
* @md: EFI memory descriptor to split

include/linux/efi.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -923,6 +923,7 @@ extern void __iomem *efi_lookup_mapped_addr(u64 phys_addr);
923923
extern int __init efi_memmap_init_early(struct efi_memory_map_data *data);
924924
extern int __init efi_memmap_init_late(phys_addr_t addr, unsigned long size);
925925
extern void __init efi_memmap_unmap(void);
926+
extern int __init efi_memmap_install(phys_addr_t addr, unsigned int nr_map);
926927
extern int __init efi_memmap_split_count(efi_memory_desc_t *md,
927928
struct range *range);
928929
extern void __init efi_memmap_insert(struct efi_memory_map *old_memmap,

0 commit comments

Comments
 (0)