nsdump.c 22.8 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6 7
/******************************************************************************
 *
 * Module Name: nsdump - table dumping routines for debug
 *
 *****************************************************************************/

/*
8
 * Copyright (C) 2000 - 2015, Intel Corp.
L
Linus Torvalds 已提交
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions, and the following disclaimer,
 *    without modification.
 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
 *    substantially similar to the "NO WARRANTY" disclaimer below
 *    ("Disclaimer") and any redistribution must be conditioned upon
 *    including a substantially similar Disclaimer requirement for further
 *    binary redistribution.
 * 3. Neither the names of the above-listed copyright holders nor the names
 *    of any contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 * Alternatively, this software may be distributed under the terms of the
 * GNU General Public License ("GPL") version 2 as published by the Free
 * Software Foundation.
 *
 * NO WARRANTY
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGES.
 */

#include <acpi/acpi.h>
L
Len Brown 已提交
45 46
#include "accommon.h"
#include "acnamesp.h"
47
#include <acpi/acoutput.h>
L
Linus Torvalds 已提交
48 49

#define _COMPONENT          ACPI_NAMESPACE
L
Len Brown 已提交
50
ACPI_MODULE_NAME("nsdump")
L
Linus Torvalds 已提交
51

R
Robert Moore 已提交
52 53
/* Local prototypes */
#ifdef ACPI_OBSOLETE_FUNCTIONS
L
Len Brown 已提交
54
void acpi_ns_dump_root_devices(void);
L
Linus Torvalds 已提交
55

R
Robert Moore 已提交
56
static acpi_status
L
Len Brown 已提交
57 58
acpi_ns_dump_one_device(acpi_handle obj_handle,
			u32 level, void *context, void **return_value);
R
Robert Moore 已提交
59 60 61
#endif

#if defined(ACPI_DEBUG_OUTPUT) || defined(ACPI_DEBUGGER)
62 63 64 65 66 67 68 69 70 71 72

#ifdef	ACPI_FUTURE_USAGE
static acpi_status
acpi_ns_dump_one_object_path(acpi_handle obj_handle,
			     u32 level, void *context, void **return_value);

static acpi_status
acpi_ns_get_max_depth(acpi_handle obj_handle,
		      u32 level, void *context, void **return_value);
#endif				/* ACPI_FUTURE_USAGE */

L
Linus Torvalds 已提交
73 74 75 76
/*******************************************************************************
 *
 * FUNCTION:    acpi_ns_print_pathname
 *
R
Robert Moore 已提交
77
 * PARAMETERS:  num_segments        - Number of ACPI name segments
78
 *              pathname            - The compressed (internal) path
L
Linus Torvalds 已提交
79
 *
R
Robert Moore 已提交
80 81
 * RETURN:      None
 *
L
Linus Torvalds 已提交
82 83 84 85
 * DESCRIPTION: Print an object's full namespace pathname
 *
 ******************************************************************************/

L
Len Brown 已提交
86
void acpi_ns_print_pathname(u32 num_segments, char *pathname)
L
Linus Torvalds 已提交
87
{
88
	u32 i;
89

B
Bob Moore 已提交
90
	ACPI_FUNCTION_NAME(ns_print_pathname);
91

92 93 94
	/* Check if debug output enabled */

	if (!ACPI_IS_DEBUG_ENABLED(ACPI_LV_NAMES, ACPI_NAMESPACE)) {
L
Linus Torvalds 已提交
95 96 97 98 99
		return;
	}

	/* Print the entire name */

L
Len Brown 已提交
100
	ACPI_DEBUG_PRINT((ACPI_DB_NAMES, "["));
L
Linus Torvalds 已提交
101 102

	while (num_segments) {
103
		for (i = 0; i < 4; i++) {
L
Len Brown 已提交
104 105 106
			ACPI_IS_PRINT(pathname[i]) ?
			    acpi_os_printf("%c", pathname[i]) :
			    acpi_os_printf("?");
107
		}
L
Linus Torvalds 已提交
108

109
		pathname += ACPI_NAME_SIZE;
L
Linus Torvalds 已提交
110 111
		num_segments--;
		if (num_segments) {
L
Len Brown 已提交
112
			acpi_os_printf(".");
L
Linus Torvalds 已提交
113 114 115
		}
	}

L
Len Brown 已提交
116
	acpi_os_printf("]\n");
L
Linus Torvalds 已提交
117 118 119 120 121 122
}

