Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 02e43c2d authored by Baoquan He's avatar Baoquan He Committed by Ingo Molnar
Browse files

efi: Introduce efi_early_memdesc_ptr to get pointer to memmap descriptor



The existing map iteration helper for_each_efi_memory_desc_in_map can
only be used after the kernel initializes the EFI subsystem to set up
struct efi_memory_map.

Before that we also need iterate map descriptors which are stored in several
intermediate structures, like struct efi_boot_memmap for arch independent
usage and struct efi_info for x86 arch only.

Introduce efi_early_memdesc_ptr() to get pointer to a map descriptor, and
replace several places where that primitive is open coded.

Signed-off-by: default avatarBaoquan He <bhe@redhat.com>
[ Various improvements to the text. ]
Acked-by: default avatarMatt Fleming <matt@codeblueprint.co.uk>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: ard.biesheuvel@linaro.org
Cc: fanc.fnst@cn.fujitsu.com
Cc: izumi.taku@jp.fujitsu.com
Cc: keescook@chromium.org
Cc: linux-efi@vger.kernel.org
Cc: n-horiguchi@ah.jp.nec.com
Cc: thgarnie@google.com
Link: http://lkml.kernel.org/r/20170816134651.GF21273@x1


Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
parent 2257e268
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -767,7 +767,7 @@ static efi_status_t setup_e820(struct boot_params *params,
		m |= (u64)efi->efi_memmap_hi << 32;
		m |= (u64)efi->efi_memmap_hi << 32;
#endif
#endif


		d = (efi_memory_desc_t *)(m + (i * efi->efi_memdesc_size));
		d = efi_early_memdesc_ptr(m, efi->efi_memdesc_size, i);
		switch (d->type) {
		switch (d->type) {
		case EFI_RESERVED_TYPE:
		case EFI_RESERVED_TYPE:
		case EFI_RUNTIME_SERVICES_CODE:
		case EFI_RUNTIME_SERVICES_CODE:
+2 −2
Original line number Original line Diff line number Diff line
@@ -205,7 +205,7 @@ efi_status_t efi_high_alloc(efi_system_table_t *sys_table_arg,
		unsigned long m = (unsigned long)map;
		unsigned long m = (unsigned long)map;
		u64 start, end;
		u64 start, end;


		desc = (efi_memory_desc_t *)(m + (i * desc_size));
		desc = efi_early_memdesc_ptr(m, desc_size, i);
		if (desc->type != EFI_CONVENTIONAL_MEMORY)
		if (desc->type != EFI_CONVENTIONAL_MEMORY)
			continue;
			continue;


@@ -298,7 +298,7 @@ efi_status_t efi_low_alloc(efi_system_table_t *sys_table_arg,
		unsigned long m = (unsigned long)map;
		unsigned long m = (unsigned long)map;
		u64 start, end;
		u64 start, end;


		desc = (efi_memory_desc_t *)(m + (i * desc_size));
		desc = efi_early_memdesc_ptr(m, desc_size, i);


		if (desc->type != EFI_CONVENTIONAL_MEMORY)
		if (desc->type != EFI_CONVENTIONAL_MEMORY)
			continue;
			continue;
+22 −0
Original line number Original line Diff line number Diff line
@@ -1020,6 +1020,28 @@ extern int efi_memattr_init(void);
extern int efi_memattr_apply_permissions(struct mm_struct *mm,
extern int efi_memattr_apply_permissions(struct mm_struct *mm,
					 efi_memattr_perm_setter fn);
					 efi_memattr_perm_setter fn);


/*
 * efi_early_memdesc_ptr - get the n-th EFI memmap descriptor
 * @map: the start of efi memmap
 * @desc_size: the size of space for each EFI memmap descriptor
 * @n: the index of efi memmap descriptor
 *
 * EFI boot service provides the GetMemoryMap() function to get a copy of the
 * current memory map which is an array of memory descriptors, each of
 * which describes a contiguous block of memory. It also gets the size of the
 * map, and the size of each descriptor, etc.
 *
 * Note that per section 6.2 of UEFI Spec 2.6 Errata A, the returned size of
 * each descriptor might not be equal to sizeof(efi_memory_memdesc_t),
 * since efi_memory_memdesc_t may be extended in the future. Thus the OS
 * MUST use the returned size of the descriptor to find the start of each
 * efi_memory_memdesc_t in the memory map array. This should only be used
 * during bootup since for_each_efi_memory_desc_xxx() is available after the
 * kernel initializes the EFI subsystem to set up struct efi_memory_map.
 */
#define efi_early_memdesc_ptr(map, desc_size, n)			\
	(efi_memory_desc_t *)((void *)(map) + ((n) * (desc_size)))

/* Iterate through an efi_memory_map */
/* Iterate through an efi_memory_map */
#define for_each_efi_memory_desc_in_map(m, md)				   \
#define for_each_efi_memory_desc_in_map(m, md)				   \
	for ((md) = (m)->map;						   \
	for ((md) = (m)->map;						   \