Deleted Added
full compact
utcopy.c (71867) utcopy.c (73561)
1/******************************************************************************
2 *
3 * Module Name: cmcopy - Internal to external object translation utilities
1/******************************************************************************
2 *
3 * Module Name: cmcopy - Internal to external object translation utilities
4 * $Revision: 62 $
4 * $Revision: 66 $
5 *
6 *****************************************************************************/
7
8/******************************************************************************
9 *
10 * 1. Copyright Notice
11 *
12 * Some or all of this work - Copyright (c) 1999, 2000, 2001, Intel Corp.

--- 101 unchanged lines hidden (view full) ---

114 *
115 *****************************************************************************/
116
117#define __CMCOPY_C__
118
119#include "acpi.h"
120#include "acinterp.h"
121#include "acnamesp.h"
5 *
6 *****************************************************************************/
7
8/******************************************************************************
9 *
10 * 1. Copyright Notice
11 *
12 * Some or all of this work - Copyright (c) 1999, 2000, 2001, Intel Corp.

--- 101 unchanged lines hidden (view full) ---

114 *
115 *****************************************************************************/
116
117#define __CMCOPY_C__
118
119#include "acpi.h"
120#include "acinterp.h"
121#include "acnamesp.h"
122#include "amlcode.h"
122
123
124#define _COMPONENT MISCELLANEOUS
125 MODULE_NAME ("cmcopy")
126
127
123
124
125#define _COMPONENT MISCELLANEOUS
126 MODULE_NAME ("cmcopy")
127
128
128typedef struct Search_st
129{
130 ACPI_OPERAND_OBJECT *InternalObj;
131 UINT32 Index;
132 ACPI_OBJECT *ExternalObj;
133
129
134} PKG_SEARCH_INFO;
135
136
137/* Used to traverse nested packages */
138
139PKG_SEARCH_INFO Level[MAX_PACKAGE_DEPTH];
140
141/******************************************************************************
130/*******************************************************************************
142 *
131 *
143 * FUNCTION: AcpiCmBuildExternalSimpleObject
132 * FUNCTION: AcpiCmCopyIsimpleToEsimple
144 *
133 *
145 * PARAMETERS: *InternalObj - Pointer to the object we are examining
146 * *Buffer - Where the object is returned
147 * *SpaceUsed - Where the data length is returned
134 * PARAMETERS: *InternalObject - Pointer to the object we are examining
135 * *Buffer - Where the object is returned
136 * *SpaceUsed - Where the data length is returned
148 *
137 *
149 * RETURN: Status - the status of the call
138 * RETURN: Status
150 *
151 * DESCRIPTION: This function is called to place a simple object in a user
139 *
140 * DESCRIPTION: This function is called to place a simple object in a user
152 * buffer.
141 * buffer.
153 *
154 * The buffer is assumed to have sufficient space for the object.
155 *
156 ******************************************************************************/
157
158static ACPI_STATUS
142 *
143 * The buffer is assumed to have sufficient space for the object.
144 *
145 ******************************************************************************/
146
147static ACPI_STATUS
159AcpiCmBuildExternalSimpleObject (
160 ACPI_OPERAND_OBJECT *InternalObj,
161 ACPI_OBJECT *ExternalObj,
148AcpiCmCopyIsimpleToEsimple (
149 ACPI_OPERAND_OBJECT *InternalObject,
150 ACPI_OBJECT *ExternalObject,
162 UINT8 *DataSpace,
163 UINT32 *BufferSpaceUsed)
164{
165 UINT32 Length = 0;
151 UINT8 *DataSpace,
152 UINT32 *BufferSpaceUsed)
153{
154 UINT32 Length = 0;
166 UINT8 *SourcePtr = NULL;
155 ACPI_STATUS Status = AE_OK;
167
168
156
157
169 FUNCTION_TRACE ("CmBuildExternalSimpleObject");
158 FUNCTION_TRACE ("CmCopyIsimpleToEsimple");
170
171
172 /*
173 * Check for NULL object case (could be an uninitialized
174 * package element
175 */
176
159
160
161 /*
162 * Check for NULL object case (could be an uninitialized
163 * package element
164 */
165
177 if (!InternalObj)
166 if (!InternalObject)
178 {
179 *BufferSpaceUsed = 0;
180 return_ACPI_STATUS (AE_OK);
181 }
182
183 /* Always clear the external object */
184
167 {
168 *BufferSpaceUsed = 0;
169 return_ACPI_STATUS (AE_OK);
170 }
171
172 /* Always clear the external object */
173
185 MEMSET (ExternalObj, 0, sizeof (ACPI_OBJECT));
174 MEMSET (ExternalObject, 0, sizeof (ACPI_OBJECT));
186
187 /*
188 * In general, the external object will be the same type as
189 * the internal object
190 */
191
175
176 /*
177 * In general, the external object will be the same type as
178 * the internal object
179 */
180
192 ExternalObj->Type = InternalObj->Common.Type;
181 ExternalObject->Type = InternalObject->Common.Type;
193
194 /* However, only a limited number of external types are supported */
195
182
183 /* However, only a limited number of external types are supported */
184
196 switch (ExternalObj->Type)
185 switch (InternalObject->Common.Type)
197 {
198
199 case ACPI_TYPE_STRING:
200
186 {
187
188 case ACPI_TYPE_STRING:
189
201 Length = InternalObj->String.Length + 1;
202 ExternalObj->String.Length = InternalObj->String.Length;
203 ExternalObj->String.Pointer = (NATIVE_CHAR *) DataSpace;
204 SourcePtr = (UINT8 *) InternalObj->String.Pointer;
190 Length = InternalObject->String.Length + 1;
191 ExternalObject->String.Length = InternalObject->String.Length;
192 ExternalObject->String.Pointer = (NATIVE_CHAR *) DataSpace;
193 MEMCPY ((void *) DataSpace, (void *) InternalObject->String.Pointer, Length);
205 break;
206
207
208 case ACPI_TYPE_BUFFER:
209
194 break;
195
196
197 case ACPI_TYPE_BUFFER:
198
210 Length = InternalObj->Buffer.Length;
211 ExternalObj->Buffer.Length = InternalObj->Buffer.Length;
212 ExternalObj->Buffer.Pointer = DataSpace;
213 SourcePtr = (UINT8 *) InternalObj->Buffer.Pointer;
199 Length = InternalObject->Buffer.Length;
200 ExternalObject->Buffer.Length = InternalObject->Buffer.Length;
201 ExternalObject->Buffer.Pointer = DataSpace;
202 MEMCPY ((void *) DataSpace, (void *) InternalObject->Buffer.Pointer, Length);
214 break;
215
216
217 case ACPI_TYPE_INTEGER:
218
203 break;
204
205
206 case ACPI_TYPE_INTEGER:
207
219 ExternalObj->Integer.Value= InternalObj->Integer.Value;
208 ExternalObject->Integer.Value= InternalObject->Integer.Value;
220 break;
221
222
223 case INTERNAL_TYPE_REFERENCE:
224
225 /*
209 break;
210
211
212 case INTERNAL_TYPE_REFERENCE:
213
214 /*
226 * This is an object reference. We use the object type of "Any"
227 * to indicate a reference object containing a handle to an ACPI
228 * named object.
215 * This is an object reference. Attempt to dereference it.
229 */
230
216 */
217
231 ExternalObj->Type = ACPI_TYPE_ANY;
232 ExternalObj->Reference.Handle = InternalObj->Reference.Node;
233 break;
218 switch (InternalObject->Reference.OpCode)
219 {
220 case AML_ZERO_OP:
221 ExternalObject->Type = ACPI_TYPE_INTEGER;
222 ExternalObject->Integer.Value = 0;
223 break;
234
224
225 case AML_ONE_OP:
226 ExternalObject->Type = ACPI_TYPE_INTEGER;
227 ExternalObject->Integer.Value = 1;
228 break;
235
229
236 case ACPI_TYPE_PROCESSOR:
230 case AML_ONES_OP:
231 ExternalObject->Type = ACPI_TYPE_INTEGER;
232 ExternalObject->Integer.Value = ACPI_INTEGER_MAX;
233 break;
237
234
238 ExternalObj->Processor.ProcId =
239 InternalObj->Processor.ProcId;
235 case AML_NAMEPATH_OP:
236 /*
237 * This is a named reference, get the string. We already know that
238 * we have room for it, use max length
239 */
240 Length = MAX_STRING_LENGTH;
241 ExternalObject->Type = ACPI_TYPE_STRING;
242 ExternalObject->String.Pointer = (NATIVE_CHAR *) DataSpace;
243 Status = AcpiNsHandleToPathname ((ACPI_HANDLE *) InternalObject->Reference.Node,
244 &Length, (char *) DataSpace);
245 break;
240
246
241 ExternalObj->Processor.PblkAddress =
242 InternalObj->Processor.Address;
247 default:
248 /*
249 * Use the object type of "Any" to indicate a reference
250 * to object containing a handle to an ACPI named object.
251 */
252 ExternalObject->Type = ACPI_TYPE_ANY;
253 ExternalObject->Reference.Handle = InternalObject->Reference.Node;
254 break;
255 }
256 break;
243
257
244 ExternalObj->Processor.PblkLength =
245 InternalObj->Processor.Length;
258
259 case ACPI_TYPE_PROCESSOR:
260
261 ExternalObject->Processor.ProcId = InternalObject->Processor.ProcId;
262 ExternalObject->Processor.PblkAddress = InternalObject->Processor.Address;
263 ExternalObject->Processor.PblkLength = InternalObject->Processor.Length;
246 break;
247
264 break;
265
266
248 case ACPI_TYPE_POWER:
249
267 case ACPI_TYPE_POWER:
268
250 ExternalObj->PowerResource.SystemLevel =
251 InternalObj->PowerResource.SystemLevel;
269 ExternalObject->PowerResource.SystemLevel =
270 InternalObject->PowerResource.SystemLevel;
252
271
253 ExternalObj->PowerResource.ResourceOrder =
254 InternalObj->PowerResource.ResourceOrder;
272 ExternalObject->PowerResource.ResourceOrder =
273 InternalObject->PowerResource.ResourceOrder;
255 break;
256
274 break;
275
276
257 default:
277 default:
258 return_ACPI_STATUS (AE_CTRL_RETURN_VALUE);
278 /*
279 * There is no corresponding external object type
280 */
281 return_ACPI_STATUS (AE_SUPPORT);
259 break;
260 }
261
262
282 break;
283 }
284
285
263 /* Copy data if necessary (strings or buffers) */
264
286
265 if (Length)
287 *BufferSpaceUsed = (UINT32) ROUND_UP_TO_NATIVE_WORD (Length);
288
289 return_ACPI_STATUS (Status);
290}
291
292
293/*******************************************************************************
294 *
295 * FUNCTION: AcpiCmCopyIelementToEelement
296 *
297 * PARAMETERS: ACPI_PKG_CALLBACK
298 *
299 * RETURN: Status
300 *
301 * DESCRIPTION: Copy one package element to another package element
302 *
303 ******************************************************************************/
304
305ACPI_STATUS
306AcpiCmCopyIelementToEelement (
307 UINT8 ObjectType,
308 ACPI_OPERAND_OBJECT *SourceObject,
309 ACPI_GENERIC_STATE *State,
310 void *Context)
311{
312 ACPI_STATUS Status = AE_OK;
313 ACPI_PKG_INFO *Info = (ACPI_PKG_INFO *) Context;
314 UINT32 ObjectSpace;
315 UINT32 ThisIndex;
316 ACPI_OBJECT *TargetObject;
317
318
319
320 ThisIndex = State->Pkg.Index;
321 TargetObject = (ACPI_OBJECT *)
322 &((ACPI_OBJECT *)(State->Pkg.DestObject))->Package.Elements[ThisIndex];
323
324
325 switch (ObjectType)
266 {
326 {
327 case 0:
328
267 /*
329 /*
268 * Copy the return data to the caller's buffer
330 * This is a simple or null object -- get the size
269 */
331 */
270 MEMCPY ((void *) DataSpace, (void *) SourcePtr, Length);
332
333 Status = AcpiCmCopyIsimpleToEsimple (SourceObject,
334 TargetObject, Info->FreeSpace, &ObjectSpace);
335 if (ACPI_FAILURE (Status))
336 {
337 return (Status);
338 }
339
340 break;
341
342 case 1:
343
344 /*
345 * Build the package object
346 */
347 TargetObject->Type = ACPI_TYPE_PACKAGE;
348 TargetObject->Package.Count = SourceObject->Package.Count;
349 TargetObject->Package.Elements = (ACPI_OBJECT *) Info->FreeSpace;
350
351 /*
352 * Pass the new package object back to the package walk routine
353 */
354 State->Pkg.ThisTargetObj = TargetObject;
355
356 /*
357 * Save space for the array of objects (Package elements)
358 * update the buffer length counter
359 */
360 ObjectSpace = (UINT32) ROUND_UP_TO_NATIVE_WORD (
361 TargetObject->Package.Count * sizeof (ACPI_OBJECT));
362 break;
363
364 default:
365 return (AE_BAD_PARAMETER);
271 }
272
273
366 }
367
368
274 *BufferSpaceUsed = (UINT32) ROUND_UP_TO_NATIVE_WORD (Length);
369 Info->FreeSpace += ObjectSpace;
370 Info->Length += ObjectSpace;
275
371
276 return_ACPI_STATUS (AE_OK);
372 return (Status);
277}
278
279
373}
374
375
280/******************************************************************************
376/*******************************************************************************
281 *
377 *
282 * FUNCTION: AcpiCmBuildExternalPackageObject
378 * FUNCTION: AcpiCmCopyIpackageToEpackage
283 *
379 *
284 * PARAMETERS: *InternalObj - Pointer to the object we are returning
285 * *Buffer - Where the object is returned
286 * *SpaceUsed - Where the object length is returned
380 * PARAMETERS: *InternalObject - Pointer to the object we are returning
381 * *Buffer - Where the object is returned
382 * *SpaceUsed - Where the object length is returned
287 *
383 *
288 * RETURN: Status - the status of the call
384 * RETURN: Status
289 *
290 * DESCRIPTION: This function is called to place a package object in a user
291 * buffer. A package object by definition contains other objects.
292 *
293 * The buffer is assumed to have sufficient space for the object.
294 * The caller must have verified the buffer length needed using the
295 * AcpiCmGetObjectSize function before calling this function.
296 *
297 ******************************************************************************/
298
299static ACPI_STATUS
385 *
386 * DESCRIPTION: This function is called to place a package object in a user
387 * buffer. A package object by definition contains other objects.
388 *
389 * The buffer is assumed to have sufficient space for the object.
390 * The caller must have verified the buffer length needed using the
391 * AcpiCmGetObjectSize function before calling this function.
392 *
393 ******************************************************************************/
394
395static ACPI_STATUS
300AcpiCmBuildExternalPackageObject (
301 ACPI_OPERAND_OBJECT *InternalObj,
396AcpiCmCopyIpackageToEpackage (
397 ACPI_OPERAND_OBJECT *InternalObject,
302 UINT8 *Buffer,
303 UINT32 *SpaceUsed)
304{
398 UINT8 *Buffer,
399 UINT32 *SpaceUsed)
400{
305 UINT8 *FreeSpace;
306 ACPI_OBJECT *ExternalObj;
307 UINT32 CurrentDepth = 0;
401 ACPI_OBJECT *ExternalObject;
308 ACPI_STATUS Status;
402 ACPI_STATUS Status;
309 UINT32 Length = 0;
310 UINT32 ThisIndex;
311 UINT32 ObjectSpace;
312 ACPI_OPERAND_OBJECT *ThisInternalObj;
313 ACPI_OBJECT *ThisExternalObj;
314 PKG_SEARCH_INFO *LevelPtr;
403 ACPI_PKG_INFO Info;
315
316
404
405
317 FUNCTION_TRACE ("CmBuildExternalPackageObject");
406 FUNCTION_TRACE ("CmCopyIpackageToEpackage");
318
319
320 /*
321 * First package at head of the buffer
322 */
407
408
409 /*
410 * First package at head of the buffer
411 */
323 ExternalObj = (ACPI_OBJECT *) Buffer;
412 ExternalObject = (ACPI_OBJECT *) Buffer;
324
325 /*
326 * Free space begins right after the first package
327 */
413
414 /*
415 * Free space begins right after the first package
416 */
328 FreeSpace = Buffer + ROUND_UP_TO_NATIVE_WORD (sizeof (ACPI_OBJECT));
417 Info.Length = 0;
418 Info.ObjectSpace = 0;
419 Info.NumPackages = 1;
420 Info.FreeSpace = Buffer + ROUND_UP_TO_NATIVE_WORD (sizeof (ACPI_OBJECT));
329
330
421
422
331 /*
332 * Initialize the working variables
333 */
334
423
335 MEMSET ((void *) Level, 0, sizeof (Level));
424 ExternalObject->Type = InternalObject->Common.Type;
425 ExternalObject->Package.Count = InternalObject->Package.Count;
426 ExternalObject->Package.Elements = (ACPI_OBJECT *) Info.FreeSpace;
336
427
337 Level[0].InternalObj = InternalObj;
338 Level[0].ExternalObj = ExternalObj;
339 Level[0].Index = 0;
340 LevelPtr = &Level[0];
341 CurrentDepth = 0;
342
428
343 ExternalObj->Type = InternalObj->Common.Type;
344 ExternalObj->Package.Count = InternalObj->Package.Count;
345 ExternalObj->Package.Elements = (ACPI_OBJECT *) FreeSpace;
346
347
348 /*
349 * Build an array of ACPI_OBJECTS in the buffer
350 * and move the free space past it
351 */
352
429 /*
430 * Build an array of ACPI_OBJECTS in the buffer
431 * and move the free space past it
432 */
433
353 FreeSpace += ExternalObj->Package.Count *
354 ROUND_UP_TO_NATIVE_WORD (sizeof (ACPI_OBJECT));
434 Info.FreeSpace += ExternalObject->Package.Count *
435 ROUND_UP_TO_NATIVE_WORD (sizeof (ACPI_OBJECT));
355
356
436
437
357 while (1)
358 {
359 ThisIndex = LevelPtr->Index;
360 ThisInternalObj =
361 (ACPI_OPERAND_OBJECT *)
362 LevelPtr->InternalObj->Package.Elements[ThisIndex];
363 ThisExternalObj =
364 (ACPI_OBJECT *)
365 &LevelPtr->ExternalObj->Package.Elements[ThisIndex];
438 Status = AcpiCmWalkPackageTree (InternalObject, ExternalObject,
439 AcpiCmCopyIelementToEelement, &Info);
366
440
441 *SpaceUsed = Info.Length;
367
442
368 /*
369 * Check for
370 * 1) Null object -- OK, this can happen if package
371 * element is never initialized
372 * 2) Not an internal object - can be Node instead
373 * 3) Any internal object other than a package.
374 *
375 * The more complex package case is handled later
376 */
443 return_ACPI_STATUS (Status);
377
444
378 if ((!ThisInternalObj) ||
379 (!VALID_DESCRIPTOR_TYPE (
380 ThisInternalObj, ACPI_DESC_TYPE_INTERNAL)) ||
381 (!IS_THIS_OBJECT_TYPE (
382 ThisInternalObj, ACPI_TYPE_PACKAGE)))
383 {
384 /*
385 * This is a simple or null object -- get the size
386 */
387
388 Status =
389 AcpiCmBuildExternalSimpleObject (ThisInternalObj,
390 ThisExternalObj,
391 FreeSpace,
392 &ObjectSpace);
393 if (ACPI_FAILURE (Status))
394 {
395 return_ACPI_STATUS (Status);
396 }
397
398 FreeSpace += ObjectSpace;
399 Length += ObjectSpace;
400
401 LevelPtr->Index++;
402 while (LevelPtr->Index >=
403 LevelPtr->InternalObj->Package.Count)
404 {
405 /*
406 * We've handled all of the objects at this
407 * level. This means that we have just
408 * completed a package. That package may
409 * have contained one or more packages
410 * itself
411 */
412 if (CurrentDepth == 0)
413 {
414 /*
415 * We have handled all of the objects
416 * in the top level package just add
417 * the length of the package objects
418 * and get out
419 */
420 *SpaceUsed = Length;
421 return_ACPI_STATUS (AE_OK);
422 }
423
424 /*
425 * go back up a level and move the index
426 * past the just completed package object.
427 */
428 CurrentDepth--;
429 LevelPtr = &Level[CurrentDepth];
430 LevelPtr->Index++;
431 }
432 }
433
434
435 else
436 {
437 /*
438 * This object is a package
439 * -- we must go one level deeper
440 */
441 if (CurrentDepth >= MAX_PACKAGE_DEPTH-1)
442 {
443 /*
444 * Too many nested levels of packages
445 * for us to handle
446 */
447 DEBUG_PRINT (ACPI_ERROR,
448 ("CmBuildPackageObject: Pkg nested too deep (max %X)\n",
449 MAX_PACKAGE_DEPTH));
450 return_ACPI_STATUS (AE_LIMIT);
451 }
452
453 /*
454 * Build the package object
455 */
456 ThisExternalObj->Type = ACPI_TYPE_PACKAGE;
457 ThisExternalObj->Package.Count =
458 ThisInternalObj->Package.Count;
459 ThisExternalObj->Package.Elements =
460 (ACPI_OBJECT *) FreeSpace;
461
462 /*
463 * Save space for the array of objects (Package elements)
464 * update the buffer length counter
465 */
466 ObjectSpace = (UINT32) ROUND_UP_TO_NATIVE_WORD (
467 ThisExternalObj->Package.Count *
468 sizeof (ACPI_OBJECT));
469
470 FreeSpace += ObjectSpace;
471 Length += ObjectSpace;
472
473 CurrentDepth++;
474 LevelPtr = &Level[CurrentDepth];
475 LevelPtr->InternalObj = ThisInternalObj;
476 LevelPtr->ExternalObj = ThisExternalObj;
477 LevelPtr->Index = 0;
478 }
479 }
480}
481
445}
446
482
483/******************************************************************************
447/*******************************************************************************
484 *
448 *
485 * FUNCTION: AcpiCmBuildExternalObject
449 * FUNCTION: AcpiCmCopyIobjectToEobject
486 *
450 *
487 * PARAMETERS: *InternalObj - The internal object to be converted
488 * *BufferPtr - Where the object is returned
451 * PARAMETERS: *InternalObject - The internal object to be converted
452 * *BufferPtr - Where the object is returned
489 *
453 *
490 * RETURN: Status - the status of the call
454 * RETURN: Status
491 *
492 * DESCRIPTION: This function is called to build an API object to be returned to
493 * the caller.
494 *
495 ******************************************************************************/
496
497ACPI_STATUS
455 *
456 * DESCRIPTION: This function is called to build an API object to be returned to
457 * the caller.
458 *
459 ******************************************************************************/
460
461ACPI_STATUS
498AcpiCmBuildExternalObject (
499 ACPI_OPERAND_OBJECT *InternalObj,
462AcpiCmCopyIobjectToEobject (
463 ACPI_OPERAND_OBJECT *InternalObject,
500 ACPI_BUFFER *RetBuffer)
501{
502 ACPI_STATUS Status;
503
504
464 ACPI_BUFFER *RetBuffer)
465{
466 ACPI_STATUS Status;
467
468
505 FUNCTION_TRACE ("CmBuildExternalObject");
469 FUNCTION_TRACE ("CmCopyIobjectToEobject");
506
507
470
471
508 if (IS_THIS_OBJECT_TYPE (InternalObj, ACPI_TYPE_PACKAGE))
472 if (IS_THIS_OBJECT_TYPE (InternalObject, ACPI_TYPE_PACKAGE))
509 {
510 /*
473 {
474 /*
511 * Package objects contain other objects (which can be objects)
512 * buildpackage does it all
475 * Package object: Copy all subobjects (including
476 * nested packages)
513 */
477 */
514 Status =
515 AcpiCmBuildExternalPackageObject (InternalObj,
516 RetBuffer->Pointer,
517 &RetBuffer->Length);
478 Status = AcpiCmCopyIpackageToEpackage (InternalObject,
479 RetBuffer->Pointer, &RetBuffer->Length);
518 }
519
520 else
521 {
522 /*
523 * Build a simple object (no nested objects)
524 */
480 }
481
482 else
483 {
484 /*
485 * Build a simple object (no nested objects)
486 */
525 Status =
526 AcpiCmBuildExternalSimpleObject (InternalObj,
527 (ACPI_OBJECT *) RetBuffer->Pointer,
528 ((UINT8 *) RetBuffer->Pointer +
529 ROUND_UP_TO_NATIVE_WORD (
530 sizeof (ACPI_OBJECT))),
531 &RetBuffer->Length);
487 Status = AcpiCmCopyIsimpleToEsimple (InternalObject,
488 (ACPI_OBJECT *) RetBuffer->Pointer,
489 ((UINT8 *) RetBuffer->Pointer +
490 ROUND_UP_TO_NATIVE_WORD (sizeof (ACPI_OBJECT))),
491 &RetBuffer->Length);
532 /*
533 * build simple does not include the object size in the length
534 * so we add it in here
535 */
536 RetBuffer->Length += sizeof (ACPI_OBJECT);
537 }
538
539 return_ACPI_STATUS (Status);
540}
541
542
492 /*
493 * build simple does not include the object size in the length
494 * so we add it in here
495 */
496 RetBuffer->Length += sizeof (ACPI_OBJECT);
497 }
498
499 return_ACPI_STATUS (Status);
500}
501
502
543/******************************************************************************
503
504/*******************************************************************************
544 *
505 *
545 * FUNCTION: AcpiCmBuildInternalSimpleObject
506 * FUNCTION: AcpiCmCopyEsimpleToIsimple
546 *
507 *
547 * PARAMETERS: *ExternalObj - The external object to be converted
548 * *InternalObj - Where the internal object is returned
508 * PARAMETERS: *ExternalObject - The external object to be converted
509 * *InternalObject - Where the internal object is returned
549 *
510 *
550 * RETURN: Status - the status of the call
511 * RETURN: Status
551 *
552 * DESCRIPTION: This function copies an external object to an internal one.
553 * NOTE: Pointers can be copied, we don't need to copy data.
554 * (The pointers have to be valid in our address space no matter
555 * what we do with them!)
556 *
557 ******************************************************************************/
558
559ACPI_STATUS
512 *
513 * DESCRIPTION: This function copies an external object to an internal one.
514 * NOTE: Pointers can be copied, we don't need to copy data.
515 * (The pointers have to be valid in our address space no matter
516 * what we do with them!)
517 *
518 ******************************************************************************/
519
520ACPI_STATUS
560AcpiCmBuildInternalSimpleObject (
561 ACPI_OBJECT *ExternalObj,
562 ACPI_OPERAND_OBJECT *InternalObj)
521AcpiCmCopyEsimpleToIsimple (
522 ACPI_OBJECT *ExternalObject,
523 ACPI_OPERAND_OBJECT *InternalObject)
563{
564
524{
525
565 FUNCTION_TRACE ("CmBuildInternalSimpleObject");
526 FUNCTION_TRACE ("CmCopyEsimpleToIsimple");
566
567
527
528
568 InternalObj->Common.Type = (UINT8) ExternalObj->Type;
529 InternalObject->Common.Type = (UINT8) ExternalObject->Type;
569
530
570 switch (ExternalObj->Type)
531 switch (ExternalObject->Type)
571 {
572
573 case ACPI_TYPE_STRING:
574
532 {
533
534 case ACPI_TYPE_STRING:
535
575 InternalObj->String.Length = ExternalObj->String.Length;
576 InternalObj->String.Pointer = ExternalObj->String.Pointer;
536 InternalObject->String.Length = ExternalObject->String.Length;
537 InternalObject->String.Pointer = ExternalObject->String.Pointer;
577 break;
578
579
580 case ACPI_TYPE_BUFFER:
581
538 break;
539
540
541 case ACPI_TYPE_BUFFER:
542
582 InternalObj->Buffer.Length = ExternalObj->Buffer.Length;
583 InternalObj->Buffer.Pointer = ExternalObj->Buffer.Pointer;
543 InternalObject->Buffer.Length = ExternalObject->Buffer.Length;
544 InternalObject->Buffer.Pointer = ExternalObject->Buffer.Pointer;
584 break;
585
586
587 case ACPI_TYPE_INTEGER:
588 /*
589 * Number is included in the object itself
590 */
545 break;
546
547
548 case ACPI_TYPE_INTEGER:
549 /*
550 * Number is included in the object itself
551 */
591 InternalObj->Integer.Value = ExternalObj->Integer.Value;
552 InternalObject->Integer.Value = ExternalObject->Integer.Value;
592 break;
593
594
595 default:
596 return_ACPI_STATUS (AE_CTRL_RETURN_VALUE);
597 break;
598 }
599
600
601 return_ACPI_STATUS (AE_OK);
602}
603
604
605#ifdef ACPI_FUTURE_IMPLEMENTATION
606
607/* Code to convert packages that are parameters to control methods */
608
553 break;
554
555
556 default:
557 return_ACPI_STATUS (AE_CTRL_RETURN_VALUE);
558 break;
559 }
560
561
562 return_ACPI_STATUS (AE_OK);
563}
564
565
566#ifdef ACPI_FUTURE_IMPLEMENTATION
567
568/* Code to convert packages that are parameters to control methods */
569
609/******************************************************************************
570/*******************************************************************************
610 *
571 *
611 * FUNCTION: AcpiCmBuildInternalPackageObject
572 * FUNCTION: AcpiCmCopyEpackageToIpackage
612 *
573 *
613 * PARAMETERS: *InternalObj - Pointer to the object we are returning
574 * PARAMETERS: *InternalObject - Pointer to the object we are returning
614 * *Buffer - Where the object is returned
615 * *SpaceUsed - Where the length of the object is returned
616 *
617 * RETURN: Status - the status of the call
618 *
619 * DESCRIPTION: This function is called to place a package object in a user
620 * buffer. A package object by definition contains other objects.
621 *
622 * The buffer is assumed to have sufficient space for the object.
623 * The caller must have verified the buffer length needed using the
624 * AcpiCmGetObjectSize function before calling this function.
625 *
626 ******************************************************************************/
627
628static ACPI_STATUS
575 * *Buffer - Where the object is returned
576 * *SpaceUsed - Where the length of the object is returned
577 *
578 * RETURN: Status - the status of the call
579 *
580 * DESCRIPTION: This function is called to place a package object in a user
581 * buffer. A package object by definition contains other objects.
582 *
583 * The buffer is assumed to have sufficient space for the object.
584 * The caller must have verified the buffer length needed using the
585 * AcpiCmGetObjectSize function before calling this function.
586 *
587 ******************************************************************************/
588
589static ACPI_STATUS
629AcpiCmBuildInternalPackageObject (
630 ACPI_OPERAND_OBJECT *InternalObj,
590AcpiCmCopyEpackageToIpackage (
591 ACPI_OPERAND_OBJECT *InternalObject,
631 UINT8 *Buffer,
632 UINT32 *SpaceUsed)
633{
634 UINT8 *FreeSpace;
592 UINT8 *Buffer,
593 UINT32 *SpaceUsed)
594{
595 UINT8 *FreeSpace;
635 ACPI_OBJECT *ExternalObj;
636 UINT32 CurrentDepth = 0;
596 ACPI_OBJECT *ExternalObject;
637 UINT32 Length = 0;
638 UINT32 ThisIndex;
639 UINT32 ObjectSpace = 0;
640 ACPI_OPERAND_OBJECT *ThisInternalObj;
641 ACPI_OBJECT *ThisExternalObj;
597 UINT32 Length = 0;
598 UINT32 ThisIndex;
599 UINT32 ObjectSpace = 0;
600 ACPI_OPERAND_OBJECT *ThisInternalObj;
601 ACPI_OBJECT *ThisExternalObj;
642 PKG_SEARCH_INFO *LevelPtr;
643
644
602
603
645 FUNCTION_TRACE ("CmBuildInternalPackageObject");
604 FUNCTION_TRACE ("CmCopyEpackageToIpackage");
646
647
648 /*
649 * First package at head of the buffer
650 */
605
606
607 /*
608 * First package at head of the buffer
609 */
651 ExternalObj = (ACPI_OBJECT *)Buffer;
610 ExternalObject = (ACPI_OBJECT *)Buffer;
652
653 /*
654 * Free space begins right after the first package
655 */
656 FreeSpace = Buffer + sizeof(ACPI_OBJECT);
657
658
611
612 /*
613 * Free space begins right after the first package
614 */
615 FreeSpace = Buffer + sizeof(ACPI_OBJECT);
616
617
659 /*
660 * Initialize the working variables
661 */
618 ExternalObject->Type = InternalObject->Common.Type;
619 ExternalObject->Package.Count = InternalObject->Package.Count;
620 ExternalObject->Package.Elements = (ACPI_OBJECT *)FreeSpace;
662
621
663 MEMSET ((void *) Level, 0, sizeof(Level));
664
622
665 Level[0].InternalObj = InternalObj;
666 Level[0].ExternalObj = ExternalObj;
667 LevelPtr = &Level[0];
668 CurrentDepth = 0;
669
670 ExternalObj->Type = InternalObj->Common.Type;
671 ExternalObj->Package.Count = InternalObj->Package.Count;
672 ExternalObj->Package.Elements = (ACPI_OBJECT *)FreeSpace;
673
674
675 /*
676 * Build an array of ACPI_OBJECTS in the buffer
677 * and move the free space past it
678 */
679
623 /*
624 * Build an array of ACPI_OBJECTS in the buffer
625 * and move the free space past it
626 */
627
680 FreeSpace += ExternalObj->Package.Count * sizeof(ACPI_OBJECT);
628 FreeSpace += ExternalObject->Package.Count * sizeof(ACPI_OBJECT);
681
682
629
630
683 while (1)
684 {
685 ThisIndex = LevelPtr->Index;
631 /* Call WalkPackage */
686
632
687 ThisInternalObj = (ACPI_OPERAND_OBJECT *)
688 &LevelPtr->InternalObj->Package.Elements[ThisIndex];
689
690 ThisExternalObj = (ACPI_OBJECT *)
691 &LevelPtr->ExternalObj->Package.Elements[ThisIndex];
692
693 if (IS_THIS_OBJECT_TYPE (ThisInternalObj, ACPI_TYPE_PACKAGE))
694 {
695 /*
696 * If this object is a package then we go one deeper
697 */
698 if (CurrentDepth >= MAX_PACKAGE_DEPTH-1)
699 {
700 /*
701 * Too many nested levels of packages for us to handle
702 */
703 DEBUG_PRINT (ACPI_ERROR,
704 ("CmBuildPackageObject: Pkg nested too deep (max %X)\n",
705 MAX_PACKAGE_DEPTH));
706 return_ACPI_STATUS (AE_LIMIT);
707 }
708
709 /*
710 * Build the package object
711 */
712 ThisExternalObj->Type = ACPI_TYPE_PACKAGE;
713 ThisExternalObj->Package.Count = ThisInternalObj->Package.Count;
714 ThisExternalObj->Package.Elements = (ACPI_OBJECT *) FreeSpace;
715
716 /*
717 * Save space for the array of objects (Package elements)
718 * update the buffer length counter
719 */
720 ObjectSpace = ThisExternalObj->Package.Count *
721 sizeof (ACPI_OBJECT);
722
723 FreeSpace += ObjectSpace;
724 Length += ObjectSpace;
725
726 CurrentDepth++;
727 LevelPtr = &Level[CurrentDepth];
728 LevelPtr->InternalObj = ThisInternalObj;
729 LevelPtr->ExternalObj = ThisExternalObj;
730 LevelPtr->Index = 0;
731
732 } /* if object is a package */
733
734 else
735 {
736 FreeSpace += ObjectSpace;
737 Length += ObjectSpace;
738
739 LevelPtr->Index++;
740 while (LevelPtr->Index >=
741 LevelPtr->InternalObj->Package.Count)
742 {
743 /*
744 * We've handled all of the objects at
745 * this level, This means that we have
746 * just completed a package. That package
747 * may have contained one or more packages
748 * itself
749 */
750 if (CurrentDepth == 0)
751 {
752 /*
753 * We have handled all of the objects
754 * in the top level package just add
755 * the length of the package objects
756 * and get out
757 */
758 *SpaceUsed = Length;
759 return_ACPI_STATUS (AE_OK);
760 }
761
762 /*
763 * go back up a level and move the index
764 * past the just completed package object.
765 */
766 CurrentDepth--;
767 LevelPtr = &Level[CurrentDepth];
768 LevelPtr->Index++;
769 }
770 } /* else object is NOT a package */
771 } /* while (1) */
772}
773
774#endif /* Future implementation */
775
776
633}
634
635#endif /* Future implementation */
636
637
777/******************************************************************************
638/*******************************************************************************
778 *
639 *
779 * FUNCTION: AcpiCmBuildInternalObject
640 * FUNCTION: AcpiCmCopyEobjectToIobject
780 *
641 *
781 * PARAMETERS: *InternalObj - The external object to be converted
642 * PARAMETERS: *InternalObject - The external object to be converted
782 * *BufferPtr - Where the internal object is returned
783 *
784 * RETURN: Status - the status of the call
785 *
786 * DESCRIPTION: Converts an external object to an internal object.
787 *
788 ******************************************************************************/
789
790ACPI_STATUS
643 * *BufferPtr - Where the internal object is returned
644 *
645 * RETURN: Status - the status of the call
646 *
647 * DESCRIPTION: Converts an external object to an internal object.
648 *
649 ******************************************************************************/
650
651ACPI_STATUS
791AcpiCmBuildInternalObject (
792 ACPI_OBJECT *ExternalObj,
793 ACPI_OPERAND_OBJECT *InternalObj)
652AcpiCmCopyEobjectToIobject (
653 ACPI_OBJECT *ExternalObject,
654 ACPI_OPERAND_OBJECT *InternalObject)
794{
795 ACPI_STATUS Status;
796
797
655{
656 ACPI_STATUS Status;
657
658
798 FUNCTION_TRACE ("CmBuildInternalObject");
659 FUNCTION_TRACE ("AcpiCmCopyEobjectToIobject");
799
800
660
661
801 if (ExternalObj->Type == ACPI_TYPE_PACKAGE)
662 if (ExternalObject->Type == ACPI_TYPE_PACKAGE)
802 {
803 /*
804 * Package objects contain other objects (which can be objects)
805 * buildpackage does it all
806 *
807 * TBD: Package conversion must be completed and tested
808 * NOTE: this code converts packages as input parameters to
809 * control methods only. This is a very, very rare case.
810 */
811/*
663 {
664 /*
665 * Package objects contain other objects (which can be objects)
666 * buildpackage does it all
667 *
668 * TBD: Package conversion must be completed and tested
669 * NOTE: this code converts packages as input parameters to
670 * control methods only. This is a very, very rare case.
671 */
672/*
812 Status = AcpiCmBuildInternalPackageObject(InternalObj,
673 Status = AcpiCmCopyEpackageToIpackage(InternalObject,
813 RetBuffer->Pointer,
814 &RetBuffer->Length);
815*/
816 DEBUG_PRINT (ACPI_ERROR,
674 RetBuffer->Pointer,
675 &RetBuffer->Length);
676*/
677 DEBUG_PRINT (ACPI_ERROR,
817 ("CmBuildInternalObject: Packages as parameters not implemented!\n"));
678 ("AcpiCmCopyEobjectToIobject: Packages as parameters not implemented!\n"));
818
819 return_ACPI_STATUS (AE_NOT_IMPLEMENTED);
820 }
821
822 else
823 {
824 /*
825 * Build a simple object (no nested objects)
826 */
679
680 return_ACPI_STATUS (AE_NOT_IMPLEMENTED);
681 }
682
683 else
684 {
685 /*
686 * Build a simple object (no nested objects)
687 */
827 Status = AcpiCmBuildInternalSimpleObject (ExternalObj, InternalObj);
688 Status = AcpiCmCopyEsimpleToIsimple (ExternalObject, InternalObject);
828 /*
829 * build simple does not include the object size in the length
830 * so we add it in here
831 */
832 }
833
834 return_ACPI_STATUS (Status);
835}
836
689 /*
690 * build simple does not include the object size in the length
691 * so we add it in here
692 */
693 }
694
695 return_ACPI_STATUS (Status);
696}
697
698
699
700/*******************************************************************************
701 *
702 * FUNCTION: AcpiCmCopyIelementToIelement
703 *
704 * PARAMETERS: ACPI_PKG_CALLBACK
705 *
706 * RETURN: Status - the status of the call
707 *
708 * DESCRIPTION: Copy one package element to another package element
709 *
710 ******************************************************************************/
711
712ACPI_STATUS
713AcpiCmCopyIelementToIelement (
714 UINT8 ObjectType,
715 ACPI_OPERAND_OBJECT *SourceObject,
716 ACPI_GENERIC_STATE *State,
717 void *Context)
718{
719 ACPI_STATUS Status = AE_OK;
720 UINT32 ThisIndex;
721 ACPI_OPERAND_OBJECT **ThisTargetPtr;
722 ACPI_OPERAND_OBJECT *TargetObject;
723
724
725
726 ThisIndex = State->Pkg.Index;
727 ThisTargetPtr = (ACPI_OPERAND_OBJECT **)
728 &State->Pkg.DestObject->Package.Elements[ThisIndex];
729
730 switch (ObjectType)
731 {
732 case 0:
733
734 /*
735 * This is a simple object, just copy it
736 */
737 TargetObject = AcpiCmCreateInternalObject (SourceObject->Common.Type);
738 if (!TargetObject)
739 {
740 return (AE_NO_MEMORY);
741 }
742
743 Status = AcpiAmlStoreObjectToObject (SourceObject, TargetObject,
744 (ACPI_WALK_STATE *) Context);
745 if (ACPI_FAILURE (Status))
746 {
747 return (Status);
748 }
749
750 *ThisTargetPtr = TargetObject;
751 break;
752
753
754 case 1:
755 /*
756 * This object is a package - go down another nesting level
757 * Create and build the package object
758 */
759 TargetObject = AcpiCmCreateInternalObject (ACPI_TYPE_PACKAGE);
760 if (!TargetObject)
761 {
762 /* TBD: must delete package created up to this point */
763
764 return (AE_NO_MEMORY);
765 }
766
767 TargetObject->Package.Count = SourceObject->Package.Count;
768
769 /*
770 * Pass the new package object back to the package walk routine
771 */
772 State->Pkg.ThisTargetObj = TargetObject;
773
774 /*
775 * Store the object pointer in the parent package object
776 */
777 *ThisTargetPtr = TargetObject;
778 break;
779
780 default:
781 return (AE_BAD_PARAMETER);
782 }
783
784
785 return (Status);
786}
787
788
789/*******************************************************************************
790 *
791 * FUNCTION: AcpiCmCopyIpackageToIpackage
792 *
793 * PARAMETERS: *SourceObj - Pointer to the source package object
794 * *DestObj - Where the internal object is returned
795 *
796 * RETURN: Status - the status of the call
797 *
798 * DESCRIPTION: This function is called to copy an internal package object
799 * into another internal package object.
800 *
801 ******************************************************************************/
802
803ACPI_STATUS
804AcpiCmCopyIpackageToIpackage (
805 ACPI_OPERAND_OBJECT *SourceObj,
806 ACPI_OPERAND_OBJECT *DestObj,
807 ACPI_WALK_STATE *WalkState)
808{
809 ACPI_STATUS Status = AE_OK;
810
811 FUNCTION_TRACE ("CmCopyIpackageToIpackage");
812
813
814
815 DestObj->Common.Type = SourceObj->Common.Type;
816 DestObj->Package.Count = SourceObj->Package.Count;
817
818
819 /*
820 * Create the object array and walk the source package tree
821 */
822
823 DestObj->Package.Elements = AcpiCmCallocate ((SourceObj->Package.Count + 1) *
824 sizeof (void *));
825 DestObj->Package.NextElement = DestObj->Package.Elements;
826
827 if (!DestObj->Package.Elements)
828 {
829 REPORT_ERROR (
830 ("AmlBuildCopyInternalPackageObject: Package allocation failure\n"));
831 return_ACPI_STATUS (AE_NO_MEMORY);
832 }
833
834
835 Status = AcpiCmWalkPackageTree (SourceObj, DestObj,
836 AcpiCmCopyIelementToIelement, WalkState);
837
838 return_ACPI_STATUS (Status);
839}
840