From patchwork Thu Sep 3 15:25:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marc Zyngier X-Patchwork-Id: 11754113 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A2037109B for ; Thu, 3 Sep 2020 15:26:48 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6D05C20775 for ; Thu, 3 Sep 2020 15:26:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="wCP+0vHs"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="U0WuPxRx" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6D05C20775 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=LhhTGGQz+1gukRrYuHHeBZgg5wtVxYxOvj5gXudR180=; b=wCP+0vHs5KqgvrB+dLNyIOJO0 2aXwYEUTQ9o3A5vEjGON/l+EdYBn2yarrVpSzcGq2gFamAptgEfRzBU6QNQIaXSC7bYMYOjOfxQcB TWoasTitf6HTJkkJ93kILxO/wzAg9SQq4QzzDNvKIOvqUroFi4BUiOrxTO8Hj91XjsdQ0YUmWapN0 GlURz3fkJAv5KfyrJp12nrwh4cmiEJlQHMEnlXsU19vhTa5QF2iRdJYyVe7aMOyybXeQG1Y7nBbA3 tqwMSiqqAXUXK/V+f9HRxqLQ86rwRaQCshUMOCVYmQroZACkk8E1jcSNBtcmqkVzSKBjpNvlzeEoC eWc37P4EA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kDr8H-0004v1-At; Thu, 03 Sep 2020 15:26:37 +0000 Received: from mail.kernel.org ([198.145.29.99]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kDr85-0004r2-2T for linux-arm-kernel@lists.infradead.org; Thu, 03 Sep 2020 15:26:26 +0000 Received: from disco-boy.misterjones.org (disco-boy.misterjones.org [51.254.78.96]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 5C381208CA; Thu, 3 Sep 2020 15:26:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1599146784; bh=UgL5h2/N4AaKwcBf0Fqm/Wf8W19Iwr6g3G+3eOn1h1g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=U0WuPxRxlpht9j/tIBc1SKbf8RKtMZHQw3Az5TvPyVABskke0c/zO1wH1YgL1iJMx zMZKSzDYidYwGi8a1waBkriX5j2NFn2CwqGMlDu/4HAoFoKkTtJ8umKbOTUob3QT1D edzUoeTYFy9aR9nicWWU/dYsCeLy8wGL22vB+Fv8= Received: from 78.163-31-62.static.virginmediabusiness.co.uk ([62.31.163.78] helo=why.lan) by disco-boy.misterjones.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kDr82-008vT9-No; Thu, 03 Sep 2020 16:26:22 +0100 From: Marc Zyngier To: kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org Subject: [PATCH 03/23] irqchip: Add Reduced Virtual Interrupt Distributor support Date: Thu, 3 Sep 2020 16:25:50 +0100 Message-Id: <20200903152610.1078827-4-maz@kernel.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200903152610.1078827-1-maz@kernel.org> References: <20200903152610.1078827-1-maz@kernel.org> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 62.31.163.78 X-SA-Exim-Rcpt-To: kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, kernel-team@android.com, Christoffer.Dall@arm.com, lorenzo.pieralisi@arm.com, james.morse@arm.com, julien.thierry.kdev@gmail.com, suzuki.poulose@arm.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200903_112625_261268_E6B979BD X-CRM114-Status: GOOD ( 29.14 ) X-Spam-Score: -5.2 (-----) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-5.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -5.0 RCVD_IN_DNSWL_HI RBL: Sender listed at https://www.dnswl.org/, high trust [198.145.29.99 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.0 DKIMWL_WL_HIGH DKIMwl.org - Whitelisted High sender X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Lorenzo Pieralisi , Suzuki K Poulose , Christoffer Dall , James Morse , kernel-team@android.com, Julien Thierry Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org Signed-off-by: Marc Zyngier --- drivers/irqchip/Kconfig | 6 + drivers/irqchip/Makefile | 1 + drivers/irqchip/irq-rvid.c | 259 +++++++++++++++++++++++++++++++ include/linux/irqchip/irq-rvic.h | 19 +++ 4 files changed, 285 insertions(+) create mode 100644 drivers/irqchip/irq-rvid.c diff --git a/drivers/irqchip/Kconfig b/drivers/irqchip/Kconfig index 348ff1d06651..731e8da9ae0c 100644 --- a/drivers/irqchip/Kconfig +++ b/drivers/irqchip/Kconfig @@ -67,6 +67,12 @@ config ARM_RVIC select IRQ_DOMAIN_HIERARCHY select GENERIC_IRQ_EFFECTIVE_AFF_MASK +config ARM_RVID + bool + default ARM64 + select IRQ_DOMAIN_HIERARCHY + select GENERIC_IRQ_EFFECTIVE_AFF_MASK + config ARM_VIC bool select IRQ_DOMAIN diff --git a/drivers/irqchip/Makefile b/drivers/irqchip/Makefile index d2b280efd2e0..cbcc23f92d31 100644 --- a/drivers/irqchip/Makefile +++ b/drivers/irqchip/Makefile @@ -38,6 +38,7 @@ obj-$(CONFIG_PARTITION_PERCPU) += irq-partition-percpu.o obj-$(CONFIG_HISILICON_IRQ_MBIGEN) += irq-mbigen.o obj-$(CONFIG_ARM_NVIC) += irq-nvic.o obj-$(CONFIG_ARM_RVIC) += irq-rvic.o +obj-$(CONFIG_ARM_RVID) += irq-rvid.o obj-$(CONFIG_ARM_VIC) += irq-vic.o obj-$(CONFIG_ARMADA_370_XP_IRQ) += irq-armada-370-xp.o obj-$(CONFIG_ATMEL_AIC_IRQ) += irq-atmel-aic-common.o irq-atmel-aic.o diff --git a/drivers/irqchip/irq-rvid.c b/drivers/irqchip/irq-rvid.c new file mode 100644 index 000000000000..953f654e58d4 --- /dev/null +++ b/drivers/irqchip/irq-rvid.c @@ -0,0 +1,259 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright 2020 Google LLC. + * Author: Marc Zyngier + */ + +#define pr_fmt(fmt) "rVID: " fmt + +#include +#include +#include +#include +#include +#include + +#include + +struct rvid_data { + struct fwnode_handle *fwnode; + struct irq_domain *domain; +}; + +static struct rvid_data rvid; + +static inline int rvid_version(unsigned long *version) +{ + struct arm_smccc_res res; + + arm_smccc_1_1_invoke(SMC64_RVID_VERSION, &res); + if (res.a0 == RVID_STATUS_SUCCESS) + *version = res.a1; + return res.a0; +} + +static inline int rvid_map(unsigned long input, + unsigned long target, unsigned long intid) +{ + struct arm_smccc_res res; + + arm_smccc_1_1_invoke(SMC64_RVID_MAP, input, target, intid, &res); + return res.a0; +} + +static inline int rvid_unmap(unsigned long input) +{ + struct arm_smccc_res res; + + arm_smccc_1_1_invoke(SMC64_RVID_UNMAP, input, &res); + return res.a0; +} + +static int rvid_irq_set_affinity(struct irq_data *data, + const struct cpumask *mask_val, + bool force) +{ + unsigned int old_cpu, cpu; + bool masked, pending; + int err = 0, ret; + u64 mpidr; + + if (force) + cpu = cpumask_first(mask_val); + else + cpu = cpumask_any_and(mask_val, cpu_online_mask); + + if (cpu >= nr_cpu_ids) + return -EINVAL; + + mpidr = cpu_logical_map(cpu) & MPIDR_HWID_BITMASK; + old_cpu = cpumask_first(data->common->effective_affinity); + if (cpu == old_cpu) + return 0; + + /* Mask on source */ + masked = irqd_irq_masked(data); + if (!masked) + irq_chip_mask_parent(data); + + /* Switch to target */ + irq_data_update_effective_affinity(data, cpumask_of(cpu)); + + /* Mask on target */ + irq_chip_mask_parent(data); + + /* Map the input signal to the new target */ + ret = rvid_map(data->hwirq, mpidr, data->parent_data->hwirq); + if (ret != RVID_STATUS_SUCCESS) { + err = -ENXIO; + goto unmask; + } + + /* Back to the source */ + irq_data_update_effective_affinity(data, cpumask_of(old_cpu)); + + /* Sample pending state and clear it if necessary */ + err = irq_chip_get_parent_state(data, IRQCHIP_STATE_PENDING, &pending); + if (err) + goto unmask; + if (pending) + irq_chip_set_parent_state(data, IRQCHIP_STATE_PENDING, false); + + /* + * To the target again (for good this time), propagating the + * pending bit if required. + */ + irq_data_update_effective_affinity(data, cpumask_of(cpu)); + if (pending) + irq_chip_set_parent_state(data, IRQCHIP_STATE_PENDING, true); +unmask: + /* Propagate the masking state */ + if (!masked) + irq_chip_unmask_parent(data); + + return err; +} + +static struct irq_chip rvid_chip = { + .name = "rvid", + .irq_mask = irq_chip_mask_parent, + .irq_unmask = irq_chip_unmask_parent, + .irq_eoi = irq_chip_eoi_parent, + .irq_get_irqchip_state = irq_chip_get_parent_state, + .irq_set_irqchip_state = irq_chip_set_parent_state, + .irq_retrigger = irq_chip_retrigger_hierarchy, + .irq_set_type = irq_chip_set_type_parent, + .irq_set_affinity = rvid_irq_set_affinity, +}; + +static int rvid_irq_domain_alloc(struct irq_domain *domain, unsigned int virq, + unsigned int nr_irqs, void *arg) +{ + struct irq_fwspec *fwspec = arg; + unsigned int type = IRQ_TYPE_NONE; + irq_hw_number_t hwirq; + int i, ret; + + ret = irq_domain_translate_onecell(domain, fwspec, &hwirq, &type); + if (ret) + return ret; + + for (i = 0; i < nr_irqs; i++) { + unsigned int intid = hwirq + i; + unsigned int irq = virq + i; + + /* Get the rVIC to allocate any untrusted intid */ + ret = irq_domain_alloc_irqs_parent(domain, irq, 1, NULL); + if (WARN_ON(ret)) + return ret; + + irq_domain_set_hwirq_and_chip(domain, irq, intid, + &rvid_chip, &rvid); + irqd_set_affinity_on_activate(irq_get_irq_data(irq)); + } + + return 0; +} + +static void rvid_irq_domain_free(struct irq_domain *domain, unsigned int virq, + unsigned int nr_irqs) +{ + int i; + + irq_domain_free_irqs_parent(domain, virq, nr_irqs); + + for (i = 0; i < nr_irqs; i++) { + struct irq_data *d; + + d = irq_domain_get_irq_data(domain, virq + i); + irq_set_handler(virq + i, NULL); + irq_domain_reset_irq_data(d); + } +} + +static int rvid_irq_domain_activate(struct irq_domain *domain, + struct irq_data *data, bool reserve) +{ + unsigned long ret; + int cpu, err = 0; + u64 mpidr; + + cpu = get_cpu(); + mpidr = cpu_logical_map(cpu) & MPIDR_HWID_BITMASK; + + /* Map the input signal */ + ret = rvid_map(data->hwirq, mpidr, data->parent_data->hwirq); + if (ret != RVID_STATUS_SUCCESS) { + err = -ENXIO; + goto out; + } + + irq_data_update_effective_affinity(data, cpumask_of(cpu)); + +out: + put_cpu(); + return err; +} + +static void rvid_irq_domain_deactivate(struct irq_domain *domain, + struct irq_data *data) +{ + rvid_unmap(data->hwirq); +} + +static const struct irq_domain_ops rvid_irq_domain_ops = { + .translate = irq_domain_translate_onecell, + .alloc = rvid_irq_domain_alloc, + .free = rvid_irq_domain_free, + .activate = rvid_irq_domain_activate, + .deactivate = rvid_irq_domain_deactivate, +}; + +static int __init rvid_init(struct device_node *node, + struct device_node *parent) +{ + struct irq_domain *parent_domain; + unsigned long ret, version; + + if (arm_smccc_get_version() < ARM_SMCCC_VERSION_1_1) { + pr_err("SMCCC 1.1 required, aborting\n"); + return -EINVAL; + } + + if (!parent) + return -ENXIO; + + parent_domain = irq_find_host(parent); + if (!parent_domain) + return -ENXIO; + + rvid.fwnode = of_node_to_fwnode(node); + + ret = rvid_version(&version); + if (ret != RVID_STATUS_SUCCESS) { + pr_err("error retrieving version (%ld, %ld)\n", + RVID_STATUS_REASON(ret), RVID_STATUS_INDEX(ret)); + return -ENXIO; + } + + if (version < RVID_VERSION(0, 3)) { + pr_err("version (%ld, %ld) too old, expected min. (%d, %d)\n", + RVID_VERSION_MAJOR(version), RVID_VERSION_MINOR(version), + 0, 3); + return -ENXIO; + } + + pr_info("distributing interrupts to %pOF\n", parent); + + rvid.domain = irq_domain_create_hierarchy(parent_domain, 0, 0, + rvid.fwnode, + &rvid_irq_domain_ops, &rvid); + if (!rvid.domain) { + pr_warn("Failed to allocate irq domain\n"); + return -ENOMEM; + } + + return 0; +} + +IRQCHIP_DECLARE(rvic, "arm,rvid", rvid_init); diff --git a/include/linux/irqchip/irq-rvic.h b/include/linux/irqchip/irq-rvic.h index 0176ca7d3c30..4545c1e89741 100644 --- a/include/linux/irqchip/irq-rvic.h +++ b/include/linux/irqchip/irq-rvic.h @@ -74,4 +74,23 @@ #define RVIC_STATUS_DISABLED RVIx_STATUS_DISABLED #define RVIC_STATUS_NO_INTERRUPTS RVIx_STATUS_NO_INTERRUPTS +/* rVID functions */ +#define SMC64_RVID_BASE 0xc5000100 +#define SMC64_RVID_FN(n) (SMC64_RVID_BASE + (n)) + +#define SMC64_RVID_VERSION SMC64_RVID_FN(0) +#define SMC64_RVID_MAP SMC64_RVID_FN(1) +#define SMC64_RVID_UNMAP SMC64_RVID_FN(2) + +#define RVID_VERSION(M, m) RVIx_VERSION((M), (m)) + +#define RVID_VERSION_MAJOR(v) RVIx_VERSION_MAJOR((v)) +#define RVID_VERSION_MINOR(v) RVIx_VERSION_MINOR((v)) + +#define RVID_STATUS_REASON(c) RVIx_STATUS_REASON((c)) +#define RVID_STATUS_INDEX(c) RVIx_STATUS_INDEX((c)) + +#define RVID_STATUS_SUCCESS RVIx_STATUS_SUCCESS +#define RVID_STATUS_ERROR_PARAMETER RVIx_STATUS_ERROR_PARAMETER + #endif /* __IRQCHIP_IRQ_RVIC_H__ */