1 /*******************************************************************************
3 * Module Name: rscreate - Acpi_rs_create_resource_list
4 * Acpi_rs_create_pci_routing_table
5 * Acpi_rs_create_byte_stream
8 ******************************************************************************/
11 * Copyright (C) 2000, 2001 R. Byron Moore
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
34 #define _COMPONENT ACPI_RESOURCES
35 MODULE_NAME ("rscreate")
38 /*******************************************************************************
40 * FUNCTION: Acpi_rs_create_resource_list
43 * Byte_stream_buffer - Pointer to the resource byte stream
44 * Output_buffer - Pointer to the user's buffer
45 * Output_buffer_length - Pointer to the size of Output_buffer
47 * RETURN: Status - AE_OK if okay, else a valid ACPI_STATUS code
48 * If Output_buffer is not large enough, Output_buffer_length
49 * indicates how large Output_buffer should be, else it
50 * indicates how may u8 elements of Output_buffer are valid.
52 * DESCRIPTION: Takes the byte stream returned from a _CRS, _PRS control method
53 * execution and parses the stream to create a linked list
54 * of device resources.
56 ******************************************************************************/
59 acpi_rs_create_resource_list (
60 ACPI_OPERAND_OBJECT *byte_stream_buffer,
62 u32 *output_buffer_length)
66 u8 *byte_stream_start = NULL;
67 u32 list_size_needed = 0;
68 u32 byte_stream_buffer_length = 0;
72 * Params already validated, so we don't re-validate here
75 byte_stream_buffer_length = byte_stream_buffer->buffer.length;
76 byte_stream_start = byte_stream_buffer->buffer.pointer;
79 * Pass the Byte_stream_buffer into a module that can calculate
80 * the buffer size needed for the linked list
82 status = acpi_rs_calculate_list_length (byte_stream_start,
83 byte_stream_buffer_length,
87 * Exit with the error passed back
89 if (ACPI_FAILURE (status)) {
94 * If the linked list will fit into the available buffer
95 * call to fill in the list
98 if (list_size_needed <= *output_buffer_length) {
100 * Zero out the return buffer before proceeding
102 MEMSET (output_buffer, 0x00, *output_buffer_length);
104 status = acpi_rs_byte_stream_to_list (byte_stream_start,
105 byte_stream_buffer_length,
109 * Exit with the error passed back
111 if (ACPI_FAILURE (status)) {
118 *output_buffer_length = list_size_needed;
119 return (AE_BUFFER_OVERFLOW);
122 *output_buffer_length = list_size_needed;
128 /*******************************************************************************
130 * FUNCTION: Acpi_rs_create_pci_routing_table
133 * Package_object - Pointer to an ACPI_OPERAND_OBJECT
135 * Output_buffer - Pointer to the user's buffer
136 * Output_buffer_length - Size of Output_buffer
138 * RETURN: Status AE_OK if okay, else a valid ACPI_STATUS code.
139 * If the Output_buffer is too small, the error will be
140 * AE_BUFFER_OVERFLOW and Output_buffer_length will point
141 * to the size buffer needed.
143 * DESCRIPTION: Takes the ACPI_OPERAND_OBJECT package and creates a
144 * linked list of PCI interrupt descriptions
146 ******************************************************************************/
149 acpi_rs_create_pci_routing_table (
150 ACPI_OPERAND_OBJECT *package_object,
152 u32 *output_buffer_length)
154 u8 *buffer = output_buffer;
155 ACPI_OPERAND_OBJECT **top_object_list = NULL;
156 ACPI_OPERAND_OBJECT **sub_object_list = NULL;
157 ACPI_OPERAND_OBJECT *package_element = NULL;
158 u32 buffer_size_needed = 0;
159 u32 number_of_elements = 0;
161 PCI_ROUTING_TABLE *user_prt = NULL;
162 ACPI_NAMESPACE_NODE *node;
167 * Params already validated, so we don't re-validate here
170 status = acpi_rs_calculate_pci_routing_table_length(package_object,
171 &buffer_size_needed);
174 * If the data will fit into the available buffer
175 * call to fill in the list
177 if (buffer_size_needed <= *output_buffer_length) {
179 * Zero out the return buffer before proceeding
181 MEMSET (output_buffer, 0x00, *output_buffer_length);
184 * Loop through the ACPI_INTERNAL_OBJECTS - Each object should
185 * contain a u32 Address, a u8 Pin, a Name and a u8
188 top_object_list = package_object->package.elements;
189 number_of_elements = package_object->package.count;
190 user_prt = (PCI_ROUTING_TABLE *) buffer;
193 buffer = ROUND_PTR_UP_TO_8 (buffer, u8);
195 for (index = 0; index < number_of_elements; index++) {
197 * Point User_prt past this current structure
199 * NOTE: On the first iteration, User_prt->Length will
200 * be zero because we cleared the return buffer earlier
202 buffer += user_prt->length;
203 user_prt = (PCI_ROUTING_TABLE *) buffer;
207 * Fill in the Length field with the information we
208 * have at this point.
209 * The minus four is to subtract the size of the
210 * u8 Source[4] member because it is added below.
212 user_prt->length = (sizeof (PCI_ROUTING_TABLE) -4);
215 * Dereference the sub-package
217 package_element = *top_object_list;
220 * The Sub_object_list will now point to an array of
221 * the four IRQ elements: Address, Pin, Source and
224 sub_object_list = package_element->package.elements;
227 * 1) First subobject: Dereference the Address
229 if (ACPI_TYPE_INTEGER == (*sub_object_list)->common.type) {
230 user_prt->address = (*sub_object_list)->integer.value;
234 return (AE_BAD_DATA);
238 * 2) Second subobject: Dereference the Pin
242 if (ACPI_TYPE_INTEGER == (*sub_object_list)->common.type) {
244 (u32) (*sub_object_list)->integer.value;
248 return (AE_BAD_DATA);
252 * 3) Third subobject: Dereference the Source Name
256 switch ((*sub_object_list)->common.type) {
257 case INTERNAL_TYPE_REFERENCE:
258 if ((*sub_object_list)->reference.opcode != AML_NAMEPATH_OP) {
259 return (AE_BAD_DATA);
262 node = (*sub_object_list)->reference.node;
264 /* TBD: use *remaining* length of the buffer! */
266 status = acpi_ns_handle_to_pathname ((ACPI_HANDLE *) node,
267 output_buffer_length, user_prt->source);
269 user_prt->length += STRLEN (user_prt->source) + 1; /* include null terminator */
273 case ACPI_TYPE_STRING:
275 STRCPY (user_prt->source,
276 (*sub_object_list)->string.pointer);
279 * Add to the Length field the length of the string
281 user_prt->length += (*sub_object_list)->string.length;
285 case ACPI_TYPE_INTEGER:
287 * If this is a number, then the Source Name
288 * is NULL, since the entire buffer was zeroed
289 * out, we can leave this alone.
292 * Add to the Length field the length of
295 user_prt->length += sizeof (u32);
300 return (AE_BAD_DATA);
304 /* Now align the current length */
306 user_prt->length = ROUND_UP_TO_64_bITS (user_prt->length);
309 * 4) Fourth subobject: Dereference the Source Index
313 if (ACPI_TYPE_INTEGER == (*sub_object_list)->common.type) {
314 user_prt->source_index =
315 (u32) (*sub_object_list)->integer.value;
319 return (AE_BAD_DATA);
323 * Point to the next ACPI_OPERAND_OBJECT
331 *output_buffer_length = buffer_size_needed;
333 return (AE_BUFFER_OVERFLOW);
337 * Report the amount of buffer used
339 *output_buffer_length = buffer_size_needed;
345 /*******************************************************************************
347 * FUNCTION: Acpi_rs_create_byte_stream
350 * Linked_list_buffer - Pointer to the resource linked list
351 * Output_buffer - Pointer to the user's buffer
352 * Output_buffer_length - Size of Output_buffer
354 * RETURN: Status AE_OK if okay, else a valid ACPI_STATUS code.
355 * If the Output_buffer is too small, the error will be
356 * AE_BUFFER_OVERFLOW and Output_buffer_length will point
357 * to the size buffer needed.
359 * DESCRIPTION: Takes the linked list of device resources and
360 * creates a bytestream to be used as input for the
361 * _SRS control method.
363 ******************************************************************************/
366 acpi_rs_create_byte_stream (
367 RESOURCE *linked_list_buffer,
369 u32 *output_buffer_length)
372 u32 byte_stream_size_needed = 0;
376 * Params already validated, so we don't re-validate here
378 * Pass the Linked_list_buffer into a module that can calculate
379 * the buffer size needed for the byte stream.
381 status = acpi_rs_calculate_byte_stream_length (linked_list_buffer,
382 &byte_stream_size_needed);
385 * Exit with the error passed back
387 if (ACPI_FAILURE (status)) {
392 * If the linked list will fit into the available buffer
393 * call to fill in the list
396 if (byte_stream_size_needed <= *output_buffer_length) {
398 * Zero out the return buffer before proceeding
400 MEMSET (output_buffer, 0x00, *output_buffer_length);
402 status = acpi_rs_list_to_byte_stream (linked_list_buffer,
403 byte_stream_size_needed,
407 * Exit with the error passed back
409 if (ACPI_FAILURE (status)) {
415 *output_buffer_length = byte_stream_size_needed;
416 return (AE_BUFFER_OVERFLOW);