evrgnini.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597
  1. /******************************************************************************
  2. *
  3. * Module Name: evrgnini- ACPI address_space (op_region) init
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2006, R. Byron Moore
  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 <acpi/acevents.h>
  44. #include <acpi/acnamesp.h>
  45. #define _COMPONENT ACPI_EVENTS
  46. ACPI_MODULE_NAME("evrgnini")
  47. /*******************************************************************************
  48. *
  49. * FUNCTION: acpi_ev_system_memory_region_setup
  50. *
  51. * PARAMETERS: Handle - Region we are interested in
  52. * Function - Start or stop
  53. * handler_context - Address space handler context
  54. * region_context - Region specific context
  55. *
  56. * RETURN: Status
  57. *
  58. * DESCRIPTION: Setup a system_memory operation region
  59. *
  60. ******************************************************************************/
  61. acpi_status
  62. acpi_ev_system_memory_region_setup(acpi_handle handle,
  63. u32 function,
  64. void *handler_context, void **region_context)
  65. {
  66. union acpi_operand_object *region_desc =
  67. (union acpi_operand_object *)handle;
  68. struct acpi_mem_space_context *local_region_context;
  69. ACPI_FUNCTION_TRACE(ev_system_memory_region_setup);
  70. if (function == ACPI_REGION_DEACTIVATE) {
  71. if (*region_context) {
  72. local_region_context =
  73. (struct acpi_mem_space_context *)*region_context;
  74. /* Delete a cached mapping if present */
  75. if (local_region_context->mapped_length) {
  76. acpi_os_unmap_memory(local_region_context->
  77. mapped_logical_address,
  78. local_region_context->
  79. mapped_length);
  80. }
  81. ACPI_FREE(local_region_context);
  82. *region_context = NULL;
  83. }
  84. return_ACPI_STATUS(AE_OK);
  85. }
  86. /* Create a new context */
  87. local_region_context =
  88. ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_mem_space_context));
  89. if (!(local_region_context)) {
  90. return_ACPI_STATUS(AE_NO_MEMORY);
  91. }
  92. /* Save the region length and address for use in the handler */
  93. local_region_context->length = region_desc->region.length;
  94. local_region_context->address = region_desc->region.address;
  95. *region_context = local_region_context;
  96. return_ACPI_STATUS(AE_OK);
  97. }
  98. /*******************************************************************************
  99. *
  100. * FUNCTION: acpi_ev_io_space_region_setup
  101. *
  102. * PARAMETERS: Handle - Region we are interested in
  103. * Function - Start or stop
  104. * handler_context - Address space handler context
  105. * region_context - Region specific context
  106. *
  107. * RETURN: Status
  108. *
  109. * DESCRIPTION: Setup a IO operation region
  110. *
  111. ******************************************************************************/
  112. acpi_status
  113. acpi_ev_io_space_region_setup(acpi_handle handle,
  114. u32 function,
  115. void *handler_context, void **region_context)
  116. {
  117. ACPI_FUNCTION_TRACE(ev_io_space_region_setup);
  118. if (function == ACPI_REGION_DEACTIVATE) {
  119. *region_context = NULL;
  120. } else {
  121. *region_context = handler_context;
  122. }
  123. return_ACPI_STATUS(AE_OK);
  124. }
  125. /*******************************************************************************
  126. *
  127. * FUNCTION: acpi_ev_pci_config_region_setup
  128. *
  129. * PARAMETERS: Handle - Region we are interested in
  130. * Function - Start or stop
  131. * handler_context - Address space handler context
  132. * region_context - Region specific context
  133. *
  134. * RETURN: Status
  135. *
  136. * DESCRIPTION: Setup a PCI_Config operation region
  137. *
  138. * MUTEX: Assumes namespace is not locked
  139. *
  140. ******************************************************************************/
  141. acpi_status
  142. acpi_ev_pci_config_region_setup(acpi_handle handle,
  143. u32 function,
  144. void *handler_context, void **region_context)
  145. {
  146. acpi_status status = AE_OK;
  147. acpi_integer pci_value;
  148. struct acpi_pci_id *pci_id = *region_context;
  149. union acpi_operand_object *handler_obj;
  150. struct acpi_namespace_node *parent_node;
  151. struct acpi_namespace_node *pci_root_node;
  152. union acpi_operand_object *region_obj =
  153. (union acpi_operand_object *)handle;
  154. struct acpi_device_id object_hID;
  155. ACPI_FUNCTION_TRACE(ev_pci_config_region_setup);
  156. handler_obj = region_obj->region.handler;
  157. if (!handler_obj) {
  158. /*
  159. * No installed handler. This shouldn't happen because the dispatch
  160. * routine checks before we get here, but we check again just in case.
  161. */
  162. ACPI_DEBUG_PRINT((ACPI_DB_OPREGION,
  163. "Attempting to init a region %p, with no handler\n",
  164. region_obj));
  165. return_ACPI_STATUS(AE_NOT_EXIST);
  166. }
  167. *region_context = NULL;
  168. if (function == ACPI_REGION_DEACTIVATE) {
  169. if (pci_id) {
  170. ACPI_FREE(pci_id);
  171. }
  172. return_ACPI_STATUS(status);
  173. }
  174. parent_node = acpi_ns_get_parent_node(region_obj->region.node);
  175. /*
  176. * Get the _SEG and _BBN values from the device upon which the handler
  177. * is installed.
  178. *
  179. * We need to get the _SEG and _BBN objects relative to the PCI BUS device.
  180. * This is the device the handler has been registered to handle.
  181. */
  182. /*
  183. * If the address_space.Node is still pointing to the root, we need
  184. * to scan upward for a PCI Root bridge and re-associate the op_region
  185. * handlers with that device.
  186. */
  187. if (handler_obj->address_space.node == acpi_gbl_root_node) {
  188. /* Start search from the parent object */
  189. pci_root_node = parent_node;
  190. while (pci_root_node != acpi_gbl_root_node) {
  191. status =
  192. acpi_ut_execute_HID(pci_root_node, &object_hID);
  193. if (ACPI_SUCCESS(status)) {
  194. /*
  195. * Got a valid _HID string, check if this is a PCI root.
  196. * New for ACPI 3.0: check for a PCI Express root also.
  197. */
  198. if (!
  199. (ACPI_STRNCMP
  200. (object_hID.value, PCI_ROOT_HID_STRING,
  201. sizeof(PCI_ROOT_HID_STRING))
  202. ||
  203. !(ACPI_STRNCMP
  204. (object_hID.value,
  205. PCI_EXPRESS_ROOT_HID_STRING,
  206. sizeof(PCI_EXPRESS_ROOT_HID_STRING)))))
  207. {
  208. /* Install a handler for this PCI root bridge */
  209. status =
  210. acpi_install_address_space_handler((acpi_handle) pci_root_node, ACPI_ADR_SPACE_PCI_CONFIG, ACPI_DEFAULT_HANDLER, NULL, NULL);
  211. if (ACPI_FAILURE(status)) {
  212. if (status == AE_SAME_HANDLER) {
  213. /*
  214. * It is OK if the handler is already installed on the root
  215. * bridge. Still need to return a context object for the
  216. * new PCI_Config operation region, however.
  217. */
  218. status = AE_OK;
  219. } else {
  220. ACPI_EXCEPTION((AE_INFO,
  221. status,
  222. "Could not install PciConfig handler for Root Bridge %4.4s",
  223. acpi_ut_get_node_name
  224. (pci_root_node)));
  225. }
  226. }
  227. break;
  228. }
  229. }
  230. pci_root_node = acpi_ns_get_parent_node(pci_root_node);
  231. }
  232. /* PCI root bridge not found, use namespace root node */
  233. } else {
  234. pci_root_node = handler_obj->address_space.node;
  235. }
  236. /*
  237. * If this region is now initialized, we are done.
  238. * (install_address_space_handler could have initialized it)
  239. */
  240. if (region_obj->region.flags & AOPOBJ_SETUP_COMPLETE) {
  241. return_ACPI_STATUS(AE_OK);
  242. }
  243. /* Region is still not initialized. Create a new context */
  244. pci_id = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_pci_id));
  245. if (!pci_id) {
  246. return_ACPI_STATUS(AE_NO_MEMORY);
  247. }
  248. /*
  249. * For PCI_Config space access, we need the segment, bus,
  250. * device and function numbers. Acquire them here.
  251. */
  252. /*
  253. * Get the PCI device and function numbers from the _ADR object
  254. * contained in the parent's scope.
  255. */
  256. status =
  257. acpi_ut_evaluate_numeric_object(METHOD_NAME__ADR, parent_node,
  258. &pci_value);
  259. /*
  260. * The default is zero, and since the allocation above zeroed
  261. * the data, just do nothing on failure.
  262. */
  263. if (ACPI_SUCCESS(status)) {
  264. pci_id->device = ACPI_HIWORD(ACPI_LODWORD(pci_value));
  265. pci_id->function = ACPI_LOWORD(ACPI_LODWORD(pci_value));
  266. }
  267. /* The PCI segment number comes from the _SEG method */
  268. status =
  269. acpi_ut_evaluate_numeric_object(METHOD_NAME__SEG, pci_root_node,
  270. &pci_value);
  271. if (ACPI_SUCCESS(status)) {
  272. pci_id->segment = ACPI_LOWORD(pci_value);
  273. }
  274. /* The PCI bus number comes from the _BBN method */
  275. status =
  276. acpi_ut_evaluate_numeric_object(METHOD_NAME__BBN, pci_root_node,
  277. &pci_value);
  278. if (ACPI_SUCCESS(status)) {
  279. pci_id->bus = ACPI_LOWORD(pci_value);
  280. }
  281. /* Complete this device's pci_id */
  282. acpi_os_derive_pci_id(pci_root_node, region_obj->region.node, &pci_id);
  283. *region_context = pci_id;
  284. return_ACPI_STATUS(AE_OK);
  285. }
  286. /*******************************************************************************
  287. *
  288. * FUNCTION: acpi_ev_pci_bar_region_setup
  289. *
  290. * PARAMETERS: Handle - Region we are interested in
  291. * Function - Start or stop
  292. * handler_context - Address space handler context
  293. * region_context - Region specific context
  294. *
  295. * RETURN: Status
  296. *
  297. * DESCRIPTION: Setup a pci_bAR operation region
  298. *
  299. * MUTEX: Assumes namespace is not locked
  300. *
  301. ******************************************************************************/
  302. acpi_status
  303. acpi_ev_pci_bar_region_setup(acpi_handle handle,
  304. u32 function,
  305. void *handler_context, void **region_context)
  306. {
  307. ACPI_FUNCTION_TRACE(ev_pci_bar_region_setup);
  308. return_ACPI_STATUS(AE_OK);
  309. }
  310. /*******************************************************************************
  311. *
  312. * FUNCTION: acpi_ev_cmos_region_setup
  313. *
  314. * PARAMETERS: Handle - Region we are interested in
  315. * Function - Start or stop
  316. * handler_context - Address space handler context
  317. * region_context - Region specific context
  318. *
  319. * RETURN: Status
  320. *
  321. * DESCRIPTION: Setup a CMOS operation region
  322. *
  323. * MUTEX: Assumes namespace is not locked
  324. *
  325. ******************************************************************************/
  326. acpi_status
  327. acpi_ev_cmos_region_setup(acpi_handle handle,
  328. u32 function,
  329. void *handler_context, void **region_context)
  330. {
  331. ACPI_FUNCTION_TRACE(ev_cmos_region_setup);
  332. return_ACPI_STATUS(AE_OK);
  333. }
  334. /*******************************************************************************
  335. *
  336. * FUNCTION: acpi_ev_default_region_setup
  337. *
  338. * PARAMETERS: Handle - Region we are interested in
  339. * Function - Start or stop
  340. * handler_context - Address space handler context
  341. * region_context - Region specific context
  342. *
  343. * RETURN: Status
  344. *
  345. * DESCRIPTION: Default region initialization
  346. *
  347. ******************************************************************************/
  348. acpi_status
  349. acpi_ev_default_region_setup(acpi_handle handle,
  350. u32 function,
  351. void *handler_context, void **region_context)
  352. {
  353. ACPI_FUNCTION_TRACE(ev_default_region_setup);
  354. if (function == ACPI_REGION_DEACTIVATE) {
  355. *region_context = NULL;
  356. } else {
  357. *region_context = handler_context;
  358. }
  359. return_ACPI_STATUS(AE_OK);
  360. }
  361. /*******************************************************************************
  362. *
  363. * FUNCTION: acpi_ev_initialize_region
  364. *
  365. * PARAMETERS: region_obj - Region we are initializing
  366. * acpi_ns_locked - Is namespace locked?
  367. *
  368. * RETURN: Status
  369. *
  370. * DESCRIPTION: Initializes the region, finds any _REG methods and saves them
  371. * for execution at a later time
  372. *
  373. * Get the appropriate address space handler for a newly
  374. * created region.
  375. *
  376. * This also performs address space specific initialization. For
  377. * example, PCI regions must have an _ADR object that contains
  378. * a PCI address in the scope of the definition. This address is
  379. * required to perform an access to PCI config space.
  380. *
  381. ******************************************************************************/
  382. acpi_status
  383. acpi_ev_initialize_region(union acpi_operand_object *region_obj,
  384. u8 acpi_ns_locked)
  385. {
  386. union acpi_operand_object *handler_obj;
  387. union acpi_operand_object *obj_desc;
  388. acpi_adr_space_type space_id;
  389. struct acpi_namespace_node *node;
  390. acpi_status status;
  391. struct acpi_namespace_node *method_node;
  392. acpi_name *reg_name_ptr = (acpi_name *) METHOD_NAME__REG;
  393. union acpi_operand_object *region_obj2;
  394. ACPI_FUNCTION_TRACE_U32(ev_initialize_region, acpi_ns_locked);
  395. if (!region_obj) {
  396. return_ACPI_STATUS(AE_BAD_PARAMETER);
  397. }
  398. if (region_obj->common.flags & AOPOBJ_OBJECT_INITIALIZED) {
  399. return_ACPI_STATUS(AE_OK);
  400. }
  401. region_obj2 = acpi_ns_get_secondary_object(region_obj);
  402. if (!region_obj2) {
  403. return_ACPI_STATUS(AE_NOT_EXIST);
  404. }
  405. node = acpi_ns_get_parent_node(region_obj->region.node);
  406. space_id = region_obj->region.space_id;
  407. /* Setup defaults */
  408. region_obj->region.handler = NULL;
  409. region_obj2->extra.method_REG = NULL;
  410. region_obj->common.flags &= ~(AOPOBJ_SETUP_COMPLETE);
  411. region_obj->common.flags |= AOPOBJ_OBJECT_INITIALIZED;
  412. /* Find any "_REG" method associated with this region definition */
  413. status =
  414. acpi_ns_search_one_scope(*reg_name_ptr, node, ACPI_TYPE_METHOD,
  415. &method_node);
  416. if (ACPI_SUCCESS(status)) {
  417. /*
  418. * The _REG method is optional and there can be only one per region
  419. * definition. This will be executed when the handler is attached
  420. * or removed
  421. */
  422. region_obj2->extra.method_REG = method_node;
  423. }
  424. /*
  425. * The following loop depends upon the root Node having no parent
  426. * ie: acpi_gbl_root_node->parent_entry being set to NULL
  427. */
  428. while (node) {
  429. /* Check to see if a handler exists */
  430. handler_obj = NULL;
  431. obj_desc = acpi_ns_get_attached_object(node);
  432. if (obj_desc) {
  433. /* Can only be a handler if the object exists */
  434. switch (node->type) {
  435. case ACPI_TYPE_DEVICE:
  436. handler_obj = obj_desc->device.handler;
  437. break;
  438. case ACPI_TYPE_PROCESSOR:
  439. handler_obj = obj_desc->processor.handler;
  440. break;
  441. case ACPI_TYPE_THERMAL:
  442. handler_obj = obj_desc->thermal_zone.handler;
  443. break;
  444. default:
  445. /* Ignore other objects */
  446. break;
  447. }
  448. while (handler_obj) {
  449. /* Is this handler of the correct type? */
  450. if (handler_obj->address_space.space_id ==
  451. space_id) {
  452. /* Found correct handler */
  453. ACPI_DEBUG_PRINT((ACPI_DB_OPREGION,
  454. "Found handler %p for region %p in obj %p\n",
  455. handler_obj,
  456. region_obj,
  457. obj_desc));
  458. status =
  459. acpi_ev_attach_region(handler_obj,
  460. region_obj,
  461. acpi_ns_locked);
  462. /*
  463. * Tell all users that this region is usable by running the _REG
  464. * method
  465. */
  466. if (acpi_ns_locked) {
  467. status =
  468. acpi_ut_release_mutex
  469. (ACPI_MTX_NAMESPACE);
  470. if (ACPI_FAILURE(status)) {
  471. return_ACPI_STATUS
  472. (status);
  473. }
  474. }
  475. status =
  476. acpi_ev_execute_reg_method
  477. (region_obj, 1);
  478. if (acpi_ns_locked) {
  479. status =
  480. acpi_ut_acquire_mutex
  481. (ACPI_MTX_NAMESPACE);
  482. if (ACPI_FAILURE(status)) {
  483. return_ACPI_STATUS
  484. (status);
  485. }
  486. }
  487. return_ACPI_STATUS(AE_OK);
  488. }
  489. /* Try next handler in the list */
  490. handler_obj = handler_obj->address_space.next;
  491. }
  492. }
  493. /*
  494. * This node does not have the handler we need;
  495. * Pop up one level
  496. */
  497. node = acpi_ns_get_parent_node(node);
  498. }
  499. /* If we get here, there is no handler for this region */
  500. ACPI_DEBUG_PRINT((ACPI_DB_OPREGION,
  501. "No handler for RegionType %s(%X) (RegionObj %p)\n",
  502. acpi_ut_get_region_name(space_id), space_id,
  503. region_obj));
  504. return_ACPI_STATUS(AE_NOT_EXIST);
  505. }