Blame view
drivers/acpi/acpica/utalloc.c
10.1 KB
1da177e4c Linux-2.6.12-rc2 |
1 2 |
/****************************************************************************** * |
73459f73e ACPICA 20050617-0... |
3 |
* Module Name: utalloc - local memory allocation routines |
1da177e4c Linux-2.6.12-rc2 |
4 5 6 7 |
* *****************************************************************************/ /* |
75a44ce00 ACPICA: update In... |
8 |
* Copyright (C) 2000 - 2008, Intel Corp. |
1da177e4c Linux-2.6.12-rc2 |
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
* All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions, and the following disclaimer, * without modification. * 2. Redistributions in binary form must reproduce at minimum a disclaimer * substantially similar to the "NO WARRANTY" disclaimer below * ("Disclaimer") and any redistribution must be conditioned upon * including a substantially similar Disclaimer requirement for further * binary redistribution. * 3. Neither the names of the above-listed copyright holders nor the names * of any contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * Alternatively, this software may be distributed under the terms of the * GNU General Public License ("GPL") version 2 as published by the Free * Software Foundation. * * NO WARRANTY * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGES. */ |
1da177e4c Linux-2.6.12-rc2 |
43 |
#include <acpi/acpi.h> |
e2f7a7772 ACPICA: hide priv... |
44 45 |
#include "accommon.h" #include "acdebug.h" |
1da177e4c Linux-2.6.12-rc2 |
46 47 |
#define _COMPONENT ACPI_UTILITIES |
4be44fcd3 [ACPI] Lindent al... |
48 |
ACPI_MODULE_NAME("utalloc") |
1da177e4c Linux-2.6.12-rc2 |
49 |
|
44f6c0124 ACPICA 20050408 f... |
50 |
/******************************************************************************* |
1da177e4c Linux-2.6.12-rc2 |
51 |
* |
73459f73e ACPICA 20050617-0... |
52 |
* FUNCTION: acpi_ut_create_caches |
1da177e4c Linux-2.6.12-rc2 |
53 |
* |
73459f73e ACPICA 20050617-0... |
54 |
* PARAMETERS: None |
1da177e4c Linux-2.6.12-rc2 |
55 |
* |
73459f73e ACPICA 20050617-0... |
56 |
* RETURN: Status |
1da177e4c Linux-2.6.12-rc2 |
57 |
* |
73459f73e ACPICA 20050617-0... |
58 |
* DESCRIPTION: Create all local caches |
1da177e4c Linux-2.6.12-rc2 |
59 60 |
* ******************************************************************************/ |
4be44fcd3 [ACPI] Lindent al... |
61 |
acpi_status acpi_ut_create_caches(void) |
1da177e4c Linux-2.6.12-rc2 |
62 |
{ |
4be44fcd3 [ACPI] Lindent al... |
63 |
acpi_status status; |
1da177e4c Linux-2.6.12-rc2 |
64 |
|
73459f73e ACPICA 20050617-0... |
65 |
/* Object Caches, for frequently used objects */ |
1da177e4c Linux-2.6.12-rc2 |
66 |
|
4be44fcd3 [ACPI] Lindent al... |
67 |
status = |
61686124f [ACPI] ACPICA 200... |
68 69 70 71 72 73 74 75 76 77 |
acpi_os_create_cache("Acpi-Namespace", sizeof(struct acpi_namespace_node), ACPI_MAX_NAMESPACE_CACHE_DEPTH, &acpi_gbl_namespace_cache); if (ACPI_FAILURE(status)) { return (status); } status = acpi_os_create_cache("Acpi-State", sizeof(union acpi_generic_state), |
4be44fcd3 [ACPI] Lindent al... |
78 79 80 |
ACPI_MAX_STATE_CACHE_DEPTH, &acpi_gbl_state_cache); if (ACPI_FAILURE(status)) { |
73459f73e ACPICA 20050617-0... |
81 |
return (status); |
1da177e4c Linux-2.6.12-rc2 |
82 |
} |
4be44fcd3 [ACPI] Lindent al... |
83 |
status = |
61686124f [ACPI] ACPICA 200... |
84 |
acpi_os_create_cache("Acpi-Parse", |
4be44fcd3 [ACPI] Lindent al... |
85 86 87 88 |
sizeof(struct acpi_parse_obj_common), ACPI_MAX_PARSE_CACHE_DEPTH, &acpi_gbl_ps_node_cache); if (ACPI_FAILURE(status)) { |
73459f73e ACPICA 20050617-0... |
89 |
return (status); |
1da177e4c Linux-2.6.12-rc2 |
90 |
} |
4be44fcd3 [ACPI] Lindent al... |
91 |
status = |
b229cf92e ACPI: ACPICA 2006... |
92 |
acpi_os_create_cache("Acpi-ParseExt", |
4be44fcd3 [ACPI] Lindent al... |
93 94 95 96 |
sizeof(struct acpi_parse_obj_named), ACPI_MAX_EXTPARSE_CACHE_DEPTH, &acpi_gbl_ps_node_ext_cache); if (ACPI_FAILURE(status)) { |
73459f73e ACPICA 20050617-0... |
97 98 |
return (status); } |
1da177e4c Linux-2.6.12-rc2 |
99 |
|
4be44fcd3 [ACPI] Lindent al... |
100 |
status = |
61686124f [ACPI] ACPICA 200... |
101 |
acpi_os_create_cache("Acpi-Operand", |
4be44fcd3 [ACPI] Lindent al... |
102 103 104 105 |
sizeof(union acpi_operand_object), ACPI_MAX_OBJECT_CACHE_DEPTH, &acpi_gbl_operand_cache); if (ACPI_FAILURE(status)) { |
73459f73e ACPICA 20050617-0... |
106 107 |
return (status); } |
4119532c9 ACPI: ACPICA 2006... |
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
#ifdef ACPI_DBG_TRACK_ALLOCATIONS /* Memory allocation lists */ status = acpi_ut_create_list("Acpi-Global", 0, &acpi_gbl_global_list); if (ACPI_FAILURE(status)) { return (status); } status = acpi_ut_create_list("Acpi-Namespace", sizeof(struct acpi_namespace_node), &acpi_gbl_ns_node_list); if (ACPI_FAILURE(status)) { return (status); } #endif |
73459f73e ACPICA 20050617-0... |
125 |
return (AE_OK); |
1da177e4c Linux-2.6.12-rc2 |
126 |
} |
44f6c0124 ACPICA 20050408 f... |
127 |
/******************************************************************************* |
1da177e4c Linux-2.6.12-rc2 |
128 |
* |
73459f73e ACPICA 20050617-0... |
129 |
* FUNCTION: acpi_ut_delete_caches |
1da177e4c Linux-2.6.12-rc2 |
130 |
* |
73459f73e ACPICA 20050617-0... |
131 |
* PARAMETERS: None |
1da177e4c Linux-2.6.12-rc2 |
132 |
* |
73459f73e ACPICA 20050617-0... |
133 |
* RETURN: Status |
1da177e4c Linux-2.6.12-rc2 |
134 |
* |
73459f73e ACPICA 20050617-0... |
135 |
* DESCRIPTION: Purge and delete all local caches |
1da177e4c Linux-2.6.12-rc2 |
136 137 |
* ******************************************************************************/ |
4be44fcd3 [ACPI] Lindent al... |
138 |
acpi_status acpi_ut_delete_caches(void) |
1da177e4c Linux-2.6.12-rc2 |
139 |
{ |
d41eb99ba ACPICA: Added opt... |
140 141 142 143 144 |
#ifdef ACPI_DBG_TRACK_ALLOCATIONS char buffer[7]; if (acpi_gbl_display_final_mem_stats) { ACPI_STRCPY(buffer, "MEMORY"); |
1d18c0582 ACPICA: Cosmetic ... |
145 |
(void)acpi_db_display_statistics(buffer); |
d41eb99ba ACPICA: Added opt... |
146 147 |
} #endif |
1da177e4c Linux-2.6.12-rc2 |
148 |
|
61686124f [ACPI] ACPICA 200... |
149 150 |
(void)acpi_os_delete_cache(acpi_gbl_namespace_cache); acpi_gbl_namespace_cache = NULL; |
4be44fcd3 [ACPI] Lindent al... |
151 |
(void)acpi_os_delete_cache(acpi_gbl_state_cache); |
73459f73e ACPICA 20050617-0... |
152 |
acpi_gbl_state_cache = NULL; |
1da177e4c Linux-2.6.12-rc2 |
153 |
|
4be44fcd3 [ACPI] Lindent al... |
154 |
(void)acpi_os_delete_cache(acpi_gbl_operand_cache); |
73459f73e ACPICA 20050617-0... |
155 |
acpi_gbl_operand_cache = NULL; |
1da177e4c Linux-2.6.12-rc2 |
156 |
|
4be44fcd3 [ACPI] Lindent al... |
157 |
(void)acpi_os_delete_cache(acpi_gbl_ps_node_cache); |
73459f73e ACPICA 20050617-0... |
158 |
acpi_gbl_ps_node_cache = NULL; |
1da177e4c Linux-2.6.12-rc2 |
159 |
|
4be44fcd3 [ACPI] Lindent al... |
160 |
(void)acpi_os_delete_cache(acpi_gbl_ps_node_ext_cache); |
73459f73e ACPICA 20050617-0... |
161 |
acpi_gbl_ps_node_ext_cache = NULL; |
1da177e4c Linux-2.6.12-rc2 |
162 |
|
4119532c9 ACPI: ACPICA 2006... |
163 164 165 166 167 168 169 |
#ifdef ACPI_DBG_TRACK_ALLOCATIONS /* Debug only - display leftover memory allocation, if any */ acpi_ut_dump_allocations(ACPI_UINT32_MAX, NULL); /* Free memory lists */ |
02438d877 ACPI: delete acpi... |
170 |
ACPI_FREE(acpi_gbl_global_list); |
4119532c9 ACPI: ACPICA 2006... |
171 |
acpi_gbl_global_list = NULL; |
02438d877 ACPI: delete acpi... |
172 |
ACPI_FREE(acpi_gbl_ns_node_list); |
4119532c9 ACPI: ACPICA 2006... |
173 174 |
acpi_gbl_ns_node_list = NULL; #endif |
73459f73e ACPICA 20050617-0... |
175 |
return (AE_OK); |
1da177e4c Linux-2.6.12-rc2 |
176 |
} |
1da177e4c Linux-2.6.12-rc2 |
177 178 179 180 181 182 183 184 185 186 187 188 |
/******************************************************************************* * * FUNCTION: acpi_ut_validate_buffer * * PARAMETERS: Buffer - Buffer descriptor to be validated * * RETURN: Status * * DESCRIPTION: Perform parameter validation checks on an struct acpi_buffer * ******************************************************************************/ |
4be44fcd3 [ACPI] Lindent al... |
189 |
acpi_status acpi_ut_validate_buffer(struct acpi_buffer * buffer) |
1da177e4c Linux-2.6.12-rc2 |
190 191 192 193 194 195 196 197 198 |
{ /* Obviously, the structure pointer must be valid */ if (!buffer) { return (AE_BAD_PARAMETER); } /* Special semantics for the length */ |
4be44fcd3 [ACPI] Lindent al... |
199 200 201 |
if ((buffer->length == ACPI_NO_BUFFER) || (buffer->length == ACPI_ALLOCATE_BUFFER) || (buffer->length == ACPI_ALLOCATE_LOCAL_BUFFER)) { |
1da177e4c Linux-2.6.12-rc2 |
202 203 204 205 206 207 208 209 210 211 212 |
return (AE_OK); } /* Length is valid, the buffer pointer must be also */ if (!buffer->pointer) { return (AE_BAD_PARAMETER); } return (AE_OK); } |
1da177e4c Linux-2.6.12-rc2 |
213 214 215 216 217 218 219 220 221 222 |
/******************************************************************************* * * FUNCTION: acpi_ut_initialize_buffer * * PARAMETERS: Buffer - Buffer to be validated * required_length - Length needed * * RETURN: Status * * DESCRIPTION: Validate that the buffer is of the required length or |
68e125c40 ACPICA: Optimize ... |
223 |
* allocate a new buffer. Returned buffer is always zeroed. |
1da177e4c Linux-2.6.12-rc2 |
224 225 226 227 |
* ******************************************************************************/ acpi_status |
4be44fcd3 [ACPI] Lindent al... |
228 229 |
acpi_ut_initialize_buffer(struct acpi_buffer * buffer, acpi_size required_length) |
1da177e4c Linux-2.6.12-rc2 |
230 |
{ |
68e125c40 ACPICA: Optimize ... |
231 |
acpi_size input_buffer_length; |
1da177e4c Linux-2.6.12-rc2 |
232 |
|
3c7db22a1 ACPICA: Additiona... |
233 234 235 236 |
/* Parameter validation */ if (!buffer || !required_length) { return (AE_BAD_PARAMETER); |
f88133d76 acpi: fix crash i... |
237 |
} |
3c7db22a1 ACPICA: Additiona... |
238 |
|
68e125c40 ACPICA: Optimize ... |
239 240 241 242 243 244 245 246 247 248 249 250 |
/* * Buffer->Length is used as both an input and output parameter. Get the * input actual length and set the output required buffer length. */ input_buffer_length = buffer->length; buffer->length = required_length; /* * The input buffer length contains the actual buffer length, or the type * of buffer to be allocated by this routine. */ switch (input_buffer_length) { |
1da177e4c Linux-2.6.12-rc2 |
251 |
case ACPI_NO_BUFFER: |
68e125c40 ACPICA: Optimize ... |
252 |
/* Return the exception (and the required buffer length) */ |
1da177e4c Linux-2.6.12-rc2 |
253 |
|
68e125c40 ACPICA: Optimize ... |
254 |
return (AE_BUFFER_OVERFLOW); |
1da177e4c Linux-2.6.12-rc2 |
255 |
|
1da177e4c Linux-2.6.12-rc2 |
256 257 258 |
case ACPI_ALLOCATE_BUFFER: /* Allocate a new buffer */ |
4be44fcd3 [ACPI] Lindent al... |
259 |
buffer->pointer = acpi_os_allocate(required_length); |
1da177e4c Linux-2.6.12-rc2 |
260 |
break; |
1da177e4c Linux-2.6.12-rc2 |
261 262 263 |
case ACPI_ALLOCATE_LOCAL_BUFFER: /* Allocate a new buffer with local interface to allow tracking */ |
68e125c40 ACPICA: Optimize ... |
264 |
buffer->pointer = ACPI_ALLOCATE(required_length); |
1da177e4c Linux-2.6.12-rc2 |
265 |
break; |
1da177e4c Linux-2.6.12-rc2 |
266 267 268 |
default: /* Existing buffer: Validate the size of the buffer */ |
68e125c40 ACPICA: Optimize ... |
269 270 |
if (input_buffer_length < required_length) { return (AE_BUFFER_OVERFLOW); |
1da177e4c Linux-2.6.12-rc2 |
271 |
} |
68e125c40 ACPICA: Optimize ... |
272 273 |
break; } |
1da177e4c Linux-2.6.12-rc2 |
274 |
|
68e125c40 ACPICA: Optimize ... |
275 |
/* Validate allocation from above or input buffer pointer */ |
1da177e4c Linux-2.6.12-rc2 |
276 |
|
68e125c40 ACPICA: Optimize ... |
277 278 |
if (!buffer->pointer) { return (AE_NO_MEMORY); |
1da177e4c Linux-2.6.12-rc2 |
279 |
} |
68e125c40 ACPICA: Optimize ... |
280 281 282 283 |
/* Have a valid buffer, clear it */ ACPI_MEMSET(buffer->pointer, 0, required_length); return (AE_OK); |
1da177e4c Linux-2.6.12-rc2 |
284 |
} |
e21c1ca3f ACPI: acpi_os_all... |
285 |
#ifdef NOT_USED_BY_LINUX |
1da177e4c Linux-2.6.12-rc2 |
286 287 288 289 290 291 292 293 294 295 296 |
/******************************************************************************* * * FUNCTION: acpi_ut_allocate * * PARAMETERS: Size - Size of the allocation * Component - Component type of caller * Module - Source file name of caller * Line - Line number of caller * * RETURN: Address of the allocated memory on success, NULL on failure. * |
61686124f [ACPI] ACPICA 200... |
297 |
* DESCRIPTION: Subsystem equivalent of malloc. |
1da177e4c Linux-2.6.12-rc2 |
298 299 |
* ******************************************************************************/ |
4b8ed6316 ACPICA: Add const... |
300 301 |
void *acpi_ut_allocate(acpi_size size, u32 component, const char *module, u32 line) |
1da177e4c Linux-2.6.12-rc2 |
302 |
{ |
4be44fcd3 [ACPI] Lindent al... |
303 |
void *allocation; |
1da177e4c Linux-2.6.12-rc2 |
304 |
|
b229cf92e ACPI: ACPICA 2006... |
305 |
ACPI_FUNCTION_TRACE_U32(ut_allocate, size); |
1da177e4c Linux-2.6.12-rc2 |
306 307 308 309 |
/* Check for an inadvertent size of zero bytes */ if (!size) { |
61686124f [ACPI] ACPICA 200... |
310 311 |
ACPI_WARNING((module, line, "Attempt to allocate zero bytes, allocating 1 byte")); |
1da177e4c Linux-2.6.12-rc2 |
312 313 |
size = 1; } |
4be44fcd3 [ACPI] Lindent al... |
314 |
allocation = acpi_os_allocate(size); |
1da177e4c Linux-2.6.12-rc2 |
315 |
if (!allocation) { |
52fc0b026 [ACPI] ACPICA 200... |
316 |
|
1da177e4c Linux-2.6.12-rc2 |
317 |
/* Report allocation error */ |
61686124f [ACPI] ACPICA 200... |
318 319 |
ACPI_WARNING((module, line, "Could not allocate size %X", (u32) size)); |
1da177e4c Linux-2.6.12-rc2 |
320 |
|
4be44fcd3 [ACPI] Lindent al... |
321 |
return_PTR(NULL); |
1da177e4c Linux-2.6.12-rc2 |
322 |
} |
4be44fcd3 [ACPI] Lindent al... |
323 |
return_PTR(allocation); |
1da177e4c Linux-2.6.12-rc2 |
324 |
} |
1da177e4c Linux-2.6.12-rc2 |
325 326 |
/******************************************************************************* * |
61686124f [ACPI] ACPICA 200... |
327 |
* FUNCTION: acpi_ut_allocate_zeroed |
1da177e4c Linux-2.6.12-rc2 |
328 329 330 331 332 333 334 335 |
* * PARAMETERS: Size - Size of the allocation * Component - Component type of caller * Module - Source file name of caller * Line - Line number of caller * * RETURN: Address of the allocated memory on success, NULL on failure. * |
61686124f [ACPI] ACPICA 200... |
336 |
* DESCRIPTION: Subsystem equivalent of calloc. Allocate and zero memory. |
1da177e4c Linux-2.6.12-rc2 |
337 338 |
* ******************************************************************************/ |
61686124f [ACPI] ACPICA 200... |
339 |
void *acpi_ut_allocate_zeroed(acpi_size size, |
4b8ed6316 ACPICA: Add const... |
340 |
u32 component, const char *module, u32 line) |
1da177e4c Linux-2.6.12-rc2 |
341 |
{ |
4be44fcd3 [ACPI] Lindent al... |
342 |
void *allocation; |
1da177e4c Linux-2.6.12-rc2 |
343 |
|
4be44fcd3 [ACPI] Lindent al... |
344 |
ACPI_FUNCTION_ENTRY(); |
1da177e4c Linux-2.6.12-rc2 |
345 |
|
61686124f [ACPI] ACPICA 200... |
346 347 |
allocation = acpi_ut_allocate(size, component, module, line); if (allocation) { |
1da177e4c Linux-2.6.12-rc2 |
348 |
|
61686124f [ACPI] ACPICA 200... |
349 |
/* Clear the memory block */ |
1da177e4c Linux-2.6.12-rc2 |
350 |
|
61686124f [ACPI] ACPICA 200... |
351 |
ACPI_MEMSET(allocation, 0, size); |
1da177e4c Linux-2.6.12-rc2 |
352 |
} |
61686124f [ACPI] ACPICA 200... |
353 |
return (allocation); |
1da177e4c Linux-2.6.12-rc2 |
354 |
} |
e21c1ca3f ACPI: acpi_os_all... |
355 |
#endif |