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 2007 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_io_devices(Sys_tree *tree);
98 void	display_diaginfo(int flag, Prom_node *root, Sys_tree *tree,
99     struct system_kstat_data *kstats);
100 Prop 	*find_prop(Prom_node *pnode, char *name);
101 int	do_piclinfo(int);
102 
103 /* Local functions */
104 static	void opl_disp_environ(void);
105 static	void opl_disp_hw_revisions(Sys_tree *tree, Prom_node *root);
106 static	uint64_t print_opl_memory_line(int lsb, struct cs_status *cs_stat,
107     int ngrps);
108 static	uint64_t get_opl_mem_regs(Board_node *bnode);
109 void 	add_node(Sys_tree *root, Prom_node *pnode);
110 static	int get_prop_size(Prop *prop);
111 
112 static int v_flag = 0;
113 
114 /*
115  * For display of I/O devices for "prtdiag"
116  */
117 void
118 display_io_devices(Sys_tree *tree)
119 {
120 	Board_node *bnode;
121 
122 	if (v_flag) {
123 		/*
124 		 * OPL's PICL interface for display of PCI I/O devices
125 		 * for "prtdiag -v"
126 		 */
127 		(void) do_piclinfo(v_flag);
128 	} else {
129 		log_printf("\n", 0);
130 		log_printf("=========================", 0);
131 		log_printf(dgettext(TEXT_DOMAIN, " IO Cards "), 0);
132 		log_printf("=========================", 0);
133 		log_printf("\n", 0);
134 		log_printf("\n", 0);
135 		bnode = tree->bd_list;
136 		while (bnode != NULL) {
137 			display_pci(bnode);
138 			bnode = bnode->next;
139 		}
140 	}
141 }
142 
143 /*
144  * Display all the leaf PCI nodes on this board that have "reg" property.
145  * If the "reg" property is NULL for a leaf node, skip parsing its sibling
146  * nodes and display the parent node properties.
147  */
148 void
149 display_pci(Board_node *board)
150 {
151 	struct io_card *card_list = NULL;
152 	struct io_card card;
153 	Prom_node *pci, *card_node;
154 	char	*name, *type;
155 	int	*int_val;
156 
157 	if (board == NULL)
158 		return;
159 
160 	/* Initialize common information */
161 	card.board = board->board_num;
162 
163 	pci = board->nodes;
164 	while (pci != NULL) {
165 		name = get_node_name(pci);
166 
167 		/* Skip non-PCI board nodes */
168 		if ((name == NULL) || (strcmp(name, "pci") != 0)) {
169 			pci = pci->sibling;
170 			continue;
171 		}
172 
173 		type = (char *)get_prop_val(find_prop(pci, "device_type"));
174 
175 		/*
176 		 * Skip PCI/ebus devices
177 		 * They have name == "pci" and type == "pci"
178 		 */
179 		if (strcmp(type, "pci") == 0) {
180 			pci = pci->sibling;
181 			continue;
182 		}
183 
184 		card_node = pci;
185 		while (card_node != NULL) {
186 			int pci_parent_bridge = 0;
187 
188 			/* If it does have a child, skip to leaf child */
189 			if (card_node->child != NULL) {
190 				card_node = card_node->child;
191 				continue;
192 			}
193 
194 			/* Get name of the card */
195 			name = (char *)get_prop_val(find_prop
196 			    (card_node, "name"));
197 
198 			/* Get type of card */
199 			type = (char *)get_prop_val(find_prop
200 			    (card_node, "device_type"));
201 
202 			/* Leaf pci-bridges are to be ignored */
203 			if (!IS_PCI_BRIDGE(name, type)) {
204 
205 				/* Get reg property of the node */
206 				int_val = (int *)get_prop_val(find_prop
207 					    (card_node, "reg"));
208 
209 				/*
210 				 * If no "reg" property check to see
211 				 * whether parent node has reg property.
212 				 * and check if parent is a bridge
213 				 */
214 				if (int_val == NULL) {
215 					Prom_node *cparent = card_node->parent;
216 					if (cparent == NULL)
217 						break;
218 
219 					name = (char *)get_prop_val(find_prop
220 						    (cparent, "name"));
221 
222 					type = (char *)get_prop_val(find_prop
223 						    (cparent, "device_type"));
224 
225 					/* check if parent is a bridge */
226 					if (IS_PCI_BRIDGE(name, type))
227 						pci_parent_bridge = 1;
228 
229 					int_val = (int *)get_prop_val(
230 						find_prop(cparent, "reg"));
231 
232 					if (int_val != NULL)
233 						/* Switch to parent */
234 						card_node = cparent;
235 					else
236 						/* parent node has no reg */
237 						break;
238 				}
239 
240 				if (!pci_parent_bridge) {
241 
242 					name = (char *)get_prop_val(find_prop
243 						    (card_node, "name"));
244 
245 					if (name == NULL)
246 						card.name[0] = '\0';
247 					else {
248 						(void) snprintf(card.name,
249 						    MAXSTRLEN, "%s", name);
250 					}
251 
252 					/* Get the model of this card */
253 					name = (char *)get_prop_val(find_prop
254 						    (card_node, "model"));
255 
256 					if (name == NULL) {
257 						(void) snprintf(card.model,
258 						    MAXSTRLEN, "%s", "N/A");
259 					} else {
260 						(void) snprintf(card.model,
261 						    MAXSTRLEN, "%s", name);
262 					}
263 
264 					/* insert card to the list */
265 					card_list = insert_io_card
266 						    (card_list, &card);
267 
268 				}
269 
270 			}
271 
272 			/*
273 			 * Parse sibling nodes.
274 			 * Then move up the parent's sibling upto the top
275 			 * intermediate node
276 			 * Stop if pci board node is reached.
277 			 */
278 			if (card_node->sibling != NULL) {
279 				if (card_node == pci)
280 					card_node = NULL;
281 				else
282 					card_node = card_node->sibling;
283 			} else {
284 				Prom_node *cparent;
285 				cparent = card_node->parent;
286 				card_node = NULL;
287 				while (cparent != NULL) {
288 					if (cparent == pci)
289 						break;
290 					if (cparent->sibling != NULL) {
291 						card_node = cparent->sibling;
292 						break;
293 					}
294 					cparent = cparent->parent;
295 				}
296 			}
297 
298 		}
299 
300 	/* On to the next board node */
301 	pci = pci->sibling;
302 
303 	}
304 
305 	display_io_cards(card_list);
306 	free_io_cards(card_list);
307 }
308 
309 /*
310  * There are no FFB's on OPL.
311  */
312 /*ARGSUSED*/
313 void
314 display_ffb(Board_node *board, int table)
315 {
316 }
317 
318 /*
319  * There are no Sbus's on OPL.
320  */
321 /*ARGSUSED*/
322 void
323 display_sbus(Board_node *board)
324 {
325 }
326 
327 /*
328  * Details of I/O information. Print out all the io cards.
329  */
330 void
331 display_io_cards(struct io_card *list)
332 {
333 	char	*hdrfmt = "%-6.6s %-14.14s %-12.12s\n";
334 
335 	struct io_card *p;
336 
337 	if (list == NULL)
338 		return;
339 
340 	(void) textdomain(TEXT_DOMAIN);
341 
342 	log_printf(hdrfmt, gettext("LSB"), gettext("Name"), gettext("Model"),
343 	    0);
344 
345 	log_printf(hdrfmt, "---", "-----------------", "------------", 0);
346 
347 	for (p = list; p != NULL; p = p->next) {
348 
349 		/* Board number */
350 		log_printf(" %02d    ", p->board, 0);
351 
352 		/* Card name */
353 		log_printf("%-15.15s", p->name, 0);
354 
355 		/* Card model */
356 		log_printf("%-12.12s", p->model, 0);
357 
358 		log_printf("\n", 0);
359 	}
360 	log_printf("\n", 0);
361 }
362 
363 /*
364  * Details of CPU information.
365  */
366 void
367 display_cpu_devices(Sys_tree *tree)
368 {
369 	Board_node *bnode;
370 	char *hdrfmt =
371 	    "%-5.5s  %-8.8s  %-20.20s  %-8.8s  %-8.8s  %-8.8s %-8.8s\n";
372 
373 	(void) textdomain(TEXT_DOMAIN);
374 
375 	/*
376 	 * Display the table header for CPUs . Then display the CPU
377 	 * frequency, cache size, and processor revision of all cpus.
378 	 */
379 	log_printf("\n", 0);
380 	log_printf("====================================", 0);
381 	log_printf(gettext(" CPUs "), 0);
382 	log_printf("====================================", 0);
383 	log_printf("\n\n", 0);
384 
385 	log_printf(hdrfmt,
386 	    "",
387 	    gettext("CPU"),
388 	    gettext("       CPU         "),
389 	    gettext("Run"),
390 	    gettext("L2$"),
391 	    gettext("CPU"),
392 	    gettext("CPU"), 0);
393 
394 	log_printf(hdrfmt,
395 	    gettext("LSB"),
396 	    gettext("Chip"),
397 	    gettext("        ID         "),
398 	    gettext("MHz"),
399 	    gettext(" MB"),
400 	    gettext("Impl."),
401 	    gettext("Mask"), 0);
402 
403 	log_printf(hdrfmt,
404 	    "---", "----", "--------------------", "----",
405 	    "---",  "-----", "----", 0);
406 
407 	/* Now display all of the cpus on each board */
408 	for (bnode = tree->bd_list; bnode != NULL; bnode = bnode->next) {
409 		display_cpus(bnode);
410 	}
411 
412 	log_printf("\n", 0);
413 }
414 
415 /*
416  * Display the CPUs present on this board.
417  */
418 void
419 display_cpus(Board_node *board)
420 {
421 	int *impl, *mask, *cpuid, *portid, *l2cache_size;
422 	uint_t freq;		/* CPU clock frequency */
423 	Prom_node *pnode, *cpu;
424 	char *name;
425 
426 	(void) textdomain(TEXT_DOMAIN);
427 
428 	/*
429 	 * Get the Cpus' properties for display
430 	 */
431 	for (pnode = board->nodes; pnode != NULL; pnode = pnode->sibling) {
432 		char cpu_str[MAXSTRLEN], fcpu_str[MAXSTRLEN] = {0};
433 
434 		name = get_node_name(pnode);
435 		if ((name == NULL) || (strncmp(name, "cmp", 3) != 0)) {
436 			continue;
437 		}
438 
439 		portid = (int *)get_prop_val(find_prop(pnode, "portid"));
440 		freq = (HZ_TO_MHZ(get_cpu_freq(pnode->child)));
441 		l2cache_size =
442 		    (int *)get_prop_val
443 			(find_prop(pnode->child, "l2-cache-size"));
444 		impl =
445 		    (int *)get_prop_val
446 			(find_prop(pnode->child, "implementation#"));
447 		mask = (int *)get_prop_val(find_prop(pnode->child, "mask#"));
448 
449 		/* Lsb id */
450 		log_printf(" %02d    ", board->board_num, 0);
451 
452 		if (portid != NULL)
453 			log_printf("%3d       ", (((*portid)>>3)&0x3), 0);
454 
455 		/*
456 		 * Specific parsing of the CMP/CORE/CPU chain.
457 		 * The internal cpu tree built by walk_di_tree()
458 		 * in common code can be illustrated by the diagram
459 		 * below:
460 		 *
461 		 *   cmp->cpu->cpu->cpu->cpu->(next board nodes)
462 		 *   / \
463 		 * core core
464 		 * where "/" or "\" are children
465 		 *    and "->" are siblings
466 		 */
467 		for (cpu = pnode->sibling; cpu != NULL; ) {
468 			Prom_node	*cpu_next = NULL;
469 
470 			name = get_node_name(cpu);
471 			if ((name == NULL) || (strncmp(name, "cpu", 3) != 0)) {
472 				break;
473 			}
474 
475 			/* Id assigned to Virtual processor core */
476 			cpuid = (int *)get_prop_val(find_prop(cpu, "cpuid"));
477 			cpu_next = cpu->sibling;
478 
479 			if (cpu_next != NULL) {
480 				name = get_node_name(cpu_next);
481 
482 				if ((name == NULL) ||
483 				    (strncmp(name, "cpu", 3) != 0)) {
484 					cpu_next = NULL;
485 				}
486 			}
487 
488 			if (cpuid != NULL) {
489 				/* Used for printing in comma format */
490 				(void) sprintf(cpu_str, "%4d", *cpuid);
491 				(void) strlcat(fcpu_str, cpu_str, MAXSTRLEN);
492 
493 				if (cpu_next != NULL)
494 				    (void) strlcat(fcpu_str, ",", MAXSTRLEN);
495 			} else {
496 				(void) sprintf(cpu_str, "%4s", "N/A");
497 				(void) strlcat(fcpu_str, cpu_str, MAXSTRLEN);
498 
499 				if (cpu_next != NULL)
500 				    (void) strlcat(fcpu_str, ",", MAXSTRLEN);
501 			}
502 			cpu = cpu_next;
503 		}
504 
505 		log_printf("%-20.20s", fcpu_str, 0);
506 
507 		/* Running frequency */
508 		if (freq != 0)
509 			log_printf("  %4ld     ", freq, 0);
510 		else
511 			log_printf("  %4s     ", "N/A", 0);
512 
513 		/* L2 cache size */
514 		if (l2cache_size == NULL)
515 			log_printf(" %3s    ", "N/A", 0);
516 		else {
517 			log_printf("%4.1f       ",
518 			    (float)(*l2cache_size) / (float)(1<<20), 0);
519 		}
520 
521 
522 		/* Implementation number of processor */
523 		if (impl != NULL)
524 			log_printf("%4d     ", *impl, 0);
525 		else
526 			log_printf("%4s     ", "N/A", 0);
527 
528 		/* Mask Set version */
529 		/* Bits 31:24 of VER register is mask. */
530 		/* Mask value : Non MTP mode - 00-7f, MTP mode - 80-ff */
531 		if (mask == NULL)
532 			log_printf("%4s", "N/A", 0);
533 		else
534 			log_printf("%4d", (*mask)&0xff, 0);
535 
536 		log_printf("\n", 0);
537 
538 	}
539 }
540 
541 /*
542  * Gather memory information: Details of memory information.
543  */
544 static uint64_t
545 get_opl_mem_regs(Board_node *bnode)
546 {
547 	Prom_node	*pnode;
548 	struct		cs_status	*cs_stat;
549 	uint64_t	total_mem = 0;
550 	int		cs_size, ngrps;
551 
552 	pnode = dev_find_node(bnode->nodes, "pseudo-mc");
553 	while (pnode != NULL) {
554 
555 		cs_size = get_prop_size(find_prop(pnode, "cs-status"));
556 
557 		if (cs_size > 0) {
558 
559 			/* OBP returns lists of 7 ints */
560 			cs_stat = (struct cs_status *)get_prop_val
561 			    (find_prop(pnode, "cs-status"));
562 
563 			/*
564 			 * The units of cs_size will be either number of bytes
565 			 * or number of int array elements as this is derived
566 			 * from the libprtdiag Prop node size field which has
567 			 * inconsistent units.   Until this is addressed in
568 			 * libprtdiag, we need a heuristic to determine the
569 			 * number of CS groups.  Given that the maximum number
570 			 * of CS groups is 2, the maximum number of cs-status
571 			 * array elements will be 2*7=14.  Since this is smaller
572 			 * than the byte size of a single struct status, we use
573 			 * this to decide if we are dealing with bytes or array
574 			 * elements in determining the number of CS groups.
575 			 */
576 			if (cs_size < sizeof (struct cs_status)) {
577 				/* cs_size is number of total int [] elements */
578 				ngrps = cs_size / 7;
579 			} else {
580 				/* cs_size is total byte count */
581 				ngrps = cs_size/sizeof (struct cs_status);
582 			}
583 
584 			if (cs_stat != NULL) {
585 				total_mem +=
586 				    print_opl_memory_line(bnode->board_num,
587 					cs_stat, ngrps);
588 			}
589 		}
590 
591 		pnode = dev_next_node(pnode, "pseudo-mc");
592 	}
593 	return (total_mem);
594 }
595 
596 /*
597  * Display memory information.
598  */
599 /*ARGSUSED*/
600 void
601 display_memoryconf(Sys_tree *tree, struct grp_info *grps)
602 {
603 	Board_node	*bnode = tree->bd_list;
604 	uint64_t	total_mem = 0, total_sys_mem = 0;
605 	char *hdrfmt =	"\n%-5.5s  %-6.6s  %-18.18s  %-10.10s"
606 			    " %-8.8s  %-10.10s";
607 
608 	(void) textdomain(TEXT_DOMAIN);
609 
610 	log_printf("======================", 0);
611 	log_printf(gettext(" Memory Configuration "), 0);
612 	log_printf("======================", 0);
613 	log_printf("\n", 0);
614 
615 	log_printf(hdrfmt,
616 		"",
617 	    gettext("Memory"),
618 	    gettext("Available"),
619 	    gettext("Memory"),
620 	    gettext("DIMM"),
621 	    gettext("Number of"),
622 	    0);
623 
624 	log_printf(hdrfmt,
625 	    gettext("LSB"),
626 	    gettext("Group"),
627 	    gettext("Size"),
628 	    gettext("Status"),
629 	    gettext("Size"),
630 	    gettext("DIMMs"), 0);
631 
632 	log_printf(hdrfmt,
633 	    "---", "-------", "------------------", "-------", "------",
634 	    "---------", 0);
635 
636 	log_printf("\n", 0);
637 
638 	for (bnode = tree->bd_list; bnode != NULL; bnode = bnode->next) {
639 		total_mem += get_opl_mem_regs(bnode);
640 	}
641 
642 	/*
643 	 * Sanity check to ensure that the total amount of system
644 	 * memory matches the total number of memory that
645 	 * we find here. Display error message if there is a mis-match.
646 	 */
647 	total_sys_mem = (((uint64_t)sysconf(_SC_PAGESIZE) * (uint64_t)sysconf
648 	    (_SC_PHYS_PAGES)) / MBYTE);
649 
650 	if (total_mem != total_sys_mem) {
651 		log_printf(dgettext(TEXT_DOMAIN,
652 		    "\nError:total available size [%lldMB] does not match"
653 			" total system memory [%lldMB]\n"),
654 			    total_mem, total_sys_mem, 0);
655 	}
656 
657 }
658 
659 /*
660  * This function provides Opl's formatting of the memory config
661  * information that get_opl_mem_regs() has gathered.
662  */
663 static uint64_t
664 print_opl_memory_line(int lsb, struct cs_status *cs_stat, int ngrps)
665 {
666 	int	i;
667 	uint64_t	total_board_mem = 0;
668 
669 	(void) textdomain(TEXT_DOMAIN);
670 
671 	for (i = 0; i < ngrps; i++) {
672 		uint64_t	mem_size;
673 
674 		mem_size = ((((uint64_t)cs_stat[i].avail_hi)<<32) +
675 		    cs_stat[i].avail_lo);
676 
677 		if (mem_size == 0)
678 			continue;
679 
680 		/* Lsb Id */
681 		log_printf(" %02d    ", lsb, 0);
682 
683 		/* Memory Group Number */
684 		if ((cs_stat[i].cs_number) == 0)
685 			log_printf("%-6.6s", "A", 0);
686 		else
687 			log_printf("%-6.6s", "B", 0);
688 
689 		/* Memory Group Size */
690 		log_printf("%8lldMB            ", mem_size/MBYTE, 0);
691 
692 		total_board_mem += (mem_size/MBYTE);
693 
694 		/* Memory Group Status */
695 		log_printf("%-11.11s",
696 		    cs_stat[i].status ? "partial": "okay", 0);
697 
698 		/* DIMM Size */
699 		log_printf("%4lldMB   ",
700 		    ((((uint64_t)cs_stat[i].dimm_hi)<<32)
701 		    + cs_stat[i].dimm_lo)/MBYTE, 0);
702 
703 		/* Number of DIMMs */
704 		log_printf("        %2d\n", cs_stat[i].dimms);
705 	}
706 	return (total_board_mem);
707 }
708 
709 /*
710  * Details of hardware revision and environmental status.
711  */
712 /*ARGSUSED*/
713 void
714 display_diaginfo(int flag, Prom_node *root, Sys_tree *tree,
715 	struct system_kstat_data *kstats)
716 {
717 	/* Print the PROM revisions */
718 	opl_disp_hw_revisions(tree, root);
719 }
720 
721 /*
722  * Gather and display hardware revision and environmental status
723  */
724 /*ARGSUSED*/
725 static void
726 opl_disp_hw_revisions(Sys_tree *tree, Prom_node *root)
727 {
728 	char		*version;
729 	Prom_node	*pnode;
730 
731 	(void) textdomain(TEXT_DOMAIN);
732 
733 	/* Print the header */
734 	log_printf("\n", 0);
735 	log_printf("====================", 0);
736 	log_printf(gettext(" Hardware Revisions "), 0);
737 	log_printf("====================", 0);
738 	log_printf("\n\n", 0);
739 
740 	/* Display Prom revision header */
741 	log_printf(gettext("System PROM revisions:"), 0);
742 	log_printf("\n----------------------\n", 0);
743 	log_printf("\n", 0);
744 
745 	/* Display OBP version info */
746 	pnode = dev_find_node(root, "openprom");
747 	if (pnode != NULL) {
748 		version = (char *)get_prop_val(find_prop(pnode, "version"));
749 		if (version != NULL)
750 			log_printf("%s\n\n", version, 0);
751 		else
752 			log_printf("%s\n\n", "N/A", 0);
753 	}
754 
755 	/* Print the header */
756 	log_printf("\n", 0);
757 	log_printf("===================", 0);
758 	log_printf(gettext(" Environmental Status "), 0);
759 	log_printf("===================", 0);
760 	log_printf("\n\n", 0);
761 
762 	opl_disp_environ();
763 }
764 
765 /*
766  * Gather environmental information
767  */
768 static void
769 opl_disp_environ(void)
770 {
771 	kstat_ctl_t *kc;
772 	kstat_t *ksp;
773 	kstat_named_t   *k;
774 
775 	if ((kc = kstat_open()) == NULL)
776 		return;
777 
778 	if ((ksp = kstat_lookup
779 	    (kc, "scfd", 0, SCF_SYSTEM_KSTAT_NAME)) == NULL) {
780 		(void) kstat_close(kc);
781 		return;
782 	}
783 
784 	if (kstat_read(kc, ksp, NULL) == -1) {
785 		(void) kstat_close(kc);
786 		return;
787 	}
788 
789 	if ((k = (kstat_named_t *)kstat_data_lookup
790 	    (ksp, SCF_SECURE_MODE_KSTAT_NAMED)) == NULL) {
791 		(void) kstat_close(kc);
792 		return;
793 	}
794 
795 	if (k->value.c[0] == SCF_STAT_MODE_LOCK)
796 		log_printf("Mode switch is in LOCK mode ", 0);
797 	else if (k->value.c[0] == SCF_STAT_MODE_UNLOCK)
798 		log_printf("Mode switch is in UNLOCK mode", 0);
799 	else
800 		log_printf("Mode switch is in UNKNOWN mode", 0);
801 
802 	log_printf("\n", 0);
803 
804 	(void) kstat_close(kc);
805 }
806 
807 
808 /*
809  * Calls do_devinfo() in order to use the libdevinfo device tree
810  * instead of OBP's device tree.
811  */
812 int
813 do_prominfo(int syserrlog, char *pgname, int log_flag, int prt_flag)
814 {
815 	v_flag = syserrlog;
816 	return (do_devinfo(syserrlog, pgname, log_flag, prt_flag));
817 }
818 
819 /*
820  * Return the property value for the Prop
821  * passed in. (When using libdevinfo)
822  */
823 void *
824 get_prop_val(Prop *prop)
825 {
826 	if (prop == NULL)
827 		return (NULL);
828 
829 	return ((void *)(prop->value.val_ptr));
830 }
831 
832 /*
833  * Return the property size for the Prop
834  * passed in. (When using libdevinfo)
835  */
836 static int
837 get_prop_size(Prop *prop)
838 {
839 
840 	if ((prop != NULL) && (prop->size > 0))
841 		return (prop->size);
842 	else
843 		return (0);
844 }
845 
846 
847 /*
848  * Search a Prom node and retrieve the property with the correct
849  * name. (When using libdevinfo)
850  */
851 Prop *
852 find_prop(Prom_node *pnode, char *name)
853 {
854 	Prop *prop;
855 
856 	if (pnode == NULL)
857 		return (NULL);
858 
859 	for (prop = pnode->props; prop != NULL; prop = prop->next) {
860 		if (prop->name.val_ptr != NULL &&
861 		    strcmp((char *)(prop->name.val_ptr), name) == 0)
862 			break;
863 	}
864 
865 	return (prop);
866 }
867 
868 /*
869  * This function adds a board node to the board structure where that
870  * that node's physical component lives.
871  */
872 void
873 add_node(Sys_tree *root, Prom_node *pnode)
874 {
875 	int board;
876 	Board_node *bnode;
877 	Prom_node *p;
878 	char *type;
879 
880 	if ((board = get_board_num(pnode)) == -1) {
881 	    type = get_node_type(pnode);
882 	    if ((type != NULL) && (strcmp(type, "cpu") == 0))
883 		board = get_board_num((pnode->parent)->parent);
884 	}
885 
886 	/* find the node with the same board number */
887 	if ((bnode = find_board(root, board)) == NULL) {
888 		bnode = insert_board(root, board);
889 		bnode->board_type = UNKNOWN_BOARD;
890 	}
891 
892 	/* now attach this prom node to the board list */
893 	/* Insert this node at the end of the list */
894 	pnode->sibling = NULL;
895 	if (bnode->nodes == NULL)
896 		bnode->nodes = pnode;
897 	else {
898 		p = bnode->nodes;
899 		while (p->sibling != NULL)
900 			p = p->sibling;
901 		p->sibling = pnode;
902 	}
903 
904 }
905