xref: /titanic_50/usr/src/psm/stand/boot/sparc/common/machdep.c (revision 880d797826457b77414b37d531cc3e1aa166ecbe)
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 2010 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #include <sys/types.h>
27 #include <sys/param.h>
28 #include <sys/fcntl.h>
29 #include <sys/promif.h>
30 #include <sys/prom_plat.h>
31 #include <sys/salib.h>
32 
33 extern int is_sun4v;
34 
35 /*
36  * Check if the CPU should default to 64-bit or not.
37  * UltraSPARC-1's default to 32-bit mode.
38  * Everything else defaults to 64-bit mode.
39  */
40 
41 /*
42  * Manufacturer codes for the CPUs we're interested in
43  */
44 #define	TI_JEDEC	0x17
45 #define	SUNW_JEDEC	0x22
46 
47 /*
48  * Implementation codes for the CPUs we're interested in
49  */
50 #define	IMPL_US_I	0x10
51 
52 static pnode_t
53 visit(pnode_t node)
54 {
55 	int impl, manu;
56 	char name[32];
57 	static char ultrasparc[] = "SUNW,UltraSPARC";
58 	static char implementation[] = "implementation#";
59 	static char manufacturer[] = "manufacturer#";
60 
61 	/*
62 	 * if name isn't 'SUNW,UltraSPARC', continue.
63 	 */
64 	if (prom_getproplen(node, "name") != sizeof (ultrasparc))
65 		return ((pnode_t)0);
66 	(void) prom_getprop(node, "name", name);
67 	if (strncmp(name, ultrasparc, sizeof (ultrasparc)) != 0)
68 		return ((pnode_t)0);
69 
70 	if (prom_getproplen(node, manufacturer) != sizeof (int))
71 		return ((pnode_t)0);
72 	(void) prom_getprop(node, manufacturer, (caddr_t)&manu);
73 
74 	if ((manu != SUNW_JEDEC) && (manu != TI_JEDEC))
75 		return ((pnode_t)0);
76 
77 	if (prom_getproplen(node, implementation) != sizeof (int))
78 		return ((pnode_t)0);
79 	(void) prom_getprop(node, implementation, (caddr_t)&impl);
80 
81 	if (impl != IMPL_US_I)
82 		return ((pnode_t)0);
83 
84 	return (node);
85 }
86 
87 /*
88  * visit each node in the device tree, until we get a non-null answer
89  */
90 static pnode_t
91 walk(pnode_t node)
92 {
93 	pnode_t id;
94 
95 	if (visit(node))
96 		return (node);
97 
98 	for (node = prom_childnode(node); node; node = prom_nextnode(node))
99 		if ((id = walk(node)) != (pnode_t)0)
100 			return (id);
101 
102 	return ((pnode_t)0);
103 }
104 
105 /*
106  * Check if the CPU is an UltraSPARC-1 or not.
107  */
108 int
109 cpu_is_ultrasparc_1(void)
110 {
111 	static int cpu_checked;
112 	static int cpu_default;
113 
114 	/*
115 	 * If we already checked or the machine is
116 	 * a sun4v, we already know the answer.
117 	 */
118 	if (!is_sun4v || cpu_checked == 0) {
119 		if (walk(prom_rootnode()))
120 			cpu_default = 1;
121 		cpu_checked = 1;
122 	}
123 
124 	return (cpu_default);
125 }
126 
127 /*
128  * Retain a page or reclaim a previously retained page of physical
129  * memory for use by the prom upgrade. If successful, leave
130  * an indication that a page was retained by creating a boolean
131  * property in the root node.
132  *
133  * XXX: SUNW,retain doesn't work as expected on server systems,
134  * so we don't try to retain any memory on those systems.
135  *
136  * XXX: do a '0 to my-self' as a workaround for 4160914
137  */
138 
139 int dont_retain_memory;
140 
141 void
142 retain_nvram_page(void)
143 {
144 	unsigned long long phys = 0;
145 	int len;
146 	char name[32];
147 	static char create_prop[] =
148 	    "0 to my-self dev / 0 0 \" boot-retained-page\" property";
149 	static char ue10000[] = "SUNW,Ultra-Enterprise-10000";
150 	static char ue[] = "SUNW,Ultra-Enterprise";
151 	extern int verbosemode;
152 
153 	if (dont_retain_memory)
154 		return;
155 
156 	if (!is_sun4v) {
157 		len = prom_getproplen(prom_rootnode(), "name");
158 		if ((len != -1) && (len <= sizeof (name))) {
159 			(void) prom_getprop(prom_rootnode(), "name", name);
160 			if ((strcmp(name, ue) == 0) ||
161 			    (strcmp(name, ue10000) == 0))
162 				return;
163 		}
164 	}
165 
166 	if (prom_retain("OBPnvram", PAGESIZE, PAGESIZE, &phys) != 0) {
167 		printf("prom_retain failed\n");
168 		return;
169 	}
170 	if (verbosemode)
171 		printf("retained OBPnvram page at 0x%llx\n", phys);
172 
173 	prom_interpret(create_prop, 0, 0, 0, 0, 0);
174 }
175