Home | History | Annotate | Line # | Download | only in libsa
sun3.c revision 1.6.78.1
      1 /*	$NetBSD: sun3.c,v 1.6.78.1 2008/05/16 02:23:23 yamt Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1998 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Gordon W. Ross.
      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  * Standalone functions specific to the Sun3.
     34  */
     35 
     36 #define _SUN3_ XXX
     37 
     38 /* Need to avoid conflicts on these: */
     39 #define get_pte sun3_get_pte
     40 #define set_pte sun3_set_pte
     41 #define get_segmap sun3_get_segmap
     42 #define set_segmap sun3_set_segmap
     43 
     44 /*
     45  * We need to get the sun3 NBSG definition, even if we're
     46  * building this with a different sun68k target.
     47  */
     48 #include <arch/sun3/include/param.h>
     49 
     50 #include <sys/param.h>
     51 #include <machine/idprom.h>
     52 #include <machine/mon.h>
     53 
     54 #include <arch/sun3/include/pte3.h>
     55 #include <arch/sun3/sun3/control.h>
     56 #include <arch/sun3/sun3/vme.h>
     57 
     58 #include <stand.h>
     59 
     60 #include "libsa.h"
     61 #include "dvma.h"
     62 #include "saio.h"	/* enum MAPTYPES */
     63 
     64 #define OBIO_MASK 0xFFFFFF
     65 
     66 u_int	get_pte(vaddr_t);
     67 void	set_pte(vaddr_t, u_int);
     68 char *	dvma3_alloc(int);
     69 void	dvma3_free(char *, int);
     70 char *	dvma3_mapin(char *, int);
     71 void	dvma3_mapout(char *, int);
     72 char *	dev3_mapin(int, u_long, int);
     73 
     74 struct mapinfo {
     75 	int maptype;
     76 	int pgtype;
     77 	u_int base;
     78 	u_int mask;
     79 };
     80 
     81 struct mapinfo
     82 sun3_mapinfo[MAP__NTYPES] = {
     83 	/* On-board memory, I/O */
     84 	{ MAP_MAINMEM,   PGT_OBMEM,   0,          ~0 },
     85 	{ MAP_OBIO,      PGT_OBIO,    0,          OBIO_MASK },
     86 	/* Multibus adapter (A24,A16) */
     87 	{ MAP_MBMEM,     PGT_VME_D16, VME24_BASE, VME24_MASK },
     88 	{ MAP_MBIO,      PGT_VME_D16, VME16_BASE, VME16_MASK },
     89 	/* VME A16 */
     90 	{ MAP_VME16A16D, PGT_VME_D16, VME16_BASE, VME16_MASK },
     91 	{ MAP_VME16A32D, PGT_VME_D32, VME16_BASE, VME16_MASK },
     92 	/* VME A24 */
     93 	{ MAP_VME24A16D, PGT_VME_D16, VME24_BASE, VME24_MASK },
     94 	{ MAP_VME24A32D, PGT_VME_D32, VME24_BASE, VME24_MASK },
     95 	/* VME A32 */
     96 	{ MAP_VME32A16D, PGT_VME_D16, VME32_BASE, VME32_MASK },
     97 	{ MAP_VME32A32D, PGT_VME_D32, VME32_BASE, VME32_MASK },
     98 };
     99 
    100 /* The virtual address we will use for PROM device mappings. */
    101 int sun3_devmap = SUN3_MONSHORTSEG;
    102 
    103 char *
    104 dev3_mapin(int maptype, u_long physaddr, int length)
    105 {
    106 	u_int i, pa, pte, pgva, va;
    107 
    108 	if ((sun3_devmap + length) > SUN3_MONSHORTPAGE)
    109 		panic("dev3_mapin: length=%d", length);
    110 
    111 	for (i = 0; i < MAP__NTYPES; i++)
    112 		if (sun3_mapinfo[i].maptype == maptype)
    113 			goto found;
    114 	panic("dev3_mapin: bad maptype");
    115 found:
    116 
    117 	if (physaddr & ~(sun3_mapinfo[i].mask))
    118 		panic("dev3_mapin: bad address");
    119 	pa = sun3_mapinfo[i].base += physaddr;
    120 
    121 	pte = PA_PGNUM(pa) | PG_PERM | sun3_mapinfo[i].pgtype;
    122 
    123 	va = pgva = sun3_devmap;
    124 	do {
    125 		set_pte(pgva, pte);
    126 		pgva += NBPG;
    127 		pte += 1;
    128 		length -= NBPG;
    129 	} while (length > 0);
    130 	sun3_devmap = pgva;
    131 	va += (physaddr & PGOFSET);
    132 
    133 #ifdef	DEBUG_PROM
    134 	if (debug)
    135 		printf("dev3_mapin: va=0x%x pte=0x%x\n",
    136 			   va, get_pte(va));
    137 #endif
    138 	return ((char*)va);
    139 }
    140 
    141 /*****************************************************************
    142  * DVMA support
    143  */
    144 
    145 /*
    146  * The easiest way to deal with the need for DVMA mappings is to
    147  * create a DVMA alias mapping of the entire address range used by
    148  * the boot program.  That way, dvma_mapin can just compute the
    149  * DVMA alias address, and dvma_mapout does nothing.
    150  *
    151  * Note that this assumes that standalone programs will do I/O
    152  * operations only within range (SA_MIN_VA .. SA_MAX_VA) checked.
    153  */
    154 
    155 #define	DVMA_BASE 0xFFf00000
    156 #define DVMA_MAPLEN  0xE0000	/* 1 MB - 128K (save MONSHORTSEG) */
    157 
    158 #define SA_MIN_VA	0x200000
    159 #define SA_MAX_VA	(SA_MIN_VA + DVMA_MAPLEN)
    160 
    161 /* This points to the end of the free DVMA space. */
    162 u_int dvma3_end = DVMA_BASE + DVMA_MAPLEN;
    163 
    164 void
    165 dvma3_init(void)
    166 {
    167 	int segva, dmava, sme;
    168 
    169 	segva = SA_MIN_VA;
    170 	dmava = DVMA_BASE;
    171 
    172 	while (segva < SA_MAX_VA) {
    173 		sme = get_segmap(segva);
    174 		set_segmap(dmava, sme);
    175 		segva += NBSG;
    176 		dmava += NBSG;
    177 	}
    178 }
    179 
    180 /* Convert a local address to a DVMA address. */
    181 char *
    182 dvma3_mapin(char *addr, int len)
    183 {
    184 	int va = (int)addr;
    185 
    186 	/* Make sure the address is in the DVMA map. */
    187 	if ((va < SA_MIN_VA) || (va >= SA_MAX_VA))
    188 		panic("dvma3_mapin");
    189 
    190 	va -= SA_MIN_VA;
    191 	va += DVMA_BASE;
    192 
    193 	return ((char *) va);
    194 }
    195 
    196 /* Destroy a DVMA address alias. */
    197 void
    198 dvma3_mapout(char *addr, int len)
    199 {
    200 	int va = (int)addr;
    201 
    202 	/* Make sure the address is in the DVMA map. */
    203 	if ((va < DVMA_BASE) || (va >= (DVMA_BASE + DVMA_MAPLEN)))
    204 		panic("dvma3_mapout");
    205 }
    206 
    207 char *
    208 dvma3_alloc(int len)
    209 {
    210 	len = m68k_round_page(len);
    211 	dvma3_end -= len;
    212 	return((char*)dvma3_end);
    213 }
    214 
    215 void
    216 dvma3_free(char *dvma, int len)
    217 {
    218 	/* not worth the trouble */
    219 }
    220 
    221 /*****************************************************************
    222  * Control space stuff...
    223  */
    224 
    225 u_int
    226 get_pte(vaddr_t va)
    227 {
    228 	va = CONTROL_ADDR_BUILD(PGMAP_BASE, va);
    229 	return (get_control_word(va));
    230 }
    231 
    232 void
    233 set_pte(vaddr_t va, u_int pte)
    234 {
    235 	va = CONTROL_ADDR_BUILD(PGMAP_BASE, va);
    236 	set_control_word(va, pte);
    237 }
    238 
    239 int
    240 get_segmap(vaddr_t va)
    241 {
    242 	va = CONTROL_ADDR_BUILD(SEGMAP_BASE, va);
    243 	return (get_control_byte(va));
    244 }
    245 
    246 void
    247 set_segmap(vaddr_t va, int sme)
    248 {
    249 	va = CONTROL_ADDR_BUILD(SEGMAP_BASE, va);
    250 	set_control_byte(va, sme);
    251 }
    252 
    253 /*
    254  * Copy the IDPROM contents into the passed buffer.
    255  * The caller (idprom.c) will do the checksum.
    256  */
    257 void
    258 sun3_getidprom(u_char *dst)
    259 {
    260 	vaddr_t src;	/* control space address */
    261 	int len, x;
    262 
    263 	src = IDPROM_BASE;
    264 	len = sizeof(struct idprom);
    265 	do {
    266 		x = get_control_byte(src++);
    267 		*dst++ = x;
    268 	} while (--len > 0);
    269 }
    270 
    271 /*****************************************************************
    272  * Init our function pointers, etc.
    273  */
    274 
    275 void
    276 sun3_init(void)
    277 {
    278 
    279 	/* Set the function pointers. */
    280 	dev_mapin_p   = dev3_mapin;
    281 	dvma_alloc_p  = dvma3_alloc;
    282 	dvma_free_p   = dvma3_free;
    283 	dvma_mapin_p  = dvma3_mapin;
    284 	dvma_mapout_p = dvma3_mapout;
    285 
    286 	/* Prepare DVMA segment. */
    287 	dvma3_init();
    288 }
    289