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