From patchwork Fri Feb 5 17:07:32 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Huang X-Patchwork-Id: 8237601 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 05FB09F3CD for ; Fri, 5 Feb 2016 17:07:57 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 2E64B20375 for ; Fri, 5 Feb 2016 17:07:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id EE59B20392 for ; Fri, 5 Feb 2016 17:07:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755629AbcBERHw (ORCPT ); Fri, 5 Feb 2016 12:07:52 -0500 Received: from mx1.redhat.com ([209.132.183.28]:39515 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755519AbcBERHn (ORCPT ); Fri, 5 Feb 2016 12:07:43 -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 318DCC815; Fri, 5 Feb 2016 17:07:43 +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 u15H7aS7017859; Fri, 5 Feb 2016 12:07:42 -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 5/7] KVM: GICv2: Add ACPI probing function Date: Fri, 5 Feb 2016 12:07:32 -0500 Message-Id: <1454692054-8984-6-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 implements ACPI probing for GICv2. Signed-off-by: Wei Huang --- virt/kvm/arm/vgic-v2.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/virt/kvm/arm/vgic-v2.c b/virt/kvm/arm/vgic-v2.c index b60e73a..7de2a1f 100644 --- a/virt/kvm/arm/vgic-v2.c +++ b/virt/kvm/arm/vgic-v2.c @@ -23,6 +23,7 @@ #include #include #include +#include #include @@ -226,6 +227,71 @@ out: return ret; } +#ifdef CONFIG_ACPI +static struct acpi_madt_generic_interrupt *vgic_acpi; +static void gic_get_acpi_header(struct acpi_subtable_header *header) +{ + vgic_acpi = (struct acpi_madt_generic_interrupt *)header; +} + +static struct acpi_madt_generic_distributor *dist_acpi; +static void gic_get_dist_header(struct acpi_subtable_header *header) +{ + dist_acpi = (struct acpi_madt_generic_distributor *)header; +} + +static int vgic_v2_acpi_probe(struct vgic_params *vgic) +{ + int irq_mode, ret = 0; + + ret = acpi_table_parse_madt(ACPI_MADT_TYPE_GENERIC_INTERRUPT, + (acpi_tbl_entry_handler)gic_get_acpi_header, 0); + if (!ret) { + ret = -ENODEV; + goto out; + } + + ret = acpi_table_parse_madt(ACPI_MADT_TYPE_GENERIC_DISTRIBUTOR, + (acpi_tbl_entry_handler)gic_get_dist_header, 0); + if (!ret) { + kvm_err("Cannot get distributor entry from ACPI\n"); + ret = -ENODEV; + goto out; + } + + if (dist_acpi->version >= ACPI_MADT_GIC_VERSION_V3) { + ret = -ENODEV; + goto out; + } + + irq_mode = (vgic_acpi->flags & ACPI_MADT_VGIC_IRQ_MODE) ? + ACPI_EDGE_SENSITIVE : ACPI_LEVEL_SENSITIVE; + /* According to GIC-400 manual, PPIs are active-LOW, level-sensative. + * We register IRQ as active-low. + */ + vgic->maint_irq = acpi_register_gsi(NULL, vgic_acpi->vgic_interrupt, + irq_mode, ACPI_ACTIVE_LOW); + if (!vgic->maint_irq) { + kvm_err("Cannot register vgic maintenance irq from ACPI\n"); + ret = -ENXIO; + goto out; + } + + vgic->vctrl_phys_base = vgic_acpi->gich_base_address; + vgic->vctrl_size = SZ_8K; + + vgic->vcpu_phys_base = vgic_acpi->gicv_base_address; + vgic->vcpu_size = 0; /* unavailable in ACPI, set to 0 */ +out: + return ret; +} +#else +static inline int vgic_v2_acpi_probe(struct vgic_params *vgic) +{ + return -ENODEV; +} +#endif /* CONFIG_ACPI */ + /** * vgic_v2_probe - probe for a GICv2 compatible interrupt controller * @ops: address of a pointer to the GICv2 operations @@ -242,6 +308,8 @@ int vgic_v2_probe(const struct vgic_ops **ops, struct vgic_params *vgic = &vgic_v2_params; ret = vgic_v2_dt_probe(vgic); + if (ret && !acpi_disabled) + ret = vgic_v2_acpi_probe(vgic); if (ret) goto err_out;