128c506b8Sjruoho /*******************************************************************************
228c506b8Sjruoho *
328c506b8Sjruoho * Module Name: nsxfobj - Public interfaces to the ACPI subsystem
428c506b8Sjruoho * ACPI Object oriented interfaces
528c506b8Sjruoho *
628c506b8Sjruoho ******************************************************************************/
728c506b8Sjruoho
8124f4c82Sjruoho /*
9*046a2985Schristos * Copyright (C) 2000 - 2023, Intel Corp.
1028c506b8Sjruoho * All rights reserved.
1128c506b8Sjruoho *
12124f4c82Sjruoho * Redistribution and use in source and binary forms, with or without
13124f4c82Sjruoho * modification, are permitted provided that the following conditions
14124f4c82Sjruoho * are met:
15124f4c82Sjruoho * 1. Redistributions of source code must retain the above copyright
16124f4c82Sjruoho * notice, this list of conditions, and the following disclaimer,
17124f4c82Sjruoho * without modification.
18124f4c82Sjruoho * 2. Redistributions in binary form must reproduce at minimum a disclaimer
19124f4c82Sjruoho * substantially similar to the "NO WARRANTY" disclaimer below
20124f4c82Sjruoho * ("Disclaimer") and any redistribution must be conditioned upon
21124f4c82Sjruoho * including a substantially similar Disclaimer requirement for further
22124f4c82Sjruoho * binary redistribution.
23124f4c82Sjruoho * 3. Neither the names of the above-listed copyright holders nor the names
24124f4c82Sjruoho * of any contributors may be used to endorse or promote products derived
25124f4c82Sjruoho * from this software without specific prior written permission.
2628c506b8Sjruoho *
27124f4c82Sjruoho * Alternatively, this software may be distributed under the terms of the
28124f4c82Sjruoho * GNU General Public License ("GPL") version 2 as published by the Free
29124f4c82Sjruoho * Software Foundation.
3028c506b8Sjruoho *
31124f4c82Sjruoho * NO WARRANTY
32124f4c82Sjruoho * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33124f4c82Sjruoho * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
3446a330b4Schristos * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
35124f4c82Sjruoho * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36124f4c82Sjruoho * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37124f4c82Sjruoho * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38124f4c82Sjruoho * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39124f4c82Sjruoho * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40124f4c82Sjruoho * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
41124f4c82Sjruoho * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42124f4c82Sjruoho * POSSIBILITY OF SUCH DAMAGES.
43124f4c82Sjruoho */
4428c506b8Sjruoho
45ff4a156dSchristos #define EXPORT_ACPI_INTERFACES
4628c506b8Sjruoho
4728c506b8Sjruoho #include "acpi.h"
4828c506b8Sjruoho #include "accommon.h"
4928c506b8Sjruoho #include "acnamesp.h"
5028c506b8Sjruoho
5128c506b8Sjruoho
5228c506b8Sjruoho #define _COMPONENT ACPI_NAMESPACE
5328c506b8Sjruoho ACPI_MODULE_NAME ("nsxfobj")
5428c506b8Sjruoho
5528c506b8Sjruoho /*******************************************************************************
5628c506b8Sjruoho *
5728c506b8Sjruoho * FUNCTION: AcpiGetType
5828c506b8Sjruoho *
5928c506b8Sjruoho * PARAMETERS: Handle - Handle of object whose type is desired
6028c506b8Sjruoho * RetType - Where the type will be placed
6128c506b8Sjruoho *
6228c506b8Sjruoho * RETURN: Status
6328c506b8Sjruoho *
64360a9019Schristos * DESCRIPTION: This routine returns the type associated with a particular
65360a9019Schristos * handle
6628c506b8Sjruoho *
6728c506b8Sjruoho ******************************************************************************/
6828c506b8Sjruoho
6928c506b8Sjruoho ACPI_STATUS
AcpiGetType(ACPI_HANDLE Handle,ACPI_OBJECT_TYPE * RetType)7028c506b8Sjruoho AcpiGetType (
7128c506b8Sjruoho ACPI_HANDLE Handle,
7228c506b8Sjruoho ACPI_OBJECT_TYPE *RetType)
7328c506b8Sjruoho {
7428c506b8Sjruoho ACPI_NAMESPACE_NODE *Node;
7528c506b8Sjruoho ACPI_STATUS Status;
7628c506b8Sjruoho
7728c506b8Sjruoho
7828c506b8Sjruoho /* Parameter Validation */
7928c506b8Sjruoho
8028c506b8Sjruoho if (!RetType)
8128c506b8Sjruoho {
8228c506b8Sjruoho return (AE_BAD_PARAMETER);
8328c506b8Sjruoho }
8428c506b8Sjruoho
8571e38f1dSchristos /* Special case for the predefined Root Node (return type ANY) */
8671e38f1dSchristos
8728c506b8Sjruoho if (Handle == ACPI_ROOT_OBJECT)
8828c506b8Sjruoho {
8928c506b8Sjruoho *RetType = ACPI_TYPE_ANY;
9028c506b8Sjruoho return (AE_OK);
9128c506b8Sjruoho }
9228c506b8Sjruoho
9328c506b8Sjruoho Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
9428c506b8Sjruoho if (ACPI_FAILURE (Status))
9528c506b8Sjruoho {
9628c506b8Sjruoho return (Status);
9728c506b8Sjruoho }
9828c506b8Sjruoho
9928c506b8Sjruoho /* Convert and validate the handle */
10028c506b8Sjruoho
10128c506b8Sjruoho Node = AcpiNsValidateHandle (Handle);
10228c506b8Sjruoho if (!Node)
10328c506b8Sjruoho {
10428c506b8Sjruoho (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
10528c506b8Sjruoho return (AE_BAD_PARAMETER);
10628c506b8Sjruoho }
10728c506b8Sjruoho
10828c506b8Sjruoho *RetType = Node->Type;
10928c506b8Sjruoho
11028c506b8Sjruoho Status = AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
11128c506b8Sjruoho return (Status);
11228c506b8Sjruoho }
11328c506b8Sjruoho
ACPI_EXPORT_SYMBOL(AcpiGetType)11428c506b8Sjruoho ACPI_EXPORT_SYMBOL (AcpiGetType)
11528c506b8Sjruoho
11628c506b8Sjruoho
11728c506b8Sjruoho /*******************************************************************************
11828c506b8Sjruoho *
11928c506b8Sjruoho * FUNCTION: AcpiGetParent
12028c506b8Sjruoho *
12128c506b8Sjruoho * PARAMETERS: Handle - Handle of object whose parent is desired
12228c506b8Sjruoho * RetHandle - Where the parent handle will be placed
12328c506b8Sjruoho *
12428c506b8Sjruoho * RETURN: Status
12528c506b8Sjruoho *
12628c506b8Sjruoho * DESCRIPTION: Returns a handle to the parent of the object represented by
12728c506b8Sjruoho * Handle.
12828c506b8Sjruoho *
12928c506b8Sjruoho ******************************************************************************/
13028c506b8Sjruoho
13128c506b8Sjruoho ACPI_STATUS
13228c506b8Sjruoho AcpiGetParent (
13328c506b8Sjruoho ACPI_HANDLE Handle,
13428c506b8Sjruoho ACPI_HANDLE *RetHandle)
13528c506b8Sjruoho {
13628c506b8Sjruoho ACPI_NAMESPACE_NODE *Node;
13728c506b8Sjruoho ACPI_NAMESPACE_NODE *ParentNode;
13828c506b8Sjruoho ACPI_STATUS Status;
13928c506b8Sjruoho
14028c506b8Sjruoho
14128c506b8Sjruoho if (!RetHandle)
14228c506b8Sjruoho {
14328c506b8Sjruoho return (AE_BAD_PARAMETER);
14428c506b8Sjruoho }
14528c506b8Sjruoho
14628c506b8Sjruoho /* Special case for the predefined Root Node (no parent) */
14728c506b8Sjruoho
14828c506b8Sjruoho if (Handle == ACPI_ROOT_OBJECT)
14928c506b8Sjruoho {
15028c506b8Sjruoho return (AE_NULL_ENTRY);
15128c506b8Sjruoho }
15228c506b8Sjruoho
15328c506b8Sjruoho Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
15428c506b8Sjruoho if (ACPI_FAILURE (Status))
15528c506b8Sjruoho {
15628c506b8Sjruoho return (Status);
15728c506b8Sjruoho }
15828c506b8Sjruoho
15928c506b8Sjruoho /* Convert and validate the handle */
16028c506b8Sjruoho
16128c506b8Sjruoho Node = AcpiNsValidateHandle (Handle);
16228c506b8Sjruoho if (!Node)
16328c506b8Sjruoho {
16428c506b8Sjruoho Status = AE_BAD_PARAMETER;
16528c506b8Sjruoho goto UnlockAndExit;
16628c506b8Sjruoho }
16728c506b8Sjruoho
16828c506b8Sjruoho /* Get the parent entry */
16928c506b8Sjruoho
17028c506b8Sjruoho ParentNode = Node->Parent;
17128c506b8Sjruoho *RetHandle = ACPI_CAST_PTR (ACPI_HANDLE, ParentNode);
17228c506b8Sjruoho
17328c506b8Sjruoho /* Return exception if parent is null */
17428c506b8Sjruoho
17528c506b8Sjruoho if (!ParentNode)
17628c506b8Sjruoho {
17728c506b8Sjruoho Status = AE_NULL_ENTRY;
17828c506b8Sjruoho }
17928c506b8Sjruoho
18028c506b8Sjruoho
18128c506b8Sjruoho UnlockAndExit:
18228c506b8Sjruoho
18328c506b8Sjruoho (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
18428c506b8Sjruoho return (Status);
18528c506b8Sjruoho }
18628c506b8Sjruoho
ACPI_EXPORT_SYMBOL(AcpiGetParent)18728c506b8Sjruoho ACPI_EXPORT_SYMBOL (AcpiGetParent)
18828c506b8Sjruoho
18928c506b8Sjruoho
19028c506b8Sjruoho /*******************************************************************************
19128c506b8Sjruoho *
19228c506b8Sjruoho * FUNCTION: AcpiGetNextObject
19328c506b8Sjruoho *
19428c506b8Sjruoho * PARAMETERS: Type - Type of object to be searched for
19528c506b8Sjruoho * Parent - Parent object whose children we are getting
19628c506b8Sjruoho * LastChild - Previous child that was found.
19728c506b8Sjruoho * The NEXT child will be returned
19828c506b8Sjruoho * RetHandle - Where handle to the next object is placed
19928c506b8Sjruoho *
20028c506b8Sjruoho * RETURN: Status
20128c506b8Sjruoho *
20228c506b8Sjruoho * DESCRIPTION: Return the next peer object within the namespace. If Handle is
20328c506b8Sjruoho * valid, Scope is ignored. Otherwise, the first object within
20428c506b8Sjruoho * Scope is returned.
20528c506b8Sjruoho *
20628c506b8Sjruoho ******************************************************************************/
20728c506b8Sjruoho
20828c506b8Sjruoho ACPI_STATUS
20928c506b8Sjruoho AcpiGetNextObject (
21028c506b8Sjruoho ACPI_OBJECT_TYPE Type,
21128c506b8Sjruoho ACPI_HANDLE Parent,
21228c506b8Sjruoho ACPI_HANDLE Child,
21328c506b8Sjruoho ACPI_HANDLE *RetHandle)
21428c506b8Sjruoho {
21528c506b8Sjruoho ACPI_STATUS Status;
21628c506b8Sjruoho ACPI_NAMESPACE_NODE *Node;
21728c506b8Sjruoho ACPI_NAMESPACE_NODE *ParentNode = NULL;
21828c506b8Sjruoho ACPI_NAMESPACE_NODE *ChildNode = NULL;
21928c506b8Sjruoho
22028c506b8Sjruoho
22128c506b8Sjruoho /* Parameter validation */
22228c506b8Sjruoho
22328c506b8Sjruoho if (Type > ACPI_TYPE_EXTERNAL_MAX)
22428c506b8Sjruoho {
22528c506b8Sjruoho return (AE_BAD_PARAMETER);
22628c506b8Sjruoho }
22728c506b8Sjruoho
22828c506b8Sjruoho Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
22928c506b8Sjruoho if (ACPI_FAILURE (Status))
23028c506b8Sjruoho {
23128c506b8Sjruoho return (Status);
23228c506b8Sjruoho }
23328c506b8Sjruoho
23428c506b8Sjruoho /* If null handle, use the parent */
23528c506b8Sjruoho
23628c506b8Sjruoho if (!Child)
23728c506b8Sjruoho {
23828c506b8Sjruoho /* Start search at the beginning of the specified scope */
23928c506b8Sjruoho
24028c506b8Sjruoho ParentNode = AcpiNsValidateHandle (Parent);
24128c506b8Sjruoho if (!ParentNode)
24228c506b8Sjruoho {
24328c506b8Sjruoho Status = AE_BAD_PARAMETER;
24428c506b8Sjruoho goto UnlockAndExit;
24528c506b8Sjruoho }
24628c506b8Sjruoho }
24728c506b8Sjruoho else
24828c506b8Sjruoho {
24928c506b8Sjruoho /* Non-null handle, ignore the parent */
25028c506b8Sjruoho /* Convert and validate the handle */
25128c506b8Sjruoho
25228c506b8Sjruoho ChildNode = AcpiNsValidateHandle (Child);
25328c506b8Sjruoho if (!ChildNode)
25428c506b8Sjruoho {
25528c506b8Sjruoho Status = AE_BAD_PARAMETER;
25628c506b8Sjruoho goto UnlockAndExit;
25728c506b8Sjruoho }
25828c506b8Sjruoho }
25928c506b8Sjruoho
26028c506b8Sjruoho /* Internal function does the real work */
26128c506b8Sjruoho
26228c506b8Sjruoho Node = AcpiNsGetNextNodeTyped (Type, ParentNode, ChildNode);
26328c506b8Sjruoho if (!Node)
26428c506b8Sjruoho {
26528c506b8Sjruoho Status = AE_NOT_FOUND;
26628c506b8Sjruoho goto UnlockAndExit;
26728c506b8Sjruoho }
26828c506b8Sjruoho
26928c506b8Sjruoho if (RetHandle)
27028c506b8Sjruoho {
27128c506b8Sjruoho *RetHandle = ACPI_CAST_PTR (ACPI_HANDLE, Node);
27228c506b8Sjruoho }
27328c506b8Sjruoho
27428c506b8Sjruoho
27528c506b8Sjruoho UnlockAndExit:
27628c506b8Sjruoho
27728c506b8Sjruoho (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
27828c506b8Sjruoho return (Status);
27928c506b8Sjruoho }
28028c506b8Sjruoho
28128c506b8Sjruoho ACPI_EXPORT_SYMBOL (AcpiGetNextObject)
282