utinit.c 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. /******************************************************************************
  2. *
  3. * Module Name: utinit - Common ACPI subsystem initialization
  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. #include <acpi/acnamesp.h>
  44. #include <acpi/acevents.h>
  45. #define _COMPONENT ACPI_UTILITIES
  46. ACPI_MODULE_NAME ("utinit")
  47. /* Local prototypes */
  48. static void
  49. acpi_ut_fadt_register_error (
  50. char *register_name,
  51. u32 value,
  52. acpi_size offset);
  53. static void acpi_ut_terminate (
  54. void);
  55. /*******************************************************************************
  56. *
  57. * FUNCTION: acpi_ut_fadt_register_error
  58. *
  59. * PARAMETERS: register_name - Pointer to string identifying register
  60. * Value - Actual register contents value
  61. * Offset - Byte offset in the FADT
  62. *
  63. * RETURN: AE_BAD_VALUE
  64. *
  65. * DESCRIPTION: Display failure message
  66. *
  67. ******************************************************************************/
  68. static void
  69. acpi_ut_fadt_register_error (
  70. char *register_name,
  71. u32 value,
  72. acpi_size offset)
  73. {
  74. ACPI_REPORT_WARNING (
  75. ("Invalid FADT value %s=%X at offset %X FADT=%p\n",
  76. register_name, value, (u32) offset, acpi_gbl_FADT));
  77. }
  78. /******************************************************************************
  79. *
  80. * FUNCTION: acpi_ut_validate_fadt
  81. *
  82. * PARAMETERS: None
  83. *
  84. * RETURN: Status
  85. *
  86. * DESCRIPTION: Validate various ACPI registers in the FADT
  87. *
  88. ******************************************************************************/
  89. acpi_status
  90. acpi_ut_validate_fadt (
  91. void)
  92. {
  93. /*
  94. * Verify Fixed ACPI Description Table fields,
  95. * but don't abort on any problems, just display error
  96. */
  97. if (acpi_gbl_FADT->pm1_evt_len < 4) {
  98. acpi_ut_fadt_register_error ("PM1_EVT_LEN",
  99. (u32) acpi_gbl_FADT->pm1_evt_len,
  100. ACPI_FADT_OFFSET (pm1_evt_len));
  101. }
  102. if (!acpi_gbl_FADT->pm1_cnt_len) {
  103. acpi_ut_fadt_register_error ("PM1_CNT_LEN", 0,
  104. ACPI_FADT_OFFSET (pm1_cnt_len));
  105. }
  106. if (!acpi_gbl_FADT->xpm1a_evt_blk.address) {
  107. acpi_ut_fadt_register_error ("X_PM1a_EVT_BLK", 0,
  108. ACPI_FADT_OFFSET (xpm1a_evt_blk.address));
  109. }
  110. if (!acpi_gbl_FADT->xpm1a_cnt_blk.address) {
  111. acpi_ut_fadt_register_error ("X_PM1a_CNT_BLK", 0,
  112. ACPI_FADT_OFFSET (xpm1a_cnt_blk.address));
  113. }
  114. if (!acpi_gbl_FADT->xpm_tmr_blk.address) {
  115. acpi_ut_fadt_register_error ("X_PM_TMR_BLK", 0,
  116. ACPI_FADT_OFFSET (xpm_tmr_blk.address));
  117. }
  118. if ((acpi_gbl_FADT->xpm2_cnt_blk.address &&
  119. !acpi_gbl_FADT->pm2_cnt_len)) {
  120. acpi_ut_fadt_register_error ("PM2_CNT_LEN",
  121. (u32) acpi_gbl_FADT->pm2_cnt_len,
  122. ACPI_FADT_OFFSET (pm2_cnt_len));
  123. }
  124. if (acpi_gbl_FADT->pm_tm_len < 4) {
  125. acpi_ut_fadt_register_error ("PM_TM_LEN",
  126. (u32) acpi_gbl_FADT->pm_tm_len,
  127. ACPI_FADT_OFFSET (pm_tm_len));
  128. }
  129. /* Length of GPE blocks must be a multiple of 2 */
  130. if (acpi_gbl_FADT->xgpe0_blk.address &&
  131. (acpi_gbl_FADT->gpe0_blk_len & 1)) {
  132. acpi_ut_fadt_register_error ("(x)GPE0_BLK_LEN",
  133. (u32) acpi_gbl_FADT->gpe0_blk_len,
  134. ACPI_FADT_OFFSET (gpe0_blk_len));
  135. }
  136. if (acpi_gbl_FADT->xgpe1_blk.address &&
  137. (acpi_gbl_FADT->gpe1_blk_len & 1)) {
  138. acpi_ut_fadt_register_error ("(x)GPE1_BLK_LEN",
  139. (u32) acpi_gbl_FADT->gpe1_blk_len,
  140. ACPI_FADT_OFFSET (gpe1_blk_len));
  141. }
  142. return (AE_OK);
  143. }
  144. /******************************************************************************
  145. *
  146. * FUNCTION: acpi_ut_terminate
  147. *
  148. * PARAMETERS: none
  149. *
  150. * RETURN: none
  151. *
  152. * DESCRIPTION: Free global memory
  153. *
  154. ******************************************************************************/
  155. static void
  156. acpi_ut_terminate (
  157. void)
  158. {
  159. struct acpi_gpe_block_info *gpe_block;
  160. struct acpi_gpe_block_info *next_gpe_block;
  161. struct acpi_gpe_xrupt_info *gpe_xrupt_info;
  162. struct acpi_gpe_xrupt_info *next_gpe_xrupt_info;
  163. ACPI_FUNCTION_TRACE ("ut_terminate");
  164. /* Free global tables, etc. */
  165. /* Free global GPE blocks and related info structures */
  166. gpe_xrupt_info = acpi_gbl_gpe_xrupt_list_head;
  167. while (gpe_xrupt_info) {
  168. gpe_block = gpe_xrupt_info->gpe_block_list_head;
  169. while (gpe_block) {
  170. next_gpe_block = gpe_block->next;
  171. ACPI_MEM_FREE (gpe_block->event_info);
  172. ACPI_MEM_FREE (gpe_block->register_info);
  173. ACPI_MEM_FREE (gpe_block);
  174. gpe_block = next_gpe_block;
  175. }
  176. next_gpe_xrupt_info = gpe_xrupt_info->next;
  177. ACPI_MEM_FREE (gpe_xrupt_info);
  178. gpe_xrupt_info = next_gpe_xrupt_info;
  179. }
  180. return_VOID;
  181. }
  182. /*******************************************************************************
  183. *
  184. * FUNCTION: acpi_ut_subsystem_shutdown
  185. *
  186. * PARAMETERS: none
  187. *
  188. * RETURN: none
  189. *
  190. * DESCRIPTION: Shutdown the various subsystems. Don't delete the mutex
  191. * objects here -- because the AML debugger may be still running.
  192. *
  193. ******************************************************************************/
  194. void
  195. acpi_ut_subsystem_shutdown (
  196. void)
  197. {
  198. ACPI_FUNCTION_TRACE ("ut_subsystem_shutdown");
  199. /* Just exit if subsystem is already shutdown */
  200. if (acpi_gbl_shutdown) {
  201. ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
  202. "ACPI Subsystem is already terminated\n"));
  203. return_VOID;
  204. }
  205. /* Subsystem appears active, go ahead and shut it down */
  206. acpi_gbl_shutdown = TRUE;
  207. ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
  208. "Shutting down ACPI Subsystem...\n"));
  209. /* Close the acpi_event Handling */
  210. acpi_ev_terminate ();
  211. /* Close the Namespace */
  212. acpi_ns_terminate ();
  213. /* Close the globals */
  214. acpi_ut_terminate ();
  215. /* Purge the local caches */
  216. (void) acpi_purge_cached_objects ();
  217. /* Debug only - display leftover memory allocation, if any */
  218. #ifdef ACPI_DBG_TRACK_ALLOCATIONS
  219. acpi_ut_dump_allocations (ACPI_UINT32_MAX, NULL);
  220. #endif
  221. return_VOID;
  222. }