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/init.h>
26 #include <xen/mm.h>
27
__acpi_map_table(paddr_t phys,unsigned long size)28 char *__acpi_map_table(paddr_t phys, unsigned long size)
29 {
30 unsigned long base, offset, mapped_size;
31 int idx;
32
33 offset = phys & (PAGE_SIZE - 1);
34 mapped_size = PAGE_SIZE - offset;
35 set_fixmap(FIXMAP_ACPI_BEGIN, maddr_to_mfn(phys), PAGE_HYPERVISOR);
36 base = FIXMAP_ADDR(FIXMAP_ACPI_BEGIN);
37
38 /* Most cases can be covered by the below. */
39 idx = FIXMAP_ACPI_BEGIN;
40 while ( mapped_size < size )
41 {
42 if ( ++idx > FIXMAP_ACPI_END )
43 return NULL; /* cannot handle this */
44 phys += PAGE_SIZE;
45 set_fixmap(idx, maddr_to_mfn(phys), PAGE_HYPERVISOR);
46 mapped_size += PAGE_SIZE;
47 }
48
49 return ((char *) base + offset);
50 }
51
52 /* True to indicate PSCI 0.2+ is implemented */
acpi_psci_present(void)53 bool __init acpi_psci_present(void)
54 {
55 return acpi_gbl_FADT.arm_boot_flags & ACPI_FADT_PSCI_COMPLIANT;
56 }
57
58 /* True to indicate HVC is present instead of SMC as the PSCI conduit */
acpi_psci_hvc_present(void)59 bool __init acpi_psci_hvc_present(void)
60 {
61 return acpi_gbl_FADT.arm_boot_flags & ACPI_FADT_PSCI_USE_HVC;
62 }
63
acpi_get_table_offset(struct membank tbl_add[],EFI_MEM_RES index)64 paddr_t __init acpi_get_table_offset(struct membank tbl_add[],
65 EFI_MEM_RES index)
66 {
67 int i;
68 paddr_t offset = 0;
69
70 for ( i = 0; i < index; i++ )
71 {
72 /* Aligned with 64bit (8 bytes) */
73 offset += ROUNDUP(tbl_add[i].size, 8);
74 }
75
76 return offset;
77 }
78