Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 1 | |
| 2 | /****************************************************************************** |
| 3 | * |
| 4 | * Module Name: hwxface - Public ACPICA hardware interfaces |
| 5 | * |
| 6 | *****************************************************************************/ |
| 7 | |
| 8 | /* |
| 9 | * Copyright (C) 2000 - 2008, Intel Corp. |
| 10 | * All rights reserved. |
| 11 | * |
| 12 | * Redistribution and use in source and binary forms, with or without |
| 13 | * modification, are permitted provided that the following conditions |
| 14 | * are met: |
| 15 | * 1. Redistributions of source code must retain the above copyright |
| 16 | * notice, this list of conditions, and the following disclaimer, |
| 17 | * without modification. |
| 18 | * 2. Redistributions in binary form must reproduce at minimum a disclaimer |
| 19 | * substantially similar to the "NO WARRANTY" disclaimer below |
| 20 | * ("Disclaimer") and any redistribution must be conditioned upon |
| 21 | * including a substantially similar Disclaimer requirement for further |
| 22 | * binary redistribution. |
| 23 | * 3. Neither the names of the above-listed copyright holders nor the names |
| 24 | * of any contributors may be used to endorse or promote products derived |
| 25 | * from this software without specific prior written permission. |
| 26 | * |
| 27 | * Alternatively, this software may be distributed under the terms of the |
| 28 | * GNU General Public License ("GPL") version 2 as published by the Free |
| 29 | * Software Foundation. |
| 30 | * |
| 31 | * NO WARRANTY |
| 32 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 33 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 34 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR |
| 35 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 36 | * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 37 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 38 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 39 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
| 40 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING |
| 41 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 42 | * POSSIBILITY OF SUCH DAMAGES. |
| 43 | */ |
| 44 | |
| 45 | #include <acpi/acpi.h> |
Len Brown | e2f7a77 | 2009-01-09 00:30:03 -0500 | [diff] [blame^] | 46 | #include "accommon.h" |
| 47 | #include "acnamesp.h" |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 48 | |
| 49 | #define _COMPONENT ACPI_HARDWARE |
| 50 | ACPI_MODULE_NAME("hwxface") |
| 51 | |
| 52 | /****************************************************************************** |
| 53 | * |
Bob Moore | d3fd902 | 2008-12-30 11:11:57 +0800 | [diff] [blame] | 54 | * FUNCTION: acpi_reset |
| 55 | * |
| 56 | * PARAMETERS: None |
| 57 | * |
| 58 | * RETURN: Status |
| 59 | * |
| 60 | * DESCRIPTION: Set reset register in memory or IO space. Note: Does not |
| 61 | * support reset register in PCI config space, this must be |
| 62 | * handled separately. |
| 63 | * |
| 64 | ******************************************************************************/ |
| 65 | acpi_status acpi_reset(void) |
| 66 | { |
| 67 | struct acpi_generic_address *reset_reg; |
| 68 | acpi_status status; |
| 69 | |
| 70 | ACPI_FUNCTION_TRACE(acpi_reset); |
| 71 | |
| 72 | reset_reg = &acpi_gbl_FADT.reset_register; |
| 73 | |
| 74 | /* Check if the reset register is supported */ |
| 75 | |
| 76 | if (!(acpi_gbl_FADT.flags & ACPI_FADT_RESET_REGISTER) || |
| 77 | !reset_reg->address) { |
| 78 | return_ACPI_STATUS(AE_NOT_EXIST); |
| 79 | } |
| 80 | |
| 81 | /* Write the reset value to the reset register */ |
| 82 | |
| 83 | status = acpi_write(acpi_gbl_FADT.reset_value, reset_reg); |
| 84 | return_ACPI_STATUS(status); |
| 85 | } |
| 86 | |
| 87 | ACPI_EXPORT_SYMBOL(acpi_reset) |
| 88 | |
| 89 | /****************************************************************************** |
| 90 | * |
Bob Moore | 7db5d82 | 2008-12-30 11:04:48 +0800 | [diff] [blame] | 91 | * FUNCTION: acpi_read |
| 92 | * |
| 93 | * PARAMETERS: Value - Where the value is returned |
| 94 | * Reg - GAS register structure |
| 95 | * |
| 96 | * RETURN: Status |
| 97 | * |
| 98 | * DESCRIPTION: Read from either memory or IO space. |
| 99 | * |
| 100 | ******************************************************************************/ |
| 101 | acpi_status acpi_read(u32 *value, struct acpi_generic_address *reg) |
| 102 | { |
| 103 | u32 width; |
| 104 | u64 address; |
| 105 | acpi_status status; |
| 106 | |
| 107 | ACPI_FUNCTION_NAME(acpi_read); |
| 108 | |
| 109 | /* |
| 110 | * Must have a valid pointer to a GAS structure, and |
| 111 | * a non-zero address within. However, don't return an error |
| 112 | * because the PM1A/B code must not fail if B isn't present. |
| 113 | */ |
| 114 | if (!reg) { |
| 115 | return (AE_OK); |
| 116 | } |
| 117 | |
| 118 | /* Get a local copy of the address. Handles possible alignment issues */ |
| 119 | |
| 120 | ACPI_MOVE_64_TO_64(&address, ®->address); |
| 121 | if (!address) { |
| 122 | return (AE_OK); |
| 123 | } |
| 124 | |
| 125 | /* Supported widths are 8/16/32 */ |
| 126 | |
| 127 | width = reg->bit_width; |
| 128 | if ((width != 8) && (width != 16) && (width != 32)) { |
| 129 | return (AE_SUPPORT); |
| 130 | } |
| 131 | |
| 132 | /* Initialize entire 32-bit return value to zero */ |
| 133 | |
| 134 | *value = 0; |
| 135 | |
| 136 | /* |
| 137 | * Two address spaces supported: Memory or IO. |
| 138 | * PCI_Config is not supported here because the GAS struct is insufficient |
| 139 | */ |
| 140 | switch (reg->space_id) { |
| 141 | case ACPI_ADR_SPACE_SYSTEM_MEMORY: |
| 142 | |
| 143 | status = acpi_os_read_memory((acpi_physical_address) address, |
| 144 | value, width); |
| 145 | break; |
| 146 | |
| 147 | case ACPI_ADR_SPACE_SYSTEM_IO: |
| 148 | |
| 149 | status = |
| 150 | acpi_os_read_port((acpi_io_address) address, value, width); |
| 151 | break; |
| 152 | |
| 153 | default: |
| 154 | ACPI_ERROR((AE_INFO, |
| 155 | "Unsupported address space: %X", reg->space_id)); |
| 156 | return (AE_BAD_PARAMETER); |
| 157 | } |
| 158 | |
| 159 | ACPI_DEBUG_PRINT((ACPI_DB_IO, |
| 160 | "Read: %8.8X width %2d from %8.8X%8.8X (%s)\n", |
| 161 | *value, width, ACPI_FORMAT_UINT64(address), |
| 162 | acpi_ut_get_region_name(reg->space_id))); |
| 163 | |
| 164 | return (status); |
| 165 | } |
| 166 | |
| 167 | ACPI_EXPORT_SYMBOL(acpi_read) |
| 168 | |
| 169 | /****************************************************************************** |
| 170 | * |
| 171 | * FUNCTION: acpi_write |
| 172 | * |
| 173 | * PARAMETERS: Value - To be written |
| 174 | * Reg - GAS register structure |
| 175 | * |
| 176 | * RETURN: Status |
| 177 | * |
| 178 | * DESCRIPTION: Write to either memory or IO space. |
| 179 | * |
| 180 | ******************************************************************************/ |
| 181 | acpi_status acpi_write(u32 value, struct acpi_generic_address *reg) |
| 182 | { |
| 183 | u32 width; |
| 184 | u64 address; |
| 185 | acpi_status status; |
| 186 | |
| 187 | ACPI_FUNCTION_NAME(acpi_write); |
| 188 | |
| 189 | /* |
| 190 | * Must have a valid pointer to a GAS structure, and |
| 191 | * a non-zero address within. However, don't return an error |
| 192 | * because the PM1A/B code must not fail if B isn't present. |
| 193 | */ |
| 194 | if (!reg) { |
| 195 | return (AE_OK); |
| 196 | } |
| 197 | |
| 198 | /* Get a local copy of the address. Handles possible alignment issues */ |
| 199 | |
| 200 | ACPI_MOVE_64_TO_64(&address, ®->address); |
| 201 | if (!address) { |
| 202 | return (AE_OK); |
| 203 | } |
| 204 | |
| 205 | /* Supported widths are 8/16/32 */ |
| 206 | |
| 207 | width = reg->bit_width; |
| 208 | if ((width != 8) && (width != 16) && (width != 32)) { |
| 209 | return (AE_SUPPORT); |
| 210 | } |
| 211 | |
| 212 | /* |
| 213 | * Two address spaces supported: Memory or IO. |
| 214 | * PCI_Config is not supported here because the GAS struct is insufficient |
| 215 | */ |
| 216 | switch (reg->space_id) { |
| 217 | case ACPI_ADR_SPACE_SYSTEM_MEMORY: |
| 218 | |
| 219 | status = acpi_os_write_memory((acpi_physical_address) address, |
| 220 | value, width); |
| 221 | break; |
| 222 | |
| 223 | case ACPI_ADR_SPACE_SYSTEM_IO: |
| 224 | |
| 225 | status = acpi_os_write_port((acpi_io_address) address, value, |
| 226 | width); |
| 227 | break; |
| 228 | |
| 229 | default: |
| 230 | ACPI_ERROR((AE_INFO, |
| 231 | "Unsupported address space: %X", reg->space_id)); |
| 232 | return (AE_BAD_PARAMETER); |
| 233 | } |
| 234 | |
| 235 | ACPI_DEBUG_PRINT((ACPI_DB_IO, |
| 236 | "Wrote: %8.8X width %2d to %8.8X%8.8X (%s)\n", |
| 237 | value, width, ACPI_FORMAT_UINT64(address), |
| 238 | acpi_ut_get_region_name(reg->space_id))); |
| 239 | |
| 240 | return (status); |
| 241 | } |
| 242 | |
| 243 | ACPI_EXPORT_SYMBOL(acpi_write) |
| 244 | |
| 245 | /******************************************************************************* |
| 246 | * |
| 247 | * FUNCTION: acpi_get_register_unlocked |
| 248 | * |
| 249 | * PARAMETERS: register_id - ID of ACPI bit_register to access |
| 250 | * return_value - Value that was read from the register |
| 251 | * |
| 252 | * RETURN: Status and the value read from specified Register. Value |
| 253 | * returned is normalized to bit0 (is shifted all the way right) |
| 254 | * |
| 255 | * DESCRIPTION: ACPI bit_register read function. Does not acquire the HW lock. |
| 256 | * |
| 257 | ******************************************************************************/ |
| 258 | acpi_status acpi_get_register_unlocked(u32 register_id, u32 *return_value) |
| 259 | { |
| 260 | u32 register_value = 0; |
| 261 | struct acpi_bit_register_info *bit_reg_info; |
| 262 | acpi_status status; |
| 263 | |
| 264 | ACPI_FUNCTION_TRACE(acpi_get_register_unlocked); |
| 265 | |
| 266 | /* Get the info structure corresponding to the requested ACPI Register */ |
| 267 | |
| 268 | bit_reg_info = acpi_hw_get_bit_register_info(register_id); |
| 269 | if (!bit_reg_info) { |
| 270 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
| 271 | } |
| 272 | |
| 273 | /* Read from the register */ |
| 274 | |
| 275 | status = acpi_hw_register_read(bit_reg_info->parent_register, |
| 276 | ®ister_value); |
| 277 | |
| 278 | if (ACPI_SUCCESS(status)) { |
| 279 | |
| 280 | /* Normalize the value that was read */ |
| 281 | |
| 282 | register_value = |
| 283 | ((register_value & bit_reg_info->access_bit_mask) |
| 284 | >> bit_reg_info->bit_position); |
| 285 | |
| 286 | *return_value = register_value; |
| 287 | |
| 288 | ACPI_DEBUG_PRINT((ACPI_DB_IO, "Read value %8.8X register %X\n", |
| 289 | register_value, |
| 290 | bit_reg_info->parent_register)); |
| 291 | } |
| 292 | |
| 293 | return_ACPI_STATUS(status); |
| 294 | } |
| 295 | |
| 296 | ACPI_EXPORT_SYMBOL(acpi_get_register_unlocked) |
| 297 | |
| 298 | /******************************************************************************* |
| 299 | * |
| 300 | * FUNCTION: acpi_get_register |
| 301 | * |
| 302 | * PARAMETERS: register_id - ID of ACPI bit_register to access |
| 303 | * return_value - Value that was read from the register |
| 304 | * |
| 305 | * RETURN: Status and the value read from specified Register. Value |
| 306 | * returned is normalized to bit0 (is shifted all the way right) |
| 307 | * |
| 308 | * DESCRIPTION: ACPI bit_register read function. |
| 309 | * |
| 310 | ******************************************************************************/ |
| 311 | acpi_status acpi_get_register(u32 register_id, u32 *return_value) |
| 312 | { |
| 313 | acpi_status status; |
| 314 | acpi_cpu_flags flags; |
| 315 | |
| 316 | flags = acpi_os_acquire_lock(acpi_gbl_hardware_lock); |
| 317 | status = acpi_get_register_unlocked(register_id, return_value); |
| 318 | acpi_os_release_lock(acpi_gbl_hardware_lock, flags); |
| 319 | |
| 320 | return (status); |
| 321 | } |
| 322 | |
| 323 | ACPI_EXPORT_SYMBOL(acpi_get_register) |
| 324 | |
| 325 | /******************************************************************************* |
| 326 | * |
| 327 | * FUNCTION: acpi_set_register |
| 328 | * |
| 329 | * PARAMETERS: register_id - ID of ACPI bit_register to access |
| 330 | * Value - (only used on write) value to write to the |
| 331 | * Register, NOT pre-normalized to the bit pos |
| 332 | * |
| 333 | * RETURN: Status |
| 334 | * |
| 335 | * DESCRIPTION: ACPI Bit Register write function. |
| 336 | * |
| 337 | ******************************************************************************/ |
| 338 | acpi_status acpi_set_register(u32 register_id, u32 value) |
| 339 | { |
| 340 | u32 register_value = 0; |
| 341 | struct acpi_bit_register_info *bit_reg_info; |
| 342 | acpi_status status; |
| 343 | acpi_cpu_flags lock_flags; |
| 344 | |
| 345 | ACPI_FUNCTION_TRACE_U32(acpi_set_register, register_id); |
| 346 | |
| 347 | /* Get the info structure corresponding to the requested ACPI Register */ |
| 348 | |
| 349 | bit_reg_info = acpi_hw_get_bit_register_info(register_id); |
| 350 | if (!bit_reg_info) { |
| 351 | ACPI_ERROR((AE_INFO, "Bad ACPI HW RegisterId: %X", |
| 352 | register_id)); |
| 353 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
| 354 | } |
| 355 | |
| 356 | lock_flags = acpi_os_acquire_lock(acpi_gbl_hardware_lock); |
| 357 | |
| 358 | /* Always do a register read first so we can insert the new bits */ |
| 359 | |
| 360 | status = acpi_hw_register_read(bit_reg_info->parent_register, |
| 361 | ®ister_value); |
| 362 | if (ACPI_FAILURE(status)) { |
| 363 | goto unlock_and_exit; |
| 364 | } |
| 365 | |
| 366 | /* |
| 367 | * Decode the Register ID |
| 368 | * Register ID = [Register block ID] | [bit ID] |
| 369 | * |
| 370 | * Check bit ID to fine locate Register offset. |
| 371 | * Check Mask to determine Register offset, and then read-write. |
| 372 | */ |
| 373 | switch (bit_reg_info->parent_register) { |
| 374 | case ACPI_REGISTER_PM1_STATUS: |
| 375 | |
| 376 | /* |
| 377 | * Status Registers are different from the rest. Clear by |
| 378 | * writing 1, and writing 0 has no effect. So, the only relevant |
| 379 | * information is the single bit we're interested in, all others should |
| 380 | * be written as 0 so they will be left unchanged. |
| 381 | */ |
| 382 | value = ACPI_REGISTER_PREPARE_BITS(value, |
| 383 | bit_reg_info->bit_position, |
| 384 | bit_reg_info-> |
| 385 | access_bit_mask); |
| 386 | if (value) { |
| 387 | status = |
| 388 | acpi_hw_register_write(ACPI_REGISTER_PM1_STATUS, |
| 389 | (u16) value); |
| 390 | register_value = 0; |
| 391 | } |
| 392 | break; |
| 393 | |
| 394 | case ACPI_REGISTER_PM1_ENABLE: |
| 395 | |
| 396 | ACPI_REGISTER_INSERT_VALUE(register_value, |
| 397 | bit_reg_info->bit_position, |
| 398 | bit_reg_info->access_bit_mask, |
| 399 | value); |
| 400 | |
| 401 | status = acpi_hw_register_write(ACPI_REGISTER_PM1_ENABLE, |
| 402 | (u16) register_value); |
| 403 | break; |
| 404 | |
| 405 | case ACPI_REGISTER_PM1_CONTROL: |
| 406 | |
| 407 | /* |
| 408 | * Write the PM1 Control register. |
| 409 | * Note that at this level, the fact that there are actually TWO |
| 410 | * registers (A and B - and B may not exist) is abstracted. |
| 411 | */ |
| 412 | ACPI_DEBUG_PRINT((ACPI_DB_IO, "PM1 control: Read %X\n", |
| 413 | register_value)); |
| 414 | |
| 415 | ACPI_REGISTER_INSERT_VALUE(register_value, |
| 416 | bit_reg_info->bit_position, |
| 417 | bit_reg_info->access_bit_mask, |
| 418 | value); |
| 419 | |
| 420 | status = acpi_hw_register_write(ACPI_REGISTER_PM1_CONTROL, |
| 421 | (u16) register_value); |
| 422 | break; |
| 423 | |
| 424 | case ACPI_REGISTER_PM2_CONTROL: |
| 425 | |
| 426 | status = acpi_hw_register_read(ACPI_REGISTER_PM2_CONTROL, |
| 427 | ®ister_value); |
| 428 | if (ACPI_FAILURE(status)) { |
| 429 | goto unlock_and_exit; |
| 430 | } |
| 431 | |
| 432 | ACPI_DEBUG_PRINT((ACPI_DB_IO, |
| 433 | "PM2 control: Read %X from %8.8X%8.8X\n", |
| 434 | register_value, |
| 435 | ACPI_FORMAT_UINT64(acpi_gbl_FADT. |
| 436 | xpm2_control_block. |
| 437 | address))); |
| 438 | |
| 439 | ACPI_REGISTER_INSERT_VALUE(register_value, |
| 440 | bit_reg_info->bit_position, |
| 441 | bit_reg_info->access_bit_mask, |
| 442 | value); |
| 443 | |
| 444 | ACPI_DEBUG_PRINT((ACPI_DB_IO, |
| 445 | "About to write %4.4X to %8.8X%8.8X\n", |
| 446 | register_value, |
| 447 | ACPI_FORMAT_UINT64(acpi_gbl_FADT. |
| 448 | xpm2_control_block. |
| 449 | address))); |
| 450 | |
| 451 | status = acpi_hw_register_write(ACPI_REGISTER_PM2_CONTROL, |
| 452 | (u8) (register_value)); |
| 453 | break; |
| 454 | |
| 455 | default: |
| 456 | break; |
| 457 | } |
| 458 | |
| 459 | unlock_and_exit: |
| 460 | |
| 461 | acpi_os_release_lock(acpi_gbl_hardware_lock, lock_flags); |
| 462 | |
| 463 | /* Normalize the value that was read */ |
| 464 | |
| 465 | ACPI_DEBUG_EXEC(register_value = |
| 466 | ((register_value & bit_reg_info->access_bit_mask) >> |
| 467 | bit_reg_info->bit_position)); |
| 468 | |
| 469 | ACPI_DEBUG_PRINT((ACPI_DB_IO, |
| 470 | "Set bits: %8.8X actual %8.8X register %X\n", value, |
| 471 | register_value, bit_reg_info->parent_register)); |
| 472 | return_ACPI_STATUS(status); |
| 473 | } |
| 474 | |
| 475 | ACPI_EXPORT_SYMBOL(acpi_set_register) |
| 476 | |
| 477 | /******************************************************************************* |
| 478 | * |
| 479 | * FUNCTION: acpi_get_sleep_type_data |
| 480 | * |
| 481 | * PARAMETERS: sleep_state - Numeric sleep state |
| 482 | * *sleep_type_a - Where SLP_TYPa is returned |
| 483 | * *sleep_type_b - Where SLP_TYPb is returned |
| 484 | * |
| 485 | * RETURN: Status - ACPI status |
| 486 | * |
| 487 | * DESCRIPTION: Obtain the SLP_TYPa and SLP_TYPb values for the requested sleep |
| 488 | * state. |
| 489 | * |
| 490 | ******************************************************************************/ |
| 491 | acpi_status |
| 492 | acpi_get_sleep_type_data(u8 sleep_state, u8 *sleep_type_a, u8 *sleep_type_b) |
| 493 | { |
| 494 | acpi_status status = AE_OK; |
| 495 | struct acpi_evaluate_info *info; |
| 496 | |
| 497 | ACPI_FUNCTION_TRACE(acpi_get_sleep_type_data); |
| 498 | |
| 499 | /* Validate parameters */ |
| 500 | |
| 501 | if ((sleep_state > ACPI_S_STATES_MAX) || !sleep_type_a || !sleep_type_b) { |
| 502 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
| 503 | } |
| 504 | |
| 505 | /* Allocate the evaluation information block */ |
| 506 | |
| 507 | info = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_evaluate_info)); |
| 508 | if (!info) { |
| 509 | return_ACPI_STATUS(AE_NO_MEMORY); |
| 510 | } |
| 511 | |
| 512 | info->pathname = |
| 513 | ACPI_CAST_PTR(char, acpi_gbl_sleep_state_names[sleep_state]); |
| 514 | |
| 515 | /* Evaluate the namespace object containing the values for this state */ |
| 516 | |
| 517 | status = acpi_ns_evaluate(info); |
| 518 | if (ACPI_FAILURE(status)) { |
| 519 | ACPI_DEBUG_PRINT((ACPI_DB_EXEC, |
| 520 | "%s while evaluating SleepState [%s]\n", |
| 521 | acpi_format_exception(status), |
| 522 | info->pathname)); |
| 523 | |
| 524 | goto cleanup; |
| 525 | } |
| 526 | |
| 527 | /* Must have a return object */ |
| 528 | |
| 529 | if (!info->return_object) { |
| 530 | ACPI_ERROR((AE_INFO, "No Sleep State object returned from [%s]", |
| 531 | info->pathname)); |
| 532 | status = AE_NOT_EXIST; |
| 533 | } |
| 534 | |
| 535 | /* It must be of type Package */ |
| 536 | |
| 537 | else if (ACPI_GET_OBJECT_TYPE(info->return_object) != ACPI_TYPE_PACKAGE) { |
| 538 | ACPI_ERROR((AE_INFO, |
| 539 | "Sleep State return object is not a Package")); |
| 540 | status = AE_AML_OPERAND_TYPE; |
| 541 | } |
| 542 | |
| 543 | /* |
| 544 | * The package must have at least two elements. NOTE (March 2005): This |
| 545 | * goes against the current ACPI spec which defines this object as a |
| 546 | * package with one encoded DWORD element. However, existing practice |
| 547 | * by BIOS vendors seems to be to have 2 or more elements, at least |
| 548 | * one per sleep type (A/B). |
| 549 | */ |
| 550 | else if (info->return_object->package.count < 2) { |
| 551 | ACPI_ERROR((AE_INFO, |
| 552 | "Sleep State return package does not have at least two elements")); |
| 553 | status = AE_AML_NO_OPERAND; |
| 554 | } |
| 555 | |
| 556 | /* The first two elements must both be of type Integer */ |
| 557 | |
| 558 | else if ((ACPI_GET_OBJECT_TYPE(info->return_object->package.elements[0]) |
| 559 | != ACPI_TYPE_INTEGER) || |
| 560 | (ACPI_GET_OBJECT_TYPE(info->return_object->package.elements[1]) |
| 561 | != ACPI_TYPE_INTEGER)) { |
| 562 | ACPI_ERROR((AE_INFO, |
| 563 | "Sleep State return package elements are not both Integers (%s, %s)", |
| 564 | acpi_ut_get_object_type_name(info->return_object-> |
| 565 | package.elements[0]), |
| 566 | acpi_ut_get_object_type_name(info->return_object-> |
| 567 | package.elements[1]))); |
| 568 | status = AE_AML_OPERAND_TYPE; |
| 569 | } else { |
| 570 | /* Valid _Sx_ package size, type, and value */ |
| 571 | |
| 572 | *sleep_type_a = (u8) |
| 573 | (info->return_object->package.elements[0])->integer.value; |
| 574 | *sleep_type_b = (u8) |
| 575 | (info->return_object->package.elements[1])->integer.value; |
| 576 | } |
| 577 | |
| 578 | if (ACPI_FAILURE(status)) { |
| 579 | ACPI_EXCEPTION((AE_INFO, status, |
| 580 | "While evaluating SleepState [%s], bad Sleep object %p type %s", |
| 581 | info->pathname, info->return_object, |
| 582 | acpi_ut_get_object_type_name(info-> |
| 583 | return_object))); |
| 584 | } |
| 585 | |
| 586 | acpi_ut_remove_reference(info->return_object); |
| 587 | |
| 588 | cleanup: |
| 589 | ACPI_FREE(info); |
| 590 | return_ACPI_STATUS(status); |
| 591 | } |
| 592 | |
| 593 | ACPI_EXPORT_SYMBOL(acpi_get_sleep_type_data) |