1*95857638SErik Schmauss // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 295b482a8SLen Brown /******************************************************************************* 395b482a8SLen Brown * 495b482a8SLen Brown * Module Name: rsmisc - Miscellaneous resource descriptors 595b482a8SLen Brown * 695b482a8SLen Brown ******************************************************************************/ 795b482a8SLen Brown 895b482a8SLen Brown #include <acpi/acpi.h> 9e2f7a777SLen Brown #include "accommon.h" 10e2f7a777SLen Brown #include "acresrc.h" 1195b482a8SLen Brown 1295b482a8SLen Brown #define _COMPONENT ACPI_RESOURCES 1395b482a8SLen Brown ACPI_MODULE_NAME("rsmisc") 1495b482a8SLen Brown #define INIT_RESOURCE_TYPE(i) i->resource_offset 1595b482a8SLen Brown #define INIT_RESOURCE_LENGTH(i) i->aml_offset 1695b482a8SLen Brown #define INIT_TABLE_LENGTH(i) i->value 1795b482a8SLen Brown #define COMPARE_OPCODE(i) i->resource_offset 1895b482a8SLen Brown #define COMPARE_TARGET(i) i->aml_offset 1995b482a8SLen Brown #define COMPARE_VALUE(i) i->value 2095b482a8SLen Brown /******************************************************************************* 2195b482a8SLen Brown * 2295b482a8SLen Brown * FUNCTION: acpi_rs_convert_aml_to_resource 2395b482a8SLen Brown * 24ba494beeSBob Moore * PARAMETERS: resource - Pointer to the resource descriptor 25ba494beeSBob Moore * aml - Where the AML descriptor is returned 26ba494beeSBob Moore * info - Pointer to appropriate conversion table 2795b482a8SLen Brown * 2895b482a8SLen Brown * RETURN: Status 2995b482a8SLen Brown * 3095b482a8SLen Brown * DESCRIPTION: Convert an external AML resource descriptor to the corresponding 3195b482a8SLen Brown * internal resource descriptor 3295b482a8SLen Brown * 3395b482a8SLen Brown ******************************************************************************/ 3495b482a8SLen Brown acpi_status 3595b482a8SLen Brown acpi_rs_convert_aml_to_resource(struct acpi_resource *resource, 3695b482a8SLen Brown union aml_resource *aml, 3795b482a8SLen Brown struct acpi_rsconvert_info *info) 3895b482a8SLen Brown { 3995b482a8SLen Brown acpi_rs_length aml_resource_length; 4095b482a8SLen Brown void *source; 4195b482a8SLen Brown void *destination; 4295b482a8SLen Brown char *target; 4395b482a8SLen Brown u8 count; 4495b482a8SLen Brown u8 flags_mode = FALSE; 4595b482a8SLen Brown u16 item_count = 0; 4695b482a8SLen Brown u16 temp16 = 0; 4795b482a8SLen Brown 4895b482a8SLen Brown ACPI_FUNCTION_TRACE(rs_convert_aml_to_resource); 4995b482a8SLen Brown 50e0fe0a8dSLin Ming if (!info) { 51e0fe0a8dSLin Ming return_ACPI_STATUS(AE_BAD_PARAMETER); 52e0fe0a8dSLin Ming } 53e0fe0a8dSLin Ming 5495b482a8SLen Brown if (((acpi_size)resource) & 0x3) { 5595b482a8SLen Brown 5695b482a8SLen Brown /* Each internal resource struct is expected to be 32-bit aligned */ 5795b482a8SLen Brown 5895b482a8SLen Brown ACPI_WARNING((AE_INFO, 59f6a22b0bSBob Moore "Misaligned resource pointer (get): %p Type 0x%2.2X Length %u", 6095b482a8SLen Brown resource, resource->type, resource->length)); 6195b482a8SLen Brown } 6295b482a8SLen Brown 6395b482a8SLen Brown /* Extract the resource Length field (does not include header length) */ 6495b482a8SLen Brown 6595b482a8SLen Brown aml_resource_length = acpi_ut_get_resource_length(aml); 6695b482a8SLen Brown 6795b482a8SLen Brown /* 6895b482a8SLen Brown * First table entry must be ACPI_RSC_INITxxx and must contain the 6995b482a8SLen Brown * table length (# of table entries) 7095b482a8SLen Brown */ 7195b482a8SLen Brown count = INIT_TABLE_LENGTH(info); 7295b482a8SLen Brown while (count) { 7395b482a8SLen Brown /* 7495b482a8SLen Brown * Source is the external AML byte stream buffer, 7595b482a8SLen Brown * destination is the internal resource descriptor 7695b482a8SLen Brown */ 7795b482a8SLen Brown source = ACPI_ADD_PTR(void, aml, info->aml_offset); 7895b482a8SLen Brown destination = 7995b482a8SLen Brown ACPI_ADD_PTR(void, resource, info->resource_offset); 8095b482a8SLen Brown 8195b482a8SLen Brown switch (info->opcode) { 8295b482a8SLen Brown case ACPI_RSC_INITGET: 8395b482a8SLen Brown /* 8495b482a8SLen Brown * Get the resource type and the initial (minimum) length 8595b482a8SLen Brown */ 864fa4616eSBob Moore memset(resource, 0, INIT_RESOURCE_LENGTH(info)); 8795b482a8SLen Brown resource->type = INIT_RESOURCE_TYPE(info); 8895b482a8SLen Brown resource->length = INIT_RESOURCE_LENGTH(info); 8995b482a8SLen Brown break; 9095b482a8SLen Brown 9195b482a8SLen Brown case ACPI_RSC_INITSET: 9295b482a8SLen Brown break; 9395b482a8SLen Brown 9495b482a8SLen Brown case ACPI_RSC_FLAGINIT: 9595b482a8SLen Brown 9695b482a8SLen Brown flags_mode = TRUE; 9795b482a8SLen Brown break; 9895b482a8SLen Brown 9995b482a8SLen Brown case ACPI_RSC_1BITFLAG: 10095b482a8SLen Brown /* 10195b482a8SLen Brown * Mask and shift the flag bit 10295b482a8SLen Brown */ 10357bf6aefSLv Zheng ACPI_SET8(destination, 10457bf6aefSLv Zheng ((ACPI_GET8(source) >> info->value) & 0x01)); 10595b482a8SLen Brown break; 10695b482a8SLen Brown 10795b482a8SLen Brown case ACPI_RSC_2BITFLAG: 10895b482a8SLen Brown /* 10995b482a8SLen Brown * Mask and shift the flag bits 11095b482a8SLen Brown */ 11157bf6aefSLv Zheng ACPI_SET8(destination, 11257bf6aefSLv Zheng ((ACPI_GET8(source) >> info->value) & 0x03)); 11395b482a8SLen Brown break; 11495b482a8SLen Brown 115e0fe0a8dSLin Ming case ACPI_RSC_3BITFLAG: 116e0fe0a8dSLin Ming /* 117e0fe0a8dSLin Ming * Mask and shift the flag bits 118e0fe0a8dSLin Ming */ 11957bf6aefSLv Zheng ACPI_SET8(destination, 12057bf6aefSLv Zheng ((ACPI_GET8(source) >> info->value) & 0x07)); 121e0fe0a8dSLin Ming break; 122e0fe0a8dSLin Ming 12395b482a8SLen Brown case ACPI_RSC_COUNT: 12495b482a8SLen Brown 12595b482a8SLen Brown item_count = ACPI_GET8(source); 12657bf6aefSLv Zheng ACPI_SET8(destination, item_count); 12795b482a8SLen Brown 12895b482a8SLen Brown resource->length = resource->length + 12995b482a8SLen Brown (info->value * (item_count - 1)); 13095b482a8SLen Brown break; 13195b482a8SLen Brown 13295b482a8SLen Brown case ACPI_RSC_COUNT16: 13395b482a8SLen Brown 13495b482a8SLen Brown item_count = aml_resource_length; 13557bf6aefSLv Zheng ACPI_SET16(destination, item_count); 13695b482a8SLen Brown 13795b482a8SLen Brown resource->length = resource->length + 13895b482a8SLen Brown (info->value * (item_count - 1)); 13995b482a8SLen Brown break; 14095b482a8SLen Brown 141e0fe0a8dSLin Ming case ACPI_RSC_COUNT_GPIO_PIN: 142e0fe0a8dSLin Ming 143e0fe0a8dSLin Ming target = ACPI_ADD_PTR(void, aml, info->value); 144e0fe0a8dSLin Ming item_count = ACPI_GET16(target) - ACPI_GET16(source); 145e0fe0a8dSLin Ming 146e0fe0a8dSLin Ming resource->length = resource->length + item_count; 147e0fe0a8dSLin Ming item_count = item_count / 2; 14857bf6aefSLv Zheng ACPI_SET16(destination, item_count); 149e0fe0a8dSLin Ming break; 150e0fe0a8dSLin Ming 151e0fe0a8dSLin Ming case ACPI_RSC_COUNT_GPIO_VEN: 152e0fe0a8dSLin Ming 153e0fe0a8dSLin Ming item_count = ACPI_GET8(source); 15457bf6aefSLv Zheng ACPI_SET8(destination, item_count); 155e0fe0a8dSLin Ming 1561fad8738SBob Moore resource->length = 1571fad8738SBob Moore resource->length + (info->value * item_count); 158e0fe0a8dSLin Ming break; 159e0fe0a8dSLin Ming 160e0fe0a8dSLin Ming case ACPI_RSC_COUNT_GPIO_RES: 161e0fe0a8dSLin Ming /* 162e0fe0a8dSLin Ming * Vendor data is optional (length/offset may both be zero) 163e0fe0a8dSLin Ming * Examine vendor data length field first 164e0fe0a8dSLin Ming */ 165e0fe0a8dSLin Ming target = ACPI_ADD_PTR(void, aml, (info->value + 2)); 166e0fe0a8dSLin Ming if (ACPI_GET16(target)) { 167e0fe0a8dSLin Ming 168e0fe0a8dSLin Ming /* Use vendor offset to get resource source length */ 169e0fe0a8dSLin Ming 170e0fe0a8dSLin Ming target = ACPI_ADD_PTR(void, aml, info->value); 171e0fe0a8dSLin Ming item_count = 172e0fe0a8dSLin Ming ACPI_GET16(target) - ACPI_GET16(source); 173e0fe0a8dSLin Ming } else { 174e0fe0a8dSLin Ming /* No vendor data to worry about */ 175e0fe0a8dSLin Ming 176e0fe0a8dSLin Ming item_count = aml->large_header.resource_length + 177e0fe0a8dSLin Ming sizeof(struct aml_resource_large_header) - 178e0fe0a8dSLin Ming ACPI_GET16(source); 179e0fe0a8dSLin Ming } 180e0fe0a8dSLin Ming 181e0fe0a8dSLin Ming resource->length = resource->length + item_count; 18257bf6aefSLv Zheng ACPI_SET16(destination, item_count); 183e0fe0a8dSLin Ming break; 184e0fe0a8dSLin Ming 185e0fe0a8dSLin Ming case ACPI_RSC_COUNT_SERIAL_VEN: 186e0fe0a8dSLin Ming 187e0fe0a8dSLin Ming item_count = ACPI_GET16(source) - info->value; 188e0fe0a8dSLin Ming 189e0fe0a8dSLin Ming resource->length = resource->length + item_count; 19057bf6aefSLv Zheng ACPI_SET16(destination, item_count); 191e0fe0a8dSLin Ming break; 192e0fe0a8dSLin Ming 193e0fe0a8dSLin Ming case ACPI_RSC_COUNT_SERIAL_RES: 194e0fe0a8dSLin Ming 195e0fe0a8dSLin Ming item_count = (aml_resource_length + 196e0fe0a8dSLin Ming sizeof(struct aml_resource_large_header)) 197e0fe0a8dSLin Ming - ACPI_GET16(source) - info->value; 198e0fe0a8dSLin Ming 199e0fe0a8dSLin Ming resource->length = resource->length + item_count; 20057bf6aefSLv Zheng ACPI_SET16(destination, item_count); 201e0fe0a8dSLin Ming break; 202e0fe0a8dSLin Ming 20395b482a8SLen Brown case ACPI_RSC_LENGTH: 20495b482a8SLen Brown 20595b482a8SLen Brown resource->length = resource->length + info->value; 20695b482a8SLen Brown break; 20795b482a8SLen Brown 20895b482a8SLen Brown case ACPI_RSC_MOVE8: 20995b482a8SLen Brown case ACPI_RSC_MOVE16: 21095b482a8SLen Brown case ACPI_RSC_MOVE32: 21195b482a8SLen Brown case ACPI_RSC_MOVE64: 21295b482a8SLen Brown /* 21395b482a8SLen Brown * Raw data move. Use the Info value field unless item_count has 21495b482a8SLen Brown * been previously initialized via a COUNT opcode 21595b482a8SLen Brown */ 21695b482a8SLen Brown if (info->value) { 21795b482a8SLen Brown item_count = info->value; 21895b482a8SLen Brown } 21995b482a8SLen Brown acpi_rs_move_data(destination, source, item_count, 22095b482a8SLen Brown info->opcode); 22195b482a8SLen Brown break; 22295b482a8SLen Brown 223e0fe0a8dSLin Ming case ACPI_RSC_MOVE_GPIO_PIN: 224e0fe0a8dSLin Ming 225e0fe0a8dSLin Ming /* Generate and set the PIN data pointer */ 226e0fe0a8dSLin Ming 227e0fe0a8dSLin Ming target = (char *)ACPI_ADD_PTR(void, resource, 228e0fe0a8dSLin Ming (resource->length - 229e0fe0a8dSLin Ming item_count * 2)); 230e0fe0a8dSLin Ming *(u16 **)destination = ACPI_CAST_PTR(u16, target); 231e0fe0a8dSLin Ming 232e0fe0a8dSLin Ming /* Copy the PIN data */ 233e0fe0a8dSLin Ming 234e0fe0a8dSLin Ming source = ACPI_ADD_PTR(void, aml, ACPI_GET16(source)); 235e0fe0a8dSLin Ming acpi_rs_move_data(target, source, item_count, 236e0fe0a8dSLin Ming info->opcode); 237e0fe0a8dSLin Ming break; 238e0fe0a8dSLin Ming 239e0fe0a8dSLin Ming case ACPI_RSC_MOVE_GPIO_RES: 240e0fe0a8dSLin Ming 241e0fe0a8dSLin Ming /* Generate and set the resource_source string pointer */ 242e0fe0a8dSLin Ming 243e0fe0a8dSLin Ming target = (char *)ACPI_ADD_PTR(void, resource, 244e0fe0a8dSLin Ming (resource->length - 245e0fe0a8dSLin Ming item_count)); 246e0fe0a8dSLin Ming *(u8 **)destination = ACPI_CAST_PTR(u8, target); 247e0fe0a8dSLin Ming 248e0fe0a8dSLin Ming /* Copy the resource_source string */ 249e0fe0a8dSLin Ming 250e0fe0a8dSLin Ming source = ACPI_ADD_PTR(void, aml, ACPI_GET16(source)); 251e0fe0a8dSLin Ming acpi_rs_move_data(target, source, item_count, 252e0fe0a8dSLin Ming info->opcode); 253e0fe0a8dSLin Ming break; 254e0fe0a8dSLin Ming 255e0fe0a8dSLin Ming case ACPI_RSC_MOVE_SERIAL_VEN: 256e0fe0a8dSLin Ming 257e0fe0a8dSLin Ming /* Generate and set the Vendor Data pointer */ 258e0fe0a8dSLin Ming 259e0fe0a8dSLin Ming target = (char *)ACPI_ADD_PTR(void, resource, 260e0fe0a8dSLin Ming (resource->length - 261e0fe0a8dSLin Ming item_count)); 262e0fe0a8dSLin Ming *(u8 **)destination = ACPI_CAST_PTR(u8, target); 263e0fe0a8dSLin Ming 264e0fe0a8dSLin Ming /* Copy the Vendor Data */ 265e0fe0a8dSLin Ming 266e0fe0a8dSLin Ming source = ACPI_ADD_PTR(void, aml, info->value); 267e0fe0a8dSLin Ming acpi_rs_move_data(target, source, item_count, 268e0fe0a8dSLin Ming info->opcode); 269e0fe0a8dSLin Ming break; 270e0fe0a8dSLin Ming 271e0fe0a8dSLin Ming case ACPI_RSC_MOVE_SERIAL_RES: 272e0fe0a8dSLin Ming 273e0fe0a8dSLin Ming /* Generate and set the resource_source string pointer */ 274e0fe0a8dSLin Ming 275e0fe0a8dSLin Ming target = (char *)ACPI_ADD_PTR(void, resource, 276e0fe0a8dSLin Ming (resource->length - 277e0fe0a8dSLin Ming item_count)); 278e0fe0a8dSLin Ming *(u8 **)destination = ACPI_CAST_PTR(u8, target); 279e0fe0a8dSLin Ming 280e0fe0a8dSLin Ming /* Copy the resource_source string */ 281e0fe0a8dSLin Ming 282e0fe0a8dSLin Ming source = 283e0fe0a8dSLin Ming ACPI_ADD_PTR(void, aml, 284e0fe0a8dSLin Ming (ACPI_GET16(source) + info->value)); 285e0fe0a8dSLin Ming acpi_rs_move_data(target, source, item_count, 286e0fe0a8dSLin Ming info->opcode); 287e0fe0a8dSLin Ming break; 288e0fe0a8dSLin Ming 28995b482a8SLen Brown case ACPI_RSC_SET8: 29095b482a8SLen Brown 2914fa4616eSBob Moore memset(destination, info->aml_offset, info->value); 29295b482a8SLen Brown break; 29395b482a8SLen Brown 29495b482a8SLen Brown case ACPI_RSC_DATA8: 29595b482a8SLen Brown 29695b482a8SLen Brown target = ACPI_ADD_PTR(char, resource, info->value); 2974fa4616eSBob Moore memcpy(destination, source, ACPI_GET16(target)); 29895b482a8SLen Brown break; 29995b482a8SLen Brown 30095b482a8SLen Brown case ACPI_RSC_ADDRESS: 30195b482a8SLen Brown /* 30295b482a8SLen Brown * Common handler for address descriptor flags 30395b482a8SLen Brown */ 30495b482a8SLen Brown if (!acpi_rs_get_address_common(resource, aml)) { 30595b482a8SLen Brown return_ACPI_STATUS 30695b482a8SLen Brown (AE_AML_INVALID_RESOURCE_TYPE); 30795b482a8SLen Brown } 30895b482a8SLen Brown break; 30995b482a8SLen Brown 31095b482a8SLen Brown case ACPI_RSC_SOURCE: 31195b482a8SLen Brown /* 31295b482a8SLen Brown * Optional resource_source (Index and String) 31395b482a8SLen Brown */ 31495b482a8SLen Brown resource->length += 31595b482a8SLen Brown acpi_rs_get_resource_source(aml_resource_length, 31695b482a8SLen Brown info->value, 31795b482a8SLen Brown destination, aml, NULL); 31895b482a8SLen Brown break; 31995b482a8SLen Brown 32095b482a8SLen Brown case ACPI_RSC_SOURCEX: 32195b482a8SLen Brown /* 32295b482a8SLen Brown * Optional resource_source (Index and String). This is the more 32395b482a8SLen Brown * complicated case used by the Interrupt() macro 32495b482a8SLen Brown */ 325e0fe0a8dSLin Ming target = ACPI_ADD_PTR(char, resource, 326e0fe0a8dSLin Ming info->aml_offset + 327e0fe0a8dSLin Ming (item_count * 4)); 32895b482a8SLen Brown 32995b482a8SLen Brown resource->length += 33095b482a8SLen Brown acpi_rs_get_resource_source(aml_resource_length, 331e0fe0a8dSLin Ming (acpi_rs_length) 332e0fe0a8dSLin Ming (((item_count - 333e0fe0a8dSLin Ming 1) * sizeof(u32)) + 334e0fe0a8dSLin Ming info->value), 335e0fe0a8dSLin Ming destination, aml, 336e0fe0a8dSLin Ming target); 33795b482a8SLen Brown break; 33895b482a8SLen Brown 33995b482a8SLen Brown case ACPI_RSC_BITMASK: 34095b482a8SLen Brown /* 34195b482a8SLen Brown * 8-bit encoded bitmask (DMA macro) 34295b482a8SLen Brown */ 34395b482a8SLen Brown item_count = 34495b482a8SLen Brown acpi_rs_decode_bitmask(ACPI_GET8(source), 34595b482a8SLen Brown destination); 34695b482a8SLen Brown if (item_count) { 34795b482a8SLen Brown resource->length += (item_count - 1); 34895b482a8SLen Brown } 34995b482a8SLen Brown 35095b482a8SLen Brown target = ACPI_ADD_PTR(char, resource, info->value); 35157bf6aefSLv Zheng ACPI_SET8(target, item_count); 35295b482a8SLen Brown break; 35395b482a8SLen Brown 35495b482a8SLen Brown case ACPI_RSC_BITMASK16: 35595b482a8SLen Brown /* 35695b482a8SLen Brown * 16-bit encoded bitmask (IRQ macro) 35795b482a8SLen Brown */ 35895b482a8SLen Brown ACPI_MOVE_16_TO_16(&temp16, source); 35995b482a8SLen Brown 36095b482a8SLen Brown item_count = 36195b482a8SLen Brown acpi_rs_decode_bitmask(temp16, destination); 36295b482a8SLen Brown if (item_count) { 36395b482a8SLen Brown resource->length += (item_count - 1); 36495b482a8SLen Brown } 36595b482a8SLen Brown 36695b482a8SLen Brown target = ACPI_ADD_PTR(char, resource, info->value); 36757bf6aefSLv Zheng ACPI_SET8(target, item_count); 36895b482a8SLen Brown break; 36995b482a8SLen Brown 37095b482a8SLen Brown case ACPI_RSC_EXIT_NE: 37195b482a8SLen Brown /* 372ba494beeSBob Moore * control - Exit conversion if not equal 37395b482a8SLen Brown */ 37495b482a8SLen Brown switch (info->resource_offset) { 37595b482a8SLen Brown case ACPI_RSC_COMPARE_AML_LENGTH: 3761d1ea1b7SChao Guan 37795b482a8SLen Brown if (aml_resource_length != info->value) { 37895b482a8SLen Brown goto exit; 37995b482a8SLen Brown } 38095b482a8SLen Brown break; 38195b482a8SLen Brown 38295b482a8SLen Brown case ACPI_RSC_COMPARE_VALUE: 3831d1ea1b7SChao Guan 38495b482a8SLen Brown if (ACPI_GET8(source) != info->value) { 38595b482a8SLen Brown goto exit; 38695b482a8SLen Brown } 38795b482a8SLen Brown break; 38895b482a8SLen Brown 38995b482a8SLen Brown default: 39095b482a8SLen Brown 39195b482a8SLen Brown ACPI_ERROR((AE_INFO, 39295b482a8SLen Brown "Invalid conversion sub-opcode")); 39395b482a8SLen Brown return_ACPI_STATUS(AE_BAD_PARAMETER); 39495b482a8SLen Brown } 39595b482a8SLen Brown break; 39695b482a8SLen Brown 39795b482a8SLen Brown default: 39895b482a8SLen Brown 39995b482a8SLen Brown ACPI_ERROR((AE_INFO, "Invalid conversion opcode")); 40095b482a8SLen Brown return_ACPI_STATUS(AE_BAD_PARAMETER); 40195b482a8SLen Brown } 40295b482a8SLen Brown 40395b482a8SLen Brown count--; 40495b482a8SLen Brown info++; 40595b482a8SLen Brown } 40695b482a8SLen Brown 40795b482a8SLen Brown exit: 40895b482a8SLen Brown if (!flags_mode) { 40995b482a8SLen Brown 41095b482a8SLen Brown /* Round the resource struct length up to the next boundary (32 or 64) */ 41195b482a8SLen Brown 4121fad8738SBob Moore resource->length = (u32) 4131fad8738SBob Moore ACPI_ROUND_UP_TO_NATIVE_WORD(resource->length); 41495b482a8SLen Brown } 41595b482a8SLen Brown return_ACPI_STATUS(AE_OK); 41695b482a8SLen Brown } 41795b482a8SLen Brown 41895b482a8SLen Brown /******************************************************************************* 41995b482a8SLen Brown * 42095b482a8SLen Brown * FUNCTION: acpi_rs_convert_resource_to_aml 42195b482a8SLen Brown * 422ba494beeSBob Moore * PARAMETERS: resource - Pointer to the resource descriptor 423ba494beeSBob Moore * aml - Where the AML descriptor is returned 424ba494beeSBob Moore * info - Pointer to appropriate conversion table 42595b482a8SLen Brown * 42695b482a8SLen Brown * RETURN: Status 42795b482a8SLen Brown * 42895b482a8SLen Brown * DESCRIPTION: Convert an internal resource descriptor to the corresponding 42995b482a8SLen Brown * external AML resource descriptor. 43095b482a8SLen Brown * 43195b482a8SLen Brown ******************************************************************************/ 43295b482a8SLen Brown 43395b482a8SLen Brown acpi_status 43495b482a8SLen Brown acpi_rs_convert_resource_to_aml(struct acpi_resource *resource, 43595b482a8SLen Brown union aml_resource *aml, 43695b482a8SLen Brown struct acpi_rsconvert_info *info) 43795b482a8SLen Brown { 43895b482a8SLen Brown void *source = NULL; 43995b482a8SLen Brown void *destination; 440e0fe0a8dSLin Ming char *target; 44195b482a8SLen Brown acpi_rsdesc_size aml_length = 0; 44295b482a8SLen Brown u8 count; 44395b482a8SLen Brown u16 temp16 = 0; 44495b482a8SLen Brown u16 item_count = 0; 44595b482a8SLen Brown 44695b482a8SLen Brown ACPI_FUNCTION_TRACE(rs_convert_resource_to_aml); 44795b482a8SLen Brown 448e0fe0a8dSLin Ming if (!info) { 449e0fe0a8dSLin Ming return_ACPI_STATUS(AE_BAD_PARAMETER); 450e0fe0a8dSLin Ming } 451e0fe0a8dSLin Ming 45295b482a8SLen Brown /* 45395b482a8SLen Brown * First table entry must be ACPI_RSC_INITxxx and must contain the 45495b482a8SLen Brown * table length (# of table entries) 45595b482a8SLen Brown */ 45695b482a8SLen Brown count = INIT_TABLE_LENGTH(info); 45795b482a8SLen Brown 45895b482a8SLen Brown while (count) { 45995b482a8SLen Brown /* 46095b482a8SLen Brown * Source is the internal resource descriptor, 46195b482a8SLen Brown * destination is the external AML byte stream buffer 46295b482a8SLen Brown */ 46395b482a8SLen Brown source = ACPI_ADD_PTR(void, resource, info->resource_offset); 46495b482a8SLen Brown destination = ACPI_ADD_PTR(void, aml, info->aml_offset); 46595b482a8SLen Brown 46695b482a8SLen Brown switch (info->opcode) { 46795b482a8SLen Brown case ACPI_RSC_INITSET: 46895b482a8SLen Brown 4694fa4616eSBob Moore memset(aml, 0, INIT_RESOURCE_LENGTH(info)); 47095b482a8SLen Brown aml_length = INIT_RESOURCE_LENGTH(info); 47195b482a8SLen Brown acpi_rs_set_resource_header(INIT_RESOURCE_TYPE(info), 47295b482a8SLen Brown aml_length, aml); 47395b482a8SLen Brown break; 47495b482a8SLen Brown 47595b482a8SLen Brown case ACPI_RSC_INITGET: 47695b482a8SLen Brown break; 47795b482a8SLen Brown 47895b482a8SLen Brown case ACPI_RSC_FLAGINIT: 47995b482a8SLen Brown /* 48095b482a8SLen Brown * Clear the flag byte 48195b482a8SLen Brown */ 48257bf6aefSLv Zheng ACPI_SET8(destination, 0); 48395b482a8SLen Brown break; 48495b482a8SLen Brown 48595b482a8SLen Brown case ACPI_RSC_1BITFLAG: 48695b482a8SLen Brown /* 48795b482a8SLen Brown * Mask and shift the flag bit 48895b482a8SLen Brown */ 48957bf6aefSLv Zheng ACPI_SET_BIT(*ACPI_CAST8(destination), (u8) 49057bf6aefSLv Zheng ((ACPI_GET8(source) & 0x01) << info-> 49157bf6aefSLv Zheng value)); 49295b482a8SLen Brown break; 49395b482a8SLen Brown 49495b482a8SLen Brown case ACPI_RSC_2BITFLAG: 49595b482a8SLen Brown /* 49695b482a8SLen Brown * Mask and shift the flag bits 49795b482a8SLen Brown */ 49857bf6aefSLv Zheng ACPI_SET_BIT(*ACPI_CAST8(destination), (u8) 49957bf6aefSLv Zheng ((ACPI_GET8(source) & 0x03) << info-> 50057bf6aefSLv Zheng value)); 50195b482a8SLen Brown break; 50295b482a8SLen Brown 503e0fe0a8dSLin Ming case ACPI_RSC_3BITFLAG: 504e0fe0a8dSLin Ming /* 505e0fe0a8dSLin Ming * Mask and shift the flag bits 506e0fe0a8dSLin Ming */ 50757bf6aefSLv Zheng ACPI_SET_BIT(*ACPI_CAST8(destination), (u8) 50857bf6aefSLv Zheng ((ACPI_GET8(source) & 0x07) << info-> 50957bf6aefSLv Zheng value)); 510e0fe0a8dSLin Ming break; 511e0fe0a8dSLin Ming 51295b482a8SLen Brown case ACPI_RSC_COUNT: 51395b482a8SLen Brown 51495b482a8SLen Brown item_count = ACPI_GET8(source); 51557bf6aefSLv Zheng ACPI_SET8(destination, item_count); 51695b482a8SLen Brown 5171fad8738SBob Moore aml_length = (u16) 5181fad8738SBob Moore (aml_length + (info->value * (item_count - 1))); 51995b482a8SLen Brown break; 52095b482a8SLen Brown 52195b482a8SLen Brown case ACPI_RSC_COUNT16: 52295b482a8SLen Brown 52395b482a8SLen Brown item_count = ACPI_GET16(source); 52495b482a8SLen Brown aml_length = (u16) (aml_length + item_count); 52595b482a8SLen Brown acpi_rs_set_resource_length(aml_length, aml); 52695b482a8SLen Brown break; 52795b482a8SLen Brown 528e0fe0a8dSLin Ming case ACPI_RSC_COUNT_GPIO_PIN: 529e0fe0a8dSLin Ming 530e0fe0a8dSLin Ming item_count = ACPI_GET16(source); 53157bf6aefSLv Zheng ACPI_SET16(destination, aml_length); 532e0fe0a8dSLin Ming 533e0fe0a8dSLin Ming aml_length = (u16)(aml_length + item_count * 2); 534e0fe0a8dSLin Ming target = ACPI_ADD_PTR(void, aml, info->value); 53557bf6aefSLv Zheng ACPI_SET16(target, aml_length); 536e0fe0a8dSLin Ming acpi_rs_set_resource_length(aml_length, aml); 537e0fe0a8dSLin Ming break; 538e0fe0a8dSLin Ming 539e0fe0a8dSLin Ming case ACPI_RSC_COUNT_GPIO_VEN: 540e0fe0a8dSLin Ming 541e0fe0a8dSLin Ming item_count = ACPI_GET16(source); 54257bf6aefSLv Zheng ACPI_SET16(destination, item_count); 543e0fe0a8dSLin Ming 544e0fe0a8dSLin Ming aml_length = 545e0fe0a8dSLin Ming (u16)(aml_length + (info->value * item_count)); 546e0fe0a8dSLin Ming acpi_rs_set_resource_length(aml_length, aml); 547e0fe0a8dSLin Ming break; 548e0fe0a8dSLin Ming 549e0fe0a8dSLin Ming case ACPI_RSC_COUNT_GPIO_RES: 550e0fe0a8dSLin Ming 551e0fe0a8dSLin Ming /* Set resource source string length */ 552e0fe0a8dSLin Ming 553e0fe0a8dSLin Ming item_count = ACPI_GET16(source); 55457bf6aefSLv Zheng ACPI_SET16(destination, aml_length); 555e0fe0a8dSLin Ming 556e0fe0a8dSLin Ming /* Compute offset for the Vendor Data */ 557e0fe0a8dSLin Ming 558e0fe0a8dSLin Ming aml_length = (u16)(aml_length + item_count); 559e0fe0a8dSLin Ming target = ACPI_ADD_PTR(void, aml, info->value); 560e0fe0a8dSLin Ming 561e0fe0a8dSLin Ming /* Set vendor offset only if there is vendor data */ 562e0fe0a8dSLin Ming 56357bf6aefSLv Zheng ACPI_SET16(target, aml_length); 564e0fe0a8dSLin Ming 565e0fe0a8dSLin Ming acpi_rs_set_resource_length(aml_length, aml); 566e0fe0a8dSLin Ming break; 567e0fe0a8dSLin Ming 568e0fe0a8dSLin Ming case ACPI_RSC_COUNT_SERIAL_VEN: 569e0fe0a8dSLin Ming 570e0fe0a8dSLin Ming item_count = ACPI_GET16(source); 57157bf6aefSLv Zheng ACPI_SET16(destination, item_count + info->value); 572e0fe0a8dSLin Ming aml_length = (u16)(aml_length + item_count); 573e0fe0a8dSLin Ming acpi_rs_set_resource_length(aml_length, aml); 574e0fe0a8dSLin Ming break; 575e0fe0a8dSLin Ming 576e0fe0a8dSLin Ming case ACPI_RSC_COUNT_SERIAL_RES: 577e0fe0a8dSLin Ming 578e0fe0a8dSLin Ming item_count = ACPI_GET16(source); 579e0fe0a8dSLin Ming aml_length = (u16)(aml_length + item_count); 580e0fe0a8dSLin Ming acpi_rs_set_resource_length(aml_length, aml); 581e0fe0a8dSLin Ming break; 582e0fe0a8dSLin Ming 58395b482a8SLen Brown case ACPI_RSC_LENGTH: 58495b482a8SLen Brown 58595b482a8SLen Brown acpi_rs_set_resource_length(info->value, aml); 58695b482a8SLen Brown break; 58795b482a8SLen Brown 58895b482a8SLen Brown case ACPI_RSC_MOVE8: 58995b482a8SLen Brown case ACPI_RSC_MOVE16: 59095b482a8SLen Brown case ACPI_RSC_MOVE32: 59195b482a8SLen Brown case ACPI_RSC_MOVE64: 59295b482a8SLen Brown 59395b482a8SLen Brown if (info->value) { 59495b482a8SLen Brown item_count = info->value; 59595b482a8SLen Brown } 59695b482a8SLen Brown acpi_rs_move_data(destination, source, item_count, 59795b482a8SLen Brown info->opcode); 59895b482a8SLen Brown break; 59995b482a8SLen Brown 600e0fe0a8dSLin Ming case ACPI_RSC_MOVE_GPIO_PIN: 601e0fe0a8dSLin Ming 602e0fe0a8dSLin Ming destination = (char *)ACPI_ADD_PTR(void, aml, 603e0fe0a8dSLin Ming ACPI_GET16 604e0fe0a8dSLin Ming (destination)); 605e0fe0a8dSLin Ming source = *(u16 **)source; 606e0fe0a8dSLin Ming acpi_rs_move_data(destination, source, item_count, 607e0fe0a8dSLin Ming info->opcode); 608e0fe0a8dSLin Ming break; 609e0fe0a8dSLin Ming 610e0fe0a8dSLin Ming case ACPI_RSC_MOVE_GPIO_RES: 611e0fe0a8dSLin Ming 612e0fe0a8dSLin Ming /* Used for both resource_source string and vendor_data */ 613e0fe0a8dSLin Ming 614e0fe0a8dSLin Ming destination = (char *)ACPI_ADD_PTR(void, aml, 615e0fe0a8dSLin Ming ACPI_GET16 616e0fe0a8dSLin Ming (destination)); 617e0fe0a8dSLin Ming source = *(u8 **)source; 618e0fe0a8dSLin Ming acpi_rs_move_data(destination, source, item_count, 619e0fe0a8dSLin Ming info->opcode); 620e0fe0a8dSLin Ming break; 621e0fe0a8dSLin Ming 622e0fe0a8dSLin Ming case ACPI_RSC_MOVE_SERIAL_VEN: 623e0fe0a8dSLin Ming 624e0fe0a8dSLin Ming destination = (char *)ACPI_ADD_PTR(void, aml, 625e0fe0a8dSLin Ming (aml_length - 626e0fe0a8dSLin Ming item_count)); 627e0fe0a8dSLin Ming source = *(u8 **)source; 628e0fe0a8dSLin Ming acpi_rs_move_data(destination, source, item_count, 629e0fe0a8dSLin Ming info->opcode); 630e0fe0a8dSLin Ming break; 631e0fe0a8dSLin Ming 632e0fe0a8dSLin Ming case ACPI_RSC_MOVE_SERIAL_RES: 633e0fe0a8dSLin Ming 634e0fe0a8dSLin Ming destination = (char *)ACPI_ADD_PTR(void, aml, 635e0fe0a8dSLin Ming (aml_length - 636e0fe0a8dSLin Ming item_count)); 637e0fe0a8dSLin Ming source = *(u8 **)source; 638e0fe0a8dSLin Ming acpi_rs_move_data(destination, source, item_count, 639e0fe0a8dSLin Ming info->opcode); 640e0fe0a8dSLin Ming break; 641e0fe0a8dSLin Ming 64295b482a8SLen Brown case ACPI_RSC_ADDRESS: 64395b482a8SLen Brown 64495b482a8SLen Brown /* Set the Resource Type, General Flags, and Type-Specific Flags */ 64595b482a8SLen Brown 64695b482a8SLen Brown acpi_rs_set_address_common(aml, resource); 64795b482a8SLen Brown break; 64895b482a8SLen Brown 64995b482a8SLen Brown case ACPI_RSC_SOURCEX: 65095b482a8SLen Brown /* 65195b482a8SLen Brown * Optional resource_source (Index and String) 65295b482a8SLen Brown */ 65395b482a8SLen Brown aml_length = 6543e8214e5SLv Zheng acpi_rs_set_resource_source(aml, 6553e8214e5SLv Zheng (acpi_rs_length) 65695b482a8SLen Brown aml_length, source); 65795b482a8SLen Brown acpi_rs_set_resource_length(aml_length, aml); 65895b482a8SLen Brown break; 65995b482a8SLen Brown 66095b482a8SLen Brown case ACPI_RSC_SOURCE: 66195b482a8SLen Brown /* 66295b482a8SLen Brown * Optional resource_source (Index and String). This is the more 66395b482a8SLen Brown * complicated case used by the Interrupt() macro 66495b482a8SLen Brown */ 66595b482a8SLen Brown aml_length = 66695b482a8SLen Brown acpi_rs_set_resource_source(aml, info->value, 66795b482a8SLen Brown source); 66895b482a8SLen Brown acpi_rs_set_resource_length(aml_length, aml); 66995b482a8SLen Brown break; 67095b482a8SLen Brown 67195b482a8SLen Brown case ACPI_RSC_BITMASK: 67295b482a8SLen Brown /* 67395b482a8SLen Brown * 8-bit encoded bitmask (DMA macro) 67495b482a8SLen Brown */ 67557bf6aefSLv Zheng ACPI_SET8(destination, 67695b482a8SLen Brown acpi_rs_encode_bitmask(source, 67757bf6aefSLv Zheng *ACPI_ADD_PTR(u8, 67857bf6aefSLv Zheng resource, 67957bf6aefSLv Zheng info-> 68057bf6aefSLv Zheng value))); 68195b482a8SLen Brown break; 68295b482a8SLen Brown 68395b482a8SLen Brown case ACPI_RSC_BITMASK16: 68495b482a8SLen Brown /* 68595b482a8SLen Brown * 16-bit encoded bitmask (IRQ macro) 68695b482a8SLen Brown */ 6871fad8738SBob Moore temp16 = 6881fad8738SBob Moore acpi_rs_encode_bitmask(source, 6891fad8738SBob Moore *ACPI_ADD_PTR(u8, resource, 6901fad8738SBob Moore info->value)); 69195b482a8SLen Brown ACPI_MOVE_16_TO_16(destination, &temp16); 69295b482a8SLen Brown break; 69395b482a8SLen Brown 69495b482a8SLen Brown case ACPI_RSC_EXIT_LE: 69595b482a8SLen Brown /* 696ba494beeSBob Moore * control - Exit conversion if less than or equal 69795b482a8SLen Brown */ 69895b482a8SLen Brown if (item_count <= info->value) { 69995b482a8SLen Brown goto exit; 70095b482a8SLen Brown } 70195b482a8SLen Brown break; 70295b482a8SLen Brown 70395b482a8SLen Brown case ACPI_RSC_EXIT_NE: 70495b482a8SLen Brown /* 705ba494beeSBob Moore * control - Exit conversion if not equal 70695b482a8SLen Brown */ 70795b482a8SLen Brown switch (COMPARE_OPCODE(info)) { 70895b482a8SLen Brown case ACPI_RSC_COMPARE_VALUE: 70995b482a8SLen Brown 71095b482a8SLen Brown if (*ACPI_ADD_PTR(u8, resource, 71195b482a8SLen Brown COMPARE_TARGET(info)) != 71295b482a8SLen Brown COMPARE_VALUE(info)) { 71395b482a8SLen Brown goto exit; 71495b482a8SLen Brown } 71595b482a8SLen Brown break; 71695b482a8SLen Brown 71795b482a8SLen Brown default: 71895b482a8SLen Brown 71995b482a8SLen Brown ACPI_ERROR((AE_INFO, 72095b482a8SLen Brown "Invalid conversion sub-opcode")); 72195b482a8SLen Brown return_ACPI_STATUS(AE_BAD_PARAMETER); 72295b482a8SLen Brown } 72395b482a8SLen Brown break; 72495b482a8SLen Brown 72595b482a8SLen Brown case ACPI_RSC_EXIT_EQ: 72695b482a8SLen Brown /* 727ba494beeSBob Moore * control - Exit conversion if equal 72895b482a8SLen Brown */ 72995b482a8SLen Brown if (*ACPI_ADD_PTR(u8, resource, 73095b482a8SLen Brown COMPARE_TARGET(info)) == 73195b482a8SLen Brown COMPARE_VALUE(info)) { 73295b482a8SLen Brown goto exit; 73395b482a8SLen Brown } 73495b482a8SLen Brown break; 73595b482a8SLen Brown 73695b482a8SLen Brown default: 73795b482a8SLen Brown 73895b482a8SLen Brown ACPI_ERROR((AE_INFO, "Invalid conversion opcode")); 73995b482a8SLen Brown return_ACPI_STATUS(AE_BAD_PARAMETER); 74095b482a8SLen Brown } 74195b482a8SLen Brown 74295b482a8SLen Brown count--; 74395b482a8SLen Brown info++; 74495b482a8SLen Brown } 74595b482a8SLen Brown 74695b482a8SLen Brown exit: 74795b482a8SLen Brown return_ACPI_STATUS(AE_OK); 74895b482a8SLen Brown } 74995b482a8SLen Brown 75095b482a8SLen Brown #if 0 75195b482a8SLen Brown /* Previous resource validations */ 75295b482a8SLen Brown 753ba494beeSBob Moore if (aml->ext_address64.revision_ID != AML_RESOURCE_EXTENDED_ADDRESS_REVISION) { 75495b482a8SLen Brown return_ACPI_STATUS(AE_SUPPORT); 75595b482a8SLen Brown } 75695b482a8SLen Brown 75795b482a8SLen Brown if (resource->data.start_dpf.performance_robustness >= 3) { 75895b482a8SLen Brown return_ACPI_STATUS(AE_AML_BAD_RESOURCE_VALUE); 75995b482a8SLen Brown } 76095b482a8SLen Brown 76195b482a8SLen Brown if (((aml->irq.flags & 0x09) == 0x00) || ((aml->irq.flags & 0x09) == 0x09)) { 76295b482a8SLen Brown /* 76395b482a8SLen Brown * Only [active_high, edge_sensitive] or [active_low, level_sensitive] 76495b482a8SLen Brown * polarity/trigger interrupts are allowed (ACPI spec, section 76595b482a8SLen Brown * "IRQ Format"), so 0x00 and 0x09 are illegal. 76695b482a8SLen Brown */ 76795b482a8SLen Brown ACPI_ERROR((AE_INFO, 768f6a22b0bSBob Moore "Invalid interrupt polarity/trigger in resource list, 0x%X", 76995b482a8SLen Brown aml->irq.flags)); 77095b482a8SLen Brown return_ACPI_STATUS(AE_BAD_DATA); 77195b482a8SLen Brown } 77295b482a8SLen Brown 77395b482a8SLen Brown resource->data.extended_irq.interrupt_count = temp8; 77495b482a8SLen Brown if (temp8 < 1) { 77595b482a8SLen Brown 77695b482a8SLen Brown /* Must have at least one IRQ */ 77795b482a8SLen Brown 77895b482a8SLen Brown return_ACPI_STATUS(AE_AML_BAD_RESOURCE_LENGTH); 77995b482a8SLen Brown } 78095b482a8SLen Brown 78195b482a8SLen Brown if (resource->data.dma.transfer == 0x03) { 78295b482a8SLen Brown ACPI_ERROR((AE_INFO, "Invalid DMA.Transfer preference (3)")); 78395b482a8SLen Brown return_ACPI_STATUS(AE_BAD_DATA); 78495b482a8SLen Brown } 78595b482a8SLen Brown #endif 786