1 /* $NetBSD: dvma.c,v 1.14 2006/07/13 20:03:34 uwe Exp $ */
3 * Copyright (c) 1995 Gordon W. Ross
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 * The easiest way to deal with the need for DVMA mappings is to just
29 * map the entire megabyte of RAM where we are loaded into DVMA space.
30 * That way, dvma_mapin can just compute the DVMA alias address, and
31 * dvma_mapout does nothing. Note that this assumes all standalone
32 * programs stay in the range `base_va' .. `base_va + DVMA_MAPLEN'
35 #include <sys/param.h>
36 #include <sparc/sparc/asm.h>
37 #include <machine/pte.h>
38 #include <machine/ctlreg.h>
40 #include <lib/libsa/stand.h>
41 #include <sparc/stand/common/promdev.h>
43 #define DVMA_BASE 0xFFF00000
44 #define DVMA_MAPLEN 0xE0000 /* 1 MB - 128K (save MONSHORTSEG) */
49 * This module is only used on sun4, so:
51 #define getsegmap(va) (lduha(va, ASI_SEGMAP))
52 #define setsegmap(va, pmeg) do stha(va, ASI_SEGMAP, pmeg); while(0)
62 * Align our address base with the DVMA segment.
63 * Allocate one DVMA segment to cover the stack, which
64 * grows downward from `start'.
67 base_va
= segva
= (((int)&start
) & -NBPSG
) - NBPSG
;
69 /* Then double-map the DVMA addresses */
70 nseg
= (DVMA_MAPLEN
+ NBPSG
- 1) >> SGSHIFT
;
72 setsegmap(dmava
, getsegmap(segva
));
79 * Convert a local address to a DVMA address.
82 dvma_mapin(char *addr
, size_t len
)
89 /* Make sure the address is in the DVMA map. */
90 if (va
< 0 || va
>= DVMA_MAPLEN
)
91 panic("dvma_mapin: va %x (DMA base %x)", va
+base_va
, base_va
);
100 * Convert a DVMA address to a local address.
103 dvma_mapout(char *addr
, size_t len
)
110 /* Make sure the address is in the DVMA map. */
111 if (va
< 0 || va
>= DVMA_MAPLEN
)
112 panic("dvma_mapout: va %x (DMA base %x)", va
+base_va
, base_va
);
128 return (dvma_mapin(mem
, len
));
132 dvma_free(char *dvma
, int len
)
136 mem
= dvma_mapout(dvma
, len
);