tbutils.c revision 1.3.4.2 1 1.3.4.2 rmind /******************************************************************************
2 1.3.4.2 rmind *
3 1.3.4.2 rmind * Module Name: tbutils - table utilities
4 1.3.4.2 rmind *
5 1.3.4.2 rmind *****************************************************************************/
6 1.3.4.2 rmind
7 1.3.4.2 rmind /*
8 1.3.4.2 rmind * Copyright (C) 2000 - 2011, Intel Corp.
9 1.3.4.2 rmind * All rights reserved.
10 1.3.4.2 rmind *
11 1.3.4.2 rmind * Redistribution and use in source and binary forms, with or without
12 1.3.4.2 rmind * modification, are permitted provided that the following conditions
13 1.3.4.2 rmind * are met:
14 1.3.4.2 rmind * 1. Redistributions of source code must retain the above copyright
15 1.3.4.2 rmind * notice, this list of conditions, and the following disclaimer,
16 1.3.4.2 rmind * without modification.
17 1.3.4.2 rmind * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 1.3.4.2 rmind * substantially similar to the "NO WARRANTY" disclaimer below
19 1.3.4.2 rmind * ("Disclaimer") and any redistribution must be conditioned upon
20 1.3.4.2 rmind * including a substantially similar Disclaimer requirement for further
21 1.3.4.2 rmind * binary redistribution.
22 1.3.4.2 rmind * 3. Neither the names of the above-listed copyright holders nor the names
23 1.3.4.2 rmind * of any contributors may be used to endorse or promote products derived
24 1.3.4.2 rmind * from this software without specific prior written permission.
25 1.3.4.2 rmind *
26 1.3.4.2 rmind * Alternatively, this software may be distributed under the terms of the
27 1.3.4.2 rmind * GNU General Public License ("GPL") version 2 as published by the Free
28 1.3.4.2 rmind * Software Foundation.
29 1.3.4.2 rmind *
30 1.3.4.2 rmind * NO WARRANTY
31 1.3.4.2 rmind * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 1.3.4.2 rmind * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 1.3.4.2 rmind * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 1.3.4.2 rmind * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 1.3.4.2 rmind * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 1.3.4.2 rmind * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 1.3.4.2 rmind * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 1.3.4.2 rmind * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 1.3.4.2 rmind * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 1.3.4.2 rmind * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 1.3.4.2 rmind * POSSIBILITY OF SUCH DAMAGES.
42 1.3.4.2 rmind */
43 1.3.4.2 rmind
44 1.3.4.2 rmind #define __TBUTILS_C__
45 1.3.4.2 rmind
46 1.3.4.2 rmind #include "acpi.h"
47 1.3.4.2 rmind #include "accommon.h"
48 1.3.4.2 rmind #include "actables.h"
49 1.3.4.2 rmind
50 1.3.4.2 rmind #define _COMPONENT ACPI_TABLES
51 1.3.4.2 rmind ACPI_MODULE_NAME ("tbutils")
52 1.3.4.2 rmind
53 1.3.4.2 rmind /* Local prototypes */
54 1.3.4.2 rmind
55 1.3.4.2 rmind static void
56 1.3.4.2 rmind AcpiTbFixString (
57 1.3.4.2 rmind char *String,
58 1.3.4.2 rmind ACPI_SIZE Length);
59 1.3.4.2 rmind
60 1.3.4.2 rmind static void
61 1.3.4.2 rmind AcpiTbCleanupTableHeader (
62 1.3.4.2 rmind ACPI_TABLE_HEADER *OutHeader,
63 1.3.4.2 rmind ACPI_TABLE_HEADER *Header);
64 1.3.4.2 rmind
65 1.3.4.2 rmind static ACPI_PHYSICAL_ADDRESS
66 1.3.4.2 rmind AcpiTbGetRootTableEntry (
67 1.3.4.2 rmind UINT8 *TableEntry,
68 1.3.4.2 rmind UINT32 TableEntrySize);
69 1.3.4.2 rmind
70 1.3.4.2 rmind
71 1.3.4.2 rmind /*******************************************************************************
72 1.3.4.2 rmind *
73 1.3.4.2 rmind * FUNCTION: AcpiTbInitializeFacs
74 1.3.4.2 rmind *
75 1.3.4.2 rmind * PARAMETERS: None
76 1.3.4.2 rmind *
77 1.3.4.2 rmind * RETURN: Status
78 1.3.4.2 rmind *
79 1.3.4.2 rmind * DESCRIPTION: Create a permanent mapping for the FADT and save it in a global
80 1.3.4.2 rmind * for accessing the Global Lock and Firmware Waking Vector
81 1.3.4.2 rmind *
82 1.3.4.2 rmind ******************************************************************************/
83 1.3.4.2 rmind
84 1.3.4.2 rmind ACPI_STATUS
85 1.3.4.2 rmind AcpiTbInitializeFacs (
86 1.3.4.2 rmind void)
87 1.3.4.2 rmind {
88 1.3.4.2 rmind ACPI_STATUS Status;
89 1.3.4.2 rmind
90 1.3.4.2 rmind
91 1.3.4.2 rmind Status = AcpiGetTableByIndex (ACPI_TABLE_INDEX_FACS,
92 1.3.4.2 rmind ACPI_CAST_INDIRECT_PTR (ACPI_TABLE_HEADER, &AcpiGbl_FACS));
93 1.3.4.2 rmind return (Status);
94 1.3.4.2 rmind }
95 1.3.4.2 rmind
96 1.3.4.2 rmind
97 1.3.4.2 rmind /*******************************************************************************
98 1.3.4.2 rmind *
99 1.3.4.2 rmind * FUNCTION: AcpiTbTablesLoaded
100 1.3.4.2 rmind *
101 1.3.4.2 rmind * PARAMETERS: None
102 1.3.4.2 rmind *
103 1.3.4.2 rmind * RETURN: TRUE if required ACPI tables are loaded
104 1.3.4.2 rmind *
105 1.3.4.2 rmind * DESCRIPTION: Determine if the minimum required ACPI tables are present
106 1.3.4.2 rmind * (FADT, FACS, DSDT)
107 1.3.4.2 rmind *
108 1.3.4.2 rmind ******************************************************************************/
109 1.3.4.2 rmind
110 1.3.4.2 rmind BOOLEAN
111 1.3.4.2 rmind AcpiTbTablesLoaded (
112 1.3.4.2 rmind void)
113 1.3.4.2 rmind {
114 1.3.4.2 rmind
115 1.3.4.2 rmind if (AcpiGbl_RootTableList.CurrentTableCount >= 3)
116 1.3.4.2 rmind {
117 1.3.4.2 rmind return (TRUE);
118 1.3.4.2 rmind }
119 1.3.4.2 rmind
120 1.3.4.2 rmind return (FALSE);
121 1.3.4.2 rmind }
122 1.3.4.2 rmind
123 1.3.4.2 rmind
124 1.3.4.2 rmind /*******************************************************************************
125 1.3.4.2 rmind *
126 1.3.4.2 rmind * FUNCTION: AcpiTbFixString
127 1.3.4.2 rmind *
128 1.3.4.2 rmind * PARAMETERS: String - String to be repaired
129 1.3.4.2 rmind * Length - Maximum length
130 1.3.4.2 rmind *
131 1.3.4.2 rmind * RETURN: None
132 1.3.4.2 rmind *
133 1.3.4.2 rmind * DESCRIPTION: Replace every non-printable or non-ascii byte in the string
134 1.3.4.2 rmind * with a question mark '?'.
135 1.3.4.2 rmind *
136 1.3.4.2 rmind ******************************************************************************/
137 1.3.4.2 rmind
138 1.3.4.2 rmind static void
139 1.3.4.2 rmind AcpiTbFixString (
140 1.3.4.2 rmind char *String,
141 1.3.4.2 rmind ACPI_SIZE Length)
142 1.3.4.2 rmind {
143 1.3.4.2 rmind
144 1.3.4.2 rmind while (Length && *String)
145 1.3.4.2 rmind {
146 1.3.4.2 rmind if (!ACPI_IS_PRINT (*String))
147 1.3.4.2 rmind {
148 1.3.4.2 rmind *String = '?';
149 1.3.4.2 rmind }
150 1.3.4.2 rmind String++;
151 1.3.4.2 rmind Length--;
152 1.3.4.2 rmind }
153 1.3.4.2 rmind }
154 1.3.4.2 rmind
155 1.3.4.2 rmind
156 1.3.4.2 rmind /*******************************************************************************
157 1.3.4.2 rmind *
158 1.3.4.2 rmind * FUNCTION: AcpiTbCleanupTableHeader
159 1.3.4.2 rmind *
160 1.3.4.2 rmind * PARAMETERS: OutHeader - Where the cleaned header is returned
161 1.3.4.2 rmind * Header - Input ACPI table header
162 1.3.4.2 rmind *
163 1.3.4.2 rmind * RETURN: Returns the cleaned header in OutHeader
164 1.3.4.2 rmind *
165 1.3.4.2 rmind * DESCRIPTION: Copy the table header and ensure that all "string" fields in
166 1.3.4.2 rmind * the header consist of printable characters.
167 1.3.4.2 rmind *
168 1.3.4.2 rmind ******************************************************************************/
169 1.3.4.2 rmind
170 1.3.4.2 rmind static void
171 1.3.4.2 rmind AcpiTbCleanupTableHeader (
172 1.3.4.2 rmind ACPI_TABLE_HEADER *OutHeader,
173 1.3.4.2 rmind ACPI_TABLE_HEADER *Header)
174 1.3.4.2 rmind {
175 1.3.4.2 rmind
176 1.3.4.2 rmind ACPI_MEMCPY (OutHeader, Header, sizeof (ACPI_TABLE_HEADER));
177 1.3.4.2 rmind
178 1.3.4.2 rmind AcpiTbFixString (OutHeader->Signature, ACPI_NAME_SIZE);
179 1.3.4.2 rmind AcpiTbFixString (OutHeader->OemId, ACPI_OEM_ID_SIZE);
180 1.3.4.2 rmind AcpiTbFixString (OutHeader->OemTableId, ACPI_OEM_TABLE_ID_SIZE);
181 1.3.4.2 rmind AcpiTbFixString (OutHeader->AslCompilerId, ACPI_NAME_SIZE);
182 1.3.4.2 rmind }
183 1.3.4.2 rmind
184 1.3.4.2 rmind
185 1.3.4.2 rmind /*******************************************************************************
186 1.3.4.2 rmind *
187 1.3.4.2 rmind * FUNCTION: AcpiTbPrintTableHeader
188 1.3.4.2 rmind *
189 1.3.4.2 rmind * PARAMETERS: Address - Table physical address
190 1.3.4.2 rmind * Header - Table header
191 1.3.4.2 rmind *
192 1.3.4.2 rmind * RETURN: None
193 1.3.4.2 rmind *
194 1.3.4.2 rmind * DESCRIPTION: Print an ACPI table header. Special cases for FACS and RSDP.
195 1.3.4.2 rmind *
196 1.3.4.2 rmind ******************************************************************************/
197 1.3.4.2 rmind
198 1.3.4.2 rmind void
199 1.3.4.2 rmind AcpiTbPrintTableHeader (
200 1.3.4.2 rmind ACPI_PHYSICAL_ADDRESS Address,
201 1.3.4.2 rmind ACPI_TABLE_HEADER *Header)
202 1.3.4.2 rmind {
203 1.3.4.2 rmind ACPI_TABLE_HEADER LocalHeader;
204 1.3.4.2 rmind
205 1.3.4.2 rmind
206 1.3.4.2 rmind /*
207 1.3.4.2 rmind * The reason that the Address is cast to a void pointer is so that we
208 1.3.4.2 rmind * can use %p which will work properly on both 32-bit and 64-bit hosts.
209 1.3.4.2 rmind */
210 1.3.4.2 rmind if (ACPI_COMPARE_NAME (Header->Signature, ACPI_SIG_FACS))
211 1.3.4.2 rmind {
212 1.3.4.2 rmind /* FACS only has signature and length fields */
213 1.3.4.2 rmind
214 1.3.4.2 rmind ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "%4.4s %p %05X",
215 1.3.4.2 rmind Header->Signature, ACPI_CAST_PTR (void, Address),
216 1.3.4.2 rmind Header->Length));
217 1.3.4.2 rmind }
218 1.3.4.2 rmind else if (ACPI_COMPARE_NAME (Header->Signature, ACPI_SIG_RSDP))
219 1.3.4.2 rmind {
220 1.3.4.2 rmind /* RSDP has no common fields */
221 1.3.4.2 rmind
222 1.3.4.2 rmind ACPI_MEMCPY (LocalHeader.OemId,
223 1.3.4.2 rmind ACPI_CAST_PTR (ACPI_TABLE_RSDP, Header)->OemId, ACPI_OEM_ID_SIZE);
224 1.3.4.2 rmind AcpiTbFixString (LocalHeader.OemId, ACPI_OEM_ID_SIZE);
225 1.3.4.2 rmind
226 1.3.4.2 rmind ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "RSDP %p %05X (v%.2d %6.6s)",
227 1.3.4.2 rmind ACPI_CAST_PTR (void, Address),
228 1.3.4.2 rmind (ACPI_CAST_PTR (ACPI_TABLE_RSDP, Header)->Revision > 0) ?
229 1.3.4.2 rmind ACPI_CAST_PTR (ACPI_TABLE_RSDP, Header)->Length : 20,
230 1.3.4.2 rmind ACPI_CAST_PTR (ACPI_TABLE_RSDP, Header)->Revision,
231 1.3.4.2 rmind LocalHeader.OemId));
232 1.3.4.2 rmind }
233 1.3.4.2 rmind else
234 1.3.4.2 rmind {
235 1.3.4.2 rmind /* Standard ACPI table with full common header */
236 1.3.4.2 rmind
237 1.3.4.2 rmind AcpiTbCleanupTableHeader (&LocalHeader, Header);
238 1.3.4.2 rmind
239 1.3.4.2 rmind ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
240 1.3.4.2 rmind "%4.4s %p %05X (v%.2d %6.6s %8.8s %08X %4.4s %08X)",
241 1.3.4.2 rmind LocalHeader.Signature, ACPI_CAST_PTR (void, Address),
242 1.3.4.2 rmind LocalHeader.Length, LocalHeader.Revision, LocalHeader.OemId,
243 1.3.4.2 rmind LocalHeader.OemTableId, LocalHeader.OemRevision,
244 1.3.4.2 rmind LocalHeader.AslCompilerId, LocalHeader.AslCompilerRevision));
245 1.3.4.2 rmind }
246 1.3.4.2 rmind }
247 1.3.4.2 rmind
248 1.3.4.2 rmind
249 1.3.4.2 rmind /*******************************************************************************
250 1.3.4.2 rmind *
251 1.3.4.2 rmind * FUNCTION: AcpiTbValidateChecksum
252 1.3.4.2 rmind *
253 1.3.4.2 rmind * PARAMETERS: Table - ACPI table to verify
254 1.3.4.2 rmind * Length - Length of entire table
255 1.3.4.2 rmind *
256 1.3.4.2 rmind * RETURN: Status
257 1.3.4.2 rmind *
258 1.3.4.2 rmind * DESCRIPTION: Verifies that the table checksums to zero. Optionally returns
259 1.3.4.2 rmind * exception on bad checksum.
260 1.3.4.2 rmind *
261 1.3.4.2 rmind ******************************************************************************/
262 1.3.4.2 rmind
263 1.3.4.2 rmind ACPI_STATUS
264 1.3.4.2 rmind AcpiTbVerifyChecksum (
265 1.3.4.2 rmind ACPI_TABLE_HEADER *Table,
266 1.3.4.2 rmind UINT32 Length)
267 1.3.4.2 rmind {
268 1.3.4.2 rmind UINT8 Checksum;
269 1.3.4.2 rmind
270 1.3.4.2 rmind
271 1.3.4.2 rmind /* Compute the checksum on the table */
272 1.3.4.2 rmind
273 1.3.4.2 rmind Checksum = AcpiTbChecksum (ACPI_CAST_PTR (UINT8, Table), Length);
274 1.3.4.2 rmind
275 1.3.4.2 rmind /* Checksum ok? (should be zero) */
276 1.3.4.2 rmind
277 1.3.4.2 rmind if (Checksum)
278 1.3.4.2 rmind {
279 1.3.4.2 rmind ACPI_WARNING ((AE_INFO,
280 1.3.4.2 rmind "Incorrect checksum in table [%4.4s] - 0x%2.2X, should be 0x%2.2X",
281 1.3.4.2 rmind Table->Signature, Table->Checksum,
282 1.3.4.2 rmind (UINT8) (Table->Checksum - Checksum)));
283 1.3.4.2 rmind
284 1.3.4.2 rmind #if (ACPI_CHECKSUM_ABORT)
285 1.3.4.2 rmind return (AE_BAD_CHECKSUM);
286 1.3.4.2 rmind #endif
287 1.3.4.2 rmind }
288 1.3.4.2 rmind
289 1.3.4.2 rmind return (AE_OK);
290 1.3.4.2 rmind }
291 1.3.4.2 rmind
292 1.3.4.2 rmind
293 1.3.4.2 rmind /*******************************************************************************
294 1.3.4.2 rmind *
295 1.3.4.2 rmind * FUNCTION: AcpiTbChecksum
296 1.3.4.2 rmind *
297 1.3.4.2 rmind * PARAMETERS: Buffer - Pointer to memory region to be checked
298 1.3.4.2 rmind * Length - Length of this memory region
299 1.3.4.2 rmind *
300 1.3.4.2 rmind * RETURN: Checksum (UINT8)
301 1.3.4.2 rmind *
302 1.3.4.2 rmind * DESCRIPTION: Calculates circular checksum of memory region.
303 1.3.4.2 rmind *
304 1.3.4.2 rmind ******************************************************************************/
305 1.3.4.2 rmind
306 1.3.4.2 rmind UINT8
307 1.3.4.2 rmind AcpiTbChecksum (
308 1.3.4.2 rmind UINT8 *Buffer,
309 1.3.4.2 rmind UINT32 Length)
310 1.3.4.2 rmind {
311 1.3.4.2 rmind UINT8 Sum = 0;
312 1.3.4.2 rmind UINT8 *End = Buffer + Length;
313 1.3.4.2 rmind
314 1.3.4.2 rmind
315 1.3.4.2 rmind while (Buffer < End)
316 1.3.4.2 rmind {
317 1.3.4.2 rmind Sum = (UINT8) (Sum + *(Buffer++));
318 1.3.4.2 rmind }
319 1.3.4.2 rmind
320 1.3.4.2 rmind return Sum;
321 1.3.4.2 rmind }
322 1.3.4.2 rmind
323 1.3.4.2 rmind
324 1.3.4.2 rmind /*******************************************************************************
325 1.3.4.2 rmind *
326 1.3.4.2 rmind * FUNCTION: AcpiTbCheckDsdtHeader
327 1.3.4.2 rmind *
328 1.3.4.2 rmind * PARAMETERS: None
329 1.3.4.2 rmind *
330 1.3.4.2 rmind * RETURN: None
331 1.3.4.2 rmind *
332 1.3.4.2 rmind * DESCRIPTION: Quick compare to check validity of the DSDT. This will detect
333 1.3.4.2 rmind * if the DSDT has been replaced from outside the OS and/or if
334 1.3.4.2 rmind * the DSDT header has been corrupted.
335 1.3.4.2 rmind *
336 1.3.4.2 rmind ******************************************************************************/
337 1.3.4.2 rmind
338 1.3.4.2 rmind void
339 1.3.4.2 rmind AcpiTbCheckDsdtHeader (
340 1.3.4.2 rmind void)
341 1.3.4.2 rmind {
342 1.3.4.2 rmind
343 1.3.4.2 rmind /* Compare original length and checksum to current values */
344 1.3.4.2 rmind
345 1.3.4.2 rmind if (AcpiGbl_OriginalDsdtHeader.Length != AcpiGbl_DSDT->Length ||
346 1.3.4.2 rmind AcpiGbl_OriginalDsdtHeader.Checksum != AcpiGbl_DSDT->Checksum)
347 1.3.4.2 rmind {
348 1.3.4.2 rmind ACPI_ERROR ((AE_INFO,
349 1.3.4.2 rmind "The DSDT has been corrupted or replaced - old, new headers below"));
350 1.3.4.2 rmind AcpiTbPrintTableHeader (0, &AcpiGbl_OriginalDsdtHeader);
351 1.3.4.2 rmind AcpiTbPrintTableHeader (0, AcpiGbl_DSDT);
352 1.3.4.2 rmind
353 1.3.4.2 rmind /* Disable further error messages */
354 1.3.4.2 rmind
355 1.3.4.2 rmind AcpiGbl_OriginalDsdtHeader.Length = AcpiGbl_DSDT->Length;
356 1.3.4.2 rmind AcpiGbl_OriginalDsdtHeader.Checksum = AcpiGbl_DSDT->Checksum;
357 1.3.4.2 rmind }
358 1.3.4.2 rmind }
359 1.3.4.2 rmind
360 1.3.4.2 rmind
361 1.3.4.2 rmind /*******************************************************************************
362 1.3.4.2 rmind *
363 1.3.4.2 rmind * FUNCTION: AcpiTbCopyDsdt
364 1.3.4.2 rmind *
365 1.3.4.2 rmind * PARAMETERS: TableDesc - Installed table to copy
366 1.3.4.2 rmind *
367 1.3.4.2 rmind * RETURN: None
368 1.3.4.2 rmind *
369 1.3.4.2 rmind * DESCRIPTION: Implements a subsystem option to copy the DSDT to local memory.
370 1.3.4.2 rmind * Some very bad BIOSs are known to either corrupt the DSDT or
371 1.3.4.2 rmind * install a new, bad DSDT. This copy works around the problem.
372 1.3.4.2 rmind *
373 1.3.4.2 rmind ******************************************************************************/
374 1.3.4.2 rmind
375 1.3.4.2 rmind ACPI_TABLE_HEADER *
376 1.3.4.2 rmind AcpiTbCopyDsdt (
377 1.3.4.2 rmind UINT32 TableIndex)
378 1.3.4.2 rmind {
379 1.3.4.2 rmind ACPI_TABLE_HEADER *NewTable;
380 1.3.4.2 rmind ACPI_TABLE_DESC *TableDesc;
381 1.3.4.2 rmind
382 1.3.4.2 rmind
383 1.3.4.2 rmind TableDesc = &AcpiGbl_RootTableList.Tables[TableIndex];
384 1.3.4.2 rmind
385 1.3.4.2 rmind NewTable = ACPI_ALLOCATE (TableDesc->Length);
386 1.3.4.2 rmind if (!NewTable)
387 1.3.4.2 rmind {
388 1.3.4.2 rmind ACPI_ERROR ((AE_INFO, "Could not copy DSDT of length 0x%X",
389 1.3.4.2 rmind TableDesc->Length));
390 1.3.4.2 rmind return (NULL);
391 1.3.4.2 rmind }
392 1.3.4.2 rmind
393 1.3.4.2 rmind ACPI_MEMCPY (NewTable, TableDesc->Pointer, TableDesc->Length);
394 1.3.4.2 rmind AcpiTbDeleteTable (TableDesc);
395 1.3.4.2 rmind TableDesc->Pointer = NewTable;
396 1.3.4.2 rmind TableDesc->Flags = ACPI_TABLE_ORIGIN_ALLOCATED;
397 1.3.4.2 rmind
398 1.3.4.2 rmind ACPI_INFO ((AE_INFO,
399 1.3.4.2 rmind "Forced DSDT copy: length 0x%05X copied locally, original unmapped",
400 1.3.4.2 rmind NewTable->Length));
401 1.3.4.2 rmind
402 1.3.4.2 rmind return (NewTable);
403 1.3.4.2 rmind }
404 1.3.4.2 rmind
405 1.3.4.2 rmind
406 1.3.4.2 rmind /*******************************************************************************
407 1.3.4.2 rmind *
408 1.3.4.2 rmind * FUNCTION: AcpiTbInstallTable
409 1.3.4.2 rmind *
410 1.3.4.2 rmind * PARAMETERS: Address - Physical address of DSDT or FACS
411 1.3.4.2 rmind * Signature - Table signature, NULL if no need to
412 1.3.4.2 rmind * match
413 1.3.4.2 rmind * TableIndex - Index into root table array
414 1.3.4.2 rmind *
415 1.3.4.2 rmind * RETURN: None
416 1.3.4.2 rmind *
417 1.3.4.2 rmind * DESCRIPTION: Install an ACPI table into the global data structure. The
418 1.3.4.2 rmind * table override mechanism is implemented here to allow the host
419 1.3.4.2 rmind * OS to replace any table before it is installed in the root
420 1.3.4.2 rmind * table array.
421 1.3.4.2 rmind *
422 1.3.4.2 rmind ******************************************************************************/
423 1.3.4.2 rmind
424 1.3.4.2 rmind void
425 1.3.4.2 rmind AcpiTbInstallTable (
426 1.3.4.2 rmind ACPI_PHYSICAL_ADDRESS Address,
427 1.3.4.2 rmind const char *Signature,
428 1.3.4.2 rmind UINT32 TableIndex)
429 1.3.4.2 rmind {
430 1.3.4.2 rmind UINT8 Flags;
431 1.3.4.2 rmind ACPI_STATUS Status;
432 1.3.4.2 rmind ACPI_TABLE_HEADER *TableToInstall;
433 1.3.4.2 rmind ACPI_TABLE_HEADER *MappedTable;
434 1.3.4.2 rmind ACPI_TABLE_HEADER *OverrideTable = NULL;
435 1.3.4.2 rmind
436 1.3.4.2 rmind
437 1.3.4.2 rmind if (!Address)
438 1.3.4.2 rmind {
439 1.3.4.2 rmind ACPI_ERROR ((AE_INFO, "Null physical address for ACPI table [%s]",
440 1.3.4.2 rmind Signature));
441 1.3.4.2 rmind return;
442 1.3.4.2 rmind }
443 1.3.4.2 rmind
444 1.3.4.2 rmind /* Map just the table header */
445 1.3.4.2 rmind
446 1.3.4.2 rmind MappedTable = AcpiOsMapMemory (Address, sizeof (ACPI_TABLE_HEADER));
447 1.3.4.2 rmind if (!MappedTable)
448 1.3.4.2 rmind {
449 1.3.4.2 rmind return;
450 1.3.4.2 rmind }
451 1.3.4.2 rmind
452 1.3.4.2 rmind /* If a particular signature is expected (DSDT/FACS), it must match */
453 1.3.4.2 rmind
454 1.3.4.2 rmind if (Signature &&
455 1.3.4.2 rmind !ACPI_COMPARE_NAME (MappedTable->Signature, Signature))
456 1.3.4.2 rmind {
457 1.3.4.2 rmind ACPI_ERROR ((AE_INFO,
458 1.3.4.2 rmind "Invalid signature 0x%X for ACPI table, expected [%s]",
459 1.3.4.2 rmind *ACPI_CAST_PTR (UINT32, MappedTable->Signature), Signature));
460 1.3.4.2 rmind goto UnmapAndExit;
461 1.3.4.2 rmind }
462 1.3.4.2 rmind
463 1.3.4.2 rmind /*
464 1.3.4.2 rmind * ACPI Table Override:
465 1.3.4.2 rmind *
466 1.3.4.2 rmind * Before we install the table, let the host OS override it with a new
467 1.3.4.2 rmind * one if desired. Any table within the RSDT/XSDT can be replaced,
468 1.3.4.2 rmind * including the DSDT which is pointed to by the FADT.
469 1.3.4.2 rmind */
470 1.3.4.2 rmind Status = AcpiOsTableOverride (MappedTable, &OverrideTable);
471 1.3.4.2 rmind if (ACPI_SUCCESS (Status) && OverrideTable)
472 1.3.4.2 rmind {
473 1.3.4.2 rmind ACPI_INFO ((AE_INFO,
474 1.3.4.2 rmind "%4.4s @ 0x%p Table override, replaced with:",
475 1.3.4.2 rmind MappedTable->Signature, ACPI_CAST_PTR (void, Address)));
476 1.3.4.2 rmind
477 1.3.4.2 rmind AcpiGbl_RootTableList.Tables[TableIndex].Pointer = OverrideTable;
478 1.3.4.2 rmind Address = ACPI_PTR_TO_PHYSADDR (OverrideTable);
479 1.3.4.2 rmind
480 1.3.4.2 rmind TableToInstall = OverrideTable;
481 1.3.4.2 rmind Flags = ACPI_TABLE_ORIGIN_OVERRIDE;
482 1.3.4.2 rmind }
483 1.3.4.2 rmind else
484 1.3.4.2 rmind {
485 1.3.4.2 rmind TableToInstall = MappedTable;
486 1.3.4.2 rmind Flags = ACPI_TABLE_ORIGIN_MAPPED;
487 1.3.4.2 rmind }
488 1.3.4.2 rmind
489 1.3.4.2 rmind /* Initialize the table entry */
490 1.3.4.2 rmind
491 1.3.4.2 rmind AcpiGbl_RootTableList.Tables[TableIndex].Address = Address;
492 1.3.4.2 rmind AcpiGbl_RootTableList.Tables[TableIndex].Length = TableToInstall->Length;
493 1.3.4.2 rmind AcpiGbl_RootTableList.Tables[TableIndex].Flags = Flags;
494 1.3.4.2 rmind
495 1.3.4.2 rmind ACPI_MOVE_32_TO_32 (
496 1.3.4.2 rmind &(AcpiGbl_RootTableList.Tables[TableIndex].Signature),
497 1.3.4.2 rmind TableToInstall->Signature);
498 1.3.4.2 rmind
499 1.3.4.2 rmind AcpiTbPrintTableHeader (Address, TableToInstall);
500 1.3.4.2 rmind
501 1.3.4.2 rmind if (TableIndex == ACPI_TABLE_INDEX_DSDT)
502 1.3.4.2 rmind {
503 1.3.4.2 rmind /* Global integer width is based upon revision of the DSDT */
504 1.3.4.2 rmind
505 1.3.4.2 rmind AcpiUtSetIntegerWidth (TableToInstall->Revision);
506 1.3.4.2 rmind }
507 1.3.4.2 rmind
508 1.3.4.2 rmind UnmapAndExit:
509 1.3.4.2 rmind AcpiOsUnmapMemory (MappedTable, sizeof (ACPI_TABLE_HEADER));
510 1.3.4.2 rmind }
511 1.3.4.2 rmind
512 1.3.4.2 rmind
513 1.3.4.2 rmind /*******************************************************************************
514 1.3.4.2 rmind *
515 1.3.4.2 rmind * FUNCTION: AcpiTbGetRootTableEntry
516 1.3.4.2 rmind *
517 1.3.4.2 rmind * PARAMETERS: TableEntry - Pointer to the RSDT/XSDT table entry
518 1.3.4.2 rmind * TableEntrySize - sizeof 32 or 64 (RSDT or XSDT)
519 1.3.4.2 rmind *
520 1.3.4.2 rmind * RETURN: Physical address extracted from the root table
521 1.3.4.2 rmind *
522 1.3.4.2 rmind * DESCRIPTION: Get one root table entry. Handles 32-bit and 64-bit cases on
523 1.3.4.2 rmind * both 32-bit and 64-bit platforms
524 1.3.4.2 rmind *
525 1.3.4.2 rmind * NOTE: ACPI_PHYSICAL_ADDRESS is 32-bit on 32-bit platforms, 64-bit on
526 1.3.4.2 rmind * 64-bit platforms.
527 1.3.4.2 rmind *
528 1.3.4.2 rmind ******************************************************************************/
529 1.3.4.2 rmind
530 1.3.4.2 rmind static ACPI_PHYSICAL_ADDRESS
531 1.3.4.2 rmind AcpiTbGetRootTableEntry (
532 1.3.4.2 rmind UINT8 *TableEntry,
533 1.3.4.2 rmind UINT32 TableEntrySize)
534 1.3.4.2 rmind {
535 1.3.4.2 rmind UINT64 Address64;
536 1.3.4.2 rmind
537 1.3.4.2 rmind
538 1.3.4.2 rmind /*
539 1.3.4.2 rmind * Get the table physical address (32-bit for RSDT, 64-bit for XSDT):
540 1.3.4.2 rmind * Note: Addresses are 32-bit aligned (not 64) in both RSDT and XSDT
541 1.3.4.2 rmind */
542 1.3.4.2 rmind if (TableEntrySize == sizeof (UINT32))
543 1.3.4.2 rmind {
544 1.3.4.2 rmind /*
545 1.3.4.2 rmind * 32-bit platform, RSDT: Return 32-bit table entry
546 1.3.4.2 rmind * 64-bit platform, RSDT: Expand 32-bit to 64-bit and return
547 1.3.4.2 rmind */
548 1.3.4.2 rmind return ((ACPI_PHYSICAL_ADDRESS) (*ACPI_CAST_PTR (UINT32, TableEntry)));
549 1.3.4.2 rmind }
550 1.3.4.2 rmind else
551 1.3.4.2 rmind {
552 1.3.4.2 rmind /*
553 1.3.4.2 rmind * 32-bit platform, XSDT: Truncate 64-bit to 32-bit and return
554 1.3.4.2 rmind * 64-bit platform, XSDT: Move (unaligned) 64-bit to local,
555 1.3.4.2 rmind * return 64-bit
556 1.3.4.2 rmind */
557 1.3.4.2 rmind ACPI_MOVE_64_TO_64 (&Address64, TableEntry);
558 1.3.4.2 rmind
559 1.3.4.2 rmind #if ACPI_MACHINE_WIDTH == 32
560 1.3.4.2 rmind if (Address64 > ACPI_UINT32_MAX)
561 1.3.4.2 rmind {
562 1.3.4.2 rmind /* Will truncate 64-bit address to 32 bits, issue warning */
563 1.3.4.2 rmind
564 1.3.4.2 rmind ACPI_WARNING ((AE_INFO,
565 1.3.4.2 rmind "64-bit Physical Address in XSDT is too large (0x%8.8X%8.8X),"
566 1.3.4.2 rmind " truncating",
567 1.3.4.2 rmind ACPI_FORMAT_UINT64 (Address64)));
568 1.3.4.2 rmind }
569 1.3.4.2 rmind #endif
570 1.3.4.2 rmind return ((ACPI_PHYSICAL_ADDRESS) (Address64));
571 1.3.4.2 rmind }
572 1.3.4.2 rmind }
573 1.3.4.2 rmind
574 1.3.4.2 rmind
575 1.3.4.2 rmind /*******************************************************************************
576 1.3.4.2 rmind *
577 1.3.4.2 rmind * FUNCTION: AcpiTbParseRootTable
578 1.3.4.2 rmind *
579 1.3.4.2 rmind * PARAMETERS: Rsdp - Pointer to the RSDP
580 1.3.4.2 rmind *
581 1.3.4.2 rmind * RETURN: Status
582 1.3.4.2 rmind *
583 1.3.4.2 rmind * DESCRIPTION: This function is called to parse the Root System Description
584 1.3.4.2 rmind * Table (RSDT or XSDT)
585 1.3.4.2 rmind *
586 1.3.4.2 rmind * NOTE: Tables are mapped (not copied) for efficiency. The FACS must
587 1.3.4.2 rmind * be mapped and cannot be copied because it contains the actual
588 1.3.4.2 rmind * memory location of the ACPI Global Lock.
589 1.3.4.2 rmind *
590 1.3.4.2 rmind ******************************************************************************/
591 1.3.4.2 rmind
592 1.3.4.2 rmind ACPI_STATUS
593 1.3.4.2 rmind AcpiTbParseRootTable (
594 1.3.4.2 rmind ACPI_PHYSICAL_ADDRESS RsdpAddress)
595 1.3.4.2 rmind {
596 1.3.4.2 rmind ACPI_TABLE_RSDP *Rsdp;
597 1.3.4.2 rmind UINT32 TableEntrySize;
598 1.3.4.2 rmind UINT32 i;
599 1.3.4.2 rmind UINT32 TableCount;
600 1.3.4.2 rmind ACPI_TABLE_HEADER *Table;
601 1.3.4.2 rmind ACPI_PHYSICAL_ADDRESS Address;
602 1.3.4.2 rmind UINT32 Length;
603 1.3.4.2 rmind UINT8 *TableEntry;
604 1.3.4.2 rmind ACPI_STATUS Status;
605 1.3.4.2 rmind
606 1.3.4.2 rmind
607 1.3.4.2 rmind ACPI_FUNCTION_TRACE (TbParseRootTable);
608 1.3.4.2 rmind
609 1.3.4.2 rmind
610 1.3.4.2 rmind /*
611 1.3.4.2 rmind * Map the entire RSDP and extract the address of the RSDT or XSDT
612 1.3.4.2 rmind */
613 1.3.4.2 rmind Rsdp = AcpiOsMapMemory (RsdpAddress, sizeof (ACPI_TABLE_RSDP));
614 1.3.4.2 rmind if (!Rsdp)
615 1.3.4.2 rmind {
616 1.3.4.2 rmind return_ACPI_STATUS (AE_NO_MEMORY);
617 1.3.4.2 rmind }
618 1.3.4.2 rmind
619 1.3.4.2 rmind AcpiTbPrintTableHeader (RsdpAddress,
620 1.3.4.2 rmind ACPI_CAST_PTR (ACPI_TABLE_HEADER, Rsdp));
621 1.3.4.2 rmind
622 1.3.4.2 rmind /* Differentiate between RSDT and XSDT root tables */
623 1.3.4.2 rmind
624 1.3.4.2 rmind if (Rsdp->Revision > 1 && Rsdp->XsdtPhysicalAddress)
625 1.3.4.2 rmind {
626 1.3.4.2 rmind /*
627 1.3.4.2 rmind * Root table is an XSDT (64-bit physical addresses). We must use the
628 1.3.4.2 rmind * XSDT if the revision is > 1 and the XSDT pointer is present, as per
629 1.3.4.2 rmind * the ACPI specification.
630 1.3.4.2 rmind */
631 1.3.4.2 rmind Address = (ACPI_PHYSICAL_ADDRESS) Rsdp->XsdtPhysicalAddress;
632 1.3.4.2 rmind TableEntrySize = sizeof (UINT64);
633 1.3.4.2 rmind }
634 1.3.4.2 rmind else
635 1.3.4.2 rmind {
636 1.3.4.2 rmind /* Root table is an RSDT (32-bit physical addresses) */
637 1.3.4.2 rmind
638 1.3.4.2 rmind Address = (ACPI_PHYSICAL_ADDRESS) Rsdp->RsdtPhysicalAddress;
639 1.3.4.2 rmind TableEntrySize = sizeof (UINT32);
640 1.3.4.2 rmind }
641 1.3.4.2 rmind
642 1.3.4.2 rmind /*
643 1.3.4.2 rmind * It is not possible to map more than one entry in some environments,
644 1.3.4.2 rmind * so unmap the RSDP here before mapping other tables
645 1.3.4.2 rmind */
646 1.3.4.2 rmind AcpiOsUnmapMemory (Rsdp, sizeof (ACPI_TABLE_RSDP));
647 1.3.4.2 rmind
648 1.3.4.2 rmind
649 1.3.4.2 rmind /* Map the RSDT/XSDT table header to get the full table length */
650 1.3.4.2 rmind
651 1.3.4.2 rmind Table = AcpiOsMapMemory (Address, sizeof (ACPI_TABLE_HEADER));
652 1.3.4.2 rmind if (!Table)
653 1.3.4.2 rmind {
654 1.3.4.2 rmind return_ACPI_STATUS (AE_NO_MEMORY);
655 1.3.4.2 rmind }
656 1.3.4.2 rmind
657 1.3.4.2 rmind AcpiTbPrintTableHeader (Address, Table);
658 1.3.4.2 rmind
659 1.3.4.2 rmind /* Get the length of the full table, verify length and map entire table */
660 1.3.4.2 rmind
661 1.3.4.2 rmind Length = Table->Length;
662 1.3.4.2 rmind AcpiOsUnmapMemory (Table, sizeof (ACPI_TABLE_HEADER));
663 1.3.4.2 rmind
664 1.3.4.2 rmind if (Length < sizeof (ACPI_TABLE_HEADER))
665 1.3.4.2 rmind {
666 1.3.4.2 rmind ACPI_ERROR ((AE_INFO, "Invalid length 0x%X in RSDT/XSDT", Length));
667 1.3.4.2 rmind return_ACPI_STATUS (AE_INVALID_TABLE_LENGTH);
668 1.3.4.2 rmind }
669 1.3.4.2 rmind
670 1.3.4.2 rmind Table = AcpiOsMapMemory (Address, Length);
671 1.3.4.2 rmind if (!Table)
672 1.3.4.2 rmind {
673 1.3.4.2 rmind return_ACPI_STATUS (AE_NO_MEMORY);
674 1.3.4.2 rmind }
675 1.3.4.2 rmind
676 1.3.4.2 rmind /* Validate the root table checksum */
677 1.3.4.2 rmind
678 1.3.4.2 rmind Status = AcpiTbVerifyChecksum (Table, Length);
679 1.3.4.2 rmind if (ACPI_FAILURE (Status))
680 1.3.4.2 rmind {
681 1.3.4.2 rmind AcpiOsUnmapMemory (Table, Length);
682 1.3.4.2 rmind return_ACPI_STATUS (Status);
683 1.3.4.2 rmind }
684 1.3.4.2 rmind
685 1.3.4.2 rmind /* Calculate the number of tables described in the root table */
686 1.3.4.2 rmind
687 1.3.4.2 rmind TableCount = (UINT32) ((Table->Length - sizeof (ACPI_TABLE_HEADER)) /
688 1.3.4.2 rmind TableEntrySize);
689 1.3.4.2 rmind
690 1.3.4.2 rmind /*
691 1.3.4.2 rmind * First two entries in the table array are reserved for the DSDT
692 1.3.4.2 rmind * and FACS, which are not actually present in the RSDT/XSDT - they
693 1.3.4.2 rmind * come from the FADT
694 1.3.4.2 rmind */
695 1.3.4.2 rmind TableEntry = ACPI_CAST_PTR (UINT8, Table) + sizeof (ACPI_TABLE_HEADER);
696 1.3.4.2 rmind AcpiGbl_RootTableList.CurrentTableCount = 2;
697 1.3.4.2 rmind
698 1.3.4.2 rmind /*
699 1.3.4.2 rmind * Initialize the root table array from the RSDT/XSDT
700 1.3.4.2 rmind */
701 1.3.4.2 rmind for (i = 0; i < TableCount; i++)
702 1.3.4.2 rmind {
703 1.3.4.2 rmind if (AcpiGbl_RootTableList.CurrentTableCount >=
704 1.3.4.2 rmind AcpiGbl_RootTableList.MaxTableCount)
705 1.3.4.2 rmind {
706 1.3.4.2 rmind /* There is no more room in the root table array, attempt resize */
707 1.3.4.2 rmind
708 1.3.4.2 rmind Status = AcpiTbResizeRootTableList ();
709 1.3.4.2 rmind if (ACPI_FAILURE (Status))
710 1.3.4.2 rmind {
711 1.3.4.2 rmind ACPI_WARNING ((AE_INFO, "Truncating %u table entries!",
712 1.3.4.2 rmind (unsigned) (TableCount -
713 1.3.4.2 rmind (AcpiGbl_RootTableList.CurrentTableCount - 2))));
714 1.3.4.2 rmind break;
715 1.3.4.2 rmind }
716 1.3.4.2 rmind }
717 1.3.4.2 rmind
718 1.3.4.2 rmind /* Get the table physical address (32-bit for RSDT, 64-bit for XSDT) */
719 1.3.4.2 rmind
720 1.3.4.2 rmind AcpiGbl_RootTableList.Tables[AcpiGbl_RootTableList.CurrentTableCount].Address =
721 1.3.4.2 rmind AcpiTbGetRootTableEntry (TableEntry, TableEntrySize);
722 1.3.4.2 rmind
723 1.3.4.2 rmind TableEntry += TableEntrySize;
724 1.3.4.2 rmind AcpiGbl_RootTableList.CurrentTableCount++;
725 1.3.4.2 rmind }
726 1.3.4.2 rmind
727 1.3.4.2 rmind /*
728 1.3.4.2 rmind * It is not possible to map more than one entry in some environments,
729 1.3.4.2 rmind * so unmap the root table here before mapping other tables
730 1.3.4.2 rmind */
731 1.3.4.2 rmind AcpiOsUnmapMemory (Table, Length);
732 1.3.4.2 rmind
733 1.3.4.2 rmind /*
734 1.3.4.2 rmind * Complete the initialization of the root table array by examining
735 1.3.4.2 rmind * the header of each table
736 1.3.4.2 rmind */
737 1.3.4.2 rmind for (i = 2; i < AcpiGbl_RootTableList.CurrentTableCount; i++)
738 1.3.4.2 rmind {
739 1.3.4.2 rmind AcpiTbInstallTable (AcpiGbl_RootTableList.Tables[i].Address,
740 1.3.4.2 rmind NULL, i);
741 1.3.4.2 rmind
742 1.3.4.2 rmind /* Special case for FADT - get the DSDT and FACS */
743 1.3.4.2 rmind
744 1.3.4.2 rmind if (ACPI_COMPARE_NAME (
745 1.3.4.2 rmind &AcpiGbl_RootTableList.Tables[i].Signature, ACPI_SIG_FADT))
746 1.3.4.2 rmind {
747 1.3.4.2 rmind AcpiTbParseFadt (i);
748 1.3.4.2 rmind }
749 1.3.4.2 rmind }
750 1.3.4.2 rmind
751 1.3.4.2 rmind return_ACPI_STATUS (AE_OK);
752 1.3.4.2 rmind }
753