Blame view

drivers/acpi/acpica/excreate.c 12.7 KB
958576388   Erik Schmauss   ACPICA: adding SP...
1
  // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2
3
4
5
  /******************************************************************************
   *
   * Module Name: excreate - Named object creation
   *
800ba7c5e   Bob Moore   ACPICA: All acpic...
6
   * Copyright (C) 2000 - 2020, Intel Corp.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
7
   *
958576388   Erik Schmauss   ACPICA: adding SP...
8
   *****************************************************************************/
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
9

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
10
  #include <acpi/acpi.h>
e2f7a7772   Len Brown   ACPICA: hide priv...
11
12
13
14
  #include "accommon.h"
  #include "acinterp.h"
  #include "amlcode.h"
  #include "acnamesp.h"
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
15

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
16
  #define _COMPONENT          ACPI_EXECUTER
4be44fcd3   Len Brown   [ACPI] Lindent al...
17
  ACPI_MODULE_NAME("excreate")
44f6c0124   Robert Moore   ACPICA 20050408 f...
18
  /*******************************************************************************
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
19
20
21
22
23
24
25
26
27
   *
   * FUNCTION:    acpi_ex_create_alias
   *
   * PARAMETERS:  walk_state           - Current state, contains operands
   *
   * RETURN:      Status
   *
   * DESCRIPTION: Create a new named alias
   *
44f6c0124   Robert Moore   ACPICA 20050408 f...
28
   ******************************************************************************/
4be44fcd3   Len Brown   [ACPI] Lindent al...
29
  acpi_status acpi_ex_create_alias(struct acpi_walk_state *walk_state)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
30
  {
4be44fcd3   Len Brown   [ACPI] Lindent al...
31
32
33
  	struct acpi_namespace_node *target_node;
  	struct acpi_namespace_node *alias_node;
  	acpi_status status = AE_OK;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
34

b229cf92e   Bob Moore   ACPI: ACPICA 2006...
35
  	ACPI_FUNCTION_TRACE(ex_create_alias);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
36
37
  
  	/* Get the source/alias operands (both namespace nodes) */
4be44fcd3   Len Brown   [ACPI] Lindent al...
38
39
  	alias_node = (struct acpi_namespace_node *)walk_state->operands[0];
  	target_node = (struct acpi_namespace_node *)walk_state->operands[1];
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
40
41
  
  	if ((target_node->type == ACPI_TYPE_LOCAL_ALIAS) ||
4be44fcd3   Len Brown   [ACPI] Lindent al...
42
  	    (target_node->type == ACPI_TYPE_LOCAL_METHOD_ALIAS)) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
43
44
  		/*
  		 * Dereference an existing alias so that we don't create a chain
73a3090a2   Bob Moore   ACPICA: Remove ex...
45
  		 * of aliases. With this code, we guarantee that an alias is
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
46
47
48
  		 * always exactly one level of indirection away from the
  		 * actual aliased name.
  		 */
4be44fcd3   Len Brown   [ACPI] Lindent al...
49
50
51
  		target_node =
  		    ACPI_CAST_PTR(struct acpi_namespace_node,
  				  target_node->object);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
52
  	}
4e6cbe568   Alex James   ACPICA: iASL: Ens...
53
54
  
  	/* Ensure that the target node is valid */
a5b6e982f   Bob Moore   ACPICA: Interpret...
55

4e6cbe568   Alex James   ACPICA: iASL: Ens...
56
57
58
  	if (!target_node) {
  		return_ACPI_STATUS(AE_NULL_OBJECT);
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
59

a5b6e982f   Bob Moore   ACPICA: Interpret...
60
  	/* Construct the alias object (a namespace node) */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
61

a5b6e982f   Bob Moore   ACPICA: Interpret...
62
  	switch (target_node->type) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
63
  	case ACPI_TYPE_METHOD:
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
64
  		/*
a5b6e982f   Bob Moore   ACPICA: Interpret...
65
66
  		 * Control method aliases need to be differentiated with
  		 * a special type
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
67
68
  		 */
  		alias_node->type = ACPI_TYPE_LOCAL_METHOD_ALIAS;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
69
70
71
  		break;
  
  	default:
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
72
  		/*
a5b6e982f   Bob Moore   ACPICA: Interpret...
73
74
75
76
  		 * All other object types.
  		 *
  		 * The new alias has the type ALIAS and points to the original
  		 * NS node, not the object itself.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
77
  		 */
a5b6e982f   Bob Moore   ACPICA: Interpret...
78
79
80
  		alias_node->type = ACPI_TYPE_LOCAL_ALIAS;
  		alias_node->object =
  		    ACPI_CAST_PTR(union acpi_operand_object, target_node);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
81
82
83
84
  		break;
  	}
  
  	/* Since both operands are Nodes, we don't need to delete them */
a5b6e982f   Bob Moore   ACPICA: Interpret...
85
86
  	alias_node->object =
  	    ACPI_CAST_PTR(union acpi_operand_object, target_node);
4be44fcd3   Len Brown   [ACPI] Lindent al...
87
  	return_ACPI_STATUS(status);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
88
  }
44f6c0124   Robert Moore   ACPICA 20050408 f...
89
  /*******************************************************************************
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
90
91
92
93
94
95
96
97
98
   *
   * FUNCTION:    acpi_ex_create_event
   *
   * PARAMETERS:  walk_state          - Current state
   *
   * RETURN:      Status
   *
   * DESCRIPTION: Create a new event object
   *
44f6c0124   Robert Moore   ACPICA 20050408 f...
99
   ******************************************************************************/
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
100

4be44fcd3   Len Brown   [ACPI] Lindent al...
101
  acpi_status acpi_ex_create_event(struct acpi_walk_state *walk_state)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
102
  {
4be44fcd3   Len Brown   [ACPI] Lindent al...
103
104
  	acpi_status status;
  	union acpi_operand_object *obj_desc;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
105

b229cf92e   Bob Moore   ACPI: ACPICA 2006...
106
  	ACPI_FUNCTION_TRACE(ex_create_event);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
107

4be44fcd3   Len Brown   [ACPI] Lindent al...
108
  	obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_EVENT);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
109
110
111
112
113
114
115
116
117
  	if (!obj_desc) {
  		status = AE_NO_MEMORY;
  		goto cleanup;
  	}
  
  	/*
  	 * Create the actual OS semaphore, with zero initial units -- meaning
  	 * that the event is created in an unsignalled state
  	 */
4be44fcd3   Len Brown   [ACPI] Lindent al...
118
  	status = acpi_os_create_semaphore(ACPI_NO_UNIT_LIMIT, 0,
967440e3b   Bob Moore   ACPI: ACPICA 2006...
119
  					  &obj_desc->event.os_semaphore);
4be44fcd3   Len Brown   [ACPI] Lindent al...
120
  	if (ACPI_FAILURE(status)) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
121
122
123
124
  		goto cleanup;
  	}
  
  	/* Attach object to the Node */
1fad87385   Bob Moore   ACPICA: Core: Maj...
125
126
127
  	status = acpi_ns_attach_object((struct acpi_namespace_node *)
  				       walk_state->operands[0], obj_desc,
  				       ACPI_TYPE_EVENT);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
128

10622bf8c   Lv Zheng   ACPICA: Linuxize:...
129
  cleanup:
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
130
131
132
133
  	/*
  	 * Remove local reference to the object (on error, will cause deletion
  	 * of both object and semaphore if present.)
  	 */
4be44fcd3   Len Brown   [ACPI] Lindent al...
134
135
  	acpi_ut_remove_reference(obj_desc);
  	return_ACPI_STATUS(status);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
136
  }
44f6c0124   Robert Moore   ACPICA 20050408 f...
137
  /*******************************************************************************
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
138
139
140
141
142
143
144
145
146
147
148
   *
   * FUNCTION:    acpi_ex_create_mutex
   *
   * PARAMETERS:  walk_state          - Current state
   *
   * RETURN:      Status
   *
   * DESCRIPTION: Create a new mutex object
   *
   *              Mutex (Name[0], sync_level[1])
   *
44f6c0124   Robert Moore   ACPICA 20050408 f...
149
   ******************************************************************************/
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
150

4be44fcd3   Len Brown   [ACPI] Lindent al...
151
  acpi_status acpi_ex_create_mutex(struct acpi_walk_state *walk_state)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
152
  {
4be44fcd3   Len Brown   [ACPI] Lindent al...
153
154
  	acpi_status status = AE_OK;
  	union acpi_operand_object *obj_desc;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
155

b229cf92e   Bob Moore   ACPI: ACPICA 2006...
156
  	ACPI_FUNCTION_TRACE_PTR(ex_create_mutex, ACPI_WALK_OPERANDS);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
157
158
  
  	/* Create the new mutex object */
4be44fcd3   Len Brown   [ACPI] Lindent al...
159
  	obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_MUTEX);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
160
161
162
163
  	if (!obj_desc) {
  		status = AE_NO_MEMORY;
  		goto cleanup;
  	}
967440e3b   Bob Moore   ACPI: ACPICA 2006...
164
165
166
  	/* Create the actual OS Mutex */
  
  	status = acpi_os_create_mutex(&obj_desc->mutex.os_mutex);
4be44fcd3   Len Brown   [ACPI] Lindent al...
167
  	if (ACPI_FAILURE(status)) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
168
169
170
171
  		goto cleanup;
  	}
  
  	/* Init object and attach to NS node */
1f86e8c1c   Lv Zheng   ACPICA: Fix inden...
172
  	obj_desc->mutex.sync_level = (u8)walk_state->operands[1]->integer.value;
4be44fcd3   Len Brown   [ACPI] Lindent al...
173
174
  	obj_desc->mutex.node =
  	    (struct acpi_namespace_node *)walk_state->operands[0];
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
175

61686124f   Bob Moore   [ACPI] ACPICA 200...
176
177
178
  	status =
  	    acpi_ns_attach_object(obj_desc->mutex.node, obj_desc,
  				  ACPI_TYPE_MUTEX);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
179

10622bf8c   Lv Zheng   ACPICA: Linuxize:...
180
  cleanup:
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
181
182
183
184
  	/*
  	 * Remove local reference to the object (on error, will cause deletion
  	 * of both object and semaphore if present.)
  	 */
4be44fcd3   Len Brown   [ACPI] Lindent al...
185
186
  	acpi_ut_remove_reference(obj_desc);
  	return_ACPI_STATUS(status);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
187
  }
44f6c0124   Robert Moore   ACPICA 20050408 f...
188
  /*******************************************************************************
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
189
190
191
192
193
   *
   * FUNCTION:    acpi_ex_create_region
   *
   * PARAMETERS:  aml_start           - Pointer to the region declaration AML
   *              aml_length          - Max length of the declaration AML
ec4636669   Bob Moore   ACPICA: Do not ab...
194
   *              space_id            - Address space ID for the region
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
195
196
197
198
199
200
   *              walk_state          - Current state
   *
   * RETURN:      Status
   *
   * DESCRIPTION: Create a new operation region object
   *
44f6c0124   Robert Moore   ACPICA 20050408 f...
201
   ******************************************************************************/
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
202
203
  
  acpi_status
4be44fcd3   Len Brown   [ACPI] Lindent al...
204
205
  acpi_ex_create_region(u8 * aml_start,
  		      u32 aml_length,
ec4636669   Bob Moore   ACPICA: Do not ab...
206
  		      u8 space_id, struct acpi_walk_state *walk_state)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
207
  {
4be44fcd3   Len Brown   [ACPI] Lindent al...
208
209
210
211
  	acpi_status status;
  	union acpi_operand_object *obj_desc;
  	struct acpi_namespace_node *node;
  	union acpi_operand_object *region_obj2;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
212

b229cf92e   Bob Moore   ACPI: ACPICA 2006...
213
  	ACPI_FUNCTION_TRACE(ex_create_region);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
214
215
216
217
218
219
220
221
222
  
  	/* Get the Namespace Node */
  
  	node = walk_state->op->common.node;
  
  	/*
  	 * If the region object is already attached to this node,
  	 * just return
  	 */
4be44fcd3   Len Brown   [ACPI] Lindent al...
223
224
  	if (acpi_ns_get_attached_object(node)) {
  		return_ACPI_STATUS(AE_OK);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
225
226
227
228
229
230
  	}
  
  	/*
  	 * Space ID must be one of the predefined IDs, or in the user-defined
  	 * range
  	 */
ec4636669   Bob Moore   ACPICA: Do not ab...
231
232
233
234
235
236
237
238
239
  	if (!acpi_is_valid_space_id(space_id)) {
  		/*
  		 * Print an error message, but continue. We don't want to abort
  		 * a table load for this exception. Instead, if the region is
  		 * actually used at runtime, abort the executing method.
  		 */
  		ACPI_ERROR((AE_INFO,
  			    "Invalid/unknown Address Space ID: 0x%2.2X",
  			    space_id));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
240
  	}
f6a22b0bc   Bob Moore   ACPICA: Standardi...
241
242
  	ACPI_DEBUG_PRINT((ACPI_DB_LOAD, "Region Type - %s (0x%X)
  ",
ec4636669   Bob Moore   ACPICA: Do not ab...
243
  			  acpi_ut_get_region_name(space_id), space_id));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
244
245
  
  	/* Create the region descriptor */
4be44fcd3   Len Brown   [ACPI] Lindent al...
246
  	obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_REGION);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
