2 * Copyright (c) 2010 ARM Limited
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software
9 * licensed hereunder. You may use the software subject to the license
10 * terms below provided that you ensure that this notice is replicated
11 * unmodified and in its entirety in all distributions of the software,
12 * modified or unmodified, in source code or in binary form.
14 * Copyright (c) 2002-2005 The Regents of The University of Michigan
15 * Copyright (c) 2007-2008 The Florida State University
16 * All rights reserved.
18 * Redistribution and use in source and binary forms, with or without
19 * modification, are permitted provided that the following conditions are
20 * met: redistributions of source code must retain the above copyright
21 * notice, this list of conditions and the following disclaimer;
22 * redistributions in binary form must reproduce the above copyright
23 * notice, this list of conditions and the following disclaimer in the
24 * documentation and/or other materials provided with the distribution;
25 * neither the name of the copyright holders nor the names of its
26 * contributors may be used to endorse or promote products derived from
27 * this software without specific prior written permission.
29 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
30 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
31 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
32 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
33 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
34 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
35 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
36 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
37 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
39 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
48 #include "arch/arm/table_walker.hh"
49 #include "arch/arm/tlb.hh"
50 #include "arch/arm/vtophys.hh"
51 #include "base/chunk_generator.hh"
52 #include "base/trace.hh"
53 #include "cpu/thread_context.hh"
54 #include "mem/fs_translating_port_proxy.hh"
57 using namespace ArmISA
;
60 ArmISA::vtophys(Addr vaddr
)
62 fatal("VTOPHYS: Can't convert vaddr to paddr on ARM without a thread context");
66 ArmISA::vtophys(ThreadContext
*tc
, Addr addr
)
68 SCTLR sctlr
= tc
->readMiscReg(MISCREG_SCTLR
);
70 // Translation is currently disabled PA == VA
77 // Check the TLBs far a translation
78 // It's possible that there is a validy translation in the tlb
79 // that is no loger valid in the page table in memory
80 // so we need to check here first
81 tlb
= static_cast<ArmISA::TLB
*>(tc
->getDTBPtr());
82 success
= tlb
->translateFunctional(tc
, addr
, pa
);
86 tlb
= static_cast<ArmISA::TLB
*>(tc
->getITBPtr());
87 success
= tlb
->translateFunctional(tc
, addr
, pa
);
91 // We've failed everything, so we need to do a
92 // hardware tlb walk without messing with any
95 uint32_t N
= tc
->readMiscReg(MISCREG_TTBCR
);
97 if (N
== 0 || !mbits(addr
, 31, 32-N
)) {
98 ttbr
= tc
->readMiscReg(MISCREG_TTBR0
);
100 ttbr
= tc
->readMiscReg(MISCREG_TTBR1
);
104 PortProxy
&port
= tc
->getPhysProxy();
105 Addr l1desc_addr
= mbits(ttbr
, 31, 14-N
) | (bits(addr
,31-N
,20) << 2);
107 TableWalker::L1Descriptor l1desc
;
108 l1desc
.data
= port
.read
<uint32_t>(l1desc_addr
);
109 if (l1desc
.type() == TableWalker::L1Descriptor::Ignore
||
110 l1desc
.type() == TableWalker::L1Descriptor::Reserved
) {
111 warn("Unable to translate virtual address: %#x\n", addr
);
114 if (l1desc
.type() == TableWalker::L1Descriptor::Section
)
115 return l1desc
.paddr(addr
);
117 // Didn't find it at the first level, try againt
118 Addr l2desc_addr
= l1desc
.l2Addr() | (bits(addr
, 19, 12) << 2);
119 TableWalker::L2Descriptor l2desc
;
120 l2desc
.data
= port
.read
<uint32_t>(l2desc_addr
);
122 if (l2desc
.invalid()) {
123 warn("Unable to translate virtual address: %#x\n", addr
);
127 return l2desc
.paddr(addr
);
131 ArmISA::virtvalid(ThreadContext
*tc
, Addr vaddr
)
133 if (vtophys(tc
, vaddr
) != -1)