Merge with 2.4.0-test3-pre4.
[linux-2.6/linux-mips.git] / drivers / acpi / resources / rsmisc.c
blobfc5a6725f031a666f4c7fef6f1b22f3cbc69d126
1 /******************************************************************************
3 * Module Name: rsmisc - Acpi_rs_end_tag_resource
4 * Acpi_rs_end_tag_stream
5 * Acpi_rs_vendor_resource
6 * Acpi_rs_vendor_stream
7 * Acpi_rs_start_dependent_functions_resource
8 * Acpi_rs_end_dependent_functions_resource
9 * Acpi_rs_start_dependent_functions_stream
10 * Acpi_rs_end_dependent_functions_stream
12 *****************************************************************************/
15 * Copyright (C) 2000 R. Byron Moore
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation; either version 2 of the License, or
20 * (at your option) any later version.
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
33 #include "acpi.h"
35 #define _COMPONENT RESOURCE_MANAGER
36 MODULE_NAME ("rsmisc");
39 /***************************************************************************
40 * FUNCTION: Acpi_rs_end_tag_resource
42 * PARAMETERS:
43 * Byte_stream_buffer - Pointer to the resource input byte
44 * stream
45 * Bytes_consumed - u32 pointer that is filled with
46 * the number of bytes consumed from
47 * the Byte_stream_buffer
48 * Output_buffer - Pointer to the user's return buffer
49 * Structure_size - u32 pointer that is filled with
50 * the number of bytes in the filled
51 * in structure
53 * RETURN: Status AE_OK if okay, else a valid ACPI_STATUS code
55 * DESCRIPTION: Take the resource byte stream and fill out the appropriate
56 * structure pointed to by the Output_buffer. Return the
57 * number of bytes consumed from the byte stream.
59 ***************************************************************************/
61 ACPI_STATUS
62 acpi_rs_end_tag_resource (
63 u8 *byte_stream_buffer,
64 u32 *bytes_consumed,
65 u8 **output_buffer,
66 u32 *structure_size)
68 RESOURCE *output_struct = (RESOURCE *) * output_buffer;
69 u32 struct_size = RESOURCE_LENGTH;
73 * The number of bytes consumed is static
75 *bytes_consumed = 2;
78 * Fill out the structure
80 output_struct->id = end_tag;
83 * Set the Length parameter
85 output_struct->length = 0;
88 * Return the final size of the structure
90 *structure_size = struct_size;
92 return (AE_OK);
96 /***************************************************************************
97 * FUNCTION: Acpi_rs_end_tag_stream
99 * PARAMETERS:
100 * Linked_list - Pointer to the resource linked list
101 * Output_buffer - Pointer to the user's return buffer
102 * Bytes_consumed - u32 pointer that is filled with
103 * the number of bytes of the
104 * Output_buffer used
106 * RETURN: Status AE_OK if okay, else a valid ACPI_STATUS code
108 * DESCRIPTION: Take the linked list resource structure and fills in the
109 * the appropriate bytes in a byte stream
111 ***************************************************************************/
113 ACPI_STATUS
114 acpi_rs_end_tag_stream (
115 RESOURCE *linked_list,
116 u8 **output_buffer,
117 u32 *bytes_consumed)
119 u8 *buffer = *output_buffer;
120 u8 temp8 = 0;
124 * The descriptor field is static
126 *buffer = 0x79;
128 buffer += 1;
131 * Set the Checksum - zero means that the resource data is treated as if
132 * the checksum operation succeeded (ACPI Spec 1.0b Section 6.4.2.8)
134 temp8 = 0;
136 *buffer = temp8;
138 buffer += 1;
141 * Return the number of bytes consumed in this operation
143 *bytes_consumed = (u32) ((NATIVE_UINT) buffer -
144 (NATIVE_UINT) *output_buffer);
146 return (AE_OK);
149 /***************************************************************************
150 * FUNCTION: Acpi_rs_vendor_resource
152 * PARAMETERS:
153 * Byte_stream_buffer - Pointer to the resource input byte
154 * stream
155 * Bytes_consumed - u32 pointer that is filled with
156 * the number of bytes consumed from
157 * the Byte_stream_buffer
158 * Output_buffer - Pointer to the user's return buffer
159 * Structure_size - u32 pointer that is filled with
160 * the number of bytes in the filled
161 * in structure
163 * RETURN: Status AE_OK if okay, else a valid ACPI_STATUS code
165 * DESCRIPTION: Take the resource byte stream and fill out the appropriate
166 * structure pointed to by the Output_buffer. Return the
167 * number of bytes consumed from the byte stream.
169 ***************************************************************************/
171 ACPI_STATUS
172 acpi_rs_vendor_resource (
173 u8 *byte_stream_buffer,
174 u32 *bytes_consumed,
175 u8 **output_buffer,
176 u32 *structure_size)
178 u8 *buffer = byte_stream_buffer;
179 RESOURCE *output_struct = (RESOURCE *) * output_buffer;
180 u16 temp16 = 0;
181 u8 temp8 = 0;
182 u8 index;
183 u32 struct_size = sizeof (VENDOR_RESOURCE) +
184 RESOURCE_LENGTH_NO_DATA;
188 * Dereference the Descriptor to find if this is a large or small item.
190 temp8 = *buffer;
192 if (temp8 & 0x80) {
194 * Large Item
196 /* Point to the length field */
198 buffer += 1;
200 /* Dereference */
202 temp16 = *(u16 *)buffer;
204 /* Calculate bytes consumed */
206 *bytes_consumed = temp16 + 3;
208 /* Point to the first vendor byte */
210 buffer += 2;
213 else {
215 * Small Item
218 /* Dereference the size */
220 temp16 = (u8)(*buffer & 0x07);
222 /* Calculate bytes consumed */
224 *bytes_consumed = temp16 + 1;
226 /* Point to the first vendor byte */
228 buffer += 1;
231 output_struct->id = vendor_specific;
233 output_struct->data.vendor_specific.length = temp16;
235 for (index = 0; index < temp16; index++) {
236 output_struct->data.vendor_specific.reserved[index] = *buffer;
237 buffer += 1;
241 * In order for the Struct_size to fall on a 32-bit boundry,
242 * calculate the length of the vendor string and expand the
243 * Struct_size to the next 32-bit boundry.
245 struct_size += ROUND_UP_TO_32_bITS (temp16);
248 * Set the Length parameter
250 output_struct->length = struct_size;
253 * Return the final size of the structure
255 *structure_size = struct_size;
257 return (AE_OK);
261 /***************************************************************************
262 * FUNCTION: Acpi_rs_vendor_stream
264 * PARAMETERS:
265 * Linked_list - Pointer to the resource linked list
266 * Output_buffer - Pointer to the user's return buffer
267 * Bytes_consumed - u32 pointer that is filled with
268 * the number of bytes of the
269 * Output_buffer used
271 * RETURN: Status AE_OK if okay, else a valid ACPI_STATUS code
273 * DESCRIPTION: Take the linked list resource structure and fills in the
274 * the appropriate bytes in a byte stream
276 ***************************************************************************/
278 ACPI_STATUS
279 acpi_rs_vendor_stream (
280 RESOURCE *linked_list,
281 u8 **output_buffer,
282 u32 *bytes_consumed)
284 u8 *buffer = *output_buffer;
285 u16 temp16 = 0;
286 u8 temp8 = 0;
287 u8 index;
291 * Dereference the length to find if this is a large or small item.
294 if(linked_list->data.vendor_specific.length > 7) {
296 * Large Item
299 * Set the descriptor field and length bytes
301 *buffer = 0x84;
303 buffer += 1;
305 temp16 = (u16) linked_list->data.vendor_specific.length;
307 *(u16 *)buffer = temp16;
309 buffer += 2;
312 else {
314 * Small Item
318 * Set the descriptor field
320 temp8 = 0x70;
322 temp8 |= linked_list->data.vendor_specific.length;
324 *buffer = temp8;
326 buffer += 1;
330 * Loop through all of the Vendor Specific fields
332 for (index = 0; index < linked_list->data.vendor_specific.length; index++) {
333 temp8 = linked_list->data.vendor_specific.reserved[index];
334 *buffer = temp8;
335 buffer += 1;
339 * Return the number of bytes consumed in this operation
341 *bytes_consumed = (u32) ((NATIVE_UINT) buffer -
342 (NATIVE_UINT) *output_buffer);
344 return (AE_OK);
347 /***************************************************************************
348 * FUNCTION: Acpi_rs_start_dependent_functions_resource
350 * PARAMETERS:
351 * Byte_stream_buffer - Pointer to the resource input byte
352 * stream
353 * Bytes_consumed - u32 pointer that is filled with
354 * the number of bytes consumed from
355 * the Byte_stream_buffer
356 * Output_buffer - Pointer to the user's return buffer
357 * Structure_size - u32 pointer that is filled with
358 * the number of bytes in the filled
359 * in structure
361 * RETURN: Status AE_OK if okay, else a valid ACPI_STATUS code
363 * DESCRIPTION: Take the resource byte stream and fill out the appropriate
364 * structure pointed to by the Output_buffer. Return the
365 * number of bytes consumed from the byte stream.
367 ***************************************************************************/
369 ACPI_STATUS
370 acpi_rs_start_dependent_functions_resource (
371 u8 *byte_stream_buffer,
372 u32 *bytes_consumed,
373 u8 **output_buffer,
374 u32 *structure_size)
376 u8 *buffer = byte_stream_buffer;
377 RESOURCE *output_struct = (RESOURCE *) * output_buffer;
378 u8 temp8 = 0;
379 u32 struct_size =
380 sizeof(START_DEPENDENT_FUNCTIONS_RESOURCE) +
381 RESOURCE_LENGTH_NO_DATA;
385 * The number of bytes consumed are contained in the descriptor (Bits:0-1)
387 temp8 = *buffer;
389 *bytes_consumed = (temp8 & 0x01) + 1;
391 output_struct->id = start_dependent_functions;
394 * Point to Byte 1 if it is used
396 if (2 == *bytes_consumed) {
397 buffer += 1;
398 temp8 = *buffer;
401 * Check Compatibility priority
403 output_struct->data.start_dependent_functions.compatibility_priority =
404 temp8 & 0x03;
406 if (3 == output_struct->data.start_dependent_functions.compatibility_priority) {
407 return (AE_ERROR);
411 * Check Performance/Robustness preference
413 output_struct->data.start_dependent_functions.performance_robustness =
414 (temp8 >> 2) & 0x03;
416 if (3 == output_struct->data.start_dependent_functions.performance_robustness) {
417 return (AE_ERROR);
421 else {
422 output_struct->data.start_dependent_functions.compatibility_priority =
423 ACCEPTABLE_CONFIGURATION;
425 output_struct->data.start_dependent_functions.performance_robustness =
426 ACCEPTABLE_CONFIGURATION;
430 * Set the Length parameter
432 output_struct->length = struct_size;
435 * Return the final size of the structure
437 *structure_size = struct_size;
439 return (AE_OK);
443 /***************************************************************************
444 * FUNCTION: Acpi_rs_end_dependent_functions_resource
446 * PARAMETERS:
447 * Byte_stream_buffer - Pointer to the resource input byte
448 * stream
449 * Bytes_consumed - u32 pointer that is filled with
450 * the number of bytes consumed from
451 * the Byte_stream_buffer
452 * Output_buffer - Pointer to the user's return buffer
453 * Structure_size - u32 pointer that is filled with
454 * the number of bytes in the filled
455 * in structure
457 * RETURN: Status AE_OK if okay, else a valid ACPI_STATUS code
459 * DESCRIPTION: Take the resource byte stream and fill out the appropriate
460 * structure pointed to by the Output_buffer. Return the
461 * number of bytes consumed from the byte stream.
463 ***************************************************************************/
465 ACPI_STATUS
466 acpi_rs_end_dependent_functions_resource (
467 u8 *byte_stream_buffer,
468 u32 *bytes_consumed,
469 u8 **output_buffer,
470 u32 *structure_size)
472 RESOURCE *output_struct = (RESOURCE *) * output_buffer;
473 u32 struct_size = RESOURCE_LENGTH;
477 * The number of bytes consumed is static
479 *bytes_consumed = 1;
482 * Fill out the structure
484 output_struct->id = end_dependent_functions;
487 * Set the Length parameter
489 output_struct->length = struct_size;
492 * Return the final size of the structure
494 *structure_size = struct_size;
496 return (AE_OK);
500 /***************************************************************************
501 * FUNCTION: Acpi_rs_start_dependent_functions_stream
503 * PARAMETERS:
504 * Linked_list - Pointer to the resource linked list
505 * Output_buffer - Pointer to the user's return buffer
506 * Bytes_consumed - u32 pointer that is filled with
507 * the number of bytes of the
508 * Output_buffer used
510 * RETURN: Status AE_OK if okay, else a valid ACPI_STATUS code
512 * DESCRIPTION: Take the linked list resource structure and fills in the
513 * the appropriate bytes in a byte stream
515 ***************************************************************************/
516 ACPI_STATUS
517 acpi_rs_start_dependent_functions_stream (
518 RESOURCE *linked_list,
519 u8 **output_buffer,
520 u32 *bytes_consumed)
522 u8 *buffer = *output_buffer;
523 u8 temp8 = 0;
527 * The descriptor field is set based upon whether a byte is needed
528 * to contain Priority data.
530 if (ACCEPTABLE_CONFIGURATION ==
531 linked_list->data.start_dependent_functions.compatibility_priority &&
532 ACCEPTABLE_CONFIGURATION ==
533 linked_list->data.start_dependent_functions.performance_robustness)
535 *buffer = 0x30;
537 else {
538 *buffer = 0x31;
540 buffer += 1;
543 * Set the Priority Byte Definition
545 temp8 = 0;
547 temp8 = (u8)
548 ((linked_list->data.start_dependent_functions.performance_robustness &
549 0x03) << 2);
551 temp8 |=
552 (linked_list->data.start_dependent_functions.compatibility_priority &
553 0x03);
555 *buffer = temp8;
558 buffer += 1;
561 * Return the number of bytes consumed in this operation
563 *bytes_consumed = (u32) ((NATIVE_UINT) buffer -
564 (NATIVE_UINT) *output_buffer);
566 return (AE_OK);
570 /***************************************************************************
571 * FUNCTION: Acpi_rs_end_dependent_functions_stream
573 * PARAMETERS:
574 * Linked_list - Pointer to the resource linked list
575 * Output_buffer - Pointer to the user's return buffer
576 * Bytes_consumed - u32 pointer that is filled with
577 * the number of bytes of the
578 * Output_buffer used
580 * RETURN: Status AE_OK if okay, else a valid ACPI_STATUS code
582 * DESCRIPTION: Take the linked list resource structure and fills in the
583 * the appropriate bytes in a byte stream
585 ***************************************************************************/
587 ACPI_STATUS
588 acpi_rs_end_dependent_functions_stream (
589 RESOURCE *linked_list,
590 u8 **output_buffer,
591 u32 *bytes_consumed
594 u8 *buffer = *output_buffer;
598 * The descriptor field is static
600 *buffer = 0x38;
602 buffer += 1;
605 * Return the number of bytes consumed in this operation
607 *bytes_consumed = (u32) ((NATIVE_UINT) buffer -
608 (NATIVE_UINT) *output_buffer);
610 return (AE_OK);