tbfadt.c revision 1.2 1 1.1 jruoho /******************************************************************************
2 1.1 jruoho *
3 1.1 jruoho * Module Name: tbfadt - FADT table utilities
4 1.1 jruoho *
5 1.1 jruoho *****************************************************************************/
6 1.1 jruoho
7 1.1 jruoho /******************************************************************************
8 1.1 jruoho *
9 1.1 jruoho * 1. Copyright Notice
10 1.1 jruoho *
11 1.1 jruoho * Some or all of this work - Copyright (c) 1999 - 2010, Intel Corp.
12 1.1 jruoho * All rights reserved.
13 1.1 jruoho *
14 1.1 jruoho * 2. License
15 1.1 jruoho *
16 1.1 jruoho * 2.1. This is your license from Intel Corp. under its intellectual property
17 1.1 jruoho * rights. You may have additional license terms from the party that provided
18 1.1 jruoho * you this software, covering your right to use that party's intellectual
19 1.1 jruoho * property rights.
20 1.1 jruoho *
21 1.1 jruoho * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22 1.1 jruoho * copy of the source code appearing in this file ("Covered Code") an
23 1.1 jruoho * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24 1.1 jruoho * base code distributed originally by Intel ("Original Intel Code") to copy,
25 1.1 jruoho * make derivatives, distribute, use and display any portion of the Covered
26 1.1 jruoho * Code in any form, with the right to sublicense such rights; and
27 1.1 jruoho *
28 1.1 jruoho * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29 1.1 jruoho * license (with the right to sublicense), under only those claims of Intel
30 1.1 jruoho * patents that are infringed by the Original Intel Code, to make, use, sell,
31 1.1 jruoho * offer to sell, and import the Covered Code and derivative works thereof
32 1.1 jruoho * solely to the minimum extent necessary to exercise the above copyright
33 1.1 jruoho * license, and in no event shall the patent license extend to any additions
34 1.1 jruoho * to or modifications of the Original Intel Code. No other license or right
35 1.1 jruoho * is granted directly or by implication, estoppel or otherwise;
36 1.1 jruoho *
37 1.1 jruoho * The above copyright and patent license is granted only if the following
38 1.1 jruoho * conditions are met:
39 1.1 jruoho *
40 1.1 jruoho * 3. Conditions
41 1.1 jruoho *
42 1.1 jruoho * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43 1.1 jruoho * Redistribution of source code of any substantial portion of the Covered
44 1.1 jruoho * Code or modification with rights to further distribute source must include
45 1.1 jruoho * the above Copyright Notice, the above License, this list of Conditions,
46 1.1 jruoho * and the following Disclaimer and Export Compliance provision. In addition,
47 1.1 jruoho * Licensee must cause all Covered Code to which Licensee contributes to
48 1.1 jruoho * contain a file documenting the changes Licensee made to create that Covered
49 1.1 jruoho * Code and the date of any change. Licensee must include in that file the
50 1.1 jruoho * documentation of any changes made by any predecessor Licensee. Licensee
51 1.1 jruoho * must include a prominent statement that the modification is derived,
52 1.1 jruoho * directly or indirectly, from Original Intel Code.
53 1.1 jruoho *
54 1.1 jruoho * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55 1.1 jruoho * Redistribution of source code of any substantial portion of the Covered
56 1.1 jruoho * Code or modification without rights to further distribute source must
57 1.1 jruoho * include the following Disclaimer and Export Compliance provision in the
58 1.1 jruoho * documentation and/or other materials provided with distribution. In
59 1.1 jruoho * addition, Licensee may not authorize further sublicense of source of any
60 1.1 jruoho * portion of the Covered Code, and must include terms to the effect that the
61 1.1 jruoho * license from Licensee to its licensee is limited to the intellectual
62 1.1 jruoho * property embodied in the software Licensee provides to its licensee, and
63 1.1 jruoho * not to intellectual property embodied in modifications its licensee may
64 1.1 jruoho * make.
65 1.1 jruoho *
66 1.1 jruoho * 3.3. Redistribution of Executable. Redistribution in executable form of any
67 1.1 jruoho * substantial portion of the Covered Code or modification must reproduce the
68 1.1 jruoho * above Copyright Notice, and the following Disclaimer and Export Compliance
69 1.1 jruoho * provision in the documentation and/or other materials provided with the
70 1.1 jruoho * distribution.
71 1.1 jruoho *
72 1.1 jruoho * 3.4. Intel retains all right, title, and interest in and to the Original
73 1.1 jruoho * Intel Code.
74 1.1 jruoho *
75 1.1 jruoho * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76 1.1 jruoho * Intel shall be used in advertising or otherwise to promote the sale, use or
77 1.1 jruoho * other dealings in products derived from or relating to the Covered Code
78 1.1 jruoho * without prior written authorization from Intel.
79 1.1 jruoho *
80 1.1 jruoho * 4. Disclaimer and Export Compliance
81 1.1 jruoho *
82 1.1 jruoho * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83 1.1 jruoho * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84 1.1 jruoho * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85 1.1 jruoho * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86 1.1 jruoho * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87 1.1 jruoho * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
88 1.1 jruoho * PARTICULAR PURPOSE.
89 1.1 jruoho *
90 1.1 jruoho * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91 1.1 jruoho * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92 1.1 jruoho * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93 1.1 jruoho * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94 1.1 jruoho * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95 1.1 jruoho * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96 1.1 jruoho * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
97 1.1 jruoho * LIMITED REMEDY.
98 1.1 jruoho *
99 1.1 jruoho * 4.3. Licensee shall not export, either directly or indirectly, any of this
100 1.1 jruoho * software or system incorporating such software without first obtaining any
101 1.1 jruoho * required license or other approval from the U. S. Department of Commerce or
102 1.1 jruoho * any other agency or department of the United States Government. In the
103 1.1 jruoho * event Licensee exports any such software from the United States or
104 1.1 jruoho * re-exports any such software from a foreign destination, Licensee shall
105 1.1 jruoho * ensure that the distribution and export/re-export of the software is in
106 1.1 jruoho * compliance with all laws, regulations, orders, or other restrictions of the
107 1.1 jruoho * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108 1.1 jruoho * any of its subsidiaries will export/re-export any technical data, process,
109 1.1 jruoho * software, or service, directly or indirectly, to any country for which the
110 1.1 jruoho * United States government or any agency thereof requires an export license,
111 1.1 jruoho * other governmental approval, or letter of assurance, without first obtaining
112 1.1 jruoho * such license, approval or letter.
113 1.1 jruoho *
114 1.1 jruoho *****************************************************************************/
115 1.1 jruoho
116 1.1 jruoho #define __TBFADT_C__
117 1.1 jruoho
118 1.1 jruoho #include "acpi.h"
119 1.1 jruoho #include "accommon.h"
120 1.1 jruoho #include "actables.h"
121 1.1 jruoho
122 1.1 jruoho #define _COMPONENT ACPI_TABLES
123 1.1 jruoho ACPI_MODULE_NAME ("tbfadt")
124 1.1 jruoho
125 1.1 jruoho /* Local prototypes */
126 1.1 jruoho
127 1.1 jruoho static inline void
128 1.1 jruoho AcpiTbInitGenericAddress (
129 1.1 jruoho ACPI_GENERIC_ADDRESS *GenericAddress,
130 1.1 jruoho UINT8 SpaceId,
131 1.1 jruoho UINT8 ByteWidth,
132 1.1 jruoho UINT64 Address);
133 1.1 jruoho
134 1.1 jruoho static void
135 1.1 jruoho AcpiTbConvertFadt (
136 1.1 jruoho void);
137 1.1 jruoho
138 1.1 jruoho static void
139 1.1 jruoho AcpiTbValidateFadt (
140 1.1 jruoho void);
141 1.1 jruoho
142 1.1 jruoho static void
143 1.1 jruoho AcpiTbSetupFadtRegisters (
144 1.1 jruoho void);
145 1.1 jruoho
146 1.1 jruoho
147 1.1 jruoho /* Table for conversion of FADT to common internal format and FADT validation */
148 1.1 jruoho
149 1.1 jruoho typedef struct acpi_fadt_info
150 1.1 jruoho {
151 1.2 jruoho const char *Name;
152 1.1 jruoho UINT8 Address64;
153 1.1 jruoho UINT8 Address32;
154 1.1 jruoho UINT8 Length;
155 1.1 jruoho UINT8 DefaultLength;
156 1.1 jruoho UINT8 Type;
157 1.1 jruoho
158 1.1 jruoho } ACPI_FADT_INFO;
159 1.1 jruoho
160 1.1 jruoho #define ACPI_FADT_REQUIRED 1
161 1.1 jruoho #define ACPI_FADT_SEPARATE_LENGTH 2
162 1.1 jruoho
163 1.1 jruoho static ACPI_FADT_INFO FadtInfoTable[] =
164 1.1 jruoho {
165 1.1 jruoho {"Pm1aEventBlock",
166 1.1 jruoho ACPI_FADT_OFFSET (XPm1aEventBlock),
167 1.1 jruoho ACPI_FADT_OFFSET (Pm1aEventBlock),
168 1.1 jruoho ACPI_FADT_OFFSET (Pm1EventLength),
169 1.1 jruoho ACPI_PM1_REGISTER_WIDTH * 2, /* Enable + Status register */
170 1.1 jruoho ACPI_FADT_REQUIRED},
171 1.1 jruoho
172 1.1 jruoho {"Pm1bEventBlock",
173 1.1 jruoho ACPI_FADT_OFFSET (XPm1bEventBlock),
174 1.1 jruoho ACPI_FADT_OFFSET (Pm1bEventBlock),
175 1.1 jruoho ACPI_FADT_OFFSET (Pm1EventLength),
176 1.1 jruoho ACPI_PM1_REGISTER_WIDTH * 2, /* Enable + Status register */
177 1.1 jruoho 0},
178 1.1 jruoho
179 1.1 jruoho {"Pm1aControlBlock",
180 1.1 jruoho ACPI_FADT_OFFSET (XPm1aControlBlock),
181 1.1 jruoho ACPI_FADT_OFFSET (Pm1aControlBlock),
182 1.1 jruoho ACPI_FADT_OFFSET (Pm1ControlLength),
183 1.1 jruoho ACPI_PM1_REGISTER_WIDTH,
184 1.1 jruoho ACPI_FADT_REQUIRED},
185 1.1 jruoho
186 1.1 jruoho {"Pm1bControlBlock",
187 1.1 jruoho ACPI_FADT_OFFSET (XPm1bControlBlock),
188 1.1 jruoho ACPI_FADT_OFFSET (Pm1bControlBlock),
189 1.1 jruoho ACPI_FADT_OFFSET (Pm1ControlLength),
190 1.1 jruoho ACPI_PM1_REGISTER_WIDTH,
191 1.1 jruoho 0},
192 1.1 jruoho
193 1.1 jruoho {"Pm2ControlBlock",
194 1.1 jruoho ACPI_FADT_OFFSET (XPm2ControlBlock),
195 1.1 jruoho ACPI_FADT_OFFSET (Pm2ControlBlock),
196 1.1 jruoho ACPI_FADT_OFFSET (Pm2ControlLength),
197 1.1 jruoho ACPI_PM2_REGISTER_WIDTH,
198 1.1 jruoho ACPI_FADT_SEPARATE_LENGTH},
199 1.1 jruoho
200 1.1 jruoho {"PmTimerBlock",
201 1.1 jruoho ACPI_FADT_OFFSET (XPmTimerBlock),
202 1.1 jruoho ACPI_FADT_OFFSET (PmTimerBlock),
203 1.1 jruoho ACPI_FADT_OFFSET (PmTimerLength),
204 1.1 jruoho ACPI_PM_TIMER_WIDTH,
205 1.1 jruoho ACPI_FADT_REQUIRED},
206 1.1 jruoho
207 1.1 jruoho {"Gpe0Block",
208 1.1 jruoho ACPI_FADT_OFFSET (XGpe0Block),
209 1.1 jruoho ACPI_FADT_OFFSET (Gpe0Block),
210 1.1 jruoho ACPI_FADT_OFFSET (Gpe0BlockLength),
211 1.1 jruoho 0,
212 1.1 jruoho ACPI_FADT_SEPARATE_LENGTH},
213 1.1 jruoho
214 1.1 jruoho {"Gpe1Block",
215 1.1 jruoho ACPI_FADT_OFFSET (XGpe1Block),
216 1.1 jruoho ACPI_FADT_OFFSET (Gpe1Block),
217 1.1 jruoho ACPI_FADT_OFFSET (Gpe1BlockLength),
218 1.1 jruoho 0,
219 1.1 jruoho ACPI_FADT_SEPARATE_LENGTH}
220 1.1 jruoho };
221 1.1 jruoho
222 1.1 jruoho #define ACPI_FADT_INFO_ENTRIES \
223 1.1 jruoho (sizeof (FadtInfoTable) / sizeof (ACPI_FADT_INFO))
224 1.1 jruoho
225 1.1 jruoho
226 1.1 jruoho /* Table used to split Event Blocks into separate status/enable registers */
227 1.1 jruoho
228 1.1 jruoho typedef struct acpi_fadt_pm_info
229 1.1 jruoho {
230 1.1 jruoho ACPI_GENERIC_ADDRESS *Target;
231 1.1 jruoho UINT8 Source;
232 1.1 jruoho UINT8 RegisterNum;
233 1.1 jruoho
234 1.1 jruoho } ACPI_FADT_PM_INFO;
235 1.1 jruoho
236 1.1 jruoho static ACPI_FADT_PM_INFO FadtPmInfoTable[] =
237 1.1 jruoho {
238 1.1 jruoho {&AcpiGbl_XPm1aStatus,
239 1.1 jruoho ACPI_FADT_OFFSET (XPm1aEventBlock),
240 1.1 jruoho 0},
241 1.1 jruoho
242 1.1 jruoho {&AcpiGbl_XPm1aEnable,
243 1.1 jruoho ACPI_FADT_OFFSET (XPm1aEventBlock),
244 1.1 jruoho 1},
245 1.1 jruoho
246 1.1 jruoho {&AcpiGbl_XPm1bStatus,
247 1.1 jruoho ACPI_FADT_OFFSET (XPm1bEventBlock),
248 1.1 jruoho 0},
249 1.1 jruoho
250 1.1 jruoho {&AcpiGbl_XPm1bEnable,
251 1.1 jruoho ACPI_FADT_OFFSET (XPm1bEventBlock),
252 1.1 jruoho 1}
253 1.1 jruoho };
254 1.1 jruoho
255 1.1 jruoho #define ACPI_FADT_PM_INFO_ENTRIES \
256 1.1 jruoho (sizeof (FadtPmInfoTable) / sizeof (ACPI_FADT_PM_INFO))
257 1.1 jruoho
258 1.1 jruoho
259 1.1 jruoho /*******************************************************************************
260 1.1 jruoho *
261 1.1 jruoho * FUNCTION: AcpiTbInitGenericAddress
262 1.1 jruoho *
263 1.1 jruoho * PARAMETERS: GenericAddress - GAS struct to be initialized
264 1.1 jruoho * SpaceId - ACPI Space ID for this register
265 1.1 jruoho * ByteWidth - Width of this register, in bytes
266 1.1 jruoho * Address - Address of the register
267 1.1 jruoho *
268 1.1 jruoho * RETURN: None
269 1.1 jruoho *
270 1.1 jruoho * DESCRIPTION: Initialize a Generic Address Structure (GAS)
271 1.1 jruoho * See the ACPI specification for a full description and
272 1.1 jruoho * definition of this structure.
273 1.1 jruoho *
274 1.1 jruoho ******************************************************************************/
275 1.1 jruoho
276 1.1 jruoho static inline void
277 1.1 jruoho AcpiTbInitGenericAddress (
278 1.1 jruoho ACPI_GENERIC_ADDRESS *GenericAddress,
279 1.1 jruoho UINT8 SpaceId,
280 1.1 jruoho UINT8 ByteWidth,
281 1.1 jruoho UINT64 Address)
282 1.1 jruoho {
283 1.1 jruoho
284 1.1 jruoho /*
285 1.1 jruoho * The 64-bit Address field is non-aligned in the byte packed
286 1.1 jruoho * GAS struct.
287 1.1 jruoho */
288 1.1 jruoho ACPI_MOVE_64_TO_64 (&GenericAddress->Address, &Address);
289 1.1 jruoho
290 1.1 jruoho /* All other fields are byte-wide */
291 1.1 jruoho
292 1.1 jruoho GenericAddress->SpaceId = SpaceId;
293 1.1 jruoho GenericAddress->BitWidth = (UINT8) ACPI_MUL_8 (ByteWidth);
294 1.1 jruoho GenericAddress->BitOffset = 0;
295 1.1 jruoho GenericAddress->AccessWidth = 0; /* Access width ANY */
296 1.1 jruoho }
297 1.1 jruoho
298 1.1 jruoho
299 1.1 jruoho /*******************************************************************************
300 1.1 jruoho *
301 1.1 jruoho * FUNCTION: AcpiTbParseFadt
302 1.1 jruoho *
303 1.1 jruoho * PARAMETERS: TableIndex - Index for the FADT
304 1.1 jruoho *
305 1.1 jruoho * RETURN: None
306 1.1 jruoho *
307 1.1 jruoho * DESCRIPTION: Initialize the FADT, DSDT and FACS tables
308 1.1 jruoho * (FADT contains the addresses of the DSDT and FACS)
309 1.1 jruoho *
310 1.1 jruoho ******************************************************************************/
311 1.1 jruoho
312 1.1 jruoho void
313 1.1 jruoho AcpiTbParseFadt (
314 1.1 jruoho UINT32 TableIndex)
315 1.1 jruoho {
316 1.1 jruoho UINT32 Length;
317 1.1 jruoho ACPI_TABLE_HEADER *Table;
318 1.1 jruoho
319 1.1 jruoho
320 1.1 jruoho /*
321 1.1 jruoho * The FADT has multiple versions with different lengths,
322 1.1 jruoho * and it contains pointers to both the DSDT and FACS tables.
323 1.1 jruoho *
324 1.1 jruoho * Get a local copy of the FADT and convert it to a common format
325 1.1 jruoho * Map entire FADT, assumed to be smaller than one page.
326 1.1 jruoho */
327 1.1 jruoho Length = AcpiGbl_RootTableList.Tables[TableIndex].Length;
328 1.1 jruoho
329 1.1 jruoho Table = AcpiOsMapMemory (
330 1.1 jruoho AcpiGbl_RootTableList.Tables[TableIndex].Address, Length);
331 1.1 jruoho if (!Table)
332 1.1 jruoho {
333 1.1 jruoho return;
334 1.1 jruoho }
335 1.1 jruoho
336 1.1 jruoho /*
337 1.1 jruoho * Validate the FADT checksum before we copy the table. Ignore
338 1.1 jruoho * checksum error as we want to try to get the DSDT and FACS.
339 1.1 jruoho */
340 1.1 jruoho (void) AcpiTbVerifyChecksum (Table, Length);
341 1.1 jruoho
342 1.1 jruoho /* Create a local copy of the FADT in common ACPI 2.0+ format */
343 1.1 jruoho
344 1.1 jruoho AcpiTbCreateLocalFadt (Table, Length);
345 1.1 jruoho
346 1.1 jruoho /* All done with the real FADT, unmap it */
347 1.1 jruoho
348 1.1 jruoho AcpiOsUnmapMemory (Table, Length);
349 1.1 jruoho
350 1.1 jruoho /* Obtain the DSDT and FACS tables via their addresses within the FADT */
351 1.1 jruoho
352 1.1 jruoho AcpiTbInstallTable ((ACPI_PHYSICAL_ADDRESS) AcpiGbl_FADT.XDsdt,
353 1.1 jruoho ACPI_SIG_DSDT, ACPI_TABLE_INDEX_DSDT);
354 1.1 jruoho
355 1.1 jruoho AcpiTbInstallTable ((ACPI_PHYSICAL_ADDRESS) AcpiGbl_FADT.XFacs,
356 1.1 jruoho ACPI_SIG_FACS, ACPI_TABLE_INDEX_FACS);
357 1.1 jruoho }
358 1.1 jruoho
359 1.1 jruoho
360 1.1 jruoho /*******************************************************************************
361 1.1 jruoho *
362 1.1 jruoho * FUNCTION: AcpiTbCreateLocalFadt
363 1.1 jruoho *
364 1.1 jruoho * PARAMETERS: Table - Pointer to BIOS FADT
365 1.1 jruoho * Length - Length of the table
366 1.1 jruoho *
367 1.1 jruoho * RETURN: None
368 1.1 jruoho *
369 1.1 jruoho * DESCRIPTION: Get a local copy of the FADT and convert it to a common format.
370 1.1 jruoho * Performs validation on some important FADT fields.
371 1.1 jruoho *
372 1.1 jruoho * NOTE: We create a local copy of the FADT regardless of the version.
373 1.1 jruoho *
374 1.1 jruoho ******************************************************************************/
375 1.1 jruoho
376 1.1 jruoho void
377 1.1 jruoho AcpiTbCreateLocalFadt (
378 1.1 jruoho ACPI_TABLE_HEADER *Table,
379 1.1 jruoho UINT32 Length)
380 1.1 jruoho {
381 1.1 jruoho
382 1.1 jruoho /*
383 1.1 jruoho * Check if the FADT is larger than the largest table that we expect
384 1.1 jruoho * (the ACPI 2.0/3.0 version). If so, truncate the table, and issue
385 1.1 jruoho * a warning.
386 1.1 jruoho */
387 1.1 jruoho if (Length > sizeof (ACPI_TABLE_FADT))
388 1.1 jruoho {
389 1.1 jruoho ACPI_WARNING ((AE_INFO,
390 1.1 jruoho "FADT (revision %u) is longer than ACPI 2.0 version, "
391 1.1 jruoho "truncating length %u to %u",
392 1.1 jruoho Table->Revision, Length, (UINT32) sizeof (ACPI_TABLE_FADT)));
393 1.1 jruoho }
394 1.1 jruoho
395 1.1 jruoho /* Clear the entire local FADT */
396 1.1 jruoho
397 1.1 jruoho ACPI_MEMSET (&AcpiGbl_FADT, 0, sizeof (ACPI_TABLE_FADT));
398 1.1 jruoho
399 1.1 jruoho /* Copy the original FADT, up to sizeof (ACPI_TABLE_FADT) */
400 1.1 jruoho
401 1.1 jruoho ACPI_MEMCPY (&AcpiGbl_FADT, Table,
402 1.1 jruoho ACPI_MIN (Length, sizeof (ACPI_TABLE_FADT)));
403 1.1 jruoho
404 1.1 jruoho /* Convert the local copy of the FADT to the common internal format */
405 1.1 jruoho
406 1.1 jruoho AcpiTbConvertFadt ();
407 1.1 jruoho
408 1.1 jruoho /* Validate FADT values now, before we make any changes */
409 1.1 jruoho
410 1.1 jruoho AcpiTbValidateFadt ();
411 1.1 jruoho
412 1.1 jruoho /* Initialize the global ACPI register structures */
413 1.1 jruoho
414 1.1 jruoho AcpiTbSetupFadtRegisters ();
415 1.1 jruoho }
416 1.1 jruoho
417 1.1 jruoho
418 1.1 jruoho /*******************************************************************************
419 1.1 jruoho *
420 1.1 jruoho * FUNCTION: AcpiTbConvertFadt
421 1.1 jruoho *
422 1.1 jruoho * PARAMETERS: None, uses AcpiGbl_FADT
423 1.1 jruoho *
424 1.1 jruoho * RETURN: None
425 1.1 jruoho *
426 1.1 jruoho * DESCRIPTION: Converts all versions of the FADT to a common internal format.
427 1.1 jruoho * Expand 32-bit addresses to 64-bit as necessary.
428 1.1 jruoho *
429 1.1 jruoho * NOTE: AcpiGbl_FADT must be of size (ACPI_TABLE_FADT),
430 1.1 jruoho * and must contain a copy of the actual FADT.
431 1.1 jruoho *
432 1.1 jruoho * Notes on 64-bit register addresses:
433 1.1 jruoho *
434 1.1 jruoho * After this FADT conversion, later ACPICA code will only use the 64-bit "X"
435 1.1 jruoho * fields of the FADT for all ACPI register addresses.
436 1.1 jruoho *
437 1.1 jruoho * The 64-bit "X" fields are optional extensions to the original 32-bit FADT
438 1.1 jruoho * V1.0 fields. Even if they are present in the FADT, they are optional and
439 1.1 jruoho * are unused if the BIOS sets them to zero. Therefore, we must copy/expand
440 1.1 jruoho * 32-bit V1.0 fields if the corresponding X field is zero.
441 1.1 jruoho *
442 1.1 jruoho * For ACPI 1.0 FADTs, all 32-bit address fields are expanded to the
443 1.1 jruoho * corresponding "X" fields in the internal FADT.
444 1.1 jruoho *
445 1.1 jruoho * For ACPI 2.0+ FADTs, all valid (non-zero) 32-bit address fields are expanded
446 1.1 jruoho * to the corresponding 64-bit X fields. For compatibility with other ACPI
447 1.1 jruoho * implementations, we ignore the 64-bit field if the 32-bit field is valid,
448 1.1 jruoho * regardless of whether the host OS is 32-bit or 64-bit.
449 1.1 jruoho *
450 1.1 jruoho ******************************************************************************/
451 1.1 jruoho
452 1.1 jruoho static void
453 1.1 jruoho AcpiTbConvertFadt (
454 1.1 jruoho void)
455 1.1 jruoho {
456 1.1 jruoho ACPI_GENERIC_ADDRESS *Address64;
457 1.1 jruoho UINT32 Address32;
458 1.1 jruoho UINT32 i;
459 1.1 jruoho
460 1.1 jruoho
461 1.1 jruoho /* Update the local FADT table header length */
462 1.1 jruoho
463 1.1 jruoho AcpiGbl_FADT.Header.Length = sizeof (ACPI_TABLE_FADT);
464 1.1 jruoho
465 1.1 jruoho /*
466 1.1 jruoho * Expand the 32-bit FACS and DSDT addresses to 64-bit as necessary.
467 1.1 jruoho * Later code will always use the X 64-bit field.
468 1.1 jruoho */
469 1.1 jruoho if (!AcpiGbl_FADT.XFacs)
470 1.1 jruoho {
471 1.1 jruoho AcpiGbl_FADT.XFacs = (UINT64) AcpiGbl_FADT.Facs;
472 1.1 jruoho }
473 1.1 jruoho if (!AcpiGbl_FADT.XDsdt)
474 1.1 jruoho {
475 1.1 jruoho AcpiGbl_FADT.XDsdt = (UINT64) AcpiGbl_FADT.Dsdt;
476 1.1 jruoho }
477 1.1 jruoho
478 1.1 jruoho /*
479 1.1 jruoho * For ACPI 1.0 FADTs (revision 1 or 2), ensure that reserved fields which
480 1.1 jruoho * should be zero are indeed zero. This will workaround BIOSs that
481 1.1 jruoho * inadvertently place values in these fields.
482 1.1 jruoho *
483 1.1 jruoho * The ACPI 1.0 reserved fields that will be zeroed are the bytes located
484 1.1 jruoho * at offset 45, 55, 95, and the word located at offset 109, 110.
485 1.1 jruoho */
486 1.1 jruoho if (AcpiGbl_FADT.Header.Revision < 3)
487 1.1 jruoho {
488 1.1 jruoho AcpiGbl_FADT.PreferredProfile = 0;
489 1.1 jruoho AcpiGbl_FADT.PstateControl = 0;
490 1.1 jruoho AcpiGbl_FADT.CstControl = 0;
491 1.1 jruoho AcpiGbl_FADT.BootFlags = 0;
492 1.1 jruoho }
493 1.1 jruoho
494 1.1 jruoho /*
495 1.1 jruoho * Expand the ACPI 1.0 32-bit addresses to the ACPI 2.0 64-bit "X"
496 1.1 jruoho * generic address structures as necessary. Later code will always use
497 1.1 jruoho * the 64-bit address structures.
498 1.1 jruoho *
499 1.1 jruoho * March 2009:
500 1.1 jruoho * We now always use the 32-bit address if it is valid (non-null). This
501 1.1 jruoho * is not in accordance with the ACPI specification which states that
502 1.1 jruoho * the 64-bit address supersedes the 32-bit version, but we do this for
503 1.1 jruoho * compatibility with other ACPI implementations. Most notably, in the
504 1.1 jruoho * case where both the 32 and 64 versions are non-null, we use the 32-bit
505 1.1 jruoho * version. This is the only address that is guaranteed to have been
506 1.1 jruoho * tested by the BIOS manufacturer.
507 1.1 jruoho */
508 1.1 jruoho for (i = 0; i < ACPI_FADT_INFO_ENTRIES; i++)
509 1.1 jruoho {
510 1.1 jruoho Address32 = *ACPI_ADD_PTR (UINT32,
511 1.1 jruoho &AcpiGbl_FADT, FadtInfoTable[i].Address32);
512 1.1 jruoho
513 1.1 jruoho Address64 = ACPI_ADD_PTR (ACPI_GENERIC_ADDRESS,
514 1.1 jruoho &AcpiGbl_FADT, FadtInfoTable[i].Address64);
515 1.1 jruoho
516 1.1 jruoho /*
517 1.1 jruoho * If both 32- and 64-bit addresses are valid (non-zero),
518 1.1 jruoho * they must match.
519 1.1 jruoho */
520 1.1 jruoho if (Address64->Address && Address32 &&
521 1.1 jruoho (Address64->Address != (UINT64) Address32))
522 1.1 jruoho {
523 1.1 jruoho ACPI_ERROR ((AE_INFO,
524 1.1 jruoho "32/64X address mismatch in %s: 0x%8.8X/0x%8.8X%8.8X, using 32",
525 1.1 jruoho FadtInfoTable[i].Name, Address32,
526 1.1 jruoho ACPI_FORMAT_UINT64 (Address64->Address)));
527 1.1 jruoho }
528 1.1 jruoho
529 1.1 jruoho /* Always use 32-bit address if it is valid (non-null) */
530 1.1 jruoho
531 1.1 jruoho if (Address32)
532 1.1 jruoho {
533 1.1 jruoho /*
534 1.1 jruoho * Copy the 32-bit address to the 64-bit GAS structure. The
535 1.1 jruoho * Space ID is always I/O for 32-bit legacy address fields
536 1.1 jruoho */
537 1.1 jruoho AcpiTbInitGenericAddress (Address64, ACPI_ADR_SPACE_SYSTEM_IO,
538 1.1 jruoho *ACPI_ADD_PTR (UINT8, &AcpiGbl_FADT, FadtInfoTable[i].Length),
539 1.1 jruoho (UINT64) Address32);
540 1.1 jruoho }
541 1.1 jruoho }
542 1.1 jruoho }
543 1.1 jruoho
544 1.1 jruoho
545 1.1 jruoho /*******************************************************************************
546 1.1 jruoho *
547 1.1 jruoho * FUNCTION: AcpiTbValidateFadt
548 1.1 jruoho *
549 1.1 jruoho * PARAMETERS: Table - Pointer to the FADT to be validated
550 1.1 jruoho *
551 1.1 jruoho * RETURN: None
552 1.1 jruoho *
553 1.1 jruoho * DESCRIPTION: Validate various important fields within the FADT. If a problem
554 1.1 jruoho * is found, issue a message, but no status is returned.
555 1.1 jruoho * Used by both the table manager and the disassembler.
556 1.1 jruoho *
557 1.1 jruoho * Possible additional checks:
558 1.1 jruoho * (AcpiGbl_FADT.Pm1EventLength >= 4)
559 1.1 jruoho * (AcpiGbl_FADT.Pm1ControlLength >= 2)
560 1.1 jruoho * (AcpiGbl_FADT.PmTimerLength >= 4)
561 1.1 jruoho * Gpe block lengths must be multiple of 2
562 1.1 jruoho *
563 1.1 jruoho ******************************************************************************/
564 1.1 jruoho
565 1.1 jruoho static void
566 1.1 jruoho AcpiTbValidateFadt (
567 1.1 jruoho void)
568 1.1 jruoho {
569 1.2 jruoho const char *Name;
570 1.1 jruoho ACPI_GENERIC_ADDRESS *Address64;
571 1.1 jruoho UINT8 Length;
572 1.1 jruoho UINT32 i;
573 1.1 jruoho
574 1.1 jruoho
575 1.1 jruoho /*
576 1.1 jruoho * Check for FACS and DSDT address mismatches. An address mismatch between
577 1.1 jruoho * the 32-bit and 64-bit address fields (FIRMWARE_CTRL/X_FIRMWARE_CTRL and
578 1.1 jruoho * DSDT/X_DSDT) would indicate the presence of two FACS or two DSDT tables.
579 1.1 jruoho */
580 1.1 jruoho if (AcpiGbl_FADT.Facs &&
581 1.1 jruoho (AcpiGbl_FADT.XFacs != (UINT64) AcpiGbl_FADT.Facs))
582 1.1 jruoho {
583 1.1 jruoho ACPI_WARNING ((AE_INFO,
584 1.1 jruoho "32/64X FACS address mismatch in FADT - "
585 1.1 jruoho "0x%8.8X/0x%8.8X%8.8X, using 32",
586 1.1 jruoho AcpiGbl_FADT.Facs, ACPI_FORMAT_UINT64 (AcpiGbl_FADT.XFacs)));
587 1.1 jruoho
588 1.1 jruoho AcpiGbl_FADT.XFacs = (UINT64) AcpiGbl_FADT.Facs;
589 1.1 jruoho }
590 1.1 jruoho
591 1.1 jruoho if (AcpiGbl_FADT.Dsdt &&
592 1.1 jruoho (AcpiGbl_FADT.XDsdt != (UINT64) AcpiGbl_FADT.Dsdt))
593 1.1 jruoho {
594 1.1 jruoho ACPI_WARNING ((AE_INFO,
595 1.1 jruoho "32/64X DSDT address mismatch in FADT - "
596 1.1 jruoho "0x%8.8X/0x%8.8X%8.8X, using 32",
597 1.1 jruoho AcpiGbl_FADT.Dsdt, ACPI_FORMAT_UINT64 (AcpiGbl_FADT.XDsdt)));
598 1.1 jruoho
599 1.1 jruoho AcpiGbl_FADT.XDsdt = (UINT64) AcpiGbl_FADT.Dsdt;
600 1.1 jruoho }
601 1.1 jruoho
602 1.1 jruoho /* Examine all of the 64-bit extended address fields (X fields) */
603 1.1 jruoho
604 1.1 jruoho for (i = 0; i < ACPI_FADT_INFO_ENTRIES; i++)
605 1.1 jruoho {
606 1.1 jruoho /*
607 1.1 jruoho * Generate pointer to the 64-bit address, get the register
608 1.1 jruoho * length (width) and the register name
609 1.1 jruoho */
610 1.1 jruoho Address64 = ACPI_ADD_PTR (ACPI_GENERIC_ADDRESS,
611 1.1 jruoho &AcpiGbl_FADT, FadtInfoTable[i].Address64);
612 1.1 jruoho Length = *ACPI_ADD_PTR (UINT8,
613 1.1 jruoho &AcpiGbl_FADT, FadtInfoTable[i].Length);
614 1.1 jruoho Name = FadtInfoTable[i].Name;
615 1.1 jruoho
616 1.1 jruoho /*
617 1.1 jruoho * For each extended field, check for length mismatch between the
618 1.1 jruoho * legacy length field and the corresponding 64-bit X length field.
619 1.1 jruoho */
620 1.1 jruoho if (Address64->Address &&
621 1.1 jruoho (Address64->BitWidth != ACPI_MUL_8 (Length)))
622 1.1 jruoho {
623 1.1 jruoho ACPI_WARNING ((AE_INFO,
624 1.1 jruoho "32/64X length mismatch in %s: %u/%u",
625 1.1 jruoho Name, ACPI_MUL_8 (Length), Address64->BitWidth));
626 1.1 jruoho }
627 1.1 jruoho
628 1.1 jruoho if (FadtInfoTable[i].Type & ACPI_FADT_REQUIRED)
629 1.1 jruoho {
630 1.1 jruoho /*
631 1.1 jruoho * Field is required (PM1aEvent, PM1aControl, PmTimer).
632 1.1 jruoho * Both the address and length must be non-zero.
633 1.1 jruoho */
634 1.1 jruoho if (!Address64->Address || !Length)
635 1.1 jruoho {
636 1.1 jruoho ACPI_ERROR ((AE_INFO,
637 1.1 jruoho "Required field %s has zero address and/or length:"
638 1.1 jruoho " 0x%8.8X%8.8X/0x%X",
639 1.1 jruoho Name, ACPI_FORMAT_UINT64 (Address64->Address), Length));
640 1.1 jruoho }
641 1.1 jruoho }
642 1.1 jruoho else if (FadtInfoTable[i].Type & ACPI_FADT_SEPARATE_LENGTH)
643 1.1 jruoho {
644 1.1 jruoho /*
645 1.1 jruoho * Field is optional (PM2Control, GPE0, GPE1) AND has its own
646 1.1 jruoho * length field. If present, both the address and length must
647 1.1 jruoho * be valid.
648 1.1 jruoho */
649 1.1 jruoho if ((Address64->Address && !Length) ||
650 1.1 jruoho (!Address64->Address && Length))
651 1.1 jruoho {
652 1.1 jruoho ACPI_WARNING ((AE_INFO,
653 1.1 jruoho "Optional field %s has zero address or length: "
654 1.1 jruoho "0x%8.8X%8.8X/0x%X",
655 1.1 jruoho Name, ACPI_FORMAT_UINT64 (Address64->Address), Length));
656 1.1 jruoho }
657 1.1 jruoho }
658 1.1 jruoho }
659 1.1 jruoho }
660 1.1 jruoho
661 1.1 jruoho
662 1.1 jruoho /*******************************************************************************
663 1.1 jruoho *
664 1.1 jruoho * FUNCTION: AcpiTbSetupFadtRegisters
665 1.1 jruoho *
666 1.1 jruoho * PARAMETERS: None, uses AcpiGbl_FADT.
667 1.1 jruoho *
668 1.1 jruoho * RETURN: None
669 1.1 jruoho *
670 1.1 jruoho * DESCRIPTION: Initialize global ACPI PM1 register definitions. Optionally,
671 1.1 jruoho * force FADT register definitions to their default lengths.
672 1.1 jruoho *
673 1.1 jruoho ******************************************************************************/
674 1.1 jruoho
675 1.1 jruoho static void
676 1.1 jruoho AcpiTbSetupFadtRegisters (
677 1.1 jruoho void)
678 1.1 jruoho {
679 1.1 jruoho ACPI_GENERIC_ADDRESS *Target64;
680 1.1 jruoho ACPI_GENERIC_ADDRESS *Source64;
681 1.1 jruoho UINT8 Pm1RegisterByteWidth;
682 1.1 jruoho UINT32 i;
683 1.1 jruoho
684 1.1 jruoho
685 1.1 jruoho /*
686 1.1 jruoho * Optionally check all register lengths against the default values and
687 1.1 jruoho * update them if they are incorrect.
688 1.1 jruoho */
689 1.1 jruoho if (AcpiGbl_UseDefaultRegisterWidths)
690 1.1 jruoho {
691 1.1 jruoho for (i = 0; i < ACPI_FADT_INFO_ENTRIES; i++)
692 1.1 jruoho {
693 1.1 jruoho Target64 = ACPI_ADD_PTR (ACPI_GENERIC_ADDRESS, &AcpiGbl_FADT,
694 1.1 jruoho FadtInfoTable[i].Address64);
695 1.1 jruoho
696 1.1 jruoho /*
697 1.1 jruoho * If a valid register (Address != 0) and the (DefaultLength > 0)
698 1.1 jruoho * (Not a GPE register), then check the width against the default.
699 1.1 jruoho */
700 1.1 jruoho if ((Target64->Address) &&
701 1.1 jruoho (FadtInfoTable[i].DefaultLength > 0) &&
702 1.1 jruoho (FadtInfoTable[i].DefaultLength != Target64->BitWidth))
703 1.1 jruoho {
704 1.1 jruoho ACPI_WARNING ((AE_INFO,
705 1.1 jruoho "Invalid length for %s: %u, using default %u",
706 1.1 jruoho FadtInfoTable[i].Name, Target64->BitWidth,
707 1.1 jruoho FadtInfoTable[i].DefaultLength));
708 1.1 jruoho
709 1.1 jruoho /* Incorrect size, set width to the default */
710 1.1 jruoho
711 1.1 jruoho Target64->BitWidth = FadtInfoTable[i].DefaultLength;
712 1.1 jruoho }
713 1.1 jruoho }
714 1.1 jruoho }
715 1.1 jruoho
716 1.1 jruoho /*
717 1.1 jruoho * Get the length of the individual PM1 registers (enable and status).
718 1.1 jruoho * Each register is defined to be (event block length / 2). Extra divide
719 1.1 jruoho * by 8 converts bits to bytes.
720 1.1 jruoho */
721 1.1 jruoho Pm1RegisterByteWidth = (UINT8)
722 1.1 jruoho ACPI_DIV_16 (AcpiGbl_FADT.XPm1aEventBlock.BitWidth);
723 1.1 jruoho
724 1.1 jruoho /*
725 1.1 jruoho * Calculate separate GAS structs for the PM1x (A/B) Status and Enable
726 1.1 jruoho * registers. These addresses do not appear (directly) in the FADT, so it
727 1.1 jruoho * is useful to pre-calculate them from the PM1 Event Block definitions.
728 1.1 jruoho *
729 1.1 jruoho * The PM event blocks are split into two register blocks, first is the
730 1.1 jruoho * PM Status Register block, followed immediately by the PM Enable
731 1.1 jruoho * Register block. Each is of length (Pm1EventLength/2)
732 1.1 jruoho *
733 1.1 jruoho * Note: The PM1A event block is required by the ACPI specification.
734 1.1 jruoho * However, the PM1B event block is optional and is rarely, if ever,
735 1.1 jruoho * used.
736 1.1 jruoho */
737 1.1 jruoho
738 1.1 jruoho for (i = 0; i < ACPI_FADT_PM_INFO_ENTRIES; i++)
739 1.1 jruoho {
740 1.1 jruoho Source64 = ACPI_ADD_PTR (ACPI_GENERIC_ADDRESS, &AcpiGbl_FADT,
741 1.1 jruoho FadtPmInfoTable[i].Source);
742 1.1 jruoho
743 1.1 jruoho if (Source64->Address)
744 1.1 jruoho {
745 1.1 jruoho AcpiTbInitGenericAddress (FadtPmInfoTable[i].Target,
746 1.1 jruoho Source64->SpaceId, Pm1RegisterByteWidth,
747 1.1 jruoho Source64->Address +
748 1.1 jruoho (FadtPmInfoTable[i].RegisterNum * Pm1RegisterByteWidth));
749 1.1 jruoho }
750 1.1 jruoho }
751 1.1 jruoho }
752 1.1 jruoho
753