1 //
2 // mmu.c - MMU related functions
3 //
4 // $Id: //depot/rel/Foxhill/dot.8/Xtensa/OS/hal/mmu.c#1 $
5
6 // Copyright (c) 2002, 2008 Tensilica Inc.
7 //
8 // Permission is hereby granted, free of charge, to any person obtaining
9 // a copy of this software and associated documentation files (the
10 // "Software"), to deal in the Software without restriction, including
11 // without limitation the rights to use, copy, modify, merge, publish,
12 // distribute, sublicense, and/or sell copies of the Software, and to
13 // permit persons to whom the Software is furnished to do so, subject to
14 // the following conditions:
15 //
16 // The above copyright notice and this permission notice shall be included
17 // in all copies or substantial portions of the Software.
18 //
19 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
22 // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
23 // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24 // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25 // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26
27 #include <xtensa/config/core.h>
28
29 /*
30 * Convert a virtual address to a physical address
31 * (through static maps only).
32 * Returns 0 if successful (*paddrp is set), -1 if not (no mapping).
33 */
xthal_static_v2p(unsigned vaddr,unsigned * paddrp)34 int xthal_static_v2p( unsigned vaddr, unsigned *paddrp /*, unsigned len, unsigned rasid*/ )
35 {
36 #if XCHAL_HAVE_PTP_MMU && !XCHAL_HAVE_SPANNING_WAY
37 if( vaddr >= XCHAL_KSEG_CACHED_VADDR
38 && vaddr <= XCHAL_KSEG_CACHED_VADDR + XCHAL_KSEG_CACHED_SIZE )
39 vaddr += XCHAL_KSEG_CACHED_PADDR - XCHAL_KSEG_CACHED_VADDR;
40 else if( vaddr >= XCHAL_KSEG_BYPASS_VADDR
41 && vaddr <= XCHAL_KSEG_BYPASS_VADDR + XCHAL_KSEG_BYPASS_SIZE )
42 vaddr += XCHAL_KSEG_BYPASS_PADDR - XCHAL_KSEG_BYPASS_VADDR;
43 else if( vaddr >= XCHAL_KIO_CACHED_VADDR
44 && vaddr <= XCHAL_KIO_CACHED_VADDR + XCHAL_KIO_CACHED_SIZE )
45 vaddr += XCHAL_KIO_CACHED_PADDR - XCHAL_KIO_CACHED_VADDR;
46 else if( vaddr >= XCHAL_KIO_BYPASS_VADDR
47 && vaddr <= XCHAL_KIO_BYPASS_VADDR + XCHAL_KIO_BYPASS_SIZE )
48 vaddr += XCHAL_KIO_BYPASS_PADDR - XCHAL_KIO_BYPASS_VADDR;
49 else
50 return( -1 ); /* no known mapping */
51 #endif /* XCHAL_HAVE_PTP_MMU && !XCHAL_HAVE_SPANNING_WAY */
52 *paddrp = vaddr; /* virtual == physical */
53 return( 0 );
54 }
55
56 /*
57 * Convert a physical address to a virtual address
58 * (through static maps only).
59 * Returns 0 if successful (*vaddrp is set), -1 if not (no mapping).
60 *
61 * NOTE: A physical address can be mapped from multiple virtual addresses
62 * (or one or none).
63 * There should be better parameter(s) to help select the mapping returned
64 * (eg. cache mode, address, asid, etc), or somehow return them all.
65 * Mappings returned currently assume the current RASID setting.
66 */
xthal_static_p2v(unsigned paddr,unsigned * vaddrp,unsigned cached)67 int xthal_static_p2v( unsigned paddr, unsigned *vaddrp, /*unsigned len, unsigned rasid,*/ unsigned cached )
68 {
69 #if XCHAL_HAVE_PTP_MMU && !XCHAL_HAVE_SPANNING_WAY
70 if( cached ) {
71 if( paddr >= XCHAL_KSEG_CACHED_PADDR
72 && paddr <= XCHAL_KSEG_CACHED_PADDR + XCHAL_KSEG_CACHED_SIZE )
73 paddr += XCHAL_KSEG_CACHED_VADDR - XCHAL_KSEG_CACHED_PADDR;
74 else if( paddr >= XCHAL_KIO_BYPASS_PADDR
75 && paddr <= XCHAL_KIO_BYPASS_PADDR + XCHAL_KIO_BYPASS_SIZE )
76 paddr += XCHAL_KIO_BYPASS_VADDR - XCHAL_KIO_BYPASS_PADDR;
77 else
78 return -1; /* no known mapping */
79 } else {
80 if( paddr >= XCHAL_KSEG_BYPASS_PADDR
81 && paddr <= XCHAL_KSEG_BYPASS_PADDR + XCHAL_KSEG_BYPASS_SIZE )
82 paddr += XCHAL_KSEG_BYPASS_VADDR - XCHAL_KSEG_BYPASS_PADDR;
83 else if( paddr >= XCHAL_KIO_CACHED_PADDR
84 && paddr <= XCHAL_KIO_CACHED_PADDR + XCHAL_KIO_CACHED_SIZE )
85 paddr += XCHAL_KIO_CACHED_VADDR - XCHAL_KIO_CACHED_PADDR;
86 else
87 return -1; /* no known mapping */
88 }
89 #endif /* XCHAL_HAVE_PTP_MMU && !XCHAL_HAVE_SPANNING_WAY */
90 *vaddrp = paddr; /* virtual == physical */
91 return( 0 );
92 }
93
94