Commit 80e80a70 authored by Marek Marczykowski-Górecki's avatar Marek Marczykowski-Górecki Committed by Ard Biesheuvel
Browse files

efi: make efi_mem_type() and efi_mem_attributes() work on Xen PV



Xen doesn't give direct access to the EFI memory map, but provides a
hypercall interface for it. efi_mem_desc_lookup() was already adjusted
in aca1d27a "efi: xen: Implement memory descriptor lookup based on
hypercall" to (optionally) use it. Now make efi_mem_type() and
efi_mem_attributes() use common efi_mem_desc_lookup() too.
This also reduces code duplication a bit.
efi_mem_type() retains separate check for -ENOTSUPP error case (even
though no caller seems to rely on this currently).

Signed-off-by: default avatarMarek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
[ardb: Drop erroneous 'const' qualifier]
Signed-off-by: default avatarArd Biesheuvel <ardb@kernel.org>
parent 1f318b96
Loading
Loading
Loading
Loading
+9 −18
Original line number Diff line number Diff line
@@ -983,18 +983,12 @@ char * __init efi_md_typeattr_format(char *buf, size_t size,
 */
u64 efi_mem_attributes(unsigned long phys_addr)
{
	efi_memory_desc_t *md;
	efi_memory_desc_t md;

	if (!efi_enabled(EFI_MEMMAP))
	if (efi_mem_desc_lookup(phys_addr, &md))
		return 0;

	for_each_efi_memory_desc(md) {
		if ((md->phys_addr <= phys_addr) &&
		    (phys_addr < (md->phys_addr +
		    (md->num_pages << EFI_PAGE_SHIFT))))
			return md->attribute;
	}
	return 0;
	return md.attribute;
}

/*
@@ -1007,18 +1001,15 @@ u64 efi_mem_attributes(unsigned long phys_addr)
 */
int efi_mem_type(unsigned long phys_addr)
{
	const efi_memory_desc_t *md;
	efi_memory_desc_t md;

	if (!efi_enabled(EFI_MEMMAP))
	if (!efi_enabled(EFI_MEMMAP) && !efi_enabled(EFI_PARAVIRT))
		return -ENOTSUPP;

	for_each_efi_memory_desc(md) {
		if ((md->phys_addr <= phys_addr) &&
		    (phys_addr < (md->phys_addr +
				  (md->num_pages << EFI_PAGE_SHIFT))))
			return md->type;
	}
	if (efi_mem_desc_lookup(phys_addr, &md))
		return -EINVAL;

	return md.type;
}

int efi_status_to_err(efi_status_t status)