[BACK]Return to dvma.c CVS log [TXT][DIR] Up to [local] / sys / arch / sparc / stand / common

Annotation of sys/arch/sparc/stand/common/dvma.c, Revision 1.1.1.1

1.1       nbrk        1: /*     $OpenBSD: dvma.c,v 1.3 2003/08/14 17:13:57 deraadt Exp $        */
                      2: /*     $NetBSD: dvma.c,v 1.2 1995/09/17 00:50:56 pk Exp $      */
                      3: /*
                      4:  * Copyright (c) 1995 Gordon W. Ross
                      5:  * All rights reserved.
                      6:  *
                      7:  * Redistribution and use in source and binary forms, with or without
                      8:  * modification, are permitted provided that the following conditions
                      9:  * are met:
                     10:  * 1. Redistributions of source code must retain the above copyright
                     11:  *    notice, this list of conditions and the following disclaimer.
                     12:  * 2. Redistributions in binary form must reproduce the above copyright
                     13:  *    notice, this list of conditions and the following disclaimer in the
                     14:  *    documentation and/or other materials provided with the distribution.
                     15:  * 3. The name of the author may not be used to endorse or promote products
                     16:  *    derived from this software without specific prior written permission.
                     17:  * 4. All advertising materials mentioning features or use of this software
                     18:  *    must display the following acknowledgement:
                     19:  *      This product includes software developed by Gordon Ross
                     20:  *
                     21:  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
                     22:  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
                     23:  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
                     24:  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
                     25:  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
                     26:  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
                     27:  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
                     28:  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
                     29:  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
                     30:  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
                     31:  */
                     32:
                     33: /*
                     34:  * The easiest way to deal with the need for DVMA mappings is
                     35:  * to just map the entire third megabyte of RAM into DVMA space.
                     36:  * That way, dvma_mapin can just compute the DVMA alias address,
                     37:  * and dvma_mapout does nothing.  Note that this assumes all
                     38:  * standalone programs stay in the range SA_MIN_VA .. SA_MAX_VA
                     39:  */
                     40:
                     41: #include <sys/param.h>
                     42: #include <machine/pte.h>
                     43: #include <machine/ctlreg.h>
                     44:
                     45: #include <sparc/stand/common/promdev.h>
                     46:
                     47: #define        DVMA_BASE       0xFFF00000
                     48: #define DVMA_MAPLEN    0xE0000 /* 1 MB - 128K (save MONSHORTSEG) */
                     49:
                     50: #define SA_MIN_VA      (RELOC - 0x40000)       /* XXX - magic constant */
                     51: #define SA_MAX_VA      (SA_MIN_VA + DVMA_MAPLEN)
                     52:
                     53: void
                     54: dvma_init(void)
                     55: {
                     56:        register int segva, dmava;
                     57:
                     58:        dmava = DVMA_BASE;
                     59:        for (segva = SA_MIN_VA; segva < SA_MAX_VA; segva += NBPSG) {
                     60:                setsegmap(dmava, getsegmap(segva));
                     61:                dmava += NBPSG;
                     62:        }
                     63: }
                     64:
                     65: /*
                     66:  * Convert a local address to a DVMA address.
                     67:  */
                     68: char *
                     69: dvma_mapin(char *addr, size_t len)
                     70: {
                     71:        register int va = (int)addr;
                     72:
                     73:        /* Make sure the address is in the DVMA map. */
                     74:        if ((va < SA_MIN_VA) || (va >= SA_MAX_VA))
                     75:                panic("dvma_mapin");
                     76:
                     77:        va += DVMA_BASE - SA_MIN_VA;
                     78:
                     79:        return ((char *)va);
                     80: }
                     81:
                     82: /*
                     83:  * Convert a DVMA address to a local address.
                     84:  */
                     85: char *
                     86: dvma_mapout(char *addr, size_t len)
                     87: {
                     88:        int va = (int)addr;
                     89:
                     90:        /* Make sure the address is in the DVMA map. */
                     91:        if ((va < DVMA_BASE) || (va >= (DVMA_BASE + DVMA_MAPLEN)))
                     92:                panic("dvma_mapout");
                     93:
                     94:        va -= DVMA_BASE - SA_MIN_VA;
                     95:
                     96:        return ((char *)va);
                     97: }
                     98:
                     99: extern char *alloc(int);
                    100:
                    101: char *
                    102: dvma_alloc(int len)
                    103: {
                    104:        char *mem;
                    105:
                    106:        mem = alloc(len);
                    107:        if (!mem)
                    108:                return (mem);
                    109:        return (dvma_mapin(mem, len));
                    110: }
                    111:
                    112: extern void free(void *ptr, int len);
                    113: void
                    114: dvma_free(char *dvma, int len)
                    115: {
                    116:        char *mem;
                    117:
                    118:        mem = dvma_mapout(dvma, len);
                    119:        if (mem)
                    120:                free(mem, len);
                    121: }

CVSweb