gem5 [DEVELOP-FOR-25.1]
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
49
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
61namespace gem5
62{
63
64class BaseGic;
65
66struct VGicParams;
67
68class VGic : public PioDevice
69{
70 private:
71 static const int VGIC_CPU_MAX = 256;
72 static const int NUM_LR = 4;
73
74 static const int GICH_SIZE = 0x200;
75 static const int GICH_REG_SIZE = 0x2000;
76
77 static const int GICH_HCR = 0x000;
78 static const int GICH_VTR = 0x004;
79 static const int GICH_VMCR = 0x008;
80 static const int GICH_MISR = 0x010;
81 static const int GICH_EISR0 = 0x020;
82 static const int GICH_EISR1 = 0x024;
83 static const int GICH_ELSR0 = 0x030;
84 static const int GICH_ELSR1 = 0x034;
85 static const int GICH_APR0 = 0x0f0;
86 static const int GICH_LR0 = 0x100;
87 static const int GICH_LR1 = 0x104;
88 static const int GICH_LR2 = 0x108;
89 static const int GICH_LR3 = 0x10c;
90
91 static const int GICV_SIZE = 0x2000;
92 static const int GICV_CTLR = 0x000;
93 static const int GICV_PMR = 0x004;
94 static const int GICV_BPR = 0x008;
95 static const int GICV_IAR = 0x00c;
96 static const int GICV_EOIR = 0x010;
97 static const int GICV_RPR = 0x014;
98 static const int GICV_HPPIR = 0x018;
99 static const int GICV_ABPR = 0x01c;
100 static const int GICV_AIAR = 0x020;
101 static const int GICV_AEOIR = 0x024;
102 static const int GICV_AHPPIR = 0x028;
103 static const int GICV_APR0 = 0x0d0;
104 static const int GICV_IIDR = 0x0fc;
105 static const int GICV_DIR = 0x1000;
106
107 static const uint32_t LR_PENDING = 1;
108 static const uint32_t LR_ACTIVE = 2;
109 const uint32_t gicvIIDR;
110
112 void processPostVIntEvent(uint32_t cpu);
113
117
120
125
126 BitUnion32(ListReg)
127 Bitfield<31> HW;
128 Bitfield<30> Grp1;
129 Bitfield<29,28> State;
130 Bitfield<27,23> Priority;
131 Bitfield<19> EOI;
132 Bitfield<12,10> CpuID;
133 Bitfield<9,0> VirtualID;
134 EndBitUnion(ListReg)
135
136 BitUnion32(HCR)
137 Bitfield<31,27> EOICount;
138 Bitfield<7> VGrp1DIE;
139 Bitfield<6> VGrp1EIE;
140 Bitfield<5> VGrp0DIE;
141 Bitfield<4> VGrp0EIE;
142 Bitfield<3> NPIE;
143 Bitfield<2> LRENPIE;
144 Bitfield<1> UIE;
145 Bitfield<0> En;
147
148 BitUnion32(VCTLR)
149 Bitfield<9> EOImode;
150 Bitfield<4> CPBR;
151 Bitfield<3> FIQEn;
152 Bitfield<2> AckCtl;
153 Bitfield<1> EnGrp1;
154 Bitfield<0> En; // This gets written to enable, not group 1.
155 EndBitUnion(VCTLR)
156
157 /* State per CPU. EVERYTHING should be in this struct and simply replicated
158 * N times.
159 */
160 struct vcpuIntData : public Serializable
161 {
162 vcpuIntData()
163 : vctrl(0), hcr(0), eisr(0), VMGrp0En(0), VMGrp1En(0),
164 VMAckCtl(0), VMFiqEn(0), VMCBPR(0), VEM(0), VMABP(0), VMBP(0),
165 VMPriMask(0)
166 {
167 std::fill(LR.begin(), LR.end(), 0);
168 }
169 virtual ~vcpuIntData() {}
170
171 std::array<ListReg, NUM_LR> LR;
172 VCTLR vctrl;
173
174 HCR hcr;
175 uint64_t eisr;
176
177 /* Host info, guest info (should be 100% accessible via GICH_* regs!) */
178 uint8_t VMGrp0En;
179 uint8_t VMGrp1En;
180 uint8_t VMAckCtl;
181 uint8_t VMFiqEn;
182 uint8_t VMCBPR;
183 uint8_t VEM;
184 uint8_t VMABP;
185 uint8_t VMBP;
186 uint8_t VMPriMask;
187
188 void serialize(CheckpointOut &cp) const override;
189 void unserialize(CheckpointIn &cp) override;
190 };
191
192 struct std::array<vcpuIntData, VGIC_CPU_MAX> vcpuData;
193
194 public:
195 using Params = VGicParams;
196 VGic(const Params &p);
197 ~VGic();
198
199 AddrRangeList getAddrRanges() const override;
200
201 Tick read(PacketPtr pkt) override;
202 Tick write(PacketPtr pkt) override;
203
204 void serialize(CheckpointOut &cp) const override;
205 void unserialize(CheckpointIn &cp) override;
206
207 private:
210
213
214 void updateIntState(ContextID ctx_id);
215 uint32_t getMISR(struct vcpuIntData *vid);
216 void postVInt(uint32_t cpu, Tick when);
217 void unPostVInt(uint32_t cpu);
218 void postMaintInt(uint32_t cpu);
219 void unPostMaintInt(uint32_t cpu);
220
221 unsigned int lrPending(struct vcpuIntData *vid)
222 {
223 unsigned int pend = 0;
224 for (int i = 0; i < NUM_LR; i++) {
225 if (vid->LR[i].State & LR_PENDING)
226 pend++;
227 }
228 return pend;
229 }
230 unsigned int lrValid(struct vcpuIntData *vid)
231 {
232 unsigned int valid = 0;
233 for (int i = 0; i < NUM_LR; i++) {
234 if (vid->LR[i].State)
235 valid++;
236 }
237 return valid;
238 }
239
241 int findHighestPendingLR(struct vcpuIntData *vid)
242 {
243 unsigned int prio = 0xff;
244 int p = -1;
245 for (int i = 0; i < NUM_LR; i++) {
246 if ((vid->LR[i].State & LR_PENDING) && (vid->LR[i].Priority < prio)) {
247 p = i;
248 prio = vid->LR[i].Priority;
249 }
250 }
251 return p;
252 }
253
254 int findLRForVIRQ(struct vcpuIntData *vid, int virq, int vcpu)
255 {
256 for (int i = 0; i < NUM_LR; i++) {
257 if (vid->LR[i].State &&
258 vid->LR[i].VirtualID == virq &&
259 vid->LR[i].CpuID == vcpu)
260 return i;
261 }
262 return -1;
263 }
264};
265
266} // namespace gem5
267
268#endif
#define BitUnion32(name)
Definition bitunion.hh:495
PioDevice(const Params &p)
Definition io_device.cc:50
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:75
static const int NUM_LR
Definition vgic.hh:72
Bitfield< 30 > Grp1
Definition vgic.hh:128
static const int GICV_APR0
Definition vgic.hh:103
Bitfield< 5 > VGrp0DIE
Definition vgic.hh:140
static const int GICV_BPR
Definition vgic.hh:94
AddrRangeList getAddrRanges() const override
Every PIO device is obliged to provide an implementation that returns the address ranges the device r...
Definition vgic.cc:455
Bitfield< 9, 0 > VirtualID
Definition vgic.hh:133
Tick writeCtrl(PacketPtr pkt)
Definition vgic.cc:291
static const int GICH_LR2
Definition vgic.hh:88
static const int GICV_CTLR
Definition vgic.hh:92
static const uint32_t LR_PENDING
Definition vgic.hh:107
VGic(const Params &p)
Definition vgic.cc:53
Tick pioDelay
Definition vgic.hh:123
Bitfield< 2 > LRENPIE
Definition vgic.hh:143
static const int GICH_HCR
Definition vgic.hh:77
static const int GICH_MISR
Definition vgic.hh:80
static const int GICH_ELSR1
Definition vgic.hh:84
static const int GICV_AEOIR
Definition vgic.hh:101
Tick readVCpu(PacketPtr pkt)
Definition vgic.cc:101
void postVInt(uint32_t cpu, Tick when)
Definition vgic.cc:368
void unPostMaintInt(uint32_t cpu)
Definition vgic.cc:400
EventFunctionWrapper * postVIntEvent[VGIC_CPU_MAX]
Definition vgic.hh:114
BaseGic * gic
Definition vgic.hh:119
Addr vcpuAddr
Definition vgic.hh:121
Bitfield< 4 > CPBR
Definition vgic.hh:150
static const int GICH_VMCR
Definition vgic.hh:79
Tick readCtrl(PacketPtr pkt)
Definition vgic.cc:148
uint32_t getMISR(struct vcpuIntData *vid)
Definition vgic.cc:355
BitUnion32(ListReg) Bitfield< 31 > HW
int findLRForVIRQ(struct vcpuIntData *vid, int virq, int vcpu)
Definition vgic.hh:254
Addr hvAddr
Definition vgic.hh:122
Bitfield< 19 > EOI
Definition vgic.hh:131
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition vgic.cc:464
Platform * platform
Definition vgic.hh:118
static const int GICV_HPPIR
Definition vgic.hh:98
static const int GICH_EISR0
Definition vgic.hh:81
unsigned int lrPending(struct vcpuIntData *vid)
Definition vgic.hh:221
static const int GICH_REG_SIZE
Definition vgic.hh:75
Bitfield< 12, 10 > CpuID
Definition vgic.hh:132
unsigned int lrValid(struct vcpuIntData *vid)
Definition vgic.hh:230
static const int GICV_DIR
Definition vgic.hh:105
Tick write(PacketPtr pkt) override
Pure virtual function that the device must implement.
Definition vgic.cc:88
const uint32_t gicvIIDR
Definition vgic.hh:109
static const int GICV_ABPR
Definition vgic.hh:99
static const int GICV_AIAR
Definition vgic.hh:100
Bitfield< 4 > VGrp0EIE
Definition vgic.hh:141
Bitfield< 1 > EnGrp1
Definition vgic.hh:153
int findHighestPendingLR(struct vcpuIntData *vid)
Returns LR index or -1 if none pending.
Definition vgic.hh:241
static const uint32_t LR_ACTIVE
Definition vgic.hh:108
Bitfield< 7 > VGrp1DIE
Definition vgic.hh:138
static const int GICH_SIZE
Definition vgic.hh:74
static const int GICH_LR1
Definition vgic.hh:87
VGicParams Params
Definition vgic.hh:195
static const int GICV_EOIR
Definition vgic.hh:96
static const int GICH_APR0
Definition vgic.hh:85
static const int GICH_LR0
Definition vgic.hh:86
static const int GICV_PMR
Definition vgic.hh:93
int maintInt
Definition vgic.hh:124
bool maintIntPosted[VGIC_CPU_MAX]
Definition vgic.hh:115
bool vIntPosted[VGIC_CPU_MAX]
Definition vgic.hh:116
Bitfield< 29, 28 > State
Definition vgic.hh:129
static const int GICV_AHPPIR
Definition vgic.hh:102
void unPostVInt(uint32_t cpu)
Definition vgic.cc:376
Tick writeVCpu(PacketPtr pkt)
Definition vgic.cc:242
Bitfield< 6 > VGrp1EIE
Definition vgic.hh:139
Bitfield< 3 > FIQEn
Definition vgic.hh:151
EndBitUnion(VCTLR) struct vcpuIntData struct std::array< vcpuIntData, VGIC_CPU_MAX > vcpuData
Definition vgic.hh:192
Bitfield< 0 > En
Definition vgic.hh:145
static const int GICH_LR3
Definition vgic.hh:89
void updateIntState(ContextID ctx_id)
Definition vgic.cc:410
Bitfield< 3 > NPIE
Definition vgic.hh:142
static const int GICV_SIZE
Definition vgic.hh:91
static const int VGIC_CPU_MAX
Definition vgic.hh:71
Bitfield< 1 > UIE
Definition vgic.hh:144
void postMaintInt(uint32_t cpu)
Definition vgic.cc:392
Bitfield< 27, 23 > Priority
Definition vgic.hh:130
EndBitUnion(ListReg) BitUnion32(HCR) Bitfield< 31
static const int GICH_VTR
Definition vgic.hh:78
static const int GICV_IIDR
Definition vgic.hh:104
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition vgic.cc:522
static const int GICV_IAR
Definition vgic.hh:95
static const int GICH_EISR1
Definition vgic.hh:82
~VGic()
Definition vgic.cc:68
static const int GICH_ELSR0
Definition vgic.hh:83
Bitfield< 2 > AckCtl
Definition vgic.hh:152
static const int GICV_RPR
Definition vgic.hh:97
void processPostVIntEvent(uint32_t cpu)
Post interrupt to CPU.
Definition vgic.cc:384
std::list< AddrRange > AddrRangeList
Convenience typedef for a collection of address ranges.
Definition addr_range.hh:64
Bitfield< 7 > i
Definition misc_types.hh:67
Bitfield< 0 > p
Copyright (c) 2024 Arm Limited 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
Packet * PacketPtr
int ContextID
Globally unique thread context ID.
Definition types.hh:239
Generic interface for platforms.

Generated on Mon Oct 27 2025 04:13:01 for gem5 by doxygen 1.14.0