evregion.c 22 KB

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