aslnamesp.c revision 245582
10Sduke/****************************************************************************** 21410Sihse * 30Sduke * Module Name: aslnamesp - Namespace output file generation 40Sduke * 50Sduke *****************************************************************************/ 60Sduke 7180Sohair/* 80Sduke * Copyright (C) 2000 - 2013, Intel Corp. 9180Sohair * All rights reserved. 100Sduke * 110Sduke * Redistribution and use in source and binary forms, with or without 120Sduke * modification, are permitted provided that the following conditions 130Sduke * are met: 140Sduke * 1. Redistributions of source code must retain the above copyright 150Sduke * notice, this list of conditions, and the following disclaimer, 160Sduke * without modification. 170Sduke * 2. Redistributions in binary form must reproduce at minimum a disclaimer 180Sduke * substantially similar to the "NO WARRANTY" disclaimer below 190Sduke * ("Disclaimer") and any redistribution must be conditioned upon 200Sduke * including a substantially similar Disclaimer requirement for further 21180Sohair * binary redistribution. 22180Sohair * 3. Neither the names of the above-listed copyright holders nor the names 23180Sohair * of any contributors may be used to endorse or promote products derived 240Sduke * from this software without specific prior written permission. 250Sduke * 261410Sihse * Alternatively, this software may be distributed under the terms of the 271410Sihse * GNU General Public License ("GPL") version 2 as published by the Free 281410Sihse * Software Foundation. 291410Sihse * 305Sohair * NO WARRANTY 312251Salanbur * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 322251Salanbur * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 331410Sihse * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 34338Sohair * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 351410Sihse * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 361410Sihse * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 371410Sihse * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 381410Sihse * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 391410Sihse * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 401410Sihse * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 410Sduke * POSSIBILITY OF SUCH DAMAGES. 421410Sihse */ 43910Sihse 441410Sihse 451410Sihse#include <contrib/dev/acpica/compiler/aslcompiler.h> 461410Sihse#include "aslcompiler.y.h" 471410Sihse#include <contrib/dev/acpica/include/acnamesp.h> 481410Sihse 491410Sihse 501410Sihse#define _COMPONENT ACPI_COMPILER 511410Sihse ACPI_MODULE_NAME ("aslnamesp") 521410Sihse 5327Sohair/* Local prototypes */ 5427Sohair 55910Sihsestatic ACPI_STATUS 561410SihseNsDoOneNamespaceObject ( 571410Sihse ACPI_HANDLE ObjHandle, 58910Sihse UINT32 Level, 591410Sihse void *Context, 601236Sihse void **ReturnValue); 611410Sihse 6227Sohairstatic ACPI_STATUS 631410SihseNsDoOnePathname ( 641410Sihse ACPI_HANDLE ObjHandle, 65 UINT32 Level, 66 void *Context, 67 void **ReturnValue); 68 69 70/******************************************************************************* 71 * 72 * FUNCTION: NsSetupNamespaceListing 73 * 74 * PARAMETERS: Handle - local file handle 75 * 76 * RETURN: None 77 * 78 * DESCRIPTION: Set the namespace output file to the input handle 79 * 80 ******************************************************************************/ 81 82void 83NsSetupNamespaceListing ( 84 void *Handle) 85{ 86 87 Gbl_NsOutputFlag = TRUE; 88 Gbl_Files[ASL_FILE_NAMESPACE_OUTPUT].Handle = Handle; 89} 90 91 92/******************************************************************************* 93 * 94 * FUNCTION: NsDisplayNamespace 95 * 96 * PARAMETERS: None 97 * 98 * RETURN: Status 99 * 100 * DESCRIPTION: Walk the namespace an display information about each node 101 * in the tree. Information is written to the optional 102 * namespace output file. 103 * 104 ******************************************************************************/ 105 106ACPI_STATUS 107NsDisplayNamespace ( 108 void) 109{ 110 ACPI_STATUS Status; 111 112 113 if (!Gbl_NsOutputFlag) 114 { 115 return (AE_OK); 116 } 117 118 Gbl_NumNamespaceObjects = 0; 119 120 /* File header */ 121 122 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "Contents of ACPI Namespace\n\n"); 123 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "Count Depth Name - Type\n\n"); 124 125 /* Walk entire namespace from the root */ 126 127 Status = AcpiNsWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT, 128 ACPI_UINT32_MAX, FALSE, NsDoOneNamespaceObject, NULL, 129 NULL, NULL); 130 131 /* Print the full pathname for each namespace node */ 132 133 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "\nNamespace pathnames\n\n"); 134 135 Status = AcpiNsWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT, 136 ACPI_UINT32_MAX, FALSE, NsDoOnePathname, NULL, 137 NULL, NULL); 138 139 return (Status); 140} 141 142 143/******************************************************************************* 144 * 145 * FUNCTION: NsDoOneNamespaceObject 146 * 147 * PARAMETERS: ACPI_WALK_CALLBACK 148 * 149 * RETURN: Status 150 * 151 * DESCRIPTION: Dump a namespace object to the namespace output file. 152 * Called during the walk of the namespace to dump all objects. 153 * 154 ******************************************************************************/ 155 156static ACPI_STATUS 157NsDoOneNamespaceObject ( 158 ACPI_HANDLE ObjHandle, 159 UINT32 Level, 160 void *Context, 161 void **ReturnValue) 162{ 163 ACPI_NAMESPACE_NODE *Node = (ACPI_NAMESPACE_NODE *) ObjHandle; 164 ACPI_OPERAND_OBJECT *ObjDesc; 165 ACPI_PARSE_OBJECT *Op; 166 167 168 Gbl_NumNamespaceObjects++; 169 170 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "%5u [%u] %*s %4.4s - %s", 171 Gbl_NumNamespaceObjects, Level, (Level * 3), " ", 172 &Node->Name, 173 AcpiUtGetTypeName (Node->Type)); 174 175 Op = Node->Op; 176 ObjDesc = ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, Node->Object); 177 178 if (!Op) 179 { 180 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "\n"); 181 return (AE_OK); 182 } 183 184 185 if ((ObjDesc) && 186 (ACPI_GET_DESCRIPTOR_TYPE (ObjDesc) == ACPI_DESC_TYPE_OPERAND)) 187 { 188 switch (Node->Type) 189 { 190 case ACPI_TYPE_INTEGER: 191 192 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, 193 " [Initial Value 0x%8.8X%8.8X]", 194 ACPI_FORMAT_UINT64 (ObjDesc->Integer.Value)); 195 break; 196 197 198 case ACPI_TYPE_STRING: 199 200 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, 201 " [Initial Value \"%s\"]", 202 ObjDesc->String.Pointer); 203 break; 204 205 default: 206 /* Nothing to do for other types */ 207 break; 208 } 209 210 } 211 else 212 { 213 switch (Node->Type) 214 { 215 case ACPI_TYPE_INTEGER: 216 217 if (Op->Asl.ParseOpcode == PARSEOP_NAME) 218 { 219 Op = Op->Asl.Child; 220 } 221 if ((Op->Asl.ParseOpcode == PARSEOP_NAMESEG) || 222 (Op->Asl.ParseOpcode == PARSEOP_NAMESTRING)) 223 { 224 Op = Op->Asl.Next; 225 } 226 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, 227 " [Initial Value 0x%8.8X%8.8X]", 228 ACPI_FORMAT_UINT64 (Op->Asl.Value.Integer)); 229 break; 230 231 232 case ACPI_TYPE_STRING: 233 234 if (Op->Asl.ParseOpcode == PARSEOP_NAME) 235 { 236 Op = Op->Asl.Child; 237 } 238 if ((Op->Asl.ParseOpcode == PARSEOP_NAMESEG) || 239 (Op->Asl.ParseOpcode == PARSEOP_NAMESTRING)) 240 { 241 Op = Op->Asl.Next; 242 } 243 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, 244 " [Initial Value \"%s\"]", 245 Op->Asl.Value.String); 246 break; 247 248 249 case ACPI_TYPE_LOCAL_REGION_FIELD: 250 251 if ((Op->Asl.ParseOpcode == PARSEOP_NAMESEG) || 252 (Op->Asl.ParseOpcode == PARSEOP_NAMESTRING)) 253 { 254 Op = Op->Asl.Child; 255 } 256 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, 257 " [Offset 0x%04X Length 0x%04X bits]", 258 Op->Asl.Parent->Asl.ExtraValue, (UINT32) Op->Asl.Value.Integer); 259 break; 260 261 262 case ACPI_TYPE_BUFFER_FIELD: 263 264 switch (Op->Asl.ParseOpcode) 265 { 266 case PARSEOP_CREATEBYTEFIELD: 267 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, " [BYTE ( 8 bit)]"); 268 break; 269 270 case PARSEOP_CREATEDWORDFIELD: 271 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, " [DWORD (32 bit)]"); 272 break; 273 274 case PARSEOP_CREATEQWORDFIELD: 275 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, " [QWORD (64 bit)]"); 276 break; 277 278 case PARSEOP_CREATEWORDFIELD: 279 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, " [WORD (16 bit)]"); 280 break; 281 282 case PARSEOP_CREATEBITFIELD: 283 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, " [BIT ( 1 bit)]"); 284 break; 285 286 case PARSEOP_CREATEFIELD: 287 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, " [Arbitrary Bit Field]"); 288 break; 289 290 default: 291 break; 292 293 } 294 break; 295 296 297 case ACPI_TYPE_PACKAGE: 298 299 if (Op->Asl.ParseOpcode == PARSEOP_NAME) 300 { 301 Op = Op->Asl.Child; 302 } 303 if ((Op->Asl.ParseOpcode == PARSEOP_NAMESEG) || 304 (Op->Asl.ParseOpcode == PARSEOP_NAMESTRING)) 305 { 306 Op = Op->Asl.Next; 307 } 308 Op = Op->Asl.Child; 309 310 if ((Op->Asl.ParseOpcode == PARSEOP_BYTECONST) || 311 (Op->Asl.ParseOpcode == PARSEOP_RAW_DATA)) 312 { 313 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, 314 " [Initial Length 0x%.2X elements]", 315 Op->Asl.Value.Integer); 316 } 317 break; 318 319 320 case ACPI_TYPE_BUFFER: 321 322 if (Op->Asl.ParseOpcode == PARSEOP_NAME) 323 { 324 Op = Op->Asl.Child; 325 } 326 if ((Op->Asl.ParseOpcode == PARSEOP_NAMESEG) || 327 (Op->Asl.ParseOpcode == PARSEOP_NAMESTRING)) 328 { 329 Op = Op->Asl.Next; 330 } 331 Op = Op->Asl.Child; 332 333 if (Op && (Op->Asl.ParseOpcode == PARSEOP_INTEGER)) 334 { 335 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, 336 " [Initial Length 0x%.2X bytes]", 337 Op->Asl.Value.Integer); 338 } 339 break; 340 341 342 case ACPI_TYPE_METHOD: 343 344 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, 345 " [Code Length 0x%.4X bytes]", 346 Op->Asl.AmlSubtreeLength); 347 break; 348 349 350 case ACPI_TYPE_LOCAL_RESOURCE: 351 352 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, 353 " [Desc Offset 0x%.4X Bytes]", Node->Value); 354 break; 355 356 357 case ACPI_TYPE_LOCAL_RESOURCE_FIELD: 358 359 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, 360 " [Field Offset 0x%.4X Bits 0x%.4X Bytes] ", 361 Node->Value, Node->Value / 8); 362 363 if (Node->Flags & ANOBJ_IS_REFERENCED) 364 { 365 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, 366 "Referenced"); 367 } 368 else 369 { 370 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, 371 "Name not referenced"); 372 } 373 break; 374 375 376 default: 377 /* Nothing to do for other types */ 378 break; 379 } 380 } 381 382 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "\n"); 383 return (AE_OK); 384} 385 386 387/******************************************************************************* 388 * 389 * FUNCTION: NsDoOnePathname 390 * 391 * PARAMETERS: ACPI_WALK_CALLBACK 392 * 393 * RETURN: Status 394 * 395 * DESCRIPTION: Print the full pathname for a namespace node. 396 * 397 ******************************************************************************/ 398 399static ACPI_STATUS 400NsDoOnePathname ( 401 ACPI_HANDLE ObjHandle, 402 UINT32 Level, 403 void *Context, 404 void **ReturnValue) 405{ 406 ACPI_NAMESPACE_NODE *Node = (ACPI_NAMESPACE_NODE *) ObjHandle; 407 ACPI_STATUS Status; 408 ACPI_BUFFER TargetPath; 409 410 411 TargetPath.Length = ACPI_ALLOCATE_LOCAL_BUFFER; 412 Status = AcpiNsHandleToPathname (Node, &TargetPath); 413 if (ACPI_FAILURE (Status)) 414 { 415 return (Status); 416 } 417 418 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "%s\n", TargetPath.Pointer); 419 ACPI_FREE (TargetPath.Pointer); 420 421 return (AE_OK); 422} 423