evregion.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873
  1. // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
  2. /******************************************************************************
  3. *
  4. * Module Name: evregion - Operation Region support
  5. *
  6. * Copyright (C) 2000 - 2022, Intel Corp.
  7. *
  8. *****************************************************************************/
  9. #include <acpi/acpi.h>
  10. #include "accommon.h"
  11. #include "acevents.h"
  12. #include "acnamesp.h"
  13. #include "acinterp.h"
  14. #define _COMPONENT ACPI_EVENTS
  15. ACPI_MODULE_NAME("evregion")
  16. extern u8 acpi_gbl_default_address_spaces[];
  17. /* Local prototypes */
  18. static void
  19. acpi_ev_execute_orphan_reg_method(struct acpi_namespace_node *device_node,
  20. acpi_adr_space_type space_id);
  21. static acpi_status
  22. acpi_ev_reg_run(acpi_handle obj_handle,
  23. u32 level, void *context, void **return_value);
  24. /*******************************************************************************
  25. *
  26. * FUNCTION: acpi_ev_initialize_op_regions
  27. *
  28. * PARAMETERS: None
  29. *
  30. * RETURN: Status
  31. *
  32. * DESCRIPTION: Execute _REG methods for all Operation Regions that have
  33. * an installed default region handler.
  34. *
  35. ******************************************************************************/
  36. acpi_status acpi_ev_initialize_op_regions(void)
  37. {
  38. acpi_status status;
  39. u32 i;
  40. ACPI_FUNCTION_TRACE(ev_initialize_op_regions);
  41. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  42. if (ACPI_FAILURE(status)) {
  43. return_ACPI_STATUS(status);
  44. }
  45. /* Run the _REG methods for op_regions in each default address space */
  46. for (i = 0; i < ACPI_NUM_DEFAULT_SPACES; i++) {
  47. /*
  48. * Make sure the installed handler is the DEFAULT handler. If not the
  49. * default, the _REG methods will have already been run (when the
  50. * handler was installed)
  51. */
  52. if (acpi_ev_has_default_handler(acpi_gbl_root_node,
  53. acpi_gbl_default_address_spaces
  54. [i])) {
  55. acpi_ev_execute_reg_methods(acpi_gbl_root_node,
  56. acpi_gbl_default_address_spaces
  57. [i], ACPI_REG_CONNECT);
  58. }
  59. }
  60. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  61. return_ACPI_STATUS(status);
  62. }
  63. /*******************************************************************************
  64. *
  65. * FUNCTION: acpi_ev_address_space_dispatch
  66. *
  67. * PARAMETERS: region_obj - Internal region object
  68. * field_obj - Corresponding field. Can be NULL.
  69. * function - Read or Write operation
  70. * region_offset - Where in the region to read or write
  71. * bit_width - Field width in bits (8, 16, 32, or 64)
  72. * value - Pointer to in or out value, must be
  73. * a full 64-bit integer
  74. *
  75. * RETURN: Status
  76. *
  77. * DESCRIPTION: Dispatch an address space or operation region access to
  78. * a previously installed handler.
  79. *
  80. * NOTE: During early initialization, we always install the default region
  81. * handlers for Memory, I/O and PCI_Config. This ensures that these operation
  82. * region address spaces are always available as per the ACPI specification.
  83. * This is especially needed in order to support the execution of
  84. * module-level AML code during loading of the ACPI tables.
  85. *
  86. ******************************************************************************/
  87. acpi_status
  88. acpi_ev_address_space_dispatch(union acpi_operand_object *region_obj,
  89. union acpi_operand_object *field_obj,
  90. u32 function,
  91. u32 region_offset, u32 bit_width, u64 *value)
  92. {
  93. acpi_status status;
  94. acpi_adr_space_handler handler;
  95. acpi_adr_space_setup region_setup;
  96. union acpi_operand_object *handler_desc;
  97. union acpi_operand_object *region_obj2;
  98. void *region_context = NULL;
  99. struct acpi_connection_info *context;
  100. acpi_mutex context_mutex;
  101. u8 context_locked;
  102. acpi_physical_address address;
  103. ACPI_FUNCTION_TRACE(ev_address_space_dispatch);
  104. region_obj2 = acpi_ns_get_secondary_object(region_obj);
  105. if (!region_obj2) {
  106. return_ACPI_STATUS(AE_NOT_EXIST);
  107. }
  108. /* Ensure that there is a handler associated with this region */
  109. handler_desc = region_obj->region.handler;
  110. if (!handler_desc) {
  111. ACPI_ERROR((AE_INFO,
  112. "No handler for Region [%4.4s] (%p) [%s]",
  113. acpi_ut_get_node_name(region_obj->region.node),
  114. region_obj,
  115. acpi_ut_get_region_name(region_obj->region.
  116. space_id)));
  117. return_ACPI_STATUS(AE_NOT_EXIST);
  118. }
  119. context = handler_desc->address_space.context;
  120. context_mutex = handler_desc->address_space.context_mutex;
  121. context_locked = FALSE;
  122. /*
  123. * It may be the case that the region has never been initialized.
  124. * Some types of regions require special init code
  125. */
  126. if (!(region_obj->region.flags & AOPOBJ_SETUP_COMPLETE)) {
  127. /* This region has not been initialized yet, do it */
  128. region_setup = handler_desc->address_space.setup;
  129. if (!region_setup) {
  130. /* No initialization routine, exit with error */
  131. ACPI_ERROR((AE_INFO,
  132. "No init routine for region(%p) [%s]",
  133. region_obj,
  134. acpi_ut_get_region_name(region_obj->region.
  135. space_id)));
  136. return_ACPI_STATUS(AE_NOT_EXIST);
  137. }
  138. if (region_obj->region.space_id == ACPI_ADR_SPACE_PLATFORM_COMM) {
  139. struct acpi_pcc_info *ctx =
  140. handler_desc->address_space.context;
  141. ctx->internal_buffer =
  142. field_obj->field.internal_pcc_buffer;
  143. ctx->length = (u16)region_obj->region.length;
  144. ctx->subspace_id = (u8)region_obj->region.address;
  145. }
  146. /*
  147. * We must exit the interpreter because the region setup will
  148. * potentially execute control methods (for example, the _REG method
  149. * for this region)
  150. */
  151. acpi_ex_exit_interpreter();
  152. status = region_setup(region_obj, ACPI_REGION_ACTIVATE,
  153. context, &region_context);
  154. /* Re-enter the interpreter */
  155. acpi_ex_enter_interpreter();
  156. /* Check for failure of the Region Setup */
  157. if (ACPI_FAILURE(status)) {
  158. ACPI_EXCEPTION((AE_INFO, status,
  159. "During region initialization: [%s]",
  160. acpi_ut_get_region_name(region_obj->
  161. region.
  162. space_id)));
  163. return_ACPI_STATUS(status);
  164. }
  165. /* Region initialization may have been completed by region_setup */
  166. if (!(region_obj->region.flags & AOPOBJ_SETUP_COMPLETE)) {
  167. region_obj->region.flags |= AOPOBJ_SETUP_COMPLETE;
  168. /*
  169. * Save the returned context for use in all accesses to
  170. * the handler for this particular region
  171. */
  172. if (!(region_obj2->extra.region_context)) {
  173. region_obj2->extra.region_context =
  174. region_context;
  175. }
  176. }
  177. }
  178. /* We have everything we need, we can invoke the address space handler */
  179. handler = handler_desc->address_space.handler;
  180. address = (region_obj->region.address + region_offset);
  181. ACPI_DEBUG_PRINT((ACPI_DB_OPREGION,
  182. "Handler %p (@%p) Address %8.8X%8.8X [%s]\n",
  183. &region_obj->region.handler->address_space, handler,
  184. ACPI_FORMAT_UINT64(address),
  185. acpi_ut_get_region_name(region_obj->region.
  186. space_id)));
  187. if (!(handler_desc->address_space.handler_flags &
  188. ACPI_ADDR_HANDLER_DEFAULT_INSTALLED)) {
  189. /*
  190. * For handlers other than the default (supplied) handlers, we must
  191. * exit the interpreter because the handler *might* block -- we don't
  192. * know what it will do, so we can't hold the lock on the interpreter.
  193. */
  194. acpi_ex_exit_interpreter();
  195. }
  196. /*
  197. * Special handling for generic_serial_bus and general_purpose_io:
  198. * There are three extra parameters that must be passed to the
  199. * handler via the context:
  200. * 1) Connection buffer, a resource template from Connection() op
  201. * 2) Length of the above buffer
  202. * 3) Actual access length from the access_as() op
  203. *
  204. * Since we pass these extra parameters via the context, which is
  205. * shared between threads, we must lock the context to avoid these
  206. * parameters being changed from another thread before the handler
  207. * has completed running.
  208. *
  209. * In addition, for general_purpose_io, the Address and bit_width fields
  210. * are defined as follows:
  211. * 1) Address is the pin number index of the field (bit offset from
  212. * the previous Connection)
  213. * 2) bit_width is the actual bit length of the field (number of pins)
  214. */
  215. if ((region_obj->region.space_id == ACPI_ADR_SPACE_GSBUS ||
  216. region_obj->region.space_id == ACPI_ADR_SPACE_GPIO) &&
  217. context && field_obj) {
  218. status =
  219. acpi_os_acquire_mutex(context_mutex, ACPI_WAIT_FOREVER);
  220. if (ACPI_FAILURE(status)) {
  221. goto re_enter_interpreter;
  222. }
  223. context_locked = TRUE;
  224. /* Get the Connection (resource_template) buffer */
  225. context->connection = field_obj->field.resource_buffer;
  226. context->length = field_obj->field.resource_length;
  227. context->access_length = field_obj->field.access_length;
  228. if (region_obj->region.space_id == ACPI_ADR_SPACE_GPIO) {
  229. address = field_obj->field.pin_number_index;
  230. bit_width = field_obj->field.bit_length;
  231. }
  232. }
  233. /* Call the handler */
  234. status = handler(function, address, bit_width, value, context,
  235. region_obj2->extra.region_context);
  236. if (context_locked) {
  237. acpi_os_release_mutex(context_mutex);
  238. }
  239. if (ACPI_FAILURE(status)) {
  240. ACPI_EXCEPTION((AE_INFO, status, "Returned by Handler for [%s]",
  241. acpi_ut_get_region_name(region_obj->region.
  242. space_id)));
  243. /*
  244. * Special case for an EC timeout. These are seen so frequently
  245. * that an additional error message is helpful
  246. */
  247. if ((region_obj->region.space_id == ACPI_ADR_SPACE_EC) &&
  248. (status == AE_TIME)) {
  249. ACPI_ERROR((AE_INFO,
  250. "Timeout from EC hardware or EC device driver"));
  251. }
  252. }
  253. re_enter_interpreter:
  254. if (!(handler_desc->address_space.handler_flags &
  255. ACPI_ADDR_HANDLER_DEFAULT_INSTALLED)) {
  256. /*
  257. * We just returned from a non-default handler, we must re-enter the
  258. * interpreter
  259. */
  260. acpi_ex_enter_interpreter();
  261. }
  262. return_ACPI_STATUS(status);
  263. }
  264. /*******************************************************************************
  265. *
  266. * FUNCTION: acpi_ev_detach_region
  267. *
  268. * PARAMETERS: region_obj - Region Object
  269. * acpi_ns_is_locked - Namespace Region Already Locked?
  270. *
  271. * RETURN: None
  272. *
  273. * DESCRIPTION: Break the association between the handler and the region
  274. * this is a two way association.
  275. *
  276. ******************************************************************************/
  277. void
  278. acpi_ev_detach_region(union acpi_operand_object *region_obj,
  279. u8 acpi_ns_is_locked)
  280. {
  281. union acpi_operand_object *handler_obj;
  282. union acpi_operand_object *obj_desc;
  283. union acpi_operand_object *start_desc;
  284. union acpi_operand_object **last_obj_ptr;
  285. acpi_adr_space_setup region_setup;
  286. void **region_context;
  287. union acpi_operand_object *region_obj2;
  288. acpi_status status;
  289. ACPI_FUNCTION_TRACE(ev_detach_region);
  290. region_obj2 = acpi_ns_get_secondary_object(region_obj);
  291. if (!region_obj2) {
  292. return_VOID;
  293. }
  294. region_context = &region_obj2->extra.region_context;
  295. /* Get the address handler from the region object */
  296. handler_obj = region_obj->region.handler;
  297. if (!handler_obj) {
  298. /* This region has no handler, all done */
  299. return_VOID;
  300. }
  301. /* Find this region in the handler's list */
  302. obj_desc = handler_obj->address_space.region_list;
  303. start_desc = obj_desc;
  304. last_obj_ptr = &handler_obj->address_space.region_list;
  305. while (obj_desc) {
  306. /* Is this the correct Region? */
  307. if (obj_desc == region_obj) {
  308. ACPI_DEBUG_PRINT((ACPI_DB_OPREGION,
  309. "Removing Region %p from address handler %p\n",
  310. region_obj, handler_obj));
  311. /* This is it, remove it from the handler's list */
  312. *last_obj_ptr = obj_desc->region.next;
  313. obj_desc->region.next = NULL; /* Must clear field */
  314. if (acpi_ns_is_locked) {
  315. status =
  316. acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  317. if (ACPI_FAILURE(status)) {
  318. return_VOID;
  319. }
  320. }
  321. /* Now stop region accesses by executing the _REG method */
  322. status =
  323. acpi_ev_execute_reg_method(region_obj,
  324. ACPI_REG_DISCONNECT);
  325. if (ACPI_FAILURE(status)) {
  326. ACPI_EXCEPTION((AE_INFO, status,
  327. "from region _REG, [%s]",
  328. acpi_ut_get_region_name
  329. (region_obj->region.space_id)));
  330. }
  331. if (acpi_ns_is_locked) {
  332. status =
  333. acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  334. if (ACPI_FAILURE(status)) {
  335. return_VOID;
  336. }
  337. }
  338. /*
  339. * If the region has been activated, call the setup handler with
  340. * the deactivate notification
  341. */
  342. if (region_obj->region.flags & AOPOBJ_SETUP_COMPLETE) {
  343. region_setup = handler_obj->address_space.setup;
  344. status =
  345. region_setup(region_obj,
  346. ACPI_REGION_DEACTIVATE,
  347. handler_obj->address_space.
  348. context, region_context);
  349. /*
  350. * region_context should have been released by the deactivate
  351. * operation. We don't need access to it anymore here.
  352. */
  353. if (region_context) {
  354. *region_context = NULL;
  355. }
  356. /* Init routine may fail, Just ignore errors */
  357. if (ACPI_FAILURE(status)) {
  358. ACPI_EXCEPTION((AE_INFO, status,
  359. "from region handler - deactivate, [%s]",
  360. acpi_ut_get_region_name
  361. (region_obj->region.
  362. space_id)));
  363. }
  364. region_obj->region.flags &=
  365. ~(AOPOBJ_SETUP_COMPLETE);
  366. }
  367. /*
  368. * Remove handler reference in the region
  369. *
  370. * NOTE: this doesn't mean that the region goes away, the region
  371. * is just inaccessible as indicated to the _REG method
  372. *
  373. * If the region is on the handler's list, this must be the
  374. * region's handler
  375. */
  376. region_obj->region.handler = NULL;
  377. acpi_ut_remove_reference(handler_obj);
  378. return_VOID;
  379. }
  380. /* Walk the linked list of handlers */
  381. last_obj_ptr = &obj_desc->region.next;
  382. obj_desc = obj_desc->region.next;
  383. /* Prevent infinite loop if list is corrupted */
  384. if (obj_desc == start_desc) {
  385. ACPI_ERROR((AE_INFO,
  386. "Circular handler list in region object %p",
  387. region_obj));
  388. return_VOID;
  389. }
  390. }
  391. /* If we get here, the region was not in the handler's region list */
  392. ACPI_DEBUG_PRINT((ACPI_DB_OPREGION,
  393. "Cannot remove region %p from address handler %p\n",
  394. region_obj, handler_obj));
  395. return_VOID;
  396. }
  397. /*******************************************************************************
  398. *
  399. * FUNCTION: acpi_ev_attach_region
  400. *
  401. * PARAMETERS: handler_obj - Handler Object
  402. * region_obj - Region Object
  403. * acpi_ns_is_locked - Namespace Region Already Locked?
  404. *
  405. * RETURN: None
  406. *
  407. * DESCRIPTION: Create the association between the handler and the region
  408. * this is a two way association.
  409. *
  410. ******************************************************************************/
  411. acpi_status
  412. acpi_ev_attach_region(union acpi_operand_object *handler_obj,
  413. union acpi_operand_object *region_obj,
  414. u8 acpi_ns_is_locked)
  415. {
  416. ACPI_FUNCTION_TRACE(ev_attach_region);
  417. /* Install the region's handler */
  418. if (region_obj->region.handler) {
  419. return_ACPI_STATUS(AE_ALREADY_EXISTS);
  420. }
  421. ACPI_DEBUG_PRINT((ACPI_DB_OPREGION,
  422. "Adding Region [%4.4s] %p to address handler %p [%s]\n",
  423. acpi_ut_get_node_name(region_obj->region.node),
  424. region_obj, handler_obj,
  425. acpi_ut_get_region_name(region_obj->region.
  426. space_id)));
  427. /* Link this region to the front of the handler's list */
  428. region_obj->region.next = handler_obj->address_space.region_list;
  429. handler_obj->address_space.region_list = region_obj;
  430. region_obj->region.handler = handler_obj;
  431. acpi_ut_add_reference(handler_obj);
  432. return_ACPI_STATUS(AE_OK);
  433. }
  434. /*******************************************************************************
  435. *
  436. * FUNCTION: acpi_ev_execute_reg_method
  437. *
  438. * PARAMETERS: region_obj - Region object
  439. * function - Passed to _REG: On (1) or Off (0)
  440. *
  441. * RETURN: Status
  442. *
  443. * DESCRIPTION: Execute _REG method for a region
  444. *
  445. ******************************************************************************/
  446. acpi_status
  447. acpi_ev_execute_reg_method(union acpi_operand_object *region_obj, u32 function)
  448. {
  449. struct acpi_evaluate_info *info;
  450. union acpi_operand_object *args[3];
  451. union acpi_operand_object *region_obj2;
  452. const acpi_name *reg_name_ptr =
  453. ACPI_CAST_PTR(acpi_name, METHOD_NAME__REG);
  454. struct acpi_namespace_node *method_node;
  455. struct acpi_namespace_node *node;
  456. acpi_status status;
  457. ACPI_FUNCTION_TRACE(ev_execute_reg_method);
  458. if (!acpi_gbl_namespace_initialized ||
  459. region_obj->region.handler == NULL) {
  460. return_ACPI_STATUS(AE_OK);
  461. }
  462. region_obj2 = acpi_ns_get_secondary_object(region_obj);
  463. if (!region_obj2) {
  464. return_ACPI_STATUS(AE_NOT_EXIST);
  465. }
  466. /*
  467. * Find any "_REG" method associated with this region definition.
  468. * The method should always be updated as this function may be
  469. * invoked after a namespace change.
  470. */
  471. node = region_obj->region.node->parent;
  472. status =
  473. acpi_ns_search_one_scope(*reg_name_ptr, node, ACPI_TYPE_METHOD,
  474. &method_node);
  475. if (ACPI_SUCCESS(status)) {
  476. /*
  477. * The _REG method is optional and there can be only one per
  478. * region definition. This will be executed when the handler is
  479. * attached or removed.
  480. */
  481. region_obj2->extra.method_REG = method_node;
  482. }
  483. if (region_obj2->extra.method_REG == NULL) {
  484. return_ACPI_STATUS(AE_OK);
  485. }
  486. /* _REG(DISCONNECT) should be paired with _REG(CONNECT) */
  487. if ((function == ACPI_REG_CONNECT &&
  488. region_obj->common.flags & AOPOBJ_REG_CONNECTED) ||
  489. (function == ACPI_REG_DISCONNECT &&
  490. !(region_obj->common.flags & AOPOBJ_REG_CONNECTED))) {
  491. return_ACPI_STATUS(AE_OK);
  492. }
  493. /* Allocate and initialize the evaluation information block */
  494. info = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_evaluate_info));
  495. if (!info) {
  496. return_ACPI_STATUS(AE_NO_MEMORY);
  497. }
  498. info->prefix_node = region_obj2->extra.method_REG;
  499. info->relative_pathname = NULL;
  500. info->parameters = args;
  501. info->flags = ACPI_IGNORE_RETURN_VALUE;
  502. /*
  503. * The _REG method has two arguments:
  504. *
  505. * arg0 - Integer:
  506. * Operation region space ID Same value as region_obj->Region.space_id
  507. *
  508. * arg1 - Integer:
  509. * connection status 1 for connecting the handler, 0 for disconnecting
  510. * the handler (Passed as a parameter)
  511. */
  512. args[0] =
  513. acpi_ut_create_integer_object((u64)region_obj->region.space_id);
  514. if (!args[0]) {
  515. status = AE_NO_MEMORY;
  516. goto cleanup1;
  517. }
  518. args[1] = acpi_ut_create_integer_object((u64)function);
  519. if (!args[1]) {
  520. status = AE_NO_MEMORY;
  521. goto cleanup2;
  522. }
  523. args[2] = NULL; /* Terminate list */
  524. /* Execute the method, no return value */
  525. ACPI_DEBUG_EXEC(acpi_ut_display_init_pathname
  526. (ACPI_TYPE_METHOD, info->prefix_node, NULL));
  527. status = acpi_ns_evaluate(info);
  528. acpi_ut_remove_reference(args[1]);
  529. if (ACPI_FAILURE(status)) {
  530. goto cleanup2;
  531. }
  532. if (function == ACPI_REG_CONNECT) {
  533. region_obj->common.flags |= AOPOBJ_REG_CONNECTED;
  534. } else {
  535. region_obj->common.flags &= ~AOPOBJ_REG_CONNECTED;
  536. }
  537. cleanup2:
  538. acpi_ut_remove_reference(args[0]);
  539. cleanup1:
  540. ACPI_FREE(info);
  541. return_ACPI_STATUS(status);
  542. }
  543. /*******************************************************************************
  544. *
  545. * FUNCTION: acpi_ev_execute_reg_methods
  546. *
  547. * PARAMETERS: node - Namespace node for the device
  548. * space_id - The address space ID
  549. * function - Passed to _REG: On (1) or Off (0)
  550. *
  551. * RETURN: None
  552. *
  553. * DESCRIPTION: Run all _REG methods for the input Space ID;
  554. * Note: assumes namespace is locked, or system init time.
  555. *
  556. ******************************************************************************/
  557. void
  558. acpi_ev_execute_reg_methods(struct acpi_namespace_node *node,
  559. acpi_adr_space_type space_id, u32 function)
  560. {
  561. struct acpi_reg_walk_info info;
  562. ACPI_FUNCTION_TRACE(ev_execute_reg_methods);
  563. /*
  564. * These address spaces do not need a call to _REG, since the ACPI
  565. * specification defines them as: "must always be accessible". Since
  566. * they never change state (never become unavailable), no need to ever
  567. * call _REG on them. Also, a data_table is not a "real" address space,
  568. * so do not call _REG. September 2018.
  569. */
  570. if ((space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) ||
  571. (space_id == ACPI_ADR_SPACE_SYSTEM_IO) ||
  572. (space_id == ACPI_ADR_SPACE_DATA_TABLE)) {
  573. return_VOID;
  574. }
  575. info.space_id = space_id;
  576. info.function = function;
  577. info.reg_run_count = 0;
  578. ACPI_DEBUG_PRINT_RAW((ACPI_DB_NAMES,
  579. " Running _REG methods for SpaceId %s\n",
  580. acpi_ut_get_region_name(info.space_id)));
  581. /*
  582. * Run all _REG methods for all Operation Regions for this space ID. This
  583. * is a separate walk in order to handle any interdependencies between
  584. * regions and _REG methods. (i.e. handlers must be installed for all
  585. * regions of this Space ID before we can run any _REG methods)
  586. */
  587. (void)acpi_ns_walk_namespace(ACPI_TYPE_ANY, node, ACPI_UINT32_MAX,
  588. ACPI_NS_WALK_UNLOCK, acpi_ev_reg_run, NULL,
  589. &info, NULL);
  590. /*
  591. * Special case for EC and GPIO: handle "orphan" _REG methods with
  592. * no region.
  593. */
  594. if (space_id == ACPI_ADR_SPACE_EC || space_id == ACPI_ADR_SPACE_GPIO) {
  595. acpi_ev_execute_orphan_reg_method(node, space_id);
  596. }
  597. ACPI_DEBUG_PRINT_RAW((ACPI_DB_NAMES,
  598. " Executed %u _REG methods for SpaceId %s\n",
  599. info.reg_run_count,
  600. acpi_ut_get_region_name(info.space_id)));
  601. return_VOID;
  602. }
  603. /*******************************************************************************
  604. *
  605. * FUNCTION: acpi_ev_reg_run
  606. *
  607. * PARAMETERS: walk_namespace callback
  608. *
  609. * DESCRIPTION: Run _REG method for region objects of the requested spaceID
  610. *
  611. ******************************************************************************/
  612. static acpi_status
  613. acpi_ev_reg_run(acpi_handle obj_handle,
  614. u32 level, void *context, void **return_value)
  615. {
  616. union acpi_operand_object *obj_desc;
  617. struct acpi_namespace_node *node;
  618. acpi_status status;
  619. struct acpi_reg_walk_info *info;
  620. info = ACPI_CAST_PTR(struct acpi_reg_walk_info, context);
  621. /* Convert and validate the device handle */
  622. node = acpi_ns_validate_handle(obj_handle);
  623. if (!node) {
  624. return (AE_BAD_PARAMETER);
  625. }
  626. /*
  627. * We only care about regions and objects that are allowed to have
  628. * address space handlers
  629. */
  630. if ((node->type != ACPI_TYPE_REGION) && (node != acpi_gbl_root_node)) {
  631. return (AE_OK);
  632. }
  633. /* Check for an existing internal object */
  634. obj_desc = acpi_ns_get_attached_object(node);
  635. if (!obj_desc) {
  636. /* No object, just exit */
  637. return (AE_OK);
  638. }
  639. /* Object is a Region */
  640. if (obj_desc->region.space_id != info->space_id) {
  641. /* This region is for a different address space, just ignore it */
  642. return (AE_OK);
  643. }
  644. info->reg_run_count++;
  645. status = acpi_ev_execute_reg_method(obj_desc, info->function);
  646. return (status);
  647. }
  648. /*******************************************************************************
  649. *
  650. * FUNCTION: acpi_ev_execute_orphan_reg_method
  651. *
  652. * PARAMETERS: device_node - Namespace node for an ACPI device
  653. * space_id - The address space ID
  654. *
  655. * RETURN: None
  656. *
  657. * DESCRIPTION: Execute an "orphan" _REG method that appears under an ACPI
  658. * device. This is a _REG method that has no corresponding region
  659. * within the device's scope. ACPI tables depending on these
  660. * "orphan" _REG methods have been seen for both EC and GPIO
  661. * Operation Regions. Presumably the Windows ACPI implementation
  662. * always calls the _REG method independent of the presence of
  663. * an actual Operation Region with the correct address space ID.
  664. *
  665. * MUTEX: Assumes the namespace is locked
  666. *
  667. ******************************************************************************/
  668. static void
  669. acpi_ev_execute_orphan_reg_method(struct acpi_namespace_node *device_node,
  670. acpi_adr_space_type space_id)
  671. {
  672. acpi_handle reg_method;
  673. struct acpi_namespace_node *next_node;
  674. acpi_status status;
  675. struct acpi_object_list args;
  676. union acpi_object objects[2];
  677. ACPI_FUNCTION_TRACE(ev_execute_orphan_reg_method);
  678. if (!device_node) {
  679. return_VOID;
  680. }
  681. /* Namespace is currently locked, must release */
  682. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  683. /* Get a handle to a _REG method immediately under the EC device */
  684. status = acpi_get_handle(device_node, METHOD_NAME__REG, &reg_method);
  685. if (ACPI_FAILURE(status)) {
  686. goto exit; /* There is no _REG method present */
  687. }
  688. /*
  689. * Execute the _REG method only if there is no Operation Region in
  690. * this scope with the Embedded Controller space ID. Otherwise, it
  691. * will already have been executed. Note, this allows for Regions
  692. * with other space IDs to be present; but the code below will then
  693. * execute the _REG method with the embedded_control space_ID argument.
  694. */
  695. next_node = acpi_ns_get_next_node(device_node, NULL);
  696. while (next_node) {
  697. if ((next_node->type == ACPI_TYPE_REGION) &&
  698. (next_node->object) &&
  699. (next_node->object->region.space_id == space_id)) {
  700. goto exit; /* Do not execute the _REG */
  701. }
  702. next_node = acpi_ns_get_next_node(device_node, next_node);
  703. }
  704. /* Evaluate the _REG(space_id,Connect) method */
  705. args.count = 2;
  706. args.pointer = objects;
  707. objects[0].type = ACPI_TYPE_INTEGER;
  708. objects[0].integer.value = space_id;
  709. objects[1].type = ACPI_TYPE_INTEGER;
  710. objects[1].integer.value = ACPI_REG_CONNECT;
  711. (void)acpi_evaluate_object(reg_method, NULL, &args, NULL);
  712. exit:
  713. /* We ignore all errors from above, don't care */
  714. (void)acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  715. return_VOID;
  716. }