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