176a6225bf0b64572251a8c27d33e84afac6af713Bob Moore/****************************************************************************** 276a6225bf0b64572251a8c27d33e84afac6af713Bob Moore * 376a6225bf0b64572251a8c27d33e84afac6af713Bob Moore * Module Name: nsconvert - Object conversions for objects returned by 476a6225bf0b64572251a8c27d33e84afac6af713Bob Moore * predefined methods 576a6225bf0b64572251a8c27d33e84afac6af713Bob Moore * 676a6225bf0b64572251a8c27d33e84afac6af713Bob Moore *****************************************************************************/ 776a6225bf0b64572251a8c27d33e84afac6af713Bob Moore 876a6225bf0b64572251a8c27d33e84afac6af713Bob Moore/* 9fbb7a2dc2be493c87399550bdc2ddaa510cdf450Bob Moore * Copyright (C) 2000 - 2014, Intel Corp. 1076a6225bf0b64572251a8c27d33e84afac6af713Bob Moore * All rights reserved. 1176a6225bf0b64572251a8c27d33e84afac6af713Bob Moore * 1276a6225bf0b64572251a8c27d33e84afac6af713Bob Moore * Redistribution and use in source and binary forms, with or without 1376a6225bf0b64572251a8c27d33e84afac6af713Bob Moore * modification, are permitted provided that the following conditions 1476a6225bf0b64572251a8c27d33e84afac6af713Bob Moore * are met: 1576a6225bf0b64572251a8c27d33e84afac6af713Bob Moore * 1. Redistributions of source code must retain the above copyright 1676a6225bf0b64572251a8c27d33e84afac6af713Bob Moore * notice, this list of conditions, and the following disclaimer, 1776a6225bf0b64572251a8c27d33e84afac6af713Bob Moore * without modification. 1876a6225bf0b64572251a8c27d33e84afac6af713Bob Moore * 2. Redistributions in binary form must reproduce at minimum a disclaimer 1976a6225bf0b64572251a8c27d33e84afac6af713Bob Moore * substantially similar to the "NO WARRANTY" disclaimer below 2076a6225bf0b64572251a8c27d33e84afac6af713Bob Moore * ("Disclaimer") and any redistribution must be conditioned upon 2176a6225bf0b64572251a8c27d33e84afac6af713Bob Moore * including a substantially similar Disclaimer requirement for further 2276a6225bf0b64572251a8c27d33e84afac6af713Bob Moore * binary redistribution. 2376a6225bf0b64572251a8c27d33e84afac6af713Bob Moore * 3. Neither the names of the above-listed copyright holders nor the names 2476a6225bf0b64572251a8c27d33e84afac6af713Bob Moore * of any contributors may be used to endorse or promote products derived 2576a6225bf0b64572251a8c27d33e84afac6af713Bob Moore * from this software without specific prior written permission. 2676a6225bf0b64572251a8c27d33e84afac6af713Bob Moore * 2776a6225bf0b64572251a8c27d33e84afac6af713Bob Moore * Alternatively, this software may be distributed under the terms of the 2876a6225bf0b64572251a8c27d33e84afac6af713Bob Moore * GNU General Public License ("GPL") version 2 as published by the Free 2976a6225bf0b64572251a8c27d33e84afac6af713Bob Moore * Software Foundation. 3076a6225bf0b64572251a8c27d33e84afac6af713Bob Moore * 3176a6225bf0b64572251a8c27d33e84afac6af713Bob Moore * NO WARRANTY 3276a6225bf0b64572251a8c27d33e84afac6af713Bob Moore * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 3376a6225bf0b64572251a8c27d33e84afac6af713Bob Moore * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 3476a6225bf0b64572251a8c27d33e84afac6af713Bob Moore * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 3576a6225bf0b64572251a8c27d33e84afac6af713Bob Moore * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 3676a6225bf0b64572251a8c27d33e84afac6af713Bob Moore * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 3776a6225bf0b64572251a8c27d33e84afac6af713Bob Moore * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 3876a6225bf0b64572251a8c27d33e84afac6af713Bob Moore * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 3976a6225bf0b64572251a8c27d33e84afac6af713Bob Moore * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 4076a6225bf0b64572251a8c27d33e84afac6af713Bob Moore * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 4176a6225bf0b64572251a8c27d33e84afac6af713Bob Moore * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 4276a6225bf0b64572251a8c27d33e84afac6af713Bob Moore * POSSIBILITY OF SUCH DAMAGES. 4376a6225bf0b64572251a8c27d33e84afac6af713Bob Moore */ 4476a6225bf0b64572251a8c27d33e84afac6af713Bob Moore 4576a6225bf0b64572251a8c27d33e84afac6af713Bob Moore#include <acpi/acpi.h> 4676a6225bf0b64572251a8c27d33e84afac6af713Bob Moore#include "accommon.h" 4776a6225bf0b64572251a8c27d33e84afac6af713Bob Moore#include "acnamesp.h" 4876a6225bf0b64572251a8c27d33e84afac6af713Bob Moore#include "acinterp.h" 4976a6225bf0b64572251a8c27d33e84afac6af713Bob Moore#include "acpredef.h" 5076a6225bf0b64572251a8c27d33e84afac6af713Bob Moore#include "amlresrc.h" 5176a6225bf0b64572251a8c27d33e84afac6af713Bob Moore 5276a6225bf0b64572251a8c27d33e84afac6af713Bob Moore#define _COMPONENT ACPI_NAMESPACE 5376a6225bf0b64572251a8c27d33e84afac6af713Bob MooreACPI_MODULE_NAME("nsconvert") 5476a6225bf0b64572251a8c27d33e84afac6af713Bob Moore 5576a6225bf0b64572251a8c27d33e84afac6af713Bob Moore/******************************************************************************* 5676a6225bf0b64572251a8c27d33e84afac6af713Bob Moore * 5776a6225bf0b64572251a8c27d33e84afac6af713Bob Moore * FUNCTION: acpi_ns_convert_to_integer 5876a6225bf0b64572251a8c27d33e84afac6af713Bob Moore * 5976a6225bf0b64572251a8c27d33e84afac6af713Bob Moore * PARAMETERS: original_object - Object to be converted 6076a6225bf0b64572251a8c27d33e84afac6af713Bob Moore * return_object - Where the new converted object is returned 6176a6225bf0b64572251a8c27d33e84afac6af713Bob Moore * 6276a6225bf0b64572251a8c27d33e84afac6af713Bob Moore * RETURN: Status. AE_OK if conversion was successful. 6376a6225bf0b64572251a8c27d33e84afac6af713Bob Moore * 6476a6225bf0b64572251a8c27d33e84afac6af713Bob Moore * DESCRIPTION: Attempt to convert a String/Buffer object to an Integer. 6576a6225bf0b64572251a8c27d33e84afac6af713Bob Moore * 6676a6225bf0b64572251a8c27d33e84afac6af713Bob Moore ******************************************************************************/ 6776a6225bf0b64572251a8c27d33e84afac6af713Bob Mooreacpi_status 6876a6225bf0b64572251a8c27d33e84afac6af713Bob Mooreacpi_ns_convert_to_integer(union acpi_operand_object *original_object, 6976a6225bf0b64572251a8c27d33e84afac6af713Bob Moore union acpi_operand_object **return_object) 7076a6225bf0b64572251a8c27d33e84afac6af713Bob Moore{ 7176a6225bf0b64572251a8c27d33e84afac6af713Bob Moore union acpi_operand_object *new_object; 7276a6225bf0b64572251a8c27d33e84afac6af713Bob Moore acpi_status status; 7376a6225bf0b64572251a8c27d33e84afac6af713Bob Moore u64 value = 0; 7476a6225bf0b64572251a8c27d33e84afac6af713Bob Moore u32 i; 7576a6225bf0b64572251a8c27d33e84afac6af713Bob Moore 7676a6225bf0b64572251a8c27d33e84afac6af713Bob Moore switch (original_object->common.type) { 7776a6225bf0b64572251a8c27d33e84afac6af713Bob Moore case ACPI_TYPE_STRING: 7876a6225bf0b64572251a8c27d33e84afac6af713Bob Moore 7976a6225bf0b64572251a8c27d33e84afac6af713Bob Moore /* String-to-Integer conversion */ 8076a6225bf0b64572251a8c27d33e84afac6af713Bob Moore 8176a6225bf0b64572251a8c27d33e84afac6af713Bob Moore status = acpi_ut_strtoul64(original_object->string.pointer, 8276a6225bf0b64572251a8c27d33e84afac6af713Bob Moore ACPI_ANY_BASE, &value); 8376a6225bf0b64572251a8c27d33e84afac6af713Bob Moore if (ACPI_FAILURE(status)) { 8476a6225bf0b64572251a8c27d33e84afac6af713Bob Moore return (status); 8576a6225bf0b64572251a8c27d33e84afac6af713Bob Moore } 8676a6225bf0b64572251a8c27d33e84afac6af713Bob Moore break; 8776a6225bf0b64572251a8c27d33e84afac6af713Bob Moore 8876a6225bf0b64572251a8c27d33e84afac6af713Bob Moore case ACPI_TYPE_BUFFER: 8976a6225bf0b64572251a8c27d33e84afac6af713Bob Moore 9076a6225bf0b64572251a8c27d33e84afac6af713Bob Moore /* Buffer-to-Integer conversion. Max buffer size is 64 bits. */ 9176a6225bf0b64572251a8c27d33e84afac6af713Bob Moore 9276a6225bf0b64572251a8c27d33e84afac6af713Bob Moore if (original_object->buffer.length > 8) { 9376a6225bf0b64572251a8c27d33e84afac6af713Bob Moore return (AE_AML_OPERAND_TYPE); 9476a6225bf0b64572251a8c27d33e84afac6af713Bob Moore } 9576a6225bf0b64572251a8c27d33e84afac6af713Bob Moore 9676a6225bf0b64572251a8c27d33e84afac6af713Bob Moore /* Extract each buffer byte to create the integer */ 9776a6225bf0b64572251a8c27d33e84afac6af713Bob Moore 9876a6225bf0b64572251a8c27d33e84afac6af713Bob Moore for (i = 0; i < original_object->buffer.length; i++) { 9976a6225bf0b64572251a8c27d33e84afac6af713Bob Moore value |= 10076a6225bf0b64572251a8c27d33e84afac6af713Bob Moore ((u64)original_object->buffer. 10176a6225bf0b64572251a8c27d33e84afac6af713Bob Moore pointer[i] << (i * 8)); 10276a6225bf0b64572251a8c27d33e84afac6af713Bob Moore } 10376a6225bf0b64572251a8c27d33e84afac6af713Bob Moore break; 10476a6225bf0b64572251a8c27d33e84afac6af713Bob Moore 10576a6225bf0b64572251a8c27d33e84afac6af713Bob Moore default: 1061d1ea1b723d9f239f736b8cf284327cbbf9d15d1Chao Guan 10776a6225bf0b64572251a8c27d33e84afac6af713Bob Moore return (AE_AML_OPERAND_TYPE); 10876a6225bf0b64572251a8c27d33e84afac6af713Bob Moore } 10976a6225bf0b64572251a8c27d33e84afac6af713Bob Moore 11076a6225bf0b64572251a8c27d33e84afac6af713Bob Moore new_object = acpi_ut_create_integer_object(value); 11176a6225bf0b64572251a8c27d33e84afac6af713Bob Moore if (!new_object) { 11276a6225bf0b64572251a8c27d33e84afac6af713Bob Moore return (AE_NO_MEMORY); 11376a6225bf0b64572251a8c27d33e84afac6af713Bob Moore } 11476a6225bf0b64572251a8c27d33e84afac6af713Bob Moore 11576a6225bf0b64572251a8c27d33e84afac6af713Bob Moore *return_object = new_object; 11676a6225bf0b64572251a8c27d33e84afac6af713Bob Moore return (AE_OK); 11776a6225bf0b64572251a8c27d33e84afac6af713Bob Moore} 11876a6225bf0b64572251a8c27d33e84afac6af713Bob Moore 11976a6225bf0b64572251a8c27d33e84afac6af713Bob Moore/******************************************************************************* 12076a6225bf0b64572251a8c27d33e84afac6af713Bob Moore * 12176a6225bf0b64572251a8c27d33e84afac6af713Bob Moore * FUNCTION: acpi_ns_convert_to_string 12276a6225bf0b64572251a8c27d33e84afac6af713Bob Moore * 12376a6225bf0b64572251a8c27d33e84afac6af713Bob Moore * PARAMETERS: original_object - Object to be converted 12476a6225bf0b64572251a8c27d33e84afac6af713Bob Moore * return_object - Where the new converted object is returned 12576a6225bf0b64572251a8c27d33e84afac6af713Bob Moore * 12676a6225bf0b64572251a8c27d33e84afac6af713Bob Moore * RETURN: Status. AE_OK if conversion was successful. 12776a6225bf0b64572251a8c27d33e84afac6af713Bob Moore * 12876a6225bf0b64572251a8c27d33e84afac6af713Bob Moore * DESCRIPTION: Attempt to convert a Integer/Buffer object to a String. 12976a6225bf0b64572251a8c27d33e84afac6af713Bob Moore * 13076a6225bf0b64572251a8c27d33e84afac6af713Bob Moore ******************************************************************************/ 13176a6225bf0b64572251a8c27d33e84afac6af713Bob Moore 13276a6225bf0b64572251a8c27d33e84afac6af713Bob Mooreacpi_status 13376a6225bf0b64572251a8c27d33e84afac6af713Bob Mooreacpi_ns_convert_to_string(union acpi_operand_object *original_object, 13476a6225bf0b64572251a8c27d33e84afac6af713Bob Moore union acpi_operand_object **return_object) 13576a6225bf0b64572251a8c27d33e84afac6af713Bob Moore{ 13676a6225bf0b64572251a8c27d33e84afac6af713Bob Moore union acpi_operand_object *new_object; 13776a6225bf0b64572251a8c27d33e84afac6af713Bob Moore acpi_size length; 13876a6225bf0b64572251a8c27d33e84afac6af713Bob Moore acpi_status status; 13976a6225bf0b64572251a8c27d33e84afac6af713Bob Moore 14076a6225bf0b64572251a8c27d33e84afac6af713Bob Moore switch (original_object->common.type) { 14176a6225bf0b64572251a8c27d33e84afac6af713Bob Moore case ACPI_TYPE_INTEGER: 14276a6225bf0b64572251a8c27d33e84afac6af713Bob Moore /* 14376a6225bf0b64572251a8c27d33e84afac6af713Bob Moore * Integer-to-String conversion. Commonly, convert 14476a6225bf0b64572251a8c27d33e84afac6af713Bob Moore * an integer of value 0 to a NULL string. The last element of 14576a6225bf0b64572251a8c27d33e84afac6af713Bob Moore * _BIF and _BIX packages occasionally need this fix. 14676a6225bf0b64572251a8c27d33e84afac6af713Bob Moore */ 14776a6225bf0b64572251a8c27d33e84afac6af713Bob Moore if (original_object->integer.value == 0) { 14876a6225bf0b64572251a8c27d33e84afac6af713Bob Moore 14976a6225bf0b64572251a8c27d33e84afac6af713Bob Moore /* Allocate a new NULL string object */ 15076a6225bf0b64572251a8c27d33e84afac6af713Bob Moore 15176a6225bf0b64572251a8c27d33e84afac6af713Bob Moore new_object = acpi_ut_create_string_object(0); 15276a6225bf0b64572251a8c27d33e84afac6af713Bob Moore if (!new_object) { 15376a6225bf0b64572251a8c27d33e84afac6af713Bob Moore return (AE_NO_MEMORY); 15476a6225bf0b64572251a8c27d33e84afac6af713Bob Moore } 15576a6225bf0b64572251a8c27d33e84afac6af713Bob Moore } else { 15676a6225bf0b64572251a8c27d33e84afac6af713Bob Moore status = 15776a6225bf0b64572251a8c27d33e84afac6af713Bob Moore acpi_ex_convert_to_string(original_object, 15876a6225bf0b64572251a8c27d33e84afac6af713Bob Moore &new_object, 15976a6225bf0b64572251a8c27d33e84afac6af713Bob Moore ACPI_IMPLICIT_CONVERT_HEX); 16076a6225bf0b64572251a8c27d33e84afac6af713Bob Moore if (ACPI_FAILURE(status)) { 16176a6225bf0b64572251a8c27d33e84afac6af713Bob Moore return (status); 16276a6225bf0b64572251a8c27d33e84afac6af713Bob Moore } 16376a6225bf0b64572251a8c27d33e84afac6af713Bob Moore } 16476a6225bf0b64572251a8c27d33e84afac6af713Bob Moore break; 16576a6225bf0b64572251a8c27d33e84afac6af713Bob Moore 16676a6225bf0b64572251a8c27d33e84afac6af713Bob Moore case ACPI_TYPE_BUFFER: 16776a6225bf0b64572251a8c27d33e84afac6af713Bob Moore /* 16876a6225bf0b64572251a8c27d33e84afac6af713Bob Moore * Buffer-to-String conversion. Use a to_string 16976a6225bf0b64572251a8c27d33e84afac6af713Bob Moore * conversion, no transform performed on the buffer data. The best 17076a6225bf0b64572251a8c27d33e84afac6af713Bob Moore * example of this is the _BIF method, where the string data from 17176a6225bf0b64572251a8c27d33e84afac6af713Bob Moore * the battery is often (incorrectly) returned as buffer object(s). 17276a6225bf0b64572251a8c27d33e84afac6af713Bob Moore */ 17376a6225bf0b64572251a8c27d33e84afac6af713Bob Moore length = 0; 17476a6225bf0b64572251a8c27d33e84afac6af713Bob Moore while ((length < original_object->buffer.length) && 17576a6225bf0b64572251a8c27d33e84afac6af713Bob Moore (original_object->buffer.pointer[length])) { 17676a6225bf0b64572251a8c27d33e84afac6af713Bob Moore length++; 17776a6225bf0b64572251a8c27d33e84afac6af713Bob Moore } 17876a6225bf0b64572251a8c27d33e84afac6af713Bob Moore 17976a6225bf0b64572251a8c27d33e84afac6af713Bob Moore /* Allocate a new string object */ 18076a6225bf0b64572251a8c27d33e84afac6af713Bob Moore 18176a6225bf0b64572251a8c27d33e84afac6af713Bob Moore new_object = acpi_ut_create_string_object(length); 18276a6225bf0b64572251a8c27d33e84afac6af713Bob Moore if (!new_object) { 18376a6225bf0b64572251a8c27d33e84afac6af713Bob Moore return (AE_NO_MEMORY); 18476a6225bf0b64572251a8c27d33e84afac6af713Bob Moore } 18576a6225bf0b64572251a8c27d33e84afac6af713Bob Moore 18676a6225bf0b64572251a8c27d33e84afac6af713Bob Moore /* 18776a6225bf0b64572251a8c27d33e84afac6af713Bob Moore * Copy the raw buffer data with no transform. String is already NULL 18876a6225bf0b64572251a8c27d33e84afac6af713Bob Moore * terminated at Length+1. 18976a6225bf0b64572251a8c27d33e84afac6af713Bob Moore */ 19076a6225bf0b64572251a8c27d33e84afac6af713Bob Moore ACPI_MEMCPY(new_object->string.pointer, 19176a6225bf0b64572251a8c27d33e84afac6af713Bob Moore original_object->buffer.pointer, length); 19276a6225bf0b64572251a8c27d33e84afac6af713Bob Moore break; 19376a6225bf0b64572251a8c27d33e84afac6af713Bob Moore 19476a6225bf0b64572251a8c27d33e84afac6af713Bob Moore default: 1951d1ea1b723d9f239f736b8cf284327cbbf9d15d1Chao Guan 19676a6225bf0b64572251a8c27d33e84afac6af713Bob Moore return (AE_AML_OPERAND_TYPE); 19776a6225bf0b64572251a8c27d33e84afac6af713Bob Moore } 19876a6225bf0b64572251a8c27d33e84afac6af713Bob Moore 19976a6225bf0b64572251a8c27d33e84afac6af713Bob Moore *return_object = new_object; 20076a6225bf0b64572251a8c27d33e84afac6af713Bob Moore return (AE_OK); 20176a6225bf0b64572251a8c27d33e84afac6af713Bob Moore} 20276a6225bf0b64572251a8c27d33e84afac6af713Bob Moore 20376a6225bf0b64572251a8c27d33e84afac6af713Bob Moore/******************************************************************************* 20476a6225bf0b64572251a8c27d33e84afac6af713Bob Moore * 20576a6225bf0b64572251a8c27d33e84afac6af713Bob Moore * FUNCTION: acpi_ns_convert_to_buffer 20676a6225bf0b64572251a8c27d33e84afac6af713Bob Moore * 20776a6225bf0b64572251a8c27d33e84afac6af713Bob Moore * PARAMETERS: original_object - Object to be converted 20876a6225bf0b64572251a8c27d33e84afac6af713Bob Moore * return_object - Where the new converted object is returned 20976a6225bf0b64572251a8c27d33e84afac6af713Bob Moore * 21076a6225bf0b64572251a8c27d33e84afac6af713Bob Moore * RETURN: Status. AE_OK if conversion was successful. 21176a6225bf0b64572251a8c27d33e84afac6af713Bob Moore * 21276a6225bf0b64572251a8c27d33e84afac6af713Bob Moore * DESCRIPTION: Attempt to convert a Integer/String/Package object to a Buffer. 21376a6225bf0b64572251a8c27d33e84afac6af713Bob Moore * 21476a6225bf0b64572251a8c27d33e84afac6af713Bob Moore ******************************************************************************/ 21576a6225bf0b64572251a8c27d33e84afac6af713Bob Moore 21676a6225bf0b64572251a8c27d33e84afac6af713Bob Mooreacpi_status 21776a6225bf0b64572251a8c27d33e84afac6af713Bob Mooreacpi_ns_convert_to_buffer(union acpi_operand_object *original_object, 21876a6225bf0b64572251a8c27d33e84afac6af713Bob Moore union acpi_operand_object **return_object) 21976a6225bf0b64572251a8c27d33e84afac6af713Bob Moore{ 22076a6225bf0b64572251a8c27d33e84afac6af713Bob Moore union acpi_operand_object *new_object; 22176a6225bf0b64572251a8c27d33e84afac6af713Bob Moore acpi_status status; 22276a6225bf0b64572251a8c27d33e84afac6af713Bob Moore union acpi_operand_object **elements; 22376a6225bf0b64572251a8c27d33e84afac6af713Bob Moore u32 *dword_buffer; 22476a6225bf0b64572251a8c27d33e84afac6af713Bob Moore u32 count; 22576a6225bf0b64572251a8c27d33e84afac6af713Bob Moore u32 i; 22676a6225bf0b64572251a8c27d33e84afac6af713Bob Moore 22776a6225bf0b64572251a8c27d33e84afac6af713Bob Moore switch (original_object->common.type) { 22876a6225bf0b64572251a8c27d33e84afac6af713Bob Moore case ACPI_TYPE_INTEGER: 22976a6225bf0b64572251a8c27d33e84afac6af713Bob Moore /* 23076a6225bf0b64572251a8c27d33e84afac6af713Bob Moore * Integer-to-Buffer conversion. 23176a6225bf0b64572251a8c27d33e84afac6af713Bob Moore * Convert the Integer to a packed-byte buffer. _MAT and other 23276a6225bf0b64572251a8c27d33e84afac6af713Bob Moore * objects need this sometimes, if a read has been performed on a 23376a6225bf0b64572251a8c27d33e84afac6af713Bob Moore * Field object that is less than or equal to the global integer 23476a6225bf0b64572251a8c27d33e84afac6af713Bob Moore * size (32 or 64 bits). 23576a6225bf0b64572251a8c27d33e84afac6af713Bob Moore */ 23676a6225bf0b64572251a8c27d33e84afac6af713Bob Moore status = 23776a6225bf0b64572251a8c27d33e84afac6af713Bob Moore acpi_ex_convert_to_buffer(original_object, &new_object); 23876a6225bf0b64572251a8c27d33e84afac6af713Bob Moore if (ACPI_FAILURE(status)) { 23976a6225bf0b64572251a8c27d33e84afac6af713Bob Moore return (status); 24076a6225bf0b64572251a8c27d33e84afac6af713Bob Moore } 24176a6225bf0b64572251a8c27d33e84afac6af713Bob Moore break; 24276a6225bf0b64572251a8c27d33e84afac6af713Bob Moore 24376a6225bf0b64572251a8c27d33e84afac6af713Bob Moore case ACPI_TYPE_STRING: 24476a6225bf0b64572251a8c27d33e84afac6af713Bob Moore 24576a6225bf0b64572251a8c27d33e84afac6af713Bob Moore /* String-to-Buffer conversion. Simple data copy */ 24676a6225bf0b64572251a8c27d33e84afac6af713Bob Moore 24776a6225bf0b64572251a8c27d33e84afac6af713Bob Moore new_object = 24876a6225bf0b64572251a8c27d33e84afac6af713Bob Moore acpi_ut_create_buffer_object(original_object->string. 24976a6225bf0b64572251a8c27d33e84afac6af713Bob Moore length); 25076a6225bf0b64572251a8c27d33e84afac6af713Bob Moore if (!new_object) { 25176a6225bf0b64572251a8c27d33e84afac6af713Bob Moore return (AE_NO_MEMORY); 25276a6225bf0b64572251a8c27d33e84afac6af713Bob Moore } 25376a6225bf0b64572251a8c27d33e84afac6af713Bob Moore 25476a6225bf0b64572251a8c27d33e84afac6af713Bob Moore ACPI_MEMCPY(new_object->buffer.pointer, 25576a6225bf0b64572251a8c27d33e84afac6af713Bob Moore original_object->string.pointer, 25676a6225bf0b64572251a8c27d33e84afac6af713Bob Moore original_object->string.length); 25776a6225bf0b64572251a8c27d33e84afac6af713Bob Moore break; 25876a6225bf0b64572251a8c27d33e84afac6af713Bob Moore 25976a6225bf0b64572251a8c27d33e84afac6af713Bob Moore case ACPI_TYPE_PACKAGE: 26076a6225bf0b64572251a8c27d33e84afac6af713Bob Moore /* 26176a6225bf0b64572251a8c27d33e84afac6af713Bob Moore * This case is often seen for predefined names that must return a 26276a6225bf0b64572251a8c27d33e84afac6af713Bob Moore * Buffer object with multiple DWORD integers within. For example, 26376a6225bf0b64572251a8c27d33e84afac6af713Bob Moore * _FDE and _GTM. The Package can be converted to a Buffer. 26476a6225bf0b64572251a8c27d33e84afac6af713Bob Moore */ 26576a6225bf0b64572251a8c27d33e84afac6af713Bob Moore 26676a6225bf0b64572251a8c27d33e84afac6af713Bob Moore /* All elements of the Package must be integers */ 26776a6225bf0b64572251a8c27d33e84afac6af713Bob Moore 26876a6225bf0b64572251a8c27d33e84afac6af713Bob Moore elements = original_object->package.elements; 26976a6225bf0b64572251a8c27d33e84afac6af713Bob Moore count = original_object->package.count; 27076a6225bf0b64572251a8c27d33e84afac6af713Bob Moore 27176a6225bf0b64572251a8c27d33e84afac6af713Bob Moore for (i = 0; i < count; i++) { 27276a6225bf0b64572251a8c27d33e84afac6af713Bob Moore if ((!*elements) || 27376a6225bf0b64572251a8c27d33e84afac6af713Bob Moore ((*elements)->common.type != ACPI_TYPE_INTEGER)) { 27476a6225bf0b64572251a8c27d33e84afac6af713Bob Moore return (AE_AML_OPERAND_TYPE); 27576a6225bf0b64572251a8c27d33e84afac6af713Bob Moore } 27676a6225bf0b64572251a8c27d33e84afac6af713Bob Moore elements++; 27776a6225bf0b64572251a8c27d33e84afac6af713Bob Moore } 27876a6225bf0b64572251a8c27d33e84afac6af713Bob Moore 27976a6225bf0b64572251a8c27d33e84afac6af713Bob Moore /* Create the new buffer object to replace the Package */ 28076a6225bf0b64572251a8c27d33e84afac6af713Bob Moore 28176a6225bf0b64572251a8c27d33e84afac6af713Bob Moore new_object = acpi_ut_create_buffer_object(ACPI_MUL_4(count)); 28276a6225bf0b64572251a8c27d33e84afac6af713Bob Moore if (!new_object) { 28376a6225bf0b64572251a8c27d33e84afac6af713Bob Moore return (AE_NO_MEMORY); 28476a6225bf0b64572251a8c27d33e84afac6af713Bob Moore } 28576a6225bf0b64572251a8c27d33e84afac6af713Bob Moore 28676a6225bf0b64572251a8c27d33e84afac6af713Bob Moore /* Copy the package elements (integers) to the buffer as DWORDs */ 28776a6225bf0b64572251a8c27d33e84afac6af713Bob Moore 28876a6225bf0b64572251a8c27d33e84afac6af713Bob Moore elements = original_object->package.elements; 28976a6225bf0b64572251a8c27d33e84afac6af713Bob Moore dword_buffer = ACPI_CAST_PTR(u32, new_object->buffer.pointer); 29076a6225bf0b64572251a8c27d33e84afac6af713Bob Moore 29176a6225bf0b64572251a8c27d33e84afac6af713Bob Moore for (i = 0; i < count; i++) { 29276a6225bf0b64572251a8c27d33e84afac6af713Bob Moore *dword_buffer = (u32)(*elements)->integer.value; 29376a6225bf0b64572251a8c27d33e84afac6af713Bob Moore dword_buffer++; 29476a6225bf0b64572251a8c27d33e84afac6af713Bob Moore elements++; 29576a6225bf0b64572251a8c27d33e84afac6af713Bob Moore } 29676a6225bf0b64572251a8c27d33e84afac6af713Bob Moore break; 29776a6225bf0b64572251a8c27d33e84afac6af713Bob Moore 29876a6225bf0b64572251a8c27d33e84afac6af713Bob Moore default: 2991d1ea1b723d9f239f736b8cf284327cbbf9d15d1Chao Guan 30076a6225bf0b64572251a8c27d33e84afac6af713Bob Moore return (AE_AML_OPERAND_TYPE); 30176a6225bf0b64572251a8c27d33e84afac6af713Bob Moore } 30276a6225bf0b64572251a8c27d33e84afac6af713Bob Moore 30376a6225bf0b64572251a8c27d33e84afac6af713Bob Moore *return_object = new_object; 30476a6225bf0b64572251a8c27d33e84afac6af713Bob Moore return (AE_OK); 30576a6225bf0b64572251a8c27d33e84afac6af713Bob Moore} 30696b44cc684b315dbcf77191809df011067f2e206Lv Zheng 30796b44cc684b315dbcf77191809df011067f2e206Lv Zheng/******************************************************************************* 30896b44cc684b315dbcf77191809df011067f2e206Lv Zheng * 30996b44cc684b315dbcf77191809df011067f2e206Lv Zheng * FUNCTION: acpi_ns_convert_to_unicode 31096b44cc684b315dbcf77191809df011067f2e206Lv Zheng * 31196b44cc684b315dbcf77191809df011067f2e206Lv Zheng * PARAMETERS: original_object - ASCII String Object to be converted 31296b44cc684b315dbcf77191809df011067f2e206Lv Zheng * return_object - Where the new converted object is returned 31396b44cc684b315dbcf77191809df011067f2e206Lv Zheng * 31496b44cc684b315dbcf77191809df011067f2e206Lv Zheng * RETURN: Status. AE_OK if conversion was successful. 31596b44cc684b315dbcf77191809df011067f2e206Lv Zheng * 31696b44cc684b315dbcf77191809df011067f2e206Lv Zheng * DESCRIPTION: Attempt to convert a String object to a Unicode string Buffer. 31796b44cc684b315dbcf77191809df011067f2e206Lv Zheng * 31896b44cc684b315dbcf77191809df011067f2e206Lv Zheng ******************************************************************************/ 31996b44cc684b315dbcf77191809df011067f2e206Lv Zheng 32096b44cc684b315dbcf77191809df011067f2e206Lv Zhengacpi_status 32196b44cc684b315dbcf77191809df011067f2e206Lv Zhengacpi_ns_convert_to_unicode(union acpi_operand_object *original_object, 32296b44cc684b315dbcf77191809df011067f2e206Lv Zheng union acpi_operand_object **return_object) 32396b44cc684b315dbcf77191809df011067f2e206Lv Zheng{ 32496b44cc684b315dbcf77191809df011067f2e206Lv Zheng union acpi_operand_object *new_object; 32596b44cc684b315dbcf77191809df011067f2e206Lv Zheng char *ascii_string; 32696b44cc684b315dbcf77191809df011067f2e206Lv Zheng u16 *unicode_buffer; 32796b44cc684b315dbcf77191809df011067f2e206Lv Zheng u32 unicode_length; 32896b44cc684b315dbcf77191809df011067f2e206Lv Zheng u32 i; 32996b44cc684b315dbcf77191809df011067f2e206Lv Zheng 33096b44cc684b315dbcf77191809df011067f2e206Lv Zheng if (!original_object) { 33196b44cc684b315dbcf77191809df011067f2e206Lv Zheng return (AE_OK); 33296b44cc684b315dbcf77191809df011067f2e206Lv Zheng } 33396b44cc684b315dbcf77191809df011067f2e206Lv Zheng 33496b44cc684b315dbcf77191809df011067f2e206Lv Zheng /* If a Buffer was returned, it must be at least two bytes long */ 33596b44cc684b315dbcf77191809df011067f2e206Lv Zheng 33696b44cc684b315dbcf77191809df011067f2e206Lv Zheng if (original_object->common.type == ACPI_TYPE_BUFFER) { 33796b44cc684b315dbcf77191809df011067f2e206Lv Zheng if (original_object->buffer.length < 2) { 33896b44cc684b315dbcf77191809df011067f2e206Lv Zheng return (AE_AML_OPERAND_VALUE); 33996b44cc684b315dbcf77191809df011067f2e206Lv Zheng } 34096b44cc684b315dbcf77191809df011067f2e206Lv Zheng 34196b44cc684b315dbcf77191809df011067f2e206Lv Zheng *return_object = NULL; 34296b44cc684b315dbcf77191809df011067f2e206Lv Zheng return (AE_OK); 34396b44cc684b315dbcf77191809df011067f2e206Lv Zheng } 34496b44cc684b315dbcf77191809df011067f2e206Lv Zheng 34596b44cc684b315dbcf77191809df011067f2e206Lv Zheng /* 34696b44cc684b315dbcf77191809df011067f2e206Lv Zheng * The original object is an ASCII string. Convert this string to 34796b44cc684b315dbcf77191809df011067f2e206Lv Zheng * a unicode buffer. 34896b44cc684b315dbcf77191809df011067f2e206Lv Zheng */ 34996b44cc684b315dbcf77191809df011067f2e206Lv Zheng ascii_string = original_object->string.pointer; 35096b44cc684b315dbcf77191809df011067f2e206Lv Zheng unicode_length = (original_object->string.length * 2) + 2; 35196b44cc684b315dbcf77191809df011067f2e206Lv Zheng 35296b44cc684b315dbcf77191809df011067f2e206Lv Zheng /* Create a new buffer object for the Unicode data */ 35396b44cc684b315dbcf77191809df011067f2e206Lv Zheng 35496b44cc684b315dbcf77191809df011067f2e206Lv Zheng new_object = acpi_ut_create_buffer_object(unicode_length); 35596b44cc684b315dbcf77191809df011067f2e206Lv Zheng if (!new_object) { 35696b44cc684b315dbcf77191809df011067f2e206Lv Zheng return (AE_NO_MEMORY); 35796b44cc684b315dbcf77191809df011067f2e206Lv Zheng } 35896b44cc684b315dbcf77191809df011067f2e206Lv Zheng 35996b44cc684b315dbcf77191809df011067f2e206Lv Zheng unicode_buffer = ACPI_CAST_PTR(u16, new_object->buffer.pointer); 36096b44cc684b315dbcf77191809df011067f2e206Lv Zheng 36196b44cc684b315dbcf77191809df011067f2e206Lv Zheng /* Convert ASCII to Unicode */ 36296b44cc684b315dbcf77191809df011067f2e206Lv Zheng 36396b44cc684b315dbcf77191809df011067f2e206Lv Zheng for (i = 0; i < original_object->string.length; i++) { 36496b44cc684b315dbcf77191809df011067f2e206Lv Zheng unicode_buffer[i] = (u16)ascii_string[i]; 36596b44cc684b315dbcf77191809df011067f2e206Lv Zheng } 36696b44cc684b315dbcf77191809df011067f2e206Lv Zheng 36796b44cc684b315dbcf77191809df011067f2e206Lv Zheng *return_object = new_object; 36896b44cc684b315dbcf77191809df011067f2e206Lv Zheng return (AE_OK); 36996b44cc684b315dbcf77191809df011067f2e206Lv Zheng} 37088fd0ac831095f52691810a3b832e884766c657eLv Zheng 37188fd0ac831095f52691810a3b832e884766c657eLv Zheng/******************************************************************************* 37288fd0ac831095f52691810a3b832e884766c657eLv Zheng * 37388fd0ac831095f52691810a3b832e884766c657eLv Zheng * FUNCTION: acpi_ns_convert_to_resource 37488fd0ac831095f52691810a3b832e884766c657eLv Zheng * 37588fd0ac831095f52691810a3b832e884766c657eLv Zheng * PARAMETERS: original_object - Object to be converted 37688fd0ac831095f52691810a3b832e884766c657eLv Zheng * return_object - Where the new converted object is returned 37788fd0ac831095f52691810a3b832e884766c657eLv Zheng * 37888fd0ac831095f52691810a3b832e884766c657eLv Zheng * RETURN: Status. AE_OK if conversion was successful 37988fd0ac831095f52691810a3b832e884766c657eLv Zheng * 38088fd0ac831095f52691810a3b832e884766c657eLv Zheng * DESCRIPTION: Attempt to convert a Integer object to a resource_template 38188fd0ac831095f52691810a3b832e884766c657eLv Zheng * Buffer. 38288fd0ac831095f52691810a3b832e884766c657eLv Zheng * 38388fd0ac831095f52691810a3b832e884766c657eLv Zheng ******************************************************************************/ 38488fd0ac831095f52691810a3b832e884766c657eLv Zheng 38588fd0ac831095f52691810a3b832e884766c657eLv Zhengacpi_status 38688fd0ac831095f52691810a3b832e884766c657eLv Zhengacpi_ns_convert_to_resource(union acpi_operand_object *original_object, 38788fd0ac831095f52691810a3b832e884766c657eLv Zheng union acpi_operand_object **return_object) 38888fd0ac831095f52691810a3b832e884766c657eLv Zheng{ 38988fd0ac831095f52691810a3b832e884766c657eLv Zheng union acpi_operand_object *new_object; 39088fd0ac831095f52691810a3b832e884766c657eLv Zheng u8 *buffer; 39188fd0ac831095f52691810a3b832e884766c657eLv Zheng 39288fd0ac831095f52691810a3b832e884766c657eLv Zheng /* 39388fd0ac831095f52691810a3b832e884766c657eLv Zheng * We can fix the following cases for an expected resource template: 39488fd0ac831095f52691810a3b832e884766c657eLv Zheng * 1. No return value (interpreter slack mode is disabled) 39588fd0ac831095f52691810a3b832e884766c657eLv Zheng * 2. A "Return (Zero)" statement 39688fd0ac831095f52691810a3b832e884766c657eLv Zheng * 3. A "Return empty buffer" statement 39788fd0ac831095f52691810a3b832e884766c657eLv Zheng * 39888fd0ac831095f52691810a3b832e884766c657eLv Zheng * We will return a buffer containing a single end_tag 39988fd0ac831095f52691810a3b832e884766c657eLv Zheng * resource descriptor. 40088fd0ac831095f52691810a3b832e884766c657eLv Zheng */ 40188fd0ac831095f52691810a3b832e884766c657eLv Zheng if (original_object) { 40288fd0ac831095f52691810a3b832e884766c657eLv Zheng switch (original_object->common.type) { 40388fd0ac831095f52691810a3b832e884766c657eLv Zheng case ACPI_TYPE_INTEGER: 40488fd0ac831095f52691810a3b832e884766c657eLv Zheng 40588fd0ac831095f52691810a3b832e884766c657eLv Zheng /* We can only repair an Integer==0 */ 40688fd0ac831095f52691810a3b832e884766c657eLv Zheng 40788fd0ac831095f52691810a3b832e884766c657eLv Zheng if (original_object->integer.value) { 40888fd0ac831095f52691810a3b832e884766c657eLv Zheng return (AE_AML_OPERAND_TYPE); 40988fd0ac831095f52691810a3b832e884766c657eLv Zheng } 41088fd0ac831095f52691810a3b832e884766c657eLv Zheng break; 41188fd0ac831095f52691810a3b832e884766c657eLv Zheng 41288fd0ac831095f52691810a3b832e884766c657eLv Zheng case ACPI_TYPE_BUFFER: 41388fd0ac831095f52691810a3b832e884766c657eLv Zheng 41488fd0ac831095f52691810a3b832e884766c657eLv Zheng if (original_object->buffer.length) { 41588fd0ac831095f52691810a3b832e884766c657eLv Zheng 41688fd0ac831095f52691810a3b832e884766c657eLv Zheng /* Additional checks can be added in the future */ 41788fd0ac831095f52691810a3b832e884766c657eLv Zheng 41888fd0ac831095f52691810a3b832e884766c657eLv Zheng *return_object = NULL; 41988fd0ac831095f52691810a3b832e884766c657eLv Zheng return (AE_OK); 42088fd0ac831095f52691810a3b832e884766c657eLv Zheng } 42188fd0ac831095f52691810a3b832e884766c657eLv Zheng break; 42288fd0ac831095f52691810a3b832e884766c657eLv Zheng 42388fd0ac831095f52691810a3b832e884766c657eLv Zheng case ACPI_TYPE_STRING: 42488fd0ac831095f52691810a3b832e884766c657eLv Zheng default: 42588fd0ac831095f52691810a3b832e884766c657eLv Zheng 42688fd0ac831095f52691810a3b832e884766c657eLv Zheng return (AE_AML_OPERAND_TYPE); 42788fd0ac831095f52691810a3b832e884766c657eLv Zheng } 42888fd0ac831095f52691810a3b832e884766c657eLv Zheng } 42988fd0ac831095f52691810a3b832e884766c657eLv Zheng 43088fd0ac831095f52691810a3b832e884766c657eLv Zheng /* Create the new buffer object for the resource descriptor */ 43188fd0ac831095f52691810a3b832e884766c657eLv Zheng 43288fd0ac831095f52691810a3b832e884766c657eLv Zheng new_object = acpi_ut_create_buffer_object(2); 43388fd0ac831095f52691810a3b832e884766c657eLv Zheng if (!new_object) { 43488fd0ac831095f52691810a3b832e884766c657eLv Zheng return (AE_NO_MEMORY); 43588fd0ac831095f52691810a3b832e884766c657eLv Zheng } 43688fd0ac831095f52691810a3b832e884766c657eLv Zheng 43788fd0ac831095f52691810a3b832e884766c657eLv Zheng buffer = ACPI_CAST_PTR(u8, new_object->buffer.pointer); 43888fd0ac831095f52691810a3b832e884766c657eLv Zheng 43988fd0ac831095f52691810a3b832e884766c657eLv Zheng /* Initialize the Buffer with a single end_tag descriptor */ 44088fd0ac831095f52691810a3b832e884766c657eLv Zheng 44188fd0ac831095f52691810a3b832e884766c657eLv Zheng buffer[0] = (ACPI_RESOURCE_NAME_END_TAG | ASL_RDESC_END_TAG_SIZE); 44288fd0ac831095f52691810a3b832e884766c657eLv Zheng buffer[1] = 0x00; 44388fd0ac831095f52691810a3b832e884766c657eLv Zheng 44488fd0ac831095f52691810a3b832e884766c657eLv Zheng *return_object = new_object; 44588fd0ac831095f52691810a3b832e884766c657eLv Zheng return (AE_OK); 44688fd0ac831095f52691810a3b832e884766c657eLv Zheng} 447