From: Len Brown Date: Fri, 9 Jan 2009 08:39:43 +0000 (-0500) Subject: Merge branch 'linus' into release X-Git-Tag: v2.6.29-rc1~34^2~2 X-Git-Url: https://git.kernel.dk/?a=commitdiff_plain;h=b2576e1d4408e134e2188c967b1f28af39cd79d4;p=linux-2.6-block.git Merge branch 'linus' into release --- b2576e1d4408e134e2188c967b1f28af39cd79d4 diff --cc arch/x86/kernel/acpi/boot.c index 39ae3d0e3a4a,29dc0c89d4af..d37593c2f438 --- a/arch/x86/kernel/acpi/boot.c +++ b/arch/x86/kernel/acpi/boot.c @@@ -1359,18 -1374,18 +1374,29 @@@ static void __init acpi_process_madt(vo "Invalid BIOS MADT, disabling ACPI\n"); disable_acpi(); } + } else { + /* + * ACPI found no MADT, and so ACPI wants UP PIC mode. + * In the event an MPS table was found, forget it. + * Boot with "acpi=off" to use MPS on such a system. + */ + if (smp_found_config) { + printk(KERN_WARNING PREFIX + "No APIC-table, disabling MPS\n"); + smp_found_config = 0; + } } + + /* + * ACPI supports both logical (e.g. Hyper-Threading) and physical + * processors, where MPS only supports physical. + */ + if (acpi_lapic && acpi_ioapic) + printk(KERN_INFO "Using ACPI (MADT) for SMP configuration " + "information\n"); + else if (acpi_lapic) + printk(KERN_INFO "Using ACPI for processor (LAPIC) " + "configuration information\n"); #endif return; } diff --cc drivers/acpi/acpica/acmacros.h index c57286a3aceb,000000000000..9c127e8e2d6d mode 100644,000000..100644 --- a/drivers/acpi/acpica/acmacros.h +++ b/drivers/acpi/acpica/acmacros.h @@@ -1,577 -1,0 +1,577 @@@ +/****************************************************************************** + * + * Name: acmacros.h - C macros for the entire subsystem. + * + *****************************************************************************/ + +/* + * Copyright (C) 2000 - 2008, Intel Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * 3. Neither the names of the above-listed copyright holders nor the names + * of any contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + */ + +#ifndef __ACMACROS_H__ +#define __ACMACROS_H__ + +/* + * Extract data using a pointer. Any more than a byte and we + * get into potential aligment issues -- see the STORE macros below. + * Use with care. + */ +#define ACPI_GET8(ptr) *ACPI_CAST_PTR (u8, ptr) +#define ACPI_GET16(ptr) *ACPI_CAST_PTR (u16, ptr) +#define ACPI_GET32(ptr) *ACPI_CAST_PTR (u32, ptr) +#define ACPI_GET64(ptr) *ACPI_CAST_PTR (u64, ptr) +#define ACPI_SET8(ptr) *ACPI_CAST_PTR (u8, ptr) +#define ACPI_SET16(ptr) *ACPI_CAST_PTR (u16, ptr) +#define ACPI_SET32(ptr) *ACPI_CAST_PTR (u32, ptr) +#define ACPI_SET64(ptr) *ACPI_CAST_PTR (u64, ptr) + +/* + * printf() format helpers + */ + +/* Split 64-bit integer into two 32-bit values. Use with %8.8_x%8.8_x */ + +#define ACPI_FORMAT_UINT64(i) ACPI_HIDWORD(i), ACPI_LODWORD(i) + +#if ACPI_MACHINE_WIDTH == 64 +#define ACPI_FORMAT_NATIVE_UINT(i) ACPI_FORMAT_UINT64(i) +#else +#define ACPI_FORMAT_NATIVE_UINT(i) 0, (i) +#endif + +/* + * Macros for moving data around to/from buffers that are possibly unaligned. + * If the hardware supports the transfer of unaligned data, just do the store. + * Otherwise, we have to move one byte at a time. + */ +#ifdef ACPI_BIG_ENDIAN +/* + * Macros for big-endian machines + */ + +/* These macros reverse the bytes during the move, converting little-endian to big endian */ + + /* Big Endian <== Little Endian */ + /* Hi...Lo Lo...Hi */ +/* 16-bit source, 16/32/64 destination */ + +#define ACPI_MOVE_16_TO_16(d, s) {(( u8 *)(void *)(d))[0] = ((u8 *)(void *)(s))[1];\ + (( u8 *)(void *)(d))[1] = ((u8 *)(void *)(s))[0];} + +#define ACPI_MOVE_16_TO_32(d, s) {(*(u32 *)(void *)(d))=0;\ + ((u8 *)(void *)(d))[2] = ((u8 *)(void *)(s))[1];\ + ((u8 *)(void *)(d))[3] = ((u8 *)(void *)(s))[0];} + +#define ACPI_MOVE_16_TO_64(d, s) {(*(u64 *)(void *)(d))=0;\ + ((u8 *)(void *)(d))[6] = ((u8 *)(void *)(s))[1];\ + ((u8 *)(void *)(d))[7] = ((u8 *)(void *)(s))[0];} + +/* 32-bit source, 16/32/64 destination */ + +#define ACPI_MOVE_32_TO_16(d, s) ACPI_MOVE_16_TO_16(d, s) /* Truncate to 16 */ + +#define ACPI_MOVE_32_TO_32(d, s) {(( u8 *)(void *)(d))[0] = ((u8 *)(void *)(s))[3];\ + (( u8 *)(void *)(d))[1] = ((u8 *)(void *)(s))[2];\ + (( u8 *)(void *)(d))[2] = ((u8 *)(void *)(s))[1];\ + (( u8 *)(void *)(d))[3] = ((u8 *)(void *)(s))[0];} + +#define ACPI_MOVE_32_TO_64(d, s) {(*(u64 *)(void *)(d))=0;\ + ((u8 *)(void *)(d))[4] = ((u8 *)(void *)(s))[3];\ + ((u8 *)(void *)(d))[5] = ((u8 *)(void *)(s))[2];\ + ((u8 *)(void *)(d))[6] = ((u8 *)(void *)(s))[1];\ + ((u8 *)(void *)(d))[7] = ((u8 *)(void *)(s))[0];} + +/* 64-bit source, 16/32/64 destination */ + +#define ACPI_MOVE_64_TO_16(d, s) ACPI_MOVE_16_TO_16(d, s) /* Truncate to 16 */ + +#define ACPI_MOVE_64_TO_32(d, s) ACPI_MOVE_32_TO_32(d, s) /* Truncate to 32 */ + +#define ACPI_MOVE_64_TO_64(d, s) {(( u8 *)(void *)(d))[0] = ((u8 *)(void *)(s))[7];\ + (( u8 *)(void *)(d))[1] = ((u8 *)(void *)(s))[6];\ + (( u8 *)(void *)(d))[2] = ((u8 *)(void *)(s))[5];\ + (( u8 *)(void *)(d))[3] = ((u8 *)(void *)(s))[4];\ + (( u8 *)(void *)(d))[4] = ((u8 *)(void *)(s))[3];\ + (( u8 *)(void *)(d))[5] = ((u8 *)(void *)(s))[2];\ + (( u8 *)(void *)(d))[6] = ((u8 *)(void *)(s))[1];\ + (( u8 *)(void *)(d))[7] = ((u8 *)(void *)(s))[0];} +#else +/* + * Macros for little-endian machines + */ + +#ifndef ACPI_MISALIGNMENT_NOT_SUPPORTED + +/* The hardware supports unaligned transfers, just do the little-endian move */ + +/* 16-bit source, 16/32/64 destination */ + +#define ACPI_MOVE_16_TO_16(d, s) *(u16 *)(void *)(d) = *(u16 *)(void *)(s) +#define ACPI_MOVE_16_TO_32(d, s) *(u32 *)(void *)(d) = *(u16 *)(void *)(s) +#define ACPI_MOVE_16_TO_64(d, s) *(u64 *)(void *)(d) = *(u16 *)(void *)(s) + +/* 32-bit source, 16/32/64 destination */ + +#define ACPI_MOVE_32_TO_16(d, s) ACPI_MOVE_16_TO_16(d, s) /* Truncate to 16 */ +#define ACPI_MOVE_32_TO_32(d, s) *(u32 *)(void *)(d) = *(u32 *)(void *)(s) +#define ACPI_MOVE_32_TO_64(d, s) *(u64 *)(void *)(d) = *(u32 *)(void *)(s) + +/* 64-bit source, 16/32/64 destination */ + +#define ACPI_MOVE_64_TO_16(d, s) ACPI_MOVE_16_TO_16(d, s) /* Truncate to 16 */ +#define ACPI_MOVE_64_TO_32(d, s) ACPI_MOVE_32_TO_32(d, s) /* Truncate to 32 */ +#define ACPI_MOVE_64_TO_64(d, s) *(u64 *)(void *)(d) = *(u64 *)(void *)(s) + +#else +/* + * The hardware does not support unaligned transfers. We must move the + * data one byte at a time. These macros work whether the source or + * the destination (or both) is/are unaligned. (Little-endian move) + */ + +/* 16-bit source, 16/32/64 destination */ + +#define ACPI_MOVE_16_TO_16(d, s) {(( u8 *)(void *)(d))[0] = ((u8 *)(void *)(s))[0];\ + (( u8 *)(void *)(d))[1] = ((u8 *)(void *)(s))[1];} + +#define ACPI_MOVE_16_TO_32(d, s) {(*(u32 *)(void *)(d)) = 0; ACPI_MOVE_16_TO_16(d, s);} +#define ACPI_MOVE_16_TO_64(d, s) {(*(u64 *)(void *)(d)) = 0; ACPI_MOVE_16_TO_16(d, s);} + +/* 32-bit source, 16/32/64 destination */ + +#define ACPI_MOVE_32_TO_16(d, s) ACPI_MOVE_16_TO_16(d, s) /* Truncate to 16 */ + +#define ACPI_MOVE_32_TO_32(d, s) {(( u8 *)(void *)(d))[0] = ((u8 *)(void *)(s))[0];\ + (( u8 *)(void *)(d))[1] = ((u8 *)(void *)(s))[1];\ + (( u8 *)(void *)(d))[2] = ((u8 *)(void *)(s))[2];\ + (( u8 *)(void *)(d))[3] = ((u8 *)(void *)(s))[3];} + +#define ACPI_MOVE_32_TO_64(d, s) {(*(u64 *)(void *)(d)) = 0; ACPI_MOVE_32_TO_32(d, s);} + +/* 64-bit source, 16/32/64 destination */ + +#define ACPI_MOVE_64_TO_16(d, s) ACPI_MOVE_16_TO_16(d, s) /* Truncate to 16 */ +#define ACPI_MOVE_64_TO_32(d, s) ACPI_MOVE_32_TO_32(d, s) /* Truncate to 32 */ +#define ACPI_MOVE_64_TO_64(d, s) {(( u8 *)(void *)(d))[0] = ((u8 *)(void *)(s))[0];\ + (( u8 *)(void *)(d))[1] = ((u8 *)(void *)(s))[1];\ + (( u8 *)(void *)(d))[2] = ((u8 *)(void *)(s))[2];\ + (( u8 *)(void *)(d))[3] = ((u8 *)(void *)(s))[3];\ + (( u8 *)(void *)(d))[4] = ((u8 *)(void *)(s))[4];\ + (( u8 *)(void *)(d))[5] = ((u8 *)(void *)(s))[5];\ + (( u8 *)(void *)(d))[6] = ((u8 *)(void *)(s))[6];\ + (( u8 *)(void *)(d))[7] = ((u8 *)(void *)(s))[7];} +#endif +#endif + +/* Macros based on machine integer width */ + +#if ACPI_MACHINE_WIDTH == 32 +#define ACPI_MOVE_SIZE_TO_16(d, s) ACPI_MOVE_32_TO_16(d, s) + +#elif ACPI_MACHINE_WIDTH == 64 +#define ACPI_MOVE_SIZE_TO_16(d, s) ACPI_MOVE_64_TO_16(d, s) + +#else +#error unknown ACPI_MACHINE_WIDTH +#endif + +/* + * Fast power-of-two math macros for non-optimized compilers + */ +#define _ACPI_DIV(value, power_of2) ((u32) ((value) >> (power_of2))) +#define _ACPI_MUL(value, power_of2) ((u32) ((value) << (power_of2))) +#define _ACPI_MOD(value, divisor) ((u32) ((value) & ((divisor) -1))) + +#define ACPI_DIV_2(a) _ACPI_DIV(a, 1) +#define ACPI_MUL_2(a) _ACPI_MUL(a, 1) +#define ACPI_MOD_2(a) _ACPI_MOD(a, 2) + +#define ACPI_DIV_4(a) _ACPI_DIV(a, 2) +#define ACPI_MUL_4(a) _ACPI_MUL(a, 2) +#define ACPI_MOD_4(a) _ACPI_MOD(a, 4) + +#define ACPI_DIV_8(a) _ACPI_DIV(a, 3) +#define ACPI_MUL_8(a) _ACPI_MUL(a, 3) +#define ACPI_MOD_8(a) _ACPI_MOD(a, 8) + +#define ACPI_DIV_16(a) _ACPI_DIV(a, 4) +#define ACPI_MUL_16(a) _ACPI_MUL(a, 4) +#define ACPI_MOD_16(a) _ACPI_MOD(a, 16) + +#define ACPI_DIV_32(a) _ACPI_DIV(a, 5) +#define ACPI_MUL_32(a) _ACPI_MUL(a, 5) +#define ACPI_MOD_32(a) _ACPI_MOD(a, 32) + +/* + * Rounding macros (Power of two boundaries only) + */ +#define ACPI_ROUND_DOWN(value, boundary) (((acpi_size)(value)) & \ + (~(((acpi_size) boundary)-1))) + +#define ACPI_ROUND_UP(value, boundary) ((((acpi_size)(value)) + \ + (((acpi_size) boundary)-1)) & \ + (~(((acpi_size) boundary)-1))) + +/* Note: sizeof(acpi_size) evaluates to either 4 or 8 (32- vs 64-bit mode) */ + +#define ACPI_ROUND_DOWN_TO_32BIT(a) ACPI_ROUND_DOWN(a, 4) +#define ACPI_ROUND_DOWN_TO_64BIT(a) ACPI_ROUND_DOWN(a, 8) +#define ACPI_ROUND_DOWN_TO_NATIVE_WORD(a) ACPI_ROUND_DOWN(a, sizeof(acpi_size)) + +#define ACPI_ROUND_UP_TO_32BIT(a) ACPI_ROUND_UP(a, 4) +#define ACPI_ROUND_UP_TO_64BIT(a) ACPI_ROUND_UP(a, 8) +#define ACPI_ROUND_UP_TO_NATIVE_WORD(a) ACPI_ROUND_UP(a, sizeof(acpi_size)) + +#define ACPI_ROUND_BITS_UP_TO_BYTES(a) ACPI_DIV_8((a) + 7) +#define ACPI_ROUND_BITS_DOWN_TO_BYTES(a) ACPI_DIV_8((a)) + +#define ACPI_ROUND_UP_TO_1K(a) (((a) + 1023) >> 10) + +/* Generic (non-power-of-two) rounding */ + +#define ACPI_ROUND_UP_TO(value, boundary) (((value) + ((boundary)-1)) / (boundary)) + +#define ACPI_IS_MISALIGNED(value) (((acpi_size) value) & (sizeof(acpi_size)-1)) + +/* + * Bitmask creation + * Bit positions start at zero. + * MASK_BITS_ABOVE creates a mask starting AT the position and above + * MASK_BITS_BELOW creates a mask starting one bit BELOW the position + */ +#define ACPI_MASK_BITS_ABOVE(position) (~((ACPI_INTEGER_MAX) << ((u32) (position)))) +#define ACPI_MASK_BITS_BELOW(position) ((ACPI_INTEGER_MAX) << ((u32) (position))) + +/* Bitfields within ACPI registers */ + +#define ACPI_REGISTER_PREPARE_BITS(val, pos, mask) ((val << pos) & mask) +#define ACPI_REGISTER_INSERT_VALUE(reg, pos, mask, val) reg = (reg & (~(mask))) | ACPI_REGISTER_PREPARE_BITS(val, pos, mask) + +#define ACPI_INSERT_BITS(target, mask, source) target = ((target & (~(mask))) | (source & mask)) + +/* - * An struct acpi_namespace_node can appear in some contexts - * where a pointer to an union acpi_operand_object can also ++ * A struct acpi_namespace_node can appear in some contexts ++ * where a pointer to a union acpi_operand_object can also + * appear. This macro is used to distinguish them. + * + * The "Descriptor" field is the first field in both structures. + */ +#define ACPI_GET_DESCRIPTOR_TYPE(d) (((union acpi_descriptor *)(void *)(d))->common.descriptor_type) +#define ACPI_SET_DESCRIPTOR_TYPE(d, t) (((union acpi_descriptor *)(void *)(d))->common.descriptor_type = t) + +/* Macro to test the object type */ + +#define ACPI_GET_OBJECT_TYPE(d) (((union acpi_operand_object *)(void *)(d))->common.type) + +/* + * Macros for the master AML opcode table + */ +#if defined (ACPI_DISASSEMBLER) || defined (ACPI_DEBUG_OUTPUT) +#define ACPI_OP(name, Pargs, Iargs, obj_type, class, type, flags) \ + {name, (u32)(Pargs), (u32)(Iargs), (u32)(flags), obj_type, class, type} +#else +#define ACPI_OP(name, Pargs, Iargs, obj_type, class, type, flags) \ + {(u32)(Pargs), (u32)(Iargs), (u32)(flags), obj_type, class, type} +#endif + +#define ARG_TYPE_WIDTH 5 +#define ARG_1(x) ((u32)(x)) +#define ARG_2(x) ((u32)(x) << (1 * ARG_TYPE_WIDTH)) +#define ARG_3(x) ((u32)(x) << (2 * ARG_TYPE_WIDTH)) +#define ARG_4(x) ((u32)(x) << (3 * ARG_TYPE_WIDTH)) +#define ARG_5(x) ((u32)(x) << (4 * ARG_TYPE_WIDTH)) +#define ARG_6(x) ((u32)(x) << (5 * ARG_TYPE_WIDTH)) + +#define ARGI_LIST1(a) (ARG_1(a)) +#define ARGI_LIST2(a, b) (ARG_1(b)|ARG_2(a)) +#define ARGI_LIST3(a, b, c) (ARG_1(c)|ARG_2(b)|ARG_3(a)) +#define ARGI_LIST4(a, b, c, d) (ARG_1(d)|ARG_2(c)|ARG_3(b)|ARG_4(a)) +#define ARGI_LIST5(a, b, c, d, e) (ARG_1(e)|ARG_2(d)|ARG_3(c)|ARG_4(b)|ARG_5(a)) +#define ARGI_LIST6(a, b, c, d, e, f) (ARG_1(f)|ARG_2(e)|ARG_3(d)|ARG_4(c)|ARG_5(b)|ARG_6(a)) + +#define ARGP_LIST1(a) (ARG_1(a)) +#define ARGP_LIST2(a, b) (ARG_1(a)|ARG_2(b)) +#define ARGP_LIST3(a, b, c) (ARG_1(a)|ARG_2(b)|ARG_3(c)) +#define ARGP_LIST4(a, b, c, d) (ARG_1(a)|ARG_2(b)|ARG_3(c)|ARG_4(d)) +#define ARGP_LIST5(a, b, c, d, e) (ARG_1(a)|ARG_2(b)|ARG_3(c)|ARG_4(d)|ARG_5(e)) +#define ARGP_LIST6(a, b, c, d, e, f) (ARG_1(a)|ARG_2(b)|ARG_3(c)|ARG_4(d)|ARG_5(e)|ARG_6(f)) + +#define GET_CURRENT_ARG_TYPE(list) (list & ((u32) 0x1F)) +#define INCREMENT_ARG_LIST(list) (list >>= ((u32) ARG_TYPE_WIDTH)) + +/* + * Ascii error messages can be configured out + */ +#ifndef ACPI_NO_ERROR_MESSAGES + +/* + * Error reporting. Callers module and line number are inserted by AE_INFO, + * the plist contains a set of parens to allow variable-length lists. + * These macros are used for both the debug and non-debug versions of the code. + */ +#define ACPI_ERROR_NAMESPACE(s, e) acpi_ns_report_error (AE_INFO, s, e); +#define ACPI_ERROR_METHOD(s, n, p, e) acpi_ns_report_method_error (AE_INFO, s, n, p, e); + +#else + +/* No error messages */ + +#define ACPI_ERROR_NAMESPACE(s, e) +#define ACPI_ERROR_METHOD(s, n, p, e) +#endif /* ACPI_NO_ERROR_MESSAGES */ + +/* + * Debug macros that are conditionally compiled + */ +#ifdef ACPI_DEBUG_OUTPUT + +/* + * Function entry tracing + */ +#ifdef CONFIG_ACPI_DEBUG_FUNC_TRACE + +#define ACPI_FUNCTION_TRACE(a) ACPI_FUNCTION_NAME(a) \ + acpi_ut_trace(ACPI_DEBUG_PARAMETERS) +#define ACPI_FUNCTION_TRACE_PTR(a, b) ACPI_FUNCTION_NAME(a) \ + acpi_ut_trace_ptr(ACPI_DEBUG_PARAMETERS, (void *)b) +#define ACPI_FUNCTION_TRACE_U32(a, b) ACPI_FUNCTION_NAME(a) \ + acpi_ut_trace_u32(ACPI_DEBUG_PARAMETERS, (u32)b) +#define ACPI_FUNCTION_TRACE_STR(a, b) ACPI_FUNCTION_NAME(a) \ + acpi_ut_trace_str(ACPI_DEBUG_PARAMETERS, (char *)b) + +#define ACPI_FUNCTION_ENTRY() acpi_ut_track_stack_ptr() + +/* + * Function exit tracing. + * WARNING: These macros include a return statement. This is usually considered + * bad form, but having a separate exit macro is very ugly and difficult to maintain. + * One of the FUNCTION_TRACE macros above must be used in conjunction with these macros + * so that "_AcpiFunctionName" is defined. + * + * Note: the DO_WHILE0 macro is used to prevent some compilers from complaining + * about these constructs. + */ +#ifdef ACPI_USE_DO_WHILE_0 +#define ACPI_DO_WHILE0(a) do a while(0) +#else +#define ACPI_DO_WHILE0(a) a +#endif + +#define return_VOID ACPI_DO_WHILE0 ({ \ + acpi_ut_exit (ACPI_DEBUG_PARAMETERS); \ + return;}) +/* + * There are two versions of most of the return macros. The default version is + * safer, since it avoids side-effects by guaranteeing that the argument will + * not be evaluated twice. + * + * A less-safe version of the macros is provided for optional use if the + * compiler uses excessive CPU stack (for example, this may happen in the + * debug case if code optimzation is disabled.) + */ +#ifndef ACPI_SIMPLE_RETURN_MACROS + +#define return_ACPI_STATUS(s) ACPI_DO_WHILE0 ({ \ + register acpi_status _s = (s); \ + acpi_ut_status_exit (ACPI_DEBUG_PARAMETERS, _s); \ + return (_s); }) +#define return_PTR(s) ACPI_DO_WHILE0 ({ \ + register void *_s = (void *) (s); \ + acpi_ut_ptr_exit (ACPI_DEBUG_PARAMETERS, (u8 *) _s); \ + return (_s); }) +#define return_VALUE(s) ACPI_DO_WHILE0 ({ \ + register acpi_integer _s = (s); \ + acpi_ut_value_exit (ACPI_DEBUG_PARAMETERS, _s); \ + return (_s); }) +#define return_UINT8(s) ACPI_DO_WHILE0 ({ \ + register u8 _s = (u8) (s); \ + acpi_ut_value_exit (ACPI_DEBUG_PARAMETERS, (acpi_integer) _s); \ + return (_s); }) +#define return_UINT32(s) ACPI_DO_WHILE0 ({ \ + register u32 _s = (u32) (s); \ + acpi_ut_value_exit (ACPI_DEBUG_PARAMETERS, (acpi_integer) _s); \ + return (_s); }) +#else /* Use original less-safe macros */ + +#define return_ACPI_STATUS(s) ACPI_DO_WHILE0 ({ \ + acpi_ut_status_exit (ACPI_DEBUG_PARAMETERS, (s)); \ + return((s)); }) +#define return_PTR(s) ACPI_DO_WHILE0 ({ \ + acpi_ut_ptr_exit (ACPI_DEBUG_PARAMETERS, (u8 *) (s)); \ + return((s)); }) +#define return_VALUE(s) ACPI_DO_WHILE0 ({ \ + acpi_ut_value_exit (ACPI_DEBUG_PARAMETERS, (acpi_integer) (s)); \ + return((s)); }) +#define return_UINT8(s) return_VALUE(s) +#define return_UINT32(s) return_VALUE(s) + +#endif /* ACPI_SIMPLE_RETURN_MACROS */ + +#else /* !CONFIG_ACPI_DEBUG_FUNC_TRACE */ + +#define ACPI_FUNCTION_TRACE(a) +#define ACPI_FUNCTION_TRACE_PTR(a,b) +#define ACPI_FUNCTION_TRACE_U32(a,b) +#define ACPI_FUNCTION_TRACE_STR(a,b) +#define ACPI_FUNCTION_EXIT +#define ACPI_FUNCTION_STATUS_EXIT(s) +#define ACPI_FUNCTION_VALUE_EXIT(s) +#define ACPI_FUNCTION_TRACE(a) +#define ACPI_FUNCTION_ENTRY() + +#define return_VOID return +#define return_ACPI_STATUS(s) return(s) +#define return_VALUE(s) return(s) +#define return_UINT8(s) return(s) +#define return_UINT32(s) return(s) +#define return_PTR(s) return(s) + +#endif /* CONFIG_ACPI_DEBUG_FUNC_TRACE */ + +/* Conditional execution */ + +#define ACPI_DEBUG_EXEC(a) a +#define ACPI_NORMAL_EXEC(a) + +#define ACPI_DEBUG_DEFINE(a) a; +#define ACPI_DEBUG_ONLY_MEMBERS(a) a; +#define _VERBOSE_STRUCTURES + +/* Stack and buffer dumping */ + +#define ACPI_DUMP_STACK_ENTRY(a) acpi_ex_dump_operand((a), 0) +#define ACPI_DUMP_OPERANDS(a, b, c) acpi_ex_dump_operands(a, b, c) + +#define ACPI_DUMP_ENTRY(a, b) acpi_ns_dump_entry (a, b) +#define ACPI_DUMP_PATHNAME(a, b, c, d) acpi_ns_dump_pathname(a, b, c, d) +#define ACPI_DUMP_RESOURCE_LIST(a) acpi_rs_dump_resource_list(a) +#define ACPI_DUMP_BUFFER(a, b) acpi_ut_dump_buffer((u8 *) a, b, DB_BYTE_DISPLAY, _COMPONENT) + +#else +/* + * This is the non-debug case -- make everything go away, + * leaving no executable debug code! + */ +#define ACPI_DEBUG_EXEC(a) +#define ACPI_NORMAL_EXEC(a) a; + +#define ACPI_DEBUG_DEFINE(a) do { } while(0) +#define ACPI_DEBUG_ONLY_MEMBERS(a) do { } while(0) +#define ACPI_FUNCTION_TRACE(a) do { } while(0) +#define ACPI_FUNCTION_TRACE_PTR(a, b) do { } while(0) +#define ACPI_FUNCTION_TRACE_U32(a, b) do { } while(0) +#define ACPI_FUNCTION_TRACE_STR(a, b) do { } while(0) +#define ACPI_FUNCTION_EXIT do { } while(0) +#define ACPI_FUNCTION_STATUS_EXIT(s) do { } while(0) +#define ACPI_FUNCTION_VALUE_EXIT(s) do { } while(0) +#define ACPI_FUNCTION_ENTRY() do { } while(0) +#define ACPI_DUMP_STACK_ENTRY(a) do { } while(0) +#define ACPI_DUMP_OPERANDS(a, b, c) do { } while(0) +#define ACPI_DUMP_ENTRY(a, b) do { } while(0) +#define ACPI_DUMP_TABLES(a, b) do { } while(0) +#define ACPI_DUMP_PATHNAME(a, b, c, d) do { } while(0) +#define ACPI_DUMP_RESOURCE_LIST(a) do { } while(0) +#define ACPI_DUMP_BUFFER(a, b) do { } while(0) + +#define return_VOID return +#define return_ACPI_STATUS(s) return(s) +#define return_VALUE(s) return(s) +#define return_UINT8(s) return(s) +#define return_UINT32(s) return(s) +#define return_PTR(s) return(s) + +#endif /* ACPI_DEBUG_OUTPUT */ + +/* + * Some code only gets executed when the debugger is built in. + * Note that this is entirely independent of whether the + * DEBUG_PRINT stuff (set by ACPI_DEBUG_OUTPUT) is on, or not. + */ +#ifdef ACPI_DEBUGGER +#define ACPI_DEBUGGER_EXEC(a) a +#else +#define ACPI_DEBUGGER_EXEC(a) +#endif + +#ifdef ACPI_DEBUG_OUTPUT +/* + * 1) Set name to blanks + * 2) Copy the object name + */ +#define ACPI_ADD_OBJECT_NAME(a,b) ACPI_MEMSET (a->common.name, ' ', sizeof (a->common.name));\ + ACPI_STRNCPY (a->common.name, acpi_gbl_ns_type_names[b], sizeof (a->common.name)) +#else + +#define ACPI_ADD_OBJECT_NAME(a,b) +#endif + +/* + * Memory allocation tracking (DEBUG ONLY) + */ +#define ACPI_MEM_PARAMETERS _COMPONENT, _acpi_module_name, __LINE__ + +#ifndef ACPI_DBG_TRACK_ALLOCATIONS + +/* Memory allocation */ + +#ifndef ACPI_ALLOCATE +#define ACPI_ALLOCATE(a) acpi_ut_allocate((acpi_size)(a), ACPI_MEM_PARAMETERS) +#endif +#ifndef ACPI_ALLOCATE_ZEROED +#define ACPI_ALLOCATE_ZEROED(a) acpi_ut_allocate_zeroed((acpi_size)(a), ACPI_MEM_PARAMETERS) +#endif +#ifndef ACPI_FREE +#define ACPI_FREE(a) acpio_os_free(a) +#endif +#define ACPI_MEM_TRACKING(a) + +#else + +/* Memory allocation */ + +#define ACPI_ALLOCATE(a) acpi_ut_allocate_and_track((acpi_size)(a), ACPI_MEM_PARAMETERS) +#define ACPI_ALLOCATE_ZEROED(a) acpi_ut_allocate_zeroed_and_track((acpi_size)(a), ACPI_MEM_PARAMETERS) +#define ACPI_FREE(a) acpi_ut_free_and_track(a, ACPI_MEM_PARAMETERS) +#define ACPI_MEM_TRACKING(a) a + +#endif /* ACPI_DBG_TRACK_ALLOCATIONS */ + +/* Preemption point */ +#ifndef ACPI_PREEMPTION_POINT +#define ACPI_PREEMPTION_POINT() /* no preemption */ +#endif + +#endif /* ACMACROS_H */ diff --cc drivers/acpi/acpica/exprep.c index 33c66eb3ae39,000000000000..a226f74d4a5c mode 100644,000000..100644 --- a/drivers/acpi/acpica/exprep.c +++ b/drivers/acpi/acpica/exprep.c @@@ -1,590 -1,0 +1,590 @@@ + +/****************************************************************************** + * + * Module Name: exprep - ACPI AML (p-code) execution - field prep utilities + * + *****************************************************************************/ + +/* + * Copyright (C) 2000 - 2008, Intel Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * 3. Neither the names of the above-listed copyright holders nor the names + * of any contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + */ + +#include +#include "accommon.h" +#include "acinterp.h" +#include "amlcode.h" +#include "acnamesp.h" + +#define _COMPONENT ACPI_EXECUTER +ACPI_MODULE_NAME("exprep") + +/* Local prototypes */ +static u32 +acpi_ex_decode_field_access(union acpi_operand_object *obj_desc, + u8 field_flags, u32 * return_byte_alignment); + +#ifdef ACPI_UNDER_DEVELOPMENT + +static u32 +acpi_ex_generate_access(u32 field_bit_offset, + u32 field_bit_length, u32 region_length); + +/******************************************************************************* + * + * FUNCTION: acpi_ex_generate_access + * + * PARAMETERS: field_bit_offset - Start of field within parent region/buffer + * field_bit_length - Length of field in bits + * region_length - Length of parent in bytes + * + * RETURN: Field granularity (8, 16, 32 or 64) and + * byte_alignment (1, 2, 3, or 4) + * + * DESCRIPTION: Generate an optimal access width for fields defined with the + * any_acc keyword. + * + * NOTE: Need to have the region_length in order to check for boundary + * conditions (end-of-region). However, the region_length is a deferred + * operation. Therefore, to complete this implementation, the generation + * of this access width must be deferred until the region length has + * been evaluated. + * + ******************************************************************************/ + +static u32 +acpi_ex_generate_access(u32 field_bit_offset, + u32 field_bit_length, u32 region_length) +{ + u32 field_byte_length; + u32 field_byte_offset; + u32 field_byte_end_offset; + u32 access_byte_width; + u32 field_start_offset; + u32 field_end_offset; + u32 minimum_access_width = 0xFFFFFFFF; + u32 minimum_accesses = 0xFFFFFFFF; + u32 accesses; + + ACPI_FUNCTION_TRACE(ex_generate_access); + + /* Round Field start offset and length to "minimal" byte boundaries */ + + field_byte_offset = ACPI_DIV_8(ACPI_ROUND_DOWN(field_bit_offset, 8)); + field_byte_end_offset = ACPI_DIV_8(ACPI_ROUND_UP(field_bit_length + + field_bit_offset, 8)); + field_byte_length = field_byte_end_offset - field_byte_offset; + + ACPI_DEBUG_PRINT((ACPI_DB_BFIELD, + "Bit length %d, Bit offset %d\n", + field_bit_length, field_bit_offset)); + + ACPI_DEBUG_PRINT((ACPI_DB_BFIELD, + "Byte Length %d, Byte Offset %d, End Offset %d\n", + field_byte_length, field_byte_offset, + field_byte_end_offset)); + + /* + * Iterative search for the maximum access width that is both aligned + * and does not go beyond the end of the region + * + * Start at byte_acc and work upwards to qword_acc max. (1,2,4,8 bytes) + */ + for (access_byte_width = 1; access_byte_width <= 8; + access_byte_width <<= 1) { + /* + * 1) Round end offset up to next access boundary and make sure that + * this does not go beyond the end of the parent region. + * 2) When the Access width is greater than the field_byte_length, we + * are done. (This does not optimize for the perfectly aligned + * case yet). + */ + if (ACPI_ROUND_UP(field_byte_end_offset, access_byte_width) <= + region_length) { + field_start_offset = + ACPI_ROUND_DOWN(field_byte_offset, + access_byte_width) / + access_byte_width; + + field_end_offset = + ACPI_ROUND_UP((field_byte_length + + field_byte_offset), + access_byte_width) / + access_byte_width; + + accesses = field_end_offset - field_start_offset; + + ACPI_DEBUG_PRINT((ACPI_DB_BFIELD, + "AccessWidth %d end is within region\n", + access_byte_width)); + + ACPI_DEBUG_PRINT((ACPI_DB_BFIELD, + "Field Start %d, Field End %d -- requires %d accesses\n", + field_start_offset, field_end_offset, + accesses)); + + /* Single access is optimal */ + + if (accesses <= 1) { + ACPI_DEBUG_PRINT((ACPI_DB_BFIELD, + "Entire field can be accessed with one operation of size %d\n", + access_byte_width)); + return_VALUE(access_byte_width); + } + + /* + * Fits in the region, but requires more than one read/write. + * try the next wider access on next iteration + */ + if (accesses < minimum_accesses) { + minimum_accesses = accesses; + minimum_access_width = access_byte_width; + } + } else { + ACPI_DEBUG_PRINT((ACPI_DB_BFIELD, + "AccessWidth %d end is NOT within region\n", + access_byte_width)); + if (access_byte_width == 1) { + ACPI_DEBUG_PRINT((ACPI_DB_BFIELD, + "Field goes beyond end-of-region!\n")); + + /* Field does not fit in the region at all */ + + return_VALUE(0); + } + + /* + * This width goes beyond the end-of-region, back off to + * previous access + */ + ACPI_DEBUG_PRINT((ACPI_DB_BFIELD, + "Backing off to previous optimal access width of %d\n", + minimum_access_width)); + return_VALUE(minimum_access_width); + } + } + + /* + * Could not read/write field with one operation, + * just use max access width + */ + ACPI_DEBUG_PRINT((ACPI_DB_BFIELD, + "Cannot access field in one operation, using width 8\n")); + return_VALUE(8); +} +#endif /* ACPI_UNDER_DEVELOPMENT */ + +/******************************************************************************* + * + * FUNCTION: acpi_ex_decode_field_access + * + * PARAMETERS: obj_desc - Field object + * field_flags - Encoded fieldflags (contains access bits) + * return_byte_alignment - Where the byte alignment is returned + * + * RETURN: Field granularity (8, 16, 32 or 64) and + * byte_alignment (1, 2, 3, or 4) + * + * DESCRIPTION: Decode the access_type bits of a field definition. + * + ******************************************************************************/ + +static u32 +acpi_ex_decode_field_access(union acpi_operand_object *obj_desc, + u8 field_flags, u32 * return_byte_alignment) +{ + u32 access; + u32 byte_alignment; + u32 bit_length; + + ACPI_FUNCTION_TRACE(ex_decode_field_access); + + access = (field_flags & AML_FIELD_ACCESS_TYPE_MASK); + + switch (access) { + case AML_FIELD_ACCESS_ANY: + +#ifdef ACPI_UNDER_DEVELOPMENT + byte_alignment = + acpi_ex_generate_access(obj_desc->common_field. + start_field_bit_offset, + obj_desc->common_field.bit_length, + 0xFFFFFFFF + /* Temp until we pass region_length as parameter */ + ); + bit_length = byte_alignment * 8; +#endif + + byte_alignment = 1; + bit_length = 8; + break; + + case AML_FIELD_ACCESS_BYTE: + case AML_FIELD_ACCESS_BUFFER: /* ACPI 2.0 (SMBus Buffer) */ + byte_alignment = 1; + bit_length = 8; + break; + + case AML_FIELD_ACCESS_WORD: + byte_alignment = 2; + bit_length = 16; + break; + + case AML_FIELD_ACCESS_DWORD: + byte_alignment = 4; + bit_length = 32; + break; + + case AML_FIELD_ACCESS_QWORD: /* ACPI 2.0 */ + byte_alignment = 8; + bit_length = 64; + break; + + default: + /* Invalid field access type */ + + ACPI_ERROR((AE_INFO, "Unknown field access type %X", access)); + return_UINT32(0); + } + + if (ACPI_GET_OBJECT_TYPE(obj_desc) == ACPI_TYPE_BUFFER_FIELD) { + /* + * buffer_field access can be on any byte boundary, so the + * byte_alignment is always 1 byte -- regardless of any byte_alignment + * implied by the field access type. + */ + byte_alignment = 1; + } + + *return_byte_alignment = byte_alignment; + return_UINT32(bit_length); +} + +/******************************************************************************* + * + * FUNCTION: acpi_ex_prep_common_field_object + * + * PARAMETERS: obj_desc - The field object + * field_flags - Access, lock_rule, and update_rule. + * The format of a field_flag is described + * in the ACPI specification + * field_attribute - Special attributes (not used) + * field_bit_position - Field start position + * field_bit_length - Field length in number of bits + * + * RETURN: Status + * + * DESCRIPTION: Initialize the areas of the field object that are common + * to the various types of fields. Note: This is very "sensitive" + * code because we are solving the general case for field + * alignment. + * + ******************************************************************************/ + +acpi_status +acpi_ex_prep_common_field_object(union acpi_operand_object *obj_desc, + u8 field_flags, + u8 field_attribute, + u32 field_bit_position, u32 field_bit_length) +{ + u32 access_bit_width; + u32 byte_alignment; + u32 nearest_byte_address; + + ACPI_FUNCTION_TRACE(ex_prep_common_field_object); + + /* + * Note: the structure being initialized is the + * ACPI_COMMON_FIELD_INFO; No structure fields outside of the common + * area are initialized by this procedure. + */ + obj_desc->common_field.field_flags = field_flags; + obj_desc->common_field.attribute = field_attribute; + obj_desc->common_field.bit_length = field_bit_length; + + /* + * Decode the access type so we can compute offsets. The access type gives + * two pieces of information - the width of each field access and the + * necessary byte_alignment (address granularity) of the access. + * + * For any_acc, the access_bit_width is the largest width that is both + * necessary and possible in an attempt to access the whole field in one + * I/O operation. However, for any_acc, the byte_alignment is always one + * byte. + * + * For all Buffer Fields, the byte_alignment is always one byte. + * + * For all other access types (Byte, Word, Dword, Qword), the Bitwidth is + * the same (equivalent) as the byte_alignment. + */ + access_bit_width = acpi_ex_decode_field_access(obj_desc, field_flags, + &byte_alignment); + if (!access_bit_width) { + return_ACPI_STATUS(AE_AML_OPERAND_VALUE); + } + + /* Setup width (access granularity) fields */ + + obj_desc->common_field.access_byte_width = (u8) + ACPI_DIV_8(access_bit_width); /* 1, 2, 4, 8 */ + + obj_desc->common_field.access_bit_width = (u8) access_bit_width; + + /* + * base_byte_offset is the address of the start of the field within the + * region. It is the byte address of the first *datum* (field-width data + * unit) of the field. (i.e., the first datum that contains at least the + * first *bit* of the field.) + * + * Note: byte_alignment is always either equal to the access_bit_width or 8 + * (Byte access), and it defines the addressing granularity of the parent + * region or buffer. + */ + nearest_byte_address = + ACPI_ROUND_BITS_DOWN_TO_BYTES(field_bit_position); + obj_desc->common_field.base_byte_offset = (u32) + ACPI_ROUND_DOWN(nearest_byte_address, byte_alignment); + + /* + * start_field_bit_offset is the offset of the first bit of the field within + * a field datum. + */ + obj_desc->common_field.start_field_bit_offset = (u8) + (field_bit_position - + ACPI_MUL_8(obj_desc->common_field.base_byte_offset)); + + /* + * Does the entire field fit within a single field access element? (datum) + * (i.e., without crossing a datum boundary) + */ + if ((obj_desc->common_field.start_field_bit_offset + + field_bit_length) <= (u16) access_bit_width) { + obj_desc->common.flags |= AOPOBJ_SINGLE_DATUM; + } + + return_ACPI_STATUS(AE_OK); +} + +/******************************************************************************* + * + * FUNCTION: acpi_ex_prep_field_value + * + * PARAMETERS: Info - Contains all field creation info + * + * RETURN: Status + * - * DESCRIPTION: Construct an union acpi_operand_object of type def_field and ++ * DESCRIPTION: Construct a union acpi_operand_object of type def_field and + * connect it to the parent Node. + * + ******************************************************************************/ + +acpi_status acpi_ex_prep_field_value(struct acpi_create_field_info *info) +{ + union acpi_operand_object *obj_desc; + union acpi_operand_object *second_desc = NULL; + u32 type; + acpi_status status; + + ACPI_FUNCTION_TRACE(ex_prep_field_value); + + /* Parameter validation */ + + if (info->field_type != ACPI_TYPE_LOCAL_INDEX_FIELD) { + if (!info->region_node) { + ACPI_ERROR((AE_INFO, "Null RegionNode")); + return_ACPI_STATUS(AE_AML_NO_OPERAND); + } + + type = acpi_ns_get_type(info->region_node); + if (type != ACPI_TYPE_REGION) { + ACPI_ERROR((AE_INFO, + "Needed Region, found type %X (%s)", + type, acpi_ut_get_type_name(type))); + + return_ACPI_STATUS(AE_AML_OPERAND_TYPE); + } + } + + /* Allocate a new field object */ + + obj_desc = acpi_ut_create_internal_object(info->field_type); + if (!obj_desc) { + return_ACPI_STATUS(AE_NO_MEMORY); + } + + /* Initialize areas of the object that are common to all fields */ + + obj_desc->common_field.node = info->field_node; + status = acpi_ex_prep_common_field_object(obj_desc, info->field_flags, + info->attribute, + info->field_bit_position, + info->field_bit_length); + if (ACPI_FAILURE(status)) { + acpi_ut_delete_object_desc(obj_desc); + return_ACPI_STATUS(status); + } + + /* Initialize areas of the object that are specific to the field type */ + + switch (info->field_type) { + case ACPI_TYPE_LOCAL_REGION_FIELD: + + obj_desc->field.region_obj = + acpi_ns_get_attached_object(info->region_node); + + /* An additional reference for the container */ + + acpi_ut_add_reference(obj_desc->field.region_obj); + + ACPI_DEBUG_PRINT((ACPI_DB_BFIELD, + "RegionField: BitOff %X, Off %X, Gran %X, Region %p\n", + obj_desc->field.start_field_bit_offset, + obj_desc->field.base_byte_offset, + obj_desc->field.access_byte_width, + obj_desc->field.region_obj)); + break; + + case ACPI_TYPE_LOCAL_BANK_FIELD: + + obj_desc->bank_field.value = info->bank_value; + obj_desc->bank_field.region_obj = + acpi_ns_get_attached_object(info->region_node); + obj_desc->bank_field.bank_obj = + acpi_ns_get_attached_object(info->register_node); + + /* An additional reference for the attached objects */ + + acpi_ut_add_reference(obj_desc->bank_field.region_obj); + acpi_ut_add_reference(obj_desc->bank_field.bank_obj); + + ACPI_DEBUG_PRINT((ACPI_DB_BFIELD, + "Bank Field: BitOff %X, Off %X, Gran %X, Region %p, BankReg %p\n", + obj_desc->bank_field.start_field_bit_offset, + obj_desc->bank_field.base_byte_offset, + obj_desc->field.access_byte_width, + obj_desc->bank_field.region_obj, + obj_desc->bank_field.bank_obj)); + + /* + * Remember location in AML stream of the field unit + * opcode and operands -- since the bank_value + * operands must be evaluated. + */ + second_desc = obj_desc->common.next_object; + second_desc->extra.aml_start = + ACPI_CAST_PTR(union acpi_parse_object, + info->data_register_node)->named.data; + second_desc->extra.aml_length = + ACPI_CAST_PTR(union acpi_parse_object, + info->data_register_node)->named.length; + + break; + + case ACPI_TYPE_LOCAL_INDEX_FIELD: + + /* Get the Index and Data registers */ + + obj_desc->index_field.index_obj = + acpi_ns_get_attached_object(info->register_node); + obj_desc->index_field.data_obj = + acpi_ns_get_attached_object(info->data_register_node); + + if (!obj_desc->index_field.data_obj + || !obj_desc->index_field.index_obj) { + ACPI_ERROR((AE_INFO, + "Null Index Object during field prep")); + acpi_ut_delete_object_desc(obj_desc); + return_ACPI_STATUS(AE_AML_INTERNAL); + } + + /* An additional reference for the attached objects */ + + acpi_ut_add_reference(obj_desc->index_field.data_obj); + acpi_ut_add_reference(obj_desc->index_field.index_obj); + + /* + * April 2006: Changed to match MS behavior + * + * The value written to the Index register is the byte offset of the + * target field in units of the granularity of the index_field + * + * Previously, the value was calculated as an index in terms of the + * width of the Data register, as below: + * + * obj_desc->index_field.Value = (u32) + * (Info->field_bit_position / ACPI_MUL_8 ( + * obj_desc->Field.access_byte_width)); + * + * February 2006: Tried value as a byte offset: + * obj_desc->index_field.Value = (u32) + * ACPI_DIV_8 (Info->field_bit_position); + */ + obj_desc->index_field.value = + (u32) ACPI_ROUND_DOWN(ACPI_DIV_8(info->field_bit_position), + obj_desc->index_field. + access_byte_width); + + ACPI_DEBUG_PRINT((ACPI_DB_BFIELD, + "IndexField: BitOff %X, Off %X, Value %X, Gran %X, Index %p, Data %p\n", + obj_desc->index_field.start_field_bit_offset, + obj_desc->index_field.base_byte_offset, + obj_desc->index_field.value, + obj_desc->field.access_byte_width, + obj_desc->index_field.index_obj, + obj_desc->index_field.data_obj)); + break; + + default: + /* No other types should get here */ + break; + } + + /* + * Store the constructed descriptor (obj_desc) into the parent Node, + * preserving the current type of that named_obj. + */ + status = acpi_ns_attach_object(info->field_node, obj_desc, + acpi_ns_get_type(info->field_node)); + + ACPI_DEBUG_PRINT((ACPI_DB_BFIELD, + "Set NamedObj %p [%4.4s], ObjDesc %p\n", + info->field_node, + acpi_ut_get_node_name(info->field_node), obj_desc)); + + /* Remove local reference to the object */ + + acpi_ut_remove_reference(obj_desc); + return_ACPI_STATUS(status); +} diff --cc drivers/acpi/acpica/exresolv.c index 3673d2b2c4ac,000000000000..f6105a6d6126 mode 100644,000000..100644 --- a/drivers/acpi/acpica/exresolv.c +++ b/drivers/acpi/acpica/exresolv.c @@@ -1,551 -1,0 +1,551 @@@ + +/****************************************************************************** + * + * Module Name: exresolv - AML Interpreter object resolution + * + *****************************************************************************/ + +/* + * Copyright (C) 2000 - 2008, Intel Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * 3. Neither the names of the above-listed copyright holders nor the names + * of any contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + */ + +#include +#include "accommon.h" +#include "amlcode.h" +#include "acdispat.h" +#include "acinterp.h" +#include "acnamesp.h" + +#define _COMPONENT ACPI_EXECUTER +ACPI_MODULE_NAME("exresolv") + +/* Local prototypes */ +static acpi_status +acpi_ex_resolve_object_to_value(union acpi_operand_object **stack_ptr, + struct acpi_walk_state *walk_state); + +/******************************************************************************* + * + * FUNCTION: acpi_ex_resolve_to_value + * + * PARAMETERS: **stack_ptr - Points to entry on obj_stack, which can + * be either an (union acpi_operand_object *) + * or an acpi_handle. + * walk_state - Current method state + * + * RETURN: Status + * + * DESCRIPTION: Convert Reference objects to values + * + ******************************************************************************/ + +acpi_status +acpi_ex_resolve_to_value(union acpi_operand_object **stack_ptr, + struct acpi_walk_state *walk_state) +{ + acpi_status status; + + ACPI_FUNCTION_TRACE_PTR(ex_resolve_to_value, stack_ptr); + + if (!stack_ptr || !*stack_ptr) { + ACPI_ERROR((AE_INFO, "Internal - null pointer")); + return_ACPI_STATUS(AE_AML_NO_OPERAND); + } + + /* + * The entity pointed to by the stack_ptr can be either + * 1) A valid union acpi_operand_object, or + * 2) A struct acpi_namespace_node (named_obj) + */ + if (ACPI_GET_DESCRIPTOR_TYPE(*stack_ptr) == ACPI_DESC_TYPE_OPERAND) { + status = acpi_ex_resolve_object_to_value(stack_ptr, walk_state); + if (ACPI_FAILURE(status)) { + return_ACPI_STATUS(status); + } + + if (!*stack_ptr) { + ACPI_ERROR((AE_INFO, "Internal - null pointer")); + return_ACPI_STATUS(AE_AML_NO_OPERAND); + } + } + + /* + * Object on the stack may have changed if acpi_ex_resolve_object_to_value() + * was called (i.e., we can't use an _else_ here.) + */ + if (ACPI_GET_DESCRIPTOR_TYPE(*stack_ptr) == ACPI_DESC_TYPE_NAMED) { + status = + acpi_ex_resolve_node_to_value(ACPI_CAST_INDIRECT_PTR + (struct acpi_namespace_node, + stack_ptr), walk_state); + if (ACPI_FAILURE(status)) { + return_ACPI_STATUS(status); + } + } + + ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Resolved object %p\n", *stack_ptr)); + return_ACPI_STATUS(AE_OK); +} + +/******************************************************************************* + * + * FUNCTION: acpi_ex_resolve_object_to_value + * + * PARAMETERS: stack_ptr - Pointer to an internal object + * walk_state - Current method state + * + * RETURN: Status + * + * DESCRIPTION: Retrieve the value from an internal object. The Reference type + * uses the associated AML opcode to determine the value. + * + ******************************************************************************/ + +static acpi_status +acpi_ex_resolve_object_to_value(union acpi_operand_object **stack_ptr, + struct acpi_walk_state *walk_state) +{ + acpi_status status = AE_OK; + union acpi_operand_object *stack_desc; + union acpi_operand_object *obj_desc = NULL; + u8 ref_type; + + ACPI_FUNCTION_TRACE(ex_resolve_object_to_value); + + stack_desc = *stack_ptr; + - /* This is an union acpi_operand_object */ ++ /* This is a union acpi_operand_object */ + + switch (ACPI_GET_OBJECT_TYPE(stack_desc)) { + case ACPI_TYPE_LOCAL_REFERENCE: + + ref_type = stack_desc->reference.class; + + switch (ref_type) { + case ACPI_REFCLASS_LOCAL: + case ACPI_REFCLASS_ARG: + + /* + * Get the local from the method's state info + * Note: this increments the local's object reference count + */ + status = acpi_ds_method_data_get_value(ref_type, + stack_desc-> + reference.value, + walk_state, + &obj_desc); + if (ACPI_FAILURE(status)) { + return_ACPI_STATUS(status); + } + + ACPI_DEBUG_PRINT((ACPI_DB_EXEC, + "[Arg/Local %X] ValueObj is %p\n", + stack_desc->reference.value, + obj_desc)); + + /* + * Now we can delete the original Reference Object and + * replace it with the resolved value + */ + acpi_ut_remove_reference(stack_desc); + *stack_ptr = obj_desc; + break; + + case ACPI_REFCLASS_INDEX: + + switch (stack_desc->reference.target_type) { + case ACPI_TYPE_BUFFER_FIELD: + + /* Just return - do not dereference */ + break; + + case ACPI_TYPE_PACKAGE: + + /* If method call or copy_object - do not dereference */ + + if ((walk_state->opcode == + AML_INT_METHODCALL_OP) + || (walk_state->opcode == AML_COPY_OP)) { + break; + } + + /* Otherwise, dereference the package_index to a package element */ + + obj_desc = *stack_desc->reference.where; + if (obj_desc) { + /* + * Valid object descriptor, copy pointer to return value + * (i.e., dereference the package index) + * Delete the ref object, increment the returned object + */ + acpi_ut_remove_reference(stack_desc); + acpi_ut_add_reference(obj_desc); + *stack_ptr = obj_desc; + } else { + /* + * A NULL object descriptor means an uninitialized element of + * the package, can't dereference it + */ + ACPI_ERROR((AE_INFO, + "Attempt to dereference an Index to NULL package element Idx=%p", + stack_desc)); + status = AE_AML_UNINITIALIZED_ELEMENT; + } + break; + + default: + + /* Invalid reference object */ + + ACPI_ERROR((AE_INFO, + "Unknown TargetType %X in Index/Reference object %p", + stack_desc->reference.target_type, + stack_desc)); + status = AE_AML_INTERNAL; + break; + } + break; + + case ACPI_REFCLASS_REFOF: + case ACPI_REFCLASS_DEBUG: + case ACPI_REFCLASS_TABLE: + + /* Just leave the object as-is, do not dereference */ + + break; + + case ACPI_REFCLASS_NAME: /* Reference to a named object */ + + /* Dereference the name */ + + if ((stack_desc->reference.node->type == + ACPI_TYPE_DEVICE) + || (stack_desc->reference.node->type == + ACPI_TYPE_THERMAL)) { + + /* These node types do not have 'real' subobjects */ + + *stack_ptr = (void *)stack_desc->reference.node; + } else { + /* Get the object pointed to by the namespace node */ + + *stack_ptr = + (stack_desc->reference.node)->object; + acpi_ut_add_reference(*stack_ptr); + } + + acpi_ut_remove_reference(stack_desc); + break; + + default: + + ACPI_ERROR((AE_INFO, + "Unknown Reference type %X in %p", ref_type, + stack_desc)); + status = AE_AML_INTERNAL; + break; + } + break; + + case ACPI_TYPE_BUFFER: + + status = acpi_ds_get_buffer_arguments(stack_desc); + break; + + case ACPI_TYPE_PACKAGE: + + status = acpi_ds_get_package_arguments(stack_desc); + break; + + case ACPI_TYPE_BUFFER_FIELD: + case ACPI_TYPE_LOCAL_REGION_FIELD: + case ACPI_TYPE_LOCAL_BANK_FIELD: + case ACPI_TYPE_LOCAL_INDEX_FIELD: + + ACPI_DEBUG_PRINT((ACPI_DB_EXEC, + "FieldRead SourceDesc=%p Type=%X\n", + stack_desc, + ACPI_GET_OBJECT_TYPE(stack_desc))); + + status = + acpi_ex_read_data_from_field(walk_state, stack_desc, + &obj_desc); + + /* Remove a reference to the original operand, then override */ + + acpi_ut_remove_reference(*stack_ptr); + *stack_ptr = (void *)obj_desc; + break; + + default: + break; + } + + return_ACPI_STATUS(status); +} + +/******************************************************************************* + * + * FUNCTION: acpi_ex_resolve_multiple + * + * PARAMETERS: walk_state - Current state (contains AML opcode) + * Operand - Starting point for resolution + * return_type - Where the object type is returned + * return_desc - Where the resolved object is returned + * + * RETURN: Status + * + * DESCRIPTION: Return the base object and type. Traverse a reference list if + * necessary to get to the base object. + * + ******************************************************************************/ + +acpi_status +acpi_ex_resolve_multiple(struct acpi_walk_state *walk_state, + union acpi_operand_object *operand, + acpi_object_type * return_type, + union acpi_operand_object **return_desc) +{ + union acpi_operand_object *obj_desc = (void *)operand; + struct acpi_namespace_node *node; + acpi_object_type type; + acpi_status status; + + ACPI_FUNCTION_TRACE(acpi_ex_resolve_multiple); + + /* Operand can be either a namespace node or an operand descriptor */ + + switch (ACPI_GET_DESCRIPTOR_TYPE(obj_desc)) { + case ACPI_DESC_TYPE_OPERAND: + type = obj_desc->common.type; + break; + + case ACPI_DESC_TYPE_NAMED: + type = ((struct acpi_namespace_node *)obj_desc)->type; + obj_desc = + acpi_ns_get_attached_object((struct acpi_namespace_node *) + obj_desc); + + /* If we had an Alias node, use the attached object for type info */ + + if (type == ACPI_TYPE_LOCAL_ALIAS) { + type = ((struct acpi_namespace_node *)obj_desc)->type; + obj_desc = + acpi_ns_get_attached_object((struct + acpi_namespace_node *) + obj_desc); + } + break; + + default: + return_ACPI_STATUS(AE_AML_OPERAND_TYPE); + } + + /* If type is anything other than a reference, we are done */ + + if (type != ACPI_TYPE_LOCAL_REFERENCE) { + goto exit; + } + + /* + * For reference objects created via the ref_of, Index, or Load/load_table + * operators, we need to get to the base object (as per the ACPI + * specification of the object_type and size_of operators). This means + * traversing the list of possibly many nested references. + */ + while (ACPI_GET_OBJECT_TYPE(obj_desc) == ACPI_TYPE_LOCAL_REFERENCE) { + switch (obj_desc->reference.class) { + case ACPI_REFCLASS_REFOF: + case ACPI_REFCLASS_NAME: + + /* Dereference the reference pointer */ + + if (obj_desc->reference.class == ACPI_REFCLASS_REFOF) { + node = obj_desc->reference.object; + } else { /* AML_INT_NAMEPATH_OP */ + + node = obj_desc->reference.node; + } + + /* All "References" point to a NS node */ + + if (ACPI_GET_DESCRIPTOR_TYPE(node) != + ACPI_DESC_TYPE_NAMED) { + ACPI_ERROR((AE_INFO, "Not a NS node %p [%s]", + node, + acpi_ut_get_descriptor_name(node))); + return_ACPI_STATUS(AE_AML_INTERNAL); + } + + /* Get the attached object */ + + obj_desc = acpi_ns_get_attached_object(node); + if (!obj_desc) { + + /* No object, use the NS node type */ + + type = acpi_ns_get_type(node); + goto exit; + } + + /* Check for circular references */ + + if (obj_desc == operand) { + return_ACPI_STATUS(AE_AML_CIRCULAR_REFERENCE); + } + break; + + case ACPI_REFCLASS_INDEX: + + /* Get the type of this reference (index into another object) */ + + type = obj_desc->reference.target_type; + if (type != ACPI_TYPE_PACKAGE) { + goto exit; + } + + /* + * The main object is a package, we want to get the type + * of the individual package element that is referenced by + * the index. + * + * This could of course in turn be another reference object. + */ + obj_desc = *(obj_desc->reference.where); + if (!obj_desc) { + + /* NULL package elements are allowed */ + + type = 0; /* Uninitialized */ + goto exit; + } + break; + + case ACPI_REFCLASS_TABLE: + + type = ACPI_TYPE_DDB_HANDLE; + goto exit; + + case ACPI_REFCLASS_LOCAL: + case ACPI_REFCLASS_ARG: + + if (return_desc) { + status = + acpi_ds_method_data_get_value(obj_desc-> + reference. + class, + obj_desc-> + reference. + value, + walk_state, + &obj_desc); + if (ACPI_FAILURE(status)) { + return_ACPI_STATUS(status); + } + acpi_ut_remove_reference(obj_desc); + } else { + status = + acpi_ds_method_data_get_node(obj_desc-> + reference. + class, + obj_desc-> + reference. + value, + walk_state, + &node); + if (ACPI_FAILURE(status)) { + return_ACPI_STATUS(status); + } + + obj_desc = acpi_ns_get_attached_object(node); + if (!obj_desc) { + type = ACPI_TYPE_ANY; + goto exit; + } + } + break; + + case ACPI_REFCLASS_DEBUG: + + /* The Debug Object is of type "DebugObject" */ + + type = ACPI_TYPE_DEBUG_OBJECT; + goto exit; + + default: + + ACPI_ERROR((AE_INFO, + "Unknown Reference Class %2.2X", + obj_desc->reference.class)); + return_ACPI_STATUS(AE_AML_INTERNAL); + } + } + + /* + * Now we are guaranteed to have an object that has not been created + * via the ref_of or Index operators. + */ + type = ACPI_GET_OBJECT_TYPE(obj_desc); + + exit: + /* Convert internal types to external types */ + + switch (type) { + case ACPI_TYPE_LOCAL_REGION_FIELD: + case ACPI_TYPE_LOCAL_BANK_FIELD: + case ACPI_TYPE_LOCAL_INDEX_FIELD: + + type = ACPI_TYPE_FIELD_UNIT; + break; + + case ACPI_TYPE_LOCAL_SCOPE: + + /* Per ACPI Specification, Scope is untyped */ + + type = ACPI_TYPE_ANY; + break; + + default: + /* No change to Type required */ + break; + } + + *return_type = type; + if (return_desc) { + *return_desc = obj_desc; + } + return_ACPI_STATUS(AE_OK); +} diff --cc drivers/acpi/acpica/exstore.c index 7c6d7e53e41e,000000000000..e35e9b4f6a4e mode 100644,000000..100644 --- a/drivers/acpi/acpica/exstore.c +++ b/drivers/acpi/acpica/exstore.c @@@ -1,716 -1,0 +1,716 @@@ + +/****************************************************************************** + * + * Module Name: exstore - AML Interpreter object store support + * + *****************************************************************************/ + +/* + * Copyright (C) 2000 - 2008, Intel Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * 3. Neither the names of the above-listed copyright holders nor the names + * of any contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + */ + +#include +#include "accommon.h" +#include "acdispat.h" +#include "acinterp.h" +#include "amlcode.h" +#include "acnamesp.h" + +#define _COMPONENT ACPI_EXECUTER +ACPI_MODULE_NAME("exstore") + +/* Local prototypes */ +static void +acpi_ex_do_debug_object(union acpi_operand_object *source_desc, + u32 level, u32 index); + +static acpi_status +acpi_ex_store_object_to_index(union acpi_operand_object *val_desc, + union acpi_operand_object *dest_desc, + struct acpi_walk_state *walk_state); + +/******************************************************************************* + * + * FUNCTION: acpi_ex_do_debug_object + * + * PARAMETERS: source_desc - Value to be stored + * Level - Indentation level (used for packages) + * Index - Current package element, zero if not pkg + * + * RETURN: None + * + * DESCRIPTION: Handles stores to the Debug Object. + * + ******************************************************************************/ + +static void +acpi_ex_do_debug_object(union acpi_operand_object *source_desc, + u32 level, u32 index) +{ + u32 i; + + ACPI_FUNCTION_TRACE_PTR(ex_do_debug_object, source_desc); + + /* Print line header as long as we are not in the middle of an object display */ + + if (!((level > 0) && index == 0)) { + ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT, "[ACPI Debug] %*s", + level, " ")); + } + + /* Display index for package output only */ + + if (index > 0) { + ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT, + "(%.2u) ", index - 1)); + } + + if (!source_desc) { + ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT, "[Null Object]\n")); + return_VOID; + } + + if (ACPI_GET_DESCRIPTOR_TYPE(source_desc) == ACPI_DESC_TYPE_OPERAND) { + ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT, "%s ", + acpi_ut_get_object_type_name + (source_desc))); + + if (!acpi_ut_valid_internal_object(source_desc)) { + ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT, + "%p, Invalid Internal Object!\n", + source_desc)); + return_VOID; + } + } else if (ACPI_GET_DESCRIPTOR_TYPE(source_desc) == + ACPI_DESC_TYPE_NAMED) { + ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT, "%s: %p\n", + acpi_ut_get_type_name(((struct + acpi_namespace_node + *)source_desc)-> + type), + source_desc)); + return_VOID; + } else { + return_VOID; + } + + /* source_desc is of type ACPI_DESC_TYPE_OPERAND */ + + switch (ACPI_GET_OBJECT_TYPE(source_desc)) { + case ACPI_TYPE_INTEGER: + + /* Output correct integer width */ + + if (acpi_gbl_integer_byte_width == 4) { + ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT, "0x%8.8X\n", + (u32) source_desc->integer. + value)); + } else { + ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT, + "0x%8.8X%8.8X\n", + ACPI_FORMAT_UINT64(source_desc-> + integer. + value))); + } + break; + + case ACPI_TYPE_BUFFER: + + ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT, "[0x%.2X]\n", + (u32) source_desc->buffer.length)); + ACPI_DUMP_BUFFER(source_desc->buffer.pointer, + (source_desc->buffer.length < + 256) ? source_desc->buffer.length : 256); + break; + + case ACPI_TYPE_STRING: + + ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT, "[0x%.2X] \"%s\"\n", + source_desc->string.length, + source_desc->string.pointer)); + break; + + case ACPI_TYPE_PACKAGE: + + ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT, + "[Contains 0x%.2X Elements]\n", + source_desc->package.count)); + + /* Output the entire contents of the package */ + + for (i = 0; i < source_desc->package.count; i++) { + acpi_ex_do_debug_object(source_desc->package. + elements[i], level + 4, i + 1); + } + break; + + case ACPI_TYPE_LOCAL_REFERENCE: + + ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT, "[%s] ", + acpi_ut_get_reference_name(source_desc))); + + /* Decode the reference */ + + switch (source_desc->reference.class) { + case ACPI_REFCLASS_INDEX: + + ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT, "0x%X\n", + source_desc->reference.value)); + break; + + case ACPI_REFCLASS_TABLE: + + ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT, + "Table Index 0x%X\n", + source_desc->reference.value)); + break; + + default: + break; + } + + ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT, " ")); + + /* Check for valid node first, then valid object */ + + if (source_desc->reference.node) { + if (ACPI_GET_DESCRIPTOR_TYPE + (source_desc->reference.node) != + ACPI_DESC_TYPE_NAMED) { + ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT, + " %p - Not a valid namespace node\n", + source_desc->reference. + node)); + } else { + ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT, + "Node %p [%4.4s] ", + source_desc->reference. + node, + (source_desc->reference. + node)->name.ascii)); + + switch ((source_desc->reference.node)->type) { + + /* These types have no attached object */ + + case ACPI_TYPE_DEVICE: + acpi_os_printf("Device\n"); + break; + + case ACPI_TYPE_THERMAL: + acpi_os_printf("Thermal Zone\n"); + break; + + default: + acpi_ex_do_debug_object((source_desc-> + reference. + node)->object, + level + 4, 0); + break; + } + } + } else if (source_desc->reference.object) { + if (ACPI_GET_DESCRIPTOR_TYPE + (source_desc->reference.object) == + ACPI_DESC_TYPE_NAMED) { + acpi_ex_do_debug_object(((struct + acpi_namespace_node *) + source_desc->reference. + object)->object, + level + 4, 0); + } else { + acpi_ex_do_debug_object(source_desc->reference. + object, level + 4, 0); + } + } + break; + + default: + + ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT, "%p\n", + source_desc)); + break; + } + + ACPI_DEBUG_PRINT_RAW((ACPI_DB_EXEC, "\n")); + return_VOID; +} + +/******************************************************************************* + * + * FUNCTION: acpi_ex_store + * + * PARAMETERS: *source_desc - Value to be stored + * *dest_desc - Where to store it. Must be an NS node - * or an union acpi_operand_object of type ++ * or a union acpi_operand_object of type + * Reference; + * walk_state - Current walk state + * + * RETURN: Status + * + * DESCRIPTION: Store the value described by source_desc into the location + * described by dest_desc. Called by various interpreter + * functions to store the result of an operation into + * the destination operand -- not just simply the actual "Store" + * ASL operator. + * + ******************************************************************************/ + +acpi_status +acpi_ex_store(union acpi_operand_object *source_desc, + union acpi_operand_object *dest_desc, + struct acpi_walk_state *walk_state) +{ + acpi_status status = AE_OK; + union acpi_operand_object *ref_desc = dest_desc; + + ACPI_FUNCTION_TRACE_PTR(ex_store, dest_desc); + + /* Validate parameters */ + + if (!source_desc || !dest_desc) { + ACPI_ERROR((AE_INFO, "Null parameter")); + return_ACPI_STATUS(AE_AML_NO_OPERAND); + } + + /* dest_desc can be either a namespace node or an ACPI object */ + + if (ACPI_GET_DESCRIPTOR_TYPE(dest_desc) == ACPI_DESC_TYPE_NAMED) { + /* + * Dest is a namespace node, + * Storing an object into a Named node. + */ + status = acpi_ex_store_object_to_node(source_desc, + (struct + acpi_namespace_node *) + dest_desc, walk_state, + ACPI_IMPLICIT_CONVERSION); + + return_ACPI_STATUS(status); + } + + /* Destination object must be a Reference or a Constant object */ + + switch (ACPI_GET_OBJECT_TYPE(dest_desc)) { + case ACPI_TYPE_LOCAL_REFERENCE: + break; + + case ACPI_TYPE_INTEGER: + + /* Allow stores to Constants -- a Noop as per ACPI spec */ + + if (dest_desc->common.flags & AOPOBJ_AML_CONSTANT) { + return_ACPI_STATUS(AE_OK); + } + + /*lint -fallthrough */ + + default: + + /* Destination is not a Reference object */ + + ACPI_ERROR((AE_INFO, + "Target is not a Reference or Constant object - %s [%p]", + acpi_ut_get_object_type_name(dest_desc), + dest_desc)); + + return_ACPI_STATUS(AE_AML_OPERAND_TYPE); + } + + /* + * Examine the Reference class. These cases are handled: + * + * 1) Store to Name (Change the object associated with a name) + * 2) Store to an indexed area of a Buffer or Package + * 3) Store to a Method Local or Arg + * 4) Store to the debug object + */ + switch (ref_desc->reference.class) { + case ACPI_REFCLASS_REFOF: + + /* Storing an object into a Name "container" */ + + status = acpi_ex_store_object_to_node(source_desc, + ref_desc->reference. + object, walk_state, + ACPI_IMPLICIT_CONVERSION); + break; + + case ACPI_REFCLASS_INDEX: + + /* Storing to an Index (pointer into a packager or buffer) */ + + status = + acpi_ex_store_object_to_index(source_desc, ref_desc, + walk_state); + break; + + case ACPI_REFCLASS_LOCAL: + case ACPI_REFCLASS_ARG: + + /* Store to a method local/arg */ + + status = + acpi_ds_store_object_to_local(ref_desc->reference.class, + ref_desc->reference.value, + source_desc, walk_state); + break; + + case ACPI_REFCLASS_DEBUG: + + /* + * Storing to the Debug object causes the value stored to be + * displayed and otherwise has no effect -- see ACPI Specification + */ + ACPI_DEBUG_PRINT((ACPI_DB_EXEC, + "**** Write to Debug Object: Object %p %s ****:\n\n", + source_desc, + acpi_ut_get_object_type_name(source_desc))); + + acpi_ex_do_debug_object(source_desc, 0, 0); + break; + + default: + + ACPI_ERROR((AE_INFO, "Unknown Reference Class %2.2X", + ref_desc->reference.class)); + ACPI_DUMP_ENTRY(ref_desc, ACPI_LV_INFO); + + status = AE_AML_INTERNAL; + break; + } + + return_ACPI_STATUS(status); +} + +/******************************************************************************* + * + * FUNCTION: acpi_ex_store_object_to_index + * + * PARAMETERS: *source_desc - Value to be stored + * *dest_desc - Named object to receive the value + * walk_state - Current walk state + * + * RETURN: Status + * + * DESCRIPTION: Store the object to indexed Buffer or Package element + * + ******************************************************************************/ + +static acpi_status +acpi_ex_store_object_to_index(union acpi_operand_object *source_desc, + union acpi_operand_object *index_desc, + struct acpi_walk_state *walk_state) +{ + acpi_status status = AE_OK; + union acpi_operand_object *obj_desc; + union acpi_operand_object *new_desc; + u8 value = 0; + u32 i; + + ACPI_FUNCTION_TRACE(ex_store_object_to_index); + + /* + * Destination must be a reference pointer, and + * must point to either a buffer or a package + */ + switch (index_desc->reference.target_type) { + case ACPI_TYPE_PACKAGE: + /* + * Storing to a package element. Copy the object and replace + * any existing object with the new object. No implicit + * conversion is performed. + * + * The object at *(index_desc->Reference.Where) is the + * element within the package that is to be modified. + * The parent package object is at index_desc->Reference.Object + */ + obj_desc = *(index_desc->reference.where); + + if (ACPI_GET_OBJECT_TYPE(source_desc) == + ACPI_TYPE_LOCAL_REFERENCE + && source_desc->reference.class == ACPI_REFCLASS_TABLE) { + + /* This is a DDBHandle, just add a reference to it */ + + acpi_ut_add_reference(source_desc); + new_desc = source_desc; + } else { + /* Normal object, copy it */ + + status = + acpi_ut_copy_iobject_to_iobject(source_desc, + &new_desc, + walk_state); + if (ACPI_FAILURE(status)) { + return_ACPI_STATUS(status); + } + } + + if (obj_desc) { + + /* Decrement reference count by the ref count of the parent package */ + + for (i = 0; i < ((union acpi_operand_object *) + index_desc->reference.object)->common. + reference_count; i++) { + acpi_ut_remove_reference(obj_desc); + } + } + + *(index_desc->reference.where) = new_desc; + + /* Increment ref count by the ref count of the parent package-1 */ + + for (i = 1; i < ((union acpi_operand_object *) + index_desc->reference.object)->common. + reference_count; i++) { + acpi_ut_add_reference(new_desc); + } + + break; + + case ACPI_TYPE_BUFFER_FIELD: + + /* + * Store into a Buffer or String (not actually a real buffer_field) + * at a location defined by an Index. + * + * The first 8-bit element of the source object is written to the + * 8-bit Buffer location defined by the Index destination object, + * according to the ACPI 2.0 specification. + */ + + /* + * Make sure the target is a Buffer or String. An error should + * not happen here, since the reference_object was constructed + * by the INDEX_OP code. + */ + obj_desc = index_desc->reference.object; + if ((ACPI_GET_OBJECT_TYPE(obj_desc) != ACPI_TYPE_BUFFER) && + (ACPI_GET_OBJECT_TYPE(obj_desc) != ACPI_TYPE_STRING)) { + return_ACPI_STATUS(AE_AML_OPERAND_TYPE); + } + + /* + * The assignment of the individual elements will be slightly + * different for each source type. + */ + switch (ACPI_GET_OBJECT_TYPE(source_desc)) { + case ACPI_TYPE_INTEGER: + + /* Use the least-significant byte of the integer */ + + value = (u8) (source_desc->integer.value); + break; + + case ACPI_TYPE_BUFFER: + case ACPI_TYPE_STRING: + + /* Note: Takes advantage of common string/buffer fields */ + + value = source_desc->buffer.pointer[0]; + break; + + default: + + /* All other types are invalid */ + + ACPI_ERROR((AE_INFO, + "Source must be Integer/Buffer/String type, not %s", + acpi_ut_get_object_type_name(source_desc))); + return_ACPI_STATUS(AE_AML_OPERAND_TYPE); + } + + /* Store the source value into the target buffer byte */ + + obj_desc->buffer.pointer[index_desc->reference.value] = value; + break; + + default: + ACPI_ERROR((AE_INFO, "Target is not a Package or BufferField")); + status = AE_AML_OPERAND_TYPE; + break; + } + + return_ACPI_STATUS(status); +} + +/******************************************************************************* + * + * FUNCTION: acpi_ex_store_object_to_node + * + * PARAMETERS: source_desc - Value to be stored + * Node - Named object to receive the value + * walk_state - Current walk state + * implicit_conversion - Perform implicit conversion (yes/no) + * + * RETURN: Status + * + * DESCRIPTION: Store the object to the named object. + * + * The Assignment of an object to a named object is handled here + * The value passed in will replace the current value (if any) + * with the input value. + * + * When storing into an object the data is converted to the + * target object type then stored in the object. This means + * that the target object type (for an initialized target) will + * not be changed by a store operation. + * + * Assumes parameters are already validated. + * + ******************************************************************************/ + +acpi_status +acpi_ex_store_object_to_node(union acpi_operand_object *source_desc, + struct acpi_namespace_node *node, + struct acpi_walk_state *walk_state, + u8 implicit_conversion) +{ + acpi_status status = AE_OK; + union acpi_operand_object *target_desc; + union acpi_operand_object *new_desc; + acpi_object_type target_type; + + ACPI_FUNCTION_TRACE_PTR(ex_store_object_to_node, source_desc); + + /* Get current type of the node, and object attached to Node */ + + target_type = acpi_ns_get_type(node); + target_desc = acpi_ns_get_attached_object(node); + + ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Storing %p(%s) into node %p(%s)\n", + source_desc, + acpi_ut_get_object_type_name(source_desc), node, + acpi_ut_get_type_name(target_type))); + + /* + * Resolve the source object to an actual value + * (If it is a reference object) + */ + status = acpi_ex_resolve_object(&source_desc, target_type, walk_state); + if (ACPI_FAILURE(status)) { + return_ACPI_STATUS(status); + } + + /* If no implicit conversion, drop into the default case below */ + + if ((!implicit_conversion) || + ((walk_state->opcode == AML_COPY_OP) && + (target_type != ACPI_TYPE_LOCAL_REGION_FIELD) && + (target_type != ACPI_TYPE_LOCAL_BANK_FIELD) && + (target_type != ACPI_TYPE_LOCAL_INDEX_FIELD))) { + /* + * Force execution of default (no implicit conversion). Note: + * copy_object does not perform an implicit conversion, as per the ACPI + * spec -- except in case of region/bank/index fields -- because these + * objects must retain their original type permanently. + */ + target_type = ACPI_TYPE_ANY; + } + + /* Do the actual store operation */ + + switch (target_type) { + case ACPI_TYPE_BUFFER_FIELD: + case ACPI_TYPE_LOCAL_REGION_FIELD: + case ACPI_TYPE_LOCAL_BANK_FIELD: + case ACPI_TYPE_LOCAL_INDEX_FIELD: + + /* For fields, copy the source data to the target field. */ + + status = acpi_ex_write_data_to_field(source_desc, target_desc, + &walk_state->result_obj); + break; + + case ACPI_TYPE_INTEGER: + case ACPI_TYPE_STRING: + case ACPI_TYPE_BUFFER: + + /* + * These target types are all of type Integer/String/Buffer, and + * therefore support implicit conversion before the store. + * + * Copy and/or convert the source object to a new target object + */ + status = + acpi_ex_store_object_to_object(source_desc, target_desc, + &new_desc, walk_state); + if (ACPI_FAILURE(status)) { + return_ACPI_STATUS(status); + } + + if (new_desc != target_desc) { + /* + * Store the new new_desc as the new value of the Name, and set + * the Name's type to that of the value being stored in it. + * source_desc reference count is incremented by attach_object. + * + * Note: This may change the type of the node if an explicit store + * has been performed such that the node/object type has been + * changed. + */ + status = + acpi_ns_attach_object(node, new_desc, + new_desc->common.type); + + ACPI_DEBUG_PRINT((ACPI_DB_EXEC, + "Store %s into %s via Convert/Attach\n", + acpi_ut_get_object_type_name + (source_desc), + acpi_ut_get_object_type_name + (new_desc))); + } + break; + + default: + + ACPI_DEBUG_PRINT((ACPI_DB_EXEC, + "Storing %s (%p) directly into node (%p) with no implicit conversion\n", + acpi_ut_get_object_type_name(source_desc), + source_desc, node)); + + /* No conversions for all other types. Just attach the source object */ + + status = acpi_ns_attach_object(node, source_desc, + ACPI_GET_OBJECT_TYPE + (source_desc)); + break; + } + + return_ACPI_STATUS(status); +} diff --cc drivers/acpi/acpica/rscreate.c index 9eb3a2a68408,000000000000..61566b1a0616 mode 100644,000000..100644 --- a/drivers/acpi/acpica/rscreate.c +++ b/drivers/acpi/acpica/rscreate.c @@@ -1,468 -1,0 +1,468 @@@ +/******************************************************************************* + * + * Module Name: rscreate - Create resource lists/tables + * + ******************************************************************************/ + +/* + * Copyright (C) 2000 - 2008, Intel Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * 3. Neither the names of the above-listed copyright holders nor the names + * of any contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + */ + +#include +#include "accommon.h" +#include "acresrc.h" +#include "acnamesp.h" + +#define _COMPONENT ACPI_RESOURCES +ACPI_MODULE_NAME("rscreate") + +/******************************************************************************* + * + * FUNCTION: acpi_rs_create_resource_list + * + * PARAMETERS: aml_buffer - Pointer to the resource byte stream + * output_buffer - Pointer to the user's buffer + * + * RETURN: Status: AE_OK if okay, else a valid acpi_status code + * If output_buffer is not large enough, output_buffer_length + * indicates how large output_buffer should be, else it + * indicates how may u8 elements of output_buffer are valid. + * + * DESCRIPTION: Takes the byte stream returned from a _CRS, _PRS control method + * execution and parses the stream to create a linked list + * of device resources. + * + ******************************************************************************/ +acpi_status +acpi_rs_create_resource_list(union acpi_operand_object *aml_buffer, + struct acpi_buffer *output_buffer) +{ + + acpi_status status; + u8 *aml_start; + acpi_size list_size_needed = 0; + u32 aml_buffer_length; + void *resource; + + ACPI_FUNCTION_TRACE(rs_create_resource_list); + + ACPI_DEBUG_PRINT((ACPI_DB_INFO, "AmlBuffer = %p\n", aml_buffer)); + + /* Params already validated, so we don't re-validate here */ + + aml_buffer_length = aml_buffer->buffer.length; + aml_start = aml_buffer->buffer.pointer; + + /* + * Pass the aml_buffer into a module that can calculate + * the buffer size needed for the linked list + */ + status = acpi_rs_get_list_length(aml_start, aml_buffer_length, + &list_size_needed); + + ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Status=%X ListSizeNeeded=%X\n", + status, (u32) list_size_needed)); + if (ACPI_FAILURE(status)) { + return_ACPI_STATUS(status); + } + + /* Validate/Allocate/Clear caller buffer */ + + status = acpi_ut_initialize_buffer(output_buffer, list_size_needed); + if (ACPI_FAILURE(status)) { + return_ACPI_STATUS(status); + } + + /* Do the conversion */ + + resource = output_buffer->pointer; + status = acpi_ut_walk_aml_resources(aml_start, aml_buffer_length, + acpi_rs_convert_aml_to_resources, + &resource); + if (ACPI_FAILURE(status)) { + return_ACPI_STATUS(status); + } + + ACPI_DEBUG_PRINT((ACPI_DB_INFO, "OutputBuffer %p Length %X\n", + output_buffer->pointer, (u32) output_buffer->length)); + return_ACPI_STATUS(AE_OK); +} + +/******************************************************************************* + * + * FUNCTION: acpi_rs_create_pci_routing_table + * - * PARAMETERS: package_object - Pointer to an union acpi_operand_object ++ * PARAMETERS: package_object - Pointer to a union acpi_operand_object + * package + * output_buffer - Pointer to the user's buffer + * + * RETURN: Status AE_OK if okay, else a valid acpi_status code. + * If the output_buffer is too small, the error will be + * AE_BUFFER_OVERFLOW and output_buffer->Length will point + * to the size buffer needed. + * + * DESCRIPTION: Takes the union acpi_operand_object package and creates a + * linked list of PCI interrupt descriptions + * + * NOTE: It is the caller's responsibility to ensure that the start of the + * output buffer is aligned properly (if necessary). + * + ******************************************************************************/ + +acpi_status +acpi_rs_create_pci_routing_table(union acpi_operand_object *package_object, + struct acpi_buffer *output_buffer) +{ + u8 *buffer; + union acpi_operand_object **top_object_list; + union acpi_operand_object **sub_object_list; + union acpi_operand_object *obj_desc; + acpi_size buffer_size_needed = 0; + u32 number_of_elements; + u32 index; + struct acpi_pci_routing_table *user_prt; + struct acpi_namespace_node *node; + acpi_status status; + struct acpi_buffer path_buffer; + + ACPI_FUNCTION_TRACE(rs_create_pci_routing_table); + + /* Params already validated, so we don't re-validate here */ + + /* Get the required buffer length */ + + status = acpi_rs_get_pci_routing_table_length(package_object, + &buffer_size_needed); + if (ACPI_FAILURE(status)) { + return_ACPI_STATUS(status); + } + + ACPI_DEBUG_PRINT((ACPI_DB_INFO, "BufferSizeNeeded = %X\n", + (u32) buffer_size_needed)); + + /* Validate/Allocate/Clear caller buffer */ + + status = acpi_ut_initialize_buffer(output_buffer, buffer_size_needed); + if (ACPI_FAILURE(status)) { + return_ACPI_STATUS(status); + } + + /* + * Loop through the ACPI_INTERNAL_OBJECTS - Each object should be a + * package that in turn contains an acpi_integer Address, a u8 Pin, + * a Name, and a u8 source_index. + */ + top_object_list = package_object->package.elements; + number_of_elements = package_object->package.count; + buffer = output_buffer->pointer; + user_prt = ACPI_CAST_PTR(struct acpi_pci_routing_table, buffer); + + for (index = 0; index < number_of_elements; index++) { + int source_name_index = 2; + int source_index_index = 3; + + /* + * Point user_prt past this current structure + * + * NOTE: On the first iteration, user_prt->Length will + * be zero because we cleared the return buffer earlier + */ + buffer += user_prt->length; + user_prt = ACPI_CAST_PTR(struct acpi_pci_routing_table, buffer); + + /* + * Fill in the Length field with the information we have at this point. + * The minus four is to subtract the size of the u8 Source[4] member + * because it is added below. + */ + user_prt->length = (sizeof(struct acpi_pci_routing_table) - 4); + + /* Each element of the top-level package must also be a package */ + + if (ACPI_GET_OBJECT_TYPE(*top_object_list) != ACPI_TYPE_PACKAGE) { + ACPI_ERROR((AE_INFO, + "(PRT[%X]) Need sub-package, found %s", + index, + acpi_ut_get_object_type_name + (*top_object_list))); + return_ACPI_STATUS(AE_AML_OPERAND_TYPE); + } + + /* Each sub-package must be of length 4 */ + + if ((*top_object_list)->package.count != 4) { + ACPI_ERROR((AE_INFO, + "(PRT[%X]) Need package of length 4, found length %d", + index, (*top_object_list)->package.count)); + return_ACPI_STATUS(AE_AML_PACKAGE_LIMIT); + } + + /* + * Dereference the sub-package. + * The sub_object_list will now point to an array of the four IRQ + * elements: [Address, Pin, Source, source_index] + */ + sub_object_list = (*top_object_list)->package.elements; + + /* 1) First subobject: Dereference the PRT.Address */ + + obj_desc = sub_object_list[0]; + if (ACPI_GET_OBJECT_TYPE(obj_desc) != ACPI_TYPE_INTEGER) { + ACPI_ERROR((AE_INFO, + "(PRT[%X].Address) Need Integer, found %s", + index, + acpi_ut_get_object_type_name(obj_desc))); + return_ACPI_STATUS(AE_BAD_DATA); + } + + user_prt->address = obj_desc->integer.value; + + /* 2) Second subobject: Dereference the PRT.Pin */ + + obj_desc = sub_object_list[1]; + if (ACPI_GET_OBJECT_TYPE(obj_desc) != ACPI_TYPE_INTEGER) { + ACPI_ERROR((AE_INFO, + "(PRT[%X].Pin) Need Integer, found %s", + index, + acpi_ut_get_object_type_name(obj_desc))); + return_ACPI_STATUS(AE_BAD_DATA); + } + + /* + * If BIOS erroneously reversed the _PRT source_name and source_index, + * then reverse them back. + */ + if (ACPI_GET_OBJECT_TYPE(sub_object_list[3]) != + ACPI_TYPE_INTEGER) { + if (acpi_gbl_enable_interpreter_slack) { + source_name_index = 3; + source_index_index = 2; + printk(KERN_WARNING + "ACPI: Handling Garbled _PRT entry\n"); + } else { + ACPI_ERROR((AE_INFO, + "(PRT[%X].source_index) Need Integer, found %s", + index, + acpi_ut_get_object_type_name + (sub_object_list[3]))); + return_ACPI_STATUS(AE_BAD_DATA); + } + } + + user_prt->pin = (u32) obj_desc->integer.value; + + /* + * If the BIOS has erroneously reversed the _PRT source_name (index 2) + * and the source_index (index 3), fix it. _PRT is important enough to + * workaround this BIOS error. This also provides compatibility with + * other ACPI implementations. + */ + obj_desc = sub_object_list[3]; + if (!obj_desc + || (ACPI_GET_OBJECT_TYPE(obj_desc) != ACPI_TYPE_INTEGER)) { + sub_object_list[3] = sub_object_list[2]; + sub_object_list[2] = obj_desc; + + ACPI_WARNING((AE_INFO, + "(PRT[%X].Source) SourceName and SourceIndex are reversed, fixed", + index)); + } + + /* + * 3) Third subobject: Dereference the PRT.source_name + * The name may be unresolved (slack mode), so allow a null object + */ + obj_desc = sub_object_list[source_name_index]; + if (obj_desc) { + switch (ACPI_GET_OBJECT_TYPE(obj_desc)) { + case ACPI_TYPE_LOCAL_REFERENCE: + + if (obj_desc->reference.class != + ACPI_REFCLASS_NAME) { + ACPI_ERROR((AE_INFO, + "(PRT[%X].Source) Need name, found Reference Class %X", + index, + obj_desc->reference.class)); + return_ACPI_STATUS(AE_BAD_DATA); + } + + node = obj_desc->reference.node; + + /* Use *remaining* length of the buffer as max for pathname */ + + path_buffer.length = output_buffer->length - + (u32) ((u8 *) user_prt->source - + (u8 *) output_buffer->pointer); + path_buffer.pointer = user_prt->source; + + status = + acpi_ns_handle_to_pathname((acpi_handle) + node, + &path_buffer); + + /* +1 to include null terminator */ + + user_prt->length += + (u32) ACPI_STRLEN(user_prt->source) + 1; + break; + + case ACPI_TYPE_STRING: + + ACPI_STRCPY(user_prt->source, + obj_desc->string.pointer); + + /* + * Add to the Length field the length of the string + * (add 1 for terminator) + */ + user_prt->length += obj_desc->string.length + 1; + break; + + case ACPI_TYPE_INTEGER: + /* + * If this is a number, then the Source Name is NULL, since the + * entire buffer was zeroed out, we can leave this alone. + * + * Add to the Length field the length of the u32 NULL + */ + user_prt->length += sizeof(u32); + break; + + default: + + ACPI_ERROR((AE_INFO, + "(PRT[%X].Source) Need Ref/String/Integer, found %s", + index, + acpi_ut_get_object_type_name + (obj_desc))); + return_ACPI_STATUS(AE_BAD_DATA); + } + } + + /* Now align the current length */ + + user_prt->length = + (u32) ACPI_ROUND_UP_TO_64BIT(user_prt->length); + + /* 4) Fourth subobject: Dereference the PRT.source_index */ + + obj_desc = sub_object_list[source_index_index]; + if (ACPI_GET_OBJECT_TYPE(obj_desc) != ACPI_TYPE_INTEGER) { + ACPI_ERROR((AE_INFO, + "(PRT[%X].SourceIndex) Need Integer, found %s", + index, + acpi_ut_get_object_type_name(obj_desc))); + return_ACPI_STATUS(AE_BAD_DATA); + } + + user_prt->source_index = (u32) obj_desc->integer.value; + + /* Point to the next union acpi_operand_object in the top level package */ + + top_object_list++; + } + + ACPI_DEBUG_PRINT((ACPI_DB_INFO, "OutputBuffer %p Length %X\n", + output_buffer->pointer, (u32) output_buffer->length)); + return_ACPI_STATUS(AE_OK); +} + +/******************************************************************************* + * + * FUNCTION: acpi_rs_create_aml_resources + * + * PARAMETERS: linked_list_buffer - Pointer to the resource linked list + * output_buffer - Pointer to the user's buffer + * + * RETURN: Status AE_OK if okay, else a valid acpi_status code. + * If the output_buffer is too small, the error will be + * AE_BUFFER_OVERFLOW and output_buffer->Length will point + * to the size buffer needed. + * + * DESCRIPTION: Takes the linked list of device resources and + * creates a bytestream to be used as input for the + * _SRS control method. + * + ******************************************************************************/ + +acpi_status +acpi_rs_create_aml_resources(struct acpi_resource *linked_list_buffer, + struct acpi_buffer *output_buffer) +{ + acpi_status status; + acpi_size aml_size_needed = 0; + + ACPI_FUNCTION_TRACE(rs_create_aml_resources); + + ACPI_DEBUG_PRINT((ACPI_DB_INFO, "LinkedListBuffer = %p\n", + linked_list_buffer)); + + /* + * Params already validated, so we don't re-validate here + * + * Pass the linked_list_buffer into a module that calculates + * the buffer size needed for the byte stream. + */ + status = acpi_rs_get_aml_length(linked_list_buffer, &aml_size_needed); + + ACPI_DEBUG_PRINT((ACPI_DB_INFO, "AmlSizeNeeded=%X, %s\n", + (u32) aml_size_needed, + acpi_format_exception(status))); + if (ACPI_FAILURE(status)) { + return_ACPI_STATUS(status); + } + + /* Validate/Allocate/Clear caller buffer */ + + status = acpi_ut_initialize_buffer(output_buffer, aml_size_needed); + if (ACPI_FAILURE(status)) { + return_ACPI_STATUS(status); + } + + /* Do the conversion */ + + status = + acpi_rs_convert_resources_to_aml(linked_list_buffer, + aml_size_needed, + output_buffer->pointer); + if (ACPI_FAILURE(status)) { + return_ACPI_STATUS(status); + } + + ACPI_DEBUG_PRINT((ACPI_DB_INFO, "OutputBuffer %p Length %X\n", + output_buffer->pointer, (u32) output_buffer->length)); + return_ACPI_STATUS(AE_OK); +} diff --cc drivers/acpi/acpica/utobject.c index 4279ed3a8782,000000000000..fd5ea7543e5b mode 100644,000000..100644 --- a/drivers/acpi/acpica/utobject.c +++ b/drivers/acpi/acpica/utobject.c @@@ -1,677 -1,0 +1,677 @@@ +/****************************************************************************** + * + * Module Name: utobject - ACPI object create/delete/size/cache routines + * + *****************************************************************************/ + +/* + * Copyright (C) 2000 - 2008, Intel Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * 3. Neither the names of the above-listed copyright holders nor the names + * of any contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + */ + +#include +#include "accommon.h" +#include "acnamesp.h" + +#define _COMPONENT ACPI_UTILITIES +ACPI_MODULE_NAME("utobject") + +/* Local prototypes */ +static acpi_status +acpi_ut_get_simple_object_size(union acpi_operand_object *obj, + acpi_size * obj_length); + +static acpi_status +acpi_ut_get_package_object_size(union acpi_operand_object *obj, + acpi_size * obj_length); + +static acpi_status +acpi_ut_get_element_length(u8 object_type, + union acpi_operand_object *source_object, + union acpi_generic_state *state, void *context); + +/******************************************************************************* + * + * FUNCTION: acpi_ut_create_internal_object_dbg + * + * PARAMETERS: module_name - Source file name of caller + * line_number - Line number of caller + * component_id - Component type of caller + * Type - ACPI Type of the new object + * + * RETURN: A new internal object, null on failure + * + * DESCRIPTION: Create and initialize a new internal object. + * + * NOTE: We always allocate the worst-case object descriptor because + * these objects are cached, and we want them to be + * one-size-satisifies-any-request. This in itself may not be + * the most memory efficient, but the efficiency of the object + * cache should more than make up for this! + * + ******************************************************************************/ + +union acpi_operand_object *acpi_ut_create_internal_object_dbg(const char + *module_name, + u32 line_number, + u32 component_id, + acpi_object_type + type) +{ + union acpi_operand_object *object; + union acpi_operand_object *second_object; + + ACPI_FUNCTION_TRACE_STR(ut_create_internal_object_dbg, + acpi_ut_get_type_name(type)); + + /* Allocate the raw object descriptor */ + + object = + acpi_ut_allocate_object_desc_dbg(module_name, line_number, + component_id); + if (!object) { + return_PTR(NULL); + } + + switch (type) { + case ACPI_TYPE_REGION: + case ACPI_TYPE_BUFFER_FIELD: + case ACPI_TYPE_LOCAL_BANK_FIELD: + + /* These types require a secondary object */ + + second_object = acpi_ut_allocate_object_desc_dbg(module_name, + line_number, + component_id); + if (!second_object) { + acpi_ut_delete_object_desc(object); + return_PTR(NULL); + } + + second_object->common.type = ACPI_TYPE_LOCAL_EXTRA; + second_object->common.reference_count = 1; + + /* Link the second object to the first */ + + object->common.next_object = second_object; + break; + + default: + /* All others have no secondary object */ + break; + } + + /* Save the object type in the object descriptor */ + + object->common.type = (u8) type; + + /* Init the reference count */ + + object->common.reference_count = 1; + + /* Any per-type initialization should go here */ + + return_PTR(object); +} + +/******************************************************************************* + * + * FUNCTION: acpi_ut_create_package_object + * + * PARAMETERS: Count - Number of package elements + * + * RETURN: Pointer to a new Package object, null on failure + * + * DESCRIPTION: Create a fully initialized package object + * + ******************************************************************************/ + +union acpi_operand_object *acpi_ut_create_package_object(u32 count) +{ + union acpi_operand_object *package_desc; + union acpi_operand_object **package_elements; + + ACPI_FUNCTION_TRACE_U32(ut_create_package_object, count); + + /* Create a new Package object */ + + package_desc = acpi_ut_create_internal_object(ACPI_TYPE_PACKAGE); + if (!package_desc) { + return_PTR(NULL); + } + + /* + * Create the element array. Count+1 allows the array to be null + * terminated. + */ + package_elements = ACPI_ALLOCATE_ZEROED(((acpi_size) count + + 1) * sizeof(void *)); + if (!package_elements) { + acpi_ut_remove_reference(package_desc); + return_PTR(NULL); + } + + package_desc->package.count = count; + package_desc->package.elements = package_elements; + return_PTR(package_desc); +} + +/******************************************************************************* + * + * FUNCTION: acpi_ut_create_buffer_object + * + * PARAMETERS: buffer_size - Size of buffer to be created + * + * RETURN: Pointer to a new Buffer object, null on failure + * + * DESCRIPTION: Create a fully initialized buffer object + * + ******************************************************************************/ + +union acpi_operand_object *acpi_ut_create_buffer_object(acpi_size buffer_size) +{ + union acpi_operand_object *buffer_desc; + u8 *buffer = NULL; + + ACPI_FUNCTION_TRACE_U32(ut_create_buffer_object, buffer_size); + + /* Create a new Buffer object */ + + buffer_desc = acpi_ut_create_internal_object(ACPI_TYPE_BUFFER); + if (!buffer_desc) { + return_PTR(NULL); + } + + /* Create an actual buffer only if size > 0 */ + + if (buffer_size > 0) { + + /* Allocate the actual buffer */ + + buffer = ACPI_ALLOCATE_ZEROED(buffer_size); + if (!buffer) { + ACPI_ERROR((AE_INFO, "Could not allocate size %X", + (u32) buffer_size)); + acpi_ut_remove_reference(buffer_desc); + return_PTR(NULL); + } + } + + /* Complete buffer object initialization */ + + buffer_desc->buffer.flags |= AOPOBJ_DATA_VALID; + buffer_desc->buffer.pointer = buffer; + buffer_desc->buffer.length = (u32) buffer_size; + + /* Return the new buffer descriptor */ + + return_PTR(buffer_desc); +} + +/******************************************************************************* + * + * FUNCTION: acpi_ut_create_string_object + * + * PARAMETERS: string_size - Size of string to be created. Does not + * include NULL terminator, this is added + * automatically. + * + * RETURN: Pointer to a new String object + * + * DESCRIPTION: Create a fully initialized string object + * + ******************************************************************************/ + +union acpi_operand_object *acpi_ut_create_string_object(acpi_size string_size) +{ + union acpi_operand_object *string_desc; + char *string; + + ACPI_FUNCTION_TRACE_U32(ut_create_string_object, string_size); + + /* Create a new String object */ + + string_desc = acpi_ut_create_internal_object(ACPI_TYPE_STRING); + if (!string_desc) { + return_PTR(NULL); + } + + /* + * Allocate the actual string buffer -- (Size + 1) for NULL terminator. + * NOTE: Zero-length strings are NULL terminated + */ + string = ACPI_ALLOCATE_ZEROED(string_size + 1); + if (!string) { + ACPI_ERROR((AE_INFO, "Could not allocate size %X", + (u32) string_size)); + acpi_ut_remove_reference(string_desc); + return_PTR(NULL); + } + + /* Complete string object initialization */ + + string_desc->string.pointer = string; + string_desc->string.length = (u32) string_size; + + /* Return the new string descriptor */ + + return_PTR(string_desc); +} + +/******************************************************************************* + * + * FUNCTION: acpi_ut_valid_internal_object + * + * PARAMETERS: Object - Object to be validated + * + * RETURN: TRUE if object is valid, FALSE otherwise + * - * DESCRIPTION: Validate a pointer to be an union acpi_operand_object ++ * DESCRIPTION: Validate a pointer to be a union acpi_operand_object + * + ******************************************************************************/ + +u8 acpi_ut_valid_internal_object(void *object) +{ + + ACPI_FUNCTION_NAME(ut_valid_internal_object); + + /* Check for a null pointer */ + + if (!object) { + ACPI_DEBUG_PRINT((ACPI_DB_INFO, "**** Null Object Ptr\n")); + return (FALSE); + } + + /* Check the descriptor type field */ + + switch (ACPI_GET_DESCRIPTOR_TYPE(object)) { + case ACPI_DESC_TYPE_OPERAND: + + /* The object appears to be a valid union acpi_operand_object */ + + return (TRUE); + + default: + ACPI_DEBUG_PRINT((ACPI_DB_INFO, + "%p is not not an ACPI operand obj [%s]\n", + object, acpi_ut_get_descriptor_name(object))); + break; + } + + return (FALSE); +} + +/******************************************************************************* + * + * FUNCTION: acpi_ut_allocate_object_desc_dbg + * + * PARAMETERS: module_name - Caller's module name (for error output) + * line_number - Caller's line number (for error output) + * component_id - Caller's component ID (for error output) + * + * RETURN: Pointer to newly allocated object descriptor. Null on error + * + * DESCRIPTION: Allocate a new object descriptor. Gracefully handle + * error conditions. + * + ******************************************************************************/ + +void *acpi_ut_allocate_object_desc_dbg(const char *module_name, + u32 line_number, u32 component_id) +{ + union acpi_operand_object *object; + + ACPI_FUNCTION_TRACE(ut_allocate_object_desc_dbg); + + object = acpi_os_acquire_object(acpi_gbl_operand_cache); + if (!object) { + ACPI_ERROR((module_name, line_number, + "Could not allocate an object descriptor")); + + return_PTR(NULL); + } + + /* Mark the descriptor type */ + + memset(object, 0, sizeof(union acpi_operand_object)); + ACPI_SET_DESCRIPTOR_TYPE(object, ACPI_DESC_TYPE_OPERAND); + + ACPI_DEBUG_PRINT((ACPI_DB_ALLOCATIONS, "%p Size %X\n", + object, (u32) sizeof(union acpi_operand_object))); + + return_PTR(object); +} + +/******************************************************************************* + * + * FUNCTION: acpi_ut_delete_object_desc + * + * PARAMETERS: Object - An Acpi internal object to be deleted + * + * RETURN: None. + * + * DESCRIPTION: Free an ACPI object descriptor or add it to the object cache + * + ******************************************************************************/ + +void acpi_ut_delete_object_desc(union acpi_operand_object *object) +{ + ACPI_FUNCTION_TRACE_PTR(ut_delete_object_desc, object); + - /* Object must be an union acpi_operand_object */ ++ /* Object must be a union acpi_operand_object */ + + if (ACPI_GET_DESCRIPTOR_TYPE(object) != ACPI_DESC_TYPE_OPERAND) { + ACPI_ERROR((AE_INFO, + "%p is not an ACPI Operand object [%s]", object, + acpi_ut_get_descriptor_name(object))); + return_VOID; + } + + (void)acpi_os_release_object(acpi_gbl_operand_cache, object); + return_VOID; +} + +/******************************************************************************* + * + * FUNCTION: acpi_ut_get_simple_object_size + * + * PARAMETERS: internal_object - An ACPI operand object + * obj_length - Where the length is returned + * + * RETURN: Status + * + * DESCRIPTION: This function is called to determine the space required to + * contain a simple object for return to an external user. + * + * The length includes the object structure plus any additional + * needed space. + * + ******************************************************************************/ + +static acpi_status +acpi_ut_get_simple_object_size(union acpi_operand_object *internal_object, + acpi_size * obj_length) +{ + acpi_size length; + acpi_size size; + acpi_status status = AE_OK; + + ACPI_FUNCTION_TRACE_PTR(ut_get_simple_object_size, internal_object); + + /* + * Handle a null object (Could be a uninitialized package + * element -- which is legal) + */ + if (!internal_object) { + *obj_length = sizeof(union acpi_object); + return_ACPI_STATUS(AE_OK); + } + + /* Start with the length of the Acpi object */ + + length = sizeof(union acpi_object); + + if (ACPI_GET_DESCRIPTOR_TYPE(internal_object) == ACPI_DESC_TYPE_NAMED) { + + /* Object is a named object (reference), just return the length */ + + *obj_length = ACPI_ROUND_UP_TO_NATIVE_WORD(length); + return_ACPI_STATUS(status); + } + + /* + * The final length depends on the object type + * Strings and Buffers are packed right up against the parent object and + * must be accessed bytewise or there may be alignment problems on + * certain processors + */ + switch (ACPI_GET_OBJECT_TYPE(internal_object)) { + case ACPI_TYPE_STRING: + + length += (acpi_size) internal_object->string.length + 1; + break; + + case ACPI_TYPE_BUFFER: + + length += (acpi_size) internal_object->buffer.length; + break; + + case ACPI_TYPE_INTEGER: + case ACPI_TYPE_PROCESSOR: + case ACPI_TYPE_POWER: + + /* No extra data for these types */ + + break; + + case ACPI_TYPE_LOCAL_REFERENCE: + + switch (internal_object->reference.class) { + case ACPI_REFCLASS_NAME: + + /* + * Get the actual length of the full pathname to this object. + * The reference will be converted to the pathname to the object + */ + size = + acpi_ns_get_pathname_length(internal_object-> + reference.node); + if (!size) { + return_ACPI_STATUS(AE_BAD_PARAMETER); + } + + length += ACPI_ROUND_UP_TO_NATIVE_WORD(size); + break; + + default: + + /* + * No other reference opcodes are supported. + * Notably, Locals and Args are not supported, but this may be + * required eventually. + */ + ACPI_ERROR((AE_INFO, + "Cannot convert to external object - " + "unsupported Reference Class [%s] %X in object %p", + acpi_ut_get_reference_name(internal_object), + internal_object->reference.class, + internal_object)); + status = AE_TYPE; + break; + } + break; + + default: + + ACPI_ERROR((AE_INFO, "Cannot convert to external object - " + "unsupported type [%s] %X in object %p", + acpi_ut_get_object_type_name(internal_object), + ACPI_GET_OBJECT_TYPE(internal_object), + internal_object)); + status = AE_TYPE; + break; + } + + /* + * Account for the space required by the object rounded up to the next + * multiple of the machine word size. This keeps each object aligned + * on a machine word boundary. (preventing alignment faults on some + * machines.) + */ + *obj_length = ACPI_ROUND_UP_TO_NATIVE_WORD(length); + return_ACPI_STATUS(status); +} + +/******************************************************************************* + * + * FUNCTION: acpi_ut_get_element_length + * + * PARAMETERS: acpi_pkg_callback + * + * RETURN: Status + * + * DESCRIPTION: Get the length of one package element. + * + ******************************************************************************/ + +static acpi_status +acpi_ut_get_element_length(u8 object_type, + union acpi_operand_object *source_object, + union acpi_generic_state *state, void *context) +{ + acpi_status status = AE_OK; + struct acpi_pkg_info *info = (struct acpi_pkg_info *)context; + acpi_size object_space; + + switch (object_type) { + case ACPI_COPY_TYPE_SIMPLE: + + /* + * Simple object - just get the size (Null object/entry is handled + * here also) and sum it into the running package length + */ + status = + acpi_ut_get_simple_object_size(source_object, + &object_space); + if (ACPI_FAILURE(status)) { + return (status); + } + + info->length += object_space; + break; + + case ACPI_COPY_TYPE_PACKAGE: + + /* Package object - nothing much to do here, let the walk handle it */ + + info->num_packages++; + state->pkg.this_target_obj = NULL; + break; + + default: + + /* No other types allowed */ + + return (AE_BAD_PARAMETER); + } + + return (status); +} + +/******************************************************************************* + * + * FUNCTION: acpi_ut_get_package_object_size + * + * PARAMETERS: internal_object - An ACPI internal object + * obj_length - Where the length is returned + * + * RETURN: Status + * + * DESCRIPTION: This function is called to determine the space required to + * contain a package object for return to an external user. + * + * This is moderately complex since a package contains other + * objects including packages. + * + ******************************************************************************/ + +static acpi_status +acpi_ut_get_package_object_size(union acpi_operand_object *internal_object, + acpi_size * obj_length) +{ + acpi_status status; + struct acpi_pkg_info info; + + ACPI_FUNCTION_TRACE_PTR(ut_get_package_object_size, internal_object); + + info.length = 0; + info.object_space = 0; + info.num_packages = 1; + + status = acpi_ut_walk_package_tree(internal_object, NULL, + acpi_ut_get_element_length, &info); + if (ACPI_FAILURE(status)) { + return_ACPI_STATUS(status); + } + + /* + * We have handled all of the objects in all levels of the package. + * just add the length of the package objects themselves. + * Round up to the next machine word. + */ + info.length += ACPI_ROUND_UP_TO_NATIVE_WORD(sizeof(union acpi_object)) * + (acpi_size) info.num_packages; + + /* Return the total package length */ + + *obj_length = info.length; + return_ACPI_STATUS(status); +} + +/******************************************************************************* + * + * FUNCTION: acpi_ut_get_object_size + * + * PARAMETERS: internal_object - An ACPI internal object + * obj_length - Where the length will be returned + * + * RETURN: Status + * + * DESCRIPTION: This function is called to determine the space required to + * contain an object for return to an API user. + * + ******************************************************************************/ + +acpi_status +acpi_ut_get_object_size(union acpi_operand_object *internal_object, + acpi_size * obj_length) +{ + acpi_status status; + + ACPI_FUNCTION_ENTRY(); + + if ((ACPI_GET_DESCRIPTOR_TYPE(internal_object) == + ACPI_DESC_TYPE_OPERAND) + && (ACPI_GET_OBJECT_TYPE(internal_object) == ACPI_TYPE_PACKAGE)) { + status = + acpi_ut_get_package_object_size(internal_object, + obj_length); + } else { + status = + acpi_ut_get_simple_object_size(internal_object, obj_length); + } + + return (status); +} diff --cc drivers/pci/hotplug/pciehp.h index 7072952ea1d2,27fd18f019f8..db85284ffb62 --- a/drivers/pci/hotplug/pciehp.h +++ b/drivers/pci/hotplug/pciehp.h @@@ -217,13 -217,26 +217,25 @@@ struct hpc_ops #ifdef CONFIG_ACPI #include #include -#include #include + extern void __init pciehp_acpi_slot_detection_init(void); + extern int pciehp_acpi_slot_detection_check(struct pci_dev *dev); + + static inline void pciehp_firmware_init(void) + { + pciehp_acpi_slot_detection_init(); + } + static inline int pciehp_get_hp_hw_control_from_firmware(struct pci_dev *dev) { + int retval; u32 flags = (OSC_PCI_EXPRESS_NATIVE_HP_CONTROL | OSC_PCI_EXPRESS_CAP_STRUCTURE_CONTROL); - return acpi_get_hp_hw_control_from_firmware(dev, flags); + retval = acpi_get_hp_hw_control_from_firmware(dev, flags); + if (retval) + return retval; + return pciehp_acpi_slot_detection_check(dev); } static inline int pciehp_get_hp_params_from_firmware(struct pci_dev *dev, diff --cc kernel/power/disk.c index 096fe4899ea4,f77d3819ef57..45e8541ab7e3 --- a/kernel/power/disk.c +++ b/kernel/power/disk.c @@@ -257,9 -256,10 +256,9 @@@ static int create_image(int platform_mo int hibernation_snapshot(int platform_mode) { - int error, ftrace_save; + int error; - /* Free memory before shutting down devices. */ - error = swsusp_shrink_memory(); + error = platform_begin(platform_mode); if (error) return error;