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