rsutils.c 7.77 KB
Newer Older
Linus Torvalds's avatar
Linus Torvalds committed
1 2 3
/*******************************************************************************
 *
 * Module Name: rsutils - Utilities for the resource manager
4
 *              $Revision: 34 $
Linus Torvalds's avatar
Linus Torvalds committed
5 6 7 8
 *
 ******************************************************************************/

/*
Andy Grover's avatar
Andy Grover committed
9
 *  Copyright (C) 2000 - 2002, R. Byron Moore
Linus Torvalds's avatar
Linus Torvalds committed
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */


#include "acpi.h"
#include "acnamesp.h"
#include "acresrc.h"


Linus Torvalds's avatar
Linus Torvalds committed
32
#define _COMPONENT          ACPI_RESOURCES
Andy Grover's avatar
Andy Grover committed
33
	 ACPI_MODULE_NAME    ("rsutils")
Linus Torvalds's avatar
Linus Torvalds committed
34 35 36 37 38 39 40 41 42 43


/*******************************************************************************
 *
 * FUNCTION:    Acpi_rs_get_prt_method_data
 *
 * PARAMETERS:  Handle          - a handle to the containing object
 *              Ret_buffer      - a pointer to a buffer structure for the
 *                                  results
 *
Linus Torvalds's avatar
Linus Torvalds committed
44
 * RETURN:      Status
Linus Torvalds's avatar
Linus Torvalds committed
45 46 47 48 49 50 51 52 53
 *
 * DESCRIPTION: This function is called to get the _PRT value of an object
 *              contained in an object specified by the handle passed in
 *
 *              If the function fails an appropriate status will be returned
 *              and the contents of the callers buffer is undefined.
 *
 ******************************************************************************/

Linus Torvalds's avatar
Linus Torvalds committed
54
acpi_status
Linus Torvalds's avatar
Linus Torvalds committed
55
acpi_rs_get_prt_method_data (
Linus Torvalds's avatar
Linus Torvalds committed
56 57
	acpi_handle             handle,
	acpi_buffer             *ret_buffer)
Linus Torvalds's avatar
Linus Torvalds committed
58
{
Andy Grover's avatar
Andy Grover committed
59
	acpi_operand_object     *obj_desc;
Linus Torvalds's avatar
Linus Torvalds committed
60
	acpi_status             status;
Linus Torvalds's avatar
Linus Torvalds committed
61 62


Andy Grover's avatar
Andy Grover committed
63
	ACPI_FUNCTION_TRACE ("Rs_get_prt_method_data");
Linus Torvalds's avatar
Linus Torvalds committed
64 65


Andy Grover's avatar
Andy Grover committed
66
	/* Parameters guaranteed valid by caller */
Linus Torvalds's avatar
Linus Torvalds committed
67 68

	/*
69
	 * Execute the method, no parameters
Linus Torvalds's avatar
Linus Torvalds committed
70
	 */
71
	status = acpi_ut_evaluate_object (handle, "_PRT", ACPI_BTYPE_PACKAGE, &obj_desc);
Linus Torvalds's avatar
Linus Torvalds committed
72
	if (ACPI_FAILURE (status)) {
Linus Torvalds's avatar
Linus Torvalds committed
73
		return_ACPI_STATUS (status);
Linus Torvalds's avatar
Linus Torvalds committed
74 75 76
	}

	/*
Andy Grover's avatar
Andy Grover committed
77 78
	 * Create a resource linked list from the byte stream buffer that comes
	 * back from the _CRS method execution.
Linus Torvalds's avatar
Linus Torvalds committed
79
	 */
Andy Grover's avatar
Andy Grover committed
80
	status = acpi_rs_create_pci_routing_table (obj_desc, ret_buffer);
Linus Torvalds's avatar
Linus Torvalds committed
81

Andy Grover's avatar
Andy Grover committed
82
	/* On exit, we must delete the object returned by Evaluate_object */
Linus Torvalds's avatar
Linus Torvalds committed
83

Andy Grover's avatar
Andy Grover committed
84
	acpi_ut_remove_reference (obj_desc);
Linus Torvalds's avatar
Linus Torvalds committed
85
	return_ACPI_STATUS (status);
Linus Torvalds's avatar
Linus Torvalds committed
86 87 88 89 90 91 92 93 94 95 96
}


