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