evgpeinit.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443
  1. /******************************************************************************
  2. *
  3. * Module Name: evgpeinit - System GPE initialization and update
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2011, Intel Corp.
  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 "accommon.h"
  44. #include "acevents.h"
  45. #include "acnamesp.h"
  46. #define _COMPONENT ACPI_EVENTS
  47. ACPI_MODULE_NAME("evgpeinit")
  48. /*
  49. * Note: History of _PRW support in ACPICA
  50. *
  51. * Originally (2000 - 2010), the GPE initialization code performed a walk of
  52. * the entire namespace to execute the _PRW methods and detect all GPEs
  53. * capable of waking the system.
  54. *
  55. * As of 10/2010, the _PRW method execution has been removed since it is
  56. * actually unnecessary. The host OS must in fact execute all _PRW methods
  57. * in order to identify the device/power-resource dependencies. We now put
  58. * the onus on the host OS to identify the wake GPEs as part of this process
  59. * and to inform ACPICA of these GPEs via the acpi_setup_gpe_for_wake interface. This
  60. * not only reduces the complexity of the ACPICA initialization code, but in
  61. * some cases (on systems with very large namespaces) it should reduce the
  62. * kernel boot time as well.
  63. */
  64. /*******************************************************************************
  65. *
  66. * FUNCTION: acpi_ev_gpe_initialize
  67. *
  68. * PARAMETERS: None
  69. *
  70. * RETURN: Status
  71. *
  72. * DESCRIPTION: Initialize the GPE data structures and the FADT GPE 0/1 blocks
  73. *
  74. ******************************************************************************/
  75. acpi_status acpi_ev_gpe_initialize(void)
  76. {
  77. u32 register_count0 = 0;
  78. u32 register_count1 = 0;
  79. u32 gpe_number_max = 0;
  80. acpi_status status;
  81. ACPI_FUNCTION_TRACE(ev_gpe_initialize);
  82. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  83. if (ACPI_FAILURE(status)) {
  84. return_ACPI_STATUS(status);
  85. }
  86. /*
  87. * Initialize the GPE Block(s) defined in the FADT
  88. *
  89. * Why the GPE register block lengths are divided by 2: From the ACPI
  90. * Spec, section "General-Purpose Event Registers", we have:
  91. *
  92. * "Each register block contains two registers of equal length
  93. * GPEx_STS and GPEx_EN (where x is 0 or 1). The length of the
  94. * GPE0_STS and GPE0_EN registers is equal to half the GPE0_LEN
  95. * The length of the GPE1_STS and GPE1_EN registers is equal to
  96. * half the GPE1_LEN. If a generic register block is not supported
  97. * then its respective block pointer and block length values in the
  98. * FADT table contain zeros. The GPE0_LEN and GPE1_LEN do not need
  99. * to be the same size."
  100. */
  101. /*
  102. * Determine the maximum GPE number for this machine.
  103. *
  104. * Note: both GPE0 and GPE1 are optional, and either can exist without
  105. * the other.
  106. *
  107. * If EITHER the register length OR the block address are zero, then that
  108. * particular block is not supported.
  109. */
  110. if (acpi_gbl_FADT.gpe0_block_length &&
  111. acpi_gbl_FADT.xgpe0_block.address) {
  112. /* GPE block 0 exists (has both length and address > 0) */
  113. register_count0 = (u16)(acpi_gbl_FADT.gpe0_block_length / 2);
  114. gpe_number_max =
  115. (register_count0 * ACPI_GPE_REGISTER_WIDTH) - 1;
  116. /* Install GPE Block 0 */
  117. status = acpi_ev_create_gpe_block(acpi_gbl_fadt_gpe_device,
  118. &acpi_gbl_FADT.xgpe0_block,
  119. register_count0, 0,
  120. acpi_gbl_FADT.sci_interrupt,
  121. &acpi_gbl_gpe_fadt_blocks[0]);
  122. if (ACPI_FAILURE(status)) {
  123. ACPI_EXCEPTION((AE_INFO, status,
  124. "Could not create GPE Block 0"));
  125. }
  126. }
  127. if (acpi_gbl_FADT.gpe1_block_length &&
  128. acpi_gbl_FADT.xgpe1_block.address) {
  129. /* GPE block 1 exists (has both length and address > 0) */
  130. register_count1 = (u16)(acpi_gbl_FADT.gpe1_block_length / 2);
  131. /* Check for GPE0/GPE1 overlap (if both banks exist) */
  132. if ((register_count0) &&
  133. (gpe_number_max >= acpi_gbl_FADT.gpe1_base)) {
  134. ACPI_ERROR((AE_INFO,
  135. "GPE0 block (GPE 0 to %u) overlaps the GPE1 block "
  136. "(GPE %u to %u) - Ignoring GPE1",
  137. gpe_number_max, acpi_gbl_FADT.gpe1_base,
  138. acpi_gbl_FADT.gpe1_base +
  139. ((register_count1 *
  140. ACPI_GPE_REGISTER_WIDTH) - 1)));
  141. /* Ignore GPE1 block by setting the register count to zero */
  142. register_count1 = 0;
  143. } else {
  144. /* Install GPE Block 1 */
  145. status =
  146. acpi_ev_create_gpe_block(acpi_gbl_fadt_gpe_device,
  147. &acpi_gbl_FADT.xgpe1_block,
  148. register_count1,
  149. acpi_gbl_FADT.gpe1_base,
  150. acpi_gbl_FADT.
  151. sci_interrupt,
  152. &acpi_gbl_gpe_fadt_blocks
  153. [1]);
  154. if (ACPI_FAILURE(status)) {
  155. ACPI_EXCEPTION((AE_INFO, status,
  156. "Could not create GPE Block 1"));
  157. }
  158. /*
  159. * GPE0 and GPE1 do not have to be contiguous in the GPE number
  160. * space. However, GPE0 always starts at GPE number zero.
  161. */
  162. gpe_number_max = acpi_gbl_FADT.gpe1_base +
  163. ((register_count1 * ACPI_GPE_REGISTER_WIDTH) - 1);
  164. }
  165. }
  166. /* Exit if there are no GPE registers */
  167. if ((register_count0 + register_count1) == 0) {
  168. /* GPEs are not required by ACPI, this is OK */
  169. ACPI_DEBUG_PRINT((ACPI_DB_INIT,
  170. "There are no GPE blocks defined in the FADT\n"));
  171. status = AE_OK;
  172. goto cleanup;
  173. }
  174. /* Check for Max GPE number out-of-range */
  175. if (gpe_number_max > ACPI_GPE_MAX) {
  176. ACPI_ERROR((AE_INFO,
  177. "Maximum GPE number from FADT is too large: 0x%X",
  178. gpe_number_max));
  179. status = AE_BAD_VALUE;
  180. goto cleanup;
  181. }
  182. cleanup:
  183. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  184. return_ACPI_STATUS(AE_OK);
  185. }
  186. /*******************************************************************************
  187. *
  188. * FUNCTION: acpi_ev_update_gpes
  189. *
  190. * PARAMETERS: table_owner_id - ID of the newly-loaded ACPI table
  191. *
  192. * RETURN: None
  193. *
  194. * DESCRIPTION: Check for new GPE methods (_Lxx/_Exx) made available as a
  195. * result of a Load() or load_table() operation. If new GPE
  196. * methods have been installed, register the new methods.
  197. *
  198. ******************************************************************************/
  199. void acpi_ev_update_gpes(acpi_owner_id table_owner_id)
  200. {
  201. struct acpi_gpe_xrupt_info *gpe_xrupt_info;
  202. struct acpi_gpe_block_info *gpe_block;
  203. struct acpi_gpe_walk_info walk_info;
  204. acpi_status status = AE_OK;
  205. /*
  206. * Find any _Lxx/_Exx GPE methods that have just been loaded.
  207. *
  208. * Any GPEs that correspond to new _Lxx/_Exx methods are immediately
  209. * enabled.
  210. *
  211. * Examine the namespace underneath each gpe_device within the
  212. * gpe_block lists.
  213. */
  214. status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
  215. if (ACPI_FAILURE(status)) {
  216. return;
  217. }
  218. walk_info.count = 0;
  219. walk_info.owner_id = table_owner_id;
  220. walk_info.execute_by_owner_id = TRUE;
  221. /* Walk the interrupt level descriptor list */
  222. gpe_xrupt_info = acpi_gbl_gpe_xrupt_list_head;
  223. while (gpe_xrupt_info) {
  224. /* Walk all Gpe Blocks attached to this interrupt level */
  225. gpe_block = gpe_xrupt_info->gpe_block_list_head;
  226. while (gpe_block) {
  227. walk_info.gpe_block = gpe_block;
  228. walk_info.gpe_device = gpe_block->node;
  229. status = acpi_ns_walk_namespace(ACPI_TYPE_METHOD,
  230. walk_info.gpe_device,
  231. ACPI_UINT32_MAX,
  232. ACPI_NS_WALK_NO_UNLOCK,
  233. acpi_ev_match_gpe_method,
  234. NULL, &walk_info, NULL);
  235. if (ACPI_FAILURE(status)) {
  236. ACPI_EXCEPTION((AE_INFO, status,
  237. "While decoding _Lxx/_Exx methods"));
  238. }
  239. gpe_block = gpe_block->next;
  240. }
  241. gpe_xrupt_info = gpe_xrupt_info->next;
  242. }
  243. if (walk_info.count) {
  244. ACPI_INFO((AE_INFO, "Enabled %u new GPEs", walk_info.count));
  245. }
  246. (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
  247. return;
  248. }
  249. /*******************************************************************************
  250. *
  251. * FUNCTION: acpi_ev_match_gpe_method
  252. *
  253. * PARAMETERS: Callback from walk_namespace
  254. *
  255. * RETURN: Status
  256. *
  257. * DESCRIPTION: Called from acpi_walk_namespace. Expects each object to be a
  258. * control method under the _GPE portion of the namespace.
  259. * Extract the name and GPE type from the object, saving this
  260. * information for quick lookup during GPE dispatch. Allows a
  261. * per-owner_id evaluation if execute_by_owner_id is TRUE in the
  262. * walk_info parameter block.
  263. *
  264. * The name of each GPE control method is of the form:
  265. * "_Lxx" or "_Exx", where:
  266. * L - means that the GPE is level triggered
  267. * E - means that the GPE is edge triggered
  268. * xx - is the GPE number [in HEX]
  269. *
  270. * If walk_info->execute_by_owner_id is TRUE, we only execute examine GPE methods
  271. * with that owner.
  272. *
  273. ******************************************************************************/
  274. acpi_status
  275. acpi_ev_match_gpe_method(acpi_handle obj_handle,
  276. u32 level, void *context, void **return_value)
  277. {
  278. struct acpi_namespace_node *method_node =
  279. ACPI_CAST_PTR(struct acpi_namespace_node, obj_handle);
  280. struct acpi_gpe_walk_info *walk_info =
  281. ACPI_CAST_PTR(struct acpi_gpe_walk_info, context);
  282. struct acpi_gpe_event_info *gpe_event_info;
  283. u32 gpe_number;
  284. char name[ACPI_NAME_SIZE + 1];
  285. u8 type;
  286. ACPI_FUNCTION_TRACE(ev_match_gpe_method);
  287. /* Check if requested owner_id matches this owner_id */
  288. if ((walk_info->execute_by_owner_id) &&
  289. (method_node->owner_id != walk_info->owner_id)) {
  290. return_ACPI_STATUS(AE_OK);
  291. }
  292. /*
  293. * Match and decode the _Lxx and _Exx GPE method names
  294. *
  295. * 1) Extract the method name and null terminate it
  296. */
  297. ACPI_MOVE_32_TO_32(name, &method_node->name.integer);
  298. name[ACPI_NAME_SIZE] = 0;
  299. /* 2) Name must begin with an underscore */
  300. if (name[0] != '_') {
  301. return_ACPI_STATUS(AE_OK); /* Ignore this method */
  302. }
  303. /*
  304. * 3) Edge/Level determination is based on the 2nd character
  305. * of the method name
  306. */
  307. switch (name[1]) {
  308. case 'L':
  309. type = ACPI_GPE_LEVEL_TRIGGERED;
  310. break;
  311. case 'E':
  312. type = ACPI_GPE_EDGE_TRIGGERED;
  313. break;
  314. default:
  315. /* Unknown method type, just ignore it */
  316. ACPI_DEBUG_PRINT((ACPI_DB_LOAD,
  317. "Ignoring unknown GPE method type: %s "
  318. "(name not of form _Lxx or _Exx)", name));
  319. return_ACPI_STATUS(AE_OK);
  320. }
  321. /* 4) The last two characters of the name are the hex GPE Number */
  322. gpe_number = ACPI_STRTOUL(&name[2], NULL, 16);
  323. if (gpe_number == ACPI_UINT32_MAX) {
  324. /* Conversion failed; invalid method, just ignore it */
  325. ACPI_DEBUG_PRINT((ACPI_DB_LOAD,
  326. "Could not extract GPE number from name: %s "
  327. "(name is not of form _Lxx or _Exx)", name));
  328. return_ACPI_STATUS(AE_OK);
  329. }
  330. /* Ensure that we have a valid GPE number for this GPE block */
  331. gpe_event_info =
  332. acpi_ev_low_get_gpe_info(gpe_number, walk_info->gpe_block);
  333. if (!gpe_event_info) {
  334. /*
  335. * This gpe_number is not valid for this GPE block, just ignore it.
  336. * However, it may be valid for a different GPE block, since GPE0
  337. * and GPE1 methods both appear under \_GPE.
  338. */
  339. return_ACPI_STATUS(AE_OK);
  340. }
  341. if ((gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) ==
  342. ACPI_GPE_DISPATCH_HANDLER) {
  343. /* If there is already a handler, ignore this GPE method */
  344. return_ACPI_STATUS(AE_OK);
  345. }
  346. if ((gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) ==
  347. ACPI_GPE_DISPATCH_METHOD) {
  348. /*
  349. * If there is already a method, ignore this method. But check
  350. * for a type mismatch (if both the _Lxx AND _Exx exist)
  351. */
  352. if (type != (gpe_event_info->flags & ACPI_GPE_XRUPT_TYPE_MASK)) {
  353. ACPI_ERROR((AE_INFO,
  354. "For GPE 0x%.2X, found both _L%2.2X and _E%2.2X methods",
  355. gpe_number, gpe_number, gpe_number));
  356. }
  357. return_ACPI_STATUS(AE_OK);
  358. }
  359. /* Disable the GPE in case it's been enabled already. */
  360. (void)acpi_hw_low_set_gpe(gpe_event_info, ACPI_GPE_DISABLE);
  361. /*
  362. * Add the GPE information from above to the gpe_event_info block for
  363. * use during dispatch of this GPE.
  364. */
  365. gpe_event_info->flags &= ~(ACPI_GPE_DISPATCH_MASK);
  366. gpe_event_info->flags |= (u8)(type | ACPI_GPE_DISPATCH_METHOD);
  367. gpe_event_info->dispatch.method_node = method_node;
  368. ACPI_DEBUG_PRINT((ACPI_DB_LOAD,
  369. "Registered GPE method %s as GPE number 0x%.2X\n",
  370. name, gpe_number));
  371. return_ACPI_STATUS(AE_OK);
  372. }