/*******************************************************************************
 *
 * FUNCTION:    acpi_ns_dump_pathname
 *
123 124 125 126
 * PARAMETERS:  handle              - Object
 *              msg                 - Prefix message
 *              level               - Desired debug level
 *              component           - Caller's component ID
L
Linus Torvalds 已提交
127
 *
R
Robert Moore 已提交
128 129
 * RETURN:      None
 *
L
Linus Torvalds 已提交
130 131 132 133 134 135
 * DESCRIPTION: Print an object's full namespace pathname
 *              Manages allocation/freeing of a pathname buffer
 *
 ******************************************************************************/

void
L
Len Brown 已提交
136
acpi_ns_dump_pathname(acpi_handle handle, char *msg, u32 level, u32 component)
L
Linus Torvalds 已提交
137 138
{

B
Bob Moore 已提交
139
	ACPI_FUNCTION_TRACE(ns_dump_pathname);
L
Linus Torvalds 已提交
140 141 142

	/* Do this only if the requested debug level and component are enabled */

143
	if (!ACPI_IS_DEBUG_ENABLED(level, component)) {
L
Linus Torvalds 已提交
144 145 146 147 148
		return_VOID;
	}

	/* Convert handle to a full pathname and print it (with supplied message) */

L
Len Brown 已提交
149 150
	acpi_ns_print_node_pathname(handle, msg);
	acpi_os_printf("\n");
L
Linus Torvalds 已提交
151 152 153 154 155 156 157
	return_VOID;
}

/*******************************************************************************
 *
 * FUNCTION:    acpi_ns_dump_one_object
 *
R
Robert Moore 已提交
158
 * PARAMETERS:  obj_handle          - Node to be dumped
159 160
 *              level               - Nesting level of the handle
 *              context             - Passed into walk_namespace
R
Robert Moore 已提交
161 162 163
 *              return_value        - Not used
 *
 * RETURN:      Status
L
Linus Torvalds 已提交
164 165 166 167 168 169 170
 *
 * DESCRIPTION: Dump a single Node
 *              This procedure is a user_function called by acpi_ns_walk_namespace.
 *
 ******************************************************************************/

acpi_status
L
Len Brown 已提交
171 172
acpi_ns_dump_one_object(acpi_handle obj_handle,
			u32 level, void *context, void **return_value)
L
Linus Torvalds 已提交
173
{
L
Len Brown 已提交
174 175 176 177 178 179 180 181
	struct acpi_walk_info *info = (struct acpi_walk_info *)context;
	struct acpi_namespace_node *this_node;
	union acpi_operand_object *obj_desc = NULL;
	acpi_object_type obj_type;
	acpi_object_type type;
	u32 bytes_to_dump;
	u32 dbg_level;
	u32 i;
L
Linus Torvalds 已提交
182

B
Bob Moore 已提交
183
	ACPI_FUNCTION_NAME(ns_dump_one_object);
L
Linus Torvalds 已提交
184 185 186 187 188 189 190 191

	/* Is output enabled? */

	if (!(acpi_dbg_level & info->debug_level)) {
		return (AE_OK);
	}

	if (!obj_handle) {
L
Len Brown 已提交
192
		ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Null object handle\n"));
L
Linus Torvalds 已提交
193 194 195
		return (AE_OK);
	}

196
	this_node = acpi_ns_validate_handle(obj_handle);
197 198 199 200 201 202
	if (!this_node) {
		ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Invalid object handle %p\n",
				  obj_handle));
		return (AE_OK);
	}

L
Linus Torvalds 已提交
203 204 205 206
	type = this_node->type;

	/* Check if the owner matches */

207
	if ((info->owner_id != ACPI_OWNER_ID_MAX) &&
L
Len Brown 已提交
208
	    (info->owner_id != this_node->owner_id)) {
L
Linus Torvalds 已提交
209 210 211
		return (AE_OK);
	}

212
	if (!(info->display_type & ACPI_DISPLAY_SHORT)) {
B
Bob Moore 已提交
213

214
		/* Indent the object according to the level */
L
Linus Torvalds 已提交
215

L
Len Brown 已提交
216
		acpi_os_printf("%2d%*s", (u32) level - 1, (int)level * 2, " ");
L
Linus Torvalds 已提交
217

218
		/* Check the node type and name */
L
Linus Torvalds 已提交
219

220
		if (type > ACPI_TYPE_LOCAL_MAX) {
221 222
			ACPI_WARNING((AE_INFO,
				      "Invalid ACPI Object Type 0x%08X", type));
223 224
		}

L
Len Brown 已提交
225
		acpi_os_printf("%4.4s", acpi_ut_get_node_name(this_node));
L
Linus Torvalds 已提交
226 227
	}

228 229
	/* Now we can print out the pertinent information */

B
Bob Moore 已提交
230 231 232
	acpi_os_printf(" %-12s %p %2.2X ",
		       acpi_ut_get_type_name(type), this_node,
		       this_node->owner_id);
L
Linus Torvalds 已提交
233 234 235

	dbg_level = acpi_dbg_level;
	acpi_dbg_level = 0;
L
Len Brown 已提交
236
	obj_desc = acpi_ns_get_attached_object(this_node);
L
Linus Torvalds 已提交
237 238
	acpi_dbg_level = dbg_level;

239 240 241 242 243 244
	/* Temp nodes are those nodes created by a control method */

	if (this_node->flags & ANOBJ_TEMPORARY) {
		acpi_os_printf("(T) ");
	}

245
	switch (info->display_type & ACPI_DISPLAY_MASK) {
L
Linus Torvalds 已提交
246 247 248
	case ACPI_DISPLAY_SUMMARY:

		if (!obj_desc) {
B
Bob Moore 已提交
249

250 251 252 253 254 255 256 257
			/* No attached object. Some types should always have an object */

			switch (type) {
			case ACPI_TYPE_INTEGER:
			case ACPI_TYPE_PACKAGE:
			case ACPI_TYPE_BUFFER:
			case ACPI_TYPE_STRING:
			case ACPI_TYPE_METHOD:
258

259 260 261 262
				acpi_os_printf("<No attached object>");
				break;

			default:
263

264 265
				break;
			}
L
Linus Torvalds 已提交
266

L
Len Brown 已提交
267
			acpi_os_printf("\n");
L
Linus Torvalds 已提交
268 269 270 271 272 273
			return (AE_OK);
		}

		switch (type) {
		case ACPI_TYPE_PROCESSOR:

274
			acpi_os_printf("ID %02X Len %02X Addr %8.8X%8.8X\n",
L
Len Brown 已提交
275 276
				       obj_desc->processor.proc_id,
				       obj_desc->processor.length,
277 278
				       ACPI_FORMAT_UINT64(obj_desc->processor.
							  address));
L
Linus Torvalds 已提交
279 280 281 282
			break;

		case ACPI_TYPE_DEVICE:

L
Len Brown 已提交
283
			acpi_os_printf("Notify Object: %p\n", obj_desc);
L
Linus Torvalds 已提交
284 285 286 287
			break;

		case ACPI_TYPE_METHOD:

L
Len Brown 已提交
288 289 290 291
			acpi_os_printf("Args %X Len %.4X Aml %p\n",
				       (u32) obj_desc->method.param_count,
				       obj_desc->method.aml_length,
				       obj_desc->method.aml_start);
L
Linus Torvalds 已提交
292 293 294 295
			break;

		case ACPI_TYPE_INTEGER:

L
Len Brown 已提交
296 297 298
			acpi_os_printf("= %8.8X%8.8X\n",
				       ACPI_FORMAT_UINT64(obj_desc->integer.
							  value));
L
Linus Torvalds 已提交
299 300 301 302 303
			break;

		case ACPI_TYPE_PACKAGE:

			if (obj_desc->common.flags & AOPOBJ_DATA_VALID) {
L
Len Brown 已提交
304 305 306 307
				acpi_os_printf("Elements %.2X\n",
					       obj_desc->package.count);
			} else {
				acpi_os_printf("[Length not yet evaluated]\n");
L
Linus Torvalds 已提交
308 309 310 311 312 313
			}
			break;

		case ACPI_TYPE_BUFFER:

			if (obj_desc->common.flags & AOPOBJ_DATA_VALID) {
L
Len Brown 已提交
314 315
				acpi_os_printf("Len %.2X",
					       obj_desc->buffer.length);
L
Linus Torvalds 已提交
316 317 318 319

				/* Dump some of the buffer */

				if (obj_desc->buffer.length > 0) {
L
Len Brown 已提交
320 321 322 323 324 325 326
					acpi_os_printf(" =");
					for (i = 0;
					     (i < obj_desc->buffer.length
					      && i < 12); i++) {
						acpi_os_printf(" %.2hX",
							       obj_desc->buffer.
							       pointer[i]);
L
Linus Torvalds 已提交
327 328
					}
				}
L
Len Brown 已提交
329 330 331
				acpi_os_printf("\n");
			} else {
				acpi_os_printf("[Length not yet evaluated]\n");
L
Linus Torvalds 已提交
332 333 334 335 336
			}
			break;

		case ACPI_TYPE_STRING:

L
Len Brown 已提交
337 338 339
			acpi_os_printf("Len %.2X ", obj_desc->string.length);
			acpi_ut_print_string(obj_desc->string.pointer, 32);
			acpi_os_printf("\n");
L
Linus Torvalds 已提交
340 341 342 343
			break;

		case ACPI_TYPE_REGION:

L
Len Brown 已提交
344 345 346
			acpi_os_printf("[%s]",
				       acpi_ut_get_region_name(obj_desc->region.
							       space_id));
L
Linus Torvalds 已提交
347
			if (obj_desc->region.flags & AOPOBJ_DATA_VALID) {
L
Len Brown 已提交
348
				acpi_os_printf(" Addr %8.8X%8.8X Len %.4X\n",
349 350 351
					       ACPI_FORMAT_UINT64(obj_desc->
								  region.
								  address),
L
Len Brown 已提交
352 353 354 355
					       obj_desc->region.length);
			} else {
				acpi_os_printf
				    (" [Address/Length not yet evaluated]\n");
L
Linus Torvalds 已提交
356 357 358 359 360
			}
			break;

		case ACPI_TYPE_LOCAL_REFERENCE:

L
Len Brown 已提交
361
			acpi_os_printf("[%s]\n",
362
				       acpi_ut_get_reference_name(obj_desc));
L
Linus Torvalds 已提交
363 364 365 366 367
			break;

		case ACPI_TYPE_BUFFER_FIELD:

			if (obj_desc->buffer_field.buffer_obj &&
L
Len Brown 已提交
368 369 370 371 372 373 374
			    obj_desc->buffer_field.buffer_obj->buffer.node) {
				acpi_os_printf("Buf [%4.4s]",
					       acpi_ut_get_node_name(obj_desc->
								     buffer_field.
								     buffer_obj->
								     buffer.
								     node));
L
Linus Torvalds 已提交
375 376 377 378 379
			}
			break;

		case ACPI_TYPE_LOCAL_REGION_FIELD:

L
Len Brown 已提交
380 381 382 383 384
			acpi_os_printf("Rgn [%4.4s]",
				       acpi_ut_get_node_name(obj_desc->
							     common_field.
							     region_obj->region.
							     node));
L
Linus Torvalds 已提交
385 386 387 388
			break;

		case ACPI_TYPE_LOCAL_BANK_FIELD:

L
Len Brown 已提交
389 390 391 392 393 394 395 396 397 398
			acpi_os_printf("Rgn [%4.4s] Bnk [%4.4s]",
				       acpi_ut_get_node_name(obj_desc->
							     common_field.
							     region_obj->region.
							     node),
				       acpi_ut_get_node_name(obj_desc->
							     bank_field.
							     bank_obj->
							     common_field.
							     node));
L
Linus Torvalds 已提交
399 400 401 402
			break;

		case ACPI_TYPE_LOCAL_INDEX_FIELD:

L
Len Brown 已提交
403 404 405 406 407 408 409 410 411 412
			acpi_os_printf("Idx [%4.4s] Dat [%4.4s]",
				       acpi_ut_get_node_name(obj_desc->
							     index_field.
							     index_obj->
							     common_field.node),
				       acpi_ut_get_node_name(obj_desc->
							     index_field.
							     data_obj->
							     common_field.
							     node));
L
Linus Torvalds 已提交
413 414 415 416 417
			break;

		case ACPI_TYPE_LOCAL_ALIAS:
		case ACPI_TYPE_LOCAL_METHOD_ALIAS:

L
Len Brown 已提交
418 419 420
			acpi_os_printf("Target %4.4s (%p)\n",
				       acpi_ut_get_node_name(obj_desc),
				       obj_desc);
L
Linus Torvalds 已提交
421 422 423 424
			break;

		default:

L
Len Brown 已提交
425
			acpi_os_printf("Object %p\n", obj_desc);
L
Linus Torvalds 已提交
426 427 428 429 430 431 432 433 434 435 436
			break;
		}

		/* Common field handling */

		switch (type) {
		case ACPI_TYPE_BUFFER_FIELD:
		case ACPI_TYPE_LOCAL_REGION_FIELD:
		case ACPI_TYPE_LOCAL_BANK_FIELD:
		case ACPI_TYPE_LOCAL_INDEX_FIELD:

L
Len Brown 已提交
437 438 439 440 441 442 443 444 445
			acpi_os_printf(" Off %.3X Len %.2X Acc %.2hd\n",
				       (obj_desc->common_field.
					base_byte_offset * 8)
				       +
				       obj_desc->common_field.
				       start_field_bit_offset,
				       obj_desc->common_field.bit_length,
				       obj_desc->common_field.
				       access_byte_width);
L
Linus Torvalds 已提交
446 447 448
			break;

		default:
449

L
Linus Torvalds 已提交
450 451 452 453 454 455
			break;
		}
		break;

	case ACPI_DISPLAY_OBJECTS:

L
Len Brown 已提交
456
		acpi_os_printf("O:%p", obj_desc);
L
Linus Torvalds 已提交
457
		if (!obj_desc) {
B
Bob Moore 已提交
458

L
Linus Torvalds 已提交
459 460
			/* No attached object, we are done */

L
Len Brown 已提交
461
			acpi_os_printf("\n");
L
Linus Torvalds 已提交
462 463 464
			return (AE_OK);
		}

465
		acpi_os_printf("(R%u)", obj_desc->common.reference_count);
L
Linus Torvalds 已提交
466 467 468 469 470 471

		switch (type) {
		case ACPI_TYPE_METHOD:

			/* Name is a Method and its AML offset/length are set */

L
Len Brown 已提交
472 473
			acpi_os_printf(" M:%p-%X\n", obj_desc->method.aml_start,
				       obj_desc->method.aml_length);
L
Linus Torvalds 已提交
474 475 476 477
			break;

		case ACPI_TYPE_INTEGER:

L
Len Brown 已提交
478 479 480
			acpi_os_printf(" I:%8.8X8.8%X\n",
				       ACPI_FORMAT_UINT64(obj_desc->integer.
							  value));
L
Linus Torvalds 已提交
481 482 483 484
			break;

		case ACPI_TYPE_STRING:

L
Len Brown 已提交
485 486
			acpi_os_printf(" S:%p-%X\n", obj_desc->string.pointer,
				       obj_desc->string.length);
L
Linus Torvalds 已提交
487 488 489 490
			break;

		case ACPI_TYPE_BUFFER:

L
Len Brown 已提交
491 492
			acpi_os_printf(" B:%p-%X\n", obj_desc->buffer.pointer,
				       obj_desc->buffer.length);
L
Linus Torvalds 已提交
493 494 495 496
			break;

		default:

L
Len Brown 已提交
497
			acpi_os_printf("\n");
L
Linus Torvalds 已提交
498 499 500 501 502
			break;
		}
		break;

	default:
L
Len Brown 已提交
503
		acpi_os_printf("\n");
L
Linus Torvalds 已提交
504 505 506 507 508 509 510 511 512 513 514
		break;
	}

	/* If debug turned off, done */

	if (!(acpi_dbg_level & ACPI_LV_VALUES)) {
		return (AE_OK);
	}

	/* If there is an attached object, display it */

L
Len Brown 已提交
515
	dbg_level = acpi_dbg_level;
L
Linus Torvalds 已提交
516
	acpi_dbg_level = 0;
L
Len Brown 已提交
517
	obj_desc = acpi_ns_get_attached_object(this_node);
L
Linus Torvalds 已提交
518 519 520 521 522 523
	acpi_dbg_level = dbg_level;

	/* Dump attached objects */

	while (obj_desc) {
		obj_type = ACPI_TYPE_INVALID;
L
Len Brown 已提交
524
		acpi_os_printf("Attached Object %p: ", obj_desc);
L
Linus Torvalds 已提交
525 526 527

		/* Decode the type of attached object and dump the contents */

L
Len Brown 已提交
528
		switch (ACPI_GET_DESCRIPTOR_TYPE(obj_desc)) {
L
Linus Torvalds 已提交
529 530
		case ACPI_DESC_TYPE_NAMED:

L
Len Brown 已提交
531 532 533
			acpi_os_printf("(Ptr to Node)\n");
			bytes_to_dump = sizeof(struct acpi_namespace_node);
			ACPI_DUMP_BUFFER(obj_desc, bytes_to_dump);
L
Linus Torvalds 已提交
534 535 536 537
			break;

		case ACPI_DESC_TYPE_OPERAND:

538
			obj_type = obj_desc->common.type;
L
Linus Torvalds 已提交
539 540

			if (obj_type > ACPI_TYPE_LOCAL_MAX) {
L
Len Brown 已提交
541
				acpi_os_printf
542
				    ("(Pointer to ACPI Object type %.2X [UNKNOWN])\n",
L
Len Brown 已提交
543
				     obj_type);
L
Linus Torvalds 已提交
544
				bytes_to_dump = 32;
L
Len Brown 已提交
545 546
			} else {
				acpi_os_printf
547
				    ("(Pointer to ACPI Object type %.2X [%s])\n",
L
Len Brown 已提交
548 549 550
				     obj_type, acpi_ut_get_type_name(obj_type));
				bytes_to_dump =
				    sizeof(union acpi_operand_object);
L
Linus Torvalds 已提交
551 552
			}

L
Len Brown 已提交
553
			ACPI_DUMP_BUFFER(obj_desc, bytes_to_dump);
554
			break;
L
Linus Torvalds 已提交
555 556 557 558 559 560 561 562

		default:

			break;
		}

		/* If value is NOT an internal object, we are done */

L
Len Brown 已提交
563 564
		if (ACPI_GET_DESCRIPTOR_TYPE(obj_desc) !=
		    ACPI_DESC_TYPE_OPERAND) {
L
Linus Torvalds 已提交
565 566 567
			goto cleanup;
		}

568 569
		/* Valid object, get the pointer to next level, if any */

L
Linus Torvalds 已提交
570
		switch (obj_type) {
571
		case ACPI_TYPE_BUFFER:
L
Linus Torvalds 已提交
572
		case ACPI_TYPE_STRING:
573 574 575 576
			/*
			 * NOTE: takes advantage of common fields between string/buffer
			 */
			bytes_to_dump = obj_desc->string.length;
L
Len Brown 已提交
577 578 579 580
			obj_desc = (void *)obj_desc->string.pointer;
			acpi_os_printf("(Buffer/String pointer %p length %X)\n",
				       obj_desc, bytes_to_dump);
			ACPI_DUMP_BUFFER(obj_desc, bytes_to_dump);
581
			goto cleanup;
L
Linus Torvalds 已提交
582 583

		case ACPI_TYPE_BUFFER_FIELD:
584

L
Len Brown 已提交
585 586 587
			obj_desc =
			    (union acpi_operand_object *)obj_desc->buffer_field.
			    buffer_obj;
L
Linus Torvalds 已提交
588 589 590
			break;

		case ACPI_TYPE_PACKAGE:
591

L
Len Brown 已提交
592
			obj_desc = (void *)obj_desc->package.elements;
L
Linus Torvalds 已提交
593 594 595
			break;

		case ACPI_TYPE_METHOD:
596

L
Len Brown 已提交
597
			obj_desc = (void *)obj_desc->method.aml_start;
L
Linus Torvalds 已提交
598 599 600
			break;

		case ACPI_TYPE_LOCAL_REGION_FIELD:
601

L
Len Brown 已提交
602
			obj_desc = (void *)obj_desc->field.region_obj;
L
Linus Torvalds 已提交
603 604 605
			break;

		case ACPI_TYPE_LOCAL_BANK_FIELD:
606

L
Len Brown 已提交
607
			obj_desc = (void *)obj_desc->bank_field.region_obj;
L
Linus Torvalds 已提交
608 609 610
			break;

		case ACPI_TYPE_LOCAL_INDEX_FIELD:
611

L
Len Brown 已提交
612
			obj_desc = (void *)obj_desc->index_field.index_obj;
L
Linus Torvalds 已提交
613 614 615
			break;

		default:
616

L
Linus Torvalds 已提交
617 618 619
			goto cleanup;
		}

L
Len Brown 已提交
620
		obj_type = ACPI_TYPE_INVALID;	/* Terminate loop after next pass */
L
Linus Torvalds 已提交
621 622
	}

