aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBob Moore <robert.moore@intel.com>2009-07-23 22:56:43 -0400
committerLen Brown <len.brown@intel.com>2009-08-28 19:40:38 -0400
commitb2deadd53c3630786e73746fb0ad8450f4e015bf (patch)
tree0115fe383ce81739ddb40a7392a3c9298811bc02
parent3ce804ed83827a7fd27190836f9421b29ac64512 (diff)
ACPICA: Move predefined repair code to new file, no functional change
New file is nsrepair.c. This is in preparation for additional errror correcting code. Signed-off-by: Bob Moore <robert.moore@intel.com> Signed-off-by: Lin Ming <ming.m.lin@intel.com> Signed-off-by: Len Brown <len.brown@intel.com>
-rw-r--r--drivers/acpi/acpica/Makefile2
-rw-r--r--drivers/acpi/acpica/acnamesp.h17
-rw-r--r--drivers/acpi/acpica/nspredef.c120
-rw-r--r--drivers/acpi/acpica/nsrepair.c151
4 files changed, 171 insertions, 119 deletions
diff --git a/drivers/acpi/acpica/Makefile b/drivers/acpi/acpica/Makefile
index 0e7d56185f6..e7973bc1684 100644
--- a/drivers/acpi/acpica/Makefile
+++ b/drivers/acpi/acpica/Makefile
@@ -28,7 +28,7 @@ acpi-$(ACPI_FUTURE_USAGE) += hwtimer.o
28acpi-y += nsaccess.o nsload.o nssearch.o nsxfeval.o \ 28acpi-y += nsaccess.o nsload.o nssearch.o nsxfeval.o \
29 nsalloc.o nseval.o nsnames.o nsutils.o nsxfname.o \ 29 nsalloc.o nseval.o nsnames.o nsutils.o nsxfname.o \
30 nsdump.o nsinit.o nsobject.o nswalk.o nsxfobj.o \ 30 nsdump.o nsinit.o nsobject.o nswalk.o nsxfobj.o \
31 nsparse.o nspredef.o 31 nsparse.o nspredef.o nsrepair.o
32 32
33acpi-$(ACPI_FUTURE_USAGE) += nsdumpdv.o 33acpi-$(ACPI_FUTURE_USAGE) += nsdumpdv.o
34 34
diff --git a/drivers/acpi/acpica/acnamesp.h b/drivers/acpi/acpica/acnamesp.h
index a78e02f62d5..908cfdd3b89 100644
--- a/drivers/acpi/acpica/acnamesp.h
+++ b/drivers/acpi/acpica/acnamesp.h
@@ -73,6 +73,14 @@
73#define ACPI_NS_WALK_UNLOCK 0x01 73#define ACPI_NS_WALK_UNLOCK 0x01
74#define ACPI_NS_WALK_TEMP_NODES 0x02 74#define ACPI_NS_WALK_TEMP_NODES 0x02
75 75
76/* Object is not a package element */
77
78#define ACPI_NOT_PACKAGE_ELEMENT ACPI_UINT32_MAX
79
80/* Always emit warning message, not dependent on node flags */
81
82#define ACPI_WARN_ALWAYS 0
83
76/* 84/*
77 * nsinit - Namespace initialization 85 * nsinit - Namespace initialization
78 */ 86 */
@@ -262,6 +270,15 @@ acpi_ns_get_attached_data(struct acpi_namespace_node *node,
262 acpi_object_handler handler, void **data); 270 acpi_object_handler handler, void **data);
263 271
264/* 272/*
273 * nsrepair - return object repair for predefined methods/objects
274 */
275acpi_status
276acpi_ns_repair_object(struct acpi_predefined_data *data,
277 u32 expected_btypes,
278 u32 package_index,
279 union acpi_operand_object **return_object_ptr);
280
281/*
265 * nssearch - Namespace searching and entry 282 * nssearch - Namespace searching and entry
266 */ 283 */
267acpi_status 284acpi_status
diff --git a/drivers/acpi/acpica/nspredef.c b/drivers/acpi/acpica/nspredef.c
index 1dc1a4737aa..e3f08dcb527 100644
--- a/drivers/acpi/acpica/nspredef.c
+++ b/drivers/acpi/acpica/nspredef.c
@@ -91,12 +91,6 @@ static acpi_status
91acpi_ns_check_reference(struct acpi_predefined_data *data, 91acpi_ns_check_reference(struct acpi_predefined_data *data,
92 union acpi_operand_object *return_object); 92 union acpi_operand_object *return_object);
93 93
94static acpi_status
95acpi_ns_repair_object(struct acpi_predefined_data *data,
96 u32 expected_btypes,
97 u32 package_index,
98 union acpi_operand_object **return_object_ptr);
99
100static void acpi_ns_get_expected_types(char *buffer, u32 expected_btypes); 94static void acpi_ns_get_expected_types(char *buffer, u32 expected_btypes);
101 95
102/* 96/*
@@ -111,14 +105,6 @@ static const char *acpi_rtype_names[] = {
111 "/Reference", 105 "/Reference",
112}; 106};
113 107
114/* Object is not a package element */
115
116#define ACPI_NOT_PACKAGE_ELEMENT ACPI_UINT32_MAX
117
118/* Always emit warning message, not dependent on node flags */
119
120#define ACPI_WARN_ALWAYS 0
121
122/******************************************************************************* 108/*******************************************************************************
123 * 109 *
124 * FUNCTION: acpi_ns_check_predefined_names 110 * FUNCTION: acpi_ns_check_predefined_names
@@ -580,8 +566,8 @@ acpi_ns_check_package(struct acpi_predefined_data *data,
580 case ACPI_PTYPE2_COUNT: 566 case ACPI_PTYPE2_COUNT:
581 567
582 /* 568 /*
583 * These types all return a single package that consists of a variable 569 * These types all return a single package that consists of a
584 * number of sub-packages 570 * variable number of sub-packages.
585 */ 571 */
586 for (i = 0; i < count; i++) { 572 for (i = 0; i < count; i++) {
587 sub_package = *elements; 573 sub_package = *elements;
@@ -979,108 +965,6 @@ acpi_ns_check_reference(struct acpi_predefined_data *data,
979 965
980/******************************************************************************* 966/*******************************************************************************
981 * 967 *
982 * FUNCTION: acpi_ns_repair_object
983 *
984 * PARAMETERS: Data - Pointer to validation data structure
985 * expected_btypes - Object types expected
986 * package_index - Index of object within parent package (if
987 * applicable - ACPI_NOT_PACKAGE_ELEMENT
988 * otherwise)
989 * return_object_ptr - Pointer to the object returned from the
990 * evaluation of a method or object
991 *
992 * RETURN: Status. AE_OK if repair was successful.
993 *
994 * DESCRIPTION: Attempt to repair/convert a return object of a type that was
995 * not expected.
996 *
997 ******************************************************************************/
998
999static acpi_status
1000acpi_ns_repair_object(struct acpi_predefined_data *data,
1001 u32 expected_btypes,
1002 u32 package_index,
1003 union acpi_operand_object **return_object_ptr)
1004{
1005 union acpi_operand_object *return_object = *return_object_ptr;
1006 union acpi_operand_object *new_object;
1007 acpi_size length;
1008
1009 switch (return_object->common.type) {
1010 case ACPI_TYPE_BUFFER:
1011
1012 /* Does the method/object legally return a string? */
1013
1014 if (!(expected_btypes & ACPI_RTYPE_STRING)) {
1015 return (AE_AML_OPERAND_TYPE);
1016 }
1017
1018 /*
1019 * Have a Buffer, expected a String, convert. Use a to_string
1020 * conversion, no transform performed on the buffer data. The best
1021 * example of this is the _BIF method, where the string data from
1022 * the battery is often (incorrectly) returned as buffer object(s).
1023 */
1024 length = 0;
1025 while ((length < return_object->buffer.length) &&
1026 (return_object->buffer.pointer[length])) {
1027 length++;
1028 }
1029
1030 /* Allocate a new string object */
1031
1032 new_object = acpi_ut_create_string_object(length);
1033 if (!new_object) {
1034 return (AE_NO_MEMORY);
1035 }
1036
1037 /*
1038 * Copy the raw buffer data with no transform. String is already NULL
1039 * terminated at Length+1.
1040 */
1041 ACPI_MEMCPY(new_object->string.pointer,
1042 return_object->buffer.pointer, length);
1043
1044 /*
1045 * If the original object is a package element, we need to:
1046 * 1. Set the reference count of the new object to match the
1047 * reference count of the old object.
1048 * 2. Decrement the reference count of the original object.
1049 */
1050 if (package_index != ACPI_NOT_PACKAGE_ELEMENT) {
1051 new_object->common.reference_count =
1052 return_object->common.reference_count;
1053
1054 if (return_object->common.reference_count > 1) {
1055 return_object->common.reference_count--;
1056 }
1057
1058 ACPI_WARN_PREDEFINED((AE_INFO, data->pathname,
1059 data->node_flags,
1060 "Converted Buffer to expected String at index %u",
1061 package_index));
1062 } else {
1063 ACPI_WARN_PREDEFINED((AE_INFO, data->pathname,
1064 data->node_flags,
1065 "Converted Buffer to expected String"));
1066 }
1067
1068 /* Delete old object, install the new return object */
1069
1070 acpi_ut_remove_reference(return_object);
1071 *return_object_ptr = new_object;
1072 data->flags |= ACPI_OBJECT_REPAIRED;
1073 return (AE_OK);
1074
1075 default:
1076 break;
1077 }
1078
1079 return (AE_AML_OPERAND_TYPE);
1080}
1081
1082/*******************************************************************************
1083 *
1084 * FUNCTION: acpi_ns_get_expected_types 968 * FUNCTION: acpi_ns_get_expected_types
1085 * 969 *
1086 * PARAMETERS: Buffer - Pointer to where the string is returned 970 * PARAMETERS: Buffer - Pointer to where the string is returned
diff --git a/drivers/acpi/acpica/nsrepair.c b/drivers/acpi/acpica/nsrepair.c
new file mode 100644
index 00000000000..b64751eacc5
--- /dev/null
+++ b/drivers/acpi/acpica/nsrepair.c
@@ -0,0 +1,151 @@
1/******************************************************************************
2 *
3 * Module Name: nsrepair - Repair for objects returned by predefined methods
4 *
5 *****************************************************************************/
6
7/*
8 * Copyright (C) 2000 - 2009, Intel Corp.
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 "accommon.h"
46#include "acnamesp.h"
47#include "acpredef.h"
48
49#define _COMPONENT ACPI_NAMESPACE
50ACPI_MODULE_NAME("nsrepair")
51
52/*******************************************************************************
53 *
54 * FUNCTION: acpi_ns_repair_object
55 *
56 * PARAMETERS: Data - Pointer to validation data structure
57 * expected_btypes - Object types expected
58 * package_index - Index of object within parent package (if
59 * applicable - ACPI_NOT_PACKAGE_ELEMENT
60 * otherwise)
61 * return_object_ptr - Pointer to the object returned from the
62 * evaluation of a method or object
63 *
64 * RETURN: Status. AE_OK if repair was successful.
65 *
66 * DESCRIPTION: Attempt to repair/convert a return object of a type that was
67 * not expected.
68 *
69 ******************************************************************************/
70acpi_status
71acpi_ns_repair_object(struct acpi_predefined_data *data,
72 u32 expected_btypes,
73 u32 package_index,
74 union acpi_operand_object **return_object_ptr)
75{
76 union acpi_operand_object *return_object = *return_object_ptr;
77 union acpi_operand_object *new_object;
78 acpi_size length;
79
80 switch (return_object->common.type) {
81 case ACPI_TYPE_BUFFER:
82
83 /* Does the method/object legally return a string? */
84
85 if (!(expected_btypes & ACPI_RTYPE_STRING)) {
86 return (AE_AML_OPERAND_TYPE);
87 }
88
89 /*
90 * Have a Buffer, expected a String, convert. Use a to_string
91 * conversion, no transform performed on the buffer data. The best
92 * example of this is the _BIF method, where the string data from
93 * the battery is often (incorrectly) returned as buffer object(s).
94 */
95 length = 0;
96 while ((length < return_object->buffer.length) &&
97 (return_object->buffer.pointer[length])) {
98 length++;
99 }
100
101 /* Allocate a new string object */
102
103 new_object = acpi_ut_create_string_object(length);
104 if (!new_object) {
105 return (AE_NO_MEMORY);
106 }
107
108 /*
109 * Copy the raw buffer data with no transform. String is already NULL
110 * terminated at Length+1.
111 */
112 ACPI_MEMCPY(new_object->string.pointer,
113 return_object->buffer.pointer, length);
114
115 /*
116 * If the original object is a package element, we need to:
117 * 1. Set the reference count of the new object to match the
118 * reference count of the old object.
119 * 2. Decrement the reference count of the original object.
120 */
121 if (package_index != ACPI_NOT_PACKAGE_ELEMENT) {
122 new_object->common.reference_count =
123 return_object->common.reference_count;
124
125 if (return_object->common.reference_count > 1) {
126 return_object->common.reference_count--;
127 }
128
129 ACPI_WARN_PREDEFINED((AE_INFO, data->pathname,
130 data->node_flags,
131 "Converted Buffer to expected String at index %u",
132 package_index));
133 } else {
134 ACPI_WARN_PREDEFINED((AE_INFO, data->pathname,
135 data->node_flags,
136 "Converted Buffer to expected String"));
137 }
138
139 /* Delete old object, install the new return object */
140
141 acpi_ut_remove_reference(return_object);
142 *return_object_ptr = new_object;
143 data->flags |= ACPI_OBJECT_REPAIRED;
144 return (AE_OK);
145
146 default:
147 break;
148 }
149
150 return (AE_AML_OPERAND_TYPE);
151}