aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/acpi/utilities
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/acpi/utilities')
-rw-r--r--drivers/acpi/utilities/Makefile2
-rw-r--r--drivers/acpi/utilities/utalloc.c304
-rw-r--r--drivers/acpi/utilities/utcache.c328
-rw-r--r--drivers/acpi/utilities/utcopy.c46
-rw-r--r--drivers/acpi/utilities/utdebug.c228
-rw-r--r--drivers/acpi/utilities/utdelete.c140
-rw-r--r--drivers/acpi/utilities/utglobal.c108
-rw-r--r--drivers/acpi/utilities/utinit.c2
-rw-r--r--drivers/acpi/utilities/utmisc.c799
-rw-r--r--drivers/acpi/utilities/utmutex.c380
-rw-r--r--drivers/acpi/utilities/utobject.c34
-rw-r--r--drivers/acpi/utilities/utstate.c376
-rw-r--r--drivers/acpi/utilities/utxface.c23
13 files changed, 1539 insertions, 1231 deletions
diff --git a/drivers/acpi/utilities/Makefile b/drivers/acpi/utilities/Makefile
index 939c447dd52a..e87108b7338a 100644
--- a/drivers/acpi/utilities/Makefile
+++ b/drivers/acpi/utilities/Makefile
@@ -3,6 +3,6 @@
3# 3#
4 4
5obj-y := utalloc.o utdebug.o uteval.o utinit.o utmisc.o utxface.o \ 5obj-y := utalloc.o utdebug.o uteval.o utinit.o utmisc.o utxface.o \
6 utcopy.o utdelete.o utglobal.o utmath.o utobject.o 6 utcopy.o utdelete.o utglobal.o utmath.o utobject.o utstate.o utmutex.o utobject.o utcache.o
7 7
8EXTRA_CFLAGS += $(ACPI_CFLAGS) 8EXTRA_CFLAGS += $(ACPI_CFLAGS)
diff --git a/drivers/acpi/utilities/utalloc.c b/drivers/acpi/utilities/utalloc.c
index c4e7f989a2bd..78270f50e625 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
@@ -52,12 +52,10 @@
52#ifdef ACPI_DBG_TRACK_ALLOCATIONS 52#ifdef ACPI_DBG_TRACK_ALLOCATIONS
53static struct acpi_debug_mem_block * 53static struct acpi_debug_mem_block *
54acpi_ut_find_allocation ( 54acpi_ut_find_allocation (
55 u32 list_id,
56 void *allocation); 55 void *allocation);
57 56
58static acpi_status 57static acpi_status
59acpi_ut_track_allocation ( 58acpi_ut_track_allocation (
60 u32 list_id,
61 struct acpi_debug_mem_block *address, 59 struct acpi_debug_mem_block *address,
62 acpi_size size, 60 acpi_size size,
63 u8 alloc_type, 61 u8 alloc_type,
@@ -67,206 +65,118 @@ acpi_ut_track_allocation (
67 65
68static acpi_status 66static acpi_status
69acpi_ut_remove_allocation ( 67acpi_ut_remove_allocation (
70 u32 list_id,
71 struct acpi_debug_mem_block *address, 68 struct acpi_debug_mem_block *address,
72 u32 component, 69 u32 component,
73 char *module, 70 char *module,
74 u32 line); 71 u32 line);
75#endif /* ACPI_DBG_TRACK_ALLOCATIONS */ 72#endif /* ACPI_DBG_TRACK_ALLOCATIONS */
76 73
77 74#ifdef ACPI_DBG_TRACK_ALLOCATIONS
78/******************************************************************************* 75static acpi_status
79 * 76acpi_ut_create_list (
80 * FUNCTION: acpi_ut_release_to_cache 77 char *list_name,
81 * 78 u16 object_size,
82 * PARAMETERS: list_id - Memory list/cache ID 79 struct acpi_memory_list **return_cache);
83 * Object - The object to be released
84 *
85 * RETURN: None
86 *
87 * DESCRIPTION: Release an object to the specified cache. If cache is full,
88 * the object is deleted.
89 *
90 ******************************************************************************/
91
92void
93acpi_ut_release_to_cache (
94 u32 list_id,
95 void *object)
96{
97 struct acpi_memory_list *cache_info;
98
99
100 ACPI_FUNCTION_ENTRY ();
101
102
103 cache_info = &acpi_gbl_memory_lists[list_id];
104
105#ifdef ACPI_ENABLE_OBJECT_CACHE
106
107 /* If walk cache is full, just free this wallkstate object */
108
109 if (cache_info->cache_depth >= cache_info->max_cache_depth) {
110 ACPI_MEM_FREE (object);
111 ACPI_MEM_TRACKING (cache_info->total_freed++);
112 }
113
114 /* Otherwise put this object back into the cache */
115
116 else {
117 if (ACPI_FAILURE (acpi_ut_acquire_mutex (ACPI_MTX_CACHES))) {
118 return;
119 }
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 }
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 80#endif
143}
144 81
145 82
146/******************************************************************************* 83/*******************************************************************************
147 * 84 *
148 * FUNCTION: acpi_ut_acquire_from_cache 85 * FUNCTION: acpi_ut_create_caches
149 * 86 *
150 * PARAMETERS: list_id - Memory list ID 87 * PARAMETERS: None
151 * 88 *
152 * RETURN: A requested object. NULL if the object could not be 89 * RETURN: Status
153 * allocated.
154 * 90 *
155 * DESCRIPTION: Get an object from the specified cache. If cache is empty, 91 * DESCRIPTION: Create all local caches
156 * the object is allocated.
157 * 92 *
158 ******************************************************************************/ 93 ******************************************************************************/
159 94
160void * 95acpi_status
161acpi_ut_acquire_from_cache ( 96acpi_ut_create_caches (
162 u32 list_id) 97 void)
163{ 98{
164 struct acpi_memory_list *cache_info; 99 acpi_status status;
165 void *object;
166
167
168 ACPI_FUNCTION_NAME ("ut_acquire_from_cache");
169 100
170 101
171 cache_info = &acpi_gbl_memory_lists[list_id]; 102#ifdef ACPI_DBG_TRACK_ALLOCATIONS
172 103
173#ifdef ACPI_ENABLE_OBJECT_CACHE 104 /* Memory allocation lists */
174 105
175 if (ACPI_FAILURE (acpi_ut_acquire_mutex (ACPI_MTX_CACHES))) { 106 status = acpi_ut_create_list ("Acpi-Global", 0,
176 return (NULL); 107 &acpi_gbl_global_list);
108 if (ACPI_FAILURE (status)) {
109 return (status);
177 } 110 }
178 111
179 ACPI_MEM_TRACKING (cache_info->cache_requests++); 112 status = acpi_ut_create_list ("Acpi-Namespace", sizeof (struct acpi_namespace_node),
180 113 &acpi_gbl_ns_node_list);
181 /* Check the cache first */ 114 if (ACPI_FAILURE (status)) {
182 115 return (status);
183 if (cache_info->list_head) { 116 }
184 /* There is an object available, use it */
185
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 117#endif
197 118
198 if (ACPI_FAILURE (acpi_ut_release_mutex (ACPI_MTX_CACHES))) { 119 /* Object Caches, for frequently used objects */
199 return (NULL);
200 }
201
202 /* Clear (zero) the previously used Object */
203 120
204 ACPI_MEMSET (object, 0, cache_info->object_size); 121 status = acpi_os_create_cache ("acpi_state", sizeof (union acpi_generic_state),
122 ACPI_MAX_STATE_CACHE_DEPTH, &acpi_gbl_state_cache);
123 if (ACPI_FAILURE (status)) {
124 return (status);
205 } 125 }
206 126
207 else { 127 status = acpi_os_create_cache ("acpi_parse", sizeof (struct acpi_parse_obj_common),
208 /* The cache is empty, create a new object */ 128 ACPI_MAX_PARSE_CACHE_DEPTH, &acpi_gbl_ps_node_cache);
209 129 if (ACPI_FAILURE (status)) {
210 /* Avoid deadlock with ACPI_MEM_CALLOCATE */ 130 return (status);
211
212 if (ACPI_FAILURE (acpi_ut_release_mutex (ACPI_MTX_CACHES))) {
213 return (NULL);
214 }
215
216 object = ACPI_MEM_CALLOCATE (cache_info->object_size);
217 ACPI_MEM_TRACKING (cache_info->total_allocated++);
218 } 131 }
219 132
220#else 133 status = acpi_os_create_cache ("acpi_parse_ext", sizeof (struct acpi_parse_obj_named),
221 134 ACPI_MAX_EXTPARSE_CACHE_DEPTH, &acpi_gbl_ps_node_ext_cache);
222 /* Object cache is disabled; just allocate the object */ 135 if (ACPI_FAILURE (status)) {
136 return (status);
137 }
223 138
224 object = ACPI_MEM_CALLOCATE (cache_info->object_size); 139 status = acpi_os_create_cache ("acpi_operand", sizeof (union acpi_operand_object),
225 ACPI_MEM_TRACKING (cache_info->total_allocated++); 140 ACPI_MAX_OBJECT_CACHE_DEPTH, &acpi_gbl_operand_cache);
226#endif 141 if (ACPI_FAILURE (status)) {
142 return (status);
143 }
227 144
228 return (object); 145 return (AE_OK);
229} 146}
230 147
231 148
232#ifdef ACPI_ENABLE_OBJECT_CACHE
233/******************************************************************************* 149/*******************************************************************************
234 * 150 *
235 * FUNCTION: acpi_ut_delete_generic_cache 151 * FUNCTION: acpi_ut_delete_caches
236 * 152 *
237 * PARAMETERS: list_id - Memory list ID 153 * PARAMETERS: None
238 * 154 *
239 * RETURN: None 155 * RETURN: Status
240 * 156 *
241 * DESCRIPTION: Free all objects within the requested cache. 157 * DESCRIPTION: Purge and delete all local caches
242 * 158 *
243 ******************************************************************************/ 159 ******************************************************************************/
244 160
245void 161acpi_status
246acpi_ut_delete_generic_cache ( 162acpi_ut_delete_caches (
247 u32 list_id) 163 void)
248{ 164{
249 struct acpi_memory_list *cache_info;
250 char *next;
251 165
166 (void) acpi_os_delete_cache (acpi_gbl_state_cache);
167 acpi_gbl_state_cache = NULL;
252 168
253 ACPI_FUNCTION_ENTRY (); 169 (void) acpi_os_delete_cache (acpi_gbl_operand_cache);
254 170 acpi_gbl_operand_cache = NULL;
255 171
256 cache_info = &acpi_gbl_memory_lists[list_id]; 172 (void) acpi_os_delete_cache (acpi_gbl_ps_node_cache);
257 while (cache_info->list_head) { 173 acpi_gbl_ps_node_cache = NULL;
258 /* Delete one cached state object */
259 174
260 next = *(ACPI_CAST_INDIRECT_PTR (char, 175 (void) acpi_os_delete_cache (acpi_gbl_ps_node_ext_cache);
261 &(((char *) cache_info->list_head)[cache_info->link_offset]))); 176 acpi_gbl_ps_node_ext_cache = NULL;
262 ACPI_MEM_FREE (cache_info->list_head);
263 177
264 cache_info->list_head = next; 178 return (AE_OK);
265 cache_info->cache_depth--;
266 }
267} 179}
268#endif
269
270 180
271/******************************************************************************* 181/*******************************************************************************
272 * 182 *
@@ -500,6 +410,43 @@ acpi_ut_callocate (
500 * occurs in the body of acpi_ut_free. 410 * occurs in the body of acpi_ut_free.
501 */ 411 */
502 412
413/*******************************************************************************
414 *
415 * FUNCTION: acpi_ut_create_list
416 *
417 * PARAMETERS: cache_name - Ascii name for the cache
418 * object_size - Size of each cached object
419 * return_cache - Where the new cache object is returned
420 *
421 * RETURN: Status
422 *
423 * DESCRIPTION: Create a local memory list for tracking purposed
424 *
425 ******************************************************************************/
426
427static acpi_status
428acpi_ut_create_list (
429 char *list_name,
430 u16 object_size,
431 struct acpi_memory_list **return_cache)
432{
433 struct acpi_memory_list *cache;
434
435
436 cache = acpi_os_allocate (sizeof (struct acpi_memory_list));
437 if (!cache) {
438 return (AE_NO_MEMORY);
439 }
440
441 ACPI_MEMSET (cache, 0, sizeof (struct acpi_memory_list));
442
443 cache->list_name = list_name;
444 cache->object_size = object_size;
445
446 *return_cache = cache;
447 return (AE_OK);
448}
449
503 450
504/******************************************************************************* 451/*******************************************************************************
505 * 452 *
@@ -533,15 +480,15 @@ acpi_ut_allocate_and_track (
533 return (NULL); 480 return (NULL);
534 } 481 }
535 482
536 status = acpi_ut_track_allocation (ACPI_MEM_LIST_GLOBAL, allocation, size, 483 status = acpi_ut_track_allocation (allocation, size,
537 ACPI_MEM_MALLOC, component, module, line); 484 ACPI_MEM_MALLOC, component, module, line);
538 if (ACPI_FAILURE (status)) { 485 if (ACPI_FAILURE (status)) {
539 acpi_os_free (allocation); 486 acpi_os_free (allocation);
540 return (NULL); 487 return (NULL);
541 } 488 }
542 489
543 acpi_gbl_memory_lists[ACPI_MEM_LIST_GLOBAL].total_allocated++; 490 acpi_gbl_global_list->total_allocated++;
544 acpi_gbl_memory_lists[ACPI_MEM_LIST_GLOBAL].current_total_size += (u32) size; 491 acpi_gbl_global_list->current_total_size += (u32) size;
545 492
546 return ((void *) &allocation->user_space); 493 return ((void *) &allocation->user_space);
547} 494}
@@ -583,15 +530,15 @@ acpi_ut_callocate_and_track (
583 return (NULL); 530 return (NULL);
584 } 531 }
585 532
586 status = acpi_ut_track_allocation (ACPI_MEM_LIST_GLOBAL, allocation, size, 533 status = acpi_ut_track_allocation (allocation, size,
587 ACPI_MEM_CALLOC, component, module, line); 534 ACPI_MEM_CALLOC, component, module, line);
588 if (ACPI_FAILURE (status)) { 535 if (ACPI_FAILURE (status)) {
589 acpi_os_free (allocation); 536 acpi_os_free (allocation);
590 return (NULL); 537 return (NULL);
591 } 538 }
592 539
593 acpi_gbl_memory_lists[ACPI_MEM_LIST_GLOBAL].total_allocated++; 540 acpi_gbl_global_list->total_allocated++;
594 acpi_gbl_memory_lists[ACPI_MEM_LIST_GLOBAL].current_total_size += (u32) size; 541 acpi_gbl_global_list->current_total_size += (u32) size;
595 542
596 return ((void *) &allocation->user_space); 543 return ((void *) &allocation->user_space);
597} 544}
@@ -636,10 +583,10 @@ acpi_ut_free_and_track (
636 debug_block = ACPI_CAST_PTR (struct acpi_debug_mem_block, 583 debug_block = ACPI_CAST_PTR (struct acpi_debug_mem_block,
637 (((char *) allocation) - sizeof (struct acpi_debug_mem_header))); 584 (((char *) allocation) - sizeof (struct acpi_debug_mem_header)));
638 585
639 acpi_gbl_memory_lists[ACPI_MEM_LIST_GLOBAL].total_freed++; 586 acpi_gbl_global_list->total_freed++;
640 acpi_gbl_memory_lists[ACPI_MEM_LIST_GLOBAL].current_total_size -= debug_block->size; 587 acpi_gbl_global_list->current_total_size -= debug_block->size;
641 588
642 status = acpi_ut_remove_allocation (ACPI_MEM_LIST_GLOBAL, debug_block, 589 status = acpi_ut_remove_allocation (debug_block,
643 component, module, line); 590 component, module, line);
644 if (ACPI_FAILURE (status)) { 591 if (ACPI_FAILURE (status)) {
645 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Could not free memory, %s\n", 592 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Could not free memory, %s\n",
@@ -658,8 +605,7 @@ acpi_ut_free_and_track (
658 * 605 *
659 * FUNCTION: acpi_ut_find_allocation 606 * FUNCTION: acpi_ut_find_allocation
660 * 607 *
661 * PARAMETERS: list_id - Memory list to search 608 * PARAMETERS: Allocation - Address of allocated memory
662 * Allocation - Address of allocated memory
663 * 609 *
664 * RETURN: A list element if found; NULL otherwise. 610 * RETURN: A list element if found; NULL otherwise.
665 * 611 *
@@ -669,7 +615,6 @@ acpi_ut_free_and_track (
669 615
670static struct acpi_debug_mem_block * 616static struct acpi_debug_mem_block *
671acpi_ut_find_allocation ( 617acpi_ut_find_allocation (
672 u32 list_id,
673 void *allocation) 618 void *allocation)
674{ 619{
675 struct acpi_debug_mem_block *element; 620 struct acpi_debug_mem_block *element;
@@ -678,11 +623,7 @@ acpi_ut_find_allocation (
678 ACPI_FUNCTION_ENTRY (); 623 ACPI_FUNCTION_ENTRY ();
679 624
680 625
681 if (list_id > ACPI_MEM_LIST_MAX) { 626 element = acpi_gbl_global_list->list_head;
682 return (NULL);
683 }
684
685 element = acpi_gbl_memory_lists[list_id].list_head;
686 627
687 /* Search for the address. */ 628 /* Search for the address. */
688 629
@@ -702,8 +643,7 @@ acpi_ut_find_allocation (
702 * 643 *
703 * FUNCTION: acpi_ut_track_allocation 644 * FUNCTION: acpi_ut_track_allocation
704 * 645 *
705 * PARAMETERS: list_id - Memory list to search 646 * PARAMETERS: Allocation - Address of allocated memory
706 * Allocation - Address of allocated memory
707 * Size - Size of the allocation 647 * Size - Size of the allocation
708 * alloc_type - MEM_MALLOC or MEM_CALLOC 648 * alloc_type - MEM_MALLOC or MEM_CALLOC
709 * Component - Component type of caller 649 * Component - Component type of caller
@@ -718,7 +658,6 @@ acpi_ut_find_allocation (
718 658
719static acpi_status 659static acpi_status
720acpi_ut_track_allocation ( 660acpi_ut_track_allocation (
721 u32 list_id,
722 struct acpi_debug_mem_block *allocation, 661 struct acpi_debug_mem_block *allocation,
723 acpi_size size, 662 acpi_size size,
724 u8 alloc_type, 663 u8 alloc_type,
@@ -734,11 +673,7 @@ acpi_ut_track_allocation (
734 ACPI_FUNCTION_TRACE_PTR ("ut_track_allocation", allocation); 673 ACPI_FUNCTION_TRACE_PTR ("ut_track_allocation", allocation);
735 674
736 675
737 if (list_id > ACPI_MEM_LIST_MAX) { 676 mem_list = acpi_gbl_global_list;
738 return_ACPI_STATUS (AE_BAD_PARAMETER);
739 }
740
741 mem_list = &acpi_gbl_memory_lists[list_id];
742 status = acpi_ut_acquire_mutex (ACPI_MTX_MEMORY); 677 status = acpi_ut_acquire_mutex (ACPI_MTX_MEMORY);
743 if (ACPI_FAILURE (status)) { 678 if (ACPI_FAILURE (status)) {
744 return_ACPI_STATUS (status); 679 return_ACPI_STATUS (status);
@@ -748,8 +683,7 @@ acpi_ut_track_allocation (
748 * Search list for this address to make sure it is not already on the list. 683 * Search list for this address to make sure it is not already on the list.
749 * This will catch several kinds of problems. 684 * This will catch several kinds of problems.
750 */ 685 */
751 686 element = acpi_ut_find_allocation (allocation);
752 element = acpi_ut_find_allocation (list_id, allocation);
753 if (element) { 687 if (element) {
754 ACPI_REPORT_ERROR (( 688 ACPI_REPORT_ERROR ((
755 "ut_track_allocation: Allocation already present in list! (%p)\n", 689 "ut_track_allocation: Allocation already present in list! (%p)\n",
@@ -793,8 +727,7 @@ unlock_and_exit:
793 * 727 *
794 * FUNCTION: acpi_ut_remove_allocation 728 * FUNCTION: acpi_ut_remove_allocation
795 * 729 *
796 * PARAMETERS: list_id - Memory list to search 730 * PARAMETERS: Allocation - Address of allocated memory
797 * Allocation - Address of allocated memory
798 * Component - Component type of caller 731 * Component - Component type of caller
799 * Module - Source file name of caller 732 * Module - Source file name of caller
800 * Line - Line number of caller 733 * Line - Line number of caller
@@ -807,7 +740,6 @@ unlock_and_exit:
807 740
808static acpi_status 741static acpi_status
809acpi_ut_remove_allocation ( 742acpi_ut_remove_allocation (
810 u32 list_id,
811 struct acpi_debug_mem_block *allocation, 743 struct acpi_debug_mem_block *allocation,
812 u32 component, 744 u32 component,
813 char *module, 745 char *module,
@@ -820,11 +752,7 @@ acpi_ut_remove_allocation (
820 ACPI_FUNCTION_TRACE ("ut_remove_allocation"); 752 ACPI_FUNCTION_TRACE ("ut_remove_allocation");
821 753
822 754
823 if (list_id > ACPI_MEM_LIST_MAX) { 755 mem_list = acpi_gbl_global_list;
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) { 756 if (NULL == mem_list->list_head) {
829 /* No allocations! */ 757 /* No allocations! */
830 758
@@ -959,7 +887,7 @@ acpi_ut_dump_allocations (
959 return; 887 return;
960 } 888 }
961 889
962 element = acpi_gbl_memory_lists[0].list_head; 890 element = acpi_gbl_global_list->list_head;
963 while (element) { 891 while (element) {
964 if ((element->component & component) && 892 if ((element->component & component) &&
965 ((module == NULL) || (0 == ACPI_STRCMP (module, element->module)))) { 893 ((module == NULL) || (0 == ACPI_STRCMP (module, element->module)))) {
diff --git a/drivers/acpi/utilities/utcache.c b/drivers/acpi/utilities/utcache.c
new file mode 100644
index 000000000000..c0df0585c683
--- /dev/null
+++ b/drivers/acpi/utilities/utcache.c
@@ -0,0 +1,328 @@
1/******************************************************************************
2 *
3 * Module Name: utcache - local cache allocation routines
4 *
5 *****************************************************************************/
6
7/*
8 * Copyright (C) 2000 - 2005, R. Byron Moore
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#include <acpi/acpi.h>
46
47#define _COMPONENT ACPI_UTILITIES
48 ACPI_MODULE_NAME ("utcache")
49
50
51#ifdef ACPI_USE_LOCAL_CACHE
52/*******************************************************************************
53 *
54 * FUNCTION: acpi_os_create_cache
55 *
56 * PARAMETERS: cache_name - Ascii name for the cache
57 * object_size - Size of each cached object
58 * max_depth - Maximum depth of the cache (in objects)
59 * return_cache - Where the new cache object is returned
60 *
61 * RETURN: Status
62 *
63 * DESCRIPTION: Create a cache object
64 *
65 ******************************************************************************/
66
67acpi_status
68acpi_os_create_cache (
69 char *cache_name,
70 u16 object_size,
71 u16 max_depth,
72 struct acpi_memory_list **return_cache)
73{
74 struct acpi_memory_list *cache;
75
76
77 ACPI_FUNCTION_ENTRY ();
78
79
80 if (!cache_name || !return_cache || (object_size < 16)) {
81 return (AE_BAD_PARAMETER);
82 }
83
84 /* Create the cache object */
85
86 cache = acpi_os_allocate (sizeof (struct acpi_memory_list));
87 if (!cache) {
88 return (AE_NO_MEMORY);
89 }
90
91 /* Populate the cache object and return it */
92
93 ACPI_MEMSET (cache, 0, sizeof (struct acpi_memory_list));
94 cache->link_offset = 8;
95 cache->list_name = cache_name;
96 cache->object_size = object_size;
97 cache->max_depth = max_depth;
98
99 *return_cache = cache;
100 return (AE_OK);
101}
102
103
104/*******************************************************************************
105 *
106 * FUNCTION: acpi_os_purge_cache
107 *
108 * PARAMETERS: Cache - Handle to cache object
109 *
110 * RETURN: Status
111 *
112 * DESCRIPTION: Free all objects within the requested cache.
113 *
114 ******************************************************************************/
115
116acpi_status
117acpi_os_purge_cache (
118 struct acpi_memory_list *cache)
119{
120 char *next;
121
122
123 ACPI_FUNCTION_ENTRY ();
124
125
126 if (!cache) {
127 return (AE_BAD_PARAMETER);
128 }
129
130 /* Walk the list of objects in this cache */
131
132 while (cache->list_head) {
133 /* Delete and unlink one cached state object */
134
135 next = *(ACPI_CAST_INDIRECT_PTR (char,
136 &(((char *) cache->list_head)[cache->link_offset])));
137 ACPI_MEM_FREE (cache->list_head);
138
139 cache->list_head = next;
140 cache->current_depth--;
141 }
142
143 return (AE_OK);
144}
145
146
147/*******************************************************************************
148 *
149 * FUNCTION: acpi_os_delete_cache
150 *
151 * PARAMETERS: Cache - Handle to cache object
152 *
153 * RETURN: Status
154 *
155 * DESCRIPTION: Free all objects within the requested cache and delete the
156 * cache object.
157 *
158 ******************************************************************************/
159
160acpi_status
161acpi_os_delete_cache (
162 struct acpi_memory_list *cache)
163{
164 acpi_status status;
165
166
167 ACPI_FUNCTION_ENTRY ();
168
169
170 /* Purge all objects in the cache */
171
172 status = acpi_os_purge_cache (cache);
173 if (ACPI_FAILURE (status)) {
174 return (status);
175 }
176
177 /* Now we can delete the cache object */
178
179 acpi_os_free (cache);
180 return (AE_OK);
181}
182
183
184/*******************************************************************************
185 *
186 * FUNCTION: acpi_os_release_object
187 *
188 * PARAMETERS: Cache - Handle to cache object
189 * Object - The object to be released
190 *
191 * RETURN: None
192 *
193 * DESCRIPTION: Release an object to the specified cache. If cache is full,
194 * the object is deleted.
195 *
196 ******************************************************************************/
197
198acpi_status
199acpi_os_release_object (
200 struct acpi_memory_list *cache,
201 void *object)
202{
203 acpi_status status;
204
205
206 ACPI_FUNCTION_ENTRY ();
207
208
209 if (!cache || !object) {
210 return (AE_BAD_PARAMETER);
211 }
212
213 /* If cache is full, just free this object */
214
215 if (cache->current_depth >= cache->max_depth) {
216 ACPI_MEM_FREE (object);
217 ACPI_MEM_TRACKING (cache->total_freed++);
218 }
219
220 /* Otherwise put this object back into the cache */
221
222 else {
223 status = acpi_ut_acquire_mutex (ACPI_MTX_CACHES);
224 if (ACPI_FAILURE (status)) {
225 return (status);
226 }
227
228 /* Mark the object as cached */
229
230 ACPI_MEMSET (object, 0xCA, cache->object_size);
231 ACPI_SET_DESCRIPTOR_TYPE (object, ACPI_DESC_TYPE_CACHED);
232
233 /* Put the object at the head of the cache list */
234
235 * (ACPI_CAST_INDIRECT_PTR (char,
236 &(((char *) object)[cache->link_offset]))) = cache->list_head;
237 cache->list_head = object;
238 cache->current_depth++;
239
240 (void) acpi_ut_release_mutex (ACPI_MTX_CACHES);
241 }
242
243 return (AE_OK);
244}
245
246
247/*******************************************************************************
248 *
249 * FUNCTION: acpi_os_acquire_object
250 *
251 * PARAMETERS: Cache - Handle to cache object
252 *
253 * RETURN: the acquired object. NULL on error
254 *
255 * DESCRIPTION: Get an object from the specified cache. If cache is empty,
256 * the object is allocated.
257 *
258 ******************************************************************************/
259
260void *
261acpi_os_acquire_object (
262 struct acpi_memory_list *cache)
263{
264 acpi_status status;
265 void *object;
266
267
268 ACPI_FUNCTION_NAME ("os_acquire_object");
269
270
271 if (!cache) {
272 return (NULL);
273 }
274
275 status = acpi_ut_acquire_mutex (ACPI_MTX_CACHES);
276 if (ACPI_FAILURE (status)) {
277 return (NULL);
278 }
279
280 ACPI_MEM_TRACKING (cache->requests++);
281
282 /* Check the cache first */
283
284 if (cache->list_head) {
285 /* There is an object available, use it */
286
287 object = cache->list_head;
288 cache->list_head = *(ACPI_CAST_INDIRECT_PTR (char,
289 &(((char *) object)[cache->link_offset])));
290
291 cache->current_depth--;
292
293 ACPI_MEM_TRACKING (cache->hits++);
294 ACPI_MEM_TRACKING (ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
295 "Object %p from %s cache\n", object, cache->list_name)));
296
297 status = acpi_ut_release_mutex (ACPI_MTX_CACHES);
298 if (ACPI_FAILURE (status)) {
299 return (NULL);
300 }
301
302 /* Clear (zero) the previously used Object */
303
304 ACPI_MEMSET (object, 0, cache->object_size);
305 }
306 else {
307 /* The cache is empty, create a new object */
308
309 ACPI_MEM_TRACKING (cache->total_allocated++);
310
311 /* Avoid deadlock with ACPI_MEM_CALLOCATE */
312
313 status = acpi_ut_release_mutex (ACPI_MTX_CACHES);
314 if (ACPI_FAILURE (status)) {
315 return (NULL);
316 }
317
318 object = ACPI_MEM_CALLOCATE (cache->object_size);
319 if (!object) {
320 return (NULL);
321 }
322 }
323
324 return (object);
325}
326#endif /* ACPI_USE_LOCAL_CACHE */
327
328
diff --git a/drivers/acpi/utilities/utcopy.c b/drivers/acpi/utilities/utcopy.c
index 11e884957162..31c30a32e5c9 100644
--- a/drivers/acpi/utilities/utcopy.c
+++ b/drivers/acpi/utilities/utcopy.c
@@ -694,58 +694,50 @@ acpi_ut_copy_simple_object (
694 dest_desc->common.reference_count = reference_count; 694 dest_desc->common.reference_count = reference_count;
695 dest_desc->common.next_object = next_object; 695 dest_desc->common.next_object = next_object;
696 696
697 /* New object is not static, regardless of source */
698
699 dest_desc->common.flags &= ~AOPOBJ_STATIC_POINTER;
700
697 /* Handle the objects with extra data */ 701 /* Handle the objects with extra data */
698 702
699 switch (ACPI_GET_OBJECT_TYPE (dest_desc)) { 703 switch (ACPI_GET_OBJECT_TYPE (dest_desc)) {
700 case ACPI_TYPE_BUFFER: 704 case ACPI_TYPE_BUFFER:
701
702 dest_desc->buffer.node = NULL;
703 dest_desc->common.flags = source_desc->common.flags;
704
705 /* 705 /*
706 * Allocate and copy the actual buffer if and only if: 706 * Allocate and copy the actual buffer if and only if:
707 * 1) There is a valid buffer pointer 707 * 1) There is a valid buffer pointer
708 * 2) The buffer is not static (not in an ACPI table) (in this case, 708 * 2) The buffer has a length > 0
709 * the actual pointer was already copied above)
710 */ 709 */
711 if ((source_desc->buffer.pointer) && 710 if ((source_desc->buffer.pointer) &&
712 (!(source_desc->common.flags & AOPOBJ_STATIC_POINTER))) { 711 (source_desc->buffer.length)) {
713 dest_desc->buffer.pointer = NULL; 712 dest_desc->buffer.pointer =
714 713 ACPI_MEM_ALLOCATE (source_desc->buffer.length);
715 /* Create an actual buffer only if length > 0 */ 714 if (!dest_desc->buffer.pointer) {
716 715 return (AE_NO_MEMORY);
717 if (source_desc->buffer.length) { 716 }
718 dest_desc->buffer.pointer =
719 ACPI_MEM_ALLOCATE (source_desc->buffer.length);
720 if (!dest_desc->buffer.pointer) {
721 return (AE_NO_MEMORY);
722 }
723 717
724 /* Copy the actual buffer data */ 718 /* Copy the actual buffer data */
725 719
726 ACPI_MEMCPY (dest_desc->buffer.pointer, 720 ACPI_MEMCPY (dest_desc->buffer.pointer,
727 source_desc->buffer.pointer, 721 source_desc->buffer.pointer,
728 source_desc->buffer.length); 722 source_desc->buffer.length);
729 }
730 } 723 }
731 break; 724 break;
732 725
733 case ACPI_TYPE_STRING: 726 case ACPI_TYPE_STRING:
734
735 /* 727 /*
736 * Allocate and copy the actual string if and only if: 728 * Allocate and copy the actual string if and only if:
737 * 1) There is a valid string pointer 729 * 1) There is a valid string pointer
738 * 2) The string is not static (not in an ACPI table) (in this case, 730 * (Pointer to a NULL string is allowed)
739 * the actual pointer was already copied above)
740 */ 731 */
741 if ((source_desc->string.pointer) && 732 if (source_desc->string.pointer) {
742 (!(source_desc->common.flags & AOPOBJ_STATIC_POINTER))) {
743 dest_desc->string.pointer = 733 dest_desc->string.pointer =
744 ACPI_MEM_ALLOCATE ((acpi_size) source_desc->string.length + 1); 734 ACPI_MEM_ALLOCATE ((acpi_size) source_desc->string.length + 1);
745 if (!dest_desc->string.pointer) { 735 if (!dest_desc->string.pointer) {
746 return (AE_NO_MEMORY); 736 return (AE_NO_MEMORY);
747 } 737 }
748 738
739 /* Copy the actual string data */
740
749 ACPI_MEMCPY (dest_desc->string.pointer, source_desc->string.pointer, 741 ACPI_MEMCPY (dest_desc->string.pointer, source_desc->string.pointer,
750 (acpi_size) source_desc->string.length + 1); 742 (acpi_size) source_desc->string.length + 1);
751 } 743 }
diff --git a/drivers/acpi/utilities/utdebug.c b/drivers/acpi/utilities/utdebug.c
index 794c7df3f2ad..c27cbb7f5c54 100644
--- a/drivers/acpi/utilities/utdebug.c
+++ b/drivers/acpi/utilities/utdebug.c
@@ -55,6 +55,12 @@ static u32 acpi_gbl_prev_thread_id = 0xFFFFFFFF;
55static char *acpi_gbl_fn_entry_str = "----Entry"; 55static char *acpi_gbl_fn_entry_str = "----Entry";
56static char *acpi_gbl_fn_exit_str = "----Exit-"; 56static char *acpi_gbl_fn_exit_str = "----Exit-";
57 57
58/* Local prototypes */
59
60static const char *
61acpi_ut_trim_function_name (
62 const char *function_name);
63
58 64
59/******************************************************************************* 65/*******************************************************************************
60 * 66 *
@@ -72,7 +78,7 @@ void
72acpi_ut_init_stack_ptr_trace ( 78acpi_ut_init_stack_ptr_trace (
73 void) 79 void)
74{ 80{
75 u32 current_sp; 81 u32 current_sp;
76 82
77 83
78 acpi_gbl_entry_stack_pointer = ACPI_PTR_DIFF (&current_sp, NULL); 84 acpi_gbl_entry_stack_pointer = ACPI_PTR_DIFF (&current_sp, NULL);
@@ -95,7 +101,7 @@ void
95acpi_ut_track_stack_ptr ( 101acpi_ut_track_stack_ptr (
96 void) 102 void)
97{ 103{
98 acpi_size current_sp; 104 acpi_size current_sp;
99 105
100 106
101 current_sp = ACPI_PTR_DIFF (&current_sp, NULL); 107 current_sp = ACPI_PTR_DIFF (&current_sp, NULL);
@@ -112,14 +118,50 @@ acpi_ut_track_stack_ptr (
112 118
113/******************************************************************************* 119/*******************************************************************************
114 * 120 *
121 * FUNCTION: acpi_ut_trim_function_name
122 *
123 * PARAMETERS: function_name - Ascii string containing a procedure name
124 *
125 * RETURN: Updated pointer to the function name
126 *
127 * DESCRIPTION: Remove the "Acpi" prefix from the function name, if present.
128 * This allows compiler macros such as __FUNCTION__ to be used
129 * with no change to the debug output.
130 *
131 ******************************************************************************/
132
133static const char *
134acpi_ut_trim_function_name (
135 const char *function_name)
136{
137
138 /* All Function names are longer than 4 chars, check is safe */
139
140 if (*(ACPI_CAST_PTR (u32, function_name)) == ACPI_FUNCTION_PREFIX1) {
141 /* This is the case where the original source has not been modified */
142
143 return (function_name + 4);
144 }
145
146 if (*(ACPI_CAST_PTR (u32, function_name)) == ACPI_FUNCTION_PREFIX2) {
147 /* This is the case where the source has been 'linuxized' */
148
149 return (function_name + 5);
150 }
151
152 return (function_name);
153}
154
155
156/*******************************************************************************
157 *
115 * FUNCTION: acpi_ut_debug_print 158 * FUNCTION: acpi_ut_debug_print
116 * 159 *
117 * PARAMETERS: requested_debug_level - Requested debug print level 160 * PARAMETERS: requested_debug_level - Requested debug print level
118 * line_number - Caller's line number (for error output) 161 * line_number - Caller's line number (for error output)
119 * dbg_info - Contains: 162 * function_name - Caller's procedure name
120 * proc_name - Caller's procedure name 163 * module_name - Caller's module name
121 * module_name - Caller's module name 164 * component_id - Caller's component ID
122 * component_id - Caller's component ID
123 * Format - Printf format field 165 * Format - Printf format field
124 * ... - Optional printf arguments 166 * ... - Optional printf arguments
125 * 167 *
@@ -134,7 +176,9 @@ void ACPI_INTERNAL_VAR_XFACE
134acpi_ut_debug_print ( 176acpi_ut_debug_print (
135 u32 requested_debug_level, 177 u32 requested_debug_level,
136 u32 line_number, 178 u32 line_number,
137 struct acpi_debug_print_info *dbg_info, 179 const char *function_name,
180 char *module_name,
181 u32 component_id,
138 char *format, 182 char *format,
139 ...) 183 ...)
140{ 184{
@@ -146,7 +190,7 @@ acpi_ut_debug_print (
146 * Stay silent if the debug level or component ID is disabled 190 * Stay silent if the debug level or component ID is disabled
147 */ 191 */
148 if (!(requested_debug_level & acpi_dbg_level) || 192 if (!(requested_debug_level & acpi_dbg_level) ||
149 !(dbg_info->component_id & acpi_dbg_layer)) { 193 !(component_id & acpi_dbg_layer)) {
150 return; 194 return;
151 } 195 }
152 196
@@ -169,14 +213,14 @@ acpi_ut_debug_print (
169 * Display the module name, current line number, thread ID (if requested), 213 * Display the module name, current line number, thread ID (if requested),
170 * current procedure nesting level, and the current procedure name 214 * current procedure nesting level, and the current procedure name
171 */ 215 */
172 acpi_os_printf ("%8s-%04ld ", dbg_info->module_name, line_number); 216 acpi_os_printf ("%8s-%04ld ", module_name, line_number);
173 217
174 if (ACPI_LV_THREADS & acpi_dbg_level) { 218 if (ACPI_LV_THREADS & acpi_dbg_level) {
175 acpi_os_printf ("[%04lX] ", thread_id); 219 acpi_os_printf ("[%04lX] ", thread_id);
176 } 220 }
177 221
178 acpi_os_printf ("[%02ld] %-22.22s: ", 222 acpi_os_printf ("[%02ld] %-22.22s: ",
179 acpi_gbl_nesting_level, dbg_info->proc_name); 223 acpi_gbl_nesting_level, acpi_ut_trim_function_name (function_name));
180 224
181 va_start (args, format); 225 va_start (args, format);
182 acpi_os_vprintf (format, args); 226 acpi_os_vprintf (format, args);
@@ -190,10 +234,9 @@ EXPORT_SYMBOL(acpi_ut_debug_print);
190 * 234 *
191 * PARAMETERS: requested_debug_level - Requested debug print level 235 * PARAMETERS: requested_debug_level - Requested debug print level
192 * line_number - Caller's line number 236 * line_number - Caller's line number
193 * dbg_info - Contains: 237 * function_name - Caller's procedure name
194 * proc_name - Caller's procedure name 238 * module_name - Caller's module name
195 * module_name - Caller's module name 239 * component_id - Caller's component ID
196 * component_id - Caller's component ID
197 * Format - Printf format field 240 * Format - Printf format field
198 * ... - Optional printf arguments 241 * ... - Optional printf arguments
199 * 242 *
@@ -208,7 +251,9 @@ void ACPI_INTERNAL_VAR_XFACE
208acpi_ut_debug_print_raw ( 251acpi_ut_debug_print_raw (
209 u32 requested_debug_level, 252 u32 requested_debug_level,
210 u32 line_number, 253 u32 line_number,
211 struct acpi_debug_print_info *dbg_info, 254 const char *function_name,
255 char *module_name,
256 u32 component_id,
212 char *format, 257 char *format,
213 ...) 258 ...)
214{ 259{
@@ -216,7 +261,7 @@ acpi_ut_debug_print_raw (
216 261
217 262
218 if (!(requested_debug_level & acpi_dbg_level) || 263 if (!(requested_debug_level & acpi_dbg_level) ||
219 !(dbg_info->component_id & acpi_dbg_layer)) { 264 !(component_id & acpi_dbg_layer)) {
220 return; 265 return;
221 } 266 }
222 267
@@ -231,10 +276,9 @@ EXPORT_SYMBOL(acpi_ut_debug_print_raw);
231 * FUNCTION: acpi_ut_trace 276 * FUNCTION: acpi_ut_trace
232 * 277 *
233 * PARAMETERS: line_number - Caller's line number 278 * PARAMETERS: line_number - Caller's line number
234 * dbg_info - Contains: 279 * function_name - Caller's procedure name
235 * proc_name - Caller's procedure name 280 * module_name - Caller's module name
236 * module_name - Caller's module name 281 * component_id - Caller's component ID
237 * component_id - Caller's component ID
238 * 282 *
239 * RETURN: None 283 * RETURN: None
240 * 284 *
@@ -246,14 +290,17 @@ EXPORT_SYMBOL(acpi_ut_debug_print_raw);
246void 290void
247acpi_ut_trace ( 291acpi_ut_trace (
248 u32 line_number, 292 u32 line_number,
249 struct acpi_debug_print_info *dbg_info) 293 const char *function_name,
294 char *module_name,
295 u32 component_id)
250{ 296{
251 297
252 acpi_gbl_nesting_level++; 298 acpi_gbl_nesting_level++;
253 acpi_ut_track_stack_ptr (); 299 acpi_ut_track_stack_ptr ();
254 300
255 acpi_ut_debug_print (ACPI_LV_FUNCTIONS, line_number, dbg_info, 301 acpi_ut_debug_print (ACPI_LV_FUNCTIONS,
256 "%s\n", acpi_gbl_fn_entry_str); 302 line_number, function_name, module_name, component_id,
303 "%s\n", acpi_gbl_fn_entry_str);
257} 304}
258EXPORT_SYMBOL(acpi_ut_trace); 305EXPORT_SYMBOL(acpi_ut_trace);
259 306
@@ -263,10 +310,9 @@ EXPORT_SYMBOL(acpi_ut_trace);
263 * FUNCTION: acpi_ut_trace_ptr 310 * FUNCTION: acpi_ut_trace_ptr
264 * 311 *
265 * PARAMETERS: line_number - Caller's line number 312 * PARAMETERS: line_number - Caller's line number
266 * dbg_info - Contains: 313 * function_name - Caller's procedure name
267 * proc_name - Caller's procedure name 314 * module_name - Caller's module name
268 * module_name - Caller's module name 315 * component_id - Caller's component ID
269 * component_id - Caller's component ID
270 * Pointer - Pointer to display 316 * Pointer - Pointer to display
271 * 317 *
272 * RETURN: None 318 * RETURN: None
@@ -279,14 +325,17 @@ EXPORT_SYMBOL(acpi_ut_trace);
279void 325void
280acpi_ut_trace_ptr ( 326acpi_ut_trace_ptr (
281 u32 line_number, 327 u32 line_number,
282 struct acpi_debug_print_info *dbg_info, 328 const char *function_name,
329 char *module_name,
330 u32 component_id,
283 void *pointer) 331 void *pointer)
284{ 332{
285 acpi_gbl_nesting_level++; 333 acpi_gbl_nesting_level++;
286 acpi_ut_track_stack_ptr (); 334 acpi_ut_track_stack_ptr ();
287 335
288 acpi_ut_debug_print (ACPI_LV_FUNCTIONS, line_number, dbg_info, 336 acpi_ut_debug_print (ACPI_LV_FUNCTIONS,
289 "%s %p\n", acpi_gbl_fn_entry_str, pointer); 337 line_number, function_name, module_name, component_id,
338 "%s %p\n", acpi_gbl_fn_entry_str, pointer);
290} 339}
291 340
292 341
@@ -295,10 +344,9 @@ acpi_ut_trace_ptr (
295 * FUNCTION: acpi_ut_trace_str 344 * FUNCTION: acpi_ut_trace_str
296 * 345 *
297 * PARAMETERS: line_number - Caller's line number 346 * PARAMETERS: line_number - Caller's line number
298 * dbg_info - Contains: 347 * function_name - Caller's procedure name
299 * proc_name - Caller's procedure name 348 * module_name - Caller's module name
300 * module_name - Caller's module name 349 * component_id - Caller's component ID
301 * component_id - Caller's component ID
302 * String - Additional string to display 350 * String - Additional string to display
303 * 351 *
304 * RETURN: None 352 * RETURN: None
@@ -311,15 +359,18 @@ acpi_ut_trace_ptr (
311void 359void
312acpi_ut_trace_str ( 360acpi_ut_trace_str (
313 u32 line_number, 361 u32 line_number,
314 struct acpi_debug_print_info *dbg_info, 362 const char *function_name,
363 char *module_name,
364 u32 component_id,
315 char *string) 365 char *string)
316{ 366{
317 367
318 acpi_gbl_nesting_level++; 368 acpi_gbl_nesting_level++;
319 acpi_ut_track_stack_ptr (); 369 acpi_ut_track_stack_ptr ();
320 370
321 acpi_ut_debug_print (ACPI_LV_FUNCTIONS, line_number, dbg_info, 371 acpi_ut_debug_print (ACPI_LV_FUNCTIONS,
322 "%s %s\n", acpi_gbl_fn_entry_str, string); 372 line_number, function_name, module_name, component_id,
373 "%s %s\n", acpi_gbl_fn_entry_str, string);
323} 374}
324 375
325 376
@@ -328,10 +379,9 @@ acpi_ut_trace_str (
328 * FUNCTION: acpi_ut_trace_u32 379 * FUNCTION: acpi_ut_trace_u32
329 * 380 *
330 * PARAMETERS: line_number - Caller's line number 381 * PARAMETERS: line_number - Caller's line number
331 * dbg_info - Contains: 382 * function_name - Caller's procedure name
332 * proc_name - Caller's procedure name 383 * module_name - Caller's module name
333 * module_name - Caller's module name 384 * component_id - Caller's component ID
334 * component_id - Caller's component ID
335 * Integer - Integer to display 385 * Integer - Integer to display
336 * 386 *
337 * RETURN: None 387 * RETURN: None
@@ -344,15 +394,18 @@ acpi_ut_trace_str (
344void 394void
345acpi_ut_trace_u32 ( 395acpi_ut_trace_u32 (
346 u32 line_number, 396 u32 line_number,
347 struct acpi_debug_print_info *dbg_info, 397 const char *function_name,
398 char *module_name,
399 u32 component_id,
348 u32 integer) 400 u32 integer)
349{ 401{
350 402
351 acpi_gbl_nesting_level++; 403 acpi_gbl_nesting_level++;
352 acpi_ut_track_stack_ptr (); 404 acpi_ut_track_stack_ptr ();
353 405
354 acpi_ut_debug_print (ACPI_LV_FUNCTIONS, line_number, dbg_info, 406 acpi_ut_debug_print (ACPI_LV_FUNCTIONS,
355 "%s %08X\n", acpi_gbl_fn_entry_str, integer); 407 line_number, function_name, module_name, component_id,
408 "%s %08X\n", acpi_gbl_fn_entry_str, integer);
356} 409}
357 410
358 411
@@ -361,10 +414,9 @@ acpi_ut_trace_u32 (
361 * FUNCTION: acpi_ut_exit 414 * FUNCTION: acpi_ut_exit
362 * 415 *
363 * PARAMETERS: line_number - Caller's line number 416 * PARAMETERS: line_number - Caller's line number
364 * dbg_info - Contains: 417 * function_name - Caller's procedure name
365 * proc_name - Caller's procedure name 418 * module_name - Caller's module name
366 * module_name - Caller's module name 419 * component_id - Caller's component ID
367 * component_id - Caller's component ID
368 * 420 *
369 * RETURN: None 421 * RETURN: None
370 * 422 *
@@ -376,11 +428,14 @@ acpi_ut_trace_u32 (
376void 428void
377acpi_ut_exit ( 429acpi_ut_exit (
378 u32 line_number, 430 u32 line_number,
379 struct acpi_debug_print_info *dbg_info) 431 const char *function_name,
432 char *module_name,
433 u32 component_id)
380{ 434{
381 435
382 acpi_ut_debug_print (ACPI_LV_FUNCTIONS, line_number, dbg_info, 436 acpi_ut_debug_print (ACPI_LV_FUNCTIONS,
383 "%s\n", acpi_gbl_fn_exit_str); 437 line_number, function_name, module_name, component_id,
438 "%s\n", acpi_gbl_fn_exit_str);
384 439
385 acpi_gbl_nesting_level--; 440 acpi_gbl_nesting_level--;
386} 441}
@@ -392,10 +447,9 @@ EXPORT_SYMBOL(acpi_ut_exit);
392 * FUNCTION: acpi_ut_status_exit 447 * FUNCTION: acpi_ut_status_exit
393 * 448 *
394 * PARAMETERS: line_number - Caller's line number 449 * PARAMETERS: line_number - Caller's line number
395 * dbg_info - Contains: 450 * function_name - Caller's procedure name
396 * proc_name - Caller's procedure name 451 * module_name - Caller's module name
397 * module_name - Caller's module name 452 * component_id - Caller's component ID
398 * component_id - Caller's component ID
399 * Status - Exit status code 453 * Status - Exit status code
400 * 454 *
401 * RETURN: None 455 * RETURN: None
@@ -408,19 +462,23 @@ EXPORT_SYMBOL(acpi_ut_exit);
408void 462void
409acpi_ut_status_exit ( 463acpi_ut_status_exit (
410 u32 line_number, 464 u32 line_number,
411 struct acpi_debug_print_info *dbg_info, 465 const char *function_name,
466 char *module_name,
467 u32 component_id,
412 acpi_status status) 468 acpi_status status)
413{ 469{
414 470
415 if (ACPI_SUCCESS (status)) { 471 if (ACPI_SUCCESS (status)) {
416 acpi_ut_debug_print (ACPI_LV_FUNCTIONS, line_number, dbg_info, 472 acpi_ut_debug_print (ACPI_LV_FUNCTIONS,
417 "%s %s\n", acpi_gbl_fn_exit_str, 473 line_number, function_name, module_name, component_id,
418 acpi_format_exception (status)); 474 "%s %s\n", acpi_gbl_fn_exit_str,
475 acpi_format_exception (status));
419 } 476 }
420 else { 477 else {
421 acpi_ut_debug_print (ACPI_LV_FUNCTIONS, line_number, dbg_info, 478 acpi_ut_debug_print (ACPI_LV_FUNCTIONS,
422 "%s ****Exception****: %s\n", acpi_gbl_fn_exit_str, 479 line_number, function_name, module_name, component_id,
423 acpi_format_exception (status)); 480 "%s ****Exception****: %s\n", acpi_gbl_fn_exit_str,
481 acpi_format_exception (status));
424 } 482 }
425 483
426 acpi_gbl_nesting_level--; 484 acpi_gbl_nesting_level--;
@@ -433,10 +491,9 @@ EXPORT_SYMBOL(acpi_ut_status_exit);
433 * FUNCTION: acpi_ut_value_exit 491 * FUNCTION: acpi_ut_value_exit
434 * 492 *
435 * PARAMETERS: line_number - Caller's line number 493 * PARAMETERS: line_number - Caller's line number
436 * dbg_info - Contains: 494 * function_name - Caller's procedure name
437 * proc_name - Caller's procedure name 495 * module_name - Caller's module name
438 * module_name - Caller's module name 496 * component_id - Caller's component ID
439 * component_id - Caller's component ID
440 * Value - Value to be printed with exit msg 497 * Value - Value to be printed with exit msg
441 * 498 *
442 * RETURN: None 499 * RETURN: None
@@ -449,13 +506,16 @@ EXPORT_SYMBOL(acpi_ut_status_exit);
449void 506void
450acpi_ut_value_exit ( 507acpi_ut_value_exit (
451 u32 line_number, 508 u32 line_number,
452 struct acpi_debug_print_info *dbg_info, 509 const char *function_name,
510 char *module_name,
511 u32 component_id,
453 acpi_integer value) 512 acpi_integer value)
454{ 513{
455 514
456 acpi_ut_debug_print (ACPI_LV_FUNCTIONS, line_number, dbg_info, 515 acpi_ut_debug_print (ACPI_LV_FUNCTIONS,
457 "%s %8.8X%8.8X\n", acpi_gbl_fn_exit_str, 516 line_number, function_name, module_name, component_id,
458 ACPI_FORMAT_UINT64 (value)); 517 "%s %8.8X%8.8X\n", acpi_gbl_fn_exit_str,
518 ACPI_FORMAT_UINT64 (value));
459 519
460 acpi_gbl_nesting_level--; 520 acpi_gbl_nesting_level--;
461} 521}
@@ -467,10 +527,9 @@ EXPORT_SYMBOL(acpi_ut_value_exit);
467 * FUNCTION: acpi_ut_ptr_exit 527 * FUNCTION: acpi_ut_ptr_exit
468 * 528 *
469 * PARAMETERS: line_number - Caller's line number 529 * PARAMETERS: line_number - Caller's line number
470 * dbg_info - Contains: 530 * function_name - Caller's procedure name
471 * proc_name - Caller's procedure name 531 * module_name - Caller's module name
472 * module_name - Caller's module name 532 * component_id - Caller's component ID
473 * component_id - Caller's component ID
474 * Ptr - Pointer to display 533 * Ptr - Pointer to display
475 * 534 *
476 * RETURN: None 535 * RETURN: None
@@ -483,12 +542,15 @@ EXPORT_SYMBOL(acpi_ut_value_exit);
483void 542void
484acpi_ut_ptr_exit ( 543acpi_ut_ptr_exit (
485 u32 line_number, 544 u32 line_number,
486 struct acpi_debug_print_info *dbg_info, 545 const char *function_name,
546 char *module_name,
547 u32 component_id,
487 u8 *ptr) 548 u8 *ptr)
488{ 549{
489 550
490 acpi_ut_debug_print (ACPI_LV_FUNCTIONS, line_number, dbg_info, 551 acpi_ut_debug_print (ACPI_LV_FUNCTIONS,
491 "%s %p\n", acpi_gbl_fn_exit_str, ptr); 552 line_number, function_name, module_name, component_id,
553 "%s %p\n", acpi_gbl_fn_exit_str, ptr);
492 554
493 acpi_gbl_nesting_level--; 555 acpi_gbl_nesting_level--;
494} 556}
@@ -549,7 +611,7 @@ acpi_ut_dump_buffer (
549 /* Dump fill spaces */ 611 /* Dump fill spaces */
550 612
551 acpi_os_printf ("%*s", ((display * 2) + 1), " "); 613 acpi_os_printf ("%*s", ((display * 2) + 1), " ");
552 j += display; 614 j += (acpi_native_uint) display;
553 continue; 615 continue;
554 } 616 }
555 617
@@ -584,12 +646,12 @@ acpi_ut_dump_buffer (
584 break; 646 break;
585 } 647 }
586 648
587 j += display; 649 j += (acpi_native_uint) display;
588 } 650 }
589 651
590 /* 652 /*
591 * Print the ASCII equivalent characters 653 * Print the ASCII equivalent characters but watch out for the bad
592 * But watch out for the bad unprintable ones... 654 * unprintable ones (printable chars are 0x20 through 0x7E)
593 */ 655 */
594 acpi_os_printf (" "); 656 acpi_os_printf (" ");
595 for (j = 0; j < 16; j++) { 657 for (j = 0; j < 16; j++) {
@@ -599,9 +661,7 @@ acpi_ut_dump_buffer (
599 } 661 }
600 662
601 buf_char = buffer[i + j]; 663 buf_char = buffer[i + j];
602 if ((buf_char > 0x1F && buf_char < 0x2E) || 664 if (ACPI_IS_PRINT (buf_char)) {
603 (buf_char > 0x2F && buf_char < 0x61) ||
604 (buf_char > 0x60 && buf_char < 0x7F)) {
605 acpi_os_printf ("%c", buf_char); 665 acpi_os_printf ("%c", buf_char);
606 } 666 }
607 else { 667 else {
diff --git a/drivers/acpi/utilities/utdelete.c b/drivers/acpi/utilities/utdelete.c
index bc5403022681..eeafb324c504 100644
--- a/drivers/acpi/utilities/utdelete.c
+++ b/drivers/acpi/utilities/utdelete.c
@@ -435,35 +435,24 @@ acpi_ut_update_object_reference (
435 union acpi_operand_object *object, 435 union acpi_operand_object *object,
436 u16 action) 436 u16 action)
437{ 437{
438 acpi_status status; 438 acpi_status status = AE_OK;
439 u32 i; 439 union acpi_generic_state *state_list = NULL;
440 union acpi_generic_state *state_list = NULL; 440 union acpi_operand_object *next_object = NULL;
441 union acpi_generic_state *state; 441 union acpi_generic_state *state;
442 union acpi_operand_object *tmp; 442 acpi_native_uint i;
443
444 ACPI_FUNCTION_TRACE_PTR ("ut_update_object_reference", object);
445 443
446 444
447 /* Ignore a null object ptr */ 445 ACPI_FUNCTION_TRACE_PTR ("ut_update_object_reference", object);
448
449 if (!object) {
450 return_ACPI_STATUS (AE_OK);
451 }
452 446
453 /* Make sure that this isn't a namespace handle */
454 447
455 if (ACPI_GET_DESCRIPTOR_TYPE (object) == ACPI_DESC_TYPE_NAMED) { 448 while (object) {
456 ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, 449 /* Make sure that this isn't a namespace handle */
457 "Object %p is NS handle\n", object));
458 return_ACPI_STATUS (AE_OK);
459 }
460 450
461 state = acpi_ut_create_update_state (object, action); 451 if (ACPI_GET_DESCRIPTOR_TYPE (object) == ACPI_DESC_TYPE_NAMED) {
462 452 ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS,
463 while (state) { 453 "Object %p is NS handle\n", object));
464 object = state->update.object; 454 return_ACPI_STATUS (AE_OK);
465 action = state->update.value; 455 }
466 acpi_ut_delete_generic_state (state);
467 456
468 /* 457 /*
469 * All sub-objects must have their reference count incremented also. 458 * All sub-objects must have their reference count incremented also.
@@ -472,24 +461,14 @@ acpi_ut_update_object_reference (
472 switch (ACPI_GET_OBJECT_TYPE (object)) { 461 switch (ACPI_GET_OBJECT_TYPE (object)) {
473 case ACPI_TYPE_DEVICE: 462 case ACPI_TYPE_DEVICE:
474 463
475 tmp = object->device.system_notify; 464 acpi_ut_update_ref_count (object->device.system_notify, action);
476 if (tmp && (tmp->common.reference_count <= 1) && action == REF_DECREMENT) 465 acpi_ut_update_ref_count (object->device.device_notify, action);
477 object->device.system_notify = NULL;
478 acpi_ut_update_ref_count (tmp, action);
479
480 tmp = object->device.device_notify;
481 if (tmp && (tmp->common.reference_count <= 1) && action == REF_DECREMENT)
482 object->device.device_notify = NULL;
483 acpi_ut_update_ref_count (tmp, action);
484
485 break; 466 break;
486 467
487
488 case ACPI_TYPE_PACKAGE: 468 case ACPI_TYPE_PACKAGE:
489
490 /* 469 /*
491 * We must update all the sub-objects of the package 470 * We must update all the sub-objects of the package,
492 * (Each of whom may have their own sub-objects, etc. 471 * each of whom may have their own sub-objects.
493 */ 472 */
494 for (i = 0; i < object->package.count; i++) { 473 for (i = 0; i < object->package.count; i++) {
495 /* 474 /*
@@ -502,111 +481,52 @@ acpi_ut_update_object_reference (
502 if (ACPI_FAILURE (status)) { 481 if (ACPI_FAILURE (status)) {
503 goto error_exit; 482 goto error_exit;
504 } 483 }
505
506 tmp = object->package.elements[i];
507 if (tmp && (tmp->common.reference_count <= 1) && action == REF_DECREMENT)
508 object->package.elements[i] = NULL;
509 } 484 }
510 break; 485 break;
511 486
512
513 case ACPI_TYPE_BUFFER_FIELD: 487 case ACPI_TYPE_BUFFER_FIELD:
514 488
515 status = acpi_ut_create_update_state_and_push ( 489 next_object = object->buffer_field.buffer_obj;
516 object->buffer_field.buffer_obj, action, &state_list);
517 if (ACPI_FAILURE (status)) {
518 goto error_exit;
519 }
520
521 tmp = object->buffer_field.buffer_obj;
522 if ( tmp && (tmp->common.reference_count <= 1) && action == REF_DECREMENT)
523 object->buffer_field.buffer_obj = NULL;
524 break; 490 break;
525 491
526
527 case ACPI_TYPE_LOCAL_REGION_FIELD: 492 case ACPI_TYPE_LOCAL_REGION_FIELD:
528 493
529 status = acpi_ut_create_update_state_and_push ( 494 next_object = object->field.region_obj;
530 object->field.region_obj, action, &state_list); 495 break;
531 if (ACPI_FAILURE (status)) {
532 goto error_exit;
533 }
534
535 tmp = object->field.region_obj;
536 if ( tmp && (tmp->common.reference_count <= 1) && action == REF_DECREMENT)
537 object->field.region_obj = NULL;
538 break;
539
540 496
541 case ACPI_TYPE_LOCAL_BANK_FIELD: 497 case ACPI_TYPE_LOCAL_BANK_FIELD:
542 498
543 status = acpi_ut_create_update_state_and_push ( 499 next_object = object->bank_field.bank_obj;
544 object->bank_field.bank_obj, action, &state_list);
545 if (ACPI_FAILURE (status)) {
546 goto error_exit;
547 }
548
549 tmp = object->bank_field.bank_obj;
550 if ( tmp && (tmp->common.reference_count <= 1) && action == REF_DECREMENT)
551 object->bank_field.bank_obj = NULL;
552
553 status = acpi_ut_create_update_state_and_push ( 500 status = acpi_ut_create_update_state_and_push (
554 object->bank_field.region_obj, action, &state_list); 501 object->bank_field.region_obj, action, &state_list);
555 if (ACPI_FAILURE (status)) { 502 if (ACPI_FAILURE (status)) {
556 goto error_exit; 503 goto error_exit;
557 } 504 }
558
559 tmp = object->bank_field.region_obj;
560 if ( tmp && (tmp->common.reference_count <= 1) && action == REF_DECREMENT)
561 object->bank_field.region_obj = NULL;
562 break; 505 break;
563 506
564
565 case ACPI_TYPE_LOCAL_INDEX_FIELD: 507 case ACPI_TYPE_LOCAL_INDEX_FIELD:
566 508
567 status = acpi_ut_create_update_state_and_push ( 509 next_object = object->index_field.index_obj;
568 object->index_field.index_obj, action, &state_list);
569 if (ACPI_FAILURE (status)) {
570 goto error_exit;
571 }
572
573 tmp = object->index_field.index_obj;
574 if ( tmp && (tmp->common.reference_count <= 1) && action == REF_DECREMENT)
575 object->index_field.index_obj = NULL;
576
577 status = acpi_ut_create_update_state_and_push ( 510 status = acpi_ut_create_update_state_and_push (
578 object->index_field.data_obj, action, &state_list); 511 object->index_field.data_obj, action, &state_list);
579 if (ACPI_FAILURE (status)) { 512 if (ACPI_FAILURE (status)) {
580 goto error_exit; 513 goto error_exit;
581 } 514 }
582
583 tmp = object->index_field.data_obj;
584 if ( tmp && (tmp->common.reference_count <= 1) && action == REF_DECREMENT)
585 object->index_field.data_obj = NULL;
586 break; 515 break;
587 516
588
589 case ACPI_TYPE_LOCAL_REFERENCE: 517 case ACPI_TYPE_LOCAL_REFERENCE:
590
591 /* 518 /*
592 * The target of an Index (a package, string, or buffer) must track 519 * The target of an Index (a package, string, or buffer) must track
593 * changes to the ref count of the index. 520 * changes to the ref count of the index.
594 */ 521 */
595 if (object->reference.opcode == AML_INDEX_OP) { 522 if (object->reference.opcode == AML_INDEX_OP) {
596 status = acpi_ut_create_update_state_and_push ( 523 next_object = object->reference.object;
597 object->reference.object, action, &state_list);
598 if (ACPI_FAILURE (status)) {
599 goto error_exit;
600 }
601 } 524 }
602 break; 525 break;
603 526
604
605 case ACPI_TYPE_REGION: 527 case ACPI_TYPE_REGION:
606 default: 528 default:
607 529 break;/* No subobjects */
608 /* No subobjects */
609 break;
610 } 530 }
611 531
612 /* 532 /*
@@ -615,15 +535,23 @@ acpi_ut_update_object_reference (
615 * main object to be deleted. 535 * main object to be deleted.
616 */ 536 */
617 acpi_ut_update_ref_count (object, action); 537 acpi_ut_update_ref_count (object, action);
538 object = NULL;
618 539
619 /* Move on to the next object to be updated */ 540 /* Move on to the next object to be updated */
620 541
621 state = acpi_ut_pop_generic_state (&state_list); 542 if (next_object) {
543 object = next_object;
544 next_object = NULL;
545 }
546 else if (state_list) {
547 state = acpi_ut_pop_generic_state (&state_list);
548 object = state->update.object;
549 acpi_ut_delete_generic_state (state);
550 }
622 } 551 }
623 552
624 return_ACPI_STATUS (AE_OK); 553 return_ACPI_STATUS (AE_OK);
625 554
626
627error_exit: 555error_exit:
628 556
629 ACPI_REPORT_ERROR (("Could not update object reference count, %s\n", 557 ACPI_REPORT_ERROR (("Could not update object reference count, %s\n",
diff --git a/drivers/acpi/utilities/utglobal.c b/drivers/acpi/utilities/utglobal.c
index 4146019b543f..0e4161c81076 100644
--- a/drivers/acpi/utilities/utglobal.c
+++ b/drivers/acpi/utilities/utglobal.c
@@ -738,73 +738,6 @@ acpi_ut_valid_object_type (
738 738
739/******************************************************************************* 739/*******************************************************************************
740 * 740 *
741 * FUNCTION: acpi_ut_allocate_owner_id
742 *
743 * PARAMETERS: id_type - Type of ID (method or table)
744 *
745 * DESCRIPTION: Allocate a table or method owner id
746 *
747 * NOTE: this algorithm has a wraparound problem at 64_k method invocations, and
748 * should be revisited (TBD)
749 *
750 ******************************************************************************/
751
752acpi_owner_id
753acpi_ut_allocate_owner_id (
754 u32 id_type)
755{
756 acpi_owner_id owner_id = 0xFFFF;
757
758
759 ACPI_FUNCTION_TRACE ("ut_allocate_owner_id");
760
761
762 if (ACPI_FAILURE (acpi_ut_acquire_mutex (ACPI_MTX_CACHES)))
763 {
764 return (0);
765 }
766
767 switch (id_type)
768 {
769 case ACPI_OWNER_TYPE_TABLE:
770
771 owner_id = acpi_gbl_next_table_owner_id;
772 acpi_gbl_next_table_owner_id++;
773
774 /* Check for wraparound */
775
776 if (acpi_gbl_next_table_owner_id == ACPI_FIRST_METHOD_ID)
777 {
778 acpi_gbl_next_table_owner_id = ACPI_FIRST_TABLE_ID;
779 ACPI_REPORT_WARNING (("Table owner ID wraparound\n"));
780 }
781 break;
782
783
784 case ACPI_OWNER_TYPE_METHOD:
785
786 owner_id = acpi_gbl_next_method_owner_id;
787 acpi_gbl_next_method_owner_id++;
788
789 if (acpi_gbl_next_method_owner_id == ACPI_FIRST_TABLE_ID)
790 {
791 /* Check for wraparound */
792
793 acpi_gbl_next_method_owner_id = ACPI_FIRST_METHOD_ID;
794 }
795 break;
796
797 default:
798 break;
799 }
800
801 (void) acpi_ut_release_mutex (ACPI_MTX_CACHES);
802 return_VALUE (owner_id);
803}
804
805
806/*******************************************************************************
807 *
808 * FUNCTION: acpi_ut_init_globals 741 * FUNCTION: acpi_ut_init_globals
809 * 742 *
810 * PARAMETERS: None 743 * PARAMETERS: None
@@ -820,42 +753,20 @@ void
820acpi_ut_init_globals ( 753acpi_ut_init_globals (
821 void) 754 void)
822{ 755{
756 acpi_status status;
823 u32 i; 757 u32 i;
824 758
825 759
826 ACPI_FUNCTION_TRACE ("ut_init_globals"); 760 ACPI_FUNCTION_TRACE ("ut_init_globals");
827 761
828 762
829 /* Memory allocation and cache lists */ 763 /* Create all memory caches */
830
831 ACPI_MEMSET (acpi_gbl_memory_lists, 0, sizeof (struct acpi_memory_list) * ACPI_NUM_MEM_LISTS);
832 764
833 acpi_gbl_memory_lists[ACPI_MEM_LIST_STATE].link_offset = (u16) ACPI_PTR_DIFF (&(((union acpi_generic_state *) NULL)->common.next), NULL); 765 status = acpi_ut_create_caches ();
834 acpi_gbl_memory_lists[ACPI_MEM_LIST_PSNODE].link_offset = (u16) ACPI_PTR_DIFF (&(((union acpi_parse_object *) NULL)->common.next), NULL); 766 if (ACPI_FAILURE (status))
835 acpi_gbl_memory_lists[ACPI_MEM_LIST_PSNODE_EXT].link_offset = (u16) ACPI_PTR_DIFF (&(((union acpi_parse_object *) NULL)->common.next), NULL); 767 {
836 acpi_gbl_memory_lists[ACPI_MEM_LIST_OPERAND].link_offset = (u16) ACPI_PTR_DIFF (&(((union acpi_operand_object *) NULL)->cache.next), NULL); 768 return;
837 acpi_gbl_memory_lists[ACPI_MEM_LIST_WALK].link_offset = (u16) ACPI_PTR_DIFF (&(((struct acpi_walk_state *) NULL)->next), NULL); 769 }
838
839 acpi_gbl_memory_lists[ACPI_MEM_LIST_NSNODE].object_size = sizeof (struct acpi_namespace_node);
840 acpi_gbl_memory_lists[ACPI_MEM_LIST_STATE].object_size = sizeof (union acpi_generic_state);
841 acpi_gbl_memory_lists[ACPI_MEM_LIST_PSNODE].object_size = sizeof (struct acpi_parse_obj_common);
842 acpi_gbl_memory_lists[ACPI_MEM_LIST_PSNODE_EXT].object_size = sizeof (struct acpi_parse_obj_named);
843 acpi_gbl_memory_lists[ACPI_MEM_LIST_OPERAND].object_size = sizeof (union acpi_operand_object);
844 acpi_gbl_memory_lists[ACPI_MEM_LIST_WALK].object_size = sizeof (struct acpi_walk_state);
845
846 acpi_gbl_memory_lists[ACPI_MEM_LIST_STATE].max_cache_depth = ACPI_MAX_STATE_CACHE_DEPTH;
847 acpi_gbl_memory_lists[ACPI_MEM_LIST_PSNODE].max_cache_depth = ACPI_MAX_PARSE_CACHE_DEPTH;
848 acpi_gbl_memory_lists[ACPI_MEM_LIST_PSNODE_EXT].max_cache_depth = ACPI_MAX_EXTPARSE_CACHE_DEPTH;
849 acpi_gbl_memory_lists[ACPI_MEM_LIST_OPERAND].max_cache_depth = ACPI_MAX_OBJECT_CACHE_DEPTH;
850 acpi_gbl_memory_lists[ACPI_MEM_LIST_WALK].max_cache_depth = ACPI_MAX_WALK_CACHE_DEPTH;
851
852 ACPI_MEM_TRACKING (acpi_gbl_memory_lists[ACPI_MEM_LIST_GLOBAL].list_name = "Global Memory Allocation");
853 ACPI_MEM_TRACKING (acpi_gbl_memory_lists[ACPI_MEM_LIST_NSNODE].list_name = "Namespace Nodes");
854 ACPI_MEM_TRACKING (acpi_gbl_memory_lists[ACPI_MEM_LIST_STATE].list_name = "State Object Cache");
855 ACPI_MEM_TRACKING (acpi_gbl_memory_lists[ACPI_MEM_LIST_PSNODE].list_name = "Parse Node Cache");
856 ACPI_MEM_TRACKING (acpi_gbl_memory_lists[ACPI_MEM_LIST_PSNODE_EXT].list_name = "Extended Parse Node Cache");
857 ACPI_MEM_TRACKING (acpi_gbl_memory_lists[ACPI_MEM_LIST_OPERAND].list_name = "Operand Object Cache");
858 ACPI_MEM_TRACKING (acpi_gbl_memory_lists[ACPI_MEM_LIST_WALK].list_name = "Tree Walk Node Cache");
859 770
860 /* ACPI table structure */ 771 /* ACPI table structure */
861 772
@@ -870,7 +781,7 @@ acpi_ut_init_globals (
870 for (i = 0; i < NUM_MUTEX; i++) 781 for (i = 0; i < NUM_MUTEX; i++)
871 { 782 {
872 acpi_gbl_mutex_info[i].mutex = NULL; 783 acpi_gbl_mutex_info[i].mutex = NULL;
873 acpi_gbl_mutex_info[i].owner_id = ACPI_MUTEX_NOT_ACQUIRED; 784 acpi_gbl_mutex_info[i].thread_id = ACPI_MUTEX_NOT_ACQUIRED;
874 acpi_gbl_mutex_info[i].use_count = 0; 785 acpi_gbl_mutex_info[i].use_count = 0;
875 } 786 }
876 787
@@ -911,8 +822,7 @@ acpi_ut_init_globals (
911 acpi_gbl_ns_lookup_count = 0; 822 acpi_gbl_ns_lookup_count = 0;
912 acpi_gbl_ps_find_count = 0; 823 acpi_gbl_ps_find_count = 0;
913 acpi_gbl_acpi_hardware_present = TRUE; 824 acpi_gbl_acpi_hardware_present = TRUE;
914 acpi_gbl_next_table_owner_id = ACPI_FIRST_TABLE_ID; 825 acpi_gbl_owner_id_mask = 0;
915 acpi_gbl_next_method_owner_id = ACPI_FIRST_METHOD_ID;
916 acpi_gbl_debugger_configuration = DEBUGGER_THREADING; 826 acpi_gbl_debugger_configuration = DEBUGGER_THREADING;
917 acpi_gbl_db_output_flags = ACPI_DB_CONSOLE_OUTPUT; 827 acpi_gbl_db_output_flags = ACPI_DB_CONSOLE_OUTPUT;
918 828
diff --git a/drivers/acpi/utilities/utinit.c b/drivers/acpi/utilities/utinit.c
index 7f3713889ff0..fd7ceba83229 100644
--- a/drivers/acpi/utilities/utinit.c
+++ b/drivers/acpi/utilities/utinit.c
@@ -264,7 +264,7 @@ acpi_ut_subsystem_shutdown (
264 264
265 /* Purge the local caches */ 265 /* Purge the local caches */
266 266
267 (void) acpi_purge_cached_objects (); 267 (void) acpi_ut_delete_caches ();
268 268
269 /* Debug only - display leftover memory allocation, if any */ 269 /* Debug only - display leftover memory allocation, if any */
270 270
diff --git a/drivers/acpi/utilities/utmisc.c b/drivers/acpi/utilities/utmisc.c
index f6de4ed3d527..1d350b302a34 100644
--- a/drivers/acpi/utilities/utmisc.c
+++ b/drivers/acpi/utilities/utmisc.c
@@ -49,15 +49,121 @@
49#define _COMPONENT ACPI_UTILITIES 49#define _COMPONENT ACPI_UTILITIES
50 ACPI_MODULE_NAME ("utmisc") 50 ACPI_MODULE_NAME ("utmisc")
51 51
52/* Local prototypes */
53 52
54static acpi_status 53/*******************************************************************************
55acpi_ut_create_mutex ( 54 *
56 acpi_mutex_handle mutex_id); 55 * FUNCTION: acpi_ut_allocate_owner_id
56 *
57 * PARAMETERS: owner_id - Where the new owner ID is returned
58 *
59 * RETURN: Status
60 *
61 * DESCRIPTION: Allocate a table or method owner ID. The owner ID is used to
62 * track objects created by the table or method, to be deleted
63 * when the method exits or the table is unloaded.
64 *
65 ******************************************************************************/
66
67acpi_status
68acpi_ut_allocate_owner_id (
69 acpi_owner_id *owner_id)
70{
71 acpi_native_uint i;
72 acpi_status status;
73
74
75 ACPI_FUNCTION_TRACE ("ut_allocate_owner_id");
57 76
58static acpi_status 77
59acpi_ut_delete_mutex ( 78 /* Mutex for the global ID mask */
60 acpi_mutex_handle mutex_id); 79
80 status = acpi_ut_acquire_mutex (ACPI_MTX_CACHES);
81 if (ACPI_FAILURE (status)) {
82 return_ACPI_STATUS (status);
83 }
84
85 /* Find a free owner ID */
86
87 for (i = 0; i < 32; i++) {
88 if (!(acpi_gbl_owner_id_mask & (1 << i))) {
89 acpi_gbl_owner_id_mask |= (1 << i);
90 *owner_id = (acpi_owner_id) (i + 1);
91 goto exit;
92 }
93 }
94
95 /*
96 * If we are here, all owner_ids have been allocated. This probably should
97 * not happen since the IDs are reused after deallocation. The IDs are
98 * allocated upon table load (one per table) and method execution, and
99 * they are released when a table is unloaded or a method completes
100 * execution.
101 */
102 *owner_id = 0;
103 status = AE_OWNER_ID_LIMIT;
104 ACPI_REPORT_ERROR ((
105 "Could not allocate new owner_id (32 max), AE_OWNER_ID_LIMIT\n"));
106
107exit:
108 (void) acpi_ut_release_mutex (ACPI_MTX_CACHES);
109 return_ACPI_STATUS (status);
110}
111
112
113/*******************************************************************************
114 *
115 * FUNCTION: acpi_ut_release_owner_id
116 *
117 * PARAMETERS: owner_id_ptr - Pointer to a previously allocated owner_iD
118 *
119 * RETURN: None. No error is returned because we are either exiting a
120 * control method or unloading a table. Either way, we would
121 * ignore any error anyway.
122 *
123 * DESCRIPTION: Release a table or method owner ID. Valid IDs are 1 - 32
124 *
125 ******************************************************************************/
126
127void
128acpi_ut_release_owner_id (
129 acpi_owner_id *owner_id_ptr)
130{
131 acpi_owner_id owner_id = *owner_id_ptr;
132 acpi_status status;
133
134
135 ACPI_FUNCTION_TRACE ("ut_release_owner_id");
136
137
138 /* Always clear the input owner_id (zero is an invalid ID) */
139
140 *owner_id_ptr = 0;
141
142 /* Zero is not a valid owner_iD */
143
144 if ((owner_id == 0) || (owner_id > 32)) {
145 ACPI_REPORT_ERROR (("Invalid owner_id: %2.2X\n", owner_id));
146 return_VOID;
147 }
148
149 /* Mutex for the global ID mask */
150
151 status = acpi_ut_acquire_mutex (ACPI_MTX_CACHES);
152 if (ACPI_FAILURE (status)) {
153 return_VOID;
154 }
155
156 owner_id--; /* Normalize to zero */
157
158 /* Free the owner ID only if it is valid */
159
160 if (acpi_gbl_owner_id_mask & (1 << owner_id)) {
161 acpi_gbl_owner_id_mask ^= (1 << owner_id);
162 }
163
164 (void) acpi_ut_release_mutex (ACPI_MTX_CACHES);
165 return_VOID;
166}
61 167
62 168
63/******************************************************************************* 169/*******************************************************************************
@@ -66,7 +172,7 @@ acpi_ut_delete_mutex (
66 * 172 *
67 * PARAMETERS: src_string - The source string to convert 173 * PARAMETERS: src_string - The source string to convert
68 * 174 *
69 * RETURN: Converted src_string (same as input pointer) 175 * RETURN: None
70 * 176 *
71 * DESCRIPTION: Convert string to uppercase 177 * DESCRIPTION: Convert string to uppercase
72 * 178 *
@@ -74,7 +180,7 @@ acpi_ut_delete_mutex (
74 * 180 *
75 ******************************************************************************/ 181 ******************************************************************************/
76 182
77char * 183void
78acpi_ut_strupr ( 184acpi_ut_strupr (
79 char *src_string) 185 char *src_string)
80{ 186{
@@ -84,13 +190,17 @@ acpi_ut_strupr (
84 ACPI_FUNCTION_ENTRY (); 190 ACPI_FUNCTION_ENTRY ();
85 191
86 192
193 if (!src_string) {
194 return;
195 }
196
87 /* Walk entire string, uppercasing the letters */ 197 /* Walk entire string, uppercasing the letters */
88 198
89 for (string = src_string; *string; string++) { 199 for (string = src_string; *string; string++) {
90 *string = (char) ACPI_TOUPPER (*string); 200 *string = (char) ACPI_TOUPPER (*string);
91 } 201 }
92 202
93 return (src_string); 203 return;
94} 204}
95 205
96 206
@@ -543,320 +653,6 @@ error_exit:
543 653
544/******************************************************************************* 654/*******************************************************************************
545 * 655 *
546 * FUNCTION: acpi_ut_mutex_initialize
547 *
548 * PARAMETERS: None.
549 *
550 * RETURN: Status
551 *
552 * DESCRIPTION: Create the system mutex objects.
553 *
554 ******************************************************************************/
555
556acpi_status
557acpi_ut_mutex_initialize (
558 void)
559{
560 u32 i;
561 acpi_status status;
562
563
564 ACPI_FUNCTION_TRACE ("ut_mutex_initialize");
565
566
567 /*
568 * Create each of the predefined mutex objects
569 */
570 for (i = 0; i < NUM_MUTEX; i++) {
571 status = acpi_ut_create_mutex (i);
572 if (ACPI_FAILURE (status)) {
573 return_ACPI_STATUS (status);
574 }
575 }
576
577 status = acpi_os_create_lock (&acpi_gbl_gpe_lock);
578 return_ACPI_STATUS (status);
579}
580
581
582/*******************************************************************************
583 *
584 * FUNCTION: acpi_ut_mutex_terminate
585 *
586 * PARAMETERS: None.
587 *
588 * RETURN: None.
589 *
590 * DESCRIPTION: Delete all of the system mutex objects.
591 *
592 ******************************************************************************/
593
594void
595acpi_ut_mutex_terminate (
596 void)
597{
598 u32 i;
599
600
601 ACPI_FUNCTION_TRACE ("ut_mutex_terminate");
602
603
604 /*
605 * Delete each predefined mutex object
606 */
607 for (i = 0; i < NUM_MUTEX; i++) {
608 (void) acpi_ut_delete_mutex (i);
609 }
610
611 acpi_os_delete_lock (acpi_gbl_gpe_lock);
612 return_VOID;
613}
614
615
616/*******************************************************************************
617 *
618 * FUNCTION: acpi_ut_create_mutex
619 *
620 * PARAMETERS: mutex_iD - ID of the mutex to be created
621 *
622 * RETURN: Status
623 *
624 * DESCRIPTION: Create a mutex object.
625 *
626 ******************************************************************************/
627
628static acpi_status
629acpi_ut_create_mutex (
630 acpi_mutex_handle mutex_id)
631{
632 acpi_status status = AE_OK;
633
634
635 ACPI_FUNCTION_TRACE_U32 ("ut_create_mutex", mutex_id);
636
637
638 if (mutex_id > MAX_MUTEX) {
639 return_ACPI_STATUS (AE_BAD_PARAMETER);
640 }
641
642 if (!acpi_gbl_mutex_info[mutex_id].mutex) {
643 status = acpi_os_create_semaphore (1, 1,
644 &acpi_gbl_mutex_info[mutex_id].mutex);
645 acpi_gbl_mutex_info[mutex_id].owner_id = ACPI_MUTEX_NOT_ACQUIRED;
646 acpi_gbl_mutex_info[mutex_id].use_count = 0;
647 }
648
649 return_ACPI_STATUS (status);
650}
651
652
653/*******************************************************************************
654 *
655 * FUNCTION: acpi_ut_delete_mutex
656 *
657 * PARAMETERS: mutex_iD - ID of the mutex to be deleted
658 *
659 * RETURN: Status
660 *
661 * DESCRIPTION: Delete a mutex object.
662 *
663 ******************************************************************************/
664
665static acpi_status
666acpi_ut_delete_mutex (
667 acpi_mutex_handle mutex_id)
668{
669 acpi_status status;
670
671
672 ACPI_FUNCTION_TRACE_U32 ("ut_delete_mutex", mutex_id);
673
674
675 if (mutex_id > MAX_MUTEX) {
676 return_ACPI_STATUS (AE_BAD_PARAMETER);
677 }
678
679 status = acpi_os_delete_semaphore (acpi_gbl_mutex_info[mutex_id].mutex);
680
681 acpi_gbl_mutex_info[mutex_id].mutex = NULL;
682 acpi_gbl_mutex_info[mutex_id].owner_id = ACPI_MUTEX_NOT_ACQUIRED;
683
684 return_ACPI_STATUS (status);
685}
686
687
688/*******************************************************************************
689 *
690 * FUNCTION: acpi_ut_acquire_mutex
691 *
692 * PARAMETERS: mutex_iD - ID of the mutex to be acquired
693 *
694 * RETURN: Status
695 *
696 * DESCRIPTION: Acquire a mutex object.
697 *
698 ******************************************************************************/
699
700acpi_status
701acpi_ut_acquire_mutex (
702 acpi_mutex_handle mutex_id)
703{
704 acpi_status status;
705 u32 this_thread_id;
706
707
708 ACPI_FUNCTION_NAME ("ut_acquire_mutex");
709
710
711 if (mutex_id > MAX_MUTEX) {
712 return (AE_BAD_PARAMETER);
713 }
714
715 this_thread_id = acpi_os_get_thread_id ();
716
717#ifdef ACPI_MUTEX_DEBUG
718 {
719 u32 i;
720 /*
721 * Mutex debug code, for internal debugging only.
722 *
723 * Deadlock prevention. Check if this thread owns any mutexes of value
724 * greater than or equal to this one. If so, the thread has violated
725 * the mutex ordering rule. This indicates a coding error somewhere in
726 * the ACPI subsystem code.
727 */
728 for (i = mutex_id; i < MAX_MUTEX; i++) {
729 if (acpi_gbl_mutex_info[i].owner_id == this_thread_id) {
730 if (i == mutex_id) {
731 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
732 "Mutex [%s] already acquired by this thread [%X]\n",
733 acpi_ut_get_mutex_name (mutex_id), this_thread_id));
734
735 return (AE_ALREADY_ACQUIRED);
736 }
737
738 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
739 "Invalid acquire order: Thread %X owns [%s], wants [%s]\n",
740 this_thread_id, acpi_ut_get_mutex_name (i),
741 acpi_ut_get_mutex_name (mutex_id)));
742
743 return (AE_ACQUIRE_DEADLOCK);
744 }
745 }
746 }
747#endif
748
749 ACPI_DEBUG_PRINT ((ACPI_DB_MUTEX,
750 "Thread %X attempting to acquire Mutex [%s]\n",
751 this_thread_id, acpi_ut_get_mutex_name (mutex_id)));
752
753 status = acpi_os_wait_semaphore (acpi_gbl_mutex_info[mutex_id].mutex,
754 1, ACPI_WAIT_FOREVER);
755 if (ACPI_SUCCESS (status)) {
756 ACPI_DEBUG_PRINT ((ACPI_DB_MUTEX, "Thread %X acquired Mutex [%s]\n",
757 this_thread_id, acpi_ut_get_mutex_name (mutex_id)));
758
759 acpi_gbl_mutex_info[mutex_id].use_count++;
760 acpi_gbl_mutex_info[mutex_id].owner_id = this_thread_id;
761 }
762 else {
763 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
764 "Thread %X could not acquire Mutex [%s] %s\n",
765 this_thread_id, acpi_ut_get_mutex_name (mutex_id),
766 acpi_format_exception (status)));
767 }
768
769 return (status);
770}
771
772
773/*******************************************************************************
774 *
775 * FUNCTION: acpi_ut_release_mutex
776 *
777 * PARAMETERS: mutex_iD - ID of the mutex to be released
778 *
779 * RETURN: Status
780 *
781 * DESCRIPTION: Release a mutex object.
782 *
783 ******************************************************************************/
784
785acpi_status
786acpi_ut_release_mutex (
787 acpi_mutex_handle mutex_id)
788{
789 acpi_status status;
790 u32 i;
791 u32 this_thread_id;
792
793
794 ACPI_FUNCTION_NAME ("ut_release_mutex");
795
796
797 this_thread_id = acpi_os_get_thread_id ();
798 ACPI_DEBUG_PRINT ((ACPI_DB_MUTEX,
799 "Thread %X releasing Mutex [%s]\n", this_thread_id,
800 acpi_ut_get_mutex_name (mutex_id)));
801
802 if (mutex_id > MAX_MUTEX) {
803 return (AE_BAD_PARAMETER);
804 }
805
806 /*
807 * Mutex must be acquired in order to release it!
808 */
809 if (acpi_gbl_mutex_info[mutex_id].owner_id == ACPI_MUTEX_NOT_ACQUIRED) {
810 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
811 "Mutex [%s] is not acquired, cannot release\n",
812 acpi_ut_get_mutex_name (mutex_id)));
813
814 return (AE_NOT_ACQUIRED);
815 }
816
817 /*
818 * Deadlock prevention. Check if this thread owns any mutexes of value
819 * greater than this one. If so, the thread has violated the mutex
820 * ordering rule. This indicates a coding error somewhere in
821 * the ACPI subsystem code.
822 */
823 for (i = mutex_id; i < MAX_MUTEX; i++) {
824 if (acpi_gbl_mutex_info[i].owner_id == this_thread_id) {
825 if (i == mutex_id) {
826 continue;
827 }
828
829 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
830 "Invalid release order: owns [%s], releasing [%s]\n",
831 acpi_ut_get_mutex_name (i), acpi_ut_get_mutex_name (mutex_id)));
832
833 return (AE_RELEASE_DEADLOCK);
834 }
835 }
836
837 /* Mark unlocked FIRST */
838
839 acpi_gbl_mutex_info[mutex_id].owner_id = ACPI_MUTEX_NOT_ACQUIRED;
840
841 status = acpi_os_signal_semaphore (acpi_gbl_mutex_info[mutex_id].mutex, 1);
842
843 if (ACPI_FAILURE (status)) {
844 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
845 "Thread %X could not release Mutex [%s] %s\n",
846 this_thread_id, acpi_ut_get_mutex_name (mutex_id),
847 acpi_format_exception (status)));
848 }
849 else {
850 ACPI_DEBUG_PRINT ((ACPI_DB_MUTEX, "Thread %X released Mutex [%s]\n",
851 this_thread_id, acpi_ut_get_mutex_name (mutex_id)));
852 }
853
854 return (status);
855}
856
857
858/*******************************************************************************
859 *
860 * FUNCTION: acpi_ut_create_update_state_and_push 656 * FUNCTION: acpi_ut_create_update_state_and_push
861 * 657 *
862 * PARAMETERS: Object - Object to be added to the new state 658 * PARAMETERS: Object - Object to be added to the new state
@@ -899,361 +695,6 @@ acpi_ut_create_update_state_and_push (
899 695
900/******************************************************************************* 696/*******************************************************************************
901 * 697 *
902 * FUNCTION: acpi_ut_create_pkg_state_and_push
903 *
904 * PARAMETERS: Object - Object to be added to the new state
905 * Action - Increment/Decrement
906 * state_list - List the state will be added to
907 *
908 * RETURN: Status
909 *
910 * DESCRIPTION: Create a new state and push it
911 *
912 ******************************************************************************/
913
914#ifdef ACPI_FUTURE_USAGE
915acpi_status
916acpi_ut_create_pkg_state_and_push (
917 void *internal_object,
918 void *external_object,
919 u16 index,
920 union acpi_generic_state **state_list)
921{
922 union acpi_generic_state *state;
923
924
925 ACPI_FUNCTION_ENTRY ();
926
927
928 state = acpi_ut_create_pkg_state (internal_object, external_object, index);
929 if (!state) {
930 return (AE_NO_MEMORY);
931 }
932
933 acpi_ut_push_generic_state (state_list, state);
934 return (AE_OK);
935}
936#endif /* ACPI_FUTURE_USAGE */
937
938/*******************************************************************************
939 *
940 * FUNCTION: acpi_ut_push_generic_state
941 *
942 * PARAMETERS: list_head - Head of the state stack
943 * State - State object to push
944 *
945 * RETURN: None
946 *
947 * DESCRIPTION: Push a state object onto a state stack
948 *
949 ******************************************************************************/
950
951void
952acpi_ut_push_generic_state (
953 union acpi_generic_state **list_head,
954 union acpi_generic_state *state)
955{
956 ACPI_FUNCTION_TRACE ("ut_push_generic_state");
957
958
959 /* Push the state object onto the front of the list (stack) */
960
961 state->common.next = *list_head;
962 *list_head = state;
963
964 return_VOID;
965}
966
967
968/*******************************************************************************
969 *
970 * FUNCTION: acpi_ut_pop_generic_state
971 *
972 * PARAMETERS: list_head - Head of the state stack
973 *
974 * RETURN: The popped state object
975 *
976 * DESCRIPTION: Pop a state object from a state stack
977 *
978 ******************************************************************************/
979
980union acpi_generic_state *
981acpi_ut_pop_generic_state (
982 union acpi_generic_state **list_head)
983{
984 union acpi_generic_state *state;
985
986
987 ACPI_FUNCTION_TRACE ("ut_pop_generic_state");
988
989
990 /* Remove the state object at the head of the list (stack) */
991
992 state = *list_head;
993 if (state) {
994 /* Update the list head */
995
996 *list_head = state->common.next;
997 }
998
999 return_PTR (state);
1000}
1001
1002
1003/*******************************************************************************
1004 *
1005 * FUNCTION: acpi_ut_create_generic_state
1006 *
1007 * PARAMETERS: None
1008 *
1009 * RETURN: The new state object. NULL on failure.
1010 *
1011 * DESCRIPTION: Create a generic state object. Attempt to obtain one from
1012 * the global state cache; If none available, create a new one.
1013 *
1014 ******************************************************************************/
1015
1016union acpi_generic_state *
1017acpi_ut_create_generic_state (
1018 void)
1019{
1020 union acpi_generic_state *state;
1021
1022
1023 ACPI_FUNCTION_ENTRY ();
1024
1025
1026 state = acpi_ut_acquire_from_cache (ACPI_MEM_LIST_STATE);
1027
1028 /* Initialize */
1029
1030 if (state) {
1031 state->common.data_type = ACPI_DESC_TYPE_STATE;
1032 }
1033
1034 return (state);
1035}
1036
1037
1038/*******************************************************************************
1039 *
1040 * FUNCTION: acpi_ut_create_thread_state
1041 *
1042 * PARAMETERS: None
1043 *
1044 * RETURN: New Thread State. NULL on failure
1045 *
1046 * DESCRIPTION: Create a "Thread State" - a flavor of the generic state used
1047 * to track per-thread info during method execution
1048 *
1049 ******************************************************************************/
1050
1051struct acpi_thread_state *
1052acpi_ut_create_thread_state (
1053 void)
1054{
1055 union acpi_generic_state *state;
1056
1057
1058 ACPI_FUNCTION_TRACE ("ut_create_thread_state");
1059
1060
1061 /* Create the generic state object */
1062
1063 state = acpi_ut_create_generic_state ();
1064 if (!state) {
1065 return_PTR (NULL);
1066 }
1067
1068 /* Init fields specific to the update struct */
1069
1070 state->common.data_type = ACPI_DESC_TYPE_STATE_THREAD;
1071 state->thread.thread_id = acpi_os_get_thread_id ();
1072
1073 return_PTR ((struct acpi_thread_state *) state);
1074}
1075
1076
1077/*******************************************************************************
1078 *
1079 * FUNCTION: acpi_ut_create_update_state
1080 *
1081 * PARAMETERS: Object - Initial Object to be installed in the state
1082 * Action - Update action to be performed
1083 *
1084 * RETURN: New state object, null on failure
1085 *
1086 * DESCRIPTION: Create an "Update State" - a flavor of the generic state used
1087 * to update reference counts and delete complex objects such
1088 * as packages.
1089 *
1090 ******************************************************************************/
1091
1092union acpi_generic_state *
1093acpi_ut_create_update_state (
1094 union acpi_operand_object *object,
1095 u16 action)
1096{
1097 union acpi_generic_state *state;
1098
1099
1100 ACPI_FUNCTION_TRACE_PTR ("ut_create_update_state", object);
1101
1102
1103 /* Create the generic state object */
1104
1105 state = acpi_ut_create_generic_state ();
1106 if (!state) {
1107 return_PTR (NULL);
1108 }
1109
1110 /* Init fields specific to the update struct */
1111
1112 state->common.data_type = ACPI_DESC_TYPE_STATE_UPDATE;
1113 state->update.object = object;
1114 state->update.value = action;
1115
1116 return_PTR (state);
1117}
1118
1119
1120/*******************************************************************************
1121 *
1122 * FUNCTION: acpi_ut_create_pkg_state
1123 *
1124 * PARAMETERS: Object - Initial Object to be installed in the state
1125 * Action - Update action to be performed
1126 *
1127 * RETURN: New state object, null on failure
1128 *
1129 * DESCRIPTION: Create a "Package State"
1130 *
1131 ******************************************************************************/
1132
1133union acpi_generic_state *
1134acpi_ut_create_pkg_state (
1135 void *internal_object,
1136 void *external_object,
1137 u16 index)
1138{
1139 union acpi_generic_state *state;
1140
1141
1142 ACPI_FUNCTION_TRACE_PTR ("ut_create_pkg_state", internal_object);
1143
1144
1145 /* Create the generic state object */
1146
1147 state = acpi_ut_create_generic_state ();
1148 if (!state) {
1149 return_PTR (NULL);
1150 }
1151
1152 /* Init fields specific to the update struct */
1153
1154 state->common.data_type = ACPI_DESC_TYPE_STATE_PACKAGE;
1155 state->pkg.source_object = (union acpi_operand_object *) internal_object;
1156 state->pkg.dest_object = external_object;
1157 state->pkg.index = index;
1158 state->pkg.num_packages = 1;
1159
1160 return_PTR (state);
1161}
1162
1163
1164/*******************************************************************************
1165 *
1166 * FUNCTION: acpi_ut_create_control_state
1167 *
1168 * PARAMETERS: None
1169 *
1170 * RETURN: New state object, null on failure
1171 *
1172 * DESCRIPTION: Create a "Control State" - a flavor of the generic state used
1173 * to support nested IF/WHILE constructs in the AML.
1174 *
1175 ******************************************************************************/
1176
1177union acpi_generic_state *
1178acpi_ut_create_control_state (
1179 void)
1180{
1181 union acpi_generic_state *state;
1182
1183
1184 ACPI_FUNCTION_TRACE ("ut_create_control_state");
1185
1186
1187 /* Create the generic state object */
1188
1189 state = acpi_ut_create_generic_state ();
1190 if (!state) {
1191 return_PTR (NULL);
1192 }
1193
1194 /* Init fields specific to the control struct */
1195
1196 state->common.data_type = ACPI_DESC_TYPE_STATE_CONTROL;
1197 state->common.state = ACPI_CONTROL_CONDITIONAL_EXECUTING;
1198
1199 return_PTR (state);
1200}
1201
1202
1203/*******************************************************************************
1204 *
1205 * FUNCTION: acpi_ut_delete_generic_state
1206 *
1207 * PARAMETERS: State - The state object to be deleted
1208 *
1209 * RETURN: None
1210 *
1211 * DESCRIPTION: Put a state object back into the global state cache. The object
1212 * is not actually freed at this time.
1213 *
1214 ******************************************************************************/
1215
1216void
1217acpi_ut_delete_generic_state (
1218 union acpi_generic_state *state)
1219{
1220 ACPI_FUNCTION_TRACE ("ut_delete_generic_state");
1221
1222
1223 acpi_ut_release_to_cache (ACPI_MEM_LIST_STATE, state);
1224 return_VOID;
1225}
1226
1227
1228#ifdef ACPI_ENABLE_OBJECT_CACHE
1229/*******************************************************************************
1230 *
1231 * FUNCTION: acpi_ut_delete_generic_state_cache
1232 *
1233 * PARAMETERS: None
1234 *
1235 * RETURN: None
1236 *
1237 * DESCRIPTION: Purge the global state object cache. Used during subsystem
1238 * termination.
1239 *
1240 ******************************************************************************/
1241
1242void
1243acpi_ut_delete_generic_state_cache (
1244 void)
1245{
1246 ACPI_FUNCTION_TRACE ("ut_delete_generic_state_cache");
1247
1248
1249 acpi_ut_delete_generic_cache (ACPI_MEM_LIST_STATE);
1250 return_VOID;
1251}
1252#endif
1253
1254
1255/*******************************************************************************
1256 *
1257 * FUNCTION: acpi_ut_walk_package_tree 698 * FUNCTION: acpi_ut_walk_package_tree
1258 * 699 *
1259 * PARAMETERS: source_object - The package to walk 700 * PARAMETERS: source_object - The package to walk
diff --git a/drivers/acpi/utilities/utmutex.c b/drivers/acpi/utilities/utmutex.c
new file mode 100644
index 000000000000..0699b6be62b6
--- /dev/null
+++ b/drivers/acpi/utilities/utmutex.c
@@ -0,0 +1,380 @@
1/*******************************************************************************
2 *
3 * Module Name: utmutex - local mutex support
4 *
5 ******************************************************************************/
6
7/*
8 * Copyright (C) 2000 - 2005, R. Byron Moore
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#include <acpi/acpi.h>
46
47#define _COMPONENT ACPI_UTILITIES
48 ACPI_MODULE_NAME ("utmutex")
49
50/* Local prototypes */
51
52static acpi_status
53acpi_ut_create_mutex (
54 acpi_mutex_handle mutex_id);
55
56static acpi_status
57acpi_ut_delete_mutex (
58 acpi_mutex_handle mutex_id);
59
60
61/*******************************************************************************
62 *
63 * FUNCTION: acpi_ut_mutex_initialize
64 *
65 * PARAMETERS: None.
66 *
67 * RETURN: Status
68 *
69 * DESCRIPTION: Create the system mutex objects.
70 *
71 ******************************************************************************/
72
73acpi_status
74acpi_ut_mutex_initialize (
75 void)
76{
77 u32 i;
78 acpi_status status;
79
80
81 ACPI_FUNCTION_TRACE ("ut_mutex_initialize");
82
83
84 /*
85 * Create each of the predefined mutex objects
86 */
87 for (i = 0; i < NUM_MUTEX; i++) {
88 status = acpi_ut_create_mutex (i);
89 if (ACPI_FAILURE (status)) {
90 return_ACPI_STATUS (status);
91 }
92 }
93
94 status = acpi_os_create_lock (&acpi_gbl_gpe_lock);
95 return_ACPI_STATUS (status);
96}
97
98
99/*******************************************************************************
100 *
101 * FUNCTION: acpi_ut_mutex_terminate
102 *
103 * PARAMETERS: None.
104 *
105 * RETURN: None.
106 *
107 * DESCRIPTION: Delete all of the system mutex objects.
108 *
109 ******************************************************************************/
110
111void
112acpi_ut_mutex_terminate (
113 void)
114{
115 u32 i;
116
117
118 ACPI_FUNCTION_TRACE ("ut_mutex_terminate");
119
120
121 /*
122 * Delete each predefined mutex object
123 */
124 for (i = 0; i < NUM_MUTEX; i++) {
125 (void) acpi_ut_delete_mutex (i);
126 }
127
128 acpi_os_delete_lock (acpi_gbl_gpe_lock);
129 return_VOID;
130}
131
132
133/*******************************************************************************
134 *
135 * FUNCTION: acpi_ut_create_mutex
136 *
137 * PARAMETERS: mutex_iD - ID of the mutex to be created
138 *
139 * RETURN: Status
140 *
141 * DESCRIPTION: Create a mutex object.
142 *
143 ******************************************************************************/
144
145static acpi_status
146acpi_ut_create_mutex (
147 acpi_mutex_handle mutex_id)
148{
149 acpi_status status = AE_OK;
150
151
152 ACPI_FUNCTION_TRACE_U32 ("ut_create_mutex", mutex_id);
153
154
155 if (mutex_id > MAX_MUTEX) {
156 return_ACPI_STATUS (AE_BAD_PARAMETER);
157 }
158
159 if (!acpi_gbl_mutex_info[mutex_id].mutex) {
160 status = acpi_os_create_semaphore (1, 1,
161 &acpi_gbl_mutex_info[mutex_id].mutex);
162 acpi_gbl_mutex_info[mutex_id].thread_id = ACPI_MUTEX_NOT_ACQUIRED;
163 acpi_gbl_mutex_info[mutex_id].use_count = 0;
164 }
165
166 return_ACPI_STATUS (status);
167}
168
169
170/*******************************************************************************
171 *
172 * FUNCTION: acpi_ut_delete_mutex
173 *
174 * PARAMETERS: mutex_iD - ID of the mutex to be deleted
175 *
176 * RETURN: Status
177 *
178 * DESCRIPTION: Delete a mutex object.
179 *
180 ******************************************************************************/
181
182static acpi_status
183acpi_ut_delete_mutex (
184 acpi_mutex_handle mutex_id)
185{
186 acpi_status status;
187
188
189 ACPI_FUNCTION_TRACE_U32 ("ut_delete_mutex", mutex_id);
190
191
192 if (mutex_id > MAX_MUTEX) {
193 return_ACPI_STATUS (AE_BAD_PARAMETER);
194 }
195
196 status = acpi_os_delete_semaphore (acpi_gbl_mutex_info[mutex_id].mutex);
197
198 acpi_gbl_mutex_info[mutex_id].mutex = NULL;
199 acpi_gbl_mutex_info[mutex_id].thread_id = ACPI_MUTEX_NOT_ACQUIRED;
200
201 return_ACPI_STATUS (status);
202}
203
204
205/*******************************************************************************
206 *
207 * FUNCTION: acpi_ut_acquire_mutex
208 *
209 * PARAMETERS: mutex_iD - ID of the mutex to be acquired
210 *
211 * RETURN: Status
212 *
213 * DESCRIPTION: Acquire a mutex object.
214 *
215 ******************************************************************************/
216
217acpi_status
218acpi_ut_acquire_mutex (
219 acpi_mutex_handle mutex_id)
220{
221 acpi_status status;
222 u32 this_thread_id;
223
224
225 ACPI_FUNCTION_NAME ("ut_acquire_mutex");
226
227
228 if (mutex_id > MAX_MUTEX) {
229 return (AE_BAD_PARAMETER);
230 }
231
232 this_thread_id = acpi_os_get_thread_id ();
233
234#ifdef ACPI_MUTEX_DEBUG
235 {
236 u32 i;
237 /*
238 * Mutex debug code, for internal debugging only.
239 *
240 * Deadlock prevention. Check if this thread owns any mutexes of value
241 * greater than or equal to this one. If so, the thread has violated
242 * the mutex ordering rule. This indicates a coding error somewhere in
243 * the ACPI subsystem code.
244 */
245 for (i = mutex_id; i < MAX_MUTEX; i++) {
246 if (acpi_gbl_mutex_info[i].owner_id == this_thread_id) {
247 if (i == mutex_id) {
248 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
249 "Mutex [%s] already acquired by this thread [%X]\n",
250 acpi_ut_get_mutex_name (mutex_id), this_thread_id));
251
252 return (AE_ALREADY_ACQUIRED);
253 }
254
255 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
256 "Invalid acquire order: Thread %X owns [%s], wants [%s]\n",
257 this_thread_id, acpi_ut_get_mutex_name (i),
258 acpi_ut_get_mutex_name (mutex_id)));
259
260 return (AE_ACQUIRE_DEADLOCK);
261 }
262 }
263 }
264#endif
265
266 ACPI_DEBUG_PRINT ((ACPI_DB_MUTEX,
267 "Thread %X attempting to acquire Mutex [%s]\n",
268 this_thread_id, acpi_ut_get_mutex_name (mutex_id)));
269
270 status = acpi_os_wait_semaphore (acpi_gbl_mutex_info[mutex_id].mutex,
271 1, ACPI_WAIT_FOREVER);
272 if (ACPI_SUCCESS (status)) {
273 ACPI_DEBUG_PRINT ((ACPI_DB_MUTEX, "Thread %X acquired Mutex [%s]\n",
274 this_thread_id, acpi_ut_get_mutex_name (mutex_id)));
275
276 acpi_gbl_mutex_info[mutex_id].use_count++;
277 acpi_gbl_mutex_info[mutex_id].thread_id = this_thread_id;
278 }
279 else {
280 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
281 "Thread %X could not acquire Mutex [%s] %s\n",
282 this_thread_id, acpi_ut_get_mutex_name (mutex_id),
283 acpi_format_exception (status)));
284 }
285
286 return (status);
287}
288
289
290/*******************************************************************************
291 *
292 * FUNCTION: acpi_ut_release_mutex
293 *
294 * PARAMETERS: mutex_iD - ID of the mutex to be released
295 *
296 * RETURN: Status
297 *
298 * DESCRIPTION: Release a mutex object.
299 *
300 ******************************************************************************/
301
302acpi_status
303acpi_ut_release_mutex (
304 acpi_mutex_handle mutex_id)
305{
306 acpi_status status;
307 u32 this_thread_id;
308
309
310 ACPI_FUNCTION_NAME ("ut_release_mutex");
311
312
313 this_thread_id = acpi_os_get_thread_id ();
314 ACPI_DEBUG_PRINT ((ACPI_DB_MUTEX,
315 "Thread %X releasing Mutex [%s]\n", this_thread_id,
316 acpi_ut_get_mutex_name (mutex_id)));
317
318 if (mutex_id > MAX_MUTEX) {
319 return (AE_BAD_PARAMETER);
320 }
321
322 /*
323 * Mutex must be acquired in order to release it!
324 */
325 if (acpi_gbl_mutex_info[mutex_id].thread_id == ACPI_MUTEX_NOT_ACQUIRED) {
326 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
327 "Mutex [%s] is not acquired, cannot release\n",
328 acpi_ut_get_mutex_name (mutex_id)));
329
330 return (AE_NOT_ACQUIRED);
331 }
332
333#ifdef ACPI_MUTEX_DEBUG
334 {
335 u32 i;
336 /*
337 * Mutex debug code, for internal debugging only.
338 *
339 * Deadlock prevention. Check if this thread owns any mutexes of value
340 * greater than this one. If so, the thread has violated the mutex
341 * ordering rule. This indicates a coding error somewhere in
342 * the ACPI subsystem code.
343 */
344 for (i = mutex_id; i < MAX_MUTEX; i++) {
345 if (acpi_gbl_mutex_info[i].owner_id == this_thread_id) {
346 if (i == mutex_id) {
347 continue;
348 }
349
350 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
351 "Invalid release order: owns [%s], releasing [%s]\n",
352 acpi_ut_get_mutex_name (i), acpi_ut_get_mutex_name (mutex_id)));
353
354 return (AE_RELEASE_DEADLOCK);
355 }
356 }
357 }
358#endif
359
360 /* Mark unlocked FIRST */
361
362 acpi_gbl_mutex_info[mutex_id].thread_id = ACPI_MUTEX_NOT_ACQUIRED;
363
364 status = acpi_os_signal_semaphore (acpi_gbl_mutex_info[mutex_id].mutex, 1);
365
366 if (ACPI_FAILURE (status)) {
367 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
368 "Thread %X could not release Mutex [%s] %s\n",
369 this_thread_id, acpi_ut_get_mutex_name (mutex_id),
370 acpi_format_exception (status)));
371 }
372 else {
373 ACPI_DEBUG_PRINT ((ACPI_DB_MUTEX, "Thread %X released Mutex [%s]\n",
374 this_thread_id, acpi_ut_get_mutex_name (mutex_id)));
375 }
376
377 return (status);
378}
379
380
diff --git a/drivers/acpi/utilities/utobject.c b/drivers/acpi/utilities/utobject.c
index cd3899b9cc5a..19178e142951 100644
--- a/drivers/acpi/utilities/utobject.c
+++ b/drivers/acpi/utilities/utobject.c
@@ -338,7 +338,7 @@ acpi_ut_allocate_object_desc_dbg (
338 ACPI_FUNCTION_TRACE ("ut_allocate_object_desc_dbg"); 338 ACPI_FUNCTION_TRACE ("ut_allocate_object_desc_dbg");
339 339
340 340
341 object = acpi_ut_acquire_from_cache (ACPI_MEM_LIST_OPERAND); 341 object = acpi_os_acquire_object (acpi_gbl_operand_cache);
342 if (!object) { 342 if (!object) {
343 _ACPI_REPORT_ERROR (module_name, line_number, component_id, 343 _ACPI_REPORT_ERROR (module_name, line_number, component_id,
344 ("Could not allocate an object descriptor\n")); 344 ("Could not allocate an object descriptor\n"));
@@ -347,7 +347,7 @@ acpi_ut_allocate_object_desc_dbg (
347 } 347 }
348 348
349 /* Mark the descriptor type */ 349 /* Mark the descriptor type */
350 350 memset(object, 0, sizeof(union acpi_operand_object));
351 ACPI_SET_DESCRIPTOR_TYPE (object, ACPI_DESC_TYPE_OPERAND); 351 ACPI_SET_DESCRIPTOR_TYPE (object, ACPI_DESC_TYPE_OPERAND);
352 352
353 ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "%p Size %X\n", 353 ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "%p Size %X\n",
@@ -385,37 +385,9 @@ acpi_ut_delete_object_desc (
385 return_VOID; 385 return_VOID;
386 } 386 }
387 387
388 acpi_ut_release_to_cache (ACPI_MEM_LIST_OPERAND, object); 388 (void) acpi_os_release_object (acpi_gbl_operand_cache, object);
389
390 return_VOID;
391}
392
393
394#ifdef ACPI_ENABLE_OBJECT_CACHE
395/*******************************************************************************
396 *
397 * FUNCTION: acpi_ut_delete_object_cache
398 *
399 * PARAMETERS: None
400 *
401 * RETURN: None
402 *
403 * DESCRIPTION: Purge the global state object cache. Used during subsystem
404 * termination.
405 *
406 ******************************************************************************/
407
408void
409acpi_ut_delete_object_cache (
410 void)
411{
412 ACPI_FUNCTION_TRACE ("ut_delete_object_cache");
413
414
415 acpi_ut_delete_generic_cache (ACPI_MEM_LIST_OPERAND);
416 return_VOID; 389 return_VOID;
417} 390}
418#endif
419 391
420 392
421/******************************************************************************* 393/*******************************************************************************
diff --git a/drivers/acpi/utilities/utstate.c b/drivers/acpi/utilities/utstate.c
new file mode 100644
index 000000000000..192e7ac95690
--- /dev/null
+++ b/drivers/acpi/utilities/utstate.c
@@ -0,0 +1,376 @@
1/*******************************************************************************
2 *
3 * Module Name: utstate - state object support procedures
4 *
5 ******************************************************************************/
6
7/*
8 * Copyright (C) 2000 - 2005, R. Byron Moore
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#include <acpi/acpi.h>
46
47#define _COMPONENT ACPI_UTILITIES
48 ACPI_MODULE_NAME ("utstate")
49
50
51/*******************************************************************************
52 *
53 * FUNCTION: acpi_ut_create_pkg_state_and_push
54 *
55 * PARAMETERS: Object - Object to be added to the new state
56 * Action - Increment/Decrement
57 * state_list - List the state will be added to
58 *
59 * RETURN: Status
60 *
61 * DESCRIPTION: Create a new state and push it
62 *
63 ******************************************************************************/
64
65acpi_status
66acpi_ut_create_pkg_state_and_push (
67 void *internal_object,
68 void *external_object,
69 u16 index,
70 union acpi_generic_state **state_list)
71{
72 union acpi_generic_state *state;
73
74
75 ACPI_FUNCTION_ENTRY ();
76
77
78 state = acpi_ut_create_pkg_state (internal_object, external_object, index);
79 if (!state) {
80 return (AE_NO_MEMORY);
81 }
82
83 acpi_ut_push_generic_state (state_list, state);
84 return (AE_OK);
85}
86
87
88/*******************************************************************************
89 *
90 * FUNCTION: acpi_ut_push_generic_state
91 *
92 * PARAMETERS: list_head - Head of the state stack
93 * State - State object to push
94 *
95 * RETURN: None
96 *
97 * DESCRIPTION: Push a state object onto a state stack
98 *
99 ******************************************************************************/
100
101void
102acpi_ut_push_generic_state (
103 union acpi_generic_state **list_head,
104 union acpi_generic_state *state)
105{
106 ACPI_FUNCTION_TRACE ("ut_push_generic_state");
107
108
109 /* Push the state object onto the front of the list (stack) */
110
111 state->common.next = *list_head;
112 *list_head = state;
113
114 return_VOID;
115}
116
117
118/*******************************************************************************
119 *
120 * FUNCTION: acpi_ut_pop_generic_state
121 *
122 * PARAMETERS: list_head - Head of the state stack
123 *
124 * RETURN: The popped state object
125 *
126 * DESCRIPTION: Pop a state object from a state stack
127 *
128 ******************************************************************************/
129
130union acpi_generic_state *
131acpi_ut_pop_generic_state (
132 union acpi_generic_state **list_head)
133{
134 union acpi_generic_state *state;
135
136
137 ACPI_FUNCTION_TRACE ("ut_pop_generic_state");
138
139
140 /* Remove the state object at the head of the list (stack) */
141
142 state = *list_head;
143 if (state) {
144 /* Update the list head */
145
146 *list_head = state->common.next;
147 }
148
149 return_PTR (state);
150}
151
152
153/*******************************************************************************
154 *
155 * FUNCTION: acpi_ut_create_generic_state
156 *
157 * PARAMETERS: None
158 *
159 * RETURN: The new state object. NULL on failure.
160 *
161 * DESCRIPTION: Create a generic state object. Attempt to obtain one from
162 * the global state cache; If none available, create a new one.
163 *
164 ******************************************************************************/
165
166union acpi_generic_state *
167acpi_ut_create_generic_state (
168 void)
169{
170 union acpi_generic_state *state;
171
172
173 ACPI_FUNCTION_ENTRY ();
174
175
176 state = acpi_os_acquire_object (acpi_gbl_state_cache);
177 if (state) {
178 /* Initialize */
179 memset(state, 0, sizeof(union acpi_generic_state));
180 state->common.data_type = ACPI_DESC_TYPE_STATE;
181 }
182
183 return (state);
184}
185
186
187/*******************************************************************************
188 *
189 * FUNCTION: acpi_ut_create_thread_state
190 *
191 * PARAMETERS: None
192 *
193 * RETURN: New Thread State. NULL on failure
194 *
195 * DESCRIPTION: Create a "Thread State" - a flavor of the generic state used
196 * to track per-thread info during method execution
197 *
198 ******************************************************************************/
199
200struct acpi_thread_state *
201acpi_ut_create_thread_state (
202 void)
203{
204 union acpi_generic_state *state;
205
206
207 ACPI_FUNCTION_TRACE ("ut_create_thread_state");
208
209
210 /* Create the generic state object */
211
212 state = acpi_ut_create_generic_state ();
213 if (!state) {
214 return_PTR (NULL);
215 }
216
217 /* Init fields specific to the update struct */
218
219 state->common.data_type = ACPI_DESC_TYPE_STATE_THREAD;
220 state->thread.thread_id = acpi_os_get_thread_id ();
221
222 return_PTR ((struct acpi_thread_state *) state);
223}
224
225
226/*******************************************************************************
227 *
228 * FUNCTION: acpi_ut_create_update_state
229 *
230 * PARAMETERS: Object - Initial Object to be installed in the state
231 * Action - Update action to be performed
232 *
233 * RETURN: New state object, null on failure
234 *
235 * DESCRIPTION: Create an "Update State" - a flavor of the generic state used
236 * to update reference counts and delete complex objects such
237 * as packages.
238 *
239 ******************************************************************************/
240
241union acpi_generic_state *
242acpi_ut_create_update_state (
243 union acpi_operand_object *object,
244 u16 action)
245{
246 union acpi_generic_state *state;
247
248
249 ACPI_FUNCTION_TRACE_PTR ("ut_create_update_state", object);
250
251
252 /* Create the generic state object */
253
254 state = acpi_ut_create_generic_state ();
255 if (!state) {
256 return_PTR (NULL);
257 }
258
259 /* Init fields specific to the update struct */
260
261 state->common.data_type = ACPI_DESC_TYPE_STATE_UPDATE;
262 state->update.object = object;
263 state->update.value = action;
264
265 return_PTR (state);
266}
267
268
269/*******************************************************************************
270 *
271 * FUNCTION: acpi_ut_create_pkg_state
272 *
273 * PARAMETERS: Object - Initial Object to be installed in the state
274 * Action - Update action to be performed
275 *
276 * RETURN: New state object, null on failure
277 *
278 * DESCRIPTION: Create a "Package State"
279 *
280 ******************************************************************************/
281
282union acpi_generic_state *
283acpi_ut_create_pkg_state (
284 void *internal_object,
285 void *external_object,
286 u16 index)
287{
288 union acpi_generic_state *state;
289
290
291 ACPI_FUNCTION_TRACE_PTR ("ut_create_pkg_state", internal_object);
292
293
294 /* Create the generic state object */
295
296 state = acpi_ut_create_generic_state ();
297 if (!state) {
298 return_PTR (NULL);
299 }
300
301 /* Init fields specific to the update struct */
302
303 state->common.data_type = ACPI_DESC_TYPE_STATE_PACKAGE;
304 state->pkg.source_object = (union acpi_operand_object *) internal_object;
305 state->pkg.dest_object = external_object;
306 state->pkg.index = index;
307 state->pkg.num_packages = 1;
308
309 return_PTR (state);
310}
311
312
313/*******************************************************************************
314 *
315 * FUNCTION: acpi_ut_create_control_state
316 *
317 * PARAMETERS: None
318 *
319 * RETURN: New state object, null on failure
320 *
321 * DESCRIPTION: Create a "Control State" - a flavor of the generic state used
322 * to support nested IF/WHILE constructs in the AML.
323 *
324 ******************************************************************************/
325
326union acpi_generic_state *
327acpi_ut_create_control_state (
328 void)
329{
330 union acpi_generic_state *state;
331
332
333 ACPI_FUNCTION_TRACE ("ut_create_control_state");
334
335
336 /* Create the generic state object */
337
338 state = acpi_ut_create_generic_state ();
339 if (!state) {
340 return_PTR (NULL);
341 }
342
343 /* Init fields specific to the control struct */
344
345 state->common.data_type = ACPI_DESC_TYPE_STATE_CONTROL;
346 state->common.state = ACPI_CONTROL_CONDITIONAL_EXECUTING;
347
348 return_PTR (state);
349}
350
351
352/*******************************************************************************
353 *
354 * FUNCTION: acpi_ut_delete_generic_state
355 *
356 * PARAMETERS: State - The state object to be deleted
357 *
358 * RETURN: None
359 *
360 * DESCRIPTION: Put a state object back into the global state cache. The object
361 * is not actually freed at this time.
362 *
363 ******************************************************************************/
364
365void
366acpi_ut_delete_generic_state (
367 union acpi_generic_state *state)
368{
369 ACPI_FUNCTION_TRACE ("ut_delete_generic_state");
370
371
372 (void) acpi_os_release_object (acpi_gbl_state_cache, state);
373 return_VOID;
374}
375
376
diff --git a/drivers/acpi/utilities/utxface.c b/drivers/acpi/utilities/utxface.c
index e8803d810656..850da6817423 100644
--- a/drivers/acpi/utilities/utxface.c
+++ b/drivers/acpi/utilities/utxface.c
@@ -46,8 +46,6 @@
46#include <acpi/acpi.h> 46#include <acpi/acpi.h>
47#include <acpi/acevents.h> 47#include <acpi/acevents.h>
48#include <acpi/acnamesp.h> 48#include <acpi/acnamesp.h>
49#include <acpi/acparser.h>
50#include <acpi/acdispat.h>
51#include <acpi/acdebug.h> 49#include <acpi/acdebug.h>
52 50
53#define _COMPONENT ACPI_UTILITIES 51#define _COMPONENT ACPI_UTILITIES
@@ -79,11 +77,6 @@ acpi_initialize_subsystem (
79 77
80 ACPI_DEBUG_EXEC (acpi_ut_init_stack_ptr_trace ()); 78 ACPI_DEBUG_EXEC (acpi_ut_init_stack_ptr_trace ());
81 79
82
83 /* Initialize all globals used by the subsystem */
84
85 acpi_ut_init_globals ();
86
87 /* Initialize the OS-Dependent layer */ 80 /* Initialize the OS-Dependent layer */
88 81
89 status = acpi_os_initialize (); 82 status = acpi_os_initialize ();
@@ -93,6 +86,10 @@ acpi_initialize_subsystem (
93 return_ACPI_STATUS (status); 86 return_ACPI_STATUS (status);
94 } 87 }
95 88
89 /* Initialize all globals used by the subsystem */
90
91 acpi_ut_init_globals ();
92
96 /* Create the default mutex objects */ 93 /* Create the default mutex objects */
97 94
98 status = acpi_ut_mutex_initialize (); 95 status = acpi_ut_mutex_initialize ();
@@ -522,13 +519,9 @@ acpi_purge_cached_objects (
522{ 519{
523 ACPI_FUNCTION_TRACE ("acpi_purge_cached_objects"); 520 ACPI_FUNCTION_TRACE ("acpi_purge_cached_objects");
524 521
525 522 (void) acpi_os_purge_cache (acpi_gbl_state_cache);
526#ifdef ACPI_ENABLE_OBJECT_CACHE 523 (void) acpi_os_purge_cache (acpi_gbl_operand_cache);
527 acpi_ut_delete_generic_state_cache (); 524 (void) acpi_os_purge_cache (acpi_gbl_ps_node_cache);
528 acpi_ut_delete_object_cache (); 525 (void) acpi_os_purge_cache (acpi_gbl_ps_node_ext_cache);
529 acpi_ds_delete_walk_state_cache ();
530 acpi_ps_delete_parse_cache ();
531#endif
532
533 return_ACPI_STATUS (AE_OK); 526 return_ACPI_STATUS (AE_OK);
534} 527}