/*******************************************************************************
 *
 * FUNCTION:    Acpi_rs_get_crs_method_data
 *
 * PARAMETERS:  Handle          - a handle to the containing object
 *              Ret_buffer      - a pointer to a buffer structure for the
 *                                  results
 *
Linus Torvalds's avatar
Linus Torvalds committed
97
 * RETURN:      Status
Linus Torvalds's avatar
Linus Torvalds committed
98 99 100 101 102 103 104 105 106
 *
 * DESCRIPTION: This function is called to get the _CRS value of an object
 *              contained in an object specified by the handle passed in
 *
 *              If the function fails an appropriate status will be returned
 *              and the contents of the callers buffer is undefined.
 *
 ******************************************************************************/

Linus Torvalds's avatar
Linus Torvalds committed
107
acpi_status
Linus Torvalds's avatar
Linus Torvalds committed
108
acpi_rs_get_crs_method_data (
Linus Torvalds's avatar
Linus Torvalds committed
109 110
	acpi_handle             handle,
	acpi_buffer             *ret_buffer)
Linus Torvalds's avatar
Linus Torvalds committed
111
{
Andy Grover's avatar
Andy Grover committed
112
	acpi_operand_object     *obj_desc;
Linus Torvalds's avatar
Linus Torvalds committed
113
	acpi_status             status;
Linus Torvalds's avatar
Linus Torvalds committed
114 115


Andy Grover's avatar
Andy Grover committed
116
	ACPI_FUNCTION_TRACE ("Rs_get_crs_method_data");
Linus Torvalds's avatar
Linus Torvalds committed
117 118


Andy Grover's avatar
Andy Grover committed
119
	/* Parameters guaranteed valid by caller */
Linus Torvalds's avatar
Linus Torvalds committed
120 121

	/*
Andy Grover's avatar
Andy Grover committed
122
	 * Execute the method, no parameters
Linus Torvalds's avatar
Linus Torvalds committed
123
	 */
124
	status = acpi_ut_evaluate_object (handle, "_CRS", ACPI_BTYPE_BUFFER, &obj_desc);
Linus Torvalds's avatar
Linus Torvalds committed
125
	if (ACPI_FAILURE (status)) {
Linus Torvalds's avatar
Linus Torvalds committed
126
		return_ACPI_STATUS (status);
Linus Torvalds's avatar
Linus Torvalds committed
127 128 129 130
	}

	/*
	 * Make the call to create a resource linked list from the
Andy Grover's avatar
Andy Grover committed
131 132
	 * byte stream buffer that comes back from the _CRS method
	 * execution.
Linus Torvalds's avatar
Linus Torvalds committed
133
	 */
Andy Grover's avatar
Andy Grover committed
134
	status = acpi_rs_create_resource_list (obj_desc, ret_buffer);
Linus Torvalds's avatar
Linus Torvalds committed
135 136 137

	/* On exit, we must delete the object returned by evaluate_object */

Andy Grover's avatar
Andy Grover committed
138
	acpi_ut_remove_reference (obj_desc);
Linus Torvalds's avatar
Linus Torvalds committed
139
	return_ACPI_STATUS (status);
Linus Torvalds's avatar
Linus Torvalds committed
140 141 142 143 144 145 146 147 148 149 150
}


