evregion.c 22 KB

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