1 /* $NetBSD: pmap_bootstrap.c,v 1.15 2026/11/15 15:16:23 thorpej 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.15 2026/11/15 15:16:23 thorpej Exp $"); 69 70 #include <sys/param.h> 71 #include <sys/systm.h> 72 #include <sys/proc.h> 73 74 #include <uvm/uvm.h> 75 76 #include <machine/pte.h> 77 #include <machine/cpu.h> 78 #include <machine/vmparam.h> 79 80 #include <m68k/cacheops.h> 81 82 #include <amiga/amiga/memlist.h> 83 84 extern paddr_t avail_start; 85 extern paddr_t avail_end; 86 87 extern paddr_t msgbufpa; 88 89 u_long noncontig_enable; 90 91 extern paddr_t z2mem_start; 92 93 extern vaddr_t reserve_dumppages(vaddr_t); 94 95 /* 96 * All those kernel PT submaps that BSD is so fond of 97 */ 98 void *CADDR1, *CADDR2; 99 100 /* 101 * Bootstrap the system enough to run with virtual memory. 102 * 103 * This is called after mapping has already been enabled 104 * and just syncs the pmap module with what has already been done. 105 */ 106 void __attribute__((no_instrument_function)) 107 pmap_bootstrap(paddr_t firstaddr, paddr_t loadaddr) 108 { 109 vaddr_t va; 110 int i; 111 struct boot_memseg *sp, *esp; 112 paddr_t fromads, toads; 113 114 fromads = firstaddr; 115 toads = maxmem << PGSHIFT; 116 117 /* XXX: allow for msgbuf */ 118 toads -= m68k_round_page(MSGBUFSIZE); 119 msgbufpa = toads; 120 /* 121 * first segment of memory is always the one loadbsd found 122 * for loading the kernel into. 123 */ 124 125 uvmexp.pagesize = NBPG; 126 uvm_md_init(); 127 128 /* 129 * May want to check if first segment is Zorro-II? 130 */ 131 uvm_page_physload(atop(fromads), atop(toads), 132 atop(fromads), atop(toads), VM_FREELIST_DEFAULT); 133 134 sp = memlist->m_seg; 135 esp = sp + memlist->m_nseg; 136 i = 1; 137 for (; noncontig_enable && sp < esp; sp++) { 138 if ((sp->ms_attrib & MEMF_FAST) == 0) 139 continue; /* skip if not FastMem */ 140 if (firstaddr >= sp->ms_start && 141 firstaddr < sp->ms_start + sp->ms_size) 142 continue; /* skip kernel segment */ 143 if (sp->ms_size == 0) 144 continue; /* skip zero size segments */ 145 fromads = sp->ms_start; 146 toads = sp->ms_start + sp->ms_size; 147 #ifdef DEBUG_A4000 148 /* 149 * My A4000 doesn't seem to like Zorro II memory - this 150 * hack is to skip the motherboard memory and use the 151 * Zorro II memory. Only for trying to debug the problem. 152 * Michael L. Hitch 153 */ 154 if (toads == 0x08000000) 155 continue; /* skip A4000 motherboard mem */ 156 #endif 157 /* 158 * Deal with Zorro II memory stolen for DMA bounce buffers. 159 * This needs to be handled better. 160 * 161 * XXX is: disabled. This is handled now in amiga_init.c 162 * by removing the stolen memory from the memlist. 163 * 164 * XXX is: enabled again, but check real size and position. 165 * We check z2mem_start is in this segment, and set its end 166 * to the z2mem_start. 167 * 168 */ 169 if ((fromads <= z2mem_start) && (toads > z2mem_start)) 170 toads = z2mem_start; 171 172 uvm_page_physload(atop(fromads), atop(toads), 173 atop(fromads), atop(toads), (fromads & 0xff000000) ? 174 VM_FREELIST_DEFAULT : VM_FREELIST_ZORROII); 175 physmem += (toads - fromads) / PAGE_SIZE; 176 ++i; 177 if (noncontig_enable == 1) 178 break; /* Only two segments enabled */ 179 } 180 181 avail_start = firstaddr; 182 avail_end = toads; 183 184 virtual_end = VM_MAX_KERNEL_ADDRESS; 185 186 /* 187 * Allocate all the submaps we need 188 */ 189 #define SYSMAP(c, v, n) \ 190 v = (c)va; va += ((n)*PAGE_SIZE); 191 192 va = virtual_avail; 193 194 SYSMAP(void * ,CADDR1 ,1 ) 195 SYSMAP(void * ,CADDR2 ,1 ) 196 SYSMAP(vaddr_t ,cpu_info_primary.ci_tmpva_vmmap,1 ) 197 SYSMAP(void * ,msgbufaddr ,btoc(m68k_round_page(MSGBUFSIZE)) ) 198 199 DCIS(); 200 201 virtual_avail = reserve_dumppages(va); 202 } 203