evgpeinit.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  1. /******************************************************************************
  2. *
  3. * Module Name: evgpeinit - System GPE initialization and update
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2015, 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. ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT,
  84. "Initializing General Purpose Events (GPEs):\n"));
  85. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  86. if (ACPI_FAILURE(status)) {
  87. return_ACPI_STATUS(status);
  88. }
  89. /*
  90. * Initialize the GPE Block(s) defined in the FADT
  91. *
  92. * Why the GPE register block lengths are divided by 2: From the ACPI
  93. * Spec, section "General-Purpose Event Registers", we have:
  94. *
  95. * "Each register block contains two registers of equal length
  96. * GPEx_STS and GPEx_EN (where x is 0 or 1). The length of the
  97. * GPE0_STS and GPE0_EN registers is equal to half the GPE0_LEN
  98. * The length of the GPE1_STS and GPE1_EN registers is equal to
  99. * half the GPE1_LEN. If a generic register block is not supported
  100. * then its respective block pointer and block length values in the
  101. * FADT table contain zeros. The GPE0_LEN and GPE1_LEN do not need
  102. * to be the same size."
  103. */
  104. /*
  105. * Determine the maximum GPE number for this machine.
  106. *
  107. * Note: both GPE0 and GPE1 are optional, and either can exist without
  108. * the other.
  109. *
  110. * If EITHER the register length OR the block address are zero, then that
  111. * particular block is not supported.
  112. */
  113. if (acpi_gbl_FADT.gpe0_block_length &&
  114. acpi_gbl_FADT.xgpe0_block.address) {
  115. /* GPE block 0 exists (has both length and address > 0) */
  116. register_count0 = (u16)(acpi_gbl_FADT.gpe0_block_length / 2);
  117. gpe_number_max =
  118. (register_count0 * ACPI_GPE_REGISTER_WIDTH) - 1;
  119. /* Install GPE Block 0 */
  120. status = acpi_ev_create_gpe_block(acpi_gbl_fadt_gpe_device,
  121. acpi_gbl_FADT.xgpe0_block.
  122. address,
  123. acpi_gbl_FADT.xgpe0_block.
  124. space_id, register_count0, 0,
  125. acpi_gbl_FADT.sci_interrupt,
  126. &acpi_gbl_gpe_fadt_blocks[0]);
  127. if (ACPI_FAILURE(status)) {
  128. ACPI_EXCEPTION((AE_INFO, status,
  129. "Could not create GPE Block 0"));
  130. }
  131. }
  132. if (acpi_gbl_FADT.gpe1_block_length &&
  133. acpi_gbl_FADT.xgpe1_block.address) {
  134. /* GPE block 1 exists (has both length and address > 0) */
  135. register_count1 = (u16)(acpi_gbl_FADT.gpe1_block_length / 2);
  136. /* Check for GPE0/GPE1 overlap (if both banks exist) */
  137. if ((register_count0) &&
  138. (gpe_number_max >= acpi_gbl_FADT.gpe1_base)) {
  139. ACPI_ERROR((AE_INFO,
  140. "GPE0 block (GPE 0 to %u) overlaps the GPE1 block "
  141. "(GPE %u to %u) - Ignoring GPE1",
  142. gpe_number_max, acpi_gbl_FADT.gpe1_base,
  143. acpi_gbl_FADT.gpe1_base +
  144. ((register_count1 *
  145. ACPI_GPE_REGISTER_WIDTH) - 1)));
  146. /* Ignore GPE1 block by setting the register count to zero */
  147. register_count1 = 0;
  148. } else {
  149. /* Install GPE Block 1 */
  150. status =
  151. acpi_ev_create_gpe_block(acpi_gbl_fadt_gpe_device,
  152. acpi_gbl_FADT.xgpe1_block.
  153. address,
  154. acpi_gbl_FADT.xgpe1_block.
  155. space_id, register_count1,
  156. acpi_gbl_FADT.gpe1_base,
  157. acpi_gbl_FADT.
  158. sci_interrupt,
  159. &acpi_gbl_gpe_fadt_blocks
  160. [1]);
  161. if (ACPI_FAILURE(status)) {
  162. ACPI_EXCEPTION((AE_INFO, status,
  163. "Could not create GPE Block 1"));
  164. }
  165. /*
  166. * GPE0 and GPE1 do not have to be contiguous in the GPE number
  167. * space. However, GPE0 always starts at GPE number zero.
  168. */
  169. gpe_number_max = acpi_gbl_FADT.gpe1_base +
  170. ((register_count1 * ACPI_GPE_REGISTER_WIDTH) - 1);
  171. }
  172. }
  173. /* Exit if there are no GPE registers */
  174. if ((register_count0 + register_count1) == 0) {
  175. /* GPEs are not required by ACPI, this is OK */
  176. ACPI_DEBUG_PRINT((ACPI_DB_INIT,
  177. "There are no GPE blocks defined in the FADT\n"));
  178. status = AE_OK;
  179. goto cleanup;
  180. }
  181. cleanup:
  182. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  183. return_ACPI_STATUS(AE_OK);
  184. }
  185. /*******************************************************************************
  186. *
  187. * FUNCTION: acpi_ev_update_gpes
  188. *
  189. * PARAMETERS: table_owner_id - ID of the newly-loaded ACPI table
  190. *
  191. * RETURN: None
  192. *
  193. * DESCRIPTION: Check for new GPE methods (_Lxx/_Exx) made available as a
  194. * result of a Load() or load_table() operation. If new GPE
  195. * methods have been installed, register the new methods.
  196. *
  197. ******************************************************************************/
  198. void acpi_ev_update_gpes(acpi_owner_id table_owner_id)
  199. {
  200. struct acpi_gpe_xrupt_info *gpe_xrupt_info;
  201. struct acpi_gpe_block_info *gpe_block;
  202. struct acpi_gpe_walk_info walk_info;
  203. acpi_status status = AE_OK;
  204. /*
  205. * Find any _Lxx/_Exx GPE methods that have just been loaded.
  206. *
  207. * Any GPEs that correspond to new _Lxx/_Exx methods are immediately
  208. * enabled.
  209. *
  210. * Examine the namespace underneath each gpe_device within the
  211. * gpe_block lists.
  212. */
  213. status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
  214. if (ACPI_FAILURE(status)) {
  215. return;
  216. }
  217. walk_info.count = 0;
  218. walk_info.owner_id = table_owner_id;
  219. walk_info.execute_by_owner_id = TRUE;
  220. /* Walk the interrupt level descriptor list */
  221. gpe_xrupt_info = acpi_gbl_gpe_xrupt_list_head;
  222. while (gpe_xrupt_info) {
  223. /* Walk all Gpe Blocks attached to this interrupt level */
  224. gpe_block = gpe_xrupt_info->gpe_block_list_head;
  225. while (gpe_block) {
  226. walk_info.gpe_block = gpe_block;
  227. walk_info.gpe_device = gpe_block->node;
  228. status = acpi_ns_walk_namespace(ACPI_TYPE_METHOD,
  229. walk_info.gpe_device,
  230. ACPI_UINT32_MAX,
  231. ACPI_NS_WALK_NO_UNLOCK,
  232. acpi_ev_match_gpe_method,
  233. NULL, &walk_info, NULL);
  234. if (ACPI_FAILURE(status)) {
  235. ACPI_EXCEPTION((AE_INFO, status,
  236. "While decoding _Lxx/_Exx methods"));
  237. }
  238. gpe_block = gpe_block->next;
  239. }
  240. gpe_xrupt_info = gpe_xrupt_info->next;
  241. }
  242. if (walk_info.count) {
  243. ACPI_INFO((AE_INFO, "Enabled %u new GPEs", walk_info.count));
  244. }
  245. (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
  246. return;
  247. }
  248. /*******************************************************************************
  249. *
  250. * FUNCTION: acpi_ev_match_gpe_method
  251. *
  252. * PARAMETERS: Callback from walk_namespace
  253. *
  254. * RETURN: Status
  255. *
  256. * DESCRIPTION: Called from acpi_walk_namespace. Expects each object to be a
  257. * control method under the _GPE portion of the namespace.
  258. * Extract the name and GPE type from the object, saving this
  259. * information for quick lookup during GPE dispatch. Allows a
  260. * per-owner_id evaluation if execute_by_owner_id is TRUE in the
  261. * walk_info parameter block.
  262. *
  263. * The name of each GPE control method is of the form:
  264. * "_Lxx" or "_Exx", where:
  265. * L - means that the GPE is level triggered
  266. * E - means that the GPE is edge triggered
  267. * xx - is the GPE number [in HEX]
  268. *
  269. * If walk_info->execute_by_owner_id is TRUE, we only execute examine GPE methods
  270. * with that owner.
  271. *
  272. ******************************************************************************/
  273. acpi_status
  274. acpi_ev_match_gpe_method(acpi_handle obj_handle,
  275. u32 level, void *context, void **return_value)
  276. {
  277. struct acpi_namespace_node *method_node =
  278. ACPI_CAST_PTR(struct acpi_namespace_node, obj_handle);
  279. struct acpi_gpe_walk_info *walk_info =
  280. ACPI_CAST_PTR(struct acpi_gpe_walk_info, context);
  281. struct acpi_gpe_event_info *gpe_event_info;
  282. u32 gpe_number;
  283. char name[ACPI_NAME_SIZE + 1];
  284. u8 type;
  285. ACPI_FUNCTION_TRACE(ev_match_gpe_method);
  286. /* Check if requested owner_id matches this owner_id */
  287. if ((walk_info->execute_by_owner_id) &&
  288. (method_node->owner_id != walk_info->owner_id)) {
  289. return_ACPI_STATUS(AE_OK);
  290. }
  291. /*
  292. * Match and decode the _Lxx and _Exx GPE method names
  293. *
  294. * 1) Extract the method name and null terminate it
  295. */
  296. ACPI_MOVE_32_TO_32(name, &method_node->name.integer);
  297. name[ACPI_NAME_SIZE] = 0;
  298. /* 2) Name must begin with an underscore */
  299. if (name[0] != '_') {
  300. return_ACPI_STATUS(AE_OK); /* Ignore this method */
  301. }
  302. /*
  303. * 3) Edge/Level determination is based on the 2nd character
  304. * of the method name
  305. */
  306. switch (name[1]) {
  307. case 'L':
  308. type = ACPI_GPE_LEVEL_TRIGGERED;
  309. break;
  310. case 'E':
  311. type = ACPI_GPE_EDGE_TRIGGERED;
  312. break;
  313. default:
  314. /* Unknown method type, just ignore it */
  315. ACPI_DEBUG_PRINT((ACPI_DB_LOAD,
  316. "Ignoring unknown GPE method type: %s "
  317. "(name not of form _Lxx or _Exx)", name));
  318. return_ACPI_STATUS(AE_OK);
  319. }
  320. /* 4) The last two characters of the name are the hex GPE Number */
  321. gpe_number = strtoul(&name[2], NULL, 16);
  322. if (gpe_number == ACPI_UINT32_MAX) {
  323. /* Conversion failed; invalid method, just ignore it */
  324. ACPI_DEBUG_PRINT((ACPI_DB_LOAD,
  325. "Could not extract GPE number from name: %s "
  326. "(name is not of form _Lxx or _Exx)", name));
  327. return_ACPI_STATUS(AE_OK);
  328. }
  329. /* Ensure that we have a valid GPE number for this GPE block */
  330. gpe_event_info =
  331. acpi_ev_low_get_gpe_info(gpe_number, walk_info->gpe_block);
  332. if (!gpe_event_info) {
  333. /*
  334. * This gpe_number is not valid for this GPE block, just ignore it.
  335. * However, it may be valid for a different GPE block, since GPE0
  336. * and GPE1 methods both appear under \_GPE.
  337. */
  338. return_ACPI_STATUS(AE_OK);
  339. }
  340. if ((ACPI_GPE_DISPATCH_TYPE(gpe_event_info->flags) ==
  341. ACPI_GPE_DISPATCH_HANDLER) ||
  342. (ACPI_GPE_DISPATCH_TYPE(gpe_event_info->flags) ==
  343. ACPI_GPE_DISPATCH_RAW_HANDLER)) {
  344. /* If there is already a handler, ignore this GPE method */
  345. return_ACPI_STATUS(AE_OK);
  346. }
  347. if (ACPI_GPE_DISPATCH_TYPE(gpe_event_info->flags) ==
  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 */