sun2.c revision 1.1.8.4 1 1.1.8.4 nathanw /* $NetBSD: sun2.c,v 1.1.8.4 2002/10/18 02:40:27 nathanw Exp $ */
2 1.1.8.2 nathanw
3 1.1.8.2 nathanw /*-
4 1.1.8.2 nathanw * Copyright (c) 1998 The NetBSD Foundation, Inc.
5 1.1.8.2 nathanw * All rights reserved.
6 1.1.8.2 nathanw *
7 1.1.8.2 nathanw * This code is derived from software contributed to The NetBSD Foundation
8 1.1.8.2 nathanw * by Gordon W. Ross and Matthew Fredette.
9 1.1.8.2 nathanw *
10 1.1.8.2 nathanw * Redistribution and use in source and binary forms, with or without
11 1.1.8.2 nathanw * modification, are permitted provided that the following conditions
12 1.1.8.2 nathanw * are met:
13 1.1.8.2 nathanw * 1. Redistributions of source code must retain the above copyright
14 1.1.8.2 nathanw * notice, this list of conditions and the following disclaimer.
15 1.1.8.2 nathanw * 2. Redistributions in binary form must reproduce the above copyright
16 1.1.8.2 nathanw * notice, this list of conditions and the following disclaimer in the
17 1.1.8.2 nathanw * documentation and/or other materials provided with the distribution.
18 1.1.8.2 nathanw * 3. All advertising materials mentioning features or use of this software
19 1.1.8.2 nathanw * must display the following acknowledgement:
20 1.1.8.2 nathanw * This product includes software developed by the NetBSD
21 1.1.8.2 nathanw * Foundation, Inc. and its contributors.
22 1.1.8.2 nathanw * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.1.8.2 nathanw * contributors may be used to endorse or promote products derived
24 1.1.8.2 nathanw * from this software without specific prior written permission.
25 1.1.8.2 nathanw *
26 1.1.8.2 nathanw * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.1.8.2 nathanw * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.1.8.2 nathanw * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.1.8.2 nathanw * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.1.8.2 nathanw * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.1.8.2 nathanw * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.1.8.2 nathanw * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.1.8.2 nathanw * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.1.8.2 nathanw * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.1.8.2 nathanw * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.1.8.2 nathanw * POSSIBILITY OF SUCH DAMAGE.
37 1.1.8.2 nathanw */
38 1.1.8.2 nathanw
39 1.1.8.2 nathanw /*
40 1.1.8.2 nathanw * Standalone functions specific to the Sun2.
41 1.1.8.2 nathanw */
42 1.1.8.2 nathanw
43 1.1.8.2 nathanw /* Need to avoid conflicts on these: */
44 1.1.8.2 nathanw #define get_pte sun2_get_pte
45 1.1.8.2 nathanw #define set_pte sun2_set_pte
46 1.1.8.2 nathanw #define get_segmap sun2_get_segmap
47 1.1.8.2 nathanw #define set_segmap sun2_set_segmap
48 1.1.8.2 nathanw
49 1.1.8.3 nathanw /*
50 1.1.8.3 nathanw * We need to get the sun2 NBSG definition, even if we're
51 1.1.8.3 nathanw * building this with a different sun68k target.
52 1.1.8.3 nathanw */
53 1.1.8.3 nathanw #include <arch/sun2/include/param.h>
54 1.1.8.3 nathanw
55 1.1.8.2 nathanw #include <sys/param.h>
56 1.1.8.2 nathanw #include <machine/idprom.h>
57 1.1.8.2 nathanw #include <machine/mon.h>
58 1.1.8.2 nathanw
59 1.1.8.2 nathanw #include <arch/sun2/include/pte.h>
60 1.1.8.2 nathanw #include <arch/sun2/sun2/control.h>
61 1.1.8.2 nathanw #ifdef notyet
62 1.1.8.2 nathanw #include <arch/sun3/sun3/vme.h>
63 1.1.8.2 nathanw #else
64 1.1.8.2 nathanw #define VME16_BASE MBIO_BASE
65 1.1.8.2 nathanw #define VME16_MASK MBIO_MASK
66 1.1.8.2 nathanw #endif
67 1.1.8.2 nathanw #include <arch/sun2/sun2/mbmem.h>
68 1.1.8.2 nathanw #include <arch/sun2/sun2/mbio.h>
69 1.1.8.2 nathanw
70 1.1.8.2 nathanw #include <stand.h>
71 1.1.8.2 nathanw
72 1.1.8.2 nathanw #include "libsa.h"
73 1.1.8.2 nathanw #include "dvma.h"
74 1.1.8.2 nathanw #include "saio.h" /* enum MAPTYPES */
75 1.1.8.2 nathanw
76 1.1.8.2 nathanw #define OBIO_MASK 0xFFFFFF
77 1.1.8.2 nathanw
78 1.1.8.2 nathanw u_int get_pte __P((vaddr_t va));
79 1.1.8.2 nathanw void set_pte __P((vaddr_t va, u_int pte));
80 1.1.8.2 nathanw char * dvma2_alloc __P((int len));
81 1.1.8.2 nathanw void dvma2_free __P((char *dvma, int len));
82 1.1.8.2 nathanw char * dvma2_mapin __P((char *pkt, int len));
83 1.1.8.2 nathanw void dvma2_mapout __P((char *dmabuf, int len));
84 1.1.8.2 nathanw char * dev2_mapin __P((int type, u_long addr, int len));
85 1.1.8.2 nathanw
86 1.1.8.2 nathanw struct mapinfo {
87 1.1.8.2 nathanw int maptype;
88 1.1.8.2 nathanw int pgtype;
89 1.1.8.2 nathanw u_int base;
90 1.1.8.2 nathanw u_int mask;
91 1.1.8.2 nathanw };
92 1.1.8.2 nathanw
93 1.1.8.2 nathanw #ifdef notyet
94 1.1.8.2 nathanw struct mapinfo
95 1.1.8.2 nathanw sun2_mapinfo[MAP__NTYPES] = {
96 1.1.8.2 nathanw /* On-board memory, I/O */
97 1.1.8.2 nathanw { MAP_MAINMEM, PGT_OBMEM, 0, ~0 },
98 1.1.8.2 nathanw { MAP_OBIO, PGT_OBIO, 0, OBIO_MASK },
99 1.1.8.2 nathanw /* Multibus memory, I/O */
100 1.1.8.2 nathanw { MAP_MBMEM, PGT_MBMEM, MBMEM_BASE, MBMEM_MASK },
101 1.1.8.2 nathanw { MAP_MBIO, PGT_MBIO, MBIO_BASE, MBIO_MASK },
102 1.1.8.2 nathanw /* VME A16 */
103 1.1.8.2 nathanw { MAP_VME16A16D, PGT_VME_D16, VME16_BASE, VME16_MASK },
104 1.1.8.2 nathanw { MAP_VME16A32D, 0, 0, 0 },
105 1.1.8.2 nathanw /* VME A24 */
106 1.1.8.2 nathanw { MAP_VME24A16D, 0, 0, 0 },
107 1.1.8.2 nathanw { MAP_VME24A32D, 0, 0, 0 },
108 1.1.8.2 nathanw /* VME A32 */
109 1.1.8.2 nathanw { MAP_VME32A16D, 0, 0, 0 },
110 1.1.8.2 nathanw { MAP_VME32A32D, 0, 0, 0 },
111 1.1.8.2 nathanw };
112 1.1.8.2 nathanw #endif
113 1.1.8.2 nathanw
114 1.1.8.2 nathanw /* The virtual address we will use for PROM device mappings. */
115 1.1.8.2 nathanw int sun2_devmap = SUN3_MONSHORTSEG;
116 1.1.8.2 nathanw
117 1.1.8.2 nathanw char *
118 1.1.8.2 nathanw dev2_mapin(maptype, physaddr, length)
119 1.1.8.2 nathanw int maptype;
120 1.1.8.2 nathanw u_long physaddr;
121 1.1.8.2 nathanw int length;
122 1.1.8.2 nathanw {
123 1.1.8.2 nathanw #ifdef notyet
124 1.1.8.2 nathanw u_int i, pa, pte, pgva, va;
125 1.1.8.2 nathanw
126 1.1.8.2 nathanw if ((sun2_devmap + length) > SUN3_MONSHORTPAGE)
127 1.1.8.4 nathanw panic("dev2_mapin: length=%d", length);
128 1.1.8.2 nathanw
129 1.1.8.2 nathanw for (i = 0; i < MAP__NTYPES; i++)
130 1.1.8.2 nathanw if (sun2_mapinfo[i].maptype == maptype)
131 1.1.8.2 nathanw goto found;
132 1.1.8.2 nathanw panic("dev2_mapin: bad maptype");
133 1.1.8.2 nathanw found:
134 1.1.8.2 nathanw
135 1.1.8.2 nathanw if (physaddr & ~(sun2_mapinfo[i].mask))
136 1.1.8.2 nathanw panic("dev2_mapin: bad address");
137 1.1.8.2 nathanw pa = sun2_mapinfo[i].base += physaddr;
138 1.1.8.2 nathanw
139 1.1.8.2 nathanw pte = PA_PGNUM(pa) | PG_PERM |
140 1.1.8.2 nathanw sun2_mapinfo[i].pgtype;
141 1.1.8.2 nathanw
142 1.1.8.2 nathanw va = pgva = sun2_devmap;
143 1.1.8.2 nathanw do {
144 1.1.8.2 nathanw set_pte(pgva, pte);
145 1.1.8.2 nathanw pgva += NBPG;
146 1.1.8.2 nathanw pte += 1;
147 1.1.8.2 nathanw length -= NBPG;
148 1.1.8.2 nathanw } while (length > 0);
149 1.1.8.2 nathanw sun2_devmap = pgva;
150 1.1.8.2 nathanw va += (physaddr & PGOFSET);
151 1.1.8.2 nathanw
152 1.1.8.2 nathanw #ifdef DEBUG_PROM
153 1.1.8.2 nathanw if (debug)
154 1.1.8.2 nathanw printf("dev2_mapin: va=0x%x pte=0x%x\n",
155 1.1.8.2 nathanw va, get_pte(va));
156 1.1.8.2 nathanw #endif
157 1.1.8.2 nathanw return ((char*)va);
158 1.1.8.2 nathanw #else
159 1.1.8.2 nathanw panic("dev2_mapin");
160 1.1.8.2 nathanw return(NULL);
161 1.1.8.2 nathanw #endif
162 1.1.8.2 nathanw }
163 1.1.8.2 nathanw
164 1.1.8.2 nathanw /*****************************************************************
165 1.1.8.2 nathanw * DVMA support
166 1.1.8.2 nathanw */
167 1.1.8.2 nathanw
168 1.1.8.2 nathanw /*
169 1.1.8.2 nathanw * The easiest way to deal with the need for DVMA mappings is to
170 1.1.8.2 nathanw * create a DVMA alias mapping of the entire address range used by
171 1.1.8.2 nathanw * the boot program. That way, dvma_mapin can just compute the
172 1.1.8.2 nathanw * DVMA alias address, and dvma_mapout does nothing.
173 1.1.8.2 nathanw *
174 1.1.8.2 nathanw * Note that this assumes that standalone programs will do I/O
175 1.1.8.2 nathanw * operations only within range (SA_MIN_VA .. SA_MAX_VA) checked.
176 1.1.8.2 nathanw */
177 1.1.8.2 nathanw
178 1.1.8.2 nathanw #define DVMA_BASE 0x00f00000
179 1.1.8.2 nathanw #define DVMA_MAPLEN 0x38000 /* 256K - 32K (save MONSHORTSEG) */
180 1.1.8.2 nathanw
181 1.1.8.2 nathanw #define SA_MIN_VA 0x220000
182 1.1.8.2 nathanw #define SA_MAX_VA (SA_MIN_VA + DVMA_MAPLEN)
183 1.1.8.2 nathanw
184 1.1.8.2 nathanw /* This points to the end of the free DVMA space. */
185 1.1.8.2 nathanw u_int dvma2_end = DVMA_BASE + DVMA_MAPLEN;
186 1.1.8.2 nathanw
187 1.1.8.2 nathanw void
188 1.1.8.2 nathanw dvma2_init()
189 1.1.8.2 nathanw {
190 1.1.8.2 nathanw int segva, dmava, sme;
191 1.1.8.2 nathanw
192 1.1.8.2 nathanw segva = SA_MIN_VA;
193 1.1.8.2 nathanw dmava = DVMA_BASE;
194 1.1.8.2 nathanw
195 1.1.8.2 nathanw while (segva < SA_MAX_VA) {
196 1.1.8.2 nathanw sme = get_segmap(segva);
197 1.1.8.2 nathanw set_segmap(dmava, sme);
198 1.1.8.2 nathanw segva += NBSG;
199 1.1.8.2 nathanw dmava += NBSG;
200 1.1.8.2 nathanw }
201 1.1.8.2 nathanw }
202 1.1.8.2 nathanw
203 1.1.8.2 nathanw /* Convert a local address to a DVMA address. */
204 1.1.8.2 nathanw char *
205 1.1.8.2 nathanw dvma2_mapin(char *addr, int len)
206 1.1.8.2 nathanw {
207 1.1.8.2 nathanw int va = (int)addr;
208 1.1.8.2 nathanw
209 1.1.8.2 nathanw /* Make sure the address is in the DVMA map. */
210 1.1.8.2 nathanw if ((va < SA_MIN_VA) || (va >= SA_MAX_VA))
211 1.1.8.4 nathanw panic("dvma2_mapin: 0x%x outside 0x%x..0x%x",
212 1.1.8.2 nathanw va, SA_MIN_VA, SA_MAX_VA);
213 1.1.8.2 nathanw
214 1.1.8.2 nathanw va -= SA_MIN_VA;
215 1.1.8.2 nathanw va += DVMA_BASE;
216 1.1.8.2 nathanw
217 1.1.8.2 nathanw return ((char *) va);
218 1.1.8.2 nathanw }
219 1.1.8.2 nathanw
220 1.1.8.2 nathanw /* Destroy a DVMA address alias. */
221 1.1.8.2 nathanw void
222 1.1.8.2 nathanw dvma2_mapout(char *addr, int len)
223 1.1.8.2 nathanw {
224 1.1.8.2 nathanw int va = (int)addr;
225 1.1.8.2 nathanw
226 1.1.8.2 nathanw /* Make sure the address is in the DVMA map. */
227 1.1.8.2 nathanw if ((va < DVMA_BASE) || (va >= (DVMA_BASE + DVMA_MAPLEN)))
228 1.1.8.2 nathanw panic("dvma2_mapout");
229 1.1.8.2 nathanw }
230 1.1.8.2 nathanw
231 1.1.8.2 nathanw char *
232 1.1.8.2 nathanw dvma2_alloc(int len)
233 1.1.8.2 nathanw {
234 1.1.8.2 nathanw len = m68k_round_page(len);
235 1.1.8.2 nathanw dvma2_end -= len;
236 1.1.8.2 nathanw return((char*)dvma2_end);
237 1.1.8.2 nathanw }
238 1.1.8.2 nathanw
239 1.1.8.2 nathanw void
240 1.1.8.2 nathanw dvma2_free(char *dvma, int len)
241 1.1.8.2 nathanw {
242 1.1.8.2 nathanw /* not worth the trouble */
243 1.1.8.2 nathanw }
244 1.1.8.2 nathanw
245 1.1.8.2 nathanw /*****************************************************************
246 1.1.8.2 nathanw * Control space stuff...
247 1.1.8.2 nathanw */
248 1.1.8.2 nathanw
249 1.1.8.2 nathanw u_int
250 1.1.8.2 nathanw get_pte(va)
251 1.1.8.2 nathanw vaddr_t va;
252 1.1.8.2 nathanw {
253 1.1.8.2 nathanw u_int pte;
254 1.1.8.2 nathanw
255 1.1.8.2 nathanw pte = get_control_word(CONTROL_ADDR_BUILD(PGMAP_BASE, va));
256 1.1.8.2 nathanw if (pte & PG_VALID) {
257 1.1.8.2 nathanw /*
258 1.1.8.2 nathanw * This clears bit 30 (the kernel readable bit, which
259 1.1.8.2 nathanw * should always be set), bit 28 (which should always
260 1.1.8.2 nathanw * be set) and bit 26 (the user writable bit, which we
261 1.1.8.2 nathanw * always have tracking the kernel writable bit). In
262 1.1.8.2 nathanw * the protection, this leaves bit 29 (the kernel
263 1.1.8.2 nathanw * writable bit) and bit 27 (the user readable bit).
264 1.1.8.2 nathanw * See pte2.h for more about this hack.
265 1.1.8.2 nathanw */
266 1.1.8.2 nathanw pte &= ~(0x54000000);
267 1.1.8.2 nathanw /*
268 1.1.8.2 nathanw * Flip bit 27 (the user readable bit) to become bit
269 1.1.8.2 nathanw * 27 (the PG_SYSTEM bit).
270 1.1.8.2 nathanw */
271 1.1.8.2 nathanw pte ^= (PG_SYSTEM);
272 1.1.8.2 nathanw }
273 1.1.8.2 nathanw return (pte);
274 1.1.8.2 nathanw }
275 1.1.8.2 nathanw
276 1.1.8.2 nathanw void
277 1.1.8.2 nathanw set_pte(va, pte)
278 1.1.8.2 nathanw vaddr_t va;
279 1.1.8.2 nathanw u_int pte;
280 1.1.8.2 nathanw {
281 1.1.8.2 nathanw if (pte & PG_VALID) {
282 1.1.8.2 nathanw /* Clear bit 26 (the user writable bit). */
283 1.1.8.2 nathanw pte &= (~0x04000000);
284 1.1.8.2 nathanw /*
285 1.1.8.2 nathanw * Flip bit 27 (the PG_SYSTEM bit) to become bit 27
286 1.1.8.2 nathanw * (the user readable bit).
287 1.1.8.2 nathanw */
288 1.1.8.2 nathanw pte ^= (PG_SYSTEM);
289 1.1.8.2 nathanw /*
290 1.1.8.2 nathanw * Always set bits 30 (the kernel readable bit) and
291 1.1.8.2 nathanw * bit 28, and set bit 26 (the user writable bit) iff
292 1.1.8.2 nathanw * bit 29 (the kernel writable bit) is set *and* bit
293 1.1.8.2 nathanw * 27 (the user readable bit) is set. This latter bit
294 1.1.8.2 nathanw * of logic is expressed in the bizarre second term
295 1.1.8.2 nathanw * below, chosen because it needs no branches.
296 1.1.8.2 nathanw */
297 1.1.8.2 nathanw #if (PG_WRITE >> 2) != PG_SYSTEM
298 1.1.8.2 nathanw #error "PG_WRITE and PG_SYSTEM definitions don't match!"
299 1.1.8.2 nathanw #endif
300 1.1.8.2 nathanw pte |= 0x50000000
301 1.1.8.2 nathanw | ((((pte & PG_WRITE) >> 2) & pte) >> 1);
302 1.1.8.2 nathanw }
303 1.1.8.2 nathanw set_control_word(CONTROL_ADDR_BUILD(PGMAP_BASE, va), pte);
304 1.1.8.2 nathanw }
305 1.1.8.2 nathanw
306 1.1.8.2 nathanw int
307 1.1.8.2 nathanw get_segmap(va)
308 1.1.8.2 nathanw vaddr_t va;
309 1.1.8.2 nathanw {
310 1.1.8.2 nathanw va = CONTROL_ADDR_BUILD(SEGMAP_BASE, va);
311 1.1.8.2 nathanw return (get_control_byte(va));
312 1.1.8.2 nathanw }
313 1.1.8.2 nathanw
314 1.1.8.2 nathanw void
315 1.1.8.2 nathanw set_segmap(va, sme)
316 1.1.8.2 nathanw vaddr_t va;
317 1.1.8.2 nathanw int sme;
318 1.1.8.2 nathanw {
319 1.1.8.2 nathanw va = CONTROL_ADDR_BUILD(SEGMAP_BASE, va);
320 1.1.8.2 nathanw set_control_byte(va, sme);
321 1.1.8.2 nathanw }
322 1.1.8.2 nathanw
323 1.1.8.2 nathanw /*
324 1.1.8.2 nathanw * Copy the IDPROM contents into the passed buffer.
325 1.1.8.2 nathanw * The caller (idprom.c) will do the checksum.
326 1.1.8.2 nathanw */
327 1.1.8.2 nathanw void
328 1.1.8.2 nathanw sun2_getidprom(u_char *dst)
329 1.1.8.2 nathanw {
330 1.1.8.2 nathanw vaddr_t src; /* control space address */
331 1.1.8.2 nathanw int len, x;
332 1.1.8.2 nathanw
333 1.1.8.2 nathanw src = IDPROM_BASE;
334 1.1.8.2 nathanw len = sizeof(struct idprom);
335 1.1.8.2 nathanw do {
336 1.1.8.2 nathanw x = get_control_byte(src);
337 1.1.8.2 nathanw src += NBPG;
338 1.1.8.2 nathanw *dst++ = x;
339 1.1.8.2 nathanw } while (--len > 0);
340 1.1.8.2 nathanw }
341 1.1.8.2 nathanw
342 1.1.8.2 nathanw /*****************************************************************
343 1.1.8.2 nathanw * Init our function pointers, etc.
344 1.1.8.2 nathanw */
345 1.1.8.2 nathanw
346 1.1.8.2 nathanw /*
347 1.1.8.2 nathanw * For booting, the PROM in fredette's Sun 2/120 doesn't map
348 1.1.8.2 nathanw * much main memory, and what is mapped is mapped strangely.
349 1.1.8.2 nathanw * Low virtual memory is mapped like:
350 1.1.8.2 nathanw *
351 1.1.8.2 nathanw * 0x000000 - 0x0bffff virtual -> 0x000000 - 0x0bffff physical
352 1.1.8.2 nathanw * 0x0c0000 - 0x0fffff virtual -> invalid
353 1.1.8.2 nathanw * 0x100000 - 0x13ffff virtual -> 0x0c0000 - 0x0fffff physical
354 1.1.8.2 nathanw * 0x200800 - 0x3fffff virtual -> 0x200800 - 0x3fffff physical
355 1.1.8.2 nathanw *
356 1.1.8.2 nathanw * I think the SunOS authors wanted to load kernels starting at
357 1.1.8.2 nathanw * physical zero, and assumed that kernels would be less
358 1.1.8.2 nathanw * than 768K (0x0c0000) long. Also, the PROM maps physical
359 1.1.8.2 nathanw * 0x0c0000 - 0x0fffff into DVMA space, so we can't take the
360 1.1.8.2 nathanw * easy road and just add more mappings to use that physical
361 1.1.8.2 nathanw * memory while loading (the PROM might do DMA there).
362 1.1.8.2 nathanw *
363 1.1.8.2 nathanw * What we do, then, is assume a 4MB machine (you'll really
364 1.1.8.2 nathanw * need that to run NetBSD at all anyways), and we map two
365 1.1.8.2 nathanw * chunks of physical and virtual space:
366 1.1.8.2 nathanw *
367 1.1.8.2 nathanw * 0x400000 - 0x4bffff virtual -> 0x000000 - 0x0bffff physical
368 1.1.8.2 nathanw * 0x4c0000 - 0x600000 virtual -> 0x2c0000 - 0x3fffff physical
369 1.1.8.2 nathanw *
370 1.1.8.2 nathanw * And then we load starting at virtual 0x400000. We will do
371 1.1.8.2 nathanw * all of this mapping just by copying PMEGs.
372 1.1.8.2 nathanw *
373 1.1.8.2 nathanw * After the load is done, but before we enter the kernel, we're
374 1.1.8.2 nathanw * done with the PROM, so we copy the part of the kernel that
375 1.1.8.2 nathanw * got loaded at physical 0x2c0000 down to physical 0x0c0000.
376 1.1.8.2 nathanw * This can't just be a PMEG copy; we've actually got to move
377 1.1.8.2 nathanw * bytes in physical memory.
378 1.1.8.2 nathanw *
379 1.1.8.2 nathanw * These two chunks of physical and virtual space are defined
380 1.1.8.2 nathanw * in macros below. Some of the macros are only for completeness:
381 1.1.8.2 nathanw */
382 1.1.8.2 nathanw #define MEM_CHUNK0_SIZE (0x0c0000)
383 1.1.8.2 nathanw #define MEM_CHUNK0_LOAD_PHYS (0x000000)
384 1.1.8.2 nathanw #define MEM_CHUNK0_LOAD_VIRT (0x400000)
385 1.1.8.2 nathanw #define MEM_CHUNK0_LOAD_VIRT_PROM MEM_CHUNK0_LOAD_PHYS
386 1.1.8.2 nathanw #define MEM_CHUNK0_COPY_PHYS MEM_CHUNK0_LOAD_PHYS
387 1.1.8.2 nathanw #define MEM_CHUNK0_COPY_VIRT MEM_CHUNK0_COPY_PHYS
388 1.1.8.2 nathanw
389 1.1.8.2 nathanw #define MEM_CHUNK1_SIZE (0x140000)
390 1.1.8.2 nathanw #define MEM_CHUNK1_LOAD_PHYS (0x2c0000)
391 1.1.8.2 nathanw #define MEM_CHUNK1_LOAD_VIRT (MEM_CHUNK0_LOAD_VIRT + MEM_CHUNK0_SIZE)
392 1.1.8.2 nathanw #define MEM_CHUNK1_LOAD_VIRT_PROM MEM_CHUNK1_LOAD_PHYS
393 1.1.8.2 nathanw #define MEM_CHUNK1_COPY_PHYS (MEM_CHUNK0_LOAD_PHYS + MEM_CHUNK0_SIZE)
394 1.1.8.2 nathanw #define MEM_CHUNK1_COPY_VIRT MEM_CHUNK1_COPY_PHYS
395 1.1.8.2 nathanw
396 1.1.8.2 nathanw /* Maps memory for loading. */
397 1.1.8.2 nathanw u_long
398 1.1.8.2 nathanw sun2_map_mem_load()
399 1.1.8.2 nathanw {
400 1.1.8.2 nathanw vaddr_t off;
401 1.1.8.2 nathanw
402 1.1.8.2 nathanw /* Map chunk zero for loading. */
403 1.1.8.2 nathanw for(off = 0; off < MEM_CHUNK0_SIZE; off += NBSG)
404 1.1.8.2 nathanw set_segmap(MEM_CHUNK0_LOAD_VIRT + off,
405 1.1.8.2 nathanw get_segmap(MEM_CHUNK0_LOAD_VIRT_PROM + off));
406 1.1.8.2 nathanw
407 1.1.8.2 nathanw /* Map chunk one for loading. */
408 1.1.8.2 nathanw for(off = 0; off < MEM_CHUNK1_SIZE; off += NBSG)
409 1.1.8.2 nathanw set_segmap(MEM_CHUNK1_LOAD_VIRT + off,
410 1.1.8.2 nathanw get_segmap(MEM_CHUNK1_LOAD_VIRT_PROM + off));
411 1.1.8.2 nathanw
412 1.1.8.2 nathanw /* Tell our caller where in virtual space to load. */
413 1.1.8.2 nathanw return MEM_CHUNK0_LOAD_VIRT;
414 1.1.8.2 nathanw }
415 1.1.8.2 nathanw
416 1.1.8.2 nathanw /* Remaps memory for running. */
417 1.1.8.2 nathanw void *
418 1.1.8.2 nathanw sun2_map_mem_run(entry)
419 1.1.8.2 nathanw void *entry;
420 1.1.8.2 nathanw {
421 1.1.8.2 nathanw vaddr_t off, off_end;
422 1.1.8.2 nathanw int sme;
423 1.1.8.2 nathanw u_int pte;
424 1.1.8.2 nathanw
425 1.1.8.2 nathanw /* Chunk zero is already mapped and copied. */
426 1.1.8.2 nathanw
427 1.1.8.2 nathanw /* Chunk one needs to be mapped and copied. */
428 1.1.8.2 nathanw pte = (get_pte(0) & ~PG_FRAME);
429 1.1.8.2 nathanw for(off = 0; off < MEM_CHUNK1_SIZE; ) {
430 1.1.8.2 nathanw
431 1.1.8.2 nathanw /*
432 1.1.8.2 nathanw * We use the PMEG immediately before the
433 1.1.8.2 nathanw * segment we're copying in the PROM virtual
434 1.1.8.2 nathanw * mapping of the chunk. If this is the first
435 1.1.8.2 nathanw * segment, this is the PMEG the PROM used to
436 1.1.8.2 nathanw * map 0x2b8000 virtual to 0x2b8000 physical,
437 1.1.8.2 nathanw * which I'll assume is unused. For the second
438 1.1.8.2 nathanw * and subsequent segments, this will be the
439 1.1.8.2 nathanw * PMEG used to map the previous segment, which
440 1.1.8.2 nathanw * is now (since we already copied it) unused.
441 1.1.8.2 nathanw */
442 1.1.8.2 nathanw sme = get_segmap((MEM_CHUNK1_LOAD_VIRT_PROM + off) - NBSG);
443 1.1.8.2 nathanw set_segmap(MEM_CHUNK1_COPY_VIRT + off, sme);
444 1.1.8.2 nathanw
445 1.1.8.2 nathanw /* Set the PTEs in this new PMEG. */
446 1.1.8.2 nathanw for(off_end = off + NBSG; off < off_end; off += NBPG)
447 1.1.8.2 nathanw set_pte(MEM_CHUNK1_COPY_VIRT + off,
448 1.1.8.2 nathanw pte | PA_PGNUM(MEM_CHUNK1_COPY_PHYS + off));
449 1.1.8.2 nathanw
450 1.1.8.2 nathanw /* Copy this segment. */
451 1.1.8.2 nathanw bcopy((caddr_t)(MEM_CHUNK1_LOAD_VIRT + (off - NBSG)),
452 1.1.8.2 nathanw (caddr_t)(MEM_CHUNK1_COPY_VIRT + (off - NBSG)),
453 1.1.8.2 nathanw NBSG);
454 1.1.8.2 nathanw }
455 1.1.8.2 nathanw
456 1.1.8.2 nathanw /* Tell our caller where in virtual space to enter. */
457 1.1.8.2 nathanw return ((caddr_t)entry) - MEM_CHUNK0_LOAD_VIRT;
458 1.1.8.2 nathanw }
459 1.1.8.2 nathanw
460 1.1.8.2 nathanw void
461 1.1.8.2 nathanw sun2_init()
462 1.1.8.2 nathanw {
463 1.1.8.2 nathanw /* Set the function pointers. */
464 1.1.8.2 nathanw dev_mapin_p = dev2_mapin;
465 1.1.8.2 nathanw dvma_alloc_p = dvma2_alloc;
466 1.1.8.2 nathanw dvma_free_p = dvma2_free;
467 1.1.8.2 nathanw dvma_mapin_p = dvma2_mapin;
468 1.1.8.2 nathanw dvma_mapout_p = dvma2_mapout;
469 1.1.8.2 nathanw
470 1.1.8.2 nathanw /* Prepare DVMA segment. */
471 1.1.8.2 nathanw dvma2_init();
472 1.1.8.2 nathanw }
473