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 <contrib/dev/acpica/include/acpi.h>
42 #include <contrib/dev/acpica/include/accommon.h>
43 #include <contrib/dev/acpica/include/actables.h>
45 #include <dev/acpica/acpivar.h>
47 extern struct bus_space memmap_bus;
50 acpi_machdep_init(device_t dev)
57 acpi_machdep_quirks(int *quirks)
64 map_table(vm_paddr_t pa, int offset, const char *sig)
66 ACPI_TABLE_HEADER *header;
70 header = pmap_mapbios(pa, sizeof(ACPI_TABLE_HEADER));
71 if (strncmp(header->Signature, sig, ACPI_NAME_SIZE) != 0) {
72 pmap_unmapbios((vm_offset_t)header, sizeof(ACPI_TABLE_HEADER));
75 length = header->Length;
76 pmap_unmapbios((vm_offset_t)header, sizeof(ACPI_TABLE_HEADER));
78 table = pmap_mapbios(pa, length);
79 if (ACPI_FAILURE(AcpiTbChecksum(table, length))) {
81 printf("ACPI: Failed checksum for table %s\n", sig);
82 #if (ACPI_CHECKSUM_ABORT)
83 pmap_unmapbios(table, length);
91 * See if a given ACPI table is the requested table. Returns the
92 * length of the able if it matches or zero on failure.
95 probe_table(vm_paddr_t address, const char *sig)
97 ACPI_TABLE_HEADER *table;
99 table = pmap_mapbios(address, sizeof(ACPI_TABLE_HEADER));
102 printf("ACPI: Failed to map table at 0x%jx\n",
107 printf("Table '%.4s' at 0x%jx\n", table->Signature,
110 if (strncmp(table->Signature, sig, ACPI_NAME_SIZE) != 0) {
111 pmap_unmapbios((vm_offset_t)table, sizeof(ACPI_TABLE_HEADER));
114 pmap_unmapbios((vm_offset_t)table, sizeof(ACPI_TABLE_HEADER));
118 /* Unmap a table previously mapped via acpi_map_table(). */
120 acpi_unmap_table(void *table)
122 ACPI_TABLE_HEADER *header;
124 header = (ACPI_TABLE_HEADER *)table;
125 pmap_unmapbios((vm_offset_t)table, header->Length);
129 * Try to map a table at a given physical address previously returned
130 * by acpi_find_table().
133 acpi_map_table(vm_paddr_t pa, const char *sig)
136 return (map_table(pa, 0, sig));
140 * Return the physical address of the requested table or zero if one
144 acpi_find_table(const char *sig)
146 ACPI_PHYSICAL_ADDRESS rsdp_ptr;
147 ACPI_TABLE_RSDP *rsdp;
148 ACPI_TABLE_XSDT *xsdt;
149 ACPI_TABLE_HEADER *table;
153 if (resource_disabled("acpi", 0))
157 * Map in the RSDP. Since ACPI uses AcpiOsMapMemory() which in turn
158 * calls pmap_mapbios() to find the RSDP, we assume that we can use
159 * pmap_mapbios() to map the RSDP.
161 if ((rsdp_ptr = AcpiOsGetRootPointer()) == 0)
163 rsdp = pmap_mapbios(rsdp_ptr, sizeof(ACPI_TABLE_RSDP));
166 printf("ACPI: Failed to map RSDP\n");
171 if (rsdp->Revision >= 2 && rsdp->XsdtPhysicalAddress != 0) {
173 * AcpiOsGetRootPointer only verifies the checksum for
174 * the version 1.0 portion of the RSDP. Version 2.0 has
175 * an additional checksum that we verify first.
177 if (AcpiTbChecksum((UINT8 *)rsdp, ACPI_RSDP_XCHECKSUM_LENGTH)) {
179 printf("ACPI: RSDP failed extended checksum\n");
182 xsdt = map_table(rsdp->XsdtPhysicalAddress, 2, ACPI_SIG_XSDT);
185 printf("ACPI: Failed to map XSDT\n");
186 pmap_unmapbios((vm_offset_t)rsdp,
187 sizeof(ACPI_TABLE_RSDP));
190 count = (xsdt->Header.Length - sizeof(ACPI_TABLE_HEADER)) /
192 for (i = 0; i < count; i++)
193 if (probe_table(xsdt->TableOffsetEntry[i], sig)) {
194 addr = xsdt->TableOffsetEntry[i];
197 acpi_unmap_table(xsdt);
199 pmap_unmapbios((vm_offset_t)rsdp, sizeof(ACPI_TABLE_RSDP));
203 printf("ACPI: No %s table found\n", sig);
207 printf("%s: Found table at 0x%jx\n", sig, (uintmax_t)addr);
210 * Verify that we can map the full table and that its checksum is
213 table = map_table(addr, 0, sig);
216 acpi_unmap_table(table);
222 acpi_map_addr(struct acpi_generic_address *addr, bus_space_tag_t *tag,
223 bus_space_handle_t *handle, bus_size_t size)
227 /* Check if the device is Memory mapped */
228 if (addr->SpaceId != 0)
231 phys = addr->Address;
234 return (bus_space_map(*tag, phys, size, 0, handle));