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
5986fd29aSsetje * Common Development and Distribution License (the "License").
6986fd29aSsetje * 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 /*
22986fd29aSsetje * Copyright 2007 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/bootconf.h>
287c478bd9Sstevel@tonic-gate #include <sys/param.h>
297c478bd9Sstevel@tonic-gate #include <sys/obpdefs.h>
307c478bd9Sstevel@tonic-gate #include <sys/promif.h>
317c478bd9Sstevel@tonic-gate #include <sys/salib.h>
327c478bd9Sstevel@tonic-gate #include <sys/boot.h>
337c478bd9Sstevel@tonic-gate #include <stddef.h>
347c478bd9Sstevel@tonic-gate #include "boot_plat.h"
357c478bd9Sstevel@tonic-gate
367c478bd9Sstevel@tonic-gate #ifdef DEBUG
377c478bd9Sstevel@tonic-gate extern int debug;
387c478bd9Sstevel@tonic-gate #else
397c478bd9Sstevel@tonic-gate static const int debug = 0;
407c478bd9Sstevel@tonic-gate #endif
417c478bd9Sstevel@tonic-gate
427c478bd9Sstevel@tonic-gate #define dprintf if (debug) printf
437c478bd9Sstevel@tonic-gate
447c478bd9Sstevel@tonic-gate extern void closeall(int);
457c478bd9Sstevel@tonic-gate
467c478bd9Sstevel@tonic-gate struct bootops bootops;
477c478bd9Sstevel@tonic-gate
48986fd29aSsetje static void
boot_fail(void)49986fd29aSsetje boot_fail(void)
50986fd29aSsetje {
51986fd29aSsetje prom_panic("bootops is gone, it should not be called");
52986fd29aSsetje }
53986fd29aSsetje
547c478bd9Sstevel@tonic-gate void
setup_bootops(void)557c478bd9Sstevel@tonic-gate setup_bootops(void)
567c478bd9Sstevel@tonic-gate {
57986fd29aSsetje bootops.bsys_version = BO_VERSION;
58986fd29aSsetje bootops.bsys_1275_call = (uint64_t)boot_fail;
59*e0731422SRichard Lowe bootops.bsys_printf = (uint32_t)(uintptr_t)boot_fail;
607c478bd9Sstevel@tonic-gate
617c478bd9Sstevel@tonic-gate if (!memlistpage) /* paranoia runs rampant */
627c478bd9Sstevel@tonic-gate prom_panic("\nMemlistpage not setup yet.");
637c478bd9Sstevel@tonic-gate /*
647c478bd9Sstevel@tonic-gate * The memory list should always be updated last. The prom
657c478bd9Sstevel@tonic-gate * calls which are made to update a memory list may have the
667c478bd9Sstevel@tonic-gate * undesirable affect of claiming physical memory. This may
677c478bd9Sstevel@tonic-gate * happen after the kernel has created its page free list.
687c478bd9Sstevel@tonic-gate * The kernel deals with this by comparing the n and n-1
697c478bd9Sstevel@tonic-gate * snapshots of memory. Updating the memory available list
707c478bd9Sstevel@tonic-gate * last guarantees we will have a current, accurate snapshot.
717c478bd9Sstevel@tonic-gate * See bug #1260786.
727c478bd9Sstevel@tonic-gate */
737c478bd9Sstevel@tonic-gate update_memlist("virtual-memory", "available", &vfreelistp);
747c478bd9Sstevel@tonic-gate update_memlist("memory", "available", &pfreelistp);
757c478bd9Sstevel@tonic-gate
767c478bd9Sstevel@tonic-gate dprintf("\nPhysinstalled: ");
777c478bd9Sstevel@tonic-gate if (debug) print_memlist(pinstalledp);
787c478bd9Sstevel@tonic-gate dprintf("\nPhysfree: ");
797c478bd9Sstevel@tonic-gate if (debug) print_memlist(pfreelistp);
807c478bd9Sstevel@tonic-gate dprintf("\nVirtfree: ");
817c478bd9Sstevel@tonic-gate if (debug) print_memlist(vfreelistp);
827c478bd9Sstevel@tonic-gate }
837c478bd9Sstevel@tonic-gate
847c478bd9Sstevel@tonic-gate void
install_memlistptrs(void)857c478bd9Sstevel@tonic-gate install_memlistptrs(void)
867c478bd9Sstevel@tonic-gate {
877c478bd9Sstevel@tonic-gate
887c478bd9Sstevel@tonic-gate /* prob only need 1 page for now */
897c478bd9Sstevel@tonic-gate memlistextent = tablep - memlistpage;
907c478bd9Sstevel@tonic-gate
917c478bd9Sstevel@tonic-gate dprintf("physinstalled = %p\n", (void *)pinstalledp);
927c478bd9Sstevel@tonic-gate dprintf("physavail = %p\n", (void *)pfreelistp);
937c478bd9Sstevel@tonic-gate dprintf("virtavail = %p\n", (void *)vfreelistp);
947c478bd9Sstevel@tonic-gate dprintf("extent = 0x%lx\n", memlistextent);
957c478bd9Sstevel@tonic-gate }
967c478bd9Sstevel@tonic-gate
977c478bd9Sstevel@tonic-gate /*
987c478bd9Sstevel@tonic-gate * A word of explanation is in order.
997c478bd9Sstevel@tonic-gate * This routine is meant to be called during
1007c478bd9Sstevel@tonic-gate * boot_release(), when the kernel is trying
1017c478bd9Sstevel@tonic-gate * to ascertain the current state of memory
1027c478bd9Sstevel@tonic-gate * so that it can use a memlist to walk itself
1037c478bd9Sstevel@tonic-gate * thru kvm_init().
1047c478bd9Sstevel@tonic-gate */
1057c478bd9Sstevel@tonic-gate
1067c478bd9Sstevel@tonic-gate void
update_memlist(char * name,char * prop,struct memlist ** list)1077c478bd9Sstevel@tonic-gate update_memlist(char *name, char *prop, struct memlist **list)
1087c478bd9Sstevel@tonic-gate {
1097c478bd9Sstevel@tonic-gate /* Just take another prom snapshot */
1107c478bd9Sstevel@tonic-gate *list = fill_memlists(name, prop, *list);
1117c478bd9Sstevel@tonic-gate install_memlistptrs();
1127c478bd9Sstevel@tonic-gate }
1137c478bd9Sstevel@tonic-gate
1147c478bd9Sstevel@tonic-gate /*
1157c478bd9Sstevel@tonic-gate * This routine is meant to be called by the
1167c478bd9Sstevel@tonic-gate * kernel to shut down all boot and prom activity.
1177c478bd9Sstevel@tonic-gate * After this routine is called, PROM or boot IO is no
1187c478bd9Sstevel@tonic-gate * longer possible, nor is memory allocation.
1197c478bd9Sstevel@tonic-gate */
1207c478bd9Sstevel@tonic-gate void
kern_killboot(void)1217c478bd9Sstevel@tonic-gate kern_killboot(void)
1227c478bd9Sstevel@tonic-gate {
1237c478bd9Sstevel@tonic-gate if (verbosemode) {
1247c478bd9Sstevel@tonic-gate dprintf("Entering boot_release()\n");
1257c478bd9Sstevel@tonic-gate dprintf("\nPhysinstalled: ");
1267c478bd9Sstevel@tonic-gate if (debug) print_memlist(pinstalledp);
1277c478bd9Sstevel@tonic-gate dprintf("\nPhysfree: ");
1287c478bd9Sstevel@tonic-gate if (debug) print_memlist(pfreelistp);
1297c478bd9Sstevel@tonic-gate dprintf("\nVirtfree: ");
1307c478bd9Sstevel@tonic-gate if (debug) print_memlist(vfreelistp);
1317c478bd9Sstevel@tonic-gate }
1327c478bd9Sstevel@tonic-gate if (debug) {
1337c478bd9Sstevel@tonic-gate dprintf("Calling quiesce_io()\n");
1347c478bd9Sstevel@tonic-gate prom_enter_mon();
1357c478bd9Sstevel@tonic-gate }
1367c478bd9Sstevel@tonic-gate
1377c478bd9Sstevel@tonic-gate /* close all open devices */
1387c478bd9Sstevel@tonic-gate closeall(1);
1397c478bd9Sstevel@tonic-gate
1407c478bd9Sstevel@tonic-gate /*
1417c478bd9Sstevel@tonic-gate * Now we take YAPS (yet another Prom snapshot) of
1427c478bd9Sstevel@tonic-gate * memory, just for safety sake.
1437c478bd9Sstevel@tonic-gate *
1447c478bd9Sstevel@tonic-gate * The memory list should always be updated last. The prom
1457c478bd9Sstevel@tonic-gate * calls which are made to update a memory list may have the
1467c478bd9Sstevel@tonic-gate * undesirable affect of claiming physical memory. This may
1477c478bd9Sstevel@tonic-gate * happen after the kernel has created its page free list.
1487c478bd9Sstevel@tonic-gate * The kernel deals with this by comparing the n and n-1
1497c478bd9Sstevel@tonic-gate * snapshots of memory. Updating the memory available list
1507c478bd9Sstevel@tonic-gate * last guarantees we will have a current, accurate snapshot.
1517c478bd9Sstevel@tonic-gate * See bug #1260786.
1527c478bd9Sstevel@tonic-gate */
1537c478bd9Sstevel@tonic-gate update_memlist("virtual-memory", "available", &vfreelistp);
1547c478bd9Sstevel@tonic-gate update_memlist("memory", "available", &pfreelistp);
1557c478bd9Sstevel@tonic-gate
1567c478bd9Sstevel@tonic-gate if (verbosemode) {
1577c478bd9Sstevel@tonic-gate dprintf("physinstalled = %p\n", (void *)pinstalledp);
1587c478bd9Sstevel@tonic-gate dprintf("physavail = %p\n", (void *)pfreelistp);
1597c478bd9Sstevel@tonic-gate dprintf("virtavail = %p\n", (void *)vfreelistp);
1607c478bd9Sstevel@tonic-gate dprintf("extent = 0x%lx\n", memlistextent);
1617c478bd9Sstevel@tonic-gate dprintf("Leaving boot_release()\n");
1627c478bd9Sstevel@tonic-gate
1637c478bd9Sstevel@tonic-gate dprintf("Physinstalled: \n");
1647c478bd9Sstevel@tonic-gate if (debug)
1657c478bd9Sstevel@tonic-gate print_memlist(pinstalledp);
1667c478bd9Sstevel@tonic-gate
1677c478bd9Sstevel@tonic-gate dprintf("Physfree:\n");
1687c478bd9Sstevel@tonic-gate if (debug)
1697c478bd9Sstevel@tonic-gate print_memlist(pfreelistp);
1707c478bd9Sstevel@tonic-gate
1717c478bd9Sstevel@tonic-gate dprintf("Virtfree: \n");
1727c478bd9Sstevel@tonic-gate if (debug)
1737c478bd9Sstevel@tonic-gate print_memlist(vfreelistp);
1747c478bd9Sstevel@tonic-gate }
1757c478bd9Sstevel@tonic-gate
1767c478bd9Sstevel@tonic-gate #ifdef DEBUG_MMU
1777c478bd9Sstevel@tonic-gate dump_mmu();
1787c478bd9Sstevel@tonic-gate prom_enter_mon();
1797c478bd9Sstevel@tonic-gate #endif
1807c478bd9Sstevel@tonic-gate }
181