ACPICA 20050408 from Bob Moore
[safe/jmp/linux-2.6] / drivers / acpi / resources / rsmisc.c
1 /*******************************************************************************
2  *
3  * Module Name: rsmisc - Miscellaneous resource descriptors
4  *
5  ******************************************************************************/
6
7 /*
8  * Copyright (C) 2000 - 2005, R. Byron Moore
9  * All rights reserved.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions, and the following disclaimer,
16  *    without modification.
17  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18  *    substantially similar to the "NO WARRANTY" disclaimer below
19  *    ("Disclaimer") and any redistribution must be conditioned upon
20  *    including a substantially similar Disclaimer requirement for further
21  *    binary redistribution.
22  * 3. Neither the names of the above-listed copyright holders nor the names
23  *    of any contributors may be used to endorse or promote products derived
24  *    from this software without specific prior written permission.
25  *
26  * Alternatively, this software may be distributed under the terms of the
27  * GNU General Public License ("GPL") version 2 as published by the Free
28  * Software Foundation.
29  *
30  * NO WARRANTY
31  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41  * POSSIBILITY OF SUCH DAMAGES.
42  */
43
44
45 #include <acpi/acpi.h>
46 #include <acpi/acresrc.h>
47
48 #define _COMPONENT          ACPI_RESOURCES
49          ACPI_MODULE_NAME    ("rsmisc")
50
51
52 /*******************************************************************************
53  *
54  * FUNCTION:    acpi_rs_end_tag_resource
55  *
56  * PARAMETERS:  byte_stream_buffer      - Pointer to the resource input byte
57  *                                        stream
58  *              bytes_consumed          - Pointer to where the number of bytes
59  *                                        consumed the byte_stream_buffer is
60  *                                        returned
61  *              output_buffer           - Pointer to the return data buffer
62  *              structure_size          - Pointer to where the number of bytes
63  *                                        in the return data struct is returned
64  *
65  * RETURN:      Status
66  *
67  * DESCRIPTION: Take the resource byte stream and fill out the appropriate
68  *              structure pointed to by the output_buffer. Return the
69  *              number of bytes consumed from the byte stream.
70  *
71  ******************************************************************************/
72
73 acpi_status
74 acpi_rs_end_tag_resource (
75         u8                              *byte_stream_buffer,
76         acpi_size                       *bytes_consumed,
77         u8                              **output_buffer,
78         acpi_size                       *structure_size)
79 {
80         struct acpi_resource            *output_struct = (void *) *output_buffer;
81         acpi_size                       struct_size = ACPI_RESOURCE_LENGTH;
82
83
84         ACPI_FUNCTION_TRACE ("rs_end_tag_resource");
85
86
87         /* The number of bytes consumed is static */
88
89         *bytes_consumed = 2;
90
91         /*  Fill out the structure */
92
93         output_struct->id = ACPI_RSTYPE_END_TAG;
94
95         /* Set the Length parameter */
96
97         output_struct->length = 0;
98
99         /* Return the final size of the structure */
100
101         *structure_size = struct_size;
102         return_ACPI_STATUS (AE_OK);
103 }
104
105
106 /*******************************************************************************
107  *
108  * FUNCTION:    acpi_rs_end_tag_stream
109  *
110  * PARAMETERS:  linked_list             - Pointer to the resource linked list
111  *              output_buffer           - Pointer to the user's return buffer
112  *              bytes_consumed          - Pointer to where the number of bytes
113  *                                        used in the output_buffer is returned
114  *
115  * RETURN:      Status
116  *
117  * DESCRIPTION: Take the linked list resource structure and fills in the
118  *              the appropriate bytes in a byte stream
119  *
120  ******************************************************************************/
121
122 acpi_status
123 acpi_rs_end_tag_stream (
124         struct acpi_resource            *linked_list,
125         u8                              **output_buffer,
126         acpi_size                       *bytes_consumed)
127 {
128         u8                              *buffer = *output_buffer;
129         u8                              temp8 = 0;
130
131
132         ACPI_FUNCTION_TRACE ("rs_end_tag_stream");
133
134
135         /* The descriptor field is static */
136
137         *buffer = 0x79;
138         buffer += 1;
139
140         /*
141          * Set the Checksum - zero means that the resource data is treated as if
142          * the checksum operation succeeded (ACPI Spec 1.0b Section 6.4.2.8)
143          */
144         temp8 = 0;
145
146         *buffer = temp8;
147         buffer += 1;
148
149         /* Return the number of bytes consumed in this operation */
150
151         *bytes_consumed = ACPI_PTR_DIFF (buffer, *output_buffer);
152         return_ACPI_STATUS (AE_OK);
153 }
154
155
156 /*******************************************************************************
157  *
158  * FUNCTION:    acpi_rs_vendor_resource
159  *
160  * PARAMETERS:  byte_stream_buffer      - Pointer to the resource input byte
161  *                                        stream
162  *              bytes_consumed          - Pointer to where the number of bytes
163  *                                        consumed the byte_stream_buffer is
164  *                                        returned
165  *              output_buffer           - Pointer to the return data buffer
166  *              structure_size          - Pointer to where the number of bytes
167  *                                        in the return data struct is returned
168  *
169  * RETURN:      Status
170  *
171  * DESCRIPTION: Take the resource byte stream and fill out the appropriate
172  *              structure pointed to by the output_buffer. Return the
173  *              number of bytes consumed from the byte stream.
174  *
175  ******************************************************************************/
176
177 acpi_status
178 acpi_rs_vendor_resource (
179         u8                              *byte_stream_buffer,
180         acpi_size                       *bytes_consumed,
181         u8                              **output_buffer,
182         acpi_size                       *structure_size)
183 {
184         u8                              *buffer = byte_stream_buffer;
185         struct acpi_resource            *output_struct = (void *) *output_buffer;
186         u16                             temp16 = 0;
187         u8                              temp8 = 0;
188         u8                              index;
189         acpi_size                       struct_size = ACPI_SIZEOF_RESOURCE (
190                           struct acpi_resource_vendor);
191
192
193         ACPI_FUNCTION_TRACE ("rs_vendor_resource");
194
195
196         /* Dereference the Descriptor to find if this is a large or small item. */
197
198         temp8 = *buffer;
199
200         if (temp8 & 0x80) {
201                 /* Large Item, point to the length field */
202
203                 buffer += 1;
204
205                 /* Dereference */
206
207                 ACPI_MOVE_16_TO_16 (&temp16, buffer);
208
209                 /* Calculate bytes consumed */
210
211                 *bytes_consumed = (acpi_size) temp16 + 3;
212
213                 /* Point to the first vendor byte */
214
215                 buffer += 2;
216         }
217         else {
218                 /* Small Item, dereference the size */
219
220                 temp16 = (u8)(*buffer & 0x07);
221
222                 /* Calculate bytes consumed */
223
224                 *bytes_consumed = (acpi_size) temp16 + 1;
225
226                 /* Point to the first vendor byte */
227
228                 buffer += 1;
229         }
230
231         output_struct->id = ACPI_RSTYPE_VENDOR;
232         output_struct->data.vendor_specific.length = temp16;
233
234         for (index = 0; index < temp16; index++) {
235                 output_struct->data.vendor_specific.reserved[index] = *buffer;
236                 buffer += 1;
237         }
238
239         /*
240          * In order for the struct_size to fall on a 32-bit boundary,
241          * calculate the length of the vendor string and expand the
242          * struct_size to the next 32-bit boundary.
243          */
244         struct_size += ACPI_ROUND_UP_to_32_bITS (temp16);
245
246         /* Set the Length parameter */
247
248         output_struct->length = (u32) struct_size;
249
250         /* Return the final size of the structure */
251
252         *structure_size = struct_size;
253         return_ACPI_STATUS (AE_OK);
254 }
255
256
257 /*******************************************************************************
258  *
259  * FUNCTION:    acpi_rs_vendor_stream
260  *
261  * PARAMETERS:  linked_list             - Pointer to the resource linked list
262  *              output_buffer           - Pointer to the user's return buffer
263  *              bytes_consumed          - Pointer to where the number of bytes
264  *                                        used in the output_buffer is returned
265  *
266  * RETURN:      Status
267  *
268  * DESCRIPTION: Take the linked list resource structure and fills in the
269  *              the appropriate bytes in a byte stream
270  *
271  ******************************************************************************/
272
273 acpi_status
274 acpi_rs_vendor_stream (
275         struct acpi_resource            *linked_list,
276         u8                              **output_buffer,
277         acpi_size                       *bytes_consumed)
278 {
279         u8                              *buffer = *output_buffer;
280         u16                             temp16 = 0;
281         u8                              temp8 = 0;
282         u8                              index;
283
284
285         ACPI_FUNCTION_TRACE ("rs_vendor_stream");
286
287
288         /* Dereference the length to find if this is a large or small item. */
289
290         if(linked_list->data.vendor_specific.length > 7) {
291                 /* Large Item, Set the descriptor field and length bytes */
292
293                 *buffer = 0x84;
294                 buffer += 1;
295
296                 temp16 = (u16) linked_list->data.vendor_specific.length;
297
298                 ACPI_MOVE_16_TO_16 (buffer, &temp16);
299                 buffer += 2;
300         }
301         else {
302                 /* Small Item, Set the descriptor field */
303
304                 temp8 = 0x70;
305                 temp8 |= (u8) linked_list->data.vendor_specific.length;
306
307                 *buffer = temp8;
308                 buffer += 1;
309         }
310
311         /* Loop through all of the Vendor Specific fields */
312
313         for (index = 0; index < linked_list->data.vendor_specific.length; index++) {
314                 temp8 = linked_list->data.vendor_specific.reserved[index];
315
316                 *buffer = temp8;
317                 buffer += 1;
318         }
319
320         /* Return the number of bytes consumed in this operation */
321
322         *bytes_consumed = ACPI_PTR_DIFF (buffer, *output_buffer);
323         return_ACPI_STATUS (AE_OK);
324 }
325
326
327 /*******************************************************************************
328  *
329  * FUNCTION:    acpi_rs_start_depend_fns_resource
330  *
331  * PARAMETERS:  byte_stream_buffer      - Pointer to the resource input byte
332  *                                        stream
333  *              bytes_consumed          - Pointer to where the number of bytes
334  *                                        consumed the byte_stream_buffer is
335  *                                        returned
336  *              output_buffer           - Pointer to the return data buffer
337  *              structure_size          - Pointer to where the number of bytes
338  *                                        in the return data struct is returned
339  *
340  * RETURN:      Status
341  *
342  * DESCRIPTION: Take the resource byte stream and fill out the appropriate
343  *              structure pointed to by the output_buffer. Return the
344  *              number of bytes consumed from the byte stream.
345  *
346  ******************************************************************************/
347
348 acpi_status
349 acpi_rs_start_depend_fns_resource (
350         u8                              *byte_stream_buffer,
351         acpi_size                       *bytes_consumed,
352         u8                              **output_buffer,
353         acpi_size                       *structure_size)
354 {
355         u8                              *buffer = byte_stream_buffer;
356         struct acpi_resource            *output_struct = (void *) *output_buffer;
357         u8                              temp8 = 0;
358         acpi_size                       struct_size = ACPI_SIZEOF_RESOURCE (
359                           struct acpi_resource_start_dpf);
360
361
362         ACPI_FUNCTION_TRACE ("rs_start_depend_fns_resource");
363
364
365         /* The number of bytes consumed are found in the descriptor (Bits:0-1) */
366
367         temp8 = *buffer;
368
369         *bytes_consumed = (temp8 & 0x01) + 1;
370
371         output_struct->id = ACPI_RSTYPE_START_DPF;
372
373         /* Point to Byte 1 if it is used */
374
375         if (2 == *bytes_consumed) {
376                 buffer += 1;
377                 temp8 = *buffer;
378
379                 /* Check Compatibility priority */
380
381                 output_struct->data.start_dpf.compatibility_priority = temp8 & 0x03;
382
383                 if (3 == output_struct->data.start_dpf.compatibility_priority) {
384                         return_ACPI_STATUS (AE_AML_BAD_RESOURCE_VALUE);
385                 }
386
387                 /* Check Performance/Robustness preference */
388
389                 output_struct->data.start_dpf.performance_robustness = (temp8 >> 2) & 0x03;
390
391                 if (3 == output_struct->data.start_dpf.performance_robustness) {
392                         return_ACPI_STATUS (AE_AML_BAD_RESOURCE_VALUE);
393                 }
394         }
395         else {
396                 output_struct->data.start_dpf.compatibility_priority =
397                         ACPI_ACCEPTABLE_CONFIGURATION;
398
399                 output_struct->data.start_dpf.performance_robustness =
400                         ACPI_ACCEPTABLE_CONFIGURATION;
401         }
402
403         /* Set the Length parameter */
404
405         output_struct->length = (u32) struct_size;
406
407         /* Return the final size of the structure */
408
409         *structure_size = struct_size;
410         return_ACPI_STATUS (AE_OK);
411 }
412
413
414 /*******************************************************************************
415  *
416  * FUNCTION:    acpi_rs_end_depend_fns_resource
417  *
418  * PARAMETERS:  byte_stream_buffer      - Pointer to the resource input byte
419  *                                        stream
420  *              bytes_consumed          - Pointer to where the number of bytes
421  *                                        consumed the byte_stream_buffer is
422  *                                        returned
423  *              output_buffer           - Pointer to the return data buffer
424  *              structure_size          - Pointer to where the number of bytes
425  *                                        in the return data struct is returned
426  *
427  * RETURN:      Status
428  *
429  * DESCRIPTION: Take the resource byte stream and fill out the appropriate
430  *              structure pointed to by the output_buffer. Return the
431  *              number of bytes consumed from the byte stream.
432  *
433  ******************************************************************************/
434
435 acpi_status
436 acpi_rs_end_depend_fns_resource (
437         u8                              *byte_stream_buffer,
438         acpi_size                       *bytes_consumed,
439         u8                              **output_buffer,
440         acpi_size                       *structure_size)
441 {
442         struct acpi_resource            *output_struct = (void *) *output_buffer;
443         acpi_size                       struct_size = ACPI_RESOURCE_LENGTH;
444
445
446         ACPI_FUNCTION_TRACE ("rs_end_depend_fns_resource");
447
448
449         /* The number of bytes consumed is static */
450
451         *bytes_consumed = 1;
452
453         /*  Fill out the structure */
454
455         output_struct->id = ACPI_RSTYPE_END_DPF;
456
457         /* Set the Length parameter */
458
459         output_struct->length = (u32) struct_size;
460
461         /* Return the final size of the structure */
462
463         *structure_size = struct_size;
464         return_ACPI_STATUS (AE_OK);
465 }
466
467
468 /*******************************************************************************
469  *
470  * FUNCTION:    acpi_rs_start_depend_fns_stream
471  *
472  * PARAMETERS:  linked_list             - Pointer to the resource linked list
473  *              output_buffer           - Pointer to the user's return buffer
474  *              bytes_consumed          - u32 pointer that is filled with
475  *                                        the number of bytes of the
476  *                                        output_buffer used
477  *
478  * RETURN:      Status
479  *
480  * DESCRIPTION: Take the linked list resource structure and fills in the
481  *              the appropriate bytes in a byte stream
482  *
483  ******************************************************************************/
484
485 acpi_status
486 acpi_rs_start_depend_fns_stream (
487         struct acpi_resource            *linked_list,
488         u8                              **output_buffer,
489         acpi_size                       *bytes_consumed)
490 {
491         u8                              *buffer = *output_buffer;
492         u8                              temp8 = 0;
493
494
495         ACPI_FUNCTION_TRACE ("rs_start_depend_fns_stream");
496
497
498         /*
499          * The descriptor field is set based upon whether a byte is needed
500          * to contain Priority data.
501          */
502         if (ACPI_ACCEPTABLE_CONFIGURATION ==
503                         linked_list->data.start_dpf.compatibility_priority &&
504                 ACPI_ACCEPTABLE_CONFIGURATION ==
505                         linked_list->data.start_dpf.performance_robustness) {
506                 *buffer = 0x30;
507         }
508         else {
509                 *buffer = 0x31;
510                 buffer += 1;
511
512                 /* Set the Priority Byte Definition */
513
514                 temp8 = 0;
515                 temp8 = (u8) ((linked_list->data.start_dpf.performance_robustness &
516                                    0x03) << 2);
517                 temp8 |= (linked_list->data.start_dpf.compatibility_priority &
518                                    0x03);
519                 *buffer = temp8;
520         }
521
522         buffer += 1;
523
524         /* Return the number of bytes consumed in this operation */
525
526         *bytes_consumed = ACPI_PTR_DIFF (buffer, *output_buffer);
527         return_ACPI_STATUS (AE_OK);
528 }
529
530
531 /*******************************************************************************
532  *
533  * FUNCTION:    acpi_rs_end_depend_fns_stream
534  *
535  * PARAMETERS:  linked_list             - Pointer to the resource linked list
536  *              output_buffer           - Pointer to the user's return buffer
537  *              bytes_consumed          - Pointer to where the number of bytes
538  *                                        used in the output_buffer is returned
539  *
540  * RETURN:      Status
541  *
542  * DESCRIPTION: Take the linked list resource structure and fills in the
543  *              the appropriate bytes in a byte stream
544  *
545  ******************************************************************************/
546
547 acpi_status
548 acpi_rs_end_depend_fns_stream (
549         struct acpi_resource            *linked_list,
550         u8                              **output_buffer,
551         acpi_size                       *bytes_consumed)
552 {
553         u8                              *buffer = *output_buffer;
554
555
556         ACPI_FUNCTION_TRACE ("rs_end_depend_fns_stream");
557
558
559         /* The descriptor field is static */
560
561         *buffer = 0x38;
562         buffer += 1;
563
564         /* Return the number of bytes consumed in this operation */
565
566         *bytes_consumed = ACPI_PTR_DIFF (buffer, *output_buffer);
567         return_ACPI_STATUS (AE_OK);
568 }
569