Skip to content

Commit 80e80a7

Browse files
marmarekardbiesheuvel
authored andcommitted
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 aca1d27 "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: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com> [ardb: Drop erroneous 'const' qualifier] Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
1 parent 1f318b9 commit 80e80a7

1 file changed

Lines changed: 9 additions & 18 deletions

File tree

  • drivers/firmware/efi

drivers/firmware/efi/efi.c

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -983,18 +983,12 @@ char * __init efi_md_typeattr_format(char *buf, size_t size,
983983
*/
984984
u64 efi_mem_attributes(unsigned long phys_addr)
985985
{
986-
efi_memory_desc_t *md;
986+
efi_memory_desc_t md;
987987

988-
if (!efi_enabled(EFI_MEMMAP))
988+
if (efi_mem_desc_lookup(phys_addr, &md))
989989
return 0;
990990

991-
for_each_efi_memory_desc(md) {
992-
if ((md->phys_addr <= phys_addr) &&
993-
(phys_addr < (md->phys_addr +
994-
(md->num_pages << EFI_PAGE_SHIFT))))
995-
return md->attribute;
996-
}
997-
return 0;
991+
return md.attribute;
998992
}
999993

1000994
/*
@@ -1007,18 +1001,15 @@ u64 efi_mem_attributes(unsigned long phys_addr)
10071001
*/
10081002
int efi_mem_type(unsigned long phys_addr)
10091003
{
1010-
const efi_memory_desc_t *md;
1004+
efi_memory_desc_t md;
10111005

1012-
if (!efi_enabled(EFI_MEMMAP))
1006+
if (!efi_enabled(EFI_MEMMAP) && !efi_enabled(EFI_PARAVIRT))
10131007
return -ENOTSUPP;
10141008

1015-
for_each_efi_memory_desc(md) {
1016-
if ((md->phys_addr <= phys_addr) &&
1017-
(phys_addr < (md->phys_addr +
1018-
(md->num_pages << EFI_PAGE_SHIFT))))
1019-
return md->type;
1020-
}
1021-
return -EINVAL;
1009+
if (efi_mem_desc_lookup(phys_addr, &md))
1010+
return -EINVAL;
1011+
1012+
return md.type;
10221013
}
10231014

10241015
int efi_status_to_err(efi_status_t status)

0 commit comments

Comments
 (0)