gic_v3.cc revision 13925:971b66c8acd7
1/* 2 * Copyright (c) 2018 Metempsy Technology Consulting 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer; 9 * redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution; 12 * neither the name of the copyright holders nor the names of its 13 * contributors may be used to endorse or promote products derived from 14 * this software without specific prior written permission. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 * 28 * Authors: Jairo Balart 29 */ 30 31#include "dev/arm/gic_v3.hh" 32 33#include "cpu/intr_control.hh" 34#include "debug/GIC.hh" 35#include "debug/Interrupt.hh" 36#include "dev/arm/gic_v3_cpu_interface.hh" 37#include "dev/arm/gic_v3_distributor.hh" 38#include "dev/arm/gic_v3_redistributor.hh" 39#include "dev/platform.hh" 40#include "mem/packet.hh" 41#include "mem/packet_access.hh" 42 43Gicv3::Gicv3(const Params * p) 44 : BaseGic(p) 45{ 46} 47 48void 49Gicv3::init() 50{ 51 distributor = new Gicv3Distributor(this, params()->it_lines); 52 redistributors.resize(sys->numContexts(), nullptr); 53 cpuInterfaces.resize(sys->numContexts(), nullptr); 54 55 panic_if(sys->numContexts() > params()->cpu_max, 56 "Exceeding maximum number of PEs supported by GICv3: " 57 "using %u while maximum is %u\n", sys->numContexts(), 58 params()->cpu_max); 59 60 for (int i = 0; i < sys->numContexts(); i++) { 61 redistributors[i] = new Gicv3Redistributor(this, i); 62 cpuInterfaces[i] = new Gicv3CPUInterface(this, i); 63 } 64 65 distRange = RangeSize(params()->dist_addr, 66 Gicv3Distributor::ADDR_RANGE_SIZE - 1); 67 68 redistSize = redistributors[0]->addrRangeSize; 69 redistRange = RangeSize(params()->redist_addr, 70 redistSize * sys->numContexts() - 1); 71 72 addrRanges = {distRange, redistRange}; 73 74 distributor->init(); 75 76 for (int i = 0; i < sys->numContexts(); i++) { 77 redistributors[i]->init(); 78 cpuInterfaces[i]->init(); 79 } 80 81 BaseGic::init(); 82} 83 84void 85Gicv3::initState() 86{ 87 distributor->initState(); 88 89 for (int i = 0; i < sys->numContexts(); i++) { 90 redistributors[i]->initState(); 91 cpuInterfaces[i]->initState(); 92 } 93} 94 95Tick 96Gicv3::read(PacketPtr pkt) 97{ 98 const Addr addr = pkt->getAddr(); 99 const size_t size = pkt->getSize(); 100 bool is_secure_access = pkt->isSecure(); 101 uint64_t resp = 0; 102 Tick delay = 0; 103 104 if (distRange.contains(addr)) { 105 const Addr daddr = addr - distRange.start(); 106 panic_if(!distributor, "Distributor is null!"); 107 resp = distributor->read(daddr, size, is_secure_access); 108 delay = params()->dist_pio_delay; 109 DPRINTF(GIC, "Gicv3::read(): (distributor) context_id %d register %#x " 110 "size %d is_secure_access %d (value %#x)\n", 111 pkt->req->contextId(), daddr, size, is_secure_access, resp); 112 } else if (redistRange.contains(addr)) { 113 Addr daddr = (addr - redistRange.start()) % redistSize; 114 115 Gicv3Redistributor *redist = getRedistributorByAddr(addr); 116 resp = redist->read(daddr, size, is_secure_access); 117 118 delay = params()->redist_pio_delay; 119 DPRINTF(GIC, "Gicv3::read(): (redistributor %d) context_id %d " 120 "register %#x size %d is_secure_access %d (value %#x)\n", 121 redist->processorNumber(), pkt->req->contextId(), daddr, size, 122 is_secure_access, resp); 123 } else { 124 panic("Gicv3::read(): unknown address %#x\n", addr); 125 } 126 127 pkt->setUintX(resp, LittleEndianByteOrder); 128 pkt->makeAtomicResponse(); 129 return delay; 130} 131 132Tick 133Gicv3::write(PacketPtr pkt) 134{ 135 const size_t size = pkt->getSize(); 136 uint64_t data = pkt->getUintX(LittleEndianByteOrder); 137 const Addr addr = pkt->getAddr(); 138 bool is_secure_access = pkt->isSecure(); 139 Tick delay = 0; 140 141 if (distRange.contains(addr)) { 142 const Addr daddr = addr - distRange.start(); 143 panic_if(!distributor, "Distributor is null!"); 144 DPRINTF(GIC, "Gicv3::write(): (distributor) context_id %d " 145 "register %#x size %d is_secure_access %d value %#x\n", 146 pkt->req->contextId(), daddr, size, is_secure_access, data); 147 distributor->write(daddr, data, size, is_secure_access); 148 delay = params()->dist_pio_delay; 149 } else if (redistRange.contains(addr)) { 150 Addr daddr = (addr - redistRange.start()) % redistSize; 151 152 Gicv3Redistributor *redist = getRedistributorByAddr(addr); 153 DPRINTF(GIC, "Gicv3::write(): (redistributor %d) context_id %d " 154 "register %#x size %d is_secure_access %d value %#x\n", 155 redist->processorNumber(), pkt->req->contextId(), daddr, size, 156 is_secure_access, data); 157 158 redist->write(daddr, data, size, is_secure_access); 159 160 delay = params()->redist_pio_delay; 161 } else { 162 panic("Gicv3::write(): unknown address %#x\n", addr); 163 } 164 165 pkt->makeAtomicResponse(); 166 return delay; 167} 168 169void 170Gicv3::sendInt(uint32_t int_id) 171{ 172 panic_if(int_id < Gicv3::SGI_MAX + Gicv3::PPI_MAX, "Invalid SPI!"); 173 panic_if(int_id >= Gicv3::INTID_SECURE, "Invalid SPI!"); 174 DPRINTF(Interrupt, "Gicv3::sendInt(): received SPI %d\n", int_id); 175 distributor->sendInt(int_id); 176} 177 178void 179Gicv3::clearInt(uint32_t number) 180{ 181 distributor->deassertSPI(number); 182} 183 184void 185Gicv3::sendPPInt(uint32_t int_id, uint32_t cpu) 186{ 187 panic_if(cpu >= redistributors.size(), "Invalid cpuID sending PPI!"); 188 panic_if(int_id < Gicv3::SGI_MAX, "Invalid PPI!"); 189 panic_if(int_id >= Gicv3::SGI_MAX + Gicv3::PPI_MAX, "Invalid PPI!"); 190 DPRINTF(Interrupt, "Gicv3::sendPPInt(): received PPI %d cpuTarget %#x\n", 191 int_id, cpu); 192 redistributors[cpu]->sendPPInt(int_id); 193} 194 195void 196Gicv3::clearPPInt(uint32_t num, uint32_t cpu) 197{ 198} 199 200void 201Gicv3::postInt(uint32_t cpu, ArmISA::InterruptTypes int_type) 202{ 203 platform->intrctrl->post(cpu, int_type, 0); 204} 205 206void 207Gicv3::deassertInt(uint32_t cpu, ArmISA::InterruptTypes int_type) 208{ 209 platform->intrctrl->clear(cpu, int_type, 0); 210} 211 212Gicv3Redistributor * 213Gicv3::getRedistributorByAffinity(uint32_t affinity) const 214{ 215 for (auto & redistributor : redistributors) { 216 if (redistributor->getAffinity() == affinity) { 217 return redistributor; 218 } 219 } 220 221 return nullptr; 222} 223 224Gicv3Redistributor * 225Gicv3::getRedistributorByAddr(Addr addr) const 226{ 227 panic_if(!redistRange.contains(addr), 228 "Address not pointing to a valid redistributor\n"); 229 230 const Addr daddr = addr - redistRange.start(); 231 const uint32_t redistributor_id = daddr / redistSize; 232 233 panic_if(redistributor_id >= redistributors.size(), 234 "Invalid redistributor_id!"); 235 panic_if(!redistributors[redistributor_id], "Redistributor is null!"); 236 237 return redistributors[redistributor_id]; 238} 239 240void 241Gicv3::serialize(CheckpointOut & cp) const 242{ 243 distributor->serializeSection(cp, "distributor"); 244 245 for (uint32_t redistributor_id = 0; 246 redistributor_id < redistributors.size(); redistributor_id++) 247 redistributors[redistributor_id]->serializeSection(cp, 248 csprintf("redistributors.%i", redistributor_id)); 249 250 for (uint32_t cpu_interface_id = 0; 251 cpu_interface_id < cpuInterfaces.size(); cpu_interface_id++) 252 cpuInterfaces[cpu_interface_id]->serializeSection(cp, 253 csprintf("cpuInterface.%i", cpu_interface_id)); 254} 255 256void 257Gicv3::unserialize(CheckpointIn & cp) 258{ 259 getSystem()->setGIC(this); 260 261 distributor->unserializeSection(cp, "distributor"); 262 263 for (uint32_t redistributor_id = 0; 264 redistributor_id < redistributors.size(); redistributor_id++) 265 redistributors[redistributor_id]->unserializeSection(cp, 266 csprintf("redistributors.%i", redistributor_id)); 267 268 for (uint32_t cpu_interface_id = 0; 269 cpu_interface_id < cpuInterfaces.size(); cpu_interface_id++) 270 cpuInterfaces[cpu_interface_id]->unserializeSection(cp, 271 csprintf("cpuInterface.%i", cpu_interface_id)); 272} 273 274Gicv3 * 275Gicv3Params::create() 276{ 277 return new Gicv3(this); 278} 279