utinit.c 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  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. #include <acpi/actables.h>
  46. #define _COMPONENT ACPI_UTILITIES
  47. ACPI_MODULE_NAME("utinit")
  48. /* Local prototypes */
  49. static void
  50. acpi_ut_fadt_register_error(char *register_name, u32 value, u8 offset);
  51. static void acpi_ut_terminate(void);
  52. /*******************************************************************************
  53. *
  54. * FUNCTION: acpi_ut_fadt_register_error
  55. *
  56. * PARAMETERS: register_name - Pointer to string identifying register
  57. * Value - Actual register contents value
  58. * Offset - Byte offset in the FADT
  59. *
  60. * RETURN: AE_BAD_VALUE
  61. *
  62. * DESCRIPTION: Display failure message
  63. *
  64. ******************************************************************************/
  65. static void
  66. acpi_ut_fadt_register_error(char *register_name, u32 value, u8 offset)
  67. {
  68. ACPI_WARNING((AE_INFO,
  69. "Invalid FADT value %s=%X at offset %X in FADT=%p",
  70. register_name, value, offset, &acpi_gbl_FADT));
  71. }
  72. /******************************************************************************
  73. *
  74. * FUNCTION: acpi_ut_validate_fadt
  75. *
  76. * PARAMETERS: None
  77. *
  78. * RETURN: Status
  79. *
  80. * DESCRIPTION: Validate various ACPI registers in the FADT
  81. *
  82. ******************************************************************************/
  83. acpi_status acpi_ut_validate_fadt(void)
  84. {
  85. /*
  86. * Verify Fixed ACPI Description Table fields,
  87. * but don't abort on any problems, just display error
  88. */
  89. if (acpi_gbl_FADT.pm1_event_length < 4) {
  90. acpi_ut_fadt_register_error("PM1_EVT_LEN",
  91. (u32) acpi_gbl_FADT.
  92. pm1_event_length,
  93. ACPI_FADT_OFFSET(pm1_event_length));
  94. }
  95. if (!acpi_gbl_FADT.pm1_control_length) {
  96. acpi_ut_fadt_register_error("PM1_CNT_LEN", 0,
  97. ACPI_FADT_OFFSET
  98. (pm1_control_length));
  99. }
  100. if (!acpi_gbl_FADT.xpm1a_event_block.address) {
  101. acpi_ut_fadt_register_error("X_PM1a_EVT_BLK", 0,
  102. ACPI_FADT_OFFSET(xpm1a_event_block.
  103. address));
  104. }
  105. if (!acpi_gbl_FADT.xpm1a_control_block.address) {
  106. acpi_ut_fadt_register_error("X_PM1a_CNT_BLK", 0,
  107. ACPI_FADT_OFFSET
  108. (xpm1a_control_block.address));
  109. }
  110. if (!acpi_gbl_FADT.xpm_timer_block.address) {
  111. acpi_ut_fadt_register_error("X_PM_TMR_BLK", 0,
  112. ACPI_FADT_OFFSET(xpm_timer_block.
  113. address));
  114. }
  115. if ((acpi_gbl_FADT.xpm2_control_block.address &&
  116. !acpi_gbl_FADT.pm2_control_length)) {
  117. acpi_ut_fadt_register_error("PM2_CNT_LEN",
  118. (u32) acpi_gbl_FADT.
  119. pm2_control_length,
  120. ACPI_FADT_OFFSET
  121. (pm2_control_length));
  122. }
  123. if (acpi_gbl_FADT.pm_timer_length < 4) {
  124. acpi_ut_fadt_register_error("PM_TM_LEN",
  125. (u32) acpi_gbl_FADT.pm_timer_length,
  126. ACPI_FADT_OFFSET(pm_timer_length));
  127. }
  128. /* Length of GPE blocks must be a multiple of 2 */
  129. if (acpi_gbl_FADT.xgpe0_block.address &&
  130. (acpi_gbl_FADT.gpe0_block_length & 1)) {
  131. acpi_ut_fadt_register_error("(x)GPE0_BLK_LEN",
  132. (u32) acpi_gbl_FADT.
  133. gpe0_block_length,
  134. ACPI_FADT_OFFSET
  135. (gpe0_block_length));
  136. }
  137. if (acpi_gbl_FADT.xgpe1_block.address &&
  138. (acpi_gbl_FADT.gpe1_block_length & 1)) {
  139. acpi_ut_fadt_register_error("(x)GPE1_BLK_LEN",
  140. (u32) acpi_gbl_FADT.
  141. gpe1_block_length,
  142. ACPI_FADT_OFFSET
  143. (gpe1_block_length));
  144. }
  145. return (AE_OK);
  146. }
  147. /******************************************************************************
  148. *
  149. * FUNCTION: acpi_ut_terminate
  150. *
  151. * PARAMETERS: none
  152. *
  153. * RETURN: none
  154. *
  155. * DESCRIPTION: Free global memory
  156. *
  157. ******************************************************************************/
  158. static void acpi_ut_terminate(void)
  159. {
  160. struct acpi_gpe_block_info *gpe_block;
  161. struct acpi_gpe_block_info *next_gpe_block;
  162. struct acpi_gpe_xrupt_info *gpe_xrupt_info;
  163. struct acpi_gpe_xrupt_info *next_gpe_xrupt_info;
  164. ACPI_FUNCTION_TRACE(ut_terminate);
  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_FREE(gpe_block->event_info);
  172. ACPI_FREE(gpe_block->register_info);
  173. ACPI_FREE(gpe_block);
  174. gpe_block = next_gpe_block;
  175. }
  176. next_gpe_xrupt_info = gpe_xrupt_info->next;
  177. ACPI_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 acpi_ut_subsystem_shutdown(void)
  195. {
  196. ACPI_FUNCTION_TRACE(ut_subsystem_shutdown);
  197. /* Just exit if subsystem is already shutdown */
  198. if (acpi_gbl_shutdown) {
  199. ACPI_ERROR((AE_INFO, "ACPI Subsystem is already terminated"));
  200. return_VOID;
  201. }
  202. /* Subsystem appears active, go ahead and shut it down */
  203. acpi_gbl_shutdown = TRUE;
  204. acpi_gbl_startup_flags = 0;
  205. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Shutting down ACPI Subsystem\n"));
  206. /* Close the acpi_event Handling */
  207. acpi_ev_terminate();
  208. /* Close the Namespace */
  209. acpi_ns_terminate();
  210. /* Delete the ACPI tables */
  211. acpi_tb_terminate();
  212. /* Close the globals */
  213. acpi_ut_terminate();
  214. /* Purge the local caches */
  215. (void)acpi_ut_delete_caches();
  216. return_VOID;
  217. }