evregion.c 22 KB

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