Erik Schmauss | 9585763 | 2018-03-14 16:13:07 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /******************************************************************************* |
| 3 | * |
| 4 | * Module Name: rscreate - Create resource lists/tables |
| 5 | * |
| 6 | ******************************************************************************/ |
| 7 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | #include <acpi/acpi.h> |
Len Brown | e2f7a77 | 2009-01-09 00:30:03 -0500 | [diff] [blame] | 9 | #include "accommon.h" |
| 10 | #include "acresrc.h" |
| 11 | #include "acnamesp.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | |
| 13 | #define _COMPONENT ACPI_RESOURCES |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 14 | ACPI_MODULE_NAME("rscreate") |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | |
| 16 | /******************************************************************************* |
| 17 | * |
Bob Moore | 0e24317 | 2011-11-16 14:51:01 +0800 | [diff] [blame] | 18 | * FUNCTION: acpi_buffer_to_resource |
| 19 | * |
| 20 | * PARAMETERS: aml_buffer - Pointer to the resource byte stream |
| 21 | * aml_buffer_length - Length of the aml_buffer |
| 22 | * resource_ptr - Where the converted resource is returned |
| 23 | * |
| 24 | * RETURN: Status |
| 25 | * |
| 26 | * DESCRIPTION: Convert a raw AML buffer to a resource list |
| 27 | * |
| 28 | ******************************************************************************/ |
| 29 | acpi_status |
| 30 | acpi_buffer_to_resource(u8 *aml_buffer, |
| 31 | u16 aml_buffer_length, |
| 32 | struct acpi_resource **resource_ptr) |
| 33 | { |
| 34 | acpi_status status; |
| 35 | acpi_size list_size_needed; |
| 36 | void *resource; |
| 37 | void *current_resource_ptr; |
| 38 | |
Bob Moore | 51e3582 | 2014-04-30 10:03:58 +0800 | [diff] [blame] | 39 | ACPI_FUNCTION_TRACE(acpi_buffer_to_resource); |
| 40 | |
Bob Moore | 0e24317 | 2011-11-16 14:51:01 +0800 | [diff] [blame] | 41 | /* |
| 42 | * Note: we allow AE_AML_NO_RESOURCE_END_TAG, since an end tag |
| 43 | * is not required here. |
| 44 | */ |
| 45 | |
| 46 | /* Get the required length for the converted resource */ |
| 47 | |
Bob Moore | 1fad873 | 2015-12-29 13:54:36 +0800 | [diff] [blame] | 48 | status = |
| 49 | acpi_rs_get_list_length(aml_buffer, aml_buffer_length, |
| 50 | &list_size_needed); |
Bob Moore | 0e24317 | 2011-11-16 14:51:01 +0800 | [diff] [blame] | 51 | if (status == AE_AML_NO_RESOURCE_END_TAG) { |
| 52 | status = AE_OK; |
| 53 | } |
| 54 | if (ACPI_FAILURE(status)) { |
Bob Moore | 51e3582 | 2014-04-30 10:03:58 +0800 | [diff] [blame] | 55 | return_ACPI_STATUS(status); |
Bob Moore | 0e24317 | 2011-11-16 14:51:01 +0800 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | /* Allocate a buffer for the converted resource */ |
| 59 | |
| 60 | resource = ACPI_ALLOCATE_ZEROED(list_size_needed); |
| 61 | current_resource_ptr = resource; |
| 62 | if (!resource) { |
Bob Moore | 51e3582 | 2014-04-30 10:03:58 +0800 | [diff] [blame] | 63 | return_ACPI_STATUS(AE_NO_MEMORY); |
Bob Moore | 0e24317 | 2011-11-16 14:51:01 +0800 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | /* Perform the AML-to-Resource conversion */ |
| 67 | |
Bob Moore | 886308e | 2012-12-19 05:38:07 +0000 | [diff] [blame] | 68 | status = acpi_ut_walk_aml_resources(NULL, aml_buffer, aml_buffer_length, |
Bob Moore | 0e24317 | 2011-11-16 14:51:01 +0800 | [diff] [blame] | 69 | acpi_rs_convert_aml_to_resources, |
| 70 | ¤t_resource_ptr); |
| 71 | if (status == AE_AML_NO_RESOURCE_END_TAG) { |
| 72 | status = AE_OK; |
| 73 | } |
| 74 | if (ACPI_FAILURE(status)) { |
| 75 | ACPI_FREE(resource); |
| 76 | } else { |
| 77 | *resource_ptr = resource; |
| 78 | } |
| 79 | |
Bob Moore | 51e3582 | 2014-04-30 10:03:58 +0800 | [diff] [blame] | 80 | return_ACPI_STATUS(status); |
Bob Moore | 0e24317 | 2011-11-16 14:51:01 +0800 | [diff] [blame] | 81 | } |
| 82 | |
Bob Moore | 51e3582 | 2014-04-30 10:03:58 +0800 | [diff] [blame] | 83 | ACPI_EXPORT_SYMBOL(acpi_buffer_to_resource) |
| 84 | |
Bob Moore | 0e24317 | 2011-11-16 14:51:01 +0800 | [diff] [blame] | 85 | /******************************************************************************* |
| 86 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | * FUNCTION: acpi_rs_create_resource_list |
| 88 | * |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 89 | * PARAMETERS: aml_buffer - Pointer to the resource byte stream |
| 90 | * output_buffer - Pointer to the user's buffer |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | * |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 92 | * RETURN: Status: AE_OK if okay, else a valid acpi_status code |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | * If output_buffer is not large enough, output_buffer_length |
| 94 | * indicates how large output_buffer should be, else it |
| 95 | * indicates how may u8 elements of output_buffer are valid. |
| 96 | * |
| 97 | * DESCRIPTION: Takes the byte stream returned from a _CRS, _PRS control method |
| 98 | * execution and parses the stream to create a linked list |
| 99 | * of device resources. |
| 100 | * |
| 101 | ******************************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | acpi_status |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 103 | acpi_rs_create_resource_list(union acpi_operand_object *aml_buffer, |
Bob Moore | 51e3582 | 2014-04-30 10:03:58 +0800 | [diff] [blame] | 104 | struct acpi_buffer *output_buffer) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | { |
| 106 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 107 | acpi_status status; |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 108 | u8 *aml_start; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 109 | acpi_size list_size_needed = 0; |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 110 | u32 aml_buffer_length; |
Bob Moore | 61686124 | 2006-03-17 16:44:00 -0500 | [diff] [blame] | 111 | void *resource; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 113 | ACPI_FUNCTION_TRACE(rs_create_resource_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 115 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "AmlBuffer = %p\n", aml_buffer)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 117 | /* Params already validated, so we don't re-validate here */ |
| 118 | |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 119 | aml_buffer_length = aml_buffer->buffer.length; |
| 120 | aml_start = aml_buffer->buffer.pointer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | |
| 122 | /* |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 123 | * Pass the aml_buffer into a module that can calculate |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | * the buffer size needed for the linked list |
| 125 | */ |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 126 | status = acpi_rs_get_list_length(aml_start, aml_buffer_length, |
| 127 | &list_size_needed); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 129 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Status=%X ListSizeNeeded=%X\n", |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 130 | status, (u32) list_size_needed)); |
| 131 | if (ACPI_FAILURE(status)) { |
| 132 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | /* Validate/Allocate/Clear caller buffer */ |
| 136 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 137 | status = acpi_ut_initialize_buffer(output_buffer, list_size_needed); |
| 138 | if (ACPI_FAILURE(status)) { |
| 139 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | /* Do the conversion */ |
| 143 | |
Bob Moore | 61686124 | 2006-03-17 16:44:00 -0500 | [diff] [blame] | 144 | resource = output_buffer->pointer; |
Bob Moore | 886308e | 2012-12-19 05:38:07 +0000 | [diff] [blame] | 145 | status = acpi_ut_walk_aml_resources(NULL, aml_start, aml_buffer_length, |
Bob Moore | 61686124 | 2006-03-17 16:44:00 -0500 | [diff] [blame] | 146 | acpi_rs_convert_aml_to_resources, |
| 147 | &resource); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 148 | if (ACPI_FAILURE(status)) { |
| 149 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | } |
| 151 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 152 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "OutputBuffer %p Length %X\n", |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 153 | output_buffer->pointer, (u32) output_buffer->length)); |
| 154 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | } |
| 156 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | /******************************************************************************* |
| 158 | * |
| 159 | * FUNCTION: acpi_rs_create_pci_routing_table |
| 160 | * |
Bob Moore | cf48958 | 2012-07-16 09:52:27 +0800 | [diff] [blame] | 161 | * PARAMETERS: package_object - Pointer to a package containing one |
| 162 | * of more ACPI_OPERAND_OBJECTs |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | * output_buffer - Pointer to the user's buffer |
| 164 | * |
| 165 | * RETURN: Status AE_OK if okay, else a valid acpi_status code. |
| 166 | * If the output_buffer is too small, the error will be |
| 167 | * AE_BUFFER_OVERFLOW and output_buffer->Length will point |
| 168 | * to the size buffer needed. |
| 169 | * |
Bob Moore | cf48958 | 2012-07-16 09:52:27 +0800 | [diff] [blame] | 170 | * DESCRIPTION: Takes the union acpi_operand_object package and creates a |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | * linked list of PCI interrupt descriptions |
| 172 | * |
| 173 | * NOTE: It is the caller's responsibility to ensure that the start of the |
| 174 | * output buffer is aligned properly (if necessary). |
| 175 | * |
| 176 | ******************************************************************************/ |
| 177 | |
| 178 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 179 | acpi_rs_create_pci_routing_table(union acpi_operand_object *package_object, |
| 180 | struct acpi_buffer *output_buffer) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 182 | u8 *buffer; |
| 183 | union acpi_operand_object **top_object_list; |
| 184 | union acpi_operand_object **sub_object_list; |
| 185 | union acpi_operand_object *obj_desc; |
| 186 | acpi_size buffer_size_needed = 0; |
| 187 | u32 number_of_elements; |
| 188 | u32 index; |
| 189 | struct acpi_pci_routing_table *user_prt; |
| 190 | struct acpi_namespace_node *node; |
| 191 | acpi_status status; |
| 192 | struct acpi_buffer path_buffer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 194 | ACPI_FUNCTION_TRACE(rs_create_pci_routing_table); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | |
| 196 | /* Params already validated, so we don't re-validate here */ |
| 197 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 198 | /* Get the required buffer length */ |
| 199 | |
Bob Moore | 1fad873 | 2015-12-29 13:54:36 +0800 | [diff] [blame] | 200 | status = |
| 201 | acpi_rs_get_pci_routing_table_length(package_object, |
| 202 | &buffer_size_needed); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 203 | if (ACPI_FAILURE(status)) { |
| 204 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | } |
| 206 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 207 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "BufferSizeNeeded = %X\n", |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 208 | (u32) buffer_size_needed)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | |
| 210 | /* Validate/Allocate/Clear caller buffer */ |
| 211 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 212 | status = acpi_ut_initialize_buffer(output_buffer, buffer_size_needed); |
| 213 | if (ACPI_FAILURE(status)) { |
| 214 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | } |
| 216 | |
| 217 | /* |
Bob Moore | fd0a432 | 2008-06-10 14:27:55 +0800 | [diff] [blame] | 218 | * Loop through the ACPI_INTERNAL_OBJECTS - Each object should be a |
Bob Moore | 5df7e6c | 2010-01-21 10:06:32 +0800 | [diff] [blame] | 219 | * package that in turn contains an u64 Address, a u8 Pin, |
Bob Moore | fd0a432 | 2008-06-10 14:27:55 +0800 | [diff] [blame] | 220 | * a Name, and a u8 source_index. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 222 | top_object_list = package_object->package.elements; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | number_of_elements = package_object->package.count; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 224 | buffer = output_buffer->pointer; |
| 225 | user_prt = ACPI_CAST_PTR(struct acpi_pci_routing_table, buffer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | |
| 227 | for (index = 0; index < number_of_elements; index++) { |
Shaohua Li | 2f894ef | 2007-03-08 03:42:42 -0500 | [diff] [blame] | 228 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | /* |
| 230 | * Point user_prt past this current structure |
| 231 | * |
| 232 | * NOTE: On the first iteration, user_prt->Length will |
| 233 | * be zero because we cleared the return buffer earlier |
| 234 | */ |
| 235 | buffer += user_prt->length; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 236 | user_prt = ACPI_CAST_PTR(struct acpi_pci_routing_table, buffer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | |
| 238 | /* |
Bob Moore | 1fad873 | 2015-12-29 13:54:36 +0800 | [diff] [blame] | 239 | * Fill in the Length field with the information we have at this |
| 240 | * point. The minus four is to subtract the size of the u8 |
| 241 | * Source[4] member because it is added below. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 243 | user_prt->length = (sizeof(struct acpi_pci_routing_table) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | |
Bob Moore | 0a16d12 | 2014-02-26 10:31:18 +0800 | [diff] [blame] | 245 | /* Each subpackage must be of length 4 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | |
| 247 | if ((*top_object_list)->package.count != 4) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 248 | ACPI_ERROR((AE_INFO, |
Bob Moore | f6a22b0 | 2010-03-05 17:56:40 +0800 | [diff] [blame] | 249 | "(PRT[%u]) Need package of length 4, found length %u", |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 250 | index, (*top_object_list)->package.count)); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 251 | return_ACPI_STATUS(AE_AML_PACKAGE_LIMIT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | /* |
Bob Moore | 0a16d12 | 2014-02-26 10:31:18 +0800 | [diff] [blame] | 255 | * Dereference the subpackage. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | * The sub_object_list will now point to an array of the four IRQ |
| 257 | * elements: [Address, Pin, Source, source_index] |
| 258 | */ |
| 259 | sub_object_list = (*top_object_list)->package.elements; |
| 260 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 261 | /* 1) First subobject: Dereference the PRT.Address */ |
| 262 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | obj_desc = sub_object_list[0]; |
Lv Zheng | 83130649 | 2014-02-26 10:29:31 +0800 | [diff] [blame] | 264 | if (!obj_desc || obj_desc->common.type != ACPI_TYPE_INTEGER) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 265 | ACPI_ERROR((AE_INFO, |
Bob Moore | f6a22b0 | 2010-03-05 17:56:40 +0800 | [diff] [blame] | 266 | "(PRT[%u].Address) Need Integer, found %s", |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 267 | index, |
| 268 | acpi_ut_get_object_type_name(obj_desc))); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 269 | return_ACPI_STATUS(AE_BAD_DATA); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | } |
| 271 | |
Bob Moore | fd0a432 | 2008-06-10 14:27:55 +0800 | [diff] [blame] | 272 | user_prt->address = obj_desc->integer.value; |
| 273 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 274 | /* 2) Second subobject: Dereference the PRT.Pin */ |
| 275 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | obj_desc = sub_object_list[1]; |
Lv Zheng | 83130649 | 2014-02-26 10:29:31 +0800 | [diff] [blame] | 277 | if (!obj_desc || obj_desc->common.type != ACPI_TYPE_INTEGER) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 278 | ACPI_ERROR((AE_INFO, |
Bob Moore | f6a22b0 | 2010-03-05 17:56:40 +0800 | [diff] [blame] | 279 | "(PRT[%u].Pin) Need Integer, found %s", |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 280 | index, |
| 281 | acpi_ut_get_object_type_name(obj_desc))); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 282 | return_ACPI_STATUS(AE_BAD_DATA); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | } |
| 284 | |
Bob Moore | fd0a432 | 2008-06-10 14:27:55 +0800 | [diff] [blame] | 285 | user_prt->pin = (u32) obj_desc->integer.value; |
| 286 | |
Shaohua Li | 2f894ef | 2007-03-08 03:42:42 -0500 | [diff] [blame] | 287 | /* |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 288 | * 3) Third subobject: Dereference the PRT.source_name |
| 289 | * The name may be unresolved (slack mode), so allow a null object |
| 290 | */ |
Zhang Rui | 82babbb38 | 2009-04-08 09:44:29 +0800 | [diff] [blame] | 291 | obj_desc = sub_object_list[2]; |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 292 | if (obj_desc) { |
Bob Moore | 3371c19 | 2009-02-18 14:44:03 +0800 | [diff] [blame] | 293 | switch (obj_desc->common.type) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 294 | case ACPI_TYPE_LOCAL_REFERENCE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | |
Bob Moore | 1044f1f | 2008-09-27 11:08:41 +0800 | [diff] [blame] | 296 | if (obj_desc->reference.class != |
| 297 | ACPI_REFCLASS_NAME) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 298 | ACPI_ERROR((AE_INFO, |
Bob Moore | f6a22b0 | 2010-03-05 17:56:40 +0800 | [diff] [blame] | 299 | "(PRT[%u].Source) Need name, found Reference Class 0x%X", |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 300 | index, |
Bob Moore | 1044f1f | 2008-09-27 11:08:41 +0800 | [diff] [blame] | 301 | obj_desc->reference.class)); |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 302 | return_ACPI_STATUS(AE_BAD_DATA); |
| 303 | } |
| 304 | |
| 305 | node = obj_desc->reference.node; |
| 306 | |
| 307 | /* Use *remaining* length of the buffer as max for pathname */ |
| 308 | |
| 309 | path_buffer.length = output_buffer->length - |
| 310 | (u32) ((u8 *) user_prt->source - |
| 311 | (u8 *) output_buffer->pointer); |
| 312 | path_buffer.pointer = user_prt->source; |
| 313 | |
Lv Zheng | f5c1e1c | 2016-05-05 12:57:53 +0800 | [diff] [blame] | 314 | status = acpi_ns_handle_to_pathname((acpi_handle)node, &path_buffer, FALSE); |
Bob Moore | aaf7566 | 2019-10-25 14:36:51 -0700 | [diff] [blame] | 315 | if (ACPI_FAILURE(status)) { |
| 316 | return_ACPI_STATUS(status); |
| 317 | } |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 318 | |
| 319 | /* +1 to include null terminator */ |
| 320 | |
| 321 | user_prt->length += |
Bob Moore | 4fa4616 | 2015-07-01 14:45:11 +0800 | [diff] [blame] | 322 | (u32)strlen(user_prt->source) + 1; |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 323 | break; |
| 324 | |
| 325 | case ACPI_TYPE_STRING: |
| 326 | |
Bob Moore | 4fa4616 | 2015-07-01 14:45:11 +0800 | [diff] [blame] | 327 | strcpy(user_prt->source, |
| 328 | obj_desc->string.pointer); |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 329 | |
| 330 | /* |
| 331 | * Add to the Length field the length of the string |
| 332 | * (add 1 for terminator) |
| 333 | */ |
| 334 | user_prt->length += obj_desc->string.length + 1; |
| 335 | break; |
| 336 | |
| 337 | case ACPI_TYPE_INTEGER: |
| 338 | /* |
Bob Moore | 1fad873 | 2015-12-29 13:54:36 +0800 | [diff] [blame] | 339 | * If this is a number, then the Source Name is NULL, since |
| 340 | * the entire buffer was zeroed out, we can leave this alone. |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 341 | * |
| 342 | * Add to the Length field the length of the u32 NULL |
| 343 | */ |
| 344 | user_prt->length += sizeof(u32); |
| 345 | break; |
| 346 | |
| 347 | default: |
| 348 | |
| 349 | ACPI_ERROR((AE_INFO, |
Bob Moore | f6a22b0 | 2010-03-05 17:56:40 +0800 | [diff] [blame] | 350 | "(PRT[%u].Source) Need Ref/String/Integer, found %s", |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 351 | index, |
| 352 | acpi_ut_get_object_type_name |
| 353 | (obj_desc))); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 354 | return_ACPI_STATUS(AE_BAD_DATA); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | } |
| 357 | |
| 358 | /* Now align the current length */ |
| 359 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 360 | user_prt->length = |
Bob Moore | 958dd24 | 2006-05-12 17:12:00 -0400 | [diff] [blame] | 361 | (u32) ACPI_ROUND_UP_TO_64BIT(user_prt->length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 363 | /* 4) Fourth subobject: Dereference the PRT.source_index */ |
| 364 | |
Zhang Rui | 82babbb38 | 2009-04-08 09:44:29 +0800 | [diff] [blame] | 365 | obj_desc = sub_object_list[3]; |
Lv Zheng | 83130649 | 2014-02-26 10:29:31 +0800 | [diff] [blame] | 366 | if (!obj_desc || obj_desc->common.type != ACPI_TYPE_INTEGER) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 367 | ACPI_ERROR((AE_INFO, |
Bob Moore | f6a22b0 | 2010-03-05 17:56:40 +0800 | [diff] [blame] | 368 | "(PRT[%u].SourceIndex) Need Integer, found %s", |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 369 | index, |
| 370 | acpi_ut_get_object_type_name(obj_desc))); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 371 | return_ACPI_STATUS(AE_BAD_DATA); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | } |
| 373 | |
Bob Moore | fd0a432 | 2008-06-10 14:27:55 +0800 | [diff] [blame] | 374 | user_prt->source_index = (u32) obj_desc->integer.value; |
| 375 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | /* Point to the next union acpi_operand_object in the top level package */ |
| 377 | |
| 378 | top_object_list++; |
| 379 | } |
| 380 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 381 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "OutputBuffer %p Length %X\n", |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 382 | output_buffer->pointer, (u32) output_buffer->length)); |
| 383 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | } |
| 385 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | /******************************************************************************* |
| 387 | * |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 388 | * FUNCTION: acpi_rs_create_aml_resources |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | * |
Lv Zheng | 9a0a359 | 2013-11-21 12:17:34 +0800 | [diff] [blame] | 390 | * PARAMETERS: resource_list - Pointer to the resource list buffer |
| 391 | * output_buffer - Where the AML buffer is returned |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | * |
| 393 | * RETURN: Status AE_OK if okay, else a valid acpi_status code. |
| 394 | * If the output_buffer is too small, the error will be |
| 395 | * AE_BUFFER_OVERFLOW and output_buffer->Length will point |
| 396 | * to the size buffer needed. |
| 397 | * |
Lv Zheng | 9a0a359 | 2013-11-21 12:17:34 +0800 | [diff] [blame] | 398 | * DESCRIPTION: Converts a list of device resources to an AML bytestream |
| 399 | * to be used as input for the _SRS control method. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | * |
| 401 | ******************************************************************************/ |
| 402 | |
| 403 | acpi_status |
Lv Zheng | 9a0a359 | 2013-11-21 12:17:34 +0800 | [diff] [blame] | 404 | acpi_rs_create_aml_resources(struct acpi_buffer *resource_list, |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 405 | struct acpi_buffer *output_buffer) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 407 | acpi_status status; |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 408 | acpi_size aml_size_needed = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 410 | ACPI_FUNCTION_TRACE(rs_create_aml_resources); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | |
Lv Zheng | 9a0a359 | 2013-11-21 12:17:34 +0800 | [diff] [blame] | 412 | /* Params already validated, no need to re-validate here */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | |
Lv Zheng | 9a0a359 | 2013-11-21 12:17:34 +0800 | [diff] [blame] | 414 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "ResourceList Buffer = %p\n", |
| 415 | resource_list->pointer)); |
| 416 | |
| 417 | /* Get the buffer size needed for the AML byte stream */ |
| 418 | |
Bob Moore | 1fad873 | 2015-12-29 13:54:36 +0800 | [diff] [blame] | 419 | status = |
| 420 | acpi_rs_get_aml_length(resource_list->pointer, |
| 421 | resource_list->length, &aml_size_needed); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 423 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "AmlSizeNeeded=%X, %s\n", |
Lv Zheng | 3e8214e | 2012-12-19 05:37:15 +0000 | [diff] [blame] | 424 | (u32)aml_size_needed, acpi_format_exception(status))); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 425 | if (ACPI_FAILURE(status)) { |
| 426 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | } |
| 428 | |
| 429 | /* Validate/Allocate/Clear caller buffer */ |
| 430 | |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 431 | status = acpi_ut_initialize_buffer(output_buffer, aml_size_needed); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 432 | if (ACPI_FAILURE(status)) { |
| 433 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | } |
| 435 | |
| 436 | /* Do the conversion */ |
| 437 | |
Lv Zheng | 9a0a359 | 2013-11-21 12:17:34 +0800 | [diff] [blame] | 438 | status = acpi_rs_convert_resources_to_aml(resource_list->pointer, |
| 439 | aml_size_needed, |
| 440 | output_buffer->pointer); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 441 | if (ACPI_FAILURE(status)) { |
| 442 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | } |
| 444 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 445 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "OutputBuffer %p Length %X\n", |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 446 | output_buffer->pointer, (u32) output_buffer->length)); |
| 447 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | } |