aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/acpi/utilities/utcache.c
diff options
context:
space:
mode:
authorRobert Moore <robert.moore@intel.com>2005-06-24 00:00:00 -0400
committerLen Brown <len.brown@intel.com>2005-07-13 23:45:36 -0400
commit73459f73e5d1602c59ebec114fc45185521353c1 (patch)
tree56c2183e345784d2be09c2f5d2530cf36221c55e /drivers/acpi/utilities/utcache.c
parent88ac00f5a841dcfc5c682000f4a6add0add8caac (diff)
ACPICA 20050617-0624 from Bob Moore <robert.moore@intel.com>
ACPICA 20050617: Moved the object cache operations into the OS interface layer (OSL) to allow the host OS to handle these operations if desired (for example, the Linux OSL will invoke the slab allocator). This support is optional; the compile time define ACPI_USE_LOCAL_CACHE may be used to utilize the original cache code in the ACPI CA core. The new OSL interfaces are shown below. See utalloc.c for an example implementation, and acpiosxf.h for the exact interface definitions. Thanks to Alexey Starikovskiy. acpi_os_create_cache acpi_os_delete_cache acpi_os_purge_cache acpi_os_acquire_object acpi_os_release_object Modified the interfaces to acpi_os_acquire_lock and acpi_os_release_lock to return and restore a flags parameter. This fits better with many OS lock models. Note: the current execution state (interrupt handler or not) is no longer passed to these interfaces. If necessary, the OSL must determine this state by itself, a simple and fast operation. Thanks to Alexey Starikovskiy. Fixed a problem in the ACPI table handling where a valid XSDT was assumed present if the revision of the RSDP was 2 or greater. According to the ACPI specification, the XSDT is optional in all cases, and the table manager therefore now checks for both an RSDP >=2 and a valid XSDT pointer. Otherwise, the RSDT pointer is used. Some ACPI 2.0 compliant BIOSs contain only the RSDT. Fixed an interpreter problem with the Mid() operator in the case of an input string where the resulting output string is of zero length. It now correctly returns a valid, null terminated string object instead of a string object with a null pointer. Fixed a problem with the control method argument handling to allow a store to an Arg object that already contains an object of type Device. The Device object is now correctly overwritten. Previously, an error was returned. ACPICA 20050624: Modified the new OSL cache interfaces to use ACPI_CACHE_T as the type for the host-defined cache object. This allows the OSL implementation to define and type this object in any manner desired, simplifying the OSL implementation. For example, ACPI_CACHE_T is defined as kmem_cache_t for Linux, and should be defined in the OS-specific header file for other operating systems as required. Changed the interface to AcpiOsAcquireObject to directly return the requested object as the function return (instead of ACPI_STATUS.) This change was made for performance reasons, since this is the purpose of the interface in the first place. acpi_os_acquire_object is now similar to the acpi_os_allocate interface. Thanks to Alexey Starikovskiy. Modified the initialization sequence in acpi_initialize_subsystem to call the OSL interface acpi_osl_initialize first, before any local initialization. This change was required because the global initialization now calls OSL interfaces. Restructured the code base to split some files because of size and/or because the code logically belonged in a separate file. New files are listed below. utilities/utcache.c /* Local cache interfaces */ utilities/utmutex.c /* Local mutex support */ utilities/utstate.c /* State object support */ parser/psloop.c /* Main AML parse loop */ Signed-off-by: Len Brown <len.brown@intel.com>
Diffstat (limited to 'drivers/acpi/utilities/utcache.c')
-rw-r--r--drivers/acpi/utilities/utcache.c322
1 files changed, 322 insertions, 0 deletions
diff --git a/drivers/acpi/utilities/utcache.c b/drivers/acpi/utilities/utcache.c
new file mode 100644
index 000000000000..07588812e72d
--- /dev/null
+++ b/drivers/acpi/utilities/utcache.c
@@ -0,0 +1,322 @@
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 if (!cache_name || !return_cache || (object_size < 16)) {
78 return (AE_BAD_PARAMETER);
79 }
80
81 /* Create the cache object */
82
83 cache = acpi_os_allocate (sizeof (struct acpi_memory_list));
84 if (!cache) {
85 return (AE_NO_MEMORY);
86 }
87
88 /* Populate the cache object and return it */
89
90 ACPI_MEMSET (cache, 0, sizeof (struct acpi_memory_list));
91 cache->link_offset = 8;
92 cache->list_name = cache_name;
93 cache->object_size = object_size;
94 cache->max_depth = max_depth;
95
96 *return_cache = cache;
97 return (AE_OK);
98}
99
100
101/*******************************************************************************
102 *
103 * FUNCTION: acpi_os_purge_cache
104 *
105 * PARAMETERS: Cache - Handle to cache object
106 *
107 * RETURN: Status
108 *
109 * DESCRIPTION: Free all objects within the requested cache.
110 *
111 ******************************************************************************/
112
113acpi_status
114acpi_os_purge_cache (
115 struct acpi_memory_list *cache)
116{
117 char *next;
118
119
120 ACPI_FUNCTION_ENTRY ();
121
122
123 if (!cache) {
124 return (AE_BAD_PARAMETER);
125 }
126
127 /* Walk the list of objects in this cache */
128
129 while (cache->list_head) {
130 /* Delete and unlink one cached state object */
131
132 next = *(ACPI_CAST_INDIRECT_PTR (char,
133 &(((char *) cache->list_head)[cache->link_offset])));
134 ACPI_MEM_FREE (cache->list_head);
135
136 cache->list_head = next;
137 cache->current_depth--;
138 }
139
140 return (AE_OK);
141}
142
143
144/*******************************************************************************
145 *
146 * FUNCTION: acpi_os_delete_cache
147 *
148 * PARAMETERS: Cache - Handle to cache object
149 *
150 * RETURN: Status
151 *
152 * DESCRIPTION: Free all objects within the requested cache and delete the
153 * cache object.
154 *
155 ******************************************************************************/
156
157acpi_status
158acpi_os_delete_cache (
159 struct acpi_memory_list *cache)
160{
161 acpi_status status;
162
163
164 /* Purge all objects in the cache */
165
166 status = acpi_os_purge_cache (cache);
167 if (ACPI_FAILURE (status)) {
168 return (status);
169 }
170
171 /* Now we can delete the cache object */
172
173 acpi_os_free (cache);
174 return (AE_OK);
175}
176
177
178/*******************************************************************************
179 *
180 * FUNCTION: acpi_os_release_object
181 *
182 * PARAMETERS: Cache - Handle to cache object
183 * Object - The object to be released
184 *
185 * RETURN: None
186 *
187 * DESCRIPTION: Release an object to the specified cache. If cache is full,
188 * the object is deleted.
189 *
190 ******************************************************************************/
191
192acpi_status
193acpi_os_release_object (
194 struct acpi_memory_list *cache,
195 void *object)
196{
197 acpi_status status;
198
199
200 ACPI_FUNCTION_ENTRY ();
201
202
203 if (!cache || !object) {
204 return (AE_BAD_PARAMETER);
205 }
206
207 /* If cache is full, just free this object */
208
209 if (cache->current_depth >= cache->max_depth) {
210 ACPI_MEM_FREE (object);
211 ACPI_MEM_TRACKING (cache->total_freed++);
212 }
213
214 /* Otherwise put this object back into the cache */
215
216 else {
217 status = acpi_ut_acquire_mutex (ACPI_MTX_CACHES);
218 if (ACPI_FAILURE (status)) {
219 return (status);
220 }
221
222 /* Mark the object as cached */
223
224 ACPI_MEMSET (object, 0xCA, cache->object_size);
225 ACPI_SET_DESCRIPTOR_TYPE (object, ACPI_DESC_TYPE_CACHED);
226
227 /* Put the object at the head of the cache list */
228
229 * (ACPI_CAST_INDIRECT_PTR (char,
230 &(((char *) object)[cache->link_offset]))) = cache->list_head;
231 cache->list_head = object;
232 cache->current_depth++;
233
234 (void) acpi_ut_release_mutex (ACPI_MTX_CACHES);
235 }
236
237 return (AE_OK);
238}
239
240
241/*******************************************************************************
242 *
243 * FUNCTION: acpi_os_acquire_object
244 *
245 * PARAMETERS: Cache - Handle to cache object
246 *
247 * RETURN: the acquired object. NULL on error
248 *
249 * DESCRIPTION: Get an object from the specified cache. If cache is empty,
250 * the object is allocated.
251 *
252 ******************************************************************************/
253
254void *
255acpi_os_acquire_object (
256 struct acpi_memory_list *cache)
257{
258 acpi_status status;
259 void *object;
260
261
262 ACPI_FUNCTION_NAME ("ut_acquire_from_cache");
263
264
265 if (!cache) {
266 return (NULL);
267 }
268
269 status = acpi_ut_acquire_mutex (ACPI_MTX_CACHES);
270 if (ACPI_FAILURE (status)) {
271 return (NULL);
272 }
273
274 ACPI_MEM_TRACKING (cache->requests++);
275
276 /* Check the cache first */
277
278 if (cache->list_head) {
279 /* There is an object available, use it */
280
281 object = cache->list_head;
282 cache->list_head = *(ACPI_CAST_INDIRECT_PTR (char,
283 &(((char *) object)[cache->link_offset])));
284
285 cache->current_depth--;
286
287 ACPI_MEM_TRACKING (cache->hits++);
288 ACPI_MEM_TRACKING (ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
289 "Object %p from %s\n", object, cache->list_name)));
290
291 status = acpi_ut_release_mutex (ACPI_MTX_CACHES);
292 if (ACPI_FAILURE (status)) {
293 return (NULL);
294 }
295
296 /* Clear (zero) the previously used Object */
297
298 ACPI_MEMSET (object, 0, cache->object_size);
299 }
300 else {
301 /* The cache is empty, create a new object */
302
303 ACPI_MEM_TRACKING (cache->total_allocated++);
304
305 /* Avoid deadlock with ACPI_MEM_CALLOCATE */
306
307 status = acpi_ut_release_mutex (ACPI_MTX_CACHES);
308 if (ACPI_FAILURE (status)) {
309 return (NULL);
310 }
311
312 object = ACPI_MEM_CALLOCATE (cache->object_size);
313 if (!object) {
314 return (NULL);
315 }
316 }
317
318 return (object);
319}
320#endif /* ACPI_USE_LOCAL_CACHE */
321
322