exconfig.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:6k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  1. /******************************************************************************
  2.  *
  3.  * Module Name: exconfig - Namespace reconfiguration (Load/Unload opcodes)
  4.  *              $Revision: 44 $
  5.  *
  6.  *****************************************************************************/
  7. /*
  8.  *  Copyright (C) 2000, 2001 R. Byron Moore
  9.  *
  10.  *  This program is free software; you can redistribute it and/or modify
  11.  *  it under the terms of the GNU General Public License as published by
  12.  *  the Free Software Foundation; either version 2 of the License, or
  13.  *  (at your option) any later version.
  14.  *
  15.  *  This program is distributed in the hope that it will be useful,
  16.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  17.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18.  *  GNU General Public License for more details.
  19.  *
  20.  *  You should have received a copy of the GNU General Public License
  21.  *  along with this program; if not, write to the Free Software
  22.  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  23.  */
  24. #include "acpi.h"
  25. #include "acparser.h"
  26. #include "acinterp.h"
  27. #include "amlcode.h"
  28. #include "acnamesp.h"
  29. #include "acevents.h"
  30. #include "actables.h"
  31. #include "acdispat.h"
  32. #define _COMPONENT          ACPI_EXECUTER
  33.  MODULE_NAME         ("exconfig")
  34. /*****************************************************************************
  35.  *
  36.  * FUNCTION:    Acpi_ex_load_table_op
  37.  *
  38.  * PARAMETERS:  Rgn_desc        - Op region where the table will be obtained
  39.  *              Ddb_handle      - Where a handle to the table will be returned
  40.  *
  41.  * RETURN:      Status
  42.  *
  43.  * DESCRIPTION: Load an ACPI table
  44.  *
  45.  ****************************************************************************/
  46. acpi_status
  47. acpi_ex_load_op (
  48. acpi_operand_object     *rgn_desc,
  49. acpi_operand_object     *ddb_handle)
  50. {
  51. acpi_status             status;
  52. acpi_operand_object     *table_desc = NULL;
  53. u8                      *table_ptr;
  54. u8                      *table_data_ptr;
  55. acpi_table_header       table_header;
  56. acpi_table_desc         table_info;
  57. u32                     i;
  58. FUNCTION_TRACE ("Ex_load_op");
  59. /* TBD: [Unhandled] Object can be either a field or an opregion */
  60. /* Get the table header */
  61. table_header.length = 0;
  62. for (i = 0; i < sizeof (acpi_table_header); i++) {
  63. status = acpi_ev_address_space_dispatch (rgn_desc, ACPI_READ_ADR_SPACE,
  64.    (ACPI_PHYSICAL_ADDRESS) i, 8,
  65.    (u32 *) ((u8 *) &table_header + i));
  66. if (ACPI_FAILURE (status)) {
  67. return_ACPI_STATUS (status);
  68. }
  69. }
  70. /* Allocate a buffer for the entire table */
  71. table_ptr = ACPI_MEM_ALLOCATE (table_header.length);
  72. if (!table_ptr) {
  73. return_ACPI_STATUS (AE_NO_MEMORY);
  74. }
  75. /* Copy the header to the buffer */
  76. MEMCPY (table_ptr, &table_header, sizeof (acpi_table_header));
  77. table_data_ptr = table_ptr + sizeof (acpi_table_header);
  78. /* Get the table from the op region */
  79. for (i = 0; i < table_header.length; i++) {
  80. status = acpi_ev_address_space_dispatch (rgn_desc, ACPI_READ_ADR_SPACE,
  81.    (ACPI_PHYSICAL_ADDRESS) i, 8,
  82.    (u32 *) (table_data_ptr + i));
  83. if (ACPI_FAILURE (status)) {
  84. goto cleanup;
  85. }
  86. }
  87. /* Table must be either an SSDT or a PSDT */
  88. if ((!STRNCMP (table_header.signature,
  89.   acpi_gbl_acpi_table_data[ACPI_TABLE_PSDT].signature,
  90.   acpi_gbl_acpi_table_data[ACPI_TABLE_PSDT].sig_length)) &&
  91. (!STRNCMP (table_header.signature,
  92.  acpi_gbl_acpi_table_data[ACPI_TABLE_SSDT].signature,
  93.  acpi_gbl_acpi_table_data[ACPI_TABLE_SSDT].sig_length))) {
  94. ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
  95. "Table has invalid signature [%4.4s], must be SSDT or PSDTn",
  96. (char*)table_header.signature));
  97. status = AE_BAD_SIGNATURE;
  98. goto cleanup;
  99. }
  100. /* Create an object to be the table handle */
  101. table_desc = acpi_ut_create_internal_object (INTERNAL_TYPE_REFERENCE);
  102. if (!table_desc) {
  103. status = AE_NO_MEMORY;
  104. goto cleanup;
  105. }
  106. /* Install the new table into the local data structures */
  107. table_info.pointer     = (acpi_table_header *) table_ptr;
  108. table_info.length      = table_header.length;
  109. table_info.allocation  = ACPI_MEM_ALLOCATED;
  110. table_info.base_pointer = table_ptr;
  111. status = acpi_tb_install_table (NULL, &table_info);
  112. if (ACPI_FAILURE (status)) {
  113. goto cleanup;
  114. }
  115. /* Add the table to the namespace */
  116. /* TBD: [Restructure] - change to whatever new interface is appropriate */
  117. /*
  118. Status = Acpi_load_namespace ();
  119. if (ACPI_FAILURE (Status))
  120. {
  121. */
  122. /* TBD: [Errors] Unload the table on failure ? */
  123. /*
  124. goto Cleanup;
  125. }
  126. */
  127. /* TBD: [Investigate] we need a pointer to the table desc */
  128. /* Init the table handle */
  129. table_desc->reference.opcode = AML_LOAD_OP;
  130. table_desc->reference.object = table_info.installed_desc;
  131. /* TBD: store the tabledesc into the Ddb_handle target */
  132. /* Ddb_handle = Table_desc; */
  133. return_ACPI_STATUS (status);
  134. cleanup:
  135. ACPI_MEM_FREE (table_desc);
  136. ACPI_MEM_FREE (table_ptr);
  137. return_ACPI_STATUS (status);
  138. }
  139. /*****************************************************************************
  140.  *
  141.  * FUNCTION:    Acpi_ex_unload_table
  142.  *
  143.  * PARAMETERS:  Ddb_handle          - Handle to a previously loaded table
  144.  *
  145.  * RETURN:      Status
  146.  *
  147.  * DESCRIPTION: Unload an ACPI table
  148.  *
  149.  ****************************************************************************/
  150. acpi_status
  151. acpi_ex_unload_table (
  152. acpi_operand_object     *ddb_handle)
  153. {
  154. acpi_status             status = AE_NOT_IMPLEMENTED;
  155. acpi_operand_object     *table_desc = ddb_handle;
  156. acpi_table_desc         *table_info;
  157. FUNCTION_TRACE ("Ex_unload_table");
  158. /*
  159.  * Validate the handle
  160.  * Although the handle is partially validated in Acpi_ex_reconfiguration(),
  161.  * when it calls Acpi_ex_resolve_operands(), the handle is more completely
  162.  * validated here.
  163.  */
  164. if ((!ddb_handle) ||
  165. (!VALID_DESCRIPTOR_TYPE (ddb_handle, ACPI_DESC_TYPE_INTERNAL)) ||
  166. (((acpi_operand_object  *)ddb_handle)->common.type !=
  167. INTERNAL_TYPE_REFERENCE)) {
  168. return_ACPI_STATUS (AE_BAD_PARAMETER);
  169. }
  170. /* Get the actual table descriptor from the Ddb_handle */
  171. table_info = (acpi_table_desc *) table_desc->reference.object;
  172. /*
  173.  * Delete the entire namespace under this table Node
  174.  * (Offset contains the Table_id)
  175.  */
  176. status = acpi_ns_delete_namespace_by_owner (table_info->table_id);
  177. if (ACPI_FAILURE (status)) {
  178. return_ACPI_STATUS (status);
  179. }
  180. /* Delete the table itself */
  181. acpi_tb_uninstall_table (table_info->installed_desc);
  182. /* Delete the table descriptor (Ddb_handle) */
  183. acpi_ut_remove_reference (table_desc);
  184. return_ACPI_STATUS (status);
  185. }