Merge from-linus to-akpm
[deliverable/linux.git] / 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 #include <acpi/acpi.h>
45 #include <acpi/acresrc.h>
46
47 #define _COMPONENT ACPI_RESOURCES
48 ACPI_MODULE_NAME("rsmisc")
49
50 /*******************************************************************************
51 *
52 * FUNCTION: acpi_rs_end_tag_resource
53 *
54 * PARAMETERS: byte_stream_buffer - Pointer to the resource input byte
55 * stream
56 * bytes_consumed - Pointer to where the number of bytes
57 * consumed the byte_stream_buffer is
58 * returned
59 * output_buffer - Pointer to the return data buffer
60 * structure_size - Pointer to where the number of bytes
61 * in the return data struct is returned
62 *
63 * RETURN: Status
64 *
65 * DESCRIPTION: Take the resource byte stream and fill out the appropriate
66 * structure pointed to by the output_buffer. Return the
67 * number of bytes consumed from the byte stream.
68 *
69 ******************************************************************************/
70 acpi_status
71 acpi_rs_end_tag_resource(u8 * byte_stream_buffer,
72 acpi_size * bytes_consumed,
73 u8 ** output_buffer, acpi_size * structure_size)
74 {
75 struct acpi_resource *output_struct = (void *)*output_buffer;
76 acpi_size struct_size = ACPI_RESOURCE_LENGTH;
77
78 ACPI_FUNCTION_TRACE("rs_end_tag_resource");
79
80 /* The number of bytes consumed is static */
81
82 *bytes_consumed = 2;
83
84 /* Fill out the structure */
85
86 output_struct->id = ACPI_RSTYPE_END_TAG;
87
88 /* Set the Length parameter */
89
90 output_struct->length = 0;
91
92 /* Return the final size of the structure */
93
94 *structure_size = struct_size;
95 return_ACPI_STATUS(AE_OK);
96 }
97
98 /*******************************************************************************
99 *
100 * FUNCTION: acpi_rs_end_tag_stream
101 *
102 * PARAMETERS: linked_list - Pointer to the resource linked list
103 * output_buffer - Pointer to the user's return buffer
104 * bytes_consumed - Pointer to where the number of bytes
105 * used in the output_buffer is returned
106 *
107 * RETURN: Status
108 *
109 * DESCRIPTION: Take the linked list resource structure and fills in the
110 * the appropriate bytes in a byte stream
111 *
112 ******************************************************************************/
113
114 acpi_status
115 acpi_rs_end_tag_stream(struct acpi_resource *linked_list,
116 u8 ** output_buffer, acpi_size * bytes_consumed)
117 {
118 u8 *buffer = *output_buffer;
119 u8 temp8 = 0;
120
121 ACPI_FUNCTION_TRACE("rs_end_tag_stream");
122
123 /* The descriptor field is static */
124
125 *buffer = 0x79;
126 buffer += 1;
127
128 /*
129 * Set the Checksum - zero means that the resource data is treated as if
130 * the checksum operation succeeded (ACPI Spec 1.0b Section 6.4.2.8)
131 */
132 temp8 = 0;
133
134 *buffer = temp8;
135 buffer += 1;
136
137 /* Return the number of bytes consumed in this operation */
138
139 *bytes_consumed = ACPI_PTR_DIFF(buffer, *output_buffer);
140 return_ACPI_STATUS(AE_OK);
141 }
142
143 /*******************************************************************************
144 *
145 * FUNCTION: acpi_rs_vendor_resource
146 *
147 * PARAMETERS: byte_stream_buffer - Pointer to the resource input byte
148 * stream
149 * bytes_consumed - Pointer to where the number of bytes
150 * consumed the byte_stream_buffer is
151 * returned
152 * output_buffer - Pointer to the return data buffer
153 * structure_size - Pointer to where the number of bytes
154 * in the return data struct is returned
155 *
156 * RETURN: Status
157 *
158 * DESCRIPTION: Take the resource byte stream and fill out the appropriate
159 * structure pointed to by the output_buffer. Return the
160 * number of bytes consumed from the byte stream.
161 *
162 ******************************************************************************/
163
164 acpi_status
165 acpi_rs_vendor_resource(u8 * byte_stream_buffer,
166 acpi_size * bytes_consumed,
167 u8 ** output_buffer, acpi_size * structure_size)
168 {
169 u8 *buffer = byte_stream_buffer;
170 struct acpi_resource *output_struct = (void *)*output_buffer;
171 u16 temp16 = 0;
172 u8 temp8 = 0;
173 u8 index;
174 acpi_size struct_size =
175 ACPI_SIZEOF_RESOURCE(struct acpi_resource_vendor);
176
177 ACPI_FUNCTION_TRACE("rs_vendor_resource");
178
179 /* Dereference the Descriptor to find if this is a large or small item. */
180
181 temp8 = *buffer;
182
183 if (temp8 & 0x80) {
184 /* Large Item, point to the length field */
185
186 buffer += 1;
187
188 /* Dereference */
189
190 ACPI_MOVE_16_TO_16(&temp16, buffer);
191
192 /* Calculate bytes consumed */
193
194 *bytes_consumed = (acpi_size) temp16 + 3;
195
196 /* Point to the first vendor byte */
197
198 buffer += 2;
199 } else {
200 /* Small Item, dereference the size */
201
202 temp16 = (u8) (*buffer & 0x07);
203
204 /* Calculate bytes consumed */
205
206 *bytes_consumed = (acpi_size) temp16 + 1;
207
208 /* Point to the first vendor byte */
209
210 buffer += 1;
211 }
212
213 output_struct->id = ACPI_RSTYPE_VENDOR;
214 output_struct->data.vendor_specific.length = temp16;
215
216 for (index = 0; index < temp16; index++) {
217 output_struct->data.vendor_specific.reserved[index] = *buffer;
218 buffer += 1;
219 }
220
221 /*
222 * In order for the struct_size to fall on a 32-bit boundary,
223 * calculate the length of the vendor string and expand the
224 * struct_size to the next 32-bit boundary.
225 */
226 struct_size += ACPI_ROUND_UP_to_32_bITS(temp16);
227
228 /* Set the Length parameter */
229
230 output_struct->length = (u32) struct_size;
231
232 /* Return the final size of the structure */
233
234 *structure_size = struct_size;
235 return_ACPI_STATUS(AE_OK);
236 }
237
238 /*******************************************************************************
239 *
240 * FUNCTION: acpi_rs_vendor_stream
241 *
242 * PARAMETERS: linked_list - Pointer to the resource linked list
243 * output_buffer - Pointer to the user's return buffer
244 * bytes_consumed - Pointer to where the number of bytes
245 * used in the output_buffer is returned
246 *
247 * RETURN: Status
248 *
249 * DESCRIPTION: Take the linked list resource structure and fills in the
250 * the appropriate bytes in a byte stream
251 *
252 ******************************************************************************/
253
254 acpi_status
255 acpi_rs_vendor_stream(struct acpi_resource *linked_list,
256 u8 ** output_buffer, acpi_size * bytes_consumed)
257 {
258 u8 *buffer = *output_buffer;
259 u16 temp16 = 0;
260 u8 temp8 = 0;
261 u8 index;
262
263 ACPI_FUNCTION_TRACE("rs_vendor_stream");
264
265 /* Dereference the length to find if this is a large or small item. */
266
267 if (linked_list->data.vendor_specific.length > 7) {
268 /* Large Item, Set the descriptor field and length bytes */
269
270 *buffer = 0x84;
271 buffer += 1;
272
273 temp16 = (u16) linked_list->data.vendor_specific.length;
274
275 ACPI_MOVE_16_TO_16(buffer, &temp16);
276 buffer += 2;
277 } else {
278 /* Small Item, Set the descriptor field */
279
280 temp8 = 0x70;
281 temp8 |= (u8) linked_list->data.vendor_specific.length;
282
283 *buffer = temp8;
284 buffer += 1;
285 }
286
287 /* Loop through all of the Vendor Specific fields */
288
289 for (index = 0; index < linked_list->data.vendor_specific.length;
290 index++) {
291 temp8 = linked_list->data.vendor_specific.reserved[index];
292
293 *buffer = temp8;
294 buffer += 1;
295 }
296
297 /* Return the number of bytes consumed in this operation */
298
299 *bytes_consumed = ACPI_PTR_DIFF(buffer, *output_buffer);
300 return_ACPI_STATUS(AE_OK);
301 }
302
303 /*******************************************************************************
304 *
305 * FUNCTION: acpi_rs_start_depend_fns_resource
306 *
307 * PARAMETERS: byte_stream_buffer - Pointer to the resource input byte
308 * stream
309 * bytes_consumed - Pointer to where the number of bytes
310 * consumed the byte_stream_buffer is
311 * returned
312 * output_buffer - Pointer to the return data buffer
313 * structure_size - Pointer to where the number of bytes
314 * in the return data struct is returned
315 *
316 * RETURN: Status
317 *
318 * DESCRIPTION: Take the resource byte stream and fill out the appropriate
319 * structure pointed to by the output_buffer. Return the
320 * number of bytes consumed from the byte stream.
321 *
322 ******************************************************************************/
323
324 acpi_status
325 acpi_rs_start_depend_fns_resource(u8 * byte_stream_buffer,
326 acpi_size * bytes_consumed,
327 u8 ** output_buffer,
328 acpi_size * structure_size)
329 {
330 u8 *buffer = byte_stream_buffer;
331 struct acpi_resource *output_struct = (void *)*output_buffer;
332 u8 temp8 = 0;
333 acpi_size struct_size =
334 ACPI_SIZEOF_RESOURCE(struct acpi_resource_start_dpf);
335
336 ACPI_FUNCTION_TRACE("rs_start_depend_fns_resource");
337
338 /* The number of bytes consumed are found in the descriptor (Bits:0-1) */
339
340 temp8 = *buffer;
341
342 *bytes_consumed = (temp8 & 0x01) + 1;
343
344 output_struct->id = ACPI_RSTYPE_START_DPF;
345
346 /* Point to Byte 1 if it is used */
347
348 if (2 == *bytes_consumed) {
349 buffer += 1;
350 temp8 = *buffer;
351
352 /* Check Compatibility priority */
353
354 output_struct->data.start_dpf.compatibility_priority =
355 temp8 & 0x03;
356
357 if (3 == output_struct->data.start_dpf.compatibility_priority) {
358 return_ACPI_STATUS(AE_AML_BAD_RESOURCE_VALUE);
359 }
360
361 /* Check Performance/Robustness preference */
362
363 output_struct->data.start_dpf.performance_robustness =
364 (temp8 >> 2) & 0x03;
365
366 if (3 == output_struct->data.start_dpf.performance_robustness) {
367 return_ACPI_STATUS(AE_AML_BAD_RESOURCE_VALUE);
368 }
369 } else {
370 output_struct->data.start_dpf.compatibility_priority =
371 ACPI_ACCEPTABLE_CONFIGURATION;
372
373 output_struct->data.start_dpf.performance_robustness =
374 ACPI_ACCEPTABLE_CONFIGURATION;
375 }
376
377 /* Set the Length parameter */
378
379 output_struct->length = (u32) struct_size;
380
381 /* Return the final size of the structure */
382
383 *structure_size = struct_size;
384 return_ACPI_STATUS(AE_OK);
385 }
386
387 /*******************************************************************************
388 *
389 * FUNCTION: acpi_rs_end_depend_fns_resource
390 *
391 * PARAMETERS: byte_stream_buffer - Pointer to the resource input byte
392 * stream
393 * bytes_consumed - Pointer to where the number of bytes
394 * consumed the byte_stream_buffer is
395 * returned
396 * output_buffer - Pointer to the return data buffer
397 * structure_size - Pointer to where the number of bytes
398 * in the return data struct is returned
399 *
400 * RETURN: Status
401 *
402 * DESCRIPTION: Take the resource byte stream and fill out the appropriate
403 * structure pointed to by the output_buffer. Return the
404 * number of bytes consumed from the byte stream.
405 *
406 ******************************************************************************/
407
408 acpi_status
409 acpi_rs_end_depend_fns_resource(u8 * byte_stream_buffer,
410 acpi_size * bytes_consumed,
411 u8 ** output_buffer, acpi_size * structure_size)
412 {
413 struct acpi_resource *output_struct = (void *)*output_buffer;
414 acpi_size struct_size = ACPI_RESOURCE_LENGTH;
415
416 ACPI_FUNCTION_TRACE("rs_end_depend_fns_resource");
417
418 /* The number of bytes consumed is static */
419
420 *bytes_consumed = 1;
421
422 /* Fill out the structure */
423
424 output_struct->id = ACPI_RSTYPE_END_DPF;
425
426 /* Set the Length parameter */
427
428 output_struct->length = (u32) struct_size;
429
430 /* Return the final size of the structure */
431
432 *structure_size = struct_size;
433 return_ACPI_STATUS(AE_OK);
434 }
435
436 /*******************************************************************************
437 *
438 * FUNCTION: acpi_rs_start_depend_fns_stream
439 *
440 * PARAMETERS: linked_list - Pointer to the resource linked list
441 * output_buffer - Pointer to the user's return buffer
442 * bytes_consumed - u32 pointer that is filled with
443 * the number of bytes of the
444 * output_buffer used
445 *
446 * RETURN: Status
447 *
448 * DESCRIPTION: Take the linked list resource structure and fills in the
449 * the appropriate bytes in a byte stream
450 *
451 ******************************************************************************/
452
453 acpi_status
454 acpi_rs_start_depend_fns_stream(struct acpi_resource *linked_list,
455 u8 ** output_buffer, acpi_size * bytes_consumed)
456 {
457 u8 *buffer = *output_buffer;
458 u8 temp8 = 0;
459
460 ACPI_FUNCTION_TRACE("rs_start_depend_fns_stream");
461
462 /*
463 * The descriptor field is set based upon whether a byte is needed
464 * to contain Priority data.
465 */
466 if (ACPI_ACCEPTABLE_CONFIGURATION ==
467 linked_list->data.start_dpf.compatibility_priority &&
468 ACPI_ACCEPTABLE_CONFIGURATION ==
469 linked_list->data.start_dpf.performance_robustness) {
470 *buffer = 0x30;
471 } else {
472 *buffer = 0x31;
473 buffer += 1;
474
475 /* Set the Priority Byte Definition */
476
477 temp8 = 0;
478 temp8 =
479 (u8) ((linked_list->data.start_dpf.
480 performance_robustness & 0x03) << 2);
481 temp8 |=
482 (linked_list->data.start_dpf.compatibility_priority & 0x03);
483 *buffer = temp8;
484 }
485
486 buffer += 1;
487
488 /* Return the number of bytes consumed in this operation */
489
490 *bytes_consumed = ACPI_PTR_DIFF(buffer, *output_buffer);
491 return_ACPI_STATUS(AE_OK);
492 }
493
494 /*******************************************************************************
495 *
496 * FUNCTION: acpi_rs_end_depend_fns_stream
497 *
498 * PARAMETERS: linked_list - Pointer to the resource linked list
499 * output_buffer - Pointer to the user's return buffer
500 * bytes_consumed - Pointer to where the number of bytes
501 * used in the output_buffer is returned
502 *
503 * RETURN: Status
504 *
505 * DESCRIPTION: Take the linked list resource structure and fills in the
506 * the appropriate bytes in a byte stream
507 *
508 ******************************************************************************/
509
510 acpi_status
511 acpi_rs_end_depend_fns_stream(struct acpi_resource *linked_list,
512 u8 ** output_buffer, acpi_size * bytes_consumed)
513 {
514 u8 *buffer = *output_buffer;
515
516 ACPI_FUNCTION_TRACE("rs_end_depend_fns_stream");
517
518 /* The descriptor field is static */
519
520 *buffer = 0x38;
521 buffer += 1;
522
523 /* Return the number of bytes consumed in this operation */
524
525 *bytes_consumed = ACPI_PTR_DIFF(buffer, *output_buffer);
526 return_ACPI_STATUS(AE_OK);
527 }
This page took 0.055284 seconds and 6 git commands to generate.