From patchwork Fri Feb 5 17:07:31 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Huang X-Patchwork-Id: 8237581 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 611009F3CD for ; Fri, 5 Feb 2016 17:07:50 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7CF1220375 for ; Fri, 5 Feb 2016 17:07:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6CF132039C for ; Fri, 5 Feb 2016 17:07:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755592AbcBERHo (ORCPT ); Fri, 5 Feb 2016 12:07:44 -0500 Received: from mx1.redhat.com ([209.132.183.28]:59571 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755548AbcBERHm (ORCPT ); Fri, 5 Feb 2016 12:07:42 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (Postfix) with ESMTPS id 27208373956; Fri, 5 Feb 2016 17:07:42 +0000 (UTC) Received: from apm-mustang-ev3-34.khw.lab.eng.bos.redhat.com (apm-mustang-ev3-34.khw.lab.eng.bos.redhat.com [10.16.184.128]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u15H7aS6017859; Fri, 5 Feb 2016 12:07:41 -0500 From: Wei Huang To: kvmarm@lists.cs.columbia.edu Cc: marc.zyngier@arm.com, christoffer.dall@linaro.org, kvm@vger.kernel.org, hanjun.guo@linaro.org, fu.wei@linaro.org, drjones@redhat.com, wei@redhat.com, al.stone@linaro.org Subject: [PATCH V1 4/7] KVM: GICv2: Extract the common code from DT Date: Fri, 5 Feb 2016 12:07:31 -0500 Message-Id: <1454692054-8984-5-git-send-email-wei@redhat.com> In-Reply-To: <1454692054-8984-1-git-send-email-wei@redhat.com> References: <1454692054-8984-1-git-send-email-wei@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-7.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch extracts the common code from the DT probe function. With this patch the DT function only fills out the following info in *vgic. - maint_irq (mapped) - GICH resource - GICV resource Note that vgic->vctrl_base io-remapping is now moved to vgic_v2_probe(). Signed-off-by: Wei Huang --- virt/kvm/arm/vgic-v2.c | 92 ++++++++++++++++++++++++-------------------------- 1 file changed, 44 insertions(+), 48 deletions(-) diff --git a/virt/kvm/arm/vgic-v2.c b/virt/kvm/arm/vgic-v2.c index 7dd5fb3..b60e73a 100644 --- a/virt/kvm/arm/vgic-v2.c +++ b/virt/kvm/arm/vgic-v2.c @@ -188,7 +188,7 @@ static const struct of_device_id vgic_v2_ids[] = { */ static int vgic_v2_dt_probe(struct vgic_params *vgic) { - int ret; + int ret = 0; struct resource vctrl_res; struct resource vcpu_res; struct device_node *vgic_node; @@ -201,24 +201,55 @@ static int vgic_v2_dt_probe(struct vgic_params *vgic) vgic->maint_irq = irq_of_parse_and_map(vgic_node, 0); if (!vgic->maint_irq) { - kvm_err("error getting vgic maintenance irq from DT\n"); + kvm_err("Cannot get vgic maintenance irq from DT\n"); ret = -ENXIO; goto out; } ret = of_address_to_resource(vgic_node, 2, &vctrl_res); if (ret) { - kvm_err("Cannot obtain GICH resource\n"); + kvm_err("Cannot obtain GICH resource from DT\n"); goto out; } vgic->vctrl_phys_base = vctrl_res.start; vgic->vctrl_size = resource_size(&vctrl_res); - vgic->vctrl_base = of_iomap(vgic_node, 2); + if (of_address_to_resource(vgic_node, 3, &vcpu_res)) { + kvm_err("Cannot obtain GICV resource\n"); + ret = -ENXIO; + goto out; + } + vgic->vcpu_phys_base = vcpu_res.start; + vgic->vcpu_size = resource_size(&vcpu_res); +out: + of_node_put(vgic_node); + return ret; +} + +/** + * vgic_v2_probe - probe for a GICv2 compatible interrupt controller + * @ops: address of a pointer to the GICv2 operations + * @params: address of a pointer to HW-specific parameters + * + * Returns 0 if a GICv2 has been found, with the low level operations + * in *ops and the HW parameters in *params. Returns an error code + * otherwise. + */ +int vgic_v2_probe(const struct vgic_ops **ops, + const struct vgic_params **params) +{ + int ret; + struct vgic_params *vgic = &vgic_v2_params; + + ret = vgic_v2_dt_probe(vgic); + if (ret) + goto err_out; + + vgic->vctrl_base = ioremap(vgic->vctrl_phys_base, vgic->vctrl_size); if (!vgic->vctrl_base) { kvm_err("Cannot ioremap GICH\n"); ret = -ENOMEM; - goto out; + goto err_out; } vgic->nr_lr = readl_relaxed(vgic->vctrl_base + GICH_VTR); @@ -229,71 +260,36 @@ static int vgic_v2_dt_probe(struct vgic_params *vgic) vgic->vctrl_phys_base); if (ret) { kvm_err("Cannot map VCTRL into hyp\n"); - goto out_unmap; - } - - if (of_address_to_resource(vgic_node, 3, &vcpu_res)) { - kvm_err("Cannot obtain GICV resource\n"); - ret = -ENXIO; - goto out_unmap; + goto err_out; } - vgic->vcpu_phys_base = vcpu_res.start; - vgic->vcpu_size = resource_size(&vcpu_res); if (!PAGE_ALIGNED(vgic->vcpu_phys_base)) { kvm_err("GICV physical address 0x%llx not page aligned\n", - (unsigned long long)vcpu_res.start); + (unsigned long long)vgic->vcpu_phys_base); ret = -ENXIO; - goto out_unmap; + goto err_out; } if (!PAGE_ALIGNED(vgic->vcpu_size)) { kvm_err("GICV size 0x%llx not a multiple of page size 0x%lx\n", (unsigned long long)vgic->vcpu_size, PAGE_SIZE); ret = -ENXIO; - goto out_unmap; + goto err_out; } - vgic->can_emulate_gicv2 = true; kvm_register_device_ops(&kvm_arm_vgic_v2_ops, KVM_DEV_TYPE_ARM_VGIC_V2); - - kvm_info("%s@%llx IRQ%d\n", vgic_node->name, - vgic->vctrl_phys_base, vgic->maint_irq); - + vgic->can_emulate_gicv2 = true; vgic->type = VGIC_V2; vgic->max_gic_vcpus = VGIC_V2_MAX_CPUS; - goto out; -out_unmap: - iounmap(vgic->vctrl_base); -out: - of_node_put(vgic_node); - return ret; -} - -/** - * vgic_v2_probe - probe for a GICv2 compatible interrupt controller - * @ops: address of a pointer to the GICv2 operations - * @params: address of a pointer to HW-specific parameters - * - * Returns 0 if a GICv2 has been found, with the low level operations - * in *ops and the HW parameters in *params. Returns an error code - * otherwise. - */ -int vgic_v2_probe(const struct vgic_ops **ops, - const struct vgic_params **params) -{ - int ret; - struct vgic_params *vgic = &vgic_v2_params; - - ret = vgic_v2_dt_probe(vgic); - if (ret) - goto err_out; + kvm_info("GICv2@%llx IRQ%d\n", vgic->vctrl_phys_base, vgic->maint_irq); *ops = &vgic_v2_ops; *params = vgic; return 0; err_out: + if (vgic->vctrl_base) + iounmap(vgic->vctrl_base); return ret; }