gic_v3_distributor.cc revision 14251
113531Sjairo.balart@metempsy.com/* 214167Sgiacomo.travaglini@arm.com * Copyright (c) 2019 ARM Limited 314167Sgiacomo.travaglini@arm.com * All rights reserved 414167Sgiacomo.travaglini@arm.com * 514167Sgiacomo.travaglini@arm.com * The license below extends only to copyright in the software and shall 614167Sgiacomo.travaglini@arm.com * not be construed as granting a license to any other intellectual 714167Sgiacomo.travaglini@arm.com * property including but not limited to intellectual property relating 814167Sgiacomo.travaglini@arm.com * to a hardware implementation of the functionality of the software 914167Sgiacomo.travaglini@arm.com * licensed hereunder. You may use the software subject to the license 1014167Sgiacomo.travaglini@arm.com * terms below provided that you ensure that this notice is replicated 1114167Sgiacomo.travaglini@arm.com * unmodified and in its entirety in all distributions of the software, 1214167Sgiacomo.travaglini@arm.com * modified or unmodified, in source code or in binary form. 1314167Sgiacomo.travaglini@arm.com * 1413531Sjairo.balart@metempsy.com * Copyright (c) 2018 Metempsy Technology Consulting 1513531Sjairo.balart@metempsy.com * All rights reserved. 1613531Sjairo.balart@metempsy.com * 1713531Sjairo.balart@metempsy.com * Redistribution and use in source and binary forms, with or without 1813531Sjairo.balart@metempsy.com * modification, are permitted provided that the following conditions are 1913531Sjairo.balart@metempsy.com * met: redistributions of source code must retain the above copyright 2013531Sjairo.balart@metempsy.com * notice, this list of conditions and the following disclaimer; 2113531Sjairo.balart@metempsy.com * redistributions in binary form must reproduce the above copyright 2213531Sjairo.balart@metempsy.com * notice, this list of conditions and the following disclaimer in the 2313531Sjairo.balart@metempsy.com * documentation and/or other materials provided with the distribution; 2413531Sjairo.balart@metempsy.com * neither the name of the copyright holders nor the names of its 2513531Sjairo.balart@metempsy.com * contributors may be used to endorse or promote products derived from 2613531Sjairo.balart@metempsy.com * this software without specific prior written permission. 2713531Sjairo.balart@metempsy.com * 2813531Sjairo.balart@metempsy.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 2913531Sjairo.balart@metempsy.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 3013531Sjairo.balart@metempsy.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 3113531Sjairo.balart@metempsy.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 3213531Sjairo.balart@metempsy.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 3313531Sjairo.balart@metempsy.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 3413531Sjairo.balart@metempsy.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 3513531Sjairo.balart@metempsy.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 3613531Sjairo.balart@metempsy.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 3713531Sjairo.balart@metempsy.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 3813531Sjairo.balart@metempsy.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 3913531Sjairo.balart@metempsy.com * 4013531Sjairo.balart@metempsy.com * Authors: Jairo Balart 4113531Sjairo.balart@metempsy.com */ 4213756Sjairo.balart@metempsy.com 4313531Sjairo.balart@metempsy.com#include "dev/arm/gic_v3_distributor.hh" 4413531Sjairo.balart@metempsy.com 4513531Sjairo.balart@metempsy.com#include <algorithm> 4613531Sjairo.balart@metempsy.com 4713531Sjairo.balart@metempsy.com#include "debug/GIC.hh" 4813531Sjairo.balart@metempsy.com#include "dev/arm/gic_v3.hh" 4913531Sjairo.balart@metempsy.com#include "dev/arm/gic_v3_cpu_interface.hh" 5013531Sjairo.balart@metempsy.com#include "dev/arm/gic_v3_redistributor.hh" 5113531Sjairo.balart@metempsy.com 5213756Sjairo.balart@metempsy.comconst AddrRange Gicv3Distributor::GICD_IGROUPR (0x0080, 0x00ff); 5313756Sjairo.balart@metempsy.comconst AddrRange Gicv3Distributor::GICD_ISENABLER (0x0100, 0x017f); 5413756Sjairo.balart@metempsy.comconst AddrRange Gicv3Distributor::GICD_ICENABLER (0x0180, 0x01ff); 5513756Sjairo.balart@metempsy.comconst AddrRange Gicv3Distributor::GICD_ISPENDR (0x0200, 0x027f); 5613756Sjairo.balart@metempsy.comconst AddrRange Gicv3Distributor::GICD_ICPENDR (0x0280, 0x02ff); 5713756Sjairo.balart@metempsy.comconst AddrRange Gicv3Distributor::GICD_ISACTIVER (0x0300, 0x037f); 5813756Sjairo.balart@metempsy.comconst AddrRange Gicv3Distributor::GICD_ICACTIVER (0x0380, 0x03ff); 5913531Sjairo.balart@metempsy.comconst AddrRange Gicv3Distributor::GICD_IPRIORITYR(0x0400, 0x07ff); 6013756Sjairo.balart@metempsy.comconst AddrRange Gicv3Distributor::GICD_ITARGETSR (0x0800, 0x08ff); 6113756Sjairo.balart@metempsy.comconst AddrRange Gicv3Distributor::GICD_ICFGR (0x0c00, 0x0cff); 6213756Sjairo.balart@metempsy.comconst AddrRange Gicv3Distributor::GICD_IGRPMODR (0x0d00, 0x0d7f); 6313756Sjairo.balart@metempsy.comconst AddrRange Gicv3Distributor::GICD_NSACR (0x0e00, 0x0eff); 6413756Sjairo.balart@metempsy.comconst AddrRange Gicv3Distributor::GICD_CPENDSGIR (0x0f10, 0x0f1f); 6513756Sjairo.balart@metempsy.comconst AddrRange Gicv3Distributor::GICD_SPENDSGIR (0x0f20, 0x0f2f); 6613756Sjairo.balart@metempsy.comconst AddrRange Gicv3Distributor::GICD_IROUTER (0x6000, 0x7fe0); 6713531Sjairo.balart@metempsy.com 6813531Sjairo.balart@metempsy.comGicv3Distributor::Gicv3Distributor(Gicv3 * gic, uint32_t it_lines) 6913531Sjairo.balart@metempsy.com : gic(gic), 7013531Sjairo.balart@metempsy.com itLines(it_lines), 7113531Sjairo.balart@metempsy.com irqGroup(it_lines), 7213531Sjairo.balart@metempsy.com irqEnabled(it_lines), 7313531Sjairo.balart@metempsy.com irqPending(it_lines), 7413531Sjairo.balart@metempsy.com irqActive(it_lines), 7513531Sjairo.balart@metempsy.com irqPriority(it_lines), 7613531Sjairo.balart@metempsy.com irqConfig(it_lines), 7713531Sjairo.balart@metempsy.com irqGrpmod(it_lines), 7813531Sjairo.balart@metempsy.com irqNsacr(it_lines), 7914167Sgiacomo.travaglini@arm.com irqAffinityRouting(it_lines), 8014167Sgiacomo.travaglini@arm.com gicdPidr0(0x92), 8114167Sgiacomo.travaglini@arm.com gicdPidr1(0xb4), 8214167Sgiacomo.travaglini@arm.com gicdPidr2(0x3b), 8314167Sgiacomo.travaglini@arm.com gicdPidr3(0), 8414167Sgiacomo.travaglini@arm.com gicdPidr4(0x44) 8513531Sjairo.balart@metempsy.com{ 8613531Sjairo.balart@metempsy.com panic_if(it_lines > Gicv3::INTID_SECURE, "Invalid value for it_lines!"); 8713531Sjairo.balart@metempsy.com} 8813531Sjairo.balart@metempsy.com 8913531Sjairo.balart@metempsy.comvoid 9013531Sjairo.balart@metempsy.comGicv3Distributor::init() 9113531Sjairo.balart@metempsy.com{ 9213531Sjairo.balart@metempsy.com} 9313531Sjairo.balart@metempsy.com 9413531Sjairo.balart@metempsy.comvoid 9513531Sjairo.balart@metempsy.comGicv3Distributor::initState() 9613531Sjairo.balart@metempsy.com{ 9713531Sjairo.balart@metempsy.com reset(); 9813531Sjairo.balart@metempsy.com} 9913531Sjairo.balart@metempsy.com 10013531Sjairo.balart@metempsy.comvoid 10113531Sjairo.balart@metempsy.comGicv3Distributor::reset() 10213531Sjairo.balart@metempsy.com{ 10313531Sjairo.balart@metempsy.com std::fill(irqGroup.begin(), irqGroup.end(), 0); 10413531Sjairo.balart@metempsy.com // Imp. defined reset value 10513531Sjairo.balart@metempsy.com std::fill(irqEnabled.begin(), irqEnabled.end(), false); 10613531Sjairo.balart@metempsy.com std::fill(irqPending.begin(), irqPending.end(), false); 10713531Sjairo.balart@metempsy.com std::fill(irqActive.begin(), irqActive.end(), false); 10813531Sjairo.balart@metempsy.com // Imp. defined reset value 10913531Sjairo.balart@metempsy.com std::fill(irqPriority.begin(), irqPriority.end(), 0xAAAAAAAA); 11013531Sjairo.balart@metempsy.com std::fill(irqConfig.begin(), irqConfig.end(), 11113531Sjairo.balart@metempsy.com Gicv3::INT_LEVEL_SENSITIVE); // Imp. defined reset value 11213531Sjairo.balart@metempsy.com std::fill(irqGrpmod.begin(), irqGrpmod.end(), 0); 11313531Sjairo.balart@metempsy.com std::fill(irqNsacr.begin(), irqNsacr.end(), 0); 11413531Sjairo.balart@metempsy.com /* 11513531Sjairo.balart@metempsy.com * For our implementation affinity routing is always enabled, 11613531Sjairo.balart@metempsy.com * no GICv2 legacy 11713531Sjairo.balart@metempsy.com */ 11813531Sjairo.balart@metempsy.com ARE = true; 11913531Sjairo.balart@metempsy.com 12013531Sjairo.balart@metempsy.com if (gic->getSystem()->haveSecurity()) { 12113531Sjairo.balart@metempsy.com DS = false; 12213531Sjairo.balart@metempsy.com } else { 12313531Sjairo.balart@metempsy.com DS = true; 12413531Sjairo.balart@metempsy.com } 12513531Sjairo.balart@metempsy.com 12613531Sjairo.balart@metempsy.com EnableGrp0 = 0; 12713531Sjairo.balart@metempsy.com EnableGrp1NS = 0; 12813531Sjairo.balart@metempsy.com EnableGrp1S = 0; 12913531Sjairo.balart@metempsy.com} 13013531Sjairo.balart@metempsy.com 13113531Sjairo.balart@metempsy.comuint64_t 13213531Sjairo.balart@metempsy.comGicv3Distributor::read(Addr addr, size_t size, bool is_secure_access) 13313531Sjairo.balart@metempsy.com{ 13413531Sjairo.balart@metempsy.com if (GICD_IGROUPR.contains(addr)) { // Interrupt Group Registers 13513531Sjairo.balart@metempsy.com uint64_t val = 0x0; 13613531Sjairo.balart@metempsy.com 13713531Sjairo.balart@metempsy.com if (!DS && !is_secure_access) { 13813531Sjairo.balart@metempsy.com // RAZ/WI for non-secure accesses 13913531Sjairo.balart@metempsy.com return 0; 14013531Sjairo.balart@metempsy.com } 14113531Sjairo.balart@metempsy.com 14213531Sjairo.balart@metempsy.com int first_intid = (addr - GICD_IGROUPR.start()) * 8; 14313531Sjairo.balart@metempsy.com 14413531Sjairo.balart@metempsy.com if (isNotSPI(first_intid)) { 14513531Sjairo.balart@metempsy.com return 0; 14613531Sjairo.balart@metempsy.com } 14713531Sjairo.balart@metempsy.com 14813531Sjairo.balart@metempsy.com for (int i = 0, int_id = first_intid; i < 8 * size && int_id < itLines; 14913756Sjairo.balart@metempsy.com i++, int_id++) { 15013531Sjairo.balart@metempsy.com val |= irqGroup[int_id] << i; 15113531Sjairo.balart@metempsy.com } 15213531Sjairo.balart@metempsy.com 15313531Sjairo.balart@metempsy.com return val; 15413756Sjairo.balart@metempsy.com } else if (GICD_ISENABLER.contains(addr)) { 15513531Sjairo.balart@metempsy.com // Interrupt Set-Enable Registers 15613531Sjairo.balart@metempsy.com uint64_t val = 0x0; 15713531Sjairo.balart@metempsy.com int first_intid = (addr - GICD_ISENABLER.start()) * 8; 15813531Sjairo.balart@metempsy.com 15913531Sjairo.balart@metempsy.com if (isNotSPI(first_intid)) { 16013531Sjairo.balart@metempsy.com return 0; 16113531Sjairo.balart@metempsy.com } 16213531Sjairo.balart@metempsy.com 16313531Sjairo.balart@metempsy.com for (int i = 0, int_id = first_intid; i < 8 * size && int_id < itLines; 16413756Sjairo.balart@metempsy.com i++, int_id++) { 16513756Sjairo.balart@metempsy.com 16613531Sjairo.balart@metempsy.com if (nsAccessToSecInt(int_id, is_secure_access)) 16713531Sjairo.balart@metempsy.com { 16813531Sjairo.balart@metempsy.com continue; 16913531Sjairo.balart@metempsy.com } 17013531Sjairo.balart@metempsy.com 17113531Sjairo.balart@metempsy.com val |= irqEnabled[int_id] << i; 17213531Sjairo.balart@metempsy.com } 17313531Sjairo.balart@metempsy.com 17413531Sjairo.balart@metempsy.com return val; 17513531Sjairo.balart@metempsy.com } else if (GICD_ICENABLER.contains(addr)) { 17613531Sjairo.balart@metempsy.com // Interrupt Clear-Enable Registers 17713531Sjairo.balart@metempsy.com uint64_t val = 0x0; 17813531Sjairo.balart@metempsy.com int first_intid = (addr - GICD_ICENABLER.start()) * 8; 17913531Sjairo.balart@metempsy.com 18013531Sjairo.balart@metempsy.com if (isNotSPI(first_intid)) { 18113531Sjairo.balart@metempsy.com return 0; 18213531Sjairo.balart@metempsy.com } 18313531Sjairo.balart@metempsy.com 18413531Sjairo.balart@metempsy.com for (int i = 0, int_id = first_intid; i < 8 * size && int_id < itLines; 18513756Sjairo.balart@metempsy.com i++, int_id++) { 18613756Sjairo.balart@metempsy.com 18713531Sjairo.balart@metempsy.com if (nsAccessToSecInt(int_id, is_secure_access)) 18813531Sjairo.balart@metempsy.com { 18913531Sjairo.balart@metempsy.com continue; 19013531Sjairo.balart@metempsy.com } 19113531Sjairo.balart@metempsy.com 19213531Sjairo.balart@metempsy.com val |= (irqEnabled[int_id] << i); 19313531Sjairo.balart@metempsy.com } 19413531Sjairo.balart@metempsy.com 19513531Sjairo.balart@metempsy.com return val; 19613531Sjairo.balart@metempsy.com } else if (GICD_ISPENDR.contains(addr)) { 19713756Sjairo.balart@metempsy.com // Interrupt Set-Pending Registers 19813531Sjairo.balart@metempsy.com uint64_t val = 0x0; 19913531Sjairo.balart@metempsy.com int first_intid = (addr - GICD_ISPENDR.start()) * 8; 20013531Sjairo.balart@metempsy.com 20113531Sjairo.balart@metempsy.com if (isNotSPI(first_intid)) { 20213531Sjairo.balart@metempsy.com return 0; 20313531Sjairo.balart@metempsy.com } 20413531Sjairo.balart@metempsy.com 20513531Sjairo.balart@metempsy.com for (int i = 0, int_id = first_intid; i < 8 * size && int_id < itLines; 20613756Sjairo.balart@metempsy.com i++, int_id++) { 20713756Sjairo.balart@metempsy.com 20813531Sjairo.balart@metempsy.com if (nsAccessToSecInt(int_id, is_secure_access)) 20913531Sjairo.balart@metempsy.com { 21013531Sjairo.balart@metempsy.com if (irqNsacr[int_id] == 0) { 21113531Sjairo.balart@metempsy.com // Group 0 or Secure Group 1 interrupts are RAZ/WI 21213531Sjairo.balart@metempsy.com continue; 21313531Sjairo.balart@metempsy.com } 21413531Sjairo.balart@metempsy.com } 21513531Sjairo.balart@metempsy.com 21613531Sjairo.balart@metempsy.com val |= (irqPending[int_id] << i); 21713531Sjairo.balart@metempsy.com } 21813531Sjairo.balart@metempsy.com 21913531Sjairo.balart@metempsy.com return val; 22013531Sjairo.balart@metempsy.com } else if (GICD_ICPENDR.contains(addr)) { 22113756Sjairo.balart@metempsy.com // Interrupt Clear-Pending Registers 22213531Sjairo.balart@metempsy.com uint64_t val = 0x0; 22313531Sjairo.balart@metempsy.com int first_intid = (addr - GICD_ICPENDR.start()) * 8; 22413531Sjairo.balart@metempsy.com 22513531Sjairo.balart@metempsy.com if (isNotSPI(first_intid)) { 22613531Sjairo.balart@metempsy.com return 0; 22713531Sjairo.balart@metempsy.com } 22813531Sjairo.balart@metempsy.com 22913531Sjairo.balart@metempsy.com for (int i = 0, int_id = first_intid; i < 8 * size && int_id < itLines; 23013756Sjairo.balart@metempsy.com i++, int_id++) { 23113756Sjairo.balart@metempsy.com 23213531Sjairo.balart@metempsy.com if (nsAccessToSecInt(int_id, is_secure_access)) 23313531Sjairo.balart@metempsy.com { 23413531Sjairo.balart@metempsy.com if (irqNsacr[int_id] < 2) { 23513531Sjairo.balart@metempsy.com // Group 0 or Secure Group 1 interrupts are RAZ/WI 23613531Sjairo.balart@metempsy.com continue; 23713531Sjairo.balart@metempsy.com } 23813531Sjairo.balart@metempsy.com } 23913531Sjairo.balart@metempsy.com 24013531Sjairo.balart@metempsy.com val |= (irqPending[int_id] << i); 24113531Sjairo.balart@metempsy.com } 24213531Sjairo.balart@metempsy.com 24313531Sjairo.balart@metempsy.com return val; 24413756Sjairo.balart@metempsy.com } else if (GICD_ISACTIVER.contains(addr)) { 24513531Sjairo.balart@metempsy.com // Interrupt Set-Active Registers 24613531Sjairo.balart@metempsy.com int first_intid = (addr - GICD_ISACTIVER.start()) * 8; 24713531Sjairo.balart@metempsy.com 24813531Sjairo.balart@metempsy.com if (isNotSPI(first_intid)) { 24913531Sjairo.balart@metempsy.com return 0; 25013531Sjairo.balart@metempsy.com } 25113531Sjairo.balart@metempsy.com 25213531Sjairo.balart@metempsy.com uint64_t val = 0x0; 25313531Sjairo.balart@metempsy.com 25413531Sjairo.balart@metempsy.com for (int i = 0, int_id = first_intid; i < 8 * size && int_id < itLines; 25513756Sjairo.balart@metempsy.com i++, int_id++) { 25613756Sjairo.balart@metempsy.com 25713531Sjairo.balart@metempsy.com if (nsAccessToSecInt(int_id, is_secure_access)) 25813531Sjairo.balart@metempsy.com { 25913531Sjairo.balart@metempsy.com // Group 0 or Secure Group 1 interrupts are RAZ/WI 26013531Sjairo.balart@metempsy.com if (irqNsacr[int_id] < 2) { 26113531Sjairo.balart@metempsy.com continue; 26213531Sjairo.balart@metempsy.com } 26313531Sjairo.balart@metempsy.com } 26413531Sjairo.balart@metempsy.com 26513531Sjairo.balart@metempsy.com val |= (irqActive[int_id] << i); 26613531Sjairo.balart@metempsy.com } 26713531Sjairo.balart@metempsy.com 26813531Sjairo.balart@metempsy.com return val; 26913756Sjairo.balart@metempsy.com } else if (GICD_ICACTIVER.contains(addr)) { 27013531Sjairo.balart@metempsy.com // Interrupt Clear-Active Registers 27113531Sjairo.balart@metempsy.com int first_intid = (addr - GICD_ICACTIVER.start()) * 8; 27213531Sjairo.balart@metempsy.com 27313531Sjairo.balart@metempsy.com if (isNotSPI(first_intid)) { 27413531Sjairo.balart@metempsy.com return 0; 27513531Sjairo.balart@metempsy.com } 27613531Sjairo.balart@metempsy.com 27713531Sjairo.balart@metempsy.com uint64_t val = 0x0; 27813531Sjairo.balart@metempsy.com 27913531Sjairo.balart@metempsy.com for (int i = 0, int_id = first_intid; i < 8 * size && int_id < itLines; 28013756Sjairo.balart@metempsy.com i++, int_id++) { 28113756Sjairo.balart@metempsy.com 28213531Sjairo.balart@metempsy.com if (nsAccessToSecInt(int_id, is_secure_access)) 28313531Sjairo.balart@metempsy.com { 28413531Sjairo.balart@metempsy.com if (irqNsacr[int_id] < 2) { 28513531Sjairo.balart@metempsy.com continue; 28613531Sjairo.balart@metempsy.com } 28713531Sjairo.balart@metempsy.com } 28813531Sjairo.balart@metempsy.com 28913531Sjairo.balart@metempsy.com val |= (irqActive[int_id] << i); 29013531Sjairo.balart@metempsy.com } 29113531Sjairo.balart@metempsy.com 29213531Sjairo.balart@metempsy.com return val; 29313756Sjairo.balart@metempsy.com } else if (GICD_IPRIORITYR.contains(addr)) { 29413531Sjairo.balart@metempsy.com // Interrupt Priority Registers 29513531Sjairo.balart@metempsy.com uint64_t val = 0x0; 29613531Sjairo.balart@metempsy.com int first_intid = addr - GICD_IPRIORITYR.start(); 29713531Sjairo.balart@metempsy.com 29813531Sjairo.balart@metempsy.com if (isNotSPI(first_intid)) { 29913531Sjairo.balart@metempsy.com return 0; 30013531Sjairo.balart@metempsy.com } 30113531Sjairo.balart@metempsy.com 30213531Sjairo.balart@metempsy.com for (int i = 0, int_id = first_intid; i < size && int_id < itLines; 30313756Sjairo.balart@metempsy.com i++, int_id++) { 30413756Sjairo.balart@metempsy.com 30513531Sjairo.balart@metempsy.com uint8_t prio = irqPriority[int_id]; 30613531Sjairo.balart@metempsy.com 30713531Sjairo.balart@metempsy.com if (!DS && !is_secure_access) { 30813531Sjairo.balart@metempsy.com if (getIntGroup(int_id) != Gicv3::G1NS) { 30913531Sjairo.balart@metempsy.com // RAZ/WI for non-secure accesses for secure interrupts 31013531Sjairo.balart@metempsy.com continue; 31113531Sjairo.balart@metempsy.com } else { 31213531Sjairo.balart@metempsy.com // NS view 31313531Sjairo.balart@metempsy.com prio = (prio << 1) & 0xff; 31413531Sjairo.balart@metempsy.com } 31513531Sjairo.balart@metempsy.com } 31613531Sjairo.balart@metempsy.com 31713531Sjairo.balart@metempsy.com val |= prio << (i * 8); 31813531Sjairo.balart@metempsy.com } 31913531Sjairo.balart@metempsy.com 32013531Sjairo.balart@metempsy.com return val; 32113531Sjairo.balart@metempsy.com } else if (GICD_ITARGETSR.contains(addr)) { 32213531Sjairo.balart@metempsy.com // Interrupt Processor Targets Registers 32313531Sjairo.balart@metempsy.com // ARE always on, RAZ/WI 32413531Sjairo.balart@metempsy.com warn("Gicv3Distributor::read(): " 32513531Sjairo.balart@metempsy.com "GICD_ITARGETSR is RAZ/WI, legacy not supported!\n"); 32613531Sjairo.balart@metempsy.com return 0; 32713756Sjairo.balart@metempsy.com } else if (GICD_ICFGR.contains(addr)) { 32813531Sjairo.balart@metempsy.com // Interrupt Configuration Registers 32913531Sjairo.balart@metempsy.com int first_intid = (addr - GICD_ICFGR.start()) * 4; 33013531Sjairo.balart@metempsy.com 33113531Sjairo.balart@metempsy.com if (isNotSPI(first_intid)) { 33213531Sjairo.balart@metempsy.com return 0; 33313531Sjairo.balart@metempsy.com } 33413531Sjairo.balart@metempsy.com 33513531Sjairo.balart@metempsy.com uint64_t val = 0x0; 33613531Sjairo.balart@metempsy.com 33713531Sjairo.balart@metempsy.com for (int i = 0, int_id = first_intid; i < 8 * size && int_id < itLines; 33813756Sjairo.balart@metempsy.com i = i + 2, int_id++) { 33913756Sjairo.balart@metempsy.com 34013531Sjairo.balart@metempsy.com if (nsAccessToSecInt(int_id, is_secure_access)) 34113531Sjairo.balart@metempsy.com { 34213531Sjairo.balart@metempsy.com continue; 34313531Sjairo.balart@metempsy.com } 34413531Sjairo.balart@metempsy.com 34513531Sjairo.balart@metempsy.com if (irqConfig[int_id] == Gicv3::INT_EDGE_TRIGGERED) { 34613531Sjairo.balart@metempsy.com val |= (0x2 << i); 34713531Sjairo.balart@metempsy.com } 34813531Sjairo.balart@metempsy.com } 34913531Sjairo.balart@metempsy.com 35013531Sjairo.balart@metempsy.com return val; 35113531Sjairo.balart@metempsy.com } else if (GICD_IGRPMODR.contains(addr)) { 35213531Sjairo.balart@metempsy.com // Interrupt Group Modifier Registers 35313531Sjairo.balart@metempsy.com if (DS) { 35413531Sjairo.balart@metempsy.com // RAZ/WI if security disabled 35513531Sjairo.balart@metempsy.com return 0; 35613531Sjairo.balart@metempsy.com } else { 35713531Sjairo.balart@metempsy.com if (!is_secure_access) { 35813531Sjairo.balart@metempsy.com // RAZ/WI for non-secure accesses 35913531Sjairo.balart@metempsy.com return 0; 36013531Sjairo.balart@metempsy.com } else { 36113531Sjairo.balart@metempsy.com int first_intid = (addr - GICD_IGRPMODR.start()) * 8; 36213531Sjairo.balart@metempsy.com 36313531Sjairo.balart@metempsy.com if (isNotSPI(first_intid)) { 36413531Sjairo.balart@metempsy.com return 0; 36513531Sjairo.balart@metempsy.com } 36613531Sjairo.balart@metempsy.com 36713531Sjairo.balart@metempsy.com uint64_t val = 0x0; 36813531Sjairo.balart@metempsy.com 36913531Sjairo.balart@metempsy.com for (int i = 0, int_id = first_intid; 37013756Sjairo.balart@metempsy.com i < 8 * size && int_id < itLines; i++, int_id++) { 37113531Sjairo.balart@metempsy.com val |= irqGrpmod[int_id] << i; 37213531Sjairo.balart@metempsy.com } 37313531Sjairo.balart@metempsy.com 37413531Sjairo.balart@metempsy.com return val; 37513531Sjairo.balart@metempsy.com } 37613531Sjairo.balart@metempsy.com } 37713756Sjairo.balart@metempsy.com } else if (GICD_NSACR.contains(addr)) { 37813531Sjairo.balart@metempsy.com // Non-secure Access Control Registers 37913531Sjairo.balart@metempsy.com // 2 bits per interrupt 38013531Sjairo.balart@metempsy.com int first_intid = (addr - GICD_NSACR.start()) * 4; 38113531Sjairo.balart@metempsy.com 38213531Sjairo.balart@metempsy.com if (isNotSPI(first_intid)) { 38313531Sjairo.balart@metempsy.com return 0; 38413531Sjairo.balart@metempsy.com } 38513531Sjairo.balart@metempsy.com 38613531Sjairo.balart@metempsy.com if (DS || (!DS && !is_secure_access)) { 38713531Sjairo.balart@metempsy.com return 0; 38813531Sjairo.balart@metempsy.com } 38913531Sjairo.balart@metempsy.com 39013531Sjairo.balart@metempsy.com uint64_t val = 0x0; 39113531Sjairo.balart@metempsy.com 39213531Sjairo.balart@metempsy.com for (int i = 0, int_id = first_intid; 39313756Sjairo.balart@metempsy.com i < 8 * size && int_id < itLines; i = i + 2, int_id++) { 39413531Sjairo.balart@metempsy.com val |= irqNsacr[int_id] << i; 39513531Sjairo.balart@metempsy.com } 39613531Sjairo.balart@metempsy.com 39713531Sjairo.balart@metempsy.com return val; 39813531Sjairo.balart@metempsy.com } else if (GICD_CPENDSGIR.contains(addr)) { // SGI Clear-Pending Registers 39913531Sjairo.balart@metempsy.com // ARE always on, RAZ/WI 40013531Sjairo.balart@metempsy.com warn("Gicv3Distributor::read(): " 40113531Sjairo.balart@metempsy.com "GICD_CPENDSGIR is RAZ/WI, legacy not supported!\n"); 40213531Sjairo.balart@metempsy.com return 0x0; 40313531Sjairo.balart@metempsy.com } else if (GICD_SPENDSGIR.contains(addr)) { // SGI Set-Pending Registers 40413531Sjairo.balart@metempsy.com // ARE always on, RAZ/WI 40513531Sjairo.balart@metempsy.com warn("Gicv3Distributor::read(): " 40613531Sjairo.balart@metempsy.com "GICD_SPENDSGIR is RAZ/WI, legacy not supported!\n"); 40713531Sjairo.balart@metempsy.com return 0x0; 40813531Sjairo.balart@metempsy.com } else if (GICD_IROUTER.contains(addr)) { // Interrupt Routing Registers 40913531Sjairo.balart@metempsy.com // 64 bit registers. 2 or 1 access. 41013531Sjairo.balart@metempsy.com int int_id = (addr - GICD_IROUTER.start()) / 8; 41113531Sjairo.balart@metempsy.com 41213531Sjairo.balart@metempsy.com if (isNotSPI(int_id)) { 41313531Sjairo.balart@metempsy.com return 0; 41413531Sjairo.balart@metempsy.com } 41513531Sjairo.balart@metempsy.com 41613531Sjairo.balart@metempsy.com if (nsAccessToSecInt(int_id, is_secure_access)) 41713531Sjairo.balart@metempsy.com { 41813531Sjairo.balart@metempsy.com if (irqNsacr[int_id] < 3) { 41913531Sjairo.balart@metempsy.com return 0; 42013531Sjairo.balart@metempsy.com } 42113531Sjairo.balart@metempsy.com } 42213531Sjairo.balart@metempsy.com 42313531Sjairo.balart@metempsy.com if (size == 4) { 42413531Sjairo.balart@metempsy.com if (addr & 7) { // high half of 64 bit register 42513531Sjairo.balart@metempsy.com return irqAffinityRouting[int_id] >> 32; 42613531Sjairo.balart@metempsy.com } else { // high low of 64 bit register 42713531Sjairo.balart@metempsy.com return irqAffinityRouting[int_id] & 0xFFFFFFFF; 42813531Sjairo.balart@metempsy.com } 42913531Sjairo.balart@metempsy.com } else { 43013531Sjairo.balart@metempsy.com return irqAffinityRouting[int_id]; 43113531Sjairo.balart@metempsy.com } 43213531Sjairo.balart@metempsy.com } 43313531Sjairo.balart@metempsy.com 43413531Sjairo.balart@metempsy.com switch (addr) { 43513531Sjairo.balart@metempsy.com case GICD_CTLR: // Control Register 43613531Sjairo.balart@metempsy.com if (!DS) { 43713531Sjairo.balart@metempsy.com if (is_secure_access) { 43813531Sjairo.balart@metempsy.com // E1NWF [7] RAZ/WI 43913531Sjairo.balart@metempsy.com // DS [6] - Disable Security 44013531Sjairo.balart@metempsy.com // ARE_NS [5] RAO/WI 44113531Sjairo.balart@metempsy.com // ARE_S [4] RAO/WI 44213531Sjairo.balart@metempsy.com // EnableGrp1S [2] 44313531Sjairo.balart@metempsy.com // EnableGrp1NS [1] 44413531Sjairo.balart@metempsy.com // EnableGrp0 [0] 44513531Sjairo.balart@metempsy.com return (EnableGrp0 << 0) | 44613531Sjairo.balart@metempsy.com (EnableGrp1NS << 1) | 44713531Sjairo.balart@metempsy.com (EnableGrp1S << 2) | 44813531Sjairo.balart@metempsy.com (1 << 4) | 44913531Sjairo.balart@metempsy.com (1 << 5) | 45013531Sjairo.balart@metempsy.com (DS << 6); 45113531Sjairo.balart@metempsy.com } else { 45213531Sjairo.balart@metempsy.com // ARE_NS [4] RAO/WI; 45313531Sjairo.balart@metempsy.com // EnableGrp1A [1] is a read-write alias of the Secure 45413531Sjairo.balart@metempsy.com // GICD_CTLR.EnableGrp1NS 45513531Sjairo.balart@metempsy.com // EnableGrp1 [0] RES0 45613531Sjairo.balart@metempsy.com return (1 << 4) | (EnableGrp1NS << 1); 45713531Sjairo.balart@metempsy.com } 45813531Sjairo.balart@metempsy.com } else { 45913531Sjairo.balart@metempsy.com return (DS << 6) | (ARE << 4) | 46013531Sjairo.balart@metempsy.com (EnableGrp1NS << 1) | (EnableGrp0 << 0); 46113531Sjairo.balart@metempsy.com } 46213531Sjairo.balart@metempsy.com 46313531Sjairo.balart@metempsy.com case GICD_TYPER: // Interrupt Controller Type Register 46413531Sjairo.balart@metempsy.com /* 46513531Sjairo.balart@metempsy.com * RSS [26] == 1 46613531Sjairo.balart@metempsy.com * (The implementation does supports targeted SGIs with affinity 46713531Sjairo.balart@metempsy.com * level 0 values of 0 - 255) 46813531Sjairo.balart@metempsy.com * No1N [25] == 1 46913531Sjairo.balart@metempsy.com * (1 of N SPI interrupts are not supported) 47013531Sjairo.balart@metempsy.com * A3V [24] == 1 47113531Sjairo.balart@metempsy.com * (Supports nonzero values of Affinity level 3) 47213531Sjairo.balart@metempsy.com * IDbits [23:19] == 0xf 47313531Sjairo.balart@metempsy.com * (The number of interrupt identifier bits supported, minus one) 47413531Sjairo.balart@metempsy.com * DVIS [18] == 0 47513531Sjairo.balart@metempsy.com * (The implementation does not support Direct Virtual LPI 47613531Sjairo.balart@metempsy.com * injection) 47713690Sjairo.balart@metempsy.com * LPIS [17] == 1 47813531Sjairo.balart@metempsy.com * (The implementation does not support LPIs) 47913531Sjairo.balart@metempsy.com * MBIS [16] == 0 48013531Sjairo.balart@metempsy.com * (The implementation does not support message-based interrupts 48113531Sjairo.balart@metempsy.com * by writing to Distributor registers) 48213531Sjairo.balart@metempsy.com * SecurityExtn [10] == X 48313531Sjairo.balart@metempsy.com * (The GIC implementation supports two Security states) 48413531Sjairo.balart@metempsy.com * CPUNumber [7:5] == 0 48513531Sjairo.balart@metempsy.com * (since for us ARE is always 1 [(ARE = 0) == Gicv2 legacy]) 48613531Sjairo.balart@metempsy.com * ITLinesNumber [4:0] == N 48713531Sjairo.balart@metempsy.com * (MaxSPIIntId = 32 (N + 1) - 1) 48813531Sjairo.balart@metempsy.com */ 48913531Sjairo.balart@metempsy.com { 49013531Sjairo.balart@metempsy.com int max_spi_int_id = itLines - 1; 49113531Sjairo.balart@metempsy.com int it_lines_number = ceil((max_spi_int_id + 1) / 32.0) - 1; 49213927Sgiacomo.travaglini@arm.com return (1 << 26) | (1 << 25) | (1 << 24) | (IDBITS << 19) | 49313690Sjairo.balart@metempsy.com (1 << 17) | (gic->getSystem()->haveSecurity() << 10) | 49413531Sjairo.balart@metempsy.com (it_lines_number << 0); 49513531Sjairo.balart@metempsy.com } 49613531Sjairo.balart@metempsy.com 49713531Sjairo.balart@metempsy.com case GICD_IIDR: // Implementer Identification Register 49813531Sjairo.balart@metempsy.com //return 0x43b; // ARM JEP106 code (r0p0 GIC-500) 49913531Sjairo.balart@metempsy.com return 0; 50013531Sjairo.balart@metempsy.com 50113531Sjairo.balart@metempsy.com case GICD_STATUSR: // Error Reporting Status Register 50213531Sjairo.balart@metempsy.com // Optional register, RAZ/WI 50313531Sjairo.balart@metempsy.com return 0x0; 50413531Sjairo.balart@metempsy.com 50513756Sjairo.balart@metempsy.com case GICD_PIDR0: // Peripheral ID0 Register 50614167Sgiacomo.travaglini@arm.com return gicdPidr0; 50713531Sjairo.balart@metempsy.com 50814167Sgiacomo.travaglini@arm.com case GICD_PIDR1: // Peripheral ID1 Register 50914167Sgiacomo.travaglini@arm.com return gicdPidr1; 51013531Sjairo.balart@metempsy.com 51114167Sgiacomo.travaglini@arm.com case GICD_PIDR2: // Peripheral ID2 Register 51214167Sgiacomo.travaglini@arm.com return gicdPidr2; 51313531Sjairo.balart@metempsy.com 51413531Sjairo.balart@metempsy.com case GICD_PIDR3: // Peripheral ID3 Register 51514167Sgiacomo.travaglini@arm.com return gicdPidr3; 51613531Sjairo.balart@metempsy.com 51714167Sgiacomo.travaglini@arm.com case GICD_PIDR4: // Peripheral ID4 Register 51814167Sgiacomo.travaglini@arm.com return gicdPidr4; 51913531Sjairo.balart@metempsy.com 52013531Sjairo.balart@metempsy.com case GICD_PIDR5: // Peripheral ID5 Register 52113531Sjairo.balart@metempsy.com case GICD_PIDR6: // Peripheral ID6 Register 52213531Sjairo.balart@metempsy.com case GICD_PIDR7: // Peripheral ID7 Register 52313531Sjairo.balart@metempsy.com return 0; // RES0 52413531Sjairo.balart@metempsy.com 52513531Sjairo.balart@metempsy.com default: 52613531Sjairo.balart@metempsy.com panic("Gicv3Distributor::read(): invalid offset %#x\n", addr); 52713531Sjairo.balart@metempsy.com break; 52813531Sjairo.balart@metempsy.com } 52913531Sjairo.balart@metempsy.com} 53013531Sjairo.balart@metempsy.com 53113531Sjairo.balart@metempsy.comvoid 53213531Sjairo.balart@metempsy.comGicv3Distributor::write(Addr addr, uint64_t data, size_t size, 53313531Sjairo.balart@metempsy.com bool is_secure_access) 53413531Sjairo.balart@metempsy.com{ 53513531Sjairo.balart@metempsy.com if (GICD_IGROUPR.contains(addr)) { // Interrupt Group Registers 53613531Sjairo.balart@metempsy.com if (!DS && !is_secure_access) { 53713531Sjairo.balart@metempsy.com // RAZ/WI for non-secure accesses 53813531Sjairo.balart@metempsy.com return; 53913531Sjairo.balart@metempsy.com } 54013531Sjairo.balart@metempsy.com 54113531Sjairo.balart@metempsy.com int first_intid = (addr - GICD_IGROUPR.start()) * 8; 54213531Sjairo.balart@metempsy.com 54313531Sjairo.balart@metempsy.com if (isNotSPI(first_intid)) { 54413531Sjairo.balart@metempsy.com return; 54513531Sjairo.balart@metempsy.com } 54613531Sjairo.balart@metempsy.com 54713531Sjairo.balart@metempsy.com for (int i = 0, int_id = first_intid; i < 8 * size && int_id < itLines; 54813756Sjairo.balart@metempsy.com i++, int_id++) { 54913531Sjairo.balart@metempsy.com irqGroup[int_id] = data & (1 << i) ? 1 : 0; 55013531Sjairo.balart@metempsy.com DPRINTF(GIC, "Gicv3Distributor::write(): int_id %d group %d\n", 55113531Sjairo.balart@metempsy.com int_id, irqGroup[int_id]); 55213531Sjairo.balart@metempsy.com } 55313531Sjairo.balart@metempsy.com 55413531Sjairo.balart@metempsy.com return; 55513756Sjairo.balart@metempsy.com } else if (GICD_ISENABLER.contains(addr)) { 55613531Sjairo.balart@metempsy.com // Interrupt Set-Enable Registers 55713531Sjairo.balart@metempsy.com int first_intid = (addr - GICD_ISENABLER.start()) * 8; 55813531Sjairo.balart@metempsy.com 55913531Sjairo.balart@metempsy.com if (isNotSPI(first_intid)) { 56013531Sjairo.balart@metempsy.com return; 56113531Sjairo.balart@metempsy.com } 56213531Sjairo.balart@metempsy.com 56313531Sjairo.balart@metempsy.com for (int i = 0, int_id = first_intid; i < 8 * size && int_id < itLines; 56413756Sjairo.balart@metempsy.com i++, int_id++) { 56513756Sjairo.balart@metempsy.com 56613531Sjairo.balart@metempsy.com if (nsAccessToSecInt(int_id, is_secure_access)) 56713531Sjairo.balart@metempsy.com { 56813531Sjairo.balart@metempsy.com continue; 56913531Sjairo.balart@metempsy.com } 57013531Sjairo.balart@metempsy.com 57113531Sjairo.balart@metempsy.com bool enable = data & (1 << i) ? 1 : 0; 57213531Sjairo.balart@metempsy.com 57313531Sjairo.balart@metempsy.com if (enable) { 57413531Sjairo.balart@metempsy.com if (!irqEnabled[int_id]) { 57513531Sjairo.balart@metempsy.com DPRINTF(GIC, "Gicv3Distributor::write(): " 57613531Sjairo.balart@metempsy.com "int_id %d enabled\n", int_id); 57713531Sjairo.balart@metempsy.com } 57813531Sjairo.balart@metempsy.com 57913531Sjairo.balart@metempsy.com irqEnabled[int_id] = true; 58013531Sjairo.balart@metempsy.com } 58113531Sjairo.balart@metempsy.com } 58213531Sjairo.balart@metempsy.com 58313531Sjairo.balart@metempsy.com return; 58413531Sjairo.balart@metempsy.com } else if (GICD_ICENABLER.contains(addr)) { 58513531Sjairo.balart@metempsy.com // Interrupt Clear-Enable Registers 58613531Sjairo.balart@metempsy.com int first_intid = (addr - GICD_ICENABLER.start()) * 8; 58713531Sjairo.balart@metempsy.com 58813812Sgiacomo.travaglini@arm.com if (isNotSPI(first_intid)) { 58913812Sgiacomo.travaglini@arm.com return; 59013812Sgiacomo.travaglini@arm.com } 59113812Sgiacomo.travaglini@arm.com 59213531Sjairo.balart@metempsy.com for (int i = 0, int_id = first_intid; i < 8 * size && int_id < itLines; 59313756Sjairo.balart@metempsy.com i++, int_id++) { 59413756Sjairo.balart@metempsy.com 59513531Sjairo.balart@metempsy.com if (nsAccessToSecInt(int_id, is_secure_access)) 59613531Sjairo.balart@metempsy.com { 59713531Sjairo.balart@metempsy.com continue; 59813531Sjairo.balart@metempsy.com } 59913531Sjairo.balart@metempsy.com 60013531Sjairo.balart@metempsy.com bool disable = data & (1 << i) ? 1 : 0; 60113531Sjairo.balart@metempsy.com 60213531Sjairo.balart@metempsy.com if (disable) { 60313531Sjairo.balart@metempsy.com if (irqEnabled[int_id]) { 60413531Sjairo.balart@metempsy.com DPRINTF(GIC, "Gicv3Distributor::write(): " 60513531Sjairo.balart@metempsy.com "int_id %d disabled\n", int_id); 60613531Sjairo.balart@metempsy.com } 60713531Sjairo.balart@metempsy.com 60813531Sjairo.balart@metempsy.com irqEnabled[int_id] = false; 60913531Sjairo.balart@metempsy.com } 61013531Sjairo.balart@metempsy.com } 61113531Sjairo.balart@metempsy.com 61213531Sjairo.balart@metempsy.com return; 61313531Sjairo.balart@metempsy.com } else if (GICD_ISPENDR.contains(addr)) { 61413756Sjairo.balart@metempsy.com // Interrupt Set-Pending Registers 61513531Sjairo.balart@metempsy.com int first_intid = (addr - GICD_ISPENDR.start()) * 8; 61613531Sjairo.balart@metempsy.com 61713531Sjairo.balart@metempsy.com if (isNotSPI(first_intid)) { 61813531Sjairo.balart@metempsy.com return; 61913531Sjairo.balart@metempsy.com } 62013531Sjairo.balart@metempsy.com 62113531Sjairo.balart@metempsy.com for (int i = 0, int_id = first_intid; i < 8 * size && int_id < itLines; 62213756Sjairo.balart@metempsy.com i++, int_id++) { 62313756Sjairo.balart@metempsy.com 62413531Sjairo.balart@metempsy.com if (nsAccessToSecInt(int_id, is_secure_access)) 62513531Sjairo.balart@metempsy.com { 62613531Sjairo.balart@metempsy.com if (irqNsacr[int_id] == 0) { 62713531Sjairo.balart@metempsy.com // Group 0 or Secure Group 1 interrupts are RAZ/WI 62813531Sjairo.balart@metempsy.com continue; 62913531Sjairo.balart@metempsy.com } 63013531Sjairo.balart@metempsy.com } 63113531Sjairo.balart@metempsy.com 63213531Sjairo.balart@metempsy.com bool pending = data & (1 << i) ? 1 : 0; 63313531Sjairo.balart@metempsy.com 63413531Sjairo.balart@metempsy.com if (pending) { 63513531Sjairo.balart@metempsy.com DPRINTF(GIC, "Gicv3Distributor::write() (GICD_ISPENDR): " 63613531Sjairo.balart@metempsy.com "int_id %d (SPI) pending bit set\n", int_id); 63713531Sjairo.balart@metempsy.com irqPending[int_id] = true; 63813531Sjairo.balart@metempsy.com } 63913531Sjairo.balart@metempsy.com } 64013531Sjairo.balart@metempsy.com 64114231Sgiacomo.travaglini@arm.com update(); 64213531Sjairo.balart@metempsy.com return; 64313531Sjairo.balart@metempsy.com } else if (GICD_ICPENDR.contains(addr)) { 64413756Sjairo.balart@metempsy.com // Interrupt Clear-Pending Registers 64513531Sjairo.balart@metempsy.com int first_intid = (addr - GICD_ICPENDR.start()) * 8; 64613531Sjairo.balart@metempsy.com 64713531Sjairo.balart@metempsy.com if (isNotSPI(first_intid)) { 64813531Sjairo.balart@metempsy.com return; 64913531Sjairo.balart@metempsy.com } 65013531Sjairo.balart@metempsy.com 65113531Sjairo.balart@metempsy.com for (int i = 0, int_id = first_intid; i < 8 * size && int_id < itLines; 65213756Sjairo.balart@metempsy.com i++, int_id++) { 65313756Sjairo.balart@metempsy.com 65413531Sjairo.balart@metempsy.com if (nsAccessToSecInt(int_id, is_secure_access)) 65513531Sjairo.balart@metempsy.com { 65613531Sjairo.balart@metempsy.com if (irqNsacr[int_id] < 2) { 65713531Sjairo.balart@metempsy.com // Group 0 or Secure Group 1 interrupts are RAZ/WI 65813531Sjairo.balart@metempsy.com continue; 65913531Sjairo.balart@metempsy.com } 66013531Sjairo.balart@metempsy.com } 66113531Sjairo.balart@metempsy.com 66213531Sjairo.balart@metempsy.com bool clear = data & (1 << i) ? 1 : 0; 66313531Sjairo.balart@metempsy.com 66413531Sjairo.balart@metempsy.com if (clear) { 66513531Sjairo.balart@metempsy.com irqPending[int_id] = false; 66614231Sgiacomo.travaglini@arm.com clearIrqCpuInterface(int_id); 66713531Sjairo.balart@metempsy.com } 66813531Sjairo.balart@metempsy.com } 66913531Sjairo.balart@metempsy.com 67014231Sgiacomo.travaglini@arm.com update(); 67113531Sjairo.balart@metempsy.com return; 67213756Sjairo.balart@metempsy.com } else if (GICD_ISACTIVER.contains(addr)) { 67313531Sjairo.balart@metempsy.com // Interrupt Set-Active Registers 67413531Sjairo.balart@metempsy.com int first_intid = (addr - GICD_ISACTIVER.start()) * 8; 67513531Sjairo.balart@metempsy.com 67613531Sjairo.balart@metempsy.com if (isNotSPI(first_intid)) { 67713531Sjairo.balart@metempsy.com return; 67813531Sjairo.balart@metempsy.com } 67913531Sjairo.balart@metempsy.com 68013531Sjairo.balart@metempsy.com for (int i = 0, int_id = first_intid; i < 8 * size && int_id < itLines; 68113756Sjairo.balart@metempsy.com i++, int_id++) { 68213756Sjairo.balart@metempsy.com 68313531Sjairo.balart@metempsy.com if (nsAccessToSecInt(int_id, is_secure_access)) 68413531Sjairo.balart@metempsy.com { 68513531Sjairo.balart@metempsy.com continue; 68613531Sjairo.balart@metempsy.com } 68713531Sjairo.balart@metempsy.com 68813531Sjairo.balart@metempsy.com bool active = data & (1 << i) ? 1 : 0; 68913531Sjairo.balart@metempsy.com 69013531Sjairo.balart@metempsy.com if (active) { 69113531Sjairo.balart@metempsy.com irqActive[int_id] = 1; 69213531Sjairo.balart@metempsy.com } 69313531Sjairo.balart@metempsy.com } 69413531Sjairo.balart@metempsy.com 69513531Sjairo.balart@metempsy.com return; 69613531Sjairo.balart@metempsy.com } else if (GICD_ICACTIVER.contains(addr)) { 69713531Sjairo.balart@metempsy.com // Interrupt Clear-Active Registers 69813531Sjairo.balart@metempsy.com int first_intid = (addr - GICD_ICACTIVER.start()) * 8; 69913531Sjairo.balart@metempsy.com 70013531Sjairo.balart@metempsy.com if (isNotSPI(first_intid)) { 70113531Sjairo.balart@metempsy.com return; 70213531Sjairo.balart@metempsy.com } 70313531Sjairo.balart@metempsy.com 70413531Sjairo.balart@metempsy.com for (int i = 0, int_id = first_intid; i < 8 * size && int_id < itLines; 70513756Sjairo.balart@metempsy.com i++, int_id++) { 70613756Sjairo.balart@metempsy.com 70713531Sjairo.balart@metempsy.com if (nsAccessToSecInt(int_id, is_secure_access)) 70813531Sjairo.balart@metempsy.com { 70913531Sjairo.balart@metempsy.com continue; 71013531Sjairo.balart@metempsy.com } 71113531Sjairo.balart@metempsy.com 71213531Sjairo.balart@metempsy.com bool clear = data & (1 << i) ? 1 : 0; 71313531Sjairo.balart@metempsy.com 71413531Sjairo.balart@metempsy.com if (clear) { 71513531Sjairo.balart@metempsy.com if (irqActive[int_id]) { 71613531Sjairo.balart@metempsy.com DPRINTF(GIC, "Gicv3Distributor::write(): " 71713531Sjairo.balart@metempsy.com "int_id %d active cleared\n", int_id); 71813531Sjairo.balart@metempsy.com } 71913531Sjairo.balart@metempsy.com 72013531Sjairo.balart@metempsy.com irqActive[int_id] = false; 72113531Sjairo.balart@metempsy.com } 72213531Sjairo.balart@metempsy.com } 72313531Sjairo.balart@metempsy.com 72413531Sjairo.balart@metempsy.com return; 72513756Sjairo.balart@metempsy.com } else if (GICD_IPRIORITYR.contains(addr)) { 72613531Sjairo.balart@metempsy.com // Interrupt Priority Registers 72713531Sjairo.balart@metempsy.com int first_intid = addr - GICD_IPRIORITYR.start(); 72813531Sjairo.balart@metempsy.com 72913531Sjairo.balart@metempsy.com if (isNotSPI(first_intid)) { 73013531Sjairo.balart@metempsy.com return; 73113531Sjairo.balart@metempsy.com } 73213531Sjairo.balart@metempsy.com 73313531Sjairo.balart@metempsy.com for (int i = 0, int_id = first_intid; i < size && int_id < itLines; 73413531Sjairo.balart@metempsy.com i++, int_id++) { 73513531Sjairo.balart@metempsy.com uint8_t prio = bits(data, (i + 1) * 8 - 1, (i * 8)); 73613531Sjairo.balart@metempsy.com 73713531Sjairo.balart@metempsy.com if (!DS && !is_secure_access) { 73813531Sjairo.balart@metempsy.com if (getIntGroup(int_id) != Gicv3::G1NS) { 73913531Sjairo.balart@metempsy.com // RAZ/WI for non-secure accesses to secure interrupts 74013531Sjairo.balart@metempsy.com continue; 74113531Sjairo.balart@metempsy.com } else { 74213531Sjairo.balart@metempsy.com prio = 0x80 | (prio >> 1); 74313531Sjairo.balart@metempsy.com } 74413531Sjairo.balart@metempsy.com } 74513531Sjairo.balart@metempsy.com 74613531Sjairo.balart@metempsy.com irqPriority[int_id] = prio; 74713531Sjairo.balart@metempsy.com DPRINTF(GIC, "Gicv3Distributor::write(): int_id %d priority %d\n", 74813531Sjairo.balart@metempsy.com int_id, irqPriority[int_id]); 74913531Sjairo.balart@metempsy.com } 75013531Sjairo.balart@metempsy.com 75113531Sjairo.balart@metempsy.com return; 75213531Sjairo.balart@metempsy.com } else if (GICD_ITARGETSR.contains(addr)) { 75313531Sjairo.balart@metempsy.com // Interrupt Processor Targets Registers 75413531Sjairo.balart@metempsy.com // ARE always on, RAZ/WI 75513531Sjairo.balart@metempsy.com warn("Gicv3Distributor::write(): " 75613531Sjairo.balart@metempsy.com "GICD_ITARGETSR is RAZ/WI, legacy not supported!\n"); 75713531Sjairo.balart@metempsy.com return; 75813756Sjairo.balart@metempsy.com } else if (GICD_ICFGR.contains(addr)) { 75913531Sjairo.balart@metempsy.com // Interrupt Configuration Registers 76013756Sjairo.balart@metempsy.com // for x = 0 to 15: 76113756Sjairo.balart@metempsy.com // GICD_ICFGR[2x] = RES0 76213756Sjairo.balart@metempsy.com // GICD_ICFGR[2x + 1] = 76313756Sjairo.balart@metempsy.com // 0 level-sensitive 76413756Sjairo.balart@metempsy.com // 1 edge-triggered 76513531Sjairo.balart@metempsy.com int first_intid = (addr - GICD_ICFGR.start()) * 4; 76613531Sjairo.balart@metempsy.com 76713531Sjairo.balart@metempsy.com if (isNotSPI(first_intid)) { 76813531Sjairo.balart@metempsy.com return; 76913531Sjairo.balart@metempsy.com } 77013531Sjairo.balart@metempsy.com 77113531Sjairo.balart@metempsy.com for (int i = 0, int_id = first_intid; i < 8 * size && int_id < itLines; 77213756Sjairo.balart@metempsy.com i = i + 2, int_id++) { 77313531Sjairo.balart@metempsy.com irqConfig[int_id] = data & (0x2 << i) ? 77413531Sjairo.balart@metempsy.com Gicv3::INT_EDGE_TRIGGERED : 77513531Sjairo.balart@metempsy.com Gicv3::INT_LEVEL_SENSITIVE; 77613531Sjairo.balart@metempsy.com DPRINTF(GIC, "Gicv3Distributor::write(): int_id %d config %d\n", 77713531Sjairo.balart@metempsy.com int_id, irqConfig[int_id]); 77813531Sjairo.balart@metempsy.com } 77913531Sjairo.balart@metempsy.com 78013531Sjairo.balart@metempsy.com return; 78113531Sjairo.balart@metempsy.com } else if (GICD_IGRPMODR.contains(addr)) { 78213531Sjairo.balart@metempsy.com // Interrupt Group Modifier Registers 78313531Sjairo.balart@metempsy.com if (DS) { 78413531Sjairo.balart@metempsy.com return; 78513531Sjairo.balart@metempsy.com } else { 78613531Sjairo.balart@metempsy.com if (!is_secure_access) { 78713531Sjairo.balart@metempsy.com // RAZ/WI for non-secure accesses 78813531Sjairo.balart@metempsy.com return; 78913531Sjairo.balart@metempsy.com } else { 79013531Sjairo.balart@metempsy.com int first_intid = (addr - GICD_IGRPMODR.start()) * 8; 79113531Sjairo.balart@metempsy.com 79213531Sjairo.balart@metempsy.com if (isNotSPI(first_intid)) { 79313531Sjairo.balart@metempsy.com return; 79413531Sjairo.balart@metempsy.com } 79513531Sjairo.balart@metempsy.com 79613531Sjairo.balart@metempsy.com for (int i = 0, int_id = first_intid; 79713756Sjairo.balart@metempsy.com i < 8 * size && int_id < itLines; i++, int_id++) { 79814230Sgiacomo.travaglini@arm.com irqGrpmod[int_id] = bits(data, i); 79913531Sjairo.balart@metempsy.com } 80013531Sjairo.balart@metempsy.com 80113531Sjairo.balart@metempsy.com return ; 80213531Sjairo.balart@metempsy.com } 80313531Sjairo.balart@metempsy.com } 80413531Sjairo.balart@metempsy.com 80513756Sjairo.balart@metempsy.com } else if (GICD_NSACR.contains(addr)) { 80613531Sjairo.balart@metempsy.com // Non-secure Access Control Registers 80713531Sjairo.balart@metempsy.com // 2 bits per interrupt 80813531Sjairo.balart@metempsy.com int first_intid = (addr - GICD_NSACR.start()) * 4; 80913531Sjairo.balart@metempsy.com 81013531Sjairo.balart@metempsy.com if (isNotSPI(first_intid)) { 81113531Sjairo.balart@metempsy.com return; 81213531Sjairo.balart@metempsy.com } 81313531Sjairo.balart@metempsy.com 81413531Sjairo.balart@metempsy.com if (DS || (!DS && !is_secure_access)) { 81513531Sjairo.balart@metempsy.com return; 81613531Sjairo.balart@metempsy.com } 81713531Sjairo.balart@metempsy.com 81813531Sjairo.balart@metempsy.com for (int i = 0, int_id = first_intid; 81913756Sjairo.balart@metempsy.com i < 8 * size && int_id < itLines; i = i + 2, int_id++) { 82013531Sjairo.balart@metempsy.com irqNsacr[int_id] = (data >> (2 * int_id)) & 0x3; 82113531Sjairo.balart@metempsy.com } 82213531Sjairo.balart@metempsy.com 82313531Sjairo.balart@metempsy.com return; 82413531Sjairo.balart@metempsy.com } else if (GICD_IROUTER.contains(addr)) { // Interrupt Routing Registers 82513531Sjairo.balart@metempsy.com // 64 bit registers. 2 accesses. 82613531Sjairo.balart@metempsy.com int int_id = (addr - GICD_IROUTER.start()) / 8; 82713531Sjairo.balart@metempsy.com 82813531Sjairo.balart@metempsy.com if (isNotSPI(int_id)) { 82913531Sjairo.balart@metempsy.com return; 83013531Sjairo.balart@metempsy.com } 83113531Sjairo.balart@metempsy.com 83213531Sjairo.balart@metempsy.com if (nsAccessToSecInt(int_id, is_secure_access)) 83313531Sjairo.balart@metempsy.com { 83413531Sjairo.balart@metempsy.com if (irqNsacr[int_id] < 3) { 83513531Sjairo.balart@metempsy.com // Group 0 or Secure Group 1 interrupts are RAZ/WI 83613531Sjairo.balart@metempsy.com return; 83713531Sjairo.balart@metempsy.com } 83813531Sjairo.balart@metempsy.com } 83913531Sjairo.balart@metempsy.com 84013531Sjairo.balart@metempsy.com if (size == 4) { 84113531Sjairo.balart@metempsy.com if (addr & 7) { // high half of 64 bit register 84213531Sjairo.balart@metempsy.com irqAffinityRouting[int_id] = 84313531Sjairo.balart@metempsy.com (irqAffinityRouting[int_id] & 0xffffffff) | (data << 32); 84413531Sjairo.balart@metempsy.com } else { // low half of 64 bit register 84513531Sjairo.balart@metempsy.com irqAffinityRouting[int_id] = 84613531Sjairo.balart@metempsy.com (irqAffinityRouting[int_id] & 0xffffffff00000000) | 84713531Sjairo.balart@metempsy.com (data & 0xffffffff); 84813531Sjairo.balart@metempsy.com } 84913531Sjairo.balart@metempsy.com } else { 85013531Sjairo.balart@metempsy.com irqAffinityRouting[int_id] = data; 85113531Sjairo.balart@metempsy.com } 85213531Sjairo.balart@metempsy.com 85313531Sjairo.balart@metempsy.com DPRINTF(GIC, "Gicv3Distributor::write(): " 85413531Sjairo.balart@metempsy.com "int_id %d GICD_IROUTER %#llx\n", 85513531Sjairo.balart@metempsy.com int_id, irqAffinityRouting[int_id]); 85613531Sjairo.balart@metempsy.com return; 85713531Sjairo.balart@metempsy.com } 85813531Sjairo.balart@metempsy.com 85913531Sjairo.balart@metempsy.com switch (addr) { 86013531Sjairo.balart@metempsy.com case GICD_CTLR: // Control Register 86113531Sjairo.balart@metempsy.com if (DS) { 86213531Sjairo.balart@metempsy.com /* 86313531Sjairo.balart@metempsy.com * E1NWF [7] 86413531Sjairo.balart@metempsy.com * 1 of N wakeup functionality not supported, RAZ/WI 86513531Sjairo.balart@metempsy.com * DS [6] - RAO/WI 86613531Sjairo.balart@metempsy.com * ARE [4] 86713531Sjairo.balart@metempsy.com * affinity routing always on, no GICv2 legacy, RAO/WI 86813531Sjairo.balart@metempsy.com * EnableGrp1 [1] 86913531Sjairo.balart@metempsy.com * EnableGrp0 [0] 87013531Sjairo.balart@metempsy.com */ 87113531Sjairo.balart@metempsy.com if ((data & (1 << 4)) == 0) { 87213531Sjairo.balart@metempsy.com warn("Gicv3Distributor::write(): " 87313531Sjairo.balart@metempsy.com "setting ARE to 0 is not supported!\n"); 87413531Sjairo.balart@metempsy.com } 87513531Sjairo.balart@metempsy.com 87613531Sjairo.balart@metempsy.com EnableGrp1NS = data & GICD_CTLR_ENABLEGRP1NS; 87713531Sjairo.balart@metempsy.com EnableGrp0 = data & GICD_CTLR_ENABLEGRP0; 87813531Sjairo.balart@metempsy.com DPRINTF(GIC, "Gicv3Distributor::write(): (DS 1)" 87913531Sjairo.balart@metempsy.com "EnableGrp1NS %d EnableGrp0 %d\n", 88013531Sjairo.balart@metempsy.com EnableGrp1NS, EnableGrp0); 88113531Sjairo.balart@metempsy.com } else { 88213531Sjairo.balart@metempsy.com if (is_secure_access) { 88313531Sjairo.balart@metempsy.com /* 88413531Sjairo.balart@metempsy.com * E1NWF [7] 88513531Sjairo.balart@metempsy.com * 1 of N wakeup functionality not supported, RAZ/WI 88613531Sjairo.balart@metempsy.com * DS [6] 88713531Sjairo.balart@metempsy.com * ARE_NS [5] 88813531Sjairo.balart@metempsy.com * affinity routing always on, no GICv2 legacy, RAO/WI 88913531Sjairo.balart@metempsy.com * ARE_S [4] 89013531Sjairo.balart@metempsy.com * affinity routing always on, no GICv2 legacy, RAO/WI 89113531Sjairo.balart@metempsy.com * EnableGrp1S [2] 89213531Sjairo.balart@metempsy.com * EnableGrp1NS [1] 89313531Sjairo.balart@metempsy.com * EnableGrp0 [0] 89413531Sjairo.balart@metempsy.com */ 89513531Sjairo.balart@metempsy.com if ((data & (1 << 5)) == 0) { 89613531Sjairo.balart@metempsy.com warn("Gicv3Distributor::write(): " 89713531Sjairo.balart@metempsy.com "setting ARE_NS to 0 is not supported!\n"); 89813531Sjairo.balart@metempsy.com } 89913531Sjairo.balart@metempsy.com 90013531Sjairo.balart@metempsy.com if ((data & (1 << 4)) == 0) { 90113531Sjairo.balart@metempsy.com warn("Gicv3Distributor::write(): " 90213531Sjairo.balart@metempsy.com "setting ARE_S to 0 is not supported!\n"); 90313531Sjairo.balart@metempsy.com } 90413531Sjairo.balart@metempsy.com 90513531Sjairo.balart@metempsy.com DS = data & GICD_CTLR_DS; 90613531Sjairo.balart@metempsy.com EnableGrp1S = data & GICD_CTLR_ENABLEGRP1S; 90713531Sjairo.balart@metempsy.com EnableGrp1NS = data & GICD_CTLR_ENABLEGRP1NS; 90813531Sjairo.balart@metempsy.com EnableGrp0 = data & GICD_CTLR_ENABLEGRP0; 90913531Sjairo.balart@metempsy.com DPRINTF(GIC, "Gicv3Distributor::write(): (DS 0 secure)" 91013531Sjairo.balart@metempsy.com "DS %d " 91113531Sjairo.balart@metempsy.com "EnableGrp1S %d EnableGrp1NS %d EnableGrp0 %d\n", 91213531Sjairo.balart@metempsy.com DS, EnableGrp1S, EnableGrp1NS, EnableGrp0); 91313531Sjairo.balart@metempsy.com 91413531Sjairo.balart@metempsy.com if (data & GICD_CTLR_DS) { 91513531Sjairo.balart@metempsy.com EnableGrp1S = 0; 91613531Sjairo.balart@metempsy.com } 91713531Sjairo.balart@metempsy.com } else { 91813531Sjairo.balart@metempsy.com /* 91913531Sjairo.balart@metempsy.com * ARE_NS [4] RAO/WI; 92013531Sjairo.balart@metempsy.com * EnableGrp1A [1] is a read-write alias of the Secure 92113531Sjairo.balart@metempsy.com * GICD_CTLR.EnableGrp1NS 92213531Sjairo.balart@metempsy.com * EnableGrp1 [0] RES0 92313531Sjairo.balart@metempsy.com */ 92413531Sjairo.balart@metempsy.com if ((data & (1 << 4)) == 0) { 92513531Sjairo.balart@metempsy.com warn("Gicv3Distributor::write(): " 92613531Sjairo.balart@metempsy.com "setting ARE_NS to 0 is not supported!\n"); 92713531Sjairo.balart@metempsy.com } 92813531Sjairo.balart@metempsy.com 92913531Sjairo.balart@metempsy.com EnableGrp1NS = data & GICD_CTLR_ENABLEGRP1A; 93013531Sjairo.balart@metempsy.com DPRINTF(GIC, "Gicv3Distributor::write(): (DS 0 non-secure)" 93113531Sjairo.balart@metempsy.com "EnableGrp1NS %d\n", EnableGrp1NS); 93213531Sjairo.balart@metempsy.com } 93313531Sjairo.balart@metempsy.com } 93413531Sjairo.balart@metempsy.com 93514232Sgiacomo.travaglini@arm.com update(); 93614232Sgiacomo.travaglini@arm.com 93713531Sjairo.balart@metempsy.com break; 93813531Sjairo.balart@metempsy.com 93914251Sgiacomo.travaglini@arm.com case GICD_SGIR: // Error Reporting Status Register 94014251Sgiacomo.travaglini@arm.com // Only if affinity routing is disabled, RES0 94114251Sgiacomo.travaglini@arm.com break; 94214251Sgiacomo.travaglini@arm.com 94313531Sjairo.balart@metempsy.com default: 94413531Sjairo.balart@metempsy.com panic("Gicv3Distributor::write(): invalid offset %#x\n", addr); 94513531Sjairo.balart@metempsy.com break; 94613531Sjairo.balart@metempsy.com } 94713531Sjairo.balart@metempsy.com} 94813531Sjairo.balart@metempsy.com 94913531Sjairo.balart@metempsy.comvoid 95013531Sjairo.balart@metempsy.comGicv3Distributor::sendInt(uint32_t int_id) 95113531Sjairo.balart@metempsy.com{ 95213531Sjairo.balart@metempsy.com panic_if(int_id < Gicv3::SGI_MAX + Gicv3::PPI_MAX, "Invalid SPI!"); 95313531Sjairo.balart@metempsy.com panic_if(int_id > itLines, "Invalid SPI!"); 95413531Sjairo.balart@metempsy.com irqPending[int_id] = true; 95513531Sjairo.balart@metempsy.com DPRINTF(GIC, "Gicv3Distributor::sendInt(): " 95613531Sjairo.balart@metempsy.com "int_id %d (SPI) pending bit set\n", int_id); 95714231Sgiacomo.travaglini@arm.com update(); 95813531Sjairo.balart@metempsy.com} 95913531Sjairo.balart@metempsy.com 96013531Sjairo.balart@metempsy.comvoid 96113756Sjairo.balart@metempsy.comGicv3Distributor::deassertSPI(uint32_t int_id) 96213531Sjairo.balart@metempsy.com{ 96313531Sjairo.balart@metempsy.com panic_if(int_id < Gicv3::SGI_MAX + Gicv3::PPI_MAX, "Invalid SPI!"); 96413531Sjairo.balart@metempsy.com panic_if(int_id > itLines, "Invalid SPI!"); 96513531Sjairo.balart@metempsy.com irqPending[int_id] = false; 96614231Sgiacomo.travaglini@arm.com clearIrqCpuInterface(int_id); 96714231Sgiacomo.travaglini@arm.com 96814231Sgiacomo.travaglini@arm.com update(); 96913531Sjairo.balart@metempsy.com} 97013531Sjairo.balart@metempsy.com 97114231Sgiacomo.travaglini@arm.comGicv3CPUInterface* 97214231Sgiacomo.travaglini@arm.comGicv3Distributor::route(uint32_t int_id) 97313531Sjairo.balart@metempsy.com{ 97414231Sgiacomo.travaglini@arm.com IROUTER affinity_routing = irqAffinityRouting[int_id]; 97514231Sgiacomo.travaglini@arm.com Gicv3Redistributor * target_redistributor = nullptr; 97613531Sjairo.balart@metempsy.com 97714231Sgiacomo.travaglini@arm.com const Gicv3::GroupId int_group = getIntGroup(int_id); 97814231Sgiacomo.travaglini@arm.com 97914231Sgiacomo.travaglini@arm.com if (affinity_routing.IRM) { 98014231Sgiacomo.travaglini@arm.com // Interrupts routed to any PE defined as a participating node 98114231Sgiacomo.travaglini@arm.com for (int i = 0; i < gic->getSystem()->numContexts(); i++) { 98214231Sgiacomo.travaglini@arm.com Gicv3Redistributor * redistributor_i = 98314231Sgiacomo.travaglini@arm.com gic->getRedistributor(i); 98414231Sgiacomo.travaglini@arm.com 98514231Sgiacomo.travaglini@arm.com if (redistributor_i-> 98614231Sgiacomo.travaglini@arm.com canBeSelectedFor1toNInterrupt(int_group)) { 98714231Sgiacomo.travaglini@arm.com target_redistributor = redistributor_i; 98814231Sgiacomo.travaglini@arm.com break; 98914231Sgiacomo.travaglini@arm.com } 99014231Sgiacomo.travaglini@arm.com } 99114231Sgiacomo.travaglini@arm.com } else { 99214231Sgiacomo.travaglini@arm.com uint32_t affinity = (affinity_routing.Aff3 << 24) | 99314231Sgiacomo.travaglini@arm.com (affinity_routing.Aff2 << 16) | 99414231Sgiacomo.travaglini@arm.com (affinity_routing.Aff1 << 8) | 99514231Sgiacomo.travaglini@arm.com (affinity_routing.Aff0 << 0); 99614231Sgiacomo.travaglini@arm.com target_redistributor = 99714231Sgiacomo.travaglini@arm.com gic->getRedistributorByAffinity(affinity); 99814231Sgiacomo.travaglini@arm.com } 99914231Sgiacomo.travaglini@arm.com 100014231Sgiacomo.travaglini@arm.com if (!target_redistributor) { 100114231Sgiacomo.travaglini@arm.com // Interrrupts targeting not present cpus must remain pending 100214231Sgiacomo.travaglini@arm.com return nullptr; 100314231Sgiacomo.travaglini@arm.com } else { 100414231Sgiacomo.travaglini@arm.com return target_redistributor->getCPUInterface(); 100513531Sjairo.balart@metempsy.com } 100613531Sjairo.balart@metempsy.com} 100713531Sjairo.balart@metempsy.com 100813531Sjairo.balart@metempsy.comvoid 100914231Sgiacomo.travaglini@arm.comGicv3Distributor::clearIrqCpuInterface(uint32_t int_id) 101013531Sjairo.balart@metempsy.com{ 101114231Sgiacomo.travaglini@arm.com auto cpu_interface = route(int_id); 101214231Sgiacomo.travaglini@arm.com if (cpu_interface) 101314231Sgiacomo.travaglini@arm.com cpu_interface->hppi.prio = 0xff; 101413531Sjairo.balart@metempsy.com} 101513531Sjairo.balart@metempsy.com 101613531Sjairo.balart@metempsy.comvoid 101713531Sjairo.balart@metempsy.comGicv3Distributor::update() 101813531Sjairo.balart@metempsy.com{ 101913531Sjairo.balart@metempsy.com // Find the highest priority pending SPI 102013531Sjairo.balart@metempsy.com for (int int_id = Gicv3::SGI_MAX + Gicv3::PPI_MAX; int_id < itLines; 102113756Sjairo.balart@metempsy.com int_id++) { 102213531Sjairo.balart@metempsy.com Gicv3::GroupId int_group = getIntGroup(int_id); 102313531Sjairo.balart@metempsy.com bool group_enabled = groupEnabled(int_group); 102413531Sjairo.balart@metempsy.com 102513531Sjairo.balart@metempsy.com if (irqPending[int_id] && irqEnabled[int_id] && 102613756Sjairo.balart@metempsy.com !irqActive[int_id] && group_enabled) { 102713531Sjairo.balart@metempsy.com 102814231Sgiacomo.travaglini@arm.com // Find the cpu interface where to route the interrupt 102914231Sgiacomo.travaglini@arm.com Gicv3CPUInterface *target_cpu_interface = route(int_id); 103013531Sjairo.balart@metempsy.com 103114231Sgiacomo.travaglini@arm.com // Invalid routing 103214231Sgiacomo.travaglini@arm.com if (!target_cpu_interface) continue; 103313531Sjairo.balart@metempsy.com 103413531Sjairo.balart@metempsy.com if ((irqPriority[int_id] < target_cpu_interface->hppi.prio) || 103513756Sjairo.balart@metempsy.com (irqPriority[int_id] == target_cpu_interface->hppi.prio && 103613756Sjairo.balart@metempsy.com int_id < target_cpu_interface->hppi.intid)) { 103714231Sgiacomo.travaglini@arm.com 103813531Sjairo.balart@metempsy.com target_cpu_interface->hppi.intid = int_id; 103913531Sjairo.balart@metempsy.com target_cpu_interface->hppi.prio = irqPriority[int_id]; 104013531Sjairo.balart@metempsy.com target_cpu_interface->hppi.group = int_group; 104113531Sjairo.balart@metempsy.com } 104213531Sjairo.balart@metempsy.com } 104313531Sjairo.balart@metempsy.com } 104413531Sjairo.balart@metempsy.com 104514231Sgiacomo.travaglini@arm.com // Update all redistributors 104613531Sjairo.balart@metempsy.com for (int i = 0; i < gic->getSystem()->numContexts(); i++) { 104714231Sgiacomo.travaglini@arm.com gic->getRedistributor(i)->update(); 104813531Sjairo.balart@metempsy.com } 104913531Sjairo.balart@metempsy.com} 105013531Sjairo.balart@metempsy.com 105113531Sjairo.balart@metempsy.comGicv3::IntStatus 105213756Sjairo.balart@metempsy.comGicv3Distributor::intStatus(uint32_t int_id) const 105313531Sjairo.balart@metempsy.com{ 105413531Sjairo.balart@metempsy.com panic_if(int_id < Gicv3::SGI_MAX + Gicv3::PPI_MAX, "Invalid SPI!"); 105513531Sjairo.balart@metempsy.com panic_if(int_id > itLines, "Invalid SPI!"); 105613531Sjairo.balart@metempsy.com 105713531Sjairo.balart@metempsy.com if (irqPending[int_id]) { 105813531Sjairo.balart@metempsy.com if (irqActive[int_id]) { 105913531Sjairo.balart@metempsy.com return Gicv3::INT_ACTIVE_PENDING; 106013531Sjairo.balart@metempsy.com } 106113531Sjairo.balart@metempsy.com 106213531Sjairo.balart@metempsy.com return Gicv3::INT_PENDING; 106313531Sjairo.balart@metempsy.com } else if (irqActive[int_id]) { 106413531Sjairo.balart@metempsy.com return Gicv3::INT_ACTIVE; 106513531Sjairo.balart@metempsy.com } else { 106613531Sjairo.balart@metempsy.com return Gicv3::INT_INACTIVE; 106713531Sjairo.balart@metempsy.com } 106813531Sjairo.balart@metempsy.com} 106913531Sjairo.balart@metempsy.com 107013531Sjairo.balart@metempsy.comGicv3::GroupId 107113756Sjairo.balart@metempsy.comGicv3Distributor::getIntGroup(int int_id) const 107213531Sjairo.balart@metempsy.com{ 107313531Sjairo.balart@metempsy.com panic_if(int_id < Gicv3::SGI_MAX + Gicv3::PPI_MAX, "Invalid SPI!"); 107413531Sjairo.balart@metempsy.com panic_if(int_id > itLines, "Invalid SPI!"); 107513531Sjairo.balart@metempsy.com 107613531Sjairo.balart@metempsy.com if (DS) { 107713531Sjairo.balart@metempsy.com if (irqGroup[int_id] == 1) { 107813531Sjairo.balart@metempsy.com return Gicv3::G1NS; 107913531Sjairo.balart@metempsy.com } else { 108013531Sjairo.balart@metempsy.com return Gicv3::G0S; 108113531Sjairo.balart@metempsy.com } 108213531Sjairo.balart@metempsy.com } else { 108313531Sjairo.balart@metempsy.com if (irqGrpmod[int_id] == 0 && irqGroup[int_id] == 0) { 108413531Sjairo.balart@metempsy.com return Gicv3::G0S; 108513531Sjairo.balart@metempsy.com } else if (irqGrpmod[int_id] == 0 && irqGroup[int_id] == 1) { 108613531Sjairo.balart@metempsy.com return Gicv3::G1NS; 108713531Sjairo.balart@metempsy.com } else if (irqGrpmod[int_id] == 1 && irqGroup[int_id] == 0) { 108813531Sjairo.balart@metempsy.com return Gicv3::G1S; 108913531Sjairo.balart@metempsy.com } else if (irqGrpmod[int_id] == 1 && irqGroup[int_id] == 1) { 109013531Sjairo.balart@metempsy.com return Gicv3::G1NS; 109113531Sjairo.balart@metempsy.com } 109213531Sjairo.balart@metempsy.com } 109313531Sjairo.balart@metempsy.com 109413531Sjairo.balart@metempsy.com M5_UNREACHABLE; 109513531Sjairo.balart@metempsy.com} 109613531Sjairo.balart@metempsy.com 109713531Sjairo.balart@metempsy.comvoid 109813531Sjairo.balart@metempsy.comGicv3Distributor::activateIRQ(uint32_t int_id) 109913531Sjairo.balart@metempsy.com{ 110013531Sjairo.balart@metempsy.com irqPending[int_id] = false; 110113531Sjairo.balart@metempsy.com irqActive[int_id] = true; 110213531Sjairo.balart@metempsy.com} 110313531Sjairo.balart@metempsy.com 110413531Sjairo.balart@metempsy.comvoid 110513531Sjairo.balart@metempsy.comGicv3Distributor::deactivateIRQ(uint32_t int_id) 110613531Sjairo.balart@metempsy.com{ 110713531Sjairo.balart@metempsy.com irqActive[int_id] = false; 110813531Sjairo.balart@metempsy.com} 110913531Sjairo.balart@metempsy.com 111013531Sjairo.balart@metempsy.comvoid 111113531Sjairo.balart@metempsy.comGicv3Distributor::serialize(CheckpointOut & cp) const 111213531Sjairo.balart@metempsy.com{ 111313531Sjairo.balart@metempsy.com SERIALIZE_SCALAR(ARE); 111413531Sjairo.balart@metempsy.com SERIALIZE_SCALAR(DS); 111513531Sjairo.balart@metempsy.com SERIALIZE_SCALAR(EnableGrp1S); 111613531Sjairo.balart@metempsy.com SERIALIZE_SCALAR(EnableGrp1NS); 111713531Sjairo.balart@metempsy.com SERIALIZE_SCALAR(EnableGrp0); 111813531Sjairo.balart@metempsy.com SERIALIZE_CONTAINER(irqGroup); 111913531Sjairo.balart@metempsy.com SERIALIZE_CONTAINER(irqEnabled); 112013531Sjairo.balart@metempsy.com SERIALIZE_CONTAINER(irqPending); 112113531Sjairo.balart@metempsy.com SERIALIZE_CONTAINER(irqActive); 112213531Sjairo.balart@metempsy.com SERIALIZE_CONTAINER(irqPriority); 112313531Sjairo.balart@metempsy.com SERIALIZE_CONTAINER(irqConfig); 112413531Sjairo.balart@metempsy.com SERIALIZE_CONTAINER(irqGrpmod); 112513531Sjairo.balart@metempsy.com SERIALIZE_CONTAINER(irqNsacr); 112613531Sjairo.balart@metempsy.com SERIALIZE_CONTAINER(irqAffinityRouting); 112713531Sjairo.balart@metempsy.com} 112813531Sjairo.balart@metempsy.com 112913531Sjairo.balart@metempsy.comvoid 113013531Sjairo.balart@metempsy.comGicv3Distributor::unserialize(CheckpointIn & cp) 113113531Sjairo.balart@metempsy.com{ 113213531Sjairo.balart@metempsy.com UNSERIALIZE_SCALAR(ARE); 113313531Sjairo.balart@metempsy.com UNSERIALIZE_SCALAR(DS); 113413531Sjairo.balart@metempsy.com UNSERIALIZE_SCALAR(EnableGrp1S); 113513531Sjairo.balart@metempsy.com UNSERIALIZE_SCALAR(EnableGrp1NS); 113613531Sjairo.balart@metempsy.com UNSERIALIZE_SCALAR(EnableGrp0); 113713531Sjairo.balart@metempsy.com UNSERIALIZE_CONTAINER(irqGroup); 113813531Sjairo.balart@metempsy.com UNSERIALIZE_CONTAINER(irqEnabled); 113913531Sjairo.balart@metempsy.com UNSERIALIZE_CONTAINER(irqPending); 114013531Sjairo.balart@metempsy.com UNSERIALIZE_CONTAINER(irqActive); 114113531Sjairo.balart@metempsy.com UNSERIALIZE_CONTAINER(irqPriority); 114213531Sjairo.balart@metempsy.com UNSERIALIZE_CONTAINER(irqConfig); 114313531Sjairo.balart@metempsy.com UNSERIALIZE_CONTAINER(irqGrpmod); 114413531Sjairo.balart@metempsy.com UNSERIALIZE_CONTAINER(irqNsacr); 114513531Sjairo.balart@metempsy.com UNSERIALIZE_CONTAINER(irqAffinityRouting); 114613531Sjairo.balart@metempsy.com} 1147