xref: /illumos-gate/usr/src/lib/libprtdiag/common/prom.c (revision 1da57d551424de5a9d469760be7c4b4d4f10a755)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright (c) 1999-2001 by Sun Microsystems, Inc.
24  * All rights reserved.
25  */
26 
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <unistd.h>
30 #include <ctype.h>
31 #include <string.h>
32 #include <kvm.h>
33 #include <varargs.h>
34 #include <errno.h>
35 #include <time.h>
36 #include <dirent.h>
37 #include <fcntl.h>
38 #include <sys/param.h>
39 #include <sys/stat.h>
40 #include <sys/types.h>
41 #include <sys/utsname.h>
42 #include <sys/openpromio.h>
43 #include <kstat.h>
44 #include <libintl.h>
45 #include <syslog.h>
46 #include <sys/dkio.h>
47 #include "pdevinfo.h"
48 #include "display.h"
49 #include "pdevinfo_sun4u.h"
50 #include "display_sun4u.h"
51 #include "libprtdiag.h"
52 
53 #if !defined(TEXT_DOMAIN)
54 #define	TEXT_DOMAIN	"SYS_TEST"
55 #endif
56 
57 
58 void
disp_prom_version(Prom_node * flashprom)59 disp_prom_version(Prom_node *flashprom)
60 {
61 	Prop *version;
62 	char *vers;		/* OBP version */
63 	char *temp;
64 
65 	/* Look version */
66 	version = find_prop(flashprom, "version");
67 
68 	vers = (char *)get_prop_val(version);
69 
70 	if (vers != NULL) {
71 		log_printf("  %s   ", vers, 0);
72 
73 		/*
74 		 * POST string follows the NULL terminated OBP
75 		 * version string. Do not attempt to print POST
76 		 * string unless node size is larger than the
77 		 * length of the OBP version string.
78 		 */
79 		if ((strlen(vers) + 1) < version->size) {
80 			temp = vers + strlen(vers) + 1;
81 			log_printf("%s", temp, 0);
82 		}
83 	}
84 
85 	log_printf("\n", 0);
86 }
87 
88 
89 void
platform_disp_prom_version(Sys_tree * tree)90 platform_disp_prom_version(Sys_tree *tree)
91 {
92 	Board_node *bnode;
93 	Prom_node *pnode;
94 
95 	bnode = tree->bd_list;
96 
97 	/* Display Prom revision header */
98 	log_printf(dgettext(TEXT_DOMAIN, "System PROM "
99 		"revisions:\n"), 0);
100 	log_printf("----------------------\n", 0);
101 
102 	if ((pnode = find_device(bnode, 0x1F, SBUS_NAME)) == NULL) {
103 		pnode = find_pci_bus(bnode->nodes, 0x1F, 1);
104 	}
105 
106 	/*
107 	 * in case of platforms with multiple flashproms, find and
108 	 * display all proms with a "version"(OBP) property. bug 4187301
109 	 */
110 	for (pnode = dev_find_node(pnode, "flashprom"); pnode != NULL;
111 		pnode = dev_next_node(pnode, "flashprom")) {
112 		    if (find_prop(pnode, "version") != NULL) {
113 				disp_prom_version(pnode);
114 		}
115 	}
116 }
117 
118 int
get_pci_class_code_reg(Prom_node * card_node)119 get_pci_class_code_reg(Prom_node *card_node)
120 {
121 	void	*value;
122 
123 	/*
124 	 * Get the class-code of this node and return it
125 	 * if it exists. Otherwise return (-1).
126 	 */
127 	value = get_prop_val(find_prop(card_node, "class-code"));
128 	if (value != NULL)
129 		return (*(int *)value);
130 	else
131 		return (-1);
132 }
133