xref: /titanic_41/usr/src/lib/libprtdiag/common/prom.c (revision ead1f93ee620d7580f7e53350fe5a884fc4f158a)
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 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <unistd.h>
32 #include <ctype.h>
33 #include <string.h>
34 #include <kvm.h>
35 #include <varargs.h>
36 #include <errno.h>
37 #include <time.h>
38 #include <dirent.h>
39 #include <fcntl.h>
40 #include <sys/param.h>
41 #include <sys/stat.h>
42 #include <sys/types.h>
43 #include <sys/utsname.h>
44 #include <sys/openpromio.h>
45 #include <kstat.h>
46 #include <libintl.h>
47 #include <syslog.h>
48 #include <sys/dkio.h>
49 #include "pdevinfo.h"
50 #include "display.h"
51 #include "pdevinfo_sun4u.h"
52 #include "display_sun4u.h"
53 #include "libprtdiag.h"
54 
55 #if !defined(TEXT_DOMAIN)
56 #define	TEXT_DOMAIN	"SYS_TEST"
57 #endif
58 
59 
60 void
61 disp_prom_version(Prom_node *flashprom)
62 {
63 	Prop *version;
64 	char *vers;		/* OBP version */
65 	char *temp;
66 
67 	/* Look version */
68 	version = find_prop(flashprom, "version");
69 
70 	vers = (char *)get_prop_val(version);
71 
72 	if (vers != NULL) {
73 		log_printf("  %s   ", vers, 0);
74 
75 		/*
76 		 * POST string follows the NULL terminated OBP
77 		 * version string. Do not attempt to print POST
78 		 * string unless node size is larger than the
79 		 * length of the OBP version string.
80 		 */
81 		if ((strlen(vers) + 1) < version->size) {
82 			temp = vers + strlen(vers) + 1;
83 			log_printf("%s", temp, 0);
84 		}
85 	}
86 
87 	log_printf("\n", 0);
88 }
89 
90 
91 void
92 platform_disp_prom_version(Sys_tree *tree)
93 {
94 	Board_node *bnode;
95 	Prom_node *pnode;
96 
97 	bnode = tree->bd_list;
98 
99 	/* Display Prom revision header */
100 	log_printf(dgettext(TEXT_DOMAIN, "System PROM "
101 		"revisions:\n"), 0);
102 	log_printf("----------------------\n", 0);
103 
104 	if ((pnode = find_device(bnode, 0x1F, SBUS_NAME)) == NULL) {
105 		pnode = find_pci_bus(bnode->nodes, 0x1F, 1);
106 	}
107 
108 	/*
109 	 * in case of platforms with multiple flashproms, find and
110 	 * display all proms with a "version"(OBP) property. bug 4187301
111 	 */
112 	for (pnode = dev_find_node(pnode, "flashprom"); pnode != NULL;
113 		pnode = dev_next_node(pnode, "flashprom")) {
114 		    if (find_prop(pnode, "version") != NULL) {
115 				disp_prom_version(pnode);
116 		}
117 	}
118 }
119 
120 int
121 get_pci_class_code_reg(Prom_node *card_node)
122 {
123 	void	*value;
124 
125 	/*
126 	 * Get the class-code of this node and return it
127 	 * if it exists. Otherwise return (-1).
128 	 */
129 	value = get_prop_val(find_prop(card_node, "class-code"));
130 	if (value != NULL)
131 		return (*(int *)value);
132 	else
133 		return (-1);
134 }
135