Print this page
acpica-unix2-20130823
PANKOVs restructure
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/intel/io/acpica/utilities/utcopy.c
+++ new/usr/src/common/acpica/components/utilities/utcopy.c
1 1 /******************************************************************************
2 2 *
3 3 * Module Name: utcopy - Internal to external object translation utilities
4 4 *
5 5 *****************************************************************************/
6 6
7 7 /*
8 - * Copyright (C) 2000 - 2011, Intel Corp.
8 + * Copyright (C) 2000 - 2013, Intel Corp.
9 9 * All rights reserved.
10 10 *
11 11 * Redistribution and use in source and binary forms, with or without
12 12 * modification, are permitted provided that the following conditions
13 13 * are met:
14 14 * 1. Redistributions of source code must retain the above copyright
15 15 * notice, this list of conditions, and the following disclaimer,
16 16 * without modification.
17 17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 18 * substantially similar to the "NO WARRANTY" disclaimer below
19 19 * ("Disclaimer") and any redistribution must be conditioned upon
20 20 * including a substantially similar Disclaimer requirement for further
21 21 * binary redistribution.
22 22 * 3. Neither the names of the above-listed copyright holders nor the names
23 23 * of any contributors may be used to endorse or promote products derived
24 24 * from this software without specific prior written permission.
25 25 *
26 26 * Alternatively, this software may be distributed under the terms of the
27 27 * GNU General Public License ("GPL") version 2 as published by the Free
28 28 * Software Foundation.
29 29 *
30 30 * NO WARRANTY
31 31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 41 * POSSIBILITY OF SUCH DAMAGES.
42 42 */
43 43
44 44 #define __UTCOPY_C__
45 45
46 46 #include "acpi.h"
47 47 #include "accommon.h"
48 48 #include "acnamesp.h"
49 49
50 50
51 51 #define _COMPONENT ACPI_UTILITIES
52 52 ACPI_MODULE_NAME ("utcopy")
53 53
54 54 /* Local prototypes */
55 55
56 56 static ACPI_STATUS
57 57 AcpiUtCopyIsimpleToEsimple (
58 58 ACPI_OPERAND_OBJECT *InternalObject,
59 59 ACPI_OBJECT *ExternalObject,
60 60 UINT8 *DataSpace,
61 61 ACPI_SIZE *BufferSpaceUsed);
62 62
63 63 static ACPI_STATUS
64 64 AcpiUtCopyIelementToIelement (
65 65 UINT8 ObjectType,
66 66 ACPI_OPERAND_OBJECT *SourceObject,
67 67 ACPI_GENERIC_STATE *State,
68 68 void *Context);
69 69
70 70 static ACPI_STATUS
71 71 AcpiUtCopyIpackageToEpackage (
72 72 ACPI_OPERAND_OBJECT *InternalObject,
73 73 UINT8 *Buffer,
74 74 ACPI_SIZE *SpaceUsed);
75 75
76 76 static ACPI_STATUS
77 77 AcpiUtCopyEsimpleToIsimple(
78 78 ACPI_OBJECT *UserObj,
79 79 ACPI_OPERAND_OBJECT **ReturnObj);
80 80
81 81 static ACPI_STATUS
82 82 AcpiUtCopyEpackageToIpackage (
83 83 ACPI_OBJECT *ExternalObject,
84 84 ACPI_OPERAND_OBJECT **InternalObject);
85 85
86 86 static ACPI_STATUS
87 87 AcpiUtCopySimpleObject (
88 88 ACPI_OPERAND_OBJECT *SourceDesc,
89 89 ACPI_OPERAND_OBJECT *DestDesc);
90 90
91 91 static ACPI_STATUS
92 92 AcpiUtCopyIelementToEelement (
93 93 UINT8 ObjectType,
94 94 ACPI_OPERAND_OBJECT *SourceObject,
95 95 ACPI_GENERIC_STATE *State,
96 96 void *Context);
97 97
98 98 static ACPI_STATUS
99 99 AcpiUtCopyIpackageToIpackage (
100 100 ACPI_OPERAND_OBJECT *SourceObj,
101 101 ACPI_OPERAND_OBJECT *DestObj,
102 102 ACPI_WALK_STATE *WalkState);
103 103
104 104
105 105 /*******************************************************************************
106 106 *
107 107 * FUNCTION: AcpiUtCopyIsimpleToEsimple
108 108 *
109 109 * PARAMETERS: InternalObject - Source object to be copied
110 110 * ExternalObject - Where to return the copied object
111 111 * DataSpace - Where object data is returned (such as
112 112 * buffer and string data)
113 113 * BufferSpaceUsed - Length of DataSpace that was used
114 114 *
115 115 * RETURN: Status
116 116 *
117 117 * DESCRIPTION: This function is called to copy a simple internal object to
118 118 * an external object.
119 119 *
120 120 * The DataSpace buffer is assumed to have sufficient space for
121 121 * the object.
122 122 *
123 123 ******************************************************************************/
124 124
125 125 static ACPI_STATUS
126 126 AcpiUtCopyIsimpleToEsimple (
127 127 ACPI_OPERAND_OBJECT *InternalObject,
128 128 ACPI_OBJECT *ExternalObject,
129 129 UINT8 *DataSpace,
130 130 ACPI_SIZE *BufferSpaceUsed)
131 131 {
132 132 ACPI_STATUS Status = AE_OK;
133 133
134 134
135 135 ACPI_FUNCTION_TRACE (UtCopyIsimpleToEsimple);
136 136
137 137
138 138 *BufferSpaceUsed = 0;
139 139
140 140 /*
141 141 * Check for NULL object case (could be an uninitialized
142 142 * package element)
143 143 */
144 144 if (!InternalObject)
145 145 {
146 146 return_ACPI_STATUS (AE_OK);
147 147 }
148 148
149 149 /* Always clear the external object */
150 150
151 151 ACPI_MEMSET (ExternalObject, 0, sizeof (ACPI_OBJECT));
152 152
153 153 /*
154 154 * In general, the external object will be the same type as
155 155 * the internal object
156 156 */
157 157 ExternalObject->Type = InternalObject->Common.Type;
158 158
159 159 /* However, only a limited number of external types are supported */
160 160
161 161 switch (InternalObject->Common.Type)
162 162 {
163 163 case ACPI_TYPE_STRING:
164 164
↓ open down ↓ |
146 lines elided |
↑ open up ↑ |
165 165 ExternalObject->String.Pointer = (char *) DataSpace;
166 166 ExternalObject->String.Length = InternalObject->String.Length;
167 167 *BufferSpaceUsed = ACPI_ROUND_UP_TO_NATIVE_WORD (
168 168 (ACPI_SIZE) InternalObject->String.Length + 1);
169 169
170 170 ACPI_MEMCPY ((void *) DataSpace,
171 171 (void *) InternalObject->String.Pointer,
172 172 (ACPI_SIZE) InternalObject->String.Length + 1);
173 173 break;
174 174
175 -
176 175 case ACPI_TYPE_BUFFER:
177 176
178 177 ExternalObject->Buffer.Pointer = DataSpace;
179 178 ExternalObject->Buffer.Length = InternalObject->Buffer.Length;
180 179 *BufferSpaceUsed = ACPI_ROUND_UP_TO_NATIVE_WORD (
181 180 InternalObject->String.Length);
182 181
183 182 ACPI_MEMCPY ((void *) DataSpace,
184 183 (void *) InternalObject->Buffer.Pointer,
185 184 InternalObject->Buffer.Length);
186 185 break;
187 186
188 -
189 187 case ACPI_TYPE_INTEGER:
190 188
191 189 ExternalObject->Integer.Value = InternalObject->Integer.Value;
192 190 break;
193 191
194 -
195 192 case ACPI_TYPE_LOCAL_REFERENCE:
196 193
197 194 /* This is an object reference. */
198 195
199 196 switch (InternalObject->Reference.Class)
200 197 {
201 198 case ACPI_REFCLASS_NAME:
202 -
203 199 /*
204 200 * For namepath, return the object handle ("reference")
205 201 * We are referring to the namespace node
206 202 */
207 203 ExternalObject->Reference.Handle =
208 204 InternalObject->Reference.Node;
209 205 ExternalObject->Reference.ActualType =
210 206 AcpiNsGetType (InternalObject->Reference.Node);
211 207 break;
212 208
213 209 default:
214 210
215 211 /* All other reference types are unsupported */
216 212
217 213 return_ACPI_STATUS (AE_TYPE);
218 214 }
219 215 break;
220 216
221 -
222 217 case ACPI_TYPE_PROCESSOR:
223 218
224 219 ExternalObject->Processor.ProcId =
225 220 InternalObject->Processor.ProcId;
226 221 ExternalObject->Processor.PblkAddress =
227 222 InternalObject->Processor.Address;
228 223 ExternalObject->Processor.PblkLength =
229 224 InternalObject->Processor.Length;
230 225 break;
231 226
232 -
233 227 case ACPI_TYPE_POWER:
234 228
235 229 ExternalObject->PowerResource.SystemLevel =
236 230 InternalObject->PowerResource.SystemLevel;
237 231
238 232 ExternalObject->PowerResource.ResourceOrder =
239 233 InternalObject->PowerResource.ResourceOrder;
240 234 break;
241 235
242 -
243 236 default:
244 237 /*
245 238 * There is no corresponding external object type
246 239 */
247 240 ACPI_ERROR ((AE_INFO,
248 241 "Unsupported object type, cannot convert to external object: %s",
249 242 AcpiUtGetTypeName (InternalObject->Common.Type)));
250 243
251 244 return_ACPI_STATUS (AE_SUPPORT);
252 245 }
253 246
254 247 return_ACPI_STATUS (Status);
255 248 }
256 249
257 250
258 251 /*******************************************************************************
259 252 *
260 253 * FUNCTION: AcpiUtCopyIelementToEelement
261 254 *
262 255 * PARAMETERS: ACPI_PKG_CALLBACK
263 256 *
264 257 * RETURN: Status
265 258 *
266 259 * DESCRIPTION: Copy one package element to another package element
267 260 *
268 261 ******************************************************************************/
269 262
270 263 static ACPI_STATUS
271 264 AcpiUtCopyIelementToEelement (
272 265 UINT8 ObjectType,
273 266 ACPI_OPERAND_OBJECT *SourceObject,
274 267 ACPI_GENERIC_STATE *State,
275 268 void *Context)
276 269 {
277 270 ACPI_STATUS Status = AE_OK;
278 271 ACPI_PKG_INFO *Info = (ACPI_PKG_INFO *) Context;
279 272 ACPI_SIZE ObjectSpace;
280 273 UINT32 ThisIndex;
281 274 ACPI_OBJECT *TargetObject;
282 275
283 276
↓ open down ↓ |
31 lines elided |
↑ open up ↑ |
284 277 ACPI_FUNCTION_ENTRY ();
285 278
286 279
287 280 ThisIndex = State->Pkg.Index;
288 281 TargetObject = (ACPI_OBJECT *)
289 282 &((ACPI_OBJECT *)(State->Pkg.DestObject))->Package.Elements[ThisIndex];
290 283
291 284 switch (ObjectType)
292 285 {
293 286 case ACPI_COPY_TYPE_SIMPLE:
294 -
295 287 /*
296 288 * This is a simple or null object
297 289 */
298 290 Status = AcpiUtCopyIsimpleToEsimple (SourceObject,
299 291 TargetObject, Info->FreeSpace, &ObjectSpace);
300 292 if (ACPI_FAILURE (Status))
301 293 {
302 294 return (Status);
303 295 }
304 296 break;
305 297
306 -
307 298 case ACPI_COPY_TYPE_PACKAGE:
308 -
309 299 /*
310 300 * Build the package object
311 301 */
312 302 TargetObject->Type = ACPI_TYPE_PACKAGE;
313 303 TargetObject->Package.Count = SourceObject->Package.Count;
314 304 TargetObject->Package.Elements =
315 305 ACPI_CAST_PTR (ACPI_OBJECT, Info->FreeSpace);
316 306
317 307 /*
318 308 * Pass the new package object back to the package walk routine
319 309 */
320 310 State->Pkg.ThisTargetObj = TargetObject;
↓ open down ↓ |
2 lines elided |
↑ open up ↑ |
321 311
322 312 /*
323 313 * Save space for the array of objects (Package elements)
324 314 * update the buffer length counter
325 315 */
326 316 ObjectSpace = ACPI_ROUND_UP_TO_NATIVE_WORD (
327 317 (ACPI_SIZE) TargetObject->Package.Count *
328 318 sizeof (ACPI_OBJECT));
329 319 break;
330 320
331 -
332 321 default:
322 +
333 323 return (AE_BAD_PARAMETER);
334 324 }
335 325
336 326 Info->FreeSpace += ObjectSpace;
337 327 Info->Length += ObjectSpace;
338 328 return (Status);
339 329 }
340 330
341 331
342 332 /*******************************************************************************
343 333 *
344 334 * FUNCTION: AcpiUtCopyIpackageToEpackage
345 335 *
346 336 * PARAMETERS: InternalObject - Pointer to the object we are returning
347 337 * Buffer - Where the object is returned
348 338 * SpaceUsed - Where the object length is returned
349 339 *
350 340 * RETURN: Status
351 341 *
352 342 * DESCRIPTION: This function is called to place a package object in a user
353 343 * buffer. A package object by definition contains other objects.
354 344 *
355 345 * The buffer is assumed to have sufficient space for the object.
356 346 * The caller must have verified the buffer length needed using
357 347 * the AcpiUtGetObjectSize function before calling this function.
358 348 *
359 349 ******************************************************************************/
360 350
361 351 static ACPI_STATUS
362 352 AcpiUtCopyIpackageToEpackage (
363 353 ACPI_OPERAND_OBJECT *InternalObject,
364 354 UINT8 *Buffer,
365 355 ACPI_SIZE *SpaceUsed)
366 356 {
367 357 ACPI_OBJECT *ExternalObject;
368 358 ACPI_STATUS Status;
369 359 ACPI_PKG_INFO Info;
370 360
371 361
372 362 ACPI_FUNCTION_TRACE (UtCopyIpackageToEpackage);
373 363
374 364
375 365 /*
376 366 * First package at head of the buffer
377 367 */
378 368 ExternalObject = ACPI_CAST_PTR (ACPI_OBJECT, Buffer);
379 369
380 370 /*
381 371 * Free space begins right after the first package
382 372 */
383 373 Info.Length = ACPI_ROUND_UP_TO_NATIVE_WORD (sizeof (ACPI_OBJECT));
384 374 Info.FreeSpace = Buffer + ACPI_ROUND_UP_TO_NATIVE_WORD (
385 375 sizeof (ACPI_OBJECT));
386 376 Info.ObjectSpace = 0;
387 377 Info.NumPackages = 1;
388 378
389 379 ExternalObject->Type = InternalObject->Common.Type;
390 380 ExternalObject->Package.Count = InternalObject->Package.Count;
391 381 ExternalObject->Package.Elements = ACPI_CAST_PTR (ACPI_OBJECT,
392 382 Info.FreeSpace);
393 383
394 384 /*
395 385 * Leave room for an array of ACPI_OBJECTS in the buffer
396 386 * and move the free space past it
397 387 */
398 388 Info.Length += (ACPI_SIZE) ExternalObject->Package.Count *
399 389 ACPI_ROUND_UP_TO_NATIVE_WORD (sizeof (ACPI_OBJECT));
400 390 Info.FreeSpace += ExternalObject->Package.Count *
401 391 ACPI_ROUND_UP_TO_NATIVE_WORD (sizeof (ACPI_OBJECT));
402 392
403 393 Status = AcpiUtWalkPackageTree (InternalObject, ExternalObject,
404 394 AcpiUtCopyIelementToEelement, &Info);
405 395
406 396 *SpaceUsed = Info.Length;
407 397 return_ACPI_STATUS (Status);
408 398 }
409 399
410 400
411 401 /*******************************************************************************
412 402 *
413 403 * FUNCTION: AcpiUtCopyIobjectToEobject
414 404 *
415 405 * PARAMETERS: InternalObject - The internal object to be converted
416 406 * RetBuffer - Where the object is returned
417 407 *
418 408 * RETURN: Status
419 409 *
420 410 * DESCRIPTION: This function is called to build an API object to be returned
421 411 * to the caller.
422 412 *
423 413 ******************************************************************************/
424 414
425 415 ACPI_STATUS
426 416 AcpiUtCopyIobjectToEobject (
427 417 ACPI_OPERAND_OBJECT *InternalObject,
428 418 ACPI_BUFFER *RetBuffer)
429 419 {
430 420 ACPI_STATUS Status;
431 421
432 422
433 423 ACPI_FUNCTION_TRACE (UtCopyIobjectToEobject);
434 424
435 425
436 426 if (InternalObject->Common.Type == ACPI_TYPE_PACKAGE)
437 427 {
438 428 /*
439 429 * Package object: Copy all subobjects (including
440 430 * nested packages)
441 431 */
442 432 Status = AcpiUtCopyIpackageToEpackage (InternalObject,
443 433 RetBuffer->Pointer, &RetBuffer->Length);
444 434 }
445 435 else
446 436 {
447 437 /*
448 438 * Build a simple object (no nested objects)
449 439 */
450 440 Status = AcpiUtCopyIsimpleToEsimple (InternalObject,
451 441 ACPI_CAST_PTR (ACPI_OBJECT, RetBuffer->Pointer),
452 442 ACPI_ADD_PTR (UINT8, RetBuffer->Pointer,
453 443 ACPI_ROUND_UP_TO_NATIVE_WORD (sizeof (ACPI_OBJECT))),
454 444 &RetBuffer->Length);
455 445 /*
456 446 * build simple does not include the object size in the length
457 447 * so we add it in here
458 448 */
459 449 RetBuffer->Length += sizeof (ACPI_OBJECT);
460 450 }
461 451
462 452 return_ACPI_STATUS (Status);
463 453 }
464 454
465 455
466 456 /*******************************************************************************
467 457 *
468 458 * FUNCTION: AcpiUtCopyEsimpleToIsimple
469 459 *
470 460 * PARAMETERS: ExternalObject - The external object to be converted
471 461 * RetInternalObject - Where the internal object is returned
472 462 *
473 463 * RETURN: Status
474 464 *
475 465 * DESCRIPTION: This function copies an external object to an internal one.
476 466 * NOTE: Pointers can be copied, we don't need to copy data.
477 467 * (The pointers have to be valid in our address space no matter
478 468 * what we do with them!)
479 469 *
480 470 ******************************************************************************/
481 471
482 472 static ACPI_STATUS
483 473 AcpiUtCopyEsimpleToIsimple (
484 474 ACPI_OBJECT *ExternalObject,
485 475 ACPI_OPERAND_OBJECT **RetInternalObject)
486 476 {
487 477 ACPI_OPERAND_OBJECT *InternalObject;
488 478
489 479
490 480 ACPI_FUNCTION_TRACE (UtCopyEsimpleToIsimple);
491 481
492 482
493 483 /*
494 484 * Simple types supported are: String, Buffer, Integer
495 485 */
496 486 switch (ExternalObject->Type)
497 487 {
498 488 case ACPI_TYPE_STRING:
499 489 case ACPI_TYPE_BUFFER:
500 490 case ACPI_TYPE_INTEGER:
501 491 case ACPI_TYPE_LOCAL_REFERENCE:
502 492
503 493 InternalObject = AcpiUtCreateInternalObject (
504 494 (UINT8) ExternalObject->Type);
505 495 if (!InternalObject)
506 496 {
↓ open down ↓ |
164 lines elided |
↑ open up ↑ |
507 497 return_ACPI_STATUS (AE_NO_MEMORY);
508 498 }
509 499 break;
510 500
511 501 case ACPI_TYPE_ANY: /* This is the case for a NULL object */
512 502
513 503 *RetInternalObject = NULL;
514 504 return_ACPI_STATUS (AE_OK);
515 505
516 506 default:
507 +
517 508 /* All other types are not supported */
518 509
519 510 ACPI_ERROR ((AE_INFO,
520 511 "Unsupported object type, cannot convert to internal object: %s",
521 512 AcpiUtGetTypeName (ExternalObject->Type)));
522 513
523 514 return_ACPI_STATUS (AE_SUPPORT);
524 515 }
525 516
526 517
527 518 /* Must COPY string and buffer contents */
528 519
529 520 switch (ExternalObject->Type)
530 521 {
531 522 case ACPI_TYPE_STRING:
532 523
533 524 InternalObject->String.Pointer =
534 525 ACPI_ALLOCATE_ZEROED ((ACPI_SIZE)
535 526 ExternalObject->String.Length + 1);
536 527
537 528 if (!InternalObject->String.Pointer)
538 529 {
↓ open down ↓ |
12 lines elided |
↑ open up ↑ |
539 530 goto ErrorExit;
540 531 }
541 532
542 533 ACPI_MEMCPY (InternalObject->String.Pointer,
543 534 ExternalObject->String.Pointer,
544 535 ExternalObject->String.Length);
545 536
546 537 InternalObject->String.Length = ExternalObject->String.Length;
547 538 break;
548 539
549 -
550 540 case ACPI_TYPE_BUFFER:
551 541
552 542 InternalObject->Buffer.Pointer =
553 543 ACPI_ALLOCATE_ZEROED (ExternalObject->Buffer.Length);
554 544 if (!InternalObject->Buffer.Pointer)
555 545 {
556 546 goto ErrorExit;
557 547 }
558 548
559 549 ACPI_MEMCPY (InternalObject->Buffer.Pointer,
560 550 ExternalObject->Buffer.Pointer,
561 551 ExternalObject->Buffer.Length);
562 552
563 553 InternalObject->Buffer.Length = ExternalObject->Buffer.Length;
564 554
565 555 /* Mark buffer data valid */
566 556
567 557 InternalObject->Buffer.Flags |= AOPOBJ_DATA_VALID;
568 558 break;
569 559
570 -
571 560 case ACPI_TYPE_INTEGER:
572 561
573 562 InternalObject->Integer.Value = ExternalObject->Integer.Value;
574 563 break;
575 564
576 565 case ACPI_TYPE_LOCAL_REFERENCE:
577 566
578 567 /* TBD: should validate incoming handle */
579 568
580 569 InternalObject->Reference.Class = ACPI_REFCLASS_NAME;
581 570 InternalObject->Reference.Node = ExternalObject->Reference.Handle;
582 571 break;
583 572
584 573 default:
574 +
585 575 /* Other types can't get here */
576 +
586 577 break;
587 578 }
588 579
589 580 *RetInternalObject = InternalObject;
590 581 return_ACPI_STATUS (AE_OK);
591 582
592 583
593 584 ErrorExit:
594 585 AcpiUtRemoveReference (InternalObject);
595 586 return_ACPI_STATUS (AE_NO_MEMORY);
596 587 }
597 588
598 589
599 590 /*******************************************************************************
600 591 *
601 592 * FUNCTION: AcpiUtCopyEpackageToIpackage
602 593 *
603 594 * PARAMETERS: ExternalObject - The external object to be converted
604 595 * InternalObject - Where the internal object is returned
605 596 *
606 597 * RETURN: Status
607 598 *
608 599 * DESCRIPTION: Copy an external package object to an internal package.
609 600 * Handles nested packages.
610 601 *
611 602 ******************************************************************************/
612 603
613 604 static ACPI_STATUS
614 605 AcpiUtCopyEpackageToIpackage (
615 606 ACPI_OBJECT *ExternalObject,
616 607 ACPI_OPERAND_OBJECT **InternalObject)
617 608 {
618 609 ACPI_STATUS Status = AE_OK;
619 610 ACPI_OPERAND_OBJECT *PackageObject;
620 611 ACPI_OPERAND_OBJECT **PackageElements;
621 612 UINT32 i;
622 613
623 614
624 615 ACPI_FUNCTION_TRACE (UtCopyEpackageToIpackage);
625 616
626 617
627 618 /* Create the package object */
628 619
629 620 PackageObject = AcpiUtCreatePackageObject (ExternalObject->Package.Count);
630 621 if (!PackageObject)
631 622 {
632 623 return_ACPI_STATUS (AE_NO_MEMORY);
633 624 }
634 625
635 626 PackageElements = PackageObject->Package.Elements;
636 627
637 628 /*
638 629 * Recursive implementation. Probably ok, since nested external packages
639 630 * as parameters should be very rare.
640 631 */
641 632 for (i = 0; i < ExternalObject->Package.Count; i++)
642 633 {
643 634 Status = AcpiUtCopyEobjectToIobject (
644 635 &ExternalObject->Package.Elements[i],
645 636 &PackageElements[i]);
646 637 if (ACPI_FAILURE (Status))
647 638 {
648 639 /* Truncate package and delete it */
649 640
650 641 PackageObject->Package.Count = i;
651 642 PackageElements[i] = NULL;
652 643 AcpiUtRemoveReference (PackageObject);
653 644 return_ACPI_STATUS (Status);
654 645 }
655 646 }
656 647
657 648 /* Mark package data valid */
658 649
659 650 PackageObject->Package.Flags |= AOPOBJ_DATA_VALID;
660 651
661 652 *InternalObject = PackageObject;
662 653 return_ACPI_STATUS (Status);
663 654 }
664 655
665 656
666 657 /*******************************************************************************
667 658 *
668 659 * FUNCTION: AcpiUtCopyEobjectToIobject
669 660 *
670 661 * PARAMETERS: ExternalObject - The external object to be converted
671 662 * InternalObject - Where the internal object is returned
672 663 *
673 664 * RETURN: Status
674 665 *
675 666 * DESCRIPTION: Converts an external object to an internal object.
676 667 *
677 668 ******************************************************************************/
678 669
679 670 ACPI_STATUS
680 671 AcpiUtCopyEobjectToIobject (
681 672 ACPI_OBJECT *ExternalObject,
682 673 ACPI_OPERAND_OBJECT **InternalObject)
683 674 {
684 675 ACPI_STATUS Status;
685 676
686 677
687 678 ACPI_FUNCTION_TRACE (UtCopyEobjectToIobject);
688 679
689 680
690 681 if (ExternalObject->Type == ACPI_TYPE_PACKAGE)
691 682 {
692 683 Status = AcpiUtCopyEpackageToIpackage (ExternalObject, InternalObject);
693 684 }
694 685 else
695 686 {
696 687 /*
697 688 * Build a simple object (no nested objects)
698 689 */
699 690 Status = AcpiUtCopyEsimpleToIsimple (ExternalObject, InternalObject);
700 691 }
701 692
702 693 return_ACPI_STATUS (Status);
703 694 }
704 695
705 696
706 697 /*******************************************************************************
707 698 *
708 699 * FUNCTION: AcpiUtCopySimpleObject
709 700 *
710 701 * PARAMETERS: SourceDesc - The internal object to be copied
711 702 * DestDesc - New target object
712 703 *
713 704 * RETURN: Status
714 705 *
715 706 * DESCRIPTION: Simple copy of one internal object to another. Reference count
716 707 * of the destination object is preserved.
717 708 *
718 709 ******************************************************************************/
719 710
720 711 static ACPI_STATUS
721 712 AcpiUtCopySimpleObject (
722 713 ACPI_OPERAND_OBJECT *SourceDesc,
723 714 ACPI_OPERAND_OBJECT *DestDesc)
724 715 {
725 716 UINT16 ReferenceCount;
726 717 ACPI_OPERAND_OBJECT *NextObject;
727 718 ACPI_STATUS Status;
728 719 ACPI_SIZE CopySize;
729 720
730 721
731 722 /* Save fields from destination that we don't want to overwrite */
732 723
733 724 ReferenceCount = DestDesc->Common.ReferenceCount;
734 725 NextObject = DestDesc->Common.NextObject;
735 726
736 727 /*
737 728 * Copy the entire source object over the destination object.
738 729 * Note: Source can be either an operand object or namespace node.
739 730 */
740 731 CopySize = sizeof (ACPI_OPERAND_OBJECT);
741 732 if (ACPI_GET_DESCRIPTOR_TYPE (SourceDesc) == ACPI_DESC_TYPE_NAMED)
742 733 {
743 734 CopySize = sizeof (ACPI_NAMESPACE_NODE);
744 735 }
745 736
746 737 ACPI_MEMCPY (ACPI_CAST_PTR (char, DestDesc),
747 738 ACPI_CAST_PTR (char, SourceDesc), CopySize);
748 739
749 740 /* Restore the saved fields */
750 741
751 742 DestDesc->Common.ReferenceCount = ReferenceCount;
752 743 DestDesc->Common.NextObject = NextObject;
753 744
754 745 /* New object is not static, regardless of source */
755 746
756 747 DestDesc->Common.Flags &= ~AOPOBJ_STATIC_POINTER;
757 748
758 749 /* Handle the objects with extra data */
759 750
760 751 switch (DestDesc->Common.Type)
761 752 {
762 753 case ACPI_TYPE_BUFFER:
763 754 /*
764 755 * Allocate and copy the actual buffer if and only if:
765 756 * 1) There is a valid buffer pointer
766 757 * 2) The buffer has a length > 0
767 758 */
768 759 if ((SourceDesc->Buffer.Pointer) &&
769 760 (SourceDesc->Buffer.Length))
770 761 {
771 762 DestDesc->Buffer.Pointer =
772 763 ACPI_ALLOCATE (SourceDesc->Buffer.Length);
773 764 if (!DestDesc->Buffer.Pointer)
774 765 {
775 766 return (AE_NO_MEMORY);
776 767 }
777 768
778 769 /* Copy the actual buffer data */
779 770
780 771 ACPI_MEMCPY (DestDesc->Buffer.Pointer,
781 772 SourceDesc->Buffer.Pointer, SourceDesc->Buffer.Length);
782 773 }
783 774 break;
784 775
785 776 case ACPI_TYPE_STRING:
786 777 /*
787 778 * Allocate and copy the actual string if and only if:
788 779 * 1) There is a valid string pointer
789 780 * (Pointer to a NULL string is allowed)
790 781 */
791 782 if (SourceDesc->String.Pointer)
792 783 {
793 784 DestDesc->String.Pointer =
794 785 ACPI_ALLOCATE ((ACPI_SIZE) SourceDesc->String.Length + 1);
795 786 if (!DestDesc->String.Pointer)
796 787 {
797 788 return (AE_NO_MEMORY);
798 789 }
799 790
800 791 /* Copy the actual string data */
801 792
802 793 ACPI_MEMCPY (DestDesc->String.Pointer, SourceDesc->String.Pointer,
803 794 (ACPI_SIZE) SourceDesc->String.Length + 1);
804 795 }
805 796 break;
806 797
807 798 case ACPI_TYPE_LOCAL_REFERENCE:
808 799 /*
809 800 * We copied the reference object, so we now must add a reference
810 801 * to the object pointed to by the reference
811 802 *
812 803 * DDBHandle reference (from Load/LoadTable) is a special reference,
813 804 * it does not have a Reference.Object, so does not need to
814 805 * increase the reference count
815 806 */
816 807 if (SourceDesc->Reference.Class == ACPI_REFCLASS_TABLE)
817 808 {
818 809 break;
819 810 }
820 811
821 812 AcpiUtAddReference (SourceDesc->Reference.Object);
822 813 break;
823 814
824 815 case ACPI_TYPE_REGION:
825 816 /*
826 817 * We copied the Region Handler, so we now must add a reference
827 818 */
828 819 if (DestDesc->Region.Handler)
829 820 {
830 821 AcpiUtAddReference (DestDesc->Region.Handler);
831 822 }
832 823 break;
833 824
834 825 /*
835 826 * For Mutex and Event objects, we cannot simply copy the underlying
836 827 * OS object. We must create a new one.
837 828 */
838 829 case ACPI_TYPE_MUTEX:
839 830
840 831 Status = AcpiOsCreateMutex (&DestDesc->Mutex.OsMutex);
841 832 if (ACPI_FAILURE (Status))
842 833 {
843 834 return (Status);
844 835 }
845 836 break;
846 837
847 838 case ACPI_TYPE_EVENT:
↓ open down ↓ |
252 lines elided |
↑ open up ↑ |
848 839
849 840 Status = AcpiOsCreateSemaphore (ACPI_NO_UNIT_LIMIT, 0,
850 841 &DestDesc->Event.OsSemaphore);
851 842 if (ACPI_FAILURE (Status))
852 843 {
853 844 return (Status);
854 845 }
855 846 break;
856 847
857 848 default:
849 +
858 850 /* Nothing to do for other simple objects */
851 +
859 852 break;
860 853 }
861 854
862 855 return (AE_OK);
863 856 }
864 857
865 858
866 859 /*******************************************************************************
867 860 *
868 861 * FUNCTION: AcpiUtCopyIelementToIelement
869 862 *
870 863 * PARAMETERS: ACPI_PKG_CALLBACK
871 864 *
872 865 * RETURN: Status
873 866 *
874 867 * DESCRIPTION: Copy one package element to another package element
875 868 *
876 869 ******************************************************************************/
877 870
878 871 static ACPI_STATUS
879 872 AcpiUtCopyIelementToIelement (
880 873 UINT8 ObjectType,
881 874 ACPI_OPERAND_OBJECT *SourceObject,
882 875 ACPI_GENERIC_STATE *State,
883 876 void *Context)
884 877 {
885 878 ACPI_STATUS Status = AE_OK;
886 879 UINT32 ThisIndex;
887 880 ACPI_OPERAND_OBJECT **ThisTargetPtr;
888 881 ACPI_OPERAND_OBJECT *TargetObject;
889 882
890 883
891 884 ACPI_FUNCTION_ENTRY ();
892 885
893 886
894 887 ThisIndex = State->Pkg.Index;
895 888 ThisTargetPtr = (ACPI_OPERAND_OBJECT **)
896 889 &State->Pkg.DestObject->Package.Elements[ThisIndex];
897 890
898 891 switch (ObjectType)
899 892 {
900 893 case ACPI_COPY_TYPE_SIMPLE:
901 894
902 895 /* A null source object indicates a (legal) null package element */
903 896
904 897 if (SourceObject)
905 898 {
906 899 /*
907 900 * This is a simple object, just copy it
908 901 */
909 902 TargetObject = AcpiUtCreateInternalObject (
910 903 SourceObject->Common.Type);
911 904 if (!TargetObject)
912 905 {
913 906 return (AE_NO_MEMORY);
914 907 }
915 908
916 909 Status = AcpiUtCopySimpleObject (SourceObject, TargetObject);
917 910 if (ACPI_FAILURE (Status))
918 911 {
919 912 goto ErrorExit;
920 913 }
921 914
↓ open down ↓ |
53 lines elided |
↑ open up ↑ |
922 915 *ThisTargetPtr = TargetObject;
923 916 }
924 917 else
925 918 {
926 919 /* Pass through a null element */
927 920
928 921 *ThisTargetPtr = NULL;
929 922 }
930 923 break;
931 924
932 -
933 925 case ACPI_COPY_TYPE_PACKAGE:
934 -
935 926 /*
936 927 * This object is a package - go down another nesting level
937 928 * Create and build the package object
938 929 */
939 930 TargetObject = AcpiUtCreatePackageObject (SourceObject->Package.Count);
940 931 if (!TargetObject)
941 932 {
942 933 return (AE_NO_MEMORY);
943 934 }
944 935
945 936 TargetObject->Common.Flags = SourceObject->Common.Flags;
↓ open down ↓ |
1 lines elided |
↑ open up ↑ |
946 937
947 938 /* Pass the new package object back to the package walk routine */
948 939
949 940 State->Pkg.ThisTargetObj = TargetObject;
950 941
951 942 /* Store the object pointer in the parent package object */
952 943
953 944 *ThisTargetPtr = TargetObject;
954 945 break;
955 946
956 -
957 947 default:
948 +
958 949 return (AE_BAD_PARAMETER);
959 950 }
960 951
961 952 return (Status);
962 953
963 954 ErrorExit:
964 955 AcpiUtRemoveReference (TargetObject);
965 956 return (Status);
966 957 }
967 958
968 959
969 960 /*******************************************************************************
970 961 *
971 962 * FUNCTION: AcpiUtCopyIpackageToIpackage
972 963 *
973 964 * PARAMETERS: SourceObj - Pointer to the source package object
974 965 * DestObj - Where the internal object is returned
975 966 * WalkState - Current Walk state descriptor
976 967 *
977 968 * RETURN: Status
978 969 *
979 970 * DESCRIPTION: This function is called to copy an internal package object
980 971 * into another internal package object.
981 972 *
982 973 ******************************************************************************/
983 974
984 975 static ACPI_STATUS
985 976 AcpiUtCopyIpackageToIpackage (
986 977 ACPI_OPERAND_OBJECT *SourceObj,
987 978 ACPI_OPERAND_OBJECT *DestObj,
988 979 ACPI_WALK_STATE *WalkState)
989 980 {
990 981 ACPI_STATUS Status = AE_OK;
991 982
992 983
993 984 ACPI_FUNCTION_TRACE (UtCopyIpackageToIpackage);
994 985
995 986
996 987 DestObj->Common.Type = SourceObj->Common.Type;
997 988 DestObj->Common.Flags = SourceObj->Common.Flags;
998 989 DestObj->Package.Count = SourceObj->Package.Count;
999 990
1000 991 /*
1001 992 * Create the object array and walk the source package tree
1002 993 */
1003 994 DestObj->Package.Elements = ACPI_ALLOCATE_ZEROED (
1004 995 ((ACPI_SIZE) SourceObj->Package.Count + 1) *
1005 996 sizeof (void *));
1006 997 if (!DestObj->Package.Elements)
1007 998 {
1008 999 ACPI_ERROR ((AE_INFO, "Package allocation failure"));
1009 1000 return_ACPI_STATUS (AE_NO_MEMORY);
1010 1001 }
1011 1002
1012 1003 /*
1013 1004 * Copy the package element-by-element by walking the package "tree".
1014 1005 * This handles nested packages of arbitrary depth.
1015 1006 */
1016 1007 Status = AcpiUtWalkPackageTree (SourceObj, DestObj,
1017 1008 AcpiUtCopyIelementToIelement, WalkState);
1018 1009 if (ACPI_FAILURE (Status))
1019 1010 {
1020 1011 /* On failure, delete the destination package object */
1021 1012
1022 1013 AcpiUtRemoveReference (DestObj);
1023 1014 }
1024 1015
1025 1016 return_ACPI_STATUS (Status);
1026 1017 }
1027 1018
1028 1019
1029 1020 /*******************************************************************************
1030 1021 *
1031 1022 * FUNCTION: AcpiUtCopyIobjectToIobject
1032 1023 *
1033 1024 * PARAMETERS: SourceDesc - The internal object to be copied
1034 1025 * DestDesc - Where the copied object is returned
1035 1026 * WalkState - Current walk state
1036 1027 *
1037 1028 * RETURN: Status
1038 1029 *
1039 1030 * DESCRIPTION: Copy an internal object to a new internal object
1040 1031 *
1041 1032 ******************************************************************************/
1042 1033
1043 1034 ACPI_STATUS
1044 1035 AcpiUtCopyIobjectToIobject (
1045 1036 ACPI_OPERAND_OBJECT *SourceDesc,
1046 1037 ACPI_OPERAND_OBJECT **DestDesc,
1047 1038 ACPI_WALK_STATE *WalkState)
1048 1039 {
1049 1040 ACPI_STATUS Status = AE_OK;
1050 1041
1051 1042
1052 1043 ACPI_FUNCTION_TRACE (UtCopyIobjectToIobject);
1053 1044
1054 1045
1055 1046 /* Create the top level object */
1056 1047
1057 1048 *DestDesc = AcpiUtCreateInternalObject (SourceDesc->Common.Type);
1058 1049 if (!*DestDesc)
1059 1050 {
1060 1051 return_ACPI_STATUS (AE_NO_MEMORY);
1061 1052 }
1062 1053
1063 1054 /* Copy the object and possible subobjects */
1064 1055
1065 1056 if (SourceDesc->Common.Type == ACPI_TYPE_PACKAGE)
1066 1057 {
↓ open down ↓ |
99 lines elided |
↑ open up ↑ |
1067 1058 Status = AcpiUtCopyIpackageToIpackage (SourceDesc, *DestDesc,
1068 1059 WalkState);
1069 1060 }
1070 1061 else
1071 1062 {
1072 1063 Status = AcpiUtCopySimpleObject (SourceDesc, *DestDesc);
1073 1064 }
1074 1065
1075 1066 return_ACPI_STATUS (Status);
1076 1067 }
1077 -
1078 -
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX