aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLv Zheng <lv.zheng@intel.com>2012-10-30 22:25:05 -0400
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>2012-11-14 18:31:21 -0500
commit6d33b6be17dd6a0934396704f969ceb7f3206347 (patch)
tree4cf68009186944acd1b8ef10fb2b5b87e8c0c2f3
parent45dcd31547fcd58273423799b12efe0e8371127e (diff)
ACPICA: Fix unmerged utility divergences.
Utility improvements in ACPICA are partial ignored by ACPICA Linux release. This will lead to divergences between Linux and ACPICA. This patch ports the entire "utility" into Linux and makes them igored in the compilation stage by "ACPI_FUTURE_USAGE". The following "Utility" files have been ported into the Linux: drivers/acpi/uttrack.c drivers/acpi/utcache.c drivers/acpi/utids.c This patch will not affect the generated vmlinx binary. This will decrease 274 lines of 20120913 divergence.diff. Signed-off-by: Robert 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>
-rw-r--r--drivers/acpi/acpica/Makefile3
-rw-r--r--drivers/acpi/acpica/acutils.h51
-rw-r--r--drivers/acpi/acpica/utcache.c323
-rw-r--r--drivers/acpi/acpica/utclib.c748
-rw-r--r--drivers/acpi/acpica/utdebug.c9
-rw-r--r--drivers/acpi/acpica/utmisc.c99
-rw-r--r--drivers/acpi/acpica/uttrack.c650
7 files changed, 1852 insertions, 31 deletions
diff --git a/drivers/acpi/acpica/Makefile b/drivers/acpi/acpica/Makefile
index 7f1d40797e80..c8bc24bd1f72 100644
--- a/drivers/acpi/acpica/Makefile
+++ b/drivers/acpi/acpica/Makefile
@@ -161,3 +161,6 @@ acpi-y += \
161 utxfinit.o \ 161 utxfinit.o \
162 utxferror.o \ 162 utxferror.o \
163 utxfmutex.o 163 utxfmutex.o
164
165acpi-$(ACPI_FUTURE_USAGE) += uttrack.o utcache.o utclib.o
166
diff --git a/drivers/acpi/acpica/acutils.h b/drivers/acpi/acpica/acutils.h
index 68cb6de26d13..82d6025332e9 100644
--- a/drivers/acpi/acpica/acutils.h
+++ b/drivers/acpi/acpica/acutils.h
@@ -69,6 +69,22 @@ extern const char *acpi_gbl_siz_decode[];
69extern const char *acpi_gbl_trs_decode[]; 69extern const char *acpi_gbl_trs_decode[];
70extern const char *acpi_gbl_ttp_decode[]; 70extern const char *acpi_gbl_ttp_decode[];
71extern const char *acpi_gbl_typ_decode[]; 71extern const char *acpi_gbl_typ_decode[];
72extern const char *acpi_gbl_ppc_decode[];
73extern const char *acpi_gbl_ior_decode[];
74extern const char *acpi_gbl_dts_decode[];
75extern const char *acpi_gbl_ct_decode[];
76extern const char *acpi_gbl_sbt_decode[];
77extern const char *acpi_gbl_am_decode[];
78extern const char *acpi_gbl_sm_decode[];
79extern const char *acpi_gbl_wm_decode[];
80extern const char *acpi_gbl_cph_decode[];
81extern const char *acpi_gbl_cpo_decode[];
82extern const char *acpi_gbl_dp_decode[];
83extern const char *acpi_gbl_ed_decode[];
84extern const char *acpi_gbl_bpb_decode[];
85extern const char *acpi_gbl_sb_decode[];
86extern const char *acpi_gbl_fc_decode[];
87extern const char *acpi_gbl_pt_decode[];
72#endif 88#endif
73 89
74/* Types for Resource descriptor entries */ 90/* Types for Resource descriptor entries */
@@ -79,14 +95,14 @@ extern const char *acpi_gbl_typ_decode[];
79#define ACPI_SMALL_VARIABLE_LENGTH 3 95#define ACPI_SMALL_VARIABLE_LENGTH 3
80 96
81typedef 97typedef
82acpi_status(*acpi_walk_aml_callback) (u8 * aml, 98acpi_status(*acpi_walk_aml_callback) (u8 *aml,
83 u32 length, 99 u32 length,
84 u32 offset, 100 u32 offset,
85 u8 resource_index, void **context); 101 u8 resource_index, void **context);
86 102
87typedef 103typedef
88acpi_status(*acpi_pkg_callback) (u8 object_type, 104acpi_status(*acpi_pkg_callback) (u8 object_type,
89 union acpi_operand_object * source_object, 105 union acpi_operand_object *source_object,
90 union acpi_generic_state * state, 106 union acpi_generic_state * state,
91 void *context); 107 void *context);
92 108
@@ -202,7 +218,9 @@ extern const u8 _acpi_ctype[];
202#define ACPI_IS_PRINT(c) (_acpi_ctype[(unsigned char)(c)] & (_ACPI_LO | _ACPI_UP | _ACPI_DI | _ACPI_SP | _ACPI_PU)) 218#define ACPI_IS_PRINT(c) (_acpi_ctype[(unsigned char)(c)] & (_ACPI_LO | _ACPI_UP | _ACPI_DI | _ACPI_SP | _ACPI_PU))
203#define ACPI_IS_ALPHA(c) (_acpi_ctype[(unsigned char)(c)] & (_ACPI_LO | _ACPI_UP)) 219#define ACPI_IS_ALPHA(c) (_acpi_ctype[(unsigned char)(c)] & (_ACPI_LO | _ACPI_UP))
204 220
205#endif /* ACPI_USE_SYSTEM_CLIBRARY */ 221#endif /* !ACPI_USE_SYSTEM_CLIBRARY */
222
223#define ACPI_IS_ASCII(c) ((c) < 0x80)
206 224
207/* 225/*
208 * utcopy - Object construction and conversion interfaces 226 * utcopy - Object construction and conversion interfaces
@@ -210,11 +228,11 @@ extern const u8 _acpi_ctype[];
210acpi_status 228acpi_status
211acpi_ut_build_simple_object(union acpi_operand_object *obj, 229acpi_ut_build_simple_object(union acpi_operand_object *obj,
212 union acpi_object *user_obj, 230 union acpi_object *user_obj,
213 u8 * data_space, u32 * buffer_space_used); 231 u8 *data_space, u32 *buffer_space_used);
214 232
215acpi_status 233acpi_status
216acpi_ut_build_package_object(union acpi_operand_object *obj, 234acpi_ut_build_package_object(union acpi_operand_object *obj,
217 u8 * buffer, u32 * space_used); 235 u8 *buffer, u32 *space_used);
218 236
219acpi_status 237acpi_status
220acpi_ut_copy_iobject_to_eobject(union acpi_operand_object *obj, 238acpi_ut_copy_iobject_to_eobject(union acpi_operand_object *obj,
@@ -287,9 +305,9 @@ acpi_ut_ptr_exit(u32 line_number,
287 const char *function_name, 305 const char *function_name,
288 const char *module_name, u32 component_id, u8 *ptr); 306 const char *module_name, u32 component_id, u8 *ptr);
289 307
290void acpi_ut_dump_buffer(u8 * buffer, u32 count, u32 display, u32 component_id); 308void acpi_ut_dump_buffer(u8 *buffer, u32 count, u32 display, u32 component_id);
291 309
292void acpi_ut_dump_buffer2(u8 * buffer, u32 count, u32 display); 310void acpi_ut_dump_buffer2(u8 *buffer, u32 count, u32 display);
293 311
294void acpi_ut_report_error(char *module_name, u32 line_number); 312void acpi_ut_report_error(char *module_name, u32 line_number);
295 313
@@ -337,15 +355,15 @@ acpi_ut_execute_power_methods(struct acpi_namespace_node *device_node,
337 */ 355 */
338acpi_status 356acpi_status
339acpi_ut_execute_HID(struct acpi_namespace_node *device_node, 357acpi_ut_execute_HID(struct acpi_namespace_node *device_node,
340 struct acpica_device_id **return_id); 358 struct acpica_device_id ** return_id);
341 359
342acpi_status 360acpi_status
343acpi_ut_execute_UID(struct acpi_namespace_node *device_node, 361acpi_ut_execute_UID(struct acpi_namespace_node *device_node,
344 struct acpica_device_id **return_id); 362 struct acpica_device_id ** return_id);
345 363
346acpi_status 364acpi_status
347acpi_ut_execute_CID(struct acpi_namespace_node *device_node, 365acpi_ut_execute_CID(struct acpi_namespace_node *device_node,
348 struct acpica_device_id_list **return_cid_list); 366 struct acpica_device_id_list ** return_cid_list);
349 367
350/* 368/*
351 * utlock - reader/writer locks 369 * utlock - reader/writer locks
@@ -479,6 +497,10 @@ acpi_ut_walk_package_tree(union acpi_operand_object *source_object,
479 497
480void acpi_ut_strupr(char *src_string); 498void acpi_ut_strupr(char *src_string);
481 499
500void acpi_ut_strlwr(char *src_string);
501
502int acpi_ut_stricmp(char *string1, char *string2);
503
482void acpi_ut_print_string(char *string, u8 max_length); 504void acpi_ut_print_string(char *string, u8 max_length);
483 505
484u8 acpi_ut_valid_acpi_name(u32 name); 506u8 acpi_ut_valid_acpi_name(u32 name);
@@ -487,7 +509,7 @@ void acpi_ut_repair_name(char *name);
487 509
488u8 acpi_ut_valid_acpi_char(char character, u32 position); 510u8 acpi_ut_valid_acpi_char(char character, u32 position);
489 511
490acpi_status acpi_ut_strtoul64(char *string, u32 base, u64 * ret_integer); 512acpi_status acpi_ut_strtoul64(char *string, u32 base, u64 *ret_integer);
491 513
492/* Values for Base above (16=Hex, 10=Decimal) */ 514/* Values for Base above (16=Hex, 10=Decimal) */
493 515
@@ -508,12 +530,12 @@ acpi_ut_display_init_pathname(u8 type,
508 * utresrc 530 * utresrc
509 */ 531 */
510acpi_status 532acpi_status
511acpi_ut_walk_aml_resources(u8 * aml, 533acpi_ut_walk_aml_resources(u8 *aml,
512 acpi_size aml_length, 534 acpi_size aml_length,
513 acpi_walk_aml_callback user_function, 535 acpi_walk_aml_callback user_function,
514 void **context); 536 void **context);
515 537
516acpi_status acpi_ut_validate_resource(void *aml, u8 * return_index); 538acpi_status acpi_ut_validate_resource(void *aml, u8 *return_index);
517 539
518u32 acpi_ut_get_descriptor_length(void *aml); 540u32 acpi_ut_get_descriptor_length(void *aml);
519 541
@@ -524,8 +546,7 @@ u8 acpi_ut_get_resource_header_length(void *aml);
524u8 acpi_ut_get_resource_type(void *aml); 546u8 acpi_ut_get_resource_type(void *aml);
525 547
526acpi_status 548acpi_status
527acpi_ut_get_resource_end_tag(union acpi_operand_object *obj_desc, 549acpi_ut_get_resource_end_tag(union acpi_operand_object *obj_desc, u8 **end_tag);
528 u8 ** end_tag);
529 550
530/* 551/*
531 * utmutex - mutex support 552 * utmutex - mutex support
diff --git a/drivers/acpi/acpica/utcache.c b/drivers/acpi/acpica/utcache.c
new file mode 100644
index 000000000000..eacb9ba2b9e0
--- /dev/null
+++ b/drivers/acpi/acpica/utcache.c
@@ -0,0 +1,323 @@
1/******************************************************************************
2 *
3 * Module Name: utcache - local cache allocation routines
4 *
5 *****************************************************************************/
6
7/*
8 * Copyright (C) 2000 - 2012, 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
47#define _COMPONENT ACPI_UTILITIES
48ACPI_MODULE_NAME("utcache")
49
50#ifdef ACPI_USE_LOCAL_CACHE
51/*******************************************************************************
52 *
53 * FUNCTION: acpi_os_create_cache
54 *
55 * PARAMETERS: cache_name - Ascii name for the cache
56 * object_size - Size of each cached object
57 * max_depth - Maximum depth of the cache (in objects)
58 * return_cache - Where the new cache object is returned
59 *
60 * RETURN: Status
61 *
62 * DESCRIPTION: Create a cache object
63 *
64 ******************************************************************************/
65acpi_status
66acpi_os_create_cache(char *cache_name,
67 u16 object_size,
68 u16 max_depth, struct acpi_memory_list ** return_cache)
69{
70 struct acpi_memory_list *cache;
71
72 ACPI_FUNCTION_ENTRY();
73
74 if (!cache_name || !return_cache || (object_size < 16)) {
75 return (AE_BAD_PARAMETER);
76 }
77
78 /* Create the cache object */
79
80 cache = acpi_os_allocate(sizeof(struct acpi_memory_list));
81 if (!cache) {
82 return (AE_NO_MEMORY);
83 }
84
85 /* Populate the cache object and return it */
86
87 ACPI_MEMSET(cache, 0, sizeof(struct acpi_memory_list));
88 cache->link_offset = 8;
89 cache->list_name = cache_name;
90 cache->object_size = object_size;
91 cache->max_depth = max_depth;
92
93 *return_cache = cache;
94 return (AE_OK);
95}
96
97/*******************************************************************************
98 *
99 * FUNCTION: acpi_os_purge_cache
100 *
101 * PARAMETERS: cache - Handle to cache object
102 *
103 * RETURN: Status
104 *
105 * DESCRIPTION: Free all objects within the requested cache.
106 *
107 ******************************************************************************/
108
109acpi_status acpi_os_purge_cache(struct acpi_memory_list * cache)
110{
111 char *next;
112 acpi_status status;
113
114 ACPI_FUNCTION_ENTRY();
115
116 if (!cache) {
117 return (AE_BAD_PARAMETER);
118 }
119
120 status = acpi_ut_acquire_mutex(ACPI_MTX_CACHES);
121 if (ACPI_FAILURE(status)) {
122 return (status);
123 }
124
125 /* Walk the list of objects in this cache */
126
127 while (cache->list_head) {
128
129 /* Delete and unlink one cached state object */
130
131 next = *(ACPI_CAST_INDIRECT_PTR(char,
132 &(((char *)cache->
133 list_head)[cache->
134 link_offset])));
135 ACPI_FREE(cache->list_head);
136
137 cache->list_head = next;
138 cache->current_depth--;
139 }
140
141 (void)acpi_ut_release_mutex(ACPI_MTX_CACHES);
142 return (AE_OK);
143}
144
145/*******************************************************************************
146 *
147 * FUNCTION: acpi_os_delete_cache
148 *
149 * PARAMETERS: cache - Handle to cache object
150 *
151 * RETURN: Status
152 *
153 * DESCRIPTION: Free all objects within the requested cache and delete the
154 * cache object.
155 *
156 ******************************************************************************/
157
158acpi_status acpi_os_delete_cache(struct acpi_memory_list * cache)
159{
160 acpi_status status;
161
162 ACPI_FUNCTION_ENTRY();
163
164 /* Purge all objects in the cache */
165
166 status = acpi_os_purge_cache(cache);
167 if (ACPI_FAILURE(status)) {
168 return (status);
169 }
170
171 /* Now we can delete the cache object */
172
173 acpi_os_free(cache);
174 return (AE_OK);
175}
176
177/*******************************************************************************
178 *
179 * FUNCTION: acpi_os_release_object
180 *
181 * PARAMETERS: cache - Handle to cache object
182 * object - The object to be released
183 *
184 * RETURN: None
185 *
186 * DESCRIPTION: Release an object to the specified cache. If cache is full,
187 * the object is deleted.
188 *
189 ******************************************************************************/
190
191acpi_status
192acpi_os_release_object(struct acpi_memory_list * cache, void *object)
193{
194 acpi_status status;
195
196 ACPI_FUNCTION_ENTRY();
197
198 if (!cache || !object) {
199 return (AE_BAD_PARAMETER);
200 }
201
202 /* If cache is full, just free this object */
203
204 if (cache->current_depth >= cache->max_depth) {
205 ACPI_FREE(object);
206 ACPI_MEM_TRACKING(cache->total_freed++);
207 }
208
209 /* Otherwise put this object back into the cache */
210
211 else {
212 status = acpi_ut_acquire_mutex(ACPI_MTX_CACHES);
213 if (ACPI_FAILURE(status)) {
214 return (status);
215 }
216
217 /* Mark the object as cached */
218
219 ACPI_MEMSET(object, 0xCA, cache->object_size);
220 ACPI_SET_DESCRIPTOR_TYPE(object, ACPI_DESC_TYPE_CACHED);
221
222 /* Put the object at the head of the cache list */
223
224 *(ACPI_CAST_INDIRECT_PTR(char,
225 &(((char *)object)[cache->
226 link_offset]))) =
227 cache->list_head;
228 cache->list_head = object;
229 cache->current_depth++;
230
231 (void)acpi_ut_release_mutex(ACPI_MTX_CACHES);
232 }
233
234 return (AE_OK);
235}
236
237/*******************************************************************************
238 *
239 * FUNCTION: acpi_os_acquire_object
240 *
241 * PARAMETERS: cache - Handle to cache object
242 *
243 * RETURN: the acquired object. NULL on error
244 *
245 * DESCRIPTION: Get an object from the specified cache. If cache is empty,
246 * the object is allocated.
247 *
248 ******************************************************************************/
249
250void *acpi_os_acquire_object(struct acpi_memory_list *cache)
251{
252 acpi_status status;
253 void *object;
254
255 ACPI_FUNCTION_NAME(os_acquire_object);
256
257 if (!cache) {
258 return (NULL);
259 }
260
261 status = acpi_ut_acquire_mutex(ACPI_MTX_CACHES);
262 if (ACPI_FAILURE(status)) {
263 return (NULL);
264 }
265
266 ACPI_MEM_TRACKING(cache->requests++);
267
268 /* Check the cache first */
269
270 if (cache->list_head) {
271
272 /* There is an object available, use it */
273
274 object = cache->list_head;
275 cache->list_head = *(ACPI_CAST_INDIRECT_PTR(char,
276 &(((char *)
277 object)[cache->
278 link_offset])));
279
280 cache->current_depth--;
281
282 ACPI_MEM_TRACKING(cache->hits++);
283 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
284 "Object %p from %s cache\n", object,
285 cache->list_name));
286
287 status = acpi_ut_release_mutex(ACPI_MTX_CACHES);
288 if (ACPI_FAILURE(status)) {
289 return (NULL);
290 }
291
292 /* Clear (zero) the previously used Object */
293
294 ACPI_MEMSET(object, 0, cache->object_size);
295 } else {
296 /* The cache is empty, create a new object */
297
298 ACPI_MEM_TRACKING(cache->total_allocated++);
299
300#ifdef ACPI_DBG_TRACK_ALLOCATIONS
301 if ((cache->total_allocated - cache->total_freed) >
302 cache->max_occupied) {
303 cache->max_occupied =
304 cache->total_allocated - cache->total_freed;
305 }
306#endif
307
308 /* Avoid deadlock with ACPI_ALLOCATE_ZEROED */
309
310 status = acpi_ut_release_mutex(ACPI_MTX_CACHES);
311 if (ACPI_FAILURE(status)) {
312 return (NULL);
313 }
314
315 object = ACPI_ALLOCATE_ZEROED(cache->object_size);
316 if (!object) {
317 return (NULL);
318 }
319 }
320
321 return (object);
322}
323#endif /* ACPI_USE_LOCAL_CACHE */
diff --git a/drivers/acpi/acpica/utclib.c b/drivers/acpi/acpica/utclib.c
new file mode 100644
index 000000000000..f887f93e56ad
--- /dev/null
+++ b/drivers/acpi/acpica/utclib.c
@@ -0,0 +1,748 @@
1/******************************************************************************
2 *
3 * Module Name: cmclib - Local implementation of C library functions
4 *
5 *****************************************************************************/
6
7/*
8 * Copyright (C) 2000 - 2012, 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
47/*
48 * These implementations of standard C Library routines can optionally be
49 * used if a C library is not available. In general, they are less efficient
50 * than an inline or assembly implementation
51 */
52
53#define _COMPONENT ACPI_UTILITIES
54ACPI_MODULE_NAME("cmclib")
55
56#ifndef ACPI_USE_SYSTEM_CLIBRARY
57#define NEGATIVE 1
58#define POSITIVE 0
59/*******************************************************************************
60 *
61 * FUNCTION: acpi_ut_memcmp (memcmp)
62 *
63 * PARAMETERS: buffer1 - First Buffer
64 * buffer2 - Second Buffer
65 * count - Maximum # of bytes to compare
66 *
67 * RETURN: Index where Buffers mismatched, or 0 if Buffers matched
68 *
69 * DESCRIPTION: Compare two Buffers, with a maximum length
70 *
71 ******************************************************************************/
72int acpi_ut_memcmp(const char *buffer1, const char *buffer2, acpi_size count)
73{
74
75 return ((count == ACPI_SIZE_MAX) ? 0 : ((unsigned char)*buffer1 -
76 (unsigned char)*buffer2));
77}
78
79/*******************************************************************************
80 *
81 * FUNCTION: acpi_ut_memcpy (memcpy)
82 *
83 * PARAMETERS: dest - Target of the copy
84 * src - Source buffer to copy
85 * count - Number of bytes to copy
86 *
87 * RETURN: Dest
88 *
89 * DESCRIPTION: Copy arbitrary bytes of memory
90 *
91 ******************************************************************************/
92
93void *acpi_ut_memcpy(void *dest, const void *src, acpi_size count)
94{
95 char *new = (char *)dest;
96 char *old = (char *)src;
97
98 while (count) {
99 *new = *old;
100 new++;
101 old++;
102 count--;
103 }
104
105 return (dest);
106}
107
108/*******************************************************************************
109 *
110 * FUNCTION: acpi_ut_memset (memset)
111 *
112 * PARAMETERS: dest - Buffer to set
113 * value - Value to set each byte of memory
114 * count - Number of bytes to set
115 *
116 * RETURN: Dest
117 *
118 * DESCRIPTION: Initialize a buffer to a known value.
119 *
120 ******************************************************************************/
121
122void *acpi_ut_memset(void *dest, u8 value, acpi_size count)
123{
124 char *new = (char *)dest;
125
126 while (count) {
127 *new = (char)value;
128 new++;
129 count--;
130 }
131
132 return (dest);
133}
134
135/*******************************************************************************
136 *
137 * FUNCTION: acpi_ut_strlen (strlen)
138 *
139 * PARAMETERS: string - Null terminated string
140 *
141 * RETURN: Length
142 *
143 * DESCRIPTION: Returns the length of the input string
144 *
145 ******************************************************************************/
146
147acpi_size acpi_ut_strlen(const char *string)
148{
149 u32 length = 0;
150
151 /* Count the string until a null is encountered */
152
153 while (*string) {
154 length++;
155 string++;
156 }
157
158 return (length);
159}
160
161/*******************************************************************************
162 *
163 * FUNCTION: acpi_ut_strcpy (strcpy)
164 *
165 * PARAMETERS: dst_string - Target of the copy
166 * src_string - The source string to copy
167 *
168 * RETURN: dst_string
169 *
170 * DESCRIPTION: Copy a null terminated string
171 *
172 ******************************************************************************/
173
174char *acpi_ut_strcpy(char *dst_string, const char *src_string)
175{
176 char *string = dst_string;
177
178 /* Move bytes brute force */
179
180 while (*src_string) {
181 *string = *src_string;
182
183 string++;
184 src_string++;
185 }
186
187 /* Null terminate */
188
189 *string = 0;
190 return (dst_string);
191}
192
193/*******************************************************************************
194 *
195 * FUNCTION: acpi_ut_strncpy (strncpy)
196 *
197 * PARAMETERS: dst_string - Target of the copy
198 * src_string - The source string to copy
199 * count - Maximum # of bytes to copy
200 *
201 * RETURN: dst_string
202 *
203 * DESCRIPTION: Copy a null terminated string, with a maximum length
204 *
205 ******************************************************************************/
206
207char *acpi_ut_strncpy(char *dst_string, const char *src_string, acpi_size count)
208{
209 char *string = dst_string;
210
211 /* Copy the string */
212
213 for (string = dst_string;
214 count && (count--, (*string++ = *src_string++));) {;
215 }
216
217 /* Pad with nulls if necessary */
218
219 while (count--) {
220 *string = 0;
221 string++;
222 }
223
224 /* Return original pointer */
225
226 return (dst_string);
227}
228
229/*******************************************************************************
230 *
231 * FUNCTION: acpi_ut_strcmp (strcmp)
232 *
233 * PARAMETERS: string1 - First string
234 * string2 - Second string
235 *
236 * RETURN: Index where strings mismatched, or 0 if strings matched
237 *
238 * DESCRIPTION: Compare two null terminated strings
239 *
240 ******************************************************************************/
241
242int acpi_ut_strcmp(const char *string1, const char *string2)
243{
244
245 for (; (*string1 == *string2); string2++) {
246 if (!*string1++) {
247 return (0);
248 }
249 }
250
251 return ((unsigned char)*string1 - (unsigned char)*string2);
252}
253
254#ifdef ACPI_FUTURE_IMPLEMENTATION
255/* Not used at this time */
256/*******************************************************************************
257 *
258 * FUNCTION: acpi_ut_strchr (strchr)
259 *
260 * PARAMETERS: string - Search string
261 * ch - character to search for
262 *
263 * RETURN: Ptr to char or NULL if not found
264 *
265 * DESCRIPTION: Search a string for a character
266 *
267 ******************************************************************************/
268
269char *acpi_ut_strchr(const char *string, int ch)
270{
271
272 for (; (*string); string++) {
273 if ((*string) == (char)ch) {
274 return ((char *)string);
275 }
276 }
277
278 return (NULL);
279}
280#endif
281
282/*******************************************************************************
283 *
284 * FUNCTION: acpi_ut_strncmp (strncmp)
285 *
286 * PARAMETERS: string1 - First string
287 * string2 - Second string
288 * count - Maximum # of bytes to compare
289 *
290 * RETURN: Index where strings mismatched, or 0 if strings matched
291 *
292 * DESCRIPTION: Compare two null terminated strings, with a maximum length
293 *
294 ******************************************************************************/
295
296int acpi_ut_strncmp(const char *string1, const char *string2, acpi_size count)
297{
298
299 for (; count-- && (*string1 == *string2); string2++) {
300 if (!*string1++) {
301 return (0);
302 }
303 }
304
305 return ((count == ACPI_SIZE_MAX) ? 0 : ((unsigned char)*string1 -
306 (unsigned char)*string2));
307}
308
309/*******************************************************************************
310 *
311 * FUNCTION: acpi_ut_strcat (Strcat)
312 *
313 * PARAMETERS: dst_string - Target of the copy
314 * src_string - The source string to copy
315 *
316 * RETURN: dst_string
317 *
318 * DESCRIPTION: Append a null terminated string to a null terminated string
319 *
320 ******************************************************************************/
321
322char *acpi_ut_strcat(char *dst_string, const char *src_string)
323{
324 char *string;
325
326 /* Find end of the destination string */
327
328 for (string = dst_string; *string++;) {;
329 }
330
331 /* Concatenate the string */
332
333 for (--string; (*string++ = *src_string++);) {;
334 }
335
336 return (dst_string);
337}
338
339/*******************************************************************************
340 *
341 * FUNCTION: acpi_ut_strncat (strncat)
342 *
343 * PARAMETERS: dst_string - Target of the copy
344 * src_string - The source string to copy
345 * count - Maximum # of bytes to copy
346 *
347 * RETURN: dst_string
348 *
349 * DESCRIPTION: Append a null terminated string to a null terminated string,
350 * with a maximum count.
351 *
352 ******************************************************************************/
353
354char *acpi_ut_strncat(char *dst_string, const char *src_string, acpi_size count)
355{
356 char *string;
357
358 if (count) {
359
360 /* Find end of the destination string */
361
362 for (string = dst_string; *string++;) {;
363 }
364
365 /* Concatenate the string */
366
367 for (--string; (*string++ = *src_string++) && --count;) {;
368 }
369
370 /* Null terminate if necessary */
371
372 if (!count) {
373 *string = 0;
374 }
375 }
376
377 return (dst_string);
378}
379
380/*******************************************************************************
381 *
382 * FUNCTION: acpi_ut_strstr (strstr)
383 *
384 * PARAMETERS: string1 - Target string
385 * string2 - Substring to search for
386 *
387 * RETURN: Where substring match starts, Null if no match found
388 *
389 * DESCRIPTION: Checks if String2 occurs in String1. This is not really a
390 * full implementation of strstr, only sufficient for command
391 * matching
392 *
393 ******************************************************************************/
394
395char *acpi_ut_strstr(char *string1, char *string2)
396{
397 char *string;
398
399 if (acpi_ut_strlen(string2) > acpi_ut_strlen(string1)) {
400 return (NULL);
401 }
402
403 /* Walk entire string, comparing the letters */
404
405 for (string = string1; *string2;) {
406 if (*string2 != *string) {
407 return (NULL);
408 }
409
410 string2++;
411 string++;
412 }
413
414 return (string1);
415}
416
417/*******************************************************************************
418 *
419 * FUNCTION: acpi_ut_strtoul (strtoul)
420 *
421 * PARAMETERS: string - Null terminated string
422 * terminater - Where a pointer to the terminating byte is
423 * returned
424 * base - Radix of the string
425 *
426 * RETURN: Converted value
427 *
428 * DESCRIPTION: Convert a string into a 32-bit unsigned value.
429 * Note: use acpi_ut_strtoul64 for 64-bit integers.
430 *
431 ******************************************************************************/
432
433u32 acpi_ut_strtoul(const char *string, char **terminator, u32 base)
434{
435 u32 converted = 0;
436 u32 index;
437 u32 sign;
438 const char *string_start;
439 u32 return_value = 0;
440 acpi_status status = AE_OK;
441
442 /*
443 * Save the value of the pointer to the buffer's first
444 * character, save the current errno value, and then
445 * skip over any white space in the buffer:
446 */
447 string_start = string;
448 while (ACPI_IS_SPACE(*string) || *string == '\t') {
449 ++string;
450 }
451
452 /*
453 * The buffer may contain an optional plus or minus sign.
454 * If it does, then skip over it but remember what is was:
455 */
456 if (*string == '-') {
457 sign = NEGATIVE;
458 ++string;
459 } else if (*string == '+') {
460 ++string;
461 sign = POSITIVE;
462 } else {
463 sign = POSITIVE;
464 }
465
466 /*
467 * If the input parameter Base is zero, then we need to
468 * determine if it is octal, decimal, or hexadecimal:
469 */
470 if (base == 0) {
471 if (*string == '0') {
472 if (acpi_ut_to_lower(*(++string)) == 'x') {
473 base = 16;
474 ++string;
475 } else {
476 base = 8;
477 }
478 } else {
479 base = 10;
480 }
481 } else if (base < 2 || base > 36) {
482 /*
483 * The specified Base parameter is not in the domain of
484 * this function:
485 */
486 goto done;
487 }
488
489 /*
490 * For octal and hexadecimal bases, skip over the leading
491 * 0 or 0x, if they are present.
492 */
493 if (base == 8 && *string == '0') {
494 string++;
495 }
496
497 if (base == 16 &&
498 *string == '0' && acpi_ut_to_lower(*(++string)) == 'x') {
499 string++;
500 }
501
502 /*
503 * Main loop: convert the string to an unsigned long:
504 */
505 while (*string) {
506 if (ACPI_IS_DIGIT(*string)) {
507 index = (u32)((u8)*string - '0');
508 } else {
509 index = (u32)acpi_ut_to_upper(*string);
510 if (ACPI_IS_UPPER(index)) {
511 index = index - 'A' + 10;
512 } else {
513 goto done;
514 }
515 }
516
517 if (index >= base) {
518 goto done;
519 }
520
521 /*
522 * Check to see if value is out of range:
523 */
524
525 if (return_value > ((ACPI_UINT32_MAX - (u32)index) / (u32)base)) {
526 status = AE_ERROR;
527 return_value = 0; /* reset */
528 } else {
529 return_value *= base;
530 return_value += index;
531 converted = 1;
532 }
533
534 ++string;
535 }
536
537 done:
538 /*
539 * If appropriate, update the caller's pointer to the next
540 * unconverted character in the buffer.
541 */
542 if (terminator) {
543 if (converted == 0 && return_value == 0 && string != NULL) {
544 *terminator = (char *)string_start;
545 } else {
546 *terminator = (char *)string;
547 }
548 }
549
550 if (status == AE_ERROR) {
551 return_value = ACPI_UINT32_MAX;
552 }
553
554 /*
555 * If a minus sign was present, then "the conversion is negated":
556 */
557 if (sign == NEGATIVE) {
558 return_value = (ACPI_UINT32_MAX - return_value) + 1;
559 }
560
561 return (return_value);
562}
563
564/*******************************************************************************
565 *
566 * FUNCTION: acpi_ut_to_upper (TOUPPER)
567 *
568 * PARAMETERS: c - Character to convert
569 *
570 * RETURN: Converted character as an int
571 *
572 * DESCRIPTION: Convert character to uppercase
573 *
574 ******************************************************************************/
575
576int acpi_ut_to_upper(int c)
577{
578
579 return (ACPI_IS_LOWER(c) ? ((c) - 0x20) : (c));
580}
581
582/*******************************************************************************
583 *
584 * FUNCTION: acpi_ut_to_lower (TOLOWER)
585 *
586 * PARAMETERS: c - Character to convert
587 *
588 * RETURN: Converted character as an int
589 *
590 * DESCRIPTION: Convert character to lowercase
591 *
592 ******************************************************************************/
593
594int acpi_ut_to_lower(int c)
595{
596
597 return (ACPI_IS_UPPER(c) ? ((c) + 0x20) : (c));
598}
599
600/*******************************************************************************
601 *
602 * FUNCTION: is* functions
603 *
604 * DESCRIPTION: is* functions use the ctype table below
605 *
606 ******************************************************************************/
607
608const u8 _acpi_ctype[257] = {
609 _ACPI_CN, /* 0x0 0. */
610 _ACPI_CN, /* 0x1 1. */
611 _ACPI_CN, /* 0x2 2. */
612 _ACPI_CN, /* 0x3 3. */
613 _ACPI_CN, /* 0x4 4. */
614 _ACPI_CN, /* 0x5 5. */
615 _ACPI_CN, /* 0x6 6. */
616 _ACPI_CN, /* 0x7 7. */
617 _ACPI_CN, /* 0x8 8. */
618 _ACPI_CN | _ACPI_SP, /* 0x9 9. */
619 _ACPI_CN | _ACPI_SP, /* 0xA 10. */
620 _ACPI_CN | _ACPI_SP, /* 0xB 11. */
621 _ACPI_CN | _ACPI_SP, /* 0xC 12. */
622 _ACPI_CN | _ACPI_SP, /* 0xD 13. */
623 _ACPI_CN, /* 0xE 14. */
624 _ACPI_CN, /* 0xF 15. */
625 _ACPI_CN, /* 0x10 16. */
626 _ACPI_CN, /* 0x11 17. */
627 _ACPI_CN, /* 0x12 18. */
628 _ACPI_CN, /* 0x13 19. */
629 _ACPI_CN, /* 0x14 20. */
630 _ACPI_CN, /* 0x15 21. */
631 _ACPI_CN, /* 0x16 22. */
632 _ACPI_CN, /* 0x17 23. */
633 _ACPI_CN, /* 0x18 24. */
634 _ACPI_CN, /* 0x19 25. */
635 _ACPI_CN, /* 0x1A 26. */
636 _ACPI_CN, /* 0x1B 27. */
637 _ACPI_CN, /* 0x1C 28. */
638 _ACPI_CN, /* 0x1D 29. */
639 _ACPI_CN, /* 0x1E 30. */
640 _ACPI_CN, /* 0x1F 31. */
641 _ACPI_XS | _ACPI_SP, /* 0x20 32. ' ' */
642 _ACPI_PU, /* 0x21 33. '!' */
643 _ACPI_PU, /* 0x22 34. '"' */
644 _ACPI_PU, /* 0x23 35. '#' */
645 _ACPI_PU, /* 0x24 36. '$' */
646 _ACPI_PU, /* 0x25 37. '%' */
647 _ACPI_PU, /* 0x26 38. '&' */
648 _ACPI_PU, /* 0x27 39. ''' */
649 _ACPI_PU, /* 0x28 40. '(' */
650 _ACPI_PU, /* 0x29 41. ')' */
651 _ACPI_PU, /* 0x2A 42. '*' */
652 _ACPI_PU, /* 0x2B 43. '+' */
653 _ACPI_PU, /* 0x2C 44. ',' */
654 _ACPI_PU, /* 0x2D 45. '-' */
655 _ACPI_PU, /* 0x2E 46. '.' */
656 _ACPI_PU, /* 0x2F 47. '/' */
657 _ACPI_XD | _ACPI_DI, /* 0x30 48. '0' */
658 _ACPI_XD | _ACPI_DI, /* 0x31 49. '1' */
659 _ACPI_XD | _ACPI_DI, /* 0x32 50. '2' */
660 _ACPI_XD | _ACPI_DI, /* 0x33 51. '3' */
661 _ACPI_XD | _ACPI_DI, /* 0x34 52. '4' */
662 _ACPI_XD | _ACPI_DI, /* 0x35 53. '5' */
663 _ACPI_XD | _ACPI_DI, /* 0x36 54. '6' */
664 _ACPI_XD | _ACPI_DI, /* 0x37 55. '7' */
665 _ACPI_XD | _ACPI_DI, /* 0x38 56. '8' */
666 _ACPI_XD | _ACPI_DI, /* 0x39 57. '9' */
667 _ACPI_PU, /* 0x3A 58. ':' */
668 _ACPI_PU, /* 0x3B 59. ';' */
669 _ACPI_PU, /* 0x3C 60. '<' */
670 _ACPI_PU, /* 0x3D 61. '=' */
671 _ACPI_PU, /* 0x3E 62. '>' */
672 _ACPI_PU, /* 0x3F 63. '?' */
673 _ACPI_PU, /* 0x40 64. '@' */
674 _ACPI_XD | _ACPI_UP, /* 0x41 65. 'A' */
675 _ACPI_XD | _ACPI_UP, /* 0x42 66. 'B' */
676 _ACPI_XD | _ACPI_UP, /* 0x43 67. 'C' */
677 _ACPI_XD | _ACPI_UP, /* 0x44 68. 'D' */
678 _ACPI_XD | _ACPI_UP, /* 0x45 69. 'E' */
679 _ACPI_XD | _ACPI_UP, /* 0x46 70. 'F' */
680 _ACPI_UP, /* 0x47 71. 'G' */
681 _ACPI_UP, /* 0x48 72. 'H' */
682 _ACPI_UP, /* 0x49 73. 'I' */
683 _ACPI_UP, /* 0x4A 74. 'J' */
684 _ACPI_UP, /* 0x4B 75. 'K' */
685 _ACPI_UP, /* 0x4C 76. 'L' */
686 _ACPI_UP, /* 0x4D 77. 'M' */
687 _ACPI_UP, /* 0x4E 78. 'N' */
688 _ACPI_UP, /* 0x4F 79. 'O' */
689 _ACPI_UP, /* 0x50 80. 'P' */
690 _ACPI_UP, /* 0x51 81. 'Q' */
691 _ACPI_UP, /* 0x52 82. 'R' */
692 _ACPI_UP, /* 0x53 83. 'S' */
693 _ACPI_UP, /* 0x54 84. 'T' */
694 _ACPI_UP, /* 0x55 85. 'U' */
695 _ACPI_UP, /* 0x56 86. 'V' */
696 _ACPI_UP, /* 0x57 87. 'W' */
697 _ACPI_UP, /* 0x58 88. 'X' */
698 _ACPI_UP, /* 0x59 89. 'Y' */
699 _ACPI_UP, /* 0x5A 90. 'Z' */
700 _ACPI_PU, /* 0x5B 91. '[' */
701 _ACPI_PU, /* 0x5C 92. '\' */
702 _ACPI_PU, /* 0x5D 93. ']' */
703 _ACPI_PU, /* 0x5E 94. '^' */
704 _ACPI_PU, /* 0x5F 95. '_' */
705 _ACPI_PU, /* 0x60 96. '`' */
706 _ACPI_XD | _ACPI_LO, /* 0x61 97. 'a' */
707 _ACPI_XD | _ACPI_LO, /* 0x62 98. 'b' */
708 _ACPI_XD | _ACPI_LO, /* 0x63 99. 'c' */
709 _ACPI_XD | _ACPI_LO, /* 0x64 100. 'd' */
710 _ACPI_XD | _ACPI_LO, /* 0x65 101. 'e' */
711 _ACPI_XD | _ACPI_LO, /* 0x66 102. 'f' */
712 _ACPI_LO, /* 0x67 103. 'g' */
713 _ACPI_LO, /* 0x68 104. 'h' */
714 _ACPI_LO, /* 0x69 105. 'i' */
715 _ACPI_LO, /* 0x6A 106. 'j' */
716 _ACPI_LO, /* 0x6B 107. 'k' */
717 _ACPI_LO, /* 0x6C 108. 'l' */
718 _ACPI_LO, /* 0x6D 109. 'm' */
719 _ACPI_LO, /* 0x6E 110. 'n' */
720 _ACPI_LO, /* 0x6F 111. 'o' */
721 _ACPI_LO, /* 0x70 112. 'p' */
722 _ACPI_LO, /* 0x71 113. 'q' */
723 _ACPI_LO, /* 0x72 114. 'r' */
724 _ACPI_LO, /* 0x73 115. 's' */
725 _ACPI_LO, /* 0x74 116. 't' */
726 _ACPI_LO, /* 0x75 117. 'u' */
727 _ACPI_LO, /* 0x76 118. 'v' */
728 _ACPI_LO, /* 0x77 119. 'w' */
729 _ACPI_LO, /* 0x78 120. 'x' */
730 _ACPI_LO, /* 0x79 121. 'y' */
731 _ACPI_LO, /* 0x7A 122. 'z' */
732 _ACPI_PU, /* 0x7B 123. '{' */
733 _ACPI_PU, /* 0x7C 124. '|' */
734 _ACPI_PU, /* 0x7D 125. '}' */
735 _ACPI_PU, /* 0x7E 126. '~' */
736 _ACPI_CN, /* 0x7F 127. */
737
738 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x80 to 0x8F */
739 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x90 to 0x9F */
740 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xA0 to 0xAF */
741 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xB0 to 0xBF */
742 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xC0 to 0xCF */
743 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xD0 to 0xDF */
744 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xE0 to 0xEF */
745 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 /* 0xF0 to 0x100 */
746};
747
748#endif /* ACPI_USE_SYSTEM_CLIBRARY */
diff --git a/drivers/acpi/acpica/utdebug.c b/drivers/acpi/acpica/utdebug.c
index e810894149ae..6e3ae6a23f0b 100644
--- a/drivers/acpi/acpica/utdebug.c
+++ b/drivers/acpi/acpica/utdebug.c
@@ -47,8 +47,9 @@
47 47
48#define _COMPONENT ACPI_UTILITIES 48#define _COMPONENT ACPI_UTILITIES
49ACPI_MODULE_NAME("utdebug") 49ACPI_MODULE_NAME("utdebug")
50
50#ifdef ACPI_DEBUG_OUTPUT 51#ifdef ACPI_DEBUG_OUTPUT
51static acpi_thread_id acpi_gbl_prev_thread_id; 52static acpi_thread_id acpi_gbl_prev_thread_id = (acpi_thread_id) 0xFFFFFFFF;
52static char *acpi_gbl_fn_entry_str = "----Entry"; 53static char *acpi_gbl_fn_entry_str = "----Entry";
53static char *acpi_gbl_fn_exit_str = "----Exit-"; 54static char *acpi_gbl_fn_exit_str = "----Exit-";
54 55
@@ -109,7 +110,7 @@ void acpi_ut_track_stack_ptr(void)
109 * RETURN: Updated pointer to the function name 110 * RETURN: Updated pointer to the function name
110 * 111 *
111 * DESCRIPTION: Remove the "Acpi" prefix from the function name, if present. 112 * DESCRIPTION: Remove the "Acpi" prefix from the function name, if present.
112 * This allows compiler macros such as __func__ to be used 113 * This allows compiler macros such as __FUNCTION__ to be used
113 * with no change to the debug output. 114 * with no change to the debug output.
114 * 115 *
115 ******************************************************************************/ 116 ******************************************************************************/
@@ -519,7 +520,7 @@ acpi_ut_ptr_exit(u32 line_number,
519 * 520 *
520 ******************************************************************************/ 521 ******************************************************************************/
521 522
522void acpi_ut_dump_buffer2(u8 * buffer, u32 count, u32 display) 523void acpi_ut_dump_buffer2(u8 *buffer, u32 count, u32 display)
523{ 524{
524 u32 i = 0; 525 u32 i = 0;
525 u32 j; 526 u32 j;
@@ -636,7 +637,7 @@ void acpi_ut_dump_buffer2(u8 * buffer, u32 count, u32 display)
636 * 637 *
637 ******************************************************************************/ 638 ******************************************************************************/
638 639
639void acpi_ut_dump_buffer(u8 * buffer, u32 count, u32 display, u32 component_id) 640void acpi_ut_dump_buffer(u8 *buffer, u32 count, u32 display, u32 component_id)
640{ 641{
641 642
642 /* Only dump the buffer if tracing is enabled */ 643 /* Only dump the buffer if tracing is enabled */
diff --git a/drivers/acpi/acpica/utmisc.c b/drivers/acpi/acpica/utmisc.c
index d91d88df2a96..0fed4bcc84b6 100644
--- a/drivers/acpi/acpica/utmisc.c
+++ b/drivers/acpi/acpica/utmisc.c
@@ -41,8 +41,6 @@
41 * POSSIBILITY OF SUCH DAMAGES. 41 * POSSIBILITY OF SUCH DAMAGES.
42 */ 42 */
43 43
44#include <linux/module.h>
45
46#include <acpi/acpi.h> 44#include <acpi/acpi.h>
47#include "accommon.h" 45#include "accommon.h"
48#include "acnamesp.h" 46#include "acnamesp.h"
@@ -201,8 +199,8 @@ acpi_status acpi_ut_allocate_owner_id(acpi_owner_id * owner_id)
201 */ 199 */
202 acpi_gbl_owner_id_mask[j] |= (1 << k); 200 acpi_gbl_owner_id_mask[j] |= (1 << k);
203 201
204 acpi_gbl_last_owner_id_index = (u8) j; 202 acpi_gbl_last_owner_id_index = (u8)j;
205 acpi_gbl_next_owner_id_offset = (u8) (k + 1); 203 acpi_gbl_next_owner_id_offset = (u8)(k + 1);
206 204
207 /* 205 /*
208 * Construct encoded ID from the index and bit position 206 * Construct encoded ID from the index and bit position
@@ -339,6 +337,73 @@ void acpi_ut_strupr(char *src_string)
339 return; 337 return;
340} 338}
341 339
340#ifdef ACPI_ASL_COMPILER
341/*******************************************************************************
342 *
343 * FUNCTION: acpi_ut_strlwr (strlwr)
344 *
345 * PARAMETERS: src_string - The source string to convert
346 *
347 * RETURN: None
348 *
349 * DESCRIPTION: Convert string to lowercase
350 *
351 * NOTE: This is not a POSIX function, so it appears here, not in utclib.c
352 *
353 ******************************************************************************/
354
355void acpi_ut_strlwr(char *src_string)
356{
357 char *string;
358
359 ACPI_FUNCTION_ENTRY();
360
361 if (!src_string) {
362 return;
363 }
364
365 /* Walk entire string, lowercasing the letters */
366
367 for (string = src_string; *string; string++) {
368 *string = (char)ACPI_TOLOWER(*string);
369 }
370
371 return;
372}
373
374/******************************************************************************
375 *
376 * FUNCTION: acpi_ut_stricmp
377 *
378 * PARAMETERS: string1 - first string to compare
379 * string2 - second string to compare
380 *
381 * RETURN: int that signifies string relationship. Zero means strings
382 * are equal.
383 *
384 * DESCRIPTION: Implementation of the non-ANSI stricmp function (compare
385 * strings with no case sensitivity)
386 *
387 ******************************************************************************/
388
389int acpi_ut_stricmp(char *string1, char *string2)
390{
391 int c1;
392 int c2;
393
394 do {
395 c1 = tolower((int)*string1);
396 c2 = tolower((int)*string2);
397
398 string1++;
399 string2++;
400 }
401 while ((c1 == c2) && (c1));
402
403 return (c1 - c2);
404}
405#endif
406
342/******************************************************************************* 407/*******************************************************************************
343 * 408 *
344 * FUNCTION: acpi_ut_print_string 409 * FUNCTION: acpi_ut_print_string
@@ -638,7 +703,16 @@ u8 acpi_ut_valid_acpi_name(u32 name)
638 * RETURN: Repaired version of the name 703 * RETURN: Repaired version of the name
639 * 704 *
640 * DESCRIPTION: Repair an ACPI name: Change invalid characters to '*' and 705 * DESCRIPTION: Repair an ACPI name: Change invalid characters to '*' and
641 * return the new name. 706 * return the new name. NOTE: the Name parameter must reside in
707 * read/write memory, cannot be a const.
708 *
709 * An ACPI Name must consist of valid ACPI characters. We will repair the name
710 * if necessary because we don't want to abort because of this, but we want
711 * all namespace names to be printable. A warning message is appropriate.
712 *
713 * This issue came up because there are in fact machines that exhibit
714 * this problem, and we want to be able to enable ACPI support for them,
715 * even though there are a few bad names.
642 * 716 *
643 ******************************************************************************/ 717 ******************************************************************************/
644 718
@@ -699,7 +773,7 @@ void acpi_ut_repair_name(char *name)
699 * 773 *
700 ******************************************************************************/ 774 ******************************************************************************/
701 775
702acpi_status acpi_ut_strtoul64(char *string, u32 base, u64 * ret_integer) 776acpi_status acpi_ut_strtoul64(char *string, u32 base, u64 *ret_integer)
703{ 777{
704 u32 this_digit = 0; 778 u32 this_digit = 0;
705 u64 return_value = 0; 779 u64 return_value = 0;
@@ -772,14 +846,14 @@ acpi_status acpi_ut_strtoul64(char *string, u32 base, u64 * ret_integer)
772 846
773 /* Convert ASCII 0-9 to Decimal value */ 847 /* Convert ASCII 0-9 to Decimal value */
774 848
775 this_digit = ((u8) * string) - '0'; 849 this_digit = ((u8)*string) - '0';
776 } else if (base == 10) { 850 } else if (base == 10) {
777 851
778 /* Digit is out of range; possible in to_integer case only */ 852 /* Digit is out of range; possible in to_integer case only */
779 853
780 term = 1; 854 term = 1;
781 } else { 855 } else {
782 this_digit = (u8) ACPI_TOUPPER(*string); 856 this_digit = (u8)ACPI_TOUPPER(*string);
783 if (ACPI_IS_XDIGIT((char)this_digit)) { 857 if (ACPI_IS_XDIGIT((char)this_digit)) {
784 858
785 /* Convert ASCII Hex char to value */ 859 /* Convert ASCII Hex char to value */
@@ -806,8 +880,9 @@ acpi_status acpi_ut_strtoul64(char *string, u32 base, u64 * ret_integer)
806 880
807 valid_digits++; 881 valid_digits++;
808 882
809 if (sign_of0x && ((valid_digits > 16) 883 if (sign_of0x
810 || ((valid_digits > 8) && mode32))) { 884 && ((valid_digits > 16)
885 || ((valid_digits > 8) && mode32))) {
811 /* 886 /*
812 * This is to_integer operation case. 887 * This is to_integer operation case.
813 * No any restrictions for string-to-integer conversion, 888 * No any restrictions for string-to-integer conversion,
@@ -818,7 +893,7 @@ acpi_status acpi_ut_strtoul64(char *string, u32 base, u64 * ret_integer)
818 893
819 /* Divide the digit into the correct position */ 894 /* Divide the digit into the correct position */
820 895
821 (void)acpi_ut_short_divide((dividend - (u64) this_digit), 896 (void)acpi_ut_short_divide((dividend - (u64)this_digit),
822 base, &quotient, NULL); 897 base, &quotient, NULL);
823 898
824 if (return_value > quotient) { 899 if (return_value > quotient) {
@@ -908,7 +983,7 @@ acpi_ut_create_update_state_and_push(union acpi_operand_object *object,
908 ******************************************************************************/ 983 ******************************************************************************/
909 984
910acpi_status 985acpi_status
911acpi_ut_walk_package_tree(union acpi_operand_object * source_object, 986acpi_ut_walk_package_tree(union acpi_operand_object *source_object,
912 void *target_object, 987 void *target_object,
913 acpi_pkg_callback walk_callback, void *context) 988 acpi_pkg_callback walk_callback, void *context)
914{ 989{
diff --git a/drivers/acpi/acpica/uttrack.c b/drivers/acpi/acpica/uttrack.c
new file mode 100644
index 000000000000..73ca27d40f9f
--- /dev/null
+++ b/drivers/acpi/acpica/uttrack.c
@@ -0,0 +1,650 @@
1/******************************************************************************
2 *
3 * Module Name: uttrack - Memory allocation tracking routines (debug only)
4 *
5 *****************************************************************************/
6
7/*
8 * Copyright (C) 2000 - 2012, 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/*
45 * These procedures are used for tracking memory leaks in the subsystem, and
46 * they get compiled out when the ACPI_DBG_TRACK_ALLOCATIONS is not set.
47 *
48 * Each memory allocation is tracked via a doubly linked list. Each
49 * element contains the caller's component, module name, function name, and
50 * line number. acpi_ut_allocate and acpi_ut_allocate_zeroed call
51 * acpi_ut_track_allocation to add an element to the list; deletion
52 * occurs in the body of acpi_ut_free.
53 */
54
55#include <acpi/acpi.h>
56#include "accommon.h"
57
58#ifdef ACPI_DBG_TRACK_ALLOCATIONS
59
60#define _COMPONENT ACPI_UTILITIES
61ACPI_MODULE_NAME("uttrack")
62
63/* Local prototypes */
64static struct acpi_debug_mem_block *acpi_ut_find_allocation(void *allocation);
65
66static acpi_status
67acpi_ut_track_allocation(struct acpi_debug_mem_block *address,
68 acpi_size size,
69 u8 alloc_type,
70 u32 component, const char *module, u32 line);
71
72static acpi_status
73acpi_ut_remove_allocation(struct acpi_debug_mem_block *address,
74 u32 component, const char *module, u32 line);
75
76/*******************************************************************************
77 *
78 * FUNCTION: acpi_ut_create_list
79 *
80 * PARAMETERS: cache_name - Ascii name for the cache
81 * object_size - Size of each cached object
82 * return_cache - Where the new cache object is returned
83 *
84 * RETURN: Status
85 *
86 * DESCRIPTION: Create a local memory list for tracking purposed
87 *
88 ******************************************************************************/
89
90acpi_status
91acpi_ut_create_list(char *list_name,
92 u16 object_size, struct acpi_memory_list **return_cache)
93{
94 struct acpi_memory_list *cache;
95
96 cache = acpi_os_allocate(sizeof(struct acpi_memory_list));
97 if (!cache) {
98 return (AE_NO_MEMORY);
99 }
100
101 ACPI_MEMSET(cache, 0, sizeof(struct acpi_memory_list));
102
103 cache->list_name = list_name;
104 cache->object_size = object_size;
105
106 *return_cache = cache;
107 return (AE_OK);
108}
109
110/*******************************************************************************
111 *
112 * FUNCTION: acpi_ut_allocate_and_track
113 *
114 * PARAMETERS: size - Size of the allocation
115 * component - Component type of caller
116 * module - Source file name of caller
117 * line - Line number of caller
118 *
119 * RETURN: Address of the allocated memory on success, NULL on failure.
120 *
121 * DESCRIPTION: The subsystem's equivalent of malloc.
122 *
123 ******************************************************************************/
124
125void *acpi_ut_allocate_and_track(acpi_size size,
126 u32 component, const char *module, u32 line)
127{
128 struct acpi_debug_mem_block *allocation;
129 acpi_status status;
130
131 allocation =
132 acpi_ut_allocate(size + sizeof(struct acpi_debug_mem_header),
133 component, module, line);
134 if (!allocation) {
135 return (NULL);
136 }
137
138 status = acpi_ut_track_allocation(allocation, size,
139 ACPI_MEM_MALLOC, component, module,
140 line);
141 if (ACPI_FAILURE(status)) {
142 acpi_os_free(allocation);
143 return (NULL);
144 }
145
146 acpi_gbl_global_list->total_allocated++;
147 acpi_gbl_global_list->total_size += (u32)size;
148 acpi_gbl_global_list->current_total_size += (u32)size;
149 if (acpi_gbl_global_list->current_total_size >
150 acpi_gbl_global_list->max_occupied) {
151 acpi_gbl_global_list->max_occupied =
152 acpi_gbl_global_list->current_total_size;
153 }
154
155 return ((void *)&allocation->user_space);
156}
157
158/*******************************************************************************
159 *
160 * FUNCTION: acpi_ut_allocate_zeroed_and_track
161 *
162 * PARAMETERS: size - Size of the allocation
163 * component - Component type of caller
164 * module - Source file name of caller
165 * line - Line number of caller
166 *
167 * RETURN: Address of the allocated memory on success, NULL on failure.
168 *
169 * DESCRIPTION: Subsystem equivalent of calloc.
170 *
171 ******************************************************************************/
172
173void *acpi_ut_allocate_zeroed_and_track(acpi_size size,
174 u32 component,
175 const char *module, u32 line)
176{
177 struct acpi_debug_mem_block *allocation;
178 acpi_status status;
179
180 allocation =
181 acpi_ut_allocate_zeroed(size + sizeof(struct acpi_debug_mem_header),
182 component, module, line);
183 if (!allocation) {
184
185 /* Report allocation error */
186
187 ACPI_ERROR((module, line,
188 "Could not allocate size %u", (u32)size));
189 return (NULL);
190 }
191
192 status = acpi_ut_track_allocation(allocation, size,
193 ACPI_MEM_CALLOC, component, module,
194 line);
195 if (ACPI_FAILURE(status)) {
196 acpi_os_free(allocation);
197 return (NULL);
198 }
199
200 acpi_gbl_global_list->total_allocated++;
201 acpi_gbl_global_list->total_size += (u32)size;
202 acpi_gbl_global_list->current_total_size += (u32)size;
203 if (acpi_gbl_global_list->current_total_size >
204 acpi_gbl_global_list->max_occupied) {
205 acpi_gbl_global_list->max_occupied =
206 acpi_gbl_global_list->current_total_size;
207 }
208
209 return ((void *)&allocation->user_space);
210}
211
212/*******************************************************************************
213 *
214 * FUNCTION: acpi_ut_free_and_track
215 *
216 * PARAMETERS: allocation - Address of the memory to deallocate
217 * component - Component type of caller
218 * module - Source file name of caller
219 * line - Line number of caller
220 *
221 * RETURN: None
222 *
223 * DESCRIPTION: Frees the memory at Allocation
224 *
225 ******************************************************************************/
226
227void
228acpi_ut_free_and_track(void *allocation,
229 u32 component, const char *module, u32 line)
230{
231 struct acpi_debug_mem_block *debug_block;
232 acpi_status status;
233
234 ACPI_FUNCTION_TRACE_PTR(ut_free, allocation);
235
236 if (NULL == allocation) {
237 ACPI_ERROR((module, line, "Attempt to delete a NULL address"));
238
239 return_VOID;
240 }
241
242 debug_block = ACPI_CAST_PTR(struct acpi_debug_mem_block,
243 (((char *)allocation) -
244 sizeof(struct acpi_debug_mem_header)));
245
246 acpi_gbl_global_list->total_freed++;
247 acpi_gbl_global_list->current_total_size -= debug_block->size;
248
249 status = acpi_ut_remove_allocation(debug_block,
250 component, module, line);
251 if (ACPI_FAILURE(status)) {
252 ACPI_EXCEPTION((AE_INFO, status, "Could not free memory"));
253 }
254
255 acpi_os_free(debug_block);
256 ACPI_DEBUG_PRINT((ACPI_DB_ALLOCATIONS, "%p freed\n", allocation));
257 return_VOID;
258}
259
260/*******************************************************************************
261 *
262 * FUNCTION: acpi_ut_find_allocation
263 *
264 * PARAMETERS: allocation - Address of allocated memory
265 *
266 * RETURN: A list element if found; NULL otherwise.
267 *
268 * DESCRIPTION: Searches for an element in the global allocation tracking list.
269 *
270 ******************************************************************************/
271
272static struct acpi_debug_mem_block *acpi_ut_find_allocation(void *allocation)
273{
274 struct acpi_debug_mem_block *element;
275
276 ACPI_FUNCTION_ENTRY();
277
278 element = acpi_gbl_global_list->list_head;
279
280 /* Search for the address. */
281
282 while (element) {
283 if (element == allocation) {
284 return (element);
285 }
286
287 element = element->next;
288 }
289
290 return (NULL);
291}
292
293/*******************************************************************************
294 *
295 * FUNCTION: acpi_ut_track_allocation
296 *
297 * PARAMETERS: allocation - Address of allocated memory
298 * size - Size of the allocation
299 * alloc_type - MEM_MALLOC or MEM_CALLOC
300 * component - Component type of caller
301 * module - Source file name of caller
302 * line - Line number of caller
303 *
304 * RETURN: None.
305 *
306 * DESCRIPTION: Inserts an element into the global allocation tracking list.
307 *
308 ******************************************************************************/
309
310static acpi_status
311acpi_ut_track_allocation(struct acpi_debug_mem_block *allocation,
312 acpi_size size,
313 u8 alloc_type,
314 u32 component, const char *module, u32 line)
315{
316 struct acpi_memory_list *mem_list;
317 struct acpi_debug_mem_block *element;
318 acpi_status status = AE_OK;
319
320 ACPI_FUNCTION_TRACE_PTR(ut_track_allocation, allocation);
321
322 if (acpi_gbl_disable_mem_tracking) {
323 return_ACPI_STATUS(AE_OK);
324 }
325
326 mem_list = acpi_gbl_global_list;
327 status = acpi_ut_acquire_mutex(ACPI_MTX_MEMORY);
328 if (ACPI_FAILURE(status)) {
329 return_ACPI_STATUS(status);
330 }
331
332 /*
333 * Search list for this address to make sure it is not already on the list.
334 * This will catch several kinds of problems.
335 */
336 element = acpi_ut_find_allocation(allocation);
337 if (element) {
338 ACPI_ERROR((AE_INFO,
339 "UtTrackAllocation: Allocation already present in list! (%p)",
340 allocation));
341
342 ACPI_ERROR((AE_INFO, "Element %p Address %p",
343 element, allocation));
344
345 goto unlock_and_exit;
346 }
347
348 /* Fill in the instance data. */
349
350 allocation->size = (u32)size;
351 allocation->alloc_type = alloc_type;
352 allocation->component = component;
353 allocation->line = line;
354
355 ACPI_STRNCPY(allocation->module, module, ACPI_MAX_MODULE_NAME);
356 allocation->module[ACPI_MAX_MODULE_NAME - 1] = 0;
357
358 /* Insert at list head */
359
360 if (mem_list->list_head) {
361 ((struct acpi_debug_mem_block *)(mem_list->list_head))->
362 previous = allocation;
363 }
364
365 allocation->next = mem_list->list_head;
366 allocation->previous = NULL;
367
368 mem_list->list_head = allocation;
369
370 unlock_and_exit:
371 status = acpi_ut_release_mutex(ACPI_MTX_MEMORY);
372 return_ACPI_STATUS(status);
373}
374
375/*******************************************************************************
376 *
377 * FUNCTION: acpi_ut_remove_allocation
378 *
379 * PARAMETERS: allocation - Address of allocated memory
380 * component - Component type of caller
381 * module - Source file name of caller
382 * line - Line number of caller
383 *
384 * RETURN:
385 *
386 * DESCRIPTION: Deletes an element from the global allocation tracking list.
387 *
388 ******************************************************************************/
389
390static acpi_status
391acpi_ut_remove_allocation(struct acpi_debug_mem_block *allocation,
392 u32 component, const char *module, u32 line)
393{
394 struct acpi_memory_list *mem_list;
395 acpi_status status;
396
397 ACPI_FUNCTION_TRACE(ut_remove_allocation);
398
399 if (acpi_gbl_disable_mem_tracking) {
400 return_ACPI_STATUS(AE_OK);
401 }
402
403 mem_list = acpi_gbl_global_list;
404 if (NULL == mem_list->list_head) {
405
406 /* No allocations! */
407
408 ACPI_ERROR((module, line,
409 "Empty allocation list, nothing to free!"));
410
411 return_ACPI_STATUS(AE_OK);
412 }
413
414 status = acpi_ut_acquire_mutex(ACPI_MTX_MEMORY);
415 if (ACPI_FAILURE(status)) {
416 return_ACPI_STATUS(status);
417 }
418
419 /* Unlink */
420
421 if (allocation->previous) {
422 (allocation->previous)->next = allocation->next;
423 } else {
424 mem_list->list_head = allocation->next;
425 }
426
427 if (allocation->next) {
428 (allocation->next)->previous = allocation->previous;
429 }
430
431 /* Mark the segment as deleted */
432
433 ACPI_MEMSET(&allocation->user_space, 0xEA, allocation->size);
434
435 ACPI_DEBUG_PRINT((ACPI_DB_ALLOCATIONS, "Freeing size 0%X\n",
436 allocation->size));
437
438 status = acpi_ut_release_mutex(ACPI_MTX_MEMORY);
439 return_ACPI_STATUS(status);
440}
441
442/*******************************************************************************
443 *
444 * FUNCTION: acpi_ut_dump_allocation_info
445 *
446 * PARAMETERS:
447 *
448 * RETURN: None
449 *
450 * DESCRIPTION: Print some info about the outstanding allocations.
451 *
452 ******************************************************************************/
453
454void acpi_ut_dump_allocation_info(void)
455{
456/*
457 struct acpi_memory_list *mem_list;
458*/
459
460 ACPI_FUNCTION_TRACE(ut_dump_allocation_info);
461
462/*
463 ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES,
464 ("%30s: %4d (%3d Kb)\n", "Current allocations",
465 mem_list->current_count,
466 ROUND_UP_TO_1K (mem_list->current_size)));
467
468 ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES,
469 ("%30s: %4d (%3d Kb)\n", "Max concurrent allocations",
470 mem_list->max_concurrent_count,
471 ROUND_UP_TO_1K (mem_list->max_concurrent_size)));
472
473 ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES,
474 ("%30s: %4d (%3d Kb)\n", "Total (all) internal objects",
475 running_object_count,
476 ROUND_UP_TO_1K (running_object_size)));
477
478 ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES,
479 ("%30s: %4d (%3d Kb)\n", "Total (all) allocations",
480 running_alloc_count,
481 ROUND_UP_TO_1K (running_alloc_size)));
482
483 ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES,
484 ("%30s: %4d (%3d Kb)\n", "Current Nodes",
485 acpi_gbl_current_node_count,
486 ROUND_UP_TO_1K (acpi_gbl_current_node_size)));
487
488 ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES,
489 ("%30s: %4d (%3d Kb)\n", "Max Nodes",
490 acpi_gbl_max_concurrent_node_count,
491 ROUND_UP_TO_1K ((acpi_gbl_max_concurrent_node_count *
492 sizeof (struct acpi_namespace_node)))));
493*/
494 return_VOID;
495}
496
497/*******************************************************************************
498 *
499 * FUNCTION: acpi_ut_dump_allocations
500 *
501 * PARAMETERS: component - Component(s) to dump info for.
502 * module - Module to dump info for. NULL means all.
503 *
504 * RETURN: None
505 *
506 * DESCRIPTION: Print a list of all outstanding allocations.
507 *
508 ******************************************************************************/
509
510void acpi_ut_dump_allocations(u32 component, const char *module)
511{
512 struct acpi_debug_mem_block *element;
513 union acpi_descriptor *descriptor;
514 u32 num_outstanding = 0;
515 u8 descriptor_type;
516
517 ACPI_FUNCTION_TRACE(ut_dump_allocations);
518
519 if (acpi_gbl_disable_mem_tracking) {
520 return;
521 }
522
523 /*
524 * Walk the allocation list.
525 */
526 if (ACPI_FAILURE(acpi_ut_acquire_mutex(ACPI_MTX_MEMORY))) {
527 return;
528 }
529
530 element = acpi_gbl_global_list->list_head;
531 while (element) {
532 if ((element->component & component) &&
533 ((module == NULL)
534 || (0 == ACPI_STRCMP(module, element->module)))) {
535 descriptor =
536 ACPI_CAST_PTR(union acpi_descriptor,
537 &element->user_space);
538
539 if (element->size <
540 sizeof(struct acpi_common_descriptor)) {
541 acpi_os_printf("%p Length 0x%04X %9.9s-%u "
542 "[Not a Descriptor - too small]\n",
543 descriptor, element->size,
544 element->module, element->line);
545 } else {
546 /* Ignore allocated objects that are in a cache */
547
548 if (ACPI_GET_DESCRIPTOR_TYPE(descriptor) !=
549 ACPI_DESC_TYPE_CACHED) {
550 acpi_os_printf
551 ("%p Length 0x%04X %9.9s-%u [%s] ",
552 descriptor, element->size,
553 element->module, element->line,
554 acpi_ut_get_descriptor_name
555 (descriptor));
556
557 /* Validate the descriptor type using Type field and length */
558
559 descriptor_type = 0; /* Not a valid descriptor type */
560
561 switch (ACPI_GET_DESCRIPTOR_TYPE
562 (descriptor)) {
563 case ACPI_DESC_TYPE_OPERAND:
564 if (element->size ==
565 sizeof(union
566 acpi_operand_object))
567 {
568 descriptor_type =
569 ACPI_DESC_TYPE_OPERAND;
570 }
571 break;
572
573 case ACPI_DESC_TYPE_PARSER:
574 if (element->size ==
575 sizeof(union
576 acpi_parse_object)) {
577 descriptor_type =
578 ACPI_DESC_TYPE_PARSER;
579 }
580 break;
581
582 case ACPI_DESC_TYPE_NAMED:
583 if (element->size ==
584 sizeof(struct
585 acpi_namespace_node))
586 {
587 descriptor_type =
588 ACPI_DESC_TYPE_NAMED;
589 }
590 break;
591
592 default:
593 break;
594 }
595
596 /* Display additional info for the major descriptor types */
597
598 switch (descriptor_type) {
599 case ACPI_DESC_TYPE_OPERAND:
600 acpi_os_printf
601 ("%12.12s RefCount 0x%04X\n",
602 acpi_ut_get_type_name
603 (descriptor->object.common.
604 type),
605 descriptor->object.common.
606 reference_count);
607 break;
608
609 case ACPI_DESC_TYPE_PARSER:
610 acpi_os_printf
611 ("AmlOpcode 0x%04hX\n",
612 descriptor->op.asl.
613 aml_opcode);
614 break;
615
616 case ACPI_DESC_TYPE_NAMED:
617 acpi_os_printf("%4.4s\n",
618 acpi_ut_get_node_name
619 (&descriptor->
620 node));
621 break;
622
623 default:
624 acpi_os_printf("\n");
625 break;
626 }
627 }
628 }
629
630 num_outstanding++;
631 }
632
633 element = element->next;
634 }
635
636 (void)acpi_ut_release_mutex(ACPI_MTX_MEMORY);
637
638 /* Print summary */
639
640 if (!num_outstanding) {
641 ACPI_INFO((AE_INFO, "No outstanding allocations"));
642 } else {
643 ACPI_ERROR((AE_INFO, "%u(0x%X) Outstanding allocations",
644 num_outstanding, num_outstanding));
645 }
646
647 return_VOID;
648}
649
650#endif /* ACPI_DBG_TRACK_ALLOCATIONS */