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