167754Smsmith/******************************************************************************
267754Smsmith *
377424Smsmith * Module Name: utinit - Common ACPI subsystem initialization
467754Smsmith *
567754Smsmith *****************************************************************************/
667754Smsmith
7217365Sjkim/*
8245582Sjkim * Copyright (C) 2000 - 2013, Intel Corp.
970243Smsmith * All rights reserved.
1067754Smsmith *
11217365Sjkim * Redistribution and use in source and binary forms, with or without
12217365Sjkim * modification, are permitted provided that the following conditions
13217365Sjkim * are met:
14217365Sjkim * 1. Redistributions of source code must retain the above copyright
15217365Sjkim *    notice, this list of conditions, and the following disclaimer,
16217365Sjkim *    without modification.
17217365Sjkim * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18217365Sjkim *    substantially similar to the "NO WARRANTY" disclaimer below
19217365Sjkim *    ("Disclaimer") and any redistribution must be conditioned upon
20217365Sjkim *    including a substantially similar Disclaimer requirement for further
21217365Sjkim *    binary redistribution.
22217365Sjkim * 3. Neither the names of the above-listed copyright holders nor the names
23217365Sjkim *    of any contributors may be used to endorse or promote products derived
24217365Sjkim *    from this software without specific prior written permission.
2567754Smsmith *
26217365Sjkim * Alternatively, this software may be distributed under the terms of the
27217365Sjkim * GNU General Public License ("GPL") version 2 as published by the Free
28217365Sjkim * Software Foundation.
2967754Smsmith *
30217365Sjkim * NO WARRANTY
31217365Sjkim * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32217365Sjkim * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33217365Sjkim * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34217365Sjkim * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35217365Sjkim * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36217365Sjkim * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37217365Sjkim * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38217365Sjkim * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39217365Sjkim * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40217365Sjkim * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41217365Sjkim * POSSIBILITY OF SUCH DAMAGES.
42217365Sjkim */
4367754Smsmith
4467754Smsmith
4577424Smsmith#define __UTINIT_C__
4667754Smsmith
47193341Sjkim#include <contrib/dev/acpica/include/acpi.h>
48193341Sjkim#include <contrib/dev/acpica/include/accommon.h>
49193341Sjkim#include <contrib/dev/acpica/include/acnamesp.h>
50193341Sjkim#include <contrib/dev/acpica/include/acevents.h>
51193341Sjkim#include <contrib/dev/acpica/include/actables.h>
5267754Smsmith
5377424Smsmith#define _COMPONENT          ACPI_UTILITIES
5491116Smsmith        ACPI_MODULE_NAME    ("utinit")
5567754Smsmith
56151937Sjkim/* Local prototypes */
5767754Smsmith
58151937Sjkimstatic void AcpiUtTerminate (
59151937Sjkim    void);
60151937Sjkim
61231844Sjkim#if (!ACPI_REDUCED_HARDWARE)
62151937Sjkim
63231844Sjkimstatic void
64231844SjkimAcpiUtFreeGpeLists (
65231844Sjkim    void);
66231844Sjkim
67231844Sjkim#else
68231844Sjkim
69231844Sjkim#define AcpiUtFreeGpeLists()
70231844Sjkim#endif /* !ACPI_REDUCED_HARDWARE */
71231844Sjkim
72231844Sjkim
73231844Sjkim#if (!ACPI_REDUCED_HARDWARE)
7467754Smsmith/******************************************************************************
7567754Smsmith *
76231844Sjkim * FUNCTION:    AcpiUtFreeGpeLists
7767754Smsmith *
7867754Smsmith * PARAMETERS:  none
7967754Smsmith *
8067754Smsmith * RETURN:      none
8167754Smsmith *
82231844Sjkim * DESCRIPTION: Free global GPE lists
8367754Smsmith *
8467754Smsmith ******************************************************************************/
8567754Smsmith
86151937Sjkimstatic void
87231844SjkimAcpiUtFreeGpeLists (
88151937Sjkim    void)
8967754Smsmith{
90117521Snjl    ACPI_GPE_BLOCK_INFO     *GpeBlock;
91117521Snjl    ACPI_GPE_BLOCK_INFO     *NextGpeBlock;
92117521Snjl    ACPI_GPE_XRUPT_INFO     *GpeXruptInfo;
93117521Snjl    ACPI_GPE_XRUPT_INFO     *NextGpeXruptInfo;
9467754Smsmith
95117521Snjl
96117521Snjl    /* Free global GPE blocks and related info structures */
97117521Snjl
98117521Snjl    GpeXruptInfo = AcpiGbl_GpeXruptListHead;
99117521Snjl    while (GpeXruptInfo)
100117521Snjl    {
101117521Snjl        GpeBlock = GpeXruptInfo->GpeBlockListHead;
102117521Snjl        while (GpeBlock)
103117521Snjl        {
104117521Snjl            NextGpeBlock = GpeBlock->Next;
105167802Sjkim            ACPI_FREE (GpeBlock->EventInfo);
106167802Sjkim            ACPI_FREE (GpeBlock->RegisterInfo);
107167802Sjkim            ACPI_FREE (GpeBlock);
108117521Snjl
109117521Snjl            GpeBlock = NextGpeBlock;
110117521Snjl        }
111117521Snjl        NextGpeXruptInfo = GpeXruptInfo->Next;
112167802Sjkim        ACPI_FREE (GpeXruptInfo);
113117521Snjl        GpeXruptInfo = NextGpeXruptInfo;
114117521Snjl    }
115231844Sjkim}
116231844Sjkim#endif /* !ACPI_REDUCED_HARDWARE */
117117521Snjl
118231844Sjkim
119231844Sjkim/******************************************************************************
120231844Sjkim *
121231844Sjkim * FUNCTION:    AcpiUtTerminate
122231844Sjkim *
123231844Sjkim * PARAMETERS:  none
124231844Sjkim *
125231844Sjkim * RETURN:      none
126231844Sjkim *
127231844Sjkim * DESCRIPTION: Free global memory
128231844Sjkim *
129231844Sjkim ******************************************************************************/
130231844Sjkim
131231844Sjkimstatic void
132231844SjkimAcpiUtTerminate (
133231844Sjkim    void)
134231844Sjkim{
135231844Sjkim    ACPI_FUNCTION_TRACE (UtTerminate);
136231844Sjkim
137231844Sjkim    AcpiUtFreeGpeLists ();
138229989Sjkim    AcpiUtDeleteAddressLists ();
13967754Smsmith    return_VOID;
14067754Smsmith}
14167754Smsmith
14267754Smsmith
14377424Smsmith/*******************************************************************************
14467754Smsmith *
14577424Smsmith * FUNCTION:    AcpiUtSubsystemShutdown
14667754Smsmith *
147197104Sjkim * PARAMETERS:  None
14867754Smsmith *
149197104Sjkim * RETURN:      None
15067754Smsmith *
151197104Sjkim * DESCRIPTION: Shutdown the various components. Do not delete the mutex
152197104Sjkim *              objects here, because the AML debugger may be still running.
15367754Smsmith *
15467754Smsmith ******************************************************************************/
15567754Smsmith
15699679Siwasakivoid
157151937SjkimAcpiUtSubsystemShutdown (
158151937Sjkim    void)
15967754Smsmith{
160167802Sjkim    ACPI_FUNCTION_TRACE (UtSubsystemShutdown);
16167754Smsmith
16267754Smsmith
163193267Sjkim#ifndef ACPI_ASL_COMPILER
164193267Sjkim
165102550Siwasaki    /* Close the AcpiEvent Handling */
166102550Siwasaki
167102550Siwasaki    AcpiEvTerminate ();
168210976Sjkim
169210976Sjkim    /* Delete any dynamic _OSI interfaces */
170210976Sjkim
171210976Sjkim    AcpiUtInterfaceTerminate ();
172193267Sjkim#endif
173102550Siwasaki
17467754Smsmith    /* Close the Namespace */
17567754Smsmith
17667754Smsmith    AcpiNsTerminate ();
17767754Smsmith
178167802Sjkim    /* Delete the ACPI tables */
179167802Sjkim
180167802Sjkim    AcpiTbTerminate ();
181167802Sjkim
18267754Smsmith    /* Close the globals */
18367754Smsmith
18477424Smsmith    AcpiUtTerminate ();
18567754Smsmith
18687031Smsmith    /* Purge the local caches */
18767754Smsmith
188151937Sjkim    (void) AcpiUtDeleteCaches ();
18999679Siwasaki    return_VOID;
19067754Smsmith}
191