Annotation of sys/arch/mac68k/mac68k/pmap_bootstrap.c, Revision 1.1
1.1 ! nbrk 1: /* $OpenBSD: pmap_bootstrap.c,v 1.38 2006/07/06 17:49:45 miod Exp $ */
! 2: /* $NetBSD: pmap_bootstrap.c,v 1.50 1999/04/07 06:14:33 scottr Exp $ */
! 3:
! 4: /*
! 5: * Copyright (c) 1991, 1993
! 6: * The Regents of the University of California. All rights reserved.
! 7: *
! 8: * This code is derived from software contributed to Berkeley by
! 9: * the Systems Programming Group of the University of Utah Computer
! 10: * Science Department.
! 11: *
! 12: * Redistribution and use in source and binary forms, with or without
! 13: * modification, are permitted provided that the following conditions
! 14: * are met:
! 15: * 1. Redistributions of source code must retain the above copyright
! 16: * notice, this list of conditions and the following disclaimer.
! 17: * 2. Redistributions in binary form must reproduce the above copyright
! 18: * notice, this list of conditions and the following disclaimer in the
! 19: * documentation and/or other materials provided with the distribution.
! 20: * 3. Neither the name of the University nor the names of its contributors
! 21: * may be used to endorse or promote products derived from this software
! 22: * without specific prior written permission.
! 23: *
! 24: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
! 25: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
! 26: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
! 27: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
! 28: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
! 29: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
! 30: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
! 31: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
! 32: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
! 33: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
! 34: * SUCH DAMAGE.
! 35: *
! 36: * @(#)pmap_bootstrap.c 8.1 (Berkeley) 6/10/93
! 37: */
! 38:
! 39: #include <sys/param.h>
! 40: #include <sys/msgbuf.h>
! 41: #include <sys/reboot.h>
! 42: #include <sys/systm.h>
! 43:
! 44: #include <uvm/uvm_extern.h>
! 45: #include <uvm/uvm_pmap.h>
! 46:
! 47: #include <machine/autoconf.h>
! 48: #include <machine/cpu.h>
! 49: #include <machine/frame.h>
! 50: #include <machine/pmap.h>
! 51: #include <machine/pte.h>
! 52: #include <machine/vmparam.h>
! 53:
! 54: #include <ufs/mfs/mfs_extern.h>
! 55:
! 56: #include "zsc.h"
! 57:
! 58: #if NZSC > 0
! 59: extern int zsinited;
! 60: #endif
! 61:
! 62: /*
! 63: * These are used to map the RAM:
! 64: */
! 65: int numranges; /* = 0 == don't use the ranges */
! 66: u_long low[8];
! 67: u_long high[8];
! 68: u_long maxaddr; /* PA of the last physical page */
! 69: int vidlen;
! 70: #define VIDMAPSIZE btoc(vidlen)
! 71: extern u_int32_t mac68k_vidphys;
! 72: extern u_int32_t videoaddr;
! 73: extern u_int32_t videorowbytes;
! 74: extern u_int32_t videosize;
! 75: static u_int32_t newvideoaddr;
! 76:
! 77: void bootstrap_mac68k(int);
! 78:
! 79: /*
! 80: * pmap_bootstrap() is very tricky on mac68k because it can be called
! 81: * with the MMU either on or off. If it's on, we assume that it's mapped
! 82: * with the same PA <=> LA mapping that we eventually want.
! 83: * The page sizes and the protections will be wrong, anyway.
! 84: *
! 85: * nextpa is the first address following the loaded kernel. On a IIsi
! 86: * on 12 May 1996, that was 0xf9000 beyond firstpa.
! 87: */
! 88:
! 89: #define RELOC(v, t) *((t*)((u_int)&(v)))
! 90: #define PA2VA(v, t) *((t*)((u_int)&(v) - firstpa))
! 91:
! 92: /*
! 93: * Present a totally tricky view of the world here...
! 94: * - count video mappings in the internal IO space (which will
! 95: * require some contortion later on)
! 96: * - no external IO space
! 97: */
! 98: #define MACHINE_IIOMAPSIZE (IIOMAPSIZE + VIDMAPSIZE)
! 99: #define MACHINE_INTIOBASE IOBase
! 100: #define MACHINE_EIOMAPSIZE 0
! 101:
! 102: /* vidpa internal video space for some machines
! 103: * PT pages VIDMAPSIZE pages
! 104: *
! 105: * XXX note that VIDMAPSIZE, hence vidlen, is needed very early
! 106: * in pmap_bootstrap(), so slightly abuse the purpose of
! 107: * PMAP_MD_LOCALS here...
! 108: */
! 109: #define PMAP_MD_LOCALS \
! 110: paddr_t vidpa; \
! 111: paddr_t avail_next; \
! 112: int avail_remaining; \
! 113: int avail_range; \
! 114: int i; \
! 115: \
! 116: vidlen = round_page(((videosize >> 16) & 0xffff) * videorowbytes + \
! 117: m68k_page_offset(mac68k_vidphys));
! 118:
! 119: #define PMAP_MD_RELOC1() \
! 120: do { \
! 121: vidpa = eiopa - VIDMAPSIZE * sizeof(pt_entry_t); \
! 122: } while (0)
! 123:
! 124: /*
! 125: * Validate the internal IO space, ROM space, and
! 126: * framebuffer PTEs (RW+CI).
! 127: *
! 128: * Note that this is done after the fake IIO space has been
! 129: * validated, hence the rom and video pte were already written to
! 130: * with incorrect values.
! 131: */
! 132: #define PMAP_MD_MAPIOSPACE() \
! 133: do { \
! 134: if (vidlen != 0) { \
! 135: pte = PA2VA(vidpa, u_int *); \
! 136: epte = pte + VIDMAPSIZE; \
! 137: protopte = trunc_page(mac68k_vidphys) | \
! 138: PG_RW | PG_V | PG_CI; \
! 139: while (pte < epte) { \
! 140: *pte++ = protopte; \
! 141: protopte += NBPG; \
! 142: } \
! 143: } \
! 144: } while (0)
! 145:
! 146: #define PMAP_MD_RELOC2() \
! 147: do { \
! 148: IOBase = iiobase; \
! 149: if (vidlen != 0) { \
! 150: newvideoaddr = iiobase + ptoa(IIOMAPSIZE) \
! 151: + m68k_page_offset(mac68k_vidphys); \
! 152: } \
! 153: } while (0)
! 154:
! 155: /*
! 156: * If the MMU was disabled, compute available memory size from the memory
! 157: * segment information.
! 158: */
! 159: #define PMAP_MD_MEMSIZE() \
! 160: do { \
! 161: avail_next = avail_start; \
! 162: avail_remaining = 0; \
! 163: avail_range = -1; \
! 164: for (i = 0; i < numranges; i++) { \
! 165: if (low[i] <= avail_next && avail_next < high[i]) { \
! 166: avail_range = i; \
! 167: avail_remaining = high[i] - avail_next; \
! 168: } else if (avail_range != -1) { \
! 169: avail_remaining += (high[i] - low[i]); \
! 170: } \
! 171: } \
! 172: physmem = atop(avail_remaining + nextpa - firstpa); \
! 173: \
! 174: maxaddr = high[numranges - 1] - ptoa(1); \
! 175: high[numranges - 1] -= \
! 176: (round_page(MSGBUFSIZE) + ptoa(1)); \
! 177: avail_end = high[numranges - 1]; \
! 178: } while (0)
! 179:
! 180: #define PMAP_MD_RELOC3() /* nothing */
! 181:
! 182: #include <m68k/m68k/pmap_bootstrap.c>
! 183:
! 184: void
! 185: bootstrap_mac68k(tc)
! 186: int tc;
! 187: {
! 188: #if NZSC > 0
! 189: extern void zs_init(void);
! 190: #endif
! 191: extern caddr_t esym;
! 192: paddr_t nextpa;
! 193:
! 194: if (mac68k_machine.do_graybars)
! 195: printf("Bootstrapping OpenBSD/mac68k.\n");
! 196:
! 197: mac68k_vidphys = videoaddr;
! 198:
! 199: if (((tc & 0x80000000) && (mmutype == MMU_68030)) ||
! 200: ((tc & 0x8000) && (mmutype == MMU_68040))) {
! 201:
! 202: if (mac68k_machine.do_graybars)
! 203: printf("Getting mapping from MMU.\n");
! 204: (void) get_mapping();
! 205: if (mac68k_machine.do_graybars)
! 206: printf("Done.\n");
! 207: } else {
! 208: /* MMU not enabled. Fake up ranges. */
! 209: numranges = 1;
! 210: low[0] = 0;
! 211: high[0] = mac68k_machine.mach_memsize * (1024 * 1024);
! 212: if (mac68k_machine.do_graybars)
! 213: printf("Faked range to byte 0x%lx.\n", high[0]);
! 214: }
! 215: nextpa = load_addr + round_page((vaddr_t)esym);
! 216:
! 217: if (mac68k_machine.do_graybars)
! 218: printf("Bootstrapping the pmap system.\n");
! 219:
! 220: pmap_bootstrap(nextpa, load_addr);
! 221:
! 222: if (mac68k_machine.do_graybars)
! 223: printf("Pmap bootstrapped.\n");
! 224:
! 225: if (!vidlen)
! 226: panic("Don't know how to relocate video!");
! 227:
! 228: if (mac68k_machine.do_graybars)
! 229: printf("Video address 0x%lx -> 0x%lx.\n",
! 230: (unsigned long)videoaddr, (unsigned long)newvideoaddr);
! 231:
! 232: mac68k_set_io_offsets(IOBase);
! 233:
! 234: /*
! 235: * If the serial ports are going (for console or 'echo'), then
! 236: * we need to make sure the IO change gets propagated properly.
! 237: * This resets the base addresses for the 8530 (serial) driver.
! 238: *
! 239: * WARNING!!! No printfs() (etc) BETWEEN zs_init() and the end
! 240: * of this function (where we start using the MMU, so the new
! 241: * address is correct).
! 242: */
! 243: #if NZSC > 0
! 244: if (zsinited != 0)
! 245: zs_init();
! 246: #endif
! 247:
! 248: videoaddr = newvideoaddr;
! 249: }
! 250:
! 251: void
! 252: pmap_init_md()
! 253: {
! 254: vaddr_t addr;
! 255:
! 256: /*
! 257: * Mark as unavailable the regions which we have mapped in
! 258: * pmap_bootstrap().
! 259: */
! 260: addr = (vaddr_t)MACHINE_INTIOBASE;
! 261: if (uvm_map(kernel_map, &addr,
! 262: ptoa(MACHINE_IIOMAPSIZE),
! 263: NULL, UVM_UNKNOWN_OFFSET, 0,
! 264: UVM_MAPFLAG(UVM_PROT_NONE, UVM_PROT_NONE,
! 265: UVM_INH_NONE, UVM_ADV_RANDOM,
! 266: UVM_FLAG_FIXED)))
! 267: panic("pmap_init: bogons in the VM system!");
! 268: }
CVSweb