Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
| 3 | * Module Name: utinit - Common ACPI subsystem initialization |
| 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 | #include <acpi/acnamesp.h> |
| 46 | #include <acpi/acevents.h> |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame^] | 47 | #include <acpi/actables.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | |
| 49 | #define _COMPONENT ACPI_UTILITIES |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 50 | ACPI_MODULE_NAME("utinit") |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 52 | /* Local prototypes */ |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 53 | static void |
Bob Moore | 793c238 | 2006-03-31 00:00:00 -0500 | [diff] [blame] | 54 | acpi_ut_fadt_register_error(char *register_name, u32 value, u8 offset); |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 55 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 56 | static void acpi_ut_terminate(void); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | |
| 58 | /******************************************************************************* |
| 59 | * |
| 60 | * FUNCTION: acpi_ut_fadt_register_error |
| 61 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 62 | * PARAMETERS: register_name - Pointer to string identifying register |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | * Value - Actual register contents value |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 64 | * Offset - Byte offset in the FADT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | * |
| 66 | * RETURN: AE_BAD_VALUE |
| 67 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 68 | * DESCRIPTION: Display failure message |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | * |
| 70 | ******************************************************************************/ |
| 71 | |
| 72 | static void |
Bob Moore | 793c238 | 2006-03-31 00:00:00 -0500 | [diff] [blame] | 73 | acpi_ut_fadt_register_error(char *register_name, u32 value, u8 offset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | { |
| 75 | |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 76 | ACPI_WARNING((AE_INFO, |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame^] | 77 | "Invalid FADT value %s=%X at offset %X in FADT=%p", |
| 78 | register_name, value, offset, &acpi_gbl_FADT)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | } |
| 80 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | /****************************************************************************** |
| 82 | * |
| 83 | * FUNCTION: acpi_ut_validate_fadt |
| 84 | * |
| 85 | * PARAMETERS: None |
| 86 | * |
| 87 | * RETURN: Status |
| 88 | * |
| 89 | * DESCRIPTION: Validate various ACPI registers in the FADT |
| 90 | * |
| 91 | ******************************************************************************/ |
| 92 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 93 | acpi_status acpi_ut_validate_fadt(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | { |
| 95 | |
| 96 | /* |
| 97 | * Verify Fixed ACPI Description Table fields, |
| 98 | * but don't abort on any problems, just display error |
| 99 | */ |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame^] | 100 | if (acpi_gbl_FADT.pm1_event_length < 4) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 101 | acpi_ut_fadt_register_error("PM1_EVT_LEN", |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame^] | 102 | (u32) acpi_gbl_FADT. |
| 103 | pm1_event_length, |
| 104 | ACPI_FADT_OFFSET(pm1_event_length)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | } |
| 106 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame^] | 107 | if (!acpi_gbl_FADT.pm1_control_length) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 108 | acpi_ut_fadt_register_error("PM1_CNT_LEN", 0, |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame^] | 109 | ACPI_FADT_OFFSET |
| 110 | (pm1_control_length)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | } |
| 112 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame^] | 113 | if (!acpi_gbl_FADT.xpm1a_event_block.address) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 114 | acpi_ut_fadt_register_error("X_PM1a_EVT_BLK", 0, |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame^] | 115 | ACPI_FADT_OFFSET(xpm1a_event_block. |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 116 | address)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | } |
| 118 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame^] | 119 | if (!acpi_gbl_FADT.xpm1a_control_block.address) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 120 | acpi_ut_fadt_register_error("X_PM1a_CNT_BLK", 0, |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame^] | 121 | ACPI_FADT_OFFSET |
| 122 | (xpm1a_control_block.address)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | } |
| 124 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame^] | 125 | if (!acpi_gbl_FADT.xpm_timer_block.address) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 126 | acpi_ut_fadt_register_error("X_PM_TMR_BLK", 0, |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame^] | 127 | ACPI_FADT_OFFSET(xpm_timer_block. |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 128 | address)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | } |
| 130 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame^] | 131 | if ((acpi_gbl_FADT.xpm2_control_block.address && |
| 132 | !acpi_gbl_FADT.pm2_control_length)) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 133 | acpi_ut_fadt_register_error("PM2_CNT_LEN", |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame^] | 134 | (u32) acpi_gbl_FADT. |
| 135 | pm2_control_length, |
| 136 | ACPI_FADT_OFFSET |
| 137 | (pm2_control_length)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | } |
| 139 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame^] | 140 | if (acpi_gbl_FADT.pm_timer_length < 4) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 141 | acpi_ut_fadt_register_error("PM_TM_LEN", |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame^] | 142 | (u32) acpi_gbl_FADT.pm_timer_length, |
| 143 | ACPI_FADT_OFFSET(pm_timer_length)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | /* Length of GPE blocks must be a multiple of 2 */ |
| 147 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame^] | 148 | if (acpi_gbl_FADT.xgpe0_block.address && |
| 149 | (acpi_gbl_FADT.gpe0_block_length & 1)) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 150 | acpi_ut_fadt_register_error("(x)GPE0_BLK_LEN", |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame^] | 151 | (u32) acpi_gbl_FADT. |
| 152 | gpe0_block_length, |
| 153 | ACPI_FADT_OFFSET |
| 154 | (gpe0_block_length)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | } |
| 156 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame^] | 157 | if (acpi_gbl_FADT.xgpe1_block.address && |
| 158 | (acpi_gbl_FADT.gpe1_block_length & 1)) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 159 | acpi_ut_fadt_register_error("(x)GPE1_BLK_LEN", |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame^] | 160 | (u32) acpi_gbl_FADT. |
| 161 | gpe1_block_length, |
| 162 | ACPI_FADT_OFFSET |
| 163 | (gpe1_block_length)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | } |
| 165 | |
| 166 | return (AE_OK); |
| 167 | } |
| 168 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | /****************************************************************************** |
| 170 | * |
| 171 | * FUNCTION: acpi_ut_terminate |
| 172 | * |
| 173 | * PARAMETERS: none |
| 174 | * |
| 175 | * RETURN: none |
| 176 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 177 | * DESCRIPTION: Free global memory |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | * |
| 179 | ******************************************************************************/ |
| 180 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 181 | static void acpi_ut_terminate(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 183 | struct acpi_gpe_block_info *gpe_block; |
| 184 | struct acpi_gpe_block_info *next_gpe_block; |
| 185 | struct acpi_gpe_xrupt_info *gpe_xrupt_info; |
| 186 | struct acpi_gpe_xrupt_info *next_gpe_xrupt_info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 188 | ACPI_FUNCTION_TRACE(ut_terminate); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | /* Free global GPE blocks and related info structures */ |
| 191 | |
| 192 | gpe_xrupt_info = acpi_gbl_gpe_xrupt_list_head; |
| 193 | while (gpe_xrupt_info) { |
| 194 | gpe_block = gpe_xrupt_info->gpe_block_list_head; |
| 195 | while (gpe_block) { |
| 196 | next_gpe_block = gpe_block->next; |
Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 197 | ACPI_FREE(gpe_block->event_info); |
| 198 | ACPI_FREE(gpe_block->register_info); |
| 199 | ACPI_FREE(gpe_block); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | |
| 201 | gpe_block = next_gpe_block; |
| 202 | } |
| 203 | next_gpe_xrupt_info = gpe_xrupt_info->next; |
Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 204 | ACPI_FREE(gpe_xrupt_info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | gpe_xrupt_info = next_gpe_xrupt_info; |
| 206 | } |
| 207 | |
| 208 | return_VOID; |
| 209 | } |
| 210 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | /******************************************************************************* |
| 212 | * |
| 213 | * FUNCTION: acpi_ut_subsystem_shutdown |
| 214 | * |
| 215 | * PARAMETERS: none |
| 216 | * |
| 217 | * RETURN: none |
| 218 | * |
| 219 | * DESCRIPTION: Shutdown the various subsystems. Don't delete the mutex |
| 220 | * objects here -- because the AML debugger may be still running. |
| 221 | * |
| 222 | ******************************************************************************/ |
| 223 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 224 | void acpi_ut_subsystem_shutdown(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | { |
| 226 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 227 | ACPI_FUNCTION_TRACE(ut_subsystem_shutdown); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | |
| 229 | /* Just exit if subsystem is already shutdown */ |
| 230 | |
| 231 | if (acpi_gbl_shutdown) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 232 | ACPI_ERROR((AE_INFO, "ACPI Subsystem is already terminated")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | return_VOID; |
| 234 | } |
| 235 | |
| 236 | /* Subsystem appears active, go ahead and shut it down */ |
| 237 | |
| 238 | acpi_gbl_shutdown = TRUE; |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 239 | acpi_gbl_startup_flags = 0; |
Bob Moore | 4a90c7e | 2006-01-13 16:22:00 -0500 | [diff] [blame] | 240 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Shutting down ACPI Subsystem\n")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | |
| 242 | /* Close the acpi_event Handling */ |
| 243 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 244 | acpi_ev_terminate(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | |
| 246 | /* Close the Namespace */ |
| 247 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 248 | acpi_ns_terminate(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame^] | 250 | /* Delete the ACPI tables */ |
| 251 | |
| 252 | acpi_tb_terminate(); |
| 253 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | /* Close the globals */ |
| 255 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 256 | acpi_ut_terminate(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | |
| 258 | /* Purge the local caches */ |
| 259 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 260 | (void)acpi_ut_delete_caches(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | return_VOID; |
| 262 | } |