gem5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
vgic.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 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  * Authors: Matt Evans
38  */
39 
40 
52 #ifndef __DEV_ARM_VGIC_H__
53 #define __DEV_ARM_VGIC_H__
54 
55 #include <algorithm>
56 #include <array>
57 
58 #include "base/addr_range.hh"
59 #include "base/bitunion.hh"
60 #include "cpu/intr_control.hh"
61 #include "dev/io_device.hh"
62 #include "dev/platform.hh"
63 #include "params/VGic.hh"
64 
65 class VGic : public PioDevice
66 {
67  private:
68  static const int VGIC_CPU_MAX = 256;
69  static const int NUM_LR = 4;
70 
71  static const int GICH_SIZE = 0x200;
72  static const int GICH_REG_SIZE = 0x2000;
73 
74  static const int GICH_HCR = 0x000;
75  static const int GICH_VTR = 0x004;
76  static const int GICH_VMCR = 0x008;
77  static const int GICH_MISR = 0x010;
78  static const int GICH_EISR0 = 0x020;
79  static const int GICH_EISR1 = 0x024;
80  static const int GICH_ELSR0 = 0x030;
81  static const int GICH_ELSR1 = 0x034;
82  static const int GICH_APR0 = 0x0f0;
83  static const int GICH_LR0 = 0x100;
84  static const int GICH_LR1 = 0x104;
85  static const int GICH_LR2 = 0x108;
86  static const int GICH_LR3 = 0x10c;
87 
88  static const int GICV_SIZE = 0x2000;
89  static const int GICV_CTLR = 0x000;
90  static const int GICV_PMR = 0x004;
91  static const int GICV_BPR = 0x008;
92  static const int GICV_IAR = 0x00c;
93  static const int GICV_EOIR = 0x010;
94  static const int GICV_RPR = 0x014;
95  static const int GICV_HPPIR = 0x018;
96  static const int GICV_ABPR = 0x01c;
97  static const int GICV_AIAR = 0x020;
98  static const int GICV_AEOIR = 0x024;
99  static const int GICV_AHPPIR = 0x028;
100  static const int GICV_APR0 = 0x0d0;
101  static const int GICV_IIDR = 0x0fc;
102  static const int GICV_DIR = 0x1000;
103 
104  static const uint32_t LR_PENDING = 1;
105  static const uint32_t LR_ACTIVE = 2;
106 
109  class PostVIntEvent : public Event
110  {
111  private:
112  uint32_t cpu;
114  public:
115  PostVIntEvent( uint32_t c, Platform* p)
116  : cpu(c), platform(p)
117  { }
119  const char *description() const { return "Post VInterrupt to CPU"; }
120  };
121 
125 
128 
132  int maintInt;
133 
134  BitUnion32(ListReg)
135  Bitfield<31> HW;
136  Bitfield<30> Grp1;
137  Bitfield<29,28> State;
138  Bitfield<27,23> Priority;
139  Bitfield<19> EOI;
140  Bitfield<12,10> CpuID;
141  Bitfield<9,0> VirtualID;
142  EndBitUnion(ListReg)
143 
144  BitUnion32(HCR)
145  Bitfield<31,27> EOICount;
146  Bitfield<7> VGrp1DIE;
147  Bitfield<6> VGrp1EIE;
148  Bitfield<5> VGrp0DIE;
149  Bitfield<4> VGrp0EIE;
150  Bitfield<3> NPIE;
151  Bitfield<2> LRENPIE;
152  Bitfield<1> UIE;
153  Bitfield<0> En;
154  EndBitUnion(HCR)
155 
156  BitUnion32(VCTLR)
157  Bitfield<9> EOImode;
158  Bitfield<4> CPBR;
159  Bitfield<3> FIQEn;
160  Bitfield<2> AckCtl;
161  Bitfield<1> EnGrp1;
162  Bitfield<0> En; // This gets written to enable, not group 1.
163  EndBitUnion(VCTLR)
164 
165  /* State per CPU. EVERYTHING should be in this struct and simply replicated
166  * N times.
167  */
168  struct vcpuIntData : public Serializable {
169  vcpuIntData()
170  : vctrl(0), hcr(0), eisr(0), VMGrp0En(0), VMGrp1En(0),
171  VMAckCtl(0), VMFiqEn(0), VMCBPR(0), VEM(0), VMABP(0), VMBP(0),
172  VMPriMask(0)
173  {
174  std::fill(LR.begin(), LR.end(), 0);
175  }
176  virtual ~vcpuIntData() {}
177 
178  std::array<ListReg, NUM_LR> LR;
179  VCTLR vctrl;
180 
181  HCR hcr;
182  uint64_t eisr;
183 
184  /* Host info, guest info (should be 100% accessible via GICH_* regs!) */
185  uint8_t VMGrp0En;
186  uint8_t VMGrp1En;
187  uint8_t VMAckCtl;
188  uint8_t VMFiqEn;
189  uint8_t VMCBPR;
190  uint8_t VEM;
191  uint8_t VMABP;
192  uint8_t VMBP;
193  uint8_t VMPriMask;
194 
195  void serialize(CheckpointOut &cp) const override;
196  void unserialize(CheckpointIn &cp) override;
197  };
198 
199  struct std::array<vcpuIntData, VGIC_CPU_MAX> vcpuData;
200 
201  public:
202  typedef VGicParams Params;
203  const Params *
204  params() const
205  {
206  return dynamic_cast<const Params *>(_params);
207  }
208  VGic(const Params *p);
209 
210  AddrRangeList getAddrRanges() const override;
211 
212  Tick read(PacketPtr pkt) override;
213  Tick write(PacketPtr pkt) override;
214 
215  void serialize(CheckpointOut &cp) const override;
216  void unserialize(CheckpointIn &cp) override;
217 
218  private:
219  Tick readVCpu(PacketPtr pkt);
220  Tick readCtrl(PacketPtr pkt);
221 
222  Tick writeVCpu(PacketPtr pkt);
223  Tick writeCtrl(PacketPtr pkt);
224 
225  void updateIntState(ContextID ctx_id);
226  uint32_t getMISR(struct vcpuIntData *vid);
227  void postVInt(uint32_t cpu, Tick when);
228  void unPostVInt(uint32_t cpu);
229  void postMaintInt(uint32_t cpu);
230  void unPostMaintInt(uint32_t cpu);
231 
232  unsigned int lrPending(struct vcpuIntData *vid)
233  {
234  unsigned int pend = 0;
235  for (int i = 0; i < NUM_LR; i++) {
236  if (vid->LR[i].State & LR_PENDING)
237  pend++;
238  }
239  return pend;
240  }
241  unsigned int lrValid(struct vcpuIntData *vid)
242  {
243  unsigned int valid = 0;
244  for (int i = 0; i < NUM_LR; i++) {
245  if (vid->LR[i].State)
246  valid++;
247  }
248  return valid;
249  }
250 
252  int findHighestPendingLR(struct vcpuIntData *vid)
253  {
254  unsigned int prio = 0xff;
255  int p = -1;
256  for (int i = 0; i < NUM_LR; i++) {
257  if ((vid->LR[i].State & LR_PENDING) && (vid->LR[i].Priority < prio)) {
258  p = i;
259  prio = vid->LR[i].Priority;
260  }
261  }
262  return p;
263  }
264 
265  int findLRForVIRQ(struct vcpuIntData *vid, int virq, int vcpu)
266  {
267  for (int i = 0; i < NUM_LR; i++) {
268  if (vid->LR[i].State &&
269  vid->LR[i].VirtualID == virq &&
270  vid->LR[i].CpuID == vcpu)
271  return i;
272  }
273  return -1;
274  }
275 };
276 
277 #endif
IntrControl * intrctrl
Pointer to the interrupt controller.
Definition: platform.hh:56
uint64_t eisr
Definition: vgic.hh:182
static const int GICH_HCR
Definition: vgic.hh:74
static const int GICH_VTR
Definition: vgic.hh:75
Bitfield< 2 > AckCtl
Definition: vgic.hh:160
Bitfield< 4 > VGrp0EIE
Definition: vgic.hh:149
static const int GICV_CTLR
Definition: vgic.hh:89
Addr vcpuAddr
Definition: vgic.hh:129
Bitfield< 9, 0 > VirtualID
Definition: vgic.hh:141
static const int GICV_SIZE
Definition: vgic.hh:88
uint8_t VMAckCtl
Definition: vgic.hh:187
VGic(const Params *p)
Definition: vgic.cc:50
Bitfield< 7 > i
Definition: miscregs.hh:1378
Bitfield< 5 > VGrp0DIE
Definition: vgic.hh:148
void process()
Definition: vgic.hh:118
void post(int cpu_id, int int_num, int index)
Definition: intr_control.cc:50
uint8_t VMCBPR
Definition: vgic.hh:189
unsigned int lrValid(struct vcpuIntData *vid)
Definition: vgic.hh:241
bool maintIntPosted[VGIC_CPU_MAX]
Definition: vgic.hh:123
uint32_t getMISR(struct vcpuIntData *vid)
Definition: vgic.cc:338
BaseGic * gic
Definition: vgic.hh:127
EndBitUnion(ListReg) BitUnion32(HCR) Bitfield< 31
Definition: vgic.hh:65
EOICount
Definition: vgic.hh:145
Event definition to post interrupt to CPU after a delay.
Definition: vgic.hh:109
static const int GICV_IIDR
Definition: vgic.hh:101
uint32_t cpu
Definition: vgic.hh:112
static const int GICH_LR3
Definition: vgic.hh:86
Tick pioDelay
Definition: vgic.hh:131
PostVIntEvent(uint32_t c, Platform *p)
Definition: vgic.hh:115
AddrRangeList getAddrRanges() const override
Every PIO device is obliged to provide an implementation that returns the address ranges the device r...
Definition: vgic.cc:429
static const int GICV_APR0
Definition: vgic.hh:100
Addr hvAddr
Definition: vgic.hh:130
VCTLR vctrl
Definition: vgic.hh:179
Bitfield< 0 > En
Definition: vgic.hh:153
Bitfield< 7 > VGrp1DIE
Definition: vgic.hh:146
uint8_t VMPriMask
Definition: vgic.hh:193
Bitfield< 1 > EnGrp1
Definition: vgic.hh:161
PostVIntEvent * postVIntEvent[VGIC_CPU_MAX]
Definition: vgic.hh:122
Bitfield< 3 > NPIE
Definition: vgic.hh:150
const char * description() const
Return a C string describing the event.
Definition: vgic.hh:119
Bitfield< 6 > VGrp1EIE
Definition: vgic.hh:147
virtual ~vcpuIntData()
Definition: vgic.hh:176
void updateIntState(ContextID ctx_id)
Definition: vgic.cc:384
static const int GICV_BPR
Definition: vgic.hh:91
static const int GICH_MISR
Definition: vgic.hh:77
uint8_t VMBP
Definition: vgic.hh:192
Bitfield< 4 > CPBR
Definition: vgic.hh:158
int maintInt
Definition: vgic.hh:132
uint64_t Tick
Tick count type.
Definition: types.hh:63
void unPostVInt(uint32_t cpu)
Definition: vgic.cc:359
Tick read(PacketPtr pkt) override
Pure virtual function that the device must implement.
Definition: vgic.cc:64
static const int NUM_LR
Definition: vgic.hh:69
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: vgic.cc:438
HCR hcr
Definition: vgic.hh:181
Bitfield< 29, 28 > State
Definition: vgic.hh:137
static const uint32_t LR_PENDING
Definition: vgic.hh:104
Bitfield< 1 > UIE
Definition: vgic.hh:152
This device is the base class which all devices senstive to an address range inherit from...
Definition: io_device.hh:84
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
std::array< ListReg, NUM_LR > LR
Definition: vgic.hh:178
Platform * platform
Definition: vgic.hh:113
A Packet is used to encapsulate a transfer between two objects in the memory system (e...
Definition: packet.hh:245
BitUnion32(ListReg) Bitfield< 31 > HW
Bitfield< 12, 10 > CpuID
Definition: vgic.hh:140
Basic support for object serialization.
Definition: serialize.hh:220
static const int GICV_AEOIR
Definition: vgic.hh:98
struct std::array< vcpuIntData, VGIC_CPU_MAX > vcpuData
Definition: vgic.hh:199
VGicParams Params
Definition: vgic.hh:202
void postMaintInt(uint32_t cpu)
Definition: vgic.cc:366
Tick readVCpu(PacketPtr pkt)
Definition: vgic.cc:90
static const int GICV_RPR
Definition: vgic.hh:94
static const int GICV_HPPIR
Definition: vgic.hh:95
static const int GICH_ELSR1
Definition: vgic.hh:81
static const int GICH_LR0
Definition: vgic.hh:83
Tick write(PacketPtr pkt) override
Pure virtual function that the device must implement.
Definition: vgic.cc:77
Bitfield< 30 > Grp1
Definition: vgic.hh:136
Generic interface for platforms.
Bitfield< 29 > c
Definition: miscregs.hh:1365
static const int GICH_VMCR
Definition: vgic.hh:76
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: vgic.cc:496
unsigned int lrPending(struct vcpuIntData *vid)
Definition: vgic.hh:232
std::ostream CheckpointOut
Definition: serialize.hh:67
static const int GICH_LR2
Definition: vgic.hh:85
static const int GICV_EOIR
Definition: vgic.hh:93
static const int VGIC_CPU_MAX
Definition: vgic.hh:68
static const int GICH_SIZE
Definition: vgic.hh:71
Bitfield< 27, 23 > Priority
Definition: vgic.hh:138
Definition: eventq.hh:185
Platform * platform
Definition: vgic.hh:126
uint8_t VMGrp0En
Definition: vgic.hh:185
int findLRForVIRQ(struct vcpuIntData *vid, int virq, int vcpu)
Definition: vgic.hh:265
Bitfield< 2 > LRENPIE
Definition: vgic.hh:151
int findHighestPendingLR(struct vcpuIntData *vid)
Returns LR index or -1 if none pending.
Definition: vgic.hh:252
Tick writeCtrl(PacketPtr pkt)
Definition: vgic.cc:275
const SimObjectParams * _params
Cached copy of the object parameters.
Definition: sim_object.hh:107
static const int GICV_AIAR
Definition: vgic.hh:97
static const int GICH_LR1
Definition: vgic.hh:84
static const int GICV_DIR
Definition: vgic.hh:102
static const int GICV_AHPPIR
Definition: vgic.hh:99
const Params * params() const
Definition: vgic.hh:204
void postVInt(uint32_t cpu, Tick when)
Definition: vgic.cc:351
Tick writeVCpu(PacketPtr pkt)
Definition: vgic.cc:228
uint8_t VMGrp1En
Definition: vgic.hh:186
Bitfield< 3 > FIQEn
Definition: vgic.hh:159
uint8_t VMABP
Definition: vgic.hh:191
static const int GICH_APR0
Definition: vgic.hh:82
static const uint32_t LR_ACTIVE
Definition: vgic.hh:105
Bitfield< 0 > p
Tick readCtrl(PacketPtr pkt)
Definition: vgic.cc:134
static const int GICH_ELSR0
Definition: vgic.hh:80
static const int GICH_REG_SIZE
Definition: vgic.hh:72
static const int GICV_PMR
Definition: vgic.hh:90
static const int GICH_EISR1
Definition: vgic.hh:79
int ContextID
Globally unique thread context ID.
Definition: types.hh:175
static const int GICV_ABPR
Definition: vgic.hh:96
bool vIntPosted[VGIC_CPU_MAX]
Definition: vgic.hh:124
static const int GICH_EISR0
Definition: vgic.hh:78
Bitfield< 19 > EOI
Definition: vgic.hh:139
uint8_t VMFiqEn
Definition: vgic.hh:188
uint8_t VEM
Definition: vgic.hh:190
void unPostMaintInt(uint32_t cpu)
Definition: vgic.cc:374
static const int GICV_IAR
Definition: vgic.hh:92

Generated on Fri Jun 9 2017 13:03:45 for gem5 by doxygen 1.8.6