blob: 5155b27cf03205c79f9a7155f9588a9153a13a0a [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/******************************************************************************
2 *
3 * Module Name: tbconvrt - ACPI Table conversion utilities
4 *
5 *****************************************************************************/
6
7/*
Bob Moore4a90c7e2006-01-13 16:22:00 -05008 * Copyright (C) 2000 - 2006, R. Byron Moore
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 * 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
Linus Torvalds1da177e2005-04-16 15:20:36 -070044#include <acpi/acpi.h>
45#include <acpi/actables.h>
46
Linus Torvalds1da177e2005-04-16 15:20:36 -070047#define _COMPONENT ACPI_TABLES
Len Brown4be44fc2005-08-05 00:44:28 -040048ACPI_MODULE_NAME("tbconvrt")
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
Robert Moore44f6c012005-04-18 22:49:35 -040050/* Local prototypes */
Len Brown4be44fc2005-08-05 00:44:28 -040051static void
52acpi_tb_init_generic_address(struct acpi_generic_address *new_gas_struct,
53 u8 register_bit_width,
54 acpi_physical_address address);
Robert Moore44f6c012005-04-18 22:49:35 -040055
56static void
Len Brown4be44fc2005-08-05 00:44:28 -040057acpi_tb_convert_fadt1(struct fadt_descriptor_rev2 *local_fadt,
58 struct fadt_descriptor_rev1 *original_fadt);
Robert Moore44f6c012005-04-18 22:49:35 -040059
60static void
Len Brown4be44fc2005-08-05 00:44:28 -040061acpi_tb_convert_fadt2(struct fadt_descriptor_rev2 *local_fadt,
62 struct fadt_descriptor_rev2 *original_fadt);
Linus Torvalds1da177e2005-04-16 15:20:36 -070063
64u8 acpi_fadt_is_v1;
Bob Moore83135242006-10-03 00:00:00 -040065ACPI_EXPORT_SYMBOL(acpi_fadt_is_v1)
Linus Torvalds1da177e2005-04-16 15:20:36 -070066
67/*******************************************************************************
68 *
69 * FUNCTION: acpi_tb_get_table_count
70 *
71 * PARAMETERS: RSDP - Pointer to the RSDP
72 * RSDT - Pointer to the RSDT/XSDT
73 *
74 * RETURN: The number of tables pointed to by the RSDT or XSDT.
75 *
76 * DESCRIPTION: Calculate the number of tables. Automatically handles either
77 * an RSDT or XSDT.
78 *
79 ******************************************************************************/
80
81u32
Len Brown4be44fc2005-08-05 00:44:28 -040082acpi_tb_get_table_count(struct rsdp_descriptor *RSDP,
83 struct acpi_table_header *RSDT)
Linus Torvalds1da177e2005-04-16 15:20:36 -070084{
Len Brown4be44fc2005-08-05 00:44:28 -040085 u32 pointer_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -070086
Len Brown4be44fc2005-08-05 00:44:28 -040087 ACPI_FUNCTION_ENTRY();
Linus Torvalds1da177e2005-04-16 15:20:36 -070088
Robert Moore73459f72005-06-24 00:00:00 -040089 /* RSDT pointers are 32 bits, XSDT pointers are 64 bits */
90
91 if (acpi_gbl_root_table_type == ACPI_TABLE_TYPE_RSDT) {
Len Brown4be44fc2005-08-05 00:44:28 -040092 pointer_size = sizeof(u32);
93 } else {
94 pointer_size = sizeof(u64);
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 }
96
97 /*
98 * Determine the number of tables pointed to by the RSDT/XSDT.
99 * This is defined by the ACPI Specification to be the number of
100 * pointers contained within the RSDT/XSDT. The size of the pointers
101 * is architecture-dependent.
102 */
Len Brown4be44fc2005-08-05 00:44:28 -0400103 return ((RSDT->length -
104 sizeof(struct acpi_table_header)) / pointer_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105}
106
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107/*******************************************************************************
108 *
109 * FUNCTION: acpi_tb_convert_to_xsdt
110 *
111 * PARAMETERS: table_info - Info about the RSDT
112 *
113 * RETURN: Status
114 *
115 * DESCRIPTION: Convert an RSDT to an XSDT (internal common format)
116 *
117 ******************************************************************************/
118
Len Brown4be44fc2005-08-05 00:44:28 -0400119acpi_status acpi_tb_convert_to_xsdt(struct acpi_table_desc *table_info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120{
Len Brown4be44fc2005-08-05 00:44:28 -0400121 acpi_size table_size;
122 u32 i;
123 XSDT_DESCRIPTOR *new_table;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124
Len Brown4be44fc2005-08-05 00:44:28 -0400125 ACPI_FUNCTION_ENTRY();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126
127 /* Compute size of the converted XSDT */
128
Len Brown4be44fc2005-08-05 00:44:28 -0400129 table_size = ((acpi_size) acpi_gbl_rsdt_table_count * sizeof(u64)) +
130 sizeof(struct acpi_table_header);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131
132 /* Allocate an XSDT */
133
Bob Moore83135242006-10-03 00:00:00 -0400134 new_table = ACPI_ALLOCATE_ZEROED(table_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 if (!new_table) {
136 return (AE_NO_MEMORY);
137 }
138
139 /* Copy the header and set the length */
140
Len Brown4be44fc2005-08-05 00:44:28 -0400141 ACPI_MEMCPY(new_table, table_info->pointer,
142 sizeof(struct acpi_table_header));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 new_table->length = (u32) table_size;
144
145 /* Copy the table pointers */
146
147 for (i = 0; i < acpi_gbl_rsdt_table_count; i++) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400148
Robert Moore73459f72005-06-24 00:00:00 -0400149 /* RSDT pointers are 32 bits, XSDT pointers are 64 bits */
150
151 if (acpi_gbl_root_table_type == ACPI_TABLE_TYPE_RSDT) {
Len Brown4be44fc2005-08-05 00:44:28 -0400152 ACPI_STORE_ADDRESS(new_table->table_offset_entry[i],
153 (ACPI_CAST_PTR
154 (struct rsdt_descriptor_rev1,
155 table_info->pointer))->
156 table_offset_entry[i]);
157 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 new_table->table_offset_entry[i] =
Len Brown4be44fc2005-08-05 00:44:28 -0400159 (ACPI_CAST_PTR(XSDT_DESCRIPTOR,
160 table_info->pointer))->
161 table_offset_entry[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162 }
163 }
164
165 /* Delete the original table (either mapped or in a buffer) */
166
Len Brown4be44fc2005-08-05 00:44:28 -0400167 acpi_tb_delete_single_table(table_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168
169 /* Point the table descriptor to the new table */
170
Len Brown4be44fc2005-08-05 00:44:28 -0400171 table_info->pointer =
172 ACPI_CAST_PTR(struct acpi_table_header, new_table);
173 table_info->length = table_size;
174 table_info->allocation = ACPI_MEM_ALLOCATED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175
176 return (AE_OK);
177}
178
Robert Moore44f6c012005-04-18 22:49:35 -0400179/*******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 *
181 * FUNCTION: acpi_tb_init_generic_address
182 *
183 * PARAMETERS: new_gas_struct - GAS struct to be initialized
184 * register_bit_width - Width of this register
185 * Address - Address of the register
186 *
187 * RETURN: None
188 *
189 * DESCRIPTION: Initialize a GAS structure.
190 *
191 ******************************************************************************/
192
193static void
Len Brown4be44fc2005-08-05 00:44:28 -0400194acpi_tb_init_generic_address(struct acpi_generic_address *new_gas_struct,
195 u8 register_bit_width,
196 acpi_physical_address address)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197{
198
Len Brown4be44fc2005-08-05 00:44:28 -0400199 ACPI_STORE_ADDRESS(new_gas_struct->address, address);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200
201 new_gas_struct->address_space_id = ACPI_ADR_SPACE_SYSTEM_IO;
202 new_gas_struct->register_bit_width = register_bit_width;
203 new_gas_struct->register_bit_offset = 0;
Len Brown4be44fc2005-08-05 00:44:28 -0400204 new_gas_struct->access_width = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205}
206
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207/*******************************************************************************
208 *
209 * FUNCTION: acpi_tb_convert_fadt1
210 *
211 * PARAMETERS: local_fadt - Pointer to new FADT
212 * original_fadt - Pointer to old FADT
213 *
Robert Moore44f6c012005-04-18 22:49:35 -0400214 * RETURN: None, populates local_fadt
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215 *
216 * DESCRIPTION: Convert an ACPI 1.0 FADT to common internal format
217 *
218 ******************************************************************************/
219
220static void
Len Brown4be44fc2005-08-05 00:44:28 -0400221acpi_tb_convert_fadt1(struct fadt_descriptor_rev2 *local_fadt,
222 struct fadt_descriptor_rev1 *original_fadt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223{
224
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 /* ACPI 1.0 FACS */
226 /* The BIOS stored FADT should agree with Revision 1.0 */
227 acpi_fadt_is_v1 = 1;
228
229 /*
230 * Copy the table header and the common part of the tables.
231 *
232 * The 2.0 table is an extension of the 1.0 table, so the entire 1.0
233 * table can be copied first, then expand some fields to 64 bits.
234 */
Len Brown4be44fc2005-08-05 00:44:28 -0400235 ACPI_MEMCPY(local_fadt, original_fadt,
236 sizeof(struct fadt_descriptor_rev1));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237
238 /* Convert table pointers to 64-bit fields */
239
Len Brown4be44fc2005-08-05 00:44:28 -0400240 ACPI_STORE_ADDRESS(local_fadt->xfirmware_ctrl,
241 local_fadt->V1_firmware_ctrl);
242 ACPI_STORE_ADDRESS(local_fadt->Xdsdt, local_fadt->V1_dsdt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243
244 /*
Robert Moore44f6c012005-04-18 22:49:35 -0400245 * System Interrupt Model isn't used in ACPI 2.0
246 * (local_fadt->Reserved1 = 0;)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247 */
248
249 /*
250 * This field is set by the OEM to convey the preferred power management
251 * profile to OSPM. It doesn't have any 1.0 equivalence. Since we don't
252 * know what kind of 32-bit system this is, we will use "unspecified".
253 */
254 local_fadt->prefer_PM_profile = PM_UNSPECIFIED;
255
256 /*
257 * Processor Performance State Control. This is the value OSPM writes to
258 * the SMI_CMD register to assume processor performance state control
259 * responsibility. There isn't any equivalence in 1.0, but as many 1.x
260 * ACPI tables contain _PCT and _PSS we also keep this value, unless
261 * acpi_strict is set.
262 */
263 if (acpi_strict)
264 local_fadt->pstate_cnt = 0;
265
266 /*
267 * Support for the _CST object and C States change notification.
268 * This data item hasn't any 1.0 equivalence so leave it zero.
269 */
270 local_fadt->cst_cnt = 0;
271
272 /*
273 * FADT Rev 2 was an interim FADT released between ACPI 1.0 and ACPI 2.0.
274 * It primarily adds the FADT reset mechanism.
275 */
276 if ((original_fadt->revision == 2) &&
Len Brown4be44fc2005-08-05 00:44:28 -0400277 (original_fadt->length ==
278 sizeof(struct fadt_descriptor_rev2_minus))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279 /*
280 * Grab the entire generic address struct, plus the 1-byte reset value
281 * that immediately follows.
282 */
Len Brown4be44fc2005-08-05 00:44:28 -0400283 ACPI_MEMCPY(&local_fadt->reset_register,
284 &(ACPI_CAST_PTR(struct fadt_descriptor_rev2_minus,
285 original_fadt))->reset_register,
286 sizeof(struct acpi_generic_address) + 1);
287 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288 /*
289 * Since there isn't any equivalence in 1.0 and since it is highly
290 * likely that a 1.0 system has legacy support.
291 */
292 local_fadt->iapc_boot_arch = BAF_LEGACY_DEVICES;
293 }
294
295 /*
296 * Convert the V1.0 block addresses to V2.0 GAS structures
297 */
Len Brown4be44fc2005-08-05 00:44:28 -0400298 acpi_tb_init_generic_address(&local_fadt->xpm1a_evt_blk,
299 local_fadt->pm1_evt_len,
300 (acpi_physical_address) local_fadt->
301 V1_pm1a_evt_blk);
302 acpi_tb_init_generic_address(&local_fadt->xpm1b_evt_blk,
303 local_fadt->pm1_evt_len,
304 (acpi_physical_address) local_fadt->
305 V1_pm1b_evt_blk);
306 acpi_tb_init_generic_address(&local_fadt->xpm1a_cnt_blk,
307 local_fadt->pm1_cnt_len,
308 (acpi_physical_address) local_fadt->
309 V1_pm1a_cnt_blk);
310 acpi_tb_init_generic_address(&local_fadt->xpm1b_cnt_blk,
311 local_fadt->pm1_cnt_len,
312 (acpi_physical_address) local_fadt->
313 V1_pm1b_cnt_blk);
314 acpi_tb_init_generic_address(&local_fadt->xpm2_cnt_blk,
315 local_fadt->pm2_cnt_len,
316 (acpi_physical_address) local_fadt->
317 V1_pm2_cnt_blk);
318 acpi_tb_init_generic_address(&local_fadt->xpm_tmr_blk,
319 local_fadt->pm_tm_len,
320 (acpi_physical_address) local_fadt->
321 V1_pm_tmr_blk);
322 acpi_tb_init_generic_address(&local_fadt->xgpe0_blk, 0,
323 (acpi_physical_address) local_fadt->
324 V1_gpe0_blk);
325 acpi_tb_init_generic_address(&local_fadt->xgpe1_blk, 0,
326 (acpi_physical_address) local_fadt->
327 V1_gpe1_blk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328
329 /* Create separate GAS structs for the PM1 Enable registers */
330
Len Brown4be44fc2005-08-05 00:44:28 -0400331 acpi_tb_init_generic_address(&acpi_gbl_xpm1a_enable,
332 (u8) ACPI_DIV_2(acpi_gbl_FADT->
333 pm1_evt_len),
334 (acpi_physical_address)
335 (local_fadt->xpm1a_evt_blk.address +
336 ACPI_DIV_2(acpi_gbl_FADT->pm1_evt_len)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337
338 /* PM1B is optional; leave null if not present */
339
340 if (local_fadt->xpm1b_evt_blk.address) {
Len Brown4be44fc2005-08-05 00:44:28 -0400341 acpi_tb_init_generic_address(&acpi_gbl_xpm1b_enable,
342 (u8) ACPI_DIV_2(acpi_gbl_FADT->
343 pm1_evt_len),
344 (acpi_physical_address)
345 (local_fadt->xpm1b_evt_blk.
346 address +
347 ACPI_DIV_2(acpi_gbl_FADT->
348 pm1_evt_len)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 }
350}
351
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352/*******************************************************************************
353 *
354 * FUNCTION: acpi_tb_convert_fadt2
355 *
356 * PARAMETERS: local_fadt - Pointer to new FADT
357 * original_fadt - Pointer to old FADT
358 *
Robert Moore44f6c012005-04-18 22:49:35 -0400359 * RETURN: None, populates local_fadt
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360 *
361 * DESCRIPTION: Convert an ACPI 2.0 FADT to common internal format.
362 * Handles optional "X" fields.
363 *
364 ******************************************************************************/
365
366static void
Len Brown4be44fc2005-08-05 00:44:28 -0400367acpi_tb_convert_fadt2(struct fadt_descriptor_rev2 *local_fadt,
368 struct fadt_descriptor_rev2 *original_fadt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369{
370
371 /* We have an ACPI 2.0 FADT but we must copy it to our local buffer */
372
Len Brown4be44fc2005-08-05 00:44:28 -0400373 ACPI_MEMCPY(local_fadt, original_fadt,
374 sizeof(struct fadt_descriptor_rev2));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375
376 /*
377 * "X" fields are optional extensions to the original V1.0 fields, so
378 * we must selectively expand V1.0 fields if the corresponding X field
379 * is zero.
380 */
381 if (!(local_fadt->xfirmware_ctrl)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400382 ACPI_STORE_ADDRESS(local_fadt->xfirmware_ctrl,
383 local_fadt->V1_firmware_ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384 }
385
386 if (!(local_fadt->Xdsdt)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400387 ACPI_STORE_ADDRESS(local_fadt->Xdsdt, local_fadt->V1_dsdt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388 }
389
390 if (!(local_fadt->xpm1a_evt_blk.address)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400391 acpi_tb_init_generic_address(&local_fadt->xpm1a_evt_blk,
392 local_fadt->pm1_evt_len,
393 (acpi_physical_address)
394 local_fadt->V1_pm1a_evt_blk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 }
396
397 if (!(local_fadt->xpm1b_evt_blk.address)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400398 acpi_tb_init_generic_address(&local_fadt->xpm1b_evt_blk,
399 local_fadt->pm1_evt_len,
400 (acpi_physical_address)
401 local_fadt->V1_pm1b_evt_blk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 }
403
404 if (!(local_fadt->xpm1a_cnt_blk.address)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400405 acpi_tb_init_generic_address(&local_fadt->xpm1a_cnt_blk,
406 local_fadt->pm1_cnt_len,
407 (acpi_physical_address)
408 local_fadt->V1_pm1a_cnt_blk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409 }
410
411 if (!(local_fadt->xpm1b_cnt_blk.address)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400412 acpi_tb_init_generic_address(&local_fadt->xpm1b_cnt_blk,
413 local_fadt->pm1_cnt_len,
414 (acpi_physical_address)
415 local_fadt->V1_pm1b_cnt_blk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416 }
417
418 if (!(local_fadt->xpm2_cnt_blk.address)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400419 acpi_tb_init_generic_address(&local_fadt->xpm2_cnt_blk,
420 local_fadt->pm2_cnt_len,
421 (acpi_physical_address)
422 local_fadt->V1_pm2_cnt_blk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 }
424
425 if (!(local_fadt->xpm_tmr_blk.address)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400426 acpi_tb_init_generic_address(&local_fadt->xpm_tmr_blk,
427 local_fadt->pm_tm_len,
428 (acpi_physical_address)
429 local_fadt->V1_pm_tmr_blk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 }
431
432 if (!(local_fadt->xgpe0_blk.address)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400433 acpi_tb_init_generic_address(&local_fadt->xgpe0_blk,
434 0,
435 (acpi_physical_address)
436 local_fadt->V1_gpe0_blk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437 }
438
439 if (!(local_fadt->xgpe1_blk.address)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400440 acpi_tb_init_generic_address(&local_fadt->xgpe1_blk,
441 0,
442 (acpi_physical_address)
443 local_fadt->V1_gpe1_blk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444 }
445
446 /* Create separate GAS structs for the PM1 Enable registers */
447
Len Brown4be44fc2005-08-05 00:44:28 -0400448 acpi_tb_init_generic_address(&acpi_gbl_xpm1a_enable,
449 (u8) ACPI_DIV_2(acpi_gbl_FADT->
450 pm1_evt_len),
451 (acpi_physical_address)
452 (local_fadt->xpm1a_evt_blk.address +
453 ACPI_DIV_2(acpi_gbl_FADT->pm1_evt_len)));
Robert Moore44f6c012005-04-18 22:49:35 -0400454
455 acpi_gbl_xpm1a_enable.address_space_id =
Len Brown4be44fc2005-08-05 00:44:28 -0400456 local_fadt->xpm1a_evt_blk.address_space_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457
458 /* PM1B is optional; leave null if not present */
459
460 if (local_fadt->xpm1b_evt_blk.address) {
Len Brown4be44fc2005-08-05 00:44:28 -0400461 acpi_tb_init_generic_address(&acpi_gbl_xpm1b_enable,
462 (u8) ACPI_DIV_2(acpi_gbl_FADT->
463 pm1_evt_len),
464 (acpi_physical_address)
465 (local_fadt->xpm1b_evt_blk.
466 address +
467 ACPI_DIV_2(acpi_gbl_FADT->
468 pm1_evt_len)));
Robert Moore44f6c012005-04-18 22:49:35 -0400469
470 acpi_gbl_xpm1b_enable.address_space_id =
Len Brown4be44fc2005-08-05 00:44:28 -0400471 local_fadt->xpm1b_evt_blk.address_space_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 }
473}
474
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475/*******************************************************************************
476 *
477 * FUNCTION: acpi_tb_convert_table_fadt
478 *
479 * PARAMETERS: None
480 *
481 * RETURN: Status
482 *
483 * DESCRIPTION: Converts a BIOS supplied ACPI 1.0 FADT to a local
484 * ACPI 2.0 FADT. If the BIOS supplied a 2.0 FADT then it is simply
485 * copied to the local FADT. The ACPI CA software uses this
486 * local FADT. Thus a significant amount of special #ifdef
487 * type codeing is saved.
488 *
489 ******************************************************************************/
490
Len Brown4be44fc2005-08-05 00:44:28 -0400491acpi_status acpi_tb_convert_table_fadt(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492{
Len Brown4be44fc2005-08-05 00:44:28 -0400493 struct fadt_descriptor_rev2 *local_fadt;
494 struct acpi_table_desc *table_desc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495
Len Brown4be44fc2005-08-05 00:44:28 -0400496 ACPI_FUNCTION_TRACE("tb_convert_table_fadt");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497
498 /*
499 * acpi_gbl_FADT is valid. Validate the FADT length. The table must be
500 * at least as long as the version 1.0 FADT
501 */
Len Brown4be44fc2005-08-05 00:44:28 -0400502 if (acpi_gbl_FADT->length < sizeof(struct fadt_descriptor_rev1)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500503 ACPI_ERROR((AE_INFO, "FADT is invalid, too short: 0x%X",
504 acpi_gbl_FADT->length));
Len Brown4be44fc2005-08-05 00:44:28 -0400505 return_ACPI_STATUS(AE_INVALID_TABLE_LENGTH);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 }
507
508 /* Allocate buffer for the ACPI 2.0(+) FADT */
509
Bob Moore83135242006-10-03 00:00:00 -0400510 local_fadt = ACPI_ALLOCATE_ZEROED(sizeof(struct fadt_descriptor_rev2));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 if (!local_fadt) {
Len Brown4be44fc2005-08-05 00:44:28 -0400512 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 }
514
515 if (acpi_gbl_FADT->revision >= FADT2_REVISION_ID) {
Len Brown4be44fc2005-08-05 00:44:28 -0400516 if (acpi_gbl_FADT->length < sizeof(struct fadt_descriptor_rev2)) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400517
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 /* Length is too short to be a V2.0 table */
519
Bob Mooreb8e4d892006-01-27 16:43:00 -0500520 ACPI_WARNING((AE_INFO,
521 "Inconsistent FADT length (0x%X) and revision (0x%X), using FADT V1.0 portion of table",
522 acpi_gbl_FADT->length,
523 acpi_gbl_FADT->revision));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524
Len Brown4be44fc2005-08-05 00:44:28 -0400525 acpi_tb_convert_fadt1(local_fadt,
526 (void *)acpi_gbl_FADT);
527 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 /* Valid V2.0 table */
529
Len Brown4be44fc2005-08-05 00:44:28 -0400530 acpi_tb_convert_fadt2(local_fadt, acpi_gbl_FADT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 }
Len Brown4be44fc2005-08-05 00:44:28 -0400532 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 /* Valid V1.0 table */
534
Len Brown4be44fc2005-08-05 00:44:28 -0400535 acpi_tb_convert_fadt1(local_fadt, (void *)acpi_gbl_FADT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 }
537
Robert Moore44f6c012005-04-18 22:49:35 -0400538 /* Global FADT pointer will point to the new common V2.0 FADT */
539
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540 acpi_gbl_FADT = local_fadt;
Len Brown4be44fc2005-08-05 00:44:28 -0400541 acpi_gbl_FADT->length = sizeof(FADT_DESCRIPTOR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542
543 /* Free the original table */
544
545 table_desc = acpi_gbl_table_lists[ACPI_TABLE_FADT].next;
Len Brown4be44fc2005-08-05 00:44:28 -0400546 acpi_tb_delete_single_table(table_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547
548 /* Install the new table */
549
Len Brown4be44fc2005-08-05 00:44:28 -0400550 table_desc->pointer =
551 ACPI_CAST_PTR(struct acpi_table_header, acpi_gbl_FADT);
552 table_desc->allocation = ACPI_MEM_ALLOCATED;
553 table_desc->length = sizeof(struct fadt_descriptor_rev2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554
555 /* Dump the entire FADT */
556
Len Brown4be44fc2005-08-05 00:44:28 -0400557 ACPI_DEBUG_PRINT((ACPI_DB_TABLES,
558 "Hex dump of common internal FADT, size %d (%X)\n",
559 acpi_gbl_FADT->length, acpi_gbl_FADT->length));
Bob Moorec51a4de2005-11-17 13:07:00 -0500560
561 ACPI_DUMP_BUFFER(ACPI_CAST_PTR(u8, acpi_gbl_FADT),
562 acpi_gbl_FADT->length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563
Len Brown4be44fc2005-08-05 00:44:28 -0400564 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565}
566
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567/*******************************************************************************
568 *
Robert Moore44f6c012005-04-18 22:49:35 -0400569 * FUNCTION: acpi_tb_build_common_facs
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570 *
571 * PARAMETERS: table_info - Info for currently installed FACS
572 *
573 * RETURN: Status
574 *
575 * DESCRIPTION: Convert ACPI 1.0 and ACPI 2.0 FACS to a common internal
576 * table format.
577 *
578 ******************************************************************************/
579
Len Brown4be44fc2005-08-05 00:44:28 -0400580acpi_status acpi_tb_build_common_facs(struct acpi_table_desc *table_info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581{
582
Len Brown4be44fc2005-08-05 00:44:28 -0400583 ACPI_FUNCTION_TRACE("tb_build_common_facs");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584
585 /* Absolute minimum length is 24, but the ACPI spec says 64 */
586
587 if (acpi_gbl_FACS->length < 24) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500588 ACPI_ERROR((AE_INFO, "Invalid FACS table length: 0x%X",
589 acpi_gbl_FACS->length));
Len Brown4be44fc2005-08-05 00:44:28 -0400590 return_ACPI_STATUS(AE_INVALID_TABLE_LENGTH);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591 }
592
593 if (acpi_gbl_FACS->length < 64) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500594 ACPI_WARNING((AE_INFO,
595 "FACS is shorter than the ACPI specification allows: 0x%X, using anyway",
596 acpi_gbl_FACS->length));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 }
598
599 /* Copy fields to the new FACS */
600
601 acpi_gbl_common_fACS.global_lock = &(acpi_gbl_FACS->global_lock);
602
603 if ((acpi_gbl_RSDP->revision < 2) ||
Len Brown4be44fc2005-08-05 00:44:28 -0400604 (acpi_gbl_FACS->length < 32) ||
605 (!(acpi_gbl_FACS->xfirmware_waking_vector))) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400606
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607 /* ACPI 1.0 FACS or short table or optional X_ field is zero */
608
Len Brown4be44fc2005-08-05 00:44:28 -0400609 acpi_gbl_common_fACS.firmware_waking_vector = ACPI_CAST_PTR(u64,
610 &
611 (acpi_gbl_FACS->
612 firmware_waking_vector));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 acpi_gbl_common_fACS.vector_width = 32;
Len Brown4be44fc2005-08-05 00:44:28 -0400614 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 /* ACPI 2.0 FACS with valid X_ field */
616
Len Brown4be44fc2005-08-05 00:44:28 -0400617 acpi_gbl_common_fACS.firmware_waking_vector =
618 &acpi_gbl_FACS->xfirmware_waking_vector;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619 acpi_gbl_common_fACS.vector_width = 64;
620 }
621
Len Brown4be44fc2005-08-05 00:44:28 -0400622 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623}