623
cleanup:
L
Len Brown 已提交
624
	acpi_os_printf("\n");
L
Linus Torvalds 已提交
625 626 627 628 629 630 631 632
	return (AE_OK);
}

#ifdef ACPI_FUTURE_USAGE
/*******************************************************************************
 *
 * FUNCTION:    acpi_ns_dump_objects
 *
633
 * PARAMETERS:  type                - Object type to be dumped
R
Robert Moore 已提交
634
 *              display_type        - 0 or ACPI_DISPLAY_SUMMARY
L
Linus Torvalds 已提交
635 636
 *              max_depth           - Maximum depth of dump. Use ACPI_UINT32_MAX
 *                                    for an effectively unlimited depth.
637
 *              owner_id            - Dump only objects owned by this ID. Use
L
Linus Torvalds 已提交
638 639 640
 *                                    ACPI_UINT32_MAX to match all owners.
 *              start_handle        - Where in namespace to start/end search
 *
R
Robert Moore 已提交
641 642
 * RETURN:      None
 *
643 644
 * DESCRIPTION: Dump typed objects within the loaded namespace. Uses
 *              acpi_ns_walk_namespace in conjunction with acpi_ns_dump_one_object.
L
Linus Torvalds 已提交
645 646 647 648
 *
 ******************************************************************************/

