utinit.c 7.5 KB

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