1 /******************************************************************************
3 * Module Name: aslmapoutput - Output/emit the resource descriptor/device maps
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2015, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
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.
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.
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.
44 #include <contrib/dev/acpica/include/acpi.h>
45 #include <contrib/dev/acpica/include/accommon.h>
46 #include <contrib/dev/acpica/include/acapps.h>
47 #include <contrib/dev/acpica/compiler/aslcompiler.h>
48 #include "aslcompiler.y.h"
49 #include <contrib/dev/acpica/include/acinterp.h>
50 #include <contrib/dev/acpica/include/acparser.h>
51 #include <contrib/dev/acpica/include/acnamesp.h>
52 #include <contrib/dev/acpica/include/amlcode.h>
54 /* This module used for application-level code only */
56 #define _COMPONENT ACPI_COMPILER
57 ACPI_MODULE_NAME ("aslmapoutput")
59 /* Local prototypes */
75 ACPI_HANDLE ObjHandle,
82 ACPI_GPIO_INFO *Info);
85 MpNamespaceXrefBegin (
86 ACPI_PARSE_OBJECT *Op,
91 /* Strings used to decode flag bits */
93 const char *DirectionDecode[] =
101 const char *PolarityDecode[] =
110 /*******************************************************************************
112 * FUNCTION: MpEmitMappingInfo
118 * DESCRIPTION: External interface.
119 * Map file has already been opened. Emit all of the collected
120 * hardware mapping information. Includes: GPIO information,
121 * Serial information, and a dump of the entire ACPI device tree.
123 ******************************************************************************/
130 /* Mapfile option enabled? */
132 if (!Gbl_MapfileFlag)
139 FlPrintFile (ASL_FILE_MAP_OUTPUT,
140 "\nNo GPIO devices found\n");
145 FlPrintFile (ASL_FILE_MAP_OUTPUT,
146 "\nNo Serial devices found (I2C/SPI/UART)\n");
149 if (!Gbl_GpioList && !Gbl_SerialList)
156 FlPrintFile (ASL_FILE_MAP_OUTPUT, "\nResource Descriptor Connectivity Map\n");
157 FlPrintFile (ASL_FILE_MAP_OUTPUT, "------------------------------------\n");
159 /* Emit GPIO and Serial descriptors, then entire ACPI device tree */
165 /* Clear the lists - no need to free memory here */
167 Gbl_SerialList = NULL;
172 /*******************************************************************************
174 * FUNCTION: MpEmitGpioInfo
180 * DESCRIPTION: Emit the info about all GPIO devices found during the
181 * compile or disassembly.
183 ******************************************************************************/
189 ACPI_GPIO_INFO *Info;
191 char *PrevDeviceName = NULL;
192 const char *Direction;
193 const char *Polarity;
194 char *ParentPathname;
195 const char *Description;
197 const AH_DEVICE_ID *HidInfo;
200 /* Walk the GPIO descriptor list */
205 HidString = MpGetHidViaNamestring (Info->DeviceName);
207 /* Print header info for the controller itself */
209 if (!PrevDeviceName ||
210 ACPI_STRCMP (PrevDeviceName, Info->DeviceName))
212 FlPrintFile (ASL_FILE_MAP_OUTPUT,
213 "\n\nGPIO Controller: %-8s %-28s",
214 HidString, Info->DeviceName);
216 HidInfo = AcpiAhMatchHardwareId (HidString);
219 FlPrintFile (ASL_FILE_MAP_OUTPUT, " // %s",
220 HidInfo->Description);
223 FlPrintFile (ASL_FILE_MAP_OUTPUT,
224 "\n\nPin Type Direction Polarity"
225 " Dest _HID Destination\n");
228 PrevDeviceName = Info->DeviceName;
230 /* Setup various strings based upon the type (GpioInt or GpioIo) */
234 case AML_RESOURCE_GPIO_TYPE_INT:
237 Direction = "-Interrupt-";
238 Polarity = PolarityDecode[Info->Polarity];
241 case AML_RESOURCE_GPIO_TYPE_IO:
244 Direction = DirectionDecode[Info->Direction];
252 /* Emit the GPIO info */
254 FlPrintFile (ASL_FILE_MAP_OUTPUT, "%4.4X %s %s %s ",
255 Info->PinNumber, Type, Direction, Polarity);
257 ParentPathname = NULL;
258 HidString = MpGetConnectionInfo (Info->Op, Info->PinIndex,
259 &Info->TargetNode, &ParentPathname);
263 * This is a Connection() field
264 * Attempt to find all references to the field.
266 FlPrintFile (ASL_FILE_MAP_OUTPUT, "%8s %-28s",
267 HidString, ParentPathname);
269 MpXrefDevices (Info);
274 * For Devices, attempt to get the _HID description string.
275 * Failing that (many _HIDs are not recognized), attempt to
276 * get the _DDN description string.
278 HidString = MpGetParentDeviceHid (Info->Op, &Info->TargetNode,
281 FlPrintFile (ASL_FILE_MAP_OUTPUT, "%8s %-28s",
282 HidString, ParentPathname);
284 /* Get the _HID description or _DDN string */
286 HidInfo = AcpiAhMatchHardwareId (HidString);
289 FlPrintFile (ASL_FILE_MAP_OUTPUT, " // %s",
290 HidInfo->Description);
292 else if ((Description = MpGetDdnValue (ParentPathname)))
294 FlPrintFile (ASL_FILE_MAP_OUTPUT, " // %s (_DDN)",
299 FlPrintFile (ASL_FILE_MAP_OUTPUT, "\n");
300 ACPI_FREE (ParentPathname);
306 /*******************************************************************************
308 * FUNCTION: MpEmitSerialInfo
314 * DESCRIPTION: Emit the info about all Serial devices found during the
315 * compile or disassembly.
317 ******************************************************************************/
323 ACPI_SERIAL_INFO *Info;
325 char *ParentPathname;
326 char *PrevDeviceName = NULL;
328 const AH_DEVICE_ID *HidInfo;
329 const char *Description;
330 AML_RESOURCE *Resource;
333 /* Walk the constructed serial descriptor list */
335 Info = Gbl_SerialList;
338 Resource = Info->Resource;
339 switch (Resource->CommonSerialBus.Type)
341 case AML_RESOURCE_I2C_SERIALBUSTYPE:
345 case AML_RESOURCE_SPI_SERIALBUSTYPE:
349 case AML_RESOURCE_UART_SERIALBUSTYPE:
358 HidString = MpGetHidViaNamestring (Info->DeviceName);
360 /* Print header info for the controller itself */
362 if (!PrevDeviceName ||
363 ACPI_STRCMP (PrevDeviceName, Info->DeviceName))
365 FlPrintFile (ASL_FILE_MAP_OUTPUT, "\n\n%s Controller: ",
367 FlPrintFile (ASL_FILE_MAP_OUTPUT, "%-8s %-28s",
368 HidString, Info->DeviceName);
370 HidInfo = AcpiAhMatchHardwareId (HidString);
373 FlPrintFile (ASL_FILE_MAP_OUTPUT, " // %s",
374 HidInfo->Description);
377 FlPrintFile (ASL_FILE_MAP_OUTPUT, "\n\n");
378 FlPrintFile (ASL_FILE_MAP_OUTPUT,
379 "Type Address Speed Dest _HID Destination\n");
382 PrevDeviceName = Info->DeviceName;
384 FlPrintFile (ASL_FILE_MAP_OUTPUT, "%s %4.4X %8.8X ",
385 Type, Info->Address, Info->Speed);
387 ParentPathname = NULL;
388 HidString = MpGetConnectionInfo (Info->Op, 0, &Info->TargetNode,
393 * This is a Connection() field
394 * Attempt to find all references to the field.
396 FlPrintFile (ASL_FILE_MAP_OUTPUT, "%8s %-28s",
397 HidString, ParentPathname);
401 /* Normal resource template */
403 HidString = MpGetParentDeviceHid (Info->Op, &Info->TargetNode,
405 FlPrintFile (ASL_FILE_MAP_OUTPUT, "%8s %-28s",
406 HidString, ParentPathname);
408 /* Get the _HID description or _DDN string */
410 HidInfo = AcpiAhMatchHardwareId (HidString);
413 FlPrintFile (ASL_FILE_MAP_OUTPUT, " // %s",
414 HidInfo->Description);
416 else if ((Description = MpGetDdnValue (ParentPathname)))
418 FlPrintFile (ASL_FILE_MAP_OUTPUT, " // %s (_DDN)",
423 FlPrintFile (ASL_FILE_MAP_OUTPUT, "\n");
424 ACPI_FREE (ParentPathname);
430 /*******************************************************************************
432 * FUNCTION: MpEmitDeviceTree
438 * DESCRIPTION: Emit information about all devices within the ACPI namespace.
440 ******************************************************************************/
447 FlPrintFile (ASL_FILE_MAP_OUTPUT, "\n\nACPI Device Tree\n");
448 FlPrintFile (ASL_FILE_MAP_OUTPUT, "----------------\n\n");
450 FlPrintFile (ASL_FILE_MAP_OUTPUT, "Device Pathname "
451 "_HID Description\n\n");
453 /* Walk the namespace from the root */
455 (void) AcpiNsWalkNamespace (ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
456 ACPI_UINT32_MAX, FALSE, MpEmitOneDevice, NULL, NULL, NULL);
460 /*******************************************************************************
462 * FUNCTION: MpEmitOneDevice
464 * PARAMETERS: ACPI_NAMESPACE_WALK callback
468 * DESCRIPTION: Emit information about one ACPI device in the namespace. Used
469 * during dump of all device objects within the namespace.
471 ******************************************************************************/
475 ACPI_HANDLE ObjHandle,
480 char *DevicePathname;
483 const AH_DEVICE_ID *HidInfo;
486 /* Device pathname */
488 DevicePathname = AcpiNsGetExternalPathname (
489 ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, ObjHandle));
491 FlPrintFile (ASL_FILE_MAP_OUTPUT, "%-32s", DevicePathname);
495 HidString = MpGetHidValue (
496 ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, ObjHandle));
497 FlPrintFile (ASL_FILE_MAP_OUTPUT, "%8s", HidString);
499 HidInfo = AcpiAhMatchHardwareId (HidString);
502 FlPrintFile (ASL_FILE_MAP_OUTPUT, " // %s",
503 HidInfo->Description);
505 else if ((DdnString = MpGetDdnValue (DevicePathname)))
507 FlPrintFile (ASL_FILE_MAP_OUTPUT, " // %s (_DDN)", DdnString);
510 FlPrintFile (ASL_FILE_MAP_OUTPUT, "\n");
511 ACPI_FREE (DevicePathname);
516 /*******************************************************************************
518 * FUNCTION: MpXrefDevices
520 * PARAMETERS: Info - A GPIO Info block
524 * DESCRIPTION: Cross-reference the parse tree and find all references to the
525 * specified GPIO device.
527 ******************************************************************************/
531 ACPI_GPIO_INFO *Info)
534 /* Walk the entire parse tree */
536 TrWalkParseTree (RootNode, ASL_WALK_VISIT_DOWNWARD,
537 MpNamespaceXrefBegin, NULL, Info);
539 if (!Info->References)
541 FlPrintFile (ASL_FILE_MAP_OUTPUT, " // **** No references in table");
546 /*******************************************************************************
548 * FUNCTION: MpNamespaceXrefBegin
550 * PARAMETERS: WALK_PARSE_TREE callback
554 * DESCRIPTION: Walk parse tree callback used to cross-reference GPIO pins.
556 ******************************************************************************/
559 MpNamespaceXrefBegin (
560 ACPI_PARSE_OBJECT *Op,
564 ACPI_GPIO_INFO *Info = ACPI_CAST_PTR (ACPI_GPIO_INFO, Context);
565 const ACPI_OPCODE_INFO *OpInfo;
566 char *DevicePathname;
567 ACPI_PARSE_OBJECT *ParentOp;
571 ACPI_FUNCTION_TRACE_PTR (MpNamespaceXrefBegin, Op);
574 * If this node is the actual declaration of a name
575 * [such as the XXXX name in "Method (XXXX)"],
576 * we are not interested in it here. We only care about names that
577 * are references to other objects within the namespace and the
578 * parent objects of name declarations
580 if (Op->Asl.CompileFlags & NODE_IS_NAME_DECLARATION)
585 /* We are only interested in opcodes that have an associated name */
587 OpInfo = AcpiPsGetOpcodeInfo (Op->Asl.AmlOpcode);
589 if ((OpInfo->Flags & AML_NAMED) ||
590 (OpInfo->Flags & AML_CREATE))
595 if ((Op->Asl.ParseOpcode != PARSEOP_NAMESTRING) &&
596 (Op->Asl.ParseOpcode != PARSEOP_NAMESEG) &&
597 (Op->Asl.ParseOpcode != PARSEOP_METHODCALL))
607 ParentOp = Op->Asl.Parent;
608 if (ParentOp->Asl.ParseOpcode == PARSEOP_FIELD)
613 if (Op->Asl.Node == Info->TargetNode)
615 while (ParentOp && (!ParentOp->Asl.Node))
617 ParentOp = ParentOp->Asl.Parent;
622 DevicePathname = AcpiNsGetExternalPathname (
625 if (!Info->References)
627 FlPrintFile (ASL_FILE_MAP_OUTPUT, " // References:");
630 HidString = MpGetHidViaNamestring (DevicePathname);
632 FlPrintFile (ASL_FILE_MAP_OUTPUT, " %s [%s]",
633 DevicePathname, HidString);
637 ACPI_FREE (DevicePathname);