From patchwork Fri Aug 23 19:20:06 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 19507 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ve0-f199.google.com (mail-ve0-f199.google.com [209.85.128.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 663A8248E6 for ; Fri, 23 Aug 2013 19:21:06 +0000 (UTC) Received: by mail-ve0-f199.google.com with SMTP id m1sf821624ves.6 for ; Fri, 23 Aug 2013 12:21:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:x-gm-message-state:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=RxgLWBFZ6oYf1owRB3TYaLCLs1VuwG9bbDcyo56bmp8=; b=GoEhw6AHstPHG8SieCSCoiTC/VJloOicL7J/aEoz/i8UPpILzjvLubf7yQNKcLDVO1 CDk+z/2QB7TlTBrjr2mkcY5PIMxBY6tYwFspcqHcJKGdvRq3mYrtXl1Vg45pTVrdaSWO iceyyf8c7P+/wIl6f4ZliswvAkvfAy1JH6QZtVUeeb1RRrxgPtXj4GBKmp0CuaCtPFL9 qfsybX5Tbpt0CzMtDKg1tIU9xvQJjWbnn0aOAR7QPTvKlb8OBw8UdW4gs7cX1ME4z9td pemJ3VFuGbWqHpZE81CDwpsTHRZbI8T+q7b19C/kGn1zWgNDXpf27Pq1QuEjt3SpGKlr dBMw== X-Received: by 10.224.13.136 with SMTP id c8mr532610qaa.0.1377285666198; Fri, 23 Aug 2013 12:21:06 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.71.83 with SMTP id s19ls1556817qeu.7.gmail; Fri, 23 Aug 2013 12:21:06 -0700 (PDT) X-Received: by 10.58.106.82 with SMTP id gs18mr801838veb.18.1377285666072; Fri, 23 Aug 2013 12:21:06 -0700 (PDT) Received: from mail-ve0-f175.google.com (mail-ve0-f175.google.com [209.85.128.175]) by mx.google.com with ESMTPS id sn2si384748vec.140.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 23 Aug 2013 12:21:06 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.128.175 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.128.175; Received: by mail-ve0-f175.google.com with SMTP id oy10so728150veb.6 for ; Fri, 23 Aug 2013 12:21:06 -0700 (PDT) X-Gm-Message-State: ALoCoQkVgceiM5r/xstjJt5a8lGWOUZjGHI8IVxLCeYWnIyWlBj4JYCbAAqk/CHYor0dVMXkpTMh X-Received: by 10.221.6.195 with SMTP id ol3mr441646vcb.34.1377285665989; Fri, 23 Aug 2013 12:21:05 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.174.196 with SMTP id u4csp111084vcz; Fri, 23 Aug 2013 12:21:05 -0700 (PDT) X-Received: by 10.68.244.168 with SMTP id xh8mr1434662pbc.3.1377285664880; Fri, 23 Aug 2013 12:21:04 -0700 (PDT) Received: from mail-pd0-f178.google.com (mail-pd0-f178.google.com [209.85.192.178]) by mx.google.com with ESMTPS id ut10si644464pbc.300.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 23 Aug 2013 12:21:04 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.192.178 is neither permitted nor denied by best guess record for domain of christoffer.dall@linaro.org) client-ip=209.85.192.178; Received: by mail-pd0-f178.google.com with SMTP id w10so1029751pde.23 for ; Fri, 23 Aug 2013 12:21:04 -0700 (PDT) X-Received: by 10.68.254.138 with SMTP id ai10mr1249919pbd.151.1377285664399; Fri, 23 Aug 2013 12:21:04 -0700 (PDT) Received: from localhost.localdomain (c-67-169-183-77.hsd1.ca.comcast.net. [67.169.183.77]) by mx.google.com with ESMTPSA id qf7sm2746078pac.14.1969.12.31.16.00.00 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 23 Aug 2013 12:21:03 -0700 (PDT) From: Christoffer Dall To: kvmarm@lists.cs.columbia.edu Cc: linaro-kernel@lists.linaro.org, patches@linaro.org, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Christoffer Dall Subject: [PATCH 8/8] KVM: arm-vgic: Support CPU interface reg access Date: Fri, 23 Aug 2013 12:20:06 -0700 Message-Id: <1377285606-15692-9-git-send-email-christoffer.dall@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1377285606-15692-1-git-send-email-christoffer.dall@linaro.org> References: <1377285606-15692-1-git-send-email-christoffer.dall@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: christoffer.dall@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.128.175 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Implement support for the CPU interface register access driven by MMIO address offsets from the CPU interface base address. Useful for user space to support save/restore of the VGIC state. This commit adds support only for the same logic as the current VGIC support, and no more. For example, the active priority registers are handled as RAZ/WI, just like setting priorities on the emulated distributor. Signed-off-by: Christoffer Dall --- virt/kvm/arm/vgic.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 62 insertions(+), 4 deletions(-) diff --git a/virt/kvm/arm/vgic.c b/virt/kvm/arm/vgic.c index d44b5a1..257dbae 100644 --- a/virt/kvm/arm/vgic.c +++ b/virt/kvm/arm/vgic.c @@ -1684,9 +1684,67 @@ int kvm_vgic_addr(struct kvm *kvm, unsigned long type, u64 *addr, bool write) static bool handle_cpu_mmio_misc(struct kvm_vcpu *vcpu, struct kvm_exit_mmio *mmio, phys_addr_t offset) { - return true; + struct vgic_cpu *vgic_cpu = &vcpu->arch.vgic_cpu; + u32 reg, mask = 0, shift = 0; + bool updated = false; + + switch (offset & ~0x3) { + case GIC_CPU_CTRL: + mask = GICH_VMCR_CTRL_MASK; + shift = GICH_VMCR_CTRL_SHIFT; + break; + case GIC_CPU_PRIMASK: + mask = GICH_VMCR_PRIMASK_MASK; + shift = GICH_VMCR_PRIMASK_SHIFT; + break; + case GIC_CPU_BINPOINT: + mask = GICH_VMCR_BINPOINT_MASK; + shift = GICH_VMCR_BINPOINT_SHIFT; + break; + case GIC_CPU_ALIAS_BINPOINT: + mask = GICH_VMCR_ALIAS_BINPOINT_MASK; + shift = GICH_VMCR_ALIAS_BINPOINT_SHIFT; + break; + } + + if (!mmio->is_write) { + reg = (vgic_cpu->vgic_vmcr & mask) >> shift; + memcpy(mmio->data, ®, sizeof(reg)); + } else { + memcpy(®, mmio->data, sizeof(reg)); + reg = (reg << shift) & mask; + if (reg != (vgic_cpu->vgic_vmcr & mask)) + updated = true; + vgic_cpu->vgic_vmcr &= ~mask; + vgic_cpu->vgic_vmcr |= reg; + } + return updated; +} + +static bool handle_mmio_abpr(struct kvm_vcpu *vcpu, + struct kvm_exit_mmio *mmio, phys_addr_t offset) +{ + return handle_cpu_mmio_misc(vcpu, mmio, GIC_CPU_ALIAS_BINPOINT); +} + +static bool handle_cpu_mmio_ident(struct kvm_vcpu *vcpu, + struct kvm_exit_mmio *mmio, + phys_addr_t offset) +{ + u32 reg; + + if (mmio->is_write) + return false; + + reg = 0x0002043B; + memcpy(mmio->data, ®, sizeof(reg)); + return false; } +/* + * CPU Interface Register accesses - these are not accessed by the VM, but by + * user space for saving and restoring VGIC state. + */ static const struct mmio_range vgic_cpu_ranges[] = { { .base = GIC_CPU_CTRL, @@ -1696,17 +1754,17 @@ static const struct mmio_range vgic_cpu_ranges[] = { { .base = GIC_CPU_ALIAS_BINPOINT, .len = 4, - .handle_mmio = handle_cpu_mmio_misc, + .handle_mmio = handle_mmio_abpr, }, { .base = GIC_CPU_ACTIVEPRIO, .len = 16, - .handle_mmio = handle_cpu_mmio_misc, + .handle_mmio = handle_mmio_raz_wi, }, { .base = GIC_CPU_IDENT, .len = 4, - .handle_mmio = handle_cpu_mmio_misc, + .handle_mmio = handle_cpu_mmio_ident, }, };