ACPICA: Predefine names: Add allowed argument types to master info table

This change adds the infrastructure to enable typechecking
on incoming arguments for the predefined methods/objects. It
does not actually contain the code that will fully utilize this
information. Also condenses some duplicate code for the predefined
names into a new module, utilities/utpredef.c

Signed-off-by: Bob Moore <robert.moore@intel.com>
Signed-off-by: Lv Zheng <lv.zheng@intel.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
This commit is contained in:
Bob Moore 2013-04-12 00:24:22 +00:00 коммит произвёл Rafael J. Wysocki
Родитель f084dbb939
Коммит c34c82bc96
8 изменённых файлов: 1298 добавлений и 450 удалений

Просмотреть файл

@ -161,6 +161,7 @@ acpi-y += \
utobject.o \
utosi.o \
utownerid.o \
utpredef.o \
utresrc.o \
utstate.o \
utstring.o \

Просмотреть файл

@ -294,6 +294,8 @@ acpi_status(*acpi_internal_method) (struct acpi_walk_state * walk_state);
#define ACPI_BTYPE_OBJECTS_AND_REFS 0x0001FFFF /* ARG or LOCAL */
#define ACPI_BTYPE_ALL_OBJECTS 0x0000FFFF
#pragma pack(1)
/*
* Information structure for ACPI predefined names.
* Each entry in the table contains the following items:
@ -304,7 +306,7 @@ acpi_status(*acpi_internal_method) (struct acpi_walk_state * walk_state);
*/
struct acpi_name_info {
char name[ACPI_NAME_SIZE];
u8 param_count;
u16 argument_list;
u8 expected_btypes;
};
@ -327,7 +329,7 @@ struct acpi_package_info {
u8 count1;
u8 object_type2;
u8 count2;
u8 reserved;
u16 reserved;
};
/* Used for ACPI_PTYPE2_FIXED */
@ -336,6 +338,7 @@ struct acpi_package_info2 {
u8 type;
u8 count;
u8 object_type[4];
u8 reserved;
};
/* Used for ACPI_PTYPE1_OPTION */
@ -345,7 +348,7 @@ struct acpi_package_info3 {
u8 count;
u8 object_type[2];
u8 tail_object_type;
u8 reserved;
u16 reserved;
};
union acpi_predefined_info {
@ -355,6 +358,10 @@ union acpi_predefined_info {
struct acpi_package_info3 ret_info3;
};
/* Reset to default packing */
#pragma pack()
/* Data block used during object validation */
struct acpi_predefined_data {

Просмотреть файл

@ -231,10 +231,6 @@ acpi_ns_check_predefined_names(struct acpi_namespace_node *node,
acpi_status return_status,
union acpi_operand_object **return_object);
const union acpi_predefined_info *acpi_ns_check_for_predefined_name(struct
acpi_namespace_node
*node);
void
acpi_ns_check_parameter_count(char *pathname,
struct acpi_namespace_node *node,

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -431,6 +431,26 @@ struct acpi_interface_info *acpi_ut_get_interface(acpi_string interface_name);
acpi_status acpi_ut_osi_implementation(struct acpi_walk_state *walk_state);
/*
* utpredef - support for predefined names
*/
const union acpi_predefined_info *acpi_ut_get_next_predefined_method(const union
acpi_predefined_info
*this_name);
const union acpi_predefined_info *acpi_ut_match_predefined_method(char *name);
const union acpi_predefined_info *acpi_ut_match_resource_name(char *name);
void
acpi_ut_display_predefined_method(char *buffer,
const union acpi_predefined_info *this_name,
u8 multi_line);
void acpi_ut_get_expected_return_types(char *buffer, u32 expected_btypes);
u32 acpi_ut_get_resource_bit_width(char *buffer, u16 types);
/*
* utstate - Generic state creation/cache routines
*/

Просмотреть файл

@ -98,17 +98,21 @@ acpi_status acpi_ns_evaluate(struct acpi_evaluate_info * info)
info->return_object = NULL;
info->param_count = 0;
/*
* Get the actual namespace node for the target object. Handles these cases:
*
* 1) Null node, Pathname (absolute path)
* 2) Node, Pathname (path relative to Node)
* 3) Node, Null Pathname
*/
status = acpi_ns_get_node(info->prefix_node, info->pathname,
ACPI_NS_NO_UPSEARCH, &info->resolved_node);
if (ACPI_FAILURE(status)) {
return_ACPI_STATUS(status);
if (!info->resolved_node) {
/*
* Get the actual namespace node for the target object if we need to.
* Handles these cases:
*
* 1) Null node, Pathname (absolute path)
* 2) Node, Pathname (path relative to Node)
* 3) Node, Null Pathname
*/
status = acpi_ns_get_node(info->prefix_node, info->pathname,
ACPI_NS_NO_UPSEARCH,
&info->resolved_node);
if (ACPI_FAILURE(status)) {
return_ACPI_STATUS(status);
}
}
/*

Просмотреть файл

@ -76,22 +76,8 @@ static acpi_status
acpi_ns_check_reference(struct acpi_predefined_data *data,
union acpi_operand_object *return_object);
static void acpi_ns_get_expected_types(char *buffer, u32 expected_btypes);
static u32 acpi_ns_get_bitmapped_type(union acpi_operand_object *return_object);
/*
* Names for the types that can be returned by the predefined objects.
* Used for warning messages. Must be in the same order as the ACPI_RTYPEs
*/
static const char *acpi_rtype_names[] = {
"/Integer",
"/String",
"/Buffer",
"/Package",
"/Reference",
};
/*******************************************************************************
*
* FUNCTION: acpi_ns_check_predefined_names
@ -121,7 +107,7 @@ acpi_ns_check_predefined_names(struct acpi_namespace_node *node,
/* Match the name for this method/object against the predefined list */
predefined = acpi_ns_check_for_predefined_name(node);
predefined = acpi_ut_match_predefined_method(node->name.ascii);
/* Get the full pathname to the object, for use in warning messages */
@ -292,8 +278,10 @@ acpi_ns_check_parameter_count(char *pathname,
* Validate the user-supplied parameter count.
* Allow two different legal argument counts (_SCP, etc.)
*/
required_params_current = predefined->info.param_count & 0x0F;
required_params_old = predefined->info.param_count >> 4;
required_params_current =
predefined->info.argument_list & METHOD_ARG_MASK;
required_params_old =
predefined->info.argument_list >> METHOD_ARG_BIT_WIDTH;
if (user_param_count != ACPI_UINT32_MAX) {
if ((user_param_count != required_params_current) &&
@ -320,52 +308,6 @@ acpi_ns_check_parameter_count(char *pathname,
}
}
/*******************************************************************************
*
* FUNCTION: acpi_ns_check_for_predefined_name
*
* PARAMETERS: node - Namespace node for the method/object
*
* RETURN: Pointer to entry in predefined table. NULL indicates not found.
*
* DESCRIPTION: Check an object name against the predefined object list.
*
******************************************************************************/
const union acpi_predefined_info *acpi_ns_check_for_predefined_name(struct
acpi_namespace_node
*node)
{
const union acpi_predefined_info *this_name;
/* Quick check for a predefined name, first character must be underscore */
if (node->name.ascii[0] != '_') {
return (NULL);
}
/* Search info table for a predefined method/object name */
this_name = predefined_names;
while (this_name->info.name[0]) {
if (ACPI_COMPARE_NAME(node->name.ascii, this_name->info.name)) {
return (this_name);
}
/*
* Skip next entry in the table if this name returns a Package
* (next entry contains the package info)
*/
if (this_name->info.expected_btypes & ACPI_RTYPE_PACKAGE) {
this_name++;
}
this_name++;
}
return (NULL); /* Not found */
}
/*******************************************************************************
*
* FUNCTION: acpi_ns_check_object_type
@ -438,7 +380,7 @@ acpi_ns_check_object_type(struct acpi_predefined_data *data,
/* Create a string with all expected types for this predefined object */
acpi_ns_get_expected_types(type_buffer, expected_btypes);
acpi_ut_get_expected_return_types(type_buffer, expected_btypes);
if (package_index == ACPI_NOT_PACKAGE_ELEMENT) {
ACPI_WARN_PREDEFINED((AE_INFO, data->pathname, data->node_flags,
@ -548,39 +490,3 @@ static u32 acpi_ns_get_bitmapped_type(union acpi_operand_object *return_object)
return (return_btype);
}
/*******************************************************************************
*
* FUNCTION: acpi_ns_get_expected_types
*
* PARAMETERS: buffer - Pointer to where the string is returned
* expected_btypes - Bitmap of expected return type(s)
*
* RETURN: Buffer is populated with type names.
*
* DESCRIPTION: Translate the expected types bitmap into a string of ascii
* names of expected types, for use in warning messages.
*
******************************************************************************/
static void acpi_ns_get_expected_types(char *buffer, u32 expected_btypes)
{
u32 this_rtype;
u32 i;
u32 j;
j = 1;
buffer[0] = 0;
this_rtype = ACPI_RTYPE_INTEGER;
for (i = 0; i < ACPI_NUM_RTYPES; i++) {
/* If one of the expected types, concatenate the name of this type */
if (expected_btypes & this_rtype) {
ACPI_STRCAT(buffer, &acpi_rtype_names[i][j]);
j = 0; /* Use name separator from now on */
}
this_rtype <<= 1; /* Next Rtype */
}
}

Просмотреть файл

@ -0,0 +1,399 @@
/******************************************************************************
*
* Module Name: utpredef - support functions for predefined names
*
*****************************************************************************/
/*
* Copyright (C) 2000 - 2013, Intel Corp.
* 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 "accommon.h"
#include "acpredef.h"
#define _COMPONENT ACPI_UTILITIES
ACPI_MODULE_NAME("utpredef")
/*
* Names for the types that can be returned by the predefined objects.
* Used for warning messages. Must be in the same order as the ACPI_RTYPEs
*/
static const char *ut_rtype_names[] = {
"/Integer",
"/String",
"/Buffer",
"/Package",
"/Reference",
};
/*******************************************************************************
*
* FUNCTION: acpi_ut_get_next_predefined_method
*
* PARAMETERS: this_name - Entry in the predefined method/name table
*
* RETURN: Pointer to next entry in predefined table.
*
* DESCRIPTION: Get the next entry in the predefine method table. Handles the
* cases where a package info entry follows a method name that
* returns a package.
*
******************************************************************************/
const union acpi_predefined_info *acpi_ut_get_next_predefined_method(const union
acpi_predefined_info
*this_name)
{
/*
* Skip next entry in the table if this name returns a Package
* (next entry contains the package info)
*/
if ((this_name->info.expected_btypes & ACPI_RTYPE_PACKAGE) &&
(this_name->info.expected_btypes != ACPI_RTYPE_ALL)) {
this_name++;
}
this_name++;
return (this_name);
}
/*******************************************************************************
*
* FUNCTION: acpi_ut_match_predefined_method
*
* PARAMETERS: name - Name to find
*
* RETURN: Pointer to entry in predefined table. NULL indicates not found.
*
* DESCRIPTION: Check an object name against the predefined object list.
*
******************************************************************************/
const union acpi_predefined_info *acpi_ut_match_predefined_method(char *name)
{
const union acpi_predefined_info *this_name;
/* Quick check for a predefined name, first character must be underscore */
if (name[0] != '_') {
return (NULL);
}
/* Search info table for a predefined method/object name */
this_name = acpi_gbl_predefined_methods;
while (this_name->info.name[0]) {
if (ACPI_COMPARE_NAME(name, this_name->info.name)) {
return (this_name);
}
this_name = acpi_ut_get_next_predefined_method(this_name);
}
return (NULL); /* Not found */
}
/*******************************************************************************
*
* FUNCTION: acpi_ut_get_expected_return_types
*
* PARAMETERS: buffer - Where the formatted string is returned
* expected_Btypes - Bitfield of expected data types
*
* RETURN: Formatted string in Buffer.
*
* DESCRIPTION: Format the expected object types into a printable string.
*
******************************************************************************/
void acpi_ut_get_expected_return_types(char *buffer, u32 expected_btypes)
{
u32 this_rtype;
u32 i;
u32 j;
j = 1;
buffer[0] = 0;
this_rtype = ACPI_RTYPE_INTEGER;
for (i = 0; i < ACPI_NUM_RTYPES; i++) {
/* If one of the expected types, concatenate the name of this type */
if (expected_btypes & this_rtype) {
ACPI_STRCAT(buffer, &ut_rtype_names[i][j]);
j = 0; /* Use name separator from now on */
}
this_rtype <<= 1; /* Next Rtype */
}
}
/*******************************************************************************
*
* The remaining functions are used by iASL and acpi_help only
*
******************************************************************************/
#if (defined ACPI_ASL_COMPILER || defined ACPI_HELP_APP)
#include <stdio.h>
#include <string.h>
/* Local prototypes */
static u32 acpi_ut_get_argument_types(char *buffer, u16 argument_types);
/* Types that can be returned externally by a predefined name */
static const char *ut_external_type_names[] = /* Indexed by ACPI_TYPE_* */
{
", UNSUPPORTED-TYPE",
", Integer",
", String",
", Buffer",
", Package"
};
/* Bit widths for resource descriptor predefined names */
static const char *ut_resource_type_names[] = {
"/1",
"/2",
"/3",
"/8",
"/16",
"/32",
"/64",
"/variable",
};
/*******************************************************************************
*
* FUNCTION: acpi_ut_match_resource_name
*
* PARAMETERS: name - Name to find
*
* RETURN: Pointer to entry in the resource table. NULL indicates not
* found.
*
* DESCRIPTION: Check an object name against the predefined resource
* descriptor object list.
*
******************************************************************************/
const union acpi_predefined_info *acpi_ut_match_resource_name(char *name)
{
const union acpi_predefined_info *this_name;
/* Quick check for a predefined name, first character must be underscore */
if (name[0] != '_') {
return (NULL);
}
/* Search info table for a predefined method/object name */
this_name = acpi_gbl_resource_names;
while (this_name->info.name[0]) {
if (ACPI_COMPARE_NAME(name, this_name->info.name)) {
return (this_name);
}
this_name++;
}
return (NULL); /* Not found */
}
/*******************************************************************************
*
* FUNCTION: acpi_ut_display_predefined_method
*
* PARAMETERS: buffer - Scratch buffer for this function
* this_name - Entry in the predefined method/name table
* multi_line - TRUE if output should be on >1 line
*
* RETURN: None
*
* DESCRIPTION: Display information about a predefined method. Number and
* type of the input arguments, and expected type(s) for the
* return value, if any.
*
******************************************************************************/
void
acpi_ut_display_predefined_method(char *buffer,
const union acpi_predefined_info *this_name,
u8 multi_line)
{
u32 arg_count;
/*
* Get the argument count and the string buffer
* containing all argument types
*/
arg_count = acpi_ut_get_argument_types(buffer,
this_name->info.argument_list);
if (multi_line) {
printf(" ");
}
printf("%4.4s Requires %s%u argument%s",
this_name->info.name,
(this_name->info.argument_list & ARG_COUNT_IS_MINIMUM) ?
"(at least) " : "", arg_count, arg_count != 1 ? "s" : "");
/* Display the types for any arguments */
if (arg_count > 0) {
printf(" (%s)", buffer);
}
if (multi_line) {
printf("\n ");
}
/* Get the return value type(s) allowed */
if (this_name->info.expected_btypes) {
acpi_ut_get_expected_return_types(buffer,
this_name->info.
expected_btypes);
printf(" Return value types: %s\n", buffer);
} else {
printf(" No return value\n");
}
}
/*******************************************************************************
*
* FUNCTION: acpi_ut_get_argument_types
*
* PARAMETERS: buffer - Where to return the formatted types
* argument_types - Types field for this method
*
* RETURN: count - the number of arguments required for this method
*
* DESCRIPTION: Format the required data types for this method (Integer,
* String, Buffer, or Package) and return the required argument
* count.
*
******************************************************************************/
static u32 acpi_ut_get_argument_types(char *buffer, u16 argument_types)
{
u16 this_argument_type;
u16 sub_index;
u16 arg_count;
u32 i;
*buffer = 0;
sub_index = 2;
/* First field in the types list is the count of args to follow */
arg_count = (argument_types & METHOD_ARG_MASK);
argument_types >>= METHOD_ARG_BIT_WIDTH;
if (arg_count > METHOD_PREDEF_ARGS_MAX) {
printf("**** Invalid argument count (%u) "
"in predefined info structure\n", arg_count);
return (arg_count);
}
/* Get each argument from the list, convert to ascii, store to buffer */
for (i = 0; i < arg_count; i++) {
this_argument_type = (argument_types & METHOD_ARG_MASK);
if (!this_argument_type
|| (this_argument_type > METHOD_MAX_ARG_TYPE)) {
printf("**** Invalid argument type (%u) "
"in predefined info structure\n",
this_argument_type);
return (arg_count);
}
strcat(buffer,
ut_external_type_names[this_argument_type] + sub_index);
/* Shift to next argument type field */
argument_types >>= METHOD_ARG_BIT_WIDTH;
sub_index = 0;
}
return (arg_count);
}
/*******************************************************************************
*
* FUNCTION: acpi_ut_get_resource_bit_width
*
* PARAMETERS: buffer - Where the formatted string is returned
* types - Bitfield of expected data types
*
* RETURN: Count of return types. Formatted string in Buffer.
*
* DESCRIPTION: Format the resource bit widths into a printable string.
*
******************************************************************************/
u32 acpi_ut_get_resource_bit_width(char *buffer, u16 types)
{
u32 i;
u16 sub_index;
u32 found;
*buffer = 0;
sub_index = 1;
found = 0;
for (i = 0; i < NUM_RESOURCE_WIDTHS; i++) {
if (types & 1) {
strcat(buffer, &(ut_resource_type_names[i][sub_index]));
sub_index = 0;
found++;
}
types >>= 1;
}
return (found);
}
#endif