evgpeinit.c 14 KB

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