1 /******************************************************************************
3 * Module Name: aslmaputils - Utilities for the resource descriptor/device maps
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2016, 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.
47 #include "aslcompiler.h"
48 #include "aslcompiler.y.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
;
85 /* Object is not resolved, probably an External */
87 return ("Unresolved Symbol - referenced but not defined in this table");
90 switch (Op
->Asl
.ParseOpcode
)
94 Arg
= Op
->Asl
.Child
; /* Get the NameSeg/NameString node */
95 Arg
= Arg
->Asl
.Next
; /* First peer is the object to be associated with the name */
97 switch (Arg
->Asl
.ParseOpcode
)
99 case PARSEOP_STRING_LITERAL
:
101 return (Arg
->Asl
.Value
.String
);
103 case PARSEOP_INTEGER
:
105 /* Convert EISAID to a string */
107 HidString
= UtStringCacheCalloc (ACPI_EISAID_STRING_SIZE
);
108 AcpiExEisaIdToString (HidString
, Arg
->Asl
.Value
.Integer
);
122 /*******************************************************************************
124 * FUNCTION: MpGetHidValue
126 * PARAMETERS: DeviceNode - Node for parent device
128 * RETURN: An _HID string value. Automatically converts _HID integers
129 * to strings. Never NULL.
131 * DESCRIPTION: Extract _HID value from within a device scope. Does not
132 * actually execute a method, just gets the string or integer
133 * value for the _HID.
135 ******************************************************************************/
139 ACPI_NAMESPACE_NODE
*DeviceNode
)
141 ACPI_NAMESPACE_NODE
*HidNode
;
146 Status
= AcpiNsGetNode (DeviceNode
, METHOD_NAME__HID
,
147 ACPI_NS_NO_UPSEARCH
, &HidNode
);
148 if (ACPI_FAILURE (Status
))
153 /* If only partial namespace, get the _HID from the parse tree */
155 if (!HidNode
->Object
)
157 return (MpGetHidFromParseTree (HidNode
));
160 /* Handle the different _HID flavors */
162 switch (HidNode
->Type
)
164 case ACPI_TYPE_STRING
:
166 return (HidNode
->Object
->String
.Pointer
);
168 case ACPI_TYPE_INTEGER
:
170 /* Convert EISAID to a string */
172 HidString
= UtStringCacheCalloc (ACPI_EISAID_STRING_SIZE
);
173 AcpiExEisaIdToString (HidString
, HidNode
->Object
->Integer
.Value
);
176 case ACPI_TYPE_METHOD
:
182 FlPrintFile (ASL_FILE_MAP_OUTPUT
, "BAD HID TYPE: %u", HidNode
->Type
);
192 /*******************************************************************************
194 * FUNCTION: MpGetHidViaNamestring
196 * PARAMETERS: DeviceName - Namepath for parent device
198 * RETURN: _HID string. Never NULL.
200 * DESCRIPTION: Get a _HID value via a device pathname (instead of just simply
203 ******************************************************************************/
206 MpGetHidViaNamestring (
209 ACPI_NAMESPACE_NODE
*DeviceNode
;
213 Status
= AcpiNsGetNode (NULL
, DeviceName
, ACPI_NS_NO_UPSEARCH
,
215 if (ACPI_FAILURE (Status
))
220 return (MpGetHidValue (DeviceNode
));
228 /*******************************************************************************
230 * FUNCTION: MpGetParentDeviceHid
232 * PARAMETERS: Op - Parse Op to be examined
233 * TargetNode - Where the field node is returned
234 * ParentDeviceName - Where the node path is returned
236 * RETURN: _HID string. Never NULL.
238 * DESCRIPTION: Find the parent Device or Scope Op, get the full pathname to
239 * the parent, and get the _HID associated with the parent.
241 ******************************************************************************/
244 MpGetParentDeviceHid (
245 ACPI_PARSE_OBJECT
*Op
,
246 ACPI_NAMESPACE_NODE
**TargetNode
,
247 char **ParentDeviceName
)
249 ACPI_NAMESPACE_NODE
*DeviceNode
;
252 /* Find parent Device() or Scope() Op */
255 (Op
->Asl
.AmlOpcode
!= AML_DEVICE_OP
) &&
256 (Op
->Asl
.AmlOpcode
!= AML_SCOPE_OP
))
263 FlPrintFile (ASL_FILE_MAP_OUTPUT
, " No_Parent_Device ");
267 /* Get the full pathname to the device and the _HID */
269 DeviceNode
= Op
->Asl
.Node
;
272 FlPrintFile (ASL_FILE_MAP_OUTPUT
, " No_Device_Node ");
276 *ParentDeviceName
= AcpiNsGetExternalPathname (DeviceNode
);
277 return (MpGetHidValue (DeviceNode
));
285 /*******************************************************************************
287 * FUNCTION: MpGetDdnValue
289 * PARAMETERS: DeviceName - Namepath for parent device
291 * RETURN: _DDN description string. NULL on failure.
293 * DESCRIPTION: Execute the _DDN method for the device.
295 ******************************************************************************/
301 ACPI_NAMESPACE_NODE
*DeviceNode
;
302 ACPI_NAMESPACE_NODE
*DdnNode
;
306 Status
= AcpiNsGetNode (NULL
, DeviceName
, ACPI_NS_NO_UPSEARCH
,
308 if (ACPI_FAILURE (Status
))
313 Status
= AcpiNsGetNode (DeviceNode
, METHOD_NAME__DDN
, ACPI_NS_NO_UPSEARCH
,
315 if (ACPI_FAILURE (Status
))
320 if ((DdnNode
->Type
!= ACPI_TYPE_STRING
) ||
326 return (DdnNode
->Object
->String
.Pointer
);
334 /*******************************************************************************
336 * FUNCTION: MpGetConnectionInfo
338 * PARAMETERS: Op - Parse Op to be examined
339 * PinIndex - Index into GPIO PinList
340 * TargetNode - Where the field node is returned
341 * TargetName - Where the node path is returned
343 * RETURN: A substitute _HID string, indicating that the name is actually
344 * a field. NULL if the Op does not refer to a Connection.
346 * DESCRIPTION: Get the Field Unit that corresponds to the PinIndex after
347 * a Connection() invocation.
349 ******************************************************************************/
352 MpGetConnectionInfo (
353 ACPI_PARSE_OBJECT
*Op
,
355 ACPI_NAMESPACE_NODE
**TargetNode
,
358 ACPI_PARSE_OBJECT
*NextOp
;
363 * Handle Connection() here. Find the next named FieldUnit.
364 * Note: we look at the ParseOpcode for the compiler, look
365 * at the AmlOpcode for the disassembler.
367 if ((Op
->Asl
.AmlOpcode
== AML_INT_CONNECTION_OP
) ||
368 (Op
->Asl
.ParseOpcode
== PARSEOP_CONNECTION
))
370 /* Find the correct field unit definition */
373 for (i
= 0; i
<= PinIndex
;)
375 NextOp
= NextOp
->Asl
.Next
;
377 (NextOp
->Asl
.ParseOpcode
!= PARSEOP_NAMESEG
) &&
378 (NextOp
->Asl
.AmlOpcode
!= AML_INT_NAMEDFIELD_OP
))
380 NextOp
= NextOp
->Asl
.Next
;
388 /* Add length of this field to the current pin index */
390 if (NextOp
->Asl
.ParseOpcode
== PARSEOP_NAMESEG
)
392 i
+= (UINT32
) NextOp
->Asl
.Child
->Asl
.Value
.Integer
;
394 else /* AML_INT_NAMEDFIELD_OP */
396 i
+= (UINT32
) NextOp
->Asl
.Value
.Integer
;
400 /* Return the node and pathname for the field unit */
402 *TargetNode
= NextOp
->Asl
.Node
;
403 *TargetName
= AcpiNsGetExternalPathname (*TargetNode
);