[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 1/2] 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 aca1d27ac38a "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@xxxxxxxxxxxxxxxxxxxxxx>
---
 drivers/firmware/efi/efi.c | 27 +++++++++------------------
 1 file changed, 9 insertions(+), 18 deletions(-)

diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
index b2fb92a..36efc92 100644
--- a/drivers/firmware/efi/efi.c
+++ b/drivers/firmware/efi/efi.c
@@ -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;
+       const 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;
-       }
-       return -EINVAL;
+       if (efi_mem_desc_lookup(phys_addr, &md))
+               return -EINVAL;
+
+       return md.type;
 }
 
 int efi_status_to_err(efi_status_t status)
-- 
git-series 0.9.1



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.