/*******************************************************************************
 *
 * FUNCTION:    Acpi_rs_get_prs_method_data
 *
 * PARAMETERS:  Handle          - a handle to the containing object
 *              Ret_buffer      - a pointer to a buffer structure for the
 *                                  results
 *
Linus Torvalds's avatar
Linus Torvalds committed
151
 * RETURN:      Status
Linus Torvalds's avatar
Linus Torvalds committed
152 153 154 155 156 157 158 159 160
 *
 * DESCRIPTION: This function is called to get the _PRS value of an object
 *              contained in an object specified by the handle passed in
 *
 *              If the function fails an appropriate status will be returned
 *              and the contents of the callers buffer is undefined.
 *
 ******************************************************************************/

Linus Torvalds's avatar
Linus Torvalds committed
161
acpi_status
Linus Torvalds's avatar
Linus Torvalds committed
162
acpi_rs_get_prs_method_data (
Linus Torvalds's avatar
Linus Torvalds committed
163 164
	acpi_handle             handle,
	acpi_buffer             *ret_buffer)
Linus Torvalds's avatar
Linus Torvalds committed
165
{
Andy Grover's avatar
Andy Grover committed
166
	acpi_operand_object     *obj_desc;
Linus Torvalds's avatar
Linus Torvalds committed
167
	acpi_status             status;
Linus Torvalds's avatar
Linus Torvalds committed
168 169


Andy Grover's avatar
Andy Grover committed
170
	ACPI_FUNCTION_TRACE ("Rs_get_prs_method_data");
Linus Torvalds's avatar
Linus Torvalds committed
171 172


Andy Grover's avatar
Andy Grover committed
173
	/* Parameters guaranteed valid by caller */
Linus Torvalds's avatar
Linus Torvalds committed
174 175

	/*
Andy Grover's avatar
Andy Grover committed
176
	 * Execute the method, no parameters
Linus Torvalds's avatar
Linus Torvalds committed
177
	 */
178
	status = acpi_ut_evaluate_object (handle, "_PRS", ACPI_BTYPE_BUFFER, &obj_desc);
Linus Torvalds's avatar
Linus Torvalds committed
179
	if (ACPI_FAILURE (status)) {
Linus Torvalds's avatar
Linus Torvalds committed
180
		return_ACPI_STATUS (status);
Linus Torvalds's avatar
Linus Torvalds committed
181 182 183 184
	}

	/*
	 * Make the call to create a resource linked list from the
Andy Grover's avatar
Andy Grover committed
185 186
	 * byte stream buffer that comes back from the _CRS method
	 * execution.
Linus Torvalds's avatar
Linus Torvalds committed
187
	 */
Andy Grover's avatar
Andy Grover committed
188
	status = acpi_rs_create_resource_list (obj_desc, ret_buffer);
Linus Torvalds's avatar
Linus Torvalds committed
189 190 191

	/* On exit, we must delete the object returned by evaluate_object */

Andy Grover's avatar
Andy Grover committed
192
	acpi_ut_remove_reference (obj_desc);
Linus Torvalds's avatar
Linus Torvalds committed
193
	return_ACPI_STATUS (status);
Linus Torvalds's avatar
Linus Torvalds committed
194 195 196 197 198 199 200 201 202 203 204
}


/*******************************************************************************
 *
 * FUNCTION:    Acpi_rs_set_srs_method_data
 *
 * PARAMETERS:  Handle          - a handle to the containing object
 *              In_buffer       - a pointer to a buffer structure of the
 *                                  parameter
 *
Linus Torvalds's avatar
Linus Torvalds committed
205
 * RETURN:      Status
Linus Torvalds's avatar
Linus Torvalds committed
206 207 208 209 210 211 212 213 214
 *
 * DESCRIPTION: This function is called to set the _SRS of an object contained
 *              in an object specified by the handle passed in
 *
 *              If the function fails an appropriate status will be returned
 *              and the contents of the callers buffer is undefined.
 *
 ******************************************************************************/

Linus Torvalds's avatar
Linus Torvalds committed
215
acpi_status
Linus Torvalds's avatar
Linus Torvalds committed
216
acpi_rs_set_srs_method_data (
Linus Torvalds's avatar
Linus Torvalds committed
217 218
	acpi_handle             handle,
	acpi_buffer             *in_buffer)
Linus Torvalds's avatar
Linus Torvalds committed
219
{
Linus Torvalds's avatar
Linus Torvalds committed
220 221
	acpi_operand_object     *params[2];
	acpi_status             status;
Andy Grover's avatar
Andy Grover committed
222
	acpi_buffer             buffer;
Linus Torvalds's avatar
Linus Torvalds committed
223 224


Andy Grover's avatar
Andy Grover committed
225
	ACPI_FUNCTION_TRACE ("Rs_set_srs_method_data");
Linus Torvalds's avatar
Linus Torvalds committed
226 227


Andy Grover's avatar
Andy Grover committed
228
	/* Parameters guaranteed valid by caller */
Linus Torvalds's avatar
Linus Torvalds committed
229 230 231

	/*
	 * The In_buffer parameter will point to a linked list of
Linus Torvalds's avatar
Linus Torvalds committed
232
	 * resource parameters.  It needs to be formatted into a
Andy Grover's avatar
Andy Grover committed
233 234 235
	 * byte stream to be sent in as an input parameter to _SRS
	 *
	 * Convert the linked list into a byte stream
Linus Torvalds's avatar
Linus Torvalds committed
236
	 */
Andy Grover's avatar
Andy Grover committed
237 238
	buffer.length = ACPI_ALLOCATE_LOCAL_BUFFER;
	status = acpi_rs_create_byte_stream (in_buffer->pointer, &buffer);
Linus Torvalds's avatar
Linus Torvalds committed
239
	if (ACPI_FAILURE (status)) {
Andy Grover's avatar
Andy Grover committed
240
		return_ACPI_STATUS (status);
Linus Torvalds's avatar
Linus Torvalds committed
241 242 243
	}

	/*
Linus Torvalds's avatar
Linus Torvalds committed
244
	 * Init the param object
Linus Torvalds's avatar
Linus Torvalds committed
245
	 */
Linus Torvalds's avatar
Linus Torvalds committed
246 247
	params[0] = acpi_ut_create_internal_object (ACPI_TYPE_BUFFER);
	if (!params[0]) {
Andy Grover's avatar
Andy Grover committed
248 249
		acpi_os_free (buffer.pointer);
		return_ACPI_STATUS (AE_NO_MEMORY);
Linus Torvalds's avatar
Linus Torvalds committed
250
	}
Linus Torvalds's avatar
Linus Torvalds committed
251 252

	/*
Andy Grover's avatar
Andy Grover committed
253
	 * Set up the parameter object
Linus Torvalds's avatar
Linus Torvalds committed
254
	 */
255
	params[0]->buffer.length  = (u32) buffer.length;
Andy Grover's avatar
Andy Grover committed
256
	params[0]->buffer.pointer = buffer.pointer;
Andy Grover's avatar
Andy Grover committed
257
	params[0]->common.flags   = AOPOBJ_DATA_VALID;
Andy Grover's avatar
Andy Grover committed
258
	params[1] = NULL;
Linus Torvalds's avatar
Linus Torvalds committed
259 260

	/*
Linus Torvalds's avatar
Linus Torvalds committed
261
	 * Execute the method, no return value
Linus Torvalds's avatar
Linus Torvalds committed
262 263 264 265
	 */
	status = acpi_ns_evaluate_relative (handle, "_SRS", params, NULL);

	/*
Linus Torvalds's avatar
Linus Torvalds committed
266
	 * Clean up and return the status from Acpi_ns_evaluate_relative
Linus Torvalds's avatar
Linus Torvalds committed
267
	 */
Andy Grover's avatar
Andy Grover committed
268
	acpi_ut_remove_reference (params[0]);
Linus Torvalds's avatar
Linus Torvalds committed
269
	return_ACPI_STATUS (status);
Linus Torvalds's avatar
Linus Torvalds committed
270 271
}