void
L
Len Brown 已提交
649 650 651 652
acpi_ns_dump_objects(acpi_object_type type,
		     u8 display_type,
		     u32 max_depth,
		     acpi_owner_id owner_id, acpi_handle start_handle)
L
Linus Torvalds 已提交
653
{
L
Len Brown 已提交
654
	struct acpi_walk_info info;
655
	acpi_status status;
L
Linus Torvalds 已提交
656

L
Len Brown 已提交
657
	ACPI_FUNCTION_ENTRY();
L
Linus Torvalds 已提交
658

659 660 661 662 663 664 665 666 667 668 669 670
	/*
	 * Just lock the entire namespace for the duration of the dump.
	 * We don't want any changes to the namespace during this time,
	 * especially the temporary nodes since we are going to display
	 * them also.
	 */
	status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
	if (ACPI_FAILURE(status)) {
		acpi_os_printf("Could not acquire namespace mutex\n");
		return;
	}

L
Linus Torvalds 已提交
671 672 673 674
	info.debug_level = ACPI_LV_TABLES;
	info.owner_id = owner_id;
	info.display_type = display_type;

L
Len Brown 已提交
675
	(void)acpi_ns_walk_namespace(type, start_handle, max_depth,
676 677
				     ACPI_NS_WALK_NO_UNLOCK |
				     ACPI_NS_WALK_TEMP_NODES,
678 679
				     acpi_ns_dump_one_object, NULL,
				     (void *)&info, NULL);
680 681

	(void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
L
Linus Torvalds 已提交
682
}
L
Len Brown 已提交
683
#endif				/* ACPI_FUTURE_USAGE */
L
Linus Torvalds 已提交
684

685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717
#ifdef	ACPI_FUTURE_USAGE
/*******************************************************************************
 *
 * FUNCTION:    acpi_ns_dump_one_object_path, acpi_ns_get_max_depth
 *
 * PARAMETERS:  obj_handle          - Node to be dumped
 *              level               - Nesting level of the handle
 *              context             - Passed into walk_namespace
 *              return_value        - Not used
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Dump the full pathname to a namespace object. acp_ns_get_max_depth
 *              computes the maximum nesting depth in the namespace tree, in
 *              order to simplify formatting in acpi_ns_dump_one_object_path.
 *              These procedures are user_functions called by acpi_ns_walk_namespace.
 *
 ******************************************************************************/

static acpi_status
acpi_ns_dump_one_object_path(acpi_handle obj_handle,
			     u32 level, void *context, void **return_value)
{
	u32 max_level = *((u32 *)context);
	char *pathname;
	struct acpi_namespace_node *node;
	int path_indent;

	if (!obj_handle) {
		return (AE_OK);
	}

	node = acpi_ns_validate_handle(obj_handle);
718 719 720 721 722 723 724
	if (!node) {

		/* Ignore bad node during namespace walk */

		return (AE_OK);
	}

725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814
	pathname = acpi_ns_get_external_pathname(node);

	path_indent = 1;
	if (level <= max_level) {
		path_indent = max_level - level + 1;
	}

	acpi_os_printf("%2d%*s%-12s%*s",
		       level, level, " ", acpi_ut_get_type_name(node->type),
		       path_indent, " ");

	acpi_os_printf("%s\n", &pathname[1]);
	ACPI_FREE(pathname);
	return (AE_OK);
}

static acpi_status
acpi_ns_get_max_depth(acpi_handle obj_handle,
		      u32 level, void *context, void **return_value)
{
	u32 *max_level = (u32 *)context;

	if (level > *max_level) {
		*max_level = level;
	}
	return (AE_OK);
}

/*******************************************************************************
 *
 * FUNCTION:    acpi_ns_dump_object_paths
 *
 * PARAMETERS:  type                - Object type to be dumped
 *              display_type        - 0 or ACPI_DISPLAY_SUMMARY
 *              max_depth           - Maximum depth of dump. Use ACPI_UINT32_MAX
 *                                    for an effectively unlimited depth.
 *              owner_id            - Dump only objects owned by this ID. Use
 *                                    ACPI_UINT32_MAX to match all owners.
 *              start_handle        - Where in namespace to start/end search
 *
 * RETURN:      None
 *
 * DESCRIPTION: Dump full object pathnames within the loaded namespace. Uses
 *              acpi_ns_walk_namespace in conjunction with acpi_ns_dump_one_object_path.
 *
 ******************************************************************************/

void
acpi_ns_dump_object_paths(acpi_object_type type,
			  u8 display_type,
			  u32 max_depth,
			  acpi_owner_id owner_id, acpi_handle start_handle)
{
	acpi_status status;
	u32 max_level = 0;

	ACPI_FUNCTION_ENTRY();

	/*
	 * Just lock the entire namespace for the duration of the dump.
	 * We don't want any changes to the namespace during this time,
	 * especially the temporary nodes since we are going to display
	 * them also.
	 */
	status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
	if (ACPI_FAILURE(status)) {
		acpi_os_printf("Could not acquire namespace mutex\n");
		return;
	}

	/* Get the max depth of the namespace tree, for formatting later */

	(void)acpi_ns_walk_namespace(type, start_handle, max_depth,
				     ACPI_NS_WALK_NO_UNLOCK |
				     ACPI_NS_WALK_TEMP_NODES,
				     acpi_ns_get_max_depth, NULL,
				     (void *)&max_level, NULL);

	/* Now dump the entire namespace */

	(void)acpi_ns_walk_namespace(type, start_handle, max_depth,
				     ACPI_NS_WALK_NO_UNLOCK |
				     ACPI_NS_WALK_TEMP_NODES,
				     acpi_ns_dump_one_object_path, NULL,
				     (void *)&max_level, NULL);

	(void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
}
#endif				/* ACPI_FUTURE_USAGE */

R
Robert Moore 已提交
815 816 817 818
/*******************************************************************************
 *
 * FUNCTION:    acpi_ns_dump_entry
 *
819
 * PARAMETERS:  handle              - Node to be dumped
R
Robert Moore 已提交
820 821 822 823 824 825 826 827
 *              debug_level         - Output level
 *
 * RETURN:      None
 *
 * DESCRIPTION: Dump a single Node
 *
 ******************************************************************************/

L
Len Brown 已提交
828
void acpi_ns_dump_entry(acpi_handle handle, u32 debug_level)
R
Robert Moore 已提交
829
{
L
Len Brown 已提交
830
	struct acpi_walk_info info;
R
Robert Moore 已提交
831

L
Len Brown 已提交
832
	ACPI_FUNCTION_ENTRY();
R
Robert Moore 已提交
833 834

	info.debug_level = debug_level;
835
	info.owner_id = ACPI_OWNER_ID_MAX;
R
Robert Moore 已提交
836 837
	info.display_type = ACPI_DISPLAY_SUMMARY;

L
Len Brown 已提交
838
	(void)acpi_ns_dump_one_object(handle, 1, &info, NULL);
R
Robert Moore 已提交
839 840
}

841
#ifdef ACPI_ASL_COMPILER
L
Linus Torvalds 已提交
842 843 844 845 846 847
/*******************************************************************************
 *
 * FUNCTION:    acpi_ns_dump_tables
 *
 * PARAMETERS:  search_base         - Root of subtree to be dumped, or
 *                                    NS_ALL to dump the entire namespace
848
 *              max_depth           - Maximum depth of dump. Use INT_MAX
L
Linus Torvalds 已提交
849 850
 *                                    for an effectively unlimited depth.
 *
R
Robert Moore 已提交
851 852
 * RETURN:      None
 *
L
Linus Torvalds 已提交
853 854 855 856
 * DESCRIPTION: Dump the name space, or a portion of it.
 *
 ******************************************************************************/

L
Len Brown 已提交
857
void acpi_ns_dump_tables(acpi_handle search_base, u32 max_depth)
L
Linus Torvalds 已提交
858
{
L
Len Brown 已提交
859
	acpi_handle search_handle = search_base;
L
Linus Torvalds 已提交
860

B
Bob Moore 已提交
861
	ACPI_FUNCTION_TRACE(ns_dump_tables);
L
Linus Torvalds 已提交
862 863 864 865 866 867

	if (!acpi_gbl_root_node) {
		/*
		 * If the name space has not been initialized,
		 * there is nothing to dump.
		 */
L
Len Brown 已提交
868 869
		ACPI_DEBUG_PRINT((ACPI_DB_TABLES,
				  "namespace not initialized!\n"));
L
Linus Torvalds 已提交
870 871 872 873
		return_VOID;
	}

	if (ACPI_NS_ALL == search_base) {
B
Bob Moore 已提交
874

R
Robert Moore 已提交
875
		/* Entire namespace */
L
Linus Torvalds 已提交
876 877

		search_handle = acpi_gbl_root_node;
L
Len Brown 已提交
878
		ACPI_DEBUG_PRINT((ACPI_DB_TABLES, "\\\n"));
L
Linus Torvalds 已提交
879 880
	}

L
Len Brown 已提交
881 882
	acpi_ns_dump_objects(ACPI_TYPE_ANY, ACPI_DISPLAY_OBJECTS, max_depth,
			     ACPI_OWNER_ID_MAX, search_handle);
L
Linus Torvalds 已提交
883 884
	return_VOID;
}
L
Lv Zheng 已提交
885 886
#endif
#endif