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