gic_v3.cc revision 13531
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 48Gicv3::~Gicv3() 49{ 50} 51 52void 53Gicv3::init() 54{ 55 distRange = RangeSize(params()->dist_addr, 56 Gicv3Distributor::ADDR_RANGE_SIZE - 1); 57 redistRange = RangeSize(params()->redist_addr, 58 Gicv3Redistributor::ADDR_RANGE_SIZE * sys->numContexts() - 1); 59 addrRanges = {distRange, redistRange}; 60 BaseGic::init(); 61 distributor = new Gicv3Distributor(this, params()->it_lines); 62 redistributors.resize(sys->numContexts(), nullptr); 63 cpuInterfaces.resize(sys->numContexts(), nullptr); 64 65 for (int i = 0; i < sys->numContexts(); i++) { 66 redistributors[i] = new Gicv3Redistributor(this, i); 67 cpuInterfaces[i] = new Gicv3CPUInterface(this, i); 68 } 69 70 distributor->init(); 71 72 for (int i = 0; i < sys->numContexts(); i++) { 73 redistributors[i]->init(); 74 cpuInterfaces[i]->init(); 75 } 76} 77 78void 79Gicv3::initState() 80{ 81 distributor->initState(); 82 83 for (int i = 0; i < sys->numContexts(); i++) { 84 redistributors[i]->initState(); 85 cpuInterfaces[i]->initState(); 86 } 87} 88 89Tick 90Gicv3::read(PacketPtr pkt) 91{ 92 const Addr addr = pkt->getAddr(); 93 const size_t size = pkt->getSize(); 94 const ContextID context_id = pkt->req->contextId(); 95 bool is_secure_access = pkt->isSecure(); 96 uint64_t resp = 0; 97 Tick delay = 0; 98 99 if (distRange.contains(addr)) { 100 const Addr daddr = addr - distRange.start(); 101 panic_if(!distributor, "Distributor is null!"); 102 resp = distributor->read(daddr, size, is_secure_access); 103 delay = params()->dist_pio_delay; 104 DPRINTF(GIC, "Gicv3::read(): (distributor) context_id %d register %#x " 105 "size %d is_secure_access %d (value %#x)\n", 106 context_id, daddr, size, is_secure_access, resp); 107 } else if (redistRange.contains(addr)) { 108 Addr daddr = addr - redistRange.start(); 109 uint32_t redistributor_id = 110 daddr / Gicv3Redistributor::ADDR_RANGE_SIZE; 111 daddr = daddr % Gicv3Redistributor::ADDR_RANGE_SIZE; 112 panic_if(redistributor_id >= redistributors.size(), 113 "Invalid redistributor_id!"); 114 panic_if(!redistributors[redistributor_id], "Redistributor is null!"); 115 resp = redistributors[redistributor_id]->read(daddr, size, 116 is_secure_access); 117 delay = params()->redist_pio_delay; 118 DPRINTF(GIC, "Gicv3::read(): (redistributor %d) context_id %d " 119 "register %#x size %d is_secure_access %d (value %#x)\n", 120 redistributor_id, context_id, daddr, size, is_secure_access, 121 resp); 122 } else { 123 panic("Gicv3::read(): unknown address %#x\n", addr); 124 } 125 126 pkt->setUintX(resp, LittleEndianByteOrder); 127 pkt->makeAtomicResponse(); 128 return delay; 129} 130 131Tick 132Gicv3::write(PacketPtr pkt) 133{ 134 const size_t size = pkt->getSize(); 135 uint64_t data = pkt->getUintX(LittleEndianByteOrder); 136 const Addr addr = pkt->getAddr(); 137 const ContextID context_id = pkt->req->contextId(); 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 context_id, 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(); 151 uint32_t redistributor_id = 152 daddr / Gicv3Redistributor::ADDR_RANGE_SIZE; 153 daddr = daddr % Gicv3Redistributor::ADDR_RANGE_SIZE; 154 panic_if(redistributor_id >= redistributors.size(), 155 "Invalid redistributor_id!"); 156 panic_if(!redistributors[redistributor_id], "Redistributor is null!"); 157 DPRINTF(GIC, "Gicv3::write(): (redistributor %d) context_id %d " 158 "register %#x size %d is_secure_access %d value %#x\n", 159 redistributor_id, context_id, daddr, size, is_secure_access, 160 data); 161 redistributors[redistributor_id]->write(daddr, data, size, 162 is_secure_access); 163 delay = params()->redist_pio_delay; 164 } else { 165 panic("Gicv3::write(): unknown address %#x\n", addr); 166 } 167 168 pkt->makeAtomicResponse(); 169 return delay; 170} 171 172void 173Gicv3::sendInt(uint32_t int_id) 174{ 175 panic_if(int_id < Gicv3::SGI_MAX + Gicv3::PPI_MAX, "Invalid SPI!"); 176 panic_if(int_id >= Gicv3::INTID_SECURE, "Invalid SPI!"); 177 DPRINTF(Interrupt, "Gicv3::sendInt(): received SPI %d\n", int_id); 178 distributor->sendInt(int_id); 179} 180 181void 182Gicv3::clearInt(uint32_t number) 183{ 184 distributor->intDeasserted(number); 185} 186 187void 188Gicv3::sendPPInt(uint32_t int_id, uint32_t cpu) 189{ 190 panic_if(cpu >= redistributors.size(), "Invalid cpuID sending PPI!"); 191 panic_if(int_id < Gicv3::SGI_MAX, "Invalid PPI!"); 192 panic_if(int_id >= Gicv3::SGI_MAX + Gicv3::PPI_MAX, "Invalid PPI!"); 193 DPRINTF(Interrupt, "Gicv3::sendPPInt(): received PPI %d cpuTarget %#x\n", 194 int_id, cpu); 195 redistributors[cpu]->sendPPInt(int_id); 196} 197 198void 199Gicv3::clearPPInt(uint32_t num, uint32_t cpu) 200{ 201} 202 203void 204Gicv3::postInt(uint32_t cpu, ArmISA::InterruptTypes int_type) 205{ 206 postDelayedInt(cpu, int_type); 207} 208 209void 210Gicv3::deassertInt(uint32_t cpu, ArmISA::InterruptTypes int_type) 211{ 212 platform->intrctrl->clear(cpu, int_type, 0); 213} 214 215void 216Gicv3::postDelayedInt(uint32_t cpu, ArmISA::InterruptTypes int_type) 217{ 218 platform->intrctrl->post(cpu, int_type, 0); 219} 220 221Gicv3Redistributor * 222Gicv3::getRedistributorByAffinity(uint32_t affinity) 223{ 224 for (auto & redistributor : redistributors) { 225 if (redistributor->getAffinity() == affinity) { 226 return redistributor; 227 } 228 } 229 230 return nullptr; 231} 232 233void 234Gicv3::serialize(CheckpointOut & cp) const 235{ 236 distributor->serializeSection(cp, "distributor"); 237 238 for (uint32_t redistributor_id = 0; 239 redistributor_id < redistributors.size(); 240 redistributor_id++) 241 redistributors[redistributor_id]->serializeSection(cp, 242 csprintf("redistributors.%i", redistributor_id)); 243 244 for (uint32_t cpu_interface_id = 0; 245 cpu_interface_id < cpuInterfaces.size(); 246 cpu_interface_id++) 247 cpuInterfaces[cpu_interface_id]->serializeSection(cp, 248 csprintf("cpuInterface.%i", cpu_interface_id)); 249} 250 251void 252Gicv3::unserialize(CheckpointIn & cp) 253{ 254 getSystem()->setGIC(this); 255 256 distributor->unserializeSection(cp, "distributor"); 257 258 for (uint32_t redistributor_id = 0; 259 redistributor_id < redistributors.size(); 260 redistributor_id++) 261 redistributors[redistributor_id]->unserializeSection(cp, 262 csprintf("redistributors.%i", redistributor_id)); 263 264 for (uint32_t cpu_interface_id = 0; 265 cpu_interface_id < cpuInterfaces.size(); 266 cpu_interface_id++) 267 cpuInterfaces[cpu_interface_id]->unserializeSection(cp, 268 csprintf("cpuInterface.%i", cpu_interface_id)); 269} 270 271Gicv3 * 272Gicv3Params::create() 273{ 274 return new Gicv3(this); 275} 276