xref: /onnv-gate/usr/src/psm/stand/boot/sparc/common/bootops.c (revision 5648:161f8007cab9)
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
5*5648Ssetje  * Common Development and Distribution License (the "License").
6*5648Ssetje  * 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*5648Ssetje  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
270Sstevel@tonic-gate 
280Sstevel@tonic-gate #include <sys/types.h>
290Sstevel@tonic-gate #include <sys/bootconf.h>
300Sstevel@tonic-gate #include <sys/param.h>
310Sstevel@tonic-gate #include <sys/obpdefs.h>
320Sstevel@tonic-gate #include <sys/promif.h>
330Sstevel@tonic-gate #include <sys/salib.h>
340Sstevel@tonic-gate #include <sys/boot.h>
350Sstevel@tonic-gate #include <stddef.h>
360Sstevel@tonic-gate #include "boot_plat.h"
370Sstevel@tonic-gate 
380Sstevel@tonic-gate #ifdef DEBUG
390Sstevel@tonic-gate extern int debug;
400Sstevel@tonic-gate #else
410Sstevel@tonic-gate static const int debug = 0;
420Sstevel@tonic-gate #endif
430Sstevel@tonic-gate 
440Sstevel@tonic-gate #define	dprintf		if (debug) printf
450Sstevel@tonic-gate 
460Sstevel@tonic-gate extern void	closeall(int);
470Sstevel@tonic-gate 
48*5648Ssetje struct bootops bootops;
490Sstevel@tonic-gate 
50*5648Ssetje static void
boot_fail(void)51*5648Ssetje boot_fail(void)
52*5648Ssetje {
53*5648Ssetje 	prom_panic("bootops is gone, it should not be called");
54*5648Ssetje }
550Sstevel@tonic-gate 
560Sstevel@tonic-gate void
setup_bootops(void)570Sstevel@tonic-gate setup_bootops(void)
580Sstevel@tonic-gate {
59*5648Ssetje 	bootops.bsys_version = BO_VERSION;
60*5648Ssetje 	bootops.bsys_1275_call = (uint64_t)boot_fail;
61*5648Ssetje 	bootops.bsys_printf = (uint32_t)boot_fail;
620Sstevel@tonic-gate 
630Sstevel@tonic-gate 	if (!memlistpage) /* paranoia runs rampant */
640Sstevel@tonic-gate 		prom_panic("\nMemlistpage not setup yet.");
650Sstevel@tonic-gate 	/*
660Sstevel@tonic-gate 	 * The memory list should always be updated last.  The prom
670Sstevel@tonic-gate 	 * calls which are made to update a memory list may have the
680Sstevel@tonic-gate 	 * undesirable affect of claiming physical memory.  This may
690Sstevel@tonic-gate 	 * happen after the kernel has created its page free list.
700Sstevel@tonic-gate 	 * The kernel deals with this by comparing the n and n-1
710Sstevel@tonic-gate 	 * snapshots of memory.  Updating the memory available list
720Sstevel@tonic-gate 	 * last guarantees we will have a current, accurate snapshot.
730Sstevel@tonic-gate 	 * See bug #1260786.
740Sstevel@tonic-gate 	 */
750Sstevel@tonic-gate 	update_memlist("virtual-memory", "available", &vfreelistp);
760Sstevel@tonic-gate 	update_memlist("memory", "available", &pfreelistp);
770Sstevel@tonic-gate 
780Sstevel@tonic-gate 	dprintf("\nPhysinstalled: ");
790Sstevel@tonic-gate 	if (debug) print_memlist(pinstalledp);
800Sstevel@tonic-gate 	dprintf("\nPhysfree: ");
810Sstevel@tonic-gate 	if (debug) print_memlist(pfreelistp);
820Sstevel@tonic-gate 	dprintf("\nVirtfree: ");
830Sstevel@tonic-gate 	if (debug) print_memlist(vfreelistp);
840Sstevel@tonic-gate }
850Sstevel@tonic-gate 
860Sstevel@tonic-gate void
install_memlistptrs(void)870Sstevel@tonic-gate install_memlistptrs(void)
880Sstevel@tonic-gate {
890Sstevel@tonic-gate 
900Sstevel@tonic-gate 	/* prob only need 1 page for now */
910Sstevel@tonic-gate 	memlistextent = tablep - memlistpage;
920Sstevel@tonic-gate 
930Sstevel@tonic-gate 	dprintf("physinstalled = %p\n", (void *)pinstalledp);
940Sstevel@tonic-gate 	dprintf("physavail = %p\n", (void *)pfreelistp);
950Sstevel@tonic-gate 	dprintf("virtavail = %p\n", (void *)vfreelistp);
960Sstevel@tonic-gate 	dprintf("extent = 0x%lx\n", memlistextent);
970Sstevel@tonic-gate }
980Sstevel@tonic-gate 
990Sstevel@tonic-gate /*
1000Sstevel@tonic-gate  *      A word of explanation is in order.
1010Sstevel@tonic-gate  *      This routine is meant to be called during
1020Sstevel@tonic-gate  *      boot_release(), when the kernel is trying
1030Sstevel@tonic-gate  *      to ascertain the current state of memory
1040Sstevel@tonic-gate  *      so that it can use a memlist to walk itself
1050Sstevel@tonic-gate  *      thru kvm_init().
1060Sstevel@tonic-gate  */
1070Sstevel@tonic-gate 
1080Sstevel@tonic-gate void
update_memlist(char * name,char * prop,struct memlist ** list)1090Sstevel@tonic-gate update_memlist(char *name, char *prop, struct memlist **list)
1100Sstevel@tonic-gate {
1110Sstevel@tonic-gate 	/* Just take another prom snapshot */
1120Sstevel@tonic-gate 	*list = fill_memlists(name, prop, *list);
1130Sstevel@tonic-gate 	install_memlistptrs();
1140Sstevel@tonic-gate }
1150Sstevel@tonic-gate 
1160Sstevel@tonic-gate /*
1170Sstevel@tonic-gate  *  This routine is meant to be called by the
1180Sstevel@tonic-gate  *  kernel to shut down all boot and prom activity.
1190Sstevel@tonic-gate  *  After this routine is called, PROM or boot IO is no
1200Sstevel@tonic-gate  *  longer possible, nor is memory allocation.
1210Sstevel@tonic-gate  */
1220Sstevel@tonic-gate void
kern_killboot(void)1230Sstevel@tonic-gate kern_killboot(void)
1240Sstevel@tonic-gate {
1250Sstevel@tonic-gate 	if (verbosemode) {
1260Sstevel@tonic-gate 		dprintf("Entering boot_release()\n");
1270Sstevel@tonic-gate 		dprintf("\nPhysinstalled: ");
1280Sstevel@tonic-gate 		if (debug) print_memlist(pinstalledp);
1290Sstevel@tonic-gate 		dprintf("\nPhysfree: ");
1300Sstevel@tonic-gate 		if (debug) print_memlist(pfreelistp);
1310Sstevel@tonic-gate 		dprintf("\nVirtfree: ");
1320Sstevel@tonic-gate 		if (debug) print_memlist(vfreelistp);
1330Sstevel@tonic-gate 	}
1340Sstevel@tonic-gate 	if (debug) {
1350Sstevel@tonic-gate 		dprintf("Calling quiesce_io()\n");
1360Sstevel@tonic-gate 		prom_enter_mon();
1370Sstevel@tonic-gate 	}
1380Sstevel@tonic-gate 
1390Sstevel@tonic-gate 	/* close all open devices */
1400Sstevel@tonic-gate 	closeall(1);
1410Sstevel@tonic-gate 
1420Sstevel@tonic-gate 	/*
1430Sstevel@tonic-gate 	 *  Now we take YAPS (yet another Prom snapshot) of
1440Sstevel@tonic-gate 	 *  memory, just for safety sake.
1450Sstevel@tonic-gate 	 *
1460Sstevel@tonic-gate 	 * The memory list should always be updated last.  The prom
1470Sstevel@tonic-gate 	 * calls which are made to update a memory list may have the
1480Sstevel@tonic-gate 	 * undesirable affect of claiming physical memory.  This may
1490Sstevel@tonic-gate 	 * happen after the kernel has created its page free list.
1500Sstevel@tonic-gate 	 * The kernel deals with this by comparing the n and n-1
1510Sstevel@tonic-gate 	 * snapshots of memory.  Updating the memory available list
1520Sstevel@tonic-gate 	 * last guarantees we will have a current, accurate snapshot.
1530Sstevel@tonic-gate 	 * See bug #1260786.
1540Sstevel@tonic-gate 	 */
1550Sstevel@tonic-gate 	update_memlist("virtual-memory", "available", &vfreelistp);
1560Sstevel@tonic-gate 	update_memlist("memory", "available", &pfreelistp);
1570Sstevel@tonic-gate 
1580Sstevel@tonic-gate 	if (verbosemode) {
1590Sstevel@tonic-gate 		dprintf("physinstalled = %p\n", (void *)pinstalledp);
1600Sstevel@tonic-gate 		dprintf("physavail = %p\n", (void *)pfreelistp);
1610Sstevel@tonic-gate 		dprintf("virtavail = %p\n", (void *)vfreelistp);
1620Sstevel@tonic-gate 		dprintf("extent = 0x%lx\n", memlistextent);
1630Sstevel@tonic-gate 		dprintf("Leaving boot_release()\n");
1640Sstevel@tonic-gate 
1650Sstevel@tonic-gate 		dprintf("Physinstalled: \n");
1660Sstevel@tonic-gate 		if (debug)
1670Sstevel@tonic-gate 			print_memlist(pinstalledp);
1680Sstevel@tonic-gate 
1690Sstevel@tonic-gate 		dprintf("Physfree:\n");
1700Sstevel@tonic-gate 		if (debug)
1710Sstevel@tonic-gate 			print_memlist(pfreelistp);
1720Sstevel@tonic-gate 
1730Sstevel@tonic-gate 		dprintf("Virtfree: \n");
1740Sstevel@tonic-gate 		if (debug)
1750Sstevel@tonic-gate 			print_memlist(vfreelistp);
1760Sstevel@tonic-gate 	}
1770Sstevel@tonic-gate 
1780Sstevel@tonic-gate #ifdef DEBUG_MMU
1790Sstevel@tonic-gate 	dump_mmu();
1800Sstevel@tonic-gate 	prom_enter_mon();
1810Sstevel@tonic-gate #endif
1820Sstevel@tonic-gate }
183