40 #include <linux/kvm.h> 43 #include "debug/GIC.hh" 44 #include "debug/Interrupt.hh" 45 #include "params/MuxingKvmGic.hh" 49 : cpuRange(
RangeSize(cpu_addr, KVM_VGIC_V2_CPU_SIZE)),
50 distRange(
RangeSize(dist_addr, KVM_VGIC_V2_DIST_SIZE)),
52 kdev(
vm.createDevice(KVM_DEV_TYPE_ARM_VGIC_V2))
59 KVM_DEV_ARM_VGIC_GRP_ADDR, KVM_VGIC_V2_ADDR_TYPE_DIST, dist_addr);
61 KVM_DEV_ARM_VGIC_GRP_ADDR, KVM_VGIC_V2_ADDR_TYPE_CPU, cpu_addr);
63 kdev.
setAttr<uint32_t>(KVM_DEV_ARM_VGIC_GRP_NR_IRQS, 0, it_lines);
91 setIntState(KVM_ARM_IRQ_TYPE_PPI, vcpu, ppi,
false);
98 assert(type <= KVM_ARM_IRQ_TYPE_MASK);
99 assert(vcpu <= KVM_ARM_IRQ_VCPU_MASK);
100 assert(irq <= KVM_ARM_IRQ_NUM_MASK);
102 (type << KVM_ARM_IRQ_TYPE_SHIFT) |
103 (vcpu << KVM_ARM_IRQ_VCPU_SHIFT) |
104 (irq << KVM_ARM_IRQ_NUM_SHIFT));
114 assert(vcpu <= KVM_ARM_IRQ_VCPU_MASK);
116 ((uint64_t)vcpu << KVM_DEV_ARM_VGIC_CPUID_SHIFT) |
117 (offset << KVM_DEV_ARM_VGIC_OFFSET_SHIFT));
120 return (uint32_t)
reg;
127 uint64_t
reg = value;
129 assert(vcpu <= KVM_ARM_IRQ_VCPU_MASK);
131 ((uint64_t)vcpu << KVM_DEV_ARM_VGIC_CPUID_SHIFT) |
132 (offset << KVM_DEV_ARM_VGIC_OFFSET_SHIFT));
141 return getGicReg(KVM_DEV_ARM_VGIC_GRP_DIST_REGS, vcpu, daddr);
148 return getGicReg(KVM_DEV_ARM_VGIC_GRP_CPU_REGS, vcpu, daddr);
155 setGicReg(KVM_DEV_ARM_VGIC_GRP_DIST_REGS, vcpu, daddr, data);
162 setGicReg(KVM_DEV_ARM_VGIC_GRP_CPU_REGS, vcpu, daddr, data);
221 panic(
"MuxingKvmGic: PIO from gem5 is currently unsupported\n");
230 panic(
"MuxingKvmGic: PIO from gem5 is currently unsupported\n");
239 DPRINTF(Interrupt,
"Set SPI %d\n", num);
249 DPRINTF(Interrupt,
"Clear SPI %d\n", num);
258 DPRINTF(Interrupt,
"Set PPI %d:%d\n", cpu, num);
268 DPRINTF(Interrupt,
"Clear PPI %d:%d\n", cpu, num);
288 DPRINTF(GIC,
"copy dist 0x%x 0x%08x\n", daddr,
val);
297 DPRINTF(GIC,
"copy cpu 0x%x 0x%08x\n", daddr,
val);
303 Addr daddr,
size_t size)
306 for (
auto a = daddr;
a < daddr + size;
a += 4)
312 Addr daddr,
size_t size)
315 for (
auto a = daddr;
a < daddr + size;
a += 4)
321 Addr daddr,
size_t size)
323 for (
auto a = daddr;
a < daddr + size;
a += 4)
329 Addr daddr,
size_t size)
331 for (
auto a = daddr;
a < daddr + size;
a += 4)
363 set += 4, clear += 4, size -= 4;
374 set += 4, clear += 4, size -= 4;
385 set += 4, clear += 4, size -= 4;
430 MuxingKvmGicParams::create()
#define panic(...)
This implements a cprintf based panic() function.
void clearInt(ContextID ctx, uint32_t int_num)
Clears a cpu IRQ or FIQ signal.
void writeDistributor(ContextID ctx, Addr daddr, uint32_t data) override
AddrRange RangeSize(Addr start, Addr size)
uint32_t getGicReg(unsigned group, unsigned vcpu, unsigned offset)
Get value of GIC register "from" a cpu.
System & system
System this interrupt controller belongs to.
void sendInt(uint32_t num) override
Post an interrupt from a device that is connected to the GIC.
void setPPI(unsigned vcpu, unsigned ppi)
Raise a private peripheral interrupt.
virtual uint32_t readCpu(ContextID ctx, Addr daddr)=0
Tick read(PacketPtr pkt) override
Pure virtual function that the device must implement.
void clearPPInt(uint32_t num, uint32_t cpu) override
virtual uint32_t readDistributor(ContextID ctx, Addr daddr)=0
void copyDistRange(BaseGicRegisters *from, BaseGicRegisters *to, Addr daddr, size_t size)
void enableKernelIRQChip()
Tell the VM and VCPUs to use an in-kernel IRQ chip for interrupt delivery.
void setAttr(uint32_t group, uint64_t attr, const T &data) const
Get the value of an attribute.
static const AddrRange GICD_ISENABLER
static const AddrRange GICD_ICENABLER
void updateIntState(int hint) override
See if some processor interrupt flags need to be enabled/disabled.
void sendPPInt(uint32_t num, uint32_t cpu) override
Interface call for private peripheral interrupts.
Tick write(PacketPtr pkt) override
A PIO read to the device, immediately split up into writeDistributor() or writeCpu() ...
void fromGicV2ToKvm()
Multiplexing implementation.
void setIntState(unsigned type, unsigned vcpu, unsigned irq, bool high)
Update the kernel's VGIC interrupt state.
virtual void updateIntState(int hint)
See if some processor interrupt flags need to be enabled/disabled.
static const AddrRange GICD_ISACTIVER
static const AddrRange GICD_IPRIORITYR
void setIRQLine(uint32_t irq, bool high)
Set the status of an IRQ line using KVM_IRQ_LINE.
DrainState
Object drain/handover states.
Tick read(PacketPtr pkt) override
A PIO read to the device, immediately split up into readDistributor() or readCpu() ...
void clearDistRange(BaseGicRegisters *to, Addr daddr, size_t size)
virtual void startup()
startup() is the final initialization call before simulation.
Tick write(PacketPtr pkt) override
Pure virtual function that the device must implement.
long contextIdToVCpuId(ContextID ctx) const
Get the VCPUID for a given context.
uint64_t Tick
Tick count type.
void copyCpuRegister(BaseGicRegisters *from, BaseGicRegisters *to, ContextID ctx, Addr daddr)
void clearBankedDistRange(BaseGicRegisters *to, Addr daddr, size_t size)
KvmVM * getKvmVM()
Get a pointer to the Kernel Virtual Machine (KVM) SimObject, if present.
unsigned numContexts() const
DrainState drain() override
Notify an object that it needs to drain its state.
uint8_t cpuPriority[CPU_MAX]
CPU priority.
void copyBankedDistRange(BaseGicRegisters *from, BaseGicRegisters *to, Addr daddr, size_t size)
DrainState drain() override
Notify an object that it needs to drain its state.
static const AddrRange GICD_ICACTIVER
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
void clearPPI(unsigned vcpu, unsigned ppi)
Clear a private peripheral interrupt.
A Packet is used to encapsulate a transfer between two objects in the memory system (e...
void sendInt(uint32_t number) override
Post an interrupt from a device that is connected to the GIC.
void getAttrPtr(uint32_t group, uint64_t attr, void *data) const
static const AddrRange GICD_ICPENDR
virtual void writeDistributor(ContextID ctx, Addr daddr, uint32_t data)=0
void copyDistRegister(BaseGicRegisters *from, BaseGicRegisters *to, ContextID ctx, Addr daddr)
void setAttrPtr(uint32_t group, uint64_t attr, const void *data) const
KvmKernelGicV2 * kernelGic
Kernel GIC device.
void startup() override
startup() is the final initialization call before simulation.
void clearPPInt(uint32_t num, uint32_t cpu) override
void writeCpu(ContextID ctx, Addr daddr, uint32_t data) override
bool validKvmEnvironment() const
Verify gem5 configuration will support KVM emulation.
KVM in-kernel GIC abstraction.
KvmVM & vm
KVM VM in the parent system.
virtual ~KvmKernelGicV2()
uint32_t itLines
Number of itLines enabled.
virtual void writeCpu(ContextID ctx, Addr daddr, uint32_t data)=0
void drainResume() override
Resume execution after a successful drain.
static const AddrRange GICD_ITARGETSR
Addr start() const
Get the start address of the range.
void copyGicState(BaseGicRegisters *from, BaseGicRegisters *to)
KvmDevice kdev
Kernel interface to the GIC.
KvmKernelGicV2(KvmVM &vm, Addr cpu_addr, Addr dist_addr, unsigned it_lines)
Instantiate a KVM in-kernel GIC model.
void drainResume() override
Resume execution after a successful drain.
static const AddrRange GICD_ICFGR
void setSPI(unsigned spi)
Raise a shared peripheral interrupt.
void setGicReg(unsigned group, unsigned vcpu, unsigned offset, unsigned value)
Set value of GIC register "from" a cpu.
static const AddrRange GICD_ISPENDR
void clearSPI(unsigned spi)
Clear a shared peripheral interrupt.
void sendPPInt(uint32_t num, uint32_t cpu) override
Interface call for private peripheral interrupts.
void clearInt(uint32_t num) override
Clear an interrupt from a device that is connected to the GIC.
MuxingKvmGic(const MuxingKvmGicParams *p)
int ContextID
Globally unique thread context ID.
uint32_t readDistributor(ContextID ctx, Addr daddr) override
BaseGicRegisters interface.
uint32_t readCpu(ContextID ctx, Addr daddr) override