evgpeinit.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653
  1. /******************************************************************************
  2. *
  3. * Module Name: evgpeinit - System GPE initialization and update
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2010, 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. #include "acinterp.h"
  47. #define _COMPONENT ACPI_EVENTS
  48. ACPI_MODULE_NAME("evgpeinit")
  49. /*******************************************************************************
  50. *
  51. * FUNCTION: acpi_ev_gpe_initialize
  52. *
  53. * PARAMETERS: None
  54. *
  55. * RETURN: Status
  56. *
  57. * DESCRIPTION: Initialize the GPE data structures and the FADT GPE 0/1 blocks
  58. *
  59. ******************************************************************************/
  60. acpi_status acpi_ev_gpe_initialize(void)
  61. {
  62. u32 register_count0 = 0;
  63. u32 register_count1 = 0;
  64. u32 gpe_number_max = 0;
  65. acpi_status status;
  66. ACPI_FUNCTION_TRACE(ev_gpe_initialize);
  67. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  68. if (ACPI_FAILURE(status)) {
  69. return_ACPI_STATUS(status);
  70. }
  71. /*
  72. * Initialize the GPE Block(s) defined in the FADT
  73. *
  74. * Why the GPE register block lengths are divided by 2: From the ACPI
  75. * Spec, section "General-Purpose Event Registers", we have:
  76. *
  77. * "Each register block contains two registers of equal length
  78. * GPEx_STS and GPEx_EN (where x is 0 or 1). The length of the
  79. * GPE0_STS and GPE0_EN registers is equal to half the GPE0_LEN
  80. * The length of the GPE1_STS and GPE1_EN registers is equal to
  81. * half the GPE1_LEN. If a generic register block is not supported
  82. * then its respective block pointer and block length values in the
  83. * FADT table contain zeros. The GPE0_LEN and GPE1_LEN do not need
  84. * to be the same size."
  85. */
  86. /*
  87. * Determine the maximum GPE number for this machine.
  88. *
  89. * Note: both GPE0 and GPE1 are optional, and either can exist without
  90. * the other.
  91. *
  92. * If EITHER the register length OR the block address are zero, then that
  93. * particular block is not supported.
  94. */
  95. if (acpi_gbl_FADT.gpe0_block_length &&
  96. acpi_gbl_FADT.xgpe0_block.address) {
  97. /* GPE block 0 exists (has both length and address > 0) */
  98. register_count0 = (u16)(acpi_gbl_FADT.gpe0_block_length / 2);
  99. gpe_number_max =
  100. (register_count0 * ACPI_GPE_REGISTER_WIDTH) - 1;
  101. /* Install GPE Block 0 */
  102. status = acpi_ev_create_gpe_block(acpi_gbl_fadt_gpe_device,
  103. &acpi_gbl_FADT.xgpe0_block,
  104. register_count0, 0,
  105. acpi_gbl_FADT.sci_interrupt,
  106. &acpi_gbl_gpe_fadt_blocks[0]);
  107. if (ACPI_FAILURE(status)) {
  108. ACPI_EXCEPTION((AE_INFO, status,
  109. "Could not create GPE Block 0"));
  110. }
  111. }
  112. if (acpi_gbl_FADT.gpe1_block_length &&
  113. acpi_gbl_FADT.xgpe1_block.address) {
  114. /* GPE block 1 exists (has both length and address > 0) */
  115. register_count1 = (u16)(acpi_gbl_FADT.gpe1_block_length / 2);
  116. /* Check for GPE0/GPE1 overlap (if both banks exist) */
  117. if ((register_count0) &&
  118. (gpe_number_max >= acpi_gbl_FADT.gpe1_base)) {
  119. ACPI_ERROR((AE_INFO,
  120. "GPE0 block (GPE 0 to %u) overlaps the GPE1 block "
  121. "(GPE %u to %u) - Ignoring GPE1",
  122. gpe_number_max, acpi_gbl_FADT.gpe1_base,
  123. acpi_gbl_FADT.gpe1_base +
  124. ((register_count1 *
  125. ACPI_GPE_REGISTER_WIDTH) - 1)));
  126. /* Ignore GPE1 block by setting the register count to zero */
  127. register_count1 = 0;
  128. } else {
  129. /* Install GPE Block 1 */
  130. status =
  131. acpi_ev_create_gpe_block(acpi_gbl_fadt_gpe_device,
  132. &acpi_gbl_FADT.xgpe1_block,
  133. register_count1,
  134. acpi_gbl_FADT.gpe1_base,
  135. acpi_gbl_FADT.
  136. sci_interrupt,
  137. &acpi_gbl_gpe_fadt_blocks
  138. [1]);
  139. if (ACPI_FAILURE(status)) {
  140. ACPI_EXCEPTION((AE_INFO, status,
  141. "Could not create GPE Block 1"));
  142. }
  143. /*
  144. * GPE0 and GPE1 do not have to be contiguous in the GPE number
  145. * space. However, GPE0 always starts at GPE number zero.
  146. */
  147. gpe_number_max = acpi_gbl_FADT.gpe1_base +
  148. ((register_count1 * ACPI_GPE_REGISTER_WIDTH) - 1);
  149. }
  150. }
  151. /* Exit if there are no GPE registers */
  152. if ((register_count0 + register_count1) == 0) {
  153. /* GPEs are not required by ACPI, this is OK */
  154. ACPI_DEBUG_PRINT((ACPI_DB_INIT,
  155. "There are no GPE blocks defined in the FADT\n"));
  156. status = AE_OK;
  157. goto cleanup;
  158. }
  159. /* Check for Max GPE number out-of-range */
  160. if (gpe_number_max > ACPI_GPE_MAX) {
  161. ACPI_ERROR((AE_INFO,
  162. "Maximum GPE number from FADT is too large: 0x%X",
  163. gpe_number_max));
  164. status = AE_BAD_VALUE;
  165. goto cleanup;
  166. }
  167. cleanup:
  168. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  169. return_ACPI_STATUS(AE_OK);
  170. }
  171. /*******************************************************************************
  172. *
  173. * FUNCTION: acpi_ev_update_gpes
  174. *
  175. * PARAMETERS: table_owner_id - ID of the newly-loaded ACPI table
  176. *
  177. * RETURN: None
  178. *
  179. * DESCRIPTION: Check for new GPE methods (_Lxx/_Exx) made available as a
  180. * result of a Load() or load_table() operation. If new GPE
  181. * methods have been installed, register the new methods and
  182. * enable and runtime GPEs that are associated with them. Also,
  183. * run any newly loaded _PRW methods in order to discover any
  184. * new CAN_WAKE GPEs.
  185. *
  186. ******************************************************************************/
  187. void acpi_ev_update_gpes(acpi_owner_id table_owner_id)
  188. {
  189. struct acpi_gpe_xrupt_info *gpe_xrupt_info;
  190. struct acpi_gpe_block_info *gpe_block;
  191. struct acpi_gpe_walk_info walk_info;
  192. acpi_status status = AE_OK;
  193. u32 new_wake_gpe_count = 0;
  194. /* We will examine only _PRW/_Lxx/_Exx methods owned by this table */
  195. walk_info.owner_id = table_owner_id;
  196. walk_info.execute_by_owner_id = TRUE;
  197. walk_info.count = 0;
  198. if (acpi_gbl_leave_wake_gpes_disabled) {
  199. /*
  200. * 1) Run any newly-loaded _PRW methods to find any GPEs that
  201. * can now be marked as CAN_WAKE GPEs. Note: We must run the
  202. * _PRW methods before we process the _Lxx/_Exx methods because
  203. * we will enable all runtime GPEs associated with the new
  204. * _Lxx/_Exx methods at the time we process those methods.
  205. *
  206. * Unlock interpreter so that we can run the _PRW methods.
  207. */
  208. walk_info.gpe_block = NULL;
  209. walk_info.gpe_device = NULL;
  210. acpi_ex_exit_interpreter();
  211. status =
  212. acpi_ns_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
  213. ACPI_UINT32_MAX,
  214. ACPI_NS_WALK_NO_UNLOCK,
  215. acpi_ev_match_prw_and_gpe, NULL,
  216. &walk_info, NULL);
  217. if (ACPI_FAILURE(status)) {
  218. ACPI_EXCEPTION((AE_INFO, status,
  219. "While executing _PRW methods"));
  220. }
  221. acpi_ex_enter_interpreter();
  222. new_wake_gpe_count = walk_info.count;
  223. }
  224. /*
  225. * 2) Find any _Lxx/_Exx GPE methods that have just been loaded.
  226. *
  227. * Any GPEs that correspond to new _Lxx/_Exx methods and are not
  228. * marked as CAN_WAKE are immediately enabled.
  229. *
  230. * Examine the namespace underneath each gpe_device within the
  231. * gpe_block lists.
  232. */
  233. status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
  234. if (ACPI_FAILURE(status)) {
  235. return;
  236. }
  237. walk_info.count = 0;
  238. walk_info.enable_this_gpe = TRUE;
  239. /* Walk the interrupt level descriptor list */
  240. gpe_xrupt_info = acpi_gbl_gpe_xrupt_list_head;
  241. while (gpe_xrupt_info) {
  242. /* Walk all Gpe Blocks attached to this interrupt level */
  243. gpe_block = gpe_xrupt_info->gpe_block_list_head;
  244. while (gpe_block) {
  245. walk_info.gpe_block = gpe_block;
  246. walk_info.gpe_device = gpe_block->node;
  247. status = acpi_ns_walk_namespace(ACPI_TYPE_METHOD,
  248. walk_info.gpe_device,
  249. ACPI_UINT32_MAX,
  250. ACPI_NS_WALK_NO_UNLOCK,
  251. acpi_ev_match_gpe_method,
  252. NULL, &walk_info, NULL);
  253. if (ACPI_FAILURE(status)) {
  254. ACPI_EXCEPTION((AE_INFO, status,
  255. "While decoding _Lxx/_Exx methods"));
  256. }
  257. gpe_block = gpe_block->next;
  258. }
  259. gpe_xrupt_info = gpe_xrupt_info->next;
  260. }
  261. if (walk_info.count || new_wake_gpe_count) {
  262. ACPI_INFO((AE_INFO,
  263. "Enabled %u new runtime GPEs, added %u new wakeup GPEs",
  264. walk_info.count, new_wake_gpe_count));
  265. }
  266. (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
  267. return;
  268. }
  269. /*******************************************************************************
  270. *
  271. * FUNCTION: acpi_ev_match_gpe_method
  272. *
  273. * PARAMETERS: Callback from walk_namespace
  274. *
  275. * RETURN: Status
  276. *
  277. * DESCRIPTION: Called from acpi_walk_namespace. Expects each object to be a
  278. * control method under the _GPE portion of the namespace.
  279. * Extract the name and GPE type from the object, saving this
  280. * information for quick lookup during GPE dispatch. Allows a
  281. * per-owner_id evaluation if execute_by_owner_id is TRUE in the
  282. * walk_info parameter block.
  283. *
  284. * The name of each GPE control method is of the form:
  285. * "_Lxx" or "_Exx", where:
  286. * L - means that the GPE is level triggered
  287. * E - means that the GPE is edge triggered
  288. * xx - is the GPE number [in HEX]
  289. *
  290. * If walk_info->execute_by_owner_id is TRUE, we only execute examine GPE methods
  291. * with that owner.
  292. * If walk_info->enable_this_gpe is TRUE, the GPE that is referred to by a GPE
  293. * method is immediately enabled (Used for Load/load_table operators)
  294. *
  295. ******************************************************************************/
  296. acpi_status
  297. acpi_ev_match_gpe_method(acpi_handle obj_handle,
  298. u32 level, void *context, void **return_value)
  299. {
  300. struct acpi_namespace_node *method_node =
  301. ACPI_CAST_PTR(struct acpi_namespace_node, obj_handle);
  302. struct acpi_gpe_walk_info *walk_info =
  303. ACPI_CAST_PTR(struct acpi_gpe_walk_info, context);
  304. struct acpi_gpe_event_info *gpe_event_info;
  305. struct acpi_namespace_node *gpe_device;
  306. acpi_status status;
  307. u32 gpe_number;
  308. char name[ACPI_NAME_SIZE + 1];
  309. u8 type;
  310. ACPI_FUNCTION_TRACE(ev_match_gpe_method);
  311. /* Check if requested owner_id matches this owner_id */
  312. if ((walk_info->execute_by_owner_id) &&
  313. (method_node->owner_id != walk_info->owner_id)) {
  314. return_ACPI_STATUS(AE_OK);
  315. }
  316. /*
  317. * Match and decode the _Lxx and _Exx GPE method names
  318. *
  319. * 1) Extract the method name and null terminate it
  320. */
  321. ACPI_MOVE_32_TO_32(name, &method_node->name.integer);
  322. name[ACPI_NAME_SIZE] = 0;
  323. /* 2) Name must begin with an underscore */
  324. if (name[0] != '_') {
  325. return_ACPI_STATUS(AE_OK); /* Ignore this method */
  326. }
  327. /*
  328. * 3) Edge/Level determination is based on the 2nd character
  329. * of the method name
  330. *
  331. * NOTE: Default GPE type is RUNTIME only. Later, if a _PRW object is
  332. * found that points to this GPE, the ACPI_GPE_CAN_WAKE flag is set.
  333. */
  334. switch (name[1]) {
  335. case 'L':
  336. type = ACPI_GPE_LEVEL_TRIGGERED;
  337. break;
  338. case 'E':
  339. type = ACPI_GPE_EDGE_TRIGGERED;
  340. break;
  341. default:
  342. /* Unknown method type, just ignore it */
  343. ACPI_DEBUG_PRINT((ACPI_DB_LOAD,
  344. "Ignoring unknown GPE method type: %s "
  345. "(name not of form _Lxx or _Exx)", name));
  346. return_ACPI_STATUS(AE_OK);
  347. }
  348. /* 4) The last two characters of the name are the hex GPE Number */
  349. gpe_number = ACPI_STRTOUL(&name[2], NULL, 16);
  350. if (gpe_number == ACPI_UINT32_MAX) {
  351. /* Conversion failed; invalid method, just ignore it */
  352. ACPI_DEBUG_PRINT((ACPI_DB_LOAD,
  353. "Could not extract GPE number from name: %s "
  354. "(name is not of form _Lxx or _Exx)", name));
  355. return_ACPI_STATUS(AE_OK);
  356. }
  357. /* Ensure that we have a valid GPE number for this GPE block */
  358. gpe_event_info =
  359. acpi_ev_low_get_gpe_info(gpe_number, walk_info->gpe_block);
  360. if (!gpe_event_info) {
  361. /*
  362. * This gpe_number is not valid for this GPE block, just ignore it.
  363. * However, it may be valid for a different GPE block, since GPE0
  364. * and GPE1 methods both appear under \_GPE.
  365. */
  366. return_ACPI_STATUS(AE_OK);
  367. }
  368. if ((gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) ==
  369. ACPI_GPE_DISPATCH_HANDLER) {
  370. /* If there is already a handler, ignore this GPE method */
  371. return_ACPI_STATUS(AE_OK);
  372. }
  373. if ((gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) ==
  374. ACPI_GPE_DISPATCH_METHOD) {
  375. /*
  376. * If there is already a method, ignore this method. But check
  377. * for a type mismatch (if both the _Lxx AND _Exx exist)
  378. */
  379. if (type != (gpe_event_info->flags & ACPI_GPE_XRUPT_TYPE_MASK)) {
  380. ACPI_ERROR((AE_INFO,
  381. "For GPE 0x%.2X, found both _L%2.2X and _E%2.2X methods",
  382. gpe_number, gpe_number, gpe_number));
  383. }
  384. return_ACPI_STATUS(AE_OK);
  385. }
  386. /*
  387. * Add the GPE information from above to the gpe_event_info block for
  388. * use during dispatch of this GPE.
  389. */
  390. gpe_event_info->flags |= (u8)(type | ACPI_GPE_DISPATCH_METHOD);
  391. gpe_event_info->dispatch.method_node = method_node;
  392. /*
  393. * Enable this GPE if requested. This only happens when during the
  394. * execution of a Load or load_table operator. We have found a new
  395. * GPE method and want to immediately enable the GPE if it is a
  396. * runtime GPE.
  397. */
  398. if (walk_info->enable_this_gpe) {
  399. /* Ignore GPEs that can wake the system */
  400. if (!(gpe_event_info->flags & ACPI_GPE_CAN_WAKE) ||
  401. !acpi_gbl_leave_wake_gpes_disabled) {
  402. walk_info->count++;
  403. gpe_device = walk_info->gpe_device;
  404. if (gpe_device == acpi_gbl_fadt_gpe_device) {
  405. gpe_device = NULL;
  406. }
  407. status = acpi_enable_gpe(gpe_device, gpe_number,
  408. ACPI_GPE_TYPE_RUNTIME);
  409. if (ACPI_FAILURE(status)) {
  410. ACPI_EXCEPTION((AE_INFO, status,
  411. "Could not enable GPE 0x%02X",
  412. gpe_number));
  413. }
  414. }
  415. }
  416. ACPI_DEBUG_PRINT((ACPI_DB_LOAD,
  417. "Registered GPE method %s as GPE number 0x%.2X\n",
  418. name, gpe_number));
  419. return_ACPI_STATUS(AE_OK);
  420. }
  421. /*******************************************************************************
  422. *
  423. * FUNCTION: acpi_ev_match_prw_and_gpe
  424. *
  425. * PARAMETERS: Callback from walk_namespace
  426. *
  427. * RETURN: Status. NOTE: We ignore errors so that the _PRW walk is
  428. * not aborted on a single _PRW failure.
  429. *
  430. * DESCRIPTION: Called from acpi_walk_namespace. Expects each object to be a
  431. * Device. Run the _PRW method. If present, extract the GPE
  432. * number and mark the GPE as a CAN_WAKE GPE. Allows a
  433. * per-owner_id execution if execute_by_owner_id is TRUE in the
  434. * walk_info parameter block.
  435. *
  436. * If walk_info->execute_by_owner_id is TRUE, we only execute _PRWs with that
  437. * owner.
  438. * If walk_info->gpe_device is NULL, we execute every _PRW found. Otherwise,
  439. * we only execute _PRWs that refer to the input gpe_device.
  440. *
  441. ******************************************************************************/
  442. acpi_status
  443. acpi_ev_match_prw_and_gpe(acpi_handle obj_handle,
  444. u32 level, void *context, void **return_value)
  445. {
  446. struct acpi_gpe_walk_info *walk_info =
  447. ACPI_CAST_PTR(struct acpi_gpe_walk_info, context);
  448. struct acpi_namespace_node *gpe_device;
  449. struct acpi_gpe_block_info *gpe_block;
  450. struct acpi_namespace_node *target_gpe_device;
  451. struct acpi_namespace_node *prw_node;
  452. struct acpi_gpe_event_info *gpe_event_info;
  453. union acpi_operand_object *pkg_desc;
  454. union acpi_operand_object *obj_desc;
  455. u32 gpe_number;
  456. acpi_status status;
  457. ACPI_FUNCTION_TRACE(ev_match_prw_and_gpe);
  458. /* Check for a _PRW method under this device */
  459. status = acpi_ns_get_node(obj_handle, METHOD_NAME__PRW,
  460. ACPI_NS_NO_UPSEARCH, &prw_node);
  461. if (ACPI_FAILURE(status)) {
  462. return_ACPI_STATUS(AE_OK);
  463. }
  464. /* Check if requested owner_id matches this owner_id */
  465. if ((walk_info->execute_by_owner_id) &&
  466. (prw_node->owner_id != walk_info->owner_id)) {
  467. return_ACPI_STATUS(AE_OK);
  468. }
  469. /* Execute the _PRW */
  470. status = acpi_ut_evaluate_object(prw_node, NULL,
  471. ACPI_BTYPE_PACKAGE, &pkg_desc);
  472. if (ACPI_FAILURE(status)) {
  473. return_ACPI_STATUS(AE_OK);
  474. }
  475. /* The returned _PRW package must have at least two elements */
  476. if (pkg_desc->package.count < 2) {
  477. goto cleanup;
  478. }
  479. /* Extract pointers from the input context */
  480. gpe_device = walk_info->gpe_device;
  481. gpe_block = walk_info->gpe_block;
  482. /*
  483. * The _PRW object must return a package, we are only interested
  484. * in the first element
  485. */
  486. obj_desc = pkg_desc->package.elements[0];
  487. if (obj_desc->common.type == ACPI_TYPE_INTEGER) {
  488. /* Use FADT-defined GPE device (from definition of _PRW) */
  489. target_gpe_device = NULL;
  490. if (gpe_device) {
  491. target_gpe_device = acpi_gbl_fadt_gpe_device;
  492. }
  493. /* Integer is the GPE number in the FADT described GPE blocks */
  494. gpe_number = (u32)obj_desc->integer.value;
  495. } else if (obj_desc->common.type == ACPI_TYPE_PACKAGE) {
  496. /* Package contains a GPE reference and GPE number within a GPE block */
  497. if ((obj_desc->package.count < 2) ||
  498. ((obj_desc->package.elements[0])->common.type !=
  499. ACPI_TYPE_LOCAL_REFERENCE) ||
  500. ((obj_desc->package.elements[1])->common.type !=
  501. ACPI_TYPE_INTEGER)) {
  502. goto cleanup;
  503. }
  504. /* Get GPE block reference and decode */
  505. target_gpe_device =
  506. obj_desc->package.elements[0]->reference.node;
  507. gpe_number = (u32)obj_desc->package.elements[1]->integer.value;
  508. } else {
  509. /* Unknown type, just ignore it */
  510. goto cleanup;
  511. }
  512. /* Get the gpe_event_info for this GPE */
  513. if (gpe_device) {
  514. /*
  515. * Is this GPE within this block?
  516. *
  517. * TRUE if and only if these conditions are true:
  518. * 1) The GPE devices match.
  519. * 2) The GPE index(number) is within the range of the Gpe Block
  520. * associated with the GPE device.
  521. */
  522. if (gpe_device != target_gpe_device) {
  523. goto cleanup;
  524. }
  525. gpe_event_info =
  526. acpi_ev_low_get_gpe_info(gpe_number, gpe_block);
  527. } else {
  528. /* gpe_device is NULL, just match the target_device and gpe_number */
  529. gpe_event_info =
  530. acpi_ev_get_gpe_event_info(target_gpe_device, gpe_number);
  531. }
  532. if (gpe_event_info) {
  533. if (!(gpe_event_info->flags & ACPI_GPE_CAN_WAKE)) {
  534. /* This GPE can wake the system */
  535. gpe_event_info->flags |= ACPI_GPE_CAN_WAKE;
  536. walk_info->count++;
  537. }
  538. }
  539. cleanup:
  540. acpi_ut_remove_reference(pkg_desc);
  541. return_ACPI_STATUS(AE_OK);
  542. }