gem5 v24.0.0.0
Loading...
Searching...
No Matches
mmu.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2011-2012,2016-2017, 2019-2021 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 * Copyright (c) 2002-2005 The Regents of The University of Michigan
15 * Copyright (c) 2011 Regents of the University of California
16 * Copyright (c) 2013 Advanced Micro Devices, Inc.
17 * Copyright (c) 2013 Mark D. Hill and David A. Wood
18 * All rights reserved.
19 *
20 * Redistribution and use in source and binary forms, with or without
21 * modification, are permitted provided that the following conditions are
22 * met: redistributions of source code must retain the above copyright
23 * notice, this list of conditions and the following disclaimer;
24 * redistributions in binary form must reproduce the above copyright
25 * notice, this list of conditions and the following disclaimer in the
26 * documentation and/or other materials provided with the distribution;
27 * neither the name of the copyright holders nor the names of its
28 * contributors may be used to endorse or promote products derived from
29 * this software without specific prior written permission.
30 *
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
36 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
37 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
38 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
39 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
40 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
41 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42 */
43
44#include "arch/generic/mmu.hh"
45#include "arch/generic/tlb.hh"
46#include "cpu/thread_context.hh"
47#include "sim/system.hh"
48
49namespace gem5
50{
51
52void
54{
55 auto traverse_hierarchy = [this](BaseTLB *starter) {
56 for (BaseTLB *tlb = starter; tlb; tlb = tlb->nextLevel()) {
57 switch (tlb->type()) {
58 case TypeTLB::instruction:
59 if (instruction.find(tlb) == instruction.end())
60 instruction.insert(tlb);
61 break;
62 case TypeTLB::data:
63 if (data.find(tlb) == data.end())
64 data.insert(tlb);
65 break;
66 case TypeTLB::unified:
67 if (unified.find(tlb) == unified.end())
68 unified.insert(tlb);
69 break;
70 default:
71 panic("Invalid TLB type\n");
72 }
73 }
74 };
75
76 traverse_hierarchy(itb);
77 traverse_hierarchy(dtb);
78}
79
80void
82{
83 for (auto tlb : instruction) {
84 tlb->flushAll();
85 }
86
87 for (auto tlb : data) {
88 tlb->flushAll();
89 }
90
91 for (auto tlb : unified) {
92 tlb->flushAll();
93 }
94}
95
96void
98{
99 itb->demapPage(vaddr, asn);
100 dtb->demapPage(vaddr, asn);
101}
102
103Fault
106{
107 return getTlb(mode)->translateAtomic(req, tc, mode);
108}
109
110void
113{
114 return getTlb(mode)->translateTiming(req, tc, translation, mode);
115}
116
117Fault
123
124Fault
126 BaseMMU::Mode mode) const
127{
128 return getTlb(mode)->finalizePhysical(req, tc, mode);
129}
130
132 Addr new_start, Addr new_size, ThreadContext *new_tc,
133 BaseMMU *new_mmu, BaseMMU::Mode new_mode, Request::Flags new_flags) :
134 TranslationGen(new_start, new_size), tc(new_tc), cid(tc->contextId()),
135 mmu(new_mmu), mode(new_mode), flags(new_flags),
136 pageBytes(page_bytes)
137{}
138
139void
141{
142 Addr next = roundUp(range.vaddr, pageBytes);
143 if (next == range.vaddr)
144 next += pageBytes;
145 range.size = std::min(range.size, next - range.vaddr);
146
147 auto req = std::make_shared<Request>(
148 range.vaddr, range.size, flags, Request::funcRequestorId, 0, cid);
149
150 range.fault = mmu->translateFunctional(req, tc, mode);
151
152 if (range.fault == NoFault) {
153 range.paddr = req->getPaddr();
154 range.flags = req->getFlags();
155 }
156}
157
158void
160{
161 Port *old_itb_port = old_mmu->itb->getTableWalkerPort();
162 Port *old_dtb_port = old_mmu->dtb->getTableWalkerPort();
163 Port *new_itb_port = itb->getTableWalkerPort();
164 Port *new_dtb_port = dtb->getTableWalkerPort();
165
166 // Move over any table walker ports if they exist
167 if (new_itb_port)
168 new_itb_port->takeOverFrom(old_itb_port);
169 if (new_dtb_port)
170 new_dtb_port->takeOverFrom(old_dtb_port);
171
172 itb->takeOverFrom(old_mmu->itb);
173 dtb->takeOverFrom(old_mmu->dtb);
174}
175
176} // namespace gem5
void translate(Range &range) const override
Subclasses implement this function to complete TranslationGen.
Definition mmu.cc:140
MMUTranslationGen(Addr page_bytes, Addr new_start, Addr new_size, ThreadContext *new_tc, BaseMMU *new_mmu, BaseMMU::Mode new_mode, Request::Flags new_flags)
Definition mmu.cc:131
std::set< BaseTLB * > instruction
It is possible from the MMU to traverse the entire hierarchy of TLBs, starting from the DTB and ITB (...
Definition mmu.hh:181
BaseTLB * getTlb(Mode mode) const
Definition mmu.hh:95
void init() override
Called at init time, this method is traversing the TLB hierarchy and pupulating the instruction/data/...
Definition mmu.cc:53
virtual void flushAll()
Definition mmu.cc:81
virtual Fault translateFunctional(const RequestPtr &req, ThreadContext *tc, Mode mode)
Definition mmu.cc:118
BaseTLB * itb
Definition mmu.hh:159
virtual void takeOverFrom(BaseMMU *old_mmu)
Definition mmu.cc:159
void demapPage(Addr vaddr, uint64_t asn)
Definition mmu.cc:97
std::set< BaseTLB * > data
Definition mmu.hh:182
virtual void translateTiming(const RequestPtr &req, ThreadContext *tc, Translation *translation, Mode mode)
Definition mmu.cc:111
std::set< BaseTLB * > unified
Definition mmu.hh:183
BaseTLB * dtb
Definition mmu.hh:158
virtual Fault translateAtomic(const RequestPtr &req, ThreadContext *tc, Mode mode)
Definition mmu.cc:104
virtual Fault finalizePhysical(const RequestPtr &req, ThreadContext *tc, Mode mode) const
Definition mmu.cc:125
BaseTLB * nextLevel() const
Definition tlb.hh:127
virtual Fault finalizePhysical(const RequestPtr &req, ThreadContext *tc, BaseMMU::Mode mode) const =0
Do post-translation physical address finalization.
virtual void translateTiming(const RequestPtr &req, ThreadContext *tc, BaseMMU::Translation *translation, BaseMMU::Mode mode)=0
virtual void takeOverFrom(BaseTLB *otlb)=0
Take over from an old tlb context.
virtual Port * getTableWalkerPort()
Get the table walker port if present.
Definition tlb.hh:121
virtual void demapPage(Addr vaddr, uint64_t asn)=0
virtual Fault translateAtomic(const RequestPtr &req, ThreadContext *tc, BaseMMU::Mode mode)=0
virtual Fault translateFunctional(const RequestPtr &req, ThreadContext *tc, BaseMMU::Mode mode)
Definition tlb.hh:78
Ports are used to interface objects to each other.
Definition port.hh:62
void takeOverFrom(Port *old)
A utility function to make it easier to swap out ports.
Definition port.hh:137
@ funcRequestorId
This requestor id is used for functional requests that don't come from a particular device.
Definition request.hh:279
ThreadContext is the external interface to all thread state for anything outside of the CPU.
TranslationGen is a base class for a generator object which returns information about address transla...
static constexpr T roundUp(const T &val, const U &align)
This function is used to align addresses in memory.
Definition intmath.hh:260
#define panic(...)
This implements a cprintf based panic() function.
Definition logging.hh:188
uint8_t flags
Definition helpers.cc:87
Bitfield< 4, 0 > mode
Definition misc_types.hh:74
Bitfield< 59, 56 > tlb
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
std::shared_ptr< FaultBase > Fault
Definition types.hh:249
std::shared_ptr< Request > RequestPtr
Definition request.hh:94
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition types.hh:147
constexpr decltype(nullptr) NoFault
Definition types.hh:253
This structure represents a single, contiguous translation, or carries information about whatever fau...

Generated on Tue Jun 18 2024 16:23:57 for gem5 by doxygen 1.11.0