xref: /illumos-gate/usr/src/psm/stand/boot/sparc/common/machdep.c (revision 9b9d39d2a32ff806d2431dbcc50968ef1e6d46b2)
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  * Copyright 2019 Peter Tribble.
27  */
28 
29 #include <sys/types.h>
30 #include <sys/param.h>
31 #include <sys/fcntl.h>
32 #include <sys/promif.h>
33 #include <sys/prom_plat.h>
34 #include <sys/salib.h>
35 
36 extern int is_sun4v;
37 
38 /*
39  * Retain a page or reclaim a previously retained page of physical
40  * memory for use by the prom upgrade. If successful, leave
41  * an indication that a page was retained by creating a boolean
42  * property in the root node.
43  *
44  * XXX: SUNW,retain doesn't work as expected on server systems,
45  * so we don't try to retain any memory on those systems.
46  *
47  * XXX: do a '0 to my-self' as a workaround for 4160914
48  */
49 
50 int dont_retain_memory;
51 
52 void
53 retain_nvram_page(void)
54 {
55 	unsigned long long phys = 0;
56 	int len;
57 	char name[32];
58 	static char create_prop[] =
59 	    "0 to my-self dev / 0 0 \" boot-retained-page\" property";
60 	static char ue[] = "SUNW,Ultra-Enterprise";
61 	extern int verbosemode;
62 
63 	if (dont_retain_memory)
64 		return;
65 
66 	if (!is_sun4v) {
67 		len = prom_getproplen(prom_rootnode(), "name");
68 		if ((len != -1) && (len <= sizeof (name))) {
69 			(void) prom_getprop(prom_rootnode(), "name", name);
70 			if (strcmp(name, ue) == 0)
71 				return;
72 		}
73 	}
74 
75 	if (prom_retain("OBPnvram", PAGESIZE, PAGESIZE, &phys) != 0) {
76 		printf("prom_retain failed\n");
77 		return;
78 	}
79 	if (verbosemode)
80 		printf("retained OBPnvram page at 0x%llx\n", phys);
81 
82 	prom_interpret(create_prop, 0, 0, 0, 0, 0);
83 }
84