195857638SErik Schmauss // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
295b482a8SLen Brown /*******************************************************************************
395b482a8SLen Brown *
495b482a8SLen Brown * Module Name: rscreate - Create resource lists/tables
595b482a8SLen Brown *
695b482a8SLen Brown ******************************************************************************/
795b482a8SLen Brown
895b482a8SLen Brown #include <acpi/acpi.h>
9e2f7a777SLen Brown #include "accommon.h"
10e2f7a777SLen Brown #include "acresrc.h"
11e2f7a777SLen Brown #include "acnamesp.h"
1295b482a8SLen Brown
1395b482a8SLen Brown #define _COMPONENT ACPI_RESOURCES
1495b482a8SLen Brown ACPI_MODULE_NAME("rscreate")
1595b482a8SLen Brown
1695b482a8SLen Brown /*******************************************************************************
1795b482a8SLen Brown *
180e243178SBob Moore * FUNCTION: acpi_buffer_to_resource
190e243178SBob Moore *
200e243178SBob Moore * PARAMETERS: aml_buffer - Pointer to the resource byte stream
210e243178SBob Moore * aml_buffer_length - Length of the aml_buffer
220e243178SBob Moore * resource_ptr - Where the converted resource is returned
230e243178SBob Moore *
240e243178SBob Moore * RETURN: Status
250e243178SBob Moore *
260e243178SBob Moore * DESCRIPTION: Convert a raw AML buffer to a resource list
270e243178SBob Moore *
280e243178SBob Moore ******************************************************************************/
290e243178SBob Moore acpi_status
acpi_buffer_to_resource(u8 * aml_buffer,u16 aml_buffer_length,struct acpi_resource ** resource_ptr)300e243178SBob Moore acpi_buffer_to_resource(u8 *aml_buffer,
310e243178SBob Moore u16 aml_buffer_length,
320e243178SBob Moore struct acpi_resource **resource_ptr)
330e243178SBob Moore {
340e243178SBob Moore acpi_status status;
350e243178SBob Moore acpi_size list_size_needed;
360e243178SBob Moore void *resource;
370e243178SBob Moore void *current_resource_ptr;
380e243178SBob Moore
3951e35823SBob Moore ACPI_FUNCTION_TRACE(acpi_buffer_to_resource);
4051e35823SBob Moore
410e243178SBob Moore /*
420e243178SBob Moore * Note: we allow AE_AML_NO_RESOURCE_END_TAG, since an end tag
430e243178SBob Moore * is not required here.
440e243178SBob Moore */
450e243178SBob Moore
460e243178SBob Moore /* Get the required length for the converted resource */
470e243178SBob Moore
481fad8738SBob Moore status =
491fad8738SBob Moore acpi_rs_get_list_length(aml_buffer, aml_buffer_length,
500e243178SBob Moore &list_size_needed);
510e243178SBob Moore if (status == AE_AML_NO_RESOURCE_END_TAG) {
520e243178SBob Moore status = AE_OK;
530e243178SBob Moore }
540e243178SBob Moore if (ACPI_FAILURE(status)) {
5551e35823SBob Moore return_ACPI_STATUS(status);
560e243178SBob Moore }
570e243178SBob Moore
580e243178SBob Moore /* Allocate a buffer for the converted resource */
590e243178SBob Moore
600e243178SBob Moore resource = ACPI_ALLOCATE_ZEROED(list_size_needed);
610e243178SBob Moore current_resource_ptr = resource;
620e243178SBob Moore if (!resource) {
6351e35823SBob Moore return_ACPI_STATUS(AE_NO_MEMORY);
640e243178SBob Moore }
650e243178SBob Moore
660e243178SBob Moore /* Perform the AML-to-Resource conversion */
670e243178SBob Moore
68886308ecSBob Moore status = acpi_ut_walk_aml_resources(NULL, aml_buffer, aml_buffer_length,
690e243178SBob Moore acpi_rs_convert_aml_to_resources,
700e243178SBob Moore ¤t_resource_ptr);
710e243178SBob Moore if (status == AE_AML_NO_RESOURCE_END_TAG) {
720e243178SBob Moore status = AE_OK;
730e243178SBob Moore }
740e243178SBob Moore if (ACPI_FAILURE(status)) {
750e243178SBob Moore ACPI_FREE(resource);
760e243178SBob Moore } else {
770e243178SBob Moore *resource_ptr = resource;
780e243178SBob Moore }
790e243178SBob Moore
8051e35823SBob Moore return_ACPI_STATUS(status);
810e243178SBob Moore }
820e243178SBob Moore
ACPI_EXPORT_SYMBOL(acpi_buffer_to_resource)8351e35823SBob Moore ACPI_EXPORT_SYMBOL(acpi_buffer_to_resource)
8451e35823SBob Moore
850e243178SBob Moore /*******************************************************************************
860e243178SBob Moore *
8795b482a8SLen Brown * FUNCTION: acpi_rs_create_resource_list
8895b482a8SLen Brown *
8995b482a8SLen Brown * PARAMETERS: aml_buffer - Pointer to the resource byte stream
9095b482a8SLen Brown * output_buffer - Pointer to the user's buffer
9195b482a8SLen Brown *
9295b482a8SLen Brown * RETURN: Status: AE_OK if okay, else a valid acpi_status code
9395b482a8SLen Brown * If output_buffer is not large enough, output_buffer_length
9495b482a8SLen Brown * indicates how large output_buffer should be, else it
9595b482a8SLen Brown * indicates how may u8 elements of output_buffer are valid.
9695b482a8SLen Brown *
9795b482a8SLen Brown * DESCRIPTION: Takes the byte stream returned from a _CRS, _PRS control method
9895b482a8SLen Brown * execution and parses the stream to create a linked list
9995b482a8SLen Brown * of device resources.
10095b482a8SLen Brown *
10195b482a8SLen Brown ******************************************************************************/
10295b482a8SLen Brown acpi_status
10395b482a8SLen Brown acpi_rs_create_resource_list(union acpi_operand_object *aml_buffer,
10495b482a8SLen Brown struct acpi_buffer *output_buffer)
10595b482a8SLen Brown {
10695b482a8SLen Brown
10795b482a8SLen Brown acpi_status status;
10895b482a8SLen Brown u8 *aml_start;
10995b482a8SLen Brown acpi_size list_size_needed = 0;
11095b482a8SLen Brown u32 aml_buffer_length;
11195b482a8SLen Brown void *resource;
11295b482a8SLen Brown
11395b482a8SLen Brown ACPI_FUNCTION_TRACE(rs_create_resource_list);
11495b482a8SLen Brown
11595b482a8SLen Brown ACPI_DEBUG_PRINT((ACPI_DB_INFO, "AmlBuffer = %p\n", aml_buffer));
11695b482a8SLen Brown
11795b482a8SLen Brown /* Params already validated, so we don't re-validate here */
11895b482a8SLen Brown
11995b482a8SLen Brown aml_buffer_length = aml_buffer->buffer.length;
12095b482a8SLen Brown aml_start = aml_buffer->buffer.pointer;
12195b482a8SLen Brown
12295b482a8SLen Brown /*
12395b482a8SLen Brown * Pass the aml_buffer into a module that can calculate
12495b482a8SLen Brown * the buffer size needed for the linked list
12595b482a8SLen Brown */
12695b482a8SLen Brown status = acpi_rs_get_list_length(aml_start, aml_buffer_length,
12795b482a8SLen Brown &list_size_needed);
12895b482a8SLen Brown
12995b482a8SLen Brown ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Status=%X ListSizeNeeded=%X\n",
13095b482a8SLen Brown status, (u32) list_size_needed));
13195b482a8SLen Brown if (ACPI_FAILURE(status)) {
13295b482a8SLen Brown return_ACPI_STATUS(status);
13395b482a8SLen Brown }
13495b482a8SLen Brown
13595b482a8SLen Brown /* Validate/Allocate/Clear caller buffer */
13695b482a8SLen Brown
13795b482a8SLen Brown status = acpi_ut_initialize_buffer(output_buffer, list_size_needed);
13895b482a8SLen Brown if (ACPI_FAILURE(status)) {
13995b482a8SLen Brown return_ACPI_STATUS(status);
14095b482a8SLen Brown }
14195b482a8SLen Brown
14295b482a8SLen Brown /* Do the conversion */
14395b482a8SLen Brown
14495b482a8SLen Brown resource = output_buffer->pointer;
145886308ecSBob Moore status = acpi_ut_walk_aml_resources(NULL, aml_start, aml_buffer_length,
14695b482a8SLen Brown acpi_rs_convert_aml_to_resources,
14795b482a8SLen Brown &resource);
14895b482a8SLen Brown if (ACPI_FAILURE(status)) {
14995b482a8SLen Brown return_ACPI_STATUS(status);
15095b482a8SLen Brown }
15195b482a8SLen Brown
15295b482a8SLen Brown ACPI_DEBUG_PRINT((ACPI_DB_INFO, "OutputBuffer %p Length %X\n",
15395b482a8SLen Brown output_buffer->pointer, (u32) output_buffer->length));
15495b482a8SLen Brown return_ACPI_STATUS(AE_OK);
15595b482a8SLen Brown }
15695b482a8SLen Brown
15795b482a8SLen Brown /*******************************************************************************
15895b482a8SLen Brown *
15995b482a8SLen Brown * FUNCTION: acpi_rs_create_pci_routing_table
16095b482a8SLen Brown *
161cf48958eSBob Moore * PARAMETERS: package_object - Pointer to a package containing one
162cf48958eSBob Moore * of more ACPI_OPERAND_OBJECTs
16395b482a8SLen Brown * output_buffer - Pointer to the user's buffer
16495b482a8SLen Brown *
16595b482a8SLen Brown * RETURN: Status AE_OK if okay, else a valid acpi_status code.
16695b482a8SLen Brown * If the output_buffer is too small, the error will be
16795b482a8SLen Brown * AE_BUFFER_OVERFLOW and output_buffer->Length will point
16895b482a8SLen Brown * to the size buffer needed.
16995b482a8SLen Brown *
17095b482a8SLen Brown * DESCRIPTION: Takes the union acpi_operand_object package and creates a
17195b482a8SLen Brown * linked list of PCI interrupt descriptions
17295b482a8SLen Brown *
17395b482a8SLen Brown * NOTE: It is the caller's responsibility to ensure that the start of the
17495b482a8SLen Brown * output buffer is aligned properly (if necessary).
17595b482a8SLen Brown *
17695b482a8SLen Brown ******************************************************************************/
17795b482a8SLen Brown
17895b482a8SLen Brown acpi_status
acpi_rs_create_pci_routing_table(union acpi_operand_object * package_object,struct acpi_buffer * output_buffer)17995b482a8SLen Brown acpi_rs_create_pci_routing_table(union acpi_operand_object *package_object,
18095b482a8SLen Brown struct acpi_buffer *output_buffer)
18195b482a8SLen Brown {
18295b482a8SLen Brown u8 *buffer;
18395b482a8SLen Brown union acpi_operand_object **top_object_list;
18495b482a8SLen Brown union acpi_operand_object **sub_object_list;
18595b482a8SLen Brown union acpi_operand_object *obj_desc;
18695b482a8SLen Brown acpi_size buffer_size_needed = 0;
18795b482a8SLen Brown u32 number_of_elements;
18895b482a8SLen Brown u32 index;
18995b482a8SLen Brown struct acpi_pci_routing_table *user_prt;
19095b482a8SLen Brown struct acpi_namespace_node *node;
19195b482a8SLen Brown acpi_status status;
19295b482a8SLen Brown struct acpi_buffer path_buffer;
19395b482a8SLen Brown
19495b482a8SLen Brown ACPI_FUNCTION_TRACE(rs_create_pci_routing_table);
19595b482a8SLen Brown
19695b482a8SLen Brown /* Params already validated, so we don't re-validate here */
19795b482a8SLen Brown
19895b482a8SLen Brown /* Get the required buffer length */
19995b482a8SLen Brown
2001fad8738SBob Moore status =
2011fad8738SBob Moore acpi_rs_get_pci_routing_table_length(package_object,
20295b482a8SLen Brown &buffer_size_needed);
20395b482a8SLen Brown if (ACPI_FAILURE(status)) {
20495b482a8SLen Brown return_ACPI_STATUS(status);
20595b482a8SLen Brown }
20695b482a8SLen Brown
20795b482a8SLen Brown ACPI_DEBUG_PRINT((ACPI_DB_INFO, "BufferSizeNeeded = %X\n",
20895b482a8SLen Brown (u32) buffer_size_needed));
20995b482a8SLen Brown
21095b482a8SLen Brown /* Validate/Allocate/Clear caller buffer */
21195b482a8SLen Brown
21295b482a8SLen Brown status = acpi_ut_initialize_buffer(output_buffer, buffer_size_needed);
21395b482a8SLen Brown if (ACPI_FAILURE(status)) {
21495b482a8SLen Brown return_ACPI_STATUS(status);
21595b482a8SLen Brown }
21695b482a8SLen Brown
21795b482a8SLen Brown /*
21895b482a8SLen Brown * Loop through the ACPI_INTERNAL_OBJECTS - Each object should be a
2195df7e6cbSBob Moore * package that in turn contains an u64 Address, a u8 Pin,
22095b482a8SLen Brown * a Name, and a u8 source_index.
22195b482a8SLen Brown */
22295b482a8SLen Brown top_object_list = package_object->package.elements;
22395b482a8SLen Brown number_of_elements = package_object->package.count;
22495b482a8SLen Brown buffer = output_buffer->pointer;
22595b482a8SLen Brown user_prt = ACPI_CAST_PTR(struct acpi_pci_routing_table, buffer);
22695b482a8SLen Brown
22795b482a8SLen Brown for (index = 0; index < number_of_elements; index++) {
22895b482a8SLen Brown
22995b482a8SLen Brown /*
23095b482a8SLen Brown * Point user_prt past this current structure
23195b482a8SLen Brown *
23295b482a8SLen Brown * NOTE: On the first iteration, user_prt->Length will
23395b482a8SLen Brown * be zero because we cleared the return buffer earlier
23495b482a8SLen Brown */
23595b482a8SLen Brown buffer += user_prt->length;
23695b482a8SLen Brown user_prt = ACPI_CAST_PTR(struct acpi_pci_routing_table, buffer);
23795b482a8SLen Brown
23895b482a8SLen Brown /*
2391fad8738SBob Moore * Fill in the Length field with the information we have at this
2401fad8738SBob Moore * point. The minus four is to subtract the size of the u8
2411fad8738SBob Moore * Source[4] member because it is added below.
24295b482a8SLen Brown */
24395b482a8SLen Brown user_prt->length = (sizeof(struct acpi_pci_routing_table) - 4);
24495b482a8SLen Brown
2450a16d12aSBob Moore /* Each subpackage must be of length 4 */
24695b482a8SLen Brown
24795b482a8SLen Brown if ((*top_object_list)->package.count != 4) {
24895b482a8SLen Brown ACPI_ERROR((AE_INFO,
249f6a22b0bSBob Moore "(PRT[%u]) Need package of length 4, found length %u",
25095b482a8SLen Brown index, (*top_object_list)->package.count));
25195b482a8SLen Brown return_ACPI_STATUS(AE_AML_PACKAGE_LIMIT);
25295b482a8SLen Brown }
25395b482a8SLen Brown
25495b482a8SLen Brown /*
2550a16d12aSBob Moore * Dereference the subpackage.
25695b482a8SLen Brown * The sub_object_list will now point to an array of the four IRQ
25795b482a8SLen Brown * elements: [Address, Pin, Source, source_index]
25895b482a8SLen Brown */
25995b482a8SLen Brown sub_object_list = (*top_object_list)->package.elements;
26095b482a8SLen Brown
26195b482a8SLen Brown /* 1) First subobject: Dereference the PRT.Address */
26295b482a8SLen Brown
26395b482a8SLen Brown obj_desc = sub_object_list[0];
26483130649SLv Zheng if (!obj_desc || obj_desc->common.type != ACPI_TYPE_INTEGER) {
26595b482a8SLen Brown ACPI_ERROR((AE_INFO,
266f6a22b0bSBob Moore "(PRT[%u].Address) Need Integer, found %s",
26795b482a8SLen Brown index,
26895b482a8SLen Brown acpi_ut_get_object_type_name(obj_desc)));
26995b482a8SLen Brown return_ACPI_STATUS(AE_BAD_DATA);
27095b482a8SLen Brown }
27195b482a8SLen Brown
27295b482a8SLen Brown user_prt->address = obj_desc->integer.value;
27395b482a8SLen Brown
27495b482a8SLen Brown /* 2) Second subobject: Dereference the PRT.Pin */
27595b482a8SLen Brown
27695b482a8SLen Brown obj_desc = sub_object_list[1];
27783130649SLv Zheng if (!obj_desc || obj_desc->common.type != ACPI_TYPE_INTEGER) {
27895b482a8SLen Brown ACPI_ERROR((AE_INFO,
279f6a22b0bSBob Moore "(PRT[%u].Pin) Need Integer, found %s",
28095b482a8SLen Brown index,
28195b482a8SLen Brown acpi_ut_get_object_type_name(obj_desc)));
28295b482a8SLen Brown return_ACPI_STATUS(AE_BAD_DATA);
28395b482a8SLen Brown }
28495b482a8SLen Brown
28595b482a8SLen Brown user_prt->pin = (u32) obj_desc->integer.value;
28695b482a8SLen Brown
28795b482a8SLen Brown /*
28895b482a8SLen Brown * 3) Third subobject: Dereference the PRT.source_name
28995b482a8SLen Brown * The name may be unresolved (slack mode), so allow a null object
29095b482a8SLen Brown */
29182babbb3SZhang Rui obj_desc = sub_object_list[2];
29295b482a8SLen Brown if (obj_desc) {
2933371c19cSBob Moore switch (obj_desc->common.type) {
29495b482a8SLen Brown case ACPI_TYPE_LOCAL_REFERENCE:
29595b482a8SLen Brown
29695b482a8SLen Brown if (obj_desc->reference.class !=
29795b482a8SLen Brown ACPI_REFCLASS_NAME) {
29895b482a8SLen Brown ACPI_ERROR((AE_INFO,
299f6a22b0bSBob Moore "(PRT[%u].Source) Need name, found Reference Class 0x%X",
30095b482a8SLen Brown index,
30195b482a8SLen Brown obj_desc->reference.class));
30295b482a8SLen Brown return_ACPI_STATUS(AE_BAD_DATA);
30395b482a8SLen Brown }
30495b482a8SLen Brown
30595b482a8SLen Brown node = obj_desc->reference.node;
30695b482a8SLen Brown
30795b482a8SLen Brown /* Use *remaining* length of the buffer as max for pathname */
30895b482a8SLen Brown
30995b482a8SLen Brown path_buffer.length = output_buffer->length -
31095b482a8SLen Brown (u32) ((u8 *) user_prt->source -
31195b482a8SLen Brown (u8 *) output_buffer->pointer);
31295b482a8SLen Brown path_buffer.pointer = user_prt->source;
31395b482a8SLen Brown
3141fad8738SBob Moore status = acpi_ns_handle_to_pathname((acpi_handle)node, &path_buffer, FALSE);
315*aaf7566fSBob Moore if (ACPI_FAILURE(status)) {
316*aaf7566fSBob Moore return_ACPI_STATUS(status);
317*aaf7566fSBob Moore }
31895b482a8SLen Brown
31995b482a8SLen Brown /* +1 to include null terminator */
32095b482a8SLen Brown
32195b482a8SLen Brown user_prt->length +=
3224fa4616eSBob Moore (u32)strlen(user_prt->source) + 1;
32395b482a8SLen Brown break;
32495b482a8SLen Brown
32595b482a8SLen Brown case ACPI_TYPE_STRING:
32695b482a8SLen Brown
3274fa4616eSBob Moore strcpy(user_prt->source,
32895b482a8SLen Brown obj_desc->string.pointer);
32995b482a8SLen Brown
33095b482a8SLen Brown /*
33195b482a8SLen Brown * Add to the Length field the length of the string
33295b482a8SLen Brown * (add 1 for terminator)
33395b482a8SLen Brown */
33495b482a8SLen Brown user_prt->length += obj_desc->string.length + 1;
33595b482a8SLen Brown break;
33695b482a8SLen Brown
33795b482a8SLen Brown case ACPI_TYPE_INTEGER:
33895b482a8SLen Brown /*
3391fad8738SBob Moore * If this is a number, then the Source Name is NULL, since
3401fad8738SBob Moore * the entire buffer was zeroed out, we can leave this alone.
34195b482a8SLen Brown *
34295b482a8SLen Brown * Add to the Length field the length of the u32 NULL
34395b482a8SLen Brown */
34495b482a8SLen Brown user_prt->length += sizeof(u32);
34595b482a8SLen Brown break;
34695b482a8SLen Brown
34795b482a8SLen Brown default:
34895b482a8SLen Brown
34995b482a8SLen Brown ACPI_ERROR((AE_INFO,
350f6a22b0bSBob Moore "(PRT[%u].Source) Need Ref/String/Integer, found %s",
35195b482a8SLen Brown index,
35295b482a8SLen Brown acpi_ut_get_object_type_name
35395b482a8SLen Brown (obj_desc)));
35495b482a8SLen Brown return_ACPI_STATUS(AE_BAD_DATA);
35595b482a8SLen Brown }
35695b482a8SLen Brown }
35795b482a8SLen Brown
35895b482a8SLen Brown /* Now align the current length */
35995b482a8SLen Brown
36095b482a8SLen Brown user_prt->length =
36195b482a8SLen Brown (u32) ACPI_ROUND_UP_TO_64BIT(user_prt->length);
36295b482a8SLen Brown
36395b482a8SLen Brown /* 4) Fourth subobject: Dereference the PRT.source_index */
36495b482a8SLen Brown
36582babbb3SZhang Rui obj_desc = sub_object_list[3];
36683130649SLv Zheng if (!obj_desc || obj_desc->common.type != ACPI_TYPE_INTEGER) {
36795b482a8SLen Brown ACPI_ERROR((AE_INFO,
368f6a22b0bSBob Moore "(PRT[%u].SourceIndex) Need Integer, found %s",
36995b482a8SLen Brown index,
37095b482a8SLen Brown acpi_ut_get_object_type_name(obj_desc)));
37195b482a8SLen Brown return_ACPI_STATUS(AE_BAD_DATA);
37295b482a8SLen Brown }
37395b482a8SLen Brown
37495b482a8SLen Brown user_prt->source_index = (u32) obj_desc->integer.value;
37595b482a8SLen Brown
37695b482a8SLen Brown /* Point to the next union acpi_operand_object in the top level package */
37795b482a8SLen Brown
37895b482a8SLen Brown top_object_list++;
37995b482a8SLen Brown }
38095b482a8SLen Brown
38195b482a8SLen Brown ACPI_DEBUG_PRINT((ACPI_DB_INFO, "OutputBuffer %p Length %X\n",
38295b482a8SLen Brown output_buffer->pointer, (u32) output_buffer->length));
38395b482a8SLen Brown return_ACPI_STATUS(AE_OK);
38495b482a8SLen Brown }
38595b482a8SLen Brown
38695b482a8SLen Brown /*******************************************************************************
38795b482a8SLen Brown *
38895b482a8SLen Brown * FUNCTION: acpi_rs_create_aml_resources
38995b482a8SLen Brown *
3909a0a3597SLv Zheng * PARAMETERS: resource_list - Pointer to the resource list buffer
3919a0a3597SLv Zheng * output_buffer - Where the AML buffer is returned
39295b482a8SLen Brown *
39395b482a8SLen Brown * RETURN: Status AE_OK if okay, else a valid acpi_status code.
39495b482a8SLen Brown * If the output_buffer is too small, the error will be
39595b482a8SLen Brown * AE_BUFFER_OVERFLOW and output_buffer->Length will point
39695b482a8SLen Brown * to the size buffer needed.
39795b482a8SLen Brown *
3989a0a3597SLv Zheng * DESCRIPTION: Converts a list of device resources to an AML bytestream
3999a0a3597SLv Zheng * to be used as input for the _SRS control method.
40095b482a8SLen Brown *
40195b482a8SLen Brown ******************************************************************************/
40295b482a8SLen Brown
40395b482a8SLen Brown acpi_status
acpi_rs_create_aml_resources(struct acpi_buffer * resource_list,struct acpi_buffer * output_buffer)4049a0a3597SLv Zheng acpi_rs_create_aml_resources(struct acpi_buffer *resource_list,
40595b482a8SLen Brown struct acpi_buffer *output_buffer)
40695b482a8SLen Brown {
40795b482a8SLen Brown acpi_status status;
40895b482a8SLen Brown acpi_size aml_size_needed = 0;
40995b482a8SLen Brown
41095b482a8SLen Brown ACPI_FUNCTION_TRACE(rs_create_aml_resources);
41195b482a8SLen Brown
4129a0a3597SLv Zheng /* Params already validated, no need to re-validate here */
41395b482a8SLen Brown
4149a0a3597SLv Zheng ACPI_DEBUG_PRINT((ACPI_DB_INFO, "ResourceList Buffer = %p\n",
4159a0a3597SLv Zheng resource_list->pointer));
4169a0a3597SLv Zheng
4179a0a3597SLv Zheng /* Get the buffer size needed for the AML byte stream */
4189a0a3597SLv Zheng
4191fad8738SBob Moore status =
4201fad8738SBob Moore acpi_rs_get_aml_length(resource_list->pointer,
4211fad8738SBob Moore resource_list->length, &aml_size_needed);
42295b482a8SLen Brown
42395b482a8SLen Brown ACPI_DEBUG_PRINT((ACPI_DB_INFO, "AmlSizeNeeded=%X, %s\n",
4243e8214e5SLv Zheng (u32)aml_size_needed, acpi_format_exception(status)));
42595b482a8SLen Brown if (ACPI_FAILURE(status)) {
42695b482a8SLen Brown return_ACPI_STATUS(status);
42795b482a8SLen Brown }
42895b482a8SLen Brown
42995b482a8SLen Brown /* Validate/Allocate/Clear caller buffer */
43095b482a8SLen Brown
43195b482a8SLen Brown status = acpi_ut_initialize_buffer(output_buffer, aml_size_needed);
43295b482a8SLen Brown if (ACPI_FAILURE(status)) {
43395b482a8SLen Brown return_ACPI_STATUS(status);
43495b482a8SLen Brown }
43595b482a8SLen Brown
43695b482a8SLen Brown /* Do the conversion */
43795b482a8SLen Brown
4389a0a3597SLv Zheng status = acpi_rs_convert_resources_to_aml(resource_list->pointer,
43995b482a8SLen Brown aml_size_needed,
44095b482a8SLen Brown output_buffer->pointer);
44195b482a8SLen Brown if (ACPI_FAILURE(status)) {
44295b482a8SLen Brown return_ACPI_STATUS(status);
44395b482a8SLen Brown }
44495b482a8SLen Brown
44595b482a8SLen Brown ACPI_DEBUG_PRINT((ACPI_DB_INFO, "OutputBuffer %p Length %X\n",
44695b482a8SLen Brown output_buffer->pointer, (u32) output_buffer->length));
44795b482a8SLen Brown return_ACPI_STATUS(AE_OK);
44895b482a8SLen Brown }
449