Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp4012055rdh; Fri, 29 Sep 2023 08:42:14 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEpQRMjIJCC6er4LSjkywIdcRHUIDs3i9qLAbejXwCWbpeKst/M+gNFI7+dBUNRdgyPx/N2 X-Received: by 2002:a05:6a20:938b:b0:161:b5f9:e78d with SMTP id x11-20020a056a20938b00b00161b5f9e78dmr6578863pzh.23.1696002134172; Fri, 29 Sep 2023 08:42:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696002134; cv=none; d=google.com; s=arc-20160816; b=PmQX2+6hzrU2WXIWu5vWV5RpOXiTwNPl8M16yCWsDTOkCxs0puSYAojfVCIR46Mnpm awUFIkrPLbWUCpg3huaVznxjSRsN+CEj3s7VuZO+mfzOR1PxwZ2aqci6HMCYhAHfgEsr c3Ot4okQn5Gv/Hv/S7qMGw2toR/hlq+Nj14kPmQDwUF0fZSUx0zxQv4jbD0KXOlookFk yqR+8KAdxnPrGbMjZCGYQSy+5PSC5UitwG+pfVAHhS0lTlvkTXMim3rc8F+LFLoBKx9U 9Fluye92bULIUP7HO+vTOmVbnN6CPsZwqYhv3z1oCD3Hpl+tn7pNTOheYD5XHg+g+r+H UELg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from; bh=LOnIzxy8EdGLjjBTEWpr2mIfpHs6+3d+IhYaSe/+QMY=; fh=iZJRvoZuVJp3Jcg3UWu0imuTLbH0nKChof8pDyzNHj4=; b=qHAqrj1IlImKs8rBbrtgsKsuiF2a+58ZLMW7dCm9/8S+lP2TPWpd/lrxiShcRfW8kx CRlpHSsaxW5fJ6u1BY0ehPRflQ54kK5wHiqr++oGtmRpW2mT5MMzgQmu0Wnd2nmYLLfB tahHY4Y0k34emvFVLvdnNXYK7zuf28zWu9sG6qyD3I2cL+ena8RN3Xm6VoCKVqUeeYHA wgMvJgJWDvI1hONZV6oSn+C2vBI52Q4uR3DIf3MIpdCiEsnLl5siqbzHo72/63unpqKg DmYfM+lyFk/yklHKMZg1607x/Lr2cjzTF1LNvDH+K2qSys+BRknWHy2AECiAA7JflR0a 3bFA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id y72-20020a638a4b000000b00563f8e3fca8si21102884pgd.49.2023.09.29.08.42.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Sep 2023 08:42:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id DC4E3829FDED; Fri, 29 Sep 2023 08:04:04 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233539AbjI2PDo (ORCPT + 99 others); Fri, 29 Sep 2023 11:03:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44906 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233367AbjI2PD0 (ORCPT ); Fri, 29 Sep 2023 11:03:26 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 6D19FCC7 for ; Fri, 29 Sep 2023 08:03:24 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 948B91007; Fri, 29 Sep 2023 08:04:02 -0700 (PDT) Received: from e103737-lin.cambridge.arm.com (e103737-lin.cambridge.arm.com [10.1.197.49]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 3DA393F5A1; Fri, 29 Sep 2023 08:03:23 -0700 (PDT) From: Sudeep Holla Date: Fri, 29 Sep 2023 16:02:57 +0100 Subject: [PATCH v3 08/17] firmware: arm_ffa: Initial support for scheduler receiver interrupt MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Message-Id: <20230929-ffa_v1-1_notif-v3-8-c8e4f15190c8@arm.com> References: <20230929-ffa_v1-1_notif-v3-0-c8e4f15190c8@arm.com> In-Reply-To: <20230929-ffa_v1-1_notif-v3-0-c8e4f15190c8@arm.com> To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Sudeep Holla , Marc Bonnici , Jens Wiklander , Coboy Chen , Lorenzo Pieralisi , Olivier Deprez X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=7567; i=sudeep.holla@arm.com; h=from:subject:message-id; bh=cEqV4YVf1LWm1xYaB7cZIwUpKEDLEWd8Uc3+Kj3BYQI=; b=owEBbAKT/ZANAwAIAQBBurwxfuKYAcsmYgBlFucvCcxjPXx8TBj4nbCzrmy1KuOnDdP4lGixl 6UZ6ZzDsruJAjIEAAEIAB0WIQS6ceUSBvMeskPdk+EAQbq8MX7imAUCZRbnLwAKCRAAQbq8MX7i mJWaD/ifHyJbruDUC9theNrtvo0jGb1ru5UA3xiOU0FdjmfkTlfhzrKsEIf3vD/VNiWrVIrLpeh iQD7oj49Afj2+HakhGwbMo1ML25XWx8ZA2TFScS1VISOorUwxXS0+s8Ve8krpWjQRaztztHRiQP JDjtuBIa5u9fw04zDIsPPyJE4WpAPaAv+8vjG5dzjO6caEmnJ+HJNsn2aKFeuJ4csOXa5yATwGk 8gvOk7wbJ9/PIKlU1/+UcXPWpyA3ZpBpVbaMho7X7D/142ZKGvp2L8F3YWo2Z1okmafVUbrwyNq a6hgu8//Ux/MjxiQZVHww2tpc44zqr+TeWZwCa8NVGO7bA8U6XLx9eyaZ16PigxKMXnFnCeyBzc EK451CBMexA+OmxNNLSgDsHgSzxROs0SuSo75sPoEIjg2KZ1yS9eGNVOkLBbdGUhQQHvR8FeOhf sw6NaJdPLAPqjv6dcfuM/bm155YP9GbJsl97CkXjHZuHcVGTTCkTL2pYVMsxIimUd5gWKnXOEhe BP4gcnAlQSLEe6aKPsAGEtiphMBcfQo0EO8wquHZqE45eOF7QZjVYTsZmQp4XhSYsvYfQ2zwktP syZVXcfXmPIeVpY7tsvAj62CY+Nho0TP0PJCEK0S+atI+XGQWbUTBeoBJPFJxvAqTLNOACitipc DA8CCM3Y9PMV4 X-Developer-Key: i=sudeep.holla@arm.com; a=openpgp; fpr=7360A21742ADF5A11767C1C139CFD4755FE2D5B4 X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Fri, 29 Sep 2023 08:04:05 -0700 (PDT) The Framework uses the schedule receiver interrupt to inform the receiver’s scheduler that the receiver must be run to handle a pending notification. A receiver’s scheduler can obtain the description of the schedule receiver interrupt by invoking the FFA_FEATURES interface. The delivery of the physical schedule receiver interrupt from the secure state to the non-secure state depends upon the state of the interrupt controller as configured by the hypervisor. The schedule seceiver interrupt is assumed to be a SGI. The Arm GIC specification defines 16 SGIs. It recommends that they are equally divided between the non-secure and secure states. OS like Linux kernel in the non-secure state typically do not have SGIs to spare. The usage of SGIs in the secure state is however limited. It is more likely that software in the Secure world does not use all the SGIs allocated to it. It is recommended that the secure world software donates an unused SGI to the normal world for use as the schedule receiver interrupt. This implies that secure world software must configure the SGI in the GIC as a non-secure interrupt before presenting it to the normal world. Signed-off-by: Sudeep Holla --- drivers/firmware/arm_ffa/driver.c | 192 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 182 insertions(+), 10 deletions(-) diff --git a/drivers/firmware/arm_ffa/driver.c b/drivers/firmware/arm_ffa/driver.c index dfeeb751bebe..a0c80eff04c4 100644 --- a/drivers/firmware/arm_ffa/driver.c +++ b/drivers/firmware/arm_ffa/driver.c @@ -22,15 +22,20 @@ #define DRIVER_NAME "ARM FF-A" #define pr_fmt(fmt) DRIVER_NAME ": " fmt +#include #include #include +#include #include +#include #include #include #include #include +#include #include #include +#include #include #include "common.h" @@ -76,6 +81,10 @@ static inline int ffa_to_linux_errno(int errno) return -EINVAL; } +struct ffa_pcpu_irq { + struct ffa_drv_info *info; +}; + struct ffa_drv_info { u32 version; u16 vm_id; @@ -85,6 +94,12 @@ struct ffa_drv_info { void *tx_buffer; bool mem_ops_native; bool bitmap_created; + unsigned int sched_recv_irq; + unsigned int cpuhp_state; + struct ffa_pcpu_irq __percpu *irq_pcpu; + struct workqueue_struct *notif_pcpu_wq; + struct work_struct irq_work; + bool info_get_64b; }; static struct ffa_drv_info *drv_info; @@ -922,9 +937,153 @@ static void ffa_setup_partitions(void) kfree(pbuf); } +/* FFA FEATURE IDs */ +#define FFA_FEAT_NOTIFICATION_PENDING_INT (1) +#define FFA_FEAT_SCHEDULE_RECEIVER_INT (2) +#define FFA_FEAT_MANAGED_EXIT_INT (3) + +static irqreturn_t irq_handler(int irq, void *irq_data) +{ + struct ffa_pcpu_irq *pcpu = irq_data; + struct ffa_drv_info *info = pcpu->info; + + queue_work(info->notif_pcpu_wq, &info->irq_work); + + return IRQ_HANDLED; +} + +static void ffa_sched_recv_irq_work_fn(struct work_struct *work) +{ + struct ffa_drv_info *info = container_of(work, struct ffa_drv_info, + irq_work); + + ffa_notification_info_get(info->info_get_64b); +} + +static int ffa_sched_recv_irq_map(void) +{ + int ret, irq, sr_intid; + + /* The returned sr_intid is assumed to be SGI donated to NS world */ + ret = ffa_features(FFA_FEAT_SCHEDULE_RECEIVER_INT, 0, &sr_intid, NULL); + if (ret < 0) { + if (ret != -EOPNOTSUPP) + pr_err("Failed to retrieve scheduler Rx interrupt\n"); + return ret; + } + + if (acpi_disabled) { + struct of_phandle_args oirq = {}; + struct device_node *gic; + + /* Only GICv3 supported currently with the device tree */ + gic = of_find_compatible_node(NULL, NULL, "arm,gic-v3"); + if (!gic) + return -ENXIO; + + oirq.np = gic; + oirq.args_count = 1; + oirq.args[0] = sr_intid; + irq = irq_create_of_mapping(&oirq); + of_node_put(gic); +#ifdef CONFIG_ACPI + } else { + irq = acpi_register_gsi(NULL, sr_intid, ACPI_EDGE_SENSITIVE, + ACPI_ACTIVE_HIGH); +#endif + } + + if (irq <= 0) { + pr_err("Failed to create IRQ mapping!\n"); + return -ENODATA; + } + + return irq; +} + +static void ffa_sched_recv_irq_unmap(void) +{ + if (drv_info->sched_recv_irq) + irq_dispose_mapping(drv_info->sched_recv_irq); +} + +static int ffa_cpuhp_pcpu_irq_enable(unsigned int cpu) +{ + enable_percpu_irq(drv_info->sched_recv_irq, IRQ_TYPE_NONE); + return 0; +} + +static int ffa_cpuhp_pcpu_irq_disable(unsigned int cpu) +{ + disable_percpu_irq(drv_info->sched_recv_irq); + return 0; +} + +static void ffa_uninit_pcpu_irq(void) +{ + if (drv_info->cpuhp_state) + cpuhp_remove_state(drv_info->cpuhp_state); + + if (drv_info->notif_pcpu_wq) + destroy_workqueue(drv_info->notif_pcpu_wq); + + if (drv_info->sched_recv_irq) + free_percpu_irq(drv_info->sched_recv_irq, drv_info->irq_pcpu); + + if (drv_info->irq_pcpu) + free_percpu(drv_info->irq_pcpu); +} + +static int ffa_init_pcpu_irq(unsigned int irq) +{ + struct ffa_pcpu_irq __percpu *irq_pcpu; + int ret, cpu; + + irq_pcpu = alloc_percpu(struct ffa_pcpu_irq); + if (!irq_pcpu) + return -ENOMEM; + + for_each_present_cpu(cpu) + per_cpu_ptr(irq_pcpu, cpu)->info = drv_info; + + drv_info->irq_pcpu = irq_pcpu; + + ret = request_percpu_irq(irq, irq_handler, "ARM-FFA", irq_pcpu); + if (ret) { + pr_err("Error registering notification IRQ %d: %d\n", irq, ret); + return ret; + } + + INIT_WORK(&drv_info->irq_work, ffa_sched_recv_irq_work_fn); + drv_info->notif_pcpu_wq = create_workqueue("ffa_pcpu_irq_notification"); + if (!drv_info->notif_pcpu_wq) + return -EINVAL; + + ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "ffa/pcpu-irq:starting", + ffa_cpuhp_pcpu_irq_enable, + ffa_cpuhp_pcpu_irq_disable); + + if (ret < 0) + return ret; + + drv_info->cpuhp_state = ret; + return 0; +} + +static void ffa_notifications_cleanup(void) +{ + ffa_uninit_pcpu_irq(); + ffa_sched_recv_irq_unmap(); + + if (drv_info->bitmap_created) { + ffa_notification_bitmap_destroy(); + drv_info->bitmap_created = false; + } +} + static int ffa_notifications_setup(void) { - int ret; + int ret, irq; ret = ffa_features(FFA_NOTIFICATION_BITMAP_CREATE, 0, NULL, NULL); if (!ret) { @@ -936,15 +1095,24 @@ static int ffa_notifications_setup(void) } drv_info->bitmap_created = true; - return 0; -} + irq = ffa_sched_recv_irq_map(); + if (irq <= 0) + goto cleanup; -static void ffa_notifications_cleanup(void) -{ - if (drv_info->bitmap_created) { - ffa_notification_bitmap_destroy(); - drv_info->bitmap_created = false; - } + if (FFA_FN_NATIVE(NOTIFICATION_INFO_GET) == + FFA_FN64_NOTIFICATION_INFO_GET) + drv_info->info_get_64b = true; + + drv_info->sched_recv_irq = irq; + + ret = ffa_init_pcpu_irq(irq); + if (ret) + goto cleanup; + + return 0; +cleanup: + ffa_notifications_cleanup(); + return ret; } static int __init ffa_init(void) @@ -1002,7 +1170,11 @@ static int __init ffa_init(void) ffa_set_up_mem_ops_native_flag(); - return ffa_notifications_setup(); + ret = ffa_notifications_setup(); + if (ret) + goto free_pages; + + return 0; free_pages: if (drv_info->tx_buffer) free_pages_exact(drv_info->tx_buffer, RXTX_BUFFER_SIZE); -- 2.42.0