Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp4012102rdh; Fri, 29 Sep 2023 08:42:18 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG08tEAt/qTPbMkaPbdXQEi60/XXl3KA8ZqJ53JUMwV/n+g1dATYjf3seTh90o9mOk4jIWb X-Received: by 2002:a05:6a00:1303:b0:690:f6a1:ae62 with SMTP id j3-20020a056a00130300b00690f6a1ae62mr4400176pfu.23.1696002137855; Fri, 29 Sep 2023 08:42:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696002137; cv=none; d=google.com; s=arc-20160816; b=r1NkjcwPbBxWIEzCo36N3og28Oi8c9fAUuDHUJmxI/OmdCuzwRaS1U+1OX57JKyDmh pkH1NbTkInscYkZH/O1lszrcOOJ7uW9gpQ5K5fPt2zpW40QIOwdOqxpjU1TrT/SW8mNx ZzDwi3rYHkvbkWaq5bKeEEzRJTZC2M2ERIeu0zZHg2n5QJ3c6Rt74rwlH+j2b4dPqJwB Tzbpme0Ji7uMkUTnRFlXHDsA9fvCaU1DzgjKYGhfYqPaQst6Jpx12TzBJ1iWtQADnF77 XIsZxWH8xSjm0wcP60PDLDS6418kUe8gzfb+5KayrXwPiH6EGgYtyEc6X2f4EsWzDPo/ MXTw== 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=ne6GPupkp+d5OsPILfDUBCgXeTm7nnbHvlUSC46/pFk=; fh=iZJRvoZuVJp3Jcg3UWu0imuTLbH0nKChof8pDyzNHj4=; b=CEF01id15Iv1SA69AKPa8lUnBWcE6V10ovZCWD6AYXc4ij4px+kVCIDGOlkZlcBhwf xlH2QqbfEpzqK+sATf088pLpynMzwDrof0MsdcJgSWQflSfMGDBpSq2kLeOkDogw6TQe ru0lLbzMhtoPN85tbExp/cf4o2VcY5r2RWOf6+t/DfMQvnag7l9upMLRZiAgY1JTRLQV GPGmIkMrroh7nncDTjn27MnAHfFGk/WKfrqWFAWdu1P34O8GGA2PfWGxWQuARXSNha6A YjAcscyCuQijfHWl3q71/meLkcxPsLQfZX6lU1MvMhz0lmbX4+d1oKhZHuR1x1QMitpL 5UWQ== 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 k24-20020a63ba18000000b0056b83e0ae92si22507778pgf.465.2023.09.29.08.42.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Sep 2023 08:42:17 -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 EBB3E82A04A8; Fri, 29 Sep 2023 08:04:14 -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 S233394AbjI2PD7 (ORCPT + 99 others); Fri, 29 Sep 2023 11:03:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55594 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233477AbjI2PDb (ORCPT ); Fri, 29 Sep 2023 11:03:31 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 141AF1BF for ; Fri, 29 Sep 2023 08:03:29 -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 55718DA7; Fri, 29 Sep 2023 08:04:07 -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 F2DDE3F5A1; Fri, 29 Sep 2023 08:03:27 -0700 (PDT) From: Sudeep Holla Date: Fri, 29 Sep 2023 16:03:01 +0100 Subject: [PATCH v3 12/17] firmware: arm_ffa: Add notification handling mechanism MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20230929-ffa_v1-1_notif-v3-12-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=4004; i=sudeep.holla@arm.com; h=from:subject:message-id; bh=P0A5RMcFNkidNv2DNz6gtpSgVPPefciFbLXlHTbsR/M=; b=owEBbQKS/ZANAwAIAQBBurwxfuKYAcsmYgBlFucwYmIkcIk2FrlNkANdeNEyh1b6LuU9cIg6j jetsf0+Ho6JAjMEAAEIAB0WIQS6ceUSBvMeskPdk+EAQbq8MX7imAUCZRbnMAAKCRAAQbq8MX7i mJwoEACek+U4yIiIyf+5+1Vh7WX8nlg+7YdLyiDPGJYHdqU881l2wYDmoBWzUK19uCCgbFPgGXv ZUVO/jtWZHzOEC1wjgPqt5GTcWcnOt0m5H4NMoSR4AfzZ1eKTFxGRiW9tJVxFVl0NkRgxGGaP9j Q2Emlt3TD140Qd+A3VSJCzq9fj73LIaN3iDy0kk9QFxHPiU1TK8Mp1deUeJFC8l7iAFn+xWo7m5 d1yqm5NcMcxCQVF6J4gS3wiGTPHrhDPnPNHTefpTFHGK5YrNlGaq8A6S33T3PlYN5BKR+JqW7SF CADpA27cPbfNbUznDeM6Fq19FwLCrNmYIC8ZaCUMoHfDCTp4t6gL6Z55kRx+TCikMvyxgk4P6sO 1lK4Q0K8nlx42ck/2b+Y8ZFsotH7zRlRZanCTU4uIvEtyuZQcfhtXhEK3jG7Eub63YfqntyOLCv 1jgzman0nENiAQ+jfiOSIYmOM1YYzFclo9DgEOYMYSWwBCPvV9u4G/AFHmg0wk67EfGlS4+jdYU JDdM95MHp9GRpO9C9vPfq9Mn8zCPG43/ew1PrFb+8+XoRYNBgxzsOftfJ+I9UDRMdjh0d+LQxUF NdngDiMl16m67dHvft3/T6GRck9IDJPmsnk0wKMosXReNgB+CgQ6BxmfT+k6Tf+OOo7DSaX6FO1 aox1d4DkRrF8gSg== 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:15 -0700 (PDT) With all the necessary plumbing in place, let us add handling the notifications as part of schedule receiver interrupt handler. In order to do so, we need to just register scheduling callback on behalf of the driver partition. Signed-off-by: Sudeep Holla --- drivers/firmware/arm_ffa/driver.c | 65 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 64 insertions(+), 1 deletion(-) diff --git a/drivers/firmware/arm_ffa/driver.c b/drivers/firmware/arm_ffa/driver.c index 94e39ee83278..28bf345862d9 100644 --- a/drivers/firmware/arm_ffa/driver.c +++ b/drivers/firmware/arm_ffa/driver.c @@ -103,6 +103,7 @@ struct ffa_drv_info { unsigned int cpuhp_state; struct ffa_pcpu_irq __percpu *irq_pcpu; struct workqueue_struct *notif_pcpu_wq; + struct work_struct notif_pcpu_work; struct work_struct irq_work; bool info_get_64b; struct xarray partition_info; @@ -634,6 +635,10 @@ static int ffa_notification_bitmap_destroy(void) #define MAX_IDS_32 10 #define PER_VCPU_NOTIFICATION_FLAG BIT(0) +#define SECURE_PARTITION_BITMAP BIT(0) +#define NON_SECURE_VM_BITMAP BIT(1) +#define SPM_FRAMEWORK_BITMAP BIT(2) +#define NS_HYP_FRAMEWORK_BITMAP BIT(3) static int ffa_notification_bind_common(u16 dst_id, u64 bitmap, u32 flags, bool is_bind) @@ -1056,6 +1061,54 @@ static int ffa_notify_send(struct ffa_device *dev, int notify_id, BIT(notify_id)); } +static void handle_notif_callbacks(u64 bitmap, enum notify_type type) +{ + int notify_id; + struct notifier_cb_info *cb_info = NULL; + + for (notify_id = 0; notify_id <= FFA_MAX_NOTIFICATIONS && bitmap; + notify_id++, bitmap >>= 1) { + if (!(bitmap & 1)) + continue; + + mutex_lock(&drv_info->notify_lock); + cb_info = notifier_hash_node_get(notify_id, type); + mutex_unlock(&drv_info->notify_lock); + + if (cb_info && cb_info->cb) + cb_info->cb(notify_id, cb_info->cb_data); + } +} + +static void notif_pcpu_irq_work_fn(struct work_struct *work) +{ + int rc; + struct ffa_notify_bitmaps bitmaps; + + rc = ffa_notification_get(SECURE_PARTITION_BITMAP | + SPM_FRAMEWORK_BITMAP, &bitmaps); + if (rc) { + pr_err("Failed to retrieve notifications with %d!\n", rc); + return; + } + + handle_notif_callbacks(bitmaps.vm_map, NON_SECURE_VM); + handle_notif_callbacks(bitmaps.sp_map, SECURE_PARTITION); + handle_notif_callbacks(bitmaps.arch_map, FRAMEWORK); +} + +static void +ffa_self_notif_handle(u16 vcpu, bool is_per_vcpu, void *cb_data) +{ + struct ffa_drv_info *info = cb_data; + + if (!is_per_vcpu) + notif_pcpu_irq_work_fn(&info->notif_pcpu_work); + else + queue_work_on(vcpu, info->notif_pcpu_wq, + &info->notif_pcpu_work); +} + static const struct ffa_info_ops ffa_drv_info_ops = { .api_version_get = ffa_api_version_get, .partition_info_get = ffa_partition_info_get, @@ -1160,6 +1213,13 @@ static void ffa_setup_partitions(void) drv_info->partition_count = count; kfree(pbuf); + + /* Allocate for the host */ + info = kzalloc(sizeof(*info), GFP_KERNEL); + if (!info) + return; + xa_store(&drv_info->partition_info, drv_info->vm_id, info, GFP_KERNEL); + drv_info->partition_count++; } static void ffa_partitions_cleanup(void) @@ -1303,6 +1363,7 @@ static int ffa_init_pcpu_irq(unsigned int irq) } INIT_WORK(&drv_info->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) return -EINVAL; @@ -1360,7 +1421,9 @@ static int ffa_notifications_setup(void) hash_init(drv_info->notifier_hash); mutex_init(&drv_info->notify_lock); - return 0; + /* Register internal scheduling callback */ + return ffa_sched_recv_cb_update(drv_info->vm_id, + ffa_self_notif_handle, drv_info, true); cleanup: ffa_notifications_cleanup(); return ret; -- 2.42.0