[ACPI] ACPICA 20060127
[deliverable/linux.git] / drivers / acpi / utilities / utalloc.c
CommitLineData
1da177e4
LT
1/******************************************************************************
2 *
73459f73 3 * Module Name: utalloc - local memory allocation routines
1da177e4
LT
4 *
5 *****************************************************************************/
6
7/*
4a90c7e8 8 * Copyright (C) 2000 - 2006, R. Byron Moore
1da177e4
LT
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
1da177e4
LT
44#include <acpi/acpi.h>
45
46#define _COMPONENT ACPI_UTILITIES
4be44fcd 47ACPI_MODULE_NAME("utalloc")
1da177e4 48
44f6c012 49/* Local prototypes */
defba1d8 50#ifdef ACPI_DBG_TRACK_ALLOCATIONS
4be44fcd 51static struct acpi_debug_mem_block *acpi_ut_find_allocation(void *allocation);
44f6c012
RM
52
53static acpi_status
4be44fcd
LB
54acpi_ut_track_allocation(struct acpi_debug_mem_block *address,
55 acpi_size size,
56 u8 alloc_type, u32 component, char *module, u32 line);
44f6c012
RM
57
58static acpi_status
4be44fcd
LB
59acpi_ut_remove_allocation(struct acpi_debug_mem_block *address,
60 u32 component, char *module, u32 line);
44f6c012 61
73459f73 62static acpi_status
4be44fcd
LB
63acpi_ut_create_list(char *list_name,
64 u16 object_size, struct acpi_memory_list **return_cache);
1da177e4 65#endif
1da177e4 66
44f6c012 67/*******************************************************************************
1da177e4 68 *
73459f73 69 * FUNCTION: acpi_ut_create_caches
1da177e4 70 *
73459f73 71 * PARAMETERS: None
1da177e4 72 *
73459f73 73 * RETURN: Status
1da177e4 74 *
73459f73 75 * DESCRIPTION: Create all local caches
1da177e4
LT
76 *
77 ******************************************************************************/
78
4be44fcd 79acpi_status acpi_ut_create_caches(void)
1da177e4 80{
4be44fcd 81 acpi_status status;
1da177e4 82
73459f73 83#ifdef ACPI_DBG_TRACK_ALLOCATIONS
1da177e4 84
73459f73 85 /* Memory allocation lists */
1da177e4 86
4be44fcd
LB
87 status = acpi_ut_create_list("Acpi-Global", 0, &acpi_gbl_global_list);
88 if (ACPI_FAILURE(status)) {
73459f73 89 return (status);
1da177e4
LT
90 }
91
4be44fcd
LB
92 status =
93 acpi_ut_create_list("Acpi-Namespace",
94 sizeof(struct acpi_namespace_node),
95 &acpi_gbl_ns_node_list);
96 if (ACPI_FAILURE(status)) {
73459f73
RM
97 return (status);
98 }
1da177e4
LT
99#endif
100
73459f73 101 /* Object Caches, for frequently used objects */
1da177e4 102
4be44fcd
LB
103 status =
104 acpi_os_create_cache("acpi_state", sizeof(union acpi_generic_state),
105 ACPI_MAX_STATE_CACHE_DEPTH,
106 &acpi_gbl_state_cache);
107 if (ACPI_FAILURE(status)) {
73459f73 108 return (status);
1da177e4
LT
109 }
110
4be44fcd
LB
111 status =
112 acpi_os_create_cache("acpi_parse",
113 sizeof(struct acpi_parse_obj_common),
114 ACPI_MAX_PARSE_CACHE_DEPTH,
115 &acpi_gbl_ps_node_cache);
116 if (ACPI_FAILURE(status)) {
73459f73 117 return (status);
1da177e4
LT
118 }
119
4be44fcd
LB
120 status =
121 acpi_os_create_cache("acpi_parse_ext",
122 sizeof(struct acpi_parse_obj_named),
123 ACPI_MAX_EXTPARSE_CACHE_DEPTH,
124 &acpi_gbl_ps_node_ext_cache);
125 if (ACPI_FAILURE(status)) {
73459f73
RM
126 return (status);
127 }
1da177e4 128
4be44fcd
LB
129 status =
130 acpi_os_create_cache("acpi_operand",
131 sizeof(union acpi_operand_object),
132 ACPI_MAX_OBJECT_CACHE_DEPTH,
133 &acpi_gbl_operand_cache);
134 if (ACPI_FAILURE(status)) {
73459f73
RM
135 return (status);
136 }
1da177e4 137
73459f73 138 return (AE_OK);
1da177e4
LT
139}
140
44f6c012 141/*******************************************************************************
1da177e4 142 *
73459f73 143 * FUNCTION: acpi_ut_delete_caches
1da177e4 144 *
73459f73 145 * PARAMETERS: None
1da177e4 146 *
73459f73 147 * RETURN: Status
1da177e4 148 *
73459f73 149 * DESCRIPTION: Purge and delete all local caches
1da177e4
LT
150 *
151 ******************************************************************************/
152
4be44fcd 153acpi_status acpi_ut_delete_caches(void)
1da177e4 154{
1da177e4 155
4be44fcd 156 (void)acpi_os_delete_cache(acpi_gbl_state_cache);
73459f73 157 acpi_gbl_state_cache = NULL;
1da177e4 158
4be44fcd 159 (void)acpi_os_delete_cache(acpi_gbl_operand_cache);
73459f73 160 acpi_gbl_operand_cache = NULL;
1da177e4 161
4be44fcd 162 (void)acpi_os_delete_cache(acpi_gbl_ps_node_cache);
73459f73 163 acpi_gbl_ps_node_cache = NULL;
1da177e4 164
4be44fcd 165 (void)acpi_os_delete_cache(acpi_gbl_ps_node_ext_cache);
73459f73 166 acpi_gbl_ps_node_ext_cache = NULL;
1da177e4 167
73459f73 168 return (AE_OK);
1da177e4 169}
1da177e4
LT
170
171/*******************************************************************************
172 *
173 * FUNCTION: acpi_ut_validate_buffer
174 *
175 * PARAMETERS: Buffer - Buffer descriptor to be validated
176 *
177 * RETURN: Status
178 *
179 * DESCRIPTION: Perform parameter validation checks on an struct acpi_buffer
180 *
181 ******************************************************************************/
182
4be44fcd 183acpi_status acpi_ut_validate_buffer(struct acpi_buffer * buffer)
1da177e4
LT
184{
185
186 /* Obviously, the structure pointer must be valid */
187
188 if (!buffer) {
189 return (AE_BAD_PARAMETER);
190 }
191
192 /* Special semantics for the length */
193
4be44fcd
LB
194 if ((buffer->length == ACPI_NO_BUFFER) ||
195 (buffer->length == ACPI_ALLOCATE_BUFFER) ||
196 (buffer->length == ACPI_ALLOCATE_LOCAL_BUFFER)) {
1da177e4
LT
197 return (AE_OK);
198 }
199
200 /* Length is valid, the buffer pointer must be also */
201
202 if (!buffer->pointer) {
203 return (AE_BAD_PARAMETER);
204 }
205
206 return (AE_OK);
207}
208
1da177e4
LT
209/*******************************************************************************
210 *
211 * FUNCTION: acpi_ut_initialize_buffer
212 *
213 * PARAMETERS: Buffer - Buffer to be validated
214 * required_length - Length needed
215 *
216 * RETURN: Status
217 *
218 * DESCRIPTION: Validate that the buffer is of the required length or
219 * allocate a new buffer. Returned buffer is always zeroed.
220 *
221 ******************************************************************************/
222
223acpi_status
4be44fcd
LB
224acpi_ut_initialize_buffer(struct acpi_buffer * buffer,
225 acpi_size required_length)
1da177e4 226{
4be44fcd 227 acpi_status status = AE_OK;
1da177e4
LT
228
229 switch (buffer->length) {
230 case ACPI_NO_BUFFER:
231
232 /* Set the exception and returned the required length */
233
234 status = AE_BUFFER_OVERFLOW;
235 break;
236
1da177e4
LT
237 case ACPI_ALLOCATE_BUFFER:
238
239 /* Allocate a new buffer */
240
4be44fcd 241 buffer->pointer = acpi_os_allocate(required_length);
1da177e4
LT
242 if (!buffer->pointer) {
243 return (AE_NO_MEMORY);
244 }
245
246 /* Clear the buffer */
247
4be44fcd 248 ACPI_MEMSET(buffer->pointer, 0, required_length);
1da177e4
LT
249 break;
250
1da177e4
LT
251 case ACPI_ALLOCATE_LOCAL_BUFFER:
252
253 /* Allocate a new buffer with local interface to allow tracking */
254
4be44fcd 255 buffer->pointer = ACPI_MEM_CALLOCATE(required_length);
1da177e4
LT
256 if (!buffer->pointer) {
257 return (AE_NO_MEMORY);
258 }
259 break;
260
1da177e4
LT
261 default:
262
263 /* Existing buffer: Validate the size of the buffer */
264
265 if (buffer->length < required_length) {
266 status = AE_BUFFER_OVERFLOW;
267 break;
268 }
269
270 /* Clear the buffer */
271
4be44fcd 272 ACPI_MEMSET(buffer->pointer, 0, required_length);
1da177e4
LT
273 break;
274 }
275
276 buffer->length = required_length;
277 return (status);
278}
279
1da177e4
LT
280/*******************************************************************************
281 *
282 * FUNCTION: acpi_ut_allocate
283 *
284 * PARAMETERS: Size - Size of the allocation
285 * Component - Component type of caller
286 * Module - Source file name of caller
287 * Line - Line number of caller
288 *
289 * RETURN: Address of the allocated memory on success, NULL on failure.
290 *
291 * DESCRIPTION: The subsystem's equivalent of malloc.
292 *
293 ******************************************************************************/
294
4be44fcd 295void *acpi_ut_allocate(acpi_size size, u32 component, char *module, u32 line)
1da177e4 296{
4be44fcd 297 void *allocation;
1da177e4 298
4be44fcd 299 ACPI_FUNCTION_TRACE_U32("ut_allocate", size);
1da177e4
LT
300
301 /* Check for an inadvertent size of zero bytes */
302
303 if (!size) {
b8e4d893
BM
304 ACPI_ERROR((module, line,
305 "ut_allocate: Attempt to allocate zero bytes, allocating 1 byte"));
1da177e4
LT
306 size = 1;
307 }
308
4be44fcd 309 allocation = acpi_os_allocate(size);
1da177e4
LT
310 if (!allocation) {
311 /* Report allocation error */
312
b8e4d893
BM
313 ACPI_ERROR((module, line,
314 "ut_allocate: Could not allocate size %X",
315 (u32) size));
1da177e4 316
4be44fcd 317 return_PTR(NULL);
1da177e4
LT
318 }
319
4be44fcd 320 return_PTR(allocation);
1da177e4
LT
321}
322
1da177e4
LT
323/*******************************************************************************
324 *
325 * FUNCTION: acpi_ut_callocate
326 *
327 * PARAMETERS: Size - Size of the allocation
328 * Component - Component type of caller
329 * Module - Source file name of caller
330 * Line - Line number of caller
331 *
332 * RETURN: Address of the allocated memory on success, NULL on failure.
333 *
334 * DESCRIPTION: Subsystem equivalent of calloc.
335 *
336 ******************************************************************************/
337
4be44fcd 338void *acpi_ut_callocate(acpi_size size, u32 component, char *module, u32 line)
1da177e4 339{
4be44fcd 340 void *allocation;
1da177e4 341
4be44fcd 342 ACPI_FUNCTION_TRACE_U32("ut_callocate", size);
1da177e4
LT
343
344 /* Check for an inadvertent size of zero bytes */
345
346 if (!size) {
b8e4d893
BM
347 ACPI_ERROR((module, line,
348 "Attempt to allocate zero bytes, allocating 1 byte"));
50eca3eb 349 size = 1;
1da177e4
LT
350 }
351
4be44fcd 352 allocation = acpi_os_allocate(size);
1da177e4
LT
353 if (!allocation) {
354 /* Report allocation error */
355
b8e4d893
BM
356 ACPI_ERROR((module, line,
357 "Could not allocate size %X", (u32) size));
4be44fcd 358 return_PTR(NULL);
1da177e4
LT
359 }
360
361 /* Clear the memory block */
362
4be44fcd
LB
363 ACPI_MEMSET(allocation, 0, size);
364 return_PTR(allocation);
1da177e4
LT
365}
366
1da177e4
LT
367#ifdef ACPI_DBG_TRACK_ALLOCATIONS
368/*
369 * These procedures are used for tracking memory leaks in the subsystem, and
370 * they get compiled out when the ACPI_DBG_TRACK_ALLOCATIONS is not set.
371 *
372 * Each memory allocation is tracked via a doubly linked list. Each
373 * element contains the caller's component, module name, function name, and
374 * line number. acpi_ut_allocate and acpi_ut_callocate call
375 * acpi_ut_track_allocation to add an element to the list; deletion
376 * occurs in the body of acpi_ut_free.
377 */
378
73459f73
RM
379/*******************************************************************************
380 *
381 * FUNCTION: acpi_ut_create_list
382 *
383 * PARAMETERS: cache_name - Ascii name for the cache
384 * object_size - Size of each cached object
385 * return_cache - Where the new cache object is returned
386 *
387 * RETURN: Status
388 *
389 * DESCRIPTION: Create a local memory list for tracking purposed
390 *
391 ******************************************************************************/
392
393static acpi_status
4be44fcd
LB
394acpi_ut_create_list(char *list_name,
395 u16 object_size, struct acpi_memory_list **return_cache)
73459f73 396{
4be44fcd 397 struct acpi_memory_list *cache;
73459f73 398
4be44fcd 399 cache = acpi_os_allocate(sizeof(struct acpi_memory_list));
73459f73
RM
400 if (!cache) {
401 return (AE_NO_MEMORY);
402 }
403
4be44fcd 404 ACPI_MEMSET(cache, 0, sizeof(struct acpi_memory_list));
73459f73 405
4be44fcd 406 cache->list_name = list_name;
73459f73
RM
407 cache->object_size = object_size;
408
409 *return_cache = cache;
410 return (AE_OK);
411}
412
1da177e4
LT
413/*******************************************************************************
414 *
415 * FUNCTION: acpi_ut_allocate_and_track
416 *
417 * PARAMETERS: Size - Size of the allocation
418 * Component - Component type of caller
419 * Module - Source file name of caller
420 * Line - Line number of caller
421 *
422 * RETURN: Address of the allocated memory on success, NULL on failure.
423 *
424 * DESCRIPTION: The subsystem's equivalent of malloc.
425 *
426 ******************************************************************************/
427
4be44fcd
LB
428void *acpi_ut_allocate_and_track(acpi_size size,
429 u32 component, char *module, u32 line)
1da177e4 430{
4be44fcd
LB
431 struct acpi_debug_mem_block *allocation;
432 acpi_status status;
1da177e4 433
4be44fcd
LB
434 allocation =
435 acpi_ut_allocate(size + sizeof(struct acpi_debug_mem_header),
436 component, module, line);
1da177e4
LT
437 if (!allocation) {
438 return (NULL);
439 }
440
4be44fcd
LB
441 status = acpi_ut_track_allocation(allocation, size,
442 ACPI_MEM_MALLOC, component, module,
443 line);
444 if (ACPI_FAILURE(status)) {
445 acpi_os_free(allocation);
1da177e4
LT
446 return (NULL);
447 }
448
73459f73
RM
449 acpi_gbl_global_list->total_allocated++;
450 acpi_gbl_global_list->current_total_size += (u32) size;
1da177e4 451
4be44fcd 452 return ((void *)&allocation->user_space);
1da177e4
LT
453}
454
1da177e4
LT
455/*******************************************************************************
456 *
457 * FUNCTION: acpi_ut_callocate_and_track
458 *
459 * PARAMETERS: Size - Size of the allocation
460 * Component - Component type of caller
461 * Module - Source file name of caller
462 * Line - Line number of caller
463 *
464 * RETURN: Address of the allocated memory on success, NULL on failure.
465 *
466 * DESCRIPTION: Subsystem equivalent of calloc.
467 *
468 ******************************************************************************/
469
4be44fcd
LB
470void *acpi_ut_callocate_and_track(acpi_size size,
471 u32 component, char *module, u32 line)
1da177e4 472{
4be44fcd
LB
473 struct acpi_debug_mem_block *allocation;
474 acpi_status status;
1da177e4 475
4be44fcd
LB
476 allocation =
477 acpi_ut_callocate(size + sizeof(struct acpi_debug_mem_header),
478 component, module, line);
1da177e4
LT
479 if (!allocation) {
480 /* Report allocation error */
481
b8e4d893
BM
482 ACPI_ERROR((module, line,
483 "Could not allocate size %X", (u32) size));
1da177e4
LT
484 return (NULL);
485 }
486
4be44fcd
LB
487 status = acpi_ut_track_allocation(allocation, size,
488 ACPI_MEM_CALLOC, component, module,
489 line);
490 if (ACPI_FAILURE(status)) {
491 acpi_os_free(allocation);
1da177e4
LT
492 return (NULL);
493 }
494
73459f73
RM
495 acpi_gbl_global_list->total_allocated++;
496 acpi_gbl_global_list->current_total_size += (u32) size;
1da177e4 497
4be44fcd 498 return ((void *)&allocation->user_space);
1da177e4
LT
499}
500
1da177e4
LT
501/*******************************************************************************
502 *
503 * FUNCTION: acpi_ut_free_and_track
504 *
505 * PARAMETERS: Allocation - Address of the memory to deallocate
506 * Component - Component type of caller
507 * Module - Source file name of caller
508 * Line - Line number of caller
509 *
510 * RETURN: None
511 *
512 * DESCRIPTION: Frees the memory at Allocation
513 *
514 ******************************************************************************/
515
516void
4be44fcd 517acpi_ut_free_and_track(void *allocation, u32 component, char *module, u32 line)
1da177e4 518{
4be44fcd
LB
519 struct acpi_debug_mem_block *debug_block;
520 acpi_status status;
1da177e4 521
4be44fcd 522 ACPI_FUNCTION_TRACE_PTR("ut_free", allocation);
1da177e4
LT
523
524 if (NULL == allocation) {
b8e4d893 525 ACPI_ERROR((module, line, "Attempt to delete a NULL address"));
1da177e4
LT
526
527 return_VOID;
528 }
529
4be44fcd
LB
530 debug_block = ACPI_CAST_PTR(struct acpi_debug_mem_block,
531 (((char *)allocation) -
532 sizeof(struct acpi_debug_mem_header)));
1da177e4 533
73459f73
RM
534 acpi_gbl_global_list->total_freed++;
535 acpi_gbl_global_list->current_total_size -= debug_block->size;
1da177e4 536
4be44fcd
LB
537 status = acpi_ut_remove_allocation(debug_block,
538 component, module, line);
539 if (ACPI_FAILURE(status)) {
b8e4d893 540 ACPI_EXCEPTION((AE_INFO, status, "Could not free memory"));
1da177e4
LT
541 }
542
4be44fcd 543 acpi_os_free(debug_block);
4be44fcd 544 ACPI_DEBUG_PRINT((ACPI_DB_ALLOCATIONS, "%p freed\n", allocation));
1da177e4
LT
545 return_VOID;
546}
547
1da177e4
LT
548/*******************************************************************************
549 *
550 * FUNCTION: acpi_ut_find_allocation
551 *
73459f73 552 * PARAMETERS: Allocation - Address of allocated memory
1da177e4
LT
553 *
554 * RETURN: A list element if found; NULL otherwise.
555 *
556 * DESCRIPTION: Searches for an element in the global allocation tracking list.
557 *
558 ******************************************************************************/
559
4be44fcd 560static struct acpi_debug_mem_block *acpi_ut_find_allocation(void *allocation)
1da177e4 561{
4be44fcd 562 struct acpi_debug_mem_block *element;
1da177e4 563
4be44fcd 564 ACPI_FUNCTION_ENTRY();
1da177e4 565
73459f73 566 element = acpi_gbl_global_list->list_head;
1da177e4
LT
567
568 /* Search for the address. */
569
570 while (element) {
571 if (element == allocation) {
572 return (element);
573 }
574
575 element = element->next;
576 }
577
578 return (NULL);
579}
580
1da177e4
LT
581/*******************************************************************************
582 *
583 * FUNCTION: acpi_ut_track_allocation
584 *
73459f73 585 * PARAMETERS: Allocation - Address of allocated memory
1da177e4
LT
586 * Size - Size of the allocation
587 * alloc_type - MEM_MALLOC or MEM_CALLOC
588 * Component - Component type of caller
589 * Module - Source file name of caller
590 * Line - Line number of caller
591 *
592 * RETURN: None.
593 *
594 * DESCRIPTION: Inserts an element into the global allocation tracking list.
595 *
596 ******************************************************************************/
597
44f6c012 598static acpi_status
4be44fcd
LB
599acpi_ut_track_allocation(struct acpi_debug_mem_block *allocation,
600 acpi_size size,
601 u8 alloc_type, u32 component, char *module, u32 line)
1da177e4 602{
4be44fcd
LB
603 struct acpi_memory_list *mem_list;
604 struct acpi_debug_mem_block *element;
605 acpi_status status = AE_OK;
1da177e4 606
4be44fcd 607 ACPI_FUNCTION_TRACE_PTR("ut_track_allocation", allocation);
1da177e4 608
73459f73 609 mem_list = acpi_gbl_global_list;
4be44fcd
LB
610 status = acpi_ut_acquire_mutex(ACPI_MTX_MEMORY);
611 if (ACPI_FAILURE(status)) {
612 return_ACPI_STATUS(status);
1da177e4
LT
613 }
614
615 /*
616 * Search list for this address to make sure it is not already on the list.
617 * This will catch several kinds of problems.
618 */
4be44fcd 619 element = acpi_ut_find_allocation(allocation);
1da177e4 620 if (element) {
b8e4d893
BM
621 ACPI_ERROR((AE_INFO,
622 "ut_track_allocation: Allocation already present in list! (%p)",
623 allocation));
1da177e4 624
b8e4d893
BM
625 ACPI_ERROR((AE_INFO, "Element %p Address %p",
626 element, allocation));
1da177e4
LT
627
628 goto unlock_and_exit;
629 }
630
631 /* Fill in the instance data. */
632
4be44fcd 633 allocation->size = (u32) size;
1da177e4
LT
634 allocation->alloc_type = alloc_type;
635 allocation->component = component;
4be44fcd 636 allocation->line = line;
1da177e4 637
4be44fcd
LB
638 ACPI_STRNCPY(allocation->module, module, ACPI_MAX_MODULE_NAME);
639 allocation->module[ACPI_MAX_MODULE_NAME - 1] = 0;
1da177e4
LT
640
641 /* Insert at list head */
642
643 if (mem_list->list_head) {
4be44fcd
LB
644 ((struct acpi_debug_mem_block *)(mem_list->list_head))->
645 previous = allocation;
1da177e4
LT
646 }
647
648 allocation->next = mem_list->list_head;
649 allocation->previous = NULL;
650
651 mem_list->list_head = allocation;
652
4be44fcd
LB
653 unlock_and_exit:
654 status = acpi_ut_release_mutex(ACPI_MTX_MEMORY);
655 return_ACPI_STATUS(status);
1da177e4
LT
656}
657
1da177e4
LT
658/*******************************************************************************
659 *
660 * FUNCTION: acpi_ut_remove_allocation
661 *
73459f73 662 * PARAMETERS: Allocation - Address of allocated memory
1da177e4
LT
663 * Component - Component type of caller
664 * Module - Source file name of caller
665 * Line - Line number of caller
666 *
667 * RETURN:
668 *
669 * DESCRIPTION: Deletes an element from the global allocation tracking list.
670 *
671 ******************************************************************************/
672
44f6c012 673static acpi_status
4be44fcd
LB
674acpi_ut_remove_allocation(struct acpi_debug_mem_block *allocation,
675 u32 component, char *module, u32 line)
1da177e4 676{
4be44fcd
LB
677 struct acpi_memory_list *mem_list;
678 acpi_status status;
1da177e4 679
4be44fcd 680 ACPI_FUNCTION_TRACE("ut_remove_allocation");
1da177e4 681
73459f73 682 mem_list = acpi_gbl_global_list;
1da177e4
LT
683 if (NULL == mem_list->list_head) {
684 /* No allocations! */
685
b8e4d893
BM
686 ACPI_ERROR((module, line,
687 "Empty allocation list, nothing to free!"));
1da177e4 688
4be44fcd 689 return_ACPI_STATUS(AE_OK);
1da177e4
LT
690 }
691
4be44fcd
LB
692 status = acpi_ut_acquire_mutex(ACPI_MTX_MEMORY);
693 if (ACPI_FAILURE(status)) {
694 return_ACPI_STATUS(status);
1da177e4
LT
695 }
696
697 /* Unlink */
698
699 if (allocation->previous) {
700 (allocation->previous)->next = allocation->next;
4be44fcd 701 } else {
1da177e4
LT
702 mem_list->list_head = allocation->next;
703 }
704
705 if (allocation->next) {
706 (allocation->next)->previous = allocation->previous;
707 }
708
709 /* Mark the segment as deleted */
710
4be44fcd 711 ACPI_MEMSET(&allocation->user_space, 0xEA, allocation->size);
1da177e4 712
4be44fcd
LB
713 ACPI_DEBUG_PRINT((ACPI_DB_ALLOCATIONS, "Freeing size 0%X\n",
714 allocation->size));
1da177e4 715
4be44fcd
LB
716 status = acpi_ut_release_mutex(ACPI_MTX_MEMORY);
717 return_ACPI_STATUS(status);
1da177e4
LT
718}
719
1da177e4
LT
720/*******************************************************************************
721 *
722 * FUNCTION: acpi_ut_dump_allocation_info
723 *
724 * PARAMETERS:
725 *
726 * RETURN: None
727 *
728 * DESCRIPTION: Print some info about the outstanding allocations.
729 *
730 ******************************************************************************/
44f6c012 731
1da177e4 732#ifdef ACPI_FUTURE_USAGE
4be44fcd 733void acpi_ut_dump_allocation_info(void)
1da177e4
LT
734{
735/*
736 struct acpi_memory_list *mem_list;
737*/
738
4be44fcd 739 ACPI_FUNCTION_TRACE("ut_dump_allocation_info");
1da177e4
LT
740
741/*
742 ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES,
743 ("%30s: %4d (%3d Kb)\n", "Current allocations",
744 mem_list->current_count,
745 ROUND_UP_TO_1K (mem_list->current_size)));
746
747 ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES,
748 ("%30s: %4d (%3d Kb)\n", "Max concurrent allocations",
749 mem_list->max_concurrent_count,
750 ROUND_UP_TO_1K (mem_list->max_concurrent_size)));
751
1da177e4
LT
752 ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES,
753 ("%30s: %4d (%3d Kb)\n", "Total (all) internal objects",
754 running_object_count,
755 ROUND_UP_TO_1K (running_object_size)));
756
757 ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES,
758 ("%30s: %4d (%3d Kb)\n", "Total (all) allocations",
759 running_alloc_count,
760 ROUND_UP_TO_1K (running_alloc_size)));
761
1da177e4
LT
762 ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES,
763 ("%30s: %4d (%3d Kb)\n", "Current Nodes",
764 acpi_gbl_current_node_count,
765 ROUND_UP_TO_1K (acpi_gbl_current_node_size)));
766
767 ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES,
768 ("%30s: %4d (%3d Kb)\n", "Max Nodes",
769 acpi_gbl_max_concurrent_node_count,
44f6c012
RM
770 ROUND_UP_TO_1K ((acpi_gbl_max_concurrent_node_count *
771 sizeof (struct acpi_namespace_node)))));
1da177e4
LT
772*/
773 return_VOID;
774}
4be44fcd 775#endif /* ACPI_FUTURE_USAGE */
1da177e4
LT
776
777/*******************************************************************************
778 *
779 * FUNCTION: acpi_ut_dump_allocations
780 *
781 * PARAMETERS: Component - Component(s) to dump info for.
782 * Module - Module to dump info for. NULL means all.
783 *
784 * RETURN: None
785 *
786 * DESCRIPTION: Print a list of all outstanding allocations.
787 *
788 ******************************************************************************/
789
4be44fcd 790void acpi_ut_dump_allocations(u32 component, char *module)
1da177e4 791{
4be44fcd
LB
792 struct acpi_debug_mem_block *element;
793 union acpi_descriptor *descriptor;
794 u32 num_outstanding = 0;
1da177e4 795
4be44fcd 796 ACPI_FUNCTION_TRACE("ut_dump_allocations");
1da177e4
LT
797
798 /*
799 * Walk the allocation list.
800 */
4be44fcd 801 if (ACPI_FAILURE(acpi_ut_acquire_mutex(ACPI_MTX_MEMORY))) {
1da177e4
LT
802 return;
803 }
804
73459f73 805 element = acpi_gbl_global_list->list_head;
1da177e4
LT
806 while (element) {
807 if ((element->component & component) &&
4be44fcd
LB
808 ((module == NULL)
809 || (0 == ACPI_STRCMP(module, element->module)))) {
1da177e4
LT
810 /* Ignore allocated objects that are in a cache */
811
4be44fcd
LB
812 descriptor =
813 ACPI_CAST_PTR(union acpi_descriptor,
814 &element->user_space);
1da177e4 815 if (descriptor->descriptor_id != ACPI_DESC_TYPE_CACHED) {
4be44fcd
LB
816 acpi_os_printf("%p Len %04X %9.9s-%d [%s] ",
817 descriptor, element->size,
818 element->module, element->line,
819 acpi_ut_get_descriptor_name
820 (descriptor));
1da177e4
LT
821
822 /* Most of the elements will be Operand objects. */
823
4be44fcd 824 switch (ACPI_GET_DESCRIPTOR_TYPE(descriptor)) {
1da177e4 825 case ACPI_DESC_TYPE_OPERAND:
4be44fcd
LB
826 acpi_os_printf("%12.12s R%hd",
827 acpi_ut_get_type_name
828 (descriptor->object.
829 common.type),
830 descriptor->object.
831 common.reference_count);
1da177e4
LT
832 break;
833
834 case ACPI_DESC_TYPE_PARSER:
4be44fcd
LB
835 acpi_os_printf("aml_opcode %04hX",
836 descriptor->op.asl.
837 aml_opcode);
1da177e4
LT
838 break;
839
840 case ACPI_DESC_TYPE_NAMED:
4be44fcd
LB
841 acpi_os_printf("%4.4s",
842 acpi_ut_get_node_name
843 (&descriptor->node));
1da177e4
LT
844 break;
845
846 default:
847 break;
848 }
849
4be44fcd 850 acpi_os_printf("\n");
1da177e4
LT
851 num_outstanding++;
852 }
853 }
854 element = element->next;
855 }
856
4be44fcd 857 (void)acpi_ut_release_mutex(ACPI_MTX_MEMORY);
1da177e4
LT
858
859 /* Print summary */
860
861 if (!num_outstanding) {
b8e4d893 862 ACPI_INFO((AE_INFO, "No outstanding allocations"));
4be44fcd 863 } else {
b8e4d893
BM
864 ACPI_ERROR((AE_INFO,
865 "%d(%X) Outstanding allocations",
866 num_outstanding, num_outstanding));
1da177e4
LT
867 }
868
869 return_VOID;
870}
871
4be44fcd 872#endif /* #ifdef ACPI_DBG_TRACK_ALLOCATIONS */
This page took 0.144904 seconds and 5 git commands to generate.