[PATCH] s390: fix invalid return code in sclp_cpi
[linux-2.6.22.y-op.git] / drivers / acpi / resources / rsmisc.c
blob7a8a34e757f506a2c4d758b206bec6458b7c54bc
1 /*******************************************************************************
3 * Module Name: rsmisc - Miscellaneous resource descriptors
5 ******************************************************************************/
7 /*
8 * Copyright (C) 2000 - 2005, R. Byron Moore
9 * All rights reserved.
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.
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.
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.
44 #include <acpi/acpi.h>
45 #include <acpi/acresrc.h>
47 #define _COMPONENT ACPI_RESOURCES
48 ACPI_MODULE_NAME("rsmisc")
50 /*******************************************************************************
52 * FUNCTION: acpi_rs_end_tag_resource
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
63 * RETURN: Status
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.
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)
75 struct acpi_resource *output_struct = (void *)*output_buffer;
76 acpi_size struct_size = ACPI_RESOURCE_LENGTH;
78 ACPI_FUNCTION_TRACE("rs_end_tag_resource");
80 /* The number of bytes consumed is static */
82 *bytes_consumed = 2;
84 /* Fill out the structure */
86 output_struct->id = ACPI_RSTYPE_END_TAG;
88 /* Set the Length parameter */
90 output_struct->length = 0;
92 /* Return the final size of the structure */
94 *structure_size = struct_size;
95 return_ACPI_STATUS(AE_OK);
98 /*******************************************************************************
100 * FUNCTION: acpi_rs_end_tag_stream
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
107 * RETURN: Status
109 * DESCRIPTION: Take the linked list resource structure and fills in the
110 * the appropriate bytes in a byte stream
112 ******************************************************************************/
114 acpi_status
115 acpi_rs_end_tag_stream(struct acpi_resource *linked_list,
116 u8 ** output_buffer, acpi_size * bytes_consumed)
118 u8 *buffer = *output_buffer;
119 u8 temp8 = 0;
121 ACPI_FUNCTION_TRACE("rs_end_tag_stream");
123 /* The descriptor field is static */
125 *buffer = 0x79;
126 buffer += 1;
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)
132 temp8 = 0;
134 *buffer = temp8;
135 buffer += 1;
137 /* Return the number of bytes consumed in this operation */
139 *bytes_consumed = ACPI_PTR_DIFF(buffer, *output_buffer);
140 return_ACPI_STATUS(AE_OK);
143 /*******************************************************************************
145 * FUNCTION: acpi_rs_vendor_resource
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
156 * RETURN: Status
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.
162 ******************************************************************************/
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)
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);
177 ACPI_FUNCTION_TRACE("rs_vendor_resource");
179 /* Dereference the Descriptor to find if this is a large or small item. */
181 temp8 = *buffer;
183 if (temp8 & 0x80) {
184 /* Large Item, point to the length field */
186 buffer += 1;
188 /* Dereference */
190 ACPI_MOVE_16_TO_16(&temp16, buffer);
192 /* Calculate bytes consumed */
194 *bytes_consumed = (acpi_size) temp16 + 3;
196 /* Point to the first vendor byte */
198 buffer += 2;
199 } else {
200 /* Small Item, dereference the size */
202 temp16 = (u8) (*buffer & 0x07);
204 /* Calculate bytes consumed */
206 *bytes_consumed = (acpi_size) temp16 + 1;
208 /* Point to the first vendor byte */
210 buffer += 1;
213 output_struct->id = ACPI_RSTYPE_VENDOR;
214 output_struct->data.vendor_specific.length = temp16;
216 for (index = 0; index < temp16; index++) {
217 output_struct->data.vendor_specific.reserved[index] = *buffer;
218 buffer += 1;
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.
226 struct_size += ACPI_ROUND_UP_to_32_bITS(temp16);
228 /* Set the Length parameter */
230 output_struct->length = (u32) struct_size;
232 /* Return the final size of the structure */
234 *structure_size = struct_size;
235 return_ACPI_STATUS(AE_OK);
238 /*******************************************************************************
240 * FUNCTION: acpi_rs_vendor_stream
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
247 * RETURN: Status
249 * DESCRIPTION: Take the linked list resource structure and fills in the
250 * the appropriate bytes in a byte stream
252 ******************************************************************************/
254 acpi_status
255 acpi_rs_vendor_stream(struct acpi_resource *linked_list,
256 u8 ** output_buffer, acpi_size * bytes_consumed)
258 u8 *buffer = *output_buffer;
259 u16 temp16 = 0;
260 u8 temp8 = 0;
261 u8 index;
263 ACPI_FUNCTION_TRACE("rs_vendor_stream");
265 /* Dereference the length to find if this is a large or small item. */
267 if (linked_list->data.vendor_specific.length > 7) {
268 /* Large Item, Set the descriptor field and length bytes */
270 *buffer = 0x84;
271 buffer += 1;
273 temp16 = (u16) linked_list->data.vendor_specific.length;
275 ACPI_MOVE_16_TO_16(buffer, &temp16);
276 buffer += 2;
277 } else {
278 /* Small Item, Set the descriptor field */
280 temp8 = 0x70;
281 temp8 |= (u8) linked_list->data.vendor_specific.length;
283 *buffer = temp8;
284 buffer += 1;
287 /* Loop through all of the Vendor Specific fields */
289 for (index = 0; index < linked_list->data.vendor_specific.length;
290 index++) {
291 temp8 = linked_list->data.vendor_specific.reserved[index];
293 *buffer = temp8;
294 buffer += 1;
297 /* Return the number of bytes consumed in this operation */
299 *bytes_consumed = ACPI_PTR_DIFF(buffer, *output_buffer);
300 return_ACPI_STATUS(AE_OK);
303 /*******************************************************************************
305 * FUNCTION: acpi_rs_start_depend_fns_resource
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
316 * RETURN: Status
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.
322 ******************************************************************************/
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)
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);
336 ACPI_FUNCTION_TRACE("rs_start_depend_fns_resource");
338 /* The number of bytes consumed are found in the descriptor (Bits:0-1) */
340 temp8 = *buffer;
342 *bytes_consumed = (temp8 & 0x01) + 1;
344 output_struct->id = ACPI_RSTYPE_START_DPF;
346 /* Point to Byte 1 if it is used */
348 if (2 == *bytes_consumed) {
349 buffer += 1;
350 temp8 = *buffer;
352 /* Check Compatibility priority */
354 output_struct->data.start_dpf.compatibility_priority =
355 temp8 & 0x03;
357 if (3 == output_struct->data.start_dpf.compatibility_priority) {
358 return_ACPI_STATUS(AE_AML_BAD_RESOURCE_VALUE);
361 /* Check Performance/Robustness preference */
363 output_struct->data.start_dpf.performance_robustness =
364 (temp8 >> 2) & 0x03;
366 if (3 == output_struct->data.start_dpf.performance_robustness) {
367 return_ACPI_STATUS(AE_AML_BAD_RESOURCE_VALUE);
369 } else {
370 output_struct->data.start_dpf.compatibility_priority =
371 ACPI_ACCEPTABLE_CONFIGURATION;
373 output_struct->data.start_dpf.performance_robustness =
374 ACPI_ACCEPTABLE_CONFIGURATION;
377 /* Set the Length parameter */
379 output_struct->length = (u32) struct_size;
381 /* Return the final size of the structure */
383 *structure_size = struct_size;
384 return_ACPI_STATUS(AE_OK);
387 /*******************************************************************************
389 * FUNCTION: acpi_rs_end_depend_fns_resource
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
400 * RETURN: Status
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.
406 ******************************************************************************/
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)
413 struct acpi_resource *output_struct = (void *)*output_buffer;
414 acpi_size struct_size = ACPI_RESOURCE_LENGTH;
416 ACPI_FUNCTION_TRACE("rs_end_depend_fns_resource");
418 /* The number of bytes consumed is static */
420 *bytes_consumed = 1;
422 /* Fill out the structure */
424 output_struct->id = ACPI_RSTYPE_END_DPF;
426 /* Set the Length parameter */
428 output_struct->length = (u32) struct_size;
430 /* Return the final size of the structure */
432 *structure_size = struct_size;
433 return_ACPI_STATUS(AE_OK);
436 /*******************************************************************************
438 * FUNCTION: acpi_rs_start_depend_fns_stream
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
446 * RETURN: Status
448 * DESCRIPTION: Take the linked list resource structure and fills in the
449 * the appropriate bytes in a byte stream
451 ******************************************************************************/
453 acpi_status
454 acpi_rs_start_depend_fns_stream(struct acpi_resource *linked_list,
455 u8 ** output_buffer, acpi_size * bytes_consumed)
457 u8 *buffer = *output_buffer;
458 u8 temp8 = 0;
460 ACPI_FUNCTION_TRACE("rs_start_depend_fns_stream");
463 * The descriptor field is set based upon whether a byte is needed
464 * to contain Priority data.
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;
475 /* Set the Priority Byte Definition */
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;
486 buffer += 1;
488 /* Return the number of bytes consumed in this operation */
490 *bytes_consumed = ACPI_PTR_DIFF(buffer, *output_buffer);
491 return_ACPI_STATUS(AE_OK);
494 /*******************************************************************************
496 * FUNCTION: acpi_rs_end_depend_fns_stream
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
503 * RETURN: Status
505 * DESCRIPTION: Take the linked list resource structure and fills in the
506 * the appropriate bytes in a byte stream
508 ******************************************************************************/
510 acpi_status
511 acpi_rs_end_depend_fns_stream(struct acpi_resource *linked_list,
512 u8 ** output_buffer, acpi_size * bytes_consumed)
514 u8 *buffer = *output_buffer;
516 ACPI_FUNCTION_TRACE("rs_end_depend_fns_stream");
518 /* The descriptor field is static */
520 *buffer = 0x38;
521 buffer += 1;
523 /* Return the number of bytes consumed in this operation */
525 *bytes_consumed = ACPI_PTR_DIFF(buffer, *output_buffer);
526 return_ACPI_STATUS(AE_OK);