evxfevnt.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870
  1. /******************************************************************************
  2. *
  3. * Module Name: evxfevnt - External Interfaces, ACPI event disable/enable
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2008, 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 <acpi/acevents.h>
  44. #include <acpi/acnamesp.h>
  45. #include <acpi/actables.h>
  46. #define _COMPONENT ACPI_EVENTS
  47. ACPI_MODULE_NAME("evxfevnt")
  48. /* Local prototypes */
  49. acpi_status
  50. acpi_ev_get_gpe_device(struct acpi_gpe_xrupt_info *gpe_xrupt_info,
  51. struct acpi_gpe_block_info *gpe_block, void *context);
  52. /*******************************************************************************
  53. *
  54. * FUNCTION: acpi_enable
  55. *
  56. * PARAMETERS: None
  57. *
  58. * RETURN: Status
  59. *
  60. * DESCRIPTION: Transfers the system into ACPI mode.
  61. *
  62. ******************************************************************************/
  63. acpi_status acpi_enable(void)
  64. {
  65. acpi_status status = AE_OK;
  66. ACPI_FUNCTION_TRACE(acpi_enable);
  67. /* ACPI tables must be present */
  68. if (!acpi_tb_tables_loaded()) {
  69. return_ACPI_STATUS(AE_NO_ACPI_TABLES);
  70. }
  71. /* Check current mode */
  72. if (acpi_hw_get_mode() == ACPI_SYS_MODE_ACPI) {
  73. ACPI_DEBUG_PRINT((ACPI_DB_INIT,
  74. "System is already in ACPI mode\n"));
  75. } else {
  76. /* Transition to ACPI mode */
  77. status = acpi_hw_set_mode(ACPI_SYS_MODE_ACPI);
  78. if (ACPI_FAILURE(status)) {
  79. ACPI_ERROR((AE_INFO,
  80. "Could not transition to ACPI mode"));
  81. return_ACPI_STATUS(status);
  82. }
  83. ACPI_DEBUG_PRINT((ACPI_DB_INIT,
  84. "Transition to ACPI mode successful\n"));
  85. }
  86. return_ACPI_STATUS(status);
  87. }
  88. ACPI_EXPORT_SYMBOL(acpi_enable)
  89. /*******************************************************************************
  90. *
  91. * FUNCTION: acpi_disable
  92. *
  93. * PARAMETERS: None
  94. *
  95. * RETURN: Status
  96. *
  97. * DESCRIPTION: Transfers the system into LEGACY (non-ACPI) mode.
  98. *
  99. ******************************************************************************/
  100. acpi_status acpi_disable(void)
  101. {
  102. acpi_status status = AE_OK;
  103. ACPI_FUNCTION_TRACE(acpi_disable);
  104. if (acpi_hw_get_mode() == ACPI_SYS_MODE_LEGACY) {
  105. ACPI_DEBUG_PRINT((ACPI_DB_INIT,
  106. "System is already in legacy (non-ACPI) mode\n"));
  107. } else {
  108. /* Transition to LEGACY mode */
  109. status = acpi_hw_set_mode(ACPI_SYS_MODE_LEGACY);
  110. if (ACPI_FAILURE(status)) {
  111. ACPI_ERROR((AE_INFO,
  112. "Could not exit ACPI mode to legacy mode"));
  113. return_ACPI_STATUS(status);
  114. }
  115. ACPI_DEBUG_PRINT((ACPI_DB_INIT, "ACPI mode disabled\n"));
  116. }
  117. return_ACPI_STATUS(status);
  118. }
  119. ACPI_EXPORT_SYMBOL(acpi_disable)
  120. /*******************************************************************************
  121. *
  122. * FUNCTION: acpi_enable_event
  123. *
  124. * PARAMETERS: Event - The fixed eventto be enabled
  125. * Flags - Reserved
  126. *
  127. * RETURN: Status
  128. *
  129. * DESCRIPTION: Enable an ACPI event (fixed)
  130. *
  131. ******************************************************************************/
  132. acpi_status acpi_enable_event(u32 event, u32 flags)
  133. {
  134. acpi_status status = AE_OK;
  135. u32 value;
  136. ACPI_FUNCTION_TRACE(acpi_enable_event);
  137. /* Decode the Fixed Event */
  138. if (event > ACPI_EVENT_MAX) {
  139. return_ACPI_STATUS(AE_BAD_PARAMETER);
  140. }
  141. /*
  142. * Enable the requested fixed event (by writing a one to the enable
  143. * register bit)
  144. */
  145. status =
  146. acpi_set_register(acpi_gbl_fixed_event_info[event].
  147. enable_register_id, 1);
  148. if (ACPI_FAILURE(status)) {
  149. return_ACPI_STATUS(status);
  150. }
  151. /* Make sure that the hardware responded */
  152. status =
  153. acpi_get_register(acpi_gbl_fixed_event_info[event].
  154. enable_register_id, &value);
  155. if (ACPI_FAILURE(status)) {
  156. return_ACPI_STATUS(status);
  157. }
  158. if (value != 1) {
  159. ACPI_ERROR((AE_INFO,
  160. "Could not enable %s event",
  161. acpi_ut_get_event_name(event)));
  162. return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
  163. }
  164. return_ACPI_STATUS(status);
  165. }
  166. ACPI_EXPORT_SYMBOL(acpi_enable_event)
  167. /*******************************************************************************
  168. *
  169. * FUNCTION: acpi_set_gpe_type
  170. *
  171. * PARAMETERS: gpe_device - Parent GPE Device
  172. * gpe_number - GPE level within the GPE block
  173. * Type - New GPE type
  174. *
  175. * RETURN: Status
  176. *
  177. * DESCRIPTION: Set the type of an individual GPE
  178. *
  179. ******************************************************************************/
  180. acpi_status acpi_set_gpe_type(acpi_handle gpe_device, u32 gpe_number, u8 type)
  181. {
  182. acpi_status status = AE_OK;
  183. struct acpi_gpe_event_info *gpe_event_info;
  184. ACPI_FUNCTION_TRACE(acpi_set_gpe_type);
  185. /* Ensure that we have a valid GPE number */
  186. gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
  187. if (!gpe_event_info) {
  188. status = AE_BAD_PARAMETER;
  189. goto unlock_and_exit;
  190. }
  191. if ((gpe_event_info->flags & ACPI_GPE_TYPE_MASK) == type) {
  192. return_ACPI_STATUS(AE_OK);
  193. }
  194. /* Set the new type (will disable GPE if currently enabled) */
  195. status = acpi_ev_set_gpe_type(gpe_event_info, type);
  196. unlock_and_exit:
  197. return_ACPI_STATUS(status);
  198. }
  199. ACPI_EXPORT_SYMBOL(acpi_set_gpe_type)
  200. /*******************************************************************************
  201. *
  202. * FUNCTION: acpi_enable_gpe
  203. *
  204. * PARAMETERS: gpe_device - Parent GPE Device
  205. * gpe_number - GPE level within the GPE block
  206. * Flags - Just enable, or also wake enable?
  207. * Called from ISR or not
  208. *
  209. * RETURN: Status
  210. *
  211. * DESCRIPTION: Enable an ACPI event (general purpose)
  212. *
  213. ******************************************************************************/
  214. acpi_status acpi_enable_gpe(acpi_handle gpe_device, u32 gpe_number)
  215. {
  216. acpi_status status = AE_OK;
  217. acpi_cpu_flags flags;
  218. struct acpi_gpe_event_info *gpe_event_info;
  219. ACPI_FUNCTION_TRACE(acpi_enable_gpe);
  220. flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
  221. /* Ensure that we have a valid GPE number */
  222. gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
  223. if (!gpe_event_info) {
  224. status = AE_BAD_PARAMETER;
  225. goto unlock_and_exit;
  226. }
  227. /* Perform the enable */
  228. status = acpi_ev_enable_gpe(gpe_event_info, TRUE);
  229. unlock_and_exit:
  230. acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
  231. return_ACPI_STATUS(status);
  232. }
  233. ACPI_EXPORT_SYMBOL(acpi_enable_gpe)
  234. /*******************************************************************************
  235. *
  236. * FUNCTION: acpi_disable_gpe
  237. *
  238. * PARAMETERS: gpe_device - Parent GPE Device
  239. * gpe_number - GPE level within the GPE block
  240. * Flags - Just disable, or also wake disable?
  241. * Called from ISR or not
  242. *
  243. * RETURN: Status
  244. *
  245. * DESCRIPTION: Disable an ACPI event (general purpose)
  246. *
  247. ******************************************************************************/
  248. acpi_status acpi_disable_gpe(acpi_handle gpe_device, u32 gpe_number)
  249. {
  250. acpi_status status = AE_OK;
  251. acpi_cpu_flags flags;
  252. struct acpi_gpe_event_info *gpe_event_info;
  253. ACPI_FUNCTION_TRACE(acpi_disable_gpe);
  254. flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
  255. /* Ensure that we have a valid GPE number */
  256. gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
  257. if (!gpe_event_info) {
  258. status = AE_BAD_PARAMETER;
  259. goto unlock_and_exit;
  260. }
  261. status = acpi_ev_disable_gpe(gpe_event_info);
  262. unlock_and_exit:
  263. acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
  264. return_ACPI_STATUS(status);
  265. }
  266. ACPI_EXPORT_SYMBOL(acpi_disable_gpe)
  267. /*******************************************************************************
  268. *
  269. * FUNCTION: acpi_disable_event
  270. *
  271. * PARAMETERS: Event - The fixed eventto be enabled
  272. * Flags - Reserved
  273. *
  274. * RETURN: Status
  275. *
  276. * DESCRIPTION: Disable an ACPI event (fixed)
  277. *
  278. ******************************************************************************/
  279. acpi_status acpi_disable_event(u32 event, u32 flags)
  280. {
  281. acpi_status status = AE_OK;
  282. u32 value;
  283. ACPI_FUNCTION_TRACE(acpi_disable_event);
  284. /* Decode the Fixed Event */
  285. if (event > ACPI_EVENT_MAX) {
  286. return_ACPI_STATUS(AE_BAD_PARAMETER);
  287. }
  288. /*
  289. * Disable the requested fixed event (by writing a zero to the enable
  290. * register bit)
  291. */
  292. status =
  293. acpi_set_register(acpi_gbl_fixed_event_info[event].
  294. enable_register_id, 0);
  295. if (ACPI_FAILURE(status)) {
  296. return_ACPI_STATUS(status);
  297. }
  298. status =
  299. acpi_get_register(acpi_gbl_fixed_event_info[event].
  300. enable_register_id, &value);
  301. if (ACPI_FAILURE(status)) {
  302. return_ACPI_STATUS(status);
  303. }
  304. if (value != 0) {
  305. ACPI_ERROR((AE_INFO,
  306. "Could not disable %s events",
  307. acpi_ut_get_event_name(event)));
  308. return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
  309. }
  310. return_ACPI_STATUS(status);
  311. }
  312. ACPI_EXPORT_SYMBOL(acpi_disable_event)
  313. /*******************************************************************************
  314. *
  315. * FUNCTION: acpi_clear_event
  316. *
  317. * PARAMETERS: Event - The fixed event to be cleared
  318. *
  319. * RETURN: Status
  320. *
  321. * DESCRIPTION: Clear an ACPI event (fixed)
  322. *
  323. ******************************************************************************/
  324. acpi_status acpi_clear_event(u32 event)
  325. {
  326. acpi_status status = AE_OK;
  327. ACPI_FUNCTION_TRACE(acpi_clear_event);
  328. /* Decode the Fixed Event */
  329. if (event > ACPI_EVENT_MAX) {
  330. return_ACPI_STATUS(AE_BAD_PARAMETER);
  331. }
  332. /*
  333. * Clear the requested fixed event (By writing a one to the status
  334. * register bit)
  335. */
  336. status =
  337. acpi_set_register(acpi_gbl_fixed_event_info[event].
  338. status_register_id, 1);
  339. return_ACPI_STATUS(status);
  340. }
  341. ACPI_EXPORT_SYMBOL(acpi_clear_event)
  342. /*******************************************************************************
  343. *
  344. * FUNCTION: acpi_clear_gpe
  345. *
  346. * PARAMETERS: gpe_device - Parent GPE Device
  347. * gpe_number - GPE level within the GPE block
  348. * Flags - Called from an ISR or not
  349. *
  350. * RETURN: Status
  351. *
  352. * DESCRIPTION: Clear an ACPI event (general purpose)
  353. *
  354. ******************************************************************************/
  355. acpi_status acpi_clear_gpe(acpi_handle gpe_device, u32 gpe_number, u32 flags)
  356. {
  357. acpi_status status = AE_OK;
  358. struct acpi_gpe_event_info *gpe_event_info;
  359. ACPI_FUNCTION_TRACE(acpi_clear_gpe);
  360. /* Use semaphore lock if not executing at interrupt level */
  361. if (flags & ACPI_NOT_ISR) {
  362. status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
  363. if (ACPI_FAILURE(status)) {
  364. return_ACPI_STATUS(status);
  365. }
  366. }
  367. /* Ensure that we have a valid GPE number */
  368. gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
  369. if (!gpe_event_info) {
  370. status = AE_BAD_PARAMETER;
  371. goto unlock_and_exit;
  372. }
  373. status = acpi_hw_clear_gpe(gpe_event_info);
  374. unlock_and_exit:
  375. if (flags & ACPI_NOT_ISR) {
  376. (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
  377. }
  378. return_ACPI_STATUS(status);
  379. }
  380. ACPI_EXPORT_SYMBOL(acpi_clear_gpe)
  381. /*******************************************************************************
  382. *
  383. * FUNCTION: acpi_get_event_status
  384. *
  385. * PARAMETERS: Event - The fixed event
  386. * event_status - Where the current status of the event will
  387. * be returned
  388. *
  389. * RETURN: Status
  390. *
  391. * DESCRIPTION: Obtains and returns the current status of the event
  392. *
  393. ******************************************************************************/
  394. acpi_status acpi_get_event_status(u32 event, acpi_event_status * event_status)
  395. {
  396. acpi_status status = AE_OK;
  397. u32 value;
  398. ACPI_FUNCTION_TRACE(acpi_get_event_status);
  399. if (!event_status) {
  400. return_ACPI_STATUS(AE_BAD_PARAMETER);
  401. }
  402. /* Decode the Fixed Event */
  403. if (event > ACPI_EVENT_MAX) {
  404. return_ACPI_STATUS(AE_BAD_PARAMETER);
  405. }
  406. /* Get the status of the requested fixed event */
  407. status =
  408. acpi_get_register(acpi_gbl_fixed_event_info[event].
  409. enable_register_id, &value);
  410. if (ACPI_FAILURE(status))
  411. return_ACPI_STATUS(status);
  412. *event_status = value;
  413. status =
  414. acpi_get_register(acpi_gbl_fixed_event_info[event].
  415. status_register_id, &value);
  416. if (ACPI_FAILURE(status))
  417. return_ACPI_STATUS(status);
  418. if (value)
  419. *event_status |= ACPI_EVENT_FLAG_SET;
  420. if (acpi_gbl_fixed_event_handlers[event].handler)
  421. *event_status |= ACPI_EVENT_FLAG_HANDLE;
  422. return_ACPI_STATUS(status);
  423. }
  424. ACPI_EXPORT_SYMBOL(acpi_get_event_status)
  425. /*******************************************************************************
  426. *
  427. * FUNCTION: acpi_get_gpe_status
  428. *
  429. * PARAMETERS: gpe_device - Parent GPE Device
  430. * gpe_number - GPE level within the GPE block
  431. * Flags - Called from an ISR or not
  432. * event_status - Where the current status of the event will
  433. * be returned
  434. *
  435. * RETURN: Status
  436. *
  437. * DESCRIPTION: Get status of an event (general purpose)
  438. *
  439. ******************************************************************************/
  440. acpi_status
  441. acpi_get_gpe_status(acpi_handle gpe_device,
  442. u32 gpe_number, u32 flags, acpi_event_status * event_status)
  443. {
  444. acpi_status status = AE_OK;
  445. struct acpi_gpe_event_info *gpe_event_info;
  446. ACPI_FUNCTION_TRACE(acpi_get_gpe_status);
  447. /* Use semaphore lock if not executing at interrupt level */
  448. if (flags & ACPI_NOT_ISR) {
  449. status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
  450. if (ACPI_FAILURE(status)) {
  451. return_ACPI_STATUS(status);
  452. }
  453. }
  454. /* Ensure that we have a valid GPE number */
  455. gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
  456. if (!gpe_event_info) {
  457. status = AE_BAD_PARAMETER;
  458. goto unlock_and_exit;
  459. }
  460. /* Obtain status on the requested GPE number */
  461. status = acpi_hw_get_gpe_status(gpe_event_info, event_status);
  462. if (gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK)
  463. *event_status |= ACPI_EVENT_FLAG_HANDLE;
  464. unlock_and_exit:
  465. if (flags & ACPI_NOT_ISR) {
  466. (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
  467. }
  468. return_ACPI_STATUS(status);
  469. }
  470. ACPI_EXPORT_SYMBOL(acpi_get_gpe_status)
  471. /*******************************************************************************
  472. *
  473. * FUNCTION: acpi_install_gpe_block
  474. *
  475. * PARAMETERS: gpe_device - Handle to the parent GPE Block Device
  476. * gpe_block_address - Address and space_iD
  477. * register_count - Number of GPE register pairs in the block
  478. * interrupt_number - H/W interrupt for the block
  479. *
  480. * RETURN: Status
  481. *
  482. * DESCRIPTION: Create and Install a block of GPE registers
  483. *
  484. ******************************************************************************/
  485. acpi_status
  486. acpi_install_gpe_block(acpi_handle gpe_device,
  487. struct acpi_generic_address *gpe_block_address,
  488. u32 register_count, u32 interrupt_number)
  489. {
  490. acpi_status status;
  491. union acpi_operand_object *obj_desc;
  492. struct acpi_namespace_node *node;
  493. struct acpi_gpe_block_info *gpe_block;
  494. ACPI_FUNCTION_TRACE(acpi_install_gpe_block);
  495. if ((!gpe_device) || (!gpe_block_address) || (!register_count)) {
  496. return_ACPI_STATUS(AE_BAD_PARAMETER);
  497. }
  498. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  499. if (ACPI_FAILURE(status)) {
  500. return (status);
  501. }
  502. node = acpi_ns_map_handle_to_node(gpe_device);
  503. if (!node) {
  504. status = AE_BAD_PARAMETER;
  505. goto unlock_and_exit;
  506. }
  507. /*
  508. * For user-installed GPE Block Devices, the gpe_block_base_number
  509. * is always zero
  510. */
  511. status =
  512. acpi_ev_create_gpe_block(node, gpe_block_address, register_count, 0,
  513. interrupt_number, &gpe_block);
  514. if (ACPI_FAILURE(status)) {
  515. goto unlock_and_exit;
  516. }
  517. /* Run the _PRW methods and enable the GPEs */
  518. status = acpi_ev_initialize_gpe_block(node, gpe_block);
  519. if (ACPI_FAILURE(status)) {
  520. goto unlock_and_exit;
  521. }
  522. /* Get the device_object attached to the node */
  523. obj_desc = acpi_ns_get_attached_object(node);
  524. if (!obj_desc) {
  525. /* No object, create a new one */
  526. obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_DEVICE);
  527. if (!obj_desc) {
  528. status = AE_NO_MEMORY;
  529. goto unlock_and_exit;
  530. }
  531. status =
  532. acpi_ns_attach_object(node, obj_desc, ACPI_TYPE_DEVICE);
  533. /* Remove local reference to the object */
  534. acpi_ut_remove_reference(obj_desc);
  535. if (ACPI_FAILURE(status)) {
  536. goto unlock_and_exit;
  537. }
  538. }
  539. /* Install the GPE block in the device_object */
  540. obj_desc->device.gpe_block = gpe_block;
  541. unlock_and_exit:
  542. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  543. return_ACPI_STATUS(status);
  544. }
  545. ACPI_EXPORT_SYMBOL(acpi_install_gpe_block)
  546. /*******************************************************************************
  547. *
  548. * FUNCTION: acpi_remove_gpe_block
  549. *
  550. * PARAMETERS: gpe_device - Handle to the parent GPE Block Device
  551. *
  552. * RETURN: Status
  553. *
  554. * DESCRIPTION: Remove a previously installed block of GPE registers
  555. *
  556. ******************************************************************************/
  557. acpi_status acpi_remove_gpe_block(acpi_handle gpe_device)
  558. {
  559. union acpi_operand_object *obj_desc;
  560. acpi_status status;
  561. struct acpi_namespace_node *node;
  562. ACPI_FUNCTION_TRACE(acpi_remove_gpe_block);
  563. if (!gpe_device) {
  564. return_ACPI_STATUS(AE_BAD_PARAMETER);
  565. }
  566. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  567. if (ACPI_FAILURE(status)) {
  568. return (status);
  569. }
  570. node = acpi_ns_map_handle_to_node(gpe_device);
  571. if (!node) {
  572. status = AE_BAD_PARAMETER;
  573. goto unlock_and_exit;
  574. }
  575. /* Get the device_object attached to the node */
  576. obj_desc = acpi_ns_get_attached_object(node);
  577. if (!obj_desc || !obj_desc->device.gpe_block) {
  578. return_ACPI_STATUS(AE_NULL_OBJECT);
  579. }
  580. /* Delete the GPE block (but not the device_object) */
  581. status = acpi_ev_delete_gpe_block(obj_desc->device.gpe_block);
  582. if (ACPI_SUCCESS(status)) {
  583. obj_desc->device.gpe_block = NULL;
  584. }
  585. unlock_and_exit:
  586. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  587. return_ACPI_STATUS(status);
  588. }
  589. ACPI_EXPORT_SYMBOL(acpi_remove_gpe_block)
  590. /*******************************************************************************
  591. *
  592. * FUNCTION: acpi_get_gpe_device
  593. *
  594. * PARAMETERS: Index - System GPE index (0-current_gpe_count)
  595. * gpe_device - Where the parent GPE Device is returned
  596. *
  597. * RETURN: Status
  598. *
  599. * DESCRIPTION: Obtain the GPE device associated with the input index. A NULL
  600. * gpe device indicates that the gpe number is contained in one of
  601. * the FADT-defined gpe blocks. Otherwise, the GPE block device.
  602. *
  603. ******************************************************************************/
  604. acpi_status
  605. acpi_get_gpe_device(u32 index, acpi_handle *gpe_device)
  606. {
  607. struct acpi_gpe_device_info info;
  608. acpi_status status;
  609. ACPI_FUNCTION_TRACE(acpi_get_gpe_device);
  610. if (!gpe_device) {
  611. return_ACPI_STATUS(AE_BAD_PARAMETER);
  612. }
  613. if (index >= acpi_current_gpe_count) {
  614. return_ACPI_STATUS(AE_NOT_EXIST);
  615. }
  616. /* Setup and walk the GPE list */
  617. info.index = index;
  618. info.status = AE_NOT_EXIST;
  619. info.gpe_device = NULL;
  620. info.next_block_base_index = 0;
  621. status = acpi_ev_walk_gpe_list(acpi_ev_get_gpe_device, &info);
  622. if (ACPI_FAILURE(status)) {
  623. return_ACPI_STATUS(status);
  624. }
  625. *gpe_device = info.gpe_device;
  626. return_ACPI_STATUS(info.status);
  627. }
  628. ACPI_EXPORT_SYMBOL(acpi_get_gpe_device)
  629. /*******************************************************************************
  630. *
  631. * FUNCTION: acpi_ev_get_gpe_device
  632. *
  633. * PARAMETERS: GPE_WALK_CALLBACK
  634. *
  635. * RETURN: Status
  636. *
  637. * DESCRIPTION: Matches the input GPE index (0-current_gpe_count) with a GPE
  638. * block device. NULL if the GPE is one of the FADT-defined GPEs.
  639. *
  640. ******************************************************************************/
  641. acpi_status
  642. acpi_ev_get_gpe_device(struct acpi_gpe_xrupt_info *gpe_xrupt_info,
  643. struct acpi_gpe_block_info *gpe_block, void *context)
  644. {
  645. struct acpi_gpe_device_info *info = context;
  646. /* Increment Index by the number of GPEs in this block */
  647. info->next_block_base_index +=
  648. (gpe_block->register_count * ACPI_GPE_REGISTER_WIDTH);
  649. if (info->index < info->next_block_base_index) {
  650. /*
  651. * The GPE index is within this block, get the node. Leave the node
  652. * NULL for the FADT-defined GPEs
  653. */
  654. if ((gpe_block->node)->type == ACPI_TYPE_DEVICE) {
  655. info->gpe_device = gpe_block->node;
  656. }
  657. info->status = AE_OK;
  658. return (AE_CTRL_END);
  659. }
  660. return (AE_OK);
  661. }
  662. /******************************************************************************
  663. *
  664. * FUNCTION: acpi_disable_all_gpes
  665. *
  666. * PARAMETERS: None
  667. *
  668. * RETURN: Status
  669. *
  670. * DESCRIPTION: Disable and clear all GPEs in all GPE blocks
  671. *
  672. ******************************************************************************/
  673. acpi_status acpi_disable_all_gpes(void)
  674. {
  675. acpi_status status;
  676. ACPI_FUNCTION_TRACE(acpi_disable_all_gpes);
  677. status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
  678. if (ACPI_FAILURE(status)) {
  679. return_ACPI_STATUS(status);
  680. }
  681. status = acpi_hw_disable_all_gpes();
  682. (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
  683. return_ACPI_STATUS(status);
  684. }
  685. /******************************************************************************
  686. *
  687. * FUNCTION: acpi_enable_all_runtime_gpes
  688. *
  689. * PARAMETERS: None
  690. *
  691. * RETURN: Status
  692. *
  693. * DESCRIPTION: Enable all "runtime" GPEs, in all GPE blocks
  694. *
  695. ******************************************************************************/
  696. acpi_status acpi_enable_all_runtime_gpes(void)
  697. {
  698. acpi_status status;
  699. ACPI_FUNCTION_TRACE(acpi_enable_all_runtime_gpes);
  700. status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
  701. if (ACPI_FAILURE(status)) {
  702. return_ACPI_STATUS(status);
  703. }
  704. status = acpi_hw_enable_all_runtime_gpes();
  705. (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
  706. return_ACPI_STATUS(status);
  707. }