tbfadt.c revision 1.4 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.3 jruoho /*
8 1.4 christos * Copyright (C) 2000 - 2013, Intel Corp.
9 1.1 jruoho * All rights reserved.
10 1.1 jruoho *
11 1.3 jruoho * Redistribution and use in source and binary forms, with or without
12 1.3 jruoho * modification, are permitted provided that the following conditions
13 1.3 jruoho * are met:
14 1.3 jruoho * 1. Redistributions of source code must retain the above copyright
15 1.3 jruoho * notice, this list of conditions, and the following disclaimer,
16 1.3 jruoho * without modification.
17 1.3 jruoho * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 1.3 jruoho * substantially similar to the "NO WARRANTY" disclaimer below
19 1.3 jruoho * ("Disclaimer") and any redistribution must be conditioned upon
20 1.3 jruoho * including a substantially similar Disclaimer requirement for further
21 1.3 jruoho * binary redistribution.
22 1.3 jruoho * 3. Neither the names of the above-listed copyright holders nor the names
23 1.3 jruoho * of any contributors may be used to endorse or promote products derived
24 1.3 jruoho * from this software without specific prior written permission.
25 1.3 jruoho *
26 1.3 jruoho * Alternatively, this software may be distributed under the terms of the
27 1.3 jruoho * GNU General Public License ("GPL") version 2 as published by the Free
28 1.3 jruoho * Software Foundation.
29 1.3 jruoho *
30 1.3 jruoho * NO WARRANTY
31 1.3 jruoho * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 1.3 jruoho * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 1.3 jruoho * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 1.3 jruoho * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 1.3 jruoho * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 1.3 jruoho * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 1.3 jruoho * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 1.3 jruoho * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 1.3 jruoho * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 1.3 jruoho * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 1.3 jruoho * POSSIBILITY OF SUCH DAMAGES.
42 1.3 jruoho */
43 1.1 jruoho
44 1.1 jruoho #define __TBFADT_C__
45 1.1 jruoho
46 1.1 jruoho #include "acpi.h"
47 1.1 jruoho #include "accommon.h"
48 1.1 jruoho #include "actables.h"
49 1.1 jruoho
50 1.1 jruoho #define _COMPONENT ACPI_TABLES
51 1.1 jruoho ACPI_MODULE_NAME ("tbfadt")
52 1.1 jruoho
53 1.1 jruoho /* Local prototypes */
54 1.1 jruoho
55 1.4 christos static void
56 1.1 jruoho AcpiTbInitGenericAddress (
57 1.1 jruoho ACPI_GENERIC_ADDRESS *GenericAddress,
58 1.1 jruoho UINT8 SpaceId,
59 1.1 jruoho UINT8 ByteWidth,
60 1.4 christos UINT64 Address,
61 1.4 christos char *RegisterName);
62 1.1 jruoho
63 1.1 jruoho static void
64 1.1 jruoho AcpiTbConvertFadt (
65 1.1 jruoho void);
66 1.1 jruoho
67 1.1 jruoho static void
68 1.4 christos AcpiTbSetupFadtRegisters (
69 1.1 jruoho void);
70 1.1 jruoho
71 1.4 christos static UINT64
72 1.4 christos AcpiTbSelectAddress (
73 1.4 christos char *RegisterName,
74 1.4 christos UINT32 Address32,
75 1.4 christos UINT64 Address64);
76 1.1 jruoho
77 1.1 jruoho
78 1.1 jruoho /* Table for conversion of FADT to common internal format and FADT validation */
79 1.1 jruoho
80 1.1 jruoho typedef struct acpi_fadt_info
81 1.1 jruoho {
82 1.2 jruoho const char *Name;
83 1.4 christos UINT16 Address64;
84 1.4 christos UINT16 Address32;
85 1.4 christos UINT16 Length;
86 1.1 jruoho UINT8 DefaultLength;
87 1.1 jruoho UINT8 Type;
88 1.1 jruoho
89 1.1 jruoho } ACPI_FADT_INFO;
90 1.1 jruoho
91 1.4 christos #define ACPI_FADT_OPTIONAL 0
92 1.1 jruoho #define ACPI_FADT_REQUIRED 1
93 1.1 jruoho #define ACPI_FADT_SEPARATE_LENGTH 2
94 1.1 jruoho
95 1.1 jruoho static ACPI_FADT_INFO FadtInfoTable[] =
96 1.1 jruoho {
97 1.1 jruoho {"Pm1aEventBlock",
98 1.1 jruoho ACPI_FADT_OFFSET (XPm1aEventBlock),
99 1.1 jruoho ACPI_FADT_OFFSET (Pm1aEventBlock),
100 1.1 jruoho ACPI_FADT_OFFSET (Pm1EventLength),
101 1.1 jruoho ACPI_PM1_REGISTER_WIDTH * 2, /* Enable + Status register */
102 1.1 jruoho ACPI_FADT_REQUIRED},
103 1.1 jruoho
104 1.1 jruoho {"Pm1bEventBlock",
105 1.1 jruoho ACPI_FADT_OFFSET (XPm1bEventBlock),
106 1.1 jruoho ACPI_FADT_OFFSET (Pm1bEventBlock),
107 1.1 jruoho ACPI_FADT_OFFSET (Pm1EventLength),
108 1.1 jruoho ACPI_PM1_REGISTER_WIDTH * 2, /* Enable + Status register */
109 1.4 christos ACPI_FADT_OPTIONAL},
110 1.1 jruoho
111 1.1 jruoho {"Pm1aControlBlock",
112 1.1 jruoho ACPI_FADT_OFFSET (XPm1aControlBlock),
113 1.1 jruoho ACPI_FADT_OFFSET (Pm1aControlBlock),
114 1.1 jruoho ACPI_FADT_OFFSET (Pm1ControlLength),
115 1.1 jruoho ACPI_PM1_REGISTER_WIDTH,
116 1.1 jruoho ACPI_FADT_REQUIRED},
117 1.1 jruoho
118 1.1 jruoho {"Pm1bControlBlock",
119 1.1 jruoho ACPI_FADT_OFFSET (XPm1bControlBlock),
120 1.1 jruoho ACPI_FADT_OFFSET (Pm1bControlBlock),
121 1.1 jruoho ACPI_FADT_OFFSET (Pm1ControlLength),
122 1.1 jruoho ACPI_PM1_REGISTER_WIDTH,
123 1.4 christos ACPI_FADT_OPTIONAL},
124 1.1 jruoho
125 1.1 jruoho {"Pm2ControlBlock",
126 1.1 jruoho ACPI_FADT_OFFSET (XPm2ControlBlock),
127 1.1 jruoho ACPI_FADT_OFFSET (Pm2ControlBlock),
128 1.1 jruoho ACPI_FADT_OFFSET (Pm2ControlLength),
129 1.1 jruoho ACPI_PM2_REGISTER_WIDTH,
130 1.1 jruoho ACPI_FADT_SEPARATE_LENGTH},
131 1.1 jruoho
132 1.1 jruoho {"PmTimerBlock",
133 1.1 jruoho ACPI_FADT_OFFSET (XPmTimerBlock),
134 1.1 jruoho ACPI_FADT_OFFSET (PmTimerBlock),
135 1.1 jruoho ACPI_FADT_OFFSET (PmTimerLength),
136 1.1 jruoho ACPI_PM_TIMER_WIDTH,
137 1.4 christos ACPI_FADT_SEPARATE_LENGTH}, /* ACPI 5.0A: Timer is optional */
138 1.1 jruoho
139 1.1 jruoho {"Gpe0Block",
140 1.1 jruoho ACPI_FADT_OFFSET (XGpe0Block),
141 1.1 jruoho ACPI_FADT_OFFSET (Gpe0Block),
142 1.1 jruoho ACPI_FADT_OFFSET (Gpe0BlockLength),
143 1.1 jruoho 0,
144 1.1 jruoho ACPI_FADT_SEPARATE_LENGTH},
145 1.1 jruoho
146 1.1 jruoho {"Gpe1Block",
147 1.1 jruoho ACPI_FADT_OFFSET (XGpe1Block),
148 1.1 jruoho ACPI_FADT_OFFSET (Gpe1Block),
149 1.1 jruoho ACPI_FADT_OFFSET (Gpe1BlockLength),
150 1.1 jruoho 0,
151 1.1 jruoho ACPI_FADT_SEPARATE_LENGTH}
152 1.1 jruoho };
153 1.1 jruoho
154 1.1 jruoho #define ACPI_FADT_INFO_ENTRIES \
155 1.1 jruoho (sizeof (FadtInfoTable) / sizeof (ACPI_FADT_INFO))
156 1.1 jruoho
157 1.1 jruoho
158 1.1 jruoho /* Table used to split Event Blocks into separate status/enable registers */
159 1.1 jruoho
160 1.1 jruoho typedef struct acpi_fadt_pm_info
161 1.1 jruoho {
162 1.1 jruoho ACPI_GENERIC_ADDRESS *Target;
163 1.4 christos UINT16 Source;
164 1.1 jruoho UINT8 RegisterNum;
165 1.1 jruoho
166 1.1 jruoho } ACPI_FADT_PM_INFO;
167 1.1 jruoho
168 1.1 jruoho static ACPI_FADT_PM_INFO FadtPmInfoTable[] =
169 1.1 jruoho {
170 1.1 jruoho {&AcpiGbl_XPm1aStatus,
171 1.1 jruoho ACPI_FADT_OFFSET (XPm1aEventBlock),
172 1.1 jruoho 0},
173 1.1 jruoho
174 1.1 jruoho {&AcpiGbl_XPm1aEnable,
175 1.1 jruoho ACPI_FADT_OFFSET (XPm1aEventBlock),
176 1.1 jruoho 1},
177 1.1 jruoho
178 1.1 jruoho {&AcpiGbl_XPm1bStatus,
179 1.1 jruoho ACPI_FADT_OFFSET (XPm1bEventBlock),
180 1.1 jruoho 0},
181 1.1 jruoho
182 1.1 jruoho {&AcpiGbl_XPm1bEnable,
183 1.1 jruoho ACPI_FADT_OFFSET (XPm1bEventBlock),
184 1.1 jruoho 1}
185 1.1 jruoho };
186 1.1 jruoho
187 1.1 jruoho #define ACPI_FADT_PM_INFO_ENTRIES \
188 1.1 jruoho (sizeof (FadtPmInfoTable) / sizeof (ACPI_FADT_PM_INFO))
189 1.1 jruoho
190 1.1 jruoho
191 1.1 jruoho /*******************************************************************************
192 1.1 jruoho *
193 1.1 jruoho * FUNCTION: AcpiTbInitGenericAddress
194 1.1 jruoho *
195 1.1 jruoho * PARAMETERS: GenericAddress - GAS struct to be initialized
196 1.1 jruoho * SpaceId - ACPI Space ID for this register
197 1.4 christos * ByteWidth - Width of this register
198 1.1 jruoho * Address - Address of the register
199 1.4 christos * RegisterName - ASCII name of the ACPI register
200 1.1 jruoho *
201 1.1 jruoho * RETURN: None
202 1.1 jruoho *
203 1.1 jruoho * DESCRIPTION: Initialize a Generic Address Structure (GAS)
204 1.1 jruoho * See the ACPI specification for a full description and
205 1.1 jruoho * definition of this structure.
206 1.1 jruoho *
207 1.1 jruoho ******************************************************************************/
208 1.1 jruoho
209 1.4 christos static void
210 1.1 jruoho AcpiTbInitGenericAddress (
211 1.1 jruoho ACPI_GENERIC_ADDRESS *GenericAddress,
212 1.1 jruoho UINT8 SpaceId,
213 1.1 jruoho UINT8 ByteWidth,
214 1.4 christos UINT64 Address,
215 1.4 christos char *RegisterName)
216 1.1 jruoho {
217 1.4 christos UINT8 BitWidth;
218 1.4 christos
219 1.4 christos
220 1.4 christos /* Bit width field in the GAS is only one byte long, 255 max */
221 1.4 christos
222 1.4 christos BitWidth = (UINT8) (ByteWidth * 8);
223 1.4 christos
224 1.4 christos if (ByteWidth > 31) /* (31*8)=248 */
225 1.4 christos {
226 1.4 christos ACPI_ERROR ((AE_INFO,
227 1.4 christos "%s - 32-bit FADT register is too long (%u bytes, %u bits) "
228 1.4 christos "to convert to GAS struct - 255 bits max, truncating",
229 1.4 christos RegisterName, ByteWidth, (ByteWidth * 8)));
230 1.4 christos
231 1.4 christos BitWidth = 255;
232 1.4 christos }
233 1.1 jruoho
234 1.1 jruoho /*
235 1.1 jruoho * The 64-bit Address field is non-aligned in the byte packed
236 1.1 jruoho * GAS struct.
237 1.1 jruoho */
238 1.1 jruoho ACPI_MOVE_64_TO_64 (&GenericAddress->Address, &Address);
239 1.1 jruoho
240 1.1 jruoho /* All other fields are byte-wide */
241 1.1 jruoho
242 1.1 jruoho GenericAddress->SpaceId = SpaceId;
243 1.4 christos GenericAddress->BitWidth = BitWidth;
244 1.1 jruoho GenericAddress->BitOffset = 0;
245 1.1 jruoho GenericAddress->AccessWidth = 0; /* Access width ANY */
246 1.1 jruoho }
247 1.1 jruoho
248 1.1 jruoho
249 1.1 jruoho /*******************************************************************************
250 1.1 jruoho *
251 1.4 christos * FUNCTION: AcpiTbSelectAddress
252 1.4 christos *
253 1.4 christos * PARAMETERS: RegisterName - ASCII name of the ACPI register
254 1.4 christos * Address32 - 32-bit address of the register
255 1.4 christos * Address64 - 64-bit address of the register
256 1.4 christos *
257 1.4 christos * RETURN: The resolved 64-bit address
258 1.4 christos *
259 1.4 christos * DESCRIPTION: Select between 32-bit and 64-bit versions of addresses within
260 1.4 christos * the FADT. Used for the FACS and DSDT addresses.
261 1.4 christos *
262 1.4 christos * NOTES:
263 1.4 christos *
264 1.4 christos * Check for FACS and DSDT address mismatches. An address mismatch between
265 1.4 christos * the 32-bit and 64-bit address fields (FIRMWARE_CTRL/X_FIRMWARE_CTRL and
266 1.4 christos * DSDT/X_DSDT) could be a corrupted address field or it might indicate
267 1.4 christos * the presence of two FACS or two DSDT tables.
268 1.4 christos *
269 1.4 christos * November 2013:
270 1.4 christos * By default, as per the ACPICA specification, a valid 64-bit address is
271 1.4 christos * used regardless of the value of the 32-bit address. However, this
272 1.4 christos * behavior can be overridden via the AcpiGbl_Use32BitFadtAddresses flag.
273 1.4 christos *
274 1.4 christos ******************************************************************************/
275 1.4 christos
276 1.4 christos static UINT64
277 1.4 christos AcpiTbSelectAddress (
278 1.4 christos char *RegisterName,
279 1.4 christos UINT32 Address32,
280 1.4 christos UINT64 Address64)
281 1.4 christos {
282 1.4 christos
283 1.4 christos if (!Address64)
284 1.4 christos {
285 1.4 christos /* 64-bit address is zero, use 32-bit address */
286 1.4 christos
287 1.4 christos return ((UINT64) Address32);
288 1.4 christos }
289 1.4 christos
290 1.4 christos if (Address32 &&
291 1.4 christos (Address64 != (UINT64) Address32))
292 1.4 christos {
293 1.4 christos /* Address mismatch between 32-bit and 64-bit versions */
294 1.4 christos
295 1.4 christos ACPI_BIOS_WARNING ((AE_INFO,
296 1.4 christos "32/64X %s address mismatch in FADT: "
297 1.4 christos "0x%8.8X/0x%8.8X%8.8X, using %u-bit address",
298 1.4 christos RegisterName, Address32, ACPI_FORMAT_UINT64 (Address64),
299 1.4 christos AcpiGbl_Use32BitFadtAddresses ? 32 : 64));
300 1.4 christos
301 1.4 christos /* 32-bit address override */
302 1.4 christos
303 1.4 christos if (AcpiGbl_Use32BitFadtAddresses)
304 1.4 christos {
305 1.4 christos return ((UINT64) Address32);
306 1.4 christos }
307 1.4 christos }
308 1.4 christos
309 1.4 christos /* Default is to use the 64-bit address */
310 1.4 christos
311 1.4 christos return (Address64);
312 1.4 christos }
313 1.4 christos
314 1.4 christos
315 1.4 christos /*******************************************************************************
316 1.4 christos *
317 1.1 jruoho * FUNCTION: AcpiTbParseFadt
318 1.1 jruoho *
319 1.1 jruoho * PARAMETERS: TableIndex - Index for the FADT
320 1.1 jruoho *
321 1.1 jruoho * RETURN: None
322 1.1 jruoho *
323 1.1 jruoho * DESCRIPTION: Initialize the FADT, DSDT and FACS tables
324 1.1 jruoho * (FADT contains the addresses of the DSDT and FACS)
325 1.1 jruoho *
326 1.1 jruoho ******************************************************************************/
327 1.1 jruoho
328 1.1 jruoho void
329 1.1 jruoho AcpiTbParseFadt (
330 1.1 jruoho UINT32 TableIndex)
331 1.1 jruoho {
332 1.1 jruoho UINT32 Length;
333 1.1 jruoho ACPI_TABLE_HEADER *Table;
334 1.1 jruoho
335 1.1 jruoho
336 1.1 jruoho /*
337 1.1 jruoho * The FADT has multiple versions with different lengths,
338 1.1 jruoho * and it contains pointers to both the DSDT and FACS tables.
339 1.1 jruoho *
340 1.1 jruoho * Get a local copy of the FADT and convert it to a common format
341 1.1 jruoho * Map entire FADT, assumed to be smaller than one page.
342 1.1 jruoho */
343 1.1 jruoho Length = AcpiGbl_RootTableList.Tables[TableIndex].Length;
344 1.1 jruoho
345 1.1 jruoho Table = AcpiOsMapMemory (
346 1.1 jruoho AcpiGbl_RootTableList.Tables[TableIndex].Address, Length);
347 1.1 jruoho if (!Table)
348 1.1 jruoho {
349 1.1 jruoho return;
350 1.1 jruoho }
351 1.1 jruoho
352 1.1 jruoho /*
353 1.1 jruoho * Validate the FADT checksum before we copy the table. Ignore
354 1.1 jruoho * checksum error as we want to try to get the DSDT and FACS.
355 1.1 jruoho */
356 1.1 jruoho (void) AcpiTbVerifyChecksum (Table, Length);
357 1.1 jruoho
358 1.1 jruoho /* Create a local copy of the FADT in common ACPI 2.0+ format */
359 1.1 jruoho
360 1.1 jruoho AcpiTbCreateLocalFadt (Table, Length);
361 1.1 jruoho
362 1.1 jruoho /* All done with the real FADT, unmap it */
363 1.1 jruoho
364 1.1 jruoho AcpiOsUnmapMemory (Table, Length);
365 1.1 jruoho
366 1.1 jruoho /* Obtain the DSDT and FACS tables via their addresses within the FADT */
367 1.1 jruoho
368 1.1 jruoho AcpiTbInstallTable ((ACPI_PHYSICAL_ADDRESS) AcpiGbl_FADT.XDsdt,
369 1.1 jruoho ACPI_SIG_DSDT, ACPI_TABLE_INDEX_DSDT);
370 1.1 jruoho
371 1.4 christos /* If Hardware Reduced flag is set, there is no FACS */
372 1.4 christos
373 1.4 christos if (!AcpiGbl_ReducedHardware)
374 1.4 christos {
375 1.4 christos AcpiTbInstallTable ((ACPI_PHYSICAL_ADDRESS) AcpiGbl_FADT.XFacs,
376 1.4 christos ACPI_SIG_FACS, ACPI_TABLE_INDEX_FACS);
377 1.4 christos }
378 1.1 jruoho }
379 1.1 jruoho
380 1.1 jruoho
381 1.1 jruoho /*******************************************************************************
382 1.1 jruoho *
383 1.1 jruoho * FUNCTION: AcpiTbCreateLocalFadt
384 1.1 jruoho *
385 1.1 jruoho * PARAMETERS: Table - Pointer to BIOS FADT
386 1.1 jruoho * Length - Length of the table
387 1.1 jruoho *
388 1.1 jruoho * RETURN: None
389 1.1 jruoho *
390 1.1 jruoho * DESCRIPTION: Get a local copy of the FADT and convert it to a common format.
391 1.1 jruoho * Performs validation on some important FADT fields.
392 1.1 jruoho *
393 1.1 jruoho * NOTE: We create a local copy of the FADT regardless of the version.
394 1.1 jruoho *
395 1.1 jruoho ******************************************************************************/
396 1.1 jruoho
397 1.1 jruoho void
398 1.1 jruoho AcpiTbCreateLocalFadt (
399 1.1 jruoho ACPI_TABLE_HEADER *Table,
400 1.1 jruoho UINT32 Length)
401 1.1 jruoho {
402 1.1 jruoho
403 1.1 jruoho /*
404 1.1 jruoho * Check if the FADT is larger than the largest table that we expect
405 1.4 christos * (the ACPI 5.0 version). If so, truncate the table, and issue
406 1.1 jruoho * a warning.
407 1.1 jruoho */
408 1.1 jruoho if (Length > sizeof (ACPI_TABLE_FADT))
409 1.1 jruoho {
410 1.4 christos ACPI_BIOS_WARNING ((AE_INFO,
411 1.4 christos "FADT (revision %u) is longer than ACPI 5.0 version, "
412 1.1 jruoho "truncating length %u to %u",
413 1.1 jruoho Table->Revision, Length, (UINT32) sizeof (ACPI_TABLE_FADT)));
414 1.1 jruoho }
415 1.1 jruoho
416 1.1 jruoho /* Clear the entire local FADT */
417 1.1 jruoho
418 1.1 jruoho ACPI_MEMSET (&AcpiGbl_FADT, 0, sizeof (ACPI_TABLE_FADT));
419 1.1 jruoho
420 1.1 jruoho /* Copy the original FADT, up to sizeof (ACPI_TABLE_FADT) */
421 1.1 jruoho
422 1.1 jruoho ACPI_MEMCPY (&AcpiGbl_FADT, Table,
423 1.1 jruoho ACPI_MIN (Length, sizeof (ACPI_TABLE_FADT)));
424 1.1 jruoho
425 1.4 christos /* Take a copy of the Hardware Reduced flag */
426 1.4 christos
427 1.4 christos AcpiGbl_ReducedHardware = FALSE;
428 1.4 christos if (AcpiGbl_FADT.Flags & ACPI_FADT_HW_REDUCED)
429 1.4 christos {
430 1.4 christos AcpiGbl_ReducedHardware = TRUE;
431 1.4 christos }
432 1.4 christos
433 1.1 jruoho /* Convert the local copy of the FADT to the common internal format */
434 1.1 jruoho
435 1.1 jruoho AcpiTbConvertFadt ();
436 1.1 jruoho
437 1.1 jruoho /* Initialize the global ACPI register structures */
438 1.1 jruoho
439 1.1 jruoho AcpiTbSetupFadtRegisters ();
440 1.1 jruoho }
441 1.1 jruoho
442 1.1 jruoho
443 1.1 jruoho /*******************************************************************************
444 1.1 jruoho *
445 1.1 jruoho * FUNCTION: AcpiTbConvertFadt
446 1.1 jruoho *
447 1.4 christos * PARAMETERS: None - AcpiGbl_FADT is used.
448 1.1 jruoho *
449 1.1 jruoho * RETURN: None
450 1.1 jruoho *
451 1.1 jruoho * DESCRIPTION: Converts all versions of the FADT to a common internal format.
452 1.4 christos * Expand 32-bit addresses to 64-bit as necessary. Also validate
453 1.4 christos * important fields within the FADT.
454 1.1 jruoho *
455 1.4 christos * NOTE: AcpiGbl_FADT must be of size (ACPI_TABLE_FADT), and must
456 1.4 christos * contain a copy of the actual BIOS-provided FADT.
457 1.1 jruoho *
458 1.1 jruoho * Notes on 64-bit register addresses:
459 1.1 jruoho *
460 1.1 jruoho * After this FADT conversion, later ACPICA code will only use the 64-bit "X"
461 1.1 jruoho * fields of the FADT for all ACPI register addresses.
462 1.1 jruoho *
463 1.4 christos * The 64-bit X fields are optional extensions to the original 32-bit FADT
464 1.1 jruoho * V1.0 fields. Even if they are present in the FADT, they are optional and
465 1.1 jruoho * are unused if the BIOS sets them to zero. Therefore, we must copy/expand
466 1.4 christos * 32-bit V1.0 fields to the 64-bit X fields if the the 64-bit X field is
467 1.4 christos * originally zero.
468 1.1 jruoho *
469 1.4 christos * For ACPI 1.0 FADTs (that contain no 64-bit addresses), all 32-bit address
470 1.4 christos * fields are expanded to the corresponding 64-bit X fields in the internal
471 1.4 christos * common FADT.
472 1.1 jruoho *
473 1.1 jruoho * For ACPI 2.0+ FADTs, all valid (non-zero) 32-bit address fields are expanded
474 1.4 christos * to the corresponding 64-bit X fields, if the 64-bit field is originally
475 1.4 christos * zero. Adhering to the ACPI specification, we completely ignore the 32-bit
476 1.4 christos * field if the 64-bit field is valid, regardless of whether the host OS is
477 1.4 christos * 32-bit or 64-bit.
478 1.4 christos *
479 1.4 christos * Possible additional checks:
480 1.4 christos * (AcpiGbl_FADT.Pm1EventLength >= 4)
481 1.4 christos * (AcpiGbl_FADT.Pm1ControlLength >= 2)
482 1.4 christos * (AcpiGbl_FADT.PmTimerLength >= 4)
483 1.4 christos * Gpe block lengths must be multiple of 2
484 1.1 jruoho *
485 1.1 jruoho ******************************************************************************/
486 1.1 jruoho
487 1.1 jruoho static void
488 1.1 jruoho AcpiTbConvertFadt (
489 1.1 jruoho void)
490 1.1 jruoho {
491 1.4 christos char *Name;
492 1.1 jruoho ACPI_GENERIC_ADDRESS *Address64;
493 1.1 jruoho UINT32 Address32;
494 1.4 christos UINT8 Length;
495 1.1 jruoho UINT32 i;
496 1.1 jruoho
497 1.1 jruoho
498 1.1 jruoho /*
499 1.1 jruoho * For ACPI 1.0 FADTs (revision 1 or 2), ensure that reserved fields which
500 1.1 jruoho * should be zero are indeed zero. This will workaround BIOSs that
501 1.1 jruoho * inadvertently place values in these fields.
502 1.1 jruoho *
503 1.1 jruoho * The ACPI 1.0 reserved fields that will be zeroed are the bytes located
504 1.1 jruoho * at offset 45, 55, 95, and the word located at offset 109, 110.
505 1.3 jruoho *
506 1.3 jruoho * Note: The FADT revision value is unreliable. Only the length can be
507 1.3 jruoho * trusted.
508 1.1 jruoho */
509 1.3 jruoho if (AcpiGbl_FADT.Header.Length <= ACPI_FADT_V2_SIZE)
510 1.1 jruoho {
511 1.1 jruoho AcpiGbl_FADT.PreferredProfile = 0;
512 1.1 jruoho AcpiGbl_FADT.PstateControl = 0;
513 1.1 jruoho AcpiGbl_FADT.CstControl = 0;
514 1.1 jruoho AcpiGbl_FADT.BootFlags = 0;
515 1.1 jruoho }
516 1.1 jruoho
517 1.1 jruoho /*
518 1.4 christos * Now we can update the local FADT length to the length of the
519 1.4 christos * current FADT version as defined by the ACPI specification.
520 1.4 christos * Thus, we will have a common FADT internally.
521 1.1 jruoho */
522 1.4 christos AcpiGbl_FADT.Header.Length = sizeof (ACPI_TABLE_FADT);
523 1.1 jruoho
524 1.1 jruoho /*
525 1.4 christos * Expand the 32-bit FACS and DSDT addresses to 64-bit as necessary.
526 1.4 christos * Later ACPICA code will always use the X 64-bit field.
527 1.1 jruoho */
528 1.4 christos AcpiGbl_FADT.XFacs = AcpiTbSelectAddress (__UNCONST("FACS"),
529 1.4 christos AcpiGbl_FADT.Facs, AcpiGbl_FADT.XFacs);
530 1.4 christos
531 1.4 christos AcpiGbl_FADT.XDsdt = AcpiTbSelectAddress (__UNCONST("DSDT"),
532 1.4 christos AcpiGbl_FADT.Dsdt, AcpiGbl_FADT.XDsdt);
533 1.1 jruoho
534 1.4 christos /* If Hardware Reduced flag is set, we are all done */
535 1.1 jruoho
536 1.4 christos if (AcpiGbl_ReducedHardware)
537 1.1 jruoho {
538 1.4 christos return;
539 1.1 jruoho }
540 1.1 jruoho
541 1.1 jruoho /* Examine all of the 64-bit extended address fields (X fields) */
542 1.1 jruoho
543 1.1 jruoho for (i = 0; i < ACPI_FADT_INFO_ENTRIES; i++)
544 1.1 jruoho {
545 1.1 jruoho /*
546 1.4 christos * Get the 32-bit and 64-bit addresses, as well as the register
547 1.4 christos * length and register name.
548 1.1 jruoho */
549 1.4 christos Address32 = *ACPI_ADD_PTR (UINT32,
550 1.4 christos &AcpiGbl_FADT, FadtInfoTable[i].Address32);
551 1.4 christos
552 1.1 jruoho Address64 = ACPI_ADD_PTR (ACPI_GENERIC_ADDRESS,
553 1.4 christos &AcpiGbl_FADT, FadtInfoTable[i].Address64);
554 1.4 christos
555 1.1 jruoho Length = *ACPI_ADD_PTR (UINT8,
556 1.4 christos &AcpiGbl_FADT, FadtInfoTable[i].Length);
557 1.4 christos
558 1.4 christos Name = __UNCONST(FadtInfoTable[i].Name);
559 1.4 christos
560 1.4 christos /*
561 1.4 christos * Expand the ACPI 1.0 32-bit addresses to the ACPI 2.0 64-bit "X"
562 1.4 christos * generic address structures as necessary. Later code will always use
563 1.4 christos * the 64-bit address structures.
564 1.4 christos *
565 1.4 christos * November 2013:
566 1.4 christos * Now always use the 64-bit address if it is valid (non-zero), in
567 1.4 christos * accordance with the ACPI specification which states that a 64-bit
568 1.4 christos * address supersedes the 32-bit version. This behavior can be
569 1.4 christos * overridden by the AcpiGbl_Use32BitFadtAddresses flag.
570 1.4 christos *
571 1.4 christos * During 64-bit address construction and verification,
572 1.4 christos * these cases are handled:
573 1.4 christos *
574 1.4 christos * Address32 zero, Address64 [don't care] - Use Address64
575 1.4 christos *
576 1.4 christos * Address32 non-zero, Address64 zero - Copy/use Address32
577 1.4 christos * Address32 non-zero == Address64 non-zero - Use Address64
578 1.4 christos * Address32 non-zero != Address64 non-zero - Warning, use Address64
579 1.4 christos *
580 1.4 christos * Override: if AcpiGbl_Use32BitFadtAddresses is TRUE, and:
581 1.4 christos * Address32 non-zero != Address64 non-zero - Warning, copy/use Address32
582 1.4 christos *
583 1.4 christos * Note: SpaceId is always I/O for 32-bit legacy address fields
584 1.4 christos */
585 1.4 christos if (Address32)
586 1.4 christos {
587 1.4 christos if (!Address64->Address)
588 1.4 christos {
589 1.4 christos /* 64-bit address is zero, use 32-bit address */
590 1.4 christos
591 1.4 christos AcpiTbInitGenericAddress (Address64,
592 1.4 christos ACPI_ADR_SPACE_SYSTEM_IO,
593 1.4 christos *ACPI_ADD_PTR (UINT8, &AcpiGbl_FADT,
594 1.4 christos FadtInfoTable[i].Length),
595 1.4 christos (UINT64) Address32, Name);
596 1.4 christos }
597 1.4 christos else if (Address64->Address != (UINT64) Address32)
598 1.4 christos {
599 1.4 christos /* Address mismatch */
600 1.4 christos
601 1.4 christos ACPI_BIOS_WARNING ((AE_INFO,
602 1.4 christos "32/64X address mismatch in FADT/%s: "
603 1.4 christos "0x%8.8X/0x%8.8X%8.8X, using %u-bit address",
604 1.4 christos Name, Address32,
605 1.4 christos ACPI_FORMAT_UINT64 (Address64->Address),
606 1.4 christos AcpiGbl_Use32BitFadtAddresses ? 32 : 64));
607 1.4 christos
608 1.4 christos if (AcpiGbl_Use32BitFadtAddresses)
609 1.4 christos {
610 1.4 christos /* 32-bit address override */
611 1.4 christos
612 1.4 christos AcpiTbInitGenericAddress (Address64,
613 1.4 christos ACPI_ADR_SPACE_SYSTEM_IO,
614 1.4 christos *ACPI_ADD_PTR (UINT8, &AcpiGbl_FADT,
615 1.4 christos FadtInfoTable[i].Length),
616 1.4 christos (UINT64) Address32, Name);
617 1.4 christos }
618 1.4 christos }
619 1.4 christos }
620 1.1 jruoho
621 1.1 jruoho /*
622 1.1 jruoho * For each extended field, check for length mismatch between the
623 1.1 jruoho * legacy length field and the corresponding 64-bit X length field.
624 1.4 christos * Note: If the legacy length field is > 0xFF bits, ignore this
625 1.4 christos * check. (GPE registers can be larger than the 64-bit GAS structure
626 1.4 christos * can accomodate, 0xFF bits).
627 1.1 jruoho */
628 1.1 jruoho if (Address64->Address &&
629 1.4 christos (ACPI_MUL_8 (Length) <= ACPI_UINT8_MAX) &&
630 1.1 jruoho (Address64->BitWidth != ACPI_MUL_8 (Length)))
631 1.1 jruoho {
632 1.4 christos ACPI_BIOS_WARNING ((AE_INFO,
633 1.4 christos "32/64X length mismatch in FADT/%s: %u/%u",
634 1.1 jruoho Name, ACPI_MUL_8 (Length), Address64->BitWidth));
635 1.1 jruoho }
636 1.1 jruoho
637 1.1 jruoho if (FadtInfoTable[i].Type & ACPI_FADT_REQUIRED)
638 1.1 jruoho {
639 1.1 jruoho /*
640 1.4 christos * Field is required (PM1aEvent, PM1aControl).
641 1.1 jruoho * Both the address and length must be non-zero.
642 1.1 jruoho */
643 1.1 jruoho if (!Address64->Address || !Length)
644 1.1 jruoho {
645 1.4 christos ACPI_BIOS_ERROR ((AE_INFO,
646 1.4 christos "Required FADT field %s has zero address and/or length: "
647 1.4 christos "0x%8.8X%8.8X/0x%X",
648 1.1 jruoho Name, ACPI_FORMAT_UINT64 (Address64->Address), Length));
649 1.1 jruoho }
650 1.1 jruoho }
651 1.1 jruoho else if (FadtInfoTable[i].Type & ACPI_FADT_SEPARATE_LENGTH)
652 1.1 jruoho {
653 1.1 jruoho /*
654 1.1 jruoho * Field is optional (PM2Control, GPE0, GPE1) AND has its own
655 1.1 jruoho * length field. If present, both the address and length must
656 1.1 jruoho * be valid.
657 1.1 jruoho */
658 1.1 jruoho if ((Address64->Address && !Length) ||
659 1.1 jruoho (!Address64->Address && Length))
660 1.1 jruoho {
661 1.4 christos ACPI_BIOS_WARNING ((AE_INFO,
662 1.4 christos "Optional FADT field %s has zero address or length: "
663 1.1 jruoho "0x%8.8X%8.8X/0x%X",
664 1.1 jruoho Name, ACPI_FORMAT_UINT64 (Address64->Address), Length));
665 1.1 jruoho }
666 1.1 jruoho }
667 1.1 jruoho }
668 1.1 jruoho }
669 1.1 jruoho
670 1.1 jruoho
671 1.1 jruoho /*******************************************************************************
672 1.1 jruoho *
673 1.1 jruoho * FUNCTION: AcpiTbSetupFadtRegisters
674 1.1 jruoho *
675 1.1 jruoho * PARAMETERS: None, uses AcpiGbl_FADT.
676 1.1 jruoho *
677 1.1 jruoho * RETURN: None
678 1.1 jruoho *
679 1.1 jruoho * DESCRIPTION: Initialize global ACPI PM1 register definitions. Optionally,
680 1.1 jruoho * force FADT register definitions to their default lengths.
681 1.1 jruoho *
682 1.1 jruoho ******************************************************************************/
683 1.1 jruoho
684 1.1 jruoho static void
685 1.1 jruoho AcpiTbSetupFadtRegisters (
686 1.1 jruoho void)
687 1.1 jruoho {
688 1.1 jruoho ACPI_GENERIC_ADDRESS *Target64;
689 1.1 jruoho ACPI_GENERIC_ADDRESS *Source64;
690 1.1 jruoho UINT8 Pm1RegisterByteWidth;
691 1.1 jruoho UINT32 i;
692 1.1 jruoho
693 1.1 jruoho
694 1.1 jruoho /*
695 1.1 jruoho * Optionally check all register lengths against the default values and
696 1.1 jruoho * update them if they are incorrect.
697 1.1 jruoho */
698 1.1 jruoho if (AcpiGbl_UseDefaultRegisterWidths)
699 1.1 jruoho {
700 1.1 jruoho for (i = 0; i < ACPI_FADT_INFO_ENTRIES; i++)
701 1.1 jruoho {
702 1.1 jruoho Target64 = ACPI_ADD_PTR (ACPI_GENERIC_ADDRESS, &AcpiGbl_FADT,
703 1.1 jruoho FadtInfoTable[i].Address64);
704 1.1 jruoho
705 1.1 jruoho /*
706 1.1 jruoho * If a valid register (Address != 0) and the (DefaultLength > 0)
707 1.1 jruoho * (Not a GPE register), then check the width against the default.
708 1.1 jruoho */
709 1.1 jruoho if ((Target64->Address) &&
710 1.1 jruoho (FadtInfoTable[i].DefaultLength > 0) &&
711 1.1 jruoho (FadtInfoTable[i].DefaultLength != Target64->BitWidth))
712 1.1 jruoho {
713 1.4 christos ACPI_BIOS_WARNING ((AE_INFO,
714 1.4 christos "Invalid length for FADT/%s: %u, using default %u",
715 1.1 jruoho FadtInfoTable[i].Name, Target64->BitWidth,
716 1.1 jruoho FadtInfoTable[i].DefaultLength));
717 1.1 jruoho
718 1.1 jruoho /* Incorrect size, set width to the default */
719 1.1 jruoho
720 1.1 jruoho Target64->BitWidth = FadtInfoTable[i].DefaultLength;
721 1.1 jruoho }
722 1.1 jruoho }
723 1.1 jruoho }
724 1.1 jruoho
725 1.1 jruoho /*
726 1.1 jruoho * Get the length of the individual PM1 registers (enable and status).
727 1.1 jruoho * Each register is defined to be (event block length / 2). Extra divide
728 1.1 jruoho * by 8 converts bits to bytes.
729 1.1 jruoho */
730 1.1 jruoho Pm1RegisterByteWidth = (UINT8)
731 1.1 jruoho ACPI_DIV_16 (AcpiGbl_FADT.XPm1aEventBlock.BitWidth);
732 1.1 jruoho
733 1.1 jruoho /*
734 1.1 jruoho * Calculate separate GAS structs for the PM1x (A/B) Status and Enable
735 1.1 jruoho * registers. These addresses do not appear (directly) in the FADT, so it
736 1.1 jruoho * is useful to pre-calculate them from the PM1 Event Block definitions.
737 1.1 jruoho *
738 1.1 jruoho * The PM event blocks are split into two register blocks, first is the
739 1.1 jruoho * PM Status Register block, followed immediately by the PM Enable
740 1.1 jruoho * Register block. Each is of length (Pm1EventLength/2)
741 1.1 jruoho *
742 1.1 jruoho * Note: The PM1A event block is required by the ACPI specification.
743 1.1 jruoho * However, the PM1B event block is optional and is rarely, if ever,
744 1.1 jruoho * used.
745 1.1 jruoho */
746 1.1 jruoho
747 1.1 jruoho for (i = 0; i < ACPI_FADT_PM_INFO_ENTRIES; i++)
748 1.1 jruoho {
749 1.1 jruoho Source64 = ACPI_ADD_PTR (ACPI_GENERIC_ADDRESS, &AcpiGbl_FADT,
750 1.1 jruoho FadtPmInfoTable[i].Source);
751 1.1 jruoho
752 1.1 jruoho if (Source64->Address)
753 1.1 jruoho {
754 1.1 jruoho AcpiTbInitGenericAddress (FadtPmInfoTable[i].Target,
755 1.1 jruoho Source64->SpaceId, Pm1RegisterByteWidth,
756 1.1 jruoho Source64->Address +
757 1.4 christos (FadtPmInfoTable[i].RegisterNum * Pm1RegisterByteWidth),
758 1.4 christos __UNCONST("PmRegisters"));
759 1.1 jruoho }
760 1.1 jruoho }
761 1.1 jruoho }
762