Print this page
update to acpica-unix2-20140114
update to acpica-unix2-20130927
acpica-unix2-20130823
PANKOVs restructure
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/intel/io/acpica/namespace/nsxfname.c
+++ new/usr/src/common/acpica/components/namespace/nsxfname.c
1 1 /******************************************************************************
2 2 *
3 3 * Module Name: nsxfname - Public interfaces to the ACPI subsystem
4 4 * ACPI Namespace oriented interfaces
5 5 *
6 6 *****************************************************************************/
7 7
8 8 /*
9 - * Copyright (C) 2000 - 2011, Intel Corp.
9 + * Copyright (C) 2000 - 2014, Intel Corp.
10 10 * All rights reserved.
11 11 *
12 12 * Redistribution and use in source and binary forms, with or without
13 13 * modification, are permitted provided that the following conditions
14 14 * are met:
15 15 * 1. Redistributions of source code must retain the above copyright
16 16 * notice, this list of conditions, and the following disclaimer,
17 17 * without modification.
18 18 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
19 19 * substantially similar to the "NO WARRANTY" disclaimer below
20 20 * ("Disclaimer") and any redistribution must be conditioned upon
21 21 * including a substantially similar Disclaimer requirement for further
22 22 * binary redistribution.
23 23 * 3. Neither the names of the above-listed copyright holders nor the names
24 24 * of any contributors may be used to endorse or promote products derived
25 25 * from this software without specific prior written permission.
26 26 *
27 27 * Alternatively, this software may be distributed under the terms of the
28 28 * GNU General Public License ("GPL") version 2 as published by the Free
29 29 * Software Foundation.
30 30 *
31 31 * NO WARRANTY
32 32 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33 33 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34 34 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
35 35 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
↓ open down ↓ |
16 lines elided |
↑ open up ↑ |
36 36 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 37 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 38 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 39 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40 40 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
41 41 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42 42 * POSSIBILITY OF SUCH DAMAGES.
43 43 */
44 44
45 45 #define __NSXFNAME_C__
46 +#define EXPORT_ACPI_INTERFACES
46 47
47 48 #include "acpi.h"
48 49 #include "accommon.h"
49 50 #include "acnamesp.h"
50 51 #include "acparser.h"
51 52 #include "amlcode.h"
52 53
53 54
54 55 #define _COMPONENT ACPI_NAMESPACE
55 56 ACPI_MODULE_NAME ("nsxfname")
56 57
57 58 /* Local prototypes */
58 59
59 60 static char *
60 61 AcpiNsCopyDeviceId (
61 - ACPI_DEVICE_ID *Dest,
62 - ACPI_DEVICE_ID *Source,
62 + ACPI_PNP_DEVICE_ID *Dest,
63 + ACPI_PNP_DEVICE_ID *Source,
63 64 char *StringArea);
64 65
65 66
66 67 /******************************************************************************
67 68 *
68 69 * FUNCTION: AcpiGetHandle
69 70 *
70 71 * PARAMETERS: Parent - Object to search under (search scope).
71 72 * Pathname - Pointer to an asciiz string containing the
72 73 * name
73 74 * RetHandle - Where the return handle is returned
74 75 *
75 76 * RETURN: Status
76 77 *
77 78 * DESCRIPTION: This routine will search for a caller specified name in the
78 - * name space. The caller can restrict the search region by
79 - * specifying a non NULL parent. The parent value is itself a
79 + * name space. The caller can restrict the search region by
80 + * specifying a non NULL parent. The parent value is itself a
80 81 * namespace handle.
81 82 *
82 83 ******************************************************************************/
83 84
84 85 ACPI_STATUS
85 86 AcpiGetHandle (
86 87 ACPI_HANDLE Parent,
87 88 ACPI_STRING Pathname,
88 89 ACPI_HANDLE *RetHandle)
89 90 {
90 91 ACPI_STATUS Status;
91 92 ACPI_NAMESPACE_NODE *Node = NULL;
92 93 ACPI_NAMESPACE_NODE *PrefixNode = NULL;
93 94
94 95
95 96 ACPI_FUNCTION_ENTRY ();
96 97
97 98
98 99 /* Parameter Validation */
99 100
100 101 if (!RetHandle || !Pathname)
101 102 {
102 103 return (AE_BAD_PARAMETER);
103 104 }
104 105
105 106 /* Convert a parent handle to a prefix node */
106 107
107 108 if (Parent)
108 109 {
109 110 PrefixNode = AcpiNsValidateHandle (Parent);
110 111 if (!PrefixNode)
111 112 {
112 113 return (AE_BAD_PARAMETER);
↓ open down ↓ |
23 lines elided |
↑ open up ↑ |
113 114 }
114 115 }
115 116
116 117 /*
117 118 * Valid cases are:
118 119 * 1) Fully qualified pathname
119 120 * 2) Parent + Relative pathname
120 121 *
121 122 * Error for <null Parent + relative path>
122 123 */
123 - if (AcpiNsValidRootPrefix (Pathname[0]))
124 + if (ACPI_IS_ROOT_PREFIX (Pathname[0]))
124 125 {
125 126 /* Pathname is fully qualified (starts with '\') */
126 127
127 128 /* Special case for root-only, since we can't search for it */
128 129
129 130 if (!ACPI_STRCMP (Pathname, ACPI_NS_ROOT_PATH))
130 131 {
131 132 *RetHandle = ACPI_CAST_PTR (ACPI_HANDLE, AcpiGbl_RootNode);
132 133 return (AE_OK);
133 134 }
134 135 }
135 136 else if (!PrefixNode)
136 137 {
137 138 /* Relative path with null prefix is disallowed */
138 139
139 140 return (AE_BAD_PARAMETER);
140 141 }
141 142
142 143 /* Find the Node and convert to a handle */
143 144
144 145 Status = AcpiNsGetNode (PrefixNode, Pathname, ACPI_NS_NO_UPSEARCH, &Node);
145 146 if (ACPI_SUCCESS (Status))
146 147 {
147 148 *RetHandle = ACPI_CAST_PTR (ACPI_HANDLE, Node);
148 149 }
149 150
150 151 return (Status);
151 152 }
152 153
153 154 ACPI_EXPORT_SYMBOL (AcpiGetHandle)
154 155
155 156
156 157 /******************************************************************************
↓ open down ↓ |
23 lines elided |
↑ open up ↑ |
157 158 *
158 159 * FUNCTION: AcpiGetName
159 160 *
160 161 * PARAMETERS: Handle - Handle to be converted to a pathname
161 162 * NameType - Full pathname or single segment
162 163 * Buffer - Buffer for returned path
163 164 *
164 165 * RETURN: Pointer to a string containing the fully qualified Name.
165 166 *
166 167 * DESCRIPTION: This routine returns the fully qualified name associated with
167 - * the Handle parameter. This and the AcpiPathnameToHandle are
168 + * the Handle parameter. This and the AcpiPathnameToHandle are
168 169 * complementary functions.
169 170 *
170 171 ******************************************************************************/
171 172
172 173 ACPI_STATUS
173 174 AcpiGetName (
174 175 ACPI_HANDLE Handle,
175 176 UINT32 NameType,
176 177 ACPI_BUFFER *Buffer)
177 178 {
178 179 ACPI_STATUS Status;
179 180 ACPI_NAMESPACE_NODE *Node;
181 + char *NodeName;
180 182
181 183
182 184 /* Parameter validation */
183 185
184 186 if (NameType > ACPI_NAME_TYPE_MAX)
185 187 {
186 188 return (AE_BAD_PARAMETER);
187 189 }
188 190
189 191 Status = AcpiUtValidateBuffer (Buffer);
190 192 if (ACPI_FAILURE (Status))
191 193 {
192 194 return (Status);
193 195 }
194 196
195 197 if (NameType == ACPI_FULL_PATHNAME)
196 198 {
197 199 /* Get the full pathname (From the namespace root) */
198 200
199 201 Status = AcpiNsHandleToPathname (Handle, Buffer);
200 202 return (Status);
201 203 }
202 204
203 205 /*
204 206 * Wants the single segment ACPI name.
205 207 * Validate handle and convert to a namespace Node
206 208 */
207 209 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
208 210 if (ACPI_FAILURE (Status))
209 211 {
210 212 return (Status);
211 213 }
212 214
213 215 Node = AcpiNsValidateHandle (Handle);
214 216 if (!Node)
215 217 {
216 218 Status = AE_BAD_PARAMETER;
217 219 goto UnlockAndExit;
218 220 }
219 221
↓ open down ↓ |
30 lines elided |
↑ open up ↑ |
220 222 /* Validate/Allocate/Clear caller buffer */
221 223
222 224 Status = AcpiUtInitializeBuffer (Buffer, ACPI_PATH_SEGMENT_LENGTH);
223 225 if (ACPI_FAILURE (Status))
224 226 {
225 227 goto UnlockAndExit;
226 228 }
227 229
228 230 /* Just copy the ACPI name from the Node and zero terminate it */
229 231
230 - ACPI_STRNCPY (Buffer->Pointer, AcpiUtGetNodeName (Node),
231 - ACPI_NAME_SIZE);
232 + NodeName = AcpiUtGetNodeName (Node);
233 + ACPI_MOVE_NAME (Buffer->Pointer, NodeName);
232 234 ((char *) Buffer->Pointer) [ACPI_NAME_SIZE] = 0;
233 235 Status = AE_OK;
234 236
235 237
236 238 UnlockAndExit:
237 239
238 240 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
239 241 return (Status);
240 242 }
241 243
242 244 ACPI_EXPORT_SYMBOL (AcpiGetName)
243 245
244 246
245 247 /******************************************************************************
246 248 *
247 249 * FUNCTION: AcpiNsCopyDeviceId
248 250 *
249 - * PARAMETERS: Dest - Pointer to the destination DEVICE_ID
250 - * Source - Pointer to the source DEVICE_ID
251 + * PARAMETERS: Dest - Pointer to the destination PNP_DEVICE_ID
252 + * Source - Pointer to the source PNP_DEVICE_ID
251 253 * StringArea - Pointer to where to copy the dest string
252 254 *
253 255 * RETURN: Pointer to the next string area
254 256 *
255 - * DESCRIPTION: Copy a single DEVICE_ID, including the string data.
257 + * DESCRIPTION: Copy a single PNP_DEVICE_ID, including the string data.
256 258 *
257 259 ******************************************************************************/
258 260
259 261 static char *
260 262 AcpiNsCopyDeviceId (
261 - ACPI_DEVICE_ID *Dest,
262 - ACPI_DEVICE_ID *Source,
263 + ACPI_PNP_DEVICE_ID *Dest,
264 + ACPI_PNP_DEVICE_ID *Source,
263 265 char *StringArea)
264 266 {
265 - /* Create the destination DEVICE_ID */
266 267
268 + /* Create the destination PNP_DEVICE_ID */
269 +
267 270 Dest->String = StringArea;
268 271 Dest->Length = Source->Length;
269 272
270 273 /* Copy actual string and return a pointer to the next string area */
271 274
272 275 ACPI_MEMCPY (StringArea, Source->String, Source->Length);
273 276 return (StringArea + Source->Length);
274 277 }
275 278
276 279
277 280 /******************************************************************************
278 281 *
279 282 * FUNCTION: AcpiGetObjectInfo
↓ open down ↓ |
3 lines elided |
↑ open up ↑ |
280 283 *
281 284 * PARAMETERS: Handle - Object Handle
282 285 * ReturnBuffer - Where the info is returned
283 286 *
284 287 * RETURN: Status
285 288 *
286 289 * DESCRIPTION: Returns information about an object as gleaned from the
287 290 * namespace node and possibly by running several standard
288 291 * control methods (Such as in the case of a device.)
289 292 *
290 - * For Device and Processor objects, run the Device _HID, _UID, _CID, _STA,
291 - * _ADR, _SxW, and _SxD methods.
293 + * For Device and Processor objects, run the Device _HID, _UID, _CID, _SUB,
294 + * _STA, _ADR, _SxW, and _SxD methods.
292 295 *
293 296 * Note: Allocates the return buffer, must be freed by the caller.
294 297 *
295 298 ******************************************************************************/
296 299
297 300 ACPI_STATUS
298 301 AcpiGetObjectInfo (
299 302 ACPI_HANDLE Handle,
300 303 ACPI_DEVICE_INFO **ReturnBuffer)
301 304 {
302 305 ACPI_NAMESPACE_NODE *Node;
303 306 ACPI_DEVICE_INFO *Info;
304 - ACPI_DEVICE_ID_LIST *CidList = NULL;
305 - ACPI_DEVICE_ID *Hid = NULL;
306 - ACPI_DEVICE_ID *Uid = NULL;
307 + ACPI_PNP_DEVICE_ID_LIST *CidList = NULL;
308 + ACPI_PNP_DEVICE_ID *Hid = NULL;
309 + ACPI_PNP_DEVICE_ID *Uid = NULL;
310 + ACPI_PNP_DEVICE_ID *Sub = NULL;
307 311 char *NextIdString;
308 312 ACPI_OBJECT_TYPE Type;
309 313 ACPI_NAME Name;
310 314 UINT8 ParamCount= 0;
311 315 UINT8 Valid = 0;
312 316 UINT32 InfoSize;
313 317 UINT32 i;
314 318 ACPI_STATUS Status;
315 319
316 320
317 321 /* Parameter validation */
318 322
319 323 if (!Handle || !ReturnBuffer)
320 324 {
321 325 return (AE_BAD_PARAMETER);
322 326 }
323 327
324 328 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
325 329 if (ACPI_FAILURE (Status))
326 330 {
327 - goto Cleanup;
331 + return (Status);
328 332 }
329 333
330 334 Node = AcpiNsValidateHandle (Handle);
331 335 if (!Node)
332 336 {
333 337 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
334 338 return (AE_BAD_PARAMETER);
335 339 }
336 340
337 341 /* Get the namespace node data while the namespace is locked */
338 342
339 343 InfoSize = sizeof (ACPI_DEVICE_INFO);
340 344 Type = Node->Type;
341 345 Name = Node->Name.Integer;
342 346
343 347 if (Node->Type == ACPI_TYPE_METHOD)
344 348 {
345 349 ParamCount = Node->Object->Method.ParamCount;
346 350 }
347 351
348 352 Status = AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
↓ open down ↓ |
11 lines elided |
↑ open up ↑ |
349 353 if (ACPI_FAILURE (Status))
350 354 {
351 355 return (Status);
352 356 }
353 357
354 358 if ((Type == ACPI_TYPE_DEVICE) ||
355 359 (Type == ACPI_TYPE_PROCESSOR))
356 360 {
357 361 /*
358 362 * Get extra info for ACPI Device/Processor objects only:
359 - * Run the Device _HID, _UID, and _CID methods.
363 + * Run the Device _HID, _UID, _SUB, and _CID methods.
360 364 *
361 365 * Note: none of these methods are required, so they may or may
362 366 * not be present for this device. The Info->Valid bitfield is used
363 367 * to indicate which methods were found and run successfully.
364 368 */
365 369
366 370 /* Execute the Device._HID method */
367 371
368 372 Status = AcpiUtExecute_HID (Node, &Hid);
369 373 if (ACPI_SUCCESS (Status))
370 374 {
371 375 InfoSize += Hid->Length;
372 376 Valid |= ACPI_VALID_HID;
373 377 }
↓ open down ↓ |
4 lines elided |
↑ open up ↑ |
374 378
375 379 /* Execute the Device._UID method */
376 380
377 381 Status = AcpiUtExecute_UID (Node, &Uid);
378 382 if (ACPI_SUCCESS (Status))
379 383 {
380 384 InfoSize += Uid->Length;
381 385 Valid |= ACPI_VALID_UID;
382 386 }
383 387
388 + /* Execute the Device._SUB method */
389 +
390 + Status = AcpiUtExecute_SUB (Node, &Sub);
391 + if (ACPI_SUCCESS (Status))
392 + {
393 + InfoSize += Sub->Length;
394 + Valid |= ACPI_VALID_SUB;
395 + }
396 +
384 397 /* Execute the Device._CID method */
385 398
386 399 Status = AcpiUtExecute_CID (Node, &CidList);
387 400 if (ACPI_SUCCESS (Status))
388 401 {
389 402 /* Add size of CID strings and CID pointer array */
390 403
391 - InfoSize += (CidList->ListSize - sizeof (ACPI_DEVICE_ID_LIST));
404 + InfoSize += (CidList->ListSize - sizeof (ACPI_PNP_DEVICE_ID_LIST));
392 405 Valid |= ACPI_VALID_CID;
393 406 }
394 407 }
395 408
396 409 /*
397 410 * Now that we have the variable-length data, we can allocate the
398 411 * return buffer
399 412 */
400 413 Info = ACPI_ALLOCATE_ZEROED (InfoSize);
401 414 if (!Info)
402 415 {
403 416 Status = AE_NO_MEMORY;
404 417 goto Cleanup;
405 418 }
↓ open down ↓ |
4 lines elided |
↑ open up ↑ |
406 419
407 420 /* Get the fixed-length data */
408 421
409 422 if ((Type == ACPI_TYPE_DEVICE) ||
410 423 (Type == ACPI_TYPE_PROCESSOR))
411 424 {
412 425 /*
413 426 * Get extra info for ACPI Device/Processor objects only:
414 427 * Run the _STA, _ADR and, SxW, and _SxD methods.
415 428 *
416 - * Note: none of these methods are required, so they may or may
429 + * Notes: none of these methods are required, so they may or may
417 430 * not be present for this device. The Info->Valid bitfield is used
418 431 * to indicate which methods were found and run successfully.
432 + *
433 + * For _STA, if the method does not exist, then (as per the ACPI
434 + * specification), the returned CurrentStatus flags will indicate
435 + * that the device is present/functional/enabled. Otherwise, the
436 + * CurrentStatus flags reflect the value returned from _STA.
419 437 */
420 438
421 439 /* Execute the Device._STA method */
422 440
423 441 Status = AcpiUtExecute_STA (Node, &Info->CurrentStatus);
424 442 if (ACPI_SUCCESS (Status))
425 443 {
426 444 Valid |= ACPI_VALID_STA;
427 445 }
428 446
429 447 /* Execute the Device._ADR method */
430 448
431 449 Status = AcpiUtEvaluateNumericObject (METHOD_NAME__ADR, Node,
432 450 &Info->Address);
433 451 if (ACPI_SUCCESS (Status))
434 452 {
435 453 Valid |= ACPI_VALID_ADR;
436 454 }
437 455
438 456 /* Execute the Device._SxW methods */
439 457
440 458 Status = AcpiUtExecutePowerMethods (Node,
441 459 AcpiGbl_LowestDstateNames, ACPI_NUM_SxW_METHODS,
442 460 Info->LowestDstates);
443 461 if (ACPI_SUCCESS (Status))
444 462 {
445 463 Valid |= ACPI_VALID_SXWS;
446 464 }
447 465
448 466 /* Execute the Device._SxD methods */
449 467
450 468 Status = AcpiUtExecutePowerMethods (Node,
451 469 AcpiGbl_HighestDstateNames, ACPI_NUM_SxD_METHODS,
452 470 Info->HighestDstates);
453 471 if (ACPI_SUCCESS (Status))
454 472 {
455 473 Valid |= ACPI_VALID_SXDS;
↓ open down ↓ |
27 lines elided |
↑ open up ↑ |
456 474 }
457 475 }
458 476
459 477 /*
460 478 * Create a pointer to the string area of the return buffer.
461 479 * Point to the end of the base ACPI_DEVICE_INFO structure.
462 480 */
463 481 NextIdString = ACPI_CAST_PTR (char, Info->CompatibleIdList.Ids);
464 482 if (CidList)
465 483 {
466 - /* Point past the CID DEVICE_ID array */
484 + /* Point past the CID PNP_DEVICE_ID array */
467 485
468 - NextIdString += ((ACPI_SIZE) CidList->Count * sizeof (ACPI_DEVICE_ID));
486 + NextIdString += ((ACPI_SIZE) CidList->Count * sizeof (ACPI_PNP_DEVICE_ID));
469 487 }
470 488
471 489 /*
472 - * Copy the HID, UID, and CIDs to the return buffer. The variable-length
473 - * strings are copied to the reserved area at the end of the buffer.
490 + * Copy the HID, UID, SUB, and CIDs to the return buffer.
491 + * The variable-length strings are copied to the reserved area
492 + * at the end of the buffer.
474 493 *
475 494 * For HID and CID, check if the ID is a PCI Root Bridge.
476 495 */
477 496 if (Hid)
478 497 {
479 498 NextIdString = AcpiNsCopyDeviceId (&Info->HardwareId,
480 499 Hid, NextIdString);
481 500
482 501 if (AcpiUtIsPciRootBridge (Hid->String))
483 502 {
484 503 Info->Flags |= ACPI_PCI_ROOT_BRIDGE;
485 504 }
486 505 }
487 506
488 507 if (Uid)
489 508 {
490 509 NextIdString = AcpiNsCopyDeviceId (&Info->UniqueId,
491 510 Uid, NextIdString);
492 511 }
493 512
513 + if (Sub)
514 + {
515 + NextIdString = AcpiNsCopyDeviceId (&Info->SubsystemId,
516 + Sub, NextIdString);
517 + }
518 +
494 519 if (CidList)
495 520 {
496 521 Info->CompatibleIdList.Count = CidList->Count;
497 522 Info->CompatibleIdList.ListSize = CidList->ListSize;
498 523
499 524 /* Copy each CID */
500 525
501 526 for (i = 0; i < CidList->Count; i++)
502 527 {
503 528 NextIdString = AcpiNsCopyDeviceId (&Info->CompatibleIdList.Ids[i],
504 529 &CidList->Ids[i], NextIdString);
505 530
506 531 if (AcpiUtIsPciRootBridge (CidList->Ids[i].String))
507 532 {
508 533 Info->Flags |= ACPI_PCI_ROOT_BRIDGE;
509 534 }
510 535 }
511 536 }
512 537
513 538 /* Copy the fixed-length data */
514 539
515 540 Info->InfoSize = InfoSize;
516 541 Info->Type = Type;
517 542 Info->Name = Name;
518 543 Info->ParamCount = ParamCount;
519 544 Info->Valid = Valid;
520 545
521 546 *ReturnBuffer = Info;
522 547 Status = AE_OK;
523 548
↓ open down ↓ |
20 lines elided |
↑ open up ↑ |
524 549
525 550 Cleanup:
526 551 if (Hid)
527 552 {
528 553 ACPI_FREE (Hid);
529 554 }
530 555 if (Uid)
531 556 {
532 557 ACPI_FREE (Uid);
533 558 }
559 + if (Sub)
560 + {
561 + ACPI_FREE (Sub);
562 + }
534 563 if (CidList)
535 564 {
536 565 ACPI_FREE (CidList);
537 566 }
538 567 return (Status);
539 568 }
540 569
541 570 ACPI_EXPORT_SYMBOL (AcpiGetObjectInfo)
542 571
543 572
544 573 /******************************************************************************
545 574 *
546 575 * FUNCTION: AcpiInstallMethod
547 576 *
548 577 * PARAMETERS: Buffer - An ACPI table containing one control method
549 578 *
550 579 * RETURN: Status
551 580 *
552 581 * DESCRIPTION: Install a control method into the namespace. If the method
553 582 * name already exists in the namespace, it is overwritten. The
554 583 * input buffer must contain a valid DSDT or SSDT containing a
555 584 * single control method.
556 585 *
557 586 ******************************************************************************/
558 587
559 588 ACPI_STATUS
560 589 AcpiInstallMethod (
561 590 UINT8 *Buffer)
562 591 {
563 592 ACPI_TABLE_HEADER *Table = ACPI_CAST_PTR (ACPI_TABLE_HEADER, Buffer);
564 593 UINT8 *AmlBuffer;
565 594 UINT8 *AmlStart;
566 595 char *Path;
567 596 ACPI_NAMESPACE_NODE *Node;
568 597 ACPI_OPERAND_OBJECT *MethodObj;
569 598 ACPI_PARSE_STATE ParserState;
570 599 UINT32 AmlLength;
571 600 UINT16 Opcode;
572 601 UINT8 MethodFlags;
573 602 ACPI_STATUS Status;
574 603
575 604
576 605 /* Parameter validation */
577 606
578 607 if (!Buffer)
579 608 {
580 609 return (AE_BAD_PARAMETER);
581 610 }
582 611
583 612 /* Table must be a DSDT or SSDT */
584 613
585 614 if (!ACPI_COMPARE_NAME (Table->Signature, ACPI_SIG_DSDT) &&
586 615 !ACPI_COMPARE_NAME (Table->Signature, ACPI_SIG_SSDT))
587 616 {
588 617 return (AE_BAD_HEADER);
589 618 }
590 619
591 620 /* First AML opcode in the table must be a control method */
592 621
593 622 ParserState.Aml = Buffer + sizeof (ACPI_TABLE_HEADER);
594 623 Opcode = AcpiPsPeekOpcode (&ParserState);
595 624 if (Opcode != AML_METHOD_OP)
596 625 {
597 626 return (AE_BAD_PARAMETER);
598 627 }
599 628
600 629 /* Extract method information from the raw AML */
601 630
602 631 ParserState.Aml += AcpiPsGetOpcodeSize (Opcode);
603 632 ParserState.PkgEnd = AcpiPsGetNextPackageEnd (&ParserState);
604 633 Path = AcpiPsGetNextNamestring (&ParserState);
605 634 MethodFlags = *ParserState.Aml++;
606 635 AmlStart = ParserState.Aml;
607 636 AmlLength = ACPI_PTR_DIFF (ParserState.PkgEnd, AmlStart);
608 637
609 638 /*
610 639 * Allocate resources up-front. We don't want to have to delete a new
611 640 * node from the namespace if we cannot allocate memory.
612 641 */
613 642 AmlBuffer = ACPI_ALLOCATE (AmlLength);
614 643 if (!AmlBuffer)
615 644 {
616 645 return (AE_NO_MEMORY);
617 646 }
618 647
619 648 MethodObj = AcpiUtCreateInternalObject (ACPI_TYPE_METHOD);
620 649 if (!MethodObj)
621 650 {
622 651 ACPI_FREE (AmlBuffer);
623 652 return (AE_NO_MEMORY);
624 653 }
625 654
626 655 /* Lock namespace for AcpiNsLookup, we may be creating a new node */
627 656
628 657 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
629 658 if (ACPI_FAILURE (Status))
630 659 {
631 660 goto ErrorExit;
632 661 }
633 662
634 663 /* The lookup either returns an existing node or creates a new one */
635 664
636 665 Status = AcpiNsLookup (NULL, Path, ACPI_TYPE_METHOD, ACPI_IMODE_LOAD_PASS1,
637 666 ACPI_NS_DONT_OPEN_SCOPE | ACPI_NS_ERROR_IF_FOUND, NULL, &Node);
638 667
639 668 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
640 669
641 670 if (ACPI_FAILURE (Status)) /* NsLookup */
642 671 {
643 672 if (Status != AE_ALREADY_EXISTS)
644 673 {
645 674 goto ErrorExit;
646 675 }
647 676
648 677 /* Node existed previously, make sure it is a method node */
649 678
650 679 if (Node->Type != ACPI_TYPE_METHOD)
651 680 {
652 681 Status = AE_TYPE;
653 682 goto ErrorExit;
654 683 }
655 684 }
656 685
657 686 /* Copy the method AML to the local buffer */
658 687
659 688 ACPI_MEMCPY (AmlBuffer, AmlStart, AmlLength);
660 689
661 690 /* Initialize the method object with the new method's information */
662 691
663 692 MethodObj->Method.AmlStart = AmlBuffer;
664 693 MethodObj->Method.AmlLength = AmlLength;
665 694
666 695 MethodObj->Method.ParamCount = (UINT8)
667 696 (MethodFlags & AML_METHOD_ARG_COUNT);
668 697
669 698 if (MethodFlags & AML_METHOD_SERIALIZED)
670 699 {
671 700 MethodObj->Method.InfoFlags = ACPI_METHOD_SERIALIZED;
672 701
673 702 MethodObj->Method.SyncLevel = (UINT8)
674 703 ((MethodFlags & AML_METHOD_SYNC_LEVEL) >> 4);
675 704 }
676 705
677 706 /*
678 707 * Now that it is complete, we can attach the new method object to
679 708 * the method Node (detaches/deletes any existing object)
680 709 */
681 710 Status = AcpiNsAttachObject (Node, MethodObj, ACPI_TYPE_METHOD);
682 711
683 712 /*
684 713 * Flag indicates AML buffer is dynamic, must be deleted later.
685 714 * Must be set only after attach above.
686 715 */
687 716 Node->Flags |= ANOBJ_ALLOCATED_BUFFER;
688 717
689 718 /* Remove local reference to the method object */
690 719
691 720 AcpiUtRemoveReference (MethodObj);
692 721 return (Status);
693 722
694 723
695 724 ErrorExit:
696 725
697 726 ACPI_FREE (AmlBuffer);
698 727 ACPI_FREE (MethodObj);
699 728 return (Status);
700 729 }
701 730
702 731 ACPI_EXPORT_SYMBOL (AcpiInstallMethod)
↓ open down ↓ |
159 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX