evregion.c 23 KB

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