utalloc.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950
  1. /******************************************************************************
  2. *
  3. * Module Name: utalloc - local memory allocation routines
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2005, R. Byron Moore
  8. * All rights reserved.
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions
  12. * are met:
  13. * 1. Redistributions of source code must retain the above copyright
  14. * notice, this list of conditions, and the following disclaimer,
  15. * without modification.
  16. * 2. Redistributions in binary form must reproduce at minimum a disclaimer
  17. * substantially similar to the "NO WARRANTY" disclaimer below
  18. * ("Disclaimer") and any redistribution must be conditioned upon
  19. * including a substantially similar Disclaimer requirement for further
  20. * binary redistribution.
  21. * 3. Neither the names of the above-listed copyright holders nor the names
  22. * of any contributors may be used to endorse or promote products derived
  23. * from this software without specific prior written permission.
  24. *
  25. * Alternatively, this software may be distributed under the terms of the
  26. * GNU General Public License ("GPL") version 2 as published by the Free
  27. * Software Foundation.
  28. *
  29. * NO WARRANTY
  30. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  31. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  32. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
  33. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  34. * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  35. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  36. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  37. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  38. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  39. * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  40. * POSSIBILITY OF SUCH DAMAGES.
  41. */
  42. #include <acpi/acpi.h>
  43. #define _COMPONENT ACPI_UTILITIES
  44. ACPI_MODULE_NAME ("utalloc")
  45. /* Local prototypes */
  46. #ifdef ACPI_DBG_TRACK_ALLOCATIONS
  47. static struct acpi_debug_mem_block *
  48. acpi_ut_find_allocation (
  49. void *allocation);
  50. static acpi_status
  51. acpi_ut_track_allocation (
  52. struct acpi_debug_mem_block *address,
  53. acpi_size size,
  54. u8 alloc_type,
  55. u32 component,
  56. char *module,
  57. u32 line);
  58. static acpi_status
  59. acpi_ut_remove_allocation (
  60. struct acpi_debug_mem_block *address,
  61. u32 component,
  62. char *module,
  63. u32 line);
  64. #endif /* ACPI_DBG_TRACK_ALLOCATIONS */
  65. #ifdef ACPI_DBG_TRACK_ALLOCATIONS
  66. static acpi_status
  67. acpi_ut_create_list (
  68. char *list_name,
  69. u16 object_size,
  70. struct acpi_memory_list **return_cache);
  71. #endif
  72. /*******************************************************************************
  73. *
  74. * FUNCTION: acpi_ut_create_caches
  75. *
  76. * PARAMETERS: None
  77. *
  78. * RETURN: Status
  79. *
  80. * DESCRIPTION: Create all local caches
  81. *
  82. ******************************************************************************/
  83. acpi_status
  84. acpi_ut_create_caches (
  85. void)
  86. {
  87. acpi_status status;
  88. #ifdef ACPI_DBG_TRACK_ALLOCATIONS
  89. /* Memory allocation lists */
  90. status = acpi_ut_create_list ("Acpi-Global", 0,
  91. &acpi_gbl_global_list);
  92. if (ACPI_FAILURE (status)) {
  93. return (status);
  94. }
  95. status = acpi_ut_create_list ("Acpi-Namespace", sizeof (struct acpi_namespace_node),
  96. &acpi_gbl_ns_node_list);
  97. if (ACPI_FAILURE (status)) {
  98. return (status);
  99. }
  100. #endif
  101. /* Object Caches, for frequently used objects */
  102. status = acpi_os_create_cache ("acpi_state", sizeof (union acpi_generic_state),
  103. ACPI_MAX_STATE_CACHE_DEPTH, &acpi_gbl_state_cache);
  104. if (ACPI_FAILURE (status)) {
  105. return (status);
  106. }
  107. status = acpi_os_create_cache ("acpi_parse", sizeof (struct acpi_parse_obj_common),
  108. ACPI_MAX_PARSE_CACHE_DEPTH, &acpi_gbl_ps_node_cache);
  109. if (ACPI_FAILURE (status)) {
  110. return (status);
  111. }
  112. status = acpi_os_create_cache ("acpi_parse_ext", sizeof (struct acpi_parse_obj_named),
  113. ACPI_MAX_EXTPARSE_CACHE_DEPTH, &acpi_gbl_ps_node_ext_cache);
  114. if (ACPI_FAILURE (status)) {
  115. return (status);
  116. }
  117. status = acpi_os_create_cache ("acpi_operand", sizeof (union acpi_operand_object),
  118. ACPI_MAX_OBJECT_CACHE_DEPTH, &acpi_gbl_operand_cache);
  119. if (ACPI_FAILURE (status)) {
  120. return (status);
  121. }
  122. return (AE_OK);
  123. }
  124. /*******************************************************************************
  125. *
  126. * FUNCTION: acpi_ut_delete_caches
  127. *
  128. * PARAMETERS: None
  129. *
  130. * RETURN: Status
  131. *
  132. * DESCRIPTION: Purge and delete all local caches
  133. *
  134. ******************************************************************************/
  135. acpi_status
  136. acpi_ut_delete_caches (
  137. void)
  138. {
  139. (void) acpi_os_delete_cache (acpi_gbl_state_cache);
  140. acpi_gbl_state_cache = NULL;
  141. (void) acpi_os_delete_cache (acpi_gbl_operand_cache);
  142. acpi_gbl_operand_cache = NULL;
  143. (void) acpi_os_delete_cache (acpi_gbl_ps_node_cache);
  144. acpi_gbl_ps_node_cache = NULL;
  145. (void) acpi_os_delete_cache (acpi_gbl_ps_node_ext_cache);
  146. acpi_gbl_ps_node_ext_cache = NULL;
  147. return (AE_OK);
  148. }
  149. /*******************************************************************************
  150. *
  151. * FUNCTION: acpi_ut_validate_buffer
  152. *
  153. * PARAMETERS: Buffer - Buffer descriptor to be validated
  154. *
  155. * RETURN: Status
  156. *
  157. * DESCRIPTION: Perform parameter validation checks on an struct acpi_buffer
  158. *
  159. ******************************************************************************/
  160. acpi_status
  161. acpi_ut_validate_buffer (
  162. struct acpi_buffer *buffer)
  163. {
  164. /* Obviously, the structure pointer must be valid */
  165. if (!buffer) {
  166. return (AE_BAD_PARAMETER);
  167. }
  168. /* Special semantics for the length */
  169. if ((buffer->length == ACPI_NO_BUFFER) ||
  170. (buffer->length == ACPI_ALLOCATE_BUFFER) ||
  171. (buffer->length == ACPI_ALLOCATE_LOCAL_BUFFER)) {
  172. return (AE_OK);
  173. }
  174. /* Length is valid, the buffer pointer must be also */
  175. if (!buffer->pointer) {
  176. return (AE_BAD_PARAMETER);
  177. }
  178. return (AE_OK);
  179. }
  180. /*******************************************************************************
  181. *
  182. * FUNCTION: acpi_ut_initialize_buffer
  183. *
  184. * PARAMETERS: Buffer - Buffer to be validated
  185. * required_length - Length needed
  186. *
  187. * RETURN: Status
  188. *
  189. * DESCRIPTION: Validate that the buffer is of the required length or
  190. * allocate a new buffer. Returned buffer is always zeroed.
  191. *
  192. ******************************************************************************/
  193. acpi_status
  194. acpi_ut_initialize_buffer (
  195. struct acpi_buffer *buffer,
  196. acpi_size required_length)
  197. {
  198. acpi_status status = AE_OK;
  199. switch (buffer->length) {
  200. case ACPI_NO_BUFFER:
  201. /* Set the exception and returned the required length */
  202. status = AE_BUFFER_OVERFLOW;
  203. break;
  204. case ACPI_ALLOCATE_BUFFER:
  205. /* Allocate a new buffer */
  206. buffer->pointer = acpi_os_allocate (required_length);
  207. if (!buffer->pointer) {
  208. return (AE_NO_MEMORY);
  209. }
  210. /* Clear the buffer */
  211. ACPI_MEMSET (buffer->pointer, 0, required_length);
  212. break;
  213. case ACPI_ALLOCATE_LOCAL_BUFFER:
  214. /* Allocate a new buffer with local interface to allow tracking */
  215. buffer->pointer = ACPI_MEM_CALLOCATE (required_length);
  216. if (!buffer->pointer) {
  217. return (AE_NO_MEMORY);
  218. }
  219. break;
  220. default:
  221. /* Existing buffer: Validate the size of the buffer */
  222. if (buffer->length < required_length) {
  223. status = AE_BUFFER_OVERFLOW;
  224. break;
  225. }
  226. /* Clear the buffer */
  227. ACPI_MEMSET (buffer->pointer, 0, required_length);
  228. break;
  229. }
  230. buffer->length = required_length;
  231. return (status);
  232. }
  233. /*******************************************************************************
  234. *
  235. * FUNCTION: acpi_ut_allocate
  236. *
  237. * PARAMETERS: Size - Size of the allocation
  238. * Component - Component type of caller
  239. * Module - Source file name of caller
  240. * Line - Line number of caller
  241. *
  242. * RETURN: Address of the allocated memory on success, NULL on failure.
  243. *
  244. * DESCRIPTION: The subsystem's equivalent of malloc.
  245. *
  246. ******************************************************************************/
  247. void *
  248. acpi_ut_allocate (
  249. acpi_size size,
  250. u32 component,
  251. char *module,
  252. u32 line)
  253. {
  254. void *allocation;
  255. ACPI_FUNCTION_TRACE_U32 ("ut_allocate", size);
  256. /* Check for an inadvertent size of zero bytes */
  257. if (!size) {
  258. _ACPI_REPORT_ERROR (module, line, component,
  259. ("ut_allocate: Attempt to allocate zero bytes\n"));
  260. size = 1;
  261. }
  262. allocation = acpi_os_allocate (size);
  263. if (!allocation) {
  264. /* Report allocation error */
  265. _ACPI_REPORT_ERROR (module, line, component,
  266. ("ut_allocate: Could not allocate size %X\n", (u32) size));
  267. return_PTR (NULL);
  268. }
  269. return_PTR (allocation);
  270. }
  271. /*******************************************************************************
  272. *
  273. * FUNCTION: acpi_ut_callocate
  274. *
  275. * PARAMETERS: Size - Size of the allocation
  276. * Component - Component type of caller
  277. * Module - Source file name of caller
  278. * Line - Line number of caller
  279. *
  280. * RETURN: Address of the allocated memory on success, NULL on failure.
  281. *
  282. * DESCRIPTION: Subsystem equivalent of calloc.
  283. *
  284. ******************************************************************************/
  285. void *
  286. acpi_ut_callocate (
  287. acpi_size size,
  288. u32 component,
  289. char *module,
  290. u32 line)
  291. {
  292. void *allocation;
  293. ACPI_FUNCTION_TRACE_U32 ("ut_callocate", size);
  294. /* Check for an inadvertent size of zero bytes */
  295. if (!size) {
  296. _ACPI_REPORT_ERROR (module, line, component,
  297. ("ut_callocate: Attempt to allocate zero bytes\n"));
  298. return_PTR (NULL);
  299. }
  300. allocation = acpi_os_allocate (size);
  301. if (!allocation) {
  302. /* Report allocation error */
  303. _ACPI_REPORT_ERROR (module, line, component,
  304. ("ut_callocate: Could not allocate size %X\n", (u32) size));
  305. return_PTR (NULL);
  306. }
  307. /* Clear the memory block */
  308. ACPI_MEMSET (allocation, 0, size);
  309. return_PTR (allocation);
  310. }
  311. #ifdef ACPI_DBG_TRACK_ALLOCATIONS
  312. /*
  313. * These procedures are used for tracking memory leaks in the subsystem, and
  314. * they get compiled out when the ACPI_DBG_TRACK_ALLOCATIONS is not set.
  315. *
  316. * Each memory allocation is tracked via a doubly linked list. Each
  317. * element contains the caller's component, module name, function name, and
  318. * line number. acpi_ut_allocate and acpi_ut_callocate call
  319. * acpi_ut_track_allocation to add an element to the list; deletion
  320. * occurs in the body of acpi_ut_free.
  321. */
  322. /*******************************************************************************
  323. *
  324. * FUNCTION: acpi_ut_create_list
  325. *
  326. * PARAMETERS: cache_name - Ascii name for the cache
  327. * object_size - Size of each cached object
  328. * return_cache - Where the new cache object is returned
  329. *
  330. * RETURN: Status
  331. *
  332. * DESCRIPTION: Create a local memory list for tracking purposed
  333. *
  334. ******************************************************************************/
  335. static acpi_status
  336. acpi_ut_create_list (
  337. char *list_name,
  338. u16 object_size,
  339. struct acpi_memory_list **return_cache)
  340. {
  341. struct acpi_memory_list *cache;
  342. cache = acpi_os_allocate (sizeof (struct acpi_memory_list));
  343. if (!cache) {
  344. return (AE_NO_MEMORY);
  345. }
  346. ACPI_MEMSET (cache, 0, sizeof (struct acpi_memory_list));
  347. cache->list_name = list_name;
  348. cache->object_size = object_size;
  349. *return_cache = cache;
  350. return (AE_OK);
  351. }
  352. /*******************************************************************************
  353. *
  354. * FUNCTION: acpi_ut_allocate_and_track
  355. *
  356. * PARAMETERS: Size - Size of the allocation
  357. * Component - Component type of caller
  358. * Module - Source file name of caller
  359. * Line - Line number of caller
  360. *
  361. * RETURN: Address of the allocated memory on success, NULL on failure.
  362. *
  363. * DESCRIPTION: The subsystem's equivalent of malloc.
  364. *
  365. ******************************************************************************/
  366. void *
  367. acpi_ut_allocate_and_track (
  368. acpi_size size,
  369. u32 component,
  370. char *module,
  371. u32 line)
  372. {
  373. struct acpi_debug_mem_block *allocation;
  374. acpi_status status;
  375. allocation = acpi_ut_allocate (size + sizeof (struct acpi_debug_mem_header),
  376. component, module, line);
  377. if (!allocation) {
  378. return (NULL);
  379. }
  380. status = acpi_ut_track_allocation (allocation, size,
  381. ACPI_MEM_MALLOC, component, module, line);
  382. if (ACPI_FAILURE (status)) {
  383. acpi_os_free (allocation);
  384. return (NULL);
  385. }
  386. acpi_gbl_global_list->total_allocated++;
  387. acpi_gbl_global_list->current_total_size += (u32) size;
  388. return ((void *) &allocation->user_space);
  389. }
  390. /*******************************************************************************
  391. *
  392. * FUNCTION: acpi_ut_callocate_and_track
  393. *
  394. * PARAMETERS: Size - Size of the allocation
  395. * Component - Component type of caller
  396. * Module - Source file name of caller
  397. * Line - Line number of caller
  398. *
  399. * RETURN: Address of the allocated memory on success, NULL on failure.
  400. *
  401. * DESCRIPTION: Subsystem equivalent of calloc.
  402. *
  403. ******************************************************************************/
  404. void *
  405. acpi_ut_callocate_and_track (
  406. acpi_size size,
  407. u32 component,
  408. char *module,
  409. u32 line)
  410. {
  411. struct acpi_debug_mem_block *allocation;
  412. acpi_status status;
  413. allocation = acpi_ut_callocate (size + sizeof (struct acpi_debug_mem_header),
  414. component, module, line);
  415. if (!allocation) {
  416. /* Report allocation error */
  417. _ACPI_REPORT_ERROR (module, line, component,
  418. ("ut_callocate: Could not allocate size %X\n", (u32) size));
  419. return (NULL);
  420. }
  421. status = acpi_ut_track_allocation (allocation, size,
  422. ACPI_MEM_CALLOC, component, module, line);
  423. if (ACPI_FAILURE (status)) {
  424. acpi_os_free (allocation);
  425. return (NULL);
  426. }
  427. acpi_gbl_global_list->total_allocated++;
  428. acpi_gbl_global_list->current_total_size += (u32) size;
  429. return ((void *) &allocation->user_space);
  430. }
  431. /*******************************************************************************
  432. *
  433. * FUNCTION: acpi_ut_free_and_track
  434. *
  435. * PARAMETERS: Allocation - Address of the memory to deallocate
  436. * Component - Component type of caller
  437. * Module - Source file name of caller
  438. * Line - Line number of caller
  439. *
  440. * RETURN: None
  441. *
  442. * DESCRIPTION: Frees the memory at Allocation
  443. *
  444. ******************************************************************************/
  445. void
  446. acpi_ut_free_and_track (
  447. void *allocation,
  448. u32 component,
  449. char *module,
  450. u32 line)
  451. {
  452. struct acpi_debug_mem_block *debug_block;
  453. acpi_status status;
  454. ACPI_FUNCTION_TRACE_PTR ("ut_free", allocation);
  455. if (NULL == allocation) {
  456. _ACPI_REPORT_ERROR (module, line, component,
  457. ("acpi_ut_free: Attempt to delete a NULL address\n"));
  458. return_VOID;
  459. }
  460. debug_block = ACPI_CAST_PTR (struct acpi_debug_mem_block,
  461. (((char *) allocation) - sizeof (struct acpi_debug_mem_header)));
  462. acpi_gbl_global_list->total_freed++;
  463. acpi_gbl_global_list->current_total_size -= debug_block->size;
  464. status = acpi_ut_remove_allocation (debug_block,
  465. component, module, line);
  466. if (ACPI_FAILURE (status)) {
  467. ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Could not free memory, %s\n",
  468. acpi_format_exception (status)));
  469. }
  470. acpi_os_free (debug_block);
  471. ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "%p freed\n", allocation));
  472. return_VOID;
  473. }
  474. /*******************************************************************************
  475. *
  476. * FUNCTION: acpi_ut_find_allocation
  477. *
  478. * PARAMETERS: Allocation - Address of allocated memory
  479. *
  480. * RETURN: A list element if found; NULL otherwise.
  481. *
  482. * DESCRIPTION: Searches for an element in the global allocation tracking list.
  483. *
  484. ******************************************************************************/
  485. static struct acpi_debug_mem_block *
  486. acpi_ut_find_allocation (
  487. void *allocation)
  488. {
  489. struct acpi_debug_mem_block *element;
  490. ACPI_FUNCTION_ENTRY ();
  491. element = acpi_gbl_global_list->list_head;
  492. /* Search for the address. */
  493. while (element) {
  494. if (element == allocation) {
  495. return (element);
  496. }
  497. element = element->next;
  498. }
  499. return (NULL);
  500. }
  501. /*******************************************************************************
  502. *
  503. * FUNCTION: acpi_ut_track_allocation
  504. *
  505. * PARAMETERS: Allocation - Address of allocated memory
  506. * Size - Size of the allocation
  507. * alloc_type - MEM_MALLOC or MEM_CALLOC
  508. * Component - Component type of caller
  509. * Module - Source file name of caller
  510. * Line - Line number of caller
  511. *
  512. * RETURN: None.
  513. *
  514. * DESCRIPTION: Inserts an element into the global allocation tracking list.
  515. *
  516. ******************************************************************************/
  517. static acpi_status
  518. acpi_ut_track_allocation (
  519. struct acpi_debug_mem_block *allocation,
  520. acpi_size size,
  521. u8 alloc_type,
  522. u32 component,
  523. char *module,
  524. u32 line)
  525. {
  526. struct acpi_memory_list *mem_list;
  527. struct acpi_debug_mem_block *element;
  528. acpi_status status = AE_OK;
  529. ACPI_FUNCTION_TRACE_PTR ("ut_track_allocation", allocation);
  530. mem_list = acpi_gbl_global_list;
  531. status = acpi_ut_acquire_mutex (ACPI_MTX_MEMORY);
  532. if (ACPI_FAILURE (status)) {
  533. return_ACPI_STATUS (status);
  534. }
  535. /*
  536. * Search list for this address to make sure it is not already on the list.
  537. * This will catch several kinds of problems.
  538. */
  539. element = acpi_ut_find_allocation (allocation);
  540. if (element) {
  541. ACPI_REPORT_ERROR ((
  542. "ut_track_allocation: Allocation already present in list! (%p)\n",
  543. allocation));
  544. ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Element %p Address %p\n",
  545. element, allocation));
  546. goto unlock_and_exit;
  547. }
  548. /* Fill in the instance data. */
  549. allocation->size = (u32) size;
  550. allocation->alloc_type = alloc_type;
  551. allocation->component = component;
  552. allocation->line = line;
  553. ACPI_STRNCPY (allocation->module, module, ACPI_MAX_MODULE_NAME);
  554. allocation->module[ACPI_MAX_MODULE_NAME-1] = 0;
  555. /* Insert at list head */
  556. if (mem_list->list_head) {
  557. ((struct acpi_debug_mem_block *)(mem_list->list_head))->previous = allocation;
  558. }
  559. allocation->next = mem_list->list_head;
  560. allocation->previous = NULL;
  561. mem_list->list_head = allocation;
  562. unlock_and_exit:
  563. status = acpi_ut_release_mutex (ACPI_MTX_MEMORY);
  564. return_ACPI_STATUS (status);
  565. }
  566. /*******************************************************************************
  567. *
  568. * FUNCTION: acpi_ut_remove_allocation
  569. *
  570. * PARAMETERS: Allocation - Address of allocated memory
  571. * Component - Component type of caller
  572. * Module - Source file name of caller
  573. * Line - Line number of caller
  574. *
  575. * RETURN:
  576. *
  577. * DESCRIPTION: Deletes an element from the global allocation tracking list.
  578. *
  579. ******************************************************************************/
  580. static acpi_status
  581. acpi_ut_remove_allocation (
  582. struct acpi_debug_mem_block *allocation,
  583. u32 component,
  584. char *module,
  585. u32 line)
  586. {
  587. struct acpi_memory_list *mem_list;
  588. acpi_status status;
  589. ACPI_FUNCTION_TRACE ("ut_remove_allocation");
  590. mem_list = acpi_gbl_global_list;
  591. if (NULL == mem_list->list_head) {
  592. /* No allocations! */
  593. _ACPI_REPORT_ERROR (module, line, component,
  594. ("ut_remove_allocation: Empty allocation list, nothing to free!\n"));
  595. return_ACPI_STATUS (AE_OK);
  596. }
  597. status = acpi_ut_acquire_mutex (ACPI_MTX_MEMORY);
  598. if (ACPI_FAILURE (status)) {
  599. return_ACPI_STATUS (status);
  600. }
  601. /* Unlink */
  602. if (allocation->previous) {
  603. (allocation->previous)->next = allocation->next;
  604. }
  605. else {
  606. mem_list->list_head = allocation->next;
  607. }
  608. if (allocation->next) {
  609. (allocation->next)->previous = allocation->previous;
  610. }
  611. /* Mark the segment as deleted */
  612. ACPI_MEMSET (&allocation->user_space, 0xEA, allocation->size);
  613. ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "Freeing size 0%X\n",
  614. allocation->size));
  615. status = acpi_ut_release_mutex (ACPI_MTX_MEMORY);
  616. return_ACPI_STATUS (status);
  617. }
  618. /*******************************************************************************
  619. *
  620. * FUNCTION: acpi_ut_dump_allocation_info
  621. *
  622. * PARAMETERS:
  623. *
  624. * RETURN: None
  625. *
  626. * DESCRIPTION: Print some info about the outstanding allocations.
  627. *
  628. ******************************************************************************/
  629. #ifdef ACPI_FUTURE_USAGE
  630. void
  631. acpi_ut_dump_allocation_info (
  632. void)
  633. {
  634. /*
  635. struct acpi_memory_list *mem_list;
  636. */
  637. ACPI_FUNCTION_TRACE ("ut_dump_allocation_info");
  638. /*
  639. ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES,
  640. ("%30s: %4d (%3d Kb)\n", "Current allocations",
  641. mem_list->current_count,
  642. ROUND_UP_TO_1K (mem_list->current_size)));
  643. ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES,
  644. ("%30s: %4d (%3d Kb)\n", "Max concurrent allocations",
  645. mem_list->max_concurrent_count,
  646. ROUND_UP_TO_1K (mem_list->max_concurrent_size)));
  647. ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES,
  648. ("%30s: %4d (%3d Kb)\n", "Total (all) internal objects",
  649. running_object_count,
  650. ROUND_UP_TO_1K (running_object_size)));
  651. ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES,
  652. ("%30s: %4d (%3d Kb)\n", "Total (all) allocations",
  653. running_alloc_count,
  654. ROUND_UP_TO_1K (running_alloc_size)));
  655. ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES,
  656. ("%30s: %4d (%3d Kb)\n", "Current Nodes",
  657. acpi_gbl_current_node_count,
  658. ROUND_UP_TO_1K (acpi_gbl_current_node_size)));
  659. ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES,
  660. ("%30s: %4d (%3d Kb)\n", "Max Nodes",
  661. acpi_gbl_max_concurrent_node_count,
  662. ROUND_UP_TO_1K ((acpi_gbl_max_concurrent_node_count *
  663. sizeof (struct acpi_namespace_node)))));
  664. */
  665. return_VOID;
  666. }
  667. #endif /* ACPI_FUTURE_USAGE */
  668. /*******************************************************************************
  669. *
  670. * FUNCTION: acpi_ut_dump_allocations
  671. *
  672. * PARAMETERS: Component - Component(s) to dump info for.
  673. * Module - Module to dump info for. NULL means all.
  674. *
  675. * RETURN: None
  676. *
  677. * DESCRIPTION: Print a list of all outstanding allocations.
  678. *
  679. ******************************************************************************/
  680. void
  681. acpi_ut_dump_allocations (
  682. u32 component,
  683. char *module)
  684. {
  685. struct acpi_debug_mem_block *element;
  686. union acpi_descriptor *descriptor;
  687. u32 num_outstanding = 0;
  688. ACPI_FUNCTION_TRACE ("ut_dump_allocations");
  689. /*
  690. * Walk the allocation list.
  691. */
  692. if (ACPI_FAILURE (acpi_ut_acquire_mutex (ACPI_MTX_MEMORY))) {
  693. return;
  694. }
  695. element = acpi_gbl_global_list->list_head;
  696. while (element) {
  697. if ((element->component & component) &&
  698. ((module == NULL) || (0 == ACPI_STRCMP (module, element->module)))) {
  699. /* Ignore allocated objects that are in a cache */
  700. descriptor = ACPI_CAST_PTR (union acpi_descriptor, &element->user_space);
  701. if (descriptor->descriptor_id != ACPI_DESC_TYPE_CACHED) {
  702. acpi_os_printf ("%p Len %04X %9.9s-%d [%s] ",
  703. descriptor, element->size, element->module,
  704. element->line, acpi_ut_get_descriptor_name (descriptor));
  705. /* Most of the elements will be Operand objects. */
  706. switch (ACPI_GET_DESCRIPTOR_TYPE (descriptor)) {
  707. case ACPI_DESC_TYPE_OPERAND:
  708. acpi_os_printf ("%12.12s R%hd",
  709. acpi_ut_get_type_name (descriptor->object.common.type),
  710. descriptor->object.common.reference_count);
  711. break;
  712. case ACPI_DESC_TYPE_PARSER:
  713. acpi_os_printf ("aml_opcode %04hX",
  714. descriptor->op.asl.aml_opcode);
  715. break;
  716. case ACPI_DESC_TYPE_NAMED:
  717. acpi_os_printf ("%4.4s",
  718. acpi_ut_get_node_name (&descriptor->node));
  719. break;
  720. default:
  721. break;
  722. }
  723. acpi_os_printf ( "\n");
  724. num_outstanding++;
  725. }
  726. }
  727. element = element->next;
  728. }
  729. (void) acpi_ut_release_mutex (ACPI_MTX_MEMORY);
  730. /* Print summary */
  731. if (!num_outstanding) {
  732. ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
  733. "No outstanding allocations.\n"));
  734. }
  735. else {
  736. ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
  737. "%d(%X) Outstanding allocations\n",
  738. num_outstanding, num_outstanding));
  739. }
  740. return_VOID;
  741. }
  742. #endif /* #ifdef ACPI_DBG_TRACK_ALLOCATIONS */