| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
#include "acpi.h" |
| 45 |
#include "accommon.h" |
| 46 |
#include "amlcode.h" |
| 47 |
#include "acnamesp.h" |
| 48 |
|
| 49 |
|
| 50 |
#define _COMPONENT ACPI_NAMESPACE |
| 51 |
ACPI_MODULE_NAME ("nsnames") |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
char * |
| 70 |
AcpiNsGetExternalPathname ( |
| 71 |
ACPI_NAMESPACE_NODE *Node) |
| 72 |
{ |
| 73 |
char *NameBuffer; |
| 74 |
|
| 75 |
|
| 76 |
ACPI_FUNCTION_TRACE_PTR (NsGetExternalPathname, Node); |
| 77 |
|
| 78 |
|
| 79 |
NameBuffer = AcpiNsGetNormalizedPathname (Node, FALSE); |
| 80 |
return_PTR (NameBuffer); |
| 81 |
} |
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
ACPI_SIZE |
| 97 |
AcpiNsGetPathnameLength ( |
| 98 |
ACPI_NAMESPACE_NODE *Node) |
| 99 |
{ |
| 100 |
ACPI_SIZE Size; |
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
if (ACPI_GET_DESCRIPTOR_TYPE (Node) != ACPI_DESC_TYPE_NAMED) |
| 106 |
{ |
| 107 |
ACPI_ERROR ((AE_INFO, |
| 108 |
"Invalid/cached reference target node: %p, descriptor type %d", |
| 109 |
Node, ACPI_GET_DESCRIPTOR_TYPE (Node))); |
| 110 |
return (0); |
| 111 |
} |
| 112 |
|
| 113 |
Size = AcpiNsBuildNormalizedPath (Node, NULL, 0, FALSE); |
| 114 |
return (Size); |
| 115 |
} |
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
ACPI_STATUS |
| 133 |
AcpiNsHandleToName ( |
| 134 |
ACPI_HANDLE TargetHandle, |
| 135 |
ACPI_BUFFER *Buffer) |
| 136 |
{ |
| 137 |
ACPI_STATUS Status; |
| 138 |
ACPI_NAMESPACE_NODE *Node; |
| 139 |
const char *NodeName; |
| 140 |
|
| 141 |
|
| 142 |
ACPI_FUNCTION_TRACE_PTR (NsHandleToName, TargetHandle); |
| 143 |
|
| 144 |
|
| 145 |
Node = AcpiNsValidateHandle (TargetHandle); |
| 146 |
if (!Node) |
| 147 |
{ |
| 148 |
return_ACPI_STATUS (AE_BAD_PARAMETER); |
| 149 |
} |
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
Status = AcpiUtInitializeBuffer (Buffer, ACPI_PATH_SEGMENT_LENGTH); |
| 154 |
if (ACPI_FAILURE (Status)) |
| 155 |
{ |
| 156 |
return_ACPI_STATUS (Status); |
| 157 |
} |
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
NodeName = AcpiUtGetNodeName (Node); |
| 162 |
ACPI_COPY_NAMESEG (Buffer->Pointer, NodeName); |
| 163 |
((char *) Buffer->Pointer) [ACPI_NAMESEG_SIZE] = 0; |
| 164 |
|
| 165 |
ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "%4.4s\n", (char *) Buffer->Pointer)); |
| 166 |
return_ACPI_STATUS (AE_OK); |
| 167 |
} |
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
ACPI_STATUS |
| 187 |
AcpiNsHandleToPathname ( |
| 188 |
ACPI_HANDLE TargetHandle, |
| 189 |
ACPI_BUFFER *Buffer, |
| 190 |
BOOLEAN NoTrailing) |
| 191 |
{ |
| 192 |
ACPI_STATUS Status; |
| 193 |
ACPI_NAMESPACE_NODE *Node; |
| 194 |
ACPI_SIZE RequiredSize; |
| 195 |
|
| 196 |
|
| 197 |
ACPI_FUNCTION_TRACE_PTR (NsHandleToPathname, TargetHandle); |
| 198 |
|
| 199 |
|
| 200 |
Node = AcpiNsValidateHandle (TargetHandle); |
| 201 |
if (!Node) |
| 202 |
{ |
| 203 |
return_ACPI_STATUS (AE_BAD_PARAMETER); |
| 204 |
} |
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
RequiredSize = AcpiNsBuildNormalizedPath (Node, NULL, 0, NoTrailing); |
| 209 |
if (!RequiredSize) |
| 210 |
{ |
| 211 |
return_ACPI_STATUS (AE_BAD_PARAMETER); |
| 212 |
} |
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
Status = AcpiUtInitializeBuffer (Buffer, RequiredSize); |
| 217 |
if (ACPI_FAILURE (Status)) |
| 218 |
{ |
| 219 |
return_ACPI_STATUS (Status); |
| 220 |
} |
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
(void) AcpiNsBuildNormalizedPath (Node, Buffer->Pointer, |
| 225 |
(UINT32) RequiredSize, NoTrailing); |
| 226 |
|
| 227 |
ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "%s [%X]\n", |
| 228 |
(char *) Buffer->Pointer, (UINT32) RequiredSize)); |
| 229 |
return_ACPI_STATUS (AE_OK); |
| 230 |
} |
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
UINT32 |
| 256 |
AcpiNsBuildNormalizedPath ( |
| 257 |
ACPI_NAMESPACE_NODE *Node, |
| 258 |
char *FullPath, |
| 259 |
UINT32 PathSize, |
| 260 |
BOOLEAN NoTrailing) |
| 261 |
{ |
| 262 |
UINT32 Length = 0, i; |
| 263 |
char Name[ACPI_NAMESEG_SIZE] ACPI_NONSTRING; |
| 264 |
BOOLEAN DoNoTrailing; |
| 265 |
char c, *Left, *Right; |
| 266 |
ACPI_NAMESPACE_NODE *NextNode; |
| 267 |
|
| 268 |
|
| 269 |
ACPI_FUNCTION_TRACE_PTR (NsBuildNormalizedPath, Node); |
| 270 |
|
| 271 |
|
| 272 |
#define ACPI_PATH_PUT8(Path, Size, Byte, Length) \ |
| 273 |
do { \ |
| 274 |
if ((Length) < (Size)) \ |
| 275 |
{ \ |
| 276 |
(Path)[(Length)] = (Byte); \ |
| 277 |
} \ |
| 278 |
(Length)++; \ |
| 279 |
} while (0) |
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
if (!FullPath) |
| 286 |
{ |
| 287 |
PathSize = 0; |
| 288 |
} |
| 289 |
|
| 290 |
if (!Node) |
| 291 |
{ |
| 292 |
goto BuildTrailingNull; |
| 293 |
} |
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
if (ACPI_GET_DESCRIPTOR_TYPE (Node) != ACPI_DESC_TYPE_NAMED) |
| 298 |
{ |
| 299 |
goto BuildTrailingNull; |
| 300 |
} |
| 301 |
|
| 302 |
NextNode = Node; |
| 303 |
while (NextNode && NextNode != AcpiGbl_RootNode) |
| 304 |
{ |
| 305 |
if (NextNode != Node) |
| 306 |
{ |
| 307 |
ACPI_PATH_PUT8(FullPath, PathSize, AML_DUAL_NAME_PREFIX, Length); |
| 308 |
} |
| 309 |
|
| 310 |
ACPI_MOVE_32_TO_32 (Name, &NextNode->Name); |
| 311 |
DoNoTrailing = NoTrailing; |
| 312 |
for (i = 0; i < 4; i++) |
| 313 |
{ |
| 314 |
c = Name[4-i-1]; |
| 315 |
if (DoNoTrailing && c != '_') |
| 316 |
{ |
| 317 |
DoNoTrailing = FALSE; |
| 318 |
} |
| 319 |
if (!DoNoTrailing) |
| 320 |
{ |
| 321 |
ACPI_PATH_PUT8(FullPath, PathSize, c, Length); |
| 322 |
} |
| 323 |
} |
| 324 |
|
| 325 |
NextNode = NextNode->Parent; |
| 326 |
} |
| 327 |
|
| 328 |
ACPI_PATH_PUT8(FullPath, PathSize, AML_ROOT_PREFIX, Length); |
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
if (Length <= PathSize) |
| 333 |
{ |
| 334 |
Left = FullPath; |
| 335 |
Right = FullPath+Length - 1; |
| 336 |
|
| 337 |
while (Left < Right) |
| 338 |
{ |
| 339 |
c = *Left; |
| 340 |
*Left++ = *Right; |
| 341 |
*Right-- = c; |
| 342 |
} |
| 343 |
} |
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
BuildTrailingNull: |
| 348 |
ACPI_PATH_PUT8 (FullPath, PathSize, '\0', Length); |
| 349 |
|
| 350 |
#undef ACPI_PATH_PUT8 |
| 351 |
|
| 352 |
return_UINT32 (Length); |
| 353 |
} |
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
char * |
| 374 |
AcpiNsGetNormalizedPathname ( |
| 375 |
ACPI_NAMESPACE_NODE *Node, |
| 376 |
BOOLEAN NoTrailing) |
| 377 |
{ |
| 378 |
char *NameBuffer; |
| 379 |
ACPI_SIZE Size; |
| 380 |
|
| 381 |
|
| 382 |
ACPI_FUNCTION_TRACE_PTR (NsGetNormalizedPathname, Node); |
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
Size = AcpiNsBuildNormalizedPath (Node, NULL, 0, NoTrailing); |
| 388 |
if (!Size) |
| 389 |
{ |
| 390 |
return_PTR (NULL); |
| 391 |
} |
| 392 |
|
| 393 |
|
| 394 |
|
| 395 |
NameBuffer = ACPI_ALLOCATE_ZEROED (Size); |
| 396 |
if (!NameBuffer) |
| 397 |
{ |
| 398 |
ACPI_ERROR ((AE_INFO, |
| 399 |
"Could not allocate %u bytes", (UINT32) Size)); |
| 400 |
return_PTR (NULL); |
| 401 |
} |
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
(void) AcpiNsBuildNormalizedPath (Node, NameBuffer, (UINT32) Size, NoTrailing); |
| 406 |
|
| 407 |
ACPI_DEBUG_PRINT_RAW ((ACPI_DB_NAMES, "%s: Path \"%s\"\n", |
| 408 |
ACPI_GET_FUNCTION_NAME, NameBuffer)); |
| 409 |
|
| 410 |
return_PTR (NameBuffer); |
| 411 |
} |
| 412 |
|
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
|
| 425 |
|
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
char * |
| 430 |
AcpiNsBuildPrefixedPathname ( |
| 431 |
ACPI_GENERIC_STATE *PrefixScope, |
| 432 |
const char *InternalPath) |
| 433 |
{ |
| 434 |
ACPI_STATUS Status; |
| 435 |
char *FullPath = NULL; |
| 436 |
char *ExternalPath = NULL; |
| 437 |
char *PrefixPath = NULL; |
| 438 |
ACPI_SIZE PrefixPathLength = 0; |
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
if (PrefixScope && PrefixScope->Scope.Node) |
| 444 |
{ |
| 445 |
PrefixPath = AcpiNsGetNormalizedPathname (PrefixScope->Scope.Node, TRUE); |
| 446 |
if (PrefixPath) |
| 447 |
{ |
| 448 |
PrefixPathLength = strlen (PrefixPath); |
| 449 |
} |
| 450 |
} |
| 451 |
|
| 452 |
Status = AcpiNsExternalizeName (ACPI_UINT32_MAX, InternalPath, |
| 453 |
NULL, &ExternalPath); |
| 454 |
if (ACPI_FAILURE (Status)) |
| 455 |
{ |
| 456 |
goto Cleanup; |
| 457 |
} |
| 458 |
|
| 459 |
|
| 460 |
|
| 461 |
FullPath = ACPI_ALLOCATE_ZEROED ( |
| 462 |
PrefixPathLength + strlen (ExternalPath) + 2); |
| 463 |
if (!FullPath) |
| 464 |
{ |
| 465 |
goto Cleanup; |
| 466 |
} |
| 467 |
|
| 468 |
|
| 469 |
|
| 470 |
if (PrefixPath && |
| 471 |
(*ExternalPath != '\\') && |
| 472 |
(*ExternalPath != '^')) |
| 473 |
{ |
| 474 |
strcat (FullPath, PrefixPath); |
| 475 |
if (PrefixPath[1]) |
| 476 |
{ |
| 477 |
strcat (FullPath, "."); |
| 478 |
} |
| 479 |
} |
| 480 |
|
| 481 |
AcpiNsNormalizePathname (ExternalPath); |
| 482 |
strcat (FullPath, ExternalPath); |
| 483 |
|
| 484 |
Cleanup: |
| 485 |
if (PrefixPath) |
| 486 |
{ |
| 487 |
ACPI_FREE (PrefixPath); |
| 488 |
} |
| 489 |
if (ExternalPath) |
| 490 |
{ |
| 491 |
ACPI_FREE (ExternalPath); |
| 492 |
} |
| 493 |
|
| 494 |
return (FullPath); |
| 495 |
} |
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
|
| 501 |
|
| 502 |
|
| 503 |
|
| 504 |
|
| 505 |
|
| 506 |
|
| 507 |
|
| 508 |
|
| 509 |
|
| 510 |
|
| 511 |
|
| 512 |
void |
| 513 |
AcpiNsNormalizePathname ( |
| 514 |
char *OriginalPath) |
| 515 |
{ |
| 516 |
char *InputPath = OriginalPath; |
| 517 |
char *NewPathBuffer; |
| 518 |
char *NewPath; |
| 519 |
UINT32 i; |
| 520 |
|
| 521 |
|
| 522 |
|
| 523 |
|
| 524 |
NewPathBuffer = ACPI_ALLOCATE_ZEROED (strlen (InputPath) + 1); |
| 525 |
NewPath = NewPathBuffer; |
| 526 |
if (!NewPathBuffer) |
| 527 |
{ |
| 528 |
return; |
| 529 |
} |
| 530 |
|
| 531 |
|
| 532 |
|
| 533 |
if (*InputPath == '\\') |
| 534 |
{ |
| 535 |
*NewPath = *InputPath; |
| 536 |
NewPath++; |
| 537 |
InputPath++; |
| 538 |
} |
| 539 |
|
| 540 |
while (*InputPath == '^') |
| 541 |
{ |
| 542 |
*NewPath = *InputPath; |
| 543 |
NewPath++; |
| 544 |
InputPath++; |
| 545 |
} |
| 546 |
|
| 547 |
|
| 548 |
|
| 549 |
while (*InputPath) |
| 550 |
{ |
| 551 |
|
| 552 |
|
| 553 |
for (i = 0; (i < ACPI_NAMESEG_SIZE) && *InputPath; i++) |
| 554 |
{ |
| 555 |
if ((i == 0) || (*InputPath != '_')) |
| 556 |
{ |
| 557 |
*NewPath = *InputPath; |
| 558 |
NewPath++; |
| 559 |
} |
| 560 |
|
| 561 |
InputPath++; |
| 562 |
} |
| 563 |
|
| 564 |
|
| 565 |
|
| 566 |
if (*InputPath == '.') |
| 567 |
{ |
| 568 |
*NewPath = *InputPath; |
| 569 |
NewPath++; |
| 570 |
InputPath++; |
| 571 |
} |
| 572 |
} |
| 573 |
|
| 574 |
*NewPath = 0; |
| 575 |
strcpy (OriginalPath, NewPathBuffer); |
| 576 |
ACPI_FREE (NewPathBuffer); |
| 577 |
} |