gem5
[DEVELOP-FOR-25.0]
Loading...
Searching...
No Matches
arch
arm
stage2_lookup.cc
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2010-2013, 2016, 2018, 2024 Arm Limited
3
* All rights reserved
4
*
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.
13
*
14
* Redistribution and use in source and binary forms, with or without
15
* modification, are permitted provided that the following conditions are
16
* met: redistributions of source code must retain the above copyright
17
* notice, this list of conditions and the following disclaimer;
18
* redistributions in binary form must reproduce the above copyright
19
* notice, this list of conditions and the following disclaimer in the
20
* documentation and/or other materials provided with the distribution;
21
* neither the name of the copyright holders nor the names of its
22
* contributors may be used to endorse or promote products derived from
23
* this software without specific prior written permission.
24
*
25
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36
*/
37
38
#include "
arch/arm/stage2_lookup.hh
"
39
40
#include "
arch/arm/faults.hh
"
41
#include "
arch/arm/system.hh
"
42
#include "
arch/arm/table_walker.hh
"
43
#include "
arch/arm/tlb.hh
"
44
#include "
cpu/base.hh
"
45
#include "
cpu/thread_context.hh
"
46
#include "debug/Checkpoint.hh"
47
#include "debug/TLB.hh"
48
#include "debug/TLBVerbose.hh"
49
#include "
sim/system.hh
"
50
51
namespace
gem5
52
{
53
54
using namespace
ArmISA
;
55
56
Fault
57
Stage2LookUp::getTe
(
ThreadContext
*tc,
TlbEntry
*destTe)
58
{
59
fault
=
mmu
->getTE(&
stage2Te
,
req
, tc,
mode
,
this
,
timing
,
60
functional
,
ss
,
ipaSpace
,
tranType
,
true
);
61
62
// Call finish if we're done already
63
if
((
fault
!=
NoFault
) || (
stage2Te
!= NULL)) {
64
// Since we directly requested the table entry (which we need later on
65
// to merge the attributes) then we've skipped some stage2 permissions
66
// checking. So call translate on stage 2 to do the checking. As the
67
// entry is now in the TLB this should always hit the cache.
68
if
(
fault
==
NoFault
) {
69
if
(
ELIs64
(tc,
EL2
))
70
fault
=
mmu
->checkPermissions64(
stage2Te
,
req
,
mode
, tc,
true
);
71
else
72
fault
=
mmu
->checkPermissions(
stage2Te
,
req
,
mode
,
true
);
73
}
74
75
mergeTe
(
mode
);
76
*destTe =
stage1Te
;
77
}
78
return
fault
;
79
}
80
81
void
82
Stage2LookUp::mergeTe
(
BaseMMU::Mode
mode
)
83
{
84
// Check again that we haven't got a fault
85
if
(
fault
==
NoFault
) {
86
assert(
stage2Te
!= NULL);
87
88
// Now we have the table entries for both stages of translation
89
// merge them and insert the result into the stage 1 TLB. See
90
// CombineS1S2Desc() in pseudocode
91
stage1Te
.nonCacheable |=
stage2Te
->nonCacheable;
92
stage1Te
.xn |=
stage2Te
->xn;
93
94
if
(
stage1Te
.size >
stage2Te
->size) {
95
// Size mismatch also implies vpn mismatch (this is shifted by
96
// sizebits!).
97
stage1Te
.vpn =
s1Req
->getVaddr() >>
stage2Te
->N;
98
stage1Te
.pfn =
stage2Te
->pfn;
99
stage1Te
.size =
stage2Te
->size;
100
stage1Te
.N =
stage2Te
->N;
101
}
else
if
(
stage1Te
.size <
stage2Te
->size) {
102
// Guest 4K could well be section-backed by host hugepage! In this
103
// case a 4K entry is added but pfn needs to be adjusted. New PFN =
104
// offset into section PFN given by stage2 IPA treated as a stage1
105
// page size.
106
const
Addr
pa
= (
stage2Te
->pfn <<
stage2Te
->N);
107
const
Addr
ipa = (
stage1Te
.pfn <<
stage1Te
.N);
108
stage1Te
.pfn = (
pa
| (ipa &
mask
(
stage2Te
->N))) >>
stage1Te
.N;
109
// Size remains smaller of the two.
110
}
else
{
111
// Matching sizes
112
stage1Te
.pfn =
stage2Te
->pfn;
113
}
114
115
if
(
stage2Te
->mtype ==
TlbEntry::MemoryType::StronglyOrdered
||
116
stage1Te
.mtype ==
TlbEntry::MemoryType::StronglyOrdered
) {
117
stage1Te
.mtype =
TlbEntry::MemoryType::StronglyOrdered
;
118
}
else
if
(
stage2Te
->mtype ==
TlbEntry::MemoryType::Device
||
119
stage1Te
.mtype ==
TlbEntry::MemoryType::Device
) {
120
stage1Te
.mtype =
TlbEntry::MemoryType::Device
;
121
}
else
{
122
stage1Te
.mtype =
TlbEntry::MemoryType::Normal
;
123
}
124
125
if
(
stage1Te
.mtype ==
TlbEntry::MemoryType::Normal
) {
126
127
if
(
stage2Te
->innerAttrs == 0 ||
128
stage1Te
.innerAttrs == 0) {
129
// either encoding Non-cacheable
130
stage1Te
.innerAttrs = 0;
131
}
else
if
(
stage2Te
->innerAttrs == 2 ||
132
stage1Te
.innerAttrs == 2) {
133
// either encoding Write-Through cacheable
134
stage1Te
.innerAttrs = 2;
135
}
else
{
136
// both encodings Write-Back
137
stage1Te
.innerAttrs = 3;
138
}
139
140
if
(
stage2Te
->outerAttrs == 0 ||
141
stage1Te
.outerAttrs == 0) {
142
// either encoding Non-cacheable
143
stage1Te
.outerAttrs = 0;
144
}
else
if
(
stage2Te
->outerAttrs == 2 ||
145
stage1Te
.outerAttrs == 2) {
146
// either encoding Write-Through cacheable
147
stage1Te
.outerAttrs = 2;
148
}
else
{
149
// both encodings Write-Back
150
stage1Te
.outerAttrs = 3;
151
}
152
153
stage1Te
.shareable |=
stage2Te
->shareable;
154
stage1Te
.outerShareable |=
stage2Te
->outerShareable;
155
if
(
stage1Te
.innerAttrs == 0 &&
156
stage1Te
.outerAttrs == 0) {
157
// something Non-cacheable at each level is outer shareable
158
stage1Te
.shareable =
true
;
159
stage1Te
.outerShareable =
true
;
160
}
161
}
else
{
162
stage1Te
.shareable =
true
;
163
stage1Te
.outerShareable =
true
;
164
}
165
166
if
(
stage1Te
.mtype ==
TlbEntry::MemoryType::Normal
&&
167
stage1Te
.innerAttrs == 3 &&
168
stage1Te
.outerAttrs == 3) {
169
stage1Te
.xs =
false
;
170
}
else
{
171
stage1Te
.xs =
stage1Te
.xs &&
stage2Te
->xs;
172
}
173
stage1Te
.updateAttributes();
174
}
175
176
// if there's a fault annotate it,
177
if
(
fault
!=
NoFault
) {
178
// If the second stage of translation generated a fault add the
179
// details of the original stage 1 virtual address
180
if
(
auto
arm_fault =
reinterpret_cast<
ArmFault
*
>
(
fault
.get())) {
181
arm_fault->annotate(
ArmFault::OVA
,
s1Req
->getVaddr());
182
}
183
}
184
complete
=
true
;
185
}
186
187
void
188
Stage2LookUp::finish
(
const
Fault
&_fault,
const
RequestPtr
&
req
,
189
ThreadContext
*tc,
BaseMMU::Mode
mode
)
190
{
191
fault
= _fault;
192
// if we haven't got the table entry get it now
193
if
((
fault
==
NoFault
) && (
stage2Te
== NULL)) {
194
// OLD_LOOK: stage2Tlb
195
fault
=
mmu
->getTE(&
stage2Te
,
req
, tc,
mode
,
this
,
196
timing
,
functional
,
ss
,
ipaSpace
,
tranType
,
true
);
197
}
198
199
// Now we have the stage 2 table entry we need to merge it with the stage
200
// 1 entry we were given at the start
201
mergeTe
(
mode
);
202
203
if
(
fault
!=
NoFault
) {
204
// Returning with a fault requires the original request
205
transState
->finish(
fault
,
s1Req
, tc,
mode
);
206
}
else
if
(
timing
) {
207
// Now notify the original stage 1 translation that we finally have
208
// a result
209
// tran_s1.callFromStage2 = true;
210
// OLD_LOOK: stage1Tlb
211
mmu
->translateComplete(
212
s1Req
, tc,
transState
,
mode
,
tranType
,
true
);
213
}
214
// if we have been asked to delete ourselfs do it now
215
if
(
selfDelete
) {
216
delete
this
;
217
}
218
}
219
220
}
// namespace gem5
faults.hh
system.hh
tlb.hh
gem5::ArmISA::ArmFault
Definition
faults.hh:65
gem5::ArmISA::ArmFault::OVA
@ OVA
Definition
faults.hh:135
gem5::ArmISA::Stage2LookUp::complete
bool complete
Definition
stage2_lookup.hh:73
gem5::ArmISA::Stage2LookUp::mode
BaseMMU::Mode mode
Definition
stage2_lookup.hh:66
gem5::ArmISA::Stage2LookUp::transState
BaseMMU::Translation * transState
Definition
stage2_lookup.hh:65
gem5::ArmISA::Stage2LookUp::mmu
MMU * mmu
Definition
stage2_lookup.hh:62
gem5::ArmISA::Stage2LookUp::ipaSpace
PASpace ipaSpace
Definition
stage2_lookup.hh:76
gem5::ArmISA::Stage2LookUp::mergeTe
void mergeTe(BaseMMU::Mode mode)
Definition
stage2_lookup.cc:82
gem5::ArmISA::Stage2LookUp::s1Req
RequestPtr s1Req
Definition
stage2_lookup.hh:64
gem5::ArmISA::Stage2LookUp::ss
SecurityState ss
Definition
stage2_lookup.hh:75
gem5::ArmISA::Stage2LookUp::stage2Te
TlbEntry * stage2Te
Definition
stage2_lookup.hh:70
gem5::ArmISA::Stage2LookUp::stage1Te
TlbEntry stage1Te
Definition
stage2_lookup.hh:63
gem5::ArmISA::Stage2LookUp::timing
bool timing
Definition
stage2_lookup.hh:67
gem5::ArmISA::Stage2LookUp::req
RequestPtr req
Definition
stage2_lookup.hh:71
gem5::ArmISA::Stage2LookUp::functional
bool functional
Definition
stage2_lookup.hh:68
gem5::ArmISA::Stage2LookUp::tranType
MMU::ArmTranslationType tranType
Definition
stage2_lookup.hh:69
gem5::ArmISA::Stage2LookUp::fault
Fault fault
Definition
stage2_lookup.hh:72
gem5::ArmISA::Stage2LookUp::selfDelete
bool selfDelete
Definition
stage2_lookup.hh:74
gem5::ArmISA::Stage2LookUp::finish
void finish(const Fault &fault, const RequestPtr &req, ThreadContext *tc, BaseMMU::Mode mode)
Definition
stage2_lookup.cc:188
gem5::ArmISA::Stage2LookUp::getTe
Fault getTe(ThreadContext *tc, TlbEntry *destTe)
Definition
stage2_lookup.cc:57
gem5::BaseMMU::Mode
Mode
Definition
mmu.hh:56
gem5::ThreadContext
ThreadContext is the external interface to all thread state for anything outside of the CPU.
Definition
thread_context.hh:89
base.hh
thread_context.hh
gem5::ArmISA
Definition
decoder.cc:54
gem5::ArmISA::mask
Bitfield< 3, 0 > mask
Definition
pcstate.hh:63
gem5::ArmISA::EL2
@ EL2
Definition
types.hh:304
gem5::ArmISA::ELIs64
bool ELIs64(ThreadContext *tc, ExceptionLevel el)
Definition
utility.cc:277
gem5::ArmISA::pa
Bitfield< 39, 12 > pa
Definition
misc_types.hh:752
gem5
Copyright (c) 2024 Arm Limited All rights reserved.
Definition
binary32.hh:36
gem5::Fault
std::shared_ptr< FaultBase > Fault
Definition
types.hh:249
gem5::RequestPtr
std::shared_ptr< Request > RequestPtr
Definition
request.hh:94
gem5::Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition
types.hh:147
gem5::NoFault
constexpr decltype(nullptr) NoFault
Definition
types.hh:253
system.hh
stage2_lookup.hh
gem5::ArmISA::TlbEntry
Definition
pagetable.hh:233
gem5::ArmISA::TlbEntry::MemoryType::StronglyOrdered
@ StronglyOrdered
Definition
pagetable.hh:241
gem5::ArmISA::TlbEntry::MemoryType::Normal
@ Normal
Definition
pagetable.hh:243
gem5::ArmISA::TlbEntry::MemoryType::Device
@ Device
Definition
pagetable.hh:242
table_walker.hh
Generated on Mon May 26 2025 09:18:58 for gem5 by
doxygen
1.13.2