2 * Copyright (c) 2001 Mitsuru IWASAKI
3 * Copyright (c) 2015 The FreeBSD Foundation
6 * This software was developed by Andrew Turner under
7 * sponsorship from the FreeBSD Foundation.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 #include <sys/cdefs.h>
32 __FBSDID("$FreeBSD$");
34 #include <sys/param.h>
36 #include <sys/kernel.h>
41 #include <machine/machdep.h>
43 #include <contrib/dev/acpica/include/acpi.h>
44 #include <contrib/dev/acpica/include/accommon.h>
45 #include <contrib/dev/acpica/include/actables.h>
47 #include <dev/acpica/acpivar.h>
49 extern struct bus_space memmap_bus;
52 acpi_machdep_init(device_t dev)
59 acpi_machdep_quirks(int *quirks)
66 map_table(vm_paddr_t pa, const char *sig)
68 ACPI_TABLE_HEADER *header;
72 header = pmap_mapbios(pa, sizeof(ACPI_TABLE_HEADER));
73 if (strncmp(header->Signature, sig, ACPI_NAMESEG_SIZE) != 0) {
74 pmap_unmapbios((vm_offset_t)header, sizeof(ACPI_TABLE_HEADER));
77 length = header->Length;
78 pmap_unmapbios((vm_offset_t)header, sizeof(ACPI_TABLE_HEADER));
80 table = pmap_mapbios(pa, length);
81 if (ACPI_FAILURE(AcpiTbChecksum(table, length))) {
83 printf("ACPI: Failed checksum for table %s\n", sig);
84 #if (ACPI_CHECKSUM_ABORT)
85 pmap_unmapbios(table, length);
93 * See if a given ACPI table is the requested table. Returns the
94 * length of the table if it matches or zero on failure.
97 probe_table(vm_paddr_t address, const char *sig)
99 ACPI_TABLE_HEADER *table;
101 table = pmap_mapbios(address, sizeof(ACPI_TABLE_HEADER));
104 printf("ACPI: Failed to map table at 0x%jx\n",
109 if (strncmp(table->Signature, sig, ACPI_NAMESEG_SIZE) != 0) {
110 pmap_unmapbios((vm_offset_t)table, sizeof(ACPI_TABLE_HEADER));
113 pmap_unmapbios((vm_offset_t)table, sizeof(ACPI_TABLE_HEADER));
117 /* Unmap a table previously mapped via acpi_map_table(). */
119 acpi_unmap_table(void *table)
121 ACPI_TABLE_HEADER *header;
123 header = (ACPI_TABLE_HEADER *)table;
124 pmap_unmapbios((vm_offset_t)table, header->Length);
128 * Try to map a table at a given physical address previously returned
129 * by acpi_find_table().
132 acpi_map_table(vm_paddr_t pa, const char *sig)
135 return (map_table(pa, sig));
139 * Return the physical address of the requested table or zero if one
143 acpi_find_table(const char *sig)
145 ACPI_PHYSICAL_ADDRESS rsdp_ptr;
146 ACPI_TABLE_RSDP *rsdp;
147 ACPI_TABLE_XSDT *xsdt;
148 ACPI_TABLE_HEADER *table;
152 if (resource_disabled("acpi", 0))
156 * Map in the RSDP. Since ACPI uses AcpiOsMapMemory() which in turn
157 * calls pmap_mapbios() to find the RSDP, we assume that we can use
158 * pmap_mapbios() to map the RSDP.
160 if ((rsdp_ptr = AcpiOsGetRootPointer()) == 0)
162 rsdp = pmap_mapbios(rsdp_ptr, sizeof(ACPI_TABLE_RSDP));
164 printf("ACPI: Failed to map RSDP\n");
169 if (rsdp->Revision >= 2 && rsdp->XsdtPhysicalAddress != 0) {
171 * AcpiOsGetRootPointer only verifies the checksum for
172 * the version 1.0 portion of the RSDP. Version 2.0 has
173 * an additional checksum that we verify first.
175 if (AcpiTbChecksum((UINT8 *)rsdp, ACPI_RSDP_XCHECKSUM_LENGTH)) {
176 printf("ACPI: RSDP failed extended checksum\n");
177 pmap_unmapbios((vm_offset_t)rsdp,
178 sizeof(ACPI_TABLE_RSDP));
181 xsdt = map_table(rsdp->XsdtPhysicalAddress, ACPI_SIG_XSDT);
183 printf("ACPI: Failed to map XSDT\n");
184 pmap_unmapbios((vm_offset_t)rsdp,
185 sizeof(ACPI_TABLE_RSDP));
188 count = (xsdt->Header.Length - sizeof(ACPI_TABLE_HEADER)) /
190 for (i = 0; i < count; i++)
191 if (probe_table(xsdt->TableOffsetEntry[i], sig)) {
192 addr = xsdt->TableOffsetEntry[i];
195 acpi_unmap_table(xsdt);
197 printf("ACPI: Unsupported RSDP version %d and XSDT %#lx\n",
198 rsdp->Revision, rsdp->XsdtPhysicalAddress);
200 pmap_unmapbios((vm_offset_t)rsdp, sizeof(ACPI_TABLE_RSDP));
206 * Verify that we can map the full table and that its checksum is
209 table = map_table(addr, sig);
212 acpi_unmap_table(table);
218 acpi_map_addr(struct acpi_generic_address *addr, bus_space_tag_t *tag,
219 bus_space_handle_t *handle, bus_size_t size)
223 /* Check if the device is Memory mapped */
224 if (addr->SpaceId != 0)
227 phys = addr->Address;
230 return (bus_space_map(*tag, phys, size, 0, handle));
235 parse_pxm_tables(void *dummy)
237 uint64_t mmfr0, parange;
239 /* Only parse ACPI tables when booting via ACPI */
240 if (arm64_bus_method != ARM64_BUS_ACPI)
243 if (!get_kernel_reg(ID_AA64MMFR0_EL1, &mmfr0)) {
244 /* chosen arbitrarily */
245 mmfr0 = ID_AA64MMFR0_PARange_1T;
248 switch (ID_AA64MMFR0_PARange_VAL(mmfr0)) {
249 case ID_AA64MMFR0_PARange_4G:
250 parange = (vm_paddr_t)4 << 30 /* GiB */;
252 case ID_AA64MMFR0_PARange_64G:
253 parange = (vm_paddr_t)64 << 30 /* GiB */;
255 case ID_AA64MMFR0_PARange_1T:
256 parange = (vm_paddr_t)1 << 40 /* TiB */;
258 case ID_AA64MMFR0_PARange_4T:
259 parange = (vm_paddr_t)4 << 40 /* TiB */;
261 case ID_AA64MMFR0_PARange_16T:
262 parange = (vm_paddr_t)16 << 40 /* TiB */;
264 case ID_AA64MMFR0_PARange_256T:
265 parange = (vm_paddr_t)256 << 40 /* TiB */;
267 case ID_AA64MMFR0_PARange_4P:
268 parange = (vm_paddr_t)4 << 50 /* PiB */;
271 /* chosen arbitrarily */
272 parange = (vm_paddr_t)1 << 40 /* TiB */;
273 printf("Unknown value for PARange in mmfr0 (%#lx)\n", mmfr0);
277 acpi_pxm_init(MAXCPU, parange);
278 acpi_pxm_parse_tables();
279 acpi_pxm_set_mem_locality();
281 SYSINIT(parse_pxm_tables, SI_SUB_VM - 1, SI_ORDER_FIRST, parse_pxm_tables,