xref: /onnv-gate/usr/src/psm/stand/boot/sparc/common/bootprop.c (revision 0:68f95e015346)
1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * CDDL HEADER START
3*0Sstevel@tonic-gate  *
4*0Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*0Sstevel@tonic-gate  * with the License.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate  * and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate  *
20*0Sstevel@tonic-gate  * CDDL HEADER END
21*0Sstevel@tonic-gate  */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24*0Sstevel@tonic-gate  * Use is subject to license terms.
25*0Sstevel@tonic-gate  */
26*0Sstevel@tonic-gate 
27*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
28*0Sstevel@tonic-gate 
29*0Sstevel@tonic-gate #include <sys/types.h>
30*0Sstevel@tonic-gate #include <sys/promif.h>
31*0Sstevel@tonic-gate #include <sys/bootconf.h>
32*0Sstevel@tonic-gate #include <sys/salib.h>
33*0Sstevel@tonic-gate #include <sys/boot.h>
34*0Sstevel@tonic-gate #include "boot_plat.h"
35*0Sstevel@tonic-gate 
36*0Sstevel@tonic-gate char *v2path, *kernname, *systype;
37*0Sstevel@tonic-gate char *my_own_name = "boot";
38*0Sstevel@tonic-gate char v2args_buf[V2ARGS_BUF_SZ];
39*0Sstevel@tonic-gate char *v2args = v2args_buf;
40*0Sstevel@tonic-gate char *mfg_name;
41*0Sstevel@tonic-gate char *impl_arch_name;
42*0Sstevel@tonic-gate char *bootp_response;
43*0Sstevel@tonic-gate char *module_path;
44*0Sstevel@tonic-gate int  cache_state;
45*0Sstevel@tonic-gate uint64_t memlistextent;		/* replacement for old member of bootops */
46*0Sstevel@tonic-gate 
47*0Sstevel@tonic-gate /*  These are the various memory lists */
48*0Sstevel@tonic-gate struct memlist	*pfreelistp, /* physmem available */
49*0Sstevel@tonic-gate 		*vfreelistp, /* virtmem available */
50*0Sstevel@tonic-gate 		*pinstalledp;   /* physmem installed */
51*0Sstevel@tonic-gate 
52*0Sstevel@tonic-gate char *boot_message;
53*0Sstevel@tonic-gate 
54*0Sstevel@tonic-gate char *netdev_path;
55*0Sstevel@tonic-gate 
56*0Sstevel@tonic-gate /*
57*0Sstevel@tonic-gate  * Support new boot properties "boot-start" and "boot-end" for
58*0Sstevel@tonic-gate  * Freeze/Thaw project.
59*0Sstevel@tonic-gate  */
60*0Sstevel@tonic-gate caddr_t start_addr, end_addr;
61*0Sstevel@tonic-gate 
62*0Sstevel@tonic-gate #define	BOOT_BADPROP	-1
63*0Sstevel@tonic-gate #define	BOOT_SUCCESS	0
64*0Sstevel@tonic-gate #define	BOOT_FAILURE	-1
65*0Sstevel@tonic-gate #define	NIL		0
66*0Sstevel@tonic-gate 
67*0Sstevel@tonic-gate #define	strequal(p, q)	(strcmp((p), (q)) == 0)
68*0Sstevel@tonic-gate 
69*0Sstevel@tonic-gate 
70*0Sstevel@tonic-gate /*
71*0Sstevel@tonic-gate  * This routine is used by stand/lib/$PROC/libnfs.a in case it comes up with a
72*0Sstevel@tonic-gate  * default filename, and by bootflags() if a default filename is specified in
73*0Sstevel@tonic-gate  * the boot arguments.
74*0Sstevel@tonic-gate  */
75*0Sstevel@tonic-gate void
76*0Sstevel@tonic-gate set_default_filename(char *filename)
77*0Sstevel@tonic-gate {
78*0Sstevel@tonic-gate 	kernname = filename;
79*0Sstevel@tonic-gate }
80*0Sstevel@tonic-gate 
81*0Sstevel@tonic-gate 
82*0Sstevel@tonic-gate static const struct bplist {
83*0Sstevel@tonic-gate 	char	*name;
84*0Sstevel@tonic-gate 	void	*val;
85*0Sstevel@tonic-gate 	uint_t	size;
86*0Sstevel@tonic-gate } bprop_tab[] = {
87*0Sstevel@tonic-gate 	"boot-args",		&v2args,		0,
88*0Sstevel@tonic-gate 	"boot-path",		&v2path,		0,
89*0Sstevel@tonic-gate 	"fstype",		&systype,		0,
90*0Sstevel@tonic-gate 	"whoami",		&my_own_name,		0,
91*0Sstevel@tonic-gate 	"mfg-name",		&mfg_name,		0,
92*0Sstevel@tonic-gate 	"impl-arch-name",	&impl_arch_name,	0,
93*0Sstevel@tonic-gate 	"module-path",		&module_path,		0,
94*0Sstevel@tonic-gate 	"virt-avail",		&vfreelistp,		0,
95*0Sstevel@tonic-gate 	"phys-avail",		&pfreelistp,		0,
96*0Sstevel@tonic-gate 	"phys-installed",	&pinstalledp,		0,
97*0Sstevel@tonic-gate 	"default-name",		&kernname,		0,
98*0Sstevel@tonic-gate 	"extent",		&memlistextent,		sizeof (memlistextent),
99*0Sstevel@tonic-gate 	"vac",			&vac,			sizeof (vac),
100*0Sstevel@tonic-gate 	"cache-on?",		&cache_state,		sizeof (int),
101*0Sstevel@tonic-gate 	"memory-update",	0,			0,
102*0Sstevel@tonic-gate 	"boot-start",		&start_addr,		sizeof (start_addr),
103*0Sstevel@tonic-gate 	"boot-end",		&scratchmemp,		sizeof (scratchmemp),
104*0Sstevel@tonic-gate 	"boot-message",		&boot_message,		0,
105*0Sstevel@tonic-gate 	"bootp-response",	&bootp_response,	0,
106*0Sstevel@tonic-gate 	"netdev-path",		&netdev_path,		0,
107*0Sstevel@tonic-gate 	0,			0,			0
108*0Sstevel@tonic-gate };
109*0Sstevel@tonic-gate 
110*0Sstevel@tonic-gate /*
111*0Sstevel@tonic-gate  *  These routines implement the boot getprop interface.
112*0Sstevel@tonic-gate  *  They are designed to mimic the corresponding devr_{getprop,getproplen}
113*0Sstevel@tonic-gate  *  functions.
114*0Sstevel@tonic-gate  *  The assumptions is that the basic property is an unsigned int.  Other
115*0Sstevel@tonic-gate  *  types (including lists) are special cases.
116*0Sstevel@tonic-gate  */
117*0Sstevel@tonic-gate 
118*0Sstevel@tonic-gate /*ARGSUSED*/
119*0Sstevel@tonic-gate int
120*0Sstevel@tonic-gate bgetproplen(struct bootops *bop, char *name)
121*0Sstevel@tonic-gate {
122*0Sstevel@tonic-gate 	int size = 0;
123*0Sstevel@tonic-gate 	struct bplist *p;
124*0Sstevel@tonic-gate 	struct memlist *ml;
125*0Sstevel@tonic-gate 
126*0Sstevel@tonic-gate 	/* this prop has side effects only.  No length.  */
127*0Sstevel@tonic-gate 	if (strequal(name, "memory-update"))
128*0Sstevel@tonic-gate 		return (BOOT_SUCCESS);
129*0Sstevel@tonic-gate 
130*0Sstevel@tonic-gate 	for (p = (struct bplist *)bprop_tab; p->name != (char *)0; p++) {
131*0Sstevel@tonic-gate 
132*0Sstevel@tonic-gate 		/* got a linked list?  */
133*0Sstevel@tonic-gate 		if ((strequal(name, "virt-avail") && strequal(name, p->name)) ||
134*0Sstevel@tonic-gate 		    (strequal(name, "phys-avail") && strequal(name, p->name)) ||
135*0Sstevel@tonic-gate 		    (strequal(name, "phys-installed") &&
136*0Sstevel@tonic-gate 		    strequal(name, p->name))) {
137*0Sstevel@tonic-gate 
138*0Sstevel@tonic-gate 			for (ml = *((struct memlist **)p->val);
139*0Sstevel@tonic-gate 					ml != NIL;
140*0Sstevel@tonic-gate 					ml = ml->next)
141*0Sstevel@tonic-gate 
142*0Sstevel@tonic-gate 				/*
143*0Sstevel@tonic-gate 				 *  subtract out the ptrs for our local
144*0Sstevel@tonic-gate 				 *  linked list.  The application will
145*0Sstevel@tonic-gate 				 *  only see an array.
146*0Sstevel@tonic-gate 				 */
147*0Sstevel@tonic-gate 				size += (int)(sizeof (struct memlist) -
148*0Sstevel@tonic-gate 						2*sizeof (struct memlist *));
149*0Sstevel@tonic-gate 			return (size);
150*0Sstevel@tonic-gate 
151*0Sstevel@tonic-gate 		} else if (strequal(name, p->name)) {
152*0Sstevel@tonic-gate 
153*0Sstevel@tonic-gate 			/* if we already know the size, return it */
154*0Sstevel@tonic-gate 			if (p->size != 0)
155*0Sstevel@tonic-gate 				return (p->size);
156*0Sstevel@tonic-gate 			else {
157*0Sstevel@tonic-gate 				if (*((char **)p->val) == NIL)
158*0Sstevel@tonic-gate 					return (0);	/* NULL is allowed */
159*0Sstevel@tonic-gate 
160*0Sstevel@tonic-gate 				/* don't forget the null termination */
161*0Sstevel@tonic-gate 				return (strlen(*((char **)p->val)) + 1);
162*0Sstevel@tonic-gate 			}
163*0Sstevel@tonic-gate 		}
164*0Sstevel@tonic-gate 	}
165*0Sstevel@tonic-gate 	printf("Property (%s) not supported by %s\n", name, my_own_name);
166*0Sstevel@tonic-gate 	return (BOOT_BADPROP);
167*0Sstevel@tonic-gate }
168*0Sstevel@tonic-gate 
169*0Sstevel@tonic-gate /*ARGSUSED*/
170*0Sstevel@tonic-gate int
171*0Sstevel@tonic-gate bgetprop(struct bootops *bop, char *name, void *buf)
172*0Sstevel@tonic-gate {
173*0Sstevel@tonic-gate 	struct bplist *p;
174*0Sstevel@tonic-gate 	struct memlist *ml;
175*0Sstevel@tonic-gate 
176*0Sstevel@tonic-gate 	if (strequal(name, "memory-update")) {
177*0Sstevel@tonic-gate /*
178*0Sstevel@tonic-gate  *		dprintf("bgetprop:  updating memlists.\n");
179*0Sstevel@tonic-gate  */
180*0Sstevel@tonic-gate 		update_memlist("virtual-memory", "available", &vfreelistp);
181*0Sstevel@tonic-gate 		update_memlist("memory", "available", &pfreelistp);
182*0Sstevel@tonic-gate 		return (BOOT_SUCCESS);
183*0Sstevel@tonic-gate 	}
184*0Sstevel@tonic-gate 
185*0Sstevel@tonic-gate 	if (strequal(name, "boot-start")) {
186*0Sstevel@tonic-gate 		start_addr = (caddr_t)_start;
187*0Sstevel@tonic-gate 		bcopy((char *)(&start_addr), buf, sizeof (start_addr));
188*0Sstevel@tonic-gate 		return (BOOT_SUCCESS);
189*0Sstevel@tonic-gate 	}
190*0Sstevel@tonic-gate 
191*0Sstevel@tonic-gate 	if (strequal(name, "boot-end")) {
192*0Sstevel@tonic-gate 		/*
193*0Sstevel@tonic-gate 		 * The true end of boot should be scratchmemp,
194*0Sstevel@tonic-gate 		 * boot gets its dynamic memory from the scratchmem
195*0Sstevel@tonic-gate 		 * which is the first 4M of the physical memory,
196*0Sstevel@tonic-gate 		 * and they are mapped 1:1.
197*0Sstevel@tonic-gate 		 */
198*0Sstevel@tonic-gate 		end_addr = scratchmemp;
199*0Sstevel@tonic-gate 		bcopy((char *)(&end_addr), buf, sizeof (scratchmemp));
200*0Sstevel@tonic-gate 		return (BOOT_SUCCESS);
201*0Sstevel@tonic-gate 	}
202*0Sstevel@tonic-gate 
203*0Sstevel@tonic-gate 	for (p = (struct bplist *)bprop_tab; p->name != (char *)0; p++) {
204*0Sstevel@tonic-gate 
205*0Sstevel@tonic-gate 		/* gotta linked list? */
206*0Sstevel@tonic-gate 		if ((strequal(name, "virt-avail") && strequal(name, p->name)) ||
207*0Sstevel@tonic-gate 		    (strequal(name, "phys-avail") && strequal(name, p->name)) ||
208*0Sstevel@tonic-gate 		    (strequal(name, "phys-installed") &&
209*0Sstevel@tonic-gate 		    strequal(name, p->name))) {
210*0Sstevel@tonic-gate 
211*0Sstevel@tonic-gate 			u_longlong_t *t = buf;
212*0Sstevel@tonic-gate 
213*0Sstevel@tonic-gate 			for (ml = *((struct memlist **)p->val);
214*0Sstevel@tonic-gate 					ml != NIL;
215*0Sstevel@tonic-gate 					ml = ml->next) {
216*0Sstevel@tonic-gate 
217*0Sstevel@tonic-gate 				/* copy out into an array */
218*0Sstevel@tonic-gate 				*t++ = ml->address;
219*0Sstevel@tonic-gate 				*t++ = ml->size;
220*0Sstevel@tonic-gate 			}
221*0Sstevel@tonic-gate 			return (BOOT_SUCCESS);
222*0Sstevel@tonic-gate 		} else if (strequal(name, p->name)) {
223*0Sstevel@tonic-gate 			if (p->size != 0) {
224*0Sstevel@tonic-gate 				bcopy(p->val, buf, p->size);
225*0Sstevel@tonic-gate 			} else {
226*0Sstevel@tonic-gate 				(void) strcpy((char *)buf, *((char **)p->val));
227*0Sstevel@tonic-gate 			}
228*0Sstevel@tonic-gate 			return (BOOT_SUCCESS);
229*0Sstevel@tonic-gate 		}
230*0Sstevel@tonic-gate 	}
231*0Sstevel@tonic-gate 	return (BOOT_FAILURE);
232*0Sstevel@tonic-gate }
233*0Sstevel@tonic-gate 
234*0Sstevel@tonic-gate /*
235*0Sstevel@tonic-gate  *  If the user wants the first property in the list, he passes in a
236*0Sstevel@tonic-gate  *  null string.  The routine will always return a ptr to the name of the
237*0Sstevel@tonic-gate  *  next prop, except when there are no more props.  In that case, it will
238*0Sstevel@tonic-gate  *  return a null string.
239*0Sstevel@tonic-gate  */
240*0Sstevel@tonic-gate 
241*0Sstevel@tonic-gate /*ARGSUSED*/
242*0Sstevel@tonic-gate char *
243*0Sstevel@tonic-gate bnextprop(struct bootops *bop, char *prev)
244*0Sstevel@tonic-gate {
245*0Sstevel@tonic-gate 	struct bplist *p;
246*0Sstevel@tonic-gate 
247*0Sstevel@tonic-gate 	/* user wants the firstprop */
248*0Sstevel@tonic-gate 	if (*prev == 0)
249*0Sstevel@tonic-gate 		return (bprop_tab->name);
250*0Sstevel@tonic-gate 
251*0Sstevel@tonic-gate 	for (p = (struct bplist *)bprop_tab; p->name != (char *)0; p++) {
252*0Sstevel@tonic-gate 
253*0Sstevel@tonic-gate 		if (strequal(prev, p->name))
254*0Sstevel@tonic-gate 			/*
255*0Sstevel@tonic-gate 			 * if prev is the last valid prop,
256*0Sstevel@tonic-gate 			 * we will return our terminator (0).
257*0Sstevel@tonic-gate 			 */
258*0Sstevel@tonic-gate 			return ((++p)->name);
259*0Sstevel@tonic-gate 
260*0Sstevel@tonic-gate 
261*0Sstevel@tonic-gate 	}
262*0Sstevel@tonic-gate 	return ((char *)0);
263*0Sstevel@tonic-gate }
264