]> xenbits.xensource.com Git - people/pauldu/xen.git/commitdiff
xen/acpi: Rework acpi_os_map_memory() and acpi_os_unmap_memory()
authorJulien Grall <jgrall@amazon.com>
Sat, 26 Sep 2020 16:44:29 +0000 (17:44 +0100)
committerJulien Grall <jgrall@amazon.com>
Fri, 30 Oct 2020 18:17:34 +0000 (18:17 +0000)
The functions acpi_os_{un,}map_memory() are meant to be arch-agnostic
while the __acpi_os_{un,}map_memory() are meant to be arch-specific.

Currently, the former are still containing x86 specific code.

To avoid this rather strange split, the generic helpers are reworked so
they are arch-agnostic. This requires the introduction of a new helper
__acpi_os_unmap_memory() that will undo any mapping done by
__acpi_os_map_memory().

Currently, the arch-helper for unmap is basically a no-op so it only
returns whether the mapping was arch specific. But this will change
in the future.

Note that the x86 version of acpi_os_map_memory() was already able to
able the 1MB region. Hence why there is no addition of new code.

Signed-off-by: Julien Grall <jgrall@amazon.com>
Reviewed-by: Rahul Singh <rahul.singh@arm.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Stefano Stabellini <sstabellini@kernel.org>
Tested-by: Rahul Singh <rahul.singh@arm.com>
Tested-by: Elliott Mitchell <ehem+xen@m5p.com>
xen/arch/arm/acpi/lib.c
xen/arch/x86/acpi/lib.c
xen/drivers/acpi/osl.c
xen/include/xen/acpi.h

index 4fc6e17322c16d232c31fa4315d9d72a9d99d25e..fcc186b03399b34e2c5d77a2295a6e904fa836a4 100644 (file)
@@ -30,6 +30,10 @@ char *__acpi_map_table(paddr_t phys, unsigned long size)
     unsigned long base, offset, mapped_size;
     int idx;
 
+    /* No arch specific implementation after early boot */
+    if ( system_state >= SYS_STATE_boot )
+        return NULL;
+
     offset = phys & (PAGE_SIZE - 1);
     mapped_size = PAGE_SIZE - offset;
     set_fixmap(FIXMAP_ACPI_BEGIN, maddr_to_mfn(phys), PAGE_HYPERVISOR);
@@ -49,6 +53,14 @@ char *__acpi_map_table(paddr_t phys, unsigned long size)
     return ((char *) base + offset);
 }
 
+bool __acpi_unmap_table(const void *ptr, unsigned long size)
+{
+    vaddr_t vaddr = (vaddr_t)ptr;
+
+    return ((vaddr >= FIXMAP_ADDR(FIXMAP_ACPI_BEGIN)) &&
+            (vaddr < (FIXMAP_ADDR(FIXMAP_ACPI_END) + PAGE_SIZE)));
+}
+
 /* True to indicate PSCI 0.2+ is implemented */
 bool __init acpi_psci_present(void)
 {
index 265b9ad8190562ad323e2e9d5f07cb3e69444b17..a22414a05c1399f537900f08e403e4688a6ee9ee 100644 (file)
@@ -46,6 +46,10 @@ char *__acpi_map_table(paddr_t phys, unsigned long size)
        if ((phys + size) <= (1 * 1024 * 1024))
                return __va(phys);
 
+       /* No further arch specific implementation after early boot */
+       if (system_state >= SYS_STATE_boot)
+               return NULL;
+
        offset = phys & (PAGE_SIZE - 1);
        mapped_size = PAGE_SIZE - offset;
        set_fixmap(FIX_ACPI_END, phys);
@@ -66,6 +70,20 @@ char *__acpi_map_table(paddr_t phys, unsigned long size)
        return ((char *) base + offset);
 }
 
+bool __acpi_unmap_table(const void *ptr, unsigned long size)
+{
+       unsigned long vaddr = (unsigned long)ptr;
+
+       if ((vaddr >= DIRECTMAP_VIRT_START) &&
+           (vaddr < DIRECTMAP_VIRT_END)) {
+               ASSERT(!((__pa(ptr) + size - 1) >> 20));
+               return true;
+       }
+
+       return ((vaddr >= __fix_to_virt(FIX_ACPI_END)) &&
+               (vaddr < (__fix_to_virt(FIX_ACPI_BEGIN) + PAGE_SIZE)));
+}
+
 unsigned int acpi_get_processor_id(unsigned int cpu)
 {
        unsigned int acpiid, apicid;
index 4c8bb7839edab0234ea1babf6a00ea154c1530c4..389505f786668dc4b6859956ee51f4f4df85f675 100644 (file)
@@ -92,27 +92,29 @@ acpi_physical_address __init acpi_os_get_root_pointer(void)
 void __iomem *
 acpi_os_map_memory(acpi_physical_address phys, acpi_size size)
 {
-       if (system_state >= SYS_STATE_boot) {
-               mfn_t mfn = _mfn(PFN_DOWN(phys));
-               unsigned int offs = phys & (PAGE_SIZE - 1);
-
-               /* The low first Mb is always mapped on x86. */
-               if (IS_ENABLED(CONFIG_X86) && !((phys + size - 1) >> 20))
-                       return __va(phys);
-               return __vmap(&mfn, PFN_UP(offs + size), 1, 1,
-                             ACPI_MAP_MEM_ATTR, VMAP_DEFAULT) + offs;
-       }
-       return __acpi_map_table(phys, size);
+       void *ptr;
+       mfn_t mfn = _mfn(PFN_DOWN(phys));
+       unsigned int offs = PAGE_OFFSET(phys);
+
+       /* Try the arch specific implementation first */
+       ptr = __acpi_map_table(phys, size);
+       if (ptr)
+               return ptr;
+
+       /* No common implementation for early boot map */
+       if (unlikely(system_state < SYS_STATE_boot))
+               return NULL;
+
+       ptr = __vmap(&mfn, PFN_UP(offs + size), 1, 1,
+                    ACPI_MAP_MEM_ATTR, VMAP_DEFAULT);
+
+       return !ptr ? NULL : (ptr + offs);
 }
 
 void acpi_os_unmap_memory(void __iomem * virt, acpi_size size)
 {
-       if (IS_ENABLED(CONFIG_X86) &&
-           (unsigned long)virt >= DIRECTMAP_VIRT_START &&
-           (unsigned long)virt < DIRECTMAP_VIRT_END) {
-               ASSERT(!((__pa(virt) + size - 1) >> 20));
+       if (__acpi_unmap_table(virt, size))
                return;
-       }
 
        if (system_state >= SYS_STATE_boot)
                vunmap((void *)((unsigned long)virt & PAGE_MASK));
index c945ab05c8647ae825a9034eee3d9ddaaa1ddc94..21d5e9feb5aec80aebacf437913f0748945e3ef2 100644 (file)
@@ -68,6 +68,7 @@ typedef int (*acpi_table_entry_handler) (struct acpi_subtable_header *header, co
 
 unsigned int acpi_get_processor_id (unsigned int cpu);
 char * __acpi_map_table (paddr_t phys_addr, unsigned long size);
+bool __acpi_unmap_table(const void *ptr, unsigned long size);
 int acpi_boot_init (void);
 int acpi_boot_table_init (void);
 int acpi_numa_init (void);