1 /*******************************************************************************
3 * Module Name: rsmisc - Miscellaneous resource descriptors
5 ******************************************************************************/
8 * Copyright (C) 2000 - 2005, R. Byron Moore
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
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.
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_get_generic_reg
54 * PARAMETERS: Aml - Pointer to the AML resource descriptor
55 * aml_resource_length - Length of the resource from the AML header
56 * Resource - Where the internal resource is returned
60 * DESCRIPTION: Convert a raw AML resource descriptor to the corresponding
61 * internal resource descriptor, simplifying bitflags and handling
62 * alignment and endian issues if necessary.
64 ******************************************************************************/
66 acpi_rs_get_generic_reg(union aml_resource *aml,
67 u16 aml_resource_length, struct acpi_resource *resource)
69 ACPI_FUNCTION_TRACE("rs_get_generic_reg");
72 * Get the following fields from the AML descriptor:
79 resource->data.generic_reg.space_id = aml->generic_reg.address_space_id;
80 resource->data.generic_reg.bit_width = aml->generic_reg.bit_width;
81 resource->data.generic_reg.bit_offset = aml->generic_reg.bit_offset;
82 resource->data.generic_reg.access_size = aml->generic_reg.access_size;
83 ACPI_MOVE_64_TO_64(&resource->data.generic_reg.address,
84 &aml->generic_reg.address);
86 /* Complete the resource header */
88 resource->type = ACPI_RESOURCE_TYPE_GENERIC_REGISTER;
90 ACPI_SIZEOF_RESOURCE(struct acpi_resource_generic_register);
91 return_ACPI_STATUS(AE_OK);
94 /*******************************************************************************
96 * FUNCTION: acpi_rs_set_generic_reg
98 * PARAMETERS: Resource - Pointer to the resource descriptor
99 * Aml - Where the AML descriptor is returned
103 * DESCRIPTION: Convert an internal resource descriptor to the corresponding
104 * external AML resource descriptor.
106 ******************************************************************************/
109 acpi_rs_set_generic_reg(struct acpi_resource *resource, union aml_resource *aml)
111 ACPI_FUNCTION_TRACE("rs_set_generic_reg");
114 * Set the following fields in the AML descriptor:
117 * Register Bit Offset
121 aml->generic_reg.address_space_id =
122 (u8) resource->data.generic_reg.space_id;
123 aml->generic_reg.bit_width = (u8) resource->data.generic_reg.bit_width;
124 aml->generic_reg.bit_offset =
125 (u8) resource->data.generic_reg.bit_offset;
126 aml->generic_reg.access_size =
127 (u8) resource->data.generic_reg.access_size;
128 ACPI_MOVE_64_TO_64(&aml->generic_reg.address,
129 &resource->data.generic_reg.address);
131 /* Complete the AML descriptor header */
133 acpi_rs_set_resource_header(ACPI_RESOURCE_NAME_GENERIC_REGISTER,
135 aml_resource_generic_register), aml);
136 return_ACPI_STATUS(AE_OK);
139 /*******************************************************************************
141 * FUNCTION: acpi_rs_get_vendor
143 * PARAMETERS: Aml - Pointer to the AML resource descriptor
144 * aml_resource_length - Length of the resource from the AML header
145 * Resource - Where the internal resource is returned
149 * DESCRIPTION: Convert a raw AML resource descriptor to the corresponding
150 * internal resource descriptor, simplifying bitflags and handling
151 * alignment and endian issues if necessary.
153 ******************************************************************************/
156 acpi_rs_get_vendor(union aml_resource *aml,
157 u16 aml_resource_length, struct acpi_resource *resource)
161 ACPI_FUNCTION_TRACE("rs_get_vendor");
163 /* Determine if this is a large or small vendor specific item */
165 if (aml->large_header.descriptor_type & ACPI_RESOURCE_NAME_LARGE) {
166 /* Large item, Point to the first vendor byte */
169 ((u8 *) aml) + sizeof(struct aml_resource_large_header);
171 /* Small item, Point to the first vendor byte */
174 ((u8 *) aml) + sizeof(struct aml_resource_small_header);
177 /* Copy the vendor-specific bytes */
179 ACPI_MEMCPY(resource->data.vendor.byte_data,
180 aml_byte_data, aml_resource_length);
181 resource->data.vendor.byte_length = aml_resource_length;
184 * In order for the struct_size to fall on a 32-bit boundary,
185 * calculate the length of the vendor string and expand the
186 * struct_size to the next 32-bit boundary.
188 resource->type = ACPI_RESOURCE_TYPE_VENDOR;
189 resource->length = ACPI_SIZEOF_RESOURCE(struct acpi_resource_vendor) +
190 ACPI_ROUND_UP_to_32_bITS(aml_resource_length);
191 return_ACPI_STATUS(AE_OK);
194 /*******************************************************************************
196 * FUNCTION: acpi_rs_set_vendor
198 * PARAMETERS: Resource - Pointer to the resource descriptor
199 * Aml - Where the AML descriptor is returned
203 * DESCRIPTION: Convert an internal resource descriptor to the corresponding
204 * external AML resource descriptor.
206 ******************************************************************************/
209 acpi_rs_set_vendor(struct acpi_resource *resource, union aml_resource *aml)
215 ACPI_FUNCTION_TRACE("rs_set_vendor");
217 resource_length = resource->data.vendor.byte_length;
218 source = ACPI_CAST_PTR(u8, resource->data.vendor.byte_data);
220 /* Length determines if this is a large or small resource */
222 if (resource_length > 7) {
223 /* Large item, get pointer to the data part of the descriptor */
226 ((u8 *) aml) + sizeof(struct aml_resource_large_header);
228 /* Complete the AML descriptor header */
230 acpi_rs_set_resource_header(ACPI_RESOURCE_NAME_VENDOR_LARGE,
231 (u32) (resource_length +
233 aml_resource_large_header)),
236 /* Small item, get pointer to the data part of the descriptor */
239 ((u8 *) aml) + sizeof(struct aml_resource_small_header);
241 /* Complete the AML descriptor header */
243 acpi_rs_set_resource_header(ACPI_RESOURCE_NAME_VENDOR_SMALL,
244 (u32) (resource_length +
246 aml_resource_small_header)),
250 /* Copy the vendor-specific bytes */
252 ACPI_MEMCPY(destination, source, resource_length);
253 return_ACPI_STATUS(AE_OK);
256 /*******************************************************************************
258 * FUNCTION: acpi_rs_get_start_dpf
260 * PARAMETERS: Aml - Pointer to the AML resource descriptor
261 * aml_resource_length - Length of the resource from the AML header
262 * Resource - Where the internal resource is returned
266 * DESCRIPTION: Convert a raw AML resource descriptor to the corresponding
267 * internal resource descriptor, simplifying bitflags and handling
268 * alignment and endian issues if necessary.
270 ******************************************************************************/
273 acpi_rs_get_start_dpf(union aml_resource *aml,
274 u16 aml_resource_length, struct acpi_resource *resource)
276 ACPI_FUNCTION_TRACE("rs_get_start_dpf");
278 /* Get the flags byte if present */
280 if (aml_resource_length == 1) {
281 /* Get the Compatibility priority */
283 resource->data.start_dpf.compatibility_priority =
284 (aml->start_dpf.flags & 0x03);
286 if (resource->data.start_dpf.compatibility_priority >= 3) {
287 return_ACPI_STATUS(AE_AML_BAD_RESOURCE_VALUE);
290 /* Get the Performance/Robustness preference */
292 resource->data.start_dpf.performance_robustness =
293 ((aml->start_dpf.flags >> 2) & 0x03);
295 if (resource->data.start_dpf.performance_robustness >= 3) {
296 return_ACPI_STATUS(AE_AML_BAD_RESOURCE_VALUE);
299 /* start_dependent_no_pri(), no flags byte, set defaults */
301 resource->data.start_dpf.compatibility_priority =
302 ACPI_ACCEPTABLE_CONFIGURATION;
304 resource->data.start_dpf.performance_robustness =
305 ACPI_ACCEPTABLE_CONFIGURATION;
308 /* Complete the resource header */
310 resource->type = ACPI_RESOURCE_TYPE_START_DEPENDENT;
312 ACPI_SIZEOF_RESOURCE(struct acpi_resource_start_dependent);
313 return_ACPI_STATUS(AE_OK);
316 /*******************************************************************************
318 * FUNCTION: acpi_rs_set_start_dpf
320 * PARAMETERS: Resource - Pointer to the resource descriptor
321 * Aml - Where the AML descriptor is returned
325 * DESCRIPTION: Convert an internal resource descriptor to the corresponding
326 * external AML resource descriptor.
328 ******************************************************************************/
331 acpi_rs_set_start_dpf(struct acpi_resource *resource, union aml_resource *aml)
333 ACPI_FUNCTION_TRACE("rs_set_start_dpf");
336 * The descriptor type field is set based upon whether a byte is needed
337 * to contain Priority data.
339 if (ACPI_ACCEPTABLE_CONFIGURATION ==
340 resource->data.start_dpf.compatibility_priority &&
341 ACPI_ACCEPTABLE_CONFIGURATION ==
342 resource->data.start_dpf.performance_robustness) {
343 acpi_rs_set_resource_header(ACPI_RESOURCE_NAME_START_DEPENDENT,
345 aml_resource_start_dependent_noprio),
348 acpi_rs_set_resource_header(ACPI_RESOURCE_NAME_START_DEPENDENT,
350 aml_resource_start_dependent),
353 /* Set the Flags byte */
355 aml->start_dpf.flags = (u8)
356 (((resource->data.start_dpf.
357 performance_robustness & 0x03) << 2) | (resource->data.
359 compatibility_priority
362 return_ACPI_STATUS(AE_OK);
365 /*******************************************************************************
367 * FUNCTION: acpi_rs_get_end_dpf
369 * PARAMETERS: Aml - Pointer to the AML resource descriptor
370 * aml_resource_length - Length of the resource from the AML header
371 * Resource - Where the internal resource is returned
375 * DESCRIPTION: Convert a raw AML resource descriptor to the corresponding
376 * internal resource descriptor, simplifying bitflags and handling
377 * alignment and endian issues if necessary.
379 ******************************************************************************/
382 acpi_rs_get_end_dpf(union aml_resource *aml,
383 u16 aml_resource_length, struct acpi_resource *resource)
385 ACPI_FUNCTION_TRACE("rs_get_end_dpf");
387 /* Complete the resource header */
389 resource->type = ACPI_RESOURCE_TYPE_END_DEPENDENT;
390 resource->length = (u32) ACPI_RESOURCE_LENGTH;
391 return_ACPI_STATUS(AE_OK);
394 /*******************************************************************************
396 * FUNCTION: acpi_rs_set_end_dpf
398 * PARAMETERS: Resource - Pointer to the resource descriptor
399 * Aml - Where the AML descriptor is returned
403 * DESCRIPTION: Convert an internal resource descriptor to the corresponding
404 * external AML resource descriptor.
406 ******************************************************************************/
409 acpi_rs_set_end_dpf(struct acpi_resource *resource, union aml_resource *aml)
411 ACPI_FUNCTION_TRACE("rs_set_end_dpf");
413 /* Complete the AML descriptor header */
415 acpi_rs_set_resource_header(ACPI_RESOURCE_NAME_END_DEPENDENT,
416 sizeof(struct aml_resource_end_dependent),
418 return_ACPI_STATUS(AE_OK);
421 /*******************************************************************************
423 * FUNCTION: acpi_rs_get_end_tag
425 * PARAMETERS: Aml - Pointer to the AML resource descriptor
426 * aml_resource_length - Length of the resource from the AML header
427 * Resource - Where the internal resource is returned
431 * DESCRIPTION: Convert a raw AML resource descriptor to the corresponding
432 * internal resource descriptor, simplifying bitflags and handling
433 * alignment and endian issues if necessary.
435 ******************************************************************************/
438 acpi_rs_get_end_tag(union aml_resource *aml,
439 u16 aml_resource_length, struct acpi_resource *resource)
441 ACPI_FUNCTION_TRACE("rs_get_end_tag");
443 /* Complete the resource header */
445 resource->type = ACPI_RESOURCE_TYPE_END_TAG;
446 resource->length = ACPI_RESOURCE_LENGTH;
447 return_ACPI_STATUS(AE_OK);
450 /*******************************************************************************
452 * FUNCTION: acpi_rs_set_end_tag
454 * PARAMETERS: Resource - Pointer to the resource descriptor
455 * Aml - Where the AML descriptor is returned
459 * DESCRIPTION: Convert an internal resource descriptor to the corresponding
460 * external AML resource descriptor.
462 ******************************************************************************/
465 acpi_rs_set_end_tag(struct acpi_resource *resource, union aml_resource *aml)
467 ACPI_FUNCTION_TRACE("rs_set_end_tag");
470 * Set the Checksum - zero means that the resource data is treated as if
471 * the checksum operation succeeded (ACPI Spec 1.0b Section 6.4.2.8)
473 aml->end_tag.checksum = 0;
475 /* Complete the AML descriptor header */
477 acpi_rs_set_resource_header(ACPI_RESOURCE_NAME_END_TAG,
478 sizeof(struct aml_resource_end_tag), aml);
479 return_ACPI_STATUS(AE_OK);