aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/acpi/utilities/utalloc.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/acpi/utilities/utalloc.c')
-rw-r--r--drivers/acpi/utilities/utalloc.c713
1 files changed, 285 insertions, 428 deletions
diff --git a/drivers/acpi/utilities/utalloc.c b/drivers/acpi/utilities/utalloc.c
index c4e7f989a2bd..068450b36475 100644
--- a/drivers/acpi/utilities/utalloc.c
+++ b/drivers/acpi/utilities/utalloc.c
@@ -1,6 +1,6 @@
1/****************************************************************************** 1/******************************************************************************
2 * 2 *
3 * Module Name: utalloc - local cache and memory allocation routines 3 * Module Name: utalloc - local memory allocation routines
4 * 4 *
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
@@ -41,232 +41,134 @@
41 * POSSIBILITY OF SUCH DAMAGES. 41 * POSSIBILITY OF SUCH DAMAGES.
42 */ 42 */
43 43
44
45#include <acpi/acpi.h> 44#include <acpi/acpi.h>
46 45
47#define _COMPONENT ACPI_UTILITIES 46#define _COMPONENT ACPI_UTILITIES
48 ACPI_MODULE_NAME ("utalloc") 47ACPI_MODULE_NAME("utalloc")
49 48
50/* Local prototypes */ 49/* Local prototypes */
51
52#ifdef ACPI_DBG_TRACK_ALLOCATIONS 50#ifdef ACPI_DBG_TRACK_ALLOCATIONS
53static struct acpi_debug_mem_block * 51static struct acpi_debug_mem_block *acpi_ut_find_allocation(void *allocation);
54acpi_ut_find_allocation (
55 u32 list_id,
56 void *allocation);
57 52
58static acpi_status 53static acpi_status
59acpi_ut_track_allocation ( 54acpi_ut_track_allocation(struct acpi_debug_mem_block *address,
60 u32 list_id, 55 acpi_size size,
61 struct acpi_debug_mem_block *address, 56 u8 alloc_type, u32 component, char *module, u32 line);
62 acpi_size size,
63 u8 alloc_type,
64 u32 component,
65 char *module,
66 u32 line);
67 57
68static acpi_status 58static acpi_status
69acpi_ut_remove_allocation ( 59acpi_ut_remove_allocation(struct acpi_debug_mem_block *address,
70 u32 list_id, 60 u32 component, char *module, u32 line);
71 struct acpi_debug_mem_block *address, 61#endif /* ACPI_DBG_TRACK_ALLOCATIONS */
72 u32 component,
73 char *module,
74 u32 line);
75#endif /* ACPI_DBG_TRACK_ALLOCATIONS */
76 62
63#ifdef ACPI_DBG_TRACK_ALLOCATIONS
64static acpi_status
65acpi_ut_create_list(char *list_name,
66 u16 object_size, struct acpi_memory_list **return_cache);
67#endif
77 68
78/******************************************************************************* 69/*******************************************************************************
79 * 70 *
80 * FUNCTION: acpi_ut_release_to_cache 71 * FUNCTION: acpi_ut_create_caches
81 * 72 *
82 * PARAMETERS: list_id - Memory list/cache ID 73 * PARAMETERS: None
83 * Object - The object to be released
84 * 74 *
85 * RETURN: None 75 * RETURN: Status
86 * 76 *
87 * DESCRIPTION: Release an object to the specified cache. If cache is full, 77 * DESCRIPTION: Create all local caches
88 * the object is deleted.
89 * 78 *
90 ******************************************************************************/ 79 ******************************************************************************/
91 80
92void 81acpi_status acpi_ut_create_caches(void)
93acpi_ut_release_to_cache (
94 u32 list_id,
95 void *object)
96{ 82{
97 struct acpi_memory_list *cache_info; 83 acpi_status status;
98
99 84
100 ACPI_FUNCTION_ENTRY (); 85#ifdef ACPI_DBG_TRACK_ALLOCATIONS
101
102
103 cache_info = &acpi_gbl_memory_lists[list_id];
104
105#ifdef ACPI_ENABLE_OBJECT_CACHE
106 86
107 /* If walk cache is full, just free this wallkstate object */ 87 /* Memory allocation lists */
108 88
109 if (cache_info->cache_depth >= cache_info->max_cache_depth) { 89 status = acpi_ut_create_list("Acpi-Global", 0, &acpi_gbl_global_list);
110 ACPI_MEM_FREE (object); 90 if (ACPI_FAILURE(status)) {
111 ACPI_MEM_TRACKING (cache_info->total_freed++); 91 return (status);
112 } 92 }
113 93
114 /* Otherwise put this object back into the cache */ 94 status =
115 95 acpi_ut_create_list("Acpi-Namespace",
116 else { 96 sizeof(struct acpi_namespace_node),
117 if (ACPI_FAILURE (acpi_ut_acquire_mutex (ACPI_MTX_CACHES))) { 97 &acpi_gbl_ns_node_list);
118 return; 98 if (ACPI_FAILURE(status)) {
119 } 99 return (status);
120
121 /* Mark the object as cached */
122
123 ACPI_MEMSET (object, 0xCA, cache_info->object_size);
124 ACPI_SET_DESCRIPTOR_TYPE (object, ACPI_DESC_TYPE_CACHED);
125
126 /* Put the object at the head of the cache list */
127
128 * (ACPI_CAST_INDIRECT_PTR (char,
129 &(((char *) object)[cache_info->link_offset]))) = cache_info->list_head;
130 cache_info->list_head = object;
131 cache_info->cache_depth++;
132
133 (void) acpi_ut_release_mutex (ACPI_MTX_CACHES);
134 } 100 }
135
136#else
137
138 /* Object cache is disabled; just free the object */
139
140 ACPI_MEM_FREE (object);
141 ACPI_MEM_TRACKING (cache_info->total_freed++);
142#endif 101#endif
143}
144
145
146/*******************************************************************************
147 *
148 * FUNCTION: acpi_ut_acquire_from_cache
149 *
150 * PARAMETERS: list_id - Memory list ID
151 *
152 * RETURN: A requested object. NULL if the object could not be
153 * allocated.
154 *
155 * DESCRIPTION: Get an object from the specified cache. If cache is empty,
156 * the object is allocated.
157 *
158 ******************************************************************************/
159
160void *
161acpi_ut_acquire_from_cache (
162 u32 list_id)
163{
164 struct acpi_memory_list *cache_info;
165 void *object;
166 102
103 /* Object Caches, for frequently used objects */
167 104
168 ACPI_FUNCTION_NAME ("ut_acquire_from_cache"); 105 status =
169 106 acpi_os_create_cache("acpi_state", sizeof(union acpi_generic_state),
170 107 ACPI_MAX_STATE_CACHE_DEPTH,
171 cache_info = &acpi_gbl_memory_lists[list_id]; 108 &acpi_gbl_state_cache);
172 109 if (ACPI_FAILURE(status)) {
173#ifdef ACPI_ENABLE_OBJECT_CACHE 110 return (status);
174
175 if (ACPI_FAILURE (acpi_ut_acquire_mutex (ACPI_MTX_CACHES))) {
176 return (NULL);
177 } 111 }
178 112
179 ACPI_MEM_TRACKING (cache_info->cache_requests++); 113 status =
180 114 acpi_os_create_cache("acpi_parse",
181 /* Check the cache first */ 115 sizeof(struct acpi_parse_obj_common),
182 116 ACPI_MAX_PARSE_CACHE_DEPTH,
183 if (cache_info->list_head) { 117 &acpi_gbl_ps_node_cache);
184 /* There is an object available, use it */ 118 if (ACPI_FAILURE(status)) {
185 119 return (status);
186 object = cache_info->list_head;
187 cache_info->list_head = *(ACPI_CAST_INDIRECT_PTR (char,
188 &(((char *) object)[cache_info->link_offset])));
189
190 ACPI_MEM_TRACKING (cache_info->cache_hits++);
191 cache_info->cache_depth--;
192
193#ifdef ACPI_DBG_TRACK_ALLOCATIONS
194 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Object %p from %s\n",
195 object, acpi_gbl_memory_lists[list_id].list_name));
196#endif
197
198 if (ACPI_FAILURE (acpi_ut_release_mutex (ACPI_MTX_CACHES))) {
199 return (NULL);
200 }
201
202 /* Clear (zero) the previously used Object */
203
204 ACPI_MEMSET (object, 0, cache_info->object_size);
205 } 120 }
206 121
207 else { 122 status =
208 /* The cache is empty, create a new object */ 123 acpi_os_create_cache("acpi_parse_ext",
209 124 sizeof(struct acpi_parse_obj_named),
210 /* Avoid deadlock with ACPI_MEM_CALLOCATE */ 125 ACPI_MAX_EXTPARSE_CACHE_DEPTH,
211 126 &acpi_gbl_ps_node_ext_cache);
212 if (ACPI_FAILURE (acpi_ut_release_mutex (ACPI_MTX_CACHES))) { 127 if (ACPI_FAILURE(status)) {
213 return (NULL); 128 return (status);
214 }
215
216 object = ACPI_MEM_CALLOCATE (cache_info->object_size);
217 ACPI_MEM_TRACKING (cache_info->total_allocated++);
218 } 129 }
219 130
220#else 131 status =
221 132 acpi_os_create_cache("acpi_operand",
222 /* Object cache is disabled; just allocate the object */ 133 sizeof(union acpi_operand_object),
223 134 ACPI_MAX_OBJECT_CACHE_DEPTH,
224 object = ACPI_MEM_CALLOCATE (cache_info->object_size); 135 &acpi_gbl_operand_cache);
225 ACPI_MEM_TRACKING (cache_info->total_allocated++); 136 if (ACPI_FAILURE(status)) {
226#endif 137 return (status);
138 }
227 139
228 return (object); 140 return (AE_OK);
229} 141}
230 142
231
232#ifdef ACPI_ENABLE_OBJECT_CACHE
233/******************************************************************************* 143/*******************************************************************************
234 * 144 *
235 * FUNCTION: acpi_ut_delete_generic_cache 145 * FUNCTION: acpi_ut_delete_caches
236 * 146 *
237 * PARAMETERS: list_id - Memory list ID 147 * PARAMETERS: None
238 * 148 *
239 * RETURN: None 149 * RETURN: Status
240 * 150 *
241 * DESCRIPTION: Free all objects within the requested cache. 151 * DESCRIPTION: Purge and delete all local caches
242 * 152 *
243 ******************************************************************************/ 153 ******************************************************************************/
244 154
245void 155acpi_status acpi_ut_delete_caches(void)
246acpi_ut_delete_generic_cache (
247 u32 list_id)
248{ 156{
249 struct acpi_memory_list *cache_info;
250 char *next;
251
252 157
253 ACPI_FUNCTION_ENTRY (); 158 (void)acpi_os_delete_cache(acpi_gbl_state_cache);
159 acpi_gbl_state_cache = NULL;
254 160
161 (void)acpi_os_delete_cache(acpi_gbl_operand_cache);
162 acpi_gbl_operand_cache = NULL;
255 163
256 cache_info = &acpi_gbl_memory_lists[list_id]; 164 (void)acpi_os_delete_cache(acpi_gbl_ps_node_cache);
257 while (cache_info->list_head) { 165 acpi_gbl_ps_node_cache = NULL;
258 /* Delete one cached state object */
259 166
260 next = *(ACPI_CAST_INDIRECT_PTR (char, 167 (void)acpi_os_delete_cache(acpi_gbl_ps_node_ext_cache);
261 &(((char *) cache_info->list_head)[cache_info->link_offset]))); 168 acpi_gbl_ps_node_ext_cache = NULL;
262 ACPI_MEM_FREE (cache_info->list_head);
263 169
264 cache_info->list_head = next; 170 return (AE_OK);
265 cache_info->cache_depth--;
266 }
267} 171}
268#endif
269
270 172
271/******************************************************************************* 173/*******************************************************************************
272 * 174 *
@@ -280,9 +182,7 @@ acpi_ut_delete_generic_cache (
280 * 182 *
281 ******************************************************************************/ 183 ******************************************************************************/
282 184
283acpi_status 185acpi_status acpi_ut_validate_buffer(struct acpi_buffer * buffer)
284acpi_ut_validate_buffer (
285 struct acpi_buffer *buffer)
286{ 186{
287 187
288 /* Obviously, the structure pointer must be valid */ 188 /* Obviously, the structure pointer must be valid */
@@ -293,9 +193,9 @@ acpi_ut_validate_buffer (
293 193
294 /* Special semantics for the length */ 194 /* Special semantics for the length */
295 195
296 if ((buffer->length == ACPI_NO_BUFFER) || 196 if ((buffer->length == ACPI_NO_BUFFER) ||
297 (buffer->length == ACPI_ALLOCATE_BUFFER) || 197 (buffer->length == ACPI_ALLOCATE_BUFFER) ||
298 (buffer->length == ACPI_ALLOCATE_LOCAL_BUFFER)) { 198 (buffer->length == ACPI_ALLOCATE_LOCAL_BUFFER)) {
299 return (AE_OK); 199 return (AE_OK);
300 } 200 }
301 201
@@ -308,7 +208,6 @@ acpi_ut_validate_buffer (
308 return (AE_OK); 208 return (AE_OK);
309} 209}
310 210
311
312/******************************************************************************* 211/*******************************************************************************
313 * 212 *
314 * FUNCTION: acpi_ut_initialize_buffer 213 * FUNCTION: acpi_ut_initialize_buffer
@@ -324,12 +223,10 @@ acpi_ut_validate_buffer (
324 ******************************************************************************/ 223 ******************************************************************************/
325 224
326acpi_status 225acpi_status
327acpi_ut_initialize_buffer ( 226acpi_ut_initialize_buffer(struct acpi_buffer * buffer,
328 struct acpi_buffer *buffer, 227 acpi_size required_length)
329 acpi_size required_length)
330{ 228{
331 acpi_status status = AE_OK; 229 acpi_status status = AE_OK;
332
333 230
334 switch (buffer->length) { 231 switch (buffer->length) {
335 case ACPI_NO_BUFFER: 232 case ACPI_NO_BUFFER:
@@ -339,33 +236,30 @@ acpi_ut_initialize_buffer (
339 status = AE_BUFFER_OVERFLOW; 236 status = AE_BUFFER_OVERFLOW;
340 break; 237 break;
341 238
342
343 case ACPI_ALLOCATE_BUFFER: 239 case ACPI_ALLOCATE_BUFFER:
344 240
345 /* Allocate a new buffer */ 241 /* Allocate a new buffer */
346 242
347 buffer->pointer = acpi_os_allocate (required_length); 243 buffer->pointer = acpi_os_allocate(required_length);
348 if (!buffer->pointer) { 244 if (!buffer->pointer) {
349 return (AE_NO_MEMORY); 245 return (AE_NO_MEMORY);
350 } 246 }
351 247
352 /* Clear the buffer */ 248 /* Clear the buffer */
353 249
354 ACPI_MEMSET (buffer->pointer, 0, required_length); 250 ACPI_MEMSET(buffer->pointer, 0, required_length);
355 break; 251 break;
356 252
357
358 case ACPI_ALLOCATE_LOCAL_BUFFER: 253 case ACPI_ALLOCATE_LOCAL_BUFFER:
359 254
360 /* Allocate a new buffer with local interface to allow tracking */ 255 /* Allocate a new buffer with local interface to allow tracking */
361 256
362 buffer->pointer = ACPI_MEM_CALLOCATE (required_length); 257 buffer->pointer = ACPI_MEM_CALLOCATE(required_length);
363 if (!buffer->pointer) { 258 if (!buffer->pointer) {
364 return (AE_NO_MEMORY); 259 return (AE_NO_MEMORY);
365 } 260 }
366 break; 261 break;
367 262
368
369 default: 263 default:
370 264
371 /* Existing buffer: Validate the size of the buffer */ 265 /* Existing buffer: Validate the size of the buffer */
@@ -377,7 +271,7 @@ acpi_ut_initialize_buffer (
377 271
378 /* Clear the buffer */ 272 /* Clear the buffer */
379 273
380 ACPI_MEMSET (buffer->pointer, 0, required_length); 274 ACPI_MEMSET(buffer->pointer, 0, required_length);
381 break; 275 break;
382 } 276 }
383 277
@@ -385,7 +279,6 @@ acpi_ut_initialize_buffer (
385 return (status); 279 return (status);
386} 280}
387 281
388
389/******************************************************************************* 282/*******************************************************************************
390 * 283 *
391 * FUNCTION: acpi_ut_allocate 284 * FUNCTION: acpi_ut_allocate
@@ -401,41 +294,34 @@ acpi_ut_initialize_buffer (
401 * 294 *
402 ******************************************************************************/ 295 ******************************************************************************/
403 296
404void * 297void *acpi_ut_allocate(acpi_size size, u32 component, char *module, u32 line)
405acpi_ut_allocate (
406 acpi_size size,
407 u32 component,
408 char *module,
409 u32 line)
410{ 298{
411 void *allocation; 299 void *allocation;
412
413
414 ACPI_FUNCTION_TRACE_U32 ("ut_allocate", size);
415 300
301 ACPI_FUNCTION_TRACE_U32("ut_allocate", size);
416 302
417 /* Check for an inadvertent size of zero bytes */ 303 /* Check for an inadvertent size of zero bytes */
418 304
419 if (!size) { 305 if (!size) {
420 _ACPI_REPORT_ERROR (module, line, component, 306 _ACPI_REPORT_ERROR(module, line, component,
421 ("ut_allocate: Attempt to allocate zero bytes\n")); 307 ("ut_allocate: Attempt to allocate zero bytes\n"));
422 size = 1; 308 size = 1;
423 } 309 }
424 310
425 allocation = acpi_os_allocate (size); 311 allocation = acpi_os_allocate(size);
426 if (!allocation) { 312 if (!allocation) {
427 /* Report allocation error */ 313 /* Report allocation error */
428 314
429 _ACPI_REPORT_ERROR (module, line, component, 315 _ACPI_REPORT_ERROR(module, line, component,
430 ("ut_allocate: Could not allocate size %X\n", (u32) size)); 316 ("ut_allocate: Could not allocate size %X\n",
317 (u32) size));
431 318
432 return_PTR (NULL); 319 return_PTR(NULL);
433 } 320 }
434 321
435 return_PTR (allocation); 322 return_PTR(allocation);
436} 323}
437 324
438
439/******************************************************************************* 325/*******************************************************************************
440 * 326 *
441 * FUNCTION: acpi_ut_callocate 327 * FUNCTION: acpi_ut_callocate
@@ -451,43 +337,36 @@ acpi_ut_allocate (
451 * 337 *
452 ******************************************************************************/ 338 ******************************************************************************/
453 339
454void * 340void *acpi_ut_callocate(acpi_size size, u32 component, char *module, u32 line)
455acpi_ut_callocate (
456 acpi_size size,
457 u32 component,
458 char *module,
459 u32 line)
460{ 341{
461 void *allocation; 342 void *allocation;
462
463
464 ACPI_FUNCTION_TRACE_U32 ("ut_callocate", size);
465 343
344 ACPI_FUNCTION_TRACE_U32("ut_callocate", size);
466 345
467 /* Check for an inadvertent size of zero bytes */ 346 /* Check for an inadvertent size of zero bytes */
468 347
469 if (!size) { 348 if (!size) {
470 _ACPI_REPORT_ERROR (module, line, component, 349 _ACPI_REPORT_ERROR(module, line, component,
471 ("ut_callocate: Attempt to allocate zero bytes\n")); 350 ("ut_callocate: Attempt to allocate zero bytes\n"));
472 return_PTR (NULL); 351 return_PTR(NULL);
473 } 352 }
474 353
475 allocation = acpi_os_allocate (size); 354 allocation = acpi_os_allocate(size);
476 if (!allocation) { 355 if (!allocation) {
477 /* Report allocation error */ 356 /* Report allocation error */
478 357
479 _ACPI_REPORT_ERROR (module, line, component, 358 _ACPI_REPORT_ERROR(module, line, component,
480 ("ut_callocate: Could not allocate size %X\n", (u32) size)); 359 ("ut_callocate: Could not allocate size %X\n",
481 return_PTR (NULL); 360 (u32) size));
361 return_PTR(NULL);
482 } 362 }
483 363
484 /* Clear the memory block */ 364 /* Clear the memory block */
485 365
486 ACPI_MEMSET (allocation, 0, size); 366 ACPI_MEMSET(allocation, 0, size);
487 return_PTR (allocation); 367 return_PTR(allocation);
488} 368}
489 369
490
491#ifdef ACPI_DBG_TRACK_ALLOCATIONS 370#ifdef ACPI_DBG_TRACK_ALLOCATIONS
492/* 371/*
493 * These procedures are used for tracking memory leaks in the subsystem, and 372 * These procedures are used for tracking memory leaks in the subsystem, and
@@ -500,6 +379,39 @@ acpi_ut_callocate (
500 * occurs in the body of acpi_ut_free. 379 * occurs in the body of acpi_ut_free.
501 */ 380 */
502 381
382/*******************************************************************************
383 *
384 * FUNCTION: acpi_ut_create_list
385 *
386 * PARAMETERS: cache_name - Ascii name for the cache
387 * object_size - Size of each cached object
388 * return_cache - Where the new cache object is returned
389 *
390 * RETURN: Status
391 *
392 * DESCRIPTION: Create a local memory list for tracking purposed
393 *
394 ******************************************************************************/
395
396static acpi_status
397acpi_ut_create_list(char *list_name,
398 u16 object_size, struct acpi_memory_list **return_cache)
399{
400 struct acpi_memory_list *cache;
401
402 cache = acpi_os_allocate(sizeof(struct acpi_memory_list));
403 if (!cache) {
404 return (AE_NO_MEMORY);
405 }
406
407 ACPI_MEMSET(cache, 0, sizeof(struct acpi_memory_list));
408
409 cache->list_name = list_name;
410 cache->object_size = object_size;
411
412 *return_cache = cache;
413 return (AE_OK);
414}
503 415
504/******************************************************************************* 416/*******************************************************************************
505 * 417 *
@@ -516,37 +428,33 @@ acpi_ut_callocate (
516 * 428 *
517 ******************************************************************************/ 429 ******************************************************************************/
518 430
519void * 431void *acpi_ut_allocate_and_track(acpi_size size,
520acpi_ut_allocate_and_track ( 432 u32 component, char *module, u32 line)
521 acpi_size size,
522 u32 component,
523 char *module,
524 u32 line)
525{ 433{
526 struct acpi_debug_mem_block *allocation; 434 struct acpi_debug_mem_block *allocation;
527 acpi_status status; 435 acpi_status status;
528
529 436
530 allocation = acpi_ut_allocate (size + sizeof (struct acpi_debug_mem_header), 437 allocation =
531 component, module, line); 438 acpi_ut_allocate(size + sizeof(struct acpi_debug_mem_header),
439 component, module, line);
532 if (!allocation) { 440 if (!allocation) {
533 return (NULL); 441 return (NULL);
534 } 442 }
535 443
536 status = acpi_ut_track_allocation (ACPI_MEM_LIST_GLOBAL, allocation, size, 444 status = acpi_ut_track_allocation(allocation, size,
537 ACPI_MEM_MALLOC, component, module, line); 445 ACPI_MEM_MALLOC, component, module,
538 if (ACPI_FAILURE (status)) { 446 line);
539 acpi_os_free (allocation); 447 if (ACPI_FAILURE(status)) {
448 acpi_os_free(allocation);
540 return (NULL); 449 return (NULL);
541 } 450 }
542 451
543 acpi_gbl_memory_lists[ACPI_MEM_LIST_GLOBAL].total_allocated++; 452 acpi_gbl_global_list->total_allocated++;
544 acpi_gbl_memory_lists[ACPI_MEM_LIST_GLOBAL].current_total_size += (u32) size; 453 acpi_gbl_global_list->current_total_size += (u32) size;
545 454
546 return ((void *) &allocation->user_space); 455 return ((void *)&allocation->user_space);
547} 456}
548 457
549
550/******************************************************************************* 458/*******************************************************************************
551 * 459 *
552 * FUNCTION: acpi_ut_callocate_and_track 460 * FUNCTION: acpi_ut_callocate_and_track
@@ -562,41 +470,38 @@ acpi_ut_allocate_and_track (
562 * 470 *
563 ******************************************************************************/ 471 ******************************************************************************/
564 472
565void * 473void *acpi_ut_callocate_and_track(acpi_size size,
566acpi_ut_callocate_and_track ( 474 u32 component, char *module, u32 line)
567 acpi_size size,
568 u32 component,
569 char *module,
570 u32 line)
571{ 475{
572 struct acpi_debug_mem_block *allocation; 476 struct acpi_debug_mem_block *allocation;
573 acpi_status status; 477 acpi_status status;
574
575 478
576 allocation = acpi_ut_callocate (size + sizeof (struct acpi_debug_mem_header), 479 allocation =
577 component, module, line); 480 acpi_ut_callocate(size + sizeof(struct acpi_debug_mem_header),
481 component, module, line);
578 if (!allocation) { 482 if (!allocation) {
579 /* Report allocation error */ 483 /* Report allocation error */
580 484
581 _ACPI_REPORT_ERROR (module, line, component, 485 _ACPI_REPORT_ERROR(module, line, component,
582 ("ut_callocate: Could not allocate size %X\n", (u32) size)); 486 ("ut_callocate: Could not allocate size %X\n",
487 (u32) size));
583 return (NULL); 488 return (NULL);
584 } 489 }
585 490
586 status = acpi_ut_track_allocation (ACPI_MEM_LIST_GLOBAL, allocation, size, 491 status = acpi_ut_track_allocation(allocation, size,
587 ACPI_MEM_CALLOC, component, module, line); 492 ACPI_MEM_CALLOC, component, module,
588 if (ACPI_FAILURE (status)) { 493 line);
589 acpi_os_free (allocation); 494 if (ACPI_FAILURE(status)) {
495 acpi_os_free(allocation);
590 return (NULL); 496 return (NULL);
591 } 497 }
592 498
593 acpi_gbl_memory_lists[ACPI_MEM_LIST_GLOBAL].total_allocated++; 499 acpi_gbl_global_list->total_allocated++;
594 acpi_gbl_memory_lists[ACPI_MEM_LIST_GLOBAL].current_total_size += (u32) size; 500 acpi_gbl_global_list->current_total_size += (u32) size;
595 501
596 return ((void *) &allocation->user_space); 502 return ((void *)&allocation->user_space);
597} 503}
598 504
599
600/******************************************************************************* 505/*******************************************************************************
601 * 506 *
602 * FUNCTION: acpi_ut_free_and_track 507 * FUNCTION: acpi_ut_free_and_track
@@ -613,53 +518,46 @@ acpi_ut_callocate_and_track (
613 ******************************************************************************/ 518 ******************************************************************************/
614 519
615void 520void
616acpi_ut_free_and_track ( 521acpi_ut_free_and_track(void *allocation, u32 component, char *module, u32 line)
617 void *allocation,
618 u32 component,
619 char *module,
620 u32 line)
621{ 522{
622 struct acpi_debug_mem_block *debug_block; 523 struct acpi_debug_mem_block *debug_block;
623 acpi_status status; 524 acpi_status status;
624
625
626 ACPI_FUNCTION_TRACE_PTR ("ut_free", allocation);
627 525
526 ACPI_FUNCTION_TRACE_PTR("ut_free", allocation);
628 527
629 if (NULL == allocation) { 528 if (NULL == allocation) {
630 _ACPI_REPORT_ERROR (module, line, component, 529 _ACPI_REPORT_ERROR(module, line, component,
631 ("acpi_ut_free: Attempt to delete a NULL address\n")); 530 ("acpi_ut_free: Attempt to delete a NULL address\n"));
632 531
633 return_VOID; 532 return_VOID;
634 } 533 }
635 534
636 debug_block = ACPI_CAST_PTR (struct acpi_debug_mem_block, 535 debug_block = ACPI_CAST_PTR(struct acpi_debug_mem_block,
637 (((char *) allocation) - sizeof (struct acpi_debug_mem_header))); 536 (((char *)allocation) -
537 sizeof(struct acpi_debug_mem_header)));
638 538
639 acpi_gbl_memory_lists[ACPI_MEM_LIST_GLOBAL].total_freed++; 539 acpi_gbl_global_list->total_freed++;
640 acpi_gbl_memory_lists[ACPI_MEM_LIST_GLOBAL].current_total_size -= debug_block->size; 540 acpi_gbl_global_list->current_total_size -= debug_block->size;
641 541
642 status = acpi_ut_remove_allocation (ACPI_MEM_LIST_GLOBAL, debug_block, 542 status = acpi_ut_remove_allocation(debug_block,
643 component, module, line); 543 component, module, line);
644 if (ACPI_FAILURE (status)) { 544 if (ACPI_FAILURE(status)) {
645 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Could not free memory, %s\n", 545 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Could not free memory, %s\n",
646 acpi_format_exception (status))); 546 acpi_format_exception(status)));
647 } 547 }
648 548
649 acpi_os_free (debug_block); 549 acpi_os_free(debug_block);
650 550
651 ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "%p freed\n", allocation)); 551 ACPI_DEBUG_PRINT((ACPI_DB_ALLOCATIONS, "%p freed\n", allocation));
652 552
653 return_VOID; 553 return_VOID;
654} 554}
655 555
656
657/******************************************************************************* 556/*******************************************************************************
658 * 557 *
659 * FUNCTION: acpi_ut_find_allocation 558 * FUNCTION: acpi_ut_find_allocation
660 * 559 *
661 * PARAMETERS: list_id - Memory list to search 560 * PARAMETERS: Allocation - Address of allocated memory
662 * Allocation - Address of allocated memory
663 * 561 *
664 * RETURN: A list element if found; NULL otherwise. 562 * RETURN: A list element if found; NULL otherwise.
665 * 563 *
@@ -667,22 +565,13 @@ acpi_ut_free_and_track (
667 * 565 *
668 ******************************************************************************/ 566 ******************************************************************************/
669 567
670static struct acpi_debug_mem_block * 568static struct acpi_debug_mem_block *acpi_ut_find_allocation(void *allocation)
671acpi_ut_find_allocation (
672 u32 list_id,
673 void *allocation)
674{ 569{
675 struct acpi_debug_mem_block *element; 570 struct acpi_debug_mem_block *element;
676
677 571
678 ACPI_FUNCTION_ENTRY (); 572 ACPI_FUNCTION_ENTRY();
679
680
681 if (list_id > ACPI_MEM_LIST_MAX) {
682 return (NULL);
683 }
684 573
685 element = acpi_gbl_memory_lists[list_id].list_head; 574 element = acpi_gbl_global_list->list_head;
686 575
687 /* Search for the address. */ 576 /* Search for the address. */
688 577
@@ -697,13 +586,11 @@ acpi_ut_find_allocation (
697 return (NULL); 586 return (NULL);
698} 587}
699 588
700
701/******************************************************************************* 589/*******************************************************************************
702 * 590 *
703 * FUNCTION: acpi_ut_track_allocation 591 * FUNCTION: acpi_ut_track_allocation
704 * 592 *
705 * PARAMETERS: list_id - Memory list to search 593 * PARAMETERS: Allocation - Address of allocated memory
706 * Allocation - Address of allocated memory
707 * Size - Size of the allocation 594 * Size - Size of the allocation
708 * alloc_type - MEM_MALLOC or MEM_CALLOC 595 * alloc_type - MEM_MALLOC or MEM_CALLOC
709 * Component - Component type of caller 596 * Component - Component type of caller
@@ -717,64 +604,51 @@ acpi_ut_find_allocation (
717 ******************************************************************************/ 604 ******************************************************************************/
718 605
719static acpi_status 606static acpi_status
720acpi_ut_track_allocation ( 607acpi_ut_track_allocation(struct acpi_debug_mem_block *allocation,
721 u32 list_id, 608 acpi_size size,
722 struct acpi_debug_mem_block *allocation, 609 u8 alloc_type, u32 component, char *module, u32 line)
723 acpi_size size,
724 u8 alloc_type,
725 u32 component,
726 char *module,
727 u32 line)
728{ 610{
729 struct acpi_memory_list *mem_list; 611 struct acpi_memory_list *mem_list;
730 struct acpi_debug_mem_block *element; 612 struct acpi_debug_mem_block *element;
731 acpi_status status = AE_OK; 613 acpi_status status = AE_OK;
732
733
734 ACPI_FUNCTION_TRACE_PTR ("ut_track_allocation", allocation);
735 614
615 ACPI_FUNCTION_TRACE_PTR("ut_track_allocation", allocation);
736 616
737 if (list_id > ACPI_MEM_LIST_MAX) { 617 mem_list = acpi_gbl_global_list;
738 return_ACPI_STATUS (AE_BAD_PARAMETER); 618 status = acpi_ut_acquire_mutex(ACPI_MTX_MEMORY);
739 } 619 if (ACPI_FAILURE(status)) {
740 620 return_ACPI_STATUS(status);
741 mem_list = &acpi_gbl_memory_lists[list_id];
742 status = acpi_ut_acquire_mutex (ACPI_MTX_MEMORY);
743 if (ACPI_FAILURE (status)) {
744 return_ACPI_STATUS (status);
745 } 621 }
746 622
747 /* 623 /*
748 * Search list for this address to make sure it is not already on the list. 624 * Search list for this address to make sure it is not already on the list.
749 * This will catch several kinds of problems. 625 * This will catch several kinds of problems.
750 */ 626 */
751 627 element = acpi_ut_find_allocation(allocation);
752 element = acpi_ut_find_allocation (list_id, allocation);
753 if (element) { 628 if (element) {
754 ACPI_REPORT_ERROR (( 629 ACPI_REPORT_ERROR(("ut_track_allocation: Allocation already present in list! (%p)\n", allocation));
755 "ut_track_allocation: Allocation already present in list! (%p)\n",
756 allocation));
757 630
758 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Element %p Address %p\n", 631 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Element %p Address %p\n",
759 element, allocation)); 632 element, allocation));
760 633
761 goto unlock_and_exit; 634 goto unlock_and_exit;
762 } 635 }
763 636
764 /* Fill in the instance data. */ 637 /* Fill in the instance data. */
765 638
766 allocation->size = (u32) size; 639 allocation->size = (u32) size;
767 allocation->alloc_type = alloc_type; 640 allocation->alloc_type = alloc_type;
768 allocation->component = component; 641 allocation->component = component;
769 allocation->line = line; 642 allocation->line = line;
770 643
771 ACPI_STRNCPY (allocation->module, module, ACPI_MAX_MODULE_NAME); 644 ACPI_STRNCPY(allocation->module, module, ACPI_MAX_MODULE_NAME);
772 allocation->module[ACPI_MAX_MODULE_NAME-1] = 0; 645 allocation->module[ACPI_MAX_MODULE_NAME - 1] = 0;
773 646
774 /* Insert at list head */ 647 /* Insert at list head */
775 648
776 if (mem_list->list_head) { 649 if (mem_list->list_head) {
777 ((struct acpi_debug_mem_block *)(mem_list->list_head))->previous = allocation; 650 ((struct acpi_debug_mem_block *)(mem_list->list_head))->
651 previous = allocation;
778 } 652 }
779 653
780 allocation->next = mem_list->list_head; 654 allocation->next = mem_list->list_head;
@@ -782,19 +656,16 @@ acpi_ut_track_allocation (
782 656
783 mem_list->list_head = allocation; 657 mem_list->list_head = allocation;
784 658
785 659 unlock_and_exit:
786unlock_and_exit: 660 status = acpi_ut_release_mutex(ACPI_MTX_MEMORY);
787 status = acpi_ut_release_mutex (ACPI_MTX_MEMORY); 661 return_ACPI_STATUS(status);
788 return_ACPI_STATUS (status);
789} 662}
790 663
791
792/******************************************************************************* 664/*******************************************************************************
793 * 665 *
794 * FUNCTION: acpi_ut_remove_allocation 666 * FUNCTION: acpi_ut_remove_allocation
795 * 667 *
796 * PARAMETERS: list_id - Memory list to search 668 * PARAMETERS: Allocation - Address of allocated memory
797 * Allocation - Address of allocated memory
798 * Component - Component type of caller 669 * Component - Component type of caller
799 * Module - Source file name of caller 670 * Module - Source file name of caller
800 * Line - Line number of caller 671 * Line - Line number of caller
@@ -806,45 +677,34 @@ unlock_and_exit:
806 ******************************************************************************/ 677 ******************************************************************************/
807 678
808static acpi_status 679static acpi_status
809acpi_ut_remove_allocation ( 680acpi_ut_remove_allocation(struct acpi_debug_mem_block *allocation,
810 u32 list_id, 681 u32 component, char *module, u32 line)
811 struct acpi_debug_mem_block *allocation,
812 u32 component,
813 char *module,
814 u32 line)
815{ 682{
816 struct acpi_memory_list *mem_list; 683 struct acpi_memory_list *mem_list;
817 acpi_status status; 684 acpi_status status;
818
819 685
820 ACPI_FUNCTION_TRACE ("ut_remove_allocation"); 686 ACPI_FUNCTION_TRACE("ut_remove_allocation");
821 687
822 688 mem_list = acpi_gbl_global_list;
823 if (list_id > ACPI_MEM_LIST_MAX) {
824 return_ACPI_STATUS (AE_BAD_PARAMETER);
825 }
826
827 mem_list = &acpi_gbl_memory_lists[list_id];
828 if (NULL == mem_list->list_head) { 689 if (NULL == mem_list->list_head) {
829 /* No allocations! */ 690 /* No allocations! */
830 691
831 _ACPI_REPORT_ERROR (module, line, component, 692 _ACPI_REPORT_ERROR(module, line, component,
832 ("ut_remove_allocation: Empty allocation list, nothing to free!\n")); 693 ("ut_remove_allocation: Empty allocation list, nothing to free!\n"));
833 694
834 return_ACPI_STATUS (AE_OK); 695 return_ACPI_STATUS(AE_OK);
835 } 696 }
836 697
837 status = acpi_ut_acquire_mutex (ACPI_MTX_MEMORY); 698 status = acpi_ut_acquire_mutex(ACPI_MTX_MEMORY);
838 if (ACPI_FAILURE (status)) { 699 if (ACPI_FAILURE(status)) {
839 return_ACPI_STATUS (status); 700 return_ACPI_STATUS(status);
840 } 701 }
841 702
842 /* Unlink */ 703 /* Unlink */
843 704
844 if (allocation->previous) { 705 if (allocation->previous) {
845 (allocation->previous)->next = allocation->next; 706 (allocation->previous)->next = allocation->next;
846 } 707 } else {
847 else {
848 mem_list->list_head = allocation->next; 708 mem_list->list_head = allocation->next;
849 } 709 }
850 710
@@ -854,16 +714,15 @@ acpi_ut_remove_allocation (
854 714
855 /* Mark the segment as deleted */ 715 /* Mark the segment as deleted */
856 716
857 ACPI_MEMSET (&allocation->user_space, 0xEA, allocation->size); 717 ACPI_MEMSET(&allocation->user_space, 0xEA, allocation->size);
858 718
859 ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "Freeing size 0%X\n", 719 ACPI_DEBUG_PRINT((ACPI_DB_ALLOCATIONS, "Freeing size 0%X\n",
860 allocation->size)); 720 allocation->size));
861 721
862 status = acpi_ut_release_mutex (ACPI_MTX_MEMORY); 722 status = acpi_ut_release_mutex(ACPI_MTX_MEMORY);
863 return_ACPI_STATUS (status); 723 return_ACPI_STATUS(status);
864} 724}
865 725
866
867/******************************************************************************* 726/*******************************************************************************
868 * 727 *
869 * FUNCTION: acpi_ut_dump_allocation_info 728 * FUNCTION: acpi_ut_dump_allocation_info
@@ -877,15 +736,13 @@ acpi_ut_remove_allocation (
877 ******************************************************************************/ 736 ******************************************************************************/
878 737
879#ifdef ACPI_FUTURE_USAGE 738#ifdef ACPI_FUTURE_USAGE
880void 739void acpi_ut_dump_allocation_info(void)
881acpi_ut_dump_allocation_info (
882 void)
883{ 740{
884/* 741/*
885 struct acpi_memory_list *mem_list; 742 struct acpi_memory_list *mem_list;
886*/ 743*/
887 744
888 ACPI_FUNCTION_TRACE ("ut_dump_allocation_info"); 745 ACPI_FUNCTION_TRACE("ut_dump_allocation_info");
889 746
890/* 747/*
891 ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES, 748 ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES,
@@ -898,7 +755,6 @@ acpi_ut_dump_allocation_info (
898 mem_list->max_concurrent_count, 755 mem_list->max_concurrent_count,
899 ROUND_UP_TO_1K (mem_list->max_concurrent_size))); 756 ROUND_UP_TO_1K (mem_list->max_concurrent_size)));
900 757
901
902 ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES, 758 ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES,
903 ("%30s: %4d (%3d Kb)\n", "Total (all) internal objects", 759 ("%30s: %4d (%3d Kb)\n", "Total (all) internal objects",
904 running_object_count, 760 running_object_count,
@@ -909,7 +765,6 @@ acpi_ut_dump_allocation_info (
909 running_alloc_count, 765 running_alloc_count,
910 ROUND_UP_TO_1K (running_alloc_size))); 766 ROUND_UP_TO_1K (running_alloc_size)));
911 767
912
913 ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES, 768 ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES,
914 ("%30s: %4d (%3d Kb)\n", "Current Nodes", 769 ("%30s: %4d (%3d Kb)\n", "Current Nodes",
915 acpi_gbl_current_node_count, 770 acpi_gbl_current_node_count,
@@ -923,8 +778,7 @@ acpi_ut_dump_allocation_info (
923*/ 778*/
924 return_VOID; 779 return_VOID;
925} 780}
926#endif /* ACPI_FUTURE_USAGE */ 781#endif /* ACPI_FUTURE_USAGE */
927
928 782
929/******************************************************************************* 783/*******************************************************************************
930 * 784 *
@@ -939,84 +793,87 @@ acpi_ut_dump_allocation_info (
939 * 793 *
940 ******************************************************************************/ 794 ******************************************************************************/
941 795
942void 796void acpi_ut_dump_allocations(u32 component, char *module)
943acpi_ut_dump_allocations (
944 u32 component,
945 char *module)
946{ 797{
947 struct acpi_debug_mem_block *element; 798 struct acpi_debug_mem_block *element;
948 union acpi_descriptor *descriptor; 799 union acpi_descriptor *descriptor;
949 u32 num_outstanding = 0; 800 u32 num_outstanding = 0;
950
951
952 ACPI_FUNCTION_TRACE ("ut_dump_allocations");
953 801
802 ACPI_FUNCTION_TRACE("ut_dump_allocations");
954 803
955 /* 804 /*
956 * Walk the allocation list. 805 * Walk the allocation list.
957 */ 806 */
958 if (ACPI_FAILURE (acpi_ut_acquire_mutex (ACPI_MTX_MEMORY))) { 807 if (ACPI_FAILURE(acpi_ut_acquire_mutex(ACPI_MTX_MEMORY))) {
959 return; 808 return;
960 } 809 }
961 810
962 element = acpi_gbl_memory_lists[0].list_head; 811 element = acpi_gbl_global_list->list_head;
963 while (element) { 812 while (element) {
964 if ((element->component & component) && 813 if ((element->component & component) &&
965 ((module == NULL) || (0 == ACPI_STRCMP (module, element->module)))) { 814 ((module == NULL)
815 || (0 == ACPI_STRCMP(module, element->module)))) {
966 /* Ignore allocated objects that are in a cache */ 816 /* Ignore allocated objects that are in a cache */
967 817
968 descriptor = ACPI_CAST_PTR (union acpi_descriptor, &element->user_space); 818 descriptor =
819 ACPI_CAST_PTR(union acpi_descriptor,
820 &element->user_space);
969 if (descriptor->descriptor_id != ACPI_DESC_TYPE_CACHED) { 821 if (descriptor->descriptor_id != ACPI_DESC_TYPE_CACHED) {
970 acpi_os_printf ("%p Len %04X %9.9s-%d [%s] ", 822 acpi_os_printf("%p Len %04X %9.9s-%d [%s] ",
971 descriptor, element->size, element->module, 823 descriptor, element->size,
972 element->line, acpi_ut_get_descriptor_name (descriptor)); 824 element->module, element->line,
825 acpi_ut_get_descriptor_name
826 (descriptor));
973 827
974 /* Most of the elements will be Operand objects. */ 828 /* Most of the elements will be Operand objects. */
975 829
976 switch (ACPI_GET_DESCRIPTOR_TYPE (descriptor)) { 830 switch (ACPI_GET_DESCRIPTOR_TYPE(descriptor)) {
977 case ACPI_DESC_TYPE_OPERAND: 831 case ACPI_DESC_TYPE_OPERAND:
978 acpi_os_printf ("%12.12s R%hd", 832 acpi_os_printf("%12.12s R%hd",
979 acpi_ut_get_type_name (descriptor->object.common.type), 833 acpi_ut_get_type_name
980 descriptor->object.common.reference_count); 834 (descriptor->object.
835 common.type),
836 descriptor->object.
837 common.reference_count);
981 break; 838 break;
982 839
983 case ACPI_DESC_TYPE_PARSER: 840 case ACPI_DESC_TYPE_PARSER:
984 acpi_os_printf ("aml_opcode %04hX", 841 acpi_os_printf("aml_opcode %04hX",
985 descriptor->op.asl.aml_opcode); 842 descriptor->op.asl.
843 aml_opcode);
986 break; 844 break;
987 845
988 case ACPI_DESC_TYPE_NAMED: 846 case ACPI_DESC_TYPE_NAMED:
989 acpi_os_printf ("%4.4s", 847 acpi_os_printf("%4.4s",
990 acpi_ut_get_node_name (&descriptor->node)); 848 acpi_ut_get_node_name
849 (&descriptor->node));
991 break; 850 break;
992 851
993 default: 852 default:
994 break; 853 break;
995 } 854 }
996 855
997 acpi_os_printf ( "\n"); 856 acpi_os_printf("\n");
998 num_outstanding++; 857 num_outstanding++;
999 } 858 }
1000 } 859 }
1001 element = element->next; 860 element = element->next;
1002 } 861 }
1003 862
1004 (void) acpi_ut_release_mutex (ACPI_MTX_MEMORY); 863 (void)acpi_ut_release_mutex(ACPI_MTX_MEMORY);
1005 864
1006 /* Print summary */ 865 /* Print summary */
1007 866
1008 if (!num_outstanding) { 867 if (!num_outstanding) {
1009 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, 868 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1010 "No outstanding allocations.\n")); 869 "No outstanding allocations.\n"));
1011 } 870 } else {
1012 else { 871 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1013 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, 872 "%d(%X) Outstanding allocations\n",
1014 "%d(%X) Outstanding allocations\n", 873 num_outstanding, num_outstanding));
1015 num_outstanding, num_outstanding));
1016 } 874 }
1017 875
1018 return_VOID; 876 return_VOID;
1019} 877}
1020 878
1021#endif /* #ifdef ACPI_DBG_TRACK_ALLOCATIONS */ 879#endif /* #ifdef ACPI_DBG_TRACK_ALLOCATIONS */
1022