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 2007 Sun Microsystems, Inc. All rights reserved. 23 * Use is subject to license terms. 24 */ 25 26 #pragma ident "%Z%%M% %I% %E% SMI" 27 28 #include <sys/types.h> 29 #include <sys/bootconf.h> 30 #include <sys/param.h> 31 #include <sys/obpdefs.h> 32 #include <sys/promif.h> 33 #include <sys/salib.h> 34 #include <sys/boot.h> 35 #include <stddef.h> 36 #include "boot_plat.h" 37 38 #ifdef DEBUG 39 extern int debug; 40 #else 41 static const int debug = 0; 42 #endif 43 44 #define dprintf if (debug) printf 45 46 extern void closeall(int); 47 48 struct bootops bootops; 49 50 static void 51 boot_fail(void) 52 { 53 prom_panic("bootops is gone, it should not be called"); 54 } 55 56 void 57 setup_bootops(void) 58 { 59 bootops.bsys_version = BO_VERSION; 60 bootops.bsys_1275_call = (uint64_t)boot_fail; 61 bootops.bsys_printf = (uint32_t)boot_fail; 62 63 if (!memlistpage) /* paranoia runs rampant */ 64 prom_panic("\nMemlistpage not setup yet."); 65 /* 66 * The memory list should always be updated last. The prom 67 * calls which are made to update a memory list may have the 68 * undesirable affect of claiming physical memory. This may 69 * happen after the kernel has created its page free list. 70 * The kernel deals with this by comparing the n and n-1 71 * snapshots of memory. Updating the memory available list 72 * last guarantees we will have a current, accurate snapshot. 73 * See bug #1260786. 74 */ 75 update_memlist("virtual-memory", "available", &vfreelistp); 76 update_memlist("memory", "available", &pfreelistp); 77 78 dprintf("\nPhysinstalled: "); 79 if (debug) print_memlist(pinstalledp); 80 dprintf("\nPhysfree: "); 81 if (debug) print_memlist(pfreelistp); 82 dprintf("\nVirtfree: "); 83 if (debug) print_memlist(vfreelistp); 84 } 85 86 void 87 install_memlistptrs(void) 88 { 89 90 /* prob only need 1 page for now */ 91 memlistextent = tablep - memlistpage; 92 93 dprintf("physinstalled = %p\n", (void *)pinstalledp); 94 dprintf("physavail = %p\n", (void *)pfreelistp); 95 dprintf("virtavail = %p\n", (void *)vfreelistp); 96 dprintf("extent = 0x%lx\n", memlistextent); 97 } 98 99 /* 100 * A word of explanation is in order. 101 * This routine is meant to be called during 102 * boot_release(), when the kernel is trying 103 * to ascertain the current state of memory 104 * so that it can use a memlist to walk itself 105 * thru kvm_init(). 106 */ 107 108 void 109 update_memlist(char *name, char *prop, struct memlist **list) 110 { 111 /* Just take another prom snapshot */ 112 *list = fill_memlists(name, prop, *list); 113 install_memlistptrs(); 114 } 115 116 /* 117 * This routine is meant to be called by the 118 * kernel to shut down all boot and prom activity. 119 * After this routine is called, PROM or boot IO is no 120 * longer possible, nor is memory allocation. 121 */ 122 void 123 kern_killboot(void) 124 { 125 if (verbosemode) { 126 dprintf("Entering boot_release()\n"); 127 dprintf("\nPhysinstalled: "); 128 if (debug) print_memlist(pinstalledp); 129 dprintf("\nPhysfree: "); 130 if (debug) print_memlist(pfreelistp); 131 dprintf("\nVirtfree: "); 132 if (debug) print_memlist(vfreelistp); 133 } 134 if (debug) { 135 dprintf("Calling quiesce_io()\n"); 136 prom_enter_mon(); 137 } 138 139 /* close all open devices */ 140 closeall(1); 141 142 /* 143 * Now we take YAPS (yet another Prom snapshot) of 144 * memory, just for safety sake. 145 * 146 * The memory list should always be updated last. The prom 147 * calls which are made to update a memory list may have the 148 * undesirable affect of claiming physical memory. This may 149 * happen after the kernel has created its page free list. 150 * The kernel deals with this by comparing the n and n-1 151 * snapshots of memory. Updating the memory available list 152 * last guarantees we will have a current, accurate snapshot. 153 * See bug #1260786. 154 */ 155 update_memlist("virtual-memory", "available", &vfreelistp); 156 update_memlist("memory", "available", &pfreelistp); 157 158 if (verbosemode) { 159 dprintf("physinstalled = %p\n", (void *)pinstalledp); 160 dprintf("physavail = %p\n", (void *)pfreelistp); 161 dprintf("virtavail = %p\n", (void *)vfreelistp); 162 dprintf("extent = 0x%lx\n", memlistextent); 163 dprintf("Leaving boot_release()\n"); 164 165 dprintf("Physinstalled: \n"); 166 if (debug) 167 print_memlist(pinstalledp); 168 169 dprintf("Physfree:\n"); 170 if (debug) 171 print_memlist(pfreelistp); 172 173 dprintf("Virtfree: \n"); 174 if (debug) 175 print_memlist(vfreelistp); 176 } 177 178 #ifdef DEBUG_MMU 179 dump_mmu(); 180 prom_enter_mon(); 181 #endif 182 } 183