Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
| 3 | * Module Name: tbconvrt - ACPI Table conversion utilities |
| 4 | * |
| 5 | *****************************************************************************/ |
| 6 | |
| 7 | /* |
Bob Moore | 4a90c7e | 2006-01-13 16:22:00 -0500 | [diff] [blame] | 8 | * Copyright (C) 2000 - 2006, R. Byron Moore |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 <linux/module.h> |
| 45 | |
| 46 | #include <acpi/acpi.h> |
| 47 | #include <acpi/actables.h> |
| 48 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | #define _COMPONENT ACPI_TABLES |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 50 | ACPI_MODULE_NAME("tbconvrt") |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 52 | /* Local prototypes */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 53 | static void |
| 54 | acpi_tb_init_generic_address(struct acpi_generic_address *new_gas_struct, |
| 55 | u8 register_bit_width, |
| 56 | acpi_physical_address address); |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 57 | |
| 58 | static void |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 59 | acpi_tb_convert_fadt1(struct fadt_descriptor_rev2 *local_fadt, |
| 60 | struct fadt_descriptor_rev1 *original_fadt); |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 61 | |
| 62 | static void |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 63 | acpi_tb_convert_fadt2(struct fadt_descriptor_rev2 *local_fadt, |
| 64 | struct fadt_descriptor_rev2 *original_fadt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | |
| 66 | u8 acpi_fadt_is_v1; |
| 67 | EXPORT_SYMBOL(acpi_fadt_is_v1); |
| 68 | |
| 69 | /******************************************************************************* |
| 70 | * |
| 71 | * FUNCTION: acpi_tb_get_table_count |
| 72 | * |
| 73 | * PARAMETERS: RSDP - Pointer to the RSDP |
| 74 | * RSDT - Pointer to the RSDT/XSDT |
| 75 | * |
| 76 | * RETURN: The number of tables pointed to by the RSDT or XSDT. |
| 77 | * |
| 78 | * DESCRIPTION: Calculate the number of tables. Automatically handles either |
| 79 | * an RSDT or XSDT. |
| 80 | * |
| 81 | ******************************************************************************/ |
| 82 | |
| 83 | u32 |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 84 | acpi_tb_get_table_count(struct rsdp_descriptor *RSDP, |
| 85 | struct acpi_table_header *RSDT) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 87 | u32 pointer_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 89 | ACPI_FUNCTION_ENTRY(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 91 | /* RSDT pointers are 32 bits, XSDT pointers are 64 bits */ |
| 92 | |
| 93 | if (acpi_gbl_root_table_type == ACPI_TABLE_TYPE_RSDT) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 94 | pointer_size = sizeof(u32); |
| 95 | } else { |
| 96 | pointer_size = sizeof(u64); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | /* |
| 100 | * Determine the number of tables pointed to by the RSDT/XSDT. |
| 101 | * This is defined by the ACPI Specification to be the number of |
| 102 | * pointers contained within the RSDT/XSDT. The size of the pointers |
| 103 | * is architecture-dependent. |
| 104 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 105 | return ((RSDT->length - |
| 106 | sizeof(struct acpi_table_header)) / pointer_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | } |
| 108 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | /******************************************************************************* |
| 110 | * |
| 111 | * FUNCTION: acpi_tb_convert_to_xsdt |
| 112 | * |
| 113 | * PARAMETERS: table_info - Info about the RSDT |
| 114 | * |
| 115 | * RETURN: Status |
| 116 | * |
| 117 | * DESCRIPTION: Convert an RSDT to an XSDT (internal common format) |
| 118 | * |
| 119 | ******************************************************************************/ |
| 120 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 121 | acpi_status acpi_tb_convert_to_xsdt(struct acpi_table_desc *table_info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 123 | acpi_size table_size; |
| 124 | u32 i; |
| 125 | XSDT_DESCRIPTOR *new_table; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 127 | ACPI_FUNCTION_ENTRY(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | |
| 129 | /* Compute size of the converted XSDT */ |
| 130 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 131 | table_size = ((acpi_size) acpi_gbl_rsdt_table_count * sizeof(u64)) + |
| 132 | sizeof(struct acpi_table_header); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | |
| 134 | /* Allocate an XSDT */ |
| 135 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 136 | new_table = ACPI_MEM_CALLOCATE(table_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | if (!new_table) { |
| 138 | return (AE_NO_MEMORY); |
| 139 | } |
| 140 | |
| 141 | /* Copy the header and set the length */ |
| 142 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 143 | ACPI_MEMCPY(new_table, table_info->pointer, |
| 144 | sizeof(struct acpi_table_header)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | new_table->length = (u32) table_size; |
| 146 | |
| 147 | /* Copy the table pointers */ |
| 148 | |
| 149 | for (i = 0; i < acpi_gbl_rsdt_table_count; i++) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame^] | 150 | |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 151 | /* RSDT pointers are 32 bits, XSDT pointers are 64 bits */ |
| 152 | |
| 153 | if (acpi_gbl_root_table_type == ACPI_TABLE_TYPE_RSDT) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 154 | ACPI_STORE_ADDRESS(new_table->table_offset_entry[i], |
| 155 | (ACPI_CAST_PTR |
| 156 | (struct rsdt_descriptor_rev1, |
| 157 | table_info->pointer))-> |
| 158 | table_offset_entry[i]); |
| 159 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | new_table->table_offset_entry[i] = |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 161 | (ACPI_CAST_PTR(XSDT_DESCRIPTOR, |
| 162 | table_info->pointer))-> |
| 163 | table_offset_entry[i]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | } |
| 165 | } |
| 166 | |
| 167 | /* Delete the original table (either mapped or in a buffer) */ |
| 168 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 169 | acpi_tb_delete_single_table(table_info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | |
| 171 | /* Point the table descriptor to the new table */ |
| 172 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 173 | table_info->pointer = |
| 174 | ACPI_CAST_PTR(struct acpi_table_header, new_table); |
| 175 | table_info->length = table_size; |
| 176 | table_info->allocation = ACPI_MEM_ALLOCATED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | |
| 178 | return (AE_OK); |
| 179 | } |
| 180 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 181 | /******************************************************************************* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | * |
| 183 | * FUNCTION: acpi_tb_init_generic_address |
| 184 | * |
| 185 | * PARAMETERS: new_gas_struct - GAS struct to be initialized |
| 186 | * register_bit_width - Width of this register |
| 187 | * Address - Address of the register |
| 188 | * |
| 189 | * RETURN: None |
| 190 | * |
| 191 | * DESCRIPTION: Initialize a GAS structure. |
| 192 | * |
| 193 | ******************************************************************************/ |
| 194 | |
| 195 | static void |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 196 | acpi_tb_init_generic_address(struct acpi_generic_address *new_gas_struct, |
| 197 | u8 register_bit_width, |
| 198 | acpi_physical_address address) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | { |
| 200 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 201 | ACPI_STORE_ADDRESS(new_gas_struct->address, address); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | |
| 203 | new_gas_struct->address_space_id = ACPI_ADR_SPACE_SYSTEM_IO; |
| 204 | new_gas_struct->register_bit_width = register_bit_width; |
| 205 | new_gas_struct->register_bit_offset = 0; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 206 | new_gas_struct->access_width = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | } |
| 208 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | /******************************************************************************* |
| 210 | * |
| 211 | * FUNCTION: acpi_tb_convert_fadt1 |
| 212 | * |
| 213 | * PARAMETERS: local_fadt - Pointer to new FADT |
| 214 | * original_fadt - Pointer to old FADT |
| 215 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 216 | * RETURN: None, populates local_fadt |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | * |
| 218 | * DESCRIPTION: Convert an ACPI 1.0 FADT to common internal format |
| 219 | * |
| 220 | ******************************************************************************/ |
| 221 | |
| 222 | static void |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 223 | acpi_tb_convert_fadt1(struct fadt_descriptor_rev2 *local_fadt, |
| 224 | struct fadt_descriptor_rev1 *original_fadt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | { |
| 226 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | /* ACPI 1.0 FACS */ |
| 228 | /* The BIOS stored FADT should agree with Revision 1.0 */ |
| 229 | acpi_fadt_is_v1 = 1; |
| 230 | |
| 231 | /* |
| 232 | * Copy the table header and the common part of the tables. |
| 233 | * |
| 234 | * The 2.0 table is an extension of the 1.0 table, so the entire 1.0 |
| 235 | * table can be copied first, then expand some fields to 64 bits. |
| 236 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 237 | ACPI_MEMCPY(local_fadt, original_fadt, |
| 238 | sizeof(struct fadt_descriptor_rev1)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | |
| 240 | /* Convert table pointers to 64-bit fields */ |
| 241 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 242 | ACPI_STORE_ADDRESS(local_fadt->xfirmware_ctrl, |
| 243 | local_fadt->V1_firmware_ctrl); |
| 244 | ACPI_STORE_ADDRESS(local_fadt->Xdsdt, local_fadt->V1_dsdt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | |
| 246 | /* |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 247 | * System Interrupt Model isn't used in ACPI 2.0 |
| 248 | * (local_fadt->Reserved1 = 0;) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | */ |
| 250 | |
| 251 | /* |
| 252 | * This field is set by the OEM to convey the preferred power management |
| 253 | * profile to OSPM. It doesn't have any 1.0 equivalence. Since we don't |
| 254 | * know what kind of 32-bit system this is, we will use "unspecified". |
| 255 | */ |
| 256 | local_fadt->prefer_PM_profile = PM_UNSPECIFIED; |
| 257 | |
| 258 | /* |
| 259 | * Processor Performance State Control. This is the value OSPM writes to |
| 260 | * the SMI_CMD register to assume processor performance state control |
| 261 | * responsibility. There isn't any equivalence in 1.0, but as many 1.x |
| 262 | * ACPI tables contain _PCT and _PSS we also keep this value, unless |
| 263 | * acpi_strict is set. |
| 264 | */ |
| 265 | if (acpi_strict) |
| 266 | local_fadt->pstate_cnt = 0; |
| 267 | |
| 268 | /* |
| 269 | * Support for the _CST object and C States change notification. |
| 270 | * This data item hasn't any 1.0 equivalence so leave it zero. |
| 271 | */ |
| 272 | local_fadt->cst_cnt = 0; |
| 273 | |
| 274 | /* |
| 275 | * FADT Rev 2 was an interim FADT released between ACPI 1.0 and ACPI 2.0. |
| 276 | * It primarily adds the FADT reset mechanism. |
| 277 | */ |
| 278 | if ((original_fadt->revision == 2) && |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 279 | (original_fadt->length == |
| 280 | sizeof(struct fadt_descriptor_rev2_minus))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | /* |
| 282 | * Grab the entire generic address struct, plus the 1-byte reset value |
| 283 | * that immediately follows. |
| 284 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 285 | ACPI_MEMCPY(&local_fadt->reset_register, |
| 286 | &(ACPI_CAST_PTR(struct fadt_descriptor_rev2_minus, |
| 287 | original_fadt))->reset_register, |
| 288 | sizeof(struct acpi_generic_address) + 1); |
| 289 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | /* |
| 291 | * Since there isn't any equivalence in 1.0 and since it is highly |
| 292 | * likely that a 1.0 system has legacy support. |
| 293 | */ |
| 294 | local_fadt->iapc_boot_arch = BAF_LEGACY_DEVICES; |
| 295 | } |
| 296 | |
| 297 | /* |
| 298 | * Convert the V1.0 block addresses to V2.0 GAS structures |
| 299 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 300 | acpi_tb_init_generic_address(&local_fadt->xpm1a_evt_blk, |
| 301 | local_fadt->pm1_evt_len, |
| 302 | (acpi_physical_address) local_fadt-> |
| 303 | V1_pm1a_evt_blk); |
| 304 | acpi_tb_init_generic_address(&local_fadt->xpm1b_evt_blk, |
| 305 | local_fadt->pm1_evt_len, |
| 306 | (acpi_physical_address) local_fadt-> |
| 307 | V1_pm1b_evt_blk); |
| 308 | acpi_tb_init_generic_address(&local_fadt->xpm1a_cnt_blk, |
| 309 | local_fadt->pm1_cnt_len, |
| 310 | (acpi_physical_address) local_fadt-> |
| 311 | V1_pm1a_cnt_blk); |
| 312 | acpi_tb_init_generic_address(&local_fadt->xpm1b_cnt_blk, |
| 313 | local_fadt->pm1_cnt_len, |
| 314 | (acpi_physical_address) local_fadt-> |
| 315 | V1_pm1b_cnt_blk); |
| 316 | acpi_tb_init_generic_address(&local_fadt->xpm2_cnt_blk, |
| 317 | local_fadt->pm2_cnt_len, |
| 318 | (acpi_physical_address) local_fadt-> |
| 319 | V1_pm2_cnt_blk); |
| 320 | acpi_tb_init_generic_address(&local_fadt->xpm_tmr_blk, |
| 321 | local_fadt->pm_tm_len, |
| 322 | (acpi_physical_address) local_fadt-> |
| 323 | V1_pm_tmr_blk); |
| 324 | acpi_tb_init_generic_address(&local_fadt->xgpe0_blk, 0, |
| 325 | (acpi_physical_address) local_fadt-> |
| 326 | V1_gpe0_blk); |
| 327 | acpi_tb_init_generic_address(&local_fadt->xgpe1_blk, 0, |
| 328 | (acpi_physical_address) local_fadt-> |
| 329 | V1_gpe1_blk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | |
| 331 | /* Create separate GAS structs for the PM1 Enable registers */ |
| 332 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 333 | acpi_tb_init_generic_address(&acpi_gbl_xpm1a_enable, |
| 334 | (u8) ACPI_DIV_2(acpi_gbl_FADT-> |
| 335 | pm1_evt_len), |
| 336 | (acpi_physical_address) |
| 337 | (local_fadt->xpm1a_evt_blk.address + |
| 338 | ACPI_DIV_2(acpi_gbl_FADT->pm1_evt_len))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | |
| 340 | /* PM1B is optional; leave null if not present */ |
| 341 | |
| 342 | if (local_fadt->xpm1b_evt_blk.address) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 343 | acpi_tb_init_generic_address(&acpi_gbl_xpm1b_enable, |
| 344 | (u8) ACPI_DIV_2(acpi_gbl_FADT-> |
| 345 | pm1_evt_len), |
| 346 | (acpi_physical_address) |
| 347 | (local_fadt->xpm1b_evt_blk. |
| 348 | address + |
| 349 | ACPI_DIV_2(acpi_gbl_FADT-> |
| 350 | pm1_evt_len))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | } |
| 352 | } |
| 353 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | /******************************************************************************* |
| 355 | * |
| 356 | * FUNCTION: acpi_tb_convert_fadt2 |
| 357 | * |
| 358 | * PARAMETERS: local_fadt - Pointer to new FADT |
| 359 | * original_fadt - Pointer to old FADT |
| 360 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 361 | * RETURN: None, populates local_fadt |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | * |
| 363 | * DESCRIPTION: Convert an ACPI 2.0 FADT to common internal format. |
| 364 | * Handles optional "X" fields. |
| 365 | * |
| 366 | ******************************************************************************/ |
| 367 | |
| 368 | static void |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 369 | acpi_tb_convert_fadt2(struct fadt_descriptor_rev2 *local_fadt, |
| 370 | struct fadt_descriptor_rev2 *original_fadt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | { |
| 372 | |
| 373 | /* We have an ACPI 2.0 FADT but we must copy it to our local buffer */ |
| 374 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 375 | ACPI_MEMCPY(local_fadt, original_fadt, |
| 376 | sizeof(struct fadt_descriptor_rev2)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | |
| 378 | /* |
| 379 | * "X" fields are optional extensions to the original V1.0 fields, so |
| 380 | * we must selectively expand V1.0 fields if the corresponding X field |
| 381 | * is zero. |
| 382 | */ |
| 383 | if (!(local_fadt->xfirmware_ctrl)) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 384 | ACPI_STORE_ADDRESS(local_fadt->xfirmware_ctrl, |
| 385 | local_fadt->V1_firmware_ctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | } |
| 387 | |
| 388 | if (!(local_fadt->Xdsdt)) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 389 | ACPI_STORE_ADDRESS(local_fadt->Xdsdt, local_fadt->V1_dsdt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | } |
| 391 | |
| 392 | if (!(local_fadt->xpm1a_evt_blk.address)) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 393 | acpi_tb_init_generic_address(&local_fadt->xpm1a_evt_blk, |
| 394 | local_fadt->pm1_evt_len, |
| 395 | (acpi_physical_address) |
| 396 | local_fadt->V1_pm1a_evt_blk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | } |
| 398 | |
| 399 | if (!(local_fadt->xpm1b_evt_blk.address)) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 400 | acpi_tb_init_generic_address(&local_fadt->xpm1b_evt_blk, |
| 401 | local_fadt->pm1_evt_len, |
| 402 | (acpi_physical_address) |
| 403 | local_fadt->V1_pm1b_evt_blk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 404 | } |
| 405 | |
| 406 | if (!(local_fadt->xpm1a_cnt_blk.address)) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 407 | acpi_tb_init_generic_address(&local_fadt->xpm1a_cnt_blk, |
| 408 | local_fadt->pm1_cnt_len, |
| 409 | (acpi_physical_address) |
| 410 | local_fadt->V1_pm1a_cnt_blk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | } |
| 412 | |
| 413 | if (!(local_fadt->xpm1b_cnt_blk.address)) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 414 | acpi_tb_init_generic_address(&local_fadt->xpm1b_cnt_blk, |
| 415 | local_fadt->pm1_cnt_len, |
| 416 | (acpi_physical_address) |
| 417 | local_fadt->V1_pm1b_cnt_blk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | } |
| 419 | |
| 420 | if (!(local_fadt->xpm2_cnt_blk.address)) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 421 | acpi_tb_init_generic_address(&local_fadt->xpm2_cnt_blk, |
| 422 | local_fadt->pm2_cnt_len, |
| 423 | (acpi_physical_address) |
| 424 | local_fadt->V1_pm2_cnt_blk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | } |
| 426 | |
| 427 | if (!(local_fadt->xpm_tmr_blk.address)) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 428 | acpi_tb_init_generic_address(&local_fadt->xpm_tmr_blk, |
| 429 | local_fadt->pm_tm_len, |
| 430 | (acpi_physical_address) |
| 431 | local_fadt->V1_pm_tmr_blk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | } |
| 433 | |
| 434 | if (!(local_fadt->xgpe0_blk.address)) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 435 | acpi_tb_init_generic_address(&local_fadt->xgpe0_blk, |
| 436 | 0, |
| 437 | (acpi_physical_address) |
| 438 | local_fadt->V1_gpe0_blk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | } |
| 440 | |
| 441 | if (!(local_fadt->xgpe1_blk.address)) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 442 | acpi_tb_init_generic_address(&local_fadt->xgpe1_blk, |
| 443 | 0, |
| 444 | (acpi_physical_address) |
| 445 | local_fadt->V1_gpe1_blk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | } |
| 447 | |
| 448 | /* Create separate GAS structs for the PM1 Enable registers */ |
| 449 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 450 | acpi_tb_init_generic_address(&acpi_gbl_xpm1a_enable, |
| 451 | (u8) ACPI_DIV_2(acpi_gbl_FADT-> |
| 452 | pm1_evt_len), |
| 453 | (acpi_physical_address) |
| 454 | (local_fadt->xpm1a_evt_blk.address + |
| 455 | ACPI_DIV_2(acpi_gbl_FADT->pm1_evt_len))); |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 456 | |
| 457 | acpi_gbl_xpm1a_enable.address_space_id = |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 458 | local_fadt->xpm1a_evt_blk.address_space_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | |
| 460 | /* PM1B is optional; leave null if not present */ |
| 461 | |
| 462 | if (local_fadt->xpm1b_evt_blk.address) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 463 | acpi_tb_init_generic_address(&acpi_gbl_xpm1b_enable, |
| 464 | (u8) ACPI_DIV_2(acpi_gbl_FADT-> |
| 465 | pm1_evt_len), |
| 466 | (acpi_physical_address) |
| 467 | (local_fadt->xpm1b_evt_blk. |
| 468 | address + |
| 469 | ACPI_DIV_2(acpi_gbl_FADT-> |
| 470 | pm1_evt_len))); |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 471 | |
| 472 | acpi_gbl_xpm1b_enable.address_space_id = |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 473 | local_fadt->xpm1b_evt_blk.address_space_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | } |
| 475 | } |
| 476 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 477 | /******************************************************************************* |
| 478 | * |
| 479 | * FUNCTION: acpi_tb_convert_table_fadt |
| 480 | * |
| 481 | * PARAMETERS: None |
| 482 | * |
| 483 | * RETURN: Status |
| 484 | * |
| 485 | * DESCRIPTION: Converts a BIOS supplied ACPI 1.0 FADT to a local |
| 486 | * ACPI 2.0 FADT. If the BIOS supplied a 2.0 FADT then it is simply |
| 487 | * copied to the local FADT. The ACPI CA software uses this |
| 488 | * local FADT. Thus a significant amount of special #ifdef |
| 489 | * type codeing is saved. |
| 490 | * |
| 491 | ******************************************************************************/ |
| 492 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 493 | acpi_status acpi_tb_convert_table_fadt(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 495 | struct fadt_descriptor_rev2 *local_fadt; |
| 496 | struct acpi_table_desc *table_desc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 497 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 498 | ACPI_FUNCTION_TRACE("tb_convert_table_fadt"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 499 | |
| 500 | /* |
| 501 | * acpi_gbl_FADT is valid. Validate the FADT length. The table must be |
| 502 | * at least as long as the version 1.0 FADT |
| 503 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 504 | if (acpi_gbl_FADT->length < sizeof(struct fadt_descriptor_rev1)) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 505 | ACPI_ERROR((AE_INFO, "FADT is invalid, too short: 0x%X", |
| 506 | acpi_gbl_FADT->length)); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 507 | return_ACPI_STATUS(AE_INVALID_TABLE_LENGTH); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 508 | } |
| 509 | |
| 510 | /* Allocate buffer for the ACPI 2.0(+) FADT */ |
| 511 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 512 | local_fadt = ACPI_MEM_CALLOCATE(sizeof(struct fadt_descriptor_rev2)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | if (!local_fadt) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 514 | return_ACPI_STATUS(AE_NO_MEMORY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 515 | } |
| 516 | |
| 517 | if (acpi_gbl_FADT->revision >= FADT2_REVISION_ID) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 518 | if (acpi_gbl_FADT->length < sizeof(struct fadt_descriptor_rev2)) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame^] | 519 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | /* Length is too short to be a V2.0 table */ |
| 521 | |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 522 | ACPI_WARNING((AE_INFO, |
| 523 | "Inconsistent FADT length (0x%X) and revision (0x%X), using FADT V1.0 portion of table", |
| 524 | acpi_gbl_FADT->length, |
| 525 | acpi_gbl_FADT->revision)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 526 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 527 | acpi_tb_convert_fadt1(local_fadt, |
| 528 | (void *)acpi_gbl_FADT); |
| 529 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 530 | /* Valid V2.0 table */ |
| 531 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 532 | acpi_tb_convert_fadt2(local_fadt, acpi_gbl_FADT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 534 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 535 | /* Valid V1.0 table */ |
| 536 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 537 | acpi_tb_convert_fadt1(local_fadt, (void *)acpi_gbl_FADT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | } |
| 539 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 540 | /* Global FADT pointer will point to the new common V2.0 FADT */ |
| 541 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | acpi_gbl_FADT = local_fadt; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 543 | acpi_gbl_FADT->length = sizeof(FADT_DESCRIPTOR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 544 | |
| 545 | /* Free the original table */ |
| 546 | |
| 547 | table_desc = acpi_gbl_table_lists[ACPI_TABLE_FADT].next; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 548 | acpi_tb_delete_single_table(table_desc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 549 | |
| 550 | /* Install the new table */ |
| 551 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 552 | table_desc->pointer = |
| 553 | ACPI_CAST_PTR(struct acpi_table_header, acpi_gbl_FADT); |
| 554 | table_desc->allocation = ACPI_MEM_ALLOCATED; |
| 555 | table_desc->length = sizeof(struct fadt_descriptor_rev2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 556 | |
| 557 | /* Dump the entire FADT */ |
| 558 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 559 | ACPI_DEBUG_PRINT((ACPI_DB_TABLES, |
| 560 | "Hex dump of common internal FADT, size %d (%X)\n", |
| 561 | acpi_gbl_FADT->length, acpi_gbl_FADT->length)); |
Bob Moore | c51a4de | 2005-11-17 13:07:00 -0500 | [diff] [blame] | 562 | |
| 563 | ACPI_DUMP_BUFFER(ACPI_CAST_PTR(u8, acpi_gbl_FADT), |
| 564 | acpi_gbl_FADT->length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 565 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 566 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | } |
| 568 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 569 | /******************************************************************************* |
| 570 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 571 | * FUNCTION: acpi_tb_build_common_facs |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 572 | * |
| 573 | * PARAMETERS: table_info - Info for currently installed FACS |
| 574 | * |
| 575 | * RETURN: Status |
| 576 | * |
| 577 | * DESCRIPTION: Convert ACPI 1.0 and ACPI 2.0 FACS to a common internal |
| 578 | * table format. |
| 579 | * |
| 580 | ******************************************************************************/ |
| 581 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 582 | acpi_status acpi_tb_build_common_facs(struct acpi_table_desc *table_info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 | { |
| 584 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 585 | ACPI_FUNCTION_TRACE("tb_build_common_facs"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 586 | |
| 587 | /* Absolute minimum length is 24, but the ACPI spec says 64 */ |
| 588 | |
| 589 | if (acpi_gbl_FACS->length < 24) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 590 | ACPI_ERROR((AE_INFO, "Invalid FACS table length: 0x%X", |
| 591 | acpi_gbl_FACS->length)); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 592 | return_ACPI_STATUS(AE_INVALID_TABLE_LENGTH); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 593 | } |
| 594 | |
| 595 | if (acpi_gbl_FACS->length < 64) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 596 | ACPI_WARNING((AE_INFO, |
| 597 | "FACS is shorter than the ACPI specification allows: 0x%X, using anyway", |
| 598 | acpi_gbl_FACS->length)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 599 | } |
| 600 | |
| 601 | /* Copy fields to the new FACS */ |
| 602 | |
| 603 | acpi_gbl_common_fACS.global_lock = &(acpi_gbl_FACS->global_lock); |
| 604 | |
| 605 | if ((acpi_gbl_RSDP->revision < 2) || |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 606 | (acpi_gbl_FACS->length < 32) || |
| 607 | (!(acpi_gbl_FACS->xfirmware_waking_vector))) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame^] | 608 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 609 | /* ACPI 1.0 FACS or short table or optional X_ field is zero */ |
| 610 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 611 | acpi_gbl_common_fACS.firmware_waking_vector = ACPI_CAST_PTR(u64, |
| 612 | & |
| 613 | (acpi_gbl_FACS-> |
| 614 | firmware_waking_vector)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 615 | acpi_gbl_common_fACS.vector_width = 32; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 616 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 617 | /* ACPI 2.0 FACS with valid X_ field */ |
| 618 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 619 | acpi_gbl_common_fACS.firmware_waking_vector = |
| 620 | &acpi_gbl_FACS->xfirmware_waking_vector; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 621 | acpi_gbl_common_fACS.vector_width = 64; |
| 622 | } |
| 623 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 624 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 625 | } |