gem5 v24.0.0.0
Loading...
Searching...
No Matches
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 "dev/io_device.hh"
59#include "dev/platform.hh"
60#include "params/VGic.hh"
61
62namespace gem5
63{
64
65class 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 const uint32_t gicvIIDR;
107
109 void processPostVIntEvent(uint32_t cpu);
110
114
117
122
123 BitUnion32(ListReg)
124 Bitfield<31> HW;
125 Bitfield<30> Grp1;
126 Bitfield<29,28> State;
127 Bitfield<27,23> Priority;
128 Bitfield<19> EOI;
129 Bitfield<12,10> CpuID;
130 Bitfield<9,0> VirtualID;
131 EndBitUnion(ListReg)
132
133 BitUnion32(HCR)
134 Bitfield<31,27> EOICount;
135 Bitfield<7> VGrp1DIE;
136 Bitfield<6> VGrp1EIE;
137 Bitfield<5> VGrp0DIE;
138 Bitfield<4> VGrp0EIE;
139 Bitfield<3> NPIE;
140 Bitfield<2> LRENPIE;
141 Bitfield<1> UIE;
142 Bitfield<0> En;
144
145 BitUnion32(VCTLR)
146 Bitfield<9> EOImode;
147 Bitfield<4> CPBR;
148 Bitfield<3> FIQEn;
149 Bitfield<2> AckCtl;
150 Bitfield<1> EnGrp1;
151 Bitfield<0> En; // This gets written to enable, not group 1.
152 EndBitUnion(VCTLR)
153
154 /* State per CPU. EVERYTHING should be in this struct and simply replicated
155 * N times.
156 */
157 struct vcpuIntData : public Serializable
158 {
159 vcpuIntData()
160 : vctrl(0), hcr(0), eisr(0), VMGrp0En(0), VMGrp1En(0),
161 VMAckCtl(0), VMFiqEn(0), VMCBPR(0), VEM(0), VMABP(0), VMBP(0),
162 VMPriMask(0)
163 {
164 std::fill(LR.begin(), LR.end(), 0);
165 }
166 virtual ~vcpuIntData() {}
167
168 std::array<ListReg, NUM_LR> LR;
169 VCTLR vctrl;
170
171 HCR hcr;
172 uint64_t eisr;
173
174 /* Host info, guest info (should be 100% accessible via GICH_* regs!) */
175 uint8_t VMGrp0En;
176 uint8_t VMGrp1En;
177 uint8_t VMAckCtl;
178 uint8_t VMFiqEn;
179 uint8_t VMCBPR;
180 uint8_t VEM;
181 uint8_t VMABP;
182 uint8_t VMBP;
183 uint8_t VMPriMask;
184
185 void serialize(CheckpointOut &cp) const override;
186 void unserialize(CheckpointIn &cp) override;
187 };
188
189 struct std::array<vcpuIntData, VGIC_CPU_MAX> vcpuData;
190
191 public:
192 using Params = VGicParams;
193 VGic(const Params &p);
194 ~VGic();
195
196 AddrRangeList getAddrRanges() const override;
197
198 Tick read(PacketPtr pkt) override;
199 Tick write(PacketPtr pkt) override;
200
201 void serialize(CheckpointOut &cp) const override;
202 void unserialize(CheckpointIn &cp) override;
203
204 private:
207
210
211 void updateIntState(ContextID ctx_id);
212 uint32_t getMISR(struct vcpuIntData *vid);
213 void postVInt(uint32_t cpu, Tick when);
214 void unPostVInt(uint32_t cpu);
215 void postMaintInt(uint32_t cpu);
216 void unPostMaintInt(uint32_t cpu);
217
218 unsigned int lrPending(struct vcpuIntData *vid)
219 {
220 unsigned int pend = 0;
221 for (int i = 0; i < NUM_LR; i++) {
222 if (vid->LR[i].State & LR_PENDING)
223 pend++;
224 }
225 return pend;
226 }
227 unsigned int lrValid(struct vcpuIntData *vid)
228 {
229 unsigned int valid = 0;
230 for (int i = 0; i < NUM_LR; i++) {
231 if (vid->LR[i].State)
232 valid++;
233 }
234 return valid;
235 }
236
238 int findHighestPendingLR(struct vcpuIntData *vid)
239 {
240 unsigned int prio = 0xff;
241 int p = -1;
242 for (int i = 0; i < NUM_LR; i++) {
243 if ((vid->LR[i].State & LR_PENDING) && (vid->LR[i].Priority < prio)) {
244 p = i;
245 prio = vid->LR[i].Priority;
246 }
247 }
248 return p;
249 }
250
251 int findLRForVIRQ(struct vcpuIntData *vid, int virq, int vcpu)
252 {
253 for (int i = 0; i < NUM_LR; i++) {
254 if (vid->LR[i].State &&
255 vid->LR[i].VirtualID == virq &&
256 vid->LR[i].CpuID == vcpu)
257 return i;
258 }
259 return -1;
260 }
261};
262
263} // namespace gem5
264
265#endif
#define BitUnion32(name)
Definition bitunion.hh:495
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition packet.hh:295
This device is the base class which all devices senstive to an address range inherit from.
Definition io_device.hh:103
Basic support for object serialization.
Definition serialize.hh:170
Tick read(PacketPtr pkt) override
Pure virtual function that the device must implement.
Definition vgic.cc:74
static const int NUM_LR
Definition vgic.hh:69
Bitfield< 30 > Grp1
Definition vgic.hh:125
static const int GICV_APR0
Definition vgic.hh:100
Bitfield< 5 > VGrp0DIE
Definition vgic.hh:137
static const int GICV_BPR
Definition vgic.hh:91
AddrRangeList getAddrRanges() const override
Every PIO device is obliged to provide an implementation that returns the address ranges the device r...
Definition vgic.cc:454
Bitfield< 9, 0 > VirtualID
Definition vgic.hh:130
Tick writeCtrl(PacketPtr pkt)
Definition vgic.cc:290
static const int GICH_LR2
Definition vgic.hh:85
static const int GICV_CTLR
Definition vgic.hh:89
static const uint32_t LR_PENDING
Definition vgic.hh:104
VGic(const Params &p)
Definition vgic.cc:52
Tick pioDelay
Definition vgic.hh:120
Bitfield< 2 > LRENPIE
Definition vgic.hh:140
static const int GICH_HCR
Definition vgic.hh:74
static const int GICH_MISR
Definition vgic.hh:77
static const int GICH_ELSR1
Definition vgic.hh:81
static const int GICV_AEOIR
Definition vgic.hh:98
Tick readVCpu(PacketPtr pkt)
Definition vgic.cc:100
void postVInt(uint32_t cpu, Tick when)
Definition vgic.cc:367
void unPostMaintInt(uint32_t cpu)
Definition vgic.cc:399
EventFunctionWrapper * postVIntEvent[VGIC_CPU_MAX]
Definition vgic.hh:111
BaseGic * gic
Definition vgic.hh:116
Addr vcpuAddr
Definition vgic.hh:118
Bitfield< 4 > CPBR
Definition vgic.hh:147
static const int GICH_VMCR
Definition vgic.hh:76
Tick readCtrl(PacketPtr pkt)
Definition vgic.cc:147
uint32_t getMISR(struct vcpuIntData *vid)
Definition vgic.cc:354
BitUnion32(ListReg) Bitfield< 31 > HW
int findLRForVIRQ(struct vcpuIntData *vid, int virq, int vcpu)
Definition vgic.hh:251
Addr hvAddr
Definition vgic.hh:119
Bitfield< 19 > EOI
Definition vgic.hh:128
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition vgic.cc:463
Platform * platform
Definition vgic.hh:115
static const int GICV_HPPIR
Definition vgic.hh:95
static const int GICH_EISR0
Definition vgic.hh:78
unsigned int lrPending(struct vcpuIntData *vid)
Definition vgic.hh:218
static const int GICH_REG_SIZE
Definition vgic.hh:72
Bitfield< 12, 10 > CpuID
Definition vgic.hh:129
unsigned int lrValid(struct vcpuIntData *vid)
Definition vgic.hh:227
static const int GICV_DIR
Definition vgic.hh:102
Tick write(PacketPtr pkt) override
Pure virtual function that the device must implement.
Definition vgic.cc:87
const uint32_t gicvIIDR
Definition vgic.hh:106
static const int GICV_ABPR
Definition vgic.hh:96
static const int GICV_AIAR
Definition vgic.hh:97
Bitfield< 4 > VGrp0EIE
Definition vgic.hh:138
Bitfield< 1 > EnGrp1
Definition vgic.hh:150
int findHighestPendingLR(struct vcpuIntData *vid)
Returns LR index or -1 if none pending.
Definition vgic.hh:238
static const uint32_t LR_ACTIVE
Definition vgic.hh:105
Bitfield< 7 > VGrp1DIE
Definition vgic.hh:135
static const int GICH_SIZE
Definition vgic.hh:71
static const int GICH_LR1
Definition vgic.hh:84
VGicParams Params
Definition vgic.hh:192
static const int GICV_EOIR
Definition vgic.hh:93
static const int GICH_APR0
Definition vgic.hh:82
static const int GICH_LR0
Definition vgic.hh:83
static const int GICV_PMR
Definition vgic.hh:90
int maintInt
Definition vgic.hh:121
bool maintIntPosted[VGIC_CPU_MAX]
Definition vgic.hh:112
bool vIntPosted[VGIC_CPU_MAX]
Definition vgic.hh:113
Bitfield< 29, 28 > State
Definition vgic.hh:126
static const int GICV_AHPPIR
Definition vgic.hh:99
void unPostVInt(uint32_t cpu)
Definition vgic.cc:375
Tick writeVCpu(PacketPtr pkt)
Definition vgic.cc:241
Bitfield< 6 > VGrp1EIE
Definition vgic.hh:136
Bitfield< 3 > FIQEn
Definition vgic.hh:148
EndBitUnion(VCTLR) struct vcpuIntData struct std::array< vcpuIntData, VGIC_CPU_MAX > vcpuData
Definition vgic.hh:189
Bitfield< 0 > En
Definition vgic.hh:142
static const int GICH_LR3
Definition vgic.hh:86
void updateIntState(ContextID ctx_id)
Definition vgic.cc:409
Bitfield< 3 > NPIE
Definition vgic.hh:139
static const int GICV_SIZE
Definition vgic.hh:88
static const int VGIC_CPU_MAX
Definition vgic.hh:68
Bitfield< 1 > UIE
Definition vgic.hh:141
void postMaintInt(uint32_t cpu)
Definition vgic.cc:391
Bitfield< 27, 23 > Priority
Definition vgic.hh:127
EndBitUnion(ListReg) BitUnion32(HCR) Bitfield< 31
static const int GICH_VTR
Definition vgic.hh:75
static const int GICV_IIDR
Definition vgic.hh:101
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition vgic.cc:521
static const int GICV_IAR
Definition vgic.hh:92
static const int GICH_EISR1
Definition vgic.hh:79
~VGic()
Definition vgic.cc:67
static const int GICH_ELSR0
Definition vgic.hh:80
Bitfield< 2 > AckCtl
Definition vgic.hh:149
static const int GICV_RPR
Definition vgic.hh:94
void processPostVIntEvent(uint32_t cpu)
Post interrupt to CPU.
Definition vgic.cc:383
#define EndBitUnion(name)
This closes off the class and union started by the above macro.
Definition bitunion.hh:428
Bitfield< 7 > i
Definition misc_types.hh:67
Bitfield< 0 > p
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
std::ostream CheckpointOut
Definition serialize.hh:66
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition types.hh:147
uint64_t Tick
Tick count type.
Definition types.hh:58
int ContextID
Globally unique thread context ID.
Definition types.hh:239
Generic interface for platforms.

Generated on Tue Jun 18 2024 16:24:03 for gem5 by doxygen 1.11.0