1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 /* 22 * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 23 * Use is subject to license terms. 24 * 25 * Opl Platform specific functions. 26 * 27 * called when : 28 * machine_type == MTYPE_OPL 29 */ 30 31 #pragma ident "%Z%%M% %I% %E% SMI" 32 33 #include <stdio.h> 34 #include <stdlib.h> 35 #include <unistd.h> 36 #include <ctype.h> 37 #include <string.h> 38 #include <varargs.h> 39 #include <fcntl.h> 40 #include <assert.h> 41 #include <sys/param.h> 42 #include <sys/stat.h> 43 #include <sys/types.h> 44 #include <sys/utsname.h> 45 #include <sys/systeminfo.h> 46 #include <sys/openpromio.h> 47 #include <libintl.h> 48 #include <syslog.h> 49 #include <sys/dkio.h> 50 #include <pdevinfo.h> 51 #include <libprtdiag.h> 52 #include <libdevinfo.h> 53 #include <kstat.h> 54 55 /* 56 * Globals and externs 57 */ 58 #define KBYTE 1024 59 #define MBYTE (KBYTE * KBYTE) 60 #define HZ_TO_MHZ(x) ((((uint64_t)(x)) + 500000) / 1000000) 61 #define SCF_SECURE_MODE_KSTAT_NAMED "secure_mode" 62 #define SCF_STAT_MODE_UNLOCK 0 63 #define SCF_STAT_MODE_LOCK 1 64 #define SCF_SYSTEM_KSTAT_NAME "scf" 65 #ifndef TEXT_DOMAIN 66 #define TEXT_DOMAIN "SYS_TEST" 67 #endif /* TEXT_DOMAIN */ 68 #define IS_PCI_BRIDGE(name, type) \ 69 (((name) != NULL) && ((type) != NULL) && \ 70 (strncmp((name), "pci", 3) == 0) && \ 71 (strncmp((type), "pci", 3) == 0)) 72 73 /* 74 * Global functions and variables 75 * these functions will overlay the symbol table of libprtdiag 76 * at runtime (Opl systems only) 77 */ 78 struct cs_status { 79 int cs_number; 80 int status; 81 int avail_hi; 82 int avail_lo; 83 int dimm_hi; 84 int dimm_lo; 85 int dimms; 86 }; 87 88 int do_prominfo(int syserrlog, char *pgname, int log_flag, int prt_flag); 89 void *get_prop_val(Prop *prop); 90 void display_pci(Board_node *); 91 void display_ffb(Board_node *, int); 92 void display_sbus(Board_node *board); 93 void display_cpu_devices(Sys_tree *tree); 94 void display_cpus(Board_node *board); 95 void display_memoryconf(Sys_tree *tree, struct grp_info *grps); 96 void display_io_cards(struct io_card *list); 97 void display_diaginfo(int flag, Prom_node *root, Sys_tree *tree, 98 struct system_kstat_data *kstats); 99 Prop *find_prop(Prom_node *pnode, char *name); 100 101 /* Local functions */ 102 static void opl_disp_environ(void); 103 static void opl_disp_hw_revisions(Sys_tree *tree, Prom_node *root); 104 static uint64_t print_opl_memory_line(int lsb, struct cs_status *cs_stat, 105 int ngrps); 106 static uint64_t get_opl_mem_regs(Board_node *bnode); 107 void add_node(Sys_tree *root, Prom_node *pnode); 108 static int get_prop_size(Prop *prop); 109 110 /* 111 * Display all the leaf PCI nodes on this board that have "reg" property. 112 * If the "reg" property is NULL for a leaf node, skip parsing its sibling 113 * nodes and display the parent node properties. 114 */ 115 void 116 display_pci(Board_node *board) 117 { 118 struct io_card *card_list = NULL; 119 struct io_card card; 120 Prom_node *pci, *card_node; 121 char *name, *type; 122 int *int_val; 123 124 if (board == NULL) 125 return; 126 127 /* Initialize common information */ 128 card.board = board->board_num; 129 130 pci = board->nodes; 131 while (pci != NULL) { 132 name = get_node_name(pci); 133 134 /* Skip non-PCI board nodes */ 135 if ((name == NULL) || (strcmp(name, "pci") != 0)) { 136 pci = pci->sibling; 137 continue; 138 } 139 140 type = (char *)get_prop_val(find_prop(pci, "device_type")); 141 142 /* 143 * Skip PCI/ebus devices 144 * They have name == "pci" and type == "pci" 145 */ 146 if (strcmp(type, "pci") == 0) { 147 pci = pci->sibling; 148 continue; 149 } 150 151 card_node = pci; 152 while (card_node != NULL) { 153 int pci_parent_bridge = 0; 154 155 /* If it does have a child, skip to leaf child */ 156 if (card_node->child != NULL) { 157 card_node = card_node->child; 158 continue; 159 } 160 161 /* Get name of the card */ 162 name = (char *)get_prop_val(find_prop 163 (card_node, "name")); 164 165 /* Get type of card */ 166 type = (char *)get_prop_val(find_prop 167 (card_node, "device_type")); 168 169 /* Leaf pci-bridges are to be ignored */ 170 if (!IS_PCI_BRIDGE(name, type)) { 171 172 /* Get reg property of the node */ 173 int_val = (int *)get_prop_val(find_prop 174 (card_node, "reg")); 175 176 /* 177 * If no "reg" property check to see 178 * whether parent node has reg property. 179 * and check if parent is a bridge 180 */ 181 if (int_val == NULL) { 182 Prom_node *cparent = card_node->parent; 183 if (cparent == NULL) 184 break; 185 186 name = (char *)get_prop_val(find_prop 187 (cparent, "name")); 188 189 type = (char *)get_prop_val(find_prop 190 (cparent, "device_type")); 191 192 /* check if parent is a bridge */ 193 if (IS_PCI_BRIDGE(name, type)) 194 pci_parent_bridge = 1; 195 196 int_val = (int *)get_prop_val( 197 find_prop(cparent, "reg")); 198 199 if (int_val != NULL) 200 /* Switch to parent */ 201 card_node = cparent; 202 else 203 /* parent node has no reg */ 204 break; 205 } 206 207 if (!pci_parent_bridge) { 208 209 name = (char *)get_prop_val(find_prop 210 (card_node, "name")); 211 212 if (name == NULL) 213 card.name[0] = '\0'; 214 else { 215 (void) snprintf(card.name, 216 MAXSTRLEN, "%s", name); 217 } 218 219 /* Get the model of this card */ 220 name = (char *)get_prop_val(find_prop 221 (card_node, "model")); 222 223 if (name == NULL) { 224 (void) snprintf(card.model, 225 MAXSTRLEN, "%s", "N/A"); 226 } else { 227 (void) snprintf(card.model, 228 MAXSTRLEN, "%s", name); 229 } 230 231 /* insert card to the list */ 232 card_list = insert_io_card 233 (card_list, &card); 234 235 } 236 237 } 238 239 /* 240 * Parse sibling nodes. 241 * Then move up the parent's sibling upto the top 242 * intermediate node 243 * Stop if pci board node is reached. 244 */ 245 if (card_node->sibling != NULL) 246 card_node = card_node->sibling; 247 else { 248 Prom_node *cparent; 249 cparent = card_node->parent; 250 card_node = NULL; 251 while (cparent != NULL) { 252 if (cparent == pci) 253 break; 254 if (cparent->sibling != NULL) { 255 card_node = cparent->sibling; 256 break; 257 } 258 cparent = cparent->parent; 259 } 260 } 261 262 } 263 264 /* On to the next board node */ 265 pci = pci->sibling; 266 267 } 268 269 display_io_cards(card_list); 270 free_io_cards(card_list); 271 } 272 273 /* 274 * There are no FFB's on OPL. 275 */ 276 /*ARGSUSED*/ 277 void 278 display_ffb(Board_node *board, int table) 279 { 280 } 281 282 /* 283 * There are no Sbus's on OPL. 284 */ 285 /*ARGSUSED*/ 286 void 287 display_sbus(Board_node *board) 288 { 289 } 290 291 /* 292 * Details of I/O information. Print out all the io cards. 293 */ 294 void 295 display_io_cards(struct io_card *list) 296 { 297 char *hdrfmt = "%-6.6s %-14.14s %-12.12s\n"; 298 299 struct io_card *p; 300 301 if (list == NULL) 302 return; 303 304 (void) textdomain(TEXT_DOMAIN); 305 306 log_printf(hdrfmt, gettext("LSB"), gettext("Name"), gettext("Model"), 307 0); 308 309 log_printf(hdrfmt, "---", "-----------------", "------------", 0); 310 311 for (p = list; p != NULL; p = p->next) { 312 313 /* Board number */ 314 log_printf(" %02d ", p->board, 0); 315 316 /* Card name */ 317 log_printf("%-15.15s", p->name, 0); 318 319 /* Card model */ 320 log_printf("%-12.12s", p->model, 0); 321 322 log_printf("\n", 0); 323 } 324 log_printf("\n", 0); 325 } 326 327 /* 328 * Details of CPU information. 329 */ 330 void 331 display_cpu_devices(Sys_tree *tree) 332 { 333 Board_node *bnode; 334 char *hdrfmt = 335 "%-5.5s %-8.8s %-20.20s %-8.8s %-8.8s %-8.8s %-8.8s\n"; 336 337 (void) textdomain(TEXT_DOMAIN); 338 339 /* 340 * Display the table header for CPUs . Then display the CPU 341 * frequency, cache size, and processor revision of all cpus. 342 */ 343 log_printf("\n", 0); 344 log_printf("====================================", 0); 345 log_printf(gettext(" CPUs "), 0); 346 log_printf("====================================", 0); 347 log_printf("\n\n", 0); 348 349 log_printf(hdrfmt, 350 "", 351 gettext("CPU"), 352 gettext(" CPU "), 353 gettext("Run"), 354 gettext("L2$"), 355 gettext("CPU"), 356 gettext("CPU"), 0); 357 358 log_printf(hdrfmt, 359 gettext("LSB"), 360 gettext("Chip"), 361 gettext(" ID "), 362 gettext("MHz"), 363 gettext(" MB"), 364 gettext("Impl."), 365 gettext("Mask"), 0); 366 367 log_printf(hdrfmt, 368 "---", "----", "--------------------", "----", 369 "---", "-----", "----", 0); 370 371 /* Now display all of the cpus on each board */ 372 for (bnode = tree->bd_list; bnode != NULL; bnode = bnode->next) { 373 display_cpus(bnode); 374 } 375 376 log_printf("\n", 0); 377 } 378 379 /* 380 * Display the CPUs present on this board. 381 */ 382 void 383 display_cpus(Board_node *board) 384 { 385 int *impl, *mask, *cpuid, *portid, *l2cache_size; 386 uint_t freq; /* CPU clock frequency */ 387 Prom_node *pnode, *cpu; 388 char *name; 389 390 (void) textdomain(TEXT_DOMAIN); 391 392 /* 393 * Get the Cpus' properties for display 394 */ 395 for (pnode = board->nodes; pnode != NULL; pnode = pnode->sibling) { 396 char cpu_str[MAXSTRLEN], fcpu_str[MAXSTRLEN] = {0}; 397 398 name = get_node_name(pnode); 399 if ((name == NULL) || (strncmp(name, "cmp", 3) != 0)) { 400 continue; 401 } 402 403 portid = (int *)get_prop_val(find_prop(pnode, "portid")); 404 freq = (HZ_TO_MHZ(get_cpu_freq(pnode->child))); 405 l2cache_size = 406 (int *)get_prop_val 407 (find_prop(pnode->child, "l2-cache-size")); 408 impl = 409 (int *)get_prop_val 410 (find_prop(pnode->child, "implementation#")); 411 mask = (int *)get_prop_val(find_prop(pnode->child, "mask#")); 412 413 /* Lsb id */ 414 log_printf(" %02d ", board->board_num, 0); 415 416 if (portid != NULL) 417 log_printf("%3d ", (((*portid)>>3)&0x3), 0); 418 419 /* 420 * Specific parsing of the CMP/CORE/CPU chain. 421 * The internal cpu tree built by walk_di_tree() 422 * in common code can be illustrated by the diagram 423 * below: 424 * 425 * cmp->cpu->cpu->cpu->cpu->(next board nodes) 426 * / \ 427 * core core 428 * where "/" or "\" are children 429 * and "->" are siblings 430 */ 431 for (cpu = pnode->sibling; cpu != NULL; ) { 432 Prom_node *cpu_next = NULL; 433 434 name = get_node_name(cpu); 435 if ((name == NULL) || (strncmp(name, "cpu", 3) != 0)) { 436 break; 437 } 438 439 /* Id assigned to Virtual processor core */ 440 cpuid = (int *)get_prop_val(find_prop(cpu, "cpuid")); 441 cpu_next = cpu->sibling; 442 443 if (cpu_next != NULL) { 444 name = get_node_name(cpu_next); 445 446 if ((name == NULL) || 447 (strncmp(name, "cpu", 3) != 0)) { 448 cpu_next = NULL; 449 } 450 } 451 452 if (cpuid != NULL) { 453 /* Used for printing in comma format */ 454 (void) sprintf(cpu_str, "%4d", *cpuid); 455 (void) strlcat(fcpu_str, cpu_str, MAXSTRLEN); 456 457 if (cpu_next != NULL) 458 (void) strlcat(fcpu_str, ",", MAXSTRLEN); 459 } else { 460 (void) sprintf(cpu_str, "%4s", "N/A"); 461 (void) strlcat(fcpu_str, cpu_str, MAXSTRLEN); 462 463 if (cpu_next != NULL) 464 (void) strlcat(fcpu_str, ",", MAXSTRLEN); 465 } 466 cpu = cpu_next; 467 } 468 469 log_printf("%-20.20s", fcpu_str, 0); 470 471 /* Running frequency */ 472 if (freq != 0) 473 log_printf(" %4ld ", freq, 0); 474 else 475 log_printf(" %4s ", "N/A", 0); 476 477 /* L2 cache size */ 478 if (l2cache_size == NULL) 479 log_printf(" %3s ", "N/A", 0); 480 else { 481 log_printf("%4.1f ", 482 (float)(*l2cache_size) / (float)(1<<20), 0); 483 } 484 485 486 /* Implementation number of processor */ 487 if (impl != NULL) 488 log_printf("%4d ", *impl, 0); 489 else 490 log_printf("%4s ", "N/A", 0); 491 492 /* Mask Set version */ 493 /* Bits 31:24 of VER register is mask. */ 494 /* Mask value : Non MTP mode - 00-7f, MTP mode - 80-ff */ 495 if (mask == NULL) 496 log_printf("%4s", "N/A", 0); 497 else 498 log_printf("%4d", (*mask)&0xff, 0); 499 500 log_printf("\n", 0); 501 502 } 503 } 504 505 /* 506 * Gather memory information: Details of memory information. 507 */ 508 static uint64_t 509 get_opl_mem_regs(Board_node *bnode) 510 { 511 Prom_node *pnode; 512 struct cs_status *cs_stat; 513 uint64_t total_mem = 0; 514 int cs_size, ngrps; 515 516 pnode = dev_find_node(bnode->nodes, "pseudo-mc"); 517 while (pnode != NULL) { 518 519 cs_size = get_prop_size(find_prop(pnode, "cs-status")); 520 521 if (cs_size > 0) { 522 523 /* OBP returns lists of 7 ints */ 524 cs_stat = (struct cs_status *)get_prop_val 525 (find_prop(pnode, "cs-status")); 526 527 /* cs_size must be at least 28 */ 528 ngrps = cs_size/sizeof (struct cs_status); 529 530 if (cs_stat != NULL) { 531 total_mem += 532 print_opl_memory_line(bnode->board_num, 533 cs_stat, ngrps); 534 } 535 } 536 537 pnode = dev_next_node(pnode, "pseudo-mc"); 538 } 539 return (total_mem); 540 } 541 542 /* 543 * Display memory information. 544 */ 545 /*ARGSUSED*/ 546 void 547 display_memoryconf(Sys_tree *tree, struct grp_info *grps) 548 { 549 Board_node *bnode = tree->bd_list; 550 uint64_t total_mem = 0, total_sys_mem = 0; 551 char *hdrfmt = "\n%-5.5s %-6.6s %-12.12s %-10.10s" 552 " %-8.8s %-10.10s"; 553 554 (void) textdomain(TEXT_DOMAIN); 555 556 log_printf("======================", 0); 557 log_printf(gettext(" Memory Configuration "), 0); 558 log_printf("======================", 0); 559 log_printf("\n", 0); 560 561 log_printf(hdrfmt, 562 "", 563 gettext("Memory"), 564 gettext("Available"), 565 gettext("Memory"), 566 gettext("DIMM"), 567 gettext("Number of"), 568 0); 569 570 log_printf(hdrfmt, 571 gettext("LSB"), 572 gettext("Group"), 573 gettext("Size"), 574 gettext("Status"), 575 gettext("Size"), 576 gettext("DIMMs"), 0); 577 578 log_printf(hdrfmt, 579 "---", "-------", "------------", "-------", "-----", 580 "---------", 0); 581 582 log_printf("\n", 0); 583 584 for (bnode = tree->bd_list; bnode != NULL; bnode = bnode->next) { 585 total_mem += get_opl_mem_regs(bnode); 586 } 587 588 /* 589 * Sanity check to ensure that the total amount of system 590 * memory matches the total number of memory that 591 * we find here. Display error message if there is a mis-match. 592 */ 593 total_sys_mem = (((uint64_t)sysconf(_SC_PAGESIZE) * (uint64_t)sysconf 594 (_SC_PHYS_PAGES)) / MBYTE); 595 596 if (total_mem != total_sys_mem) { 597 log_printf(dgettext(TEXT_DOMAIN, 598 "\nError:total available size [%lldMB] does not match" 599 " total system memory [%lldMB]\n"), 600 total_mem, total_sys_mem, 0); 601 } 602 603 } 604 605 /* 606 * This function provides Opl's formatting of the memory config 607 * information that get_opl_mem_regs() has gathered. 608 */ 609 static uint64_t 610 print_opl_memory_line(int lsb, struct cs_status *cs_stat, int ngrps) 611 { 612 int i; 613 uint64_t total_board_mem = 0; 614 615 (void) textdomain(TEXT_DOMAIN); 616 617 618 for (i = 0; i < ngrps; i++) { 619 int64_t mem_size = 0; 620 621 mem_size = ((((int64_t)cs_stat[i].avail_hi)<<32) + 622 cs_stat[i].avail_lo); 623 624 if (mem_size == 0) continue; 625 626 /* Lsb Id */ 627 log_printf(" %02d ", lsb, 0); 628 629 /* Memory Group Number */ 630 if ((cs_stat[i].cs_number) == 0) 631 log_printf("%-6.6s", "A", 0); 632 else 633 log_printf("%-6.6s", "B", 0); 634 635 /* Memory Group Size */ 636 log_printf(" %4lldMB ", mem_size/MBYTE, 0); 637 638 total_board_mem += (mem_size/MBYTE); 639 640 /* Memory Group Status */ 641 log_printf("%-11.11s", 642 cs_stat[i].status ? "partial": "okay", 0); 643 644 /* DIMM Size */ 645 log_printf("%4lldMB ", 646 ((((int64_t)cs_stat[i].dimm_hi)<<32) 647 + cs_stat[i].dimm_lo)/MBYTE, 0); 648 649 /* Number of DIMMs */ 650 log_printf("%9d\n", cs_stat[i].dimms); 651 } 652 return (total_board_mem); 653 } 654 655 /* 656 * Details of hardware revision and environmental status. 657 */ 658 /*ARGSUSED*/ 659 void 660 display_diaginfo(int flag, Prom_node *root, Sys_tree *tree, 661 struct system_kstat_data *kstats) 662 { 663 /* Print the PROM revisions */ 664 if (flag) 665 opl_disp_hw_revisions(tree, root); 666 } 667 668 /* 669 * Gather and display hardware revision and environmental status 670 */ 671 /*ARGSUSED*/ 672 static void 673 opl_disp_hw_revisions(Sys_tree *tree, Prom_node *root) 674 { 675 char *version; 676 Prom_node *pnode; 677 678 (void) textdomain(TEXT_DOMAIN); 679 680 /* Print the header */ 681 log_printf("\n", 0); 682 log_printf("====================", 0); 683 log_printf(gettext(" Hardware Revisions "), 0); 684 log_printf("====================", 0); 685 log_printf("\n\n", 0); 686 687 /* Display Prom revision header */ 688 log_printf(gettext("System PROM revisions:"), 0); 689 log_printf("\n----------------------\n", 0); 690 log_printf("\n", 0); 691 692 /* Display OBP version info */ 693 pnode = dev_find_node(root, "openprom"); 694 if (pnode != NULL) { 695 version = (char *)get_prop_val(find_prop(pnode, "version")); 696 if (version != NULL) 697 log_printf("%s\n\n", version, 0); 698 else 699 log_printf("%s\n\n", "N/A", 0); 700 } 701 702 /* Print the header */ 703 log_printf("\n", 0); 704 log_printf("===================", 0); 705 log_printf(gettext(" Environmental Status "), 0); 706 log_printf("===================", 0); 707 log_printf("\n\n", 0); 708 709 opl_disp_environ(); 710 } 711 712 /* 713 * Gather environmental information 714 */ 715 static void 716 opl_disp_environ(void) 717 { 718 kstat_ctl_t *kc; 719 kstat_t *ksp; 720 kstat_named_t *k; 721 722 if ((kc = kstat_open()) == NULL) 723 return; 724 725 if ((ksp = kstat_lookup 726 (kc, "scfd", 0, SCF_SYSTEM_KSTAT_NAME)) == NULL) { 727 (void) kstat_close(kc); 728 return; 729 } 730 731 if (kstat_read(kc, ksp, NULL) == -1) { 732 (void) kstat_close(kc); 733 return; 734 } 735 736 if ((k = (kstat_named_t *)kstat_data_lookup 737 (ksp, SCF_SECURE_MODE_KSTAT_NAMED)) == NULL) { 738 (void) kstat_close(kc); 739 return; 740 } 741 742 if (k->value.c[0] == SCF_STAT_MODE_LOCK) 743 log_printf("Mode switch is in LOCK mode ", 0); 744 else if (k->value.c[0] == SCF_STAT_MODE_UNLOCK) 745 log_printf("Mode switch is in UNLOCK mode", 0); 746 else 747 log_printf("Mode switch is in UNKNOWN mode", 0); 748 749 log_printf("\n", 0); 750 751 (void) kstat_close(kc); 752 } 753 754 755 /* 756 * Calls do_devinfo() in order to use the libdevinfo device tree 757 * instead of OBP's device tree. 758 */ 759 int 760 do_prominfo(int syserrlog, char *pgname, int log_flag, int prt_flag) 761 { 762 return (do_devinfo(syserrlog, pgname, log_flag, prt_flag)); 763 } 764 765 /* 766 * Return the property value for the Prop 767 * passed in. (When using libdevinfo) 768 */ 769 void * 770 get_prop_val(Prop *prop) 771 { 772 if (prop == NULL) 773 return (NULL); 774 775 return ((void *)(prop->value.val_ptr)); 776 } 777 778 /* 779 * Return the property size for the Prop 780 * passed in. (When using libdevinfo) 781 */ 782 static int 783 get_prop_size(Prop *prop) 784 { 785 786 if ((prop != NULL) && (prop->size > 0)) 787 return (prop->size); 788 else 789 return (0); 790 } 791 792 793 /* 794 * Search a Prom node and retrieve the property with the correct 795 * name. (When using libdevinfo) 796 */ 797 Prop * 798 find_prop(Prom_node *pnode, char *name) 799 { 800 Prop *prop; 801 802 if (pnode == NULL) 803 return (NULL); 804 805 for (prop = pnode->props; prop != NULL; prop = prop->next) { 806 if (prop->name.val_ptr != NULL && 807 strcmp((char *)(prop->name.val_ptr), name) == 0) 808 break; 809 } 810 811 return (prop); 812 } 813 814 /* 815 * This function adds a board node to the board structure where that 816 * that node's physical component lives. 817 */ 818 void 819 add_node(Sys_tree *root, Prom_node *pnode) 820 { 821 int board; 822 Board_node *bnode; 823 Prom_node *p; 824 char *type; 825 826 if ((board = get_board_num(pnode)) == -1) { 827 type = get_node_type(pnode); 828 if ((type != NULL) && (strcmp(type, "cpu") == 0)) 829 board = get_board_num((pnode->parent)->parent); 830 } 831 832 /* find the node with the same board number */ 833 if ((bnode = find_board(root, board)) == NULL) { 834 bnode = insert_board(root, board); 835 bnode->board_type = UNKNOWN_BOARD; 836 } 837 838 /* now attach this prom node to the board list */ 839 /* Insert this node at the end of the list */ 840 pnode->sibling = NULL; 841 if (bnode->nodes == NULL) 842 bnode->nodes = pnode; 843 else { 844 p = bnode->nodes; 845 while (p->sibling != NULL) 846 p = p->sibling; 847 p->sibling = pnode; 848 } 849 850 } 851