247
248
249
250
251
252
253
254
255
  	if (!obj_desc) {
  		status = AE_NO_MEMORY;
  		goto cleanup;
  	}
  
  	/*
  	 * Remember location in AML stream of address & length
  	 * operands since they need to be evaluated at run time.
  	 */
849c25719   Lv Zheng   ACPICA: Events: S...
256
  	region_obj2 = acpi_ns_get_secondary_object(obj_desc);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
257
258
  	region_obj2->extra.aml_start = aml_start;
  	region_obj2->extra.aml_length = aml_length;
849c25719   Lv Zheng   ACPICA: Events: S...
259
  	region_obj2->extra.method_REG = NULL;
8931d9ea7   Lin Ming   ACPICA: Fix to al...
260
261
262
263
264
265
  	if (walk_state->scope_info) {
  		region_obj2->extra.scope_node =
  		    walk_state->scope_info->scope.node;
  	} else {
  		region_obj2->extra.scope_node = node;
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
266
267
  
  	/* Init the region from the operands */
ec4636669   Bob Moore   ACPICA: Do not ab...
268
  	obj_desc->region.space_id = space_id;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
269
270
  	obj_desc->region.address = 0;
  	obj_desc->region.length = 0;
4be44fcd3   Len Brown   [ACPI] Lindent al...
271
  	obj_desc->region.node = node;
849c25719   Lv Zheng   ACPICA: Events: S...
272
273
  	obj_desc->region.handler = NULL;
  	obj_desc->common.flags &=
efaed9be9   Lv Zheng   ACPICA: Events: E...
274
275
  	    ~(AOPOBJ_SETUP_COMPLETE | AOPOBJ_REG_CONNECTED |
  	      AOPOBJ_OBJECT_INITIALIZED);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
276
277
  
  	/* Install the new region object in the parent Node */
4be44fcd3   Len Brown   [ACPI] Lindent al...
278
  	status = acpi_ns_attach_object(node, obj_desc, ACPI_TYPE_REGION);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
279

10622bf8c   Lv Zheng   ACPICA: Linuxize:...
280
  cleanup:
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
281
282
  
  	/* Remove local reference to the object */
4be44fcd3   Len Brown   [ACPI] Lindent al...
283
284
  	acpi_ut_remove_reference(obj_desc);
  	return_ACPI_STATUS(status);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
285
  }
44f6c0124   Robert Moore   ACPICA 20050408 f...
286
  /*******************************************************************************
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
287
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
288
289
290
291
292
293
294
295
   * FUNCTION:    acpi_ex_create_processor
   *
   * PARAMETERS:  walk_state          - Current state
   *
   * RETURN:      Status
   *
   * DESCRIPTION: Create a new processor object and populate the fields
   *
ba494beea   Bob Moore   ACPICA: AcpiSrc: ...
296
   *              Processor (Name[0], cpu_ID[1], pblock_addr[2], pblock_length[3])
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
297
   *
44f6c0124   Robert Moore   ACPICA 20050408 f...
298
   ******************************************************************************/
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
299

4be44fcd3   Len Brown   [ACPI] Lindent al...
300
  acpi_status acpi_ex_create_processor(struct acpi_walk_state *walk_state)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
301
  {
4be44fcd3   Len Brown   [ACPI] Lindent al...
302
303
304
  	union acpi_operand_object **operand = &walk_state->operands[0];
  	union acpi_operand_object *obj_desc;
  	acpi_status status;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
305

b229cf92e   Bob Moore   ACPI: ACPICA 2006...
306
  	ACPI_FUNCTION_TRACE_PTR(ex_create_processor, walk_state);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
307
308
  
  	/* Create the processor object */
4be44fcd3   Len Brown   [ACPI] Lindent al...
309
  	obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_PROCESSOR);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
310
  	if (!obj_desc) {
4be44fcd3   Len Brown   [ACPI] Lindent al...
311
  		return_ACPI_STATUS(AE_NO_MEMORY);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
312
  	}
44f6c0124   Robert Moore   ACPICA 20050408 f...
313
  	/* Initialize the processor object from the operands */
4be44fcd3   Len Brown   [ACPI] Lindent al...
314
  	obj_desc->processor.proc_id = (u8) operand[1]->integer.value;
61686124f   Bob Moore   [ACPI] ACPICA 200...
315
  	obj_desc->processor.length = (u8) operand[3]->integer.value;
4be44fcd3   Len Brown   [ACPI] Lindent al...
316
  	obj_desc->processor.address =
f5c1e1c5a   Lv Zheng   ACPICA: Divergenc...
317
  	    (acpi_io_address)operand[2]->integer.value;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
318
319
  
  	/* Install the processor object in the parent Node */
4be44fcd3   Len Brown   [ACPI] Lindent al...
320
321
  	status = acpi_ns_attach_object((struct acpi_namespace_node *)operand[0],
  				       obj_desc, ACPI_TYPE_PROCESSOR);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
322
323
  
  	/* Remove local reference to the object */
4be44fcd3   Len Brown   [ACPI] Lindent al...
324
325
  	acpi_ut_remove_reference(obj_desc);
  	return_ACPI_STATUS(status);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
326
  }
44f6c0124   Robert Moore   ACPICA 20050408 f...
327
  /*******************************************************************************
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
328
329
330
331
332
333
334
335
336
337
338
   *
   * FUNCTION:    acpi_ex_create_power_resource
   *
   * PARAMETERS:  walk_state          - Current state
   *
   * RETURN:      Status
   *
   * DESCRIPTION: Create a new power_resource object and populate the fields
   *
   *              power_resource (Name[0], system_level[1], resource_order[2])
   *
44f6c0124   Robert Moore   ACPICA 20050408 f...
339
   ******************************************************************************/
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
340

4be44fcd3   Len Brown   [ACPI] Lindent al...
341
  acpi_status acpi_ex_create_power_resource(struct acpi_walk_state *walk_state)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
342
  {
4be44fcd3   Len Brown   [ACPI] Lindent al...
343
344
345
  	union acpi_operand_object **operand = &walk_state->operands[0];
  	acpi_status status;
  	union acpi_operand_object *obj_desc;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
346

b229cf92e   Bob Moore   ACPI: ACPICA 2006...
347
  	ACPI_FUNCTION_TRACE_PTR(ex_create_power_resource, walk_state);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
348
349
  
  	/* Create the power resource object */
4be44fcd3   Len Brown   [ACPI] Lindent al...
350
  	obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_POWER);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
351
  	if (!obj_desc) {
4be44fcd3   Len Brown   [ACPI] Lindent al...
352
  		return_ACPI_STATUS(AE_NO_MEMORY);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
353
354
355
356
357
  	}
  
  	/* Initialize the power object from the operands */
  
  	obj_desc->power_resource.system_level = (u8) operand[1]->integer.value;
4be44fcd3   Len Brown   [ACPI] Lindent al...
358
359
  	obj_desc->power_resource.resource_order =
  	    (u16) operand[2]->integer.value;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
360
361
  
  	/* Install the  power resource object in the parent Node */
4be44fcd3   Len Brown   [ACPI] Lindent al...
362
363
  	status = acpi_ns_attach_object((struct acpi_namespace_node *)operand[0],
  				       obj_desc, ACPI_TYPE_POWER);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
364
365
  
  	/* Remove local reference to the object */
4be44fcd3   Len Brown   [ACPI] Lindent al...
366
367
  	acpi_ut_remove_reference(obj_desc);
  	return_ACPI_STATUS(status);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
368
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
369

44f6c0124   Robert Moore   ACPICA 20050408 f...
370
  /*******************************************************************************
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
371
372
373
374
375
376
377
378
379
380
381
   *
   * FUNCTION:    acpi_ex_create_method
   *
   * PARAMETERS:  aml_start       - First byte of the method's AML
   *              aml_length      - AML byte count for this method
   *              walk_state      - Current state
   *
   * RETURN:      Status
   *
   * DESCRIPTION: Create a new method object
   *
44f6c0124   Robert Moore   ACPICA 20050408 f...
382
   ******************************************************************************/
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
383
384
  
  acpi_status
4be44fcd3   Len Brown   [ACPI] Lindent al...
385
386
  acpi_ex_create_method(u8 * aml_start,
  		      u32 aml_length, struct acpi_walk_state *walk_state)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
387
  {
4be44fcd3   Len Brown   [ACPI] Lindent al...
388
389
390
391
  	union acpi_operand_object **operand = &walk_state->operands[0];
  	union acpi_operand_object *obj_desc;
  	acpi_status status;
  	u8 method_flags;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
392

b229cf92e   Bob Moore   ACPI: ACPICA 2006...
393
  	ACPI_FUNCTION_TRACE_PTR(ex_create_method, walk_state);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
394
395
  
  	/* Create a new method object */
4be44fcd3   Len Brown   [ACPI] Lindent al...
396
  	obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_METHOD);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
397
  	if (!obj_desc) {
f3d2e7865   Bob Moore   ACPICA: Implement...
398
399
  		status = AE_NO_MEMORY;
  		goto exit;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
400
401
402
403
404
405
  	}
  
  	/* Save the method's AML pointer and length  */
  
  	obj_desc->method.aml_start = aml_start;
  	obj_desc->method.aml_length = aml_length;
07b9c9122   Lv Zheng   ACPICA: Executer:...
406
  	obj_desc->method.node = operand[0];
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
407
408
  
  	/*
262948428   Lin Ming   ACPICA: Fix issue...
409
410
  	 * Disassemble the method flags. Split off the arg_count, Serialized
  	 * flag, and sync_level for efficiency.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
411
  	 */
5431b6543   Lv Zheng   ACPICA: Linuxize:...
412
  	method_flags = (u8)operand[1]->integer.value;
1fad87385   Bob Moore   ACPICA: Core: Maj...
413
414
  	obj_desc->method.param_count = (u8)
  	    (method_flags & AML_METHOD_ARG_COUNT);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
415
416
  
  	/*
967440e3b   Bob Moore   ACPI: ACPICA 2006...
417
  	 * Get the sync_level. If method is serialized, a mutex will be
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
418
419
  	 * created for this method when it is parsed.
  	 */
4d2acd9ea   Len Brown   Revert "ACPICA: r...
420
  	if (method_flags & AML_METHOD_SERIALIZED) {
262948428   Lin Ming   ACPICA: Fix issue...
421
  		obj_desc->method.info_flags = ACPI_METHOD_SERIALIZED;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
422
  		/*
967440e3b   Bob Moore   ACPI: ACPICA 2006...
423
424
  		 * ACPI 1.0: sync_level = 0
  		 * ACPI 2.0: sync_level = sync_level in method declaration
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
425
  		 */
967440e3b   Bob Moore   ACPI: ACPICA 2006...
426
  		obj_desc->method.sync_level = (u8)
b2f7ddcfc   Lin Ming   ACPICA: New: Acpi...
427
  		    ((method_flags & AML_METHOD_SYNC_LEVEL) >> 4);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
428
429
430
  	}
  
  	/* Attach the new object to the method Node */
4be44fcd3   Len Brown   [ACPI] Lindent al...
431
432
  	status = acpi_ns_attach_object((struct acpi_namespace_node *)operand[0],
  				       obj_desc, ACPI_TYPE_METHOD);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
433
434
  
  	/* Remove local reference to the object */
4be44fcd3   Len Brown   [ACPI] Lindent al...
435
  	acpi_ut_remove_reference(obj_desc);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
436

10622bf8c   Lv Zheng   ACPICA: Linuxize:...
437
  exit:
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
438
  	/* Remove a reference to the operand */
4be44fcd3   Len Brown   [ACPI] Lindent al...
439
440
  	acpi_ut_remove_reference(operand[1]);
  	return_ACPI_STATUS(status);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
441
  }