]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blame - drivers/acpi/acpica/utdelete.c
ACPICA: Update for some debug output. No functional change
[mirror_ubuntu-hirsute-kernel.git] / drivers / acpi / acpica / utdelete.c
CommitLineData
1da177e4
LT
1/*******************************************************************************
2 *
3 * Module Name: utdelete - object deletion and reference count utilities
4 *
5 ******************************************************************************/
6
7/*
da6f8320 8 * Copyright (C) 2000 - 2018, Intel Corp.
1da177e4
LT
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
29 *
30 * NO WARRANTY
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
42 */
43
1da177e4 44#include <acpi/acpi.h>
e2f7a777
LB
45#include "accommon.h"
46#include "acinterp.h"
47#include "acnamesp.h"
48#include "acevents.h"
1da177e4
LT
49
50#define _COMPONENT ACPI_UTILITIES
4be44fcd 51ACPI_MODULE_NAME("utdelete")
1da177e4 52
44f6c012 53/* Local prototypes */
4be44fcd 54static void acpi_ut_delete_internal_obj(union acpi_operand_object *object);
44f6c012
RM
55
56static void
4be44fcd 57acpi_ut_update_ref_count(union acpi_operand_object *object, u32 action);
1da177e4
LT
58
59/*******************************************************************************
60 *
61 * FUNCTION: acpi_ut_delete_internal_obj
62 *
ba494bee 63 * PARAMETERS: object - Object to be deleted
1da177e4
LT
64 *
65 * RETURN: None
66 *
67 * DESCRIPTION: Low level object deletion, after reference counts have been
68 * updated (All reference counts, including sub-objects!)
69 *
70 ******************************************************************************/
71
4be44fcd 72static void acpi_ut_delete_internal_obj(union acpi_operand_object *object)
1da177e4 73{
4be44fcd
LB
74 void *obj_pointer = NULL;
75 union acpi_operand_object *handler_desc;
76 union acpi_operand_object *second_desc;
77 union acpi_operand_object *next_desc;
f953529f 78 union acpi_operand_object *start_desc;
3362a6ba 79 union acpi_operand_object **last_obj_ptr;
1da177e4 80
b229cf92 81 ACPI_FUNCTION_TRACE_PTR(ut_delete_internal_obj, object);
1da177e4
LT
82
83 if (!object) {
84 return_VOID;
85 }
86
87 /*
88 * Must delete or free any pointers within the object that are not
89 * actual ACPI objects (for example, a raw buffer pointer).
90 */
3371c19c 91 switch (object->common.type) {
1da177e4
LT
92 case ACPI_TYPE_STRING:
93
4be44fcd
LB
94 ACPI_DEBUG_PRINT((ACPI_DB_ALLOCATIONS,
95 "**** String %p, ptr %p\n", object,
96 object->string.pointer));
1da177e4
LT
97
98 /* Free the actual string buffer */
99
100 if (!(object->common.flags & AOPOBJ_STATIC_POINTER)) {
52fc0b02 101
1da177e4
LT
102 /* But only if it is NOT a pointer into an ACPI table */
103
104 obj_pointer = object->string.pointer;
105 }
106 break;
107
1da177e4
LT
108 case ACPI_TYPE_BUFFER:
109
4be44fcd
LB
110 ACPI_DEBUG_PRINT((ACPI_DB_ALLOCATIONS,
111 "**** Buffer %p, ptr %p\n", object,
112 object->buffer.pointer));
1da177e4
LT
113
114 /* Free the actual buffer */
115
116 if (!(object->common.flags & AOPOBJ_STATIC_POINTER)) {
52fc0b02 117
1da177e4
LT
118 /* But only if it is NOT a pointer into an ACPI table */
119
120 obj_pointer = object->buffer.pointer;
121 }
122 break;
123
1da177e4
LT
124 case ACPI_TYPE_PACKAGE:
125
4be44fcd
LB
126 ACPI_DEBUG_PRINT((ACPI_DB_ALLOCATIONS,
127 " **** Package of count %X\n",
128 object->package.count));
1da177e4
LT
129
130 /*
131 * Elements of the package are not handled here, they are deleted
132 * separately
133 */
134
135 /* Free the (variable length) element pointer array */
136
137 obj_pointer = object->package.elements;
138 break;
139
2843ae77
BM
140 /*
141 * These objects have a possible list of notify handlers.
142 * Device object also may have a GPE block.
143 */
1da177e4
LT
144 case ACPI_TYPE_DEVICE:
145
146 if (object->device.gpe_block) {
4be44fcd
LB
147 (void)acpi_ev_delete_gpe_block(object->device.
148 gpe_block);
1da177e4
LT
149 }
150
2843ae77
BM
151 /*lint -fallthrough */
152
153 case ACPI_TYPE_PROCESSOR:
154 case ACPI_TYPE_THERMAL:
155
86ed4bc8 156 /* Walk the address handler list for this object */
1da177e4 157
2843ae77 158 handler_desc = object->common_notify.handler;
1da177e4
LT
159 while (handler_desc) {
160 next_desc = handler_desc->address_space.next;
4be44fcd 161 acpi_ut_remove_reference(handler_desc);
1da177e4
LT
162 handler_desc = next_desc;
163 }
164 break;
165
1da177e4
LT
166 case ACPI_TYPE_MUTEX:
167
4be44fcd 168 ACPI_DEBUG_PRINT((ACPI_DB_ALLOCATIONS,
967440e3
BM
169 "***** Mutex %p, OS Mutex %p\n",
170 object, object->mutex.os_mutex));
171
ba886cd4 172 if (object == acpi_gbl_global_lock_mutex) {
c81da666
BM
173
174 /* Global Lock has extra semaphore */
967440e3
BM
175
176 (void)
177 acpi_os_delete_semaphore
178 (acpi_gbl_global_lock_semaphore);
179 acpi_gbl_global_lock_semaphore = NULL;
c81da666
BM
180
181 acpi_os_delete_mutex(object->mutex.os_mutex);
182 acpi_gbl_global_lock_mutex = NULL;
183 } else {
262a7a28 184 acpi_ex_unlink_mutex(object);
c81da666 185 acpi_os_delete_mutex(object->mutex.os_mutex);
967440e3 186 }
1da177e4
LT
187 break;
188
1da177e4
LT
189 case ACPI_TYPE_EVENT:
190
4be44fcd 191 ACPI_DEBUG_PRINT((ACPI_DB_ALLOCATIONS,
967440e3
BM
192 "***** Event %p, OS Semaphore %p\n",
193 object, object->event.os_semaphore));
1da177e4 194
967440e3
BM
195 (void)acpi_os_delete_semaphore(object->event.os_semaphore);
196 object->event.os_semaphore = NULL;
1da177e4
LT
197 break;
198
1da177e4
LT
199 case ACPI_TYPE_METHOD:
200
4be44fcd
LB
201 ACPI_DEBUG_PRINT((ACPI_DB_ALLOCATIONS,
202 "***** Method %p\n", object));
1da177e4 203
967440e3 204 /* Delete the method mutex if it exists */
1da177e4 205
967440e3
BM
206 if (object->method.mutex) {
207 acpi_os_delete_mutex(object->method.mutex->mutex.
208 os_mutex);
209 acpi_ut_delete_object_desc(object->method.mutex);
210 object->method.mutex = NULL;
1da177e4 211 }
1fad8738 212
07b9c912
LZ
213 if (object->method.node) {
214 object->method.node = NULL;
215 }
1da177e4
LT
216 break;
217
1da177e4
LT
218 case ACPI_TYPE_REGION:
219
4be44fcd
LB
220 ACPI_DEBUG_PRINT((ACPI_DB_ALLOCATIONS,
221 "***** Region %p\n", object));
1da177e4 222
f654c0fe
LM
223 /*
224 * Update address_range list. However, only permanent regions
225 * are installed in this list. (Not created within a method)
226 */
227 if (!(object->region.node->flags & ANOBJ_TEMPORARY)) {
228 acpi_ut_remove_address_range(object->region.space_id,
229 object->region.node);
230 }
a5fe1a03 231
4be44fcd 232 second_desc = acpi_ns_get_secondary_object(object);
1da177e4
LT
233 if (second_desc) {
234 /*
235 * Free the region_context if and only if the handler is one of the
236 * default handlers -- and therefore, we created the context object
237 * locally, it was not created by an external caller.
238 */
239 handler_desc = object->region.handler;
240 if (handler_desc) {
3362a6ba
LM
241 next_desc =
242 handler_desc->address_space.region_list;
f953529f 243 start_desc = next_desc;
3362a6ba
LM
244 last_obj_ptr =
245 &handler_desc->address_space.region_list;
246
f953529f 247 /* Remove the region object from the handler list */
3362a6ba
LM
248
249 while (next_desc) {
250 if (next_desc == object) {
251 *last_obj_ptr =
252 next_desc->region.next;
253 break;
254 }
255
f953529f 256 /* Walk the linked list of handlers */
3362a6ba
LM
257
258 last_obj_ptr = &next_desc->region.next;
259 next_desc = next_desc->region.next;
f953529f
BM
260
261 /* Prevent infinite loop if list is corrupted */
262
263 if (next_desc == start_desc) {
264 ACPI_ERROR((AE_INFO,
265 "Circular region list in address handler object %p",
266 handler_desc));
267 return_VOID;
268 }
3362a6ba
LM
269 }
270
61686124 271 if (handler_desc->address_space.handler_flags &
4be44fcd 272 ACPI_ADDR_HANDLER_DEFAULT_INSTALLED) {
793c2388
BM
273
274 /* Deactivate region and free region context */
275
276 if (handler_desc->address_space.setup) {
277 (void)handler_desc->
278 address_space.setup(object,
279 ACPI_REGION_DEACTIVATE,
280 handler_desc->
281 address_space.
282 context,
283 &second_desc->
284 extra.
285 region_context);
286 }
1da177e4
LT
287 }
288
4be44fcd 289 acpi_ut_remove_reference(handler_desc);
1da177e4
LT
290 }
291
292 /* Now we can free the Extra object */
293
4be44fcd 294 acpi_ut_delete_object_desc(second_desc);
1da177e4
LT
295 }
296 break;
297
1da177e4
LT
298 case ACPI_TYPE_BUFFER_FIELD:
299
4be44fcd
LB
300 ACPI_DEBUG_PRINT((ACPI_DB_ALLOCATIONS,
301 "***** Buffer Field %p\n", object));
1da177e4 302
4be44fcd 303 second_desc = acpi_ns_get_secondary_object(object);
1da177e4 304 if (second_desc) {
ef805d95
LM
305 acpi_ut_delete_object_desc(second_desc);
306 }
307 break;
308
309 case ACPI_TYPE_LOCAL_BANK_FIELD:
310
311 ACPI_DEBUG_PRINT((ACPI_DB_ALLOCATIONS,
312 "***** Bank Field %p\n", object));
313
314 second_desc = acpi_ns_get_secondary_object(object);
315 if (second_desc) {
4be44fcd 316 acpi_ut_delete_object_desc(second_desc);
1da177e4
LT
317 }
318 break;
319
1da177e4 320 default:
1d1ea1b7 321
1da177e4
LT
322 break;
323 }
324
325 /* Free any allocated memory (pointer within the object) found above */
326
327 if (obj_pointer) {
4be44fcd
LB
328 ACPI_DEBUG_PRINT((ACPI_DB_ALLOCATIONS,
329 "Deleting Object Subptr %p\n", obj_pointer));
8313524a 330 ACPI_FREE(obj_pointer);
1da177e4
LT
331 }
332
333 /* Now the object can be safely deleted */
334
1ef63231
BM
335 ACPI_DEBUG_PRINT_RAW((ACPI_DB_ALLOCATIONS,
336 "%s: Deleting Object %p [%s]\n",
337 ACPI_GET_FUNCTION_NAME, object,
338 acpi_ut_get_object_type_name(object)));
1da177e4 339
4be44fcd 340 acpi_ut_delete_object_desc(object);
1da177e4
LT
341 return_VOID;
342}
343
1da177e4
LT
344/*******************************************************************************
345 *
346 * FUNCTION: acpi_ut_delete_internal_object_list
347 *
44f6c012 348 * PARAMETERS: obj_list - Pointer to the list to be deleted
1da177e4
LT
349 *
350 * RETURN: None
351 *
352 * DESCRIPTION: This function deletes an internal object list, including both
353 * simple objects and package objects
354 *
355 ******************************************************************************/
356
4be44fcd 357void acpi_ut_delete_internal_object_list(union acpi_operand_object **obj_list)
1da177e4 358{
4be44fcd 359 union acpi_operand_object **internal_obj;
1da177e4 360
c8d586f8 361 ACPI_FUNCTION_ENTRY();
1da177e4
LT
362
363 /* Walk the null-terminated internal list */
364
365 for (internal_obj = obj_list; *internal_obj; internal_obj++) {
4be44fcd 366 acpi_ut_remove_reference(*internal_obj);
1da177e4
LT
367 }
368
369 /* Free the combined parameter pointer list and object array */
370
8313524a 371 ACPI_FREE(obj_list);
0e770b32 372 return;
1da177e4
LT
373}
374
1da177e4
LT
375/*******************************************************************************
376 *
377 * FUNCTION: acpi_ut_update_ref_count
378 *
ba494bee 379 * PARAMETERS: object - Object whose ref count is to be updated
58892c96 380 * action - What to do (REF_INCREMENT or REF_DECREMENT)
1da177e4 381 *
58892c96 382 * RETURN: None. Sets new reference count within the object
1da177e4 383 *
58892c96 384 * DESCRIPTION: Modify the reference count for an internal acpi object
1da177e4
LT
385 *
386 ******************************************************************************/
387
388static void
4be44fcd 389acpi_ut_update_ref_count(union acpi_operand_object *object, u32 action)
1da177e4 390{
58892c96
BM
391 u16 original_count;
392 u16 new_count = 0;
393 acpi_cpu_flags lock_flags;
1da177e4 394
b229cf92 395 ACPI_FUNCTION_NAME(ut_update_ref_count);
1da177e4
LT
396
397 if (!object) {
398 return;
399 }
400
1da177e4 401 /*
58892c96
BM
402 * Always get the reference count lock. Note: Interpreter and/or
403 * Namespace is not always locked when this function is called.
1da177e4 404 */
58892c96
BM
405 lock_flags = acpi_os_acquire_lock(acpi_gbl_reference_count_lock);
406 original_count = object->common.reference_count;
407
408 /* Perform the reference count action (increment, decrement) */
409
1da177e4 410 switch (action) {
1da177e4
LT
411 case REF_INCREMENT:
412
58892c96 413 new_count = original_count + 1;
1da177e4 414 object->common.reference_count = new_count;
58892c96
BM
415 acpi_os_release_lock(acpi_gbl_reference_count_lock, lock_flags);
416
417 /* The current reference count should never be zero here */
418
419 if (!original_count) {
420 ACPI_WARNING((AE_INFO,
421 "Obj %p, Reference Count was zero before increment\n",
422 object));
423 }
1da177e4 424
4be44fcd 425 ACPI_DEBUG_PRINT((ACPI_DB_ALLOCATIONS,
7225d046
BM
426 "Obj %p Type %.2X [%s] Refs %.2X [Incremented]\n",
427 object, object->common.type,
428 acpi_ut_get_object_type_name(object),
429 new_count));
1da177e4
LT
430 break;
431
1da177e4
LT
432 case REF_DECREMENT:
433
58892c96 434 /* The current reference count must be non-zero */
1da177e4 435
58892c96
BM
436 if (original_count) {
437 new_count = original_count - 1;
438 object->common.reference_count = new_count;
1da177e4
LT
439 }
440
58892c96
BM
441 acpi_os_release_lock(acpi_gbl_reference_count_lock, lock_flags);
442
443 if (!original_count) {
444 ACPI_WARNING((AE_INFO,
445 "Obj %p, Reference Count is already zero, cannot decrement\n",
446 object));
1da177e4
LT
447 }
448
1ef63231
BM
449 ACPI_DEBUG_PRINT_RAW((ACPI_DB_ALLOCATIONS,
450 "%s: Obj %p Type %.2X Refs %.2X [Decremented]\n",
451 ACPI_GET_FUNCTION_NAME, object,
452 object->common.type, new_count));
58892c96
BM
453
454 /* Actually delete the object on a reference count of zero */
455
1da177e4 456 if (new_count == 0) {
4be44fcd 457 acpi_ut_delete_internal_obj(object);
1da177e4 458 }
1da177e4
LT
459 break;
460
1da177e4
LT
461 default:
462
58892c96
BM
463 acpi_os_release_lock(acpi_gbl_reference_count_lock, lock_flags);
464 ACPI_ERROR((AE_INFO, "Unknown Reference Count action (0x%X)",
465 action));
466 return;
1da177e4
LT
467 }
468
469 /*
470 * Sanity check the reference count, for debug purposes only.
471 * (A deleted object will have a huge reference count)
472 */
58892c96 473 if (new_count > ACPI_MAX_REFERENCE_COUNT) {
b8e4d893 474 ACPI_WARNING((AE_INFO,
58892c96
BM
475 "Large Reference Count (0x%X) in object %p, Type=0x%.2X",
476 new_count, object, object->common.type));
1da177e4 477 }
1da177e4
LT
478}
479
1da177e4
LT
480/*******************************************************************************
481 *
482 * FUNCTION: acpi_ut_update_object_reference
483 *
ba494bee 484 * PARAMETERS: object - Increment ref count for this object
1da177e4 485 * and all sub-objects
60f3deb5 486 * action - Either REF_INCREMENT or REF_DECREMENT
1da177e4
LT
487 *
488 * RETURN: Status
489 *
490 * DESCRIPTION: Increment the object reference count
491 *
492 * Object references are incremented when:
493 * 1) An object is attached to a Node (namespace object)
494 * 2) An object is copied (all subobjects must be incremented)
495 *
496 * Object references are decremented when:
497 * 1) An object is detached from an Node
498 *
499 ******************************************************************************/
500
501acpi_status
4119532c 502acpi_ut_update_object_reference(union acpi_operand_object *object, u16 action)
1da177e4 503{
4be44fcd
LB
504 acpi_status status = AE_OK;
505 union acpi_generic_state *state_list = NULL;
506 union acpi_operand_object *next_object = NULL;
86ed4bc8 507 union acpi_operand_object *prev_object;
4be44fcd 508 union acpi_generic_state *state;
67a119f9 509 u32 i;
1da177e4 510
0e770b32 511 ACPI_FUNCTION_NAME(ut_update_object_reference);
1da177e4 512
f9f4601f 513 while (object) {
52fc0b02 514
f9f4601f 515 /* Make sure that this isn't a namespace handle */
1da177e4 516
4be44fcd
LB
517 if (ACPI_GET_DESCRIPTOR_TYPE(object) == ACPI_DESC_TYPE_NAMED) {
518 ACPI_DEBUG_PRINT((ACPI_DB_ALLOCATIONS,
519 "Object %p is NS handle\n", object));
0e770b32 520 return (AE_OK);
f9f4601f 521 }
1da177e4
LT
522
523 /*
1fad8738
BM
524 * All sub-objects must have their reference count incremented
525 * also. Different object types have different subobjects.
1da177e4 526 */
3371c19c 527 switch (object->common.type) {
1da177e4 528 case ACPI_TYPE_DEVICE:
f6dd9221
BM
529 case ACPI_TYPE_PROCESSOR:
530 case ACPI_TYPE_POWER:
531 case ACPI_TYPE_THERMAL:
86ed4bc8
BM
532 /*
533 * Update the notify objects for these types (if present)
534 * Two lists, system and device notify handlers.
535 */
536 for (i = 0; i < ACPI_NUM_NOTIFY_TYPES; i++) {
537 prev_object =
538 object->common_notify.notify_list[i];
539 while (prev_object) {
540 next_object =
541 prev_object->notify.next[i];
542 acpi_ut_update_ref_count(prev_object,
543 action);
544 prev_object = next_object;
545 }
546 }
1da177e4
LT
547 break;
548
1da177e4 549 case ACPI_TYPE_PACKAGE:
1da177e4 550 /*
f9f4601f
RM
551 * We must update all the sub-objects of the package,
552 * each of whom may have their own sub-objects.
1da177e4
LT
553 */
554 for (i = 0; i < object->package.count; i++) {
555 /*
53938551
CG
556 * Null package elements are legal and can be simply
557 * ignored.
1da177e4 558 */
53938551
CG
559 next_object = object->package.elements[i];
560 if (!next_object) {
561 continue;
562 }
563
564 switch (next_object->common.type) {
565 case ACPI_TYPE_INTEGER:
566 case ACPI_TYPE_STRING:
567 case ACPI_TYPE_BUFFER:
568 /*
569 * For these very simple sub-objects, we can just
570 * update the reference count here and continue.
571 * Greatly increases performance of this operation.
572 */
573 acpi_ut_update_ref_count(next_object,
574 action);
575 break;
576
577 default:
578 /*
579 * For complex sub-objects, push them onto the stack
580 * for later processing (this eliminates recursion.)
581 */
582 status =
583 acpi_ut_create_update_state_and_push
584 (next_object, action, &state_list);
585 if (ACPI_FAILURE(status)) {
586 goto error_exit;
587 }
588 break;
1da177e4 589 }
1da177e4 590 }
53938551 591 next_object = NULL;
1da177e4
LT
592 break;
593
1da177e4
LT
594 case ACPI_TYPE_BUFFER_FIELD:
595
f9f4601f 596 next_object = object->buffer_field.buffer_obj;
1da177e4
LT
597 break;
598
1da177e4
LT
599 case ACPI_TYPE_LOCAL_REGION_FIELD:
600
f9f4601f
RM
601 next_object = object->field.region_obj;
602 break;
1da177e4
LT
603
604 case ACPI_TYPE_LOCAL_BANK_FIELD:
605
f9f4601f 606 next_object = object->bank_field.bank_obj;
4be44fcd
LB
607 status =
608 acpi_ut_create_update_state_and_push(object->
609 bank_field.
610 region_obj,
611 action,
612 &state_list);
613 if (ACPI_FAILURE(status)) {
1da177e4
LT
614 goto error_exit;
615 }
1da177e4
LT
616 break;
617
1da177e4
LT
618 case ACPI_TYPE_LOCAL_INDEX_FIELD:
619
f9f4601f 620 next_object = object->index_field.index_obj;
4be44fcd
LB
621 status =
622 acpi_ut_create_update_state_and_push(object->
623 index_field.
624 data_obj,
625 action,
626 &state_list);
627 if (ACPI_FAILURE(status)) {
1da177e4
LT
628 goto error_exit;
629 }
1da177e4
LT
630 break;
631
1da177e4 632 case ACPI_TYPE_LOCAL_REFERENCE:
1da177e4 633 /*
9e41d93c
BM
634 * The target of an Index (a package, string, or buffer) or a named
635 * reference must track changes to the ref count of the index or
636 * target object.
1da177e4 637 */
1044f1f6
BM
638 if ((object->reference.class == ACPI_REFCLASS_INDEX) ||
639 (object->reference.class == ACPI_REFCLASS_NAME)) {
f9f4601f 640 next_object = object->reference.object;
1da177e4
LT
641 }
642 break;
643
1da177e4
LT
644 case ACPI_TYPE_REGION:
645 default:
1d1ea1b7 646
4119532c 647 break; /* No subobjects for all other types */
1da177e4
LT
648 }
649
650 /*
4119532c 651 * Now we can update the count in the main object. This can only
1da177e4
LT
652 * happen after we update the sub-objects in case this causes the
653 * main object to be deleted.
654 */
4be44fcd 655 acpi_ut_update_ref_count(object, action);
f9f4601f 656 object = NULL;
1da177e4
LT
657
658 /* Move on to the next object to be updated */
659
f9f4601f
RM
660 if (next_object) {
661 object = next_object;
662 next_object = NULL;
4be44fcd
LB
663 } else if (state_list) {
664 state = acpi_ut_pop_generic_state(&state_list);
f9f4601f 665 object = state->update.object;
4be44fcd 666 acpi_ut_delete_generic_state(state);
f9f4601f 667 }
1da177e4
LT
668 }
669
0e770b32 670 return (AE_OK);
1da177e4 671
10622bf8 672error_exit:
1da177e4 673
b8e4d893
BM
674 ACPI_EXCEPTION((AE_INFO, status,
675 "Could not update object reference count"));
1da177e4 676
cf058bd1
LM
677 /* Free any stacked Update State objects */
678
679 while (state_list) {
680 state = acpi_ut_pop_generic_state(&state_list);
681 acpi_ut_delete_generic_state(state);
682 }
683
0e770b32 684 return (status);
1da177e4
LT
685}
686
1da177e4
LT
687/*******************************************************************************
688 *
689 * FUNCTION: acpi_ut_add_reference
690 *
ba494bee 691 * PARAMETERS: object - Object whose reference count is to be
44f6c012 692 * incremented
1da177e4
LT
693 *
694 * RETURN: None
695 *
696 * DESCRIPTION: Add one reference to an ACPI object
697 *
698 ******************************************************************************/
699
4be44fcd 700void acpi_ut_add_reference(union acpi_operand_object *object)
1da177e4
LT
701{
702
0e770b32 703 ACPI_FUNCTION_NAME(ut_add_reference);
1da177e4
LT
704
705 /* Ensure that we have a valid object */
706
4be44fcd 707 if (!acpi_ut_valid_internal_object(object)) {
0e770b32 708 return;
1da177e4
LT
709 }
710
4be44fcd
LB
711 ACPI_DEBUG_PRINT((ACPI_DB_ALLOCATIONS,
712 "Obj %p Current Refs=%X [To Be Incremented]\n",
713 object, object->common.reference_count));
1da177e4
LT
714
715 /* Increment the reference count */
716
4be44fcd 717 (void)acpi_ut_update_object_reference(object, REF_INCREMENT);
0e770b32 718 return;
1da177e4
LT
719}
720
1da177e4
LT
721/*******************************************************************************
722 *
723 * FUNCTION: acpi_ut_remove_reference
724 *
ba494bee 725 * PARAMETERS: object - Object whose ref count will be decremented
1da177e4
LT
726 *
727 * RETURN: None
728 *
729 * DESCRIPTION: Decrement the reference count of an ACPI internal object
730 *
731 ******************************************************************************/
732
4be44fcd 733void acpi_ut_remove_reference(union acpi_operand_object *object)
1da177e4
LT
734{
735
0e770b32 736 ACPI_FUNCTION_NAME(ut_remove_reference);
1da177e4
LT
737
738 /*
4119532c
BM
739 * Allow a NULL pointer to be passed in, just ignore it. This saves
740 * each caller from having to check. Also, ignore NS nodes.
1da177e4
LT
741 */
742 if (!object ||
4be44fcd 743 (ACPI_GET_DESCRIPTOR_TYPE(object) == ACPI_DESC_TYPE_NAMED)) {
0e770b32 744 return;
1da177e4
LT
745 }
746
747 /* Ensure that we have a valid object */
748
4be44fcd 749 if (!acpi_ut_valid_internal_object(object)) {
0e770b32 750 return;
1da177e4
LT
751 }
752
1ef63231
BM
753 ACPI_DEBUG_PRINT_RAW((ACPI_DB_ALLOCATIONS,
754 "%s: Obj %p Current Refs=%X [To Be Decremented]\n",
755 ACPI_GET_FUNCTION_NAME, object,
756 object->common.reference_count));
1da177e4
LT
757
758 /*
759 * Decrement the reference count, and only actually delete the object
4119532c 760 * if the reference count becomes 0. (Must also decrement the ref count
1da177e4
LT
761 * of all subobjects!)
762 */
4be44fcd 763 (void)acpi_ut_update_object_reference(object, REF_DECREMENT);
0e770b32 764 return;
1da177e4 765}