gic.cc (11839:dd6df2e47c14) gic.cc (11840:16943209ed85)
1/*
1/*
2 * Copyright (c) 2015-2016 ARM Limited
2 * Copyright (c) 2015-2017 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

--- 19 unchanged lines hidden (view full) ---

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: Andreas Sandberg
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

--- 19 unchanged lines hidden (view full) ---

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: Andreas Sandberg
38 * Curtis Dunham
38 */
39
40#include "arch/arm/kvm/gic.hh"
41
42#include <linux/kvm.h>
43
39 */
40
41#include "arch/arm/kvm/gic.hh"
42
43#include <linux/kvm.h>
44
45#include "arch/arm/kvm/base_cpu.hh"
44#include "debug/Interrupt.hh"
45#include "params/KvmGic.hh"
46#include "debug/Interrupt.hh"
47#include "params/KvmGic.hh"
48#include "params/MuxingKvmGic.hh"
46
47KvmKernelGicV2::KvmKernelGicV2(KvmVM &_vm, Addr cpu_addr, Addr dist_addr,
48 unsigned it_lines)
49 : cpuRange(RangeSize(cpu_addr, KVM_VGIC_V2_CPU_SIZE)),
50 distRange(RangeSize(dist_addr, KVM_VGIC_V2_DIST_SIZE)),
51 vm(_vm),
52 kdev(vm.createDevice(KVM_DEV_TYPE_ARM_VGIC_V2))
53{

--- 124 unchanged lines hidden (view full) ---

178}
179
180
181KvmGic *
182KvmGicParams::create()
183{
184 return new KvmGic(this);
185}
49
50KvmKernelGicV2::KvmKernelGicV2(KvmVM &_vm, Addr cpu_addr, Addr dist_addr,
51 unsigned it_lines)
52 : cpuRange(RangeSize(cpu_addr, KVM_VGIC_V2_CPU_SIZE)),
53 distRange(RangeSize(dist_addr, KVM_VGIC_V2_DIST_SIZE)),
54 vm(_vm),
55 kdev(vm.createDevice(KVM_DEV_TYPE_ARM_VGIC_V2))
56{

--- 124 unchanged lines hidden (view full) ---

181}
182
183
184KvmGic *
185KvmGicParams::create()
186{
187 return new KvmGic(this);
188}
189
190
191MuxingKvmGic::MuxingKvmGic(const MuxingKvmGicParams *p)
192 : Pl390(p),
193 system(*p->system),
194 kernelGic(nullptr),
195 usingKvm(false)
196{
197 if (auto vm = system.getKvmVM()) {
198 kernelGic = new KvmKernelGicV2(*vm, p->cpu_addr, p->dist_addr,
199 p->it_lines);
200 }
201}
202
203MuxingKvmGic::~MuxingKvmGic()
204{
205}
206
207void
208MuxingKvmGic::startup()
209{
210 usingKvm = (kernelGic != nullptr) && validKvmEnvironment();
211}
212
213void
214MuxingKvmGic::drainResume()
215{
216 bool use_kvm = (kernelGic != nullptr) && validKvmEnvironment();
217 if (use_kvm != usingKvm) {
218 if (use_kvm) // from simulation to KVM emulation
219 fromPl390ToKvm();
220 else // from KVM emulation to simulation
221 fromKvmToPl390();
222
223 usingKvm = use_kvm;
224 }
225}
226
227void
228MuxingKvmGic::serialize(CheckpointOut &cp) const
229{
230 if (!usingKvm)
231 return Pl390::serialize(cp);
232
233 panic("Checkpointing unsupported\n");
234}
235
236void
237MuxingKvmGic::unserialize(CheckpointIn &cp)
238{
239 if (!usingKvm)
240 return Pl390::unserialize(cp);
241
242 panic("Checkpointing unsupported\n");
243}
244
245Tick
246MuxingKvmGic::read(PacketPtr pkt)
247{
248 if (!usingKvm)
249 return Pl390::read(pkt);
250
251 panic("MuxingKvmGic: PIO from gem5 is currently unsupported\n");
252}
253
254Tick
255MuxingKvmGic::write(PacketPtr pkt)
256{
257 if (!usingKvm)
258 return Pl390::write(pkt);
259
260 panic("MuxingKvmGic: PIO from gem5 is currently unsupported\n");
261}
262
263void
264MuxingKvmGic::sendInt(uint32_t num)
265{
266 if (!usingKvm)
267 return Pl390::sendInt(num);
268
269 DPRINTF(Interrupt, "Set SPI %d\n", num);
270 kernelGic->setSPI(num);
271}
272
273void
274MuxingKvmGic::clearInt(uint32_t num)
275{
276 if (!usingKvm)
277 return Pl390::clearInt(num);
278
279 DPRINTF(Interrupt, "Clear SPI %d\n", num);
280 kernelGic->clearSPI(num);
281}
282
283void
284MuxingKvmGic::sendPPInt(uint32_t num, uint32_t cpu)
285{
286 if (!usingKvm)
287 return Pl390::sendPPInt(num, cpu);
288 DPRINTF(Interrupt, "Set PPI %d:%d\n", cpu, num);
289 kernelGic->setPPI(cpu, num);
290}
291
292void
293MuxingKvmGic::clearPPInt(uint32_t num, uint32_t cpu)
294{
295 if (!usingKvm)
296 return Pl390::clearPPInt(num, cpu);
297
298 DPRINTF(Interrupt, "Clear PPI %d:%d\n", cpu, num);
299 kernelGic->clearPPI(cpu, num);
300}
301
302bool
303MuxingKvmGic::validKvmEnvironment() const
304{
305 if (system.threadContexts.empty())
306 return false;
307
308 for (auto tc : system.threadContexts) {
309 if (dynamic_cast<BaseArmKvmCPU*>(tc->getCpuPtr()) == nullptr) {
310 return false;
311 }
312 }
313 return true;
314}
315
316void
317MuxingKvmGic::fromPl390ToKvm()
318{
319 panic("Gic multiplexing not implemented.\n");
320}
321
322void
323MuxingKvmGic::fromKvmToPl390()
324{
325 panic("Gic multiplexing not implemented.\n");
326}
327
328MuxingKvmGic *
329MuxingKvmGicParams::create()
330{
331 return new MuxingKvmGic(this);
332}