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