aehandlers.c revision 1.1.1.4 1 1.1 jruoho /******************************************************************************
2 1.1 jruoho *
3 1.1 jruoho * Module Name: aehandlers - Various handlers for acpiexec
4 1.1 jruoho *
5 1.1 jruoho *****************************************************************************/
6 1.1 jruoho
7 1.1.1.2 jruoho /*
8 1.1.1.4 christos * Copyright (C) 2000 - 2013, Intel Corp.
9 1.1 jruoho * All rights reserved.
10 1.1 jruoho *
11 1.1.1.2 jruoho * Redistribution and use in source and binary forms, with or without
12 1.1.1.2 jruoho * modification, are permitted provided that the following conditions
13 1.1.1.2 jruoho * are met:
14 1.1.1.2 jruoho * 1. Redistributions of source code must retain the above copyright
15 1.1.1.2 jruoho * notice, this list of conditions, and the following disclaimer,
16 1.1.1.2 jruoho * without modification.
17 1.1.1.2 jruoho * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 1.1.1.2 jruoho * substantially similar to the "NO WARRANTY" disclaimer below
19 1.1.1.2 jruoho * ("Disclaimer") and any redistribution must be conditioned upon
20 1.1.1.2 jruoho * including a substantially similar Disclaimer requirement for further
21 1.1.1.2 jruoho * binary redistribution.
22 1.1.1.2 jruoho * 3. Neither the names of the above-listed copyright holders nor the names
23 1.1.1.2 jruoho * of any contributors may be used to endorse or promote products derived
24 1.1.1.2 jruoho * from this software without specific prior written permission.
25 1.1.1.2 jruoho *
26 1.1.1.2 jruoho * Alternatively, this software may be distributed under the terms of the
27 1.1.1.2 jruoho * GNU General Public License ("GPL") version 2 as published by the Free
28 1.1.1.2 jruoho * Software Foundation.
29 1.1.1.2 jruoho *
30 1.1.1.2 jruoho * NO WARRANTY
31 1.1.1.2 jruoho * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 1.1.1.2 jruoho * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 1.1.1.2 jruoho * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 1.1.1.2 jruoho * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 1.1.1.2 jruoho * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 1.1.1.2 jruoho * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 1.1.1.2 jruoho * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 1.1.1.2 jruoho * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 1.1.1.2 jruoho * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 1.1.1.2 jruoho * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 1.1.1.2 jruoho * POSSIBILITY OF SUCH DAMAGES.
42 1.1.1.2 jruoho */
43 1.1 jruoho
44 1.1 jruoho #include "aecommon.h"
45 1.1 jruoho
46 1.1 jruoho #define _COMPONENT ACPI_TOOLS
47 1.1 jruoho ACPI_MODULE_NAME ("aehandlers")
48 1.1 jruoho
49 1.1 jruoho /* Local prototypes */
50 1.1 jruoho
51 1.1.1.2 jruoho static void
52 1.1.1.4 christos AeNotifyHandler1 (
53 1.1 jruoho ACPI_HANDLE Device,
54 1.1 jruoho UINT32 Value,
55 1.1 jruoho void *Context);
56 1.1 jruoho
57 1.1.1.2 jruoho static void
58 1.1.1.4 christos AeNotifyHandler2 (
59 1.1.1.4 christos ACPI_HANDLE Device,
60 1.1.1.4 christos UINT32 Value,
61 1.1.1.4 christos void *Context);
62 1.1.1.4 christos
63 1.1.1.4 christos static void
64 1.1.1.4 christos AeCommonNotifyHandler (
65 1.1.1.4 christos ACPI_HANDLE Device,
66 1.1.1.4 christos UINT32 Value,
67 1.1.1.4 christos UINT32 HandlerId);
68 1.1.1.4 christos
69 1.1.1.4 christos static void
70 1.1 jruoho AeDeviceNotifyHandler (
71 1.1 jruoho ACPI_HANDLE Device,
72 1.1 jruoho UINT32 Value,
73 1.1 jruoho void *Context);
74 1.1 jruoho
75 1.1.1.2 jruoho static ACPI_STATUS
76 1.1 jruoho AeExceptionHandler (
77 1.1 jruoho ACPI_STATUS AmlStatus,
78 1.1 jruoho ACPI_NAME Name,
79 1.1 jruoho UINT16 Opcode,
80 1.1 jruoho UINT32 AmlOffset,
81 1.1 jruoho void *Context);
82 1.1 jruoho
83 1.1.1.2 jruoho static ACPI_STATUS
84 1.1 jruoho AeTableHandler (
85 1.1 jruoho UINT32 Event,
86 1.1 jruoho void *Table,
87 1.1 jruoho void *Context);
88 1.1 jruoho
89 1.1.1.2 jruoho static ACPI_STATUS
90 1.1 jruoho AeRegionInit (
91 1.1 jruoho ACPI_HANDLE RegionHandle,
92 1.1 jruoho UINT32 Function,
93 1.1 jruoho void *HandlerContext,
94 1.1 jruoho void **RegionContext);
95 1.1 jruoho
96 1.1.1.2 jruoho static void
97 1.1 jruoho AeAttachedDataHandler (
98 1.1 jruoho ACPI_HANDLE Object,
99 1.1 jruoho void *Data);
100 1.1 jruoho
101 1.1.1.4 christos static void
102 1.1.1.4 christos AeAttachedDataHandler2 (
103 1.1.1.4 christos ACPI_HANDLE Object,
104 1.1.1.4 christos void *Data);
105 1.1.1.4 christos
106 1.1.1.2 jruoho static UINT32
107 1.1.1.2 jruoho AeInterfaceHandler (
108 1.1.1.2 jruoho ACPI_STRING InterfaceName,
109 1.1.1.2 jruoho UINT32 Supported);
110 1.1.1.2 jruoho
111 1.1.1.4 christos static ACPI_STATUS
112 1.1.1.4 christos AeInstallEcHandler (
113 1.1.1.4 christos ACPI_HANDLE ObjHandle,
114 1.1.1.4 christos UINT32 Level,
115 1.1.1.4 christos void *Context,
116 1.1.1.4 christos void **ReturnValue);
117 1.1.1.4 christos
118 1.1.1.4 christos static ACPI_STATUS
119 1.1.1.4 christos AeInstallPciHandler (
120 1.1.1.4 christos ACPI_HANDLE ObjHandle,
121 1.1.1.4 christos UINT32 Level,
122 1.1.1.4 christos void *Context,
123 1.1.1.4 christos void **ReturnValue);
124 1.1.1.4 christos
125 1.1.1.4 christos static ACPI_STATUS
126 1.1.1.4 christos AeInstallDeviceHandlers (
127 1.1.1.4 christos void);
128 1.1.1.4 christos
129 1.1.1.4 christos #if (!ACPI_REDUCED_HARDWARE)
130 1.1.1.2 jruoho static UINT32
131 1.1.1.2 jruoho AeEventHandler (
132 1.1.1.2 jruoho void *Context);
133 1.1.1.2 jruoho
134 1.1.1.4 christos static UINT32
135 1.1.1.4 christos AeSciHandler (
136 1.1.1.4 christos void *Context);
137 1.1.1.4 christos
138 1.1.1.4 christos static char *TableEvents[] =
139 1.1.1.4 christos {
140 1.1.1.4 christos "LOAD",
141 1.1.1.4 christos "UNLOAD",
142 1.1.1.4 christos "UNKNOWN"
143 1.1.1.4 christos };
144 1.1.1.4 christos #endif /* !ACPI_REDUCED_HARDWARE */
145 1.1.1.4 christos
146 1.1.1.4 christos
147 1.1.1.2 jruoho static UINT32 SigintCount = 0;
148 1.1.1.2 jruoho static AE_DEBUG_REGIONS AeRegions;
149 1.1.1.4 christos BOOLEAN AcpiGbl_DisplayRegionAccess = FALSE;
150 1.1.1.2 jruoho
151 1.1.1.2 jruoho /*
152 1.1.1.3 jruoho * We will override some of the default region handlers, especially the
153 1.1.1.3 jruoho * SystemMemory handler, which must be implemented locally. Do not override
154 1.1.1.3 jruoho * the PCI_Config handler since we would like to exercise the default handler
155 1.1.1.3 jruoho * code. These handlers are installed "early" - before any _REG methods
156 1.1.1.4 christos * are executed - since they are special in the sense that the ACPI spec
157 1.1.1.3 jruoho * declares that they must "always be available". Cannot override the
158 1.1.1.3 jruoho * DataTable region handler either -- needed for test execution.
159 1.1.1.2 jruoho */
160 1.1.1.4 christos static ACPI_ADR_SPACE_TYPE DefaultSpaceIdList[] =
161 1.1.1.4 christos {
162 1.1.1.2 jruoho ACPI_ADR_SPACE_SYSTEM_MEMORY,
163 1.1.1.2 jruoho ACPI_ADR_SPACE_SYSTEM_IO
164 1.1.1.2 jruoho };
165 1.1.1.2 jruoho
166 1.1.1.2 jruoho /*
167 1.1.1.4 christos * We will install handlers for some of the various address space IDs.
168 1.1.1.4 christos * Test one user-defined address space (used by aslts).
169 1.1.1.2 jruoho */
170 1.1.1.4 christos #define ACPI_ADR_SPACE_USER_DEFINED1 0x80
171 1.1.1.4 christos #define ACPI_ADR_SPACE_USER_DEFINED2 0xE4
172 1.1.1.3 jruoho
173 1.1.1.4 christos static ACPI_ADR_SPACE_TYPE SpaceIdList[] =
174 1.1.1.4 christos {
175 1.1.1.2 jruoho ACPI_ADR_SPACE_SMBUS,
176 1.1.1.4 christos ACPI_ADR_SPACE_CMOS,
177 1.1.1.2 jruoho ACPI_ADR_SPACE_PCI_BAR_TARGET,
178 1.1.1.2 jruoho ACPI_ADR_SPACE_IPMI,
179 1.1.1.4 christos ACPI_ADR_SPACE_GPIO,
180 1.1.1.4 christos ACPI_ADR_SPACE_GSBUS,
181 1.1.1.3 jruoho ACPI_ADR_SPACE_FIXED_HARDWARE,
182 1.1.1.4 christos ACPI_ADR_SPACE_USER_DEFINED1,
183 1.1.1.4 christos ACPI_ADR_SPACE_USER_DEFINED2
184 1.1.1.2 jruoho };
185 1.1 jruoho
186 1.1.1.4 christos static ACPI_CONNECTION_INFO AeMyContext;
187 1.1.1.4 christos
188 1.1 jruoho
189 1.1 jruoho /******************************************************************************
190 1.1 jruoho *
191 1.1 jruoho * FUNCTION: AeCtrlCHandler
192 1.1 jruoho *
193 1.1 jruoho * PARAMETERS: Sig
194 1.1 jruoho *
195 1.1 jruoho * RETURN: none
196 1.1 jruoho *
197 1.1.1.4 christos * DESCRIPTION: Control-C handler. Abort running control method if any.
198 1.1 jruoho *
199 1.1 jruoho *****************************************************************************/
200 1.1 jruoho
201 1.1.1.2 jruoho void ACPI_SYSTEM_XFACE
202 1.1 jruoho AeCtrlCHandler (
203 1.1 jruoho int Sig)
204 1.1 jruoho {
205 1.1 jruoho
206 1.1 jruoho signal (SIGINT, SIG_IGN);
207 1.1 jruoho SigintCount++;
208 1.1 jruoho
209 1.1 jruoho AcpiOsPrintf ("Caught a ctrl-c (#%u)\n\n", SigintCount);
210 1.1 jruoho
211 1.1 jruoho if (AcpiGbl_MethodExecuting)
212 1.1 jruoho {
213 1.1 jruoho AcpiGbl_AbortMethod = TRUE;
214 1.1 jruoho signal (SIGINT, AeCtrlCHandler);
215 1.1 jruoho
216 1.1 jruoho if (SigintCount < 10)
217 1.1 jruoho {
218 1.1 jruoho return;
219 1.1 jruoho }
220 1.1 jruoho }
221 1.1 jruoho
222 1.1.1.4 christos (void) AcpiOsTerminate ();
223 1.1 jruoho exit (0);
224 1.1 jruoho }
225 1.1 jruoho
226 1.1 jruoho
227 1.1 jruoho /******************************************************************************
228 1.1 jruoho *
229 1.1.1.4 christos * FUNCTION: AeNotifyHandler(s)
230 1.1 jruoho *
231 1.1 jruoho * PARAMETERS: Standard notify handler parameters
232 1.1 jruoho *
233 1.1 jruoho * RETURN: Status
234 1.1 jruoho *
235 1.1.1.4 christos * DESCRIPTION: Notify handlers for AcpiExec utility. Used by the ASL
236 1.1 jruoho * test suite(s) to communicate errors and other information to
237 1.1.1.4 christos * this utility via the Notify() operator. Tests notify handling
238 1.1.1.4 christos * and multiple notify handler support.
239 1.1 jruoho *
240 1.1 jruoho *****************************************************************************/
241 1.1 jruoho
242 1.1.1.2 jruoho static void
243 1.1.1.4 christos AeNotifyHandler1 (
244 1.1.1.4 christos ACPI_HANDLE Device,
245 1.1.1.4 christos UINT32 Value,
246 1.1.1.4 christos void *Context)
247 1.1.1.4 christos {
248 1.1.1.4 christos AeCommonNotifyHandler (Device, Value, 1);
249 1.1.1.4 christos }
250 1.1.1.4 christos
251 1.1.1.4 christos static void
252 1.1.1.4 christos AeNotifyHandler2 (
253 1.1.1.4 christos ACPI_HANDLE Device,
254 1.1.1.4 christos UINT32 Value,
255 1.1.1.4 christos void *Context)
256 1.1.1.4 christos {
257 1.1.1.4 christos AeCommonNotifyHandler (Device, Value, 2);
258 1.1.1.4 christos }
259 1.1.1.4 christos
260 1.1.1.4 christos static void
261 1.1.1.4 christos AeCommonNotifyHandler (
262 1.1.1.4 christos ACPI_HANDLE Device,
263 1.1.1.4 christos UINT32 Value,
264 1.1.1.4 christos UINT32 HandlerId)
265 1.1 jruoho {
266 1.1.1.4 christos char *Type;
267 1.1.1.4 christos
268 1.1.1.4 christos
269 1.1.1.4 christos Type = "Device";
270 1.1.1.4 christos if (Value <= ACPI_MAX_SYS_NOTIFY)
271 1.1.1.4 christos {
272 1.1.1.4 christos Type = "System";
273 1.1.1.4 christos }
274 1.1 jruoho
275 1.1 jruoho switch (Value)
276 1.1 jruoho {
277 1.1 jruoho #if 0
278 1.1 jruoho case 0:
279 1.1.1.4 christos
280 1.1 jruoho printf ("[AcpiExec] Method Error 0x%X: Results not equal\n", Value);
281 1.1 jruoho if (AcpiGbl_DebugFile)
282 1.1 jruoho {
283 1.1 jruoho AcpiOsPrintf ("[AcpiExec] Method Error: Results not equal\n");
284 1.1 jruoho }
285 1.1 jruoho break;
286 1.1 jruoho
287 1.1 jruoho case 1:
288 1.1.1.4 christos
289 1.1 jruoho printf ("[AcpiExec] Method Error: Incorrect numeric result\n");
290 1.1 jruoho if (AcpiGbl_DebugFile)
291 1.1 jruoho {
292 1.1 jruoho AcpiOsPrintf ("[AcpiExec] Method Error: Incorrect numeric result\n");
293 1.1 jruoho }
294 1.1 jruoho break;
295 1.1 jruoho
296 1.1 jruoho case 2:
297 1.1.1.4 christos
298 1.1 jruoho printf ("[AcpiExec] Method Error: An operand was overwritten\n");
299 1.1 jruoho if (AcpiGbl_DebugFile)
300 1.1 jruoho {
301 1.1 jruoho AcpiOsPrintf ("[AcpiExec] Method Error: An operand was overwritten\n");
302 1.1 jruoho }
303 1.1 jruoho break;
304 1.1 jruoho
305 1.1 jruoho #endif
306 1.1 jruoho
307 1.1 jruoho default:
308 1.1.1.4 christos
309 1.1.1.4 christos printf ("[AcpiExec] Handler %u: Received a %s Notify on [%4.4s] %p Value 0x%2.2X (%s)\n",
310 1.1.1.4 christos HandlerId, Type, AcpiUtGetNodeName (Device), Device, Value,
311 1.1 jruoho AcpiUtGetNotifyName (Value));
312 1.1 jruoho if (AcpiGbl_DebugFile)
313 1.1 jruoho {
314 1.1.1.4 christos AcpiOsPrintf ("[AcpiExec] Handler %u: Received a %s notify, Value 0x%2.2X\n",
315 1.1.1.4 christos HandlerId, Type, Value);
316 1.1 jruoho }
317 1.1 jruoho
318 1.1 jruoho (void) AcpiEvaluateObject (Device, "_NOT", NULL, NULL);
319 1.1 jruoho break;
320 1.1 jruoho }
321 1.1 jruoho }
322 1.1 jruoho
323 1.1 jruoho
324 1.1 jruoho /******************************************************************************
325 1.1 jruoho *
326 1.1.1.4 christos * FUNCTION: AeSystemNotifyHandler
327 1.1.1.4 christos *
328 1.1.1.4 christos * PARAMETERS: Standard notify handler parameters
329 1.1.1.4 christos *
330 1.1.1.4 christos * RETURN: Status
331 1.1.1.4 christos *
332 1.1.1.4 christos * DESCRIPTION: System notify handler for AcpiExec utility. Used by the ASL
333 1.1.1.4 christos * test suite(s) to communicate errors and other information to
334 1.1.1.4 christos * this utility via the Notify() operator.
335 1.1.1.4 christos *
336 1.1.1.4 christos *****************************************************************************/
337 1.1.1.4 christos
338 1.1.1.4 christos static void
339 1.1.1.4 christos AeSystemNotifyHandler (
340 1.1.1.4 christos ACPI_HANDLE Device,
341 1.1.1.4 christos UINT32 Value,
342 1.1.1.4 christos void *Context)
343 1.1.1.4 christos {
344 1.1.1.4 christos
345 1.1.1.4 christos printf ("[AcpiExec] Global: Received a System Notify on [%4.4s] %p Value 0x%2.2X (%s)\n",
346 1.1.1.4 christos AcpiUtGetNodeName (Device), Device, Value,
347 1.1.1.4 christos AcpiUtGetNotifyName (Value));
348 1.1.1.4 christos if (AcpiGbl_DebugFile)
349 1.1.1.4 christos {
350 1.1.1.4 christos AcpiOsPrintf ("[AcpiExec] Global: Received a System Notify, Value 0x%2.2X\n", Value);
351 1.1.1.4 christos }
352 1.1.1.4 christos
353 1.1.1.4 christos (void) AcpiEvaluateObject (Device, "_NOT", NULL, NULL);
354 1.1.1.4 christos }
355 1.1.1.4 christos
356 1.1.1.4 christos
357 1.1.1.4 christos /******************************************************************************
358 1.1.1.4 christos *
359 1.1 jruoho * FUNCTION: AeDeviceNotifyHandler
360 1.1 jruoho *
361 1.1 jruoho * PARAMETERS: Standard notify handler parameters
362 1.1 jruoho *
363 1.1 jruoho * RETURN: Status
364 1.1 jruoho *
365 1.1.1.4 christos * DESCRIPTION: Device notify handler for AcpiExec utility. Used by the ASL
366 1.1 jruoho * test suite(s) to communicate errors and other information to
367 1.1 jruoho * this utility via the Notify() operator.
368 1.1 jruoho *
369 1.1 jruoho *****************************************************************************/
370 1.1 jruoho
371 1.1.1.2 jruoho static void
372 1.1 jruoho AeDeviceNotifyHandler (
373 1.1 jruoho ACPI_HANDLE Device,
374 1.1 jruoho UINT32 Value,
375 1.1 jruoho void *Context)
376 1.1 jruoho {
377 1.1 jruoho
378 1.1.1.4 christos printf ("[AcpiExec] Global: Received a Device Notify on [%4.4s] %p Value 0x%2.2X (%s)\n",
379 1.1 jruoho AcpiUtGetNodeName (Device), Device, Value,
380 1.1 jruoho AcpiUtGetNotifyName (Value));
381 1.1 jruoho if (AcpiGbl_DebugFile)
382 1.1 jruoho {
383 1.1.1.4 christos AcpiOsPrintf ("[AcpiExec] Global: Received a Device Notify, Value 0x%2.2X\n", Value);
384 1.1 jruoho }
385 1.1 jruoho
386 1.1 jruoho (void) AcpiEvaluateObject (Device, "_NOT", NULL, NULL);
387 1.1 jruoho }
388 1.1 jruoho
389 1.1 jruoho
390 1.1 jruoho /******************************************************************************
391 1.1 jruoho *
392 1.1 jruoho * FUNCTION: AeExceptionHandler
393 1.1 jruoho *
394 1.1 jruoho * PARAMETERS: Standard exception handler parameters
395 1.1 jruoho *
396 1.1 jruoho * RETURN: Status
397 1.1 jruoho *
398 1.1 jruoho * DESCRIPTION: System exception handler for AcpiExec utility.
399 1.1 jruoho *
400 1.1 jruoho *****************************************************************************/
401 1.1 jruoho
402 1.1.1.2 jruoho static ACPI_STATUS
403 1.1 jruoho AeExceptionHandler (
404 1.1 jruoho ACPI_STATUS AmlStatus,
405 1.1 jruoho ACPI_NAME Name,
406 1.1 jruoho UINT16 Opcode,
407 1.1 jruoho UINT32 AmlOffset,
408 1.1 jruoho void *Context)
409 1.1 jruoho {
410 1.1 jruoho ACPI_STATUS NewAmlStatus = AmlStatus;
411 1.1 jruoho ACPI_STATUS Status;
412 1.1 jruoho ACPI_BUFFER ReturnObj;
413 1.1 jruoho ACPI_OBJECT_LIST ArgList;
414 1.1 jruoho ACPI_OBJECT Arg[3];
415 1.1 jruoho const char *Exception;
416 1.1 jruoho
417 1.1 jruoho
418 1.1 jruoho Exception = AcpiFormatException (AmlStatus);
419 1.1 jruoho AcpiOsPrintf ("[AcpiExec] Exception %s during execution ", Exception);
420 1.1 jruoho if (Name)
421 1.1 jruoho {
422 1.1 jruoho AcpiOsPrintf ("of method [%4.4s]", (char *) &Name);
423 1.1 jruoho }
424 1.1 jruoho else
425 1.1 jruoho {
426 1.1 jruoho AcpiOsPrintf ("at module level (table load)");
427 1.1 jruoho }
428 1.1 jruoho AcpiOsPrintf (" Opcode [%s] @%X\n", AcpiPsGetOpcodeName (Opcode), AmlOffset);
429 1.1 jruoho
430 1.1 jruoho /*
431 1.1 jruoho * Invoke the _ERR method if present
432 1.1 jruoho *
433 1.1 jruoho * Setup parameter object
434 1.1 jruoho */
435 1.1 jruoho ArgList.Count = 3;
436 1.1 jruoho ArgList.Pointer = Arg;
437 1.1 jruoho
438 1.1 jruoho Arg[0].Type = ACPI_TYPE_INTEGER;
439 1.1 jruoho Arg[0].Integer.Value = AmlStatus;
440 1.1 jruoho
441 1.1 jruoho Arg[1].Type = ACPI_TYPE_STRING;
442 1.1 jruoho Arg[1].String.Pointer = ACPI_CAST_PTR (char, Exception);
443 1.1 jruoho Arg[1].String.Length = ACPI_STRLEN (Exception);
444 1.1 jruoho
445 1.1 jruoho Arg[2].Type = ACPI_TYPE_INTEGER;
446 1.1.1.2 jruoho Arg[2].Integer.Value = AcpiOsGetThreadId();
447 1.1 jruoho
448 1.1 jruoho /* Setup return buffer */
449 1.1 jruoho
450 1.1 jruoho ReturnObj.Pointer = NULL;
451 1.1 jruoho ReturnObj.Length = ACPI_ALLOCATE_BUFFER;
452 1.1 jruoho
453 1.1 jruoho Status = AcpiEvaluateObject (NULL, "\\_ERR", &ArgList, &ReturnObj);
454 1.1 jruoho if (ACPI_SUCCESS (Status))
455 1.1 jruoho {
456 1.1 jruoho if (ReturnObj.Pointer)
457 1.1 jruoho {
458 1.1 jruoho /* Override original status */
459 1.1 jruoho
460 1.1 jruoho NewAmlStatus = (ACPI_STATUS)
461 1.1 jruoho ((ACPI_OBJECT *) ReturnObj.Pointer)->Integer.Value;
462 1.1 jruoho
463 1.1.1.4 christos /* Free a buffer created via ACPI_ALLOCATE_BUFFER */
464 1.1.1.4 christos
465 1.1 jruoho AcpiOsFree (ReturnObj.Pointer);
466 1.1 jruoho }
467 1.1 jruoho }
468 1.1 jruoho else if (Status != AE_NOT_FOUND)
469 1.1 jruoho {
470 1.1 jruoho AcpiOsPrintf ("[AcpiExec] Could not execute _ERR method, %s\n",
471 1.1 jruoho AcpiFormatException (Status));
472 1.1 jruoho }
473 1.1 jruoho
474 1.1 jruoho /* Global override */
475 1.1 jruoho
476 1.1 jruoho if (AcpiGbl_IgnoreErrors)
477 1.1 jruoho {
478 1.1 jruoho NewAmlStatus = AE_OK;
479 1.1 jruoho }
480 1.1 jruoho
481 1.1 jruoho if (NewAmlStatus != AmlStatus)
482 1.1 jruoho {
483 1.1 jruoho AcpiOsPrintf ("[AcpiExec] Exception override, new status %s\n",
484 1.1 jruoho AcpiFormatException (NewAmlStatus));
485 1.1 jruoho }
486 1.1 jruoho
487 1.1 jruoho return (NewAmlStatus);
488 1.1 jruoho }
489 1.1 jruoho
490 1.1 jruoho
491 1.1 jruoho /******************************************************************************
492 1.1 jruoho *
493 1.1 jruoho * FUNCTION: AeTableHandler
494 1.1 jruoho *
495 1.1 jruoho * PARAMETERS: Table handler
496 1.1 jruoho *
497 1.1 jruoho * RETURN: Status
498 1.1 jruoho *
499 1.1 jruoho * DESCRIPTION: System table handler for AcpiExec utility.
500 1.1 jruoho *
501 1.1 jruoho *****************************************************************************/
502 1.1 jruoho
503 1.1.1.2 jruoho static ACPI_STATUS
504 1.1 jruoho AeTableHandler (
505 1.1 jruoho UINT32 Event,
506 1.1 jruoho void *Table,
507 1.1 jruoho void *Context)
508 1.1 jruoho {
509 1.1.1.4 christos #if (!ACPI_REDUCED_HARDWARE)
510 1.1.1.2 jruoho ACPI_STATUS Status;
511 1.1.1.4 christos #endif /* !ACPI_REDUCED_HARDWARE */
512 1.1.1.2 jruoho
513 1.1 jruoho
514 1.1 jruoho if (Event > ACPI_NUM_TABLE_EVENTS)
515 1.1 jruoho {
516 1.1 jruoho Event = ACPI_NUM_TABLE_EVENTS;
517 1.1 jruoho }
518 1.1 jruoho
519 1.1.1.4 christos #if (!ACPI_REDUCED_HARDWARE)
520 1.1.1.2 jruoho /* Enable any GPEs associated with newly-loaded GPE methods */
521 1.1.1.2 jruoho
522 1.1.1.2 jruoho Status = AcpiUpdateAllGpes ();
523 1.1.1.2 jruoho AE_CHECK_OK (AcpiUpdateAllGpes, Status);
524 1.1 jruoho
525 1.1 jruoho printf ("[AcpiExec] Table Event %s, [%4.4s] %p\n",
526 1.1 jruoho TableEvents[Event], ((ACPI_TABLE_HEADER *) Table)->Signature, Table);
527 1.1.1.4 christos #endif /* !ACPI_REDUCED_HARDWARE */
528 1.1.1.4 christos
529 1.1 jruoho return (AE_OK);
530 1.1 jruoho }
531 1.1 jruoho
532 1.1 jruoho
533 1.1 jruoho /******************************************************************************
534 1.1 jruoho *
535 1.1 jruoho * FUNCTION: AeGpeHandler
536 1.1 jruoho *
537 1.1.1.2 jruoho * DESCRIPTION: Common GPE handler for acpiexec
538 1.1 jruoho *
539 1.1 jruoho *****************************************************************************/
540 1.1 jruoho
541 1.1 jruoho UINT32
542 1.1 jruoho AeGpeHandler (
543 1.1.1.2 jruoho ACPI_HANDLE GpeDevice,
544 1.1.1.2 jruoho UINT32 GpeNumber,
545 1.1 jruoho void *Context)
546 1.1 jruoho {
547 1.1.1.2 jruoho ACPI_NAMESPACE_NODE *DeviceNode = (ACPI_NAMESPACE_NODE *) GpeDevice;
548 1.1.1.2 jruoho
549 1.1.1.2 jruoho
550 1.1.1.2 jruoho AcpiOsPrintf ("[AcpiExec] GPE Handler received GPE%02X (GPE block %4.4s)\n",
551 1.1.1.2 jruoho GpeNumber, GpeDevice ? DeviceNode->Name.Ascii : "FADT");
552 1.1.1.2 jruoho
553 1.1.1.2 jruoho return (ACPI_REENABLE_GPE);
554 1.1.1.2 jruoho }
555 1.1.1.2 jruoho
556 1.1.1.2 jruoho
557 1.1.1.2 jruoho /******************************************************************************
558 1.1.1.2 jruoho *
559 1.1.1.2 jruoho * FUNCTION: AeGlobalEventHandler
560 1.1.1.2 jruoho *
561 1.1.1.2 jruoho * DESCRIPTION: Global GPE/Fixed event handler
562 1.1.1.2 jruoho *
563 1.1.1.2 jruoho *****************************************************************************/
564 1.1.1.2 jruoho
565 1.1.1.2 jruoho void
566 1.1.1.2 jruoho AeGlobalEventHandler (
567 1.1.1.2 jruoho UINT32 Type,
568 1.1.1.2 jruoho ACPI_HANDLE Device,
569 1.1.1.2 jruoho UINT32 EventNumber,
570 1.1.1.2 jruoho void *Context)
571 1.1.1.2 jruoho {
572 1.1.1.2 jruoho char *TypeName;
573 1.1.1.2 jruoho
574 1.1.1.2 jruoho
575 1.1.1.2 jruoho switch (Type)
576 1.1.1.2 jruoho {
577 1.1.1.2 jruoho case ACPI_EVENT_TYPE_GPE:
578 1.1.1.4 christos
579 1.1.1.2 jruoho TypeName = "GPE";
580 1.1.1.2 jruoho break;
581 1.1.1.2 jruoho
582 1.1.1.2 jruoho case ACPI_EVENT_TYPE_FIXED:
583 1.1.1.4 christos
584 1.1.1.2 jruoho TypeName = "FixedEvent";
585 1.1.1.2 jruoho break;
586 1.1.1.2 jruoho
587 1.1.1.2 jruoho default:
588 1.1.1.4 christos
589 1.1.1.2 jruoho TypeName = "UNKNOWN";
590 1.1.1.2 jruoho break;
591 1.1.1.2 jruoho }
592 1.1.1.2 jruoho
593 1.1.1.2 jruoho AcpiOsPrintf ("[AcpiExec] Global Event Handler received: Type %s Number %.2X Dev %p\n",
594 1.1.1.2 jruoho TypeName, EventNumber, Device);
595 1.1 jruoho }
596 1.1 jruoho
597 1.1 jruoho
598 1.1 jruoho /******************************************************************************
599 1.1 jruoho *
600 1.1 jruoho * FUNCTION: AeAttachedDataHandler
601 1.1 jruoho *
602 1.1 jruoho * DESCRIPTION: Handler for deletion of nodes with attached data (attached via
603 1.1 jruoho * AcpiAttachData)
604 1.1 jruoho *
605 1.1 jruoho *****************************************************************************/
606 1.1 jruoho
607 1.1.1.2 jruoho static void
608 1.1 jruoho AeAttachedDataHandler (
609 1.1 jruoho ACPI_HANDLE Object,
610 1.1 jruoho void *Data)
611 1.1 jruoho {
612 1.1 jruoho ACPI_NAMESPACE_NODE *Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, Data);
613 1.1 jruoho
614 1.1 jruoho
615 1.1.1.4 christos AcpiOsPrintf ("Received an attached data deletion (1) on %4.4s\n",
616 1.1.1.4 christos Node->Name.Ascii);
617 1.1.1.4 christos }
618 1.1.1.4 christos
619 1.1.1.4 christos
620 1.1.1.4 christos /******************************************************************************
621 1.1.1.4 christos *
622 1.1.1.4 christos * FUNCTION: AeAttachedDataHandler2
623 1.1.1.4 christos *
624 1.1.1.4 christos * DESCRIPTION: Handler for deletion of nodes with attached data (attached via
625 1.1.1.4 christos * AcpiAttachData)
626 1.1.1.4 christos *
627 1.1.1.4 christos *****************************************************************************/
628 1.1.1.4 christos
629 1.1.1.4 christos static void
630 1.1.1.4 christos AeAttachedDataHandler2 (
631 1.1.1.4 christos ACPI_HANDLE Object,
632 1.1.1.4 christos void *Data)
633 1.1.1.4 christos {
634 1.1.1.4 christos ACPI_NAMESPACE_NODE *Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, Data);
635 1.1.1.4 christos
636 1.1.1.4 christos
637 1.1.1.4 christos AcpiOsPrintf ("Received an attached data deletion (2) on %4.4s\n",
638 1.1 jruoho Node->Name.Ascii);
639 1.1 jruoho }
640 1.1 jruoho
641 1.1 jruoho
642 1.1 jruoho /******************************************************************************
643 1.1 jruoho *
644 1.1.1.2 jruoho * FUNCTION: AeInterfaceHandler
645 1.1.1.2 jruoho *
646 1.1.1.2 jruoho * DESCRIPTION: Handler for _OSI invocations
647 1.1.1.2 jruoho *
648 1.1.1.2 jruoho *****************************************************************************/
649 1.1.1.2 jruoho
650 1.1.1.2 jruoho static UINT32
651 1.1.1.2 jruoho AeInterfaceHandler (
652 1.1.1.2 jruoho ACPI_STRING InterfaceName,
653 1.1.1.2 jruoho UINT32 Supported)
654 1.1.1.2 jruoho {
655 1.1.1.2 jruoho ACPI_FUNCTION_NAME (AeInterfaceHandler);
656 1.1.1.2 jruoho
657 1.1.1.2 jruoho
658 1.1.1.2 jruoho ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
659 1.1.1.2 jruoho "Received _OSI (\"%s\"), is %ssupported\n",
660 1.1.1.2 jruoho InterfaceName, Supported == 0 ? "not " : ""));
661 1.1.1.2 jruoho
662 1.1.1.2 jruoho return (Supported);
663 1.1.1.2 jruoho }
664 1.1.1.2 jruoho
665 1.1.1.2 jruoho
666 1.1.1.4 christos #if (!ACPI_REDUCED_HARDWARE)
667 1.1.1.2 jruoho /******************************************************************************
668 1.1.1.2 jruoho *
669 1.1.1.4 christos * FUNCTION: AeEventHandler, AeSciHandler
670 1.1.1.2 jruoho *
671 1.1.1.4 christos * DESCRIPTION: Handler for Fixed Events and SCIs
672 1.1.1.2 jruoho *
673 1.1.1.2 jruoho *****************************************************************************/
674 1.1.1.2 jruoho
675 1.1.1.2 jruoho static UINT32
676 1.1.1.2 jruoho AeEventHandler (
677 1.1.1.2 jruoho void *Context)
678 1.1.1.2 jruoho {
679 1.1.1.2 jruoho return (0);
680 1.1.1.2 jruoho }
681 1.1.1.2 jruoho
682 1.1.1.4 christos static UINT32
683 1.1.1.4 christos AeSciHandler (
684 1.1.1.4 christos void *Context)
685 1.1.1.4 christos {
686 1.1.1.4 christos
687 1.1.1.4 christos AcpiOsPrintf ("[AcpiExec] Received an SCI at handler\n");
688 1.1.1.4 christos return (0);
689 1.1.1.4 christos }
690 1.1.1.4 christos
691 1.1.1.4 christos #endif /* !ACPI_REDUCED_HARDWARE */
692 1.1.1.4 christos
693 1.1.1.2 jruoho
694 1.1.1.2 jruoho /******************************************************************************
695 1.1.1.2 jruoho *
696 1.1 jruoho * FUNCTION: AeRegionInit
697 1.1 jruoho *
698 1.1 jruoho * PARAMETERS: None
699 1.1 jruoho *
700 1.1 jruoho * RETURN: Status
701 1.1 jruoho *
702 1.1 jruoho * DESCRIPTION: Opregion init function.
703 1.1 jruoho *
704 1.1 jruoho *****************************************************************************/
705 1.1 jruoho
706 1.1.1.2 jruoho static ACPI_STATUS
707 1.1 jruoho AeRegionInit (
708 1.1 jruoho ACPI_HANDLE RegionHandle,
709 1.1 jruoho UINT32 Function,
710 1.1 jruoho void *HandlerContext,
711 1.1 jruoho void **RegionContext)
712 1.1 jruoho {
713 1.1 jruoho
714 1.1.1.4 christos if (Function == ACPI_REGION_DEACTIVATE)
715 1.1.1.4 christos {
716 1.1.1.4 christos *RegionContext = NULL;
717 1.1.1.4 christos }
718 1.1.1.4 christos else
719 1.1.1.4 christos {
720 1.1.1.4 christos *RegionContext = RegionHandle;
721 1.1.1.4 christos }
722 1.1.1.4 christos
723 1.1.1.4 christos return (AE_OK);
724 1.1.1.4 christos }
725 1.1.1.4 christos
726 1.1.1.4 christos
727 1.1.1.4 christos /*******************************************************************************
728 1.1.1.4 christos *
729 1.1.1.4 christos * FUNCTION: AeInstallSciHandler
730 1.1.1.4 christos *
731 1.1.1.4 christos * PARAMETERS: None
732 1.1.1.4 christos *
733 1.1.1.4 christos * RETURN: Status
734 1.1.1.4 christos *
735 1.1.1.4 christos * DESCRIPTION: Install handler for SCIs. Exercise the code by doing an
736 1.1.1.4 christos * install/remove/install.
737 1.1.1.4 christos *
738 1.1.1.4 christos ******************************************************************************/
739 1.1.1.4 christos
740 1.1.1.4 christos static ACPI_STATUS
741 1.1.1.4 christos AeInstallSciHandler (
742 1.1.1.4 christos void)
743 1.1.1.4 christos {
744 1.1.1.4 christos ACPI_STATUS Status;
745 1.1.1.4 christos
746 1.1.1.4 christos
747 1.1.1.4 christos Status = AcpiInstallSciHandler (AeSciHandler, &AeMyContext);
748 1.1.1.4 christos if (ACPI_FAILURE (Status))
749 1.1.1.4 christos {
750 1.1.1.4 christos ACPI_EXCEPTION ((AE_INFO, Status,
751 1.1.1.4 christos "Could not install an SCI handler (1)"));
752 1.1.1.4 christos }
753 1.1.1.4 christos
754 1.1.1.4 christos Status = AcpiRemoveSciHandler (AeSciHandler);
755 1.1.1.4 christos if (ACPI_FAILURE (Status))
756 1.1.1.4 christos {
757 1.1.1.4 christos ACPI_EXCEPTION ((AE_INFO, Status,
758 1.1.1.4 christos "Could not remove an SCI handler"));
759 1.1.1.4 christos }
760 1.1.1.4 christos
761 1.1.1.4 christos Status = AcpiInstallSciHandler (AeSciHandler, &AeMyContext);
762 1.1.1.4 christos if (ACPI_FAILURE (Status))
763 1.1.1.4 christos {
764 1.1.1.4 christos ACPI_EXCEPTION ((AE_INFO, Status,
765 1.1.1.4 christos "Could not install an SCI handler (2)"));
766 1.1.1.4 christos }
767 1.1.1.4 christos
768 1.1.1.4 christos return (Status);
769 1.1.1.4 christos }
770 1.1.1.4 christos
771 1.1.1.4 christos
772 1.1.1.4 christos /*******************************************************************************
773 1.1.1.4 christos *
774 1.1.1.4 christos * FUNCTION: AeInstallDeviceHandlers, AeInstallEcHandler,
775 1.1.1.4 christos * AeInstallPciHandler
776 1.1.1.4 christos *
777 1.1.1.4 christos * PARAMETERS: ACPI_WALK_NAMESPACE callback
778 1.1.1.4 christos *
779 1.1.1.4 christos * RETURN: Status
780 1.1.1.4 christos *
781 1.1.1.4 christos * DESCRIPTION: Walk entire namespace, install a handler for every EC
782 1.1.1.4 christos * and PCI device found.
783 1.1.1.4 christos *
784 1.1.1.4 christos ******************************************************************************/
785 1.1.1.4 christos
786 1.1.1.4 christos static ACPI_STATUS
787 1.1.1.4 christos AeInstallEcHandler (
788 1.1.1.4 christos ACPI_HANDLE ObjHandle,
789 1.1.1.4 christos UINT32 Level,
790 1.1.1.4 christos void *Context,
791 1.1.1.4 christos void **ReturnValue)
792 1.1.1.4 christos {
793 1.1.1.4 christos ACPI_STATUS Status;
794 1.1.1.4 christos
795 1.1.1.4 christos
796 1.1.1.4 christos /* Install the handler for this EC device */
797 1.1.1.4 christos
798 1.1.1.4 christos Status = AcpiInstallAddressSpaceHandler (ObjHandle, ACPI_ADR_SPACE_EC,
799 1.1.1.4 christos AeRegionHandler, AeRegionInit, &AeMyContext);
800 1.1.1.4 christos if (ACPI_FAILURE (Status))
801 1.1.1.4 christos {
802 1.1.1.4 christos ACPI_EXCEPTION ((AE_INFO, Status,
803 1.1.1.4 christos "Could not install an OpRegion handler for EC device (%p)",
804 1.1.1.4 christos ObjHandle));
805 1.1.1.4 christos }
806 1.1.1.4 christos
807 1.1.1.4 christos return (Status);
808 1.1.1.4 christos }
809 1.1.1.4 christos
810 1.1.1.4 christos static ACPI_STATUS
811 1.1.1.4 christos AeInstallPciHandler (
812 1.1.1.4 christos ACPI_HANDLE ObjHandle,
813 1.1.1.4 christos UINT32 Level,
814 1.1.1.4 christos void *Context,
815 1.1.1.4 christos void **ReturnValue)
816 1.1.1.4 christos {
817 1.1.1.4 christos ACPI_STATUS Status;
818 1.1.1.4 christos
819 1.1.1.4 christos
820 1.1.1.4 christos /* Install memory and I/O handlers for the PCI device */
821 1.1.1.4 christos
822 1.1.1.4 christos Status = AcpiInstallAddressSpaceHandler (ObjHandle, ACPI_ADR_SPACE_SYSTEM_IO,
823 1.1.1.4 christos AeRegionHandler, AeRegionInit, &AeMyContext);
824 1.1.1.4 christos if (ACPI_FAILURE (Status))
825 1.1.1.4 christos {
826 1.1.1.4 christos ACPI_EXCEPTION ((AE_INFO, Status,
827 1.1.1.4 christos "Could not install an OpRegion handler for PCI device (%p)",
828 1.1.1.4 christos ObjHandle));
829 1.1.1.4 christos }
830 1.1.1.4 christos
831 1.1.1.4 christos Status = AcpiInstallAddressSpaceHandler (ObjHandle, ACPI_ADR_SPACE_SYSTEM_MEMORY,
832 1.1.1.4 christos AeRegionHandler, AeRegionInit, &AeMyContext);
833 1.1.1.4 christos if (ACPI_FAILURE (Status))
834 1.1.1.4 christos {
835 1.1.1.4 christos ACPI_EXCEPTION ((AE_INFO, Status,
836 1.1.1.4 christos "Could not install an OpRegion handler for PCI device (%p)",
837 1.1.1.4 christos ObjHandle));
838 1.1.1.4 christos }
839 1.1.1.4 christos
840 1.1.1.4 christos return (AE_CTRL_TERMINATE);
841 1.1.1.4 christos }
842 1.1.1.4 christos
843 1.1.1.4 christos static ACPI_STATUS
844 1.1.1.4 christos AeInstallDeviceHandlers (
845 1.1.1.4 christos void)
846 1.1.1.4 christos {
847 1.1.1.4 christos
848 1.1.1.4 christos /* Find all Embedded Controller devices */
849 1.1.1.4 christos
850 1.1.1.4 christos AcpiGetDevices ("PNP0C09", AeInstallEcHandler, NULL, NULL);
851 1.1.1.4 christos
852 1.1.1.4 christos /* Install a PCI handler */
853 1.1.1.4 christos
854 1.1.1.4 christos AcpiGetDevices ("PNP0A08", AeInstallPciHandler, NULL, NULL);
855 1.1.1.2 jruoho return (AE_OK);
856 1.1 jruoho }
857 1.1 jruoho
858 1.1 jruoho
859 1.1 jruoho /******************************************************************************
860 1.1 jruoho *
861 1.1.1.2 jruoho * FUNCTION: AeInstallLateHandlers
862 1.1 jruoho *
863 1.1 jruoho * PARAMETERS: None
864 1.1 jruoho *
865 1.1 jruoho * RETURN: Status
866 1.1 jruoho *
867 1.1 jruoho * DESCRIPTION: Install handlers for the AcpiExec utility.
868 1.1 jruoho *
869 1.1 jruoho *****************************************************************************/
870 1.1 jruoho
871 1.1.1.2 jruoho ACPI_STATUS
872 1.1.1.2 jruoho AeInstallLateHandlers (
873 1.1.1.2 jruoho void)
874 1.1.1.2 jruoho {
875 1.1.1.2 jruoho ACPI_STATUS Status;
876 1.1.1.2 jruoho UINT32 i;
877 1.1.1.2 jruoho
878 1.1.1.2 jruoho
879 1.1.1.4 christos #if (!ACPI_REDUCED_HARDWARE)
880 1.1.1.4 christos if (!AcpiGbl_ReducedHardware)
881 1.1.1.4 christos {
882 1.1.1.4 christos /* Install a user SCI handler */
883 1.1.1.4 christos
884 1.1.1.4 christos Status = AeInstallSciHandler ();
885 1.1.1.4 christos AE_CHECK_OK (AeInstallSciHandler, Status);
886 1.1.1.4 christos
887 1.1.1.4 christos /* Install some fixed event handlers */
888 1.1.1.2 jruoho
889 1.1.1.4 christos Status = AcpiInstallFixedEventHandler (ACPI_EVENT_GLOBAL, AeEventHandler, NULL);
890 1.1.1.4 christos AE_CHECK_OK (AcpiInstallFixedEventHandler, Status);
891 1.1.1.2 jruoho
892 1.1.1.4 christos Status = AcpiInstallFixedEventHandler (ACPI_EVENT_RTC, AeEventHandler, NULL);
893 1.1.1.4 christos AE_CHECK_OK (AcpiInstallFixedEventHandler, Status);
894 1.1.1.4 christos }
895 1.1.1.4 christos #endif /* !ACPI_REDUCED_HARDWARE */
896 1.1.1.4 christos
897 1.1.1.4 christos AeMyContext.Connection = NULL;
898 1.1.1.4 christos AeMyContext.AccessLength = 0xA5;
899 1.1.1.4 christos
900 1.1.1.4 christos /*
901 1.1.1.4 christos * We will install a handler for each EC device, directly under the EC
902 1.1.1.4 christos * device definition. This is unlike the other handlers which we install
903 1.1.1.4 christos * at the root node. Also install memory and I/O handlers at any PCI
904 1.1.1.4 christos * devices.
905 1.1.1.4 christos */
906 1.1.1.4 christos AeInstallDeviceHandlers ();
907 1.1.1.2 jruoho
908 1.1.1.2 jruoho /*
909 1.1.1.2 jruoho * Install handlers for some of the "device driver" address spaces
910 1.1.1.4 christos * such as SMBus, etc.
911 1.1.1.2 jruoho */
912 1.1.1.2 jruoho for (i = 0; i < ACPI_ARRAY_LENGTH (SpaceIdList); i++)
913 1.1.1.2 jruoho {
914 1.1.1.2 jruoho /* Install handler at the root object */
915 1.1.1.2 jruoho
916 1.1.1.4 christos Status = AcpiInstallAddressSpaceHandler (ACPI_ROOT_OBJECT,
917 1.1.1.4 christos SpaceIdList[i], AeRegionHandler,
918 1.1.1.4 christos AeRegionInit, &AeMyContext);
919 1.1.1.2 jruoho if (ACPI_FAILURE (Status))
920 1.1.1.2 jruoho {
921 1.1.1.2 jruoho ACPI_EXCEPTION ((AE_INFO, Status,
922 1.1.1.2 jruoho "Could not install an OpRegion handler for %s space(%u)",
923 1.1.1.2 jruoho AcpiUtGetRegionName((UINT8) SpaceIdList[i]), SpaceIdList[i]));
924 1.1.1.2 jruoho return (Status);
925 1.1.1.2 jruoho }
926 1.1.1.2 jruoho }
927 1.1.1.2 jruoho
928 1.1.1.2 jruoho return (AE_OK);
929 1.1.1.2 jruoho }
930 1.1.1.2 jruoho
931 1.1.1.2 jruoho
932 1.1.1.2 jruoho /******************************************************************************
933 1.1.1.2 jruoho *
934 1.1.1.2 jruoho * FUNCTION: AeInstallEarlyHandlers
935 1.1.1.2 jruoho *
936 1.1.1.2 jruoho * PARAMETERS: None
937 1.1.1.2 jruoho *
938 1.1.1.2 jruoho * RETURN: Status
939 1.1.1.2 jruoho *
940 1.1.1.2 jruoho * DESCRIPTION: Install handlers for the AcpiExec utility.
941 1.1.1.2 jruoho *
942 1.1.1.2 jruoho * Notes: Don't install handler for PCI_Config, we want to use the
943 1.1.1.2 jruoho * default handler to exercise that code.
944 1.1.1.2 jruoho *
945 1.1.1.2 jruoho *****************************************************************************/
946 1.1 jruoho
947 1.1 jruoho ACPI_STATUS
948 1.1.1.2 jruoho AeInstallEarlyHandlers (
949 1.1.1.2 jruoho void)
950 1.1 jruoho {
951 1.1 jruoho ACPI_STATUS Status;
952 1.1 jruoho UINT32 i;
953 1.1 jruoho ACPI_HANDLE Handle;
954 1.1 jruoho
955 1.1 jruoho
956 1.1 jruoho ACPI_FUNCTION_ENTRY ();
957 1.1 jruoho
958 1.1 jruoho
959 1.1.1.2 jruoho Status = AcpiInstallInterfaceHandler (AeInterfaceHandler);
960 1.1.1.2 jruoho if (ACPI_FAILURE (Status))
961 1.1.1.2 jruoho {
962 1.1.1.2 jruoho printf ("Could not install interface handler, %s\n",
963 1.1.1.2 jruoho AcpiFormatException (Status));
964 1.1.1.2 jruoho }
965 1.1.1.2 jruoho
966 1.1 jruoho Status = AcpiInstallTableHandler (AeTableHandler, NULL);
967 1.1 jruoho if (ACPI_FAILURE (Status))
968 1.1 jruoho {
969 1.1 jruoho printf ("Could not install table handler, %s\n",
970 1.1 jruoho AcpiFormatException (Status));
971 1.1 jruoho }
972 1.1 jruoho
973 1.1 jruoho Status = AcpiInstallExceptionHandler (AeExceptionHandler);
974 1.1 jruoho if (ACPI_FAILURE (Status))
975 1.1 jruoho {
976 1.1 jruoho printf ("Could not install exception handler, %s\n",
977 1.1 jruoho AcpiFormatException (Status));
978 1.1 jruoho }
979 1.1 jruoho
980 1.1.1.4 christos /* Install global notify handlers */
981 1.1 jruoho
982 1.1 jruoho Status = AcpiInstallNotifyHandler (ACPI_ROOT_OBJECT, ACPI_SYSTEM_NOTIFY,
983 1.1.1.4 christos AeSystemNotifyHandler, NULL);
984 1.1 jruoho if (ACPI_FAILURE (Status))
985 1.1 jruoho {
986 1.1.1.4 christos printf ("Could not install a global system notify handler, %s\n",
987 1.1 jruoho AcpiFormatException (Status));
988 1.1 jruoho }
989 1.1 jruoho
990 1.1 jruoho Status = AcpiInstallNotifyHandler (ACPI_ROOT_OBJECT, ACPI_DEVICE_NOTIFY,
991 1.1.1.4 christos AeDeviceNotifyHandler, NULL);
992 1.1 jruoho if (ACPI_FAILURE (Status))
993 1.1 jruoho {
994 1.1 jruoho printf ("Could not install a global notify handler, %s\n",
995 1.1 jruoho AcpiFormatException (Status));
996 1.1 jruoho }
997 1.1 jruoho
998 1.1 jruoho Status = AcpiGetHandle (NULL, "\\_SB", &Handle);
999 1.1 jruoho if (ACPI_SUCCESS (Status))
1000 1.1 jruoho {
1001 1.1 jruoho Status = AcpiInstallNotifyHandler (Handle, ACPI_SYSTEM_NOTIFY,
1002 1.1.1.4 christos AeNotifyHandler1, NULL);
1003 1.1 jruoho if (ACPI_FAILURE (Status))
1004 1.1 jruoho {
1005 1.1 jruoho printf ("Could not install a notify handler, %s\n",
1006 1.1 jruoho AcpiFormatException (Status));
1007 1.1 jruoho }
1008 1.1 jruoho
1009 1.1 jruoho Status = AcpiRemoveNotifyHandler (Handle, ACPI_SYSTEM_NOTIFY,
1010 1.1.1.4 christos AeNotifyHandler1);
1011 1.1 jruoho if (ACPI_FAILURE (Status))
1012 1.1 jruoho {
1013 1.1 jruoho printf ("Could not remove a notify handler, %s\n",
1014 1.1 jruoho AcpiFormatException (Status));
1015 1.1 jruoho }
1016 1.1 jruoho
1017 1.1 jruoho Status = AcpiInstallNotifyHandler (Handle, ACPI_ALL_NOTIFY,
1018 1.1.1.4 christos AeNotifyHandler1, NULL);
1019 1.1.1.2 jruoho AE_CHECK_OK (AcpiInstallNotifyHandler, Status);
1020 1.1.1.2 jruoho
1021 1.1 jruoho Status = AcpiRemoveNotifyHandler (Handle, ACPI_ALL_NOTIFY,
1022 1.1.1.4 christos AeNotifyHandler1);
1023 1.1.1.2 jruoho AE_CHECK_OK (AcpiRemoveNotifyHandler, Status);
1024 1.1.1.2 jruoho
1025 1.1.1.4 christos #if 0
1026 1.1 jruoho Status = AcpiInstallNotifyHandler (Handle, ACPI_ALL_NOTIFY,
1027 1.1.1.4 christos AeNotifyHandler1, NULL);
1028 1.1 jruoho if (ACPI_FAILURE (Status))
1029 1.1 jruoho {
1030 1.1 jruoho printf ("Could not install a notify handler, %s\n",
1031 1.1 jruoho AcpiFormatException (Status));
1032 1.1 jruoho }
1033 1.1.1.4 christos #endif
1034 1.1.1.4 christos
1035 1.1.1.4 christos /* Install two handlers for _SB_ */
1036 1.1.1.4 christos
1037 1.1.1.4 christos Status = AcpiInstallNotifyHandler (Handle, ACPI_SYSTEM_NOTIFY,
1038 1.1.1.4 christos AeNotifyHandler1, ACPI_CAST_PTR (void, 0x01234567));
1039 1.1.1.4 christos
1040 1.1.1.4 christos Status = AcpiInstallNotifyHandler (Handle, ACPI_SYSTEM_NOTIFY,
1041 1.1.1.4 christos AeNotifyHandler2, ACPI_CAST_PTR (void, 0x89ABCDEF));
1042 1.1.1.4 christos
1043 1.1.1.4 christos /* Attempt duplicate handler installation, should fail */
1044 1.1.1.4 christos
1045 1.1.1.4 christos Status = AcpiInstallNotifyHandler (Handle, ACPI_SYSTEM_NOTIFY,
1046 1.1.1.4 christos AeNotifyHandler1, ACPI_CAST_PTR (void, 0x77777777));
1047 1.1 jruoho
1048 1.1 jruoho Status = AcpiAttachData (Handle, AeAttachedDataHandler, Handle);
1049 1.1.1.2 jruoho AE_CHECK_OK (AcpiAttachData, Status);
1050 1.1.1.2 jruoho
1051 1.1 jruoho Status = AcpiDetachData (Handle, AeAttachedDataHandler);
1052 1.1.1.2 jruoho AE_CHECK_OK (AcpiDetachData, Status);
1053 1.1.1.2 jruoho
1054 1.1 jruoho Status = AcpiAttachData (Handle, AeAttachedDataHandler, Handle);
1055 1.1.1.2 jruoho AE_CHECK_OK (AcpiAttachData, Status);
1056 1.1.1.4 christos
1057 1.1.1.4 christos /* Test support for multiple attaches */
1058 1.1.1.4 christos
1059 1.1.1.4 christos Status = AcpiAttachData (Handle, AeAttachedDataHandler2, Handle);
1060 1.1.1.4 christos AE_CHECK_OK (AcpiAttachData, Status);
1061 1.1 jruoho }
1062 1.1 jruoho else
1063 1.1 jruoho {
1064 1.1 jruoho printf ("No _SB_ found, %s\n", AcpiFormatException (Status));
1065 1.1 jruoho }
1066 1.1 jruoho
1067 1.1 jruoho
1068 1.1.1.4 christos Status = AcpiGetHandle (NULL, "\\_TZ.TZ1", &Handle);
1069 1.1.1.4 christos if (ACPI_SUCCESS (Status))
1070 1.1.1.4 christos {
1071 1.1.1.4 christos Status = AcpiInstallNotifyHandler (Handle, ACPI_ALL_NOTIFY,
1072 1.1.1.4 christos AeNotifyHandler1, ACPI_CAST_PTR (void, 0x01234567));
1073 1.1.1.4 christos
1074 1.1.1.4 christos Status = AcpiInstallNotifyHandler (Handle, ACPI_ALL_NOTIFY,
1075 1.1.1.4 christos AeNotifyHandler2, ACPI_CAST_PTR (void, 0x89ABCDEF));
1076 1.1.1.4 christos
1077 1.1.1.4 christos Status = AcpiRemoveNotifyHandler (Handle, ACPI_ALL_NOTIFY,
1078 1.1.1.4 christos AeNotifyHandler1);
1079 1.1.1.4 christos Status = AcpiRemoveNotifyHandler (Handle, ACPI_ALL_NOTIFY,
1080 1.1.1.4 christos AeNotifyHandler2);
1081 1.1.1.4 christos
1082 1.1.1.4 christos Status = AcpiInstallNotifyHandler (Handle, ACPI_ALL_NOTIFY,
1083 1.1.1.4 christos AeNotifyHandler2, ACPI_CAST_PTR (void, 0x89ABCDEF));
1084 1.1.1.4 christos
1085 1.1.1.4 christos Status = AcpiInstallNotifyHandler (Handle, ACPI_ALL_NOTIFY,
1086 1.1.1.4 christos AeNotifyHandler1, ACPI_CAST_PTR (void, 0x01234567));
1087 1.1.1.4 christos }
1088 1.1.1.4 christos
1089 1.1.1.4 christos Status = AcpiGetHandle (NULL, "\\_PR.CPU0", &Handle);
1090 1.1.1.4 christos if (ACPI_SUCCESS (Status))
1091 1.1.1.4 christos {
1092 1.1.1.4 christos Status = AcpiInstallNotifyHandler (Handle, ACPI_ALL_NOTIFY,
1093 1.1.1.4 christos AeNotifyHandler1, ACPI_CAST_PTR (void, 0x01234567));
1094 1.1.1.4 christos
1095 1.1.1.4 christos Status = AcpiInstallNotifyHandler (Handle, ACPI_SYSTEM_NOTIFY,
1096 1.1.1.4 christos AeNotifyHandler2, ACPI_CAST_PTR (void, 0x89ABCDEF));
1097 1.1.1.4 christos }
1098 1.1.1.4 christos
1099 1.1.1.2 jruoho /*
1100 1.1.1.2 jruoho * Install handlers that will override the default handlers for some of
1101 1.1.1.2 jruoho * the space IDs.
1102 1.1.1.2 jruoho */
1103 1.1.1.2 jruoho for (i = 0; i < ACPI_ARRAY_LENGTH (DefaultSpaceIdList); i++)
1104 1.1 jruoho {
1105 1.1.1.2 jruoho /* Install handler at the root object */
1106 1.1 jruoho
1107 1.1.1.4 christos Status = AcpiInstallAddressSpaceHandler (ACPI_ROOT_OBJECT,
1108 1.1.1.2 jruoho DefaultSpaceIdList[i], AeRegionHandler,
1109 1.1.1.4 christos AeRegionInit, &AeMyContext);
1110 1.1 jruoho if (ACPI_FAILURE (Status))
1111 1.1 jruoho {
1112 1.1 jruoho ACPI_EXCEPTION ((AE_INFO, Status,
1113 1.1.1.2 jruoho "Could not install a default OpRegion handler for %s space(%u)",
1114 1.1.1.2 jruoho AcpiUtGetRegionName ((UINT8) DefaultSpaceIdList[i]),
1115 1.1.1.2 jruoho DefaultSpaceIdList[i]));
1116 1.1 jruoho return (Status);
1117 1.1 jruoho }
1118 1.1 jruoho }
1119 1.1 jruoho
1120 1.1 jruoho /*
1121 1.1 jruoho * Initialize the global Region Handler space
1122 1.1 jruoho * MCW 3/23/00
1123 1.1 jruoho */
1124 1.1 jruoho AeRegions.NumberOfRegions = 0;
1125 1.1 jruoho AeRegions.RegionList = NULL;
1126 1.1.1.2 jruoho return (Status);
1127 1.1 jruoho }
1128 1.1 jruoho
1129 1.1 jruoho
1130 1.1 jruoho /******************************************************************************
1131 1.1 jruoho *
1132 1.1 jruoho * FUNCTION: AeRegionHandler
1133 1.1 jruoho *
1134 1.1 jruoho * PARAMETERS: Standard region handler parameters
1135 1.1 jruoho *
1136 1.1 jruoho * RETURN: Status
1137 1.1 jruoho *
1138 1.1 jruoho * DESCRIPTION: Test handler - Handles some dummy regions via memory that can
1139 1.1 jruoho * be manipulated in Ring 3. Simulates actual reads and writes.
1140 1.1 jruoho *
1141 1.1 jruoho *****************************************************************************/
1142 1.1 jruoho
1143 1.1 jruoho ACPI_STATUS
1144 1.1 jruoho AeRegionHandler (
1145 1.1 jruoho UINT32 Function,
1146 1.1 jruoho ACPI_PHYSICAL_ADDRESS Address,
1147 1.1 jruoho UINT32 BitWidth,
1148 1.1 jruoho UINT64 *Value,
1149 1.1 jruoho void *HandlerContext,
1150 1.1 jruoho void *RegionContext)
1151 1.1 jruoho {
1152 1.1 jruoho
1153 1.1 jruoho ACPI_OPERAND_OBJECT *RegionObject = ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, RegionContext);
1154 1.1 jruoho UINT8 *Buffer = ACPI_CAST_PTR (UINT8, Value);
1155 1.1 jruoho ACPI_PHYSICAL_ADDRESS BaseAddress;
1156 1.1 jruoho ACPI_SIZE Length;
1157 1.1 jruoho BOOLEAN BufferExists;
1158 1.1 jruoho AE_REGION *RegionElement;
1159 1.1 jruoho void *BufferValue;
1160 1.1 jruoho ACPI_STATUS Status;
1161 1.1 jruoho UINT32 ByteWidth;
1162 1.1 jruoho UINT32 i;
1163 1.1 jruoho UINT8 SpaceId;
1164 1.1.1.4 christos ACPI_CONNECTION_INFO *MyContext;
1165 1.1.1.4 christos UINT32 Value1;
1166 1.1.1.4 christos UINT32 Value2;
1167 1.1.1.4 christos ACPI_RESOURCE *Resource;
1168 1.1 jruoho
1169 1.1 jruoho
1170 1.1 jruoho ACPI_FUNCTION_NAME (AeRegionHandler);
1171 1.1 jruoho
1172 1.1 jruoho /*
1173 1.1 jruoho * If the object is not a region, simply return
1174 1.1 jruoho */
1175 1.1 jruoho if (RegionObject->Region.Type != ACPI_TYPE_REGION)
1176 1.1 jruoho {
1177 1.1.1.2 jruoho return (AE_OK);
1178 1.1 jruoho }
1179 1.1 jruoho
1180 1.1.1.4 christos /* Check that we actually got back our context parameter */
1181 1.1.1.4 christos
1182 1.1.1.4 christos if (HandlerContext != &AeMyContext)
1183 1.1.1.4 christos {
1184 1.1.1.4 christos printf ("Region handler received incorrect context %p, should be %p\n",
1185 1.1.1.4 christos HandlerContext, &AeMyContext);
1186 1.1.1.4 christos }
1187 1.1.1.4 christos
1188 1.1.1.4 christos MyContext = ACPI_CAST_PTR (ACPI_CONNECTION_INFO, HandlerContext);
1189 1.1.1.4 christos
1190 1.1 jruoho /*
1191 1.1.1.4 christos * Find the region's address space and length before searching
1192 1.1.1.4 christos * the linked list.
1193 1.1.1.4 christos */
1194 1.1.1.4 christos BaseAddress = RegionObject->Region.Address;
1195 1.1.1.4 christos Length = (ACPI_SIZE) RegionObject->Region.Length;
1196 1.1.1.4 christos SpaceId = RegionObject->Region.SpaceId;
1197 1.1.1.4 christos
1198 1.1.1.4 christos ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION, "Operation Region request on %s at 0x%X\n",
1199 1.1.1.4 christos AcpiUtGetRegionName (RegionObject->Region.SpaceId),
1200 1.1.1.4 christos (UINT32) Address));
1201 1.1.1.4 christos
1202 1.1.1.4 christos /*
1203 1.1.1.4 christos * Region support can be disabled with the -do option.
1204 1.1 jruoho * We use this to support dynamically loaded tables where we pass a valid
1205 1.1 jruoho * address to the AML.
1206 1.1 jruoho */
1207 1.1 jruoho if (AcpiGbl_DbOpt_NoRegionSupport)
1208 1.1 jruoho {
1209 1.1 jruoho BufferValue = ACPI_TO_POINTER (Address);
1210 1.1 jruoho ByteWidth = (BitWidth / 8);
1211 1.1 jruoho
1212 1.1 jruoho if (BitWidth % 8)
1213 1.1 jruoho {
1214 1.1 jruoho ByteWidth += 1;
1215 1.1 jruoho }
1216 1.1 jruoho goto DoFunction;
1217 1.1 jruoho }
1218 1.1 jruoho
1219 1.1 jruoho switch (SpaceId)
1220 1.1 jruoho {
1221 1.1 jruoho case ACPI_ADR_SPACE_SYSTEM_IO:
1222 1.1 jruoho /*
1223 1.1 jruoho * For I/O space, exercise the port validation
1224 1.1.1.4 christos * Note: ReadPort currently always returns all ones, length=BitLength
1225 1.1 jruoho */
1226 1.1 jruoho switch (Function & ACPI_IO_MASK)
1227 1.1 jruoho {
1228 1.1 jruoho case ACPI_READ:
1229 1.1.1.4 christos
1230 1.1.1.4 christos if (BitWidth == 64)
1231 1.1.1.4 christos {
1232 1.1.1.4 christos /* Split the 64-bit request into two 32-bit requests */
1233 1.1.1.4 christos
1234 1.1.1.4 christos Status = AcpiHwReadPort (Address, &Value1, 32);
1235 1.1.1.4 christos AE_CHECK_OK (AcpiHwReadPort, Status);
1236 1.1.1.4 christos Status = AcpiHwReadPort (Address+4, &Value2, 32);
1237 1.1.1.4 christos AE_CHECK_OK (AcpiHwReadPort, Status);
1238 1.1.1.4 christos
1239 1.1.1.4 christos *Value = Value1 | ((UINT64) Value2 << 32);
1240 1.1.1.4 christos }
1241 1.1.1.4 christos else
1242 1.1.1.4 christos {
1243 1.1.1.4 christos Status = AcpiHwReadPort (Address, &Value1, BitWidth);
1244 1.1.1.4 christos AE_CHECK_OK (AcpiHwReadPort, Status);
1245 1.1.1.4 christos *Value = (UINT64) Value1;
1246 1.1.1.4 christos }
1247 1.1 jruoho break;
1248 1.1 jruoho
1249 1.1 jruoho case ACPI_WRITE:
1250 1.1.1.4 christos
1251 1.1.1.4 christos if (BitWidth == 64)
1252 1.1.1.4 christos {
1253 1.1.1.4 christos /* Split the 64-bit request into two 32-bit requests */
1254 1.1.1.4 christos
1255 1.1.1.4 christos Status = AcpiHwWritePort (Address, ACPI_LODWORD (*Value), 32);
1256 1.1.1.4 christos AE_CHECK_OK (AcpiHwWritePort, Status);
1257 1.1.1.4 christos Status = AcpiHwWritePort (Address+4, ACPI_HIDWORD (*Value), 32);
1258 1.1.1.4 christos AE_CHECK_OK (AcpiHwWritePort, Status);
1259 1.1.1.4 christos }
1260 1.1.1.4 christos else
1261 1.1.1.4 christos {
1262 1.1.1.4 christos Status = AcpiHwWritePort (Address, (UINT32) *Value, BitWidth);
1263 1.1.1.4 christos AE_CHECK_OK (AcpiHwWritePort, Status);
1264 1.1.1.4 christos }
1265 1.1 jruoho break;
1266 1.1 jruoho
1267 1.1 jruoho default:
1268 1.1.1.4 christos
1269 1.1 jruoho Status = AE_BAD_PARAMETER;
1270 1.1 jruoho break;
1271 1.1 jruoho }
1272 1.1 jruoho
1273 1.1 jruoho if (ACPI_FAILURE (Status))
1274 1.1 jruoho {
1275 1.1 jruoho return (Status);
1276 1.1 jruoho }
1277 1.1 jruoho
1278 1.1 jruoho /* Now go ahead and simulate the hardware */
1279 1.1 jruoho break;
1280 1.1 jruoho
1281 1.1.1.4 christos /*
1282 1.1.1.4 christos * SMBus and GenericSerialBus support the various bidirectional
1283 1.1.1.4 christos * protocols.
1284 1.1.1.4 christos */
1285 1.1 jruoho case ACPI_ADR_SPACE_SMBUS:
1286 1.1.1.4 christos case ACPI_ADR_SPACE_GSBUS: /* ACPI 5.0 */
1287 1.1 jruoho
1288 1.1 jruoho Length = 0;
1289 1.1 jruoho
1290 1.1 jruoho switch (Function & ACPI_IO_MASK)
1291 1.1 jruoho {
1292 1.1 jruoho case ACPI_READ:
1293 1.1.1.4 christos
1294 1.1 jruoho switch (Function >> 16)
1295 1.1 jruoho {
1296 1.1.1.4 christos case AML_FIELD_ATTRIB_QUICK:
1297 1.1.1.4 christos case AML_FIELD_ATTRIB_SEND_RCV:
1298 1.1.1.4 christos case AML_FIELD_ATTRIB_BYTE:
1299 1.1.1.4 christos
1300 1.1 jruoho Length = 1;
1301 1.1 jruoho break;
1302 1.1 jruoho
1303 1.1.1.4 christos case AML_FIELD_ATTRIB_WORD:
1304 1.1.1.4 christos case AML_FIELD_ATTRIB_WORD_CALL:
1305 1.1.1.4 christos
1306 1.1 jruoho Length = 2;
1307 1.1 jruoho break;
1308 1.1 jruoho
1309 1.1.1.4 christos case AML_FIELD_ATTRIB_BLOCK:
1310 1.1.1.4 christos case AML_FIELD_ATTRIB_BLOCK_CALL:
1311 1.1.1.4 christos
1312 1.1 jruoho Length = 32;
1313 1.1 jruoho break;
1314 1.1 jruoho
1315 1.1.1.4 christos case AML_FIELD_ATTRIB_MULTIBYTE:
1316 1.1.1.4 christos case AML_FIELD_ATTRIB_RAW_BYTES:
1317 1.1.1.4 christos case AML_FIELD_ATTRIB_RAW_PROCESS:
1318 1.1.1.4 christos
1319 1.1.1.4 christos /* (-2) for status/length */
1320 1.1.1.4 christos Length = MyContext->AccessLength - 2;
1321 1.1.1.4 christos break;
1322 1.1.1.4 christos
1323 1.1 jruoho default:
1324 1.1.1.4 christos
1325 1.1 jruoho break;
1326 1.1 jruoho }
1327 1.1 jruoho break;
1328 1.1 jruoho
1329 1.1 jruoho case ACPI_WRITE:
1330 1.1.1.4 christos
1331 1.1 jruoho switch (Function >> 16)
1332 1.1 jruoho {
1333 1.1.1.4 christos case AML_FIELD_ATTRIB_QUICK:
1334 1.1.1.4 christos case AML_FIELD_ATTRIB_SEND_RCV:
1335 1.1.1.4 christos case AML_FIELD_ATTRIB_BYTE:
1336 1.1.1.4 christos case AML_FIELD_ATTRIB_WORD:
1337 1.1.1.4 christos case AML_FIELD_ATTRIB_BLOCK:
1338 1.1.1.4 christos
1339 1.1 jruoho Length = 0;
1340 1.1 jruoho break;
1341 1.1 jruoho
1342 1.1.1.4 christos case AML_FIELD_ATTRIB_WORD_CALL:
1343 1.1 jruoho Length = 2;
1344 1.1 jruoho break;
1345 1.1 jruoho
1346 1.1.1.4 christos case AML_FIELD_ATTRIB_BLOCK_CALL:
1347 1.1 jruoho Length = 32;
1348 1.1 jruoho break;
1349 1.1 jruoho
1350 1.1.1.4 christos case AML_FIELD_ATTRIB_MULTIBYTE:
1351 1.1.1.4 christos case AML_FIELD_ATTRIB_RAW_BYTES:
1352 1.1.1.4 christos case AML_FIELD_ATTRIB_RAW_PROCESS:
1353 1.1.1.4 christos
1354 1.1.1.4 christos /* (-2) for status/length */
1355 1.1.1.4 christos Length = MyContext->AccessLength - 2;
1356 1.1.1.4 christos break;
1357 1.1.1.4 christos
1358 1.1 jruoho default:
1359 1.1.1.4 christos
1360 1.1 jruoho break;
1361 1.1 jruoho }
1362 1.1 jruoho break;
1363 1.1 jruoho
1364 1.1 jruoho default:
1365 1.1.1.4 christos
1366 1.1 jruoho break;
1367 1.1 jruoho }
1368 1.1 jruoho
1369 1.1.1.4 christos if (AcpiGbl_DisplayRegionAccess)
1370 1.1.1.4 christos {
1371 1.1.1.4 christos AcpiOsPrintf ("AcpiExec: %s "
1372 1.1.1.4 christos "%s: Attr %X Addr %.4X BaseAddr %.4X Len %.2X Width %X BufLen %X",
1373 1.1.1.4 christos AcpiUtGetRegionName (SpaceId),
1374 1.1.1.4 christos (Function & ACPI_IO_MASK) ? "Write" : "Read ",
1375 1.1.1.4 christos (UINT32) (Function >> 16),
1376 1.1.1.4 christos (UINT32) Address, (UINT32) BaseAddress,
1377 1.1.1.4 christos Length, BitWidth, Buffer[1]);
1378 1.1.1.4 christos
1379 1.1.1.4 christos /* GenericSerialBus has a Connection() parameter */
1380 1.1.1.4 christos
1381 1.1.1.4 christos if (SpaceId == ACPI_ADR_SPACE_GSBUS)
1382 1.1.1.4 christos {
1383 1.1.1.4 christos Status = AcpiBufferToResource (MyContext->Connection,
1384 1.1.1.4 christos MyContext->Length, &Resource);
1385 1.1.1.4 christos
1386 1.1.1.4 christos AcpiOsPrintf (" [AccLen %.2X Conn %p]",
1387 1.1.1.4 christos MyContext->AccessLength, MyContext->Connection);
1388 1.1.1.4 christos }
1389 1.1.1.4 christos AcpiOsPrintf ("\n");
1390 1.1.1.4 christos }
1391 1.1.1.4 christos
1392 1.1.1.4 christos /* Setup the return buffer. Note: ASLTS depends on these fill values */
1393 1.1.1.4 christos
1394 1.1 jruoho for (i = 0; i < Length; i++)
1395 1.1 jruoho {
1396 1.1 jruoho Buffer[i+2] = (UINT8) (0xA0 + i);
1397 1.1 jruoho }
1398 1.1 jruoho
1399 1.1 jruoho Buffer[0] = 0x7A;
1400 1.1 jruoho Buffer[1] = (UINT8) Length;
1401 1.1 jruoho return (AE_OK);
1402 1.1 jruoho
1403 1.1 jruoho
1404 1.1 jruoho case ACPI_ADR_SPACE_IPMI: /* ACPI 4.0 */
1405 1.1 jruoho
1406 1.1.1.4 christos if (AcpiGbl_DisplayRegionAccess)
1407 1.1.1.4 christos {
1408 1.1.1.4 christos AcpiOsPrintf ("AcpiExec: IPMI "
1409 1.1.1.4 christos "%s: Attr %X Addr %.4X BaseAddr %.4X Len %.2X Width %X BufLen %X\n",
1410 1.1.1.4 christos (Function & ACPI_IO_MASK) ? "Write" : "Read ",
1411 1.1.1.4 christos (UINT32) (Function >> 16), (UINT32) Address, (UINT32) BaseAddress,
1412 1.1.1.4 christos Length, BitWidth, Buffer[1]);
1413 1.1.1.4 christos }
1414 1.1 jruoho
1415 1.1 jruoho /*
1416 1.1 jruoho * Regardless of a READ or WRITE, this handler is passed a 66-byte
1417 1.1 jruoho * buffer in which to return the IPMI status/length/data.
1418 1.1 jruoho *
1419 1.1 jruoho * Return some example data to show use of the bidirectional buffer
1420 1.1 jruoho */
1421 1.1 jruoho Buffer[0] = 0; /* Status byte */
1422 1.1 jruoho Buffer[1] = 64; /* Return buffer data length */
1423 1.1 jruoho Buffer[2] = 0; /* Completion code */
1424 1.1.1.4 christos Buffer[3] = 0; /* Reserved */
1425 1.1.1.4 christos
1426 1.1.1.4 christos /*
1427 1.1.1.4 christos * Fill the 66-byte buffer with the return data.
1428 1.1.1.4 christos * Note: ASLTS depends on these fill values.
1429 1.1.1.4 christos */
1430 1.1.1.4 christos for (i = 4; i < 66; i++)
1431 1.1.1.4 christos {
1432 1.1.1.4 christos Buffer[i] = (UINT8) (i);
1433 1.1.1.4 christos }
1434 1.1 jruoho return (AE_OK);
1435 1.1 jruoho
1436 1.1 jruoho default:
1437 1.1 jruoho break;
1438 1.1 jruoho }
1439 1.1 jruoho
1440 1.1 jruoho /*
1441 1.1 jruoho * Search through the linked list for this region's buffer
1442 1.1 jruoho */
1443 1.1 jruoho BufferExists = FALSE;
1444 1.1 jruoho RegionElement = AeRegions.RegionList;
1445 1.1 jruoho
1446 1.1 jruoho if (AeRegions.NumberOfRegions)
1447 1.1 jruoho {
1448 1.1 jruoho while (!BufferExists && RegionElement)
1449 1.1 jruoho {
1450 1.1 jruoho if (RegionElement->Address == BaseAddress &&
1451 1.1 jruoho RegionElement->Length == Length &&
1452 1.1 jruoho RegionElement->SpaceId == SpaceId)
1453 1.1 jruoho {
1454 1.1 jruoho BufferExists = TRUE;
1455 1.1 jruoho }
1456 1.1 jruoho else
1457 1.1 jruoho {
1458 1.1 jruoho RegionElement = RegionElement->NextRegion;
1459 1.1 jruoho }
1460 1.1 jruoho }
1461 1.1 jruoho }
1462 1.1 jruoho
1463 1.1 jruoho /*
1464 1.1 jruoho * If the Region buffer does not exist, create it now
1465 1.1 jruoho */
1466 1.1 jruoho if (!BufferExists)
1467 1.1 jruoho {
1468 1.1 jruoho /*
1469 1.1 jruoho * Do the memory allocations first
1470 1.1 jruoho */
1471 1.1 jruoho RegionElement = AcpiOsAllocate (sizeof (AE_REGION));
1472 1.1 jruoho if (!RegionElement)
1473 1.1 jruoho {
1474 1.1.1.2 jruoho return (AE_NO_MEMORY);
1475 1.1 jruoho }
1476 1.1 jruoho
1477 1.1 jruoho RegionElement->Buffer = AcpiOsAllocate (Length);
1478 1.1 jruoho if (!RegionElement->Buffer)
1479 1.1 jruoho {
1480 1.1 jruoho AcpiOsFree (RegionElement);
1481 1.1.1.2 jruoho return (AE_NO_MEMORY);
1482 1.1 jruoho }
1483 1.1 jruoho
1484 1.1 jruoho /* Initialize the region with the default fill value */
1485 1.1 jruoho
1486 1.1 jruoho ACPI_MEMSET (RegionElement->Buffer, AcpiGbl_RegionFillValue, Length);
1487 1.1 jruoho
1488 1.1 jruoho RegionElement->Address = BaseAddress;
1489 1.1 jruoho RegionElement->Length = Length;
1490 1.1 jruoho RegionElement->SpaceId = SpaceId;
1491 1.1 jruoho RegionElement->NextRegion = NULL;
1492 1.1 jruoho
1493 1.1 jruoho /*
1494 1.1 jruoho * Increment the number of regions and put this one
1495 1.1 jruoho * at the head of the list as it will probably get accessed
1496 1.1 jruoho * more often anyway.
1497 1.1 jruoho */
1498 1.1 jruoho AeRegions.NumberOfRegions += 1;
1499 1.1 jruoho
1500 1.1 jruoho if (AeRegions.RegionList)
1501 1.1 jruoho {
1502 1.1 jruoho RegionElement->NextRegion = AeRegions.RegionList;
1503 1.1 jruoho }
1504 1.1 jruoho
1505 1.1 jruoho AeRegions.RegionList = RegionElement;
1506 1.1 jruoho }
1507 1.1 jruoho
1508 1.1 jruoho /*
1509 1.1 jruoho * Calculate the size of the memory copy
1510 1.1 jruoho */
1511 1.1 jruoho ByteWidth = (BitWidth / 8);
1512 1.1 jruoho
1513 1.1 jruoho if (BitWidth % 8)
1514 1.1 jruoho {
1515 1.1 jruoho ByteWidth += 1;
1516 1.1 jruoho }
1517 1.1 jruoho
1518 1.1 jruoho /*
1519 1.1 jruoho * The buffer exists and is pointed to by RegionElement.
1520 1.1 jruoho * We now need to verify the request is valid and perform the operation.
1521 1.1 jruoho *
1522 1.1 jruoho * NOTE: RegionElement->Length is in bytes, therefore it we compare against
1523 1.1 jruoho * ByteWidth (see above)
1524 1.1 jruoho */
1525 1.1 jruoho if (((UINT64) Address + ByteWidth) >
1526 1.1 jruoho ((UINT64)(RegionElement->Address) + RegionElement->Length))
1527 1.1 jruoho {
1528 1.1 jruoho ACPI_WARNING ((AE_INFO,
1529 1.1 jruoho "Request on [%4.4s] is beyond region limit Req-0x%X+0x%X, Base=0x%X, Len-0x%X",
1530 1.1 jruoho (RegionObject->Region.Node)->Name.Ascii, (UINT32) Address,
1531 1.1 jruoho ByteWidth, (UINT32)(RegionElement->Address),
1532 1.1 jruoho RegionElement->Length));
1533 1.1 jruoho
1534 1.1.1.2 jruoho return (AE_AML_REGION_LIMIT);
1535 1.1 jruoho }
1536 1.1 jruoho
1537 1.1 jruoho /*
1538 1.1 jruoho * Get BufferValue to point to the "address" in the buffer
1539 1.1 jruoho */
1540 1.1 jruoho BufferValue = ((UINT8 *) RegionElement->Buffer +
1541 1.1 jruoho ((UINT64) Address - (UINT64) RegionElement->Address));
1542 1.1 jruoho
1543 1.1 jruoho DoFunction:
1544 1.1 jruoho /*
1545 1.1 jruoho * Perform a read or write to the buffer space
1546 1.1 jruoho */
1547 1.1 jruoho switch (Function)
1548 1.1 jruoho {
1549 1.1 jruoho case ACPI_READ:
1550 1.1 jruoho /*
1551 1.1 jruoho * Set the pointer Value to whatever is in the buffer
1552 1.1 jruoho */
1553 1.1 jruoho ACPI_MEMCPY (Value, BufferValue, ByteWidth);
1554 1.1 jruoho break;
1555 1.1 jruoho
1556 1.1 jruoho case ACPI_WRITE:
1557 1.1 jruoho /*
1558 1.1 jruoho * Write the contents of Value to the buffer
1559 1.1 jruoho */
1560 1.1 jruoho ACPI_MEMCPY (BufferValue, Value, ByteWidth);
1561 1.1 jruoho break;
1562 1.1 jruoho
1563 1.1 jruoho default:
1564 1.1.1.4 christos
1565 1.1.1.2 jruoho return (AE_BAD_PARAMETER);
1566 1.1 jruoho }
1567 1.1.1.2 jruoho
1568 1.1.1.4 christos if (AcpiGbl_DisplayRegionAccess)
1569 1.1.1.4 christos {
1570 1.1.1.4 christos switch (SpaceId)
1571 1.1.1.4 christos {
1572 1.1.1.4 christos case ACPI_ADR_SPACE_SYSTEM_MEMORY:
1573 1.1.1.4 christos
1574 1.1.1.4 christos AcpiOsPrintf ("AcpiExec: SystemMemory "
1575 1.1.1.4 christos "%s: Val %.8X Addr %.4X Width %X [REGION: BaseAddr %.4X Len %.2X]\n",
1576 1.1.1.4 christos (Function & ACPI_IO_MASK) ? "Write" : "Read ",
1577 1.1.1.4 christos (UINT32) *Value, (UINT32) Address, BitWidth, (UINT32) BaseAddress, Length);
1578 1.1.1.4 christos break;
1579 1.1.1.4 christos
1580 1.1.1.4 christos case ACPI_ADR_SPACE_GPIO: /* ACPI 5.0 */
1581 1.1 jruoho
1582 1.1.1.4 christos /* This space is required to always be ByteAcc */
1583 1.1 jruoho
1584 1.1.1.4 christos Status = AcpiBufferToResource (MyContext->Connection,
1585 1.1.1.4 christos MyContext->Length, &Resource);
1586 1.1.1.4 christos
1587 1.1.1.4 christos AcpiOsPrintf ("AcpiExec: GeneralPurposeIo "
1588 1.1.1.4 christos "%s: Val %.8X Addr %.4X BaseAddr %.4X Len %.2X Width %X AccLen %.2X Conn %p\n",
1589 1.1.1.4 christos (Function & ACPI_IO_MASK) ? "Write" : "Read ", (UINT32) *Value,
1590 1.1.1.4 christos (UINT32) Address, (UINT32) BaseAddress, Length, BitWidth,
1591 1.1.1.4 christos MyContext->AccessLength, MyContext->Connection);
1592 1.1.1.4 christos break;
1593 1.1.1.4 christos
1594 1.1.1.4 christos default:
1595 1.1.1.4 christos
1596 1.1.1.4 christos break;
1597 1.1.1.4 christos }
1598 1.1.1.4 christos }
1599 1.1.1.4 christos
1600 1.1.1.4 christos return (AE_OK);
1601 1.1.1.4 christos }
1602