Received: by 2002:a05:6358:700f:b0:131:369:b2a3 with SMTP id 15csp2667978rwo; Thu, 3 Aug 2023 13:00:13 -0700 (PDT) X-Google-Smtp-Source: APBJJlHBZ/gfDP4/sGyjniW48q6Cyh+VK8RsSMGeuGGXGP0iJtS/Nw2SJs9UE1ZhXGewPc1alZHF X-Received: by 2002:a05:6512:782:b0:4f7:6a40:9fd7 with SMTP id x2-20020a056512078200b004f76a409fd7mr6626413lfr.47.1691092813406; Thu, 03 Aug 2023 13:00:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691092813; cv=none; d=google.com; s=arc-20160816; b=Gyy+UCxQruVYYxmWj23S4G+egwGynsW5ktDNq2mlGCB8/QlrxvdDS3sFT1W0+nwzKt /RmEzyoRpkGWA7ncHVEFTYk2hz5cu4X0YHdN0Er72vdZphgfOcUDeCPSetS+QGaSOivQ qs86RXYTLie497pm0HDrF0Cx+EUo01/pahp/9B6QZLqN8vw7+NnhD0x+iSRV0a3/ltp0 SMdw9iQ6VN5RLdOAJnEFVPvv/9ewPaDwkYoyr5DJZ6a9ZofqkPo9phgg/T4FZWnGUcE3 nbU349rvm233VwnrMgSXtq2czJlkCSqmtqrHe2JdmDDP4OSx1v2OC3ZAqukaIZidPMSn 0/4w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=ywnjChimo/EuS6U+u4itbR6McnBnraRkroTYd2XOQOo=; fh=uIXkm8cj3c9TR2+QLs5NFfyS+JdekmBAQ3a9JCgCFII=; b=itTRw03Mt6ts/uCNYA+kmdfsPLns4CdG5UL2/TyHlcjEamvamubAygUvCi/F5CC7ys h4nuNO1lw1MlMxavvn97gLUY7q4EbGDXWg8wV6aXIT/gfGBGGLNCbRVI/5ULYRkXSfTq XdGtNuTYK5TUT7VD8R/NOiLg71cUqOrdu4flYd8evDA7uiWHNMGdpeV6g1G35UgJK7oq x/637iGBfJdB5tzEodGEfHVeYX8ZLF17cjbAYqWL70xpRwDb8/zVp7AtTvUHDPeHijWk fTZh46dFtGmJ20/Yj3iyIA0QAHcM1KiID5ZiLorPvryqXrxcomxZnxRHmzNdWKj6brbn OnMA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r25-20020aa7cfd9000000b00522bb898a06si333442edy.18.2023.08.03.12.59.48; Thu, 03 Aug 2023 13:00:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233854AbjHCTDk (ORCPT + 99 others); Thu, 3 Aug 2023 15:03:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47758 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233968AbjHCTDR (ORCPT ); Thu, 3 Aug 2023 15:03:17 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 1BCFC468E for ; Thu, 3 Aug 2023 12:02:38 -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 159F31477; Thu, 3 Aug 2023 12:03:21 -0700 (PDT) Received: from usa.arm.com (e103737-lin.cambridge.arm.com [10.1.197.49]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id EE5F43F6C4; Thu, 3 Aug 2023 12:02:36 -0700 (PDT) From: Sudeep Holla To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Sudeep Holla , Jens Wiklander , Lucian Paul-Trifu , Marc Bonnici , Coboy Chen Subject: [PATCH RFT 12/12] firmware: arm_ffa: Add notification handling mechanism Date: Thu, 3 Aug 2023 20:02:16 +0100 Message-ID: <20230803-ffa_v1-1_notif-v1-12-6613ff2b1f81@arm.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230803-ffa_v1-1_notif-v1-0-6613ff2b1f81@arm.com> References: <20230803-ffa_v1-1_notif-v1-0-6613ff2b1f81@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=3617; i=sudeep.holla@arm.com; h=from:subject:message-id; bh=alNQ8WKZzdLc226LuzWNQjd8s+t3f1uUa9m/aytNi74=; b=owEBbQKS/ZANAwAIAQBBurwxfuKYAcsmYgBky/iOoWGRp8MIkYKLKd/x+ellGoFwhm3RhX3kz sKucyPu4VCJAjMEAAEIAB0WIQS6ceUSBvMeskPdk+EAQbq8MX7imAUCZMv4jgAKCRAAQbq8MX7i mPDcEADPet/4EO7Br+XNllMSOUk+R0E485k23G+eMp9JL6aTv25MKnHpCBeB1peYYV7olLJ7t0n uEGziIcBnphjXKyQPp3Y7VjrPbXa4dqRUJvfVxvGzMFcX62lAP3ZXtgeqY2PS0p1Get13IgBBCr CPB368Q8teY84JnzlCWVvNJik+FfWneVKQiyn7+KMVagA/rXueVthuBBQ9HI6RYGKzk/aT2YV/C I0S3gyinCVWCXUAdeXADVaDyIrRs20AtVqs6e2UhPApN9Y8Az5dIDV+1LVEI8bXuKOtGpuqktjQ 3tlEaHe7rlVYYJEBrpivp2VTtZLKZVYB+aRtyyFUNVa6wJNLySLr////uUd9twpMoStIa6sdaI8 aDRZLQ7u02Qs7ytjtYnNqKYoY5FGAmwdH6AN5YuIERO3hCJe6bzs3Q/vn0Rek9YcxNJkLtQM49X Q6/EhcX6RGvqvs9CYGwZjKLEN4qwIuLMFqQXGJek2YZ1zN61C96rjlYV0iLjzFlbFn2nNY29xfD bR8tIekEK8fuF7tLJyy7uIsN6K9jCpsx3Um42ZV+9aTYop7zuP9WMHlgpOvg0haxXaSlMKo52Kd 39VfO9lywpdqe17XkyHDZ/lBbL4Of1d6v/rYtrPAW4TOI+WJp2kmwKZwYEIDT1ctelZtcQq62lh rS9GM59D ta7ofVg== X-Developer-Key: i=sudeep.holla@arm.com; a=openpgp; fpr=7360A21742ADF5A11767C1C139CFD4755FE2D5B4 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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 | 61 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 59 insertions(+), 2 deletions(-) diff --git a/drivers/firmware/arm_ffa/driver.c b/drivers/firmware/arm_ffa/driver.c index d98d0fbe5605..63daef95b048 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; @@ -1027,6 +1028,54 @@ static int ffa_notify_send(struct ffa_device *dev, int notify_id, BIT(notify_id)); } +static void handle_notif_callbacks(u64 bitmap, u16 part_id) +{ + int i = 0; + struct notifier_cb_info *cb_info = NULL; + + while (bitmap) { + if (bitmap & 1) { + mutex_lock(&drv_info->notify_lock); + cb_info = notifier_hash_node_get(part_id, i); + mutex_unlock(&drv_info->notify_lock); + if (cb_info->cb) + cb_info->cb(part_id, i, cb_info->cb_data); + } + i++; + bitmap >>= 1; + } +} + +static void notif_pcpu_irq_work_fn(struct work_struct *work) +{ + int rc; + struct ffa_notify_bitmaps bitmaps; + struct ffa_drv_info *info = container_of(work, struct ffa_drv_info, + notif_pcpu_work); + + rc = ffa_notification_get(ALL_NOTIFICATION_BITMAPS_FLAGS, &bitmaps); + if (rc) { + pr_err("Failed to retrieve notifications with %d!\n", rc); + return; + } + + handle_notif_callbacks(bitmaps.vm_map, info->vm_id); + handle_notif_callbacks(bitmaps.sp_map, info->vm_id); + handle_notif_callbacks(bitmaps.arch_map, info->vm_id); +} + +static void +ffa_self_notif_handle(u16 part_id, 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, @@ -1128,7 +1177,12 @@ static void ffa_setup_partitions(void) } xa_store(&drv_info->partition_info, tpbuf->id, info, GFP_KERNEL); } - drv_info->partition_count = count; + /* 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 = count + 1; kfree(pbuf); } @@ -1270,6 +1324,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; @@ -1325,7 +1380,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.41.0