Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 3 | * Module Name: utalloc - local memory allocation routines |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * |
| 5 | *****************************************************************************/ |
| 6 | |
| 7 | /* |
Bob Moore | 4a90c7e | 2006-01-13 16:22:00 -0500 | [diff] [blame] | 8 | * Copyright (C) 2000 - 2006, R. Byron Moore |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | #include <acpi/acpi.h> |
| 45 | |
| 46 | #define _COMPONENT ACPI_UTILITIES |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 47 | ACPI_MODULE_NAME("utalloc") |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 49 | /* Local prototypes */ |
Bob Moore | defba1d | 2005-12-16 17:05:00 -0500 | [diff] [blame] | 50 | #ifdef ACPI_DBG_TRACK_ALLOCATIONS |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 51 | static struct acpi_debug_mem_block *acpi_ut_find_allocation(void *allocation); |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 52 | |
| 53 | static acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 54 | acpi_ut_track_allocation(struct acpi_debug_mem_block *address, |
| 55 | acpi_size size, |
| 56 | u8 alloc_type, u32 component, char *module, u32 line); |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 57 | |
| 58 | static acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 59 | acpi_ut_remove_allocation(struct acpi_debug_mem_block *address, |
| 60 | u32 component, char *module, u32 line); |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 61 | |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 62 | static acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 63 | acpi_ut_create_list(char *list_name, |
| 64 | u16 object_size, struct acpi_memory_list **return_cache); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 67 | /******************************************************************************* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | * |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 69 | * FUNCTION: acpi_ut_create_caches |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | * |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 71 | * PARAMETERS: None |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | * |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 73 | * RETURN: Status |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | * |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 75 | * DESCRIPTION: Create all local caches |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | * |
| 77 | ******************************************************************************/ |
| 78 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 79 | acpi_status acpi_ut_create_caches(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 81 | acpi_status status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | #ifdef ACPI_DBG_TRACK_ALLOCATIONS |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 85 | /* Memory allocation lists */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 87 | status = acpi_ut_create_list("Acpi-Global", 0, &acpi_gbl_global_list); |
| 88 | if (ACPI_FAILURE(status)) { |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 89 | return (status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | } |
| 91 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 92 | status = |
| 93 | acpi_ut_create_list("Acpi-Namespace", |
| 94 | sizeof(struct acpi_namespace_node), |
| 95 | &acpi_gbl_ns_node_list); |
| 96 | if (ACPI_FAILURE(status)) { |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 97 | return (status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | #endif |
| 100 | |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 101 | /* Object Caches, for frequently used objects */ |
| 102 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 103 | status = |
| 104 | acpi_os_create_cache("acpi_state", sizeof(union acpi_generic_state), |
| 105 | ACPI_MAX_STATE_CACHE_DEPTH, |
| 106 | &acpi_gbl_state_cache); |
| 107 | if (ACPI_FAILURE(status)) { |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 108 | return (status); |
| 109 | } |
| 110 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 111 | status = |
| 112 | acpi_os_create_cache("acpi_parse", |
| 113 | sizeof(struct acpi_parse_obj_common), |
| 114 | ACPI_MAX_PARSE_CACHE_DEPTH, |
| 115 | &acpi_gbl_ps_node_cache); |
| 116 | if (ACPI_FAILURE(status)) { |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 117 | return (status); |
| 118 | } |
| 119 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 120 | status = |
| 121 | acpi_os_create_cache("acpi_parse_ext", |
| 122 | sizeof(struct acpi_parse_obj_named), |
| 123 | ACPI_MAX_EXTPARSE_CACHE_DEPTH, |
| 124 | &acpi_gbl_ps_node_ext_cache); |
| 125 | if (ACPI_FAILURE(status)) { |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 126 | return (status); |
| 127 | } |
| 128 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 129 | status = |
| 130 | acpi_os_create_cache("acpi_operand", |
| 131 | sizeof(union acpi_operand_object), |
| 132 | ACPI_MAX_OBJECT_CACHE_DEPTH, |
| 133 | &acpi_gbl_operand_cache); |
| 134 | if (ACPI_FAILURE(status)) { |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 135 | return (status); |
| 136 | } |
| 137 | |
| 138 | return (AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | } |
| 140 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 141 | /******************************************************************************* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | * |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 143 | * FUNCTION: acpi_ut_delete_caches |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | * |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 145 | * PARAMETERS: None |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | * |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 147 | * RETURN: Status |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | * |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 149 | * DESCRIPTION: Purge and delete all local caches |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | * |
| 151 | ******************************************************************************/ |
| 152 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 153 | acpi_status acpi_ut_delete_caches(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 156 | (void)acpi_os_delete_cache(acpi_gbl_state_cache); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 157 | acpi_gbl_state_cache = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 159 | (void)acpi_os_delete_cache(acpi_gbl_operand_cache); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 160 | acpi_gbl_operand_cache = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 162 | (void)acpi_os_delete_cache(acpi_gbl_ps_node_cache); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 163 | acpi_gbl_ps_node_cache = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 165 | (void)acpi_os_delete_cache(acpi_gbl_ps_node_ext_cache); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 166 | acpi_gbl_ps_node_ext_cache = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 168 | return (AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | |
| 171 | /******************************************************************************* |
| 172 | * |
| 173 | * FUNCTION: acpi_ut_validate_buffer |
| 174 | * |
| 175 | * PARAMETERS: Buffer - Buffer descriptor to be validated |
| 176 | * |
| 177 | * RETURN: Status |
| 178 | * |
| 179 | * DESCRIPTION: Perform parameter validation checks on an struct acpi_buffer |
| 180 | * |
| 181 | ******************************************************************************/ |
| 182 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 183 | acpi_status acpi_ut_validate_buffer(struct acpi_buffer * buffer) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | { |
| 185 | |
| 186 | /* Obviously, the structure pointer must be valid */ |
| 187 | |
| 188 | if (!buffer) { |
| 189 | return (AE_BAD_PARAMETER); |
| 190 | } |
| 191 | |
| 192 | /* Special semantics for the length */ |
| 193 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 194 | if ((buffer->length == ACPI_NO_BUFFER) || |
| 195 | (buffer->length == ACPI_ALLOCATE_BUFFER) || |
| 196 | (buffer->length == ACPI_ALLOCATE_LOCAL_BUFFER)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | return (AE_OK); |
| 198 | } |
| 199 | |
| 200 | /* Length is valid, the buffer pointer must be also */ |
| 201 | |
| 202 | if (!buffer->pointer) { |
| 203 | return (AE_BAD_PARAMETER); |
| 204 | } |
| 205 | |
| 206 | return (AE_OK); |
| 207 | } |
| 208 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | /******************************************************************************* |
| 210 | * |
| 211 | * FUNCTION: acpi_ut_initialize_buffer |
| 212 | * |
| 213 | * PARAMETERS: Buffer - Buffer to be validated |
| 214 | * required_length - Length needed |
| 215 | * |
| 216 | * RETURN: Status |
| 217 | * |
| 218 | * DESCRIPTION: Validate that the buffer is of the required length or |
| 219 | * allocate a new buffer. Returned buffer is always zeroed. |
| 220 | * |
| 221 | ******************************************************************************/ |
| 222 | |
| 223 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 224 | acpi_ut_initialize_buffer(struct acpi_buffer * buffer, |
| 225 | acpi_size required_length) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 227 | acpi_status status = AE_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | |
| 229 | switch (buffer->length) { |
| 230 | case ACPI_NO_BUFFER: |
| 231 | |
| 232 | /* Set the exception and returned the required length */ |
| 233 | |
| 234 | status = AE_BUFFER_OVERFLOW; |
| 235 | break; |
| 236 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | case ACPI_ALLOCATE_BUFFER: |
| 238 | |
| 239 | /* Allocate a new buffer */ |
| 240 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 241 | buffer->pointer = acpi_os_allocate(required_length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | if (!buffer->pointer) { |
| 243 | return (AE_NO_MEMORY); |
| 244 | } |
| 245 | |
| 246 | /* Clear the buffer */ |
| 247 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 248 | ACPI_MEMSET(buffer->pointer, 0, required_length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | break; |
| 250 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | case ACPI_ALLOCATE_LOCAL_BUFFER: |
| 252 | |
| 253 | /* Allocate a new buffer with local interface to allow tracking */ |
| 254 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 255 | buffer->pointer = ACPI_MEM_CALLOCATE(required_length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | if (!buffer->pointer) { |
| 257 | return (AE_NO_MEMORY); |
| 258 | } |
| 259 | break; |
| 260 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | default: |
| 262 | |
| 263 | /* Existing buffer: Validate the size of the buffer */ |
| 264 | |
| 265 | if (buffer->length < required_length) { |
| 266 | status = AE_BUFFER_OVERFLOW; |
| 267 | break; |
| 268 | } |
| 269 | |
| 270 | /* Clear the buffer */ |
| 271 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 272 | ACPI_MEMSET(buffer->pointer, 0, required_length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | break; |
| 274 | } |
| 275 | |
| 276 | buffer->length = required_length; |
| 277 | return (status); |
| 278 | } |
| 279 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | /******************************************************************************* |
| 281 | * |
| 282 | * FUNCTION: acpi_ut_allocate |
| 283 | * |
| 284 | * PARAMETERS: Size - Size of the allocation |
| 285 | * Component - Component type of caller |
| 286 | * Module - Source file name of caller |
| 287 | * Line - Line number of caller |
| 288 | * |
| 289 | * RETURN: Address of the allocated memory on success, NULL on failure. |
| 290 | * |
| 291 | * DESCRIPTION: The subsystem's equivalent of malloc. |
| 292 | * |
| 293 | ******************************************************************************/ |
| 294 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 295 | void *acpi_ut_allocate(acpi_size size, u32 component, char *module, u32 line) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 297 | void *allocation; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 299 | ACPI_FUNCTION_TRACE_U32("ut_allocate", size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | |
| 301 | /* Check for an inadvertent size of zero bytes */ |
| 302 | |
| 303 | if (!size) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 304 | ACPI_ERROR((module, line, |
| 305 | "ut_allocate: Attempt to allocate zero bytes, allocating 1 byte")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | size = 1; |
| 307 | } |
| 308 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 309 | allocation = acpi_os_allocate(size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | if (!allocation) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame^] | 311 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | /* Report allocation error */ |
| 313 | |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 314 | ACPI_ERROR((module, line, |
| 315 | "ut_allocate: Could not allocate size %X", |
| 316 | (u32) size)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 318 | return_PTR(NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | } |
| 320 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 321 | return_PTR(allocation); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | } |
| 323 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | /******************************************************************************* |
| 325 | * |
| 326 | * FUNCTION: acpi_ut_callocate |
| 327 | * |
| 328 | * PARAMETERS: Size - Size of the allocation |
| 329 | * Component - Component type of caller |
| 330 | * Module - Source file name of caller |
| 331 | * Line - Line number of caller |
| 332 | * |
| 333 | * RETURN: Address of the allocated memory on success, NULL on failure. |
| 334 | * |
| 335 | * DESCRIPTION: Subsystem equivalent of calloc. |
| 336 | * |
| 337 | ******************************************************************************/ |
| 338 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 339 | void *acpi_ut_callocate(acpi_size size, u32 component, char *module, u32 line) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 341 | void *allocation; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 343 | ACPI_FUNCTION_TRACE_U32("ut_callocate", size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | |
| 345 | /* Check for an inadvertent size of zero bytes */ |
| 346 | |
| 347 | if (!size) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 348 | ACPI_ERROR((module, line, |
| 349 | "Attempt to allocate zero bytes, allocating 1 byte")); |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 350 | size = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | } |
| 352 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 353 | allocation = acpi_os_allocate(size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | if (!allocation) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame^] | 355 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | /* Report allocation error */ |
| 357 | |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 358 | ACPI_ERROR((module, line, |
| 359 | "Could not allocate size %X", (u32) size)); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 360 | return_PTR(NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | } |
| 362 | |
| 363 | /* Clear the memory block */ |
| 364 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 365 | ACPI_MEMSET(allocation, 0, size); |
| 366 | return_PTR(allocation); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | } |
| 368 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | #ifdef ACPI_DBG_TRACK_ALLOCATIONS |
| 370 | /* |
| 371 | * These procedures are used for tracking memory leaks in the subsystem, and |
| 372 | * they get compiled out when the ACPI_DBG_TRACK_ALLOCATIONS is not set. |
| 373 | * |
| 374 | * Each memory allocation is tracked via a doubly linked list. Each |
| 375 | * element contains the caller's component, module name, function name, and |
| 376 | * line number. acpi_ut_allocate and acpi_ut_callocate call |
| 377 | * acpi_ut_track_allocation to add an element to the list; deletion |
| 378 | * occurs in the body of acpi_ut_free. |
| 379 | */ |
| 380 | |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 381 | /******************************************************************************* |
| 382 | * |
| 383 | * FUNCTION: acpi_ut_create_list |
| 384 | * |
| 385 | * PARAMETERS: cache_name - Ascii name for the cache |
| 386 | * object_size - Size of each cached object |
| 387 | * return_cache - Where the new cache object is returned |
| 388 | * |
| 389 | * RETURN: Status |
| 390 | * |
| 391 | * DESCRIPTION: Create a local memory list for tracking purposed |
| 392 | * |
| 393 | ******************************************************************************/ |
| 394 | |
| 395 | static acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 396 | acpi_ut_create_list(char *list_name, |
| 397 | u16 object_size, struct acpi_memory_list **return_cache) |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 398 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 399 | struct acpi_memory_list *cache; |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 400 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 401 | cache = acpi_os_allocate(sizeof(struct acpi_memory_list)); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 402 | if (!cache) { |
| 403 | return (AE_NO_MEMORY); |
| 404 | } |
| 405 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 406 | ACPI_MEMSET(cache, 0, sizeof(struct acpi_memory_list)); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 407 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 408 | cache->list_name = list_name; |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 409 | cache->object_size = object_size; |
| 410 | |
| 411 | *return_cache = cache; |
| 412 | return (AE_OK); |
| 413 | } |
| 414 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | /******************************************************************************* |
| 416 | * |
| 417 | * FUNCTION: acpi_ut_allocate_and_track |
| 418 | * |
| 419 | * PARAMETERS: Size - Size of the allocation |
| 420 | * Component - Component type of caller |
| 421 | * Module - Source file name of caller |
| 422 | * Line - Line number of caller |
| 423 | * |
| 424 | * RETURN: Address of the allocated memory on success, NULL on failure. |
| 425 | * |
| 426 | * DESCRIPTION: The subsystem's equivalent of malloc. |
| 427 | * |
| 428 | ******************************************************************************/ |
| 429 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 430 | void *acpi_ut_allocate_and_track(acpi_size size, |
| 431 | u32 component, char *module, u32 line) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 433 | struct acpi_debug_mem_block *allocation; |
| 434 | acpi_status status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 436 | allocation = |
| 437 | acpi_ut_allocate(size + sizeof(struct acpi_debug_mem_header), |
| 438 | component, module, line); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | if (!allocation) { |
| 440 | return (NULL); |
| 441 | } |
| 442 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 443 | status = acpi_ut_track_allocation(allocation, size, |
| 444 | ACPI_MEM_MALLOC, component, module, |
| 445 | line); |
| 446 | if (ACPI_FAILURE(status)) { |
| 447 | acpi_os_free(allocation); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | return (NULL); |
| 449 | } |
| 450 | |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 451 | acpi_gbl_global_list->total_allocated++; |
| 452 | acpi_gbl_global_list->current_total_size += (u32) size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 453 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 454 | return ((void *)&allocation->user_space); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | } |
| 456 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | /******************************************************************************* |
| 458 | * |
| 459 | * FUNCTION: acpi_ut_callocate_and_track |
| 460 | * |
| 461 | * PARAMETERS: Size - Size of the allocation |
| 462 | * Component - Component type of caller |
| 463 | * Module - Source file name of caller |
| 464 | * Line - Line number of caller |
| 465 | * |
| 466 | * RETURN: Address of the allocated memory on success, NULL on failure. |
| 467 | * |
| 468 | * DESCRIPTION: Subsystem equivalent of calloc. |
| 469 | * |
| 470 | ******************************************************************************/ |
| 471 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 472 | void *acpi_ut_callocate_and_track(acpi_size size, |
| 473 | u32 component, char *module, u32 line) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 475 | struct acpi_debug_mem_block *allocation; |
| 476 | acpi_status status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 477 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 478 | allocation = |
| 479 | acpi_ut_callocate(size + sizeof(struct acpi_debug_mem_header), |
| 480 | component, module, line); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | if (!allocation) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame^] | 482 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | /* Report allocation error */ |
| 484 | |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 485 | ACPI_ERROR((module, line, |
| 486 | "Could not allocate size %X", (u32) size)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | return (NULL); |
| 488 | } |
| 489 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 490 | status = acpi_ut_track_allocation(allocation, size, |
| 491 | ACPI_MEM_CALLOC, component, module, |
| 492 | line); |
| 493 | if (ACPI_FAILURE(status)) { |
| 494 | acpi_os_free(allocation); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 495 | return (NULL); |
| 496 | } |
| 497 | |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 498 | acpi_gbl_global_list->total_allocated++; |
| 499 | acpi_gbl_global_list->current_total_size += (u32) size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 500 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 501 | return ((void *)&allocation->user_space); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 502 | } |
| 503 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 504 | /******************************************************************************* |
| 505 | * |
| 506 | * FUNCTION: acpi_ut_free_and_track |
| 507 | * |
| 508 | * PARAMETERS: Allocation - Address of the memory to deallocate |
| 509 | * Component - Component type of caller |
| 510 | * Module - Source file name of caller |
| 511 | * Line - Line number of caller |
| 512 | * |
| 513 | * RETURN: None |
| 514 | * |
| 515 | * DESCRIPTION: Frees the memory at Allocation |
| 516 | * |
| 517 | ******************************************************************************/ |
| 518 | |
| 519 | void |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 520 | acpi_ut_free_and_track(void *allocation, u32 component, char *module, u32 line) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 522 | struct acpi_debug_mem_block *debug_block; |
| 523 | acpi_status status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 525 | ACPI_FUNCTION_TRACE_PTR("ut_free", allocation); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 526 | |
| 527 | if (NULL == allocation) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 528 | ACPI_ERROR((module, line, "Attempt to delete a NULL address")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 529 | |
| 530 | return_VOID; |
| 531 | } |
| 532 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 533 | debug_block = ACPI_CAST_PTR(struct acpi_debug_mem_block, |
| 534 | (((char *)allocation) - |
| 535 | sizeof(struct acpi_debug_mem_header))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 536 | |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 537 | acpi_gbl_global_list->total_freed++; |
| 538 | acpi_gbl_global_list->current_total_size -= debug_block->size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 540 | status = acpi_ut_remove_allocation(debug_block, |
| 541 | component, module, line); |
| 542 | if (ACPI_FAILURE(status)) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 543 | ACPI_EXCEPTION((AE_INFO, status, "Could not free memory")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 544 | } |
| 545 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 546 | acpi_os_free(debug_block); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 547 | ACPI_DEBUG_PRINT((ACPI_DB_ALLOCATIONS, "%p freed\n", allocation)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 548 | return_VOID; |
| 549 | } |
| 550 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | /******************************************************************************* |
| 552 | * |
| 553 | * FUNCTION: acpi_ut_find_allocation |
| 554 | * |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 555 | * PARAMETERS: Allocation - Address of allocated memory |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 556 | * |
| 557 | * RETURN: A list element if found; NULL otherwise. |
| 558 | * |
| 559 | * DESCRIPTION: Searches for an element in the global allocation tracking list. |
| 560 | * |
| 561 | ******************************************************************************/ |
| 562 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 563 | static struct acpi_debug_mem_block *acpi_ut_find_allocation(void *allocation) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 565 | struct acpi_debug_mem_block *element; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 566 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 567 | ACPI_FUNCTION_ENTRY(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 569 | element = acpi_gbl_global_list->list_head; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 570 | |
| 571 | /* Search for the address. */ |
| 572 | |
| 573 | while (element) { |
| 574 | if (element == allocation) { |
| 575 | return (element); |
| 576 | } |
| 577 | |
| 578 | element = element->next; |
| 579 | } |
| 580 | |
| 581 | return (NULL); |
| 582 | } |
| 583 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 584 | /******************************************************************************* |
| 585 | * |
| 586 | * FUNCTION: acpi_ut_track_allocation |
| 587 | * |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 588 | * PARAMETERS: Allocation - Address of allocated memory |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 589 | * Size - Size of the allocation |
| 590 | * alloc_type - MEM_MALLOC or MEM_CALLOC |
| 591 | * Component - Component type of caller |
| 592 | * Module - Source file name of caller |
| 593 | * Line - Line number of caller |
| 594 | * |
| 595 | * RETURN: None. |
| 596 | * |
| 597 | * DESCRIPTION: Inserts an element into the global allocation tracking list. |
| 598 | * |
| 599 | ******************************************************************************/ |
| 600 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 601 | static acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 602 | acpi_ut_track_allocation(struct acpi_debug_mem_block *allocation, |
| 603 | acpi_size size, |
| 604 | u8 alloc_type, u32 component, char *module, u32 line) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 605 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 606 | struct acpi_memory_list *mem_list; |
| 607 | struct acpi_debug_mem_block *element; |
| 608 | acpi_status status = AE_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 609 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 610 | ACPI_FUNCTION_TRACE_PTR("ut_track_allocation", allocation); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 611 | |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 612 | mem_list = acpi_gbl_global_list; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 613 | status = acpi_ut_acquire_mutex(ACPI_MTX_MEMORY); |
| 614 | if (ACPI_FAILURE(status)) { |
| 615 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 616 | } |
| 617 | |
| 618 | /* |
| 619 | * Search list for this address to make sure it is not already on the list. |
| 620 | * This will catch several kinds of problems. |
| 621 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 622 | element = acpi_ut_find_allocation(allocation); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 623 | if (element) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 624 | ACPI_ERROR((AE_INFO, |
| 625 | "ut_track_allocation: Allocation already present in list! (%p)", |
| 626 | allocation)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 627 | |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 628 | ACPI_ERROR((AE_INFO, "Element %p Address %p", |
| 629 | element, allocation)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 630 | |
| 631 | goto unlock_and_exit; |
| 632 | } |
| 633 | |
| 634 | /* Fill in the instance data. */ |
| 635 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 636 | allocation->size = (u32) size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 637 | allocation->alloc_type = alloc_type; |
| 638 | allocation->component = component; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 639 | allocation->line = line; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 640 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 641 | ACPI_STRNCPY(allocation->module, module, ACPI_MAX_MODULE_NAME); |
| 642 | allocation->module[ACPI_MAX_MODULE_NAME - 1] = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 643 | |
| 644 | /* Insert at list head */ |
| 645 | |
| 646 | if (mem_list->list_head) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 647 | ((struct acpi_debug_mem_block *)(mem_list->list_head))-> |
| 648 | previous = allocation; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 649 | } |
| 650 | |
| 651 | allocation->next = mem_list->list_head; |
| 652 | allocation->previous = NULL; |
| 653 | |
| 654 | mem_list->list_head = allocation; |
| 655 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 656 | unlock_and_exit: |
| 657 | status = acpi_ut_release_mutex(ACPI_MTX_MEMORY); |
| 658 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 659 | } |
| 660 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 661 | /******************************************************************************* |
| 662 | * |
| 663 | * FUNCTION: acpi_ut_remove_allocation |
| 664 | * |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 665 | * PARAMETERS: Allocation - Address of allocated memory |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 666 | * Component - Component type of caller |
| 667 | * Module - Source file name of caller |
| 668 | * Line - Line number of caller |
| 669 | * |
| 670 | * RETURN: |
| 671 | * |
| 672 | * DESCRIPTION: Deletes an element from the global allocation tracking list. |
| 673 | * |
| 674 | ******************************************************************************/ |
| 675 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 676 | static acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 677 | acpi_ut_remove_allocation(struct acpi_debug_mem_block *allocation, |
| 678 | u32 component, char *module, u32 line) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 679 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 680 | struct acpi_memory_list *mem_list; |
| 681 | acpi_status status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 682 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 683 | ACPI_FUNCTION_TRACE("ut_remove_allocation"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 684 | |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 685 | mem_list = acpi_gbl_global_list; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 686 | if (NULL == mem_list->list_head) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame^] | 687 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 688 | /* No allocations! */ |
| 689 | |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 690 | ACPI_ERROR((module, line, |
| 691 | "Empty allocation list, nothing to free!")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 692 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 693 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 694 | } |
| 695 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 696 | status = acpi_ut_acquire_mutex(ACPI_MTX_MEMORY); |
| 697 | if (ACPI_FAILURE(status)) { |
| 698 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 699 | } |
| 700 | |
| 701 | /* Unlink */ |
| 702 | |
| 703 | if (allocation->previous) { |
| 704 | (allocation->previous)->next = allocation->next; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 705 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 706 | mem_list->list_head = allocation->next; |
| 707 | } |
| 708 | |
| 709 | if (allocation->next) { |
| 710 | (allocation->next)->previous = allocation->previous; |
| 711 | } |
| 712 | |
| 713 | /* Mark the segment as deleted */ |
| 714 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 715 | ACPI_MEMSET(&allocation->user_space, 0xEA, allocation->size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 716 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 717 | ACPI_DEBUG_PRINT((ACPI_DB_ALLOCATIONS, "Freeing size 0%X\n", |
| 718 | allocation->size)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 719 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 720 | status = acpi_ut_release_mutex(ACPI_MTX_MEMORY); |
| 721 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 722 | } |
| 723 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 724 | /******************************************************************************* |
| 725 | * |
| 726 | * FUNCTION: acpi_ut_dump_allocation_info |
| 727 | * |
| 728 | * PARAMETERS: |
| 729 | * |
| 730 | * RETURN: None |
| 731 | * |
| 732 | * DESCRIPTION: Print some info about the outstanding allocations. |
| 733 | * |
| 734 | ******************************************************************************/ |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 735 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 736 | #ifdef ACPI_FUTURE_USAGE |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 737 | void acpi_ut_dump_allocation_info(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 738 | { |
| 739 | /* |
| 740 | struct acpi_memory_list *mem_list; |
| 741 | */ |
| 742 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 743 | ACPI_FUNCTION_TRACE("ut_dump_allocation_info"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 744 | |
| 745 | /* |
| 746 | ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES, |
| 747 | ("%30s: %4d (%3d Kb)\n", "Current allocations", |
| 748 | mem_list->current_count, |
| 749 | ROUND_UP_TO_1K (mem_list->current_size))); |
| 750 | |
| 751 | ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES, |
| 752 | ("%30s: %4d (%3d Kb)\n", "Max concurrent allocations", |
| 753 | mem_list->max_concurrent_count, |
| 754 | ROUND_UP_TO_1K (mem_list->max_concurrent_size))); |
| 755 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 756 | ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES, |
| 757 | ("%30s: %4d (%3d Kb)\n", "Total (all) internal objects", |
| 758 | running_object_count, |
| 759 | ROUND_UP_TO_1K (running_object_size))); |
| 760 | |
| 761 | ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES, |
| 762 | ("%30s: %4d (%3d Kb)\n", "Total (all) allocations", |
| 763 | running_alloc_count, |
| 764 | ROUND_UP_TO_1K (running_alloc_size))); |
| 765 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 766 | ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES, |
| 767 | ("%30s: %4d (%3d Kb)\n", "Current Nodes", |
| 768 | acpi_gbl_current_node_count, |
| 769 | ROUND_UP_TO_1K (acpi_gbl_current_node_size))); |
| 770 | |
| 771 | ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES, |
| 772 | ("%30s: %4d (%3d Kb)\n", "Max Nodes", |
| 773 | acpi_gbl_max_concurrent_node_count, |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 774 | ROUND_UP_TO_1K ((acpi_gbl_max_concurrent_node_count * |
| 775 | sizeof (struct acpi_namespace_node))))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 776 | */ |
| 777 | return_VOID; |
| 778 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 779 | #endif /* ACPI_FUTURE_USAGE */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 780 | |
| 781 | /******************************************************************************* |
| 782 | * |
| 783 | * FUNCTION: acpi_ut_dump_allocations |
| 784 | * |
| 785 | * PARAMETERS: Component - Component(s) to dump info for. |
| 786 | * Module - Module to dump info for. NULL means all. |
| 787 | * |
| 788 | * RETURN: None |
| 789 | * |
| 790 | * DESCRIPTION: Print a list of all outstanding allocations. |
| 791 | * |
| 792 | ******************************************************************************/ |
| 793 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 794 | void acpi_ut_dump_allocations(u32 component, char *module) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 795 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 796 | struct acpi_debug_mem_block *element; |
| 797 | union acpi_descriptor *descriptor; |
| 798 | u32 num_outstanding = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 799 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 800 | ACPI_FUNCTION_TRACE("ut_dump_allocations"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 801 | |
| 802 | /* |
| 803 | * Walk the allocation list. |
| 804 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 805 | if (ACPI_FAILURE(acpi_ut_acquire_mutex(ACPI_MTX_MEMORY))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 806 | return; |
| 807 | } |
| 808 | |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 809 | element = acpi_gbl_global_list->list_head; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 810 | while (element) { |
| 811 | if ((element->component & component) && |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 812 | ((module == NULL) |
| 813 | || (0 == ACPI_STRCMP(module, element->module)))) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame^] | 814 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 815 | /* Ignore allocated objects that are in a cache */ |
| 816 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 817 | descriptor = |
| 818 | ACPI_CAST_PTR(union acpi_descriptor, |
| 819 | &element->user_space); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 820 | if (descriptor->descriptor_id != ACPI_DESC_TYPE_CACHED) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 821 | acpi_os_printf("%p Len %04X %9.9s-%d [%s] ", |
| 822 | descriptor, element->size, |
| 823 | element->module, element->line, |
| 824 | acpi_ut_get_descriptor_name |
| 825 | (descriptor)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 826 | |
| 827 | /* Most of the elements will be Operand objects. */ |
| 828 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 829 | switch (ACPI_GET_DESCRIPTOR_TYPE(descriptor)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 830 | case ACPI_DESC_TYPE_OPERAND: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 831 | acpi_os_printf("%12.12s R%hd", |
| 832 | acpi_ut_get_type_name |
| 833 | (descriptor->object. |
| 834 | common.type), |
| 835 | descriptor->object. |
| 836 | common.reference_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 837 | break; |
| 838 | |
| 839 | case ACPI_DESC_TYPE_PARSER: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 840 | acpi_os_printf("aml_opcode %04hX", |
| 841 | descriptor->op.asl. |
| 842 | aml_opcode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 843 | break; |
| 844 | |
| 845 | case ACPI_DESC_TYPE_NAMED: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 846 | acpi_os_printf("%4.4s", |
| 847 | acpi_ut_get_node_name |
| 848 | (&descriptor->node)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 849 | break; |
| 850 | |
| 851 | default: |
| 852 | break; |
| 853 | } |
| 854 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 855 | acpi_os_printf("\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 856 | num_outstanding++; |
| 857 | } |
| 858 | } |
| 859 | element = element->next; |
| 860 | } |
| 861 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 862 | (void)acpi_ut_release_mutex(ACPI_MTX_MEMORY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 863 | |
| 864 | /* Print summary */ |
| 865 | |
| 866 | if (!num_outstanding) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 867 | ACPI_INFO((AE_INFO, "No outstanding allocations")); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 868 | } else { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 869 | ACPI_ERROR((AE_INFO, |
| 870 | "%d(%X) Outstanding allocations", |
| 871 | num_outstanding, num_outstanding)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 872 | } |
| 873 | |
| 874 | return_VOID; |
| 875 | } |
| 876 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 877 | #endif /* #ifdef ACPI_DBG_TRACK_ALLOCATIONS */ |