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 uint_t avail_hi; 82 uint_t avail_lo; 83 uint_t dimm_hi; 84 uint_t 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 /* 528 * The units of cs_size will be either number of bytes 529 * or number of int array elements as this is derived 530 * from the libprtdiag Prop node size field which has 531 * inconsistent units. Until this is addressed in 532 * libprtdiag, we need a heuristic to determine the 533 * number of CS groups. Given that the maximum number 534 * of CS groups is 2, the maximum number of cs-status 535 * array elements will be 2*7=14. Since this is smaller 536 * than the byte size of a single struct status, we use 537 * this to decide if we are dealing with bytes or array 538 * elements in determining the number of CS groups. 539 */ 540 if (cs_size < sizeof (struct cs_status)) { 541 /* cs_size is number of total int [] elements */ 542 ngrps = cs_size / 7; 543 } else { 544 /* cs_size is total byte count */ 545 ngrps = cs_size/sizeof (struct cs_status); 546 } 547 548 if (cs_stat != NULL) { 549 total_mem += 550 print_opl_memory_line(bnode->board_num, 551 cs_stat, ngrps); 552 } 553 } 554 555 pnode = dev_next_node(pnode, "pseudo-mc"); 556 } 557 return (total_mem); 558 } 559 560 /* 561 * Display memory information. 562 */ 563 /*ARGSUSED*/ 564 void 565 display_memoryconf(Sys_tree *tree, struct grp_info *grps) 566 { 567 Board_node *bnode = tree->bd_list; 568 uint64_t total_mem = 0, total_sys_mem = 0; 569 char *hdrfmt = "\n%-5.5s %-6.6s %-12.12s %-10.10s" 570 " %-8.8s %-10.10s"; 571 572 (void) textdomain(TEXT_DOMAIN); 573 574 log_printf("======================", 0); 575 log_printf(gettext(" Memory Configuration "), 0); 576 log_printf("======================", 0); 577 log_printf("\n", 0); 578 579 log_printf(hdrfmt, 580 "", 581 gettext("Memory"), 582 gettext("Available"), 583 gettext("Memory"), 584 gettext("DIMM"), 585 gettext("Number of"), 586 0); 587 588 log_printf(hdrfmt, 589 gettext("LSB"), 590 gettext("Group"), 591 gettext("Size"), 592 gettext("Status"), 593 gettext("Size"), 594 gettext("DIMMs"), 0); 595 596 log_printf(hdrfmt, 597 "---", "-------", "------------", "-------", "-----", 598 "---------", 0); 599 600 log_printf("\n", 0); 601 602 for (bnode = tree->bd_list; bnode != NULL; bnode = bnode->next) { 603 total_mem += get_opl_mem_regs(bnode); 604 } 605 606 /* 607 * Sanity check to ensure that the total amount of system 608 * memory matches the total number of memory that 609 * we find here. Display error message if there is a mis-match. 610 */ 611 total_sys_mem = (((uint64_t)sysconf(_SC_PAGESIZE) * (uint64_t)sysconf 612 (_SC_PHYS_PAGES)) / MBYTE); 613 614 if (total_mem != total_sys_mem) { 615 log_printf(dgettext(TEXT_DOMAIN, 616 "\nError:total available size [%lldMB] does not match" 617 " total system memory [%lldMB]\n"), 618 total_mem, total_sys_mem, 0); 619 } 620 621 } 622 623 /* 624 * This function provides Opl's formatting of the memory config 625 * information that get_opl_mem_regs() has gathered. 626 */ 627 static uint64_t 628 print_opl_memory_line(int lsb, struct cs_status *cs_stat, int ngrps) 629 { 630 int i; 631 uint64_t total_board_mem = 0; 632 633 (void) textdomain(TEXT_DOMAIN); 634 635 for (i = 0; i < ngrps; i++) { 636 uint64_t mem_size; 637 638 mem_size = ((((uint64_t)cs_stat[i].avail_hi)<<32) + 639 cs_stat[i].avail_lo); 640 641 if (mem_size == 0) 642 continue; 643 644 /* Lsb Id */ 645 log_printf(" %02d ", lsb, 0); 646 647 /* Memory Group Number */ 648 if ((cs_stat[i].cs_number) == 0) 649 log_printf("%-6.6s", "A", 0); 650 else 651 log_printf("%-6.6s", "B", 0); 652 653 /* Memory Group Size */ 654 log_printf(" %4lldMB ", mem_size/MBYTE, 0); 655 656 total_board_mem += (mem_size/MBYTE); 657 658 /* Memory Group Status */ 659 log_printf("%-11.11s", 660 cs_stat[i].status ? "partial": "okay", 0); 661 662 /* DIMM Size */ 663 log_printf("%4lldMB ", 664 ((((uint64_t)cs_stat[i].dimm_hi)<<32) 665 + cs_stat[i].dimm_lo)/MBYTE, 0); 666 667 /* Number of DIMMs */ 668 log_printf("%9d\n", cs_stat[i].dimms); 669 } 670 return (total_board_mem); 671 } 672 673 /* 674 * Details of hardware revision and environmental status. 675 */ 676 /*ARGSUSED*/ 677 void 678 display_diaginfo(int flag, Prom_node *root, Sys_tree *tree, 679 struct system_kstat_data *kstats) 680 { 681 /* Print the PROM revisions */ 682 if (flag) 683 opl_disp_hw_revisions(tree, root); 684 } 685 686 /* 687 * Gather and display hardware revision and environmental status 688 */ 689 /*ARGSUSED*/ 690 static void 691 opl_disp_hw_revisions(Sys_tree *tree, Prom_node *root) 692 { 693 char *version; 694 Prom_node *pnode; 695 696 (void) textdomain(TEXT_DOMAIN); 697 698 /* Print the header */ 699 log_printf("\n", 0); 700 log_printf("====================", 0); 701 log_printf(gettext(" Hardware Revisions "), 0); 702 log_printf("====================", 0); 703 log_printf("\n\n", 0); 704 705 /* Display Prom revision header */ 706 log_printf(gettext("System PROM revisions:"), 0); 707 log_printf("\n----------------------\n", 0); 708 log_printf("\n", 0); 709 710 /* Display OBP version info */ 711 pnode = dev_find_node(root, "openprom"); 712 if (pnode != NULL) { 713 version = (char *)get_prop_val(find_prop(pnode, "version")); 714 if (version != NULL) 715 log_printf("%s\n\n", version, 0); 716 else 717 log_printf("%s\n\n", "N/A", 0); 718 } 719 720 /* Print the header */ 721 log_printf("\n", 0); 722 log_printf("===================", 0); 723 log_printf(gettext(" Environmental Status "), 0); 724 log_printf("===================", 0); 725 log_printf("\n\n", 0); 726 727 opl_disp_environ(); 728 } 729 730 /* 731 * Gather environmental information 732 */ 733 static void 734 opl_disp_environ(void) 735 { 736 kstat_ctl_t *kc; 737 kstat_t *ksp; 738 kstat_named_t *k; 739 740 if ((kc = kstat_open()) == NULL) 741 return; 742 743 if ((ksp = kstat_lookup 744 (kc, "scfd", 0, SCF_SYSTEM_KSTAT_NAME)) == NULL) { 745 (void) kstat_close(kc); 746 return; 747 } 748 749 if (kstat_read(kc, ksp, NULL) == -1) { 750 (void) kstat_close(kc); 751 return; 752 } 753 754 if ((k = (kstat_named_t *)kstat_data_lookup 755 (ksp, SCF_SECURE_MODE_KSTAT_NAMED)) == NULL) { 756 (void) kstat_close(kc); 757 return; 758 } 759 760 if (k->value.c[0] == SCF_STAT_MODE_LOCK) 761 log_printf("Mode switch is in LOCK mode ", 0); 762 else if (k->value.c[0] == SCF_STAT_MODE_UNLOCK) 763 log_printf("Mode switch is in UNLOCK mode", 0); 764 else 765 log_printf("Mode switch is in UNKNOWN mode", 0); 766 767 log_printf("\n", 0); 768 769 (void) kstat_close(kc); 770 } 771 772 773 /* 774 * Calls do_devinfo() in order to use the libdevinfo device tree 775 * instead of OBP's device tree. 776 */ 777 int 778 do_prominfo(int syserrlog, char *pgname, int log_flag, int prt_flag) 779 { 780 return (do_devinfo(syserrlog, pgname, log_flag, prt_flag)); 781 } 782 783 /* 784 * Return the property value for the Prop 785 * passed in. (When using libdevinfo) 786 */ 787 void * 788 get_prop_val(Prop *prop) 789 { 790 if (prop == NULL) 791 return (NULL); 792 793 return ((void *)(prop->value.val_ptr)); 794 } 795 796 /* 797 * Return the property size for the Prop 798 * passed in. (When using libdevinfo) 799 */ 800 static int 801 get_prop_size(Prop *prop) 802 { 803 804 if ((prop != NULL) && (prop->size > 0)) 805 return (prop->size); 806 else 807 return (0); 808 } 809 810 811 /* 812 * Search a Prom node and retrieve the property with the correct 813 * name. (When using libdevinfo) 814 */ 815 Prop * 816 find_prop(Prom_node *pnode, char *name) 817 { 818 Prop *prop; 819 820 if (pnode == NULL) 821 return (NULL); 822 823 for (prop = pnode->props; prop != NULL; prop = prop->next) { 824 if (prop->name.val_ptr != NULL && 825 strcmp((char *)(prop->name.val_ptr), name) == 0) 826 break; 827 } 828 829 return (prop); 830 } 831 832 /* 833 * This function adds a board node to the board structure where that 834 * that node's physical component lives. 835 */ 836 void 837 add_node(Sys_tree *root, Prom_node *pnode) 838 { 839 int board; 840 Board_node *bnode; 841 Prom_node *p; 842 char *type; 843 844 if ((board = get_board_num(pnode)) == -1) { 845 type = get_node_type(pnode); 846 if ((type != NULL) && (strcmp(type, "cpu") == 0)) 847 board = get_board_num((pnode->parent)->parent); 848 } 849 850 /* find the node with the same board number */ 851 if ((bnode = find_board(root, board)) == NULL) { 852 bnode = insert_board(root, board); 853 bnode->board_type = UNKNOWN_BOARD; 854 } 855 856 /* now attach this prom node to the board list */ 857 /* Insert this node at the end of the list */ 858 pnode->sibling = NULL; 859 if (bnode->nodes == NULL) 860 bnode->nodes = pnode; 861 else { 862 p = bnode->nodes; 863 while (p->sibling != NULL) 864 p = p->sibling; 865 p->sibling = pnode; 866 } 867 868 } 869