evregion.c 22 KB

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