evregion.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858
  1. /******************************************************************************
  2. *
  3. * Module Name: evregion - Operation Region support
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2016, 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("evregion")
  49. extern u8 acpi_gbl_default_address_spaces[];
  50. /* Local prototypes */
  51. static void
  52. acpi_ev_orphan_ec_reg_method(struct acpi_namespace_node *ec_device_node);
  53. static acpi_status
  54. acpi_ev_reg_run(acpi_handle obj_handle,
  55. u32 level, void *context, void **return_value);
  56. /*******************************************************************************
  57. *
  58. * FUNCTION: acpi_ev_initialize_op_regions
  59. *
  60. * PARAMETERS: None
  61. *
  62. * RETURN: Status
  63. *
  64. * DESCRIPTION: Execute _REG methods for all Operation Regions that have
  65. * an installed default region handler.
  66. *
  67. ******************************************************************************/
  68. acpi_status acpi_ev_initialize_op_regions(void)
  69. {
  70. acpi_status status;
  71. u32 i;
  72. ACPI_FUNCTION_TRACE(ev_initialize_op_regions);
  73. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  74. if (ACPI_FAILURE(status)) {
  75. return_ACPI_STATUS(status);
  76. }
  77. /* Run the _REG methods for op_regions in each default address space */
  78. for (i = 0; i < ACPI_NUM_DEFAULT_SPACES; i++) {
  79. /*
  80. * Make sure the installed handler is the DEFAULT handler. If not the
  81. * default, the _REG methods will have already been run (when the
  82. * handler was installed)
  83. */
  84. if (acpi_ev_has_default_handler(acpi_gbl_root_node,
  85. acpi_gbl_default_address_spaces
  86. [i])) {
  87. acpi_ev_execute_reg_methods(acpi_gbl_root_node,
  88. acpi_gbl_default_address_spaces
  89. [i], ACPI_REG_CONNECT);
  90. }
  91. }
  92. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  93. return_ACPI_STATUS(status);
  94. }
  95. /*******************************************************************************
  96. *
  97. * FUNCTION: acpi_ev_address_space_dispatch
  98. *
  99. * PARAMETERS: region_obj - Internal region object
  100. * field_obj - Corresponding field. Can be NULL.
  101. * function - Read or Write operation
  102. * region_offset - Where in the region to read or write
  103. * bit_width - Field width in bits (8, 16, 32, or 64)
  104. * value - Pointer to in or out value, must be
  105. * a full 64-bit integer
  106. *
  107. * RETURN: Status
  108. *
  109. * DESCRIPTION: Dispatch an address space or operation region access to
  110. * a previously installed handler.
  111. *
  112. * NOTE: During early initialization, we always install the default region
  113. * handlers for Memory, I/O and PCI_Config. This ensures that these operation
  114. * region address spaces are always available as per the ACPI specification.
  115. * This is especially needed in order to support the execution of
  116. * module-level AML code during loading of the ACPI tables.
  117. *
  118. ******************************************************************************/
  119. acpi_status
  120. acpi_ev_address_space_dispatch(union acpi_operand_object *region_obj,
  121. union acpi_operand_object *field_obj,
  122. u32 function,
  123. u32 region_offset, u32 bit_width, u64 *value)
  124. {
  125. acpi_status status;
  126. acpi_adr_space_handler handler;
  127. acpi_adr_space_setup region_setup;
  128. union acpi_operand_object *handler_desc;
  129. union acpi_operand_object *region_obj2;
  130. void *region_context = NULL;
  131. struct acpi_connection_info *context;
  132. acpi_physical_address address;
  133. ACPI_FUNCTION_TRACE(ev_address_space_dispatch);
  134. region_obj2 = acpi_ns_get_secondary_object(region_obj);
  135. if (!region_obj2) {
  136. return_ACPI_STATUS(AE_NOT_EXIST);
  137. }
  138. /* Ensure that there is a handler associated with this region */
  139. handler_desc = region_obj->region.handler;
  140. if (!handler_desc) {
  141. ACPI_ERROR((AE_INFO,
  142. "No handler for Region [%4.4s] (%p) [%s]",
  143. acpi_ut_get_node_name(region_obj->region.node),
  144. region_obj,
  145. acpi_ut_get_region_name(region_obj->region.
  146. space_id)));
  147. return_ACPI_STATUS(AE_NOT_EXIST);
  148. }
  149. context = handler_desc->address_space.context;
  150. /*
  151. * It may be the case that the region has never been initialized.
  152. * Some types of regions require special init code
  153. */
  154. if (!(region_obj->region.flags & AOPOBJ_SETUP_COMPLETE)) {
  155. /* This region has not been initialized yet, do it */
  156. region_setup = handler_desc->address_space.setup;
  157. if (!region_setup) {
  158. /* No initialization routine, exit with error */
  159. ACPI_ERROR((AE_INFO,
  160. "No init routine for region(%p) [%s]",
  161. region_obj,
  162. acpi_ut_get_region_name(region_obj->region.
  163. space_id)));
  164. return_ACPI_STATUS(AE_NOT_EXIST);
  165. }
  166. /*
  167. * We must exit the interpreter because the region setup will
  168. * potentially execute control methods (for example, the _REG method
  169. * for this region)
  170. */
  171. acpi_ex_exit_interpreter();
  172. status = region_setup(region_obj, ACPI_REGION_ACTIVATE,
  173. context, &region_context);
  174. /* Re-enter the interpreter */
  175. acpi_ex_enter_interpreter();
  176. /* Check for failure of the Region Setup */
  177. if (ACPI_FAILURE(status)) {
  178. ACPI_EXCEPTION((AE_INFO, status,
  179. "During region initialization: [%s]",
  180. acpi_ut_get_region_name(region_obj->
  181. region.
  182. space_id)));
  183. return_ACPI_STATUS(status);
  184. }
  185. /* Region initialization may have been completed by region_setup */
  186. if (!(region_obj->region.flags & AOPOBJ_SETUP_COMPLETE)) {
  187. region_obj->region.flags |= AOPOBJ_SETUP_COMPLETE;
  188. /*
  189. * Save the returned context for use in all accesses to
  190. * the handler for this particular region
  191. */
  192. if (!(region_obj2->extra.region_context)) {
  193. region_obj2->extra.region_context =
  194. region_context;
  195. }
  196. }
  197. }
  198. /* We have everything we need, we can invoke the address space handler */
  199. handler = handler_desc->address_space.handler;
  200. address = (region_obj->region.address + region_offset);
  201. /*
  202. * Special handling for generic_serial_bus and general_purpose_io:
  203. * There are three extra parameters that must be passed to the
  204. * handler via the context:
  205. * 1) Connection buffer, a resource template from Connection() op
  206. * 2) Length of the above buffer
  207. * 3) Actual access length from the access_as() op
  208. *
  209. * In addition, for general_purpose_io, the Address and bit_width fields
  210. * are defined as follows:
  211. * 1) Address is the pin number index of the field (bit offset from
  212. * the previous Connection)
  213. * 2) bit_width is the actual bit length of the field (number of pins)
  214. */
  215. if ((region_obj->region.space_id == ACPI_ADR_SPACE_GSBUS) &&
  216. context && field_obj) {
  217. /* Get the Connection (resource_template) buffer */
  218. context->connection = field_obj->field.resource_buffer;
  219. context->length = field_obj->field.resource_length;
  220. context->access_length = field_obj->field.access_length;
  221. }
  222. if ((region_obj->region.space_id == ACPI_ADR_SPACE_GPIO) &&
  223. context && field_obj) {
  224. /* Get the Connection (resource_template) buffer */
  225. context->connection = field_obj->field.resource_buffer;
  226. context->length = field_obj->field.resource_length;
  227. context->access_length = field_obj->field.access_length;
  228. address = field_obj->field.pin_number_index;
  229. bit_width = field_obj->field.bit_length;
  230. }
  231. ACPI_DEBUG_PRINT((ACPI_DB_OPREGION,
  232. "Handler %p (@%p) Address %8.8X%8.8X [%s]\n",
  233. &region_obj->region.handler->address_space, handler,
  234. ACPI_FORMAT_UINT64(address),
  235. acpi_ut_get_region_name(region_obj->region.
  236. space_id)));
  237. if (!(handler_desc->address_space.handler_flags &
  238. ACPI_ADDR_HANDLER_DEFAULT_INSTALLED)) {
  239. /*
  240. * For handlers other than the default (supplied) handlers, we must
  241. * exit the interpreter because the handler *might* block -- we don't
  242. * know what it will do, so we can't hold the lock on the intepreter.
  243. */
  244. acpi_ex_exit_interpreter();
  245. }
  246. /* Call the handler */
  247. status = handler(function, address, bit_width, value, context,
  248. region_obj2->extra.region_context);
  249. if (ACPI_FAILURE(status)) {
  250. ACPI_EXCEPTION((AE_INFO, status, "Returned by Handler for [%s]",
  251. acpi_ut_get_region_name(region_obj->region.
  252. space_id)));
  253. }
  254. if (!(handler_desc->address_space.handler_flags &
  255. ACPI_ADDR_HANDLER_DEFAULT_INSTALLED)) {
  256. /*
  257. * We just returned from a non-default handler, we must re-enter the
  258. * interpreter
  259. */
  260. acpi_ex_enter_interpreter();
  261. }
  262. return_ACPI_STATUS(status);
  263. }
  264. /*******************************************************************************
  265. *
  266. * FUNCTION: acpi_ev_detach_region
  267. *
  268. * PARAMETERS: region_obj - Region Object
  269. * acpi_ns_is_locked - Namespace Region Already Locked?
  270. *
  271. * RETURN: None
  272. *
  273. * DESCRIPTION: Break the association between the handler and the region
  274. * this is a two way association.
  275. *
  276. ******************************************************************************/
  277. void
  278. acpi_ev_detach_region(union acpi_operand_object *region_obj,
  279. u8 acpi_ns_is_locked)
  280. {
  281. union acpi_operand_object *handler_obj;
  282. union acpi_operand_object *obj_desc;
  283. union acpi_operand_object *start_desc;
  284. union acpi_operand_object **last_obj_ptr;
  285. acpi_adr_space_setup region_setup;
  286. void **region_context;
  287. union acpi_operand_object *region_obj2;
  288. acpi_status status;
  289. ACPI_FUNCTION_TRACE(ev_detach_region);
  290. region_obj2 = acpi_ns_get_secondary_object(region_obj);
  291. if (!region_obj2) {
  292. return_VOID;
  293. }
  294. region_context = &region_obj2->extra.region_context;
  295. /* Get the address handler from the region object */
  296. handler_obj = region_obj->region.handler;
  297. if (!handler_obj) {
  298. /* This region has no handler, all done */
  299. return_VOID;
  300. }
  301. /* Find this region in the handler's list */
  302. obj_desc = handler_obj->address_space.region_list;
  303. start_desc = obj_desc;
  304. last_obj_ptr = &handler_obj->address_space.region_list;
  305. while (obj_desc) {
  306. /* Is this the correct Region? */
  307. if (obj_desc == region_obj) {
  308. ACPI_DEBUG_PRINT((ACPI_DB_OPREGION,
  309. "Removing Region %p from address handler %p\n",
  310. region_obj, handler_obj));
  311. /* This is it, remove it from the handler's list */
  312. *last_obj_ptr = obj_desc->region.next;
  313. obj_desc->region.next = NULL; /* Must clear field */
  314. if (acpi_ns_is_locked) {
  315. status =
  316. acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  317. if (ACPI_FAILURE(status)) {
  318. return_VOID;
  319. }
  320. }
  321. /* Now stop region accesses by executing the _REG method */
  322. status =
  323. acpi_ev_execute_reg_method(region_obj,
  324. ACPI_REG_DISCONNECT);
  325. if (ACPI_FAILURE(status)) {
  326. ACPI_EXCEPTION((AE_INFO, status,
  327. "from region _REG, [%s]",
  328. acpi_ut_get_region_name
  329. (region_obj->region.space_id)));
  330. }
  331. if (acpi_ns_is_locked) {
  332. status =
  333. acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  334. if (ACPI_FAILURE(status)) {
  335. return_VOID;
  336. }
  337. }
  338. /*
  339. * If the region has been activated, call the setup handler with
  340. * the deactivate notification
  341. */
  342. if (region_obj->region.flags & AOPOBJ_SETUP_COMPLETE) {
  343. region_setup = handler_obj->address_space.setup;
  344. status =
  345. region_setup(region_obj,
  346. ACPI_REGION_DEACTIVATE,
  347. handler_obj->address_space.
  348. context, region_context);
  349. /*
  350. * region_context should have been released by the deactivate
  351. * operation. We don't need access to it anymore here.
  352. */
  353. if (region_context) {
  354. *region_context = NULL;
  355. }
  356. /* Init routine may fail, Just ignore errors */
  357. if (ACPI_FAILURE(status)) {
  358. ACPI_EXCEPTION((AE_INFO, status,
  359. "from region handler - deactivate, [%s]",
  360. acpi_ut_get_region_name
  361. (region_obj->region.
  362. space_id)));
  363. }
  364. region_obj->region.flags &=
  365. ~(AOPOBJ_SETUP_COMPLETE);
  366. }
  367. /*
  368. * Remove handler reference in the region
  369. *
  370. * NOTE: this doesn't mean that the region goes away, the region
  371. * is just inaccessible as indicated to the _REG method
  372. *
  373. * If the region is on the handler's list, this must be the
  374. * region's handler
  375. */
  376. region_obj->region.handler = NULL;
  377. acpi_ut_remove_reference(handler_obj);
  378. return_VOID;
  379. }
  380. /* Walk the linked list of handlers */
  381. last_obj_ptr = &obj_desc->region.next;
  382. obj_desc = obj_desc->region.next;
  383. /* Prevent infinite loop if list is corrupted */
  384. if (obj_desc == start_desc) {
  385. ACPI_ERROR((AE_INFO,
  386. "Circular handler list in region object %p",
  387. region_obj));
  388. return_VOID;
  389. }
  390. }
  391. /* If we get here, the region was not in the handler's region list */
  392. ACPI_DEBUG_PRINT((ACPI_DB_OPREGION,
  393. "Cannot remove region %p from address handler %p\n",
  394. region_obj, handler_obj));
  395. return_VOID;
  396. }
  397. /*******************************************************************************
  398. *
  399. * FUNCTION: acpi_ev_attach_region
  400. *
  401. * PARAMETERS: handler_obj - Handler Object
  402. * region_obj - Region Object
  403. * acpi_ns_is_locked - Namespace Region Already Locked?
  404. *
  405. * RETURN: None
  406. *
  407. * DESCRIPTION: Create the association between the handler and the region
  408. * this is a two way association.
  409. *
  410. ******************************************************************************/
  411. acpi_status
  412. acpi_ev_attach_region(union acpi_operand_object *handler_obj,
  413. union acpi_operand_object *region_obj,
  414. u8 acpi_ns_is_locked)
  415. {
  416. ACPI_FUNCTION_TRACE(ev_attach_region);
  417. /* Install the region's handler */
  418. if (region_obj->region.handler) {
  419. return_ACPI_STATUS(AE_ALREADY_EXISTS);
  420. }
  421. ACPI_DEBUG_PRINT((ACPI_DB_OPREGION,
  422. "Adding Region [%4.4s] %p to address handler %p [%s]\n",
  423. acpi_ut_get_node_name(region_obj->region.node),
  424. region_obj, handler_obj,
  425. acpi_ut_get_region_name(region_obj->region.
  426. space_id)));
  427. /* Link this region to the front of the handler's list */
  428. region_obj->region.next = handler_obj->address_space.region_list;
  429. handler_obj->address_space.region_list = region_obj;
  430. region_obj->region.handler = handler_obj;
  431. acpi_ut_add_reference(handler_obj);
  432. return_ACPI_STATUS(AE_OK);
  433. }
  434. /*******************************************************************************
  435. *
  436. * FUNCTION: acpi_ev_execute_reg_method
  437. *
  438. * PARAMETERS: region_obj - Region object
  439. * function - Passed to _REG: On (1) or Off (0)
  440. *
  441. * RETURN: Status
  442. *
  443. * DESCRIPTION: Execute _REG method for a region
  444. *
  445. ******************************************************************************/
  446. acpi_status
  447. acpi_ev_execute_reg_method(union acpi_operand_object *region_obj, u32 function)
  448. {
  449. struct acpi_evaluate_info *info;
  450. union acpi_operand_object *args[3];
  451. union acpi_operand_object *region_obj2;
  452. const acpi_name *reg_name_ptr =
  453. ACPI_CAST_PTR(acpi_name, METHOD_NAME__REG);
  454. struct acpi_namespace_node *method_node;
  455. struct acpi_namespace_node *node;
  456. acpi_status status;
  457. ACPI_FUNCTION_TRACE(ev_execute_reg_method);
  458. if (!acpi_gbl_namespace_initialized ||
  459. region_obj->region.handler == NULL) {
  460. return_ACPI_STATUS(AE_OK);
  461. }
  462. region_obj2 = acpi_ns_get_secondary_object(region_obj);
  463. if (!region_obj2) {
  464. return_ACPI_STATUS(AE_NOT_EXIST);
  465. }
  466. /*
  467. * Find any "_REG" method associated with this region definition.
  468. * The method should always be updated as this function may be
  469. * invoked after a namespace change.
  470. */
  471. node = region_obj->region.node->parent;
  472. status =
  473. acpi_ns_search_one_scope(*reg_name_ptr, node, ACPI_TYPE_METHOD,
  474. &method_node);
  475. if (ACPI_SUCCESS(status)) {
  476. /*
  477. * The _REG method is optional and there can be only one per
  478. * region definition. This will be executed when the handler is
  479. * attached or removed.
  480. */
  481. region_obj2->extra.method_REG = method_node;
  482. }
  483. if (region_obj2->extra.method_REG == NULL) {
  484. return_ACPI_STATUS(AE_OK);
  485. }
  486. /* _REG(DISCONNECT) should be paired with _REG(CONNECT) */
  487. if ((function == ACPI_REG_CONNECT &&
  488. region_obj->common.flags & AOPOBJ_REG_CONNECTED) ||
  489. (function == ACPI_REG_DISCONNECT &&
  490. !(region_obj->common.flags & AOPOBJ_REG_CONNECTED))) {
  491. return_ACPI_STATUS(AE_OK);
  492. }
  493. /* Allocate and initialize the evaluation information block */
  494. info = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_evaluate_info));
  495. if (!info) {
  496. return_ACPI_STATUS(AE_NO_MEMORY);
  497. }
  498. info->prefix_node = region_obj2->extra.method_REG;
  499. info->relative_pathname = NULL;
  500. info->parameters = args;
  501. info->flags = ACPI_IGNORE_RETURN_VALUE;
  502. /*
  503. * The _REG method has two arguments:
  504. *
  505. * arg0 - Integer:
  506. * Operation region space ID Same value as region_obj->Region.space_id
  507. *
  508. * arg1 - Integer:
  509. * connection status 1 for connecting the handler, 0 for disconnecting
  510. * the handler (Passed as a parameter)
  511. */
  512. args[0] =
  513. acpi_ut_create_integer_object((u64)region_obj->region.space_id);
  514. if (!args[0]) {
  515. status = AE_NO_MEMORY;
  516. goto cleanup1;
  517. }
  518. args[1] = acpi_ut_create_integer_object((u64)function);
  519. if (!args[1]) {
  520. status = AE_NO_MEMORY;
  521. goto cleanup2;
  522. }
  523. args[2] = NULL; /* Terminate list */
  524. /* Execute the method, no return value */
  525. ACPI_DEBUG_EXEC(acpi_ut_display_init_pathname
  526. (ACPI_TYPE_METHOD, info->prefix_node, NULL));
  527. status = acpi_ns_evaluate(info);
  528. acpi_ut_remove_reference(args[1]);
  529. if (ACPI_FAILURE(status)) {
  530. goto cleanup2;
  531. }
  532. if (function == ACPI_REG_CONNECT) {
  533. region_obj->common.flags |= AOPOBJ_REG_CONNECTED;
  534. } else {
  535. region_obj->common.flags &= ~AOPOBJ_REG_CONNECTED;
  536. }
  537. cleanup2:
  538. acpi_ut_remove_reference(args[0]);
  539. cleanup1:
  540. ACPI_FREE(info);
  541. return_ACPI_STATUS(status);
  542. }
  543. /*******************************************************************************
  544. *
  545. * FUNCTION: acpi_ev_execute_reg_methods
  546. *
  547. * PARAMETERS: node - Namespace node for the device
  548. * space_id - The address space ID
  549. * function - Passed to _REG: On (1) or Off (0)
  550. *
  551. * RETURN: None
  552. *
  553. * DESCRIPTION: Run all _REG methods for the input Space ID;
  554. * Note: assumes namespace is locked, or system init time.
  555. *
  556. ******************************************************************************/
  557. void
  558. acpi_ev_execute_reg_methods(struct acpi_namespace_node *node,
  559. acpi_adr_space_type space_id, u32 function)
  560. {
  561. struct acpi_reg_walk_info info;
  562. ACPI_FUNCTION_TRACE(ev_execute_reg_methods);
  563. info.space_id = space_id;
  564. info.function = function;
  565. info.reg_run_count = 0;
  566. ACPI_DEBUG_PRINT_RAW((ACPI_DB_NAMES,
  567. " Running _REG methods for SpaceId %s\n",
  568. acpi_ut_get_region_name(info.space_id)));
  569. /*
  570. * Run all _REG methods for all Operation Regions for this space ID. This
  571. * is a separate walk in order to handle any interdependencies between
  572. * regions and _REG methods. (i.e. handlers must be installed for all
  573. * regions of this Space ID before we can run any _REG methods)
  574. */
  575. (void)acpi_ns_walk_namespace(ACPI_TYPE_ANY, node, ACPI_UINT32_MAX,
  576. ACPI_NS_WALK_UNLOCK, acpi_ev_reg_run, NULL,
  577. &info, NULL);
  578. /* Special case for EC: handle "orphan" _REG methods with no region */
  579. if (space_id == ACPI_ADR_SPACE_EC) {
  580. acpi_ev_orphan_ec_reg_method(node);
  581. }
  582. ACPI_DEBUG_PRINT_RAW((ACPI_DB_NAMES,
  583. " Executed %u _REG methods for SpaceId %s\n",
  584. info.reg_run_count,
  585. acpi_ut_get_region_name(info.space_id)));
  586. return_VOID;
  587. }
  588. /*******************************************************************************
  589. *
  590. * FUNCTION: acpi_ev_reg_run
  591. *
  592. * PARAMETERS: walk_namespace callback
  593. *
  594. * DESCRIPTION: Run _REG method for region objects of the requested spaceID
  595. *
  596. ******************************************************************************/
  597. static acpi_status
  598. acpi_ev_reg_run(acpi_handle obj_handle,
  599. u32 level, void *context, void **return_value)
  600. {
  601. union acpi_operand_object *obj_desc;
  602. struct acpi_namespace_node *node;
  603. acpi_status status;
  604. struct acpi_reg_walk_info *info;
  605. info = ACPI_CAST_PTR(struct acpi_reg_walk_info, context);
  606. /* Convert and validate the device handle */
  607. node = acpi_ns_validate_handle(obj_handle);
  608. if (!node) {
  609. return (AE_BAD_PARAMETER);
  610. }
  611. /*
  612. * We only care about regions.and objects that are allowed to have address
  613. * space handlers
  614. */
  615. if ((node->type != ACPI_TYPE_REGION) && (node != acpi_gbl_root_node)) {
  616. return (AE_OK);
  617. }
  618. /* Check for an existing internal object */
  619. obj_desc = acpi_ns_get_attached_object(node);
  620. if (!obj_desc) {
  621. /* No object, just exit */
  622. return (AE_OK);
  623. }
  624. /* Object is a Region */
  625. if (obj_desc->region.space_id != info->space_id) {
  626. /* This region is for a different address space, just ignore it */
  627. return (AE_OK);
  628. }
  629. info->reg_run_count++;
  630. status = acpi_ev_execute_reg_method(obj_desc, info->function);
  631. return (status);
  632. }
  633. /*******************************************************************************
  634. *
  635. * FUNCTION: acpi_ev_orphan_ec_reg_method
  636. *
  637. * PARAMETERS: ec_device_node - Namespace node for an EC device
  638. *
  639. * RETURN: None
  640. *
  641. * DESCRIPTION: Execute an "orphan" _REG method that appears under the EC
  642. * device. This is a _REG method that has no corresponding region
  643. * within the EC device scope. The orphan _REG method appears to
  644. * have been enabled by the description of the ECDT in the ACPI
  645. * specification: "The availability of the region space can be
  646. * detected by providing a _REG method object underneath the
  647. * Embedded Controller device."
  648. *
  649. * To quickly access the EC device, we use the ec_device_node used
  650. * during EC handler installation. Otherwise, we would need to
  651. * perform a time consuming namespace walk, executing _HID
  652. * methods to find the EC device.
  653. *
  654. * MUTEX: Assumes the namespace is locked
  655. *
  656. ******************************************************************************/
  657. static void
  658. acpi_ev_orphan_ec_reg_method(struct acpi_namespace_node *ec_device_node)
  659. {
  660. acpi_handle reg_method;
  661. struct acpi_namespace_node *next_node;
  662. acpi_status status;
  663. struct acpi_object_list args;
  664. union acpi_object objects[2];
  665. ACPI_FUNCTION_TRACE(ev_orphan_ec_reg_method);
  666. if (!ec_device_node) {
  667. return_VOID;
  668. }
  669. /* Namespace is currently locked, must release */
  670. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  671. /* Get a handle to a _REG method immediately under the EC device */
  672. status = acpi_get_handle(ec_device_node, METHOD_NAME__REG, &reg_method);
  673. if (ACPI_FAILURE(status)) {
  674. goto exit; /* There is no _REG method present */
  675. }
  676. /*
  677. * Execute the _REG method only if there is no Operation Region in
  678. * this scope with the Embedded Controller space ID. Otherwise, it
  679. * will already have been executed. Note, this allows for Regions
  680. * with other space IDs to be present; but the code below will then
  681. * execute the _REG method with the embedded_control space_ID argument.
  682. */
  683. next_node = acpi_ns_get_next_node(ec_device_node, NULL);
  684. while (next_node) {
  685. if ((next_node->type == ACPI_TYPE_REGION) &&
  686. (next_node->object) &&
  687. (next_node->object->region.space_id == ACPI_ADR_SPACE_EC)) {
  688. goto exit; /* Do not execute the _REG */
  689. }
  690. next_node = acpi_ns_get_next_node(ec_device_node, next_node);
  691. }
  692. /* Evaluate the _REG(embedded_control,Connect) method */
  693. args.count = 2;
  694. args.pointer = objects;
  695. objects[0].type = ACPI_TYPE_INTEGER;
  696. objects[0].integer.value = ACPI_ADR_SPACE_EC;
  697. objects[1].type = ACPI_TYPE_INTEGER;
  698. objects[1].integer.value = ACPI_REG_CONNECT;
  699. status = acpi_evaluate_object(reg_method, NULL, &args, NULL);
  700. exit:
  701. /* We ignore all errors from above, don't care */
  702. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  703. return_VOID;
  704. }