gic_v3_cpu_interface.hh revision 13826:34a9929c35eb
18706Sandreas.hansson@arm.com/* 212522Sandreas.sandberg@arm.com * Copyright (c) 2018 Metempsy Technology Consulting 38706Sandreas.hansson@arm.com * All rights reserved. 48706Sandreas.hansson@arm.com * 58706Sandreas.hansson@arm.com * Redistribution and use in source and binary forms, with or without 68706Sandreas.hansson@arm.com * modification, are permitted provided that the following conditions are 78706Sandreas.hansson@arm.com * met: redistributions of source code must retain the above copyright 88706Sandreas.hansson@arm.com * notice, this list of conditions and the following disclaimer; 98706Sandreas.hansson@arm.com * redistributions in binary form must reproduce the above copyright 108706Sandreas.hansson@arm.com * notice, this list of conditions and the following disclaimer in the 118706Sandreas.hansson@arm.com * documentation and/or other materials provided with the distribution; 128706Sandreas.hansson@arm.com * neither the name of the copyright holders nor the names of its 138706Sandreas.hansson@arm.com * contributors may be used to endorse or promote products derived from 148706Sandreas.hansson@arm.com * this software without specific prior written permission. 158706Sandreas.hansson@arm.com * 168706Sandreas.hansson@arm.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 178706Sandreas.hansson@arm.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 188706Sandreas.hansson@arm.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 198706Sandreas.hansson@arm.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 208706Sandreas.hansson@arm.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 218706Sandreas.hansson@arm.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 228706Sandreas.hansson@arm.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 238706Sandreas.hansson@arm.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 248706Sandreas.hansson@arm.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 258706Sandreas.hansson@arm.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 268706Sandreas.hansson@arm.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 278706Sandreas.hansson@arm.com * 288706Sandreas.hansson@arm.com * Authors: Jairo Balart 298706Sandreas.hansson@arm.com */ 308706Sandreas.hansson@arm.com 318706Sandreas.hansson@arm.com#ifndef __DEV_ARM_GICV3_CPU_INTERFACE_H__ 328706Sandreas.hansson@arm.com#define __DEV_ARM_GICV3_CPU_INTERFACE_H__ 338706Sandreas.hansson@arm.com 348706Sandreas.hansson@arm.com#include "arch/arm/isa_device.hh" 358706Sandreas.hansson@arm.com#include "dev/arm/gic_v3.hh" 368706Sandreas.hansson@arm.com 378706Sandreas.hansson@arm.comclass Gicv3Distributor; 388706Sandreas.hansson@arm.comclass Gicv3Redistributor; 398706Sandreas.hansson@arm.com 408706Sandreas.hansson@arm.comclass Gicv3CPUInterface : public ArmISA::BaseISADevice, public Serializable 418706Sandreas.hansson@arm.com{ 428706Sandreas.hansson@arm.com private: 438706Sandreas.hansson@arm.com 448853Sandreas.hansson@arm.com friend class Gicv3Distributor; 458853Sandreas.hansson@arm.com friend class Gicv3Redistributor; 468853Sandreas.hansson@arm.com 478853Sandreas.hansson@arm.com protected: 488853Sandreas.hansson@arm.com 498853Sandreas.hansson@arm.com Gicv3 * gic; 508853Sandreas.hansson@arm.com Gicv3Redistributor * redistributor; 518853Sandreas.hansson@arm.com Gicv3Distributor * distributor; 528853Sandreas.hansson@arm.com uint32_t cpuId; 538853Sandreas.hansson@arm.com 548853Sandreas.hansson@arm.com ArmInterruptPin *maintenanceInterrupt; 558706Sandreas.hansson@arm.com 568706Sandreas.hansson@arm.com BitUnion64(ICC_CTLR_EL1) 578706Sandreas.hansson@arm.com Bitfield<63, 20> res0_3; 588706Sandreas.hansson@arm.com Bitfield<19> ExtRange; 598706Sandreas.hansson@arm.com Bitfield<18> RSS; 608706Sandreas.hansson@arm.com Bitfield<17, 16> res0_2; 618706Sandreas.hansson@arm.com Bitfield<15> A3V; 6214012Sgabeblack@google.com Bitfield<14> SEIS; 6314012Sgabeblack@google.com Bitfield<13, 11> IDbits; 648706Sandreas.hansson@arm.com Bitfield<10, 8> PRIbits; 658706Sandreas.hansson@arm.com Bitfield<7> res0_1; 668706Sandreas.hansson@arm.com Bitfield<6> PMHE; 678706Sandreas.hansson@arm.com Bitfield<5, 2> res0_0; 688853Sandreas.hansson@arm.com Bitfield<1> EOImode; 698853Sandreas.hansson@arm.com Bitfield<0> CBPR; 708706Sandreas.hansson@arm.com EndBitUnion(ICC_CTLR_EL1) 718706Sandreas.hansson@arm.com 728706Sandreas.hansson@arm.com BitUnion64(ICC_CTLR_EL3) 738706Sandreas.hansson@arm.com Bitfield<63, 20> res0_2; 748706Sandreas.hansson@arm.com Bitfield<19> ExtRange; 758706Sandreas.hansson@arm.com Bitfield<18> RSS; 768706Sandreas.hansson@arm.com Bitfield<17> nDS; 778706Sandreas.hansson@arm.com Bitfield<16> res0_1; 788706Sandreas.hansson@arm.com Bitfield<15> A3V; 798706Sandreas.hansson@arm.com Bitfield<14> SEIS; 808706Sandreas.hansson@arm.com Bitfield<13, 11> IDbits; 818706Sandreas.hansson@arm.com Bitfield<10, 8> PRIbits; 828706Sandreas.hansson@arm.com Bitfield<7> res0_0; 838853Sandreas.hansson@arm.com Bitfield<6> PMHE; 848853Sandreas.hansson@arm.com Bitfield<5> RM; 858853Sandreas.hansson@arm.com Bitfield<4> EOImode_EL1NS; 868922Swilliam.wang@arm.com Bitfield<3> EOImode_EL1S; 878706Sandreas.hansson@arm.com Bitfield<2> EOImode_EL3; 889814Sandreas.hansson@arm.com Bitfield<1> CBPR_EL1NS; 899814Sandreas.hansson@arm.com Bitfield<0> CBPR_EL1S; 909814Sandreas.hansson@arm.com EndBitUnion(ICC_CTLR_EL3) 918706Sandreas.hansson@arm.com 929814Sandreas.hansson@arm.com BitUnion64(ICC_IGRPEN0_EL1) 9313893Sgabeblack@google.com Bitfield<63, 1> res0; 9413893Sgabeblack@google.com Bitfield<0> Enable; 958706Sandreas.hansson@arm.com EndBitUnion(ICC_IGRPEN0_EL1) 968706Sandreas.hansson@arm.com 978706Sandreas.hansson@arm.com BitUnion64(ICC_IGRPEN1_EL1) 988706Sandreas.hansson@arm.com Bitfield<63, 1> res0; 9914008Sgabeblack@google.com Bitfield<0> Enable; 10012532Sandreas.sandberg@arm.com EndBitUnion(ICC_IGRPEN1_EL1) 10112532Sandreas.sandberg@arm.com 10212532Sandreas.sandberg@arm.com BitUnion64(ICC_IGRPEN1_EL3) 10312532Sandreas.sandberg@arm.com Bitfield<63, 2> res0; 10412532Sandreas.sandberg@arm.com Bitfield<1> EnableGrp1S; 10514009Sgabeblack@google.com Bitfield<0> EnableGrp1NS; 10612532Sandreas.sandberg@arm.com EndBitUnion(ICC_IGRPEN1_EL3) 10712532Sandreas.sandberg@arm.com 10812532Sandreas.sandberg@arm.com BitUnion64(ICC_SRE_EL1) 10912532Sandreas.sandberg@arm.com Bitfield<63, 3> res0; 11012532Sandreas.sandberg@arm.com Bitfield<2> DIB; 11114009Sgabeblack@google.com Bitfield<1> DFB; 11212532Sandreas.sandberg@arm.com Bitfield<0> SRE; 11312532Sandreas.sandberg@arm.com EndBitUnion(ICC_SRE_EL1) 11412532Sandreas.sandberg@arm.com 11512532Sandreas.sandberg@arm.com BitUnion64(ICC_SRE_EL2) 11612532Sandreas.sandberg@arm.com Bitfield<63, 4> res0; 11712532Sandreas.sandberg@arm.com Bitfield<3> Enable; 1188706Sandreas.hansson@arm.com Bitfield<2> DIB; 11914008Sgabeblack@google.com Bitfield<1> DFB; 12014008Sgabeblack@google.com Bitfield<0> SRE; 12114008Sgabeblack@google.com EndBitUnion(ICC_SRE_EL2) 12214008Sgabeblack@google.com 12314008Sgabeblack@google.com BitUnion64(ICC_SRE_EL3) 12414008Sgabeblack@google.com Bitfield<63, 4> res0; 12514008Sgabeblack@google.com Bitfield<3> Enable; 12614008Sgabeblack@google.com Bitfield<2> DIB; 12714008Sgabeblack@google.com Bitfield<1> DFB; 12814009Sgabeblack@google.com Bitfield<0> SRE; 12914008Sgabeblack@google.com EndBitUnion(ICC_SRE_EL3) 13014008Sgabeblack@google.com 13114008Sgabeblack@google.com static const uint8_t PRIORITY_BITS = 5; 13214008Sgabeblack@google.com 13314008Sgabeblack@google.com // Minimum BPR for Secure, or when security not enabled 13414008Sgabeblack@google.com static const uint8_t GIC_MIN_BPR = 2; 13514008Sgabeblack@google.com // Minimum BPR for Nonsecure when security is enabled 13614008Sgabeblack@google.com static const uint8_t GIC_MIN_BPR_NS = GIC_MIN_BPR + 1; 13714008Sgabeblack@google.com 13814008Sgabeblack@google.com static const uint8_t VIRTUAL_PRIORITY_BITS = 5; 13914009Sgabeblack@google.com static const uint8_t VIRTUAL_PREEMPTION_BITS = 5; 14014008Sgabeblack@google.com static const uint8_t VIRTUAL_NUM_LIST_REGS = 16; 14114008Sgabeblack@google.com 14214008Sgabeblack@google.com static const uint8_t GIC_MIN_VBPR = 7 - VIRTUAL_PREEMPTION_BITS; 14314008Sgabeblack@google.com 14414008Sgabeblack@google.com typedef struct { 14514008Sgabeblack@google.com uint32_t intid; 14614008Sgabeblack@google.com uint8_t prio; 14714008Sgabeblack@google.com Gicv3::GroupId group; 14814008Sgabeblack@google.com } hppi_t; 14914008Sgabeblack@google.com 15014008Sgabeblack@google.com hppi_t hppi; 15114008Sgabeblack@google.com 15214008Sgabeblack@google.com // GIC CPU interface memory mapped control registers (legacy) 15314008Sgabeblack@google.com enum { 15414008Sgabeblack@google.com GICC_CTLR = 0x0000, 15514008Sgabeblack@google.com GICC_PMR = 0x0004, 15614008Sgabeblack@google.com GICC_BPR = 0x0008, 15714008Sgabeblack@google.com GICC_IAR = 0x000C, 15814008Sgabeblack@google.com GICC_EOIR = 0x0010, 15914008Sgabeblack@google.com GICC_RPR = 0x0014, 16014008Sgabeblack@google.com GICC_HPPI = 0x0018, 16114008Sgabeblack@google.com GICC_ABPR = 0x001C, 16214008Sgabeblack@google.com GICC_AIAR = 0x0020, 16314008Sgabeblack@google.com GICC_AEOIR = 0x0024, 16414009Sgabeblack@google.com GICC_AHPPIR = 0x0028, 16514008Sgabeblack@google.com GICC_STATUSR = 0x002C, 16614008Sgabeblack@google.com GICC_IIDR = 0x00FC, 16714008Sgabeblack@google.com }; 16814008Sgabeblack@google.com 16914008Sgabeblack@google.com static const AddrRange GICC_APR; 17014008Sgabeblack@google.com static const AddrRange GICC_NSAPR; 17114008Sgabeblack@google.com 17214008Sgabeblack@google.com // GIC CPU virtual interface memory mapped control registers (legacy) 17314008Sgabeblack@google.com enum { 17414009Sgabeblack@google.com GICH_HCR = 0x0000, 17514008Sgabeblack@google.com GICH_VTR = 0x0004, 17614008Sgabeblack@google.com GICH_VMCR = 0x0008, 17714008Sgabeblack@google.com GICH_MISR = 0x0010, 17814008Sgabeblack@google.com GICH_EISR = 0x0020, 17914008Sgabeblack@google.com GICH_ELRSR = 0x0030, 18014008Sgabeblack@google.com }; 18114008Sgabeblack@google.com 18214008Sgabeblack@google.com static const AddrRange GICH_APR; 18314008Sgabeblack@google.com static const AddrRange GICH_LR; 18414008Sgabeblack@google.com 18514008Sgabeblack@google.com BitUnion64(ICH_HCR_EL2) 18614008Sgabeblack@google.com Bitfield<63, 32> res0_2; 18714008Sgabeblack@google.com Bitfield<31, 27> EOIcount; 18814008Sgabeblack@google.com Bitfield<26, 15> res0_1; 18914008Sgabeblack@google.com Bitfield<14> TDIR; 1908706Sandreas.hansson@arm.com Bitfield<13> TSEI; 1918706Sandreas.hansson@arm.com Bitfield<12> TALL1; 1928706Sandreas.hansson@arm.com Bitfield<11> TALL0; 1938706Sandreas.hansson@arm.com Bitfield<10> TC; 1948861Sandreas.hansson@arm.com Bitfield<9, 8> res0_0; 1958706Sandreas.hansson@arm.com Bitfield<7> VGrp1DIE; 1968706Sandreas.hansson@arm.com Bitfield<6> VGrp1EIE; 1978706Sandreas.hansson@arm.com Bitfield<5> VGrp0DIE; 1988706Sandreas.hansson@arm.com Bitfield<4> VGrp0EIE; 1998706Sandreas.hansson@arm.com Bitfield<3> NPIE; 20014011Sgabeblack@google.com Bitfield<2> LRENPIE; 2018706Sandreas.hansson@arm.com Bitfield<1> UIE; 20212522Sandreas.sandberg@arm.com Bitfield<0> En; 20312522Sandreas.sandberg@arm.com EndBitUnion(ICH_HCR_EL2) 20413893Sgabeblack@google.com 20512522Sandreas.sandberg@arm.com BitUnion64(ICH_LR_EL2) 20612522Sandreas.sandberg@arm.com Bitfield<63, 62> State; 20713893Sgabeblack@google.com Bitfield<61> HW; 20812522Sandreas.sandberg@arm.com Bitfield<60> Group; 20912522Sandreas.sandberg@arm.com Bitfield<59, 56> res0_1; 21012522Sandreas.sandberg@arm.com Bitfield<55, 48> Priority; 21113893Sgabeblack@google.com Bitfield<47, 45> res0_0; 21212522Sandreas.sandberg@arm.com Bitfield<44, 32> pINTID; 21312522Sandreas.sandberg@arm.com Bitfield<41> EOI; 21413893Sgabeblack@google.com Bitfield<31, 0> vINTID; 21514008Sgabeblack@google.com EndBitUnion(ICH_LR_EL2) 21614008Sgabeblack@google.com 21714008Sgabeblack@google.com static const uint64_t ICH_LR_EL2_STATE_INVALID = 0; 21814008Sgabeblack@google.com static const uint64_t ICH_LR_EL2_STATE_PENDING = 1; 21914008Sgabeblack@google.com static const uint64_t ICH_LR_EL2_STATE_ACTIVE = 2; 22014008Sgabeblack@google.com static const uint64_t ICH_LR_EL2_STATE_ACTIVE_PENDING = 3; 22114008Sgabeblack@google.com 22214008Sgabeblack@google.com BitUnion32(ICH_LRC) 22314008Sgabeblack@google.com Bitfield<31, 30> State; 22414008Sgabeblack@google.com Bitfield<29> HW; 22514008Sgabeblack@google.com Bitfield<28> Group; 22614008Sgabeblack@google.com Bitfield<27, 24> res0_1; 22714008Sgabeblack@google.com Bitfield<23, 16> Priority; 22814008Sgabeblack@google.com Bitfield<15, 13> res0_0; 22914008Sgabeblack@google.com Bitfield<12, 0> pINTID; 23014008Sgabeblack@google.com Bitfield<9> EOI; 23114008Sgabeblack@google.com EndBitUnion(ICH_LRC) 23214008Sgabeblack@google.com 23314008Sgabeblack@google.com BitUnion64(ICH_MISR_EL2) 23414008Sgabeblack@google.com Bitfield<63, 8> res0; 23514008Sgabeblack@google.com Bitfield<7> VGrp1D; 23614008Sgabeblack@google.com Bitfield<6> VGrp1E; 23714008Sgabeblack@google.com Bitfield<5> VGrp0D; 23814008Sgabeblack@google.com Bitfield<4> VGrp0E; 23914008Sgabeblack@google.com Bitfield<3> NP; 24014008Sgabeblack@google.com Bitfield<2> LRENP; 24114008Sgabeblack@google.com Bitfield<1> U; 24214008Sgabeblack@google.com Bitfield<0> EOI; 24314008Sgabeblack@google.com EndBitUnion(ICH_MISR_EL2) 24414008Sgabeblack@google.com 24514008Sgabeblack@google.com BitUnion64(ICH_VMCR_EL2) 24614008Sgabeblack@google.com Bitfield<63, 32> res0_2; 24714012Sgabeblack@google.com Bitfield<31, 24> VPMR; 24814012Sgabeblack@google.com Bitfield<23, 21> VBPR0; 24914012Sgabeblack@google.com Bitfield<20, 18> VBPR1; 25014012Sgabeblack@google.com Bitfield<17, 10> res0_1; 25114012Sgabeblack@google.com Bitfield<9> VEOIM; 25214012Sgabeblack@google.com Bitfield<8, 5> res0_0; 25314012Sgabeblack@google.com Bitfield<4> VCBPR; 25414012Sgabeblack@google.com Bitfield<3> VFIQEn; 25514012Sgabeblack@google.com Bitfield<2> VAckCtl; 25614012Sgabeblack@google.com Bitfield<1> VENG1; 25714012Sgabeblack@google.com Bitfield<0> VENG0; 25814012Sgabeblack@google.com EndBitUnion(ICH_VMCR_EL2) 25914012Sgabeblack@google.com 26014012Sgabeblack@google.com BitUnion64(ICH_VTR_EL2) 26114012Sgabeblack@google.com Bitfield<63, 32> res0_1; 26214012Sgabeblack@google.com Bitfield<31, 29> PRIbits; 26314012Sgabeblack@google.com Bitfield<28, 26> PREbits; 2648706Sandreas.hansson@arm.com Bitfield<25, 23> IDbits; 2658706Sandreas.hansson@arm.com Bitfield<22> SEIS; 2668706Sandreas.hansson@arm.com Bitfield<21> A3V; 2678706Sandreas.hansson@arm.com Bitfield<20> res1; 2688706Sandreas.hansson@arm.com Bitfield<19> TDS; 2698861Sandreas.hansson@arm.com Bitfield<18, 5> res0_0; 2708706Sandreas.hansson@arm.com Bitfield<4, 0> ListRegs; 2718706Sandreas.hansson@arm.com EndBitUnion(ICH_VTR_EL2) 27214009Sgabeblack@google.com 2738706Sandreas.hansson@arm.com BitUnion64(ICV_CTLR_EL1) 2748706Sandreas.hansson@arm.com Bitfield<63, 19> res0_2; 2758706Sandreas.hansson@arm.com Bitfield<18> RSS; 2768706Sandreas.hansson@arm.com Bitfield<17, 16> res0_1; 2778706Sandreas.hansson@arm.com Bitfield<15> A3V; 27814011Sgabeblack@google.com Bitfield<14> SEIS; 2798706Sandreas.hansson@arm.com Bitfield<13, 11> IDbits; 28014009Sgabeblack@google.com Bitfield<10, 8> PRIbits; 2818706Sandreas.hansson@arm.com Bitfield<7, 2> res0_0; 2828706Sandreas.hansson@arm.com Bitfield<1> EOImode; 28312522Sandreas.sandberg@arm.com Bitfield<0> CBPR; 28412522Sandreas.sandberg@arm.com EndBitUnion(ICV_CTLR_EL1) 28513893Sgabeblack@google.com 28612522Sandreas.sandberg@arm.com protected: 28712522Sandreas.sandberg@arm.com 28814009Sgabeblack@google.com void activateIRQ(uint32_t intid, Gicv3::GroupId group); 28912522Sandreas.sandberg@arm.com int currEL() const; 29012522Sandreas.sandberg@arm.com void deactivateIRQ(uint32_t intid, Gicv3::GroupId group); 29112522Sandreas.sandberg@arm.com void dropPriority(Gicv3::GroupId group); 29212522Sandreas.sandberg@arm.com uint64_t eoiMaintenanceInterruptStatus() const; 29312522Sandreas.sandberg@arm.com bool getHCREL2FMO() const; 29413893Sgabeblack@google.com bool getHCREL2IMO() const; 29512522Sandreas.sandberg@arm.com uint32_t getHPPIR0() const; 29612522Sandreas.sandberg@arm.com uint32_t getHPPIR1() const; 29714009Sgabeblack@google.com int getHPPVILR() const; 29812522Sandreas.sandberg@arm.com bool groupEnabled(Gicv3::GroupId group) const; 29912522Sandreas.sandberg@arm.com uint32_t groupPriorityMask(Gicv3::GroupId group) const; 3008706Sandreas.hansson@arm.com bool haveEL(ArmISA::ExceptionLevel el) const; 301 int highestActiveGroup() const; 302 uint8_t highestActivePriority() const; 303 bool hppiCanPreempt() const; 304 bool hppviCanPreempt(int lrIdx) const; 305 bool inSecureState() const; 306 ArmISA::InterruptTypes intSignalType(Gicv3::GroupId group) const; 307 bool isAA64() const; 308 bool isEL3OrMon() const; 309 bool isEOISplitMode() const; 310 bool isSecureBelowEL3() const; 311 ICH_MISR_EL2 maintenanceInterruptStatus() const; 312 void reset(); 313 void serialize(CheckpointOut & cp) const override; 314 void unserialize(CheckpointIn & cp) override; 315 void update(); 316 void virtualActivateIRQ(uint32_t lrIdx); 317 void virtualDeactivateIRQ(int lrIdx); 318 uint8_t virtualDropPriority(); 319 int virtualFindActive(uint32_t intid) const; 320 uint32_t virtualGroupPriorityMask(Gicv3::GroupId group) const; 321 uint8_t virtualHighestActivePriority() const; 322 void virtualIncrementEOICount(); 323 bool virtualIsEOISplitMode() const; 324 void virtualUpdate(); 325 326 public: 327 328 Gicv3CPUInterface(Gicv3 * gic, uint32_t cpu_id); 329 330 void init(); 331 void initState(); 332 333 public: // BaseISADevice 334 RegVal readMiscReg(int misc_reg) override; 335 void setMiscReg(int misc_reg, RegVal val) override; 336 void setThreadContext(ThreadContext *tc) override; 337}; 338 339#endif //__DEV_ARM_GICV3_CPU_INTERFACE_H__ 340