41#include "debug/SMMUv3.hh"
42#include "debug/SMMUv3Hazard.hh"
51using namespace ArmISA;
61 pkt->
req->substreamId() : 0;
126 assert(!
"Stalls are broken");
131 DPRINTF(
SMMUv3,
"Resume at tick = %d. Fault duration = %d (%.3fus)\n",
153 panic(
"Transaction crosses 4k boundary (addr=%#x size=%#x)!\n",
175 bool wasPrefetched =
false;
267 bool haveConfig =
true;
328 DPRINTF(
SMMUv3,
"micro TLB miss vaddr=%#x sid=%#x ssid=%#x\n",
335 "micro TLB hit vaddr=%#x amask=%#x sid=%#x ssid=%#x paddr=%#x\n",
361 "RESPONSE Interface TLB miss vaddr=%#x sid=%#x ssid=%#x\n",
368 "RESPONSE Interface TLB hit vaddr=%#x amask=%#x sid=%#x ssid=%#x "
376 wasPrefetched =
e->prefetched;
394 DPRINTF(
SMMUv3,
"SMMU TLB miss vaddr=%#x asid=%#x vmid=%#x\n",
401 "SMMU TLB hit vaddr=%#x amask=%#x asid=%#x vmid=%#x paddr=%#x\n",
423 e.prefetched =
false;
428 e.pa = tr.
addr &
e.vaMask;
436 "micro TLB upd vaddr=%#x amask=%#x paddr=%#x sid=%#x ssid=%#x\n",
437 e.va,
e.vaMask,
e.pa,
e.sid,
e.ssid);
460 e.pa = tr.
addr &
e.vaMask;
473 "RESPONSE Interface upd vaddr=%#x amask=%#x paddr=%#x sid=%#x "
474 "ssid=%#x\n",
e.va,
e.vaMask,
e.pa,
e.sid,
e.ssid);
496 e.pa = tr.
addr &
e.vaMask;
502 "SMMU TLB upd vaddr=%#x amask=%#x paddr=%#x asid=%#x vmid=%#x\n",
503 e.va,
e.vaMask,
e.pa,
e.asid,
e.vmid);
529 DPRINTF(
SMMUv3,
"Config hit sid=%#x ssid=%#x ttb=%#08x asid=%#x\n",
611 panic(
"Bad or unimplemented STE config %d\n",
624 tc.
httb = 0xdeadbeef;
642 tc.
ttb0 = 0xcafebabe;
643 tc.
ttb1 = 0xcafed00d;
657 unsigned stage,
unsigned level)
659 const char *indent = stage==2 ?
" " :
"";
662 const auto tg = stage == 1 ?
668 unsigned walkCacheLevels =
673 if ((1 <<
level) & walkCacheLevels) {
682 "base=%#x (S%d, L%d)\n",
697 unsigned stage,
unsigned level,
698 bool leaf, uint8_t permissions)
700 unsigned walkCacheLevels =
714 e.permissions = permissions;
718 DPRINTF(
SMMUv3,
"%sWalkCache upd va=%#x mask=%#x asid=%#x vmid=%#x "
719 "tpa=%#x leaf=%s (S%d, L%d)\n",
720 e.stage==2 ?
" " :
"",
721 e.va,
e.vaMask,
e.asid,
e.vmid,
722 e.pa,
e.leaf,
e.stage,
e.level);
756 level, pte, pte_addr);
803 tr.
addr = walkPtr + (
addr & ~tr.addrMask);
843 level, pte, pte_addr);
883 tr.
addr = walkPtr + (
addr & ~tr.addrMask);
900 for (
level = pt_ops->lastLevel() + 1;
918 tr.
addr = walk_ep->
pa + (
addr & ~walk_ep->vaMask);
932 table_addr = s2tr.
addr;
963 tr.
addr = ipa_ep->
pa + (
addr & ~ipa_ep->ipaMask);
982 for (
level = pt_ops->lastLevel() + 1;
1001 tr.
addr = walk_ep->
pa + (
addr & ~walk_ep->vaMask);
1022 e.ipa =
addr &
e.ipaMask;
1062 Addr other4k = (*it)->request.addr & ~0xfffULL;
1063 if (addr4k == other4k)
1073 DPRINTF(SMMUv3Hazard,
"4kReg: p=%p a4k=%#x\n",
1087 found_hazard =
false;
1093 Addr other4k = (*it)->request.addr & ~0xfffULL;
1095 DPRINTF(SMMUv3Hazard,
"4kHold: p=%p a4k=%#x Q: p=%p a4k=%#x\n",
1096 this, addr4k, *it, other4k);
1098 if (addr4k == other4k) {
1100 "4kHold: p=%p a4k=%#x WAIT on p=%p a4k=%#x\n",
1101 this, addr4k, *it, other4k);
1105 DPRINTF(SMMUv3Hazard,
"4kHold: p=%p a4k=%#x RESUME\n",
1110 found_hazard =
true;
1114 }
while (found_hazard);
1120 DPRINTF(SMMUv3Hazard,
"4kRel: p=%p a4k=%#x\n",
1130 panic(
"hazard4kRelease: request not found");
1142 DPRINTF(SMMUv3Hazard,
"IdReg: p=%p oid=%d\n",
this, orderId);
1149 depReqs.push_back(
this);
1157 DPRINTF(SMMUv3Hazard,
"IdHold: p=%p oid=%d\n",
this, orderId);
1167 found_hazard =
false;
1169 for (
auto it = depReqs.begin(); it!=depReqs.end() && *it!=
this; ++it) {
1170 DPRINTF(SMMUv3Hazard,
"IdHold: p=%p oid=%d Q: %p\n",
1171 this, orderId, *it);
1174 DPRINTF(SMMUv3Hazard,
"IdHold: p=%p oid=%d WAIT on=%p\n",
1175 this, orderId, *it);
1179 DPRINTF(SMMUv3Hazard,
"IdHold: p=%p oid=%d RESUME\n",
1184 found_hazard =
true;
1188 }
while (found_hazard);
1196 DPRINTF(SMMUv3Hazard,
"IdRel: p=%p oid=%d\n",
this, orderId);
1203 for (it = depReqs.begin(); it != depReqs.end(); ++it) {
1208 if (it == depReqs.end())
1209 panic(
"hazardIdRelease: request not found");
1238 DPRINTF(
SMMUv3,
"Translation Fault (addr=%#x, size=%#x, sid=%d, ssid=%d, "
1239 "isWrite=%d, isPrefetch=%d, isAtsRequest=%d)\n",
1260 panic(
"Not in atomic or timing mode");
1309 panic(
"Not in atomic or timing mode");
1320 a.pkt->req->setPaddr(tr.
addr);
1363 event.data.dw1.nsipa =
true;
1380 if (((
smmu.
regs.eventq_prod+1) & sizeMask) ==
1381 (
smmu.
regs.eventq_cons & sizeMask))
1382 panic(
"Event queue full - aborting\n");
1388 DPRINTF(
SMMUv3,
"Sending event to addr=%#08x (pos=%d): %s\n",
1391 bool empty_queue = (
smmu.
regs.eventq_prod & sizeMask) ==
1392 (
smmu.
regs.eventq_cons & sizeMask);
1401 if (IRQCtrl irq_ctrl =
smmu.
regs.irq_ctrl;
1402 irq_ctrl.eventqIrqEn && empty_queue) {
1416 if (IDR0 idr0 =
smmu.
regs.idr0; idr0.msi && msi_addr != 0) {
1434 panic(
"SID %#x out of range, max=%#x", sid, max_sid);
1442 if (split!= 7 && split!=8 && split!=16)
1443 panic(
"Invalid stream table split %d", split);
1448 bits(sid, 32, split) *
sizeof(l2_ptr);
1452 doReadConfig(yield, l2_addr, &l2_ptr,
sizeof(l2_ptr), sid, 0);
1454 DPRINTF(
SMMUv3,
"Got L1STE L1 at %#x: 0x%016x\n", l2_addr, l2_ptr);
1458 panic(
"Invalid level 1 stream table descriptor");
1462 panic(
"StreamID %d out of level 1 descriptor range %d",
1473 panic(
"Invalid stream table format");
1478 doReadConfig(yield, ste_addr, &ste,
sizeof(ste), sid, 0);
1480 DPRINTF(
SMMUv3,
"Got STE at %#x [0]: 0x%016x\n", ste_addr, ste.dw0);
1481 DPRINTF(
SMMUv3,
" STE at %#x [1]: 0x%016x\n", ste_addr, ste.dw1);
1482 DPRINTF(
SMMUv3,
" STE at %#x [2]: 0x%016x\n", ste_addr, ste.dw2);
1483 DPRINTF(
SMMUv3,
" STE at %#x [3]: 0x%016x\n", ste_addr, ste.dw3);
1490 panic(
"STE @ %#x not valid\n", ste_addr);
1499 uint32_t sid, uint32_t ssid)
1507 unsigned max_ssid = 1 << ste.dw0.
s1cdmax;
1508 if (ssid >= max_ssid)
1509 panic(
"SSID %#x out of range, max=%#x", ssid, max_ssid);
1518 bits(ssid, 24, split) *
sizeof(l2_ptr);
1532 doReadConfig(yield, l2_addr, &l2_ptr,
sizeof(l2_ptr), sid, ssid);
1534 DPRINTF(
SMMUv3,
"Got L1CD at %#x: 0x%016x\n", l2_addr, l2_ptr);
1536 cd_addr = l2_ptr +
bits(ssid, split-1, 0) *
sizeof(
cd);
1569 panic(
"CD @ %#x not valid\n", cd_addr);
1577 void *ptr,
size_t size,
1578 uint32_t sid, uint32_t ssid)
1585 void *ptr,
unsigned stage,
Base class for ARM GIC implementations.
void store(const Entry &incoming)
const Entry * lookup(Addr va, uint16_t asid, uint16_t vmid, bool updStats=true)
virtual void raise()=0
Signal an interrupt.
Tick clockEdge(Cycles cycles=Cycles(0)) const
Determine the tick when a cycle begins, by default the current one, but the argument also enables the...
const Entry * lookup(uint32_t sid, uint32_t ssid, bool updStats=true)
void store(const Entry &incoming)
CallerType: A reference to an object of this class will be passed to the coroutine task.
Cycles is a wrapper class for representing cycle counts, i.e.
void store(const Entry &incoming)
const Entry * lookup(Addr ipa, uint16_t vmid, bool updStats=true)
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
void makeTimingResponse()
void setAddr(Addr _addr)
Update the address of this packet mid-transaction.
RequestPtr req
A pointer to the original request.
void makeAtomicResponse()
const std::string name() const
void doWrite(Yield &yield, Addr addr, const void *ptr, size_t size)
void doDelay(Yield &yield, Cycles cycles)
void doSemaphoreUp(SMMUSemaphore &sem)
void scheduleWakeup(Tick when)
void doBroadcastSignal(SMMUSignal &sig)
void doSemaphoreDown(Yield &yield, SMMUSemaphore &sem)
void doWaitForSignal(Yield &yield, SMMUSignal &sig)
void doRead(Yield &yield, Addr addr, void *ptr, size_t size)
void store(const Entry &incoming, AllocPolicy alloc)
const Entry * lookup(uint32_t sid, uint32_t ssid, Addr va, bool updStats=true)
bool ifcTLBLookup(Yield &yield, TranslResult &tr, bool &wasPrefetched)
void configCacheUpdate(Yield &yield, const TranslContext &tc)
TranslResult translateStage1And2(Yield &yield, Addr addr)
void smmuTLBUpdate(Yield &yield, const TranslResult &tr)
SMMUTranslationProcess(const std::string &name, SMMUv3 &_smmu, SMMUv3DeviceInterface &_ifc)
TranslResult smmuTranslation(Yield &yield)
SMMUTranslRequest request
TranslResult bypass(Addr addr) const
void beginTransaction(const SMMUTranslRequest &req)
bool findConfig(Yield &yield, TranslContext &tc, TranslResult &tr)
void walkCacheLookup(Yield &yield, const WalkCache::Entry *&walkEntry, Addr addr, uint16_t asid, uint16_t vmid, unsigned stage, unsigned level)
bool smmuTLBLookup(Yield &yield, TranslResult &tr)
virtual void main(Yield &yield)
void abortTransaction(Yield &yield, const TranslResult &tr)
SMMUEvent generateEvent(const TranslResult &tr)
virtual ~SMMUTranslationProcess()
void hazardIdRegister()
Used to force ordering on transactions with the same orderId.
TranslResult walkStage2(Yield &yield, Addr addr, bool final_tr, const ArmISA::PageTableOps *pt_ops, unsigned level, Addr walkPtr)
TranslResult translateStage2(Yield &yield, Addr addr, bool final_tr)
void doReadConfig(Yield &yield, Addr addr, void *ptr, size_t size, uint32_t sid, uint32_t ssid)
void hazard4kHold(Yield &yield)
void doReadSTE(Yield &yield, StreamTableEntry &ste, uint32_t sid)
void hazardIdHold(Yield &yield)
void issuePrefetch(Addr addr)
SMMUv3DeviceInterface & ifc
bool microTLBLookup(Yield &yield, TranslResult &tr)
bool configCacheLookup(Yield &yield, TranslContext &tc)
TranslResult doReadCD(Yield &yield, ContextDescriptor &cd, const StreamTableEntry &ste, uint32_t sid, uint32_t ssid)
bool hazard4kCheck()
Used to force ordering on transactions with same (SID, SSID, 4k page) to avoid multiple identical pag...
void ifcTLBUpdate(Yield &yield, const TranslResult &tr)
TranslResult walkStage1And2(Yield &yield, Addr addr, const ArmISA::PageTableOps *pt_ops, unsigned level, Addr walkPtr)
void sendEvent(Yield &yield, const SMMUEvent &ev)
void microTLBUpdate(Yield &yield, const TranslResult &tr)
void doReadPTE(Yield &yield, Addr va, Addr addr, void *ptr, unsigned stage, unsigned level)
void walkCacheUpdate(Yield &yield, Addr va, Addr vaMask, Addr pa, unsigned stage, unsigned level, bool leaf, uint8_t permissions)
void completePrefetch(Yield &yield)
GEM5_CLASS_VAR_USED Tick faultTick
TranslResult combineTranslations(const TranslResult &s1tr, const TranslResult &s2tr) const
void completeTransaction(Yield &yield, const TranslResult &tr)
void sendEventInterrupt(Yield &yield)
std::list< SMMUTranslationProcess * > dependentReads[SMMU_MAX_TRANS_ID]
SMMUSignal duplicateReqRemoved
const bool prefetchReserveLastWay
const bool microTLBEnable
const bool prefetchEnable
std::list< SMMUTranslationProcess * > dependentWrites[SMMU_MAX_TRANS_ID]
SMMUSemaphore microTLBSem
unsigned wrBufSlotsRemaining
unsigned pendingMemAccesses
unsigned xlateSlotsRemaining
SMMUSemaphore devicePortSem
SMMUSignal dependentReqRemoved
std::list< SMMUTranslationProcess * > duplicateReqs
const bool ipaCacheEnable
const unsigned requestPortWidth
gem5::SMMUv3::SMMUv3Stats stats
SMMUSemaphore requestPortSem
const bool configCacheEnable
ArmInterruptPin *const eventqInterrupt
const bool walkCacheNonfinalEnable
const unsigned walkCacheS1Levels
const bool walkCacheEnable
void scheduleDeviceRetries()
const unsigned walkCacheS2Levels
SMMUAction runProcessTiming(SMMUProcess *proc, PacketPtr pkt)
bool isAtomicMode() const
Is the system in atomic mode?
bool isTimingMode() const
Is the system in timing mode?
void store(const Entry &incoming)
const Entry * lookup(Addr va, Addr vaMask, uint16_t asid, uint16_t vmid, unsigned stage, unsigned level, bool updStats=true)
void sample(const U &v, int n=1)
Add a value to the distribtion n times.
constexpr T bits(T val, unsigned first, unsigned last)
Extract the bitfield from position 'first' to 'last' (inclusive) from 'val' and right justify it.
std::enable_if_t<!std::is_same_v< T, void >, T > get()
get() is the way we can extrapolate arguments from the coroutine caller.
void signalDrainDone() const
Signal that an object is drained.
#define panic(...)
This implements a cprintf based panic() function.
static OrderID orderId(PacketPtr pkt)
const PageTableOps * getPageTableOps(GrainSize trans_granule)
const GrainSize GrainMap_tg0[]
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
std::shared_ptr< FaultBase > Fault
@ STE_CONFIG_STAGE1_AND_2
Tick curTick()
The universal simulation clock.
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
uint64_t Tick
Tick count type.
std::string csprintf(const char *format, const Args &...args)
This is an implementation of the SMMUv3 architecture.
virtual bool isWritable(pte_t pte, unsigned level, bool stage2) const =0
Addr walkMask(unsigned level) const
virtual LookupLevel lastLevel() const =0
virtual Addr nextLevelPointer(pte_t pte, unsigned level) const =0
virtual bool isValid(pte_t pte, unsigned level) const =0
virtual Addr pageMask(pte_t pte, unsigned level) const =0
virtual Addr index(Addr va, unsigned level, int tsz) const =0
virtual bool isLeaf(pte_t pte, unsigned level) const =0
Bitfield< 63, 32 > streamId
struct gem5::SMMUEvent::Data data
std::string print() const
static SMMUTranslRequest fromPacket(PacketPtr pkt, bool ats=false)
static SMMUTranslRequest prefetch(Addr addr, uint32_t sid, uint32_t ssid)
uint8_t stage1TranslGranule
uint8_t stage2TranslGranule
statistics::Distribution ptwTimeDist
statistics::Scalar cdL1Fetches
statistics::Scalar steL1Fetches
statistics::Scalar steFetches
statistics::Distribution translationTimeDist
statistics::Scalar cdFetches
Bitfield< 51, 6 > s1ctxptr
Bitfield< 37, 32 > s2t0sz
Bitfield< 63, 59 > s1cdmax
const std::string & name()