:pserver:cvsanon@mok.lvcm.com:/CVS/ReactOS reactos
[reactos.git] / drivers / bus / acpi / utils / cminit.c
1 /******************************************************************************
2  *
3  * Module Name: cminit - Common ACPI subsystem initialization
4  *              $Revision$
5  *
6  *****************************************************************************/
7
8 /*
9  *  Copyright (C) 2000, 2001 R. Byron Moore
10  *
11  *  This program is free software; you can redistribute it and/or modify
12  *  it under the terms of the GNU General Public License as published by
13  *  the Free Software Foundation; either version 2 of the License, or
14  *  (at your option) any later version.
15  *
16  *  This program is distributed in the hope that it will be useful,
17  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  *  GNU General Public License for more details.
20  *
21  *  You should have received a copy of the GNU General Public License
22  *  along with this program; if not, write to the Free Software
23  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
24  */
25
26
27 #include "acpi.h"
28 #include "achware.h"
29 #include "acnamesp.h"
30 #include "acevents.h"
31 #include "acparser.h"
32 #include "acdispat.h"
33
34 #define _COMPONENT          ACPI_UTILITIES
35          MODULE_NAME         ("cminit")
36
37
38 #define ACPI_OFFSET(d,o)    ((u32) &(((d *)0)->o))
39 #define ACPI_FADT_OFFSET(o) ACPI_OFFSET (FADT_DESCRIPTOR, o)
40
41 /*******************************************************************************
42  *
43  * FUNCTION:    Acpi_cm_fadt_register_error
44  *
45  * PARAMETERS:  *Register_name          - Pointer to string identifying register
46  *              Value                   - Actual register contents value
47  *              Acpi_test_spec_section  - TDS section containing assertion
48  *              Acpi_assertion          - Assertion number being tested
49  *
50  * RETURN:      AE_BAD_VALUE
51  *
52  * DESCRIPTION: Display failure message and link failure to TDS assertion
53  *
54  ******************************************************************************/
55
56 static ACPI_STATUS
57 acpi_cm_fadt_register_error (
58         NATIVE_CHAR             *register_name,
59         u32                     value,
60         u32                     offset)
61 {
62
63         REPORT_ERROR (
64                 ("Invalid FADT value %s=%lX at offset %lX FADT=%p\n",
65                 register_name, value, offset, acpi_gbl_FADT));
66
67
68         return (AE_BAD_VALUE);
69 }
70
71
72 /******************************************************************************
73  *
74  * FUNCTION:    Acpi_cm_validate_fadt
75  *
76  * PARAMETERS:  None
77  *
78  * RETURN:      Status
79  *
80  * DESCRIPTION: Validate various ACPI registers in the FADT
81  *
82  ******************************************************************************/
83
84 ACPI_STATUS
85 acpi_cm_validate_fadt (
86         void)
87 {
88         ACPI_STATUS                 status = AE_OK;
89
90
91         /*
92          * Verify Fixed ACPI Description Table fields,
93          * but don't abort on any problems, just display error
94          */
95
96         if (acpi_gbl_FADT->pm1_evt_len < 4) {
97                 status = acpi_cm_fadt_register_error ("PM1_EVT_LEN",
98                                   (u32) acpi_gbl_FADT->pm1_evt_len,
99                                   ACPI_FADT_OFFSET (pm1_evt_len));
100         }
101
102         if (!acpi_gbl_FADT->pm1_cnt_len) {
103                 status = acpi_cm_fadt_register_error ("PM1_CNT_LEN", 0,
104                                   ACPI_FADT_OFFSET (pm1_cnt_len));
105         }
106
107         if (!ACPI_VALID_ADDRESS (acpi_gbl_FADT->Xpm1a_evt_blk.address)) {
108                 status = acpi_cm_fadt_register_error ("X_PM1a_EVT_BLK", 0,
109                                   ACPI_FADT_OFFSET (Xpm1a_evt_blk.address));
110         }
111
112         if (!ACPI_VALID_ADDRESS (acpi_gbl_FADT->Xpm1a_cnt_blk.address)) {
113                 status = acpi_cm_fadt_register_error ("X_PM1a_CNT_BLK", 0,
114                                   ACPI_FADT_OFFSET (Xpm1a_cnt_blk.address));
115         }
116
117         if (!ACPI_VALID_ADDRESS (acpi_gbl_FADT->Xpm_tmr_blk.address)) {
118                 status = acpi_cm_fadt_register_error ("X_PM_TMR_BLK", 0,
119                                   ACPI_FADT_OFFSET (Xpm_tmr_blk.address));
120         }
121
122         if ((ACPI_VALID_ADDRESS (acpi_gbl_FADT->Xpm2_cnt_blk.address) &&
123                 !acpi_gbl_FADT->pm2_cnt_len)) {
124                 status = acpi_cm_fadt_register_error ("PM2_CNT_LEN",
125                                   (u32) acpi_gbl_FADT->pm2_cnt_len,
126                                   ACPI_FADT_OFFSET (pm2_cnt_len));
127         }
128
129         if (acpi_gbl_FADT->pm_tm_len < 4) {
130                 status = acpi_cm_fadt_register_error ("PM_TM_LEN",
131                                   (u32) acpi_gbl_FADT->pm_tm_len,
132                                   ACPI_FADT_OFFSET (pm_tm_len));
133         }
134
135         /* length of GPE blocks must be a multiple of 2 */
136
137
138         if (ACPI_VALID_ADDRESS (acpi_gbl_FADT->Xgpe0blk.address) &&
139                 (acpi_gbl_FADT->gpe0blk_len & 1)) {
140                 status = acpi_cm_fadt_register_error ("(x)GPE0_BLK_LEN",
141                                   (u32) acpi_gbl_FADT->gpe0blk_len,
142                                   ACPI_FADT_OFFSET (gpe0blk_len));
143         }
144
145         if (ACPI_VALID_ADDRESS (acpi_gbl_FADT->Xgpe1_blk.address) &&
146                 (acpi_gbl_FADT->gpe1_blk_len & 1)) {
147                 status = acpi_cm_fadt_register_error ("(x)GPE1_BLK_LEN",
148                                   (u32) acpi_gbl_FADT->gpe1_blk_len,
149                                   ACPI_FADT_OFFSET (gpe1_blk_len));
150         }
151
152         return (status);
153 }
154
155
156 /******************************************************************************
157  *
158  * FUNCTION:    Acpi_cm_terminate
159  *
160  * PARAMETERS:  none
161  *
162  * RETURN:      none
163  *
164  * DESCRIPTION: free memory allocated for table storage.
165  *
166  ******************************************************************************/
167
168 void
169 acpi_cm_terminate (void)
170 {
171
172
173         /* Free global tables, etc. */
174
175         if (acpi_gbl_gpe0enable_register_save) {
176                 acpi_cm_free (acpi_gbl_gpe0enable_register_save);
177         }
178
179         if (acpi_gbl_gpe1_enable_register_save) {
180                 acpi_cm_free (acpi_gbl_gpe1_enable_register_save);
181         }
182
183
184         return;
185 }
186
187
188 /******************************************************************************
189  *
190  * FUNCTION:    Acpi_cm_subsystem_shutdown
191  *
192  * PARAMETERS:  none
193  *
194  * RETURN:      none
195  *
196  * DESCRIPTION: Shutdown the various subsystems.  Don't delete the mutex
197  *              objects here -- because the AML debugger may be still running.
198  *
199  ******************************************************************************/
200
201 ACPI_STATUS
202 acpi_cm_subsystem_shutdown (void)
203 {
204
205         /* Just exit if subsystem is already shutdown */
206
207         if (acpi_gbl_shutdown) {
208                 return (AE_OK);
209         }
210
211         /* Subsystem appears active, go ahead and shut it down */
212
213         acpi_gbl_shutdown = TRUE;
214
215         /* Close the Namespace */
216
217         acpi_ns_terminate ();
218
219         /* Close the Acpi_event Handling */
220
221         acpi_ev_terminate ();
222
223         /* Close the globals */
224
225         acpi_cm_terminate ();
226
227         /* Flush the local cache(s) */
228
229         acpi_cm_delete_generic_state_cache ();
230         acpi_cm_delete_object_cache ();
231         acpi_ds_delete_walk_state_cache ();
232
233         /* Close the Parser */
234
235         /* TBD: [Restructure] Acpi_ps_terminate () */
236
237         acpi_ps_delete_parse_cache ();
238
239         /* Debug only - display leftover memory allocation, if any */
240 #ifdef ENABLE_DEBUGGER
241         acpi_cm_dump_current_allocations (ACPI_UINT32_MAX, NULL);
242 #endif
243
244         return (AE_OK);
245 }
246
247