1 /******************************************************************************
3 * Module Name: aslmaputils - Utilities for 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/acnamesp.h>
51 #include <contrib/dev/acpica/include/amlcode.h>
53 /* This module used for application-level code only */
55 #define _COMPONENT ACPI_COMPILER
56 ACPI_MODULE_NAME ("aslmaputils")
59 /*******************************************************************************
61 * FUNCTION: MpGetHidFromParseTree
63 * PARAMETERS: HidNode - Node for a _HID object
65 * RETURN: An _HID string value. Automatically converts _HID integers
66 * to strings. Never NULL.
68 * DESCRIPTION: Extract a _HID value from the parse tree, not the namespace.
69 * Used when a fully initialized namespace is not available.
71 ******************************************************************************/
74 MpGetHidFromParseTree (
75 ACPI_NAMESPACE_NODE *HidNode)
77 ACPI_PARSE_OBJECT *Op;
78 ACPI_PARSE_OBJECT *Arg;
84 switch (Op->Asl.ParseOpcode)
88 Arg = Op->Asl.Child; /* Get the NameSeg/NameString node */
89 Arg = Arg->Asl.Next; /* First peer is the object to be associated with the name */
91 switch (Arg->Asl.ParseOpcode)
93 case PARSEOP_STRING_LITERAL:
95 return (Arg->Asl.Value.String);
99 /* Convert EISAID to a string */
101 HidString = UtStringCacheCalloc (ACPI_EISAID_STRING_SIZE);
102 AcpiExEisaIdToString (HidString, Arg->Asl.Value.Integer);
116 /*******************************************************************************
118 * FUNCTION: MpGetHidValue
120 * PARAMETERS: DeviceNode - Node for parent device
122 * RETURN: An _HID string value. Automatically converts _HID integers
123 * to strings. Never NULL.
125 * DESCRIPTION: Extract _HID value from within a device scope. Does not
126 * actually execute a method, just gets the string or integer
127 * value for the _HID.
129 ******************************************************************************/
133 ACPI_NAMESPACE_NODE *DeviceNode)
135 ACPI_NAMESPACE_NODE *HidNode;
140 Status = AcpiNsGetNode (DeviceNode, METHOD_NAME__HID,
141 ACPI_NS_NO_UPSEARCH, &HidNode);
142 if (ACPI_FAILURE (Status))
147 /* If only partial namespace, get the _HID from the parse tree */
149 if (!HidNode->Object)
151 return (MpGetHidFromParseTree (HidNode));
154 /* Handle the different _HID flavors */
156 switch (HidNode->Type)
158 case ACPI_TYPE_STRING:
160 return (HidNode->Object->String.Pointer);
162 case ACPI_TYPE_INTEGER:
164 /* Convert EISAID to a string */
166 HidString = UtStringCacheCalloc (ACPI_EISAID_STRING_SIZE);
167 AcpiExEisaIdToString (HidString, HidNode->Object->Integer.Value);
170 case ACPI_TYPE_METHOD:
176 FlPrintFile (ASL_FILE_MAP_OUTPUT, "BAD HID TYPE: %u", HidNode->Type);
186 /*******************************************************************************
188 * FUNCTION: MpGetHidViaNamestring
190 * PARAMETERS: DeviceName - Namepath for parent device
192 * RETURN: _HID string. Never NULL.
194 * DESCRIPTION: Get a _HID value via a device pathname (instead of just simply
197 ******************************************************************************/
200 MpGetHidViaNamestring (
203 ACPI_NAMESPACE_NODE *DeviceNode;
207 Status = AcpiNsGetNode (NULL, DeviceName, ACPI_NS_NO_UPSEARCH,
209 if (ACPI_FAILURE (Status))
214 return (MpGetHidValue (DeviceNode));
222 /*******************************************************************************
224 * FUNCTION: MpGetParentDeviceHid
226 * PARAMETERS: Op - Parse Op to be examined
227 * TargetNode - Where the field node is returned
228 * ParentDeviceName - Where the node path is returned
230 * RETURN: _HID string. Never NULL.
232 * DESCRIPTION: Find the parent Device or Scope Op, get the full pathname to
233 * the parent, and get the _HID associated with the parent.
235 ******************************************************************************/
238 MpGetParentDeviceHid (
239 ACPI_PARSE_OBJECT *Op,
240 ACPI_NAMESPACE_NODE **TargetNode,
241 char **ParentDeviceName)
243 ACPI_NAMESPACE_NODE *DeviceNode;
246 /* Find parent Device() or Scope() Op */
249 (Op->Asl.AmlOpcode != AML_DEVICE_OP) &&
250 (Op->Asl.AmlOpcode != AML_SCOPE_OP))
257 FlPrintFile (ASL_FILE_MAP_OUTPUT, " No_Parent_Device ");
261 /* Get the full pathname to the device and the _HID */
263 DeviceNode = Op->Asl.Node;
266 FlPrintFile (ASL_FILE_MAP_OUTPUT, " No_Device_Node ");
270 *ParentDeviceName = AcpiNsGetExternalPathname (DeviceNode);
271 return (MpGetHidValue (DeviceNode));
279 /*******************************************************************************
281 * FUNCTION: MpGetDdnValue
283 * PARAMETERS: DeviceName - Namepath for parent device
285 * RETURN: _DDN description string. NULL on failure.
287 * DESCRIPTION: Execute the _DDN method for the device.
289 ******************************************************************************/
295 ACPI_NAMESPACE_NODE *DeviceNode;
296 ACPI_NAMESPACE_NODE *DdnNode;
300 Status = AcpiNsGetNode (NULL, DeviceName, ACPI_NS_NO_UPSEARCH,
302 if (ACPI_FAILURE (Status))
307 Status = AcpiNsGetNode (DeviceNode, METHOD_NAME__DDN, ACPI_NS_NO_UPSEARCH,
309 if (ACPI_FAILURE (Status))
314 if ((DdnNode->Type != ACPI_TYPE_STRING) ||
320 return (DdnNode->Object->String.Pointer);
328 /*******************************************************************************
330 * FUNCTION: MpGetConnectionInfo
332 * PARAMETERS: Op - Parse Op to be examined
333 * PinIndex - Index into GPIO PinList
334 * TargetNode - Where the field node is returned
335 * TargetName - Where the node path is returned
337 * RETURN: A substitute _HID string, indicating that the name is actually
338 * a field. NULL if the Op does not refer to a Connection.
340 * DESCRIPTION: Get the Field Unit that corresponds to the PinIndex after
341 * a Connection() invocation.
343 ******************************************************************************/
346 MpGetConnectionInfo (
347 ACPI_PARSE_OBJECT *Op,
349 ACPI_NAMESPACE_NODE **TargetNode,
352 ACPI_PARSE_OBJECT *NextOp;
357 * Handle Connection() here. Find the next named FieldUnit.
358 * Note: we look at the ParseOpcode for the compiler, look
359 * at the AmlOpcode for the disassembler.
361 if ((Op->Asl.AmlOpcode == AML_INT_CONNECTION_OP) ||
362 (Op->Asl.ParseOpcode == PARSEOP_CONNECTION))
364 /* Find the correct field unit definition */
367 for (i = 0; i <= PinIndex;)
369 NextOp = NextOp->Asl.Next;
371 (NextOp->Asl.ParseOpcode != PARSEOP_NAMESEG) &&
372 (NextOp->Asl.AmlOpcode != AML_INT_NAMEDFIELD_OP))
374 NextOp = NextOp->Asl.Next;
382 /* Add length of this field to the current pin index */
384 if (NextOp->Asl.ParseOpcode == PARSEOP_NAMESEG)
386 i += (UINT32) NextOp->Asl.Child->Asl.Value.Integer;
388 else /* AML_INT_NAMEDFIELD_OP */
390 i += (UINT32) NextOp->Asl.Value.Integer;
394 /* Return the node and pathname for the field unit */
396 *TargetNode = NextOp->Asl.Node;
397 *TargetName = AcpiNsGetExternalPathname (*TargetNode);