From patchwork Thu Apr 11 12:57:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sudeep Holla X-Patchwork-Id: 13625940 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 68EE1CD128A for ; Thu, 11 Apr 2024 12:58:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References:Message-Id :MIME-Version:Subject:Date:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=R3aw7ng0IDljZtHGn3FuSc38nFWoP1eN4El0db8cd1M=; b=Y8ugB//6uzb+VV Kl/2znVTmQu9844DWQVSEC9IXvhuXfRmTA1cwkI0OWKNKTFUwRGShOddZdETOH3YNglu/FIJRxevr nq5c+1YN/js9PkC5hj4a6mz7Hn5KISU3Qlb0yw3JqBy6GbAdFtQD9Sh+41ORuJlNt9+uBjWSPbrpz +OD4FvMArgqBSMMSZNmS0ZT5YP/VhuVkTVGKttKDwIkNwq4fO/HQ+gU25WSaokR4+yL09t9BtU9tN hh3z8utVKbmKeiz8GvdM3ZKkrtrwUAzNFW/HHRz89ZoO6KKvmbALFTc4T8Eu1+q6NTLKS6FfhFK2B y3rpIe/qKXFgLATLRYpw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1ruu02-0000000C2gV-11Nr; Thu, 11 Apr 2024 12:57:54 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rutzx-0000000C2eK-0ofQ for linux-arm-kernel@lists.infradead.org; Thu, 11 Apr 2024 12:57:50 +0000 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 D5F8C11FB; Thu, 11 Apr 2024 05:58:15 -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 771A23F64C; Thu, 11 Apr 2024 05:57:45 -0700 (PDT) From: Sudeep Holla Date: Thu, 11 Apr 2024 13:57:32 +0100 Subject: [PATCH v2 1/3] firmware: arm_ffa: Skip creation of the notification bitmaps MIME-Version: 1.0 Message-Id: <20240411-ffa_npi_support-v2-1-927a670254e6@arm.com> References: <20240411-ffa_npi_support-v2-0-927a670254e6@arm.com> In-Reply-To: <20240411-ffa_npi_support-v2-0-927a670254e6@arm.com> To: linux-arm-kernel@lists.infradead.org Cc: Marc Bonnici , Olivier Deprez , Lorenzo Pieralisi , Bertrand Marquis , Jens Wiklander , Sudeep Holla X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1919; i=sudeep.holla@arm.com; h=from:subject:message-id; bh=yYE2AimCAKquv8X253zD5tNeVF9AH66uvZSRJabNqIM=; b=owEBbQKS/ZANAwAIAQBBurwxfuKYAcsmYgBmF95HWp3g2c0MZCVwMs0vyyVul8amRC4FzjFyP vwtjVPreNCJAjMEAAEIAB0WIQS6ceUSBvMeskPdk+EAQbq8MX7imAUCZhfeRwAKCRAAQbq8MX7i mPq2EACOthx7t4Xsm+cw+j4YfmHj/noqrGKFVixICbf6DjMGuMX+KlaVdAz6Ygfv+8vzv56yJZ/ tvUekWTa+BrWSl/dRdnXlpLpgX+qKyrLj62ULGT1sHV7naBaGflJvlQ+m2WbJha8LVx4pPsD5a1 7JiGbpMJSdfpQ/HKerFkaP3otaEqBzj5n+0HAyzNzOSPIgL1LO2FWGFH7XKNCm+Q9M3N0iAjJK5 fAFId/ecuQrF3OhHqWd7ipa06ZG5odfnXKJyi0WhT0oVK7CClrZeFIynQgWSeFh2zU27rZ8aE2/ NCz61/5lyhdVQpZ2A2UdBqLIwqjmbcpddzI3cRmUcCYbdzpq+JMJqA6yWrJIgcbu9A0Rdru7Elq zEk650/IhlpaN8Xycl1fGwkvuYz1YERgzvN+JKXS7+CxS7+BuAN02gkRCKwRNFli9Qu/ZESLIcB qZcwItFWTKw7b6HQ3HNF01hb/rr/8/CzKQJ6Xi+7EQhE3eu4/ykkPXww0vG8IJq6k3Hq2Kxrh/B ybwWZhP6elTgsQZiXnKxfrtdUaznpVEDBNMOIigtX86HrfNe+SWBbAXprAnlj+cqHdBMFnZpHM0 1UW6ugGMiL979ojS0jyXPs36vlyAorA2Zh2TmqN1q4ihWWmlydOjjgw6jrwkZZO034s8AnBO2UQ 02hVgjRVBbriteg== X-Developer-Key: i=sudeep.holla@arm.com; a=openpgp; fpr=7360A21742ADF5A11767C1C139CFD4755FE2D5B4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240411_055749_340291_CCCED27B X-CRM114-Status: GOOD ( 12.09 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Jens Wiklander When the FF-A driver is running inside a guest VM under an hypervisor, the driver/guest VM doesn't have the permission/capability to request the creation of notification bitmaps. For a VM, the hypervisor reserves memory for its VM and hypervisor framework notification bitmaps and the SPMC reserves memory for its SP and SPMC framework notification bitmaps before the hypervisor initializes it. The hypervisor does not initialize a VM if memory cannot be reserved for all its notification bitmaps. So the creation of all the necessary bitmaps are already done when the driver initialises and hence it can be skipped. We rely on FFA_FEATURES(FFA_NOTIFICATION_BITMAP_CREATE) to fail when running in the guest to handle this in the driver. Signed-off-by:Jens Wiklander [sudeep.holla: Updated the commit message] Signed-off-by: Sudeep Holla --- drivers/firmware/arm_ffa/driver.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/drivers/firmware/arm_ffa/driver.c b/drivers/firmware/arm_ffa/driver.c index f2556a8e9401..4a576af7b8fd 100644 --- a/drivers/firmware/arm_ffa/driver.c +++ b/drivers/firmware/arm_ffa/driver.c @@ -1442,17 +1442,15 @@ static void ffa_notifications_setup(void) int ret, irq; ret = ffa_features(FFA_NOTIFICATION_BITMAP_CREATE, 0, NULL, NULL); - if (ret) { - pr_info("Notifications not supported, continuing with it ..\n"); - return; - } + if (!ret) { + ret = ffa_notification_bitmap_create(); + if (ret) { + pr_info("Notification bitmap create error %d\n", ret); + return; + } - ret = ffa_notification_bitmap_create(); - if (ret) { - pr_info("Notification bitmap create error %d\n", ret); - return; + drv_info->bitmap_created = true; } - drv_info->bitmap_created = true; irq = ffa_sched_recv_irq_map(); if (irq <= 0) { From patchwork Thu Apr 11 12:57:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sudeep Holla X-Patchwork-Id: 13625941 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4536FCD1299 for ; Thu, 11 Apr 2024 12:58:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References:Message-Id :MIME-Version:Subject:Date:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=ZXFrXWzQVb/grz57qLl4L3fOJl20iVfWsBquxoou+Ys=; b=AxQvCowUOa0+ES lbKeEU4WUM0ByOS9PcyAqAhKETQ9/B6SJfHHAGymyrun4rXEctAy/H1WSME6kV2ZFub0ElAz6O8mu xj9DtSOflD5Rg6xG+CLa0/pgQkyWpgEZKHLo/Po12Majf/kTtn0HCN6ksZ7tlZ22O4UglBGg9mZqq MUBOj/drQIcs/JGub7dUZF6L2r2UDlQ8bQjIlMxmjoaA/Hr3W6ZcWsWv+MuNKmnGKRySBDhymdWT8 xVkxQ5QccRHkDcH69/T2QN6VLIKnM0HGB/oZNHu5lUuE3AtuThPb0hX9Mf/IhAEmHrTY0m26L01gt FnrXG/bXdoLDQesPIzPw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1ruu03-0000000C2hF-1tIR; Thu, 11 Apr 2024 12:57:55 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rutzy-0000000C2eb-0iDV for linux-arm-kernel@lists.infradead.org; Thu, 11 Apr 2024 12:57:51 +0000 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 EADCB1596; Thu, 11 Apr 2024 05:58:16 -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 8BEE83F64C; Thu, 11 Apr 2024 05:57:46 -0700 (PDT) From: Sudeep Holla Date: Thu, 11 Apr 2024 13:57:33 +0100 Subject: [PATCH v2 2/3] firmware: arm_ffa: Refactor SRI handling in prepartion to add NPI support MIME-Version: 1.0 Message-Id: <20240411-ffa_npi_support-v2-2-927a670254e6@arm.com> References: <20240411-ffa_npi_support-v2-0-927a670254e6@arm.com> In-Reply-To: <20240411-ffa_npi_support-v2-0-927a670254e6@arm.com> To: linux-arm-kernel@lists.infradead.org Cc: Marc Bonnici , Olivier Deprez , Lorenzo Pieralisi , Bertrand Marquis , Jens Wiklander , Sudeep Holla X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=4797; i=sudeep.holla@arm.com; h=from:subject:message-id; bh=YkB4WStiavLKbfkF66XQA+E56jOJurekZRpAQYR/JBY=; b=owEBbQKS/ZANAwAIAQBBurwxfuKYAcsmYgBmF95HWcVrAH5wJsCTe9iJZ49Hg1VJ8LPxQh/Jy 6cbes64/KGJAjMEAAEIAB0WIQS6ceUSBvMeskPdk+EAQbq8MX7imAUCZhfeRwAKCRAAQbq8MX7i mNGLEACFGgmAQlIY89a2gCkbSx1OsXO8NGMZ0rmXjiaoJ0HR1hmpryE9XABMTR9wNyTlMF/+1cf eGzPqKdvQTZe1LcIAsMXG8Z02e3C9l/S2rA+ZhUVAQPGZO63kgQbzmgVhK3hQoGPj9hlt9xZU/w JVyAvmnuUU/MEFzqbMyNlAqO2miEvlkCyItki8oD9T6ZaDcr2ROH/+TTWKgaaBfIq7jsyuBOJg6 qFRQwU1m3kbHkiOl9qX4Ay88SF1RWKxlhr9qvAvZttRE4DSKH7fO5HmgvGiBr8z7h/NVNM1HSZn q8rAhY10CNkN1O6D89LdBQPMQKsJduQZk+pp8z9uwrJKI0V5hgul9K5BvFnCDZcpHnrBz+9DBdw sEUieGWa5hVkb/U1gz7EuXlKjtqlVSdyID87kbALTFhpUDy3pkZfT68zg4C8y3d+MnFQ6EO9fFL bXfRWSZz6EVlrJN7iKX+gTRFL/0CyY6fu8CYzqQ3Ja6cmf1LXCg3jeEdu0JgtnORUGMVEJNXm70 L4eYMhZc6BGEs3fyuCl+slMypiD9Fha9wgmlpOgAwv7SgtA0hMpYMcOieFSlbuIaVozJzcm5YrD C5XPU2Hl8OT+7ArmxwNzc/QmayOiZontTH/1Dl0QSdYCqYyYFgcCGp9FV05CbpXgaXiDIS2Xlsl r/eR13j3ahlfg9w== X-Developer-Key: i=sudeep.holla@arm.com; a=openpgp; fpr=7360A21742ADF5A11767C1C139CFD4755FE2D5B4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240411_055750_329803_46D93DB7 X-CRM114-Status: GOOD ( 15.94 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org In preparation to support handling of Notification Pending Interrupt(NPI) in addition to the existing support for Schedule Reciever Interrupt(SRI), refactor the code around SRI handling so that NPI support can reuse some of it. This change shouldn't have any functionality impact. It neither adds the support for NPIs nor changes any SRI support. Signed-off-by: Sudeep Holla --- drivers/firmware/arm_ffa/driver.c | 47 +++++++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/drivers/firmware/arm_ffa/driver.c b/drivers/firmware/arm_ffa/driver.c index 4a576af7b8fd..1ef5d6752c35 100644 --- a/drivers/firmware/arm_ffa/driver.c +++ b/drivers/firmware/arm_ffa/driver.c @@ -105,7 +105,7 @@ struct ffa_drv_info { struct ffa_pcpu_irq __percpu *irq_pcpu; struct workqueue_struct *notif_pcpu_wq; struct work_struct notif_pcpu_work; - struct work_struct irq_work; + struct work_struct sched_recv_irq_work; struct xarray partition_info; DECLARE_HASHTABLE(notifier_hash, ilog2(FFA_MAX_NOTIFICATIONS)); struct mutex notify_lock; /* lock to protect notifier hashtable */ @@ -1291,12 +1291,12 @@ static void ffa_partitions_cleanup(void) #define FFA_FEAT_SCHEDULE_RECEIVER_INT (2) #define FFA_FEAT_MANAGED_EXIT_INT (3) -static irqreturn_t irq_handler(int irq, void *irq_data) +static irqreturn_t ffa_sched_recv_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); + queue_work(info->notif_pcpu_wq, &info->sched_recv_irq_work); return IRQ_HANDLED; } @@ -1306,15 +1306,23 @@ static void ffa_sched_recv_irq_work_fn(struct work_struct *work) ffa_notification_info_get(); } -static int ffa_sched_recv_irq_map(void) +static int ffa_irq_map(u32 id) { - int ret, irq, sr_intid; + char *err_str; + int ret, irq, 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 (id == FFA_FEAT_NOTIFICATION_PENDING_INT) + err_str = "Notification Pending Interrupt"; + else if (id == FFA_FEAT_SCHEDULE_RECEIVER_INT) + err_str = "Schedule Receiver Interrupt"; + else + err_str = "Unknown ID"; + + /* The returned intid is assumed to be SGI donated to NS world */ + ret = ffa_features(id, 0, &intid, NULL); if (ret < 0) { if (ret != -EOPNOTSUPP) - pr_err("Failed to retrieve scheduler Rx interrupt\n"); + pr_err("Failed to retrieve FF-A %s %u\n", err_str ,id); return ret; } @@ -1329,12 +1337,12 @@ static int ffa_sched_recv_irq_map(void) oirq.np = gic; oirq.args_count = 1; - oirq.args[0] = sr_intid; + oirq.args[0] = 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, + irq = acpi_register_gsi(NULL, intid, ACPI_EDGE_SENSITIVE, ACPI_ACTIVE_HIGH); #endif } @@ -1347,12 +1355,11 @@ static int ffa_sched_recv_irq_map(void) return irq; } -static void ffa_sched_recv_irq_unmap(void) +static void ffa_irq_unmap(unsigned int irq) { - if (drv_info->sched_recv_irq) { - irq_dispose_mapping(drv_info->sched_recv_irq); - drv_info->sched_recv_irq = 0; - } + if (!irq) + return; + irq_dispose_mapping(irq); } static int ffa_cpuhp_pcpu_irq_enable(unsigned int cpu) @@ -1402,13 +1409,14 @@ static int ffa_init_pcpu_irq(unsigned int irq) drv_info->irq_pcpu = irq_pcpu; - ret = request_percpu_irq(irq, irq_handler, "ARM-FFA", irq_pcpu); + ret = request_percpu_irq(irq, ffa_sched_recv_irq_handler, "ARM-FFA-SRI", + 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); + INIT_WORK(&drv_info->sched_recv_irq_work, ffa_sched_recv_irq_work_fn); INIT_WORK(&drv_info->notif_pcpu_work, notif_pcpu_irq_work_fn); drv_info->notif_pcpu_wq = create_workqueue("ffa_pcpu_irq_notification"); if (!drv_info->notif_pcpu_wq) @@ -1428,7 +1436,8 @@ static int ffa_init_pcpu_irq(unsigned int irq) static void ffa_notifications_cleanup(void) { ffa_uninit_pcpu_irq(); - ffa_sched_recv_irq_unmap(); + ffa_irq_unmap(drv_info->sched_recv_irq); + drv_info->sched_recv_irq = 0; if (drv_info->bitmap_created) { ffa_notification_bitmap_destroy(); @@ -1452,7 +1461,7 @@ static void ffa_notifications_setup(void) drv_info->bitmap_created = true; } - irq = ffa_sched_recv_irq_map(); + irq = ffa_irq_map(FFA_FEAT_SCHEDULE_RECEIVER_INT); if (irq <= 0) { ret = irq; goto cleanup; From patchwork Thu Apr 11 12:57:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sudeep Holla X-Patchwork-Id: 13625939 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5DABBCD1284 for ; Thu, 11 Apr 2024 12:58:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References:Message-Id :MIME-Version:Subject:Date:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=nbcwtTyy8+3WV1+ZhoIMIKYNj6+YpSV2qEZFLWpMSWY=; b=U5+UiPOko4REPO e2nFC8UR9vT/Gv/Y4i+lKcrTI+uXmZeN9lOAZnn7s7xvod9tGUIUqt9K+SIefWt3gGjM6KdSQxaX4 jBL7TSP1Q/zS8aL4ncZJUJucEAURevE9R8gM+uIwG2hVi84VcVZxWVe1daFZRwRRz3/H9p9Gb2pze 2TTyVT2ElcLY7YqxUl5+j/wgBAYKmLCXz6rXR7sM/RY7oVj0rKuodT2MV5EK10W3Cdv+NmbJQCbzz ycKLu6qhw5rXw3+aluqIMqwWPh+EeutEN4CMiD/K18i3NghcuLe8mqPCcFh/6oAtoRbHTyUTsRykg 1VsNmqpaYZxSuhYPXTDg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1ruu02-0000000C2gt-3bKy; Thu, 11 Apr 2024 12:57:54 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rutzx-0000000C2eq-1p7J for linux-arm-kernel@lists.infradead.org; Thu, 11 Apr 2024 12:57:51 +0000 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 0BBAB15A1; Thu, 11 Apr 2024 05:58:18 -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 A0E3E3F64C; Thu, 11 Apr 2024 05:57:47 -0700 (PDT) From: Sudeep Holla Date: Thu, 11 Apr 2024 13:57:34 +0100 Subject: [PATCH v2 3/3] firmware: arm_ffa: Add support for handling notification pending interrupt(NPI) MIME-Version: 1.0 Message-Id: <20240411-ffa_npi_support-v2-3-927a670254e6@arm.com> References: <20240411-ffa_npi_support-v2-0-927a670254e6@arm.com> In-Reply-To: <20240411-ffa_npi_support-v2-0-927a670254e6@arm.com> To: linux-arm-kernel@lists.infradead.org Cc: Marc Bonnici , Olivier Deprez , Lorenzo Pieralisi , Bertrand Marquis , Jens Wiklander , Sudeep Holla X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=5261; i=sudeep.holla@arm.com; h=from:subject:message-id; bh=2fozqumkZrPuKpT72urDFNsC5Afcmcq9cMGiulV/x2o=; b=owEBbQKS/ZANAwAIAQBBurwxfuKYAcsmYgBmF95IJUDfDaDZlOizcyXje2veQszpuZfLGO3dq K0JbG5V97mJAjMEAAEIAB0WIQS6ceUSBvMeskPdk+EAQbq8MX7imAUCZhfeSAAKCRAAQbq8MX7i mBQQD/4n899b1p3VhpLJzuW6+lSRwIRhh2PUBv7r6kRLbXP8EZDbStC+RYl3EbL3MphlLzpstEI u7HKc3juhfX5bdElb1Hni9XenXcJTOr9kUSqf4zGrJETWX+c7cSV6Yn9XoSsN9CONN2Q3w5bPPo LQfHG8/Hie0SRV5+chI6q5xV9TBMQ5qQJZOAAxjlt4S0pelpjuqzaawfCT7IOasp141DKsz6Vqc EBmeLC+jp8rJsajjJ8YgQAnBrW/FXPmuoDuZc5aRhPQ5kudtSmeF+xcB6hcfpGHBcg8FEqM5F6q P3a7EN/+tOskDa2lSfU0Ik2hxIKaRDnbEkSfSLHvvN+ABxsamBvRQNH1Eyuk5x1rW2YVjc8oIUW 06FWh9HT1xCfzo8+30FDHISzeA8JSfBxwNj3SA77IE6Ij/TmySrN5AU1P8y81kgVVxUEry6PGbD 24m/vjAnv0kWEL0VozfHDNvX6JpshrPCnbKNgTaTsH9/2EbEREwi2xjc7Srk+4CaHxk/2ZPRGcu m7lKTil9SFM0uyybqCGcyoOQ582kwc8F4eazIYCvcUipzW0HfiU+cYsPn+nQz0qw0p+O5igTFKA Sqh9XgWi9kjOdFU90YqObMsvxAfVSBTbKUx3Qw6cl2joREfcBQni0BDj7nAEuynZ2eKM0cLF/c9 TTTrB1pbhuRY2ug== X-Developer-Key: i=sudeep.holla@arm.com; a=openpgp; fpr=7360A21742ADF5A11767C1C139CFD4755FE2D5B4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240411_055749_622964_B73C8582 X-CRM114-Status: GOOD ( 17.11 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Jens Wiklander The FF-A uses the notification pending interrupt to inform the receiver that it has a pending notification. This is a virtual interrupt and is used by the following type of receivers: 1. A guest/VM running under a hypervisor. 2. An S-EL1 SP running under a S-EL2 SPMC. The rules that govern the properties of the NPI are the same as the rules for the SRI with couple of exceptions. Both SRI and NPI can be supported simultaneously. The handling of NPI is also same as the handling of notification for the self/primary VM with ID 0 except the absence of global notification. Signed-off-by: Jens Wiklander [sudeep.holla: minor refactoring] Signed-off-by: Sudeep Holla --- drivers/firmware/arm_ffa/driver.c | 71 ++++++++++++++++++++++++++++++--------- 1 file changed, 55 insertions(+), 16 deletions(-) diff --git a/drivers/firmware/arm_ffa/driver.c b/drivers/firmware/arm_ffa/driver.c index 1ef5d6752c35..87bd30c4bb67 100644 --- a/drivers/firmware/arm_ffa/driver.c +++ b/drivers/firmware/arm_ffa/driver.c @@ -101,6 +101,7 @@ struct ffa_drv_info { bool bitmap_created; bool notif_enabled; unsigned int sched_recv_irq; + unsigned int notif_pend_irq; unsigned int cpuhp_state; struct ffa_pcpu_irq __percpu *irq_pcpu; struct workqueue_struct *notif_pcpu_wq; @@ -1301,6 +1302,15 @@ static irqreturn_t ffa_sched_recv_irq_handler(int irq, void *irq_data) return IRQ_HANDLED; } +static irqreturn_t notif_pend_irq_handler(int irq, void *irq_data) +{ + struct ffa_pcpu_irq *pcpu = irq_data; + + ffa_self_notif_handle(smp_processor_id(), true, pcpu->info); + + return IRQ_HANDLED; +} + static void ffa_sched_recv_irq_work_fn(struct work_struct *work) { ffa_notification_info_get(); @@ -1364,13 +1374,19 @@ static void ffa_irq_unmap(unsigned int irq) static int ffa_cpuhp_pcpu_irq_enable(unsigned int cpu) { - enable_percpu_irq(drv_info->sched_recv_irq, IRQ_TYPE_NONE); + if (drv_info->sched_recv_irq) + enable_percpu_irq(drv_info->sched_recv_irq, IRQ_TYPE_NONE); + if (drv_info->notif_pend_irq) + enable_percpu_irq(drv_info->notif_pend_irq, IRQ_TYPE_NONE); return 0; } static int ffa_cpuhp_pcpu_irq_disable(unsigned int cpu) { - disable_percpu_irq(drv_info->sched_recv_irq); + if (drv_info->sched_recv_irq) + disable_percpu_irq(drv_info->sched_recv_irq); + if (drv_info->notif_pend_irq) + disable_percpu_irq(drv_info->notif_pend_irq); return 0; } @@ -1389,13 +1405,16 @@ static void ffa_uninit_pcpu_irq(void) if (drv_info->sched_recv_irq) free_percpu_irq(drv_info->sched_recv_irq, drv_info->irq_pcpu); + if (drv_info->notif_pend_irq) + free_percpu_irq(drv_info->notif_pend_irq, drv_info->irq_pcpu); + if (drv_info->irq_pcpu) { free_percpu(drv_info->irq_pcpu); drv_info->irq_pcpu = NULL; } } -static int ffa_init_pcpu_irq(unsigned int irq) +static int ffa_init_pcpu_irq(void) { struct ffa_pcpu_irq __percpu *irq_pcpu; int ret, cpu; @@ -1409,11 +1428,26 @@ static int ffa_init_pcpu_irq(unsigned int irq) drv_info->irq_pcpu = irq_pcpu; - ret = request_percpu_irq(irq, ffa_sched_recv_irq_handler, "ARM-FFA-SRI", - irq_pcpu); - if (ret) { - pr_err("Error registering notification IRQ %d: %d\n", irq, ret); - return ret; + if (drv_info->sched_recv_irq) { + ret = request_percpu_irq(drv_info->sched_recv_irq, + ffa_sched_recv_irq_handler, + "ARM-FFA-SRI", irq_pcpu); + if (ret) { + pr_err("Error registering percpu SRI nIRQ %d : %d\n", + drv_info->sched_recv_irq, ret); + return ret; + } + } + + if (drv_info->notif_pend_irq) { + ret = request_percpu_irq(drv_info->notif_pend_irq, + notif_pend_irq_handler, + "ARM-FFA-NPI", irq_pcpu); + if (ret) { + pr_err("Error registering percpu NPI nIRQ %d : %d\n", + drv_info->notif_pend_irq, ret); + return ret; + } } INIT_WORK(&drv_info->sched_recv_irq_work, ffa_sched_recv_irq_work_fn); @@ -1438,6 +1472,8 @@ static void ffa_notifications_cleanup(void) ffa_uninit_pcpu_irq(); ffa_irq_unmap(drv_info->sched_recv_irq); drv_info->sched_recv_irq = 0; + ffa_irq_unmap(drv_info->notif_pend_irq); + drv_info->notif_pend_irq = 0; if (drv_info->bitmap_created) { ffa_notification_bitmap_destroy(); @@ -1448,7 +1484,7 @@ static void ffa_notifications_cleanup(void) static void ffa_notifications_setup(void) { - int ret, irq; + int ret; ret = ffa_features(FFA_NOTIFICATION_BITMAP_CREATE, 0, NULL, NULL); if (!ret) { @@ -1461,15 +1497,18 @@ static void ffa_notifications_setup(void) drv_info->bitmap_created = true; } - irq = ffa_irq_map(FFA_FEAT_SCHEDULE_RECEIVER_INT); - if (irq <= 0) { - ret = irq; - goto cleanup; - } + ret = ffa_irq_map(FFA_FEAT_SCHEDULE_RECEIVER_INT); + if (ret > 0) + drv_info->sched_recv_irq = ret; - drv_info->sched_recv_irq = irq; + ret = ffa_irq_map(FFA_FEAT_NOTIFICATION_PENDING_INT); + if (ret > 0) + drv_info->notif_pend_irq = ret; + + if (!drv_info->sched_recv_irq && !drv_info->notif_pend_irq) + goto cleanup; - ret = ffa_init_pcpu_irq(irq); + ret = ffa_init_pcpu_irq(); if (ret) goto cleanup;