10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
52484Sszhou * Common Development and Distribution License (the "License").
62484Sszhou * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate *
80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate * See the License for the specific language governing permissions
110Sstevel@tonic-gate * and limitations under the License.
120Sstevel@tonic-gate *
130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate *
190Sstevel@tonic-gate * CDDL HEADER END
200Sstevel@tonic-gate */
210Sstevel@tonic-gate /*
22*11474SJonathan.Adams@Sun.COM * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
230Sstevel@tonic-gate * Use is subject to license terms.
240Sstevel@tonic-gate */
250Sstevel@tonic-gate
260Sstevel@tonic-gate #include <sys/types.h>
270Sstevel@tonic-gate #include <sys/promif.h>
280Sstevel@tonic-gate #include <sys/bootconf.h>
290Sstevel@tonic-gate #include <sys/salib.h>
300Sstevel@tonic-gate #include <sys/boot.h>
310Sstevel@tonic-gate #include "boot_plat.h"
320Sstevel@tonic-gate
330Sstevel@tonic-gate char *v2path, *kernname, *systype;
340Sstevel@tonic-gate char *my_own_name = "boot";
350Sstevel@tonic-gate char v2args_buf[V2ARGS_BUF_SZ];
360Sstevel@tonic-gate char *v2args = v2args_buf;
370Sstevel@tonic-gate char *mfg_name;
380Sstevel@tonic-gate char *impl_arch_name;
390Sstevel@tonic-gate char *bootp_response;
400Sstevel@tonic-gate char *module_path;
410Sstevel@tonic-gate int cache_state;
420Sstevel@tonic-gate uint64_t memlistextent; /* replacement for old member of bootops */
430Sstevel@tonic-gate
440Sstevel@tonic-gate /* These are the various memory lists */
450Sstevel@tonic-gate struct memlist *pfreelistp, /* physmem available */
460Sstevel@tonic-gate *vfreelistp, /* virtmem available */
470Sstevel@tonic-gate *pinstalledp; /* physmem installed */
480Sstevel@tonic-gate
490Sstevel@tonic-gate char *boot_message;
500Sstevel@tonic-gate
510Sstevel@tonic-gate char *netdev_path;
520Sstevel@tonic-gate
530Sstevel@tonic-gate /*
540Sstevel@tonic-gate * Support new boot properties "boot-start" and "boot-end" for
550Sstevel@tonic-gate * Freeze/Thaw project.
560Sstevel@tonic-gate */
570Sstevel@tonic-gate caddr_t start_addr, end_addr;
580Sstevel@tonic-gate
590Sstevel@tonic-gate #define BOOT_BADPROP -1
600Sstevel@tonic-gate #define BOOT_SUCCESS 0
610Sstevel@tonic-gate #define BOOT_FAILURE -1
620Sstevel@tonic-gate #define NIL 0
630Sstevel@tonic-gate
640Sstevel@tonic-gate #define strequal(p, q) (strcmp((p), (q)) == 0)
650Sstevel@tonic-gate
660Sstevel@tonic-gate
670Sstevel@tonic-gate /*
680Sstevel@tonic-gate * This routine is used by stand/lib/$PROC/libnfs.a in case it comes up with a
690Sstevel@tonic-gate * default filename, and by bootflags() if a default filename is specified in
700Sstevel@tonic-gate * the boot arguments.
710Sstevel@tonic-gate */
720Sstevel@tonic-gate void
set_default_filename(char * filename)730Sstevel@tonic-gate set_default_filename(char *filename)
740Sstevel@tonic-gate {
750Sstevel@tonic-gate kernname = filename;
760Sstevel@tonic-gate }
770Sstevel@tonic-gate
780Sstevel@tonic-gate
790Sstevel@tonic-gate static const struct bplist {
800Sstevel@tonic-gate char *name;
810Sstevel@tonic-gate void *val;
820Sstevel@tonic-gate uint_t size;
830Sstevel@tonic-gate } bprop_tab[] = {
840Sstevel@tonic-gate "boot-args", &v2args, 0,
850Sstevel@tonic-gate "boot-path", &v2path, 0,
860Sstevel@tonic-gate "fstype", &systype, 0,
870Sstevel@tonic-gate "whoami", &my_own_name, 0,
880Sstevel@tonic-gate "mfg-name", &mfg_name, 0,
890Sstevel@tonic-gate "impl-arch-name", &impl_arch_name, 0,
900Sstevel@tonic-gate "module-path", &module_path, 0,
910Sstevel@tonic-gate "virt-avail", &vfreelistp, 0,
920Sstevel@tonic-gate "phys-avail", &pfreelistp, 0,
930Sstevel@tonic-gate "phys-installed", &pinstalledp, 0,
940Sstevel@tonic-gate "default-name", &kernname, 0,
950Sstevel@tonic-gate "extent", &memlistextent, sizeof (memlistextent),
960Sstevel@tonic-gate "vac", &vac, sizeof (vac),
970Sstevel@tonic-gate "cache-on?", &cache_state, sizeof (int),
980Sstevel@tonic-gate "memory-update", 0, 0,
990Sstevel@tonic-gate "boot-start", &start_addr, sizeof (start_addr),
1000Sstevel@tonic-gate "boot-end", &scratchmemp, sizeof (scratchmemp),
1010Sstevel@tonic-gate "boot-message", &boot_message, 0,
1020Sstevel@tonic-gate "bootp-response", &bootp_response, 0,
1030Sstevel@tonic-gate "netdev-path", &netdev_path, 0,
1040Sstevel@tonic-gate 0, 0, 0
1050Sstevel@tonic-gate };
1060Sstevel@tonic-gate
1070Sstevel@tonic-gate /*
1080Sstevel@tonic-gate * These routines implement the boot getprop interface.
1090Sstevel@tonic-gate * They are designed to mimic the corresponding devr_{getprop,getproplen}
1100Sstevel@tonic-gate * functions.
1110Sstevel@tonic-gate * The assumptions is that the basic property is an unsigned int. Other
1120Sstevel@tonic-gate * types (including lists) are special cases.
1130Sstevel@tonic-gate */
1140Sstevel@tonic-gate
1150Sstevel@tonic-gate /*ARGSUSED*/
1160Sstevel@tonic-gate int
bgetproplen(struct bootops * bop,char * name)1170Sstevel@tonic-gate bgetproplen(struct bootops *bop, char *name)
1180Sstevel@tonic-gate {
1190Sstevel@tonic-gate int size = 0;
1200Sstevel@tonic-gate struct bplist *p;
1210Sstevel@tonic-gate struct memlist *ml;
1220Sstevel@tonic-gate
1230Sstevel@tonic-gate /* this prop has side effects only. No length. */
1240Sstevel@tonic-gate if (strequal(name, "memory-update"))
1250Sstevel@tonic-gate return (BOOT_SUCCESS);
1260Sstevel@tonic-gate
1270Sstevel@tonic-gate for (p = (struct bplist *)bprop_tab; p->name != (char *)0; p++) {
1280Sstevel@tonic-gate
1290Sstevel@tonic-gate /* got a linked list? */
1300Sstevel@tonic-gate if ((strequal(name, "virt-avail") && strequal(name, p->name)) ||
1310Sstevel@tonic-gate (strequal(name, "phys-avail") && strequal(name, p->name)) ||
1320Sstevel@tonic-gate (strequal(name, "phys-installed") &&
1330Sstevel@tonic-gate strequal(name, p->name))) {
1340Sstevel@tonic-gate
1350Sstevel@tonic-gate for (ml = *((struct memlist **)p->val);
136*11474SJonathan.Adams@Sun.COM ml != NIL;
137*11474SJonathan.Adams@Sun.COM ml = ml->ml_next)
1380Sstevel@tonic-gate
1390Sstevel@tonic-gate /*
1400Sstevel@tonic-gate * subtract out the ptrs for our local
1410Sstevel@tonic-gate * linked list. The application will
1420Sstevel@tonic-gate * only see an array.
1430Sstevel@tonic-gate */
1440Sstevel@tonic-gate size += (int)(sizeof (struct memlist) -
145*11474SJonathan.Adams@Sun.COM 2*sizeof (struct memlist *));
1460Sstevel@tonic-gate return (size);
1470Sstevel@tonic-gate
1480Sstevel@tonic-gate } else if (strequal(name, p->name)) {
1490Sstevel@tonic-gate
1500Sstevel@tonic-gate /* if we already know the size, return it */
1510Sstevel@tonic-gate if (p->size != 0)
1520Sstevel@tonic-gate return (p->size);
1530Sstevel@tonic-gate else {
1540Sstevel@tonic-gate if (*((char **)p->val) == NIL)
1550Sstevel@tonic-gate return (0); /* NULL is allowed */
1560Sstevel@tonic-gate
1570Sstevel@tonic-gate /* don't forget the null termination */
1580Sstevel@tonic-gate return (strlen(*((char **)p->val)) + 1);
1590Sstevel@tonic-gate }
1600Sstevel@tonic-gate }
1610Sstevel@tonic-gate }
1620Sstevel@tonic-gate return (BOOT_BADPROP);
1630Sstevel@tonic-gate }
1640Sstevel@tonic-gate
1650Sstevel@tonic-gate /*ARGSUSED*/
1660Sstevel@tonic-gate int
bgetprop(struct bootops * bop,char * name,void * buf)1670Sstevel@tonic-gate bgetprop(struct bootops *bop, char *name, void *buf)
1680Sstevel@tonic-gate {
1690Sstevel@tonic-gate struct bplist *p;
1700Sstevel@tonic-gate struct memlist *ml;
1710Sstevel@tonic-gate
1720Sstevel@tonic-gate if (strequal(name, "memory-update")) {
1730Sstevel@tonic-gate /*
1740Sstevel@tonic-gate * dprintf("bgetprop: updating memlists.\n");
1750Sstevel@tonic-gate */
1760Sstevel@tonic-gate update_memlist("virtual-memory", "available", &vfreelistp);
1770Sstevel@tonic-gate update_memlist("memory", "available", &pfreelistp);
1780Sstevel@tonic-gate return (BOOT_SUCCESS);
1790Sstevel@tonic-gate }
1800Sstevel@tonic-gate
1810Sstevel@tonic-gate if (strequal(name, "boot-start")) {
1820Sstevel@tonic-gate start_addr = (caddr_t)_start;
1830Sstevel@tonic-gate bcopy((char *)(&start_addr), buf, sizeof (start_addr));
1840Sstevel@tonic-gate return (BOOT_SUCCESS);
1850Sstevel@tonic-gate }
1860Sstevel@tonic-gate
1870Sstevel@tonic-gate if (strequal(name, "boot-end")) {
1880Sstevel@tonic-gate /*
1890Sstevel@tonic-gate * The true end of boot should be scratchmemp,
1900Sstevel@tonic-gate * boot gets its dynamic memory from the scratchmem
1910Sstevel@tonic-gate * which is the first 4M of the physical memory,
1920Sstevel@tonic-gate * and they are mapped 1:1.
1930Sstevel@tonic-gate */
1940Sstevel@tonic-gate end_addr = scratchmemp;
1950Sstevel@tonic-gate bcopy((char *)(&end_addr), buf, sizeof (scratchmemp));
1960Sstevel@tonic-gate return (BOOT_SUCCESS);
1970Sstevel@tonic-gate }
1980Sstevel@tonic-gate
1990Sstevel@tonic-gate for (p = (struct bplist *)bprop_tab; p->name != (char *)0; p++) {
2000Sstevel@tonic-gate
2010Sstevel@tonic-gate /* gotta linked list? */
2020Sstevel@tonic-gate if ((strequal(name, "virt-avail") && strequal(name, p->name)) ||
2030Sstevel@tonic-gate (strequal(name, "phys-avail") && strequal(name, p->name)) ||
2040Sstevel@tonic-gate (strequal(name, "phys-installed") &&
2050Sstevel@tonic-gate strequal(name, p->name))) {
2060Sstevel@tonic-gate
2070Sstevel@tonic-gate u_longlong_t *t = buf;
2080Sstevel@tonic-gate
2090Sstevel@tonic-gate for (ml = *((struct memlist **)p->val);
210*11474SJonathan.Adams@Sun.COM ml != NIL;
211*11474SJonathan.Adams@Sun.COM ml = ml->ml_next) {
2120Sstevel@tonic-gate
2130Sstevel@tonic-gate /* copy out into an array */
214*11474SJonathan.Adams@Sun.COM *t++ = ml->ml_address;
215*11474SJonathan.Adams@Sun.COM *t++ = ml->ml_size;
2160Sstevel@tonic-gate }
2170Sstevel@tonic-gate return (BOOT_SUCCESS);
2180Sstevel@tonic-gate } else if (strequal(name, p->name)) {
2190Sstevel@tonic-gate if (p->size != 0) {
2200Sstevel@tonic-gate bcopy(p->val, buf, p->size);
2210Sstevel@tonic-gate } else {
2220Sstevel@tonic-gate (void) strcpy((char *)buf, *((char **)p->val));
2230Sstevel@tonic-gate }
2240Sstevel@tonic-gate return (BOOT_SUCCESS);
2250Sstevel@tonic-gate }
2260Sstevel@tonic-gate }
2270Sstevel@tonic-gate return (BOOT_FAILURE);
2280Sstevel@tonic-gate }
2290Sstevel@tonic-gate
2300Sstevel@tonic-gate /*
2310Sstevel@tonic-gate * If the user wants the first property in the list, he passes in a
2320Sstevel@tonic-gate * null string. The routine will always return a ptr to the name of the
2330Sstevel@tonic-gate * next prop, except when there are no more props. In that case, it will
2340Sstevel@tonic-gate * return a null string.
2350Sstevel@tonic-gate */
2360Sstevel@tonic-gate
2370Sstevel@tonic-gate /*ARGSUSED*/
2380Sstevel@tonic-gate char *
bnextprop(struct bootops * bop,char * prev)2390Sstevel@tonic-gate bnextprop(struct bootops *bop, char *prev)
2400Sstevel@tonic-gate {
2410Sstevel@tonic-gate struct bplist *p;
2420Sstevel@tonic-gate
2430Sstevel@tonic-gate /* user wants the firstprop */
2440Sstevel@tonic-gate if (*prev == 0)
2450Sstevel@tonic-gate return (bprop_tab->name);
2460Sstevel@tonic-gate
2470Sstevel@tonic-gate for (p = (struct bplist *)bprop_tab; p->name != (char *)0; p++) {
2480Sstevel@tonic-gate
2490Sstevel@tonic-gate if (strequal(prev, p->name))
2500Sstevel@tonic-gate /*
2510Sstevel@tonic-gate * if prev is the last valid prop,
2520Sstevel@tonic-gate * we will return our terminator (0).
2530Sstevel@tonic-gate */
2540Sstevel@tonic-gate return ((++p)->name);
2550Sstevel@tonic-gate
2560Sstevel@tonic-gate
2570Sstevel@tonic-gate }
2580Sstevel@tonic-gate return ((char *)0);
2590Sstevel@tonic-gate }
260