1 /* $NetBSD: pmap_bootstrap.c,v 1.2 2008/04/28 20:23:12 martin Exp $ */ 2 3 /*- 4 * Copyright (c) 1999 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Jason R. Thorpe. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32 /* 33 * Copyright (c) 1991 Regents of the University of California. 34 * All rights reserved. 35 * 36 * This code is derived from software contributed to Berkeley by 37 * the Systems Programming Group of the University of Utah Computer 38 * Science Department. 39 * 40 * Redistribution and use in source and binary forms, with or without 41 * modification, are permitted provided that the following conditions 42 * are met: 43 * 1. Redistributions of source code must retain the above copyright 44 * notice, this list of conditions and the following disclaimer. 45 * 2. Redistributions in binary form must reproduce the above copyright 46 * notice, this list of conditions and the following disclaimer in the 47 * documentation and/or other materials provided with the distribution. 48 * 3. Neither the name of the University nor the names of its contributors 49 * may be used to endorse or promote products derived from this software 50 * without specific prior written permission. 51 * 52 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 53 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 54 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 55 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 56 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 57 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 58 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 59 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 60 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 61 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 62 * SUCH DAMAGE. 63 * 64 * @(#)pmap.c 7.5 (Berkeley) 5/10/91 65 */ 66 67 #include <sys/cdefs.h> 68 __KERNEL_RCSID(0, "$NetBSD: pmap_bootstrap.c,v 1.2 2008/04/28 20:23:12 martin Exp $"); 69 70 #include <sys/param.h> 71 #include <sys/systm.h> 72 #include <sys/proc.h> 73 #include <sys/malloc.h> 74 #include <sys/user.h> 75 76 #include <uvm/uvm.h> 77 78 #include <machine/pte.h> 79 #include <machine/cpu.h> 80 #include <machine/vmparam.h> 81 82 #include <m68k/cacheops.h> 83 84 #include <amiga/amiga/memlist.h> 85 86 /* 87 * Kernel segment/page table and page table map. 88 * The page table map gives us a level of indirection we need to dynamically 89 * expand the page table. It is essentially a copy of the segment table 90 * with PTEs instead of STEs. All are initialized in locore at boot time. 91 * Sysmap will initially contain VM_KERNEL_PT_PAGES pages of PTEs. 92 * Segtabzero is an empty segment table which all processes share til they 93 * reference something. 94 */ 95 u_int *Sysseg, *Sysseg_pa; 96 97 vsize_t mem_size; /* memory size in bytes */ 98 vaddr_t virtual_avail; /* VA of first avail page (after kernel bss)*/ 99 vaddr_t virtual_end; /* VA of last avail page (end of kernel AS) */ 100 #if defined(M68040) || defined(M68060) 101 int protostfree; /* prototype (default) free ST map */ 102 #endif 103 104 extern paddr_t msgbufpa; 105 106 u_long noncontig_enable; 107 108 extern paddr_t z2mem_start; 109 110 extern vaddr_t reserve_dumppages(vaddr_t); 111 112 /* 113 * All those kernel PT submaps that BSD is so fond of 114 */ 115 void *CADDR1, *CADDR2; 116 char *vmmap; 117 118 extern int protection_codes[]; 119 120 /* 121 * Bootstrap the system enough to run with virtual memory. 122 * Map the kernel's code and data, and allocate the system page table. 123 * 124 * On the HP this is called after mapping has already been enabled 125 * and just syncs the pmap module with what has already been done. 126 * [We can't call it easily with mapping off since the kernel is not 127 * mapped with PA == VA, hence we would have to relocate every address 128 * from the linked base (virtual) address 0 to the actual (physical) 129 * address of 0xFFxxxxxx.] 130 */ 131 void 132 pmap_bootstrap(firstaddr, loadaddr) 133 paddr_t firstaddr; 134 paddr_t loadaddr; 135 { 136 vaddr_t va; 137 int i; 138 struct boot_memseg *sp, *esp; 139 paddr_t fromads, toads; 140 141 fromads = firstaddr; 142 toads = maxmem << PGSHIFT; 143 144 /* XXX: allow for msgbuf */ 145 toads -= m68k_round_page(MSGBUFSIZE); 146 msgbufpa = toads; 147 /* 148 * first segment of memory is always the one loadbsd found 149 * for loading the kernel into. 150 */ 151 152 uvmexp.pagesize = NBPG; 153 uvm_setpagesize(); 154 155 /* 156 * May want to check if first segment is Zorro-II? 157 */ 158 uvm_page_physload(atop(fromads), atop(toads), 159 atop(fromads), atop(toads), VM_FREELIST_DEFAULT); 160 161 sp = memlist->m_seg; 162 esp = sp + memlist->m_nseg; 163 i = 1; 164 for (; noncontig_enable && sp < esp; sp++) { 165 if ((sp->ms_attrib & MEMF_FAST) == 0) 166 continue; /* skip if not FastMem */ 167 if (firstaddr >= sp->ms_start && 168 firstaddr < sp->ms_start + sp->ms_size) 169 continue; /* skip kernel segment */ 170 if (sp->ms_size == 0) 171 continue; /* skip zero size segments */ 172 fromads = sp->ms_start; 173 toads = sp->ms_start + sp->ms_size; 174 #ifdef DEBUG_A4000 175 /* 176 * My A4000 doesn't seem to like Zorro II memory - this 177 * hack is to skip the motherboard memory and use the 178 * Zorro II memory. Only for trying to debug the problem. 179 * Michael L. Hitch 180 */ 181 if (toads == 0x08000000) 182 continue; /* skip A4000 motherboard mem */ 183 #endif 184 /* 185 * Deal with Zorro II memory stolen for DMA bounce buffers. 186 * This needs to be handled better. 187 * 188 * XXX is: disabled. This is handled now in amiga_init.c 189 * by removing the stolen memory from the memlist. 190 * 191 * XXX is: enabled again, but check real size and position. 192 * We check z2mem_start is in this segment, and set its end 193 * to the z2mem_start. 194 * 195 */ 196 if ((fromads <= z2mem_start) && (toads > z2mem_start)) 197 toads = z2mem_start; 198 199 uvm_page_physload(atop(fromads), atop(toads), 200 atop(fromads), atop(toads), (fromads & 0xff000000) ? 201 VM_FREELIST_DEFAULT : VM_FREELIST_ZORROII); 202 physmem += (toads - fromads) / PAGE_SIZE; 203 ++i; 204 if (noncontig_enable == 1) 205 break; /* Only two segments enabled */ 206 } 207 208 mem_size = physmem << PGSHIFT; 209 virtual_end = VM_MAX_KERNEL_ADDRESS; 210 211 /* 212 * Initialize protection array. 213 * XXX don't use a switch statement, it might produce an 214 * absolute "jmp" table. 215 */ 216 { 217 int *kp; 218 219 kp = (int *)&protection_codes; 220 kp[VM_PROT_NONE|VM_PROT_NONE|VM_PROT_NONE] = 0; 221 kp[VM_PROT_READ|VM_PROT_NONE|VM_PROT_NONE] = PG_RO; 222 kp[VM_PROT_READ|VM_PROT_NONE|VM_PROT_EXECUTE] = PG_RO; 223 kp[VM_PROT_NONE|VM_PROT_NONE|VM_PROT_EXECUTE] = PG_RO; 224 kp[VM_PROT_NONE|VM_PROT_WRITE|VM_PROT_NONE] = PG_RW; 225 kp[VM_PROT_NONE|VM_PROT_WRITE|VM_PROT_EXECUTE] = PG_RW; 226 kp[VM_PROT_READ|VM_PROT_WRITE|VM_PROT_NONE] = PG_RW; 227 kp[VM_PROT_READ|VM_PROT_WRITE|VM_PROT_EXECUTE] = PG_RW; 228 } 229 230 /* 231 * Kernel page/segment table allocated in locore, 232 * just initialize pointers. 233 */ 234 pmap_kernel()->pm_stpa = Sysseg_pa; 235 pmap_kernel()->pm_stab = Sysseg; 236 pmap_kernel()->pm_ptab = Sysmap; 237 #if defined(M68040) || defined(M68060) 238 if (mmutype == MMU_68040) 239 pmap_kernel()->pm_stfree = protostfree; 240 #endif 241 242 simple_lock_init(&pmap_kernel()->pm_lock); 243 pmap_kernel()->pm_count = 1; 244 245 /* 246 * Allocate all the submaps we need 247 */ 248 #define SYSMAP(c, v, n) \ 249 v = (c)va; va += ((n)*PAGE_SIZE); 250 251 va = virtual_avail; 252 253 SYSMAP(void * ,CADDR1 ,1 ) 254 SYSMAP(void * ,CADDR2 ,1 ) 255 SYSMAP(void * ,vmmap ,1 ) 256 SYSMAP(void * ,msgbufaddr ,btoc(MSGBUFSIZE) ) 257 258 DCIS(); 259 260 virtual_avail = reserve_dumppages(va); 261 } 262