1/* 2 * Copyright (c) 2019 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 * Authors: Stan Czerniawski 38 * Giacomo Travaglini 39 */ 40 41#include "dev/arm/smmu_v3_slaveifc.hh" 42 43#include "debug/SMMUv3.hh" 44#include "dev/arm/smmu_v3.hh" 45#include "dev/arm/smmu_v3_transl.hh" 46 47SMMUv3SlaveInterface::SMMUv3SlaveInterface( 48 const SMMUv3SlaveInterfaceParams *p) : 49 MemObject(p), 50 smmu(nullptr), 51 microTLB(new SMMUTLB(p->utlb_entries, 52 p->utlb_assoc, 53 p->utlb_policy)), 54 mainTLB(new SMMUTLB(p->tlb_entries, 55 p->tlb_assoc, 56 p->tlb_policy)), 57 microTLBEnable(p->utlb_enable), 58 mainTLBEnable(p->tlb_enable), 59 slavePortSem(1), 60 microTLBSem(p->utlb_slots), 61 mainTLBSem(p->tlb_slots), 62 microTLBLat(p->utlb_lat), 63 mainTLBLat(p->tlb_lat), 64 slavePort(new SMMUSlavePort(csprintf("%s.slave", name()), *this)), 65 atsSlavePort(name() + ".atsSlave", *this), 66 atsMasterPort(name() + ".atsMaster", *this), 67 portWidth(p->port_width), 68 wrBufSlotsRemaining(p->wrbuf_slots), 69 xlateSlotsRemaining(p->xlate_slots),
| 1/* 2 * Copyright (c) 2019 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 * Authors: Stan Czerniawski 38 * Giacomo Travaglini 39 */ 40 41#include "dev/arm/smmu_v3_slaveifc.hh" 42 43#include "debug/SMMUv3.hh" 44#include "dev/arm/smmu_v3.hh" 45#include "dev/arm/smmu_v3_transl.hh" 46 47SMMUv3SlaveInterface::SMMUv3SlaveInterface( 48 const SMMUv3SlaveInterfaceParams *p) : 49 MemObject(p), 50 smmu(nullptr), 51 microTLB(new SMMUTLB(p->utlb_entries, 52 p->utlb_assoc, 53 p->utlb_policy)), 54 mainTLB(new SMMUTLB(p->tlb_entries, 55 p->tlb_assoc, 56 p->tlb_policy)), 57 microTLBEnable(p->utlb_enable), 58 mainTLBEnable(p->tlb_enable), 59 slavePortSem(1), 60 microTLBSem(p->utlb_slots), 61 mainTLBSem(p->tlb_slots), 62 microTLBLat(p->utlb_lat), 63 mainTLBLat(p->tlb_lat), 64 slavePort(new SMMUSlavePort(csprintf("%s.slave", name()), *this)), 65 atsSlavePort(name() + ".atsSlave", *this), 66 atsMasterPort(name() + ".atsMaster", *this), 67 portWidth(p->port_width), 68 wrBufSlotsRemaining(p->wrbuf_slots), 69 xlateSlotsRemaining(p->xlate_slots),
|
70 prefetchEnable(p->prefetch_enable), 71 prefetchReserveLastWay( 72 p->prefetch_reserve_last_way), 73 deviceNeedsRetry(false), 74 atsDeviceNeedsRetry(false), 75 sendDeviceRetryEvent(*this), 76 atsSendDeviceRetryEvent(this) 77{} 78 79void 80SMMUv3SlaveInterface::sendRange() 81{ 82 if (slavePort->isConnected()) { 83 inform("Slave port is connected to %s\n", slavePort->getPeer()); 84 85 slavePort->sendRangeChange(); 86 } else { 87 fatal("Slave port is not connected.\n"); 88 } 89} 90 91Port& 92SMMUv3SlaveInterface::getPort(const std::string &name, PortID id) 93{ 94 if (name == "ats_master") { 95 return atsMasterPort; 96 } else if (name == "slave") { 97 return *slavePort; 98 } else if (name == "ats_slave") { 99 return atsSlavePort; 100 } else { 101 return MemObject::getPort(name, id); 102 } 103} 104 105void 106SMMUv3SlaveInterface::schedTimingResp(PacketPtr pkt) 107{ 108 slavePort->schedTimingResp(pkt, nextCycle()); 109} 110 111void 112SMMUv3SlaveInterface::schedAtsTimingResp(PacketPtr pkt) 113{ 114 atsSlavePort.schedTimingResp(pkt, nextCycle()); 115 116 if (atsDeviceNeedsRetry) { 117 atsDeviceNeedsRetry = false; 118 schedule(atsSendDeviceRetryEvent, nextCycle()); 119 } 120} 121 122Tick 123SMMUv3SlaveInterface::recvAtomic(PacketPtr pkt) 124{ 125 DPRINTF(SMMUv3, "[a] req from %s addr=%#x size=%#x\n", 126 slavePort->getPeer(), pkt->getAddr(), pkt->getSize()); 127 128 std::string proc_name = csprintf("%s.port", name()); 129 SMMUTranslationProcess proc(proc_name, *smmu, *this); 130 proc.beginTransaction(SMMUTranslRequest::fromPacket(pkt)); 131 132 SMMUAction a = smmu->runProcessAtomic(&proc, pkt); 133 assert(a.type == ACTION_SEND_RESP); 134 135 return a.delay; 136} 137 138bool 139SMMUv3SlaveInterface::recvTimingReq(PacketPtr pkt) 140{ 141 DPRINTF(SMMUv3, "[t] req from %s addr=%#x size=%#x\n", 142 slavePort->getPeer(), pkt->getAddr(), pkt->getSize()); 143 144 // @todo: We need to pay for this and not just zero it out 145 pkt->headerDelay = pkt->payloadDelay = 0; 146 147 unsigned nbeats = 148 (pkt->getSize() + (portWidth-1)) / portWidth; 149 150 if (xlateSlotsRemaining==0 || 151 (pkt->isWrite() && wrBufSlotsRemaining < nbeats)) 152 { 153 deviceNeedsRetry = true; 154 return false; 155 } 156 157 if (pkt->isWrite()) 158 wrBufSlotsRemaining -= nbeats; 159 160 std::string proc_name = csprintf("%s.port", name()); 161 SMMUTranslationProcess *proc = 162 new SMMUTranslationProcess(proc_name, *smmu, *this); 163 proc->beginTransaction(SMMUTranslRequest::fromPacket(pkt)); 164 165 smmu->runProcessTiming(proc, pkt); 166 167 return true; 168} 169 170Tick 171SMMUv3SlaveInterface::atsSlaveRecvAtomic(PacketPtr pkt) 172{ 173 DPRINTF(SMMUv3, "[a] ATS slave req addr=%#x size=%#x\n", 174 pkt->getAddr(), pkt->getSize()); 175 176 std::string proc_name = csprintf("%s.atsport", name()); 177 const bool ats_request = true; 178 SMMUTranslationProcess proc( 179 proc_name, *smmu, *this); 180 proc.beginTransaction(SMMUTranslRequest::fromPacket(pkt, ats_request)); 181 182 SMMUAction a = smmu->runProcessAtomic(&proc, pkt); 183 assert(a.type == ACTION_SEND_RESP_ATS); 184 185 return a.delay; 186} 187 188bool 189SMMUv3SlaveInterface::atsSlaveRecvTimingReq(PacketPtr pkt) 190{ 191 DPRINTF(SMMUv3, "[t] ATS slave req addr=%#x size=%#x\n", 192 pkt->getAddr(), pkt->getSize()); 193 194 // @todo: We need to pay for this and not just zero it out 195 pkt->headerDelay = pkt->payloadDelay = 0; 196 197 if (xlateSlotsRemaining == 0) { 198 deviceNeedsRetry = true; 199 return false; 200 } 201 202 std::string proc_name = csprintf("%s.atsport", name()); 203 const bool ats_request = true; 204 SMMUTranslationProcess *proc = 205 new SMMUTranslationProcess(proc_name, *smmu, *this); 206 proc->beginTransaction(SMMUTranslRequest::fromPacket(pkt, ats_request)); 207 208 smmu->runProcessTiming(proc, pkt); 209 210 return true; 211} 212 213bool 214SMMUv3SlaveInterface::atsMasterRecvTimingResp(PacketPtr pkt) 215{ 216 DPRINTF(SMMUv3, "[t] ATS master resp addr=%#x size=%#x\n", 217 pkt->getAddr(), pkt->getSize()); 218 219 // @todo: We need to pay for this and not just zero it out 220 pkt->headerDelay = pkt->payloadDelay = 0; 221 222 SMMUProcess *proc = 223 safe_cast<SMMUProcess *>(pkt->popSenderState()); 224 225 smmu->runProcessTiming(proc, pkt); 226 227 return true; 228} 229 230void 231SMMUv3SlaveInterface::sendDeviceRetry() 232{ 233 slavePort->sendRetryReq(); 234} 235 236void 237SMMUv3SlaveInterface::atsSendDeviceRetry() 238{ 239 DPRINTF(SMMUv3, "ATS retry\n"); 240 atsSlavePort.sendRetryReq(); 241} 242 243void 244SMMUv3SlaveInterface::scheduleDeviceRetry() 245{ 246 if (deviceNeedsRetry && !sendDeviceRetryEvent.scheduled()) { 247 DPRINTF(SMMUv3, "sched slave retry\n"); 248 deviceNeedsRetry = false; 249 schedule(sendDeviceRetryEvent, nextCycle()); 250 } 251} 252 253DrainState 254SMMUv3SlaveInterface::drain() 255{ 256 // Wait until all SMMU translations are completed 257 if (xlateSlotsRemaining < params()->xlate_slots) { 258 return DrainState::Draining; 259 } 260 return DrainState::Drained; 261} 262 263SMMUv3SlaveInterface* 264SMMUv3SlaveInterfaceParams::create() 265{ 266 return new SMMUv3SlaveInterface(this); 267}
| 71 prefetchEnable(p->prefetch_enable), 72 prefetchReserveLastWay( 73 p->prefetch_reserve_last_way), 74 deviceNeedsRetry(false), 75 atsDeviceNeedsRetry(false), 76 sendDeviceRetryEvent(*this), 77 atsSendDeviceRetryEvent(this) 78{} 79 80void 81SMMUv3SlaveInterface::sendRange() 82{ 83 if (slavePort->isConnected()) { 84 inform("Slave port is connected to %s\n", slavePort->getPeer()); 85 86 slavePort->sendRangeChange(); 87 } else { 88 fatal("Slave port is not connected.\n"); 89 } 90} 91 92Port& 93SMMUv3SlaveInterface::getPort(const std::string &name, PortID id) 94{ 95 if (name == "ats_master") { 96 return atsMasterPort; 97 } else if (name == "slave") { 98 return *slavePort; 99 } else if (name == "ats_slave") { 100 return atsSlavePort; 101 } else { 102 return MemObject::getPort(name, id); 103 } 104} 105 106void 107SMMUv3SlaveInterface::schedTimingResp(PacketPtr pkt) 108{ 109 slavePort->schedTimingResp(pkt, nextCycle()); 110} 111 112void 113SMMUv3SlaveInterface::schedAtsTimingResp(PacketPtr pkt) 114{ 115 atsSlavePort.schedTimingResp(pkt, nextCycle()); 116 117 if (atsDeviceNeedsRetry) { 118 atsDeviceNeedsRetry = false; 119 schedule(atsSendDeviceRetryEvent, nextCycle()); 120 } 121} 122 123Tick 124SMMUv3SlaveInterface::recvAtomic(PacketPtr pkt) 125{ 126 DPRINTF(SMMUv3, "[a] req from %s addr=%#x size=%#x\n", 127 slavePort->getPeer(), pkt->getAddr(), pkt->getSize()); 128 129 std::string proc_name = csprintf("%s.port", name()); 130 SMMUTranslationProcess proc(proc_name, *smmu, *this); 131 proc.beginTransaction(SMMUTranslRequest::fromPacket(pkt)); 132 133 SMMUAction a = smmu->runProcessAtomic(&proc, pkt); 134 assert(a.type == ACTION_SEND_RESP); 135 136 return a.delay; 137} 138 139bool 140SMMUv3SlaveInterface::recvTimingReq(PacketPtr pkt) 141{ 142 DPRINTF(SMMUv3, "[t] req from %s addr=%#x size=%#x\n", 143 slavePort->getPeer(), pkt->getAddr(), pkt->getSize()); 144 145 // @todo: We need to pay for this and not just zero it out 146 pkt->headerDelay = pkt->payloadDelay = 0; 147 148 unsigned nbeats = 149 (pkt->getSize() + (portWidth-1)) / portWidth; 150 151 if (xlateSlotsRemaining==0 || 152 (pkt->isWrite() && wrBufSlotsRemaining < nbeats)) 153 { 154 deviceNeedsRetry = true; 155 return false; 156 } 157 158 if (pkt->isWrite()) 159 wrBufSlotsRemaining -= nbeats; 160 161 std::string proc_name = csprintf("%s.port", name()); 162 SMMUTranslationProcess *proc = 163 new SMMUTranslationProcess(proc_name, *smmu, *this); 164 proc->beginTransaction(SMMUTranslRequest::fromPacket(pkt)); 165 166 smmu->runProcessTiming(proc, pkt); 167 168 return true; 169} 170 171Tick 172SMMUv3SlaveInterface::atsSlaveRecvAtomic(PacketPtr pkt) 173{ 174 DPRINTF(SMMUv3, "[a] ATS slave req addr=%#x size=%#x\n", 175 pkt->getAddr(), pkt->getSize()); 176 177 std::string proc_name = csprintf("%s.atsport", name()); 178 const bool ats_request = true; 179 SMMUTranslationProcess proc( 180 proc_name, *smmu, *this); 181 proc.beginTransaction(SMMUTranslRequest::fromPacket(pkt, ats_request)); 182 183 SMMUAction a = smmu->runProcessAtomic(&proc, pkt); 184 assert(a.type == ACTION_SEND_RESP_ATS); 185 186 return a.delay; 187} 188 189bool 190SMMUv3SlaveInterface::atsSlaveRecvTimingReq(PacketPtr pkt) 191{ 192 DPRINTF(SMMUv3, "[t] ATS slave req addr=%#x size=%#x\n", 193 pkt->getAddr(), pkt->getSize()); 194 195 // @todo: We need to pay for this and not just zero it out 196 pkt->headerDelay = pkt->payloadDelay = 0; 197 198 if (xlateSlotsRemaining == 0) { 199 deviceNeedsRetry = true; 200 return false; 201 } 202 203 std::string proc_name = csprintf("%s.atsport", name()); 204 const bool ats_request = true; 205 SMMUTranslationProcess *proc = 206 new SMMUTranslationProcess(proc_name, *smmu, *this); 207 proc->beginTransaction(SMMUTranslRequest::fromPacket(pkt, ats_request)); 208 209 smmu->runProcessTiming(proc, pkt); 210 211 return true; 212} 213 214bool 215SMMUv3SlaveInterface::atsMasterRecvTimingResp(PacketPtr pkt) 216{ 217 DPRINTF(SMMUv3, "[t] ATS master resp addr=%#x size=%#x\n", 218 pkt->getAddr(), pkt->getSize()); 219 220 // @todo: We need to pay for this and not just zero it out 221 pkt->headerDelay = pkt->payloadDelay = 0; 222 223 SMMUProcess *proc = 224 safe_cast<SMMUProcess *>(pkt->popSenderState()); 225 226 smmu->runProcessTiming(proc, pkt); 227 228 return true; 229} 230 231void 232SMMUv3SlaveInterface::sendDeviceRetry() 233{ 234 slavePort->sendRetryReq(); 235} 236 237void 238SMMUv3SlaveInterface::atsSendDeviceRetry() 239{ 240 DPRINTF(SMMUv3, "ATS retry\n"); 241 atsSlavePort.sendRetryReq(); 242} 243 244void 245SMMUv3SlaveInterface::scheduleDeviceRetry() 246{ 247 if (deviceNeedsRetry && !sendDeviceRetryEvent.scheduled()) { 248 DPRINTF(SMMUv3, "sched slave retry\n"); 249 deviceNeedsRetry = false; 250 schedule(sendDeviceRetryEvent, nextCycle()); 251 } 252} 253 254DrainState 255SMMUv3SlaveInterface::drain() 256{ 257 // Wait until all SMMU translations are completed 258 if (xlateSlotsRemaining < params()->xlate_slots) { 259 return DrainState::Draining; 260 } 261 return DrainState::Drained; 262} 263 264SMMUv3SlaveInterface* 265SMMUv3SlaveInterfaceParams::create() 266{ 267 return new SMMUv3SlaveInterface(this); 268}
|