1 /*
2 * lib.c - Architecture-Specific Low-Level ACPI Support
3 *
4 * Copyright (C) 2015, Shannon Zhao <shannon.zhao@linaro.org>
5 *
6 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; If not, see <http://www.gnu.org/licenses/>.
20 *
21 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
22 */
23
24 #include <xen/acpi.h>
25 #include <xen/mm.h>
26
__acpi_map_table(paddr_t phys,unsigned long size)27 char *__acpi_map_table(paddr_t phys, unsigned long size)
28 {
29 unsigned long base, offset, mapped_size;
30 int idx;
31
32 offset = phys & (PAGE_SIZE - 1);
33 mapped_size = PAGE_SIZE - offset;
34 set_fixmap(FIXMAP_ACPI_BEGIN, maddr_to_mfn(phys), PAGE_HYPERVISOR);
35 base = FIXMAP_ADDR(FIXMAP_ACPI_BEGIN);
36
37 /* Most cases can be covered by the below. */
38 idx = FIXMAP_ACPI_BEGIN;
39 while ( mapped_size < size )
40 {
41 if ( ++idx > FIXMAP_ACPI_END )
42 return NULL; /* cannot handle this */
43 phys += PAGE_SIZE;
44 set_fixmap(idx, maddr_to_mfn(phys), PAGE_HYPERVISOR);
45 mapped_size += PAGE_SIZE;
46 }
47
48 return ((char *) base + offset);
49 }
50
51 /* True to indicate PSCI 0.2+ is implemented */
acpi_psci_present(void)52 bool __init acpi_psci_present(void)
53 {
54 return acpi_gbl_FADT.arm_boot_flags & ACPI_FADT_PSCI_COMPLIANT;
55 }
56
57 /* True to indicate HVC is present instead of SMC as the PSCI conduit */
acpi_psci_hvc_present(void)58 bool __init acpi_psci_hvc_present(void)
59 {
60 return acpi_gbl_FADT.arm_boot_flags & ACPI_FADT_PSCI_USE_HVC;
61 }
62
acpi_get_table_offset(struct membank tbl_add[],EFI_MEM_RES index)63 paddr_t __init acpi_get_table_offset(struct membank tbl_add[],
64 EFI_MEM_RES index)
65 {
66 int i;
67 paddr_t offset = 0;
68
69 for ( i = 0; i < index; i++ )
70 {
71 /* Aligned with 64bit (8 bytes) */
72 offset += ROUNDUP(tbl_add[i].size, 8);
73 }
74
75 return offset;
76 }
77