evgpeblk.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513
  1. /******************************************************************************
  2. *
  3. * Module Name: evgpeblk - GPE block creation and initialization.
  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("evgpeblk")
  48. #if (!ACPI_REDUCED_HARDWARE) /* Entire module */
  49. /* Local prototypes */
  50. static acpi_status
  51. acpi_ev_install_gpe_block(struct acpi_gpe_block_info *gpe_block,
  52. u32 interrupt_number);
  53. static acpi_status
  54. acpi_ev_create_gpe_info_blocks(struct acpi_gpe_block_info *gpe_block);
  55. /*******************************************************************************
  56. *
  57. * FUNCTION: acpi_ev_install_gpe_block
  58. *
  59. * PARAMETERS: gpe_block - New GPE block
  60. * interrupt_number - Xrupt to be associated with this
  61. * GPE block
  62. *
  63. * RETURN: Status
  64. *
  65. * DESCRIPTION: Install new GPE block with mutex support
  66. *
  67. ******************************************************************************/
  68. static acpi_status
  69. acpi_ev_install_gpe_block(struct acpi_gpe_block_info *gpe_block,
  70. u32 interrupt_number)
  71. {
  72. struct acpi_gpe_block_info *next_gpe_block;
  73. struct acpi_gpe_xrupt_info *gpe_xrupt_block;
  74. acpi_status status;
  75. acpi_cpu_flags flags;
  76. ACPI_FUNCTION_TRACE(ev_install_gpe_block);
  77. status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
  78. if (ACPI_FAILURE(status)) {
  79. return_ACPI_STATUS(status);
  80. }
  81. status =
  82. acpi_ev_get_gpe_xrupt_block(interrupt_number, &gpe_xrupt_block);
  83. if (ACPI_FAILURE(status)) {
  84. goto unlock_and_exit;
  85. }
  86. /* Install the new block at the end of the list with lock */
  87. flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
  88. if (gpe_xrupt_block->gpe_block_list_head) {
  89. next_gpe_block = gpe_xrupt_block->gpe_block_list_head;
  90. while (next_gpe_block->next) {
  91. next_gpe_block = next_gpe_block->next;
  92. }
  93. next_gpe_block->next = gpe_block;
  94. gpe_block->previous = next_gpe_block;
  95. } else {
  96. gpe_xrupt_block->gpe_block_list_head = gpe_block;
  97. }
  98. gpe_block->xrupt_block = gpe_xrupt_block;
  99. acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
  100. unlock_and_exit:
  101. (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
  102. return_ACPI_STATUS(status);
  103. }
  104. /*******************************************************************************
  105. *
  106. * FUNCTION: acpi_ev_delete_gpe_block
  107. *
  108. * PARAMETERS: gpe_block - Existing GPE block
  109. *
  110. * RETURN: Status
  111. *
  112. * DESCRIPTION: Remove a GPE block
  113. *
  114. ******************************************************************************/
  115. acpi_status acpi_ev_delete_gpe_block(struct acpi_gpe_block_info *gpe_block)
  116. {
  117. acpi_status status;
  118. acpi_cpu_flags flags;
  119. ACPI_FUNCTION_TRACE(ev_install_gpe_block);
  120. status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
  121. if (ACPI_FAILURE(status)) {
  122. return_ACPI_STATUS(status);
  123. }
  124. /* Disable all GPEs in this block */
  125. status =
  126. acpi_hw_disable_gpe_block(gpe_block->xrupt_block, gpe_block, NULL);
  127. if (!gpe_block->previous && !gpe_block->next) {
  128. /* This is the last gpe_block on this interrupt */
  129. status = acpi_ev_delete_gpe_xrupt(gpe_block->xrupt_block);
  130. if (ACPI_FAILURE(status)) {
  131. goto unlock_and_exit;
  132. }
  133. } else {
  134. /* Remove the block on this interrupt with lock */
  135. flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
  136. if (gpe_block->previous) {
  137. gpe_block->previous->next = gpe_block->next;
  138. } else {
  139. gpe_block->xrupt_block->gpe_block_list_head =
  140. gpe_block->next;
  141. }
  142. if (gpe_block->next) {
  143. gpe_block->next->previous = gpe_block->previous;
  144. }
  145. acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
  146. }
  147. acpi_current_gpe_count -= gpe_block->gpe_count;
  148. /* Free the gpe_block */
  149. ACPI_FREE(gpe_block->register_info);
  150. ACPI_FREE(gpe_block->event_info);
  151. ACPI_FREE(gpe_block);
  152. unlock_and_exit:
  153. status = acpi_ut_release_mutex(ACPI_MTX_EVENTS);
  154. return_ACPI_STATUS(status);
  155. }
  156. /*******************************************************************************
  157. *
  158. * FUNCTION: acpi_ev_create_gpe_info_blocks
  159. *
  160. * PARAMETERS: gpe_block - New GPE block
  161. *
  162. * RETURN: Status
  163. *
  164. * DESCRIPTION: Create the register_info and event_info blocks for this GPE block
  165. *
  166. ******************************************************************************/
  167. static acpi_status
  168. acpi_ev_create_gpe_info_blocks(struct acpi_gpe_block_info *gpe_block)
  169. {
  170. struct acpi_gpe_register_info *gpe_register_info = NULL;
  171. struct acpi_gpe_event_info *gpe_event_info = NULL;
  172. struct acpi_gpe_event_info *this_event;
  173. struct acpi_gpe_register_info *this_register;
  174. u32 i;
  175. u32 j;
  176. acpi_status status;
  177. ACPI_FUNCTION_TRACE(ev_create_gpe_info_blocks);
  178. /* Allocate the GPE register information block */
  179. gpe_register_info = ACPI_ALLOCATE_ZEROED((acpi_size) gpe_block->
  180. register_count *
  181. sizeof(struct
  182. acpi_gpe_register_info));
  183. if (!gpe_register_info) {
  184. ACPI_ERROR((AE_INFO,
  185. "Could not allocate the GpeRegisterInfo table"));
  186. return_ACPI_STATUS(AE_NO_MEMORY);
  187. }
  188. /*
  189. * Allocate the GPE event_info block. There are eight distinct GPEs
  190. * per register. Initialization to zeros is sufficient.
  191. */
  192. gpe_event_info = ACPI_ALLOCATE_ZEROED((acpi_size) gpe_block->gpe_count *
  193. sizeof(struct
  194. acpi_gpe_event_info));
  195. if (!gpe_event_info) {
  196. ACPI_ERROR((AE_INFO,
  197. "Could not allocate the GpeEventInfo table"));
  198. status = AE_NO_MEMORY;
  199. goto error_exit;
  200. }
  201. /* Save the new Info arrays in the GPE block */
  202. gpe_block->register_info = gpe_register_info;
  203. gpe_block->event_info = gpe_event_info;
  204. /*
  205. * Initialize the GPE Register and Event structures. A goal of these
  206. * tables is to hide the fact that there are two separate GPE register
  207. * sets in a given GPE hardware block, the status registers occupy the
  208. * first half, and the enable registers occupy the second half.
  209. */
  210. this_register = gpe_register_info;
  211. this_event = gpe_event_info;
  212. for (i = 0; i < gpe_block->register_count; i++) {
  213. /* Init the register_info for this GPE register (8 GPEs) */
  214. this_register->base_gpe_number = (u16)
  215. (gpe_block->block_base_number +
  216. (i * ACPI_GPE_REGISTER_WIDTH));
  217. this_register->status_address.address = gpe_block->address + i;
  218. this_register->enable_address.address =
  219. gpe_block->address + i + gpe_block->register_count;
  220. this_register->status_address.space_id = gpe_block->space_id;
  221. this_register->enable_address.space_id = gpe_block->space_id;
  222. this_register->status_address.bit_width =
  223. ACPI_GPE_REGISTER_WIDTH;
  224. this_register->enable_address.bit_width =
  225. ACPI_GPE_REGISTER_WIDTH;
  226. this_register->status_address.bit_offset = 0;
  227. this_register->enable_address.bit_offset = 0;
  228. /* Init the event_info for each GPE within this register */
  229. for (j = 0; j < ACPI_GPE_REGISTER_WIDTH; j++) {
  230. this_event->gpe_number =
  231. (u8) (this_register->base_gpe_number + j);
  232. this_event->register_info = this_register;
  233. this_event++;
  234. }
  235. /* Disable all GPEs within this register */
  236. status = acpi_hw_write(0x00, &this_register->enable_address);
  237. if (ACPI_FAILURE(status)) {
  238. goto error_exit;
  239. }
  240. /* Clear any pending GPE events within this register */
  241. status = acpi_hw_write(0xFF, &this_register->status_address);
  242. if (ACPI_FAILURE(status)) {
  243. goto error_exit;
  244. }
  245. this_register++;
  246. }
  247. return_ACPI_STATUS(AE_OK);
  248. error_exit:
  249. if (gpe_register_info) {
  250. ACPI_FREE(gpe_register_info);
  251. }
  252. if (gpe_event_info) {
  253. ACPI_FREE(gpe_event_info);
  254. }
  255. return_ACPI_STATUS(status);
  256. }
  257. /*******************************************************************************
  258. *
  259. * FUNCTION: acpi_ev_create_gpe_block
  260. *
  261. * PARAMETERS: gpe_device - Handle to the parent GPE block
  262. * gpe_block_address - Address and space_ID
  263. * register_count - Number of GPE register pairs in the block
  264. * gpe_block_base_number - Starting GPE number for the block
  265. * interrupt_number - H/W interrupt for the block
  266. * return_gpe_block - Where the new block descriptor is returned
  267. *
  268. * RETURN: Status
  269. *
  270. * DESCRIPTION: Create and Install a block of GPE registers. All GPEs within
  271. * the block are disabled at exit.
  272. * Note: Assumes namespace is locked.
  273. *
  274. ******************************************************************************/
  275. acpi_status
  276. acpi_ev_create_gpe_block(struct acpi_namespace_node *gpe_device,
  277. u64 address,
  278. u8 space_id,
  279. u32 register_count,
  280. u16 gpe_block_base_number,
  281. u32 interrupt_number,
  282. struct acpi_gpe_block_info **return_gpe_block)
  283. {
  284. acpi_status status;
  285. struct acpi_gpe_block_info *gpe_block;
  286. struct acpi_gpe_walk_info walk_info;
  287. ACPI_FUNCTION_TRACE(ev_create_gpe_block);
  288. if (!register_count) {
  289. return_ACPI_STATUS(AE_OK);
  290. }
  291. /* Allocate a new GPE block */
  292. gpe_block = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_gpe_block_info));
  293. if (!gpe_block) {
  294. return_ACPI_STATUS(AE_NO_MEMORY);
  295. }
  296. /* Initialize the new GPE block */
  297. gpe_block->address = address;
  298. gpe_block->space_id = space_id;
  299. gpe_block->node = gpe_device;
  300. gpe_block->gpe_count = (u16)(register_count * ACPI_GPE_REGISTER_WIDTH);
  301. gpe_block->initialized = FALSE;
  302. gpe_block->register_count = register_count;
  303. gpe_block->block_base_number = gpe_block_base_number;
  304. /*
  305. * Create the register_info and event_info sub-structures
  306. * Note: disables and clears all GPEs in the block
  307. */
  308. status = acpi_ev_create_gpe_info_blocks(gpe_block);
  309. if (ACPI_FAILURE(status)) {
  310. ACPI_FREE(gpe_block);
  311. return_ACPI_STATUS(status);
  312. }
  313. /* Install the new block in the global lists */
  314. status = acpi_ev_install_gpe_block(gpe_block, interrupt_number);
  315. if (ACPI_FAILURE(status)) {
  316. ACPI_FREE(gpe_block->register_info);
  317. ACPI_FREE(gpe_block->event_info);
  318. ACPI_FREE(gpe_block);
  319. return_ACPI_STATUS(status);
  320. }
  321. acpi_gbl_all_gpes_initialized = FALSE;
  322. /* Find all GPE methods (_Lxx or_Exx) for this block */
  323. walk_info.gpe_block = gpe_block;
  324. walk_info.gpe_device = gpe_device;
  325. walk_info.execute_by_owner_id = FALSE;
  326. status = acpi_ns_walk_namespace(ACPI_TYPE_METHOD, gpe_device,
  327. ACPI_UINT32_MAX, ACPI_NS_WALK_NO_UNLOCK,
  328. acpi_ev_match_gpe_method, NULL,
  329. &walk_info, NULL);
  330. /* Return the new block */
  331. if (return_gpe_block) {
  332. (*return_gpe_block) = gpe_block;
  333. }
  334. ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT,
  335. " Initialized GPE %02X to %02X [%4.4s] %u regs on interrupt 0x%X%s\n",
  336. (u32)gpe_block->block_base_number,
  337. (u32)(gpe_block->block_base_number +
  338. (gpe_block->gpe_count - 1)),
  339. gpe_device->name.ascii, gpe_block->register_count,
  340. interrupt_number,
  341. interrupt_number ==
  342. acpi_gbl_FADT.sci_interrupt ? " (SCI)" : ""));
  343. /* Update global count of currently available GPEs */
  344. acpi_current_gpe_count += gpe_block->gpe_count;
  345. return_ACPI_STATUS(AE_OK);
  346. }
  347. /*******************************************************************************
  348. *
  349. * FUNCTION: acpi_ev_initialize_gpe_block
  350. *
  351. * PARAMETERS: acpi_gpe_callback
  352. *
  353. * RETURN: Status
  354. *
  355. * DESCRIPTION: Initialize and enable a GPE block. Enable GPEs that have
  356. * associated methods.
  357. * Note: Assumes namespace is locked.
  358. *
  359. ******************************************************************************/
  360. acpi_status
  361. acpi_ev_initialize_gpe_block(struct acpi_gpe_xrupt_info *gpe_xrupt_info,
  362. struct acpi_gpe_block_info *gpe_block,
  363. void *ignored)
  364. {
  365. acpi_status status;
  366. struct acpi_gpe_event_info *gpe_event_info;
  367. u32 gpe_enabled_count;
  368. u32 gpe_index;
  369. u32 i;
  370. u32 j;
  371. ACPI_FUNCTION_TRACE(ev_initialize_gpe_block);
  372. /*
  373. * Ignore a null GPE block (e.g., if no GPE block 1 exists), and
  374. * any GPE blocks that have been initialized already.
  375. */
  376. if (!gpe_block || gpe_block->initialized) {
  377. return_ACPI_STATUS(AE_OK);
  378. }
  379. /*
  380. * Enable all GPEs that have a corresponding method and have the
  381. * ACPI_GPE_CAN_WAKE flag unset. Any other GPEs within this block
  382. * must be enabled via the acpi_enable_gpe() interface.
  383. */
  384. gpe_enabled_count = 0;
  385. for (i = 0; i < gpe_block->register_count; i++) {
  386. for (j = 0; j < ACPI_GPE_REGISTER_WIDTH; j++) {
  387. /* Get the info block for this particular GPE */
  388. gpe_index = (i * ACPI_GPE_REGISTER_WIDTH) + j;
  389. gpe_event_info = &gpe_block->event_info[gpe_index];
  390. /*
  391. * Ignore GPEs that have no corresponding _Lxx/_Exx method
  392. * and GPEs that are used to wake the system
  393. */
  394. if ((ACPI_GPE_DISPATCH_TYPE(gpe_event_info->flags) ==
  395. ACPI_GPE_DISPATCH_NONE)
  396. || (ACPI_GPE_DISPATCH_TYPE(gpe_event_info->flags) ==
  397. ACPI_GPE_DISPATCH_HANDLER)
  398. || (ACPI_GPE_DISPATCH_TYPE(gpe_event_info->flags) ==
  399. ACPI_GPE_DISPATCH_RAW_HANDLER)
  400. || (gpe_event_info->flags & ACPI_GPE_CAN_WAKE)) {
  401. continue;
  402. }
  403. status = acpi_ev_add_gpe_reference(gpe_event_info);
  404. if (ACPI_FAILURE(status)) {
  405. ACPI_EXCEPTION((AE_INFO, status,
  406. "Could not enable GPE 0x%02X",
  407. gpe_index +
  408. gpe_block->block_base_number));
  409. continue;
  410. }
  411. gpe_enabled_count++;
  412. }
  413. }
  414. if (gpe_enabled_count) {
  415. ACPI_INFO((AE_INFO,
  416. "Enabled %u GPEs in block %02X to %02X",
  417. gpe_enabled_count, (u32)gpe_block->block_base_number,
  418. (u32)(gpe_block->block_base_number +
  419. (gpe_block->gpe_count - 1))));
  420. }
  421. gpe_block->initialized = TRUE;
  422. return_ACPI_STATUS(AE_OK);
  423. }
  424. #endif /* !ACPI_REDUCED_HARDWARE */