From patchwork Wed Apr 10 11:39:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sudeep Holla X-Patchwork-Id: 13624127 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 1FB6CCD128A for ; Wed, 10 Apr 2024 11:40:29 +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=qKggTccfub7T1G1oXm2MYcgTawwQQsWJyy0aSD2TNSI=; b=2ZfHU7vwkk1Lfi h3RoEDL0QTS8WGdQF5bU/AlAUl10NG/nCv/mTHsI1xug/JpL86nICAIsT6bOEDxcmB4b5NBFRUiEO p9npZcNLRUZ4VQEMKtGxQwcATzBn5iuqLOs/vWkdRbsUaVDanqF/PrDKnCH/NlCoVOPoDj6wxdTqX +iW0UrS06hImOHWZ2J2EIpnFikDxBYbz2ifEEnZBq9pEt+RrAI74zEAF8RNLciTChW3i3t8c/3hOO 4XIl4ysAl8fKyfhIJPjWE4w58PLnUPj5sBa1r/sdqWIEsTgPD5Zbuc8SXA0dXSlXGwKLP/stgqWWK eApbbIGi9gBN6riMA1wA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1ruWJO-00000006gSL-27uH; Wed, 10 Apr 2024 11:40:18 +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 1ruWJC-00000006gNT-49OX for linux-arm-kernel@lists.infradead.org; Wed, 10 Apr 2024 11:40:09 +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 5F99C1596; Wed, 10 Apr 2024 04:40:34 -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 9D6643F6C4; Wed, 10 Apr 2024 04:40:03 -0700 (PDT) From: Sudeep Holla Date: Wed, 10 Apr 2024 12:39:48 +0100 Subject: [PATCH 3/3] firmware: arm_ffa: Add support for handling notification pending interrupt(NPI) MIME-Version: 1.0 Message-Id: <20240410-ffa_npi_support-v1-3-1a5223391bd1@arm.com> References: <20240410-ffa_npi_support-v1-0-1a5223391bd1@arm.com> In-Reply-To: <20240410-ffa_npi_support-v1-0-1a5223391bd1@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=4124; i=sudeep.holla@arm.com; h=from:subject:message-id; bh=oaerHtW21WfH1I6iThYJxby/im1n07tjFTafbtiE+Ik=; b=owEBbQKS/ZANAwAIAQBBurwxfuKYAcsmYgBmFnqQrId4d0/yt6FTDUc034kkgJIGD0IY8LYbE t40sML0gnWJAjMEAAEIAB0WIQS6ceUSBvMeskPdk+EAQbq8MX7imAUCZhZ6kAAKCRAAQbq8MX7i mNlxD/44eGcCcMuYRClaDDp44vwtnl//dIyjsFQZY07T6q8ts8cVx4aUH6uFp3VVozqyfLmspRV o3cbIzhV8LvrV2cKRt1UhGZTySwQqp0nAGmBX7dAwXwcC3kt4sBmUSeqzA6jEqKE9eg89IsM74o xmNvcVv51rzO+8QzLxnrwpkatWSAwrH5zakh/QTtmrc56iV/6Uafq36JxwlGHBMrRFVFs9PK7xf UPZZ1QQyC0H/KUOa31j3OKjLOQzwc45gw5waw9431xbaUN1CGQfQas/dhgvrjTUalQweVtGcgUL j1FgfIE0fqqZgbOCi6OGW5ojbyACmoVKVwOGGzFFXbYm8sPvtdtiDL4b3KTbbjSmfsgN66yIsdi 7hpy5pM0O2gze5jLRGlMfS2rSt/Dg3kGZfexOQ52aokLPPeT29YyQuXlrkzKYOovPqSoxLjg/R7 fWhdwWg9KpT53X4NKd1HYGyBK2q9I5cKdY/+CKmH41nSMcflBDrVxUpgEg2ftvIhXkMiEGJy5VL 6mEgTu6rnoUZzTx3gXxRnNxbGh8jKMkcN0i01vfP/ig3nFrS7kC42Ft4N8aAIiw4IVBtPJEtknB RV+ikDkoBb4bhcsUNTxX5lgchNkhyXO67CjUYxzko9zA/Pljv5OyOKeoX49rUetZz0mgPlpS8zb RFfIN5sw0TD64WA== 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-20240410_044007_258851_FF5A8A8A X-CRM114-Status: GOOD ( 18.40 ) 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 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. If the SRI is not supported, then an attempt to discover NPI will be made in the driver. 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. Co-Developed-by: Jens Wiklander Signed-off-by: Sudeep Holla --- drivers/firmware/arm_ffa/driver.c | 43 +++++++++++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 9 deletions(-) diff --git a/drivers/firmware/arm_ffa/driver.c b/drivers/firmware/arm_ffa/driver.c index c299cb9e6889..d50b41a815b9 100644 --- a/drivers/firmware/arm_ffa/driver.c +++ b/drivers/firmware/arm_ffa/driver.c @@ -100,6 +100,8 @@ struct ffa_drv_info { bool mem_ops_native; bool bitmap_created; bool notif_enabled; + /* Flag to indicate it is Notification pending interrupt */ + bool irq_is_npi; /* Schedule Receiver(SRI) or Notification pending interrupt(NPI) */ unsigned int sr_or_np_irq; unsigned int cpuhp_state; @@ -1138,6 +1140,15 @@ ffa_self_notif_handle(u16 vcpu, bool is_per_vcpu, void *cb_data) &info->notif_pcpu_work); } +static irqreturn_t npi_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 const struct ffa_info_ops ffa_drv_info_ops = { .api_version_get = ffa_api_version_get, .partition_info_get = ffa_partition_info_get, @@ -1307,16 +1318,24 @@ static void ffa_sched_recv_irq_work_fn(struct work_struct *work) ffa_notification_info_get(); } -static int ffa_sr_or_np_irq_map(void) +static int ffa_sr_or_np_irq_map(bool *irq_is_npi) { int ret, irq, intr_id; /* The returned intr_id is assumed to be SGI donated to NS world */ ret = ffa_features(FFA_FEAT_SCHEDULE_RECEIVER_INT, 0, &intr_id, NULL); - if (ret < 0) { - if (ret != -EOPNOTSUPP) - pr_err("Failed to retrieve scheduler Rx interrupt\n"); + if (ret && ret != -EOPNOTSUPP) { + pr_err("Failed to retrieve scheduler Rx interrupt\n"); return ret; + } else if (ret) { + ret = ffa_features(FFA_FEAT_NOTIFICATION_PENDING_INT, 0, + &intr_id, NULL); + if (ret) { + if (ret != -EOPNOTSUPP) + pr_err("Failed to retrieve notification pending interrupt\n"); + return ret; + } + *irq_is_npi = true; } if (acpi_disabled) { @@ -1389,7 +1408,7 @@ static void ffa_uninit_pcpu_irq(void) } } -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; @@ -1403,9 +1422,15 @@ static int ffa_init_pcpu_irq(unsigned int irq) drv_info->irq_pcpu = irq_pcpu; - ret = request_percpu_irq(irq, sri_handler, "ARM-FFA-SRI", irq_pcpu); + if (drv_info->irq_is_npi) + ret = request_percpu_irq(drv_info->sr_or_np_irq, npi_handler, + "ARM-FFA-NPI", irq_pcpu); + else + ret = request_percpu_irq(drv_info->sr_or_np_irq, sri_handler, + "ARM-FFA-SRI", irq_pcpu); if (ret) { - pr_err("Error registering notification IRQ %d: %d\n", irq, ret); + pr_err("Error registering NPI/SRI IRQ %d: %d\n", + drv_info->sr_or_np_irq, ret); return ret; } @@ -1453,7 +1478,7 @@ static void ffa_notifications_setup(void) drv_info->bitmap_created = true; } - irq = ffa_sr_or_np_irq_map(); + irq = ffa_sr_or_np_irq_map(&drv_info->irq_is_npi); if (irq <= 0) { ret = irq; goto cleanup; @@ -1461,7 +1486,7 @@ static void ffa_notifications_setup(void) drv_info->sr_or_np_irq = irq; - ret = ffa_init_pcpu_irq(irq); + ret = ffa_init_pcpu_irq(); if (ret) goto cleanup;