Print this page
update to acpica-unix2-20140114
update to acpica-unix2-20131218
acpica-unix2-20130823
PANKOVs restructure
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/intel/io/acpica/utilities/utcache.c
+++ new/usr/src/common/acpica/components/utilities/utcache.c
1 1 /******************************************************************************
2 2 *
3 3 * Module Name: utcache - local cache allocation routines
4 4 *
5 5 *****************************************************************************/
6 6
7 7 /*
8 - * Copyright (C) 2000 - 2011, Intel Corp.
8 + * Copyright (C) 2000 - 2014, Intel Corp.
9 9 * All rights reserved.
10 10 *
11 11 * Redistribution and use in source and binary forms, with or without
12 12 * modification, are permitted provided that the following conditions
13 13 * are met:
14 14 * 1. Redistributions of source code must retain the above copyright
15 15 * notice, this list of conditions, and the following disclaimer,
16 16 * without modification.
17 17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 18 * substantially similar to the "NO WARRANTY" disclaimer below
19 19 * ("Disclaimer") and any redistribution must be conditioned upon
20 20 * including a substantially similar Disclaimer requirement for further
21 21 * binary redistribution.
22 22 * 3. Neither the names of the above-listed copyright holders nor the names
23 23 * of any contributors may be used to endorse or promote products derived
24 24 * from this software without specific prior written permission.
25 25 *
26 26 * Alternatively, this software may be distributed under the terms of the
27 27 * GNU General Public License ("GPL") version 2 as published by the Free
28 28 * Software Foundation.
29 29 *
30 30 * NO WARRANTY
31 31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 41 * POSSIBILITY OF SUCH DAMAGES.
42 42 */
43 43
44 44 #define __UTCACHE_C__
45 45
46 46 #include "acpi.h"
47 47 #include "accommon.h"
48 48
49 49 #define _COMPONENT ACPI_UTILITIES
50 50 ACPI_MODULE_NAME ("utcache")
51 51
52 52
53 53 #ifdef ACPI_USE_LOCAL_CACHE
54 54 /*******************************************************************************
55 55 *
56 56 * FUNCTION: AcpiOsCreateCache
57 57 *
58 58 * PARAMETERS: CacheName - Ascii name for the cache
59 59 * ObjectSize - Size of each cached object
60 60 * MaxDepth - Maximum depth of the cache (in objects)
61 61 * ReturnCache - Where the new cache object is returned
62 62 *
63 63 * RETURN: Status
64 64 *
65 65 * DESCRIPTION: Create a cache object
66 66 *
67 67 ******************************************************************************/
68 68
69 69 ACPI_STATUS
70 70 AcpiOsCreateCache (
71 71 char *CacheName,
72 72 UINT16 ObjectSize,
73 73 UINT16 MaxDepth,
74 74 ACPI_MEMORY_LIST **ReturnCache)
75 75 {
76 76 ACPI_MEMORY_LIST *Cache;
77 77
78 78
79 79 ACPI_FUNCTION_ENTRY ();
80 80
81 81
82 82 if (!CacheName || !ReturnCache || (ObjectSize < 16))
83 83 {
84 84 return (AE_BAD_PARAMETER);
85 85 }
86 86
87 87 /* Create the cache object */
↓ open down ↓ |
69 lines elided |
↑ open up ↑ |
88 88
89 89 Cache = AcpiOsAllocate (sizeof (ACPI_MEMORY_LIST));
90 90 if (!Cache)
91 91 {
92 92 return (AE_NO_MEMORY);
93 93 }
94 94
95 95 /* Populate the cache object and return it */
96 96
97 97 ACPI_MEMSET (Cache, 0, sizeof (ACPI_MEMORY_LIST));
98 - Cache->LinkOffset = 8;
99 98 Cache->ListName = CacheName;
100 99 Cache->ObjectSize = ObjectSize;
101 100 Cache->MaxDepth = MaxDepth;
102 101
103 102 *ReturnCache = Cache;
104 103 return (AE_OK);
105 104 }
106 105
107 106
108 107 /*******************************************************************************
109 108 *
110 109 * FUNCTION: AcpiOsPurgeCache
111 110 *
112 111 * PARAMETERS: Cache - Handle to cache object
113 112 *
↓ open down ↓ |
5 lines elided |
↑ open up ↑ |
114 113 * RETURN: Status
115 114 *
116 115 * DESCRIPTION: Free all objects within the requested cache.
117 116 *
118 117 ******************************************************************************/
119 118
120 119 ACPI_STATUS
121 120 AcpiOsPurgeCache (
122 121 ACPI_MEMORY_LIST *Cache)
123 122 {
124 - char *Next;
123 + void *Next;
125 124 ACPI_STATUS Status;
126 125
127 126
128 127 ACPI_FUNCTION_ENTRY ();
129 128
130 129
131 130 if (!Cache)
132 131 {
133 132 return (AE_BAD_PARAMETER);
134 133 }
135 134
136 135 Status = AcpiUtAcquireMutex (ACPI_MTX_CACHES);
137 136 if (ACPI_FAILURE (Status))
↓ open down ↓ |
3 lines elided |
↑ open up ↑ |
138 137 {
139 138 return (Status);
140 139 }
141 140
142 141 /* Walk the list of objects in this cache */
143 142
144 143 while (Cache->ListHead)
145 144 {
146 145 /* Delete and unlink one cached state object */
147 146
148 - Next = *(ACPI_CAST_INDIRECT_PTR (char,
149 - &(((char *) Cache->ListHead)[Cache->LinkOffset])));
147 + Next = ACPI_GET_DESCRIPTOR_PTR (Cache->ListHead);
150 148 ACPI_FREE (Cache->ListHead);
151 149
152 150 Cache->ListHead = Next;
153 151 Cache->CurrentDepth--;
154 152 }
155 153
156 154 (void) AcpiUtReleaseMutex (ACPI_MTX_CACHES);
157 155 return (AE_OK);
158 156 }
159 157
160 158
161 159 /*******************************************************************************
162 160 *
163 161 * FUNCTION: AcpiOsDeleteCache
164 162 *
165 163 * PARAMETERS: Cache - Handle to cache object
166 164 *
167 165 * RETURN: Status
168 166 *
169 167 * DESCRIPTION: Free all objects within the requested cache and delete the
170 168 * cache object.
171 169 *
172 170 ******************************************************************************/
173 171
174 172 ACPI_STATUS
175 173 AcpiOsDeleteCache (
176 174 ACPI_MEMORY_LIST *Cache)
177 175 {
178 176 ACPI_STATUS Status;
179 177
180 178
181 179 ACPI_FUNCTION_ENTRY ();
182 180
183 181
184 182 /* Purge all objects in the cache */
185 183
186 184 Status = AcpiOsPurgeCache (Cache);
187 185 if (ACPI_FAILURE (Status))
188 186 {
189 187 return (Status);
190 188 }
191 189
192 190 /* Now we can delete the cache object */
193 191
194 192 AcpiOsFree (Cache);
195 193 return (AE_OK);
196 194 }
197 195
↓ open down ↓ |
38 lines elided |
↑ open up ↑ |
198 196
199 197 /*******************************************************************************
200 198 *
201 199 * FUNCTION: AcpiOsReleaseObject
202 200 *
203 201 * PARAMETERS: Cache - Handle to cache object
204 202 * Object - The object to be released
205 203 *
206 204 * RETURN: None
207 205 *
208 - * DESCRIPTION: Release an object to the specified cache. If cache is full,
206 + * DESCRIPTION: Release an object to the specified cache. If cache is full,
209 207 * the object is deleted.
210 208 *
211 209 ******************************************************************************/
212 210
213 211 ACPI_STATUS
214 212 AcpiOsReleaseObject (
215 213 ACPI_MEMORY_LIST *Cache,
216 214 void *Object)
217 215 {
218 216 ACPI_STATUS Status;
219 217
220 218
221 219 ACPI_FUNCTION_ENTRY ();
222 220
223 221
224 222 if (!Cache || !Object)
225 223 {
226 224 return (AE_BAD_PARAMETER);
227 225 }
228 226
229 227 /* If cache is full, just free this object */
230 228
231 229 if (Cache->CurrentDepth >= Cache->MaxDepth)
232 230 {
233 231 ACPI_FREE (Object);
234 232 ACPI_MEM_TRACKING (Cache->TotalFreed++);
235 233 }
236 234
237 235 /* Otherwise put this object back into the cache */
238 236
239 237 else
240 238 {
241 239 Status = AcpiUtAcquireMutex (ACPI_MTX_CACHES);
242 240 if (ACPI_FAILURE (Status))
243 241 {
↓ open down ↓ |
25 lines elided |
↑ open up ↑ |
244 242 return (Status);
245 243 }
246 244
247 245 /* Mark the object as cached */
248 246
249 247 ACPI_MEMSET (Object, 0xCA, Cache->ObjectSize);
250 248 ACPI_SET_DESCRIPTOR_TYPE (Object, ACPI_DESC_TYPE_CACHED);
251 249
252 250 /* Put the object at the head of the cache list */
253 251
254 - * (ACPI_CAST_INDIRECT_PTR (char,
255 - &(((char *) Object)[Cache->LinkOffset]))) = Cache->ListHead;
252 + ACPI_SET_DESCRIPTOR_PTR (Object, Cache->ListHead);
256 253 Cache->ListHead = Object;
257 254 Cache->CurrentDepth++;
258 255
259 256 (void) AcpiUtReleaseMutex (ACPI_MTX_CACHES);
260 257 }
261 258
262 259 return (AE_OK);
263 260 }
264 261
265 262
266 263 /*******************************************************************************
267 264 *
268 265 * FUNCTION: AcpiOsAcquireObject
269 266 *
270 267 * PARAMETERS: Cache - Handle to cache object
271 268 *
272 - * RETURN: the acquired object. NULL on error
269 + * RETURN: the acquired object. NULL on error
273 270 *
274 - * DESCRIPTION: Get an object from the specified cache. If cache is empty,
271 + * DESCRIPTION: Get an object from the specified cache. If cache is empty,
275 272 * the object is allocated.
276 273 *
277 274 ******************************************************************************/
278 275
279 276 void *
280 277 AcpiOsAcquireObject (
281 278 ACPI_MEMORY_LIST *Cache)
282 279 {
283 280 ACPI_STATUS Status;
284 281 void *Object;
285 282
286 283
287 284 ACPI_FUNCTION_NAME (OsAcquireObject);
288 285
289 286
290 287 if (!Cache)
291 288 {
292 - return (NULL);
289 + return_PTR (NULL);
293 290 }
294 291
295 292 Status = AcpiUtAcquireMutex (ACPI_MTX_CACHES);
296 293 if (ACPI_FAILURE (Status))
297 294 {
298 - return (NULL);
295 + return_PTR (NULL);
299 296 }
300 297
301 298 ACPI_MEM_TRACKING (Cache->Requests++);
302 299
303 300 /* Check the cache first */
304 301
305 302 if (Cache->ListHead)
306 303 {
307 304 /* There is an object available, use it */
308 305
309 306 Object = Cache->ListHead;
310 - Cache->ListHead = *(ACPI_CAST_INDIRECT_PTR (char,
311 - &(((char *) Object)[Cache->LinkOffset])));
307 + Cache->ListHead = ACPI_GET_DESCRIPTOR_PTR (Object);
312 308
313 309 Cache->CurrentDepth--;
314 310
315 311 ACPI_MEM_TRACKING (Cache->Hits++);
316 312 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
317 313 "Object %p from %s cache\n", Object, Cache->ListName));
318 314
319 315 Status = AcpiUtReleaseMutex (ACPI_MTX_CACHES);
320 316 if (ACPI_FAILURE (Status))
321 317 {
322 - return (NULL);
318 + return_PTR (NULL);
323 319 }
324 320
325 321 /* Clear (zero) the previously used Object */
326 322
327 323 ACPI_MEMSET (Object, 0, Cache->ObjectSize);
328 324 }
329 325 else
330 326 {
331 327 /* The cache is empty, create a new object */
332 328
333 329 ACPI_MEM_TRACKING (Cache->TotalAllocated++);
334 330
335 331 #ifdef ACPI_DBG_TRACK_ALLOCATIONS
336 332 if ((Cache->TotalAllocated - Cache->TotalFreed) > Cache->MaxOccupied)
↓ open down ↓ |
4 lines elided |
↑ open up ↑ |
337 333 {
338 334 Cache->MaxOccupied = Cache->TotalAllocated - Cache->TotalFreed;
339 335 }
340 336 #endif
341 337
342 338 /* Avoid deadlock with ACPI_ALLOCATE_ZEROED */
343 339
344 340 Status = AcpiUtReleaseMutex (ACPI_MTX_CACHES);
345 341 if (ACPI_FAILURE (Status))
346 342 {
347 - return (NULL);
343 + return_PTR (NULL);
348 344 }
349 345
350 346 Object = ACPI_ALLOCATE_ZEROED (Cache->ObjectSize);
351 347 if (!Object)
352 348 {
353 - return (NULL);
349 + return_PTR (NULL);
354 350 }
355 351 }
356 352
357 - return (Object);
353 + return_PTR (Object);
358 354 }
359 355 #endif /* ACPI_USE_LOCAL_CACHE */
360 -
361 -
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX