0001
0002
0003
0004
0005
0006
0007
0008 #include <acpi/acpi.h>
0009 #include "accommon.h"
0010 #include "acresrc.h"
0011
0012 #define _COMPONENT ACPI_RESOURCES
0013 ACPI_MODULE_NAME("rslist")
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029 acpi_status
0030 acpi_rs_convert_aml_to_resources(u8 * aml,
0031 u32 length,
0032 u32 offset, u8 resource_index, void **context)
0033 {
0034 struct acpi_resource **resource_ptr =
0035 ACPI_CAST_INDIRECT_PTR(struct acpi_resource, context);
0036 struct acpi_resource *resource;
0037 union aml_resource *aml_resource;
0038 struct acpi_rsconvert_info *conversion_table;
0039 acpi_status status;
0040
0041 ACPI_FUNCTION_TRACE(rs_convert_aml_to_resources);
0042
0043
0044
0045
0046
0047 resource = *resource_ptr;
0048 if (ACPI_IS_MISALIGNED(resource)) {
0049 ACPI_WARNING((AE_INFO,
0050 "Misaligned resource pointer %p", resource));
0051 }
0052
0053
0054
0055 aml_resource = ACPI_CAST_PTR(union aml_resource, aml);
0056
0057 if (acpi_ut_get_resource_type(aml) == ACPI_RESOURCE_NAME_SERIAL_BUS) {
0058 if (aml_resource->common_serial_bus.type >
0059 AML_RESOURCE_MAX_SERIALBUSTYPE) {
0060 conversion_table = NULL;
0061 } else {
0062
0063
0064 conversion_table =
0065 acpi_gbl_convert_resource_serial_bus_dispatch
0066 [aml_resource->common_serial_bus.type];
0067 }
0068 } else {
0069 conversion_table =
0070 acpi_gbl_get_resource_dispatch[resource_index];
0071 }
0072
0073 if (!conversion_table) {
0074 ACPI_ERROR((AE_INFO,
0075 "Invalid/unsupported resource descriptor: Type 0x%2.2X",
0076 resource_index));
0077 return_ACPI_STATUS(AE_AML_INVALID_RESOURCE_TYPE);
0078 }
0079
0080
0081
0082 status =
0083 acpi_rs_convert_aml_to_resource(resource, aml_resource,
0084 conversion_table);
0085 if (ACPI_FAILURE(status)) {
0086 ACPI_EXCEPTION((AE_INFO, status,
0087 "Could not convert AML resource (Type 0x%X)",
0088 *aml));
0089 return_ACPI_STATUS(status);
0090 }
0091
0092 if (!resource->length) {
0093 ACPI_EXCEPTION((AE_INFO, status,
0094 "Zero-length resource returned from RsConvertAmlToResource"));
0095 }
0096
0097 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
0098 "Type %.2X, AmlLength %.2X InternalLength %.2X\n",
0099 acpi_ut_get_resource_type(aml), length,
0100 resource->length));
0101
0102
0103
0104 *resource_ptr = ACPI_NEXT_RESOURCE(resource);
0105 return_ACPI_STATUS(AE_OK);
0106 }
0107
0108
0109
0110
0111
0112
0113
0114
0115
0116
0117
0118
0119
0120
0121
0122
0123
0124
0125
0126
0127 acpi_status
0128 acpi_rs_convert_resources_to_aml(struct acpi_resource *resource,
0129 acpi_size aml_size_needed, u8 * output_buffer)
0130 {
0131 u8 *aml = output_buffer;
0132 u8 *end_aml = output_buffer + aml_size_needed;
0133 struct acpi_rsconvert_info *conversion_table;
0134 acpi_status status;
0135
0136 ACPI_FUNCTION_TRACE(rs_convert_resources_to_aml);
0137
0138
0139
0140 while (aml < end_aml) {
0141
0142
0143
0144 if (resource->type > ACPI_RESOURCE_TYPE_MAX) {
0145 ACPI_ERROR((AE_INFO,
0146 "Invalid descriptor type (0x%X) in resource list",
0147 resource->type));
0148 return_ACPI_STATUS(AE_BAD_DATA);
0149 }
0150
0151
0152
0153 if (!resource->length) {
0154 ACPI_ERROR((AE_INFO,
0155 "Invalid zero length descriptor in resource list\n"));
0156 return_ACPI_STATUS(AE_AML_BAD_RESOURCE_LENGTH);
0157 }
0158
0159
0160
0161 if (resource->type == ACPI_RESOURCE_TYPE_SERIAL_BUS) {
0162 if (resource->data.common_serial_bus.type >
0163 AML_RESOURCE_MAX_SERIALBUSTYPE) {
0164 conversion_table = NULL;
0165 } else {
0166
0167
0168 conversion_table =
0169 acpi_gbl_convert_resource_serial_bus_dispatch
0170 [resource->data.common_serial_bus.type];
0171 }
0172 } else {
0173 conversion_table =
0174 acpi_gbl_set_resource_dispatch[resource->type];
0175 }
0176
0177 if (!conversion_table) {
0178 ACPI_ERROR((AE_INFO,
0179 "Invalid/unsupported resource descriptor: Type 0x%2.2X",
0180 resource->type));
0181 return_ACPI_STATUS(AE_AML_INVALID_RESOURCE_TYPE);
0182 }
0183
0184 status = acpi_rs_convert_resource_to_aml(resource,
0185 ACPI_CAST_PTR(union
0186 aml_resource,
0187 aml),
0188 conversion_table);
0189 if (ACPI_FAILURE(status)) {
0190 ACPI_EXCEPTION((AE_INFO, status,
0191 "Could not convert resource (type 0x%X) to AML",
0192 resource->type));
0193 return_ACPI_STATUS(status);
0194 }
0195
0196
0197
0198 status =
0199 acpi_ut_validate_resource(NULL,
0200 ACPI_CAST_PTR(union aml_resource,
0201 aml), NULL);
0202 if (ACPI_FAILURE(status)) {
0203 return_ACPI_STATUS(status);
0204 }
0205
0206
0207
0208 if (resource->type == ACPI_RESOURCE_TYPE_END_TAG) {
0209
0210
0211
0212 return_ACPI_STATUS(AE_OK);
0213 }
0214
0215
0216
0217
0218
0219 aml += acpi_ut_get_descriptor_length(aml);
0220
0221
0222
0223 resource = ACPI_NEXT_RESOURCE(resource);
0224 }
0225
0226
0227
0228 return_ACPI_STATUS(AE_AML_NO_RESOURCE_END_TAG);
0229 }