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