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