17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5bbeeca55Sszhou * Common Development and Distribution License (the "License"). 6bbeeca55Sszhou * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217c478bd9Sstevel@tonic-gate /* 22*56f33205SJonathan Adams * Copyright 2010 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate #include <sys/types.h> 277c478bd9Sstevel@tonic-gate #include <sys/promif.h> 287c478bd9Sstevel@tonic-gate #include <sys/bootconf.h> 297c478bd9Sstevel@tonic-gate #include <sys/salib.h> 307c478bd9Sstevel@tonic-gate #include <sys/boot.h> 317c478bd9Sstevel@tonic-gate #include "boot_plat.h" 327c478bd9Sstevel@tonic-gate 337c478bd9Sstevel@tonic-gate char *v2path, *kernname, *systype; 347c478bd9Sstevel@tonic-gate char *my_own_name = "boot"; 357c478bd9Sstevel@tonic-gate char v2args_buf[V2ARGS_BUF_SZ]; 367c478bd9Sstevel@tonic-gate char *v2args = v2args_buf; 377c478bd9Sstevel@tonic-gate char *mfg_name; 387c478bd9Sstevel@tonic-gate char *impl_arch_name; 397c478bd9Sstevel@tonic-gate char *bootp_response; 407c478bd9Sstevel@tonic-gate char *module_path; 417c478bd9Sstevel@tonic-gate int cache_state; 427c478bd9Sstevel@tonic-gate uint64_t memlistextent; /* replacement for old member of bootops */ 437c478bd9Sstevel@tonic-gate 447c478bd9Sstevel@tonic-gate /* These are the various memory lists */ 457c478bd9Sstevel@tonic-gate struct memlist *pfreelistp, /* physmem available */ 467c478bd9Sstevel@tonic-gate *vfreelistp, /* virtmem available */ 477c478bd9Sstevel@tonic-gate *pinstalledp; /* physmem installed */ 487c478bd9Sstevel@tonic-gate 497c478bd9Sstevel@tonic-gate char *boot_message; 507c478bd9Sstevel@tonic-gate 517c478bd9Sstevel@tonic-gate char *netdev_path; 527c478bd9Sstevel@tonic-gate 537c478bd9Sstevel@tonic-gate /* 547c478bd9Sstevel@tonic-gate * Support new boot properties "boot-start" and "boot-end" for 557c478bd9Sstevel@tonic-gate * Freeze/Thaw project. 567c478bd9Sstevel@tonic-gate */ 577c478bd9Sstevel@tonic-gate caddr_t start_addr, end_addr; 587c478bd9Sstevel@tonic-gate 597c478bd9Sstevel@tonic-gate #define BOOT_BADPROP -1 607c478bd9Sstevel@tonic-gate #define BOOT_SUCCESS 0 617c478bd9Sstevel@tonic-gate #define BOOT_FAILURE -1 627c478bd9Sstevel@tonic-gate #define NIL 0 637c478bd9Sstevel@tonic-gate 647c478bd9Sstevel@tonic-gate #define strequal(p, q) (strcmp((p), (q)) == 0) 657c478bd9Sstevel@tonic-gate 667c478bd9Sstevel@tonic-gate 677c478bd9Sstevel@tonic-gate /* 687c478bd9Sstevel@tonic-gate * This routine is used by stand/lib/$PROC/libnfs.a in case it comes up with a 697c478bd9Sstevel@tonic-gate * default filename, and by bootflags() if a default filename is specified in 707c478bd9Sstevel@tonic-gate * the boot arguments. 717c478bd9Sstevel@tonic-gate */ 727c478bd9Sstevel@tonic-gate void 737c478bd9Sstevel@tonic-gate set_default_filename(char *filename) 747c478bd9Sstevel@tonic-gate { 757c478bd9Sstevel@tonic-gate kernname = filename; 767c478bd9Sstevel@tonic-gate } 777c478bd9Sstevel@tonic-gate 787c478bd9Sstevel@tonic-gate 797c478bd9Sstevel@tonic-gate static const struct bplist { 807c478bd9Sstevel@tonic-gate char *name; 817c478bd9Sstevel@tonic-gate void *val; 827c478bd9Sstevel@tonic-gate uint_t size; 837c478bd9Sstevel@tonic-gate } bprop_tab[] = { 847c478bd9Sstevel@tonic-gate "boot-args", &v2args, 0, 857c478bd9Sstevel@tonic-gate "boot-path", &v2path, 0, 867c478bd9Sstevel@tonic-gate "fstype", &systype, 0, 877c478bd9Sstevel@tonic-gate "whoami", &my_own_name, 0, 887c478bd9Sstevel@tonic-gate "mfg-name", &mfg_name, 0, 897c478bd9Sstevel@tonic-gate "impl-arch-name", &impl_arch_name, 0, 907c478bd9Sstevel@tonic-gate "module-path", &module_path, 0, 917c478bd9Sstevel@tonic-gate "virt-avail", &vfreelistp, 0, 927c478bd9Sstevel@tonic-gate "phys-avail", &pfreelistp, 0, 937c478bd9Sstevel@tonic-gate "phys-installed", &pinstalledp, 0, 947c478bd9Sstevel@tonic-gate "default-name", &kernname, 0, 957c478bd9Sstevel@tonic-gate "extent", &memlistextent, sizeof (memlistextent), 967c478bd9Sstevel@tonic-gate "vac", &vac, sizeof (vac), 977c478bd9Sstevel@tonic-gate "cache-on?", &cache_state, sizeof (int), 987c478bd9Sstevel@tonic-gate "memory-update", 0, 0, 997c478bd9Sstevel@tonic-gate "boot-start", &start_addr, sizeof (start_addr), 1007c478bd9Sstevel@tonic-gate "boot-end", &scratchmemp, sizeof (scratchmemp), 1017c478bd9Sstevel@tonic-gate "boot-message", &boot_message, 0, 1027c478bd9Sstevel@tonic-gate "bootp-response", &bootp_response, 0, 1037c478bd9Sstevel@tonic-gate "netdev-path", &netdev_path, 0, 1047c478bd9Sstevel@tonic-gate 0, 0, 0 1057c478bd9Sstevel@tonic-gate }; 1067c478bd9Sstevel@tonic-gate 1077c478bd9Sstevel@tonic-gate /* 1087c478bd9Sstevel@tonic-gate * These routines implement the boot getprop interface. 1097c478bd9Sstevel@tonic-gate * They are designed to mimic the corresponding devr_{getprop,getproplen} 1107c478bd9Sstevel@tonic-gate * functions. 1117c478bd9Sstevel@tonic-gate * The assumptions is that the basic property is an unsigned int. Other 1127c478bd9Sstevel@tonic-gate * types (including lists) are special cases. 1137c478bd9Sstevel@tonic-gate */ 1147c478bd9Sstevel@tonic-gate 1157c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 1167c478bd9Sstevel@tonic-gate int 1177c478bd9Sstevel@tonic-gate bgetproplen(struct bootops *bop, char *name) 1187c478bd9Sstevel@tonic-gate { 1197c478bd9Sstevel@tonic-gate int size = 0; 1207c478bd9Sstevel@tonic-gate struct bplist *p; 1217c478bd9Sstevel@tonic-gate struct memlist *ml; 1227c478bd9Sstevel@tonic-gate 1237c478bd9Sstevel@tonic-gate /* this prop has side effects only. No length. */ 1247c478bd9Sstevel@tonic-gate if (strequal(name, "memory-update")) 1257c478bd9Sstevel@tonic-gate return (BOOT_SUCCESS); 1267c478bd9Sstevel@tonic-gate 1277c478bd9Sstevel@tonic-gate for (p = (struct bplist *)bprop_tab; p->name != (char *)0; p++) { 1287c478bd9Sstevel@tonic-gate 1297c478bd9Sstevel@tonic-gate /* got a linked list? */ 1307c478bd9Sstevel@tonic-gate if ((strequal(name, "virt-avail") && strequal(name, p->name)) || 1317c478bd9Sstevel@tonic-gate (strequal(name, "phys-avail") && strequal(name, p->name)) || 1327c478bd9Sstevel@tonic-gate (strequal(name, "phys-installed") && 1337c478bd9Sstevel@tonic-gate strequal(name, p->name))) { 1347c478bd9Sstevel@tonic-gate 1357c478bd9Sstevel@tonic-gate for (ml = *((struct memlist **)p->val); 1367c478bd9Sstevel@tonic-gate ml != NIL; 137*56f33205SJonathan Adams ml = ml->ml_next) 1387c478bd9Sstevel@tonic-gate 1397c478bd9Sstevel@tonic-gate /* 1407c478bd9Sstevel@tonic-gate * subtract out the ptrs for our local 1417c478bd9Sstevel@tonic-gate * linked list. The application will 1427c478bd9Sstevel@tonic-gate * only see an array. 1437c478bd9Sstevel@tonic-gate */ 1447c478bd9Sstevel@tonic-gate size += (int)(sizeof (struct memlist) - 1457c478bd9Sstevel@tonic-gate 2*sizeof (struct memlist *)); 1467c478bd9Sstevel@tonic-gate return (size); 1477c478bd9Sstevel@tonic-gate 1487c478bd9Sstevel@tonic-gate } else if (strequal(name, p->name)) { 1497c478bd9Sstevel@tonic-gate 1507c478bd9Sstevel@tonic-gate /* if we already know the size, return it */ 1517c478bd9Sstevel@tonic-gate if (p->size != 0) 1527c478bd9Sstevel@tonic-gate return (p->size); 1537c478bd9Sstevel@tonic-gate else { 1547c478bd9Sstevel@tonic-gate if (*((char **)p->val) == NIL) 1557c478bd9Sstevel@tonic-gate return (0); /* NULL is allowed */ 1567c478bd9Sstevel@tonic-gate 1577c478bd9Sstevel@tonic-gate /* don't forget the null termination */ 1587c478bd9Sstevel@tonic-gate return (strlen(*((char **)p->val)) + 1); 1597c478bd9Sstevel@tonic-gate } 1607c478bd9Sstevel@tonic-gate } 1617c478bd9Sstevel@tonic-gate } 1627c478bd9Sstevel@tonic-gate return (BOOT_BADPROP); 1637c478bd9Sstevel@tonic-gate } 1647c478bd9Sstevel@tonic-gate 1657c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 1667c478bd9Sstevel@tonic-gate int 1677c478bd9Sstevel@tonic-gate bgetprop(struct bootops *bop, char *name, void *buf) 1687c478bd9Sstevel@tonic-gate { 1697c478bd9Sstevel@tonic-gate struct bplist *p; 1707c478bd9Sstevel@tonic-gate struct memlist *ml; 1717c478bd9Sstevel@tonic-gate 1727c478bd9Sstevel@tonic-gate if (strequal(name, "memory-update")) { 1737c478bd9Sstevel@tonic-gate /* 1747c478bd9Sstevel@tonic-gate * dprintf("bgetprop: updating memlists.\n"); 1757c478bd9Sstevel@tonic-gate */ 1767c478bd9Sstevel@tonic-gate update_memlist("virtual-memory", "available", &vfreelistp); 1777c478bd9Sstevel@tonic-gate update_memlist("memory", "available", &pfreelistp); 1787c478bd9Sstevel@tonic-gate return (BOOT_SUCCESS); 1797c478bd9Sstevel@tonic-gate } 1807c478bd9Sstevel@tonic-gate 1817c478bd9Sstevel@tonic-gate if (strequal(name, "boot-start")) { 1827c478bd9Sstevel@tonic-gate start_addr = (caddr_t)_start; 1837c478bd9Sstevel@tonic-gate bcopy((char *)(&start_addr), buf, sizeof (start_addr)); 1847c478bd9Sstevel@tonic-gate return (BOOT_SUCCESS); 1857c478bd9Sstevel@tonic-gate } 1867c478bd9Sstevel@tonic-gate 1877c478bd9Sstevel@tonic-gate if (strequal(name, "boot-end")) { 1887c478bd9Sstevel@tonic-gate /* 1897c478bd9Sstevel@tonic-gate * The true end of boot should be scratchmemp, 1907c478bd9Sstevel@tonic-gate * boot gets its dynamic memory from the scratchmem 1917c478bd9Sstevel@tonic-gate * which is the first 4M of the physical memory, 1927c478bd9Sstevel@tonic-gate * and they are mapped 1:1. 1937c478bd9Sstevel@tonic-gate */ 1947c478bd9Sstevel@tonic-gate end_addr = scratchmemp; 1957c478bd9Sstevel@tonic-gate bcopy((char *)(&end_addr), buf, sizeof (scratchmemp)); 1967c478bd9Sstevel@tonic-gate return (BOOT_SUCCESS); 1977c478bd9Sstevel@tonic-gate } 1987c478bd9Sstevel@tonic-gate 1997c478bd9Sstevel@tonic-gate for (p = (struct bplist *)bprop_tab; p->name != (char *)0; p++) { 2007c478bd9Sstevel@tonic-gate 2017c478bd9Sstevel@tonic-gate /* gotta linked list? */ 2027c478bd9Sstevel@tonic-gate if ((strequal(name, "virt-avail") && strequal(name, p->name)) || 2037c478bd9Sstevel@tonic-gate (strequal(name, "phys-avail") && strequal(name, p->name)) || 2047c478bd9Sstevel@tonic-gate (strequal(name, "phys-installed") && 2057c478bd9Sstevel@tonic-gate strequal(name, p->name))) { 2067c478bd9Sstevel@tonic-gate 2077c478bd9Sstevel@tonic-gate u_longlong_t *t = buf; 2087c478bd9Sstevel@tonic-gate 2097c478bd9Sstevel@tonic-gate for (ml = *((struct memlist **)p->val); 2107c478bd9Sstevel@tonic-gate ml != NIL; 211*56f33205SJonathan Adams ml = ml->ml_next) { 2127c478bd9Sstevel@tonic-gate 2137c478bd9Sstevel@tonic-gate /* copy out into an array */ 214*56f33205SJonathan Adams *t++ = ml->ml_address; 215*56f33205SJonathan Adams *t++ = ml->ml_size; 2167c478bd9Sstevel@tonic-gate } 2177c478bd9Sstevel@tonic-gate return (BOOT_SUCCESS); 2187c478bd9Sstevel@tonic-gate } else if (strequal(name, p->name)) { 2197c478bd9Sstevel@tonic-gate if (p->size != 0) { 2207c478bd9Sstevel@tonic-gate bcopy(p->val, buf, p->size); 2217c478bd9Sstevel@tonic-gate } else { 2227c478bd9Sstevel@tonic-gate (void) strcpy((char *)buf, *((char **)p->val)); 2237c478bd9Sstevel@tonic-gate } 2247c478bd9Sstevel@tonic-gate return (BOOT_SUCCESS); 2257c478bd9Sstevel@tonic-gate } 2267c478bd9Sstevel@tonic-gate } 2277c478bd9Sstevel@tonic-gate return (BOOT_FAILURE); 2287c478bd9Sstevel@tonic-gate } 2297c478bd9Sstevel@tonic-gate 2307c478bd9Sstevel@tonic-gate /* 2317c478bd9Sstevel@tonic-gate * If the user wants the first property in the list, he passes in a 2327c478bd9Sstevel@tonic-gate * null string. The routine will always return a ptr to the name of the 2337c478bd9Sstevel@tonic-gate * next prop, except when there are no more props. In that case, it will 2347c478bd9Sstevel@tonic-gate * return a null string. 2357c478bd9Sstevel@tonic-gate */ 2367c478bd9Sstevel@tonic-gate 2377c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 2387c478bd9Sstevel@tonic-gate char * 2397c478bd9Sstevel@tonic-gate bnextprop(struct bootops *bop, char *prev) 2407c478bd9Sstevel@tonic-gate { 2417c478bd9Sstevel@tonic-gate struct bplist *p; 2427c478bd9Sstevel@tonic-gate 2437c478bd9Sstevel@tonic-gate /* user wants the firstprop */ 2447c478bd9Sstevel@tonic-gate if (*prev == 0) 2457c478bd9Sstevel@tonic-gate return (bprop_tab->name); 2467c478bd9Sstevel@tonic-gate 2477c478bd9Sstevel@tonic-gate for (p = (struct bplist *)bprop_tab; p->name != (char *)0; p++) { 2487c478bd9Sstevel@tonic-gate 2497c478bd9Sstevel@tonic-gate if (strequal(prev, p->name)) 2507c478bd9Sstevel@tonic-gate /* 2517c478bd9Sstevel@tonic-gate * if prev is the last valid prop, 2527c478bd9Sstevel@tonic-gate * we will return our terminator (0). 2537c478bd9Sstevel@tonic-gate */ 2547c478bd9Sstevel@tonic-gate return ((++p)->name); 2557c478bd9Sstevel@tonic-gate 2567c478bd9Sstevel@tonic-gate 2577c478bd9Sstevel@tonic-gate } 2587c478bd9Sstevel@tonic-gate return ((char *)0); 2597c478bd9Sstevel@tonic-gate } 260