evgpeblk.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509
  1. /******************************************************************************
  2. *
  3. * Module Name: evgpeblk - GPE block creation and initialization.
  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("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. gpe_xrupt_block = acpi_ev_get_gpe_xrupt_block(interrupt_number);
  82. if (!gpe_xrupt_block) {
  83. status = AE_NO_MEMORY;
  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. status = 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 =
  215. (u8) (gpe_block->block_base_number +
  216. (i * ACPI_GPE_REGISTER_WIDTH));
  217. this_register->status_address.address =
  218. gpe_block->block_address.address + i;
  219. this_register->enable_address.address =
  220. gpe_block->block_address.address + i +
  221. gpe_block->register_count;
  222. this_register->status_address.space_id =
  223. gpe_block->block_address.space_id;
  224. this_register->enable_address.space_id =
  225. gpe_block->block_address.space_id;
  226. this_register->status_address.bit_width =
  227. ACPI_GPE_REGISTER_WIDTH;
  228. this_register->enable_address.bit_width =
  229. ACPI_GPE_REGISTER_WIDTH;
  230. this_register->status_address.bit_offset = 0;
  231. this_register->enable_address.bit_offset = 0;
  232. /* Init the event_info for each GPE within this register */
  233. for (j = 0; j < ACPI_GPE_REGISTER_WIDTH; j++) {
  234. this_event->gpe_number =
  235. (u8) (this_register->base_gpe_number + j);
  236. this_event->register_info = this_register;
  237. this_event++;
  238. }
  239. /* Disable all GPEs within this register */
  240. status = acpi_hw_write(0x00, &this_register->enable_address);
  241. if (ACPI_FAILURE(status)) {
  242. goto error_exit;
  243. }
  244. /* Clear any pending GPE events within this register */
  245. status = acpi_hw_write(0xFF, &this_register->status_address);
  246. if (ACPI_FAILURE(status)) {
  247. goto error_exit;
  248. }
  249. this_register++;
  250. }
  251. return_ACPI_STATUS(AE_OK);
  252. error_exit:
  253. if (gpe_register_info) {
  254. ACPI_FREE(gpe_register_info);
  255. }
  256. if (gpe_event_info) {
  257. ACPI_FREE(gpe_event_info);
  258. }
  259. return_ACPI_STATUS(status);
  260. }
  261. /*******************************************************************************
  262. *
  263. * FUNCTION: acpi_ev_create_gpe_block
  264. *
  265. * PARAMETERS: gpe_device - Handle to the parent GPE block
  266. * gpe_block_address - Address and space_iD
  267. * register_count - Number of GPE register pairs in the block
  268. * gpe_block_base_number - Starting GPE number for the block
  269. * interrupt_number - H/W interrupt for the block
  270. * return_gpe_block - Where the new block descriptor is returned
  271. *
  272. * RETURN: Status
  273. *
  274. * DESCRIPTION: Create and Install a block of GPE registers. All GPEs within
  275. * the block are disabled at exit.
  276. * Note: Assumes namespace is locked.
  277. *
  278. ******************************************************************************/
  279. acpi_status
  280. acpi_ev_create_gpe_block(struct acpi_namespace_node *gpe_device,
  281. struct acpi_generic_address *gpe_block_address,
  282. u32 register_count,
  283. u8 gpe_block_base_number,
  284. u32 interrupt_number,
  285. struct acpi_gpe_block_info **return_gpe_block)
  286. {
  287. acpi_status status;
  288. struct acpi_gpe_block_info *gpe_block;
  289. struct acpi_gpe_walk_info walk_info;
  290. ACPI_FUNCTION_TRACE(ev_create_gpe_block);
  291. if (!register_count) {
  292. return_ACPI_STATUS(AE_OK);
  293. }
  294. /* Allocate a new GPE block */
  295. gpe_block = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_gpe_block_info));
  296. if (!gpe_block) {
  297. return_ACPI_STATUS(AE_NO_MEMORY);
  298. }
  299. /* Initialize the new GPE block */
  300. gpe_block->node = gpe_device;
  301. gpe_block->gpe_count = (u16)(register_count * ACPI_GPE_REGISTER_WIDTH);
  302. gpe_block->initialized = FALSE;
  303. gpe_block->register_count = register_count;
  304. gpe_block->block_base_number = gpe_block_base_number;
  305. ACPI_MEMCPY(&gpe_block->block_address, gpe_block_address,
  306. sizeof(struct acpi_generic_address));
  307. /*
  308. * Create the register_info and event_info sub-structures
  309. * Note: disables and clears all GPEs in the block
  310. */
  311. status = acpi_ev_create_gpe_info_blocks(gpe_block);
  312. if (ACPI_FAILURE(status)) {
  313. ACPI_FREE(gpe_block);
  314. return_ACPI_STATUS(status);
  315. }
  316. /* Install the new block in the global lists */
  317. status = acpi_ev_install_gpe_block(gpe_block, interrupt_number);
  318. if (ACPI_FAILURE(status)) {
  319. ACPI_FREE(gpe_block);
  320. return_ACPI_STATUS(status);
  321. }
  322. acpi_gbl_all_gpes_initialized = FALSE;
  323. /* Find all GPE methods (_Lxx or_Exx) for this block */
  324. walk_info.gpe_block = gpe_block;
  325. walk_info.gpe_device = gpe_device;
  326. walk_info.execute_by_owner_id = FALSE;
  327. status = acpi_ns_walk_namespace(ACPI_TYPE_METHOD, gpe_device,
  328. ACPI_UINT32_MAX, ACPI_NS_WALK_NO_UNLOCK,
  329. acpi_ev_match_gpe_method, NULL,
  330. &walk_info, NULL);
  331. /* Return the new block */
  332. if (return_gpe_block) {
  333. (*return_gpe_block) = gpe_block;
  334. }
  335. ACPI_DEBUG_PRINT((ACPI_DB_INIT,
  336. "GPE %02X to %02X [%4.4s] %u regs on int 0x%X\n",
  337. (u32) gpe_block->block_base_number,
  338. (u32) (gpe_block->block_base_number +
  339. (gpe_block->gpe_count - 1)),
  340. gpe_device->name.ascii, gpe_block->register_count,
  341. interrupt_number));
  342. /* Update global count of currently available GPEs */
  343. acpi_current_gpe_count += gpe_block->gpe_count;
  344. return_ACPI_STATUS(AE_OK);
  345. }
  346. /*******************************************************************************
  347. *
  348. * FUNCTION: acpi_ev_initialize_gpe_block
  349. *
  350. * PARAMETERS: acpi_gpe_callback
  351. *
  352. * RETURN: Status
  353. *
  354. * DESCRIPTION: Initialize and enable a GPE block. Enable GPEs that have
  355. * associated methods.
  356. * Note: Assumes namespace is locked.
  357. *
  358. ******************************************************************************/
  359. acpi_status
  360. acpi_ev_initialize_gpe_block(struct acpi_gpe_xrupt_info *gpe_xrupt_info,
  361. struct acpi_gpe_block_info *gpe_block,
  362. void *ignored)
  363. {
  364. acpi_status status;
  365. struct acpi_gpe_event_info *gpe_event_info;
  366. u32 gpe_enabled_count;
  367. u32 gpe_index;
  368. u32 i;
  369. u32 j;
  370. ACPI_FUNCTION_TRACE(ev_initialize_gpe_block);
  371. /*
  372. * Ignore a null GPE block (e.g., if no GPE block 1 exists), and
  373. * any GPE blocks that have been initialized already.
  374. */
  375. if (!gpe_block || gpe_block->initialized) {
  376. return_ACPI_STATUS(AE_OK);
  377. }
  378. /*
  379. * Enable all GPEs that have a corresponding method and have the
  380. * ACPI_GPE_CAN_WAKE flag unset. Any other GPEs within this block
  381. * must be enabled via the acpi_enable_gpe() interface.
  382. */
  383. gpe_enabled_count = 0;
  384. for (i = 0; i < gpe_block->register_count; i++) {
  385. for (j = 0; j < ACPI_GPE_REGISTER_WIDTH; j++) {
  386. /* Get the info block for this particular GPE */
  387. gpe_index = (i * ACPI_GPE_REGISTER_WIDTH) + j;
  388. gpe_event_info = &gpe_block->event_info[gpe_index];
  389. /*
  390. * Ignore GPEs that have no corresponding _Lxx/_Exx method
  391. * and GPEs that are used to wake the system
  392. */
  393. if (((gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) ==
  394. ACPI_GPE_DISPATCH_NONE)
  395. || ((gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK)
  396. == ACPI_GPE_DISPATCH_HANDLER)
  397. || (gpe_event_info->flags & ACPI_GPE_CAN_WAKE)) {
  398. continue;
  399. }
  400. status = acpi_ev_add_gpe_reference(gpe_event_info);
  401. if (ACPI_FAILURE(status)) {
  402. ACPI_EXCEPTION((AE_INFO, status,
  403. "Could not enable GPE 0x%02X",
  404. gpe_index + gpe_block->block_base_number));
  405. continue;
  406. }
  407. gpe_enabled_count++;
  408. }
  409. }
  410. if (gpe_enabled_count) {
  411. ACPI_DEBUG_PRINT((ACPI_DB_INIT,
  412. "Enabled %u GPEs in this block\n",
  413. gpe_enabled_count));
  414. }
  415. gpe_block->initialized = TRUE;
  416. return_ACPI_STATUS(AE_OK);
  417. }
  418. #endif /* !ACPI_REDUCED_HARDWARE */