xref: /netbsd-src/sys/arch/amiga/amiga/pmap_bootstrap.c (revision eb8043c7664ab56510d9b8fb96251ab47b25bce8)
1 /*	$NetBSD: pmap_bootstrap.c,v 1.6 2009/03/14 15:36:00 dsl 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.6 2009/03/14 15:36:00 dsl 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 u_int		Sysseg_pa;
87 
88 extern paddr_t		avail_start;
89 extern paddr_t		avail_end;
90 #if defined(M68040) || defined(M68060)
91 extern int		protostfree;
92 #endif
93 
94 extern paddr_t	msgbufpa;
95 
96 u_long	noncontig_enable;
97 
98 extern paddr_t z2mem_start;
99 
100 extern vaddr_t reserve_dumppages(vaddr_t);
101 
102 /*
103  * All those kernel PT submaps that BSD is so fond of
104  */
105 void	*CADDR1, *CADDR2;
106 char	*vmmap;
107 
108 /*
109  *	Bootstrap the system enough to run with virtual memory.
110  *
111  *	This is called after mapping has already been enabled
112  *	and just syncs the pmap module with what has already been done.
113  */
114 void
115 pmap_bootstrap(paddr_t firstaddr, paddr_t loadaddr)
116 {
117 	vaddr_t va;
118 	int i;
119 	struct boot_memseg *sp, *esp;
120 	paddr_t fromads, toads;
121 
122 	fromads = firstaddr;
123 	toads = maxmem << PGSHIFT;
124 
125 	/* XXX: allow for msgbuf */
126 	toads -= m68k_round_page(MSGBUFSIZE);
127 	msgbufpa = toads;
128 	/*
129 	 * first segment of memory is always the one loadbsd found
130 	 * for loading the kernel into.
131 	 */
132 
133 	uvmexp.pagesize = NBPG;
134 	uvm_setpagesize();
135 
136 	/*
137 	 * May want to check if first segment is Zorro-II?
138 	 */
139 	uvm_page_physload(atop(fromads), atop(toads),
140 	    atop(fromads), atop(toads), VM_FREELIST_DEFAULT);
141 
142 	sp = memlist->m_seg;
143 	esp = sp + memlist->m_nseg;
144 	i = 1;
145 	for (; noncontig_enable && sp < esp; sp++) {
146 		if ((sp->ms_attrib & MEMF_FAST) == 0)
147 			continue;		/* skip if not FastMem */
148 		if (firstaddr >= sp->ms_start &&
149 		    firstaddr < sp->ms_start + sp->ms_size)
150 			continue;		/* skip kernel segment */
151 		if (sp->ms_size == 0)
152 			continue;		/* skip zero size segments */
153 		fromads = sp->ms_start;
154 		toads = sp->ms_start + sp->ms_size;
155 #ifdef DEBUG_A4000
156 		/*
157 		 * My A4000 doesn't seem to like Zorro II memory - this
158 		 * hack is to skip the motherboard memory and use the
159 		 * Zorro II memory.  Only for trying to debug the problem.
160 		 * Michael L. Hitch
161 		 */
162 		if (toads == 0x08000000)
163 			continue;	/* skip A4000 motherboard mem */
164 #endif
165 		/*
166 		 * Deal with Zorro II memory stolen for DMA bounce buffers.
167 		 * This needs to be handled better.
168 		 *
169 		 * XXX is: disabled. This is handled now in amiga_init.c
170 		 * by removing the stolen memory from the memlist.
171 		 *
172 		 * XXX is: enabled again, but check real size and position.
173 		 * We check z2mem_start is in this segment, and set its end
174 		 * to the z2mem_start.
175 		 *
176 		 */
177 		if ((fromads <= z2mem_start) && (toads > z2mem_start))
178 			toads = z2mem_start;
179 
180 		uvm_page_physload(atop(fromads), atop(toads),
181 		    atop(fromads), atop(toads), (fromads & 0xff000000) ?
182 		    VM_FREELIST_DEFAULT : VM_FREELIST_ZORROII);
183 		physmem += (toads - fromads) / PAGE_SIZE;
184 		++i;
185 		if (noncontig_enable == 1)
186 			break;		/* Only two segments enabled */
187 	}
188 
189 	mem_size = physmem << PGSHIFT;
190 
191 	avail_start = firstaddr;
192 	avail_end   = toads;
193 
194 	virtual_end = VM_MAX_KERNEL_ADDRESS;
195 
196 	/*
197 	 * Initialize protection array.
198 	 * XXX don't use a switch statement, it might produce an
199 	 * absolute "jmp" table.
200 	 */
201 	{
202 		u_int *kp;
203 
204 		kp = (u_int *)&protection_codes;
205 		kp[VM_PROT_NONE|VM_PROT_NONE|VM_PROT_NONE] = 0;
206 		kp[VM_PROT_READ|VM_PROT_NONE|VM_PROT_NONE] = PG_RO;
207 		kp[VM_PROT_READ|VM_PROT_NONE|VM_PROT_EXECUTE] = PG_RO;
208 		kp[VM_PROT_NONE|VM_PROT_NONE|VM_PROT_EXECUTE] = PG_RO;
209 		kp[VM_PROT_NONE|VM_PROT_WRITE|VM_PROT_NONE] = PG_RW;
210 		kp[VM_PROT_NONE|VM_PROT_WRITE|VM_PROT_EXECUTE] = PG_RW;
211 		kp[VM_PROT_READ|VM_PROT_WRITE|VM_PROT_NONE] = PG_RW;
212 		kp[VM_PROT_READ|VM_PROT_WRITE|VM_PROT_EXECUTE] = PG_RW;
213 	}
214 
215 	/*
216 	 * Kernel page/segment table allocated in locore,
217 	 * just initialize pointers.
218 	 */
219 	pmap_kernel()->pm_stpa = (st_entry_t *)Sysseg_pa;
220 	pmap_kernel()->pm_stab = Sysseg;
221 	pmap_kernel()->pm_ptab = Sysmap;
222 #if defined(M68040) || defined(M68060)
223 	if (mmutype == MMU_68040)
224 		pmap_kernel()->pm_stfree = protostfree;
225 #endif
226 
227 	simple_lock_init(&pmap_kernel()->pm_lock);
228 	pmap_kernel()->pm_count = 1;
229 
230 	/*
231 	 * Allocate all the submaps we need
232 	 */
233 #define	SYSMAP(c, v, n)	\
234 	v = (c)va; va += ((n)*PAGE_SIZE);
235 
236 	va = virtual_avail;
237 
238 	SYSMAP(void *	,CADDR1	 ,1			)
239 	SYSMAP(void *	,CADDR2	 ,1			)
240 	SYSMAP(void *	,vmmap	 ,1			)
241 	SYSMAP(void *	,msgbufaddr ,btoc(MSGBUFSIZE)	)
242 
243 	DCIS();
244 
245 	virtual_avail = reserve_dumppages(va);
246 }
247