gem5  v20.1.0.0
vgic.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013,2018 ARM Limited
3  * All rights reserved
4  *
5  * The license below extends only to copyright in the software and shall
6  * not be construed as granting a license to any other intellectual
7  * property including but not limited to intellectual property relating
8  * to a hardware implementation of the functionality of the software
9  * licensed hereunder. You may use the software subject to the license
10  * terms below provided that you ensure that this notice is replicated
11  * unmodified and in its entirety in all distributions of the software,
12  * modified or unmodified, in source code or in binary form.
13  *
14  * Redistribution and use in source and binary forms, with or without
15  * modification, are permitted provided that the following conditions are
16  * met: redistributions of source code must retain the above copyright
17  * notice, this list of conditions and the following disclaimer;
18  * redistributions in binary form must reproduce the above copyright
19  * notice, this list of conditions and the following disclaimer in the
20  * documentation and/or other materials provided with the distribution;
21  * neither the name of the copyright holders nor the names of its
22  * contributors may be used to endorse or promote products derived from
23  * this software without specific prior written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36  */
37 
38 
50 #ifndef __DEV_ARM_VGIC_H__
51 #define __DEV_ARM_VGIC_H__
52 
53 #include <algorithm>
54 #include <array>
55 
56 #include "base/addr_range.hh"
57 #include "base/bitunion.hh"
58 #include "cpu/intr_control.hh"
59 #include "dev/io_device.hh"
60 #include "dev/platform.hh"
61 #include "params/VGic.hh"
62 
63 class VGic : public PioDevice
64 {
65  private:
66  static const int VGIC_CPU_MAX = 256;
67  static const int NUM_LR = 4;
68 
69  static const int GICH_SIZE = 0x200;
70  static const int GICH_REG_SIZE = 0x2000;
71 
72  static const int GICH_HCR = 0x000;
73  static const int GICH_VTR = 0x004;
74  static const int GICH_VMCR = 0x008;
75  static const int GICH_MISR = 0x010;
76  static const int GICH_EISR0 = 0x020;
77  static const int GICH_EISR1 = 0x024;
78  static const int GICH_ELSR0 = 0x030;
79  static const int GICH_ELSR1 = 0x034;
80  static const int GICH_APR0 = 0x0f0;
81  static const int GICH_LR0 = 0x100;
82  static const int GICH_LR1 = 0x104;
83  static const int GICH_LR2 = 0x108;
84  static const int GICH_LR3 = 0x10c;
85 
86  static const int GICV_SIZE = 0x2000;
87  static const int GICV_CTLR = 0x000;
88  static const int GICV_PMR = 0x004;
89  static const int GICV_BPR = 0x008;
90  static const int GICV_IAR = 0x00c;
91  static const int GICV_EOIR = 0x010;
92  static const int GICV_RPR = 0x014;
93  static const int GICV_HPPIR = 0x018;
94  static const int GICV_ABPR = 0x01c;
95  static const int GICV_AIAR = 0x020;
96  static const int GICV_AEOIR = 0x024;
97  static const int GICV_AHPPIR = 0x028;
98  static const int GICV_APR0 = 0x0d0;
99  static const int GICV_IIDR = 0x0fc;
100  static const int GICV_DIR = 0x1000;
101 
102  static const uint32_t LR_PENDING = 1;
103  static const uint32_t LR_ACTIVE = 2;
104  const uint32_t gicvIIDR;
105 
107  void processPostVIntEvent(uint32_t cpu);
108 
112 
115 
119  int maintInt;
120 
121  BitUnion32(ListReg)
122  Bitfield<31> HW;
123  Bitfield<30> Grp1;
124  Bitfield<29,28> State;
125  Bitfield<27,23> Priority;
126  Bitfield<19> EOI;
127  Bitfield<12,10> CpuID;
128  Bitfield<9,0> VirtualID;
129  EndBitUnion(ListReg)
130 
131  BitUnion32(HCR)
132  Bitfield<31,27> EOICount;
133  Bitfield<7> VGrp1DIE;
134  Bitfield<6> VGrp1EIE;
135  Bitfield<5> VGrp0DIE;
136  Bitfield<4> VGrp0EIE;
137  Bitfield<3> NPIE;
138  Bitfield<2> LRENPIE;
139  Bitfield<1> UIE;
140  Bitfield<0> En;
141  EndBitUnion(HCR)
142 
143  BitUnion32(VCTLR)
144  Bitfield<9> EOImode;
145  Bitfield<4> CPBR;
146  Bitfield<3> FIQEn;
147  Bitfield<2> AckCtl;
148  Bitfield<1> EnGrp1;
149  Bitfield<0> En; // This gets written to enable, not group 1.
150  EndBitUnion(VCTLR)
151 
152  /* State per CPU. EVERYTHING should be in this struct and simply replicated
153  * N times.
154  */
155  struct vcpuIntData : public Serializable {
156  vcpuIntData()
157  : vctrl(0), hcr(0), eisr(0), VMGrp0En(0), VMGrp1En(0),
158  VMAckCtl(0), VMFiqEn(0), VMCBPR(0), VEM(0), VMABP(0), VMBP(0),
159  VMPriMask(0)
160  {
161  std::fill(LR.begin(), LR.end(), 0);
162  }
163  virtual ~vcpuIntData() {}
164 
165  std::array<ListReg, NUM_LR> LR;
166  VCTLR vctrl;
167 
168  HCR hcr;
169  uint64_t eisr;
170 
171  /* Host info, guest info (should be 100% accessible via GICH_* regs!) */
172  uint8_t VMGrp0En;
173  uint8_t VMGrp1En;
174  uint8_t VMAckCtl;
175  uint8_t VMFiqEn;
176  uint8_t VMCBPR;
177  uint8_t VEM;
178  uint8_t VMABP;
179  uint8_t VMBP;
180  uint8_t VMPriMask;
181 
182  void serialize(CheckpointOut &cp) const override;
183  void unserialize(CheckpointIn &cp) override;
184  };
185 
186  struct std::array<vcpuIntData, VGIC_CPU_MAX> vcpuData;
187 
188  public:
189  typedef VGicParams Params;
190  const Params *
191  params() const
192  {
193  return dynamic_cast<const Params *>(_params);
194  }
195  VGic(const Params *p);
196  ~VGic();
197 
198  AddrRangeList getAddrRanges() const override;
199 
200  Tick read(PacketPtr pkt) override;
201  Tick write(PacketPtr pkt) override;
202 
203  void serialize(CheckpointOut &cp) const override;
204  void unserialize(CheckpointIn &cp) override;
205 
206  private:
207  Tick readVCpu(PacketPtr pkt);
208  Tick readCtrl(PacketPtr pkt);
209 
210  Tick writeVCpu(PacketPtr pkt);
211  Tick writeCtrl(PacketPtr pkt);
212 
213  void updateIntState(ContextID ctx_id);
214  uint32_t getMISR(struct vcpuIntData *vid);
215  void postVInt(uint32_t cpu, Tick when);
216  void unPostVInt(uint32_t cpu);
217  void postMaintInt(uint32_t cpu);
218  void unPostMaintInt(uint32_t cpu);
219 
220  unsigned int lrPending(struct vcpuIntData *vid)
221  {
222  unsigned int pend = 0;
223  for (int i = 0; i < NUM_LR; i++) {
224  if (vid->LR[i].State & LR_PENDING)
225  pend++;
226  }
227  return pend;
228  }
229  unsigned int lrValid(struct vcpuIntData *vid)
230  {
231  unsigned int valid = 0;
232  for (int i = 0; i < NUM_LR; i++) {
233  if (vid->LR[i].State)
234  valid++;
235  }
236  return valid;
237  }
238 
240  int findHighestPendingLR(struct vcpuIntData *vid)
241  {
242  unsigned int prio = 0xff;
243  int p = -1;
244  for (int i = 0; i < NUM_LR; i++) {
245  if ((vid->LR[i].State & LR_PENDING) && (vid->LR[i].Priority < prio)) {
246  p = i;
247  prio = vid->LR[i].Priority;
248  }
249  }
250  return p;
251  }
252 
253  int findLRForVIRQ(struct vcpuIntData *vid, int virq, int vcpu)
254  {
255  for (int i = 0; i < NUM_LR; i++) {
256  if (vid->LR[i].State &&
257  vid->LR[i].VirtualID == virq &&
258  vid->LR[i].CpuID == vcpu)
259  return i;
260  }
261  return -1;
262  }
263 };
264 
265 #endif
VGic::unPostVInt
void unPostVInt(uint32_t cpu)
Definition: vgic.cc:371
VGic::vcpuAddr
Addr vcpuAddr
Definition: vgic.hh:116
VGic::getAddrRanges
AddrRangeList getAddrRanges() const override
Every PIO device is obliged to provide an implementation that returns the address ranges the device r...
Definition: vgic.cc:448
io_device.hh
VGic::GICV_BPR
static const int GICV_BPR
Definition: vgic.hh:89
VGic::GICH_VMCR
static const int GICH_VMCR
Definition: vgic.hh:74
VGic::GICH_LR1
static const int GICH_LR1
Definition: vgic.hh:82
VGic::GICH_EISR0
static const int GICH_EISR0
Definition: vgic.hh:76
VGic::vIntPosted
bool vIntPosted[VGIC_CPU_MAX]
Definition: vgic.hh:111
VGic::VGrp0DIE
Bitfield< 5 > VGrp0DIE
Definition: vgic.hh:135
VGic::AckCtl
Bitfield< 2 > AckCtl
Definition: vgic.hh:147
VGic::getMISR
uint32_t getMISR(struct vcpuIntData *vid)
Definition: vgic.cc:350
VGic::postMaintInt
void postMaintInt(uint32_t cpu)
Definition: vgic.cc:385
ArmISA::i
Bitfield< 7 > i
Definition: miscregs_types.hh:63
VGic::maintIntPosted
bool maintIntPosted[VGIC_CPU_MAX]
Definition: vgic.hh:110
VGic::GICV_IAR
static const int GICV_IAR
Definition: vgic.hh:90
Serializable
Basic support for object serialization.
Definition: serialize.hh:172
VGic::GICH_VTR
static const int GICH_VTR
Definition: vgic.hh:73
ContextID
int ContextID
Globally unique thread context ID.
Definition: types.hh:231
VGic::CpuID
Bitfield< 12, 10 > CpuID
Definition: vgic.hh:127
VGic::VirtualID
Bitfield< 9, 0 > VirtualID
Definition: vgic.hh:128
VGic::updateIntState
void updateIntState(ContextID ctx_id)
Definition: vgic.cc:403
Tick
uint64_t Tick
Tick count type.
Definition: types.hh:63
VGic::GICH_EISR1
static const int GICH_EISR1
Definition: vgic.hh:77
VGic::writeVCpu
Tick writeVCpu(PacketPtr pkt)
Definition: vgic.cc:237
VGic::~VGic
~VGic()
Definition: vgic.cc:63
VGic::pioDelay
Tick pioDelay
Definition: vgic.hh:118
VGic::readCtrl
Tick readCtrl(PacketPtr pkt)
Definition: vgic.cc:143
VGic::VGic
VGic(const Params *p)
Definition: vgic.cc:48
VGic::GICV_EOIR
static const int GICV_EOIR
Definition: vgic.hh:91
VGic::platform
Platform * platform
Definition: vgic.hh:113
VGic::findLRForVIRQ
int findLRForVIRQ(struct vcpuIntData *vid, int virq, int vcpu)
Definition: vgic.hh:253
VGic::writeCtrl
Tick writeCtrl(PacketPtr pkt)
Definition: vgic.cc:286
VGic::maintInt
int maintInt
Definition: vgic.hh:119
VGic::hvAddr
Addr hvAddr
Definition: vgic.hh:117
EventFunctionWrapper
Definition: eventq.hh:1101
VGic::EOICount
EOICount
Definition: vgic.hh:132
VGic::lrPending
unsigned int lrPending(struct vcpuIntData *vid)
Definition: vgic.hh:220
VGic::lrValid
unsigned int lrValid(struct vcpuIntData *vid)
Definition: vgic.hh:229
VGic::GICH_ELSR0
static const int GICH_ELSR0
Definition: vgic.hh:78
cp
Definition: cprintf.cc:40
VGic::GICV_APR0
static const int GICV_APR0
Definition: vgic.hh:98
PioDevice
This device is the base class which all devices senstive to an address range inherit from.
Definition: io_device.hh:99
VGic::CPBR
Bitfield< 4 > CPBR
Definition: vgic.hh:145
VGic::GICH_APR0
static const int GICH_APR0
Definition: vgic.hh:80
VGic::GICV_IIDR
static const int GICV_IIDR
Definition: vgic.hh:99
bitunion.hh
VGic::read
Tick read(PacketPtr pkt) override
Pure virtual function that the device must implement.
Definition: vgic.cc:70
VGic::GICH_MISR
static const int GICH_MISR
Definition: vgic.hh:75
VGic::GICV_CTLR
static const int GICV_CTLR
Definition: vgic.hh:87
VGic::UIE
Bitfield< 1 > UIE
Definition: vgic.hh:139
VGic::serialize
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: vgic.cc:457
VGic::Priority
Bitfield< 27, 23 > Priority
Definition: vgic.hh:125
VGic::readVCpu
Tick readVCpu(PacketPtr pkt)
Definition: vgic.cc:96
VGic::VGrp1EIE
Bitfield< 6 > VGrp1EIE
Definition: vgic.hh:134
VGic::GICH_LR0
static const int GICH_LR0
Definition: vgic.hh:81
Platform
Definition: platform.hh:49
VGic::postVIntEvent
EventFunctionWrapper * postVIntEvent[VGIC_CPU_MAX]
Definition: vgic.hh:109
VGic::GICV_DIR
static const int GICV_DIR
Definition: vgic.hh:100
platform.hh
VGic::vcpuData
EndBitUnion(VCTLR) struct vcpuIntData struct std::array< vcpuIntData, VGIC_CPU_MAX > vcpuData
Definition: vgic.hh:186
VGic::GICH_SIZE
static const int GICH_SIZE
Definition: vgic.hh:69
Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
VGic::gic
BaseGic * gic
Definition: vgic.hh:114
VGic::GICH_ELSR1
static const int GICH_ELSR1
Definition: vgic.hh:79
VGic::GICV_AIAR
static const int GICV_AIAR
Definition: vgic.hh:95
VGic::EndBitUnion
EndBitUnion(ListReg) BitUnion32(HCR) Bitfield< 31
addr_range.hh
VGic::FIQEn
Bitfield< 3 > FIQEn
Definition: vgic.hh:146
VGic::unserialize
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: vgic.cc:515
VGic::LR_PENDING
static const uint32_t LR_PENDING
Definition: vgic.hh:102
VGic::LR_ACTIVE
static const uint32_t LR_ACTIVE
Definition: vgic.hh:103
MipsISA::fill
fill
Definition: pra_constants.hh:54
VGic::State
Bitfield< 29, 28 > State
Definition: vgic.hh:124
VGic::EnGrp1
Bitfield< 1 > EnGrp1
Definition: vgic.hh:148
VGic::BitUnion32
BitUnion32(ListReg) Bitfield< 31 > HW
VGic::NUM_LR
static const int NUM_LR
Definition: vgic.hh:67
VGic::params
const Params * params() const
Definition: vgic.hh:191
VGic::write
Tick write(PacketPtr pkt) override
Pure virtual function that the device must implement.
Definition: vgic.cc:83
VGic::GICV_HPPIR
static const int GICV_HPPIR
Definition: vgic.hh:93
BaseGic
Definition: base_gic.hh:62
SimObject::_params
const SimObjectParams * _params
Cached copy of the object parameters.
Definition: sim_object.hh:110
VGic::LRENPIE
Bitfield< 2 > LRENPIE
Definition: vgic.hh:138
VGic
Definition: vgic.hh:63
VGic::findHighestPendingLR
int findHighestPendingLR(struct vcpuIntData *vid)
Returns LR index or -1 if none pending.
Definition: vgic.hh:240
intr_control.hh
Packet
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:257
VGic::Grp1
Bitfield< 30 > Grp1
Definition: vgic.hh:123
VGic::En
Bitfield< 0 > En
Definition: vgic.hh:140
VGic::GICV_PMR
static const int GICV_PMR
Definition: vgic.hh:88
VGic::VGrp1DIE
Bitfield< 7 > VGrp1DIE
Definition: vgic.hh:133
VGic::gicvIIDR
const uint32_t gicvIIDR
Definition: vgic.hh:104
VGic::processPostVIntEvent
void processPostVIntEvent(uint32_t cpu)
Post interrupt to CPU.
Definition: vgic.cc:378
VGic::GICV_SIZE
static const int GICV_SIZE
Definition: vgic.hh:86
VGic::NPIE
Bitfield< 3 > NPIE
Definition: vgic.hh:137
VGic::unPostMaintInt
void unPostMaintInt(uint32_t cpu)
Definition: vgic.cc:393
CheckpointOut
std::ostream CheckpointOut
Definition: serialize.hh:63
VGic::EOI
Bitfield< 19 > EOI
Definition: vgic.hh:126
VGic::GICV_AHPPIR
static const int GICV_AHPPIR
Definition: vgic.hh:97
VGic::Params
VGicParams Params
Definition: vgic.hh:189
MipsISA::p
Bitfield< 0 > p
Definition: pra_constants.hh:323
std::list< AddrRange >
CheckpointIn
Definition: serialize.hh:67
VGic::GICV_ABPR
static const int GICV_ABPR
Definition: vgic.hh:94
VGic::GICV_RPR
static const int GICV_RPR
Definition: vgic.hh:92
VGic::postVInt
void postVInt(uint32_t cpu, Tick when)
Definition: vgic.cc:363
VGic::GICH_LR2
static const int GICH_LR2
Definition: vgic.hh:83
VGic::GICH_HCR
static const int GICH_HCR
Definition: vgic.hh:72
VGic::VGIC_CPU_MAX
static const int VGIC_CPU_MAX
Definition: vgic.hh:66
VGic::VGrp0EIE
Bitfield< 4 > VGrp0EIE
Definition: vgic.hh:136
VGic::GICH_LR3
static const int GICH_LR3
Definition: vgic.hh:84
VGic::GICH_REG_SIZE
static const int GICH_REG_SIZE
Definition: vgic.hh:70
VGic::GICV_AEOIR
static const int GICV_AEOIR
Definition: vgic.hh:96

Generated on Wed Sep 30 2020 14:02:10 for gem5 by doxygen 1.8.17