dbtest.c revision 1.1.1.13 1 1.1 christos /*******************************************************************************
2 1.1 christos *
3 1.1 christos * Module Name: dbtest - Various debug-related tests
4 1.1 christos *
5 1.1 christos ******************************************************************************/
6 1.1 christos
7 1.1.1.13 christos /******************************************************************************
8 1.1.1.13 christos *
9 1.1.1.13 christos * 1. Copyright Notice
10 1.1.1.13 christos *
11 1.1.1.13 christos * Some or all of this work - Copyright (c) 1999 - 2024, Intel Corp.
12 1.1 christos * All rights reserved.
13 1.1 christos *
14 1.1.1.13 christos * 2. License
15 1.1.1.13 christos *
16 1.1.1.13 christos * 2.1. This is your license from Intel Corp. under its intellectual property
17 1.1.1.13 christos * rights. You may have additional license terms from the party that provided
18 1.1.1.13 christos * you this software, covering your right to use that party's intellectual
19 1.1.1.13 christos * property rights.
20 1.1.1.13 christos *
21 1.1.1.13 christos * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22 1.1.1.13 christos * copy of the source code appearing in this file ("Covered Code") an
23 1.1.1.13 christos * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24 1.1.1.13 christos * base code distributed originally by Intel ("Original Intel Code") to copy,
25 1.1.1.13 christos * make derivatives, distribute, use and display any portion of the Covered
26 1.1.1.13 christos * Code in any form, with the right to sublicense such rights; and
27 1.1.1.13 christos *
28 1.1.1.13 christos * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29 1.1.1.13 christos * license (with the right to sublicense), under only those claims of Intel
30 1.1.1.13 christos * patents that are infringed by the Original Intel Code, to make, use, sell,
31 1.1.1.13 christos * offer to sell, and import the Covered Code and derivative works thereof
32 1.1.1.13 christos * solely to the minimum extent necessary to exercise the above copyright
33 1.1.1.13 christos * license, and in no event shall the patent license extend to any additions
34 1.1.1.13 christos * to or modifications of the Original Intel Code. No other license or right
35 1.1.1.13 christos * is granted directly or by implication, estoppel or otherwise;
36 1.1.1.13 christos *
37 1.1.1.13 christos * The above copyright and patent license is granted only if the following
38 1.1.1.13 christos * conditions are met:
39 1.1.1.13 christos *
40 1.1.1.13 christos * 3. Conditions
41 1.1.1.13 christos *
42 1.1.1.13 christos * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43 1.1.1.13 christos * Redistribution of source code of any substantial portion of the Covered
44 1.1.1.13 christos * Code or modification with rights to further distribute source must include
45 1.1.1.13 christos * the above Copyright Notice, the above License, this list of Conditions,
46 1.1.1.13 christos * and the following Disclaimer and Export Compliance provision. In addition,
47 1.1.1.13 christos * Licensee must cause all Covered Code to which Licensee contributes to
48 1.1.1.13 christos * contain a file documenting the changes Licensee made to create that Covered
49 1.1.1.13 christos * Code and the date of any change. Licensee must include in that file the
50 1.1.1.13 christos * documentation of any changes made by any predecessor Licensee. Licensee
51 1.1.1.13 christos * must include a prominent statement that the modification is derived,
52 1.1.1.13 christos * directly or indirectly, from Original Intel Code.
53 1.1.1.13 christos *
54 1.1.1.13 christos * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55 1.1.1.13 christos * Redistribution of source code of any substantial portion of the Covered
56 1.1.1.13 christos * Code or modification without rights to further distribute source must
57 1.1.1.13 christos * include the following Disclaimer and Export Compliance provision in the
58 1.1.1.13 christos * documentation and/or other materials provided with distribution. In
59 1.1.1.13 christos * addition, Licensee may not authorize further sublicense of source of any
60 1.1.1.13 christos * portion of the Covered Code, and must include terms to the effect that the
61 1.1.1.13 christos * license from Licensee to its licensee is limited to the intellectual
62 1.1.1.13 christos * property embodied in the software Licensee provides to its licensee, and
63 1.1.1.13 christos * not to intellectual property embodied in modifications its licensee may
64 1.1.1.13 christos * make.
65 1.1.1.13 christos *
66 1.1.1.13 christos * 3.3. Redistribution of Executable. Redistribution in executable form of any
67 1.1.1.13 christos * substantial portion of the Covered Code or modification must reproduce the
68 1.1.1.13 christos * above Copyright Notice, and the following Disclaimer and Export Compliance
69 1.1.1.13 christos * provision in the documentation and/or other materials provided with the
70 1.1.1.13 christos * distribution.
71 1.1.1.13 christos *
72 1.1.1.13 christos * 3.4. Intel retains all right, title, and interest in and to the Original
73 1.1.1.13 christos * Intel Code.
74 1.1.1.13 christos *
75 1.1.1.13 christos * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76 1.1.1.13 christos * Intel shall be used in advertising or otherwise to promote the sale, use or
77 1.1.1.13 christos * other dealings in products derived from or relating to the Covered Code
78 1.1.1.13 christos * without prior written authorization from Intel.
79 1.1.1.13 christos *
80 1.1.1.13 christos * 4. Disclaimer and Export Compliance
81 1.1.1.13 christos *
82 1.1.1.13 christos * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83 1.1.1.13 christos * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84 1.1.1.13 christos * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85 1.1.1.13 christos * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86 1.1.1.13 christos * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87 1.1.1.13 christos * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
88 1.1.1.13 christos * PARTICULAR PURPOSE.
89 1.1.1.13 christos *
90 1.1.1.13 christos * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91 1.1.1.13 christos * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92 1.1.1.13 christos * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93 1.1.1.13 christos * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94 1.1.1.13 christos * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95 1.1.1.13 christos * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96 1.1.1.13 christos * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
97 1.1.1.13 christos * LIMITED REMEDY.
98 1.1.1.13 christos *
99 1.1.1.13 christos * 4.3. Licensee shall not export, either directly or indirectly, any of this
100 1.1.1.13 christos * software or system incorporating such software without first obtaining any
101 1.1.1.13 christos * required license or other approval from the U. S. Department of Commerce or
102 1.1.1.13 christos * any other agency or department of the United States Government. In the
103 1.1.1.13 christos * event Licensee exports any such software from the United States or
104 1.1.1.13 christos * re-exports any such software from a foreign destination, Licensee shall
105 1.1.1.13 christos * ensure that the distribution and export/re-export of the software is in
106 1.1.1.13 christos * compliance with all laws, regulations, orders, or other restrictions of the
107 1.1.1.13 christos * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108 1.1.1.13 christos * any of its subsidiaries will export/re-export any technical data, process,
109 1.1.1.13 christos * software, or service, directly or indirectly, to any country for which the
110 1.1.1.13 christos * United States government or any agency thereof requires an export license,
111 1.1.1.13 christos * other governmental approval, or letter of assurance, without first obtaining
112 1.1.1.13 christos * such license, approval or letter.
113 1.1.1.13 christos *
114 1.1.1.13 christos *****************************************************************************
115 1.1.1.13 christos *
116 1.1.1.13 christos * Alternatively, you may choose to be licensed under the terms of the
117 1.1.1.13 christos * following license:
118 1.1.1.13 christos *
119 1.1 christos * Redistribution and use in source and binary forms, with or without
120 1.1 christos * modification, are permitted provided that the following conditions
121 1.1 christos * are met:
122 1.1 christos * 1. Redistributions of source code must retain the above copyright
123 1.1 christos * notice, this list of conditions, and the following disclaimer,
124 1.1 christos * without modification.
125 1.1 christos * 2. Redistributions in binary form must reproduce at minimum a disclaimer
126 1.1 christos * substantially similar to the "NO WARRANTY" disclaimer below
127 1.1 christos * ("Disclaimer") and any redistribution must be conditioned upon
128 1.1 christos * including a substantially similar Disclaimer requirement for further
129 1.1 christos * binary redistribution.
130 1.1 christos * 3. Neither the names of the above-listed copyright holders nor the names
131 1.1 christos * of any contributors may be used to endorse or promote products derived
132 1.1 christos * from this software without specific prior written permission.
133 1.1 christos *
134 1.1 christos * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
135 1.1 christos * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136 1.1.1.10 christos * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
137 1.1 christos * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
138 1.1.1.13 christos * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139 1.1.1.13 christos * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
140 1.1.1.13 christos * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141 1.1.1.13 christos * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142 1.1.1.13 christos * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143 1.1.1.13 christos * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
144 1.1.1.13 christos * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
145 1.1.1.13 christos *
146 1.1.1.13 christos * Alternatively, you may choose to be licensed under the terms of the
147 1.1.1.13 christos * GNU General Public License ("GPL") version 2 as published by the Free
148 1.1.1.13 christos * Software Foundation.
149 1.1.1.13 christos *
150 1.1.1.13 christos *****************************************************************************/
151 1.1 christos
152 1.1 christos #include "acpi.h"
153 1.1 christos #include "accommon.h"
154 1.1 christos #include "acdebug.h"
155 1.1 christos #include "acnamesp.h"
156 1.1 christos #include "acpredef.h"
157 1.1.1.8 christos #include "acinterp.h"
158 1.1 christos
159 1.1 christos
160 1.1 christos #define _COMPONENT ACPI_CA_DEBUGGER
161 1.1 christos ACPI_MODULE_NAME ("dbtest")
162 1.1 christos
163 1.1 christos
164 1.1 christos /* Local prototypes */
165 1.1 christos
166 1.1 christos static void
167 1.1 christos AcpiDbTestAllObjects (
168 1.1 christos void);
169 1.1 christos
170 1.1 christos static ACPI_STATUS
171 1.1 christos AcpiDbTestOneObject (
172 1.1 christos ACPI_HANDLE ObjHandle,
173 1.1 christos UINT32 NestingLevel,
174 1.1 christos void *Context,
175 1.1 christos void **ReturnValue);
176 1.1 christos
177 1.1 christos static ACPI_STATUS
178 1.1 christos AcpiDbTestIntegerType (
179 1.1 christos ACPI_NAMESPACE_NODE *Node,
180 1.1 christos UINT32 BitLength);
181 1.1 christos
182 1.1 christos static ACPI_STATUS
183 1.1 christos AcpiDbTestBufferType (
184 1.1 christos ACPI_NAMESPACE_NODE *Node,
185 1.1 christos UINT32 BitLength);
186 1.1 christos
187 1.1 christos static ACPI_STATUS
188 1.1 christos AcpiDbTestStringType (
189 1.1 christos ACPI_NAMESPACE_NODE *Node,
190 1.1 christos UINT32 ByteLength);
191 1.1 christos
192 1.1 christos static ACPI_STATUS
193 1.1.1.7 christos AcpiDbTestPackageType (
194 1.1.1.7 christos ACPI_NAMESPACE_NODE *Node);
195 1.1.1.7 christos
196 1.1.1.7 christos static ACPI_STATUS
197 1.1.1.8 christos AcpiDbTestFieldUnitType (
198 1.1.1.8 christos ACPI_OPERAND_OBJECT *ObjDesc);
199 1.1.1.8 christos
200 1.1.1.8 christos static ACPI_STATUS
201 1.1 christos AcpiDbReadFromObject (
202 1.1 christos ACPI_NAMESPACE_NODE *Node,
203 1.1 christos ACPI_OBJECT_TYPE ExpectedType,
204 1.1 christos ACPI_OBJECT **Value);
205 1.1 christos
206 1.1 christos static ACPI_STATUS
207 1.1 christos AcpiDbWriteToObject (
208 1.1 christos ACPI_NAMESPACE_NODE *Node,
209 1.1 christos ACPI_OBJECT *Value);
210 1.1 christos
211 1.1 christos static void
212 1.1 christos AcpiDbEvaluateAllPredefinedNames (
213 1.1 christos char *CountArg);
214 1.1 christos
215 1.1 christos static ACPI_STATUS
216 1.1 christos AcpiDbEvaluateOnePredefinedName (
217 1.1 christos ACPI_HANDLE ObjHandle,
218 1.1 christos UINT32 NestingLevel,
219 1.1 christos void *Context,
220 1.1 christos void **ReturnValue);
221 1.1 christos
222 1.1 christos /*
223 1.1 christos * Test subcommands
224 1.1 christos */
225 1.1 christos static ACPI_DB_ARGUMENT_INFO AcpiDbTestTypes [] =
226 1.1 christos {
227 1.1 christos {"OBJECTS"},
228 1.1 christos {"PREDEFINED"},
229 1.1 christos {NULL} /* Must be null terminated */
230 1.1 christos };
231 1.1 christos
232 1.1 christos #define CMD_TEST_OBJECTS 0
233 1.1 christos #define CMD_TEST_PREDEFINED 1
234 1.1 christos
235 1.1 christos #define BUFFER_FILL_VALUE 0xFF
236 1.1 christos
237 1.1 christos /*
238 1.1 christos * Support for the special debugger read/write control methods.
239 1.1 christos * These methods are installed into the current namespace and are
240 1.1 christos * used to read and write the various namespace objects. The point
241 1.1 christos * is to force the AML interpreter do all of the work.
242 1.1 christos */
243 1.1.1.4 christos #define ACPI_DB_READ_METHOD "\\_T98"
244 1.1.1.4 christos #define ACPI_DB_WRITE_METHOD "\\_T99"
245 1.1 christos
246 1.1 christos static ACPI_HANDLE ReadHandle = NULL;
247 1.1 christos static ACPI_HANDLE WriteHandle = NULL;
248 1.1 christos
249 1.1.1.8 christos /* ASL Definitions of the debugger read/write control methods. AML below. */
250 1.1 christos
251 1.1 christos #if 0
252 1.1 christos DefinitionBlock ("ssdt.aml", "SSDT", 2, "Intel", "DEBUG", 0x00000001)
253 1.1 christos {
254 1.1 christos Method (_T98, 1, NotSerialized) /* Read */
255 1.1 christos {
256 1.1 christos Return (DeRefOf (Arg0))
257 1.1 christos }
258 1.1 christos }
259 1.1 christos DefinitionBlock ("ssdt2.aml", "SSDT", 2, "Intel", "DEBUG", 0x00000001)
260 1.1 christos {
261 1.1 christos Method (_T99, 2, NotSerialized) /* Write */
262 1.1 christos {
263 1.1 christos Store (Arg1, Arg0)
264 1.1 christos }
265 1.1 christos }
266 1.1 christos #endif
267 1.1 christos
268 1.1 christos static unsigned char ReadMethodCode[] =
269 1.1 christos {
270 1.1 christos 0x53,0x53,0x44,0x54,0x2E,0x00,0x00,0x00, /* 00000000 "SSDT...." */
271 1.1 christos 0x02,0xC9,0x49,0x6E,0x74,0x65,0x6C,0x00, /* 00000008 "..Intel." */
272 1.1 christos 0x44,0x45,0x42,0x55,0x47,0x00,0x00,0x00, /* 00000010 "DEBUG..." */
273 1.1 christos 0x01,0x00,0x00,0x00,0x49,0x4E,0x54,0x4C, /* 00000018 "....INTL" */
274 1.1 christos 0x18,0x12,0x13,0x20,0x14,0x09,0x5F,0x54, /* 00000020 "... .._T" */
275 1.1 christos 0x39,0x38,0x01,0xA4,0x83,0x68 /* 00000028 "98...h" */
276 1.1 christos };
277 1.1 christos
278 1.1 christos static unsigned char WriteMethodCode[] =
279 1.1 christos {
280 1.1 christos 0x53,0x53,0x44,0x54,0x2E,0x00,0x00,0x00, /* 00000000 "SSDT...." */
281 1.1 christos 0x02,0x15,0x49,0x6E,0x74,0x65,0x6C,0x00, /* 00000008 "..Intel." */
282 1.1 christos 0x44,0x45,0x42,0x55,0x47,0x00,0x00,0x00, /* 00000010 "DEBUG..." */
283 1.1 christos 0x01,0x00,0x00,0x00,0x49,0x4E,0x54,0x4C, /* 00000018 "....INTL" */
284 1.1 christos 0x18,0x12,0x13,0x20,0x14,0x09,0x5F,0x54, /* 00000020 "... .._T" */
285 1.1 christos 0x39,0x39,0x02,0x70,0x69,0x68 /* 00000028 "99.pih" */
286 1.1 christos };
287 1.1 christos
288 1.1 christos
289 1.1 christos /*******************************************************************************
290 1.1 christos *
291 1.1 christos * FUNCTION: AcpiDbExecuteTest
292 1.1 christos *
293 1.1 christos * PARAMETERS: TypeArg - Subcommand
294 1.1 christos *
295 1.1 christos * RETURN: None
296 1.1 christos *
297 1.1 christos * DESCRIPTION: Execute various debug tests.
298 1.1 christos *
299 1.1 christos * Note: Code is prepared for future expansion of the TEST command.
300 1.1 christos *
301 1.1 christos ******************************************************************************/
302 1.1 christos
303 1.1 christos void
304 1.1 christos AcpiDbExecuteTest (
305 1.1 christos char *TypeArg)
306 1.1 christos {
307 1.1 christos UINT32 Temp;
308 1.1 christos
309 1.1 christos
310 1.1 christos AcpiUtStrupr (TypeArg);
311 1.1 christos Temp = AcpiDbMatchArgument (TypeArg, AcpiDbTestTypes);
312 1.1 christos if (Temp == ACPI_TYPE_NOT_FOUND)
313 1.1 christos {
314 1.1 christos AcpiOsPrintf ("Invalid or unsupported argument\n");
315 1.1 christos return;
316 1.1 christos }
317 1.1 christos
318 1.1 christos switch (Temp)
319 1.1 christos {
320 1.1 christos case CMD_TEST_OBJECTS:
321 1.1 christos
322 1.1 christos AcpiDbTestAllObjects ();
323 1.1 christos break;
324 1.1 christos
325 1.1 christos case CMD_TEST_PREDEFINED:
326 1.1 christos
327 1.1 christos AcpiDbEvaluateAllPredefinedNames (NULL);
328 1.1 christos break;
329 1.1 christos
330 1.1 christos default:
331 1.1 christos break;
332 1.1 christos }
333 1.1 christos }
334 1.1 christos
335 1.1 christos
336 1.1 christos /*******************************************************************************
337 1.1 christos *
338 1.1 christos * FUNCTION: AcpiDbTestAllObjects
339 1.1 christos *
340 1.1 christos * PARAMETERS: None
341 1.1 christos *
342 1.1 christos * RETURN: None
343 1.1 christos *
344 1.1 christos * DESCRIPTION: This test implements the OBJECTS subcommand. It exercises the
345 1.1 christos * namespace by reading/writing/comparing all data objects such
346 1.1 christos * as integers, strings, buffers, fields, buffer fields, etc.
347 1.1 christos *
348 1.1 christos ******************************************************************************/
349 1.1 christos
350 1.1 christos static void
351 1.1 christos AcpiDbTestAllObjects (
352 1.1 christos void)
353 1.1 christos {
354 1.1 christos ACPI_STATUS Status;
355 1.1 christos
356 1.1 christos
357 1.1 christos /* Install the debugger read-object control method if necessary */
358 1.1 christos
359 1.1 christos if (!ReadHandle)
360 1.1 christos {
361 1.1 christos Status = AcpiInstallMethod (ReadMethodCode);
362 1.1 christos if (ACPI_FAILURE (Status))
363 1.1 christos {
364 1.1 christos AcpiOsPrintf ("%s, Could not install debugger read method\n",
365 1.1 christos AcpiFormatException (Status));
366 1.1 christos return;
367 1.1 christos }
368 1.1 christos
369 1.1 christos Status = AcpiGetHandle (NULL, ACPI_DB_READ_METHOD, &ReadHandle);
370 1.1 christos if (ACPI_FAILURE (Status))
371 1.1 christos {
372 1.1 christos AcpiOsPrintf ("Could not obtain handle for debug method %s\n",
373 1.1 christos ACPI_DB_READ_METHOD);
374 1.1 christos return;
375 1.1 christos }
376 1.1 christos }
377 1.1 christos
378 1.1 christos /* Install the debugger write-object control method if necessary */
379 1.1 christos
380 1.1 christos if (!WriteHandle)
381 1.1 christos {
382 1.1 christos Status = AcpiInstallMethod (WriteMethodCode);
383 1.1 christos if (ACPI_FAILURE (Status))
384 1.1 christos {
385 1.1 christos AcpiOsPrintf ("%s, Could not install debugger write method\n",
386 1.1 christos AcpiFormatException (Status));
387 1.1 christos return;
388 1.1 christos }
389 1.1 christos
390 1.1 christos Status = AcpiGetHandle (NULL, ACPI_DB_WRITE_METHOD, &WriteHandle);
391 1.1 christos if (ACPI_FAILURE (Status))
392 1.1 christos {
393 1.1 christos AcpiOsPrintf ("Could not obtain handle for debug method %s\n",
394 1.1 christos ACPI_DB_WRITE_METHOD);
395 1.1 christos return;
396 1.1 christos }
397 1.1 christos }
398 1.1 christos
399 1.1 christos /* Walk the entire namespace, testing each supported named data object */
400 1.1 christos
401 1.1 christos (void) AcpiWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
402 1.1.1.4 christos ACPI_UINT32_MAX, AcpiDbTestOneObject, NULL, NULL, NULL);
403 1.1 christos }
404 1.1 christos
405 1.1 christos
406 1.1 christos /*******************************************************************************
407 1.1 christos *
408 1.1 christos * FUNCTION: AcpiDbTestOneObject
409 1.1 christos *
410 1.1 christos * PARAMETERS: ACPI_WALK_CALLBACK
411 1.1 christos *
412 1.1 christos * RETURN: Status
413 1.1 christos *
414 1.1 christos * DESCRIPTION: Test one namespace object. Supported types are Integer,
415 1.1.1.8 christos * String, Buffer, Package, BufferField, and FieldUnit.
416 1.1.1.8 christos * All other object types are simply ignored.
417 1.1 christos *
418 1.1 christos ******************************************************************************/
419 1.1 christos
420 1.1 christos static ACPI_STATUS
421 1.1 christos AcpiDbTestOneObject (
422 1.1 christos ACPI_HANDLE ObjHandle,
423 1.1 christos UINT32 NestingLevel,
424 1.1 christos void *Context,
425 1.1 christos void **ReturnValue)
426 1.1 christos {
427 1.1 christos ACPI_NAMESPACE_NODE *Node;
428 1.1 christos ACPI_OPERAND_OBJECT *ObjDesc;
429 1.1 christos ACPI_OBJECT_TYPE LocalType;
430 1.1 christos UINT32 BitLength = 0;
431 1.1 christos UINT32 ByteLength = 0;
432 1.1 christos ACPI_STATUS Status = AE_OK;
433 1.1 christos
434 1.1 christos
435 1.1 christos Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, ObjHandle);
436 1.1 christos ObjDesc = Node->Object;
437 1.1 christos
438 1.1 christos /*
439 1.1 christos * For the supported types, get the actual bit length or
440 1.1 christos * byte length. Map the type to one of Integer/String/Buffer.
441 1.1 christos */
442 1.1 christos switch (Node->Type)
443 1.1 christos {
444 1.1 christos case ACPI_TYPE_INTEGER:
445 1.1 christos
446 1.1 christos /* Integer width is either 32 or 64 */
447 1.1 christos
448 1.1 christos LocalType = ACPI_TYPE_INTEGER;
449 1.1 christos BitLength = AcpiGbl_IntegerBitWidth;
450 1.1 christos break;
451 1.1 christos
452 1.1 christos case ACPI_TYPE_STRING:
453 1.1 christos
454 1.1 christos LocalType = ACPI_TYPE_STRING;
455 1.1 christos ByteLength = ObjDesc->String.Length;
456 1.1 christos break;
457 1.1 christos
458 1.1 christos case ACPI_TYPE_BUFFER:
459 1.1 christos
460 1.1 christos LocalType = ACPI_TYPE_BUFFER;
461 1.1 christos ByteLength = ObjDesc->Buffer.Length;
462 1.1 christos BitLength = ByteLength * 8;
463 1.1 christos break;
464 1.1 christos
465 1.1.1.7 christos case ACPI_TYPE_PACKAGE:
466 1.1.1.7 christos
467 1.1.1.7 christos LocalType = ACPI_TYPE_PACKAGE;
468 1.1.1.7 christos break;
469 1.1.1.7 christos
470 1.1 christos case ACPI_TYPE_FIELD_UNIT:
471 1.1 christos case ACPI_TYPE_LOCAL_REGION_FIELD:
472 1.1 christos case ACPI_TYPE_LOCAL_INDEX_FIELD:
473 1.1 christos case ACPI_TYPE_LOCAL_BANK_FIELD:
474 1.1 christos
475 1.1.1.8 christos LocalType = ACPI_TYPE_FIELD_UNIT;
476 1.1.1.8 christos break;
477 1.1.1.8 christos
478 1.1.1.8 christos case ACPI_TYPE_BUFFER_FIELD:
479 1.1.1.8 christos /*
480 1.1.1.8 christos * The returned object will be a Buffer if the field length
481 1.1.1.8 christos * is larger than the size of an Integer (32 or 64 bits
482 1.1.1.8 christos * depending on the DSDT version).
483 1.1.1.8 christos */
484 1.1 christos LocalType = ACPI_TYPE_INTEGER;
485 1.1 christos if (ObjDesc)
486 1.1 christos {
487 1.1 christos BitLength = ObjDesc->CommonField.BitLength;
488 1.1 christos ByteLength = ACPI_ROUND_BITS_UP_TO_BYTES (BitLength);
489 1.1 christos if (BitLength > AcpiGbl_IntegerBitWidth)
490 1.1 christos {
491 1.1 christos LocalType = ACPI_TYPE_BUFFER;
492 1.1 christos }
493 1.1 christos }
494 1.1 christos break;
495 1.1 christos
496 1.1.1.8 christos default:
497 1.1 christos
498 1.1.1.8 christos /* Ignore all non-data types - Methods, Devices, Scopes, etc. */
499 1.1 christos
500 1.1 christos return (AE_OK);
501 1.1 christos }
502 1.1 christos
503 1.1 christos /* Emit the common prefix: Type:Name */
504 1.1 christos
505 1.1 christos AcpiOsPrintf ("%14s: %4.4s",
506 1.1 christos AcpiUtGetTypeName (Node->Type), Node->Name.Ascii);
507 1.1.1.7 christos
508 1.1 christos if (!ObjDesc)
509 1.1 christos {
510 1.1.1.8 christos AcpiOsPrintf (" No attached sub-object, ignoring\n");
511 1.1 christos return (AE_OK);
512 1.1 christos }
513 1.1 christos
514 1.1 christos /* At this point, we have resolved the object to one of the major types */
515 1.1 christos
516 1.1 christos switch (LocalType)
517 1.1 christos {
518 1.1 christos case ACPI_TYPE_INTEGER:
519 1.1 christos
520 1.1 christos Status = AcpiDbTestIntegerType (Node, BitLength);
521 1.1 christos break;
522 1.1 christos
523 1.1 christos case ACPI_TYPE_STRING:
524 1.1 christos
525 1.1 christos Status = AcpiDbTestStringType (Node, ByteLength);
526 1.1 christos break;
527 1.1 christos
528 1.1 christos case ACPI_TYPE_BUFFER:
529 1.1 christos
530 1.1 christos Status = AcpiDbTestBufferType (Node, BitLength);
531 1.1 christos break;
532 1.1 christos
533 1.1.1.7 christos case ACPI_TYPE_PACKAGE:
534 1.1.1.7 christos
535 1.1.1.7 christos Status = AcpiDbTestPackageType (Node);
536 1.1.1.7 christos break;
537 1.1.1.7 christos
538 1.1.1.8 christos case ACPI_TYPE_FIELD_UNIT:
539 1.1.1.8 christos
540 1.1.1.8 christos Status = AcpiDbTestFieldUnitType (ObjDesc);
541 1.1.1.8 christos break;
542 1.1.1.8 christos
543 1.1 christos default:
544 1.1 christos
545 1.1 christos AcpiOsPrintf (" Ignoring, type not implemented (%2.2X)",
546 1.1 christos LocalType);
547 1.1 christos break;
548 1.1 christos }
549 1.1 christos
550 1.1.1.7 christos /* Exit on error, but don't abort the namespace walk */
551 1.1.1.7 christos
552 1.1.1.7 christos if (ACPI_FAILURE (Status))
553 1.1.1.7 christos {
554 1.1.1.7 christos Status = AE_OK;
555 1.1.1.7 christos }
556 1.1.1.7 christos
557 1.1 christos AcpiOsPrintf ("\n");
558 1.1 christos return (Status);
559 1.1 christos }
560 1.1 christos
561 1.1 christos
562 1.1 christos /*******************************************************************************
563 1.1 christos *
564 1.1 christos * FUNCTION: AcpiDbTestIntegerType
565 1.1 christos *
566 1.1 christos * PARAMETERS: Node - Parent NS node for the object
567 1.1 christos * BitLength - Actual length of the object. Used for
568 1.1 christos * support of arbitrary length FieldUnit
569 1.1 christos * and BufferField objects.
570 1.1 christos *
571 1.1 christos * RETURN: Status
572 1.1 christos *
573 1.1 christos * DESCRIPTION: Test read/write for an Integer-valued object. Performs a
574 1.1 christos * write/read/compare of an arbitrary new value, then performs
575 1.1 christos * a write/read/compare of the original value.
576 1.1 christos *
577 1.1 christos ******************************************************************************/
578 1.1 christos
579 1.1 christos static ACPI_STATUS
580 1.1 christos AcpiDbTestIntegerType (
581 1.1 christos ACPI_NAMESPACE_NODE *Node,
582 1.1 christos UINT32 BitLength)
583 1.1 christos {
584 1.1 christos ACPI_OBJECT *Temp1 = NULL;
585 1.1 christos ACPI_OBJECT *Temp2 = NULL;
586 1.1 christos ACPI_OBJECT *Temp3 = NULL;
587 1.1 christos ACPI_OBJECT WriteValue;
588 1.1 christos UINT64 ValueToWrite;
589 1.1 christos ACPI_STATUS Status;
590 1.1 christos
591 1.1 christos
592 1.1 christos if (BitLength > 64)
593 1.1 christos {
594 1.1 christos AcpiOsPrintf (" Invalid length for an Integer: %u", BitLength);
595 1.1 christos return (AE_OK);
596 1.1 christos }
597 1.1 christos
598 1.1 christos /* Read the original value */
599 1.1 christos
600 1.1 christos Status = AcpiDbReadFromObject (Node, ACPI_TYPE_INTEGER, &Temp1);
601 1.1 christos if (ACPI_FAILURE (Status))
602 1.1 christos {
603 1.1 christos return (Status);
604 1.1 christos }
605 1.1 christos
606 1.1.1.8 christos AcpiOsPrintf (ACPI_DEBUG_LENGTH_FORMAT " %8.8X%8.8X",
607 1.1 christos BitLength, ACPI_ROUND_BITS_UP_TO_BYTES (BitLength),
608 1.1 christos ACPI_FORMAT_UINT64 (Temp1->Integer.Value));
609 1.1 christos
610 1.1 christos ValueToWrite = ACPI_UINT64_MAX >> (64 - BitLength);
611 1.1 christos if (Temp1->Integer.Value == ValueToWrite)
612 1.1 christos {
613 1.1 christos ValueToWrite = 0;
614 1.1 christos }
615 1.1 christos /* Write a new value */
616 1.1 christos
617 1.1 christos WriteValue.Type = ACPI_TYPE_INTEGER;
618 1.1 christos WriteValue.Integer.Value = ValueToWrite;
619 1.1 christos Status = AcpiDbWriteToObject (Node, &WriteValue);
620 1.1 christos if (ACPI_FAILURE (Status))
621 1.1 christos {
622 1.1 christos goto Exit;
623 1.1 christos }
624 1.1 christos
625 1.1 christos /* Ensure that we can read back the new value */
626 1.1 christos
627 1.1 christos Status = AcpiDbReadFromObject (Node, ACPI_TYPE_INTEGER, &Temp2);
628 1.1 christos if (ACPI_FAILURE (Status))
629 1.1 christos {
630 1.1 christos goto Exit;
631 1.1 christos }
632 1.1 christos
633 1.1 christos if (Temp2->Integer.Value != ValueToWrite)
634 1.1 christos {
635 1.1 christos AcpiOsPrintf (" MISMATCH 2: %8.8X%8.8X, expecting %8.8X%8.8X",
636 1.1 christos ACPI_FORMAT_UINT64 (Temp2->Integer.Value),
637 1.1 christos ACPI_FORMAT_UINT64 (ValueToWrite));
638 1.1 christos }
639 1.1 christos
640 1.1 christos /* Write back the original value */
641 1.1 christos
642 1.1 christos WriteValue.Integer.Value = Temp1->Integer.Value;
643 1.1 christos Status = AcpiDbWriteToObject (Node, &WriteValue);
644 1.1 christos if (ACPI_FAILURE (Status))
645 1.1 christos {
646 1.1 christos goto Exit;
647 1.1 christos }
648 1.1 christos
649 1.1 christos /* Ensure that we can read back the original value */
650 1.1 christos
651 1.1 christos Status = AcpiDbReadFromObject (Node, ACPI_TYPE_INTEGER, &Temp3);
652 1.1 christos if (ACPI_FAILURE (Status))
653 1.1 christos {
654 1.1 christos goto Exit;
655 1.1 christos }
656 1.1 christos
657 1.1 christos if (Temp3->Integer.Value != Temp1->Integer.Value)
658 1.1 christos {
659 1.1 christos AcpiOsPrintf (" MISMATCH 3: %8.8X%8.8X, expecting %8.8X%8.8X",
660 1.1 christos ACPI_FORMAT_UINT64 (Temp3->Integer.Value),
661 1.1 christos ACPI_FORMAT_UINT64 (Temp1->Integer.Value));
662 1.1 christos }
663 1.1 christos
664 1.1 christos Exit:
665 1.1 christos if (Temp1) {AcpiOsFree (Temp1);}
666 1.1 christos if (Temp2) {AcpiOsFree (Temp2);}
667 1.1 christos if (Temp3) {AcpiOsFree (Temp3);}
668 1.1 christos return (AE_OK);
669 1.1 christos }
670 1.1 christos
671 1.1 christos
672 1.1 christos /*******************************************************************************
673 1.1 christos *
674 1.1 christos * FUNCTION: AcpiDbTestBufferType
675 1.1 christos *
676 1.1 christos * PARAMETERS: Node - Parent NS node for the object
677 1.1 christos * BitLength - Actual length of the object.
678 1.1 christos *
679 1.1 christos * RETURN: Status
680 1.1 christos *
681 1.1 christos * DESCRIPTION: Test read/write for an Buffer-valued object. Performs a
682 1.1 christos * write/read/compare of an arbitrary new value, then performs
683 1.1 christos * a write/read/compare of the original value.
684 1.1 christos *
685 1.1 christos ******************************************************************************/
686 1.1 christos
687 1.1 christos static ACPI_STATUS
688 1.1 christos AcpiDbTestBufferType (
689 1.1 christos ACPI_NAMESPACE_NODE *Node,
690 1.1 christos UINT32 BitLength)
691 1.1 christos {
692 1.1 christos ACPI_OBJECT *Temp1 = NULL;
693 1.1 christos ACPI_OBJECT *Temp2 = NULL;
694 1.1 christos ACPI_OBJECT *Temp3 = NULL;
695 1.1 christos UINT8 *Buffer;
696 1.1 christos ACPI_OBJECT WriteValue;
697 1.1 christos ACPI_STATUS Status;
698 1.1 christos UINT32 ByteLength;
699 1.1 christos UINT32 i;
700 1.1 christos UINT8 ExtraBits;
701 1.1 christos
702 1.1 christos
703 1.1 christos ByteLength = ACPI_ROUND_BITS_UP_TO_BYTES (BitLength);
704 1.1 christos if (ByteLength == 0)
705 1.1 christos {
706 1.1 christos AcpiOsPrintf (" Ignoring zero length buffer");
707 1.1 christos return (AE_OK);
708 1.1 christos }
709 1.1 christos
710 1.1 christos /* Allocate a local buffer */
711 1.1 christos
712 1.1 christos Buffer = ACPI_ALLOCATE_ZEROED (ByteLength);
713 1.1 christos if (!Buffer)
714 1.1 christos {
715 1.1 christos return (AE_NO_MEMORY);
716 1.1 christos }
717 1.1 christos
718 1.1 christos /* Read the original value */
719 1.1 christos
720 1.1 christos Status = AcpiDbReadFromObject (Node, ACPI_TYPE_BUFFER, &Temp1);
721 1.1 christos if (ACPI_FAILURE (Status))
722 1.1 christos {
723 1.1 christos goto Exit;
724 1.1 christos }
725 1.1 christos
726 1.1 christos /* Emit a few bytes of the buffer */
727 1.1 christos
728 1.1.1.8 christos AcpiOsPrintf (ACPI_DEBUG_LENGTH_FORMAT, BitLength, Temp1->Buffer.Length);
729 1.1.1.8 christos for (i = 0; ((i < 8) && (i < ByteLength)); i++)
730 1.1 christos {
731 1.1 christos AcpiOsPrintf (" %2.2X", Temp1->Buffer.Pointer[i]);
732 1.1 christos }
733 1.1 christos AcpiOsPrintf ("... ");
734 1.1 christos
735 1.1 christos /*
736 1.1 christos * Write a new value.
737 1.1 christos *
738 1.1 christos * Handle possible extra bits at the end of the buffer. Can
739 1.1 christos * happen for FieldUnits larger than an integer, but the bit
740 1.1 christos * count is not an integral number of bytes. Zero out the
741 1.1 christos * unused bits.
742 1.1 christos */
743 1.1.1.3 christos memset (Buffer, BUFFER_FILL_VALUE, ByteLength);
744 1.1 christos ExtraBits = BitLength % 8;
745 1.1 christos if (ExtraBits)
746 1.1 christos {
747 1.1 christos Buffer [ByteLength - 1] = ACPI_MASK_BITS_ABOVE (ExtraBits);
748 1.1 christos }
749 1.1 christos
750 1.1 christos WriteValue.Type = ACPI_TYPE_BUFFER;
751 1.1 christos WriteValue.Buffer.Length = ByteLength;
752 1.1 christos WriteValue.Buffer.Pointer = Buffer;
753 1.1 christos
754 1.1 christos Status = AcpiDbWriteToObject (Node, &WriteValue);
755 1.1 christos if (ACPI_FAILURE (Status))
756 1.1 christos {
757 1.1 christos goto Exit;
758 1.1 christos }
759 1.1 christos
760 1.1 christos /* Ensure that we can read back the new value */
761 1.1 christos
762 1.1 christos Status = AcpiDbReadFromObject (Node, ACPI_TYPE_BUFFER, &Temp2);
763 1.1 christos if (ACPI_FAILURE (Status))
764 1.1 christos {
765 1.1 christos goto Exit;
766 1.1 christos }
767 1.1 christos
768 1.1.1.3 christos if (memcmp (Temp2->Buffer.Pointer, Buffer, ByteLength))
769 1.1 christos {
770 1.1 christos AcpiOsPrintf (" MISMATCH 2: New buffer value");
771 1.1 christos }
772 1.1 christos
773 1.1 christos /* Write back the original value */
774 1.1 christos
775 1.1 christos WriteValue.Buffer.Length = ByteLength;
776 1.1 christos WriteValue.Buffer.Pointer = Temp1->Buffer.Pointer;
777 1.1 christos
778 1.1 christos Status = AcpiDbWriteToObject (Node, &WriteValue);
779 1.1 christos if (ACPI_FAILURE (Status))
780 1.1 christos {
781 1.1 christos goto Exit;
782 1.1 christos }
783 1.1 christos
784 1.1 christos /* Ensure that we can read back the original value */
785 1.1 christos
786 1.1 christos Status = AcpiDbReadFromObject (Node, ACPI_TYPE_BUFFER, &Temp3);
787 1.1 christos if (ACPI_FAILURE (Status))
788 1.1 christos {
789 1.1 christos goto Exit;
790 1.1 christos }
791 1.1 christos
792 1.1.1.4 christos if (memcmp (Temp1->Buffer.Pointer,
793 1.1.1.4 christos Temp3->Buffer.Pointer, ByteLength))
794 1.1 christos {
795 1.1 christos AcpiOsPrintf (" MISMATCH 3: While restoring original buffer");
796 1.1 christos }
797 1.1 christos
798 1.1 christos Exit:
799 1.1 christos ACPI_FREE (Buffer);
800 1.1 christos if (Temp1) {AcpiOsFree (Temp1);}
801 1.1 christos if (Temp2) {AcpiOsFree (Temp2);}
802 1.1 christos if (Temp3) {AcpiOsFree (Temp3);}
803 1.1 christos return (Status);
804 1.1 christos }
805 1.1 christos
806 1.1 christos
807 1.1 christos /*******************************************************************************
808 1.1 christos *
809 1.1 christos * FUNCTION: AcpiDbTestStringType
810 1.1 christos *
811 1.1 christos * PARAMETERS: Node - Parent NS node for the object
812 1.1 christos * ByteLength - Actual length of the object.
813 1.1 christos *
814 1.1 christos * RETURN: Status
815 1.1 christos *
816 1.1 christos * DESCRIPTION: Test read/write for an String-valued object. Performs a
817 1.1 christos * write/read/compare of an arbitrary new value, then performs
818 1.1 christos * a write/read/compare of the original value.
819 1.1 christos *
820 1.1 christos ******************************************************************************/
821 1.1 christos
822 1.1 christos static ACPI_STATUS
823 1.1 christos AcpiDbTestStringType (
824 1.1 christos ACPI_NAMESPACE_NODE *Node,
825 1.1 christos UINT32 ByteLength)
826 1.1 christos {
827 1.1 christos ACPI_OBJECT *Temp1 = NULL;
828 1.1 christos ACPI_OBJECT *Temp2 = NULL;
829 1.1 christos ACPI_OBJECT *Temp3 = NULL;
830 1.1 christos char *ValueToWrite = "Test String from AML Debugger";
831 1.1 christos ACPI_OBJECT WriteValue;
832 1.1 christos ACPI_STATUS Status;
833 1.1 christos
834 1.1 christos
835 1.1 christos /* Read the original value */
836 1.1 christos
837 1.1 christos Status = AcpiDbReadFromObject (Node, ACPI_TYPE_STRING, &Temp1);
838 1.1 christos if (ACPI_FAILURE (Status))
839 1.1 christos {
840 1.1 christos return (Status);
841 1.1 christos }
842 1.1 christos
843 1.1.1.8 christos AcpiOsPrintf (ACPI_DEBUG_LENGTH_FORMAT " \"%s\"", (Temp1->String.Length * 8),
844 1.1 christos Temp1->String.Length, Temp1->String.Pointer);
845 1.1 christos
846 1.1 christos /* Write a new value */
847 1.1 christos
848 1.1 christos WriteValue.Type = ACPI_TYPE_STRING;
849 1.1.1.3 christos WriteValue.String.Length = strlen (ValueToWrite);
850 1.1 christos WriteValue.String.Pointer = ValueToWrite;
851 1.1 christos
852 1.1 christos Status = AcpiDbWriteToObject (Node, &WriteValue);
853 1.1 christos if (ACPI_FAILURE (Status))
854 1.1 christos {
855 1.1 christos goto Exit;
856 1.1 christos }
857 1.1 christos
858 1.1 christos /* Ensure that we can read back the new value */
859 1.1 christos
860 1.1 christos Status = AcpiDbReadFromObject (Node, ACPI_TYPE_STRING, &Temp2);
861 1.1 christos if (ACPI_FAILURE (Status))
862 1.1 christos {
863 1.1 christos goto Exit;
864 1.1 christos }
865 1.1 christos
866 1.1.1.3 christos if (strcmp (Temp2->String.Pointer, ValueToWrite))
867 1.1 christos {
868 1.1 christos AcpiOsPrintf (" MISMATCH 2: %s, expecting %s",
869 1.1 christos Temp2->String.Pointer, ValueToWrite);
870 1.1 christos }
871 1.1 christos
872 1.1 christos /* Write back the original value */
873 1.1 christos
874 1.1.1.3 christos WriteValue.String.Length = strlen (Temp1->String.Pointer);
875 1.1 christos WriteValue.String.Pointer = Temp1->String.Pointer;
876 1.1 christos
877 1.1 christos Status = AcpiDbWriteToObject (Node, &WriteValue);
878 1.1 christos if (ACPI_FAILURE (Status))
879 1.1 christos {
880 1.1 christos goto Exit;
881 1.1 christos }
882 1.1 christos
883 1.1 christos /* Ensure that we can read back the original value */
884 1.1 christos
885 1.1 christos Status = AcpiDbReadFromObject (Node, ACPI_TYPE_STRING, &Temp3);
886 1.1 christos if (ACPI_FAILURE (Status))
887 1.1 christos {
888 1.1 christos goto Exit;
889 1.1 christos }
890 1.1 christos
891 1.1.1.3 christos if (strcmp (Temp1->String.Pointer, Temp3->String.Pointer))
892 1.1 christos {
893 1.1 christos AcpiOsPrintf (" MISMATCH 3: %s, expecting %s",
894 1.1 christos Temp3->String.Pointer, Temp1->String.Pointer);
895 1.1 christos }
896 1.1 christos
897 1.1 christos Exit:
898 1.1 christos if (Temp1) {AcpiOsFree (Temp1);}
899 1.1 christos if (Temp2) {AcpiOsFree (Temp2);}
900 1.1 christos if (Temp3) {AcpiOsFree (Temp3);}
901 1.1 christos return (Status);
902 1.1 christos }
903 1.1 christos
904 1.1 christos
905 1.1 christos /*******************************************************************************
906 1.1 christos *
907 1.1.1.7 christos * FUNCTION: AcpiDbTestPackageType
908 1.1.1.7 christos *
909 1.1.1.7 christos * PARAMETERS: Node - Parent NS node for the object
910 1.1.1.7 christos *
911 1.1.1.7 christos * RETURN: Status
912 1.1.1.7 christos *
913 1.1.1.7 christos * DESCRIPTION: Test read for a Package object.
914 1.1.1.7 christos *
915 1.1.1.7 christos ******************************************************************************/
916 1.1.1.7 christos
917 1.1.1.7 christos static ACPI_STATUS
918 1.1.1.7 christos AcpiDbTestPackageType (
919 1.1.1.7 christos ACPI_NAMESPACE_NODE *Node)
920 1.1.1.7 christos {
921 1.1.1.7 christos ACPI_OBJECT *Temp1 = NULL;
922 1.1.1.7 christos ACPI_STATUS Status;
923 1.1.1.7 christos
924 1.1.1.7 christos
925 1.1.1.7 christos /* Read the original value */
926 1.1.1.7 christos
927 1.1.1.7 christos Status = AcpiDbReadFromObject (Node, ACPI_TYPE_PACKAGE, &Temp1);
928 1.1.1.7 christos if (ACPI_FAILURE (Status))
929 1.1.1.7 christos {
930 1.1.1.7 christos return (Status);
931 1.1.1.7 christos }
932 1.1.1.7 christos
933 1.1.1.8 christos AcpiOsPrintf (" %.2X Elements", Temp1->Package.Count);
934 1.1.1.7 christos AcpiOsFree (Temp1);
935 1.1.1.7 christos return (Status);
936 1.1.1.7 christos }
937 1.1.1.7 christos
938 1.1.1.7 christos
939 1.1.1.7 christos /*******************************************************************************
940 1.1.1.7 christos *
941 1.1.1.8 christos * FUNCTION: AcpiDbTestFieldUnitType
942 1.1.1.8 christos *
943 1.1.1.8 christos * PARAMETERS: ObjDesc - A field unit object
944 1.1.1.8 christos *
945 1.1.1.8 christos * RETURN: Status
946 1.1.1.8 christos *
947 1.1.1.8 christos * DESCRIPTION: Test read/write on a named field unit.
948 1.1.1.8 christos *
949 1.1.1.8 christos ******************************************************************************/
950 1.1.1.8 christos
951 1.1.1.8 christos static ACPI_STATUS
952 1.1.1.8 christos AcpiDbTestFieldUnitType (
953 1.1.1.8 christos ACPI_OPERAND_OBJECT *ObjDesc)
954 1.1.1.8 christos {
955 1.1.1.8 christos ACPI_OPERAND_OBJECT *RegionObj;
956 1.1.1.8 christos UINT32 BitLength = 0;
957 1.1.1.8 christos UINT32 ByteLength = 0;
958 1.1.1.8 christos ACPI_STATUS Status = AE_OK;
959 1.1.1.8 christos ACPI_OPERAND_OBJECT *RetBufferDesc;
960 1.1.1.8 christos
961 1.1.1.8 christos
962 1.1.1.8 christos /* Supported spaces are memory/io/pci_config */
963 1.1.1.8 christos
964 1.1.1.8 christos RegionObj = ObjDesc->Field.RegionObj;
965 1.1.1.8 christos switch (RegionObj->Region.SpaceId)
966 1.1.1.8 christos {
967 1.1.1.8 christos case ACPI_ADR_SPACE_SYSTEM_MEMORY:
968 1.1.1.8 christos case ACPI_ADR_SPACE_SYSTEM_IO:
969 1.1.1.8 christos case ACPI_ADR_SPACE_PCI_CONFIG:
970 1.1.1.8 christos
971 1.1.1.8 christos /* Need the interpreter to execute */
972 1.1.1.8 christos
973 1.1.1.8 christos AcpiUtAcquireMutex (ACPI_MTX_INTERPRETER);
974 1.1.1.8 christos AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
975 1.1.1.8 christos
976 1.1.1.8 christos /* Exercise read-then-write */
977 1.1.1.8 christos
978 1.1.1.8 christos Status = AcpiExReadDataFromField (NULL, ObjDesc, &RetBufferDesc);
979 1.1.1.8 christos if (Status == AE_OK)
980 1.1.1.8 christos {
981 1.1.1.8 christos AcpiExWriteDataToField (RetBufferDesc, ObjDesc, NULL);
982 1.1.1.8 christos AcpiUtRemoveReference (RetBufferDesc);
983 1.1.1.8 christos }
984 1.1.1.8 christos
985 1.1.1.8 christos AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
986 1.1.1.8 christos AcpiUtReleaseMutex (ACPI_MTX_INTERPRETER);
987 1.1.1.8 christos
988 1.1.1.8 christos BitLength = ObjDesc->CommonField.BitLength;
989 1.1.1.8 christos ByteLength = ACPI_ROUND_BITS_UP_TO_BYTES (BitLength);
990 1.1.1.8 christos
991 1.1.1.8 christos AcpiOsPrintf (ACPI_DEBUG_LENGTH_FORMAT " [%s]", BitLength,
992 1.1.1.8 christos ByteLength, AcpiUtGetRegionName (RegionObj->Region.SpaceId));
993 1.1.1.8 christos return (Status);
994 1.1.1.8 christos
995 1.1.1.8 christos default:
996 1.1.1.8 christos
997 1.1.1.8 christos AcpiOsPrintf (
998 1.1.1.8 christos " %s address space is not supported in this command [%4.4s]",
999 1.1.1.8 christos AcpiUtGetRegionName (RegionObj->Region.SpaceId),
1000 1.1.1.8 christos RegionObj->Region.Node->Name.Ascii);
1001 1.1.1.8 christos return (AE_OK);
1002 1.1.1.8 christos }
1003 1.1.1.8 christos }
1004 1.1.1.8 christos
1005 1.1.1.8 christos
1006 1.1.1.8 christos /*******************************************************************************
1007 1.1.1.8 christos *
1008 1.1 christos * FUNCTION: AcpiDbReadFromObject
1009 1.1 christos *
1010 1.1 christos * PARAMETERS: Node - Parent NS node for the object
1011 1.1 christos * ExpectedType - Object type expected from the read
1012 1.1 christos * Value - Where the value read is returned
1013 1.1 christos *
1014 1.1 christos * RETURN: Status
1015 1.1 christos *
1016 1.1 christos * DESCRIPTION: Performs a read from the specified object by invoking the
1017 1.1 christos * special debugger control method that reads the object. Thus,
1018 1.1 christos * the AML interpreter is doing all of the work, increasing the
1019 1.1 christos * validity of the test.
1020 1.1 christos *
1021 1.1 christos ******************************************************************************/
1022 1.1 christos
1023 1.1 christos static ACPI_STATUS
1024 1.1 christos AcpiDbReadFromObject (
1025 1.1 christos ACPI_NAMESPACE_NODE *Node,
1026 1.1 christos ACPI_OBJECT_TYPE ExpectedType,
1027 1.1 christos ACPI_OBJECT **Value)
1028 1.1 christos {
1029 1.1 christos ACPI_OBJECT *RetValue;
1030 1.1 christos ACPI_OBJECT_LIST ParamObjects;
1031 1.1 christos ACPI_OBJECT Params[2];
1032 1.1 christos ACPI_BUFFER ReturnObj;
1033 1.1 christos ACPI_STATUS Status;
1034 1.1 christos
1035 1.1 christos
1036 1.1 christos Params[0].Type = ACPI_TYPE_LOCAL_REFERENCE;
1037 1.1 christos Params[0].Reference.ActualType = Node->Type;
1038 1.1 christos Params[0].Reference.Handle = ACPI_CAST_PTR (ACPI_HANDLE, Node);
1039 1.1 christos
1040 1.1 christos ParamObjects.Count = 1;
1041 1.1 christos ParamObjects.Pointer = Params;
1042 1.1 christos
1043 1.1 christos ReturnObj.Length = ACPI_ALLOCATE_BUFFER;
1044 1.1 christos
1045 1.1 christos AcpiGbl_MethodExecuting = TRUE;
1046 1.1.1.4 christos Status = AcpiEvaluateObject (ReadHandle, NULL,
1047 1.1.1.4 christos &ParamObjects, &ReturnObj);
1048 1.1 christos
1049 1.1.1.7 christos AcpiGbl_MethodExecuting = FALSE;
1050 1.1 christos if (ACPI_FAILURE (Status))
1051 1.1 christos {
1052 1.1 christos AcpiOsPrintf ("Could not read from object, %s",
1053 1.1 christos AcpiFormatException (Status));
1054 1.1 christos return (Status);
1055 1.1 christos }
1056 1.1 christos
1057 1.1 christos RetValue = (ACPI_OBJECT *) ReturnObj.Pointer;
1058 1.1 christos
1059 1.1 christos switch (RetValue->Type)
1060 1.1 christos {
1061 1.1 christos case ACPI_TYPE_INTEGER:
1062 1.1 christos case ACPI_TYPE_BUFFER:
1063 1.1 christos case ACPI_TYPE_STRING:
1064 1.1.1.7 christos case ACPI_TYPE_PACKAGE:
1065 1.1 christos /*
1066 1.1 christos * Did we receive the type we wanted? Most important for the
1067 1.1 christos * Integer/Buffer case (when a field is larger than an Integer,
1068 1.1 christos * it should return a Buffer).
1069 1.1 christos */
1070 1.1 christos if (RetValue->Type != ExpectedType)
1071 1.1 christos {
1072 1.1 christos AcpiOsPrintf (" Type mismatch: Expected %s, Received %s",
1073 1.1 christos AcpiUtGetTypeName (ExpectedType),
1074 1.1 christos AcpiUtGetTypeName (RetValue->Type));
1075 1.1 christos
1076 1.1.1.7 christos AcpiOsFree (ReturnObj.Pointer);
1077 1.1 christos return (AE_TYPE);
1078 1.1 christos }
1079 1.1 christos
1080 1.1 christos *Value = RetValue;
1081 1.1 christos break;
1082 1.1 christos
1083 1.1 christos default:
1084 1.1 christos
1085 1.1 christos AcpiOsPrintf (" Unsupported return object type, %s",
1086 1.1 christos AcpiUtGetTypeName (RetValue->Type));
1087 1.1 christos
1088 1.1.1.4 christos AcpiOsFree (ReturnObj.Pointer);
1089 1.1 christos return (AE_TYPE);
1090 1.1 christos }
1091 1.1 christos
1092 1.1 christos return (Status);
1093 1.1 christos }
1094 1.1 christos
1095 1.1 christos
1096 1.1 christos /*******************************************************************************
1097 1.1 christos *
1098 1.1 christos * FUNCTION: AcpiDbWriteToObject
1099 1.1 christos *
1100 1.1 christos * PARAMETERS: Node - Parent NS node for the object
1101 1.1 christos * Value - Value to be written
1102 1.1 christos *
1103 1.1 christos * RETURN: Status
1104 1.1 christos *
1105 1.1 christos * DESCRIPTION: Performs a write to the specified object by invoking the
1106 1.1 christos * special debugger control method that writes the object. Thus,
1107 1.1 christos * the AML interpreter is doing all of the work, increasing the
1108 1.1 christos * validity of the test.
1109 1.1 christos *
1110 1.1 christos ******************************************************************************/
1111 1.1 christos
1112 1.1 christos static ACPI_STATUS
1113 1.1 christos AcpiDbWriteToObject (
1114 1.1 christos ACPI_NAMESPACE_NODE *Node,
1115 1.1 christos ACPI_OBJECT *Value)
1116 1.1 christos {
1117 1.1 christos ACPI_OBJECT_LIST ParamObjects;
1118 1.1 christos ACPI_OBJECT Params[2];
1119 1.1 christos ACPI_STATUS Status;
1120 1.1 christos
1121 1.1 christos
1122 1.1 christos Params[0].Type = ACPI_TYPE_LOCAL_REFERENCE;
1123 1.1 christos Params[0].Reference.ActualType = Node->Type;
1124 1.1 christos Params[0].Reference.Handle = ACPI_CAST_PTR (ACPI_HANDLE, Node);
1125 1.1 christos
1126 1.1 christos /* Copy the incoming user parameter */
1127 1.1 christos
1128 1.1.1.3 christos memcpy (&Params[1], Value, sizeof (ACPI_OBJECT));
1129 1.1 christos
1130 1.1 christos ParamObjects.Count = 2;
1131 1.1 christos ParamObjects.Pointer = Params;
1132 1.1 christos
1133 1.1 christos AcpiGbl_MethodExecuting = TRUE;
1134 1.1 christos Status = AcpiEvaluateObject (WriteHandle, NULL, &ParamObjects, NULL);
1135 1.1 christos AcpiGbl_MethodExecuting = FALSE;
1136 1.1 christos
1137 1.1 christos if (ACPI_FAILURE (Status))
1138 1.1 christos {
1139 1.1 christos AcpiOsPrintf ("Could not write to object, %s",
1140 1.1 christos AcpiFormatException (Status));
1141 1.1 christos }
1142 1.1 christos
1143 1.1 christos return (Status);
1144 1.1 christos }
1145 1.1 christos
1146 1.1 christos
1147 1.1 christos /*******************************************************************************
1148 1.1 christos *
1149 1.1 christos * FUNCTION: AcpiDbEvaluateAllPredefinedNames
1150 1.1 christos *
1151 1.1 christos * PARAMETERS: CountArg - Max number of methods to execute
1152 1.1 christos *
1153 1.1 christos * RETURN: None
1154 1.1 christos *
1155 1.1 christos * DESCRIPTION: Namespace batch execution. Execute predefined names in the
1156 1.1 christos * namespace, up to the max count, if specified.
1157 1.1 christos *
1158 1.1 christos ******************************************************************************/
1159 1.1 christos
1160 1.1 christos static void
1161 1.1 christos AcpiDbEvaluateAllPredefinedNames (
1162 1.1 christos char *CountArg)
1163 1.1 christos {
1164 1.1 christos ACPI_DB_EXECUTE_WALK Info;
1165 1.1 christos
1166 1.1 christos
1167 1.1 christos Info.Count = 0;
1168 1.1 christos Info.MaxCount = ACPI_UINT32_MAX;
1169 1.1 christos
1170 1.1 christos if (CountArg)
1171 1.1 christos {
1172 1.1.1.3 christos Info.MaxCount = strtoul (CountArg, NULL, 0);
1173 1.1 christos }
1174 1.1 christos
1175 1.1 christos /* Search all nodes in namespace */
1176 1.1 christos
1177 1.1.1.4 christos (void) AcpiWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
1178 1.1.1.4 christos ACPI_UINT32_MAX, AcpiDbEvaluateOnePredefinedName, NULL,
1179 1.1.1.4 christos (void *) &Info, NULL);
1180 1.1 christos
1181 1.1.1.4 christos AcpiOsPrintf (
1182 1.1.1.4 christos "Evaluated %u predefined names in the namespace\n", Info.Count);
1183 1.1 christos }
1184 1.1 christos
1185 1.1 christos
1186 1.1 christos /*******************************************************************************
1187 1.1 christos *
1188 1.1 christos * FUNCTION: AcpiDbEvaluateOnePredefinedName
1189 1.1 christos *
1190 1.1 christos * PARAMETERS: Callback from WalkNamespace
1191 1.1 christos *
1192 1.1 christos * RETURN: Status
1193 1.1 christos *
1194 1.1 christos * DESCRIPTION: Batch execution module. Currently only executes predefined
1195 1.1 christos * ACPI names.
1196 1.1 christos *
1197 1.1 christos ******************************************************************************/
1198 1.1 christos
1199 1.1 christos static ACPI_STATUS
1200 1.1 christos AcpiDbEvaluateOnePredefinedName (
1201 1.1 christos ACPI_HANDLE ObjHandle,
1202 1.1 christos UINT32 NestingLevel,
1203 1.1 christos void *Context,
1204 1.1 christos void **ReturnValue)
1205 1.1 christos {
1206 1.1 christos ACPI_NAMESPACE_NODE *Node = (ACPI_NAMESPACE_NODE *) ObjHandle;
1207 1.1 christos ACPI_DB_EXECUTE_WALK *Info = (ACPI_DB_EXECUTE_WALK *) Context;
1208 1.1 christos char *Pathname;
1209 1.1 christos const ACPI_PREDEFINED_INFO *Predefined;
1210 1.1 christos ACPI_DEVICE_INFO *ObjInfo;
1211 1.1 christos ACPI_OBJECT_LIST ParamObjects;
1212 1.1 christos ACPI_OBJECT Params[ACPI_METHOD_NUM_ARGS];
1213 1.1 christos ACPI_OBJECT *ThisParam;
1214 1.1 christos ACPI_BUFFER ReturnObj;
1215 1.1 christos ACPI_STATUS Status;
1216 1.1 christos UINT16 ArgTypeList;
1217 1.1 christos UINT8 ArgCount;
1218 1.1 christos UINT8 ArgType;
1219 1.1 christos UINT32 i;
1220 1.1 christos
1221 1.1 christos
1222 1.1 christos /* The name must be a predefined ACPI name */
1223 1.1 christos
1224 1.1 christos Predefined = AcpiUtMatchPredefinedMethod (Node->Name.Ascii);
1225 1.1 christos if (!Predefined)
1226 1.1 christos {
1227 1.1 christos return (AE_OK);
1228 1.1 christos }
1229 1.1 christos
1230 1.1 christos if (Node->Type == ACPI_TYPE_LOCAL_SCOPE)
1231 1.1 christos {
1232 1.1 christos return (AE_OK);
1233 1.1 christos }
1234 1.1 christos
1235 1.1.1.4 christos Pathname = AcpiNsGetNormalizedPathname (Node, TRUE);
1236 1.1 christos if (!Pathname)
1237 1.1 christos {
1238 1.1 christos return (AE_OK);
1239 1.1 christos }
1240 1.1 christos
1241 1.1 christos /* Get the object info for number of method parameters */
1242 1.1 christos
1243 1.1 christos Status = AcpiGetObjectInfo (ObjHandle, &ObjInfo);
1244 1.1 christos if (ACPI_FAILURE (Status))
1245 1.1 christos {
1246 1.1 christos ACPI_FREE (Pathname);
1247 1.1 christos return (Status);
1248 1.1 christos }
1249 1.1 christos
1250 1.1 christos ParamObjects.Count = 0;
1251 1.1 christos ParamObjects.Pointer = NULL;
1252 1.1 christos
1253 1.1 christos if (ObjInfo->Type == ACPI_TYPE_METHOD)
1254 1.1 christos {
1255 1.1 christos /* Setup default parameters (with proper types) */
1256 1.1 christos
1257 1.1 christos ArgTypeList = Predefined->Info.ArgumentList;
1258 1.1 christos ArgCount = METHOD_GET_ARG_COUNT (ArgTypeList);
1259 1.1 christos
1260 1.1 christos /*
1261 1.1 christos * Setup the ACPI-required number of arguments, regardless of what
1262 1.1 christos * the actual method defines. If there is a difference, then the
1263 1.1 christos * method is wrong and a warning will be issued during execution.
1264 1.1 christos */
1265 1.1 christos ThisParam = Params;
1266 1.1 christos for (i = 0; i < ArgCount; i++)
1267 1.1 christos {
1268 1.1 christos ArgType = METHOD_GET_NEXT_TYPE (ArgTypeList);
1269 1.1 christos ThisParam->Type = ArgType;
1270 1.1 christos
1271 1.1 christos switch (ArgType)
1272 1.1 christos {
1273 1.1 christos case ACPI_TYPE_INTEGER:
1274 1.1 christos
1275 1.1 christos ThisParam->Integer.Value = 1;
1276 1.1 christos break;
1277 1.1 christos
1278 1.1 christos case ACPI_TYPE_STRING:
1279 1.1 christos
1280 1.1.1.4 christos ThisParam->String.Pointer =
1281 1.1.1.4 christos "This is the default argument string";
1282 1.1.1.4 christos ThisParam->String.Length =
1283 1.1.1.4 christos strlen (ThisParam->String.Pointer);
1284 1.1 christos break;
1285 1.1 christos
1286 1.1 christos case ACPI_TYPE_BUFFER:
1287 1.1 christos
1288 1.1 christos ThisParam->Buffer.Pointer = (UINT8 *) Params; /* just a garbage buffer */
1289 1.1 christos ThisParam->Buffer.Length = 48;
1290 1.1 christos break;
1291 1.1 christos
1292 1.1 christos case ACPI_TYPE_PACKAGE:
1293 1.1 christos
1294 1.1 christos ThisParam->Package.Elements = NULL;
1295 1.1 christos ThisParam->Package.Count = 0;
1296 1.1 christos break;
1297 1.1 christos
1298 1.1 christos default:
1299 1.1 christos
1300 1.1 christos AcpiOsPrintf ("%s: Unsupported argument type: %u\n",
1301 1.1 christos Pathname, ArgType);
1302 1.1 christos break;
1303 1.1 christos }
1304 1.1 christos
1305 1.1 christos ThisParam++;
1306 1.1 christos }
1307 1.1 christos
1308 1.1 christos ParamObjects.Count = ArgCount;
1309 1.1 christos ParamObjects.Pointer = Params;
1310 1.1 christos }
1311 1.1 christos
1312 1.1 christos ACPI_FREE (ObjInfo);
1313 1.1 christos ReturnObj.Pointer = NULL;
1314 1.1 christos ReturnObj.Length = ACPI_ALLOCATE_BUFFER;
1315 1.1 christos
1316 1.1 christos /* Do the actual method execution */
1317 1.1 christos
1318 1.1 christos AcpiGbl_MethodExecuting = TRUE;
1319 1.1 christos
1320 1.1 christos Status = AcpiEvaluateObject (Node, NULL, &ParamObjects, &ReturnObj);
1321 1.1 christos
1322 1.1.1.4 christos AcpiOsPrintf ("%-32s returned %s\n",
1323 1.1.1.4 christos Pathname, AcpiFormatException (Status));
1324 1.1 christos AcpiGbl_MethodExecuting = FALSE;
1325 1.1 christos ACPI_FREE (Pathname);
1326 1.1 christos
1327 1.1 christos /* Ignore status from method execution */
1328 1.1 christos
1329 1.1 christos Status = AE_OK;
1330 1.1 christos
1331 1.1 christos /* Update count, check if we have executed enough methods */
1332 1.1 christos
1333 1.1 christos Info->Count++;
1334 1.1 christos if (Info->Count >= Info->MaxCount)
1335 1.1 christos {
1336 1.1 christos Status = AE_CTRL_TERMINATE;
1337 1.1 christos }
1338 1.1 christos
1339 1.1 christos return (Status);
1340 1.1 christos }
1341