ia64/xen-unstable

view xen/drivers/acpi/tables/tbxface.c @ 18896:f7f8f44b9292

tools: Fix a few error-path memory leaks.

Signed-off-by: Keir Fraser <keir.fraser@citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Tue Dec 09 12:53:19 2008 +0000 (2008-12-09)
parents ae29cd95ba7d
children
line source
1 /******************************************************************************
2 *
3 * Module Name: tbxface - Public interfaces to the ACPI subsystem
4 * ACPI table oriented interfaces
5 *
6 *****************************************************************************/
8 /*
9 * Copyright (C) 2000 - 2008, Intel Corp.
10 * All rights reserved.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions, and the following disclaimer,
17 * without modification.
18 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
19 * substantially similar to the "NO WARRANTY" disclaimer below
20 * ("Disclaimer") and any redistribution must be conditioned upon
21 * including a substantially similar Disclaimer requirement for further
22 * binary redistribution.
23 * 3. Neither the names of the above-listed copyright holders nor the names
24 * of any contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
26 *
27 * Alternatively, this software may be distributed under the terms of the
28 * GNU General Public License ("GPL") version 2 as published by the Free
29 * Software Foundation.
30 *
31 * NO WARRANTY
32 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
35 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
41 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42 * POSSIBILITY OF SUCH DAMAGES.
43 */
45 #include <xen/config.h>
46 #include <xen/init.h>
47 #include <acpi/acpi.h>
48 #include <acpi/acnamesp.h>
49 #include <acpi/actables.h>
51 #define _COMPONENT ACPI_TABLES
52 ACPI_MODULE_NAME("tbxface")
54 /*******************************************************************************
55 *
56 * FUNCTION: acpi_allocate_root_table
57 *
58 * PARAMETERS: initial_table_count - Size of initial_table_array, in number of
59 * struct acpi_table_desc structures
60 *
61 * RETURN: Status
62 *
63 * DESCRIPTION: Allocate a root table array. Used by i_aSL compiler and
64 * acpi_initialize_tables.
65 *
66 ******************************************************************************/
68 acpi_status __init acpi_allocate_root_table(u32 initial_table_count)
69 {
71 acpi_gbl_root_table_list.size = initial_table_count;
72 acpi_gbl_root_table_list.flags = ACPI_ROOT_ALLOW_RESIZE;
74 return (acpi_tb_resize_root_table_list());
75 }
77 /*******************************************************************************
78 *
79 * FUNCTION: acpi_initialize_tables
80 *
81 * PARAMETERS: initial_table_array - Pointer to an array of pre-allocated
82 * struct acpi_table_desc structures. If NULL, the
83 * array is dynamically allocated.
84 * initial_table_count - Size of initial_table_array, in number of
85 * struct acpi_table_desc structures
86 * allow_realloc - Flag to tell Table Manager if resize of
87 * pre-allocated array is allowed. Ignored
88 * if initial_table_array is NULL.
89 *
90 * RETURN: Status
91 *
92 * DESCRIPTION: Initialize the table manager, get the RSDP and RSDT/XSDT.
93 *
94 * NOTE: Allows static allocation of the initial table array in order
95 * to avoid the use of dynamic memory in confined environments
96 * such as the kernel boot sequence where it may not be available.
97 *
98 * If the host OS memory managers are initialized, use NULL for
99 * initial_table_array, and the table will be dynamically allocated.
100 *
101 ******************************************************************************/
103 acpi_status __init
104 acpi_initialize_tables(struct acpi_table_desc * initial_table_array,
105 u32 initial_table_count, u8 allow_resize)
106 {
107 acpi_physical_address rsdp_address;
108 acpi_status status;
110 ACPI_FUNCTION_TRACE(acpi_initialize_tables);
112 /*
113 * Set up the Root Table Array
114 * Allocate the table array if requested
115 */
116 if (!initial_table_array) {
117 status = acpi_allocate_root_table(initial_table_count);
118 if (ACPI_FAILURE(status)) {
119 return_ACPI_STATUS(status);
120 }
121 } else {
122 /* Root Table Array has been statically allocated by the host */
124 ACPI_MEMSET(initial_table_array, 0,
125 initial_table_count *
126 sizeof(struct acpi_table_desc));
128 acpi_gbl_root_table_list.tables = initial_table_array;
129 acpi_gbl_root_table_list.size = initial_table_count;
130 acpi_gbl_root_table_list.flags = ACPI_ROOT_ORIGIN_UNKNOWN;
131 if (allow_resize) {
132 acpi_gbl_root_table_list.flags |=
133 ACPI_ROOT_ALLOW_RESIZE;
134 }
135 }
137 /* Get the address of the RSDP */
139 rsdp_address = acpi_os_get_root_pointer();
140 if (!rsdp_address) {
141 return_ACPI_STATUS(AE_NOT_FOUND);
142 }
144 /*
145 * Get the root table (RSDT or XSDT) and extract all entries to the local
146 * Root Table Array. This array contains the information of the RSDT/XSDT
147 * in a common, more useable format.
148 */
149 status =
150 acpi_tb_parse_root_table(rsdp_address, ACPI_TABLE_ORIGIN_MAPPED);
151 return_ACPI_STATUS(status);
152 }
154 /*******************************************************************************
155 *
156 * FUNCTION: acpi_get_table
157 *
158 * PARAMETERS: Signature - ACPI signature of needed table
159 * Instance - Which instance (for SSDTs)
160 * out_table - Where the pointer to the table is returned
161 *
162 * RETURN: Status and pointer to table
163 *
164 * DESCRIPTION: Finds and verifies an ACPI table.
165 *
166 *****************************************************************************/
167 acpi_status
168 acpi_get_table(char *signature,
169 acpi_native_uint instance, struct acpi_table_header **out_table)
170 {
171 acpi_native_uint i;
172 acpi_native_uint j;
173 acpi_status status;
175 /* Parameter validation */
177 if (!signature || !out_table) {
178 return (AE_BAD_PARAMETER);
179 }
181 /*
182 * Walk the root table list
183 */
184 for (i = 0, j = 0; i < acpi_gbl_root_table_list.count; i++) {
185 if (!ACPI_COMPARE_NAME
186 (&(acpi_gbl_root_table_list.tables[i].signature),
187 signature)) {
188 continue;
189 }
191 if (++j < instance) {
192 continue;
193 }
195 status =
196 acpi_tb_verify_table(&acpi_gbl_root_table_list.tables[i]);
197 if (ACPI_SUCCESS(status)) {
198 *out_table = acpi_gbl_root_table_list.tables[i].pointer;
199 }
201 /*if (!acpi_gbl_permanent_mmap)*/ {
202 acpi_gbl_root_table_list.tables[i].pointer = NULL;
203 }
205 return (status);
206 }
208 return (AE_NOT_FOUND);
209 }
211 ACPI_EXPORT_SYMBOL(acpi_get_table)