1 /******************************************************************************
2  *
3  * Module Name: aeexec - Argument testing for control method execution.
4  *                       Also some other miscellaneous tests.
5  *
6  *****************************************************************************/
7 
8 /******************************************************************************
9  *
10  * 1. Copyright Notice
11  *
12  * Some or all of this work - Copyright (c) 1999 - 2023, Intel Corp.
13  * All rights reserved.
14  *
15  * 2. License
16  *
17  * 2.1. This is your license from Intel Corp. under its intellectual property
18  * rights. You may have additional license terms from the party that provided
19  * you this software, covering your right to use that party's intellectual
20  * property rights.
21  *
22  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
23  * copy of the source code appearing in this file ("Covered Code") an
24  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
25  * base code distributed originally by Intel ("Original Intel Code") to copy,
26  * make derivatives, distribute, use and display any portion of the Covered
27  * Code in any form, with the right to sublicense such rights; and
28  *
29  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
30  * license (with the right to sublicense), under only those claims of Intel
31  * patents that are infringed by the Original Intel Code, to make, use, sell,
32  * offer to sell, and import the Covered Code and derivative works thereof
33  * solely to the minimum extent necessary to exercise the above copyright
34  * license, and in no event shall the patent license extend to any additions
35  * to or modifications of the Original Intel Code. No other license or right
36  * is granted directly or by implication, estoppel or otherwise;
37  *
38  * The above copyright and patent license is granted only if the following
39  * conditions are met:
40  *
41  * 3. Conditions
42  *
43  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
44  * Redistribution of source code of any substantial portion of the Covered
45  * Code or modification with rights to further distribute source must include
46  * the above Copyright Notice, the above License, this list of Conditions,
47  * and the following Disclaimer and Export Compliance provision. In addition,
48  * Licensee must cause all Covered Code to which Licensee contributes to
49  * contain a file documenting the changes Licensee made to create that Covered
50  * Code and the date of any change. Licensee must include in that file the
51  * documentation of any changes made by any predecessor Licensee. Licensee
52  * must include a prominent statement that the modification is derived,
53  * directly or indirectly, from Original Intel Code.
54  *
55  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
56  * Redistribution of source code of any substantial portion of the Covered
57  * Code or modification without rights to further distribute source must
58  * include the following Disclaimer and Export Compliance provision in the
59  * documentation and/or other materials provided with distribution. In
60  * addition, Licensee may not authorize further sublicense of source of any
61  * portion of the Covered Code, and must include terms to the effect that the
62  * license from Licensee to its licensee is limited to the intellectual
63  * property embodied in the software Licensee provides to its licensee, and
64  * not to intellectual property embodied in modifications its licensee may
65  * make.
66  *
67  * 3.3. Redistribution of Executable. Redistribution in executable form of any
68  * substantial portion of the Covered Code or modification must reproduce the
69  * above Copyright Notice, and the following Disclaimer and Export Compliance
70  * provision in the documentation and/or other materials provided with the
71  * distribution.
72  *
73  * 3.4. Intel retains all right, title, and interest in and to the Original
74  * Intel Code.
75  *
76  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
77  * Intel shall be used in advertising or otherwise to promote the sale, use or
78  * other dealings in products derived from or relating to the Covered Code
79  * without prior written authorization from Intel.
80  *
81  * 4. Disclaimer and Export Compliance
82  *
83  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
84  * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
85  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
86  * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
87  * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
88  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
89  * PARTICULAR PURPOSE.
90  *
91  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
92  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
93  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
94  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
95  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
96  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
97  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
98  * LIMITED REMEDY.
99  *
100  * 4.3. Licensee shall not export, either directly or indirectly, any of this
101  * software or system incorporating such software without first obtaining any
102  * required license or other approval from the U. S. Department of Commerce or
103  * any other agency or department of the United States Government. In the
104  * event Licensee exports any such software from the United States or
105  * re-exports any such software from a foreign destination, Licensee shall
106  * ensure that the distribution and export/re-export of the software is in
107  * compliance with all laws, regulations, orders, or other restrictions of the
108  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
109  * any of its subsidiaries will export/re-export any technical data, process,
110  * software, or service, directly or indirectly, to any country for which the
111  * United States government or any agency thereof requires an export license,
112  * other governmental approval, or letter of assurance, without first obtaining
113  * such license, approval or letter.
114  *
115  *****************************************************************************
116  *
117  * Alternatively, you may choose to be licensed under the terms of the
118  * following license:
119  *
120  * Redistribution and use in source and binary forms, with or without
121  * modification, are permitted provided that the following conditions
122  * are met:
123  * 1. Redistributions of source code must retain the above copyright
124  *    notice, this list of conditions, and the following disclaimer,
125  *    without modification.
126  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
127  *    substantially similar to the "NO WARRANTY" disclaimer below
128  *    ("Disclaimer") and any redistribution must be conditioned upon
129  *    including a substantially similar Disclaimer requirement for further
130  *    binary redistribution.
131  * 3. Neither the names of the above-listed copyright holders nor the names
132  *    of any contributors may be used to endorse or promote products derived
133  *    from this software without specific prior written permission.
134  *
135  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
136  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
137  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
138  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
139  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
140  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
141  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
142  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
143  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
144  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
145  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
146  *
147  * Alternatively, you may choose to be licensed under the terms of the
148  * GNU General Public License ("GPL") version 2 as published by the Free
149  * Software Foundation.
150  *
151  *****************************************************************************/
152 
153 #include "aecommon.h"
154 
155 #define _COMPONENT          ACPI_TOOLS
156         ACPI_MODULE_NAME    ("aeexec")
157 
158 
159 /******************************************************************************
160  *
161  * FUNCTION:    AeSetupConfiguration
162  *
163  * PARAMETERS:  RegionAddr          - Address for an ACPI table to be loaded
164  *                                    dynamically. Test purposes only.
165  *
166  * RETURN:      Status
167  *
168  * DESCRIPTION: Call AML _CFG configuration control method
169  *
170  *****************************************************************************/
171 
172 ACPI_STATUS
AeSetupConfiguration(void * RegionAddr)173 AeSetupConfiguration (
174     void                    *RegionAddr)
175 {
176     ACPI_OBJECT_LIST        ArgList;
177     ACPI_OBJECT             Arg[3];
178 
179 
180     /*
181      * Invoke _CFG method if present
182      */
183     ArgList.Count = 1;
184     ArgList.Pointer = Arg;
185 
186     Arg[0].Type = ACPI_TYPE_INTEGER;
187     Arg[0].Integer.Value = ACPI_TO_INTEGER (RegionAddr);
188 
189     (void) AcpiEvaluateObject (NULL, "\\_CFG", &ArgList, NULL);
190     return (AE_OK);
191 }
192 
193 
194 #if (!ACPI_REDUCED_HARDWARE)
195 /******************************************************************************
196  *
197  * FUNCTION:    AfInstallGpeBlock
198  *
199  * PARAMETERS:  None
200  *
201  * RETURN:      None
202  *
203  * DESCRIPTION: Test GPE block device initialization. Requires test ASL with
204  *              A \GPE2 device.
205  *
206  *****************************************************************************/
207 
208 void
AfInstallGpeBlock(void)209 AfInstallGpeBlock (
210     void)
211 {
212     ACPI_STATUS                 Status;
213     ACPI_HANDLE                 Handle;
214     ACPI_GENERIC_ADDRESS        BlockAddress;
215     ACPI_HANDLE                 GpeDevice;
216     ACPI_OBJECT_TYPE            Type;
217 
218 
219     /* _GPE should always exist */
220 
221     Status = AcpiGetHandle (NULL, "\\_GPE", &Handle);
222     ACPI_CHECK_OK (AcpiGetHandle, Status);
223     if (ACPI_FAILURE (Status))
224     {
225         return;
226     }
227 
228     memset (&BlockAddress, 0, sizeof (ACPI_GENERIC_ADDRESS));
229     BlockAddress.SpaceId = ACPI_ADR_SPACE_SYSTEM_MEMORY;
230     BlockAddress.Address = 0x76540000;
231 
232     /* Attempt to install a GPE block on GPE2 (if present) */
233 
234     Status = AcpiGetHandle (NULL, "\\GPE2", &Handle);
235     if (ACPI_SUCCESS (Status))
236     {
237         Status = AcpiGetType (Handle, &Type);
238         if (ACPI_FAILURE (Status) ||
239            (Type != ACPI_TYPE_DEVICE))
240         {
241             return;
242         }
243 
244         Status = AcpiInstallGpeBlock (Handle, &BlockAddress, 7, 8);
245         ACPI_CHECK_OK (AcpiInstallGpeBlock, Status);
246 
247         Status = AcpiInstallGpeHandler (Handle, 8,
248             ACPI_GPE_LEVEL_TRIGGERED, AeGpeHandler, NULL);
249         ACPI_CHECK_OK (AcpiInstallGpeHandler, Status);
250 
251         Status = AcpiEnableGpe (Handle, 8);
252         ACPI_CHECK_OK (AcpiEnableGpe, Status);
253 
254         Status = AcpiGetGpeDevice (0x30, &GpeDevice);
255         ACPI_CHECK_OK (AcpiGetGpeDevice, Status);
256 
257         Status = AcpiGetGpeDevice (0x42, &GpeDevice);
258         ACPI_CHECK_OK (AcpiGetGpeDevice, Status);
259 
260         Status = AcpiGetGpeDevice (AcpiCurrentGpeCount-1, &GpeDevice);
261         ACPI_CHECK_OK (AcpiGetGpeDevice, Status);
262 
263         Status = AcpiGetGpeDevice (AcpiCurrentGpeCount, &GpeDevice);
264         ACPI_CHECK_STATUS (AcpiGetGpeDevice, Status, AE_NOT_EXIST);
265 
266         Status = AcpiRemoveGpeHandler (Handle, 8, AeGpeHandler);
267         ACPI_CHECK_OK (AcpiRemoveGpeHandler, Status);
268     }
269 
270     /* Attempt to install a GPE block on GPE3 (if present) */
271 
272     Status = AcpiGetHandle (NULL, "\\GPE3", &Handle);
273     if (ACPI_SUCCESS (Status))
274     {
275         Status = AcpiGetType (Handle, &Type);
276         if (ACPI_FAILURE (Status) ||
277            (Type != ACPI_TYPE_DEVICE))
278         {
279             return;
280         }
281 
282         Status = AcpiInstallGpeBlock (Handle, &BlockAddress, 8, 11);
283         ACPI_CHECK_OK (AcpiInstallGpeBlock, Status);
284     }
285 }
286 #endif /* !ACPI_REDUCED_HARDWARE */
287 
288 
289 /******************************************************************************
290  *
291  * FUNCTION:    AeTestBufferArgument
292  *
293  * DESCRIPTION: Test using a Buffer object as a method argument
294  *
295  *****************************************************************************/
296 
297 void
AeTestBufferArgument(void)298 AeTestBufferArgument (
299     void)
300 {
301     ACPI_OBJECT_LIST        Params;
302     ACPI_OBJECT             BufArg;
303     UINT8                   Buffer[] =
304     {
305         0,0,0,0,
306         4,0,0,0,
307         1,2,3,4
308     };
309 
310 
311     BufArg.Type = ACPI_TYPE_BUFFER;
312     BufArg.Buffer.Length = 12;
313     BufArg.Buffer.Pointer = Buffer;
314 
315     Params.Count = 1;
316     Params.Pointer = &BufArg;
317 
318     (void) AcpiEvaluateObject (NULL, "\\BUF", &Params, NULL);
319 }
320 
321 
322 static ACPI_OBJECT                 PkgArg;
323 static ACPI_OBJECT                 PkgElements[5];
324 static ACPI_OBJECT                 Pkg2Elements[5];
325 static ACPI_OBJECT_LIST            Params;
326 
327 /******************************************************************************
328  *
329  * FUNCTION:    AeTestPackageArgument
330  *
331  * DESCRIPTION: Test using a Package object as a method argument
332  *
333  *****************************************************************************/
334 
335 void
AeTestPackageArgument(void)336 AeTestPackageArgument (
337     void)
338 {
339 
340     /* Main package */
341 
342     PkgArg.Type = ACPI_TYPE_PACKAGE;
343     PkgArg.Package.Count = 4;
344     PkgArg.Package.Elements = PkgElements;
345 
346     /* Main package elements */
347 
348     PkgElements[0].Type = ACPI_TYPE_INTEGER;
349     PkgElements[0].Integer.Value = 0x22228888;
350 
351     PkgElements[1].Type = ACPI_TYPE_STRING;
352     PkgElements[1].String.Length = sizeof ("Top-level package");
353     PkgElements[1].String.Pointer = "Top-level package";
354 
355     PkgElements[2].Type = ACPI_TYPE_BUFFER;
356     PkgElements[2].Buffer.Length = sizeof ("XXXX");
357     PkgElements[2].Buffer.Pointer = (UINT8 *) "XXXX";
358 
359     PkgElements[3].Type = ACPI_TYPE_PACKAGE;
360     PkgElements[3].Package.Count = 2;
361     PkgElements[3].Package.Elements = Pkg2Elements;
362 
363     /* Subpackage elements */
364 
365     Pkg2Elements[0].Type = ACPI_TYPE_INTEGER;
366     Pkg2Elements[0].Integer.Value = 0xAAAABBBB;
367 
368     Pkg2Elements[1].Type = ACPI_TYPE_STRING;
369     Pkg2Elements[1].String.Length = sizeof ("Nested Package");
370     Pkg2Elements[1].String.Pointer = "Nested Package";
371 
372     /* Parameter object */
373 
374     Params.Count = 1;
375     Params.Pointer = &PkgArg;
376 
377     (void) AcpiEvaluateObject (NULL, "\\_PKG", &Params, NULL);
378 }
379 
380 
381 /******************************************************************************
382  *
383  * FUNCTION:    AeGetDevices
384  *
385  * DESCRIPTION: Stubbed at this time.
386  *
387  *****************************************************************************/
388 
389 ACPI_STATUS
AeGetDevices(ACPI_HANDLE ObjHandle,UINT32 NestingLevel,void * Context,void ** ReturnValue)390 AeGetDevices (
391     ACPI_HANDLE                     ObjHandle,
392     UINT32                          NestingLevel,
393     void                            *Context,
394     void                            **ReturnValue)
395 {
396 
397     return (AE_OK);
398 }
399 
400 
401 /******************************************************************************
402  *
403  * FUNCTION:    ExecuteOSI
404  *
405  * PARAMETERS:  OsiString           - String passed to _OSI method
406  *              ExpectedResult      - 0 (FALSE) or ACPI_UINT64_MAX (TRUE)
407  *
408  * RETURN:      Status
409  *
410  * DESCRIPTION: Execute the internally implemented (in ACPICA) _OSI method.
411  *
412  *****************************************************************************/
413 
414 ACPI_STATUS
ExecuteOSI(char * OsiString,UINT64 ExpectedResult)415 ExecuteOSI (
416     char                    *OsiString,
417     UINT64                  ExpectedResult)
418 {
419     ACPI_STATUS             Status;
420     ACPI_OBJECT_LIST        ArgList;
421     ACPI_OBJECT             Arg[1];
422     ACPI_BUFFER             ReturnValue;
423     ACPI_OBJECT             *Obj;
424 
425 
426     /* Setup input argument */
427 
428     ArgList.Count = 1;
429     ArgList.Pointer = Arg;
430 
431     Arg[0].Type = ACPI_TYPE_STRING;
432     Arg[0].String.Pointer = OsiString;
433     Arg[0].String.Length = strlen (Arg[0].String.Pointer);
434 
435     /* Ask ACPICA to allocate space for the return object */
436 
437     ReturnValue.Length = ACPI_ALLOCATE_BUFFER;
438 
439     Status = AcpiEvaluateObject (NULL, "\\_OSI", &ArgList, &ReturnValue);
440 
441     if (ACPI_FAILURE (Status))
442     {
443         AcpiOsPrintf (
444             "Could not execute _OSI method, %s\n",
445             AcpiFormatException (Status));
446         return (Status);
447     }
448 
449     Status = AE_ERROR;
450 
451     if (ReturnValue.Length < sizeof (ACPI_OBJECT))
452     {
453         AcpiOsPrintf (
454             "Return value from _OSI method too small, %.8X\n",
455             (UINT32) ReturnValue.Length);
456         goto ErrorExit;
457     }
458 
459     Obj = ReturnValue.Pointer;
460     if (Obj->Type != ACPI_TYPE_INTEGER)
461     {
462         AcpiOsPrintf (
463             "Invalid return type from _OSI method, %.2X\n", Obj->Type);
464         goto ErrorExit;
465     }
466 
467     if (Obj->Integer.Value != ExpectedResult)
468     {
469         AcpiOsPrintf (
470             "Invalid return value from _OSI, expected %8.8X%8.8X found %8.8X%8.8X\n",
471             ACPI_FORMAT_UINT64 (ExpectedResult),
472             ACPI_FORMAT_UINT64 (Obj->Integer.Value));
473         goto ErrorExit;
474     }
475 
476     Status = AE_OK;
477 
478     /* Reset the OSI data */
479 
480     AcpiGbl_OsiData = 0;
481 
482 ErrorExit:
483 
484     /* Free a buffer created via ACPI_ALLOCATE_BUFFER */
485 
486     AcpiOsFree (ReturnValue.Pointer);
487     return (Status);
488 }
489 
490 
491 /******************************************************************************
492  *
493  * FUNCTION:    AeGenericRegisters
494  *
495  * DESCRIPTION: Call the AcpiRead/Write interfaces.
496  *
497  *****************************************************************************/
498 
499 static ACPI_GENERIC_ADDRESS       GenericRegister;
500 
501 void
AeGenericRegisters(void)502 AeGenericRegisters (
503     void)
504 {
505     ACPI_STATUS             Status;
506     UINT64                  Value;
507 
508 
509     GenericRegister.Address = 0x1234;
510     GenericRegister.BitWidth = 64;
511     GenericRegister.BitOffset = 0;
512     GenericRegister.SpaceId = ACPI_ADR_SPACE_SYSTEM_IO;
513 
514     Status = AcpiRead (&Value, &GenericRegister);
515     ACPI_CHECK_OK (AcpiRead, Status);
516 
517     Status = AcpiWrite (Value, &GenericRegister);
518     ACPI_CHECK_OK (AcpiWrite, Status);
519 
520     GenericRegister.Address = 0x12345678;
521     GenericRegister.BitOffset = 0;
522     GenericRegister.SpaceId = ACPI_ADR_SPACE_SYSTEM_MEMORY;
523 
524     Status = AcpiRead (&Value, &GenericRegister);
525     ACPI_CHECK_OK (AcpiRead, Status);
526 
527     Status = AcpiWrite (Value, &GenericRegister);
528     ACPI_CHECK_OK (AcpiWrite, Status);
529 }
530