gic_v3.cc revision 13878:40a2ec55ad89
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(); 114 uint32_t redistributor_id = 115 daddr / redistSize; 116 daddr = daddr % redistSize; 117 panic_if(redistributor_id >= redistributors.size(), 118 "Invalid redistributor_id!"); 119 panic_if(!redistributors[redistributor_id], "Redistributor is null!"); 120 resp = redistributors[redistributor_id]->read(daddr, size, 121 is_secure_access); 122 delay = params()->redist_pio_delay; 123 DPRINTF(GIC, "Gicv3::read(): (redistributor %d) context_id %d " 124 "register %#x size %d is_secure_access %d (value %#x)\n", 125 redistributor_id, pkt->req->contextId(), daddr, size, 126 is_secure_access, resp); 127 } else { 128 panic("Gicv3::read(): unknown address %#x\n", addr); 129 } 130 131 pkt->setUintX(resp, LittleEndianByteOrder); 132 pkt->makeAtomicResponse(); 133 return delay; 134} 135 136Tick 137Gicv3::write(PacketPtr pkt) 138{ 139 const size_t size = pkt->getSize(); 140 uint64_t data = pkt->getUintX(LittleEndianByteOrder); 141 const Addr addr = pkt->getAddr(); 142 bool is_secure_access = pkt->isSecure(); 143 Tick delay = 0; 144 145 if (distRange.contains(addr)) { 146 const Addr daddr = addr - distRange.start(); 147 panic_if(!distributor, "Distributor is null!"); 148 DPRINTF(GIC, "Gicv3::write(): (distributor) context_id %d " 149 "register %#x size %d is_secure_access %d value %#x\n", 150 pkt->req->contextId(), daddr, size, is_secure_access, data); 151 distributor->write(daddr, data, size, is_secure_access); 152 delay = params()->dist_pio_delay; 153 } else if (redistRange.contains(addr)) { 154 Addr daddr = addr - redistRange.start(); 155 uint32_t redistributor_id = 156 daddr / redistSize; 157 daddr = daddr % redistSize; 158 panic_if(redistributor_id >= redistributors.size(), 159 "Invalid redistributor_id!"); 160 panic_if(!redistributors[redistributor_id], "Redistributor is null!"); 161 DPRINTF(GIC, "Gicv3::write(): (redistributor %d) context_id %d " 162 "register %#x size %d is_secure_access %d value %#x\n", 163 redistributor_id, pkt->req->contextId(), daddr, size, 164 is_secure_access, data); 165 redistributors[redistributor_id]->write(daddr, data, size, 166 is_secure_access); 167 delay = params()->redist_pio_delay; 168 } else { 169 panic("Gicv3::write(): unknown address %#x\n", addr); 170 } 171 172 pkt->makeAtomicResponse(); 173 return delay; 174} 175 176void 177Gicv3::sendInt(uint32_t int_id) 178{ 179 panic_if(int_id < Gicv3::SGI_MAX + Gicv3::PPI_MAX, "Invalid SPI!"); 180 panic_if(int_id >= Gicv3::INTID_SECURE, "Invalid SPI!"); 181 DPRINTF(Interrupt, "Gicv3::sendInt(): received SPI %d\n", int_id); 182 distributor->sendInt(int_id); 183} 184 185void 186Gicv3::clearInt(uint32_t number) 187{ 188 distributor->deassertSPI(number); 189} 190 191void 192Gicv3::sendPPInt(uint32_t int_id, uint32_t cpu) 193{ 194 panic_if(cpu >= redistributors.size(), "Invalid cpuID sending PPI!"); 195 panic_if(int_id < Gicv3::SGI_MAX, "Invalid PPI!"); 196 panic_if(int_id >= Gicv3::SGI_MAX + Gicv3::PPI_MAX, "Invalid PPI!"); 197 DPRINTF(Interrupt, "Gicv3::sendPPInt(): received PPI %d cpuTarget %#x\n", 198 int_id, cpu); 199 redistributors[cpu]->sendPPInt(int_id); 200} 201 202void 203Gicv3::clearPPInt(uint32_t num, uint32_t cpu) 204{ 205} 206 207void 208Gicv3::postInt(uint32_t cpu, ArmISA::InterruptTypes int_type) 209{ 210 platform->intrctrl->post(cpu, int_type, 0); 211} 212 213void 214Gicv3::deassertInt(uint32_t cpu, ArmISA::InterruptTypes int_type) 215{ 216 platform->intrctrl->clear(cpu, int_type, 0); 217} 218 219Gicv3Redistributor * 220Gicv3::getRedistributorByAffinity(uint32_t affinity) const 221{ 222 for (auto & redistributor : redistributors) { 223 if (redistributor->getAffinity() == affinity) { 224 return redistributor; 225 } 226 } 227 228 return nullptr; 229} 230 231void 232Gicv3::serialize(CheckpointOut & cp) const 233{ 234 distributor->serializeSection(cp, "distributor"); 235 236 for (uint32_t redistributor_id = 0; 237 redistributor_id < redistributors.size(); redistributor_id++) 238 redistributors[redistributor_id]->serializeSection(cp, 239 csprintf("redistributors.%i", redistributor_id)); 240 241 for (uint32_t cpu_interface_id = 0; 242 cpu_interface_id < cpuInterfaces.size(); cpu_interface_id++) 243 cpuInterfaces[cpu_interface_id]->serializeSection(cp, 244 csprintf("cpuInterface.%i", cpu_interface_id)); 245} 246 247void 248Gicv3::unserialize(CheckpointIn & cp) 249{ 250 getSystem()->setGIC(this); 251 252 distributor->unserializeSection(cp, "distributor"); 253 254 for (uint32_t redistributor_id = 0; 255 redistributor_id < redistributors.size(); redistributor_id++) 256 redistributors[redistributor_id]->unserializeSection(cp, 257 csprintf("redistributors.%i", redistributor_id)); 258 259 for (uint32_t cpu_interface_id = 0; 260 cpu_interface_id < cpuInterfaces.size(); cpu_interface_id++) 261 cpuInterfaces[cpu_interface_id]->unserializeSection(cp, 262 csprintf("cpuInterface.%i", cpu_interface_id)); 263} 264 265Gicv3 * 266Gicv3Params::create() 267{ 268 return new Gicv3(this); 269} 270