evrgnini.c 17 KB

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