import of ftp.dlink.com/GPL/DSMG-600_reB/ppclinux.tar.gz
[linux-2.4.21-pre4.git] / drivers / acpi / resources / rsmisc.c
1 /*******************************************************************************
2  *
3  * Module Name: rsmisc - Miscellaneous resource descriptors
4  *              $Revision: 1.1.1.1 $
5  *
6  ******************************************************************************/
7
8 /*
9  *  Copyright (C) 2000, 2001 R. Byron Moore
10  *
11  *  This program is free software; you can redistribute it and/or modify
12  *  it under the terms of the GNU General Public License as published by
13  *  the Free Software Foundation; either version 2 of the License, or
14  *  (at your option) any later version.
15  *
16  *  This program is distributed in the hope that it will be useful,
17  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  *  GNU General Public License for more details.
20  *
21  *  You should have received a copy of the GNU General Public License
22  *  along with this program; if not, write to the Free Software
23  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
24  */
25
26
27 #include "acpi.h"
28 #include "acresrc.h"
29
30 #define _COMPONENT          ACPI_RESOURCES
31          MODULE_NAME         ("rsmisc")
32
33
34 /*******************************************************************************
35  *
36  * FUNCTION:    Acpi_rs_end_tag_resource
37  *
38  * PARAMETERS:  Byte_stream_buffer      - Pointer to the resource input byte
39  *                                        stream
40  *              Bytes_consumed          - u32 pointer that is filled with
41  *                                        the number of bytes consumed from
42  *                                        the Byte_stream_buffer
43  *              Output_buffer           - Pointer to the user's return buffer
44  *              Structure_size          - u32 pointer that is filled with
45  *                                        the number of bytes in the filled
46  *                                        in structure
47  *
48  * RETURN:      Status
49  *
50  * DESCRIPTION: Take the resource byte stream and fill out the appropriate
51  *              structure pointed to by the Output_buffer. Return the
52  *              number of bytes consumed from the byte stream.
53  *
54  ******************************************************************************/
55
56 acpi_status
57 acpi_rs_end_tag_resource (
58         u8                      *byte_stream_buffer,
59         u32                     *bytes_consumed,
60         u8                      **output_buffer,
61         u32                     *structure_size)
62 {
63         acpi_resource           *output_struct = (acpi_resource *) *output_buffer;
64         u32                     struct_size = ACPI_RESOURCE_LENGTH;
65
66
67         FUNCTION_TRACE ("Rs_end_tag_resource");
68
69
70         /*
71          * The number of bytes consumed is static
72          */
73         *bytes_consumed = 2;
74
75         /*
76          *  Fill out the structure
77          */
78         output_struct->id = ACPI_RSTYPE_END_TAG;
79
80         /*
81          * Set the Length parameter
82          */
83         output_struct->length = 0;
84
85         /*
86          * Return the final size of the structure
87          */
88         *structure_size = struct_size;
89         return_ACPI_STATUS (AE_OK);
90 }
91
92
93 /*******************************************************************************
94  *
95  * FUNCTION:    Acpi_rs_end_tag_stream
96  *
97  * PARAMETERS:  Linked_list             - Pointer to the resource linked list
98  *              Output_buffer           - Pointer to the user's return buffer
99  *              Bytes_consumed          - u32 pointer that is filled with
100  *                                        the number of bytes of the
101  *                                        Output_buffer used
102  *
103  * RETURN:      Status
104  *
105  * DESCRIPTION: Take the linked list resource structure and fills in the
106  *              the appropriate bytes in a byte stream
107  *
108  ******************************************************************************/
109
110 acpi_status
111 acpi_rs_end_tag_stream (
112         acpi_resource           *linked_list,
113         u8                      **output_buffer,
114         u32                     *bytes_consumed)
115 {
116         u8                      *buffer = *output_buffer;
117         u8                      temp8 = 0;
118
119
120         FUNCTION_TRACE ("Rs_end_tag_stream");
121
122
123         /*
124          * The descriptor field is static
125          */
126         *buffer = 0x79;
127         buffer += 1;
128
129         /*
130          * Set the Checksum - zero means that the resource data is treated as if
131          * the checksum operation succeeded (ACPI Spec 1.0b Section 6.4.2.8)
132          */
133         temp8 = 0;
134
135         *buffer = temp8;
136         buffer += 1;
137
138         /*
139          * Return the number of bytes consumed in this operation
140          */
141         *bytes_consumed = POINTER_DIFF (buffer, *output_buffer);
142         return_ACPI_STATUS (AE_OK);
143 }
144
145
146 /*******************************************************************************
147  *
148  * FUNCTION:    Acpi_rs_vendor_resource
149  *
150  * PARAMETERS:  Byte_stream_buffer      - Pointer to the resource input byte
151  *                                        stream
152  *              Bytes_consumed          - u32 pointer that is filled with
153  *                                        the number of bytes consumed from
154  *                                        the Byte_stream_buffer
155  *              Output_buffer           - Pointer to the user's return buffer
156  *              Structure_size          - u32 pointer that is filled with
157  *                                        the number of bytes in the filled
158  *                                        in structure
159  *
160  * RETURN:      Status
161  *
162  * DESCRIPTION: Take the resource byte stream and fill out the appropriate
163  *              structure pointed to by the Output_buffer. Return the
164  *              number of bytes consumed from the byte stream.
165  *
166  ******************************************************************************/
167
168 acpi_status
169 acpi_rs_vendor_resource (
170         u8                      *byte_stream_buffer,
171         u32                     *bytes_consumed,
172         u8                      **output_buffer,
173         u32                     *structure_size)
174 {
175         u8                      *buffer = byte_stream_buffer;
176         acpi_resource           *output_struct = (acpi_resource *) *output_buffer;
177         u16                     temp16 = 0;
178         u8                      temp8 = 0;
179         u8                      index;
180         u32                     struct_size = SIZEOF_RESOURCE (acpi_resource_vendor);
181
182
183         FUNCTION_TRACE ("Rs_vendor_resource");
184
185
186         /*
187          * Dereference the Descriptor to find if this is a large or small item.
188          */
189         temp8 = *buffer;
190
191         if (temp8 & 0x80) {
192                 /*
193                  * Large Item
194                  * Point to the length field
195                  */
196                 buffer += 1;
197
198                 /* Dereference */
199
200                 MOVE_UNALIGNED16_TO_16 (&temp16, buffer);
201
202                 /* Calculate bytes consumed */
203
204                 *bytes_consumed = temp16 + 3;
205
206                 /* Point to the first vendor byte */
207
208                 buffer += 2;
209         }
210
211         else {
212                 /*
213                  * Small Item
214                  * Dereference the size
215                  */
216                 temp16 = (u8)(*buffer & 0x07);
217
218                 /* Calculate bytes consumed */
219
220                 *bytes_consumed = temp16 + 1;
221
222                 /* Point to the first vendor byte */
223
224                 buffer += 1;
225         }
226
227         output_struct->id = ACPI_RSTYPE_VENDOR;
228         output_struct->data.vendor_specific.length = temp16;
229
230         for (index = 0; index < temp16; index++) {
231                 output_struct->data.vendor_specific.reserved[index] = *buffer;
232                 buffer += 1;
233         }
234
235         /*
236          * In order for the Struct_size to fall on a 32-bit boundary,
237          * calculate the length of the vendor string and expand the
238          * Struct_size to the next 32-bit boundary.
239          */
240         struct_size += ROUND_UP_TO_32_bITS (temp16);
241
242         /*
243          * Set the Length parameter
244          */
245         output_struct->length = struct_size;
246
247         /*
248          * Return the final size of the structure
249          */
250         *structure_size = struct_size;
251         return_ACPI_STATUS (AE_OK);
252 }
253
254
255 /*******************************************************************************
256  *
257  * FUNCTION:    Acpi_rs_vendor_stream
258  *
259  * PARAMETERS:  Linked_list             - Pointer to the resource linked list
260  *              Output_buffer           - Pointer to the user's return buffer
261  *              Bytes_consumed          - u32 pointer that is filled with
262  *                                        the number of bytes of the
263  *                                        Output_buffer used
264  *
265  * RETURN:      Status
266  *
267  * DESCRIPTION: Take the linked list resource structure and fills in the
268  *              the appropriate bytes in a byte stream
269  *
270  ******************************************************************************/
271
272 acpi_status
273 acpi_rs_vendor_stream (
274         acpi_resource           *linked_list,
275         u8                      **output_buffer,
276         u32                     *bytes_consumed)
277 {
278         u8                      *buffer = *output_buffer;
279         u16                     temp16 = 0;
280         u8                      temp8 = 0;
281         u8                      index;
282
283
284         FUNCTION_TRACE ("Rs_vendor_stream");
285
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                 /*
292                  * Large Item
293                  * Set the descriptor field and length bytes
294                  */
295                 *buffer = 0x84;
296                 buffer += 1;
297
298                 temp16 = (u16) linked_list->data.vendor_specific.length;
299
300                 MOVE_UNALIGNED16_TO_16 (buffer, &temp16);
301                 buffer += 2;
302         }
303
304         else {
305                 /*
306                  * Small Item
307                  * Set the descriptor field
308                  */
309                 temp8 = 0x70;
310                 temp8 |= linked_list->data.vendor_specific.length;
311
312                 *buffer = temp8;
313                 buffer += 1;
314         }
315
316         /*
317          * Loop through all of the Vendor Specific fields
318          */
319         for (index = 0; index < linked_list->data.vendor_specific.length; index++) {
320                 temp8 = linked_list->data.vendor_specific.reserved[index];
321
322                 *buffer = temp8;
323                 buffer += 1;
324         }
325
326         /*
327          * Return the number of bytes consumed in this operation
328          */
329         *bytes_consumed = POINTER_DIFF (buffer, *output_buffer);
330         return_ACPI_STATUS (AE_OK);
331 }
332
333
334 /*******************************************************************************
335  *
336  * FUNCTION:    Acpi_rs_start_dependent_functions_resource
337  *
338  * PARAMETERS:  Byte_stream_buffer      - Pointer to the resource input byte
339  *                                        stream
340  *              Bytes_consumed          - u32 pointer that is filled with
341  *                                        the number of bytes consumed from
342  *                                        the Byte_stream_buffer
343  *              Output_buffer           - Pointer to the user's return buffer
344  *              Structure_size          - u32 pointer that is filled with
345  *                                        the number of bytes in the filled
346  *                                        in structure
347  *
348  * RETURN:      Status
349  *
350  * DESCRIPTION: Take the resource byte stream and fill out the appropriate
351  *              structure pointed to by the Output_buffer. Return the
352  *              number of bytes consumed from the byte stream.
353  *
354  ******************************************************************************/
355
356 acpi_status
357 acpi_rs_start_dependent_functions_resource (
358         u8                      *byte_stream_buffer,
359         u32                     *bytes_consumed,
360         u8                      **output_buffer,
361         u32                     *structure_size)
362 {
363         u8                      *buffer = byte_stream_buffer;
364         acpi_resource          *output_struct = (acpi_resource *) *output_buffer;
365         u8                      temp8 = 0;
366         u32                     struct_size = SIZEOF_RESOURCE (acpi_resource_start_dpf);
367
368
369         FUNCTION_TRACE ("Rs_start_dependent_functions_resource");
370
371
372         /*
373          * The number of bytes consumed are contained in the descriptor (Bits:0-1)
374          */
375         temp8 = *buffer;
376
377         *bytes_consumed = (temp8 & 0x01) + 1;
378
379         output_struct->id = ACPI_RSTYPE_START_DPF;
380
381         /*
382          * Point to Byte 1 if it is used
383          */
384         if (2 == *bytes_consumed) {
385                 buffer += 1;
386                 temp8 = *buffer;
387
388                 /*
389                  * Check Compatibility priority
390                  */
391                 output_struct->data.start_dpf.compatibility_priority = temp8 & 0x03;
392
393                 if (3 == output_struct->data.start_dpf.compatibility_priority) {
394                         return_ACPI_STATUS (AE_AML_ERROR);
395                 }
396
397                 /*
398                  * Check Performance/Robustness preference
399                  */
400                 output_struct->data.start_dpf.performance_robustness = (temp8 >> 2) & 0x03;
401
402                 if (3 == output_struct->data.start_dpf.performance_robustness) {
403                         return_ACPI_STATUS (AE_AML_ERROR);
404                 }
405         }
406
407         else {
408                 output_struct->data.start_dpf.compatibility_priority =
409                                 ACCEPTABLE_CONFIGURATION;
410
411                 output_struct->data.start_dpf.performance_robustness =
412                                 ACCEPTABLE_CONFIGURATION;
413         }
414
415         /*
416          * Set the Length parameter
417          */
418         output_struct->length = struct_size;
419
420         /*
421          * Return the final size of the structure
422          */
423         *structure_size = struct_size;
424         return_ACPI_STATUS (AE_OK);
425 }
426
427
428 /*******************************************************************************
429  *
430  * FUNCTION:    Acpi_rs_end_dependent_functions_resource
431  *
432  * PARAMETERS:  Byte_stream_buffer      - Pointer to the resource input byte
433  *                                        stream
434  *              Bytes_consumed          - u32 pointer that is filled with
435  *                                        the number of bytes consumed from
436  *                                        the Byte_stream_buffer
437  *              Output_buffer           - Pointer to the user's return buffer
438  *              Structure_size          - u32 pointer that is filled with
439  *                                        the number of bytes in the filled
440  *                                        in structure
441  *
442  * RETURN:      Status
443  *
444  * DESCRIPTION: Take the resource byte stream and fill out the appropriate
445  *              structure pointed to by the Output_buffer. Return the
446  *              number of bytes consumed from the byte stream.
447  *
448  ******************************************************************************/
449
450 acpi_status
451 acpi_rs_end_dependent_functions_resource (
452         u8                      *byte_stream_buffer,
453         u32                     *bytes_consumed,
454         u8                      **output_buffer,
455         u32                     *structure_size)
456 {
457         acpi_resource           *output_struct = (acpi_resource *) *output_buffer;
458         u32                     struct_size = ACPI_RESOURCE_LENGTH;
459
460
461         FUNCTION_TRACE ("Rs_end_dependent_functions_resource");
462
463
464         /*
465          * The number of bytes consumed is static
466          */
467         *bytes_consumed = 1;
468
469         /*
470          *  Fill out the structure
471          */
472         output_struct->id = ACPI_RSTYPE_END_DPF;
473
474         /*
475          * Set the Length parameter
476          */
477         output_struct->length = struct_size;
478
479         /*
480          * Return the final size of the structure
481          */
482         *structure_size = struct_size;
483         return_ACPI_STATUS (AE_OK);
484 }
485
486
487 /*******************************************************************************
488  *
489  * FUNCTION:    Acpi_rs_start_dependent_functions_stream
490  *
491  * PARAMETERS:  Linked_list             - Pointer to the resource linked list
492  *              Output_buffer           - Pointer to the user's return buffer
493  *              Bytes_consumed          - u32 pointer that is filled with
494  *                                        the number of bytes of the
495  *                                        Output_buffer used
496  *
497  * RETURN:      Status
498  *
499  * DESCRIPTION: Take the linked list resource structure and fills in the
500  *              the appropriate bytes in a byte stream
501  *
502  ******************************************************************************/
503
504 acpi_status
505 acpi_rs_start_dependent_functions_stream (
506         acpi_resource           *linked_list,
507         u8                      **output_buffer,
508         u32                     *bytes_consumed)
509 {
510         u8                      *buffer = *output_buffer;
511         u8                      temp8 = 0;
512
513
514         FUNCTION_TRACE ("Rs_start_dependent_functions_stream");
515
516
517         /*
518          * The descriptor field is set based upon whether a byte is needed
519          * to contain Priority data.
520          */
521         if (ACCEPTABLE_CONFIGURATION ==
522                         linked_list->data.start_dpf.compatibility_priority &&
523                 ACCEPTABLE_CONFIGURATION ==
524                         linked_list->data.start_dpf.performance_robustness) {
525                 *buffer = 0x30;
526         }
527         else {
528                 *buffer = 0x31;
529                 buffer += 1;
530
531                 /*
532                  * Set the Priority Byte Definition
533                  */
534                 temp8 = 0;
535                 temp8 = (u8) ((linked_list->data.start_dpf.performance_robustness &
536                                    0x03) << 2);
537                 temp8 |= (linked_list->data.start_dpf.compatibility_priority &
538                                    0x03);
539                 *buffer = temp8;
540         }
541
542         buffer += 1;
543
544         /*
545          * Return the number of bytes consumed in this operation
546          */
547         *bytes_consumed = POINTER_DIFF (buffer, *output_buffer);
548         return_ACPI_STATUS (AE_OK);
549 }
550
551
552 /*******************************************************************************
553  *
554  * FUNCTION:    Acpi_rs_end_dependent_functions_stream
555  *
556  * PARAMETERS:  Linked_list             - Pointer to the resource linked list
557  *              Output_buffer           - Pointer to the user's return buffer
558  *              Bytes_consumed          - u32 pointer that is filled with
559  *                                        the number of bytes of the
560  *                                        Output_buffer used
561  *
562  * RETURN:      Status
563  *
564  * DESCRIPTION: Take the linked list resource structure and fills in the
565  *              the appropriate bytes in a byte stream
566  *
567  ******************************************************************************/
568
569 acpi_status
570 acpi_rs_end_dependent_functions_stream (
571         acpi_resource           *linked_list,
572         u8                      **output_buffer,
573         u32                     *bytes_consumed
574         )
575 {
576         u8                      *buffer = *output_buffer;
577
578
579         FUNCTION_TRACE ("Rs_end_dependent_functions_stream");
580
581
582         /*
583          * The descriptor field is static
584          */
585         *buffer = 0x38;
586         buffer += 1;
587
588         /*
589          * Return the number of bytes consumed in this operation
590          */
591         *bytes_consumed = POINTER_DIFF (buffer, *output_buffer);
592         return_ACPI_STATUS (AE_OK);
593 }
594