tbfadt.c revision 1.16 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.16 christos * Copyright (C) 2000 - 2021, 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.16 christos * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 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 #include "acpi.h"
45 1.1 jruoho #include "accommon.h"
46 1.1 jruoho #include "actables.h"
47 1.1 jruoho
48 1.1 jruoho #define _COMPONENT ACPI_TABLES
49 1.1 jruoho ACPI_MODULE_NAME ("tbfadt")
50 1.1 jruoho
51 1.1 jruoho /* Local prototypes */
52 1.1 jruoho
53 1.4 christos static void
54 1.1 jruoho AcpiTbInitGenericAddress (
55 1.1 jruoho ACPI_GENERIC_ADDRESS *GenericAddress,
56 1.1 jruoho UINT8 SpaceId,
57 1.1 jruoho UINT8 ByteWidth,
58 1.4 christos UINT64 Address,
59 1.9 christos const char *RegisterName,
60 1.5 christos UINT8 Flags);
61 1.1 jruoho
62 1.1 jruoho static void
63 1.1 jruoho AcpiTbConvertFadt (
64 1.1 jruoho void);
65 1.1 jruoho
66 1.1 jruoho static void
67 1.4 christos AcpiTbSetupFadtRegisters (
68 1.1 jruoho void);
69 1.1 jruoho
70 1.4 christos static UINT64
71 1.4 christos AcpiTbSelectAddress (
72 1.4 christos char *RegisterName,
73 1.4 christos UINT32 Address32,
74 1.4 christos UINT64 Address64);
75 1.1 jruoho
76 1.1 jruoho
77 1.1 jruoho /* Table for conversion of FADT to common internal format and FADT validation */
78 1.1 jruoho
79 1.1 jruoho typedef struct acpi_fadt_info
80 1.1 jruoho {
81 1.2 jruoho const char *Name;
82 1.4 christos UINT16 Address64;
83 1.4 christos UINT16 Address32;
84 1.4 christos UINT16 Length;
85 1.1 jruoho UINT8 DefaultLength;
86 1.5 christos UINT8 Flags;
87 1.1 jruoho
88 1.1 jruoho } ACPI_FADT_INFO;
89 1.1 jruoho
90 1.4 christos #define ACPI_FADT_OPTIONAL 0
91 1.1 jruoho #define ACPI_FADT_REQUIRED 1
92 1.1 jruoho #define ACPI_FADT_SEPARATE_LENGTH 2
93 1.5 christos #define ACPI_FADT_GPE_REGISTER 4
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.5 christos ACPI_FADT_SEPARATE_LENGTH | ACPI_FADT_GPE_REGISTER},
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.5 christos ACPI_FADT_SEPARATE_LENGTH | ACPI_FADT_GPE_REGISTER}
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.9 christos const char *RegisterName,
216 1.5 christos UINT8 Flags)
217 1.1 jruoho {
218 1.4 christos UINT8 BitWidth;
219 1.4 christos
220 1.4 christos
221 1.5 christos /*
222 1.5 christos * Bit width field in the GAS is only one byte long, 255 max.
223 1.5 christos * Check for BitWidth overflow in GAS.
224 1.5 christos */
225 1.4 christos BitWidth = (UINT8) (ByteWidth * 8);
226 1.5 christos if (ByteWidth > 31) /* (31*8)=248, (32*8)=256 */
227 1.4 christos {
228 1.5 christos /*
229 1.5 christos * No error for GPE blocks, because we do not use the BitWidth
230 1.5 christos * for GPEs, the legacy length (ByteWidth) is used instead to
231 1.5 christos * allow for a large number of GPEs.
232 1.5 christos */
233 1.5 christos if (!(Flags & ACPI_FADT_GPE_REGISTER))
234 1.5 christos {
235 1.5 christos ACPI_ERROR ((AE_INFO,
236 1.5 christos "%s - 32-bit FADT register is too long (%u bytes, %u bits) "
237 1.5 christos "to convert to GAS struct - 255 bits max, truncating",
238 1.5 christos RegisterName, ByteWidth, (ByteWidth * 8)));
239 1.5 christos }
240 1.4 christos
241 1.4 christos BitWidth = 255;
242 1.4 christos }
243 1.1 jruoho
244 1.1 jruoho /*
245 1.1 jruoho * The 64-bit Address field is non-aligned in the byte packed
246 1.1 jruoho * GAS struct.
247 1.1 jruoho */
248 1.1 jruoho ACPI_MOVE_64_TO_64 (&GenericAddress->Address, &Address);
249 1.1 jruoho
250 1.1 jruoho /* All other fields are byte-wide */
251 1.1 jruoho
252 1.1 jruoho GenericAddress->SpaceId = SpaceId;
253 1.4 christos GenericAddress->BitWidth = BitWidth;
254 1.1 jruoho GenericAddress->BitOffset = 0;
255 1.1 jruoho GenericAddress->AccessWidth = 0; /* Access width ANY */
256 1.1 jruoho }
257 1.1 jruoho
258 1.1 jruoho
259 1.1 jruoho /*******************************************************************************
260 1.1 jruoho *
261 1.4 christos * FUNCTION: AcpiTbSelectAddress
262 1.4 christos *
263 1.4 christos * PARAMETERS: RegisterName - ASCII name of the ACPI register
264 1.4 christos * Address32 - 32-bit address of the register
265 1.4 christos * Address64 - 64-bit address of the register
266 1.4 christos *
267 1.4 christos * RETURN: The resolved 64-bit address
268 1.4 christos *
269 1.4 christos * DESCRIPTION: Select between 32-bit and 64-bit versions of addresses within
270 1.4 christos * the FADT. Used for the FACS and DSDT addresses.
271 1.4 christos *
272 1.4 christos * NOTES:
273 1.4 christos *
274 1.4 christos * Check for FACS and DSDT address mismatches. An address mismatch between
275 1.4 christos * the 32-bit and 64-bit address fields (FIRMWARE_CTRL/X_FIRMWARE_CTRL and
276 1.4 christos * DSDT/X_DSDT) could be a corrupted address field or it might indicate
277 1.4 christos * the presence of two FACS or two DSDT tables.
278 1.4 christos *
279 1.4 christos * November 2013:
280 1.4 christos * By default, as per the ACPICA specification, a valid 64-bit address is
281 1.4 christos * used regardless of the value of the 32-bit address. However, this
282 1.4 christos * behavior can be overridden via the AcpiGbl_Use32BitFadtAddresses flag.
283 1.4 christos *
284 1.4 christos ******************************************************************************/
285 1.4 christos
286 1.4 christos static UINT64
287 1.4 christos AcpiTbSelectAddress (
288 1.4 christos char *RegisterName,
289 1.4 christos UINT32 Address32,
290 1.4 christos UINT64 Address64)
291 1.4 christos {
292 1.4 christos
293 1.4 christos if (!Address64)
294 1.4 christos {
295 1.4 christos /* 64-bit address is zero, use 32-bit address */
296 1.4 christos
297 1.4 christos return ((UINT64) Address32);
298 1.4 christos }
299 1.4 christos
300 1.4 christos if (Address32 &&
301 1.4 christos (Address64 != (UINT64) Address32))
302 1.4 christos {
303 1.4 christos /* Address mismatch between 32-bit and 64-bit versions */
304 1.4 christos
305 1.4 christos ACPI_BIOS_WARNING ((AE_INFO,
306 1.4 christos "32/64X %s address mismatch in FADT: "
307 1.4 christos "0x%8.8X/0x%8.8X%8.8X, using %u-bit address",
308 1.4 christos RegisterName, Address32, ACPI_FORMAT_UINT64 (Address64),
309 1.4 christos AcpiGbl_Use32BitFadtAddresses ? 32 : 64));
310 1.4 christos
311 1.4 christos /* 32-bit address override */
312 1.4 christos
313 1.4 christos if (AcpiGbl_Use32BitFadtAddresses)
314 1.4 christos {
315 1.4 christos return ((UINT64) Address32);
316 1.4 christos }
317 1.4 christos }
318 1.4 christos
319 1.4 christos /* Default is to use the 64-bit address */
320 1.4 christos
321 1.4 christos return (Address64);
322 1.4 christos }
323 1.4 christos
324 1.4 christos
325 1.4 christos /*******************************************************************************
326 1.4 christos *
327 1.1 jruoho * FUNCTION: AcpiTbParseFadt
328 1.1 jruoho *
329 1.8 christos * PARAMETERS: None
330 1.1 jruoho *
331 1.1 jruoho * RETURN: None
332 1.1 jruoho *
333 1.1 jruoho * DESCRIPTION: Initialize the FADT, DSDT and FACS tables
334 1.1 jruoho * (FADT contains the addresses of the DSDT and FACS)
335 1.1 jruoho *
336 1.1 jruoho ******************************************************************************/
337 1.1 jruoho
338 1.1 jruoho void
339 1.1 jruoho AcpiTbParseFadt (
340 1.8 christos void)
341 1.1 jruoho {
342 1.1 jruoho UINT32 Length;
343 1.1 jruoho ACPI_TABLE_HEADER *Table;
344 1.11 christos ACPI_TABLE_DESC *FadtDesc;
345 1.11 christos ACPI_STATUS Status;
346 1.1 jruoho
347 1.1 jruoho
348 1.1 jruoho /*
349 1.1 jruoho * The FADT has multiple versions with different lengths,
350 1.1 jruoho * and it contains pointers to both the DSDT and FACS tables.
351 1.1 jruoho *
352 1.1 jruoho * Get a local copy of the FADT and convert it to a common format
353 1.1 jruoho * Map entire FADT, assumed to be smaller than one page.
354 1.1 jruoho */
355 1.11 christos FadtDesc = &AcpiGbl_RootTableList.Tables[AcpiGbl_FadtIndex];
356 1.11 christos Status = AcpiTbGetTable (FadtDesc, &Table);
357 1.11 christos if (ACPI_FAILURE (Status))
358 1.1 jruoho {
359 1.1 jruoho return;
360 1.1 jruoho }
361 1.11 christos Length = FadtDesc->Length;
362 1.1 jruoho
363 1.1 jruoho /*
364 1.1 jruoho * Validate the FADT checksum before we copy the table. Ignore
365 1.1 jruoho * checksum error as we want to try to get the DSDT and FACS.
366 1.1 jruoho */
367 1.1 jruoho (void) AcpiTbVerifyChecksum (Table, Length);
368 1.1 jruoho
369 1.1 jruoho /* Create a local copy of the FADT in common ACPI 2.0+ format */
370 1.1 jruoho
371 1.1 jruoho AcpiTbCreateLocalFadt (Table, Length);
372 1.1 jruoho
373 1.1 jruoho /* All done with the real FADT, unmap it */
374 1.1 jruoho
375 1.11 christos AcpiTbPutTable (FadtDesc);
376 1.1 jruoho
377 1.1 jruoho /* Obtain the DSDT and FACS tables via their addresses within the FADT */
378 1.1 jruoho
379 1.10 christos AcpiTbInstallStandardTable (
380 1.10 christos (ACPI_PHYSICAL_ADDRESS) AcpiGbl_FADT.XDsdt,
381 1.10 christos ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL, FALSE, TRUE,
382 1.10 christos &AcpiGbl_DsdtIndex);
383 1.1 jruoho
384 1.4 christos /* If Hardware Reduced flag is set, there is no FACS */
385 1.4 christos
386 1.4 christos if (!AcpiGbl_ReducedHardware)
387 1.4 christos {
388 1.7 christos if (AcpiGbl_FADT.Facs)
389 1.7 christos {
390 1.10 christos AcpiTbInstallStandardTable (
391 1.10 christos (ACPI_PHYSICAL_ADDRESS) AcpiGbl_FADT.Facs,
392 1.10 christos ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL, FALSE, TRUE,
393 1.10 christos &AcpiGbl_FacsIndex);
394 1.7 christos }
395 1.7 christos if (AcpiGbl_FADT.XFacs)
396 1.7 christos {
397 1.10 christos AcpiTbInstallStandardTable (
398 1.10 christos (ACPI_PHYSICAL_ADDRESS) AcpiGbl_FADT.XFacs,
399 1.10 christos ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL, FALSE, TRUE,
400 1.10 christos &AcpiGbl_XFacsIndex);
401 1.7 christos }
402 1.4 christos }
403 1.1 jruoho }
404 1.1 jruoho
405 1.1 jruoho
406 1.1 jruoho /*******************************************************************************
407 1.1 jruoho *
408 1.1 jruoho * FUNCTION: AcpiTbCreateLocalFadt
409 1.1 jruoho *
410 1.1 jruoho * PARAMETERS: Table - Pointer to BIOS FADT
411 1.1 jruoho * Length - Length of the table
412 1.1 jruoho *
413 1.1 jruoho * RETURN: None
414 1.1 jruoho *
415 1.1 jruoho * DESCRIPTION: Get a local copy of the FADT and convert it to a common format.
416 1.1 jruoho * Performs validation on some important FADT fields.
417 1.1 jruoho *
418 1.1 jruoho * NOTE: We create a local copy of the FADT regardless of the version.
419 1.1 jruoho *
420 1.1 jruoho ******************************************************************************/
421 1.1 jruoho
422 1.1 jruoho void
423 1.1 jruoho AcpiTbCreateLocalFadt (
424 1.1 jruoho ACPI_TABLE_HEADER *Table,
425 1.1 jruoho UINT32 Length)
426 1.1 jruoho {
427 1.1 jruoho
428 1.1 jruoho /*
429 1.1 jruoho * Check if the FADT is larger than the largest table that we expect
430 1.9 christos * (typically the current ACPI specification version). If so, truncate
431 1.9 christos * the table, and issue a warning.
432 1.1 jruoho */
433 1.1 jruoho if (Length > sizeof (ACPI_TABLE_FADT))
434 1.1 jruoho {
435 1.4 christos ACPI_BIOS_WARNING ((AE_INFO,
436 1.9 christos "FADT (revision %u) is longer than %s length, "
437 1.1 jruoho "truncating length %u to %u",
438 1.9 christos Table->Revision, ACPI_FADT_CONFORMANCE, Length,
439 1.9 christos (UINT32) sizeof (ACPI_TABLE_FADT)));
440 1.1 jruoho }
441 1.1 jruoho
442 1.1 jruoho /* Clear the entire local FADT */
443 1.1 jruoho
444 1.7 christos memset (&AcpiGbl_FADT, 0, sizeof (ACPI_TABLE_FADT));
445 1.1 jruoho
446 1.1 jruoho /* Copy the original FADT, up to sizeof (ACPI_TABLE_FADT) */
447 1.1 jruoho
448 1.7 christos memcpy (&AcpiGbl_FADT, Table,
449 1.1 jruoho ACPI_MIN (Length, sizeof (ACPI_TABLE_FADT)));
450 1.1 jruoho
451 1.4 christos /* Take a copy of the Hardware Reduced flag */
452 1.4 christos
453 1.4 christos AcpiGbl_ReducedHardware = FALSE;
454 1.4 christos if (AcpiGbl_FADT.Flags & ACPI_FADT_HW_REDUCED)
455 1.4 christos {
456 1.4 christos AcpiGbl_ReducedHardware = TRUE;
457 1.4 christos }
458 1.4 christos
459 1.1 jruoho /* Convert the local copy of the FADT to the common internal format */
460 1.1 jruoho
461 1.1 jruoho AcpiTbConvertFadt ();
462 1.1 jruoho
463 1.1 jruoho /* Initialize the global ACPI register structures */
464 1.1 jruoho
465 1.1 jruoho AcpiTbSetupFadtRegisters ();
466 1.1 jruoho }
467 1.1 jruoho
468 1.1 jruoho
469 1.1 jruoho /*******************************************************************************
470 1.1 jruoho *
471 1.1 jruoho * FUNCTION: AcpiTbConvertFadt
472 1.1 jruoho *
473 1.4 christos * PARAMETERS: None - AcpiGbl_FADT is used.
474 1.1 jruoho *
475 1.1 jruoho * RETURN: None
476 1.1 jruoho *
477 1.1 jruoho * DESCRIPTION: Converts all versions of the FADT to a common internal format.
478 1.4 christos * Expand 32-bit addresses to 64-bit as necessary. Also validate
479 1.4 christos * important fields within the FADT.
480 1.1 jruoho *
481 1.4 christos * NOTE: AcpiGbl_FADT must be of size (ACPI_TABLE_FADT), and must
482 1.4 christos * contain a copy of the actual BIOS-provided FADT.
483 1.1 jruoho *
484 1.1 jruoho * Notes on 64-bit register addresses:
485 1.1 jruoho *
486 1.1 jruoho * After this FADT conversion, later ACPICA code will only use the 64-bit "X"
487 1.1 jruoho * fields of the FADT for all ACPI register addresses.
488 1.1 jruoho *
489 1.4 christos * The 64-bit X fields are optional extensions to the original 32-bit FADT
490 1.1 jruoho * V1.0 fields. Even if they are present in the FADT, they are optional and
491 1.1 jruoho * are unused if the BIOS sets them to zero. Therefore, we must copy/expand
492 1.12 christos * 32-bit V1.0 fields to the 64-bit X fields if the 64-bit X field is originally
493 1.12 christos * zero.
494 1.1 jruoho *
495 1.4 christos * For ACPI 1.0 FADTs (that contain no 64-bit addresses), all 32-bit address
496 1.4 christos * fields are expanded to the corresponding 64-bit X fields in the internal
497 1.4 christos * common FADT.
498 1.1 jruoho *
499 1.1 jruoho * For ACPI 2.0+ FADTs, all valid (non-zero) 32-bit address fields are expanded
500 1.4 christos * to the corresponding 64-bit X fields, if the 64-bit field is originally
501 1.4 christos * zero. Adhering to the ACPI specification, we completely ignore the 32-bit
502 1.4 christos * field if the 64-bit field is valid, regardless of whether the host OS is
503 1.4 christos * 32-bit or 64-bit.
504 1.4 christos *
505 1.4 christos * Possible additional checks:
506 1.4 christos * (AcpiGbl_FADT.Pm1EventLength >= 4)
507 1.4 christos * (AcpiGbl_FADT.Pm1ControlLength >= 2)
508 1.4 christos * (AcpiGbl_FADT.PmTimerLength >= 4)
509 1.4 christos * Gpe block lengths must be multiple of 2
510 1.1 jruoho *
511 1.1 jruoho ******************************************************************************/
512 1.1 jruoho
513 1.1 jruoho static void
514 1.1 jruoho AcpiTbConvertFadt (
515 1.1 jruoho void)
516 1.1 jruoho {
517 1.9 christos const char *Name;
518 1.1 jruoho ACPI_GENERIC_ADDRESS *Address64;
519 1.1 jruoho UINT32 Address32;
520 1.4 christos UINT8 Length;
521 1.5 christos UINT8 Flags;
522 1.1 jruoho UINT32 i;
523 1.1 jruoho
524 1.1 jruoho
525 1.1 jruoho /*
526 1.11 christos * For ACPI 1.0 FADTs (revision 1 or 2), ensure that reserved fields which
527 1.1 jruoho * should be zero are indeed zero. This will workaround BIOSs that
528 1.1 jruoho * inadvertently place values in these fields.
529 1.1 jruoho *
530 1.1 jruoho * The ACPI 1.0 reserved fields that will be zeroed are the bytes located
531 1.1 jruoho * at offset 45, 55, 95, and the word located at offset 109, 110.
532 1.3 jruoho *
533 1.11 christos * Note: The FADT revision value is unreliable. Only the length can be
534 1.11 christos * trusted.
535 1.1 jruoho */
536 1.11 christos if (AcpiGbl_FADT.Header.Length <= ACPI_FADT_V2_SIZE)
537 1.1 jruoho {
538 1.1 jruoho AcpiGbl_FADT.PreferredProfile = 0;
539 1.1 jruoho AcpiGbl_FADT.PstateControl = 0;
540 1.1 jruoho AcpiGbl_FADT.CstControl = 0;
541 1.1 jruoho AcpiGbl_FADT.BootFlags = 0;
542 1.1 jruoho }
543 1.1 jruoho
544 1.1 jruoho /*
545 1.4 christos * Now we can update the local FADT length to the length of the
546 1.4 christos * current FADT version as defined by the ACPI specification.
547 1.4 christos * Thus, we will have a common FADT internally.
548 1.1 jruoho */
549 1.4 christos AcpiGbl_FADT.Header.Length = sizeof (ACPI_TABLE_FADT);
550 1.1 jruoho
551 1.1 jruoho /*
552 1.7 christos * Expand the 32-bit DSDT addresses to 64-bit as necessary.
553 1.4 christos * Later ACPICA code will always use the X 64-bit field.
554 1.1 jruoho */
555 1.4 christos AcpiGbl_FADT.XDsdt = AcpiTbSelectAddress (__UNCONST("DSDT"),
556 1.4 christos AcpiGbl_FADT.Dsdt, AcpiGbl_FADT.XDsdt);
557 1.1 jruoho
558 1.4 christos /* If Hardware Reduced flag is set, we are all done */
559 1.1 jruoho
560 1.4 christos if (AcpiGbl_ReducedHardware)
561 1.1 jruoho {
562 1.4 christos return;
563 1.1 jruoho }
564 1.1 jruoho
565 1.1 jruoho /* Examine all of the 64-bit extended address fields (X fields) */
566 1.1 jruoho
567 1.1 jruoho for (i = 0; i < ACPI_FADT_INFO_ENTRIES; i++)
568 1.1 jruoho {
569 1.1 jruoho /*
570 1.4 christos * Get the 32-bit and 64-bit addresses, as well as the register
571 1.4 christos * length and register name.
572 1.1 jruoho */
573 1.4 christos Address32 = *ACPI_ADD_PTR (UINT32,
574 1.4 christos &AcpiGbl_FADT, FadtInfoTable[i].Address32);
575 1.4 christos
576 1.1 jruoho Address64 = ACPI_ADD_PTR (ACPI_GENERIC_ADDRESS,
577 1.4 christos &AcpiGbl_FADT, FadtInfoTable[i].Address64);
578 1.4 christos
579 1.1 jruoho Length = *ACPI_ADD_PTR (UINT8,
580 1.4 christos &AcpiGbl_FADT, FadtInfoTable[i].Length);
581 1.4 christos
582 1.4 christos Name = __UNCONST(FadtInfoTable[i].Name);
583 1.5 christos Flags = FadtInfoTable[i].Flags;
584 1.4 christos
585 1.4 christos /*
586 1.4 christos * Expand the ACPI 1.0 32-bit addresses to the ACPI 2.0 64-bit "X"
587 1.4 christos * generic address structures as necessary. Later code will always use
588 1.4 christos * the 64-bit address structures.
589 1.4 christos *
590 1.4 christos * November 2013:
591 1.4 christos * Now always use the 64-bit address if it is valid (non-zero), in
592 1.4 christos * accordance with the ACPI specification which states that a 64-bit
593 1.4 christos * address supersedes the 32-bit version. This behavior can be
594 1.4 christos * overridden by the AcpiGbl_Use32BitFadtAddresses flag.
595 1.4 christos *
596 1.4 christos * During 64-bit address construction and verification,
597 1.4 christos * these cases are handled:
598 1.4 christos *
599 1.4 christos * Address32 zero, Address64 [don't care] - Use Address64
600 1.4 christos *
601 1.10 christos * No override: if AcpiGbl_Use32BitFadtAddresses is FALSE, and:
602 1.4 christos * Address32 non-zero, Address64 zero - Copy/use Address32
603 1.4 christos * Address32 non-zero == Address64 non-zero - Use Address64
604 1.4 christos * Address32 non-zero != Address64 non-zero - Warning, use Address64
605 1.4 christos *
606 1.4 christos * Override: if AcpiGbl_Use32BitFadtAddresses is TRUE, and:
607 1.10 christos * Address32 non-zero, Address64 zero - Copy/use Address32
608 1.10 christos * Address32 non-zero == Address64 non-zero - Copy/use Address32
609 1.4 christos * Address32 non-zero != Address64 non-zero - Warning, copy/use Address32
610 1.4 christos *
611 1.4 christos * Note: SpaceId is always I/O for 32-bit legacy address fields
612 1.4 christos */
613 1.4 christos if (Address32)
614 1.4 christos {
615 1.10 christos if (Address64->Address)
616 1.4 christos {
617 1.10 christos if (Address64->Address != (UINT64) Address32)
618 1.10 christos {
619 1.10 christos /* Address mismatch */
620 1.4 christos
621 1.10 christos ACPI_BIOS_WARNING ((AE_INFO,
622 1.10 christos "32/64X address mismatch in FADT/%s: "
623 1.10 christos "0x%8.8X/0x%8.8X%8.8X, using %u-bit address",
624 1.10 christos Name, Address32,
625 1.10 christos ACPI_FORMAT_UINT64 (Address64->Address),
626 1.10 christos AcpiGbl_Use32BitFadtAddresses ? 32 : 64));
627 1.10 christos }
628 1.4 christos
629 1.10 christos /*
630 1.10 christos * For each extended field, check for length mismatch
631 1.10 christos * between the legacy length field and the corresponding
632 1.10 christos * 64-bit X length field.
633 1.10 christos * Note: If the legacy length field is > 0xFF bits, ignore
634 1.10 christos * this check. (GPE registers can be larger than the
635 1.14 christos * 64-bit GAS structure can accommodate, 0xFF bits).
636 1.10 christos */
637 1.10 christos if ((ACPI_MUL_8 (Length) <= ACPI_UINT8_MAX) &&
638 1.10 christos (Address64->BitWidth != ACPI_MUL_8 (Length)))
639 1.4 christos {
640 1.10 christos ACPI_BIOS_WARNING ((AE_INFO,
641 1.10 christos "32/64X length mismatch in FADT/%s: %u/%u",
642 1.10 christos Name, ACPI_MUL_8 (Length), Address64->BitWidth));
643 1.4 christos }
644 1.4 christos }
645 1.1 jruoho
646 1.10 christos /*
647 1.10 christos * Hardware register access code always uses the 64-bit fields.
648 1.10 christos * So if the 64-bit field is zero or is to be overridden,
649 1.10 christos * initialize it with the 32-bit fields.
650 1.10 christos * Note that when the 32-bit address favor is specified, the
651 1.10 christos * 64-bit fields are always re-initialized so that
652 1.10 christos * AccessSize/BitWidth/BitOffset fields can be correctly
653 1.10 christos * configured to the values to trigger a 32-bit compatible
654 1.10 christos * access mode in the hardware register access code.
655 1.10 christos */
656 1.10 christos if (!Address64->Address || AcpiGbl_Use32BitFadtAddresses)
657 1.10 christos {
658 1.10 christos AcpiTbInitGenericAddress (Address64,
659 1.10 christos ACPI_ADR_SPACE_SYSTEM_IO, Length,
660 1.10 christos (UINT64) Address32, Name, Flags);
661 1.10 christos }
662 1.1 jruoho }
663 1.1 jruoho
664 1.5 christos if (FadtInfoTable[i].Flags & ACPI_FADT_REQUIRED)
665 1.1 jruoho {
666 1.1 jruoho /*
667 1.4 christos * Field is required (PM1aEvent, PM1aControl).
668 1.1 jruoho * Both the address and length must be non-zero.
669 1.1 jruoho */
670 1.1 jruoho if (!Address64->Address || !Length)
671 1.1 jruoho {
672 1.4 christos ACPI_BIOS_ERROR ((AE_INFO,
673 1.4 christos "Required FADT field %s has zero address and/or length: "
674 1.4 christos "0x%8.8X%8.8X/0x%X",
675 1.1 jruoho Name, ACPI_FORMAT_UINT64 (Address64->Address), Length));
676 1.1 jruoho }
677 1.1 jruoho }
678 1.5 christos else if (FadtInfoTable[i].Flags & ACPI_FADT_SEPARATE_LENGTH)
679 1.1 jruoho {
680 1.1 jruoho /*
681 1.1 jruoho * Field is optional (PM2Control, GPE0, GPE1) AND has its own
682 1.1 jruoho * length field. If present, both the address and length must
683 1.1 jruoho * be valid.
684 1.1 jruoho */
685 1.1 jruoho if ((Address64->Address && !Length) ||
686 1.1 jruoho (!Address64->Address && Length))
687 1.1 jruoho {
688 1.4 christos ACPI_BIOS_WARNING ((AE_INFO,
689 1.9 christos "Optional FADT field %s has valid %s but zero %s: "
690 1.9 christos "0x%8.8X%8.8X/0x%X", Name,
691 1.9 christos (Length ? "Length" : "Address"),
692 1.9 christos (Length ? "Address": "Length"),
693 1.9 christos ACPI_FORMAT_UINT64 (Address64->Address), Length));
694 1.1 jruoho }
695 1.1 jruoho }
696 1.1 jruoho }
697 1.1 jruoho }
698 1.1 jruoho
699 1.1 jruoho
700 1.1 jruoho /*******************************************************************************
701 1.1 jruoho *
702 1.1 jruoho * FUNCTION: AcpiTbSetupFadtRegisters
703 1.1 jruoho *
704 1.1 jruoho * PARAMETERS: None, uses AcpiGbl_FADT.
705 1.1 jruoho *
706 1.1 jruoho * RETURN: None
707 1.1 jruoho *
708 1.1 jruoho * DESCRIPTION: Initialize global ACPI PM1 register definitions. Optionally,
709 1.1 jruoho * force FADT register definitions to their default lengths.
710 1.1 jruoho *
711 1.1 jruoho ******************************************************************************/
712 1.1 jruoho
713 1.1 jruoho static void
714 1.1 jruoho AcpiTbSetupFadtRegisters (
715 1.1 jruoho void)
716 1.1 jruoho {
717 1.1 jruoho ACPI_GENERIC_ADDRESS *Target64;
718 1.1 jruoho ACPI_GENERIC_ADDRESS *Source64;
719 1.1 jruoho UINT8 Pm1RegisterByteWidth;
720 1.1 jruoho UINT32 i;
721 1.1 jruoho
722 1.1 jruoho
723 1.1 jruoho /*
724 1.1 jruoho * Optionally check all register lengths against the default values and
725 1.1 jruoho * update them if they are incorrect.
726 1.1 jruoho */
727 1.1 jruoho if (AcpiGbl_UseDefaultRegisterWidths)
728 1.1 jruoho {
729 1.1 jruoho for (i = 0; i < ACPI_FADT_INFO_ENTRIES; i++)
730 1.1 jruoho {
731 1.1 jruoho Target64 = ACPI_ADD_PTR (ACPI_GENERIC_ADDRESS, &AcpiGbl_FADT,
732 1.1 jruoho FadtInfoTable[i].Address64);
733 1.1 jruoho
734 1.1 jruoho /*
735 1.1 jruoho * If a valid register (Address != 0) and the (DefaultLength > 0)
736 1.1 jruoho * (Not a GPE register), then check the width against the default.
737 1.1 jruoho */
738 1.1 jruoho if ((Target64->Address) &&
739 1.1 jruoho (FadtInfoTable[i].DefaultLength > 0) &&
740 1.1 jruoho (FadtInfoTable[i].DefaultLength != Target64->BitWidth))
741 1.1 jruoho {
742 1.4 christos ACPI_BIOS_WARNING ((AE_INFO,
743 1.4 christos "Invalid length for FADT/%s: %u, using default %u",
744 1.1 jruoho FadtInfoTable[i].Name, Target64->BitWidth,
745 1.1 jruoho FadtInfoTable[i].DefaultLength));
746 1.1 jruoho
747 1.1 jruoho /* Incorrect size, set width to the default */
748 1.1 jruoho
749 1.1 jruoho Target64->BitWidth = FadtInfoTable[i].DefaultLength;
750 1.1 jruoho }
751 1.1 jruoho }
752 1.1 jruoho }
753 1.1 jruoho
754 1.1 jruoho /*
755 1.1 jruoho * Get the length of the individual PM1 registers (enable and status).
756 1.1 jruoho * Each register is defined to be (event block length / 2). Extra divide
757 1.1 jruoho * by 8 converts bits to bytes.
758 1.1 jruoho */
759 1.1 jruoho Pm1RegisterByteWidth = (UINT8)
760 1.1 jruoho ACPI_DIV_16 (AcpiGbl_FADT.XPm1aEventBlock.BitWidth);
761 1.1 jruoho
762 1.1 jruoho /*
763 1.1 jruoho * Calculate separate GAS structs for the PM1x (A/B) Status and Enable
764 1.1 jruoho * registers. These addresses do not appear (directly) in the FADT, so it
765 1.1 jruoho * is useful to pre-calculate them from the PM1 Event Block definitions.
766 1.1 jruoho *
767 1.1 jruoho * The PM event blocks are split into two register blocks, first is the
768 1.1 jruoho * PM Status Register block, followed immediately by the PM Enable
769 1.1 jruoho * Register block. Each is of length (Pm1EventLength/2)
770 1.1 jruoho *
771 1.1 jruoho * Note: The PM1A event block is required by the ACPI specification.
772 1.1 jruoho * However, the PM1B event block is optional and is rarely, if ever,
773 1.1 jruoho * used.
774 1.1 jruoho */
775 1.1 jruoho
776 1.1 jruoho for (i = 0; i < ACPI_FADT_PM_INFO_ENTRIES; i++)
777 1.1 jruoho {
778 1.1 jruoho Source64 = ACPI_ADD_PTR (ACPI_GENERIC_ADDRESS, &AcpiGbl_FADT,
779 1.1 jruoho FadtPmInfoTable[i].Source);
780 1.1 jruoho
781 1.1 jruoho if (Source64->Address)
782 1.1 jruoho {
783 1.1 jruoho AcpiTbInitGenericAddress (FadtPmInfoTable[i].Target,
784 1.1 jruoho Source64->SpaceId, Pm1RegisterByteWidth,
785 1.1 jruoho Source64->Address +
786 1.4 christos (FadtPmInfoTable[i].RegisterNum * Pm1RegisterByteWidth),
787 1.5 christos __UNCONST("PmRegisters"), 0);
788 1.1 jruoho }
789 1.1 jruoho }
790 1.1 jruoho }
791