blob: c659b54985a5f0991c96ae6af5bd414041f17c77 [file] [log] [blame]
Erik Schmauss95857632018-03-14 16:13:07 -07001// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*******************************************************************************
3 *
4 * Module Name: rscreate - Create resource lists/tables
5 *
6 ******************************************************************************/
7
Linus Torvalds1da177e2005-04-16 15:20:36 -07008#include <acpi/acpi.h>
Len Browne2f7a772009-01-09 00:30:03 -05009#include "accommon.h"
10#include "acresrc.h"
11#include "acnamesp.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070012
13#define _COMPONENT ACPI_RESOURCES
Len Brown4be44fc2005-08-05 00:44:28 -040014ACPI_MODULE_NAME("rscreate")
Linus Torvalds1da177e2005-04-16 15:20:36 -070015
16/*******************************************************************************
17 *
Bob Moore0e243172011-11-16 14:51:01 +080018 * 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 ******************************************************************************/
29acpi_status
30acpi_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 Moore51e35822014-04-30 10:03:58 +080039 ACPI_FUNCTION_TRACE(acpi_buffer_to_resource);
40
Bob Moore0e243172011-11-16 14:51:01 +080041 /*
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 Moore1fad8732015-12-29 13:54:36 +080048 status =
49 acpi_rs_get_list_length(aml_buffer, aml_buffer_length,
50 &list_size_needed);
Bob Moore0e243172011-11-16 14:51:01 +080051 if (status == AE_AML_NO_RESOURCE_END_TAG) {
52 status = AE_OK;
53 }
54 if (ACPI_FAILURE(status)) {
Bob Moore51e35822014-04-30 10:03:58 +080055 return_ACPI_STATUS(status);
Bob Moore0e243172011-11-16 14:51:01 +080056 }
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 Moore51e35822014-04-30 10:03:58 +080063 return_ACPI_STATUS(AE_NO_MEMORY);
Bob Moore0e243172011-11-16 14:51:01 +080064 }
65
66 /* Perform the AML-to-Resource conversion */
67
Bob Moore886308e2012-12-19 05:38:07 +000068 status = acpi_ut_walk_aml_resources(NULL, aml_buffer, aml_buffer_length,
Bob Moore0e243172011-11-16 14:51:01 +080069 acpi_rs_convert_aml_to_resources,
70 &current_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 Moore51e35822014-04-30 10:03:58 +080080 return_ACPI_STATUS(status);
Bob Moore0e243172011-11-16 14:51:01 +080081}
82
Bob Moore51e35822014-04-30 10:03:58 +080083ACPI_EXPORT_SYMBOL(acpi_buffer_to_resource)
84
Bob Moore0e243172011-11-16 14:51:01 +080085/*******************************************************************************
86 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 * FUNCTION: acpi_rs_create_resource_list
88 *
Bob Moore50eca3e2005-09-30 19:03:00 -040089 * PARAMETERS: aml_buffer - Pointer to the resource byte stream
90 * output_buffer - Pointer to the user's buffer
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 *
Bob Moore50eca3e2005-09-30 19:03:00 -040092 * RETURN: Status: AE_OK if okay, else a valid acpi_status code
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 * 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 Torvalds1da177e2005-04-16 15:20:36 -0700102acpi_status
Bob Moore50eca3e2005-09-30 19:03:00 -0400103acpi_rs_create_resource_list(union acpi_operand_object *aml_buffer,
Bob Moore51e35822014-04-30 10:03:58 +0800104 struct acpi_buffer *output_buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105{
106
Len Brown4be44fc2005-08-05 00:44:28 -0400107 acpi_status status;
Bob Moore50eca3e2005-09-30 19:03:00 -0400108 u8 *aml_start;
Len Brown4be44fc2005-08-05 00:44:28 -0400109 acpi_size list_size_needed = 0;
Bob Moore50eca3e2005-09-30 19:03:00 -0400110 u32 aml_buffer_length;
Bob Moore616861242006-03-17 16:44:00 -0500111 void *resource;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112
Bob Mooreb229cf92006-04-21 17:15:00 -0400113 ACPI_FUNCTION_TRACE(rs_create_resource_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114
Bob Mooreb229cf92006-04-21 17:15:00 -0400115 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "AmlBuffer = %p\n", aml_buffer));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116
Robert Moore44f6c012005-04-18 22:49:35 -0400117 /* Params already validated, so we don't re-validate here */
118
Bob Moore50eca3e2005-09-30 19:03:00 -0400119 aml_buffer_length = aml_buffer->buffer.length;
120 aml_start = aml_buffer->buffer.pointer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121
122 /*
Bob Moore50eca3e2005-09-30 19:03:00 -0400123 * Pass the aml_buffer into a module that can calculate
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 * the buffer size needed for the linked list
125 */
Bob Moore50eca3e2005-09-30 19:03:00 -0400126 status = acpi_rs_get_list_length(aml_start, aml_buffer_length,
127 &list_size_needed);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128
Bob Mooreb229cf92006-04-21 17:15:00 -0400129 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Status=%X ListSizeNeeded=%X\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400130 status, (u32) list_size_needed));
131 if (ACPI_FAILURE(status)) {
132 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 }
134
135 /* Validate/Allocate/Clear caller buffer */
136
Len Brown4be44fc2005-08-05 00:44:28 -0400137 status = acpi_ut_initialize_buffer(output_buffer, list_size_needed);
138 if (ACPI_FAILURE(status)) {
139 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 }
141
142 /* Do the conversion */
143
Bob Moore616861242006-03-17 16:44:00 -0500144 resource = output_buffer->pointer;
Bob Moore886308e2012-12-19 05:38:07 +0000145 status = acpi_ut_walk_aml_resources(NULL, aml_start, aml_buffer_length,
Bob Moore616861242006-03-17 16:44:00 -0500146 acpi_rs_convert_aml_to_resources,
147 &resource);
Len Brown4be44fc2005-08-05 00:44:28 -0400148 if (ACPI_FAILURE(status)) {
149 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 }
151
Bob Mooreb229cf92006-04-21 17:15:00 -0400152 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "OutputBuffer %p Length %X\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400153 output_buffer->pointer, (u32) output_buffer->length));
154 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155}
156
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157/*******************************************************************************
158 *
159 * FUNCTION: acpi_rs_create_pci_routing_table
160 *
Bob Moorecf489582012-07-16 09:52:27 +0800161 * PARAMETERS: package_object - Pointer to a package containing one
162 * of more ACPI_OPERAND_OBJECTs
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 * 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 Moorecf489582012-07-16 09:52:27 +0800170 * DESCRIPTION: Takes the union acpi_operand_object package and creates a
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171 * 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
178acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400179acpi_rs_create_pci_routing_table(union acpi_operand_object *package_object,
180 struct acpi_buffer *output_buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181{
Len Brown4be44fc2005-08-05 00:44:28 -0400182 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 Torvalds1da177e2005-04-16 15:20:36 -0700193
Bob Mooreb229cf92006-04-21 17:15:00 -0400194 ACPI_FUNCTION_TRACE(rs_create_pci_routing_table);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195
196 /* Params already validated, so we don't re-validate here */
197
Robert Moore44f6c012005-04-18 22:49:35 -0400198 /* Get the required buffer length */
199
Bob Moore1fad8732015-12-29 13:54:36 +0800200 status =
201 acpi_rs_get_pci_routing_table_length(package_object,
202 &buffer_size_needed);
Len Brown4be44fc2005-08-05 00:44:28 -0400203 if (ACPI_FAILURE(status)) {
204 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 }
206
Bob Mooreb229cf92006-04-21 17:15:00 -0400207 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "BufferSizeNeeded = %X\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400208 (u32) buffer_size_needed));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209
210 /* Validate/Allocate/Clear caller buffer */
211
Len Brown4be44fc2005-08-05 00:44:28 -0400212 status = acpi_ut_initialize_buffer(output_buffer, buffer_size_needed);
213 if (ACPI_FAILURE(status)) {
214 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215 }
216
217 /*
Bob Moorefd0a4322008-06-10 14:27:55 +0800218 * Loop through the ACPI_INTERNAL_OBJECTS - Each object should be a
Bob Moore5df7e6c2010-01-21 10:06:32 +0800219 * package that in turn contains an u64 Address, a u8 Pin,
Bob Moorefd0a4322008-06-10 14:27:55 +0800220 * a Name, and a u8 source_index.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221 */
Len Brown4be44fc2005-08-05 00:44:28 -0400222 top_object_list = package_object->package.elements;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 number_of_elements = package_object->package.count;
Len Brown4be44fc2005-08-05 00:44:28 -0400224 buffer = output_buffer->pointer;
225 user_prt = ACPI_CAST_PTR(struct acpi_pci_routing_table, buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226
227 for (index = 0; index < number_of_elements; index++) {
Shaohua Li2f894ef2007-03-08 03:42:42 -0500228
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229 /*
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 Brown4be44fc2005-08-05 00:44:28 -0400236 user_prt = ACPI_CAST_PTR(struct acpi_pci_routing_table, buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237
238 /*
Bob Moore1fad8732015-12-29 13:54:36 +0800239 * 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 Torvalds1da177e2005-04-16 15:20:36 -0700242 */
Len Brown4be44fc2005-08-05 00:44:28 -0400243 user_prt->length = (sizeof(struct acpi_pci_routing_table) - 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244
Bob Moore0a16d122014-02-26 10:31:18 +0800245 /* Each subpackage must be of length 4 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246
247 if ((*top_object_list)->package.count != 4) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500248 ACPI_ERROR((AE_INFO,
Bob Mooref6a22b02010-03-05 17:56:40 +0800249 "(PRT[%u]) Need package of length 4, found length %u",
Bob Mooreb8e4d892006-01-27 16:43:00 -0500250 index, (*top_object_list)->package.count));
Len Brown4be44fc2005-08-05 00:44:28 -0400251 return_ACPI_STATUS(AE_AML_PACKAGE_LIMIT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252 }
253
254 /*
Bob Moore0a16d122014-02-26 10:31:18 +0800255 * Dereference the subpackage.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256 * 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 Moore44f6c012005-04-18 22:49:35 -0400261 /* 1) First subobject: Dereference the PRT.Address */
262
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 obj_desc = sub_object_list[0];
Lv Zheng831306492014-02-26 10:29:31 +0800264 if (!obj_desc || obj_desc->common.type != ACPI_TYPE_INTEGER) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500265 ACPI_ERROR((AE_INFO,
Bob Mooref6a22b02010-03-05 17:56:40 +0800266 "(PRT[%u].Address) Need Integer, found %s",
Bob Mooreb8e4d892006-01-27 16:43:00 -0500267 index,
268 acpi_ut_get_object_type_name(obj_desc)));
Len Brown4be44fc2005-08-05 00:44:28 -0400269 return_ACPI_STATUS(AE_BAD_DATA);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 }
271
Bob Moorefd0a4322008-06-10 14:27:55 +0800272 user_prt->address = obj_desc->integer.value;
273
Robert Moore44f6c012005-04-18 22:49:35 -0400274 /* 2) Second subobject: Dereference the PRT.Pin */
275
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 obj_desc = sub_object_list[1];
Lv Zheng831306492014-02-26 10:29:31 +0800277 if (!obj_desc || obj_desc->common.type != ACPI_TYPE_INTEGER) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500278 ACPI_ERROR((AE_INFO,
Bob Mooref6a22b02010-03-05 17:56:40 +0800279 "(PRT[%u].Pin) Need Integer, found %s",
Bob Mooreb8e4d892006-01-27 16:43:00 -0500280 index,
281 acpi_ut_get_object_type_name(obj_desc)));
Len Brown4be44fc2005-08-05 00:44:28 -0400282 return_ACPI_STATUS(AE_BAD_DATA);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283 }
284
Bob Moorefd0a4322008-06-10 14:27:55 +0800285 user_prt->pin = (u32) obj_desc->integer.value;
286
Shaohua Li2f894ef2007-03-08 03:42:42 -0500287 /*
Bob Mooreb8e4d892006-01-27 16:43:00 -0500288 * 3) Third subobject: Dereference the PRT.source_name
289 * The name may be unresolved (slack mode), so allow a null object
290 */
Zhang Rui82babbb382009-04-08 09:44:29 +0800291 obj_desc = sub_object_list[2];
Bob Mooreb8e4d892006-01-27 16:43:00 -0500292 if (obj_desc) {
Bob Moore3371c192009-02-18 14:44:03 +0800293 switch (obj_desc->common.type) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500294 case ACPI_TYPE_LOCAL_REFERENCE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295
Bob Moore1044f1f2008-09-27 11:08:41 +0800296 if (obj_desc->reference.class !=
297 ACPI_REFCLASS_NAME) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500298 ACPI_ERROR((AE_INFO,
Bob Mooref6a22b02010-03-05 17:56:40 +0800299 "(PRT[%u].Source) Need name, found Reference Class 0x%X",
Bob Mooreb8e4d892006-01-27 16:43:00 -0500300 index,
Bob Moore1044f1f2008-09-27 11:08:41 +0800301 obj_desc->reference.class));
Bob Mooreb8e4d892006-01-27 16:43:00 -0500302 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 Zhengf5c1e1c2016-05-05 12:57:53 +0800314 status = acpi_ns_handle_to_pathname((acpi_handle)node, &path_buffer, FALSE);
Bob Mooreaaf75662019-10-25 14:36:51 -0700315 if (ACPI_FAILURE(status)) {
316 return_ACPI_STATUS(status);
317 }
Bob Mooreb8e4d892006-01-27 16:43:00 -0500318
319 /* +1 to include null terminator */
320
321 user_prt->length +=
Bob Moore4fa46162015-07-01 14:45:11 +0800322 (u32)strlen(user_prt->source) + 1;
Bob Mooreb8e4d892006-01-27 16:43:00 -0500323 break;
324
325 case ACPI_TYPE_STRING:
326
Bob Moore4fa46162015-07-01 14:45:11 +0800327 strcpy(user_prt->source,
328 obj_desc->string.pointer);
Bob Mooreb8e4d892006-01-27 16:43:00 -0500329
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 Moore1fad8732015-12-29 13:54:36 +0800339 * 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 Mooreb8e4d892006-01-27 16:43:00 -0500341 *
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 Mooref6a22b02010-03-05 17:56:40 +0800350 "(PRT[%u].Source) Need Ref/String/Integer, found %s",
Bob Mooreb8e4d892006-01-27 16:43:00 -0500351 index,
352 acpi_ut_get_object_type_name
353 (obj_desc)));
Len Brown4be44fc2005-08-05 00:44:28 -0400354 return_ACPI_STATUS(AE_BAD_DATA);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356 }
357
358 /* Now align the current length */
359
Len Brown4be44fc2005-08-05 00:44:28 -0400360 user_prt->length =
Bob Moore958dd242006-05-12 17:12:00 -0400361 (u32) ACPI_ROUND_UP_TO_64BIT(user_prt->length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362
Robert Moore44f6c012005-04-18 22:49:35 -0400363 /* 4) Fourth subobject: Dereference the PRT.source_index */
364
Zhang Rui82babbb382009-04-08 09:44:29 +0800365 obj_desc = sub_object_list[3];
Lv Zheng831306492014-02-26 10:29:31 +0800366 if (!obj_desc || obj_desc->common.type != ACPI_TYPE_INTEGER) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500367 ACPI_ERROR((AE_INFO,
Bob Mooref6a22b02010-03-05 17:56:40 +0800368 "(PRT[%u].SourceIndex) Need Integer, found %s",
Bob Mooreb8e4d892006-01-27 16:43:00 -0500369 index,
370 acpi_ut_get_object_type_name(obj_desc)));
Len Brown4be44fc2005-08-05 00:44:28 -0400371 return_ACPI_STATUS(AE_BAD_DATA);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 }
373
Bob Moorefd0a4322008-06-10 14:27:55 +0800374 user_prt->source_index = (u32) obj_desc->integer.value;
375
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 /* Point to the next union acpi_operand_object in the top level package */
377
378 top_object_list++;
379 }
380
Bob Mooreb229cf92006-04-21 17:15:00 -0400381 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "OutputBuffer %p Length %X\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400382 output_buffer->pointer, (u32) output_buffer->length));
383 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384}
385
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386/*******************************************************************************
387 *
Bob Moore50eca3e2005-09-30 19:03:00 -0400388 * FUNCTION: acpi_rs_create_aml_resources
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 *
Lv Zheng9a0a3592013-11-21 12:17:34 +0800390 * PARAMETERS: resource_list - Pointer to the resource list buffer
391 * output_buffer - Where the AML buffer is returned
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392 *
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 Zheng9a0a3592013-11-21 12:17:34 +0800398 * DESCRIPTION: Converts a list of device resources to an AML bytestream
399 * to be used as input for the _SRS control method.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 *
401 ******************************************************************************/
402
403acpi_status
Lv Zheng9a0a3592013-11-21 12:17:34 +0800404acpi_rs_create_aml_resources(struct acpi_buffer *resource_list,
Bob Moore50eca3e2005-09-30 19:03:00 -0400405 struct acpi_buffer *output_buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406{
Len Brown4be44fc2005-08-05 00:44:28 -0400407 acpi_status status;
Bob Moore50eca3e2005-09-30 19:03:00 -0400408 acpi_size aml_size_needed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409
Bob Mooreb229cf92006-04-21 17:15:00 -0400410 ACPI_FUNCTION_TRACE(rs_create_aml_resources);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411
Lv Zheng9a0a3592013-11-21 12:17:34 +0800412 /* Params already validated, no need to re-validate here */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413
Lv Zheng9a0a3592013-11-21 12:17:34 +0800414 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 Moore1fad8732015-12-29 13:54:36 +0800419 status =
420 acpi_rs_get_aml_length(resource_list->pointer,
421 resource_list->length, &aml_size_needed);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422
Bob Mooreb229cf92006-04-21 17:15:00 -0400423 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "AmlSizeNeeded=%X, %s\n",
Lv Zheng3e8214e2012-12-19 05:37:15 +0000424 (u32)aml_size_needed, acpi_format_exception(status)));
Len Brown4be44fc2005-08-05 00:44:28 -0400425 if (ACPI_FAILURE(status)) {
426 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 }
428
429 /* Validate/Allocate/Clear caller buffer */
430
Bob Moore50eca3e2005-09-30 19:03:00 -0400431 status = acpi_ut_initialize_buffer(output_buffer, aml_size_needed);
Len Brown4be44fc2005-08-05 00:44:28 -0400432 if (ACPI_FAILURE(status)) {
433 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434 }
435
436 /* Do the conversion */
437
Lv Zheng9a0a3592013-11-21 12:17:34 +0800438 status = acpi_rs_convert_resources_to_aml(resource_list->pointer,
439 aml_size_needed,
440 output_buffer->pointer);
Len Brown4be44fc2005-08-05 00:44:28 -0400441 if (ACPI_FAILURE(status)) {
442 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443 }
444
Bob Mooreb229cf92006-04-21 17:15:00 -0400445 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "OutputBuffer %p Length %X\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400446 output_buffer->pointer, (u32) output_buffer->length));
447 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448}