From patchwork Mon Mar 2 13:29:02 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 45283 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f200.google.com (mail-lb0-f200.google.com [209.85.217.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 29D622149C for ; Mon, 2 Mar 2015 13:29:22 +0000 (UTC) Received: by lbdu10 with SMTP id u10sf24129027lbd.3 for ; Mon, 02 Mar 2015 05:29:21 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-type :content-transfer-encoding:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=oOS4KYmjmpi0StmRtU6keKnUo78ikqfIGFczRdXNWhg=; b=hnC79I5CQpvDkV00DU9mee6iMwu9QVdhneUxImoAzZK7uURDo/sp4t6V5l4CdahOQF jrmcFz2TSrsp15nwq3cUfE3tTnsPw+ds455sAGQeYfVlCtdR0vPUtAcL049L16378JBU 51KxeshcqTLO2XUwrySULfSXpRFkxLO7i8sT5Ldw7xhkz6ksipO2Lb8AOABJ6RukwipZ qSQn/D64KgJR8y6Uqtf/SeCzsAfy172V3CfsQPYP2VSeGfrJOewNg6pP1AWpkEyaoW5a aCah7QG/JBWFGhi7sKFsJflKNYQgUqUz20nJNTn34IcHVYE5u4lIo6nDu0gn3iDNh5pw Isxw== X-Gm-Message-State: ALoCoQm7Qkw+hJp8wDI0WpDo7PfHJuIhWjlBR6nvdRwTMhoSh5NsOwdwYJCg0pISnJQXEa6hYC13 X-Received: by 10.152.19.100 with SMTP id d4mr3789057lae.7.1425302961109; Mon, 02 Mar 2015 05:29:21 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.170.167 with SMTP id an7ls361814lac.47.gmail; Mon, 02 Mar 2015 05:29:20 -0800 (PST) X-Received: by 10.152.10.98 with SMTP id h2mr23991660lab.18.1425302960703; Mon, 02 Mar 2015 05:29:20 -0800 (PST) Received: from mail-la0-f48.google.com (mail-la0-f48.google.com. [209.85.215.48]) by mx.google.com with ESMTPS id ll8si8762470lac.166.2015.03.02.05.29.20 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 02 Mar 2015 05:29:20 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.48 as permitted sender) client-ip=209.85.215.48; Received: by lams18 with SMTP id s18so30201312lam.13 for ; Mon, 02 Mar 2015 05:29:20 -0800 (PST) X-Received: by 10.112.130.39 with SMTP id ob7mr14781376lbb.32.1425302960569; Mon, 02 Mar 2015 05:29:20 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.35.133 with SMTP id h5csp5526579lbj; Mon, 2 Mar 2015 05:29:19 -0800 (PST) X-Received: by 10.70.24.37 with SMTP id r5mr46868370pdf.157.1425302958896; Mon, 02 Mar 2015 05:29:18 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id iw9si6563074pac.200.2015.03.02.05.29.17; Mon, 02 Mar 2015 05:29:18 -0800 (PST) Received-SPF: none (google.com: linux-kernel-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754056AbbCBN3O (ORCPT + 28 others); Mon, 2 Mar 2015 08:29:14 -0500 Received: from static.88-198-71-155.clients.your-server.de ([88.198.71.155]:38557 "EHLO socrates.bennee.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752518AbbCBN3L (ORCPT ); Mon, 2 Mar 2015 08:29:11 -0500 Received: from localhost ([127.0.0.1] helo=zen.linaroharston) by socrates.bennee.com with esmtp (Exim 4.80) (envelope-from ) id 1YSROE-0005dI-Pl; Mon, 02 Mar 2015 15:32:10 +0100 From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, christoffer.dall@linaro.org, marc.zyngier@arm.com Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Gleb Natapov , Paolo Bonzini , linux-kernel@vger.kernel.org (open list) Subject: [PATCH v2 3/5] arm: KVM: add a common vgic_queue_irq_to_lr fn Date: Mon, 2 Mar 2015 13:29:02 +0000 Message-Id: <1425302944-6276-4-git-send-email-alex.bennee@linaro.org> X-Mailer: git-send-email 2.3.0 In-Reply-To: <1425302944-6276-1-git-send-email-alex.bennee@linaro.org> References: <1425302944-6276-1-git-send-email-alex.bennee@linaro.org> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 127.0.0.1 X-SA-Exim-Mail-From: alex.bennee@linaro.org X-SA-Exim-Scanned: No (on socrates.bennee.com); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: alex.bennee@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.48 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , This helps re-factor away some of the repetitive code and makes the code flow more nicely. Signed-off-by: Alex Bennée Reviewed-by: Christoffer Dall diff --git a/virt/kvm/arm/vgic.c b/virt/kvm/arm/vgic.c index bfb6fbb..3b4ded2 100644 --- a/virt/kvm/arm/vgic.c +++ b/virt/kvm/arm/vgic.c @@ -263,6 +263,13 @@ static int vgic_irq_is_queued(struct kvm_vcpu *vcpu, int irq) return vgic_bitmap_get_irq_val(&dist->irq_queued, vcpu->vcpu_id, irq); } +static int vgic_irq_is_active(struct kvm_vcpu *vcpu, int irq) +{ + struct vgic_dist *dist = &vcpu->kvm->arch.vgic; + + return vgic_bitmap_get_irq_val(&dist->irq_active, vcpu->vcpu_id, irq); +} + static void vgic_irq_set_queued(struct kvm_vcpu *vcpu, int irq) { struct vgic_dist *dist = &vcpu->kvm->arch.vgic; @@ -285,6 +292,13 @@ static void vgic_irq_set_active(struct kvm_vcpu *vcpu, int irq) vgic_bitmap_set_irq_val(&dist->irq_active, vcpu->vcpu_id, irq, 1); } +static void vgic_irq_clear_active(struct kvm_vcpu *vcpu, int irq) +{ + struct vgic_dist *dist = &vcpu->kvm->arch.vgic; + + vgic_bitmap_set_irq_val(&dist->irq_active, vcpu->vcpu_id, irq, 0); +} + static int vgic_dist_irq_get_level(struct kvm_vcpu *vcpu, int irq) { struct vgic_dist *dist = &vcpu->kvm->arch.vgic; @@ -1032,6 +1046,25 @@ static void vgic_retire_disabled_irqs(struct kvm_vcpu *vcpu) } } +static void vgic_queue_irq_to_lr(struct kvm_vcpu *vcpu, int irq, + int lr_nr, struct vgic_lr vlr) +{ + if (vgic_irq_is_active(vcpu, irq)) { + vlr.state |= LR_STATE_ACTIVE; + kvm_debug("Set active, clear distributor: 0x%x\n", vlr.state); + vgic_irq_clear_active(vcpu, irq); + vgic_update_state(vcpu->kvm); + } else if (vgic_dist_irq_is_pending(vcpu, irq)) { + vlr.state |= LR_STATE_PENDING; + kvm_debug("Set pending: 0x%x\n", vlr.state); + } + + if (!vgic_irq_is_edge(vcpu, irq)) + vlr.state |= LR_EOI_INT; + + vgic_set_lr(vcpu, lr_nr, vlr); +} + /* * Queue an interrupt to a CPU virtual interface. Return true on success, * or false if it wasn't possible to queue it. @@ -1059,8 +1092,7 @@ bool vgic_queue_irq(struct kvm_vcpu *vcpu, u8 sgi_source_id, int irq) if (vlr.source == sgi_source_id) { kvm_debug("LR%d piggyback for IRQ%d\n", lr, vlr.irq); BUG_ON(!test_bit(lr, vgic_cpu->lr_used)); - vlr.state |= LR_STATE_PENDING; - vgic_set_lr(vcpu, lr, vlr); + vgic_queue_irq_to_lr(vcpu, irq, lr, vlr); return true; } } @@ -1077,11 +1109,8 @@ bool vgic_queue_irq(struct kvm_vcpu *vcpu, u8 sgi_source_id, int irq) vlr.irq = irq; vlr.source = sgi_source_id; - vlr.state = LR_STATE_PENDING; - if (!vgic_irq_is_edge(vcpu, irq)) - vlr.state |= LR_EOI_INT; - - vgic_set_lr(vcpu, lr, vlr); + vlr.state = 0; + vgic_queue_irq_to_lr(vcpu, irq, lr, vlr); return true; }