Print this page
update to acpica-unix2-20131218
update to acpica-unix2-20130927
acpica-unix2-20130823
PANKOVs restructure
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/intel/io/acpica/utilities/utalloc.c
+++ new/usr/src/common/acpica/components/utilities/utalloc.c
1 1 /******************************************************************************
2 2 *
3 3 * Module Name: utalloc - local memory allocation routines
4 4 *
5 5 *****************************************************************************/
6 6
7 7 /*
8 - * Copyright (C) 2000 - 2011, Intel Corp.
8 + * Copyright (C) 2000 - 2013, 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
↓ open down ↓ |
25 lines elided |
↑ open up ↑ |
44 44 #define __UTALLOC_C__
45 45
46 46 #include "acpi.h"
47 47 #include "accommon.h"
48 48 #include "acdebug.h"
49 49
50 50 #define _COMPONENT ACPI_UTILITIES
51 51 ACPI_MODULE_NAME ("utalloc")
52 52
53 53
54 +#if !defined (USE_NATIVE_ALLOCATE_ZEROED)
54 55 /*******************************************************************************
55 56 *
57 + * FUNCTION: AcpiOsAllocateZeroed
58 + *
59 + * PARAMETERS: Size - Size of the allocation
60 + *
61 + * RETURN: Address of the allocated memory on success, NULL on failure.
62 + *
63 + * DESCRIPTION: Subsystem equivalent of calloc. Allocate and zero memory.
64 + * This is the default implementation. Can be overridden via the
65 + * USE_NATIVE_ALLOCATE_ZEROED flag.
66 + *
67 + ******************************************************************************/
68 +
69 +void *
70 +AcpiOsAllocateZeroed (
71 + ACPI_SIZE Size)
72 +{
73 + void *Allocation;
74 +
75 +
76 + ACPI_FUNCTION_ENTRY ();
77 +
78 +
79 + Allocation = AcpiOsAllocate (Size);
80 + if (Allocation)
81 + {
82 + /* Clear the memory block */
83 +
84 + ACPI_MEMSET (Allocation, 0, Size);
85 + }
86 +
87 + return (Allocation);
88 +}
89 +
90 +#endif /* !USE_NATIVE_ALLOCATE_ZEROED */
91 +
92 +
93 +/*******************************************************************************
94 + *
56 95 * FUNCTION: AcpiUtCreateCaches
57 96 *
58 97 * PARAMETERS: None
59 98 *
60 99 * RETURN: Status
61 100 *
62 101 * DESCRIPTION: Create all local caches
63 102 *
64 103 ******************************************************************************/
65 104
66 105 ACPI_STATUS
67 106 AcpiUtCreateCaches (
68 107 void)
69 108 {
70 109 ACPI_STATUS Status;
71 110
72 111
73 112 /* Object Caches, for frequently used objects */
74 113
75 114 Status = AcpiOsCreateCache ("Acpi-Namespace", sizeof (ACPI_NAMESPACE_NODE),
76 115 ACPI_MAX_NAMESPACE_CACHE_DEPTH, &AcpiGbl_NamespaceCache);
77 116 if (ACPI_FAILURE (Status))
78 117 {
79 118 return (Status);
80 119 }
81 120
82 121 Status = AcpiOsCreateCache ("Acpi-State", sizeof (ACPI_GENERIC_STATE),
83 122 ACPI_MAX_STATE_CACHE_DEPTH, &AcpiGbl_StateCache);
84 123 if (ACPI_FAILURE (Status))
85 124 {
86 125 return (Status);
87 126 }
88 127
89 128 Status = AcpiOsCreateCache ("Acpi-Parse", sizeof (ACPI_PARSE_OBJ_COMMON),
90 129 ACPI_MAX_PARSE_CACHE_DEPTH, &AcpiGbl_PsNodeCache);
91 130 if (ACPI_FAILURE (Status))
92 131 {
93 132 return (Status);
94 133 }
95 134
96 135 Status = AcpiOsCreateCache ("Acpi-ParseExt", sizeof (ACPI_PARSE_OBJ_NAMED),
97 136 ACPI_MAX_EXTPARSE_CACHE_DEPTH, &AcpiGbl_PsNodeExtCache);
98 137 if (ACPI_FAILURE (Status))
99 138 {
100 139 return (Status);
101 140 }
102 141
103 142 Status = AcpiOsCreateCache ("Acpi-Operand", sizeof (ACPI_OPERAND_OBJECT),
104 143 ACPI_MAX_OBJECT_CACHE_DEPTH, &AcpiGbl_OperandCache);
105 144 if (ACPI_FAILURE (Status))
106 145 {
107 146 return (Status);
108 147 }
109 148
110 149
111 150 #ifdef ACPI_DBG_TRACK_ALLOCATIONS
112 151
113 152 /* Memory allocation lists */
114 153
115 154 Status = AcpiUtCreateList ("Acpi-Global", 0,
116 155 &AcpiGbl_GlobalList);
117 156 if (ACPI_FAILURE (Status))
118 157 {
119 158 return (Status);
120 159 }
121 160
122 161 Status = AcpiUtCreateList ("Acpi-Namespace", sizeof (ACPI_NAMESPACE_NODE),
123 162 &AcpiGbl_NsNodeList);
124 163 if (ACPI_FAILURE (Status))
125 164 {
126 165 return (Status);
127 166 }
128 167 #endif
129 168
130 169 return (AE_OK);
131 170 }
132 171
133 172
134 173 /*******************************************************************************
135 174 *
136 175 * FUNCTION: AcpiUtDeleteCaches
137 176 *
138 177 * PARAMETERS: None
139 178 *
140 179 * RETURN: Status
141 180 *
142 181 * DESCRIPTION: Purge and delete all local caches
143 182 *
144 183 ******************************************************************************/
145 184
146 185 ACPI_STATUS
147 186 AcpiUtDeleteCaches (
148 187 void)
149 188 {
150 189 #ifdef ACPI_DBG_TRACK_ALLOCATIONS
151 190 char Buffer[7];
152 191
153 192 if (AcpiGbl_DisplayFinalMemStats)
154 193 {
155 194 ACPI_STRCPY (Buffer, "MEMORY");
156 195 (void) AcpiDbDisplayStatistics (Buffer);
157 196 }
158 197 #endif
159 198
160 199 (void) AcpiOsDeleteCache (AcpiGbl_NamespaceCache);
161 200 AcpiGbl_NamespaceCache = NULL;
162 201
163 202 (void) AcpiOsDeleteCache (AcpiGbl_StateCache);
164 203 AcpiGbl_StateCache = NULL;
165 204
166 205 (void) AcpiOsDeleteCache (AcpiGbl_OperandCache);
167 206 AcpiGbl_OperandCache = NULL;
168 207
169 208 (void) AcpiOsDeleteCache (AcpiGbl_PsNodeCache);
170 209 AcpiGbl_PsNodeCache = NULL;
171 210
172 211 (void) AcpiOsDeleteCache (AcpiGbl_PsNodeExtCache);
173 212 AcpiGbl_PsNodeExtCache = NULL;
174 213
175 214
176 215 #ifdef ACPI_DBG_TRACK_ALLOCATIONS
177 216
178 217 /* Debug only - display leftover memory allocation, if any */
179 218
180 219 AcpiUtDumpAllocations (ACPI_UINT32_MAX, NULL);
181 220
182 221 /* Free memory lists */
183 222
184 223 AcpiOsFree (AcpiGbl_GlobalList);
185 224 AcpiGbl_GlobalList = NULL;
186 225
187 226 AcpiOsFree (AcpiGbl_NsNodeList);
188 227 AcpiGbl_NsNodeList = NULL;
189 228 #endif
190 229
191 230 return (AE_OK);
192 231 }
193 232
194 233
195 234 /*******************************************************************************
196 235 *
197 236 * FUNCTION: AcpiUtValidateBuffer
198 237 *
199 238 * PARAMETERS: Buffer - Buffer descriptor to be validated
200 239 *
201 240 * RETURN: Status
202 241 *
203 242 * DESCRIPTION: Perform parameter validation checks on an ACPI_BUFFER
204 243 *
205 244 ******************************************************************************/
206 245
207 246 ACPI_STATUS
208 247 AcpiUtValidateBuffer (
209 248 ACPI_BUFFER *Buffer)
210 249 {
211 250
212 251 /* Obviously, the structure pointer must be valid */
213 252
214 253 if (!Buffer)
215 254 {
216 255 return (AE_BAD_PARAMETER);
217 256 }
218 257
219 258 /* Special semantics for the length */
220 259
221 260 if ((Buffer->Length == ACPI_NO_BUFFER) ||
222 261 (Buffer->Length == ACPI_ALLOCATE_BUFFER) ||
223 262 (Buffer->Length == ACPI_ALLOCATE_LOCAL_BUFFER))
224 263 {
225 264 return (AE_OK);
226 265 }
227 266
228 267 /* Length is valid, the buffer pointer must be also */
229 268
230 269 if (!Buffer->Pointer)
231 270 {
232 271 return (AE_BAD_PARAMETER);
233 272 }
234 273
235 274 return (AE_OK);
236 275 }
237 276
238 277
239 278 /*******************************************************************************
240 279 *
241 280 * FUNCTION: AcpiUtInitializeBuffer
242 281 *
243 282 * PARAMETERS: Buffer - Buffer to be validated
244 283 * RequiredLength - Length needed
245 284 *
246 285 * RETURN: Status
247 286 *
248 287 * DESCRIPTION: Validate that the buffer is of the required length or
249 288 * allocate a new buffer. Returned buffer is always zeroed.
250 289 *
251 290 ******************************************************************************/
252 291
253 292 ACPI_STATUS
254 293 AcpiUtInitializeBuffer (
255 294 ACPI_BUFFER *Buffer,
256 295 ACPI_SIZE RequiredLength)
257 296 {
258 297 ACPI_SIZE InputBufferLength;
259 298
260 299
261 300 /* Parameter validation */
262 301
263 302 if (!Buffer || !RequiredLength)
264 303 {
265 304 return (AE_BAD_PARAMETER);
266 305 }
267 306
268 307 /*
269 308 * Buffer->Length is used as both an input and output parameter. Get the
270 309 * input actual length and set the output required buffer length.
271 310 */
272 311 InputBufferLength = Buffer->Length;
273 312 Buffer->Length = RequiredLength;
274 313
275 314 /*
276 315 * The input buffer length contains the actual buffer length, or the type
277 316 * of buffer to be allocated by this routine.
↓ open down ↓ |
212 lines elided |
↑ open up ↑ |
278 317 */
279 318 switch (InputBufferLength)
280 319 {
281 320 case ACPI_NO_BUFFER:
282 321
283 322 /* Return the exception (and the required buffer length) */
284 323
285 324 return (AE_BUFFER_OVERFLOW);
286 325
287 326 case ACPI_ALLOCATE_BUFFER:
288 -
289 - /* Allocate a new buffer */
290 -
327 + /*
328 + * Allocate a new buffer. We directectly call AcpiOsAllocate here to
329 + * purposefully bypass the (optionally enabled) internal allocation
330 + * tracking mechanism since we only want to track internal
331 + * allocations. Note: The caller should use AcpiOsFree to free this
332 + * buffer created via ACPI_ALLOCATE_BUFFER.
333 + */
291 334 Buffer->Pointer = AcpiOsAllocate (RequiredLength);
292 335 break;
293 336
294 337 case ACPI_ALLOCATE_LOCAL_BUFFER:
295 338
296 339 /* Allocate a new buffer with local interface to allow tracking */
297 340
298 341 Buffer->Pointer = ACPI_ALLOCATE (RequiredLength);
299 342 break;
300 343
301 344 default:
302 345
303 346 /* Existing buffer: Validate the size of the buffer */
304 347
305 348 if (InputBufferLength < RequiredLength)
306 349 {
307 350 return (AE_BUFFER_OVERFLOW);
308 351 }
309 352 break;
310 353 }
311 354
312 355 /* Validate allocation from above or input buffer pointer */
313 356
↓ open down ↓ |
13 lines elided |
↑ open up ↑ |
314 357 if (!Buffer->Pointer)
315 358 {
316 359 return (AE_NO_MEMORY);
317 360 }
318 361
319 362 /* Have a valid buffer, clear it */
320 363
321 364 ACPI_MEMSET (Buffer->Pointer, 0, RequiredLength);
322 365 return (AE_OK);
323 366 }
324 -
325 -
326 -/*******************************************************************************
327 - *
328 - * FUNCTION: AcpiUtAllocate
329 - *
330 - * PARAMETERS: Size - Size of the allocation
331 - * Component - Component type of caller
332 - * Module - Source file name of caller
333 - * Line - Line number of caller
334 - *
335 - * RETURN: Address of the allocated memory on success, NULL on failure.
336 - *
337 - * DESCRIPTION: Subsystem equivalent of malloc.
338 - *
339 - ******************************************************************************/
340 -
341 -void *
342 -AcpiUtAllocate (
343 - ACPI_SIZE Size,
344 - UINT32 Component,
345 - const char *Module,
346 - UINT32 Line)
347 -{
348 - void *Allocation;
349 -
350 -
351 - ACPI_FUNCTION_TRACE_U32 (UtAllocate, Size);
352 -
353 -
354 - /* Check for an inadvertent size of zero bytes */
355 -
356 - if (!Size)
357 - {
358 - ACPI_WARNING ((Module, Line,
359 - "Attempt to allocate zero bytes, allocating 1 byte"));
360 - Size = 1;
361 - }
362 -
363 - Allocation = AcpiOsAllocate (Size);
364 - if (!Allocation)
365 - {
366 - /* Report allocation error */
367 -
368 - ACPI_WARNING ((Module, Line,
369 - "Could not allocate size %u", (UINT32) Size));
370 -
371 - return_PTR (NULL);
372 - }
373 -
374 - return_PTR (Allocation);
375 -}
376 -
377 -
378 -/*******************************************************************************
379 - *
380 - * FUNCTION: AcpiUtAllocateZeroed
381 - *
382 - * PARAMETERS: Size - Size of the allocation
383 - * Component - Component type of caller
384 - * Module - Source file name of caller
385 - * Line - Line number of caller
386 - *
387 - * RETURN: Address of the allocated memory on success, NULL on failure.
388 - *
389 - * DESCRIPTION: Subsystem equivalent of calloc. Allocate and zero memory.
390 - *
391 - ******************************************************************************/
392 -
393 -void *
394 -AcpiUtAllocateZeroed (
395 - ACPI_SIZE Size,
396 - UINT32 Component,
397 - const char *Module,
398 - UINT32 Line)
399 -{
400 - void *Allocation;
401 -
402 -
403 - ACPI_FUNCTION_ENTRY ();
404 -
405 -
406 - Allocation = AcpiUtAllocate (Size, Component, Module, Line);
407 - if (Allocation)
408 - {
409 - /* Clear the memory block */
410 -
411 - ACPI_MEMSET (Allocation, 0, Size);
412 - }
413 -
414 - return (Allocation);
415 -}
416 -
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX