diff options
Diffstat (limited to 'drivers/acpi/tables/tbfadt.c')
-rw-r--r-- | drivers/acpi/tables/tbfadt.c | 380 |
1 files changed, 380 insertions, 0 deletions
diff --git a/drivers/acpi/tables/tbfadt.c b/drivers/acpi/tables/tbfadt.c new file mode 100644 index 00000000000..2336a72fab4 --- /dev/null +++ b/drivers/acpi/tables/tbfadt.c | |||
@@ -0,0 +1,380 @@ | |||
1 | /****************************************************************************** | ||
2 | * | ||
3 | * Module Name: tbfadt - FADT table utilities | ||
4 | * | ||
5 | *****************************************************************************/ | ||
6 | |||
7 | /* | ||
8 | * Copyright (C) 2000 - 2006, R. Byron Moore | ||
9 | * All rights reserved. | ||
10 | * | ||
11 | * Redistribution and use in source and binary forms, with or without | ||
12 | * modification, are permitted provided that the following conditions | ||
13 | * are met: | ||
14 | * 1. Redistributions of source code must retain the above copyright | ||
15 | * notice, this list of conditions, and the following disclaimer, | ||
16 | * without modification. | ||
17 | * 2. Redistributions in binary form must reproduce at minimum a disclaimer | ||
18 | * substantially similar to the "NO WARRANTY" disclaimer below | ||
19 | * ("Disclaimer") and any redistribution must be conditioned upon | ||
20 | * including a substantially similar Disclaimer requirement for further | ||
21 | * binary redistribution. | ||
22 | * 3. Neither the names of the above-listed copyright holders nor the names | ||
23 | * of any contributors may be used to endorse or promote products derived | ||
24 | * from this software without specific prior written permission. | ||
25 | * | ||
26 | * Alternatively, this software may be distributed under the terms of the | ||
27 | * GNU General Public License ("GPL") version 2 as published by the Free | ||
28 | * Software Foundation. | ||
29 | * | ||
30 | * NO WARRANTY | ||
31 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
32 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
33 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR | ||
34 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
35 | * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
36 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
37 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
38 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
39 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | ||
40 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
41 | * POSSIBILITY OF SUCH DAMAGES. | ||
42 | */ | ||
43 | |||
44 | #include <acpi/acpi.h> | ||
45 | #include <acpi/actables.h> | ||
46 | |||
47 | #define _COMPONENT ACPI_TABLES | ||
48 | ACPI_MODULE_NAME("tbfadt") | ||
49 | |||
50 | /* Local prototypes */ | ||
51 | static void inline | ||
52 | acpi_tb_init_generic_address(struct acpi_generic_address *new_gas_struct, | ||
53 | u8 bit_width, u64 address); | ||
54 | |||
55 | static void acpi_tb_fadt_register_error(char *register_name, u32 value); | ||
56 | |||
57 | static void acpi_tb_convert_fadt(void); | ||
58 | |||
59 | static void acpi_tb_validate_fadt(void); | ||
60 | |||
61 | /* Table used for conversion of FADT to common format */ | ||
62 | |||
63 | typedef struct acpi_fadt_conversion { | ||
64 | u8 target; | ||
65 | u8 source; | ||
66 | u8 length; | ||
67 | |||
68 | } acpi_fadt_conversion; | ||
69 | |||
70 | static struct acpi_fadt_conversion fadt_conversion_table[] = { | ||
71 | {ACPI_FADT_OFFSET(xpm1a_event_block), | ||
72 | ACPI_FADT_OFFSET(pm1a_event_block), | ||
73 | ACPI_FADT_OFFSET(pm1_event_length)}, | ||
74 | {ACPI_FADT_OFFSET(xpm1b_event_block), | ||
75 | ACPI_FADT_OFFSET(pm1b_event_block), | ||
76 | ACPI_FADT_OFFSET(pm1_event_length)}, | ||
77 | {ACPI_FADT_OFFSET(xpm1a_control_block), | ||
78 | ACPI_FADT_OFFSET(pm1a_control_block), | ||
79 | ACPI_FADT_OFFSET(pm1_control_length)}, | ||
80 | {ACPI_FADT_OFFSET(xpm1b_control_block), | ||
81 | ACPI_FADT_OFFSET(pm1b_control_block), | ||
82 | ACPI_FADT_OFFSET(pm1_control_length)}, | ||
83 | {ACPI_FADT_OFFSET(xpm2_control_block), | ||
84 | ACPI_FADT_OFFSET(pm2_control_block), | ||
85 | ACPI_FADT_OFFSET(pm2_control_length)}, | ||
86 | {ACPI_FADT_OFFSET(xpm_timer_block), ACPI_FADT_OFFSET(pm_timer_block), | ||
87 | ACPI_FADT_OFFSET(pm_timer_length)}, | ||
88 | {ACPI_FADT_OFFSET(xgpe0_block), ACPI_FADT_OFFSET(gpe0_block), | ||
89 | ACPI_FADT_OFFSET(gpe0_block_length)}, | ||
90 | {ACPI_FADT_OFFSET(xgpe1_block), ACPI_FADT_OFFSET(gpe1_block), | ||
91 | ACPI_FADT_OFFSET(gpe1_block_length)} | ||
92 | }; | ||
93 | |||
94 | #define ACPI_FADT_CONVERSION_ENTRIES (sizeof (fadt_conversion_table) / sizeof (struct acpi_fadt_conversion)) | ||
95 | |||
96 | /******************************************************************************* | ||
97 | * | ||
98 | * FUNCTION: acpi_tb_init_generic_address | ||
99 | * | ||
100 | * PARAMETERS: new_gas_struct - GAS struct to be initialized | ||
101 | * bit_width - Width of this register | ||
102 | * Address - Address of the register | ||
103 | * | ||
104 | * RETURN: None | ||
105 | * | ||
106 | * DESCRIPTION: Initialize a GAS structure. | ||
107 | * | ||
108 | ******************************************************************************/ | ||
109 | |||
110 | static void inline | ||
111 | acpi_tb_init_generic_address(struct acpi_generic_address *new_gas_struct, | ||
112 | u8 bit_width, u64 address) | ||
113 | { | ||
114 | |||
115 | ACPI_MOVE_64_TO_64(&new_gas_struct->address, &address); | ||
116 | new_gas_struct->space_id = ACPI_ADR_SPACE_SYSTEM_IO; | ||
117 | new_gas_struct->bit_width = bit_width; | ||
118 | new_gas_struct->bit_offset = 0; | ||
119 | new_gas_struct->access_width = 0; | ||
120 | } | ||
121 | |||
122 | /******************************************************************************* | ||
123 | * | ||
124 | * FUNCTION: acpi_tb_parse_fadt | ||
125 | * | ||
126 | * PARAMETERS: table_index - Index for the FADT | ||
127 | * Flags - Flags | ||
128 | * | ||
129 | * RETURN: None | ||
130 | * | ||
131 | * DESCRIPTION: Initialize the FADT, DSDT and FACS tables | ||
132 | * (FADT contains the addresses of the DSDT and FACS) | ||
133 | * | ||
134 | ******************************************************************************/ | ||
135 | |||
136 | void acpi_tb_parse_fadt(acpi_native_uint table_index, u8 flags) | ||
137 | { | ||
138 | u32 length; | ||
139 | struct acpi_table_header *table; | ||
140 | |||
141 | /* | ||
142 | * Special case for the FADT because of multiple versions and the fact | ||
143 | * that it contains pointers to both the DSDT and FACS tables. | ||
144 | * | ||
145 | * Get a local copy of the FADT and convert it to a common format | ||
146 | * Map entire FADT, assumed to be smaller than one page. | ||
147 | */ | ||
148 | length = acpi_gbl_root_table_list.tables[table_index].length; | ||
149 | |||
150 | table = | ||
151 | acpi_os_map_memory(acpi_gbl_root_table_list.tables[table_index]. | ||
152 | address, length); | ||
153 | if (!table) { | ||
154 | return; | ||
155 | } | ||
156 | |||
157 | /* | ||
158 | * Validate the FADT checksum before we copy the table. Ignore | ||
159 | * checksum error as we want to try to get the DSDT and FACS. | ||
160 | */ | ||
161 | (void)acpi_tb_verify_checksum(table, length); | ||
162 | |||
163 | /* Copy the entire FADT locally */ | ||
164 | |||
165 | ACPI_MEMSET(&acpi_gbl_FADT, 0, sizeof(struct acpi_table_fadt)); | ||
166 | |||
167 | ACPI_MEMCPY(&acpi_gbl_FADT, table, | ||
168 | ACPI_MIN(length, sizeof(struct acpi_table_fadt))); | ||
169 | acpi_os_unmap_memory(table, length); | ||
170 | |||
171 | /* Convert local FADT to the common internal format */ | ||
172 | |||
173 | acpi_tb_convert_fadt(); | ||
174 | |||
175 | /* Extract the DSDT and FACS tables from the FADT */ | ||
176 | |||
177 | acpi_tb_install_table((acpi_physical_address) acpi_gbl_FADT.Xdsdt, | ||
178 | flags, ACPI_SIG_DSDT, ACPI_TABLE_INDEX_DSDT); | ||
179 | |||
180 | acpi_tb_install_table((acpi_physical_address) acpi_gbl_FADT.Xfacs, | ||
181 | flags, ACPI_SIG_FACS, ACPI_TABLE_INDEX_FACS); | ||
182 | |||
183 | /* Validate important FADT values */ | ||
184 | |||
185 | acpi_tb_validate_fadt(); | ||
186 | } | ||
187 | |||
188 | /******************************************************************************* | ||
189 | * | ||
190 | * FUNCTION: acpi_tb_convert_fadt | ||
191 | * | ||
192 | * PARAMETERS: None, uses acpi_gbl_FADT | ||
193 | * | ||
194 | * RETURN: None | ||
195 | * | ||
196 | * DESCRIPTION: Converts all versions of the FADT to a common internal format. | ||
197 | * | ||
198 | * NOTE: acpi_gbl_FADT must be of size (struct acpi_table_fadt), and must contain | ||
199 | * a copy of the actual FADT. | ||
200 | * | ||
201 | * ACPICA will use the "X" fields of the FADT for all addresses. | ||
202 | * | ||
203 | * "X" fields are optional extensions to the original V1.0 fields. Even if | ||
204 | * they are present in the structure, they can be optionally not used by | ||
205 | * setting them to zero. Therefore, we must selectively expand V1.0 fields | ||
206 | * if the corresponding X field is zero. | ||
207 | * | ||
208 | * For ACPI 1.0 FADTs, all address fields are expanded to the corresponding | ||
209 | * "X" fields. | ||
210 | * | ||
211 | * For ACPI 2.0 FADTs, any "X" fields that are NULL are filled in by | ||
212 | * expanding the corresponding ACPI 1.0 field. | ||
213 | * | ||
214 | ******************************************************************************/ | ||
215 | |||
216 | static void acpi_tb_convert_fadt(void) | ||
217 | { | ||
218 | u8 pm1_register_length; | ||
219 | struct acpi_generic_address *target; | ||
220 | acpi_native_uint i; | ||
221 | |||
222 | /* Expand the FACS and DSDT addresses as necessary */ | ||
223 | |||
224 | if (!acpi_gbl_FADT.Xfacs) { | ||
225 | acpi_gbl_FADT.Xfacs = (u64) acpi_gbl_FADT.facs; | ||
226 | } | ||
227 | |||
228 | if (!acpi_gbl_FADT.Xdsdt) { | ||
229 | acpi_gbl_FADT.Xdsdt = (u64) acpi_gbl_FADT.dsdt; | ||
230 | } | ||
231 | |||
232 | /* | ||
233 | * Expand the 32-bit V1.0 addresses to the 64-bit "X" generic address | ||
234 | * structures as necessary. | ||
235 | */ | ||
236 | for (i = 0; i < ACPI_FADT_CONVERSION_ENTRIES; i++) { | ||
237 | target = | ||
238 | ACPI_ADD_PTR(struct acpi_generic_address, &acpi_gbl_FADT, | ||
239 | fadt_conversion_table[i].target); | ||
240 | |||
241 | /* Expand only if the X target is null */ | ||
242 | |||
243 | if (!target->address) { | ||
244 | acpi_tb_init_generic_address(target, | ||
245 | *ACPI_ADD_PTR(u8, | ||
246 | &acpi_gbl_FADT, | ||
247 | fadt_conversion_table | ||
248 | [i].length), | ||
249 | (u64) * ACPI_ADD_PTR(u32, | ||
250 | &acpi_gbl_FADT, | ||
251 | fadt_conversion_table | ||
252 | [i]. | ||
253 | source)); | ||
254 | } | ||
255 | } | ||
256 | |||
257 | /* | ||
258 | * Calculate separate GAS structs for the PM1 Enable registers. | ||
259 | * These addresses do not appear (directly) in the FADT, so it is | ||
260 | * useful to calculate them once, here. | ||
261 | * | ||
262 | * The PM event blocks are split into two register blocks, first is the | ||
263 | * PM Status Register block, followed immediately by the PM Enable Register | ||
264 | * block. Each is of length (pm1_event_length/2) | ||
265 | */ | ||
266 | pm1_register_length = (u8) ACPI_DIV_2(acpi_gbl_FADT.pm1_event_length); | ||
267 | |||
268 | /* PM1A is required */ | ||
269 | |||
270 | acpi_tb_init_generic_address(&acpi_gbl_xpm1a_enable, | ||
271 | pm1_register_length, | ||
272 | (acpi_gbl_FADT.xpm1a_event_block.address + | ||
273 | pm1_register_length)); | ||
274 | |||
275 | /* PM1B is optional; leave null if not present */ | ||
276 | |||
277 | if (acpi_gbl_FADT.xpm1b_event_block.address) { | ||
278 | acpi_tb_init_generic_address(&acpi_gbl_xpm1b_enable, | ||
279 | pm1_register_length, | ||
280 | (acpi_gbl_FADT.xpm1b_event_block. | ||
281 | address + pm1_register_length)); | ||
282 | } | ||
283 | |||
284 | /* Global FADT is the new common V2.0 FADT */ | ||
285 | |||
286 | acpi_gbl_FADT.header.length = sizeof(struct acpi_table_fadt); | ||
287 | } | ||
288 | |||
289 | /****************************************************************************** | ||
290 | * | ||
291 | * FUNCTION: acpi_tb_validate_fadt | ||
292 | * | ||
293 | * PARAMETERS: None | ||
294 | * | ||
295 | * RETURN: Status | ||
296 | * | ||
297 | * DESCRIPTION: Validate various ACPI registers in the FADT | ||
298 | * | ||
299 | ******************************************************************************/ | ||
300 | |||
301 | static void acpi_tb_validate_fadt(void) | ||
302 | { | ||
303 | |||
304 | /* These length fields have a minimum value */ | ||
305 | |||
306 | if (acpi_gbl_FADT.pm1_event_length < 4) { | ||
307 | acpi_tb_fadt_register_error("Pm1EventLength", | ||
308 | (u32) acpi_gbl_FADT. | ||
309 | pm1_event_length); | ||
310 | } | ||
311 | |||
312 | if (acpi_gbl_FADT.pm_timer_length < 4) { | ||
313 | acpi_tb_fadt_register_error("PmTimerLength", | ||
314 | (u32) acpi_gbl_FADT. | ||
315 | pm_timer_length); | ||
316 | } | ||
317 | |||
318 | /* These length and address fields must be non-zero */ | ||
319 | |||
320 | if (!acpi_gbl_FADT.pm1_control_length) { | ||
321 | acpi_tb_fadt_register_error("Pm1ControlLength", 0); | ||
322 | } | ||
323 | |||
324 | if (!acpi_gbl_FADT.xpm1a_event_block.address) { | ||
325 | acpi_tb_fadt_register_error("XPm1aEventBlock.Address", 0); | ||
326 | } | ||
327 | |||
328 | if (!acpi_gbl_FADT.xpm1a_control_block.address) { | ||
329 | acpi_tb_fadt_register_error("XPm1aControlBlock.Address", 0); | ||
330 | } | ||
331 | |||
332 | if (!acpi_gbl_FADT.xpm_timer_block.address) { | ||
333 | acpi_tb_fadt_register_error("XPmTimerBlock.Address", 0); | ||
334 | } | ||
335 | |||
336 | /* If PM2 block is present, must have non-zero length */ | ||
337 | |||
338 | if ((acpi_gbl_FADT.xpm2_control_block.address && | ||
339 | !acpi_gbl_FADT.pm2_control_length)) { | ||
340 | acpi_tb_fadt_register_error("Pm2ControlLength", | ||
341 | (u32) acpi_gbl_FADT. | ||
342 | pm2_control_length); | ||
343 | } | ||
344 | |||
345 | /* Length of any valid GPE blocks must be a multiple of 2 */ | ||
346 | |||
347 | if (acpi_gbl_FADT.xgpe0_block.address && | ||
348 | (acpi_gbl_FADT.gpe0_block_length & 1)) { | ||
349 | acpi_tb_fadt_register_error("Gpe0BlockLength", | ||
350 | (u32) acpi_gbl_FADT. | ||
351 | gpe0_block_length); | ||
352 | } | ||
353 | |||
354 | if (acpi_gbl_FADT.xgpe1_block.address && | ||
355 | (acpi_gbl_FADT.gpe1_block_length & 1)) { | ||
356 | acpi_tb_fadt_register_error("Gpe1BlockLength", | ||
357 | (u32) acpi_gbl_FADT. | ||
358 | gpe1_block_length); | ||
359 | } | ||
360 | } | ||
361 | |||
362 | /******************************************************************************* | ||
363 | * | ||
364 | * FUNCTION: acpi_tb_fadt_register_error | ||
365 | * | ||
366 | * PARAMETERS: register_name - Pointer to string identifying register | ||
367 | * Value - Actual register contents value | ||
368 | * | ||
369 | * RETURN: None | ||
370 | * | ||
371 | * DESCRIPTION: Display FADT warning message | ||
372 | * | ||
373 | ******************************************************************************/ | ||
374 | |||
375 | static void acpi_tb_fadt_register_error(char *register_name, u32 value) | ||
376 | { | ||
377 | |||
378 | ACPI_WARNING((AE_INFO, "Invalid FADT value \"%s\" = %X", | ||
379 | register_name, value)); | ||
380 | } | ||