1 /* $NetBSD: pmap_bootstrap.c,v 1.11 2023/12/20 00:40:42 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.11 2023/12/20 00:40:42 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 char *vmmap;
100
101 /*
102 * Bootstrap the system enough to run with virtual memory.
103 *
104 * This is called after mapping has already been enabled
105 * and just syncs the pmap module with what has already been done.
106 */
107 void
pmap_bootstrap(paddr_t firstaddr,paddr_t loadaddr)108 pmap_bootstrap(paddr_t firstaddr, paddr_t loadaddr)
109 {
110 vaddr_t va;
111 int i;
112 struct boot_memseg *sp, *esp;
113 paddr_t fromads, toads;
114
115 fromads = firstaddr;
116 toads = maxmem << PGSHIFT;
117
118 /* XXX: allow for msgbuf */
119 toads -= m68k_round_page(MSGBUFSIZE);
120 msgbufpa = toads;
121 /*
122 * first segment of memory is always the one loadbsd found
123 * for loading the kernel into.
124 */
125
126 uvmexp.pagesize = NBPG;
127 uvm_md_init();
128
129 /*
130 * May want to check if first segment is Zorro-II?
131 */
132 uvm_page_physload(atop(fromads), atop(toads),
133 atop(fromads), atop(toads), VM_FREELIST_DEFAULT);
134
135 sp = memlist->m_seg;
136 esp = sp + memlist->m_nseg;
137 i = 1;
138 for (; noncontig_enable && sp < esp; sp++) {
139 if ((sp->ms_attrib & MEMF_FAST) == 0)
140 continue; /* skip if not FastMem */
141 if (firstaddr >= sp->ms_start &&
142 firstaddr < sp->ms_start + sp->ms_size)
143 continue; /* skip kernel segment */
144 if (sp->ms_size == 0)
145 continue; /* skip zero size segments */
146 fromads = sp->ms_start;
147 toads = sp->ms_start + sp->ms_size;
148 #ifdef DEBUG_A4000
149 /*
150 * My A4000 doesn't seem to like Zorro II memory - this
151 * hack is to skip the motherboard memory and use the
152 * Zorro II memory. Only for trying to debug the problem.
153 * Michael L. Hitch
154 */
155 if (toads == 0x08000000)
156 continue; /* skip A4000 motherboard mem */
157 #endif
158 /*
159 * Deal with Zorro II memory stolen for DMA bounce buffers.
160 * This needs to be handled better.
161 *
162 * XXX is: disabled. This is handled now in amiga_init.c
163 * by removing the stolen memory from the memlist.
164 *
165 * XXX is: enabled again, but check real size and position.
166 * We check z2mem_start is in this segment, and set its end
167 * to the z2mem_start.
168 *
169 */
170 if ((fromads <= z2mem_start) && (toads > z2mem_start))
171 toads = z2mem_start;
172
173 uvm_page_physload(atop(fromads), atop(toads),
174 atop(fromads), atop(toads), (fromads & 0xff000000) ?
175 VM_FREELIST_DEFAULT : VM_FREELIST_ZORROII);
176 physmem += (toads - fromads) / PAGE_SIZE;
177 ++i;
178 if (noncontig_enable == 1)
179 break; /* Only two segments enabled */
180 }
181
182 mem_size = physmem << PGSHIFT;
183
184 avail_start = firstaddr;
185 avail_end = toads;
186
187 virtual_end = VM_MAX_KERNEL_ADDRESS;
188
189 /*
190 * Allocate all the submaps we need
191 */
192 #define SYSMAP(c, v, n) \
193 v = (c)va; va += ((n)*PAGE_SIZE);
194
195 va = virtual_avail;
196
197 SYSMAP(void * ,CADDR1 ,1 )
198 SYSMAP(void * ,CADDR2 ,1 )
199 SYSMAP(void * ,vmmap ,1 )
200 SYSMAP(void * ,msgbufaddr ,btoc(MSGBUFSIZE) )
201
202 DCIS();
203
204 virtual_avail = reserve_dumppages(va);
205 }
206