From patchwork Tue Jun 11 04:51:19 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 17782 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qa0-f70.google.com (mail-qa0-f70.google.com [209.85.216.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id EA49D2397B for ; Tue, 11 Jun 2013 04:52:29 +0000 (UTC) Received: by mail-qa0-f70.google.com with SMTP id cr7sf4923651qab.5 for ; Mon, 10 Jun 2013 21:52:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:x-beenthere:x-forwarded-to:x-forwarded-for :delivered-to:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references:x-gm-message-state:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-google-group-id:list-post:list-help:list-archive:list-unsubscribe; bh=KxmPkbJXYVB6oc6bJydwO4TO3T5HeudVw1s6R+X6cDE=; b=Do9FaL9EKXEdzg/SzvDZEG7jfs1NNiTltK8hjjfULbnD36/snarZ2jLZ5ADuYSqXyi sq5eXg4JRCDp2z5wfoOhOUPwXJNZmsbrPOGL44iY/v7Wuhn3D7DvYAwYLf9KeHWFLyis Bcgy0Qca3rxRlgCxvK0NDtr+BijiWGjM4uBL1FcQ1yhOkBZU65XCPnVrx3S5NDHcjo+U A6Iu3PUn7mw7vLs6+/Hywg46m6lNai4QLyrCFqube/44VwkYtpuroGs4yL2r9TROiQI5 zefffkIWhKtd5A9fzhQkQ5ljz1SK9dLzXC+bLYO0Ky4dnKdeXeDFQzMqs2uOMBKwR1/3 PA+Q== X-Received: by 10.224.205.138 with SMTP id fq10mr10141392qab.1.1370926349728; Mon, 10 Jun 2013 21:52:29 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.97.4 with SMTP id dw4ls3105355qeb.58.gmail; Mon, 10 Jun 2013 21:52:29 -0700 (PDT) X-Received: by 10.220.161.2 with SMTP id p2mr7396806vcx.72.1370926349533; Mon, 10 Jun 2013 21:52:29 -0700 (PDT) Received: from mail-vc0-f180.google.com (mail-vc0-f180.google.com [209.85.220.180]) by mx.google.com with ESMTPS id to9si6373911vdc.45.2013.06.10.21.52.29 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 10 Jun 2013 21:52:29 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.220.180 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.180; Received: by mail-vc0-f180.google.com with SMTP id gf11so2948951vcb.25 for ; Mon, 10 Jun 2013 21:52:29 -0700 (PDT) X-Received: by 10.220.246.8 with SMTP id lw8mr7352292vcb.8.1370926349397; Mon, 10 Jun 2013 21:52:29 -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.221.10.206 with SMTP id pb14csp94479vcb; Mon, 10 Jun 2013 21:52:28 -0700 (PDT) X-Received: by 10.68.219.42 with SMTP id pl10mr13089090pbc.24.1370926348332; Mon, 10 Jun 2013 21:52:28 -0700 (PDT) Received: from mail-pa0-x22d.google.com (mail-pa0-x22d.google.com [2607:f8b0:400e:c03::22d]) by mx.google.com with ESMTPS id pn6si6142565pbb.291.2013.06.10.21.52.28 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 10 Jun 2013 21:52:28 -0700 (PDT) Received-SPF: neutral (google.com: 2607:f8b0:400e:c03::22d is neither permitted nor denied by best guess record for domain of christoffer.dall@linaro.org) client-ip=2607:f8b0:400e:c03::22d; Received: by mail-pa0-f45.google.com with SMTP id bi5so5104312pad.4 for ; Mon, 10 Jun 2013 21:52:28 -0700 (PDT) X-Received: by 10.68.130.199 with SMTP id og7mr13063152pbb.132.1370926347900; Mon, 10 Jun 2013 21:52:27 -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 i16sm18268008pag.18.2013.06.10.21.52.20 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 10 Jun 2013 21:52:26 -0700 (PDT) From: Christoffer Dall To: linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu Cc: patches@linaro.org, linaro-kernel@lists.linaro.org, Christoffer Dall Subject: [PATCH 7/7] KVM: arm-vgic: Support CPU interface reg access Date: Mon, 10 Jun 2013 21:51:19 -0700 Message-Id: <1370926279-32532-8-git-send-email-christoffer.dall@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1370926279-32532-1-git-send-email-christoffer.dall@linaro.org> References: <1370926279-32532-1-git-send-email-christoffer.dall@linaro.org> X-Gm-Message-State: ALoCoQnO3GwRXZJqw3zNKjuwKSznD9oUx7CCzn+defWYblZgiY8PcV9rShU7sWdoFFnLBzlmi6O0 X-Original-Sender: christoffer.dall@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.220.180 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 | 58 ++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 55 insertions(+), 3 deletions(-) diff --git a/virt/kvm/arm/vgic.c b/virt/kvm/arm/vgic.c index 62d0fec..64bea93 100644 --- a/virt/kvm/arm/vgic.c +++ b/virt/kvm/arm/vgic.c @@ -1660,9 +1660,61 @@ 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) >> 0; + 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_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, @@ -1687,12 +1739,12 @@ static const struct mmio_range vgic_cpu_ranges[] = { { .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, }, };