dt-bindings: mtd: ingenic: Use standard ecc-engine property
[linux/fpc-iii.git] / drivers / acpi / acpica / nsobject.c
blob8638f43cfc3d87184c9a0cc91318f07ab5abff8a
1 // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
2 /*******************************************************************************
4 * Module Name: nsobject - Utilities for objects attached to namespace
5 * table entries
7 ******************************************************************************/
9 #include <acpi/acpi.h>
10 #include "accommon.h"
11 #include "acnamesp.h"
13 #define _COMPONENT ACPI_NAMESPACE
14 ACPI_MODULE_NAME("nsobject")
16 /*******************************************************************************
18 * FUNCTION: acpi_ns_attach_object
20 * PARAMETERS: node - Parent Node
21 * object - Object to be attached
22 * type - Type of object, or ACPI_TYPE_ANY if not
23 * known
25 * RETURN: Status
27 * DESCRIPTION: Record the given object as the value associated with the
28 * name whose acpi_handle is passed. If Object is NULL
29 * and Type is ACPI_TYPE_ANY, set the name as having no value.
30 * Note: Future may require that the Node->Flags field be passed
31 * as a parameter.
33 * MUTEX: Assumes namespace is locked
35 ******************************************************************************/
36 acpi_status
37 acpi_ns_attach_object(struct acpi_namespace_node *node,
38 union acpi_operand_object *object, acpi_object_type type)
40 union acpi_operand_object *obj_desc;
41 union acpi_operand_object *last_obj_desc;
42 acpi_object_type object_type = ACPI_TYPE_ANY;
44 ACPI_FUNCTION_TRACE(ns_attach_object);
47 * Parameter validation
49 if (!node) {
51 /* Invalid handle */
53 ACPI_ERROR((AE_INFO, "Null NamedObj handle"));
54 return_ACPI_STATUS(AE_BAD_PARAMETER);
57 if (!object && (ACPI_TYPE_ANY != type)) {
59 /* Null object */
61 ACPI_ERROR((AE_INFO,
62 "Null object, but type not ACPI_TYPE_ANY"));
63 return_ACPI_STATUS(AE_BAD_PARAMETER);
66 if (ACPI_GET_DESCRIPTOR_TYPE(node) != ACPI_DESC_TYPE_NAMED) {
68 /* Not a name handle */
70 ACPI_ERROR((AE_INFO, "Invalid handle %p [%s]",
71 node, acpi_ut_get_descriptor_name(node)));
72 return_ACPI_STATUS(AE_BAD_PARAMETER);
75 /* Check if this object is already attached */
77 if (node->object == object) {
78 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
79 "Obj %p already installed in NameObj %p\n",
80 object, node));
82 return_ACPI_STATUS(AE_OK);
85 /* If null object, we will just install it */
87 if (!object) {
88 obj_desc = NULL;
89 object_type = ACPI_TYPE_ANY;
93 * If the source object is a namespace Node with an attached object,
94 * we will use that (attached) object
96 else if ((ACPI_GET_DESCRIPTOR_TYPE(object) == ACPI_DESC_TYPE_NAMED) &&
97 ((struct acpi_namespace_node *)object)->object) {
99 * Value passed is a name handle and that name has a
100 * non-null value. Use that name's value and type.
102 obj_desc = ((struct acpi_namespace_node *)object)->object;
103 object_type = ((struct acpi_namespace_node *)object)->type;
107 * Otherwise, we will use the parameter object, but we must type
108 * it first
110 else {
111 obj_desc = (union acpi_operand_object *)object;
113 /* Use the given type */
115 object_type = type;
118 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Installing %p into Node %p [%4.4s]\n",
119 obj_desc, node, acpi_ut_get_node_name(node)));
121 /* Detach an existing attached object if present */
123 if (node->object) {
124 acpi_ns_detach_object(node);
127 if (obj_desc) {
129 * Must increment the new value's reference count
130 * (if it is an internal object)
132 acpi_ut_add_reference(obj_desc);
135 * Handle objects with multiple descriptors - walk
136 * to the end of the descriptor list
138 last_obj_desc = obj_desc;
139 while (last_obj_desc->common.next_object) {
140 last_obj_desc = last_obj_desc->common.next_object;
143 /* Install the object at the front of the object list */
145 last_obj_desc->common.next_object = node->object;
148 node->type = (u8) object_type;
149 node->object = obj_desc;
151 return_ACPI_STATUS(AE_OK);
154 /*******************************************************************************
156 * FUNCTION: acpi_ns_detach_object
158 * PARAMETERS: node - A Namespace node whose object will be detached
160 * RETURN: None.
162 * DESCRIPTION: Detach/delete an object associated with a namespace node.
163 * if the object is an allocated object, it is freed.
164 * Otherwise, the field is simply cleared.
166 ******************************************************************************/
168 void acpi_ns_detach_object(struct acpi_namespace_node *node)
170 union acpi_operand_object *obj_desc;
172 ACPI_FUNCTION_TRACE(ns_detach_object);
174 obj_desc = node->object;
176 if (!obj_desc || (obj_desc->common.type == ACPI_TYPE_LOCAL_DATA)) {
177 return_VOID;
180 if (node->flags & ANOBJ_ALLOCATED_BUFFER) {
182 /* Free the dynamic aml buffer */
184 if (obj_desc->common.type == ACPI_TYPE_METHOD) {
185 ACPI_FREE(obj_desc->method.aml_start);
189 /* Clear the Node entry in all cases */
191 node->object = NULL;
192 if (ACPI_GET_DESCRIPTOR_TYPE(obj_desc) == ACPI_DESC_TYPE_OPERAND) {
194 /* Unlink object from front of possible object list */
196 node->object = obj_desc->common.next_object;
198 /* Handle possible 2-descriptor object */
200 if (node->object &&
201 (node->object->common.type != ACPI_TYPE_LOCAL_DATA)) {
202 node->object = node->object->common.next_object;
206 * Detach the object from any data objects (which are still held by
207 * the namespace node)
209 if (obj_desc->common.next_object &&
210 ((obj_desc->common.next_object)->common.type ==
211 ACPI_TYPE_LOCAL_DATA)) {
212 obj_desc->common.next_object = NULL;
216 /* Reset the node type to untyped */
218 node->type = ACPI_TYPE_ANY;
220 ACPI_DEBUG_PRINT((ACPI_DB_NAMES, "Node %p [%4.4s] Object %p\n",
221 node, acpi_ut_get_node_name(node), obj_desc));
223 /* Remove one reference on the object (and all subobjects) */
225 acpi_ut_remove_reference(obj_desc);
226 return_VOID;
229 /*******************************************************************************
231 * FUNCTION: acpi_ns_get_attached_object
233 * PARAMETERS: node - Namespace node
235 * RETURN: Current value of the object field from the Node whose
236 * handle is passed
238 * DESCRIPTION: Obtain the object attached to a namespace node.
240 ******************************************************************************/
242 union acpi_operand_object *acpi_ns_get_attached_object(struct
243 acpi_namespace_node
244 *node)
246 ACPI_FUNCTION_TRACE_PTR(ns_get_attached_object, node);
248 if (!node) {
249 ACPI_WARNING((AE_INFO, "Null Node ptr"));
250 return_PTR(NULL);
253 if (!node->object ||
254 ((ACPI_GET_DESCRIPTOR_TYPE(node->object) != ACPI_DESC_TYPE_OPERAND)
255 && (ACPI_GET_DESCRIPTOR_TYPE(node->object) !=
256 ACPI_DESC_TYPE_NAMED))
257 || ((node->object)->common.type == ACPI_TYPE_LOCAL_DATA)) {
258 return_PTR(NULL);
261 return_PTR(node->object);
264 /*******************************************************************************
266 * FUNCTION: acpi_ns_get_secondary_object
268 * PARAMETERS: node - Namespace node
270 * RETURN: Current value of the object field from the Node whose
271 * handle is passed.
273 * DESCRIPTION: Obtain a secondary object associated with a namespace node.
275 ******************************************************************************/
277 union acpi_operand_object *acpi_ns_get_secondary_object(union
278 acpi_operand_object
279 *obj_desc)
281 ACPI_FUNCTION_TRACE_PTR(ns_get_secondary_object, obj_desc);
283 if ((!obj_desc) ||
284 (obj_desc->common.type == ACPI_TYPE_LOCAL_DATA) ||
285 (!obj_desc->common.next_object) ||
286 ((obj_desc->common.next_object)->common.type ==
287 ACPI_TYPE_LOCAL_DATA)) {
288 return_PTR(NULL);
291 return_PTR(obj_desc->common.next_object);
294 /*******************************************************************************
296 * FUNCTION: acpi_ns_attach_data
298 * PARAMETERS: node - Namespace node
299 * handler - Handler to be associated with the data
300 * data - Data to be attached
302 * RETURN: Status
304 * DESCRIPTION: Low-level attach data. Create and attach a Data object.
306 ******************************************************************************/
308 acpi_status
309 acpi_ns_attach_data(struct acpi_namespace_node *node,
310 acpi_object_handler handler, void *data)
312 union acpi_operand_object *prev_obj_desc;
313 union acpi_operand_object *obj_desc;
314 union acpi_operand_object *data_desc;
316 /* We only allow one attachment per handler */
318 prev_obj_desc = NULL;
319 obj_desc = node->object;
320 while (obj_desc) {
321 if ((obj_desc->common.type == ACPI_TYPE_LOCAL_DATA) &&
322 (obj_desc->data.handler == handler)) {
323 return (AE_ALREADY_EXISTS);
326 prev_obj_desc = obj_desc;
327 obj_desc = obj_desc->common.next_object;
330 /* Create an internal object for the data */
332 data_desc = acpi_ut_create_internal_object(ACPI_TYPE_LOCAL_DATA);
333 if (!data_desc) {
334 return (AE_NO_MEMORY);
337 data_desc->data.handler = handler;
338 data_desc->data.pointer = data;
340 /* Install the data object */
342 if (prev_obj_desc) {
343 prev_obj_desc->common.next_object = data_desc;
344 } else {
345 node->object = data_desc;
348 return (AE_OK);
351 /*******************************************************************************
353 * FUNCTION: acpi_ns_detach_data
355 * PARAMETERS: node - Namespace node
356 * handler - Handler associated with the data
358 * RETURN: Status
360 * DESCRIPTION: Low-level detach data. Delete the data node, but the caller
361 * is responsible for the actual data.
363 ******************************************************************************/
365 acpi_status
366 acpi_ns_detach_data(struct acpi_namespace_node *node,
367 acpi_object_handler handler)
369 union acpi_operand_object *obj_desc;
370 union acpi_operand_object *prev_obj_desc;
372 prev_obj_desc = NULL;
373 obj_desc = node->object;
374 while (obj_desc) {
375 if ((obj_desc->common.type == ACPI_TYPE_LOCAL_DATA) &&
376 (obj_desc->data.handler == handler)) {
377 if (prev_obj_desc) {
378 prev_obj_desc->common.next_object =
379 obj_desc->common.next_object;
380 } else {
381 node->object = obj_desc->common.next_object;
384 acpi_ut_remove_reference(obj_desc);
385 return (AE_OK);
388 prev_obj_desc = obj_desc;
389 obj_desc = obj_desc->common.next_object;
392 return (AE_NOT_FOUND);
395 /*******************************************************************************
397 * FUNCTION: acpi_ns_get_attached_data
399 * PARAMETERS: node - Namespace node
400 * handler - Handler associated with the data
401 * data - Where the data is returned
403 * RETURN: Status
405 * DESCRIPTION: Low level interface to obtain data previously associated with
406 * a namespace node.
408 ******************************************************************************/
410 acpi_status
411 acpi_ns_get_attached_data(struct acpi_namespace_node *node,
412 acpi_object_handler handler, void **data)
414 union acpi_operand_object *obj_desc;
416 obj_desc = node->object;
417 while (obj_desc) {
418 if ((obj_desc->common.type == ACPI_TYPE_LOCAL_DATA) &&
419 (obj_desc->data.handler == handler)) {
420 *data = obj_desc->data.pointer;
421 return (AE_OK);
424 obj_desc = obj_desc->common.next_object;
427 return (AE_NOT_FOUND);