gic.cc revision 11462
12SN/A/* 21762SN/A * Copyright (c) 2015-2016 ARM Limited 32SN/A * All rights reserved 42SN/A * 52SN/A * The license below extends only to copyright in the software and shall 62SN/A * not be construed as granting a license to any other intellectual 72SN/A * property including but not limited to intellectual property relating 82SN/A * to a hardware implementation of the functionality of the software 92SN/A * licensed hereunder. You may use the software subject to the license 102SN/A * terms below provided that you ensure that this notice is replicated 112SN/A * unmodified and in its entirety in all distributions of the software, 122SN/A * modified or unmodified, in source code or in binary form. 132SN/A * 142SN/A * Redistribution and use in source and binary forms, with or without 152SN/A * modification, are permitted provided that the following conditions are 162SN/A * met: redistributions of source code must retain the above copyright 172SN/A * notice, this list of conditions and the following disclaimer; 182SN/A * redistributions in binary form must reproduce the above copyright 192SN/A * notice, this list of conditions and the following disclaimer in the 202SN/A * documentation and/or other materials provided with the distribution; 212SN/A * neither the name of the copyright holders nor the names of its 222SN/A * contributors may be used to endorse or promote products derived from 232SN/A * this software without specific prior written permission. 242SN/A * 252SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 262SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 272665Ssaidi@eecs.umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 282665Ssaidi@eecs.umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 292SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 302SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 3111793Sbrandon.potter@amd.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 3211793Sbrandon.potter@amd.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 332SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 342SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 352SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 362SN/A * 372SN/A * Authors: Andreas Sandberg 381380SN/A */ 391380SN/A 401380SN/A#include "arch/arm/kvm/gic.hh" 411380SN/A 421380SN/A#include <linux/kvm.h> 431380SN/A 441380SN/A#include "debug/Interrupt.hh" 451380SN/A#include "params/KvmGic.hh" 461380SN/A 471380SN/AKvmKernelGicV2::KvmKernelGicV2(KvmVM &_vm, Addr cpu_addr, Addr dist_addr, 481380SN/A unsigned it_lines) 491380SN/A : cpuRange(RangeSize(cpu_addr, KVM_VGIC_V2_CPU_SIZE)), 501380SN/A distRange(RangeSize(dist_addr, KVM_VGIC_V2_DIST_SIZE)), 511380SN/A vm(_vm), 521380SN/A kdev(vm.createDevice(KVM_DEV_TYPE_ARM_VGIC_V2)) 531380SN/A{ 541380SN/A kdev.setAttr<uint64_t>( 551380SN/A KVM_DEV_ARM_VGIC_GRP_ADDR, KVM_VGIC_V2_ADDR_TYPE_DIST, dist_addr); 561380SN/A kdev.setAttr<uint64_t>( 571380SN/A KVM_DEV_ARM_VGIC_GRP_ADDR, KVM_VGIC_V2_ADDR_TYPE_CPU, cpu_addr); 581380SN/A 591380SN/A kdev.setAttr<uint32_t>(KVM_DEV_ARM_VGIC_GRP_NR_IRQS, 0, it_lines); 601380SN/A} 611380SN/A 621380SN/AKvmKernelGicV2::~KvmKernelGicV2() 631380SN/A{ 641380SN/A} 651380SN/A 661380SN/Avoid 671380SN/AKvmKernelGicV2::setSPI(unsigned spi) 682SN/A{ 692SN/A setIntState(KVM_ARM_IRQ_TYPE_SPI, 0, spi, true); 702SN/A} 712SN/A 722SN/Avoid 732SN/AKvmKernelGicV2::clearSPI(unsigned spi) 741793SN/A{ 751793SN/A setIntState(KVM_ARM_IRQ_TYPE_SPI, 0, spi, false); 762SN/A} 771793SN/A 781793SN/Avoid 791793SN/AKvmKernelGicV2::setPPI(unsigned vcpu, unsigned ppi) 801793SN/A{ 811793SN/A setIntState(KVM_ARM_IRQ_TYPE_PPI, vcpu, ppi, true); 821793SN/A} 831793SN/A 841793SN/Avoid 852SN/AKvmKernelGicV2::clearPPI(unsigned vcpu, unsigned ppi) 862SN/A{ 872SN/A setIntState(KVM_ARM_IRQ_TYPE_PPI, vcpu, ppi, false); 882SN/A} 892SN/A 902SN/Avoid 912SN/AKvmKernelGicV2::setIntState(unsigned type, unsigned vcpu, unsigned irq, 922SN/A bool high) 932SN/A{ 942SN/A assert(type <= KVM_ARM_IRQ_TYPE_MASK); 952SN/A assert(vcpu <= KVM_ARM_IRQ_VCPU_MASK); 962SN/A assert(irq <= KVM_ARM_IRQ_NUM_MASK); 972SN/A const uint32_t line( 982SN/A (type << KVM_ARM_IRQ_TYPE_SHIFT) | 992SN/A (vcpu << KVM_ARM_IRQ_VCPU_SHIFT) | 1002SN/A (irq << KVM_ARM_IRQ_NUM_SHIFT)); 1012SN/A 1022SN/A vm.setIRQLine(line, high); 1032SN/A} 104 105 106KvmGic::KvmGic(const KvmGicParams *p) 107 : BaseGic(p), 108 system(*p->system), 109 kernelGic(*p->kvmVM, p->cpu_addr, p->dist_addr, p->it_lines), 110 addrRanges{kernelGic.distRange, kernelGic.cpuRange} 111{ 112} 113 114KvmGic::~KvmGic() 115{ 116} 117 118void 119KvmGic::serialize(CheckpointOut &cp) const 120{ 121 panic("Checkpointing unsupported\n"); 122} 123 124void 125KvmGic::unserialize(CheckpointIn &cp) 126{ 127 panic("Checkpointing unsupported\n"); 128} 129 130Tick 131KvmGic::read(PacketPtr pkt) 132{ 133 panic("KvmGic: PIO from gem5 is currently unsupported\n"); 134} 135 136Tick 137KvmGic::write(PacketPtr pkt) 138{ 139 panic("KvmGic: PIO from gem5 is currently unsupported\n"); 140} 141 142void 143KvmGic::sendInt(uint32_t num) 144{ 145 DPRINTF(Interrupt, "Set SPI %d\n", num); 146 kernelGic.setSPI(num); 147} 148 149void 150KvmGic::clearInt(uint32_t num) 151{ 152 DPRINTF(Interrupt, "Clear SPI %d\n", num); 153 kernelGic.clearSPI(num); 154} 155 156void 157KvmGic::sendPPInt(uint32_t num, uint32_t cpu) 158{ 159 DPRINTF(Interrupt, "Set PPI %d:%d\n", cpu, num); 160 kernelGic.setPPI(cpu, num); 161} 162 163void 164KvmGic::clearPPInt(uint32_t num, uint32_t cpu) 165{ 166 DPRINTF(Interrupt, "Clear PPI %d:%d\n", cpu, num); 167 kernelGic.clearPPI(cpu, num); 168} 169 170void 171KvmGic::verifyMemoryMode() const 172{ 173 if (!(system.isAtomicMode() && system.bypassCaches())) { 174 fatal("The in-kernel KVM GIC can only be used with KVM CPUs, but the " 175 "current memory mode does not support KVM.\n"); 176 } 177} 178 179 180KvmGic * 181KvmGicParams::create() 182{ 183 return new KvmGic(this); 184} 185