From patchwork Fri Sep 29 15:03:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sudeep Holla X-Patchwork-Id: 13404510 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 B3252E71D40 for ; Fri, 29 Sep 2023 15:04:20 +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:To:In-Reply-To:References:Message-Id: MIME-Version:Subject:Date:From:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=bHdu/KAZvWqSfh0UMAAGZFGDTNHBu46LLFPnZp51I80=; b=XRivp2pmxwEGfv +vGySnLGssz8xUPQ5RsgA2JqzCiXwSjDk4NRHdyYnYKzEnt0DY74F4RepMdOLucnZzTFOG0VyqepX /Wzhi8POBmNz7QLgNOFhPPa/1u33yQgaxdE6Pr7xqBQCxcIi18tfSLoKv/RKawTsvW5zSAhtnaKdC Ci+FvPBePO/p6SMZL1Xt4ICucYb3JsxKa6XGS/T4YM2U0oQcKi2t5LKfD0yuV6Cm9yTLhwMSosEUB JO3bTLZ8Zj/r+uwTmw+nR1VPUv/a5DejIndfjNN73kOdvJBVgfjo/IsTCEUdCzfKuJ4pnrHSKb8Fy PxNwD5ejGafw9ZooE79g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qmF1q-0088ST-2V; Fri, 29 Sep 2023 15:03:42 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qmF1e-0088HZ-0N for linux-arm-kernel@lists.infradead.org; Fri, 29 Sep 2023 15:03:34 +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 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 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-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230929_080330_267752_C0A44058 X-CRM114-Status: GOOD ( 15.86 ) 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 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;