gem5  v20.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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
static const int GICH_HCR
Definition: vgic.hh:72
static const int GICH_VTR
Definition: vgic.hh:73
Bitfield< 2 > AckCtl
Definition: vgic.hh:147
Bitfield< 4 > VGrp0EIE
Definition: vgic.hh:136
static const int GICV_CTLR
Definition: vgic.hh:87
EndBitUnion(VCTLR) struct vcpuIntData struct std::array< vcpuIntData, VGIC_CPU_MAX > vcpuData
Definition: vgic.hh:186
Addr vcpuAddr
Definition: vgic.hh:116
Bitfield< 9, 0 > VirtualID
Definition: vgic.hh:128
static const int GICV_SIZE
Definition: vgic.hh:86
~VGic()
Definition: vgic.cc:62
VGic(const Params *p)
Definition: vgic.cc:47
Bitfield< 7 > i
Bitfield< 5 > VGrp0DIE
Definition: vgic.hh:135
unsigned int lrValid(struct vcpuIntData *vid)
Definition: vgic.hh:229
bool maintIntPosted[VGIC_CPU_MAX]
Definition: vgic.hh:110
uint32_t getMISR(struct vcpuIntData *vid)
Definition: vgic.cc:349
BaseGic * gic
Definition: vgic.hh:114
EndBitUnion(ListReg) BitUnion32(HCR) Bitfield< 31
Definition: vgic.hh:63
EOICount
Definition: vgic.hh:132
static const int GICV_IIDR
Definition: vgic.hh:99
static const int GICH_LR3
Definition: vgic.hh:84
Tick pioDelay
Definition: vgic.hh:118
void processPostVIntEvent(uint32_t cpu)
Post interrupt to CPU.
Definition: vgic.cc:377
Definition: cprintf.cc:40
AddrRangeList getAddrRanges() const override
Every PIO device is obliged to provide an implementation that returns the address ranges the device r...
Definition: vgic.cc:447
static const int GICV_APR0
Definition: vgic.hh:98
Addr hvAddr
Definition: vgic.hh:117
Bitfield< 0 > En
Definition: vgic.hh:140
Bitfield< 7 > VGrp1DIE
Definition: vgic.hh:133
Bitfield< 1 > EnGrp1
Definition: vgic.hh:148
Bitfield< 3 > NPIE
Definition: vgic.hh:137
Bitfield< 6 > VGrp1EIE
Definition: vgic.hh:134
void updateIntState(ContextID ctx_id)
Definition: vgic.cc:402
static const int GICV_BPR
Definition: vgic.hh:89
static const int GICH_MISR
Definition: vgic.hh:75
Bitfield< 4 > CPBR
Definition: vgic.hh:145
int maintInt
Definition: vgic.hh:119
uint64_t Tick
Tick count type.
Definition: types.hh:61
void unPostVInt(uint32_t cpu)
Definition: vgic.cc:370
Tick read(PacketPtr pkt) override
Pure virtual function that the device must implement.
Definition: vgic.cc:69
static const int NUM_LR
Definition: vgic.hh:67
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: vgic.cc:456
EventFunctionWrapper * postVIntEvent[VGIC_CPU_MAX]
Definition: vgic.hh:109
Bitfield< 29, 28 > State
Definition: vgic.hh:124
static const uint32_t LR_PENDING
Definition: vgic.hh:102
Bitfield< 1 > UIE
Definition: vgic.hh:139
const Params * params() const
Definition: vgic.hh:191
This device is the base class which all devices senstive to an address range inherit from...
Definition: io_device.hh:99
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:140
A Packet is used to encapsulate a transfer between two objects in the memory system (e...
Definition: packet.hh:249
BitUnion32(ListReg) Bitfield< 31 > HW
Bitfield< 12, 10 > CpuID
Definition: vgic.hh:127
Basic support for object serialization.
Definition: serialize.hh:166
static const int GICV_AEOIR
Definition: vgic.hh:96
VGicParams Params
Definition: vgic.hh:189
void postMaintInt(uint32_t cpu)
Definition: vgic.cc:384
Tick readVCpu(PacketPtr pkt)
Definition: vgic.cc:95
static const int GICV_RPR
Definition: vgic.hh:92
static const int GICV_HPPIR
Definition: vgic.hh:93
static const int GICH_ELSR1
Definition: vgic.hh:79
static const int GICH_LR0
Definition: vgic.hh:81
const uint32_t gicvIIDR
Definition: vgic.hh:104
Tick write(PacketPtr pkt) override
Pure virtual function that the device must implement.
Definition: vgic.cc:82
Bitfield< 30 > Grp1
Definition: vgic.hh:123
Generic interface for platforms.
static const int GICH_VMCR
Definition: vgic.hh:74
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: vgic.cc:514
unsigned int lrPending(struct vcpuIntData *vid)
Definition: vgic.hh:220
std::ostream CheckpointOut
Definition: serialize.hh:63
static const int GICH_LR2
Definition: vgic.hh:83
static const int GICV_EOIR
Definition: vgic.hh:91
static const int VGIC_CPU_MAX
Definition: vgic.hh:66
static const int GICH_SIZE
Definition: vgic.hh:69
Bitfield< 27, 23 > Priority
Definition: vgic.hh:125
Platform * platform
Definition: vgic.hh:113
const SimObjectParams * _params
Cached copy of the object parameters.
Definition: sim_object.hh:111
int findLRForVIRQ(struct vcpuIntData *vid, int virq, int vcpu)
Definition: vgic.hh:253
Bitfield< 2 > LRENPIE
Definition: vgic.hh:138
int findHighestPendingLR(struct vcpuIntData *vid)
Returns LR index or -1 if none pending.
Definition: vgic.hh:240
Tick writeCtrl(PacketPtr pkt)
Definition: vgic.cc:285
static const int GICV_AIAR
Definition: vgic.hh:95
static const int GICH_LR1
Definition: vgic.hh:82
static const int GICV_DIR
Definition: vgic.hh:100
static const int GICV_AHPPIR
Definition: vgic.hh:97
void postVInt(uint32_t cpu, Tick when)
Definition: vgic.cc:362
Tick writeVCpu(PacketPtr pkt)
Definition: vgic.cc:236
Bitfield< 3 > FIQEn
Definition: vgic.hh:146
static const int GICH_APR0
Definition: vgic.hh:80
static const uint32_t LR_ACTIVE
Definition: vgic.hh:103
Bitfield< 0 > p
Tick readCtrl(PacketPtr pkt)
Definition: vgic.cc:142
static const int GICH_ELSR0
Definition: vgic.hh:78
static const int GICH_REG_SIZE
Definition: vgic.hh:70
static const int GICV_PMR
Definition: vgic.hh:88
static const int GICH_EISR1
Definition: vgic.hh:77
int ContextID
Globally unique thread context ID.
Definition: types.hh:229
static const int GICV_ABPR
Definition: vgic.hh:94
bool vIntPosted[VGIC_CPU_MAX]
Definition: vgic.hh:111
static const int GICH_EISR0
Definition: vgic.hh:76
Bitfield< 19 > EOI
Definition: vgic.hh:126
void unPostMaintInt(uint32_t cpu)
Definition: vgic.cc:392
static const int GICV_IAR
Definition: vgic.hh:90

Generated on Thu May 28 2020 16:21:32 for gem5 by doxygen 1.8.13