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