rsutils.c
来自「LINUX 2.6.17.4的源码」· C语言 代码 · 共 711 行 · 第 1/2 页
C
711 行
/******************************************************************************* * * Module Name: rsutils - Utilities for the resource manager * ******************************************************************************//* * Copyright (C) 2000 - 2006, R. Byron Moore * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions, and the following disclaimer, * without modification. * 2. Redistributions in binary form must reproduce at minimum a disclaimer * substantially similar to the "NO WARRANTY" disclaimer below * ("Disclaimer") and any redistribution must be conditioned upon * including a substantially similar Disclaimer requirement for further * binary redistribution. * 3. Neither the names of the above-listed copyright holders nor the names * of any contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * Alternatively, this software may be distributed under the terms of the * GNU General Public License ("GPL") version 2 as published by the Free * Software Foundation. * * NO WARRANTY * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGES. */#include <acpi/acpi.h>#include <acpi/acnamesp.h>#include <acpi/acresrc.h>#define _COMPONENT ACPI_RESOURCESACPI_MODULE_NAME("rsutils")/******************************************************************************* * * FUNCTION: acpi_rs_decode_bitmask * * PARAMETERS: Mask - Bitmask to decode * List - Where the converted list is returned * * RETURN: Count of bits set (length of list) * * DESCRIPTION: Convert a bit mask into a list of values * ******************************************************************************/u8 acpi_rs_decode_bitmask(u16 mask, u8 * list){ acpi_native_uint i; u8 bit_count; ACPI_FUNCTION_ENTRY(); /* Decode the mask bits */ for (i = 0, bit_count = 0; mask; i++) { if (mask & 0x0001) { list[bit_count] = (u8) i; bit_count++; } mask >>= 1; } return (bit_count);}/******************************************************************************* * * FUNCTION: acpi_rs_encode_bitmask * * PARAMETERS: List - List of values to encode * Count - Length of list * * RETURN: Encoded bitmask * * DESCRIPTION: Convert a list of values to an encoded bitmask * ******************************************************************************/u16 acpi_rs_encode_bitmask(u8 * list, u8 count){ acpi_native_uint i; u16 mask; ACPI_FUNCTION_ENTRY(); /* Encode the list into a single bitmask */ for (i = 0, mask = 0; i < count; i++) { mask |= (0x0001 << list[i]); } return (mask);}/******************************************************************************* * * FUNCTION: acpi_rs_move_data * * PARAMETERS: Destination - Pointer to the destination descriptor * Source - Pointer to the source descriptor * item_count - How many items to move * move_type - Byte width * * RETURN: None * * DESCRIPTION: Move multiple data items from one descriptor to another. Handles * alignment issues and endian issues if necessary, as configured * via the ACPI_MOVE_* macros. (This is why a memcpy is not used) * ******************************************************************************/voidacpi_rs_move_data(void *destination, void *source, u16 item_count, u8 move_type){ acpi_native_uint i; ACPI_FUNCTION_ENTRY(); /* One move per item */ for (i = 0; i < item_count; i++) { switch (move_type) { /* * For the 8-bit case, we can perform the move all at once * since there are no alignment or endian issues */ case ACPI_RSC_MOVE8: ACPI_MEMCPY(destination, source, item_count); return; /* * 16-, 32-, and 64-bit cases must use the move macros that perform * endian conversion and/or accomodate hardware that cannot perform * misaligned memory transfers */ case ACPI_RSC_MOVE16: ACPI_MOVE_16_TO_16(&ACPI_CAST_PTR(u16, destination)[i], &ACPI_CAST_PTR(u16, source)[i]); break; case ACPI_RSC_MOVE32: ACPI_MOVE_32_TO_32(&ACPI_CAST_PTR(u32, destination)[i], &ACPI_CAST_PTR(u32, source)[i]); break; case ACPI_RSC_MOVE64: ACPI_MOVE_64_TO_64(&ACPI_CAST_PTR(u64, destination)[i], &ACPI_CAST_PTR(u64, source)[i]); break; default: return; } }}/******************************************************************************* * * FUNCTION: acpi_rs_set_resource_length * * PARAMETERS: total_length - Length of the AML descriptor, including * the header and length fields. * Aml - Pointer to the raw AML descriptor * * RETURN: None * * DESCRIPTION: Set the resource_length field of an AML * resource descriptor, both Large and Small descriptors are * supported automatically. Note: Descriptor Type field must * be valid. * ******************************************************************************/voidacpi_rs_set_resource_length(acpi_rsdesc_size total_length, union aml_resource *aml){ acpi_rs_length resource_length; ACPI_FUNCTION_ENTRY(); /* Length is the total descriptor length minus the header length */ resource_length = (acpi_rs_length) (total_length - acpi_ut_get_resource_header_length(aml)); /* Length is stored differently for large and small descriptors */ if (aml->small_header.descriptor_type & ACPI_RESOURCE_NAME_LARGE) { /* Large descriptor -- bytes 1-2 contain the 16-bit length */ ACPI_MOVE_16_TO_16(&aml->large_header.resource_length, &resource_length); } else { /* Small descriptor -- bits 2:0 of byte 0 contain the length */ aml->small_header.descriptor_type = (u8) /* Clear any existing length, preserving descriptor type bits */ ((aml->small_header. descriptor_type & ~ACPI_RESOURCE_NAME_SMALL_LENGTH_MASK) | resource_length); }}/******************************************************************************* * * FUNCTION: acpi_rs_set_resource_header * * PARAMETERS: descriptor_type - Byte to be inserted as the type * total_length - Length of the AML descriptor, including * the header and length fields. * Aml - Pointer to the raw AML descriptor * * RETURN: None * * DESCRIPTION: Set the descriptor_type and resource_length fields of an AML * resource descriptor, both Large and Small descriptors are * supported automatically * ******************************************************************************/voidacpi_rs_set_resource_header(u8 descriptor_type, acpi_rsdesc_size total_length, union aml_resource *aml){ ACPI_FUNCTION_ENTRY(); /* Set the Resource Type */ aml->small_header.descriptor_type = descriptor_type; /* Set the Resource Length */ acpi_rs_set_resource_length(total_length, aml);}/******************************************************************************* * * FUNCTION: acpi_rs_strcpy * * PARAMETERS: Destination - Pointer to the destination string * Source - Pointer to the source string * * RETURN: String length, including NULL terminator * * DESCRIPTION: Local string copy that returns the string length, saving a * strcpy followed by a strlen. * ******************************************************************************/static u16 acpi_rs_strcpy(char *destination, char *source){ u16 i; ACPI_FUNCTION_ENTRY(); for (i = 0; source[i]; i++) { destination[i] = source[i]; } destination[i] = 0; /* Return string length including the NULL terminator */ return ((u16) (i + 1));}/******************************************************************************* * * FUNCTION: acpi_rs_get_resource_source * * PARAMETERS: resource_length - Length field of the descriptor * minimum_length - Minimum length of the descriptor (minus * any optional fields) * resource_source - Where the resource_source is returned * Aml - Pointer to the raw AML descriptor * string_ptr - (optional) where to store the actual * resource_source string * * RETURN: Length of the string plus NULL terminator, rounded up to 32 bit * * DESCRIPTION: Copy the optional resource_source data from a raw AML descriptor * to an internal resource descriptor * ******************************************************************************/acpi_rs_lengthacpi_rs_get_resource_source(acpi_rs_length resource_length, acpi_rs_length minimum_length, struct acpi_resource_source * resource_source, union aml_resource * aml, char *string_ptr){ acpi_rsdesc_size total_length; u8 *aml_resource_source; ACPI_FUNCTION_ENTRY(); total_length = resource_length + sizeof(struct aml_resource_large_header); aml_resource_source = ACPI_ADD_PTR(u8, aml, minimum_length); /* * resource_source is present if the length of the descriptor is longer than * the minimum length. * * Note: Some resource descriptors will have an additional null, so * we add 1 to the minimum length. */ if (total_length > (acpi_rsdesc_size) (minimum_length + 1)) { /* Get the resource_source_index */ resource_source->index = aml_resource_source[0]; resource_source->string_ptr = string_ptr; if (!string_ptr) { /* * String destination pointer is not specified; Set the String * pointer to the end of the current resource_source structure. */ resource_source->string_ptr = ACPI_ADD_PTR(char, resource_source, sizeof(struct acpi_resource_source)); } /* * In order for the struct_size to fall on a 32-bit boundary, calculate * the length of the string (+1 for the NULL terminator) and expand the * struct_size to the next 32-bit boundary. * * Zero the entire area of the buffer. */ total_length = ACPI_ROUND_UP_to_32_bITS(ACPI_STRLEN ((char *)&aml_resource_source[1]) + 1);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?