From nobody Mon Feb 9 15:49:04 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 83C9D2918D7; Mon, 12 May 2025 11:40:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747050019; cv=none; b=gmrNHd7oy1PxBDeyzur/UWcJbqy+kq1wmFb+KQ211i6iuB7kY8EQNlmoVwA5pfYhH/DcXQbiO11yQQdgls42kvNun7e1cM4MWWAGOypVc5drm2fyVLrU/MNZMQ+7xaha4GDtpKXs/2EM0vF0EYRMSpFUN8nGyq/HDT8mTGbprV0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747050019; c=relaxed/simple; bh=/PqeRx1G8yWgH2bpaj+v9geJqih0EWc+M09T0J5VbYU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=icoy6U0KI+UBXhtEw5RjafMIgNVNS189Yu9qzt4uhD09K+YPSfgA97nYd1Bj2tgPVWr3deJECkNA2ZkaODfqMcDdCXymxTjaniwnBBaYw4bSrqQxTxPLlPkDB7vbPT6+Ob5xo741fxnPsw7RcvXA9PxzOpsnAyYb9A4XLeS+Kiw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=JVKNdRtL; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="JVKNdRtL" Received: by smtp.kernel.org (Postfix) with ESMTPS id 0207CC4CEF8; Mon, 12 May 2025 11:40:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1747050019; bh=/PqeRx1G8yWgH2bpaj+v9geJqih0EWc+M09T0J5VbYU=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=JVKNdRtLhHEgwSwP78dDFvf8os7r2Ya+lLE7oGdI205ZB84fwV3ErJBWmiDYIuhre LxpLv7UYXsFDkbFJwryj1Ll/KJz2/PJRAdOArR0RzfNRIWY+eMw9deZpl7e54YWMNn SZUm8SOKR0dHqeQsx0L2NvRdUdj/hkwokl1Iscn1KcnOoNAMCIXVvcy1MN9jZdrMRc x4LEQcyr8KQCbHcHk1pCXFx/EXnejuOO/dPPQ/vWZRvx6y85J2ck7LO58ckuHb7w7l N7pJ6g8gj1tRrB3ytIaV9LjVL2HfjufjmBisNY0jLna1qLrCAvvX0G59ib61hUf7lS m5w1Hy9C24hzQ== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id E227BC3ABCD; Mon, 12 May 2025 11:40:18 +0000 (UTC) From: Mahesh Rao via B4 Relay Date: Mon, 12 May 2025 19:39:51 +0800 Subject: [PATCH v2 1/7] firmware: stratix10-svc: Add mutex lock and unlock in stratix10 memory allocation/free Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250512-sip_svc_upstream-v2-1-fae5c45c059d@altera.com> References: <20250512-sip_svc_upstream-v2-0-fae5c45c059d@altera.com> In-Reply-To: <20250512-sip_svc_upstream-v2-0-fae5c45c059d@altera.com> To: Dinh Nguyen , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Mahesh Rao Cc: Matthew Gerlach , linux-kernel@vger.kernel.org, devicetree@vger.kernel.org X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1747050016; l=3909; i=mahesh.rao@altera.com; s=20250107; h=from:subject:message-id; bh=U7peSYw634W0vjNlQpTtWPEU2kILWkLlInRHSfUpC/A=; b=aATMkkE/hT3g6shV+y2mDaZrhthT/+T0kkMEPnnXPXoMKXjUSJWoV1pMj10cGJ296cr+g8+bo KVj5OaDNb5gCgJ8hB/JCKPGwbOSm8XTr3wIZQEVGJdkMAJ2A2E1DU2I X-Developer-Key: i=mahesh.rao@altera.com; a=ed25519; pk=tQiFUzoKxHrQLDtWeEeaeTeJTl/UfclUHWZy1fjSiyg= X-Endpoint-Received: by B4 Relay for mahesh.rao@altera.com/20250107 with auth_id=337 X-Original-From: Mahesh Rao Reply-To: mahesh.rao@altera.com From: Mahesh Rao This commit adds a mutex lock to stratix10_svc_allocate_memory and stratix10_svc_free_memory functions to ensure thread safety when allocating and freeing memory. This prevents potential race conditions and ensures synchronization. Signed-off-by: Mahesh Rao Reviewed-by: Matthew Gerlach --- drivers/firmware/stratix10-svc.c | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/drivers/firmware/stratix10-svc.c b/drivers/firmware/stratix10-= svc.c index e3f990d888d71829f0ab22b8a59aa7af0316bea0..3d42d4b18b7299d0a9e5110159e= 06253dfeddf88 100644 --- a/drivers/firmware/stratix10-svc.c +++ b/drivers/firmware/stratix10-svc.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 /* * Copyright (C) 2017-2018, Intel Corporation + * Copyright (C) 2025, Altera Corporation */ =20 #include @@ -171,6 +172,7 @@ struct stratix10_svc_chan { =20 static LIST_HEAD(svc_ctrl); static LIST_HEAD(svc_data_mem); +static DEFINE_MUTEX(svc_mem_lock); =20 /** * svc_pa_to_va() - translate physical address to virtual address @@ -182,14 +184,17 @@ static LIST_HEAD(svc_data_mem); static void *svc_pa_to_va(unsigned long addr) { struct stratix10_svc_data_mem *pmem; + void *ret =3D NULL; =20 pr_debug("claim back P-addr=3D0x%016x\n", (unsigned int)addr); + mutex_lock(&svc_mem_lock); list_for_each_entry(pmem, &svc_data_mem, node) - if (pmem->paddr =3D=3D addr) - return pmem->vaddr; - - /* physical address is not found */ - return NULL; + if (pmem->paddr =3D=3D addr) { + /* physical address is found */ + ret =3D pmem->vaddr; + } + mutex_unlock(&svc_mem_lock); + return ret; } =20 /** @@ -990,13 +995,16 @@ int stratix10_svc_send(struct stratix10_svc_chan *cha= n, void *msg) p_data->flag =3D ct->flags; } } else { + mutex_lock(&svc_mem_lock); list_for_each_entry(p_mem, &svc_data_mem, node) if (p_mem->vaddr =3D=3D p_msg->payload) { p_data->paddr =3D p_mem->paddr; p_data->size =3D p_msg->payload_length; break; } + mutex_unlock(&svc_mem_lock); if (p_msg->payload_output) { + mutex_lock(&svc_mem_lock); list_for_each_entry(p_mem, &svc_data_mem, node) if (p_mem->vaddr =3D=3D p_msg->payload_output) { p_data->paddr_output =3D @@ -1005,6 +1013,7 @@ int stratix10_svc_send(struct stratix10_svc_chan *cha= n, void *msg) p_msg->payload_length_output; break; } + mutex_unlock(&svc_mem_lock); } } =20 @@ -1072,9 +1081,12 @@ void *stratix10_svc_allocate_memory(struct stratix10= _svc_chan *chan, if (!pmem) return ERR_PTR(-ENOMEM); =20 + mutex_lock(&svc_mem_lock); va =3D gen_pool_alloc(genpool, s); - if (!va) + if (!va) { + mutex_unlock(&svc_mem_lock); return ERR_PTR(-ENOMEM); + } =20 memset((void *)va, 0, s); pa =3D gen_pool_virt_to_phys(genpool, va); @@ -1086,6 +1098,7 @@ void *stratix10_svc_allocate_memory(struct stratix10_= svc_chan *chan, pr_debug("%s: va=3D%p, pa=3D0x%016x\n", __func__, pmem->vaddr, (unsigned int)pmem->paddr); =20 + mutex_unlock(&svc_mem_lock); return (void *)va; } EXPORT_SYMBOL_GPL(stratix10_svc_allocate_memory); @@ -1100,6 +1113,7 @@ EXPORT_SYMBOL_GPL(stratix10_svc_allocate_memory); void stratix10_svc_free_memory(struct stratix10_svc_chan *chan, void *kadd= r) { struct stratix10_svc_data_mem *pmem; + mutex_lock(&svc_mem_lock); =20 list_for_each_entry(pmem, &svc_data_mem, node) if (pmem->vaddr =3D=3D kaddr) { @@ -1107,9 +1121,10 @@ void stratix10_svc_free_memory(struct stratix10_svc_= chan *chan, void *kaddr) (unsigned long)kaddr, pmem->size); pmem->vaddr =3D NULL; list_del(&pmem->node); + mutex_unlock(&svc_mem_lock); return; } - + mutex_unlock(&svc_mem_lock); list_del(&svc_data_mem); } EXPORT_SYMBOL_GPL(stratix10_svc_free_memory); --=20 2.35.3 From nobody Mon Feb 9 15:49:04 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 83D0E2918E1; Mon, 12 May 2025 11:40:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747050019; cv=none; b=LFIwil3saMHGIFiegwe3lfck5H6pBdKVa2fkJPq3cCY0t0UCHNqmc73SONDGGtLaDnE0d4j2fQJB1iGIIYnbouLJJ8CFevNtHuO9ZIPr8uZvhbF11bVwKSkorNIFBaXubDiKtzHDWaJgM92ugbLGnELGw+kBgKIFzQXjgwsrVbY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747050019; c=relaxed/simple; bh=HT6/2/GedgWpF6igAvBUqPc/BsGvXccamOg4GedgCHA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=HnJk8aLdEEbT52A8AOJwppbB+J1CgTru/dwAdfTDu+EI1PSHKzCmjMKuOGNtpAKKvGWwSXtSZa7EByKVTjbsyPqw/fS7acjt70RpdW0CwKyf6jaeM7YscJI9qXBYm/kGnFGQah8h1mOrjAu3qAAXjWKTOz6hWg86fGvrn63uUU0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=bbK4u1c8; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="bbK4u1c8" Received: by smtp.kernel.org (Postfix) with ESMTPS id 0B5A3C4CEFB; Mon, 12 May 2025 11:40:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1747050019; bh=HT6/2/GedgWpF6igAvBUqPc/BsGvXccamOg4GedgCHA=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=bbK4u1c8/0JLdK2Dho4yHx0OqHQnXwxztFPrd8qa0erEfP24q4lKpbT6rU0dsURQ1 iOdNhUkuC1U6Fag8SSxvYYr+p3Z+SXLnV/71Btbt3outQPlSdDV+oOrPt68G/vGBcf UxP0bPyWP1otg7ojTL2pZkrc3SmX3tTy01SYJjMja63JemaxphFe58cH2SdmERCln8 9BO2uigQ7+AQY/6vDchnsi7uJwN8sJ2A7dkw/SuB5THHkkaVOLARbQXw8i8++D6saO odYdZbo/Ow/7/lusarNGWS8ER90/KitoYUh9tt0b7G8z+RFnWev45ikHF6ZCCHrdav QQ+44Q6M8jbXQ== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id F0B04C3ABD2; Mon, 12 May 2025 11:40:18 +0000 (UTC) From: Mahesh Rao via B4 Relay Date: Mon, 12 May 2025 19:39:52 +0800 Subject: [PATCH v2 2/7] firmware: stratix10-svc: Implement ID pool management for asynchronous operations Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250512-sip_svc_upstream-v2-2-fae5c45c059d@altera.com> References: <20250512-sip_svc_upstream-v2-0-fae5c45c059d@altera.com> In-Reply-To: <20250512-sip_svc_upstream-v2-0-fae5c45c059d@altera.com> To: Dinh Nguyen , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Mahesh Rao Cc: Matthew Gerlach , linux-kernel@vger.kernel.org, devicetree@vger.kernel.org X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1747050016; l=6225; i=mahesh.rao@altera.com; s=20250107; h=from:subject:message-id; bh=5FyTpVzGBXpgVnqCoQDLP/cb2s1zL/TKwkYIX3LjCZk=; b=HMc7PJb0YzedCgoO2Wrg+q63J0Z/PgIQJ8cyneJ/uRCPL6spvAaa5Xhcd/I0oduHFqqtZ2nqG Rw07FAA4IjoDbC/wN/2P/3KwVtJEp9evODLYwqKfer4jMUFMgxJhqU6 X-Developer-Key: i=mahesh.rao@altera.com; a=ed25519; pk=tQiFUzoKxHrQLDtWeEeaeTeJTl/UfclUHWZy1fjSiyg= X-Endpoint-Received: by B4 Relay for mahesh.rao@altera.com/20250107 with auth_id=337 X-Original-From: Mahesh Rao Reply-To: mahesh.rao@altera.com From: Mahesh Rao Implement ID pool management API's which will be used for Stratix10 Asynchronous communication with Secure Device Manager. These API's will be used in subsequent patches for ID management in asynchronous operations. Signed-off-by: Mahesh Rao Reviewed-by: Matthew Gerlach --- drivers/firmware/stratix10-svc.c | 191 +++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 191 insertions(+) diff --git a/drivers/firmware/stratix10-svc.c b/drivers/firmware/stratix10-= svc.c index 3d42d4b18b7299d0a9e5110159e06253dfeddf88..f487b6a7ef7b7cf7fdb4b4132d7= a92b601803d8a 100644 --- a/drivers/firmware/stratix10-svc.c +++ b/drivers/firmware/stratix10-svc.c @@ -170,10 +170,201 @@ struct stratix10_svc_chan { spinlock_t lock; }; =20 +/** + * struct stratix10_sip_id_pool - Structure representing a pool of IDs for + * asynchronous operations. + * @head: The head index of the ID pool. + * @size: The total size of the ID pool. + * @id_mask: Pointer to an array representing the mask of allocated I= Ds. + * @lock: Mutex lock to protect access to the ID pool. + */ +struct stratix10_sip_id_pool { + unsigned long head; + unsigned long size; + unsigned long *id_mask; + struct mutex lock; +}; + static LIST_HEAD(svc_ctrl); static LIST_HEAD(svc_data_mem); static DEFINE_MUTEX(svc_mem_lock); =20 +/** + * stratix10_id_pool_create - Create a new ID pool for Stratix10 async ope= ration + * @size: The size of the ID pool to create + * + * This function allocates and initializes a new ID pool structure for + * Stratix10 async operations. It allocates memory for the ID pool structu= re + * and the associated bitmaps for ID management. + * + * Return: Pointer to the newly created ID pool structure, or NULL on fail= ure. + */ +static struct stratix10_sip_id_pool *stratix10_id_pool_create(unsigned lon= g size) +{ + struct stratix10_sip_id_pool *id_pool =3D NULL; + + if (size =3D=3D 0) + return NULL; + + id_pool =3D kzalloc(sizeof(*id_pool), GFP_KERNEL); + if (!id_pool) + return NULL; + + id_pool->size =3D size; + + id_pool->id_mask =3D bitmap_zalloc(size, GFP_KERNEL); + if (!id_pool->id_mask) { + kfree(id_pool); + return NULL; + } + + id_pool->head =3D 0; + + mutex_init(&id_pool->lock); + + return id_pool; +} + +/** + * stratix10_id_pool_destroy - Destroy an ID pool for Stratix10 async oper= ation + * @id_pool: Pointer to the ID pool structure + * + * This function destroys an ID pool for Stratix10 async operations. It fi= rst + * checks if the ID pool is valid, then frees the associated bitmap and the + * ID pool structure itself. + * + * Return: 0 on success, -EINVAL if the ID pool is invalid. + */ +static int stratix10_id_pool_destroy(struct stratix10_sip_id_pool *id_pool) +{ + if (!id_pool) + return -EINVAL; + + mutex_lock(&id_pool->lock); + + if (id_pool->id_mask) + bitmap_free(id_pool->id_mask); + + mutex_unlock(&id_pool->lock); + mutex_destroy(&id_pool->lock); + + kfree(id_pool); + + return 0; +} + +/** + * stratix10_reserve_id - Reserve an ID in the ID pool + * @id_pool: Pointer to the ID pool structure + * @id: The ID to be reserved + * + * This function reserves an ID in the given ID pool. It first checks if t= he + * ID pool is valid and if the ID is within the valid range. + * + * Return: + * 0 on success, + * -EINVAL if the ID pool is invalid, the ID is out of range, or the ID is + * already reserved. + */ +static int stratix10_reserve_id(struct stratix10_sip_id_pool *id_pool, uns= igned long id) +{ + if (!id_pool) + return -EINVAL; + + if (id >=3D id_pool->size) + return -EINVAL; + + mutex_lock(&id_pool->lock); + + if (test_bit(id, id_pool->id_mask)) { + mutex_unlock(&id_pool->lock); + return -EINVAL; + } + set_bit(id, id_pool->id_mask); + + mutex_unlock(&id_pool->lock); + return 0; +} + +/** + * stratix10_allocate_id - Allocate an ID from the ID pool + * @id_pool: Pointer to the ID pool structure + * + * This function allocates an ID from the given ID pool. It searches for t= he + * next available ID in the pool, marks it as allocated, and returns it. + * + * Return: + * A non-negative integer representing the allocated ID on success + * -EINVAL if the id_pool is NULL + * -ENOMEM if no IDs are available in the pool + */ +static int stratix10_allocate_id(struct stratix10_sip_id_pool *id_pool) +{ + unsigned long tries =3D 0; + int id; + + if (!id_pool) + return -EINVAL; + + if (id_pool->head >=3D id_pool->size) + return -ENOMEM; + + mutex_lock(&id_pool->lock); + + do { + id_pool->head =3D find_next_zero_bit(id_pool->id_mask, + id_pool->size, id_pool->head); + if (id_pool->head >=3D id_pool->size) { + id_pool->head =3D 0; + tries++; + } + /* cycle through the whole bitmap at least once*/ + } while (tries < 2 && test_bit(id_pool->head, id_pool->id_mask)); + + if (tries >=3D 2) { + mutex_unlock(&id_pool->lock); + return -ENOMEM; + } + + set_bit(id_pool->head, id_pool->id_mask); + id =3D id_pool->head; + id_pool->head =3D (id_pool->head + 1) % id_pool->size; + mutex_unlock(&id_pool->lock); + return id; +} + +/** + * stratix10_deallocate_id - Deallocate an ID in the ID pool + * @id_pool: Pointer to the ID pool structure + * @id: The ID to be deallocated + * + * This function deallocates an ID in the given ID pool. It first checks i= f the + * ID pool is valid and if the ID is within the valid range. + * + * Return: + * 0 on success, + * -EINVAL if the ID pool is invalid, the ID is out of range, or the ID is + * not set. + */ +static int stratix10_deallocate_id(struct stratix10_sip_id_pool *id_pool, = unsigned long id) +{ + if (!id_pool) + return -EINVAL; + + if (id >=3D id_pool->size) + return -EINVAL; + + mutex_lock(&id_pool->lock); + if (!test_bit(id, id_pool->id_mask)) { + mutex_unlock(&id_pool->lock); + return -EINVAL; + } + clear_bit(id, id_pool->id_mask); + mutex_unlock(&id_pool->lock); + + return 0; +} + /** * svc_pa_to_va() - translate physical address to virtual address * @addr: to be translated physical address --=20 2.35.3 From nobody Mon Feb 9 15:49:04 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 967B529187D; Mon, 12 May 2025 11:40:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747050019; cv=none; b=opx4xwsbB4QdGJftERiwAxqWxq7ShMi8sFhLhBYIUwzAOzpaNX9fl77wiBIuSpH80D5BLzYMsWvluNe5JtpxgXzHaOHAe0trDTUgWrHjN0/3lEjlQQVgmnUuwcqEENhTx24Y8IM0OQ0Hgje9w3JA5GJPqIYNy7y+lKDttoFZjt0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747050019; c=relaxed/simple; bh=mpTtBpToadTUR++68U6PVUrV0GgS9pXERm9BA80Jzfk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=MYZNHDJecxRMleL5GnzRd716l+h8dZ7Pm6Kh34XDg2krYgNQU8wyUZdF3wsBZDfGntP93xiU6Ml5re2+C/NmKtKuYdy+664N87Zb7ZZ+g6dwLFhRFDv7XbG7uYf7pDY/bVlvRsj+Y2SACptUqm6Uu15nxxNE3T3qwK4HLs/WN+o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Xth1hggS; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Xth1hggS" Received: by smtp.kernel.org (Postfix) with ESMTPS id 1C6FAC4CEEF; Mon, 12 May 2025 11:40:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1747050019; bh=mpTtBpToadTUR++68U6PVUrV0GgS9pXERm9BA80Jzfk=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=Xth1hggSLZbpo2FFu+bbuDRjhh1ZlMlIn4BOgpQzWddvhv8LV3sUeZmXzylrvXGrh BXoBxWZC6X48Xz2cXz0tJCBkhQiTKI/zEQQ1B6kiMiAz0BPgM6y4s5wVkgRyO7EWUG STe1j2idjkyC6D7WSrUFY3uUocKEls/5R8tFwgDZK3QEuaxAYcgKlMufapetqa98D0 cmxWJbflBa/Aed7khvWDwXzpHQC7U8Xk59auZltOyWy5scX2Jta3xTacqivLwCUgwQ G4i8GV1kRRfZkDIwvvN6cpzacyG3IVsp5btdZp8ep7SrAZ2hOvH1xYU0CqTbw94nwx y2yF7YmpGkpNQ== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 10671C3ABC3; Mon, 12 May 2025 11:40:19 +0000 (UTC) From: Mahesh Rao via B4 Relay Date: Mon, 12 May 2025 19:39:53 +0800 Subject: [PATCH v2 3/7] firmware: stratix10-svc: Add initial support for asynchronous communication with Stratix 10 service channel Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250512-sip_svc_upstream-v2-3-fae5c45c059d@altera.com> References: <20250512-sip_svc_upstream-v2-0-fae5c45c059d@altera.com> In-Reply-To: <20250512-sip_svc_upstream-v2-0-fae5c45c059d@altera.com> To: Dinh Nguyen , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Mahesh Rao Cc: Matthew Gerlach , linux-kernel@vger.kernel.org, devicetree@vger.kernel.org X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1747050016; l=34685; i=mahesh.rao@altera.com; s=20250107; h=from:subject:message-id; bh=p16xUf4USi6AG8uqn6EV4ct1CZ/lhX5iCuAfglmj83s=; b=9go51Nk+klStYlxvaFaDkovRiXooMzCYDmN2tWJxknvwbNJNdg5SJV/NXiftDQLOPvF9Z87LF XV2uPGi0HDGAH9ApfygWMIhHvokdzc1BgaEjLoW7RzfiT+lmS5TXtVJ X-Developer-Key: i=mahesh.rao@altera.com; a=ed25519; pk=tQiFUzoKxHrQLDtWeEeaeTeJTl/UfclUHWZy1fjSiyg= X-Endpoint-Received: by B4 Relay for mahesh.rao@altera.com/20250107 with auth_id=337 X-Original-From: Mahesh Rao Reply-To: mahesh.rao@altera.com From: Mahesh Rao This commit adds support for asynchronous communication with the Stratix 10 service channel. It introduces new definitions to enable asynchronous messaging to the Secure Device Manager (SDM). The changes include the adding/removing of asynchronous support to existing channels, initializing/exit-cleanup of the new asynchronous framework and sending/polling of messages to SDM. The new public functions added are: - stratix10_svc_add_async_client: Adds an client to the service channel. - stratix10_svc_remove_async_client: Removes an asynchronous client from the service channel. - stratix10_svc_async_send: Sends an asynchronous message to the SDM mailbox in EL3 secure firmware. - stratix10_svc_async_poll: Polls the status of an asynchronous service request in EL3 secure firmware. - stratix10_svc_async_done: Marks an asynchronous transaction as complete and free's up the resources. These changes enhance the functionality of the Stratix 10 service channel by allowing for more efficient and flexible communication with the firmware. Signed-off-by: Mahesh Rao Reviewed-by: Matthew Gerlach --- drivers/firmware/stratix10-svc.c | 646 +++++++++++++++++= +++- include/linux/firmware/intel/stratix10-smc.h | 24 + .../linux/firmware/intel/stratix10-svc-client.h | 88 +++ 3 files changed, 755 insertions(+), 3 deletions(-) diff --git a/drivers/firmware/stratix10-svc.c b/drivers/firmware/stratix10-= svc.c index f487b6a7ef7b7cf7fdb4b4132d7a92b601803d8a..e25493db074930dcc16964fbb42= 7be7168a841e6 100644 --- a/drivers/firmware/stratix10-svc.c +++ b/drivers/firmware/stratix10-svc.c @@ -4,9 +4,11 @@ * Copyright (C) 2025, Altera Corporation */ =20 +#include #include #include #include +#include #include #include #include @@ -44,6 +46,35 @@ #define STRATIX10_RSU "stratix10-rsu" #define INTEL_FCS "intel-fcs" =20 +/*Maximum number of SDM client IDs.*/ +#define MAX_SDM_CLIENT_IDS 16 +/*Client ID for SIP Service Version 1.*/ +#define SIP_SVC_V1_CLIENT_ID 0x1 +/*Maximum number of SDM job IDs.*/ +#define MAX_SDM_JOB_IDS 16 +/*Number of bits used for asynchronous transaction hashing.*/ +#define ASYNC_TRX_HASH_BITS 3 +/*Total number of transactions-id's which is a combination of client id an= d job id.*/ +#define TOTAL_TRANSACTION_IDS (MAX_SDM_CLIENT_IDS * MAX_SDM_JOB_IDS) + +/*Minimum major version of the ATF for Asynchronous transactions.*/ +#define ASYNC_ATF_MINIMUM_MAJOR_VERSION 0x3 +/*Minimum minor version of the ATF for Asynchronous transactions.*/ +#define ASYNC_ATF_MINIMUM_MINOR_VERSION 0x0 + +/*Macro to extract the job ID from a transaction ID.*/ +#define STRATIX10_GET_JOBID(transaction_id) ((transaction_id) & 0xf) +/*Macro to set a transaction ID using a client ID and a transaction ID.*/ +#define STRATIX10_SET_TRANSACTIONID(clientid, transaction_id) \ + ((((clientid) & 0xf) << 4) | ((transaction_id) & 0xf)) + +/* Macro to set a transaction ID for SIP SMC using the lower 8 bits of the= transaction ID.*/ +#define STRATIX10_SIP_SMC_SET_TRANSACTIONID_X1(transaction_id) \ + ((transaction_id) & 0xff) + +/* Macro to get the SDM mailbox error status */ +#define STRATIX10_GET_SDM_STATUS_CODE(status) ((status) & 0x3ff) + typedef void (svc_invoke_fn)(unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, @@ -64,7 +95,7 @@ struct stratix10_svc { * @sync_complete: state for a completion * @addr: physical address of shared memory block * @size: size of shared memory block - * @invoke_fn: function to issue secure monitor or hypervisor call + * @invoke_fn: service clients to handle secure monitor or hypervisor calls * * This struct is used to save physical address and size of shared memory * block. The shared memory blocked is allocated by secure monitor software @@ -122,6 +153,64 @@ struct stratix10_svc_data { u64 arg[3]; }; =20 +/** + * struct stratix10_svc_async_handler - Asynchronous handler for Stratix 1= 0 service layer + * @transaction_id: Unique identifier for the transaction + * @achan: Pointer to the asynchronous channel structure + * @cb_arg: Argument to be passed to the callback function + * @cb: Callback function to be called upon completion + * @msg: Pointer to the client message structure + * @next: Node in the hash list + * + * This structure is used to handle asynchronous transactions in the + * Stratix 10 service layer. It maintains the necessary information + * for processing and completing asynchronous requests. + */ + +struct stratix10_svc_async_handler { + u8 transaction_id; + struct stratix10_async_chan *achan; + void *cb_arg; + async_callback_t cb; + struct stratix10_svc_client_msg *msg; + struct hlist_node next; + struct arm_smccc_1_2_regs res; +}; + +/** + * struct stratix10_async_chan - Structure representing an asynchronous ch= annel + * @async_client_id: Unique client identifier for the asynchronous operati= on + * @job_id_pool: Pointer to the job ID pool associated with this channel + */ + +struct stratix10_async_chan { + unsigned long async_client_id; + struct stratix10_sip_id_pool *job_id_pool; +}; + +/** + * struct stratix10_async_ctrl - Control structure for Stratix 10 asynchro= nous operations + * @initialized: Flag indicating whether the control structure has been in= itialized + * @invoke_fn: Function pointer for invoking Stratix 10 service calls to E= L3 secure firmware + * @async_id_pool: Pointer to the ID pool used for asynchronous operations + * @common_achan_refcount: Atomic reference count for the common asynchron= ous channel usage + * @common_async_chan: Pointer to the common asynchronous channel structure + * @trx_list_wr_lock: Spinlock for protecting the transaction list write o= perations + * @trx_list: Hash table for managing asynchronous transactions + */ + +struct stratix10_async_ctrl { + bool initialized; + void (*invoke_fn)(struct stratix10_async_ctrl *actrl, + const struct arm_smccc_1_2_regs *args, struct arm_smccc_1_2_regs *res= ); + struct stratix10_sip_id_pool *async_id_pool; + atomic_t common_achan_refcount; + struct stratix10_async_chan *common_async_chan; + /* spinlock to protect the writes to trx_list hash table */ + spinlock_t trx_list_wr_lock; + DECLARE_HASHTABLE(trx_list, ASYNC_TRX_HASH_BITS); +}; + /** * struct stratix10_svc_controller - service controller * @dev: device @@ -135,6 +224,7 @@ struct stratix10_svc_data { * @complete_status: state for completion * @svc_fifo_lock: protect access to service message data queue * @invoke_fn: function to issue secure monitor call or hypervisor call + * @actrl: async control structure * * This struct is used to create communication channels for service client= s, to * handle secure monitor or hypervisor call. @@ -151,6 +241,7 @@ struct stratix10_svc_controller { struct completion complete_status; spinlock_t svc_fifo_lock; svc_invoke_fn *invoke_fn; + struct stratix10_async_ctrl actrl; }; =20 /** @@ -159,15 +250,17 @@ struct stratix10_svc_controller { * @scl: pointer to service client which owns the channel * @name: service client name associated with the channel * @lock: protect access to the channel + * @async_chan: reference to asynchronous channel object for this channel * - * This struct is used by service client to communicate with service layer= , each - * service client has its own channel created by service controller. + * This struct is used by service client to communicate with service layer. + * Each service client has its own channel created by service controller. */ struct stratix10_svc_chan { struct stratix10_svc_controller *ctrl; struct stratix10_svc_client *scl; char *name; spinlock_t lock; + struct stratix10_async_chan *async_chan; }; =20 /** @@ -1118,6 +1211,546 @@ struct stratix10_svc_chan *stratix10_svc_request_ch= annel_byname( } EXPORT_SYMBOL_GPL(stratix10_svc_request_channel_byname); =20 +/** + * stratix10_svc_add_async_client - Add an asynchronous client to the Stra= tix10 service channel. + * @chan: Pointer to the Stratix10 service channel structure. + * @use_unique_clientid: Boolean flag indicating whether to use a unique c= lient ID. + * + * This function adds an asynchronous client to the specified Stratix10 se= rvice channel. + * If the `use_unique_clientid` flag is set to true, a unique client ID is= allocated for + * the asynchronous channel. Otherwise, a common asynchronous channel is u= sed. + * + * Return: 0 on success, or a negative error code on failure: + * -EINVAL if the channel is NULL or the async controller is not i= nitialized. + * -EALREADY if the async channel is already allocated. + * -ENOMEM if memory allocation fails. + * Other negative values if ID allocation fails. + */ +int stratix10_svc_add_async_client(struct stratix10_svc_chan *chan, + bool use_unique_clientid) +{ + int ret =3D 0; + struct stratix10_async_chan *achan; + + if (!chan) + return -EINVAL; + + struct stratix10_svc_controller *ctrl =3D chan->ctrl; + struct stratix10_async_ctrl *actrl =3D &ctrl->actrl; + + if (!actrl->initialized) { + dev_err(ctrl->dev, "Async controller not initialized\n"); + return -EINVAL; + } + + if (chan->async_chan) { + dev_err(ctrl->dev, "async channel already allocated\n"); + return -EALREADY; + } + + if (use_unique_clientid) { + achan =3D kzalloc(sizeof(*achan), GFP_KERNEL); + if (!achan) + return -ENOMEM; + + achan->job_id_pool =3D stratix10_id_pool_create(MAX_SDM_JOB_IDS); + if (!achan->job_id_pool) { + dev_err(ctrl->dev, "Failed to create job id pool\n"); + kfree(achan); + return -ENOMEM; + } + + ret =3D stratix10_allocate_id(actrl->async_id_pool); + if (ret < 0) { + dev_err(ctrl->dev, + "Failed to allocate async client id\n"); + stratix10_id_pool_destroy(achan->job_id_pool); + kfree(achan); + return ret; + } + achan->async_client_id =3D ret; + chan->async_chan =3D achan; + } else { + if (atomic_read(&actrl->common_achan_refcount) =3D=3D 0) { + achan =3D kzalloc(sizeof(*achan), GFP_KERNEL); + if (!achan) + return -ENOMEM; + + achan->job_id_pool =3D + stratix10_id_pool_create(MAX_SDM_JOB_IDS); + if (!achan->job_id_pool) { + dev_err(ctrl->dev, + "Failed to create job id pool\n"); + kfree(achan); + return -ENOMEM; + } + + ret =3D stratix10_allocate_id(actrl->async_id_pool); + if (ret < 0) { + dev_err(ctrl->dev, + "Failed to allocate async client id\n"); + stratix10_id_pool_destroy(achan->job_id_pool); + kfree(achan); + return ret; + } + achan->async_client_id =3D ret; + actrl->common_async_chan =3D achan; + dev_info(ctrl->dev, + "Common async channel allocated with id %ld\n", + achan->async_client_id); + } + chan->async_chan =3D actrl->common_async_chan; + atomic_inc(&actrl->common_achan_refcount); + } + + return 0; +} +EXPORT_SYMBOL_GPL(stratix10_svc_add_async_client); + +/** + * stratix10_svc_remove_async_client - Remove an asynchronous client from + * the Stratix10 service channel. + * @chan: Pointer to the Stratix10 service channel structure. + * + * This function removes an asynchronous client associated with the given = service channel. + * It checks if the channel and the asynchronous channel are valid, and th= en proceeds to + * decrement the reference count for the common asynchronous channel if ap= plicable. If the + * reference count reaches zero, it destroys the job ID pool and deallocat= es the asynchronous + * client ID. For non-common asynchronous channels, it directly destroys t= he job ID pool, + * deallocates the asynchronous client ID, and frees the memory allocated = for the asynchronous + * channel. + * + * Return: 0 on success, -EINVAL if the channel or asynchronous channel is= invalid. + */ +int stratix10_svc_remove_async_client(struct stratix10_svc_chan *chan) +{ + if (!chan) + return -EINVAL; + + struct stratix10_svc_controller *ctrl =3D chan->ctrl; + struct stratix10_async_ctrl *actrl =3D &ctrl->actrl; + struct stratix10_async_chan *achan =3D chan->async_chan; + + if (!achan) { + dev_err(ctrl->dev, "async channel not allocated\n"); + return -EINVAL; + } + + if (achan =3D=3D actrl->common_async_chan) { + atomic_dec(&actrl->common_achan_refcount); + if (atomic_read(&actrl->common_achan_refcount) =3D=3D 0) { + stratix10_id_pool_destroy(achan->job_id_pool); + stratix10_deallocate_id(actrl->async_id_pool, achan->async_client_id); + } + } else { + stratix10_id_pool_destroy(achan->job_id_pool); + stratix10_deallocate_id(actrl->async_id_pool, achan->async_client_id); + kfree(achan); + } + chan->async_chan =3D NULL; + + return 0; +} +EXPORT_SYMBOL_GPL(stratix10_svc_remove_async_client); + +/** + * stratix10_svc_async_send - Send an asynchronous message to the Stratix1= 0 service + * @chan: Pointer to the service channel structure + * @msg: Pointer to the message to be sent + * @handler: Pointer to the handler for the asynchronous message used by c= aller for later reference. + * @cb: Callback function to be called upon completion + * @cb_arg: Argument to be passed to the callback function + * + * This function sends an asynchronous message to the SDM mailbox in EL3 s= ecure + * firmware. It performs various checks and setups, including allocating a= job ID, + * setting up the transaction ID and packaging it to El3 firmware. + * The function handles different commands by setting up the appropriate + * arguments for the SMC call. If the SMC call is successful, the handler + * is set up and the function returns 0. If the SMC call fails, appropriate + * error handling is performed along with cleanup of resources. + * + * Return: 0 on success,-EINVAL for invalid argument,-ENOMEM if memory is = not available, + * -EAGAIN if EL3 firmware is busy, -EBADF if the message is rejec= ted + * by EL3 firmware and -EIO on ther errors from EL3 firmware. + */ +int stratix10_svc_async_send(struct stratix10_svc_chan *chan, void *msg, v= oid **handler, + async_callback_t cb, void *cb_arg) +{ + struct stratix10_svc_client_msg *p_msg =3D (struct stratix10_svc_client_m= sg *)msg; + struct arm_smccc_1_2_regs args =3D { 0 }, res =3D { 0 }; + struct stratix10_svc_async_handler *handle =3D NULL; + int ret =3D 0; + + if (!chan || !msg || !handler) + return -EINVAL; + + struct stratix10_async_chan *achan =3D chan->async_chan; + struct stratix10_svc_controller *ctrl =3D chan->ctrl; + struct stratix10_async_ctrl *actrl =3D &ctrl->actrl; + + if (!actrl->initialized) { + dev_err(ctrl->dev, "Async controller not initialized\n"); + return -EINVAL; + } + + if (!achan) { + dev_err(ctrl->dev, "Async channel not allocated\n"); + return -EINVAL; + } + + handle =3D + kzalloc(sizeof(struct stratix10_svc_async_handler), GFP_KERNEL); + if (!handle) + return -ENOMEM; + + ret =3D stratix10_allocate_id(achan->job_id_pool); + if (ret < 0) { + dev_err(ctrl->dev, "Failed to allocate job id\n"); + kfree(handle); + return -ENOMEM; + } + + handle->transaction_id =3D + STRATIX10_SET_TRANSACTIONID(achan->async_client_id, ret); + handle->cb =3D cb; + handle->msg =3D p_msg; + handle->cb_arg =3D cb_arg; + handle->achan =3D achan; + + /*set the transaction jobid in args.a1*/ + args.a1 =3D + STRATIX10_SIP_SMC_SET_TRANSACTIONID_X1(handle->transaction_id); + + switch (p_msg->command) { + default: + dev_err(ctrl->dev, "Invalid command ,%d\n", p_msg->command); + ret =3D -EINVAL; + goto deallocate_id; + } + + /** + * There is a chance that during the execution of async_send() in one cor= e, + * an interrupt might be received in another core; to mitigate this we are + * adding the handle to the DB and then send the smc call. If the smc call + * is rejected or busy then we will deallocate the handle for the client + * to retry again. + */ + spin_lock(&actrl->trx_list_wr_lock); + hash_add_rcu(actrl->trx_list, &handle->next, handle->transaction_id); + spin_unlock(&actrl->trx_list_wr_lock); + synchronize_rcu(); + + actrl->invoke_fn(actrl, &args, &res); + + switch (res.a0) { + case INTEL_SIP_SMC_STATUS_OK: + dev_dbg(ctrl->dev, + "Async message sent with transaction_id 0x%02x\n", + handle->transaction_id); + *handler =3D handle; + return 0; + case INTEL_SIP_SMC_STATUS_BUSY: + dev_warn(ctrl->dev, "Mailbox is busy, try after some time\n"); + ret =3D -EAGAIN; + break; + case INTEL_SIP_SMC_STATUS_REJECTED: + dev_err(ctrl->dev, "Async message rejected\n"); + ret =3D -EBADF; + break; + default: + dev_err(ctrl->dev, + "Failed to send async message ,got status as %ld\n", + res.a0); + ret =3D -EIO; + } + + spin_lock(&actrl->trx_list_wr_lock); + hash_del_rcu(&handle->next); + spin_unlock(&actrl->trx_list_wr_lock); + synchronize_rcu(); + +deallocate_id: + stratix10_deallocate_id(achan->job_id_pool, + STRATIX10_GET_JOBID(handle->transaction_id)); + kfree(handle); + return ret; +} +EXPORT_SYMBOL_GPL(stratix10_svc_async_send); + +/** + * stratix10_svc_async_prepare_response - Prepare the response data for an= asynchronous transaction. + * @chan: Pointer to the service channel structure. + * @handle: Pointer to the asynchronous handler structure. + * @data: Pointer to the callback data structure. + * + * This function prepares the response data for an asynchronous transactio= n. It + * extracts the response data from the SMC response structure and stores i= t in + * the callback data structure. The function also logs the completion of t= he + * asynchronous transaction. + * + * Return: 0 on success, -ENOENT if the command is invalid + */ +static int stratix10_svc_async_prepare_response(struct stratix10_svc_chan = *chan, + struct stratix10_svc_async_handler *handle, + struct stratix10_svc_cb_data *data) +{ + struct stratix10_svc_client_msg *p_msg =3D + (struct stratix10_svc_client_msg *)handle->msg; + struct stratix10_svc_controller *ctrl =3D chan->ctrl; + + data->status =3D STRATIX10_GET_SDM_STATUS_CODE(handle->res.a1); + + switch (p_msg->command) { + default: + dev_alert(ctrl->dev, "Invalid command\n ,%d", p_msg->command); + return -ENOENT; + } + dev_dbg(ctrl->dev, "Async message completed transaction_id 0x%02x\n", + handle->transaction_id); + return 0; +} + +/** + * stratix10_svc_async_poll - Polls the status of an asynchronous transact= ion. + * @chan: Pointer to the service channel structure. + * @tx_handle: Handle to the transaction being polled. + * @data: Pointer to the callback data structure. + * + * This function polls the status of an asynchronous transaction identifie= d by the + * given transaction handle. It ensures that the necessary structures are = initialized + * and valid before proceeding with the poll operation. The function sets = up the + * necessary arguments for the SMC call, invokes the call, and prepares th= e response + * data if the call is successful. If the call fails, the function returns + * the error mapped the SVC status error. + * + * Return: 0 on success, -EINVAL if any input parameter is invalid, -EAGAI= N if the + * transaction is still in progress,-EPERM if the command is inval= id. + * or other negative error codes on failure. + */ +int stratix10_svc_async_poll(struct stratix10_svc_chan *chan, void *tx_han= dle, + struct stratix10_svc_cb_data *data) +{ + int ret; + struct arm_smccc_1_2_regs args =3D { 0 }; + + if (!chan || !tx_handle || !data) + return -EINVAL; + + struct stratix10_svc_controller *ctrl =3D chan->ctrl; + struct stratix10_async_ctrl *actrl =3D &ctrl->actrl; + struct stratix10_async_chan *achan =3D chan->async_chan; + + if (!achan) { + dev_err(ctrl->dev, "Async channel not allocated\n"); + return -EINVAL; + } + + struct stratix10_svc_async_handler *handle =3D + (struct stratix10_svc_async_handler *)tx_handle; + if (!hash_hashed(&handle->next)) { + dev_err(ctrl->dev, "Invalid transaction handler\n"); + return -EINVAL; + } + + args.a0 =3D INTEL_SIP_SMC_ASYNC_POLL; + args.a1 =3D + STRATIX10_SIP_SMC_SET_TRANSACTIONID_X1(handle->transaction_id); + + actrl->invoke_fn(actrl, &args, &handle->res); + + data->status =3D 0; + if (handle->res.a0 =3D=3D INTEL_SIP_SMC_STATUS_OK) { + ret =3D stratix10_svc_async_prepare_response(chan, handle, data); + if (ret) { + dev_err(ctrl->dev, "Error in preparation of response,%d\n", ret); + WARN_ON_ONCE(1); + } + return 0; + } else if (handle->res.a0 =3D=3D INTEL_SIP_SMC_STATUS_BUSY) { + dev_dbg(ctrl->dev, "async message is still in progress\n"); + return -EAGAIN; + } + + dev_err(ctrl->dev, + "Failed to poll async message ,got status as %ld\n", + handle->res.a0); + return -EINVAL; +} +EXPORT_SYMBOL_GPL(stratix10_svc_async_poll); + +/** + * stratix10_svc_async_done - Completes an asynchronous transaction. + * @chan: Pointer to the service channel structure. + * @tx_handle: Handle to the transaction being completed. + * + * This function completes an asynchronous transaction identified by the g= iven + * transaction handle. It ensures that the necessary structures are initia= lized + * and valid before proceeding with the completion operation. The function + * deallocates the transaction ID, frees the memory allocated for the hand= ler, + * and removes the handler from the transaction list. + * + * Return: 0 on success, -EINVAL if any input parameter is invalid, or oth= er + * negative error codes on failure. + */ +int stratix10_svc_async_done(struct stratix10_svc_chan *chan, void *tx_han= dle) +{ + if (!chan || !tx_handle) + return -EINVAL; + + struct stratix10_svc_controller *ctrl =3D chan->ctrl; + struct stratix10_async_chan *achan =3D chan->async_chan; + + if (!achan) { + dev_err(ctrl->dev, "async channel not allocated\n"); + return -EINVAL; + } + + struct stratix10_svc_async_handler *handle =3D + (struct stratix10_svc_async_handler *)tx_handle; + if (!hash_hashed(&handle->next)) { + dev_err(ctrl->dev, "Invalid transaction handle\n"); + return -EINVAL; + } + + struct stratix10_async_ctrl *actrl =3D &ctrl->actrl; + + spin_lock(&actrl->trx_list_wr_lock); + hash_del_rcu(&handle->next); + spin_unlock(&actrl->trx_list_wr_lock); + synchronize_rcu(); + stratix10_deallocate_id(achan->job_id_pool, + STRATIX10_GET_JOBID(handle->transaction_id)); + kfree(handle); + return 0; +} +EXPORT_SYMBOL_GPL(stratix10_svc_async_done); + +static inline void stratix10_smc_1_2(struct stratix10_async_ctrl *actrl, + const struct arm_smccc_1_2_regs *args, + struct arm_smccc_1_2_regs *res) +{ + arm_smccc_1_2_smc(args, res); +} + +/** + * stratix10_svc_async_init - Initialize the Stratix 10 service controller + * for asynchronous operations. + * @controller: Pointer to the Stratix 10 service controller structure. + * + * This function initializes the asynchronous service controller by settin= g up + * the necessary data structures, initializing the transaction list, and + * + * Return: 0 on success, -EINVAL if the controller is NULL or already init= ialized, + * -ENOMEM if memory allocation fails, -EADDRINUSE if the client I= D is already + * reserved, or other negative error codes on failure. + */ +static int stratix10_svc_async_init(struct stratix10_svc_controller *contr= oller) +{ + int ret; + struct arm_smccc_res res; + + if (!controller) + return -EINVAL; + + struct stratix10_async_ctrl *actrl =3D &controller->actrl; + + if (actrl->initialized) + return -EINVAL; + + struct device *dev =3D controller->dev; + + controller->invoke_fn(INTEL_SIP_SMC_SVC_VERSION, 0, 0, 0, 0, 0, 0, 0, &re= s); + if (res.a0 !=3D INTEL_SIP_SMC_STATUS_OK && + !(res.a1 > ASYNC_ATF_MINIMUM_MAJOR_VERSION || + (res.a1 =3D=3D ASYNC_ATF_MINIMUM_MAJOR_VERSION && + res.a2 >=3D ASYNC_ATF_MINIMUM_MINOR_VERSION))) { + dev_err(dev, + "Intel Service Layer Driver: ATF version is not compatible for async op= eration\n"); + return -EINVAL; + } + + actrl->invoke_fn =3D stratix10_smc_1_2; + + actrl->async_id_pool =3D stratix10_id_pool_create(MAX_SDM_CLIENT_IDS); + if (!actrl->async_id_pool) + return -ENOMEM; + + /** + * SIP_SVC_V1_CLIENT_ID is used by V1 clients/stratix10_svc_send() + * for communicating with SDM synchronously. We need to restrict this + * in V3 usage to distinguish the V1 and V3 messages in El3 firmware. + */ + ret =3D stratix10_reserve_id(actrl->async_id_pool, SIP_SVC_V1_CLIENT_ID); + if (ret < 0) { + dev_err(dev, + "Intel Service Layer Driver: Error on reserving SIP_SVC_V1_CLIENT_ID\n"= ); + stratix10_id_pool_destroy(actrl->async_id_pool); + actrl->invoke_fn =3D NULL; + return -EADDRINUSE; + } + + spin_lock_init(&actrl->trx_list_wr_lock); + hash_init(actrl->trx_list); + atomic_set(&actrl->common_achan_refcount, 0); + + actrl->initialized =3D true; + return 0; +} + +/** + * stratix10_svc_async_exit - Clean up and exit the asynchronous service c= ontroller + * @ctrl: Pointer to the stratix10_svc_controller structure + * + * This function performs the necessary cleanup for the asynchronous servi= ce + * controller. It checks if the controller is valid and if it has been + * initialized. If the controller has an IRQ assigned, it frees the IRQ and + * flushes any pending asynchronous work. It then locks the transaction li= st + * and safely removes and deallocates each handler in the list. The functi= on + * also removes any asynchronous clients associated with the controller's + * channels and destroys the asynchronous ID pool. Finally, it resets the + * asynchronous ID pool and invoke function pointers to NULL. + * + * Return: 0 on success, -EINVAL if the controller is invalid or not initi= alized. + */ +static int stratix10_svc_async_exit(struct stratix10_svc_controller *ctrl) +{ + int i; + struct hlist_node *tmp; + struct stratix10_svc_async_handler *handler; + + if (!ctrl) + return -EINVAL; + + struct stratix10_async_ctrl *actrl =3D &ctrl->actrl; + + if (!actrl->initialized) + return -EINVAL; + + actrl->initialized =3D false; + + spin_lock(&actrl->trx_list_wr_lock); + hash_for_each_safe(actrl->trx_list, i, tmp, handler, next) { + stratix10_deallocate_id(handler->achan->job_id_pool, + STRATIX10_GET_JOBID(handler->transaction_id)); + hash_del_rcu(&handler->next); + kfree(handler); + } + spin_unlock(&actrl->trx_list_wr_lock); + + for (i =3D 0; i < SVC_NUM_CHANNEL; i++) { + if (ctrl->chans[i].async_chan) { + stratix10_svc_remove_async_client(&ctrl->chans[i]); + ctrl->chans[i].async_chan =3D NULL; + } + } + + stratix10_id_pool_destroy(actrl->async_id_pool); + actrl->async_id_pool =3D NULL; + actrl->invoke_fn =3D NULL; + + return 0; +} + /** * stratix10_svc_free_channel() - free service channel * @chan: service channel to be freed @@ -1380,6 +2013,11 @@ static int stratix10_svc_drv_probe(struct platform_d= evice *pdev) controller->invoke_fn =3D invoke_fn; init_completion(&controller->complete_status); =20 + ret =3D stratix10_svc_async_init(controller); + if (ret) + dev_dbg(dev, "Intel Service Layer Driver: Error on stratix10_svc_async_i= nit %d\n", + ret); + fifo_size =3D sizeof(struct stratix10_svc_data) * SVC_NUM_DATA_IN_FIFO; ret =3D kfifo_alloc(&controller->svc_fifo, fifo_size, GFP_KERNEL); if (ret) { @@ -1465,6 +2103,8 @@ static void stratix10_svc_drv_remove(struct platform_= device *pdev) struct stratix10_svc *svc =3D dev_get_drvdata(&pdev->dev); struct stratix10_svc_controller *ctrl =3D platform_get_drvdata(pdev); =20 + stratix10_svc_async_exit(ctrl); + of_platform_depopulate(ctrl->dev); =20 platform_device_unregister(svc->intel_svc_fcs); diff --git a/include/linux/firmware/intel/stratix10-smc.h b/include/linux/f= irmware/intel/stratix10-smc.h index ee80ca4bb0d0c6d3aa99aeeca6a4980a315dcc43..c98ed992d23bed5aa344868ca0c= 77a2d19d94c06 100644 --- a/include/linux/firmware/intel/stratix10-smc.h +++ b/include/linux/firmware/intel/stratix10-smc.h @@ -1,6 +1,7 @@ /* SPDX-License-Identifier: GPL-2.0 */ /* * Copyright (C) 2017-2018, Intel Corporation + * Copyright (C) 2025, Altera Corporation */ =20 #ifndef __STRATIX10_SMC_H @@ -47,6 +48,10 @@ ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, ARM_SMCCC_SMC_64, \ ARM_SMCCC_OWNER_SIP, (func_num)) =20 +#define INTEL_SIP_SMC_ASYNC_VAL(func_name) \ + ARM_SMCCC_CALL_VAL(ARM_SMCCC_STD_CALL, ARM_SMCCC_SMC_64, \ + ARM_SMCCC_OWNER_SIP, (func_name)) + /** * Return values in INTEL_SIP_SMC_* call * @@ -620,4 +625,23 @@ INTEL_SIP_SMC_FAST_CALL_VAL(INTEL_SIP_SMC_FUNCID_FPGA_= CONFIG_COMPLETED_WRITE) #define INTEL_SIP_SMC_FCS_GET_PROVISION_DATA \ INTEL_SIP_SMC_FAST_CALL_VAL(INTEL_SIP_SMC_FUNCID_FCS_GET_PROVISION_DATA) =20 +/** + * Request INTEL_SIP_SMC_ASYNC_POLL + * Async call used by service driver at EL1 to query mailbox response from= SDM. + * + * Call register usage: + * a0 INTEL_SIP_SMC_ASYNC_POLL + * a1 transaction job id + * a2-17 will be used to return the response data + * + * Return status + * a0 INTEL_SIP_SMC_STATUS_OK + * a1-17 will contain the response values from mailbox for the previous se= nd transaction + * Or + * a0 INTEL_SIP_SMC_STATUS_NO_RESPONSE + * a1-17 not used + */ +#define INTEL_SIP_SMC_ASYNC_FUNC_ID_POLL (0xC8) +#define INTEL_SIP_SMC_ASYNC_POLL \ + INTEL_SIP_SMC_ASYNC_VAL(INTEL_SIP_SMC_ASYNC_FUNC_ID_POLL) #endif diff --git a/include/linux/firmware/intel/stratix10-svc-client.h b/include/= linux/firmware/intel/stratix10-svc-client.h index 60ed82112680e3674b6b7e9852d315922ffff33e..bda837815bae35fbf4df6280dba= 5bc02d747426e 100644 --- a/include/linux/firmware/intel/stratix10-svc-client.h +++ b/include/linux/firmware/intel/stratix10-svc-client.h @@ -1,6 +1,7 @@ /* SPDX-License-Identifier: GPL-2.0 */ /* * Copyright (C) 2017-2018, Intel Corporation + * Copyright (C) 2025, Altera Corporation */ =20 #ifndef __STRATIX10_SVC_CLIENT_H @@ -284,5 +285,92 @@ int stratix10_svc_send(struct stratix10_svc_chan *chan= , void *msg); * request process. */ void stratix10_svc_done(struct stratix10_svc_chan *chan); + +/** + * typedef async_callback_t - A type definition for an asynchronous callba= ck function. + * + * This type defines a function pointer for an asynchronous callback. + * The callback function takes a single argument, which is a pointer to + * user-defined data. + * + * @param cb_arg A pointer to user-defined data passed to the callback fun= ction. + */ +typedef void (*async_callback_t)(void *cb_arg); + +/** + * stratix10_svc_add_async_client - Add an asynchronous client to a Strati= x 10 + * service channel. + * @chan: Pointer to the Stratix 10 service channel structure. + * @use_unique_clientid: Boolean flag indicating whether to use a unique c= lient ID. + * + * This function registers an asynchronous client with the specified Strat= ix 10 + * service channel. If the use_unique_clientid flag is set to true, a uniq= ue client + * ID will be assigned to the client. + * + * Return: 0 on success, or a negative error code on failure: + * -EINVAL if the channel is NULL or the async controller is not i= nitialized. + * -EALREADY if the async channel is already allocated. + * -ENOMEM if memory allocation fails. + * Other negative values if ID allocation fails + */ +int stratix10_svc_add_async_client(struct stratix10_svc_chan *chan, bool u= se_unique_clientid); + +/** + * stratix10_svc_remove_async_client - Remove an asynchronous client from = the Stratix 10 + * service channel. + * @chan: Pointer to the Stratix 10 service channel structure. + * + * This function removes an asynchronous client from the specified Stratix= 10 service channel. + * It is typically used to clean up and release resources associated with = the client. + * + * Return: 0 on success, -EINVAL if the channel or asynchronous channel is= invalid. + */ +int stratix10_svc_remove_async_client(struct stratix10_svc_chan *chan); + +/** + * stratix10_svc_async_send - Send an asynchronous message to the SDM mail= box + * in EL3 secure firmware. + * @chan: Pointer to the service channel structure. + * @msg: Pointer to the message to be sent. + * @handler: Pointer to the handler object used by caller to track the tra= nsaction. + * @cb: Callback function to be called upon completion. + * @cb_arg: Argument to be passed to the callback function. + * + * This function sends a message asynchronously to the SDM mailbox in EL3 = secure firmware. + * and registers a callback function to be invoked when the operation comp= letes. + * + * Return: 0 on success,and negative error codes on failure. + */ +int stratix10_svc_async_send(struct stratix10_svc_chan *chan, void *msg, v= oid **handler, + async_callback_t cb, void *cb_arg); + +/** + * stratix10_svc_async_poll - Polls the status of an asynchronous service = request. + * @chan: Pointer to the service channel structure. + * @tx_handle: Handle to the transaction being polled. + * @data: Pointer to the callback data structure to be filled with the res= ult. + * + * This function checks the status of an asynchronous service request + * and fills the provided callback data structure with the result. + * + * Return: 0 on success, -EINVAL if any input parameter is invalid or if t= he + * async controller is not initialized, -EAGAIN if the transaction= is + * still in progress, or other negative error codes on failure. + */ +int stratix10_svc_async_poll(struct stratix10_svc_chan *chan, void *tx_han= dle, + struct stratix10_svc_cb_data *data); + +/** + * stratix10_svc_async_done - Complete an asynchronous transaction + * @chan: Pointer to the service channel structure + * @tx_handle: Pointer to the transaction handle + * + * This function completes an asynchronous transaction by removing the + * transaction from the hash table and deallocating the associated resourc= es. + * + * Return: 0 on success, -EINVAL on invalid input or errors. + */ +int stratix10_svc_async_done(struct stratix10_svc_chan *chan, void *tx_han= dle); + #endif =20 --=20 2.35.3 From nobody Mon Feb 9 15:49:04 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 96822292080; Mon, 12 May 2025 11:40:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747050019; cv=none; b=tWRfplfiN21/sBY1AbVVSI3XNfmisPzM/z1SzfDTavUIbDrBeQHI1fpHCutUKVQPWCJRQ6gDEzRLt1CR5dHgsuA+SryZalpvtSHh2ps96b1Cf2iuMmjV/aNYTj7Nk4jjZvVRQ4D+laZBEuZ1aD9EAm7KyaGiFR1zaOGSox/OUE0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747050019; c=relaxed/simple; bh=CLMpKrTrD+1F6YeWwuDcqlirxHopHnUHK3PKeL3Qewc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=iv8bk4JrUEzBrM61tJQ8f7QCmugf417f6tQWssksfiwzP7XUCmCA/8WdPFh3ocz7NktX31g6CaQIaug9BJQ7Ko5O+X/tT+BcMhg9IxcpSzjIEXLiGbJLKY56aqhSzXaZEFgNgnxVv6AmwNdACcj9msMSIEWtlVokjBZv6y8mlyk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=jUYrYvoM; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="jUYrYvoM" Received: by smtp.kernel.org (Postfix) with ESMTPS id 29A51C4CEF7; Mon, 12 May 2025 11:40:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1747050019; bh=CLMpKrTrD+1F6YeWwuDcqlirxHopHnUHK3PKeL3Qewc=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=jUYrYvoMl5raBTYUl5TA+QGdRDcbX5/lrjmTMSOMcJTvxOs3Wnl3fwQZia5teMhu2 0byE8YfwMaam2kYcB4BS/QkF2fXIXX0GZEHWgdEv/Sv/Q0zOOrBEWiO1Up7PIEp2Ek B4oD70ibqHgBpEBqt+5g1SYNHNaDMLddS1ervcKOHeX4VfvWqOEVLYdTOVHW7g7z3J 2zhM8UWbaF+vKnHiYLAS6uwzeGZ+z7Hhkki0nQA6EzSBjs1Y1gFUoaJKl5Ntwje1zU mDJ+zNKY1pJRooT1UNYDofP1uH8UMB8uq01DLo7sIGc0FYv3voW6GTAx727w2tK9+A ifCMgnK81vxiA== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1D54EC3ABD4; Mon, 12 May 2025 11:40:19 +0000 (UTC) From: Mahesh Rao via B4 Relay Date: Mon, 12 May 2025 19:39:54 +0800 Subject: [PATCH v2 4/7] dt-bindings: firmware: Add interrupt specification for Intel Stratix 10 Service Layer. Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250512-sip_svc_upstream-v2-4-fae5c45c059d@altera.com> References: <20250512-sip_svc_upstream-v2-0-fae5c45c059d@altera.com> In-Reply-To: <20250512-sip_svc_upstream-v2-0-fae5c45c059d@altera.com> To: Dinh Nguyen , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Mahesh Rao Cc: Matthew Gerlach , linux-kernel@vger.kernel.org, devicetree@vger.kernel.org X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1747050016; l=1851; i=mahesh.rao@altera.com; s=20250107; h=from:subject:message-id; bh=AOemBCgdL+N65O4/Not6GZwfFLWHmbGOTOms8z2w2Jo=; b=BV5ewUJ5op6igt7FS8Q7vHHWVKc+xb+Cc0CLiZvtsc4/zyaXufjOyi4UfKNyh0yyXsZplvwKF Wr0tKCNSc8XBl3I/dk99nteZ2+xM0mJwYhjorSbIrINFuhcYZD8HSNx X-Developer-Key: i=mahesh.rao@altera.com; a=ed25519; pk=tQiFUzoKxHrQLDtWeEeaeTeJTl/UfclUHWZy1fjSiyg= X-Endpoint-Received: by B4 Relay for mahesh.rao@altera.com/20250107 with auth_id=337 X-Original-From: Mahesh Rao Reply-To: mahesh.rao@altera.com From: Mahesh Rao Add interrupt specification for Intel Stratix10 Service layer for asynchronous communication. Reviewed-by: Matthew Gerlach Reviewed-by: Rob Herring (Arm) Signed-off-by: Mahesh Rao --- .../devicetree/bindings/firmware/intel,stratix10-svc.yaml | 10 ++++++= ++++ 1 file changed, 10 insertions(+) diff --git a/Documentation/devicetree/bindings/firmware/intel,stratix10-svc= .yaml b/Documentation/devicetree/bindings/firmware/intel,stratix10-svc.yaml index fac1e955852e4f9b966c991dcfac56222c5f7315..656cc50fd08217f270f95ae3901= 0152423315ed1 100644 --- a/Documentation/devicetree/bindings/firmware/intel,stratix10-svc.yaml +++ b/Documentation/devicetree/bindings/firmware/intel,stratix10-svc.yaml @@ -54,6 +54,12 @@ properties: reserved memory region for the service layer driver to communicate with the secure device manager. =20 + interrupts: + maxItems: 1 + description: + This interrupt is used by the Secure Device Manager (SDM) to signal + completion of an asynchronous operation to service layer driver. + fpga-mgr: $ref: /schemas/fpga/intel,stratix10-soc-fpga-mgr.yaml description: Optional child node for fpga manager to perform fabric co= nfiguration. @@ -67,6 +73,8 @@ additionalProperties: false =20 examples: - | + #include + reserved-memory { #address-cells =3D <2>; #size-cells =3D <2>; @@ -84,6 +92,8 @@ examples: compatible =3D "intel,stratix10-svc"; method =3D "smc"; memory-region =3D <&service_reserved>; + interrupts =3D ; + interrupt-parent =3D <&intc0>; =20 fpga-mgr { compatible =3D "intel,stratix10-soc-fpga-mgr"; --=20 2.35.3 From nobody Mon Feb 9 15:49:04 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B44CE2920A1; Mon, 12 May 2025 11:40:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747050019; cv=none; b=eAvxyKjrUKa4X2wY9dY8JYAPU4M3WghTeJqsdTvCAJqQSSed1Lsk1AT/Alxt8wFs33N5J9K9NkjC/J8KptQXD2oq8xB0PY1oix8r75RRUZQHLucCkS0TVZGGZfYwWbioGHKJYMh91pW4FWumdTZTRCvdaOaQzIG8PQDxS0fRMBg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747050019; c=relaxed/simple; bh=zT77NuhIoGQABDi8akJqR9yK5e3XaT0TZe2nPOp+CyU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=b48zlHDg7xmc+wI+6Fz1SAwmb+jUqagnQrgNPrZTeJlFMgBSF+7t1tnFS7d8Kk/JIETqlvNG5g7fBfPTzevtR7OevRsVwkktFDU1eGNDmZZontf78rx4imze6ZYQU0JAt7z1s73wA9XeNV6mWKjcSQz2y1qyDBfDhim4+zwDXgg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Yk9Nr00R; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Yk9Nr00R" Received: by smtp.kernel.org (Postfix) with ESMTPS id 33658C4CEF9; Mon, 12 May 2025 11:40:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1747050019; bh=zT77NuhIoGQABDi8akJqR9yK5e3XaT0TZe2nPOp+CyU=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=Yk9Nr00RrBA37y9Mvhy1YGZmJIuA0kgHYvG9SrEJijCM3/MqpGXkPoN/YeX4gp9FV 0K3gM5QAHwkHcpLnECUTh9raldv23Kq5yFEyDbLGDageDdkYKv7ufjpcI81xHzTWq9 DromQt9DzjOdLTWrwlSUdD0Lv14qpXmBqNrFCF4iF4Vao5H+7izW6FiHlFPMPigoQ5 +KQSX+HMbMgDn8htlqLikK1lbfBk4UiFyax3XGNVoKR1xl55WZXLiKRjlyXEMikoci cOQuf/mazriUYCwDYRsr2pTSwzSqdZ3VmzRcYHc74SFX4h0ZFrhNAEdDcBvhqJIXe9 OT+43EDgz6m5w== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 292F8C3ABCD; Mon, 12 May 2025 11:40:19 +0000 (UTC) From: Mahesh Rao via B4 Relay Date: Mon, 12 May 2025 19:39:55 +0800 Subject: [PATCH v2 5/7] dts: agilex: Add support for SDM mailbox interrupt for Intel Agilex SoC FPGA. Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250512-sip_svc_upstream-v2-5-fae5c45c059d@altera.com> References: <20250512-sip_svc_upstream-v2-0-fae5c45c059d@altera.com> In-Reply-To: <20250512-sip_svc_upstream-v2-0-fae5c45c059d@altera.com> To: Dinh Nguyen , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Mahesh Rao Cc: Matthew Gerlach , linux-kernel@vger.kernel.org, devicetree@vger.kernel.org X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1747050016; l=956; i=mahesh.rao@altera.com; s=20250107; h=from:subject:message-id; bh=Qju5FftDEBjY7mgDWEHoQiNo3ptWBPQcrDs6T4v7xUo=; b=tIZE59Rukq2QBCrIeK7LfK3lKt7SYYhFKwjXcF+tOwJCIBXcw3OngRIjBfC6PU8lTMMRunoIL XzzSGvaxmCrCPoTIqsiDJmS9uP3n6+1vtiozYOiBF4EG3kVq1XWYF9K X-Developer-Key: i=mahesh.rao@altera.com; a=ed25519; pk=tQiFUzoKxHrQLDtWeEeaeTeJTl/UfclUHWZy1fjSiyg= X-Endpoint-Received: by B4 Relay for mahesh.rao@altera.com/20250107 with auth_id=337 X-Original-From: Mahesh Rao Reply-To: mahesh.rao@altera.com From: Mahesh Rao Add support for Secure Device Manager (SDM) mailbox doorbell interrupt on Agilex SoC FPGA for supporting asynchronous transactions. Signed-off-by: Mahesh Rao Reviewed-by: Matthew Gerlach --- arch/arm64/boot/dts/intel/socfpga_agilex.dtsi | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch/arm64/boot/dts/intel/socfpga_agilex.dtsi b/arch/arm64/boo= t/dts/intel/socfpga_agilex.dtsi index 1235ba5a9865a175001fd3ef2bad710842f93be4..bd8c386a2ee31b85d6ee9be2dff= 6176565a85077 100644 --- a/arch/arm64/boot/dts/intel/socfpga_agilex.dtsi +++ b/arch/arm64/boot/dts/intel/socfpga_agilex.dtsi @@ -65,6 +65,8 @@ svc { compatible =3D "intel,agilex-svc"; method =3D "smc"; memory-region =3D <&service_reserved>; + interrupts =3D ; + interrupt-parent =3D <&intc>; =20 fpga_mgr: fpga-mgr { compatible =3D "intel,agilex-soc-fpga-mgr"; --=20 2.35.3 From nobody Mon Feb 9 15:49:04 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B444929209D; Mon, 12 May 2025 11:40:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747050019; cv=none; b=u72FNknn/kOs+YCnfPeUiqZV0zzqKF6yqfZKLbJT0F0dFzvDuOae1ifFQHqSaXCrpv1yShVu2b/c6QkvEb3yo6cUAvoU2uAIpCmVM/Qh6fqC3XGitMeCKTztwO8x+m3WoPHdEzH8Srf68NKoIuVen/jJDY+39Ma0rKOUoFAFCug= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747050019; c=relaxed/simple; bh=ibeU41DrHsv6J87QYx9gpQfkrUVjiWDuwngy+ibG+JU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=e8jWal30+92b0pdiVSzYeIPqg/MSVDnsI81N1jjxGbBLsc4VicKOrUyjuudNgqoO2Sc3fR8od1A6fZBdJoKVbkdHHtTBERA2g5B5+GKbnRokSH16IqRh4/5rGu0Ppsj7eAWD7yEcgeVR2Ot+AQ1IkK9heW18woY/0Z5ct6mQEcs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=RHO8RsIK; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="RHO8RsIK" Received: by smtp.kernel.org (Postfix) with ESMTPS id 4146CC4CEF2; Mon, 12 May 2025 11:40:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1747050019; bh=ibeU41DrHsv6J87QYx9gpQfkrUVjiWDuwngy+ibG+JU=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=RHO8RsIKDa5mH823BllY9gVsOePqLyU4OQ6HrTJd+6X/HhP/3DCmAsML73NMaFozE mb/8Gh5CZDzJRtzHb8iwWIvGElQ16v2123rIs5L9PsMG2gxNQfM0kTZW4Mb5wknFaH ATUQpQREBTu+juKo7km5YEAG2+TUsldt9/NxqjtRvuxxjg+beZAA5wvqYctbjp2Dc9 MdIlM00WihFizfflghS1TpGj9/TnYMsuQaqfKql0nNYp8gTHfP4uo8+oAVTfUl2P+j a3hCD58R9dwSWVKLtS9RPUSdM3xYBTJnsJDR1/xJovAl/eUxJEN4puxuEIC6EUohdn wBIYFEvHQoBZg== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 37045C3ABD5; Mon, 12 May 2025 11:40:19 +0000 (UTC) From: Mahesh Rao via B4 Relay Date: Mon, 12 May 2025 19:39:56 +0800 Subject: [PATCH v2 6/7] firmware: stratix10-svc: Add for SDM mailbox doorbell interrupt Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250512-sip_svc_upstream-v2-6-fae5c45c059d@altera.com> References: <20250512-sip_svc_upstream-v2-0-fae5c45c059d@altera.com> In-Reply-To: <20250512-sip_svc_upstream-v2-0-fae5c45c059d@altera.com> To: Dinh Nguyen , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Mahesh Rao Cc: Matthew Gerlach , linux-kernel@vger.kernel.org, devicetree@vger.kernel.org X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1747050016; l=8985; i=mahesh.rao@altera.com; s=20250107; h=from:subject:message-id; bh=dlRM3LW8GIMqbmovGBPGMrJEM/n02Ou9PDk2reiH21M=; b=T1zvMnm5GvUyO6/XxYkQwc0Grtnz9fb0LasHAzsMFqFLXJOZ/9m9DHTZoJRNCq9luzPhWou81 lhQng4gHEEsBhGol5ujXHhsUrsNyXuwDYZ0ITkDJEJGOL5rWKbY/MbB X-Developer-Key: i=mahesh.rao@altera.com; a=ed25519; pk=tQiFUzoKxHrQLDtWeEeaeTeJTl/UfclUHWZy1fjSiyg= X-Endpoint-Received: by B4 Relay for mahesh.rao@altera.com/20250107 with auth_id=337 X-Original-From: Mahesh Rao Reply-To: mahesh.rao@altera.com From: Mahesh Rao Add support for SDM (Secure Device Manager) mailbox doorbell interrupt for async transactions. On interrupt, a workqueue is triggered which polls the ATF for pending responses and retrieves the bitmap of all retrieved and unprocessed transaction ids of mailbox responses from SDM. It then triggers the corresponding registered callbacks. Signed-off-by: Mahesh Rao Reviewed-by: Matthew Gerlach --- drivers/firmware/stratix10-svc.c | 97 ++++++++++++++++++++++++= +++- include/linux/firmware/intel/stratix10-smc.h | 22 +++++++ 2 files changed, 118 insertions(+), 1 deletion(-) diff --git a/drivers/firmware/stratix10-svc.c b/drivers/firmware/stratix10-= svc.c index e25493db074930dcc16964fbb427be7168a841e6..d60808cc077da6d88ca6cc1043f= 6da46df31ebad 100644 --- a/drivers/firmware/stratix10-svc.c +++ b/drivers/firmware/stratix10-svc.c @@ -9,12 +9,14 @@ #include #include #include +#include #include #include #include #include #include #include +#include #include #include #include @@ -22,6 +24,7 @@ #include #include #include +#include =20 /** * SVC_NUM_DATA_IN_FIFO - number of struct stratix10_svc_data in the FIFO @@ -190,17 +193,20 @@ struct stratix10_async_chan { =20 /** * struct stratix10_async_ctrl - Control structure for Stratix 10 asynchro= nous operations + * @irq: Interrupt request number associated with the asynchronous control * @initialized: Flag indicating whether the control structure has been in= itialized * @invoke_fn: Function pointer for invoking Stratix 10 service calls to E= L3 secure firmware * @async_id_pool: Pointer to the ID pool used for asynchronous operations * @common_achan_refcount: Atomic reference count for the common asynchron= ous channel usage * @common_async_chan: Pointer to the common asynchronous channel structure * @trx_list_wr_lock: Spinlock for protecting the transaction list write o= perations + * @async_work: Work structure for scheduling asynchronous work * @trx_list: Hash table for managing asynchronous transactions */ =20 struct stratix10_async_ctrl { bool initialized; + int irq; void (*invoke_fn)(struct stratix10_async_ctrl *actrl, const struct arm_smccc_1_2_regs *args, struct arm_smccc_1_2_regs *res= ); struct stratix10_sip_id_pool *async_id_pool; @@ -208,6 +214,7 @@ struct stratix10_async_ctrl { struct stratix10_async_chan *common_async_chan; /* spinlock to protect the writes to trx_list hash table */ spinlock_t trx_list_wr_lock; + struct work_struct async_work; DECLARE_HASHTABLE(trx_list, ASYNC_TRX_HASH_BITS); }; =20 @@ -1632,6 +1639,71 @@ static inline void stratix10_smc_1_2(struct stratix1= 0_async_ctrl *actrl, arm_smccc_1_2_smc(args, res); } =20 +static irqreturn_t stratix10_svc_async_irq_handler(int irq, void *dev_id) +{ + struct stratix10_svc_controller *ctrl =3D dev_id; + struct stratix10_async_ctrl *actrl =3D &ctrl->actrl; + + queue_work(system_bh_wq, &actrl->async_work); + disable_irq_nosync(actrl->irq); + return IRQ_HANDLED; +} + +/** + * stratix10_async_workqueue_handler - Handles asynchronous workqueue tasks + * @work: Pointer to the work_struct representing the work to be handled + * + * This function is the handler for the asynchronous workqueue. It performs + * the following tasks: + * - Invokes the asynchronous polling on interrupt supervisory call. + * - On success,it retrieves the bitmap of pending transactions from mailb= ox + * fifo in ATF. + * - It processes each pending transaction by calling the corresponding + * callback function. + * + * The function ensures that the IRQ is enabled after processing the trans= actions + * and logs the total time taken to handle the transactions along with the= number + * of transactions handled and the CPU on which the handler ran. + */ +static void stratix10_async_workqueue_handler(struct work_struct *work) +{ + u64 bitmap_array[4]; + unsigned long transaction_id =3D 0; + struct stratix10_svc_async_handler *handler; + DECLARE_BITMAP(pend_on_irq, TOTAL_TRANSACTION_IDS); + struct arm_smccc_1_2_regs args =3D { .a0 =3D INTEL_SIP_SMC_ASYNC_POLL_ON_= IRQ }, res; + struct stratix10_async_ctrl *actrl =3D + container_of(work, struct stratix10_async_ctrl, async_work); + + actrl->invoke_fn(actrl, &args, &res); + if (res.a0 =3D=3D INTEL_SIP_SMC_STATUS_OK) { + bitmap_array[0] =3D res.a1; + bitmap_array[1] =3D res.a2; + bitmap_array[2] =3D res.a3; + bitmap_array[3] =3D res.a4; + bitmap_from_arr64(pend_on_irq, bitmap_array, TOTAL_TRANSACTION_IDS); + rcu_read_lock(); + do { + transaction_id =3D find_next_bit(pend_on_irq, + TOTAL_TRANSACTION_IDS, + transaction_id); + if (transaction_id >=3D TOTAL_TRANSACTION_IDS) + break; + hash_for_each_possible_rcu_notrace(actrl->trx_list, + handler, next, + transaction_id) { + if (handler->transaction_id =3D=3D transaction_id) { + handler->cb(handler->cb_arg); + break; + } + } + transaction_id++; + } while (transaction_id < TOTAL_TRANSACTION_IDS); + rcu_read_unlock(); + } + enable_irq(actrl->irq); +} + /** * stratix10_svc_async_init - Initialize the Stratix 10 service controller * for asynchronous operations. @@ -1639,6 +1711,7 @@ static inline void stratix10_smc_1_2(struct stratix10= _async_ctrl *actrl, * * This function initializes the asynchronous service controller by settin= g up * the necessary data structures, initializing the transaction list, and + * registering the IRQ handler for asynchronous transactions. * * Return: 0 on success, -EINVAL if the controller is NULL or already init= ialized, * -ENOMEM if memory allocation fails, -EADDRINUSE if the client I= D is already @@ -1646,7 +1719,7 @@ static inline void stratix10_smc_1_2(struct stratix10= _async_ctrl *actrl, */ static int stratix10_svc_async_init(struct stratix10_svc_controller *contr= oller) { - int ret; + int ret, irq; struct arm_smccc_res res; =20 if (!controller) @@ -1693,6 +1766,22 @@ static int stratix10_svc_async_init(struct stratix10= _svc_controller *controller) hash_init(actrl->trx_list); atomic_set(&actrl->common_achan_refcount, 0); =20 + irq =3D of_irq_get(dev_of_node(dev), 0); + if (irq < 0) { + dev_warn(dev, "Failed to get IRQ, falling back to polling mode\n"); + } else { + ret =3D devm_request_any_context_irq(dev, irq, stratix10_svc_async_irq_h= andler, + IRQF_NO_AUTOEN, "stratix10_svc", controller); + if (ret =3D=3D 0) { + dev_alert(dev, + "Registered IRQ %d for sip async operations\n", + irq); + actrl->irq =3D irq; + INIT_WORK(&actrl->async_work, stratix10_async_workqueue_handler); + enable_irq(actrl->irq); + } + } + actrl->initialized =3D true; return 0; } @@ -1728,6 +1817,12 @@ static int stratix10_svc_async_exit(struct stratix10= _svc_controller *ctrl) =20 actrl->initialized =3D false; =20 + if (actrl->irq > 0) { + free_irq(actrl->irq, ctrl); + flush_work(&actrl->async_work); + actrl->irq =3D 0; + } + spin_lock(&actrl->trx_list_wr_lock); hash_for_each_safe(actrl->trx_list, i, tmp, handler, next) { stratix10_deallocate_id(handler->achan->job_id_pool, diff --git a/include/linux/firmware/intel/stratix10-smc.h b/include/linux/f= irmware/intel/stratix10-smc.h index c98ed992d23bed5aa344868ca0c77a2d19d94c06..ee00f17ea9f6c7a1114fb617d4d= 6393f2c27e2a9 100644 --- a/include/linux/firmware/intel/stratix10-smc.h +++ b/include/linux/firmware/intel/stratix10-smc.h @@ -644,4 +644,26 @@ INTEL_SIP_SMC_FAST_CALL_VAL(INTEL_SIP_SMC_FUNCID_FPGA_= CONFIG_COMPLETED_WRITE) #define INTEL_SIP_SMC_ASYNC_FUNC_ID_POLL (0xC8) #define INTEL_SIP_SMC_ASYNC_POLL \ INTEL_SIP_SMC_ASYNC_VAL(INTEL_SIP_SMC_ASYNC_FUNC_ID_POLL) + +/** + * Request INTEL_SIP_SMC_ASYNC_POLL_ON_IRQ + * Async call used by service driver at EL1 to read response from SDM mail= box and + * to retrieve the transaction id's of the read response's. + * + * Call register usage: + * a0 INTEL_SIP_SMC_ASYNC_POLL_ON_IRQ + * a1 transaction job id + * a2-7 will be used to return the response data + * + * Return status + * a0 INTEL_SIP_SMC_STATUS_OK + * a1-a4 will contain bitmap of available responses's transaction id as se= t bit position. + * a5-17 not used + * Or + * a0 INTEL_SIP_SMC_STATUS_NO_RESPONSE + * a1-17 not used + */ +#define INTEL_SIP_SMC_ASYNC_FUNC_ID_IRQ_POLL (0xC9) +#define INTEL_SIP_SMC_ASYNC_POLL_ON_IRQ \ + INTEL_SIP_SMC_ASYNC_VAL(INTEL_SIP_SMC_ASYNC_FUNC_ID_IRQ_POLL) #endif --=20 2.35.3 From nobody Mon Feb 9 15:49:04 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E8E78292908; Mon, 12 May 2025 11:40:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747050020; cv=none; b=ZMipHTBcheA//owxyyW+Xx6qscOAqXfBxAuaeaFvp4wwLr7UrT5nTE/VyQPEi2yjMFNGfuaEtgJJMj/5i/vVrauJr+mRBtFBnyTKFU6KbC7AGYY+uyTeEbOlz/GQ3hCpNR1uWzyUc75McJ1xsTo8YZ5YF0Nwa85u22U3CzHihfc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747050020; c=relaxed/simple; bh=3+mgovEH2U7GbbwYUPvC67milPze1pciOWU6d6iilto=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Gq5G5IBkotUKh6nBXz5Q8BabxTtxsiQwI05K2C7iZ8ozbVV+RO7YQ5K+ruM+PX/2q8MlJfuE79HIsNhlKj5ska9Ovg753XedLxxPyPuBITLuYaatBSG90pDfTqk1Q725QVNezQQFfQbqTQgHH6ELx8wa94CABISxNfuDpjvupOM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=avqs1XCH; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="avqs1XCH" Received: by smtp.kernel.org (Postfix) with ESMTPS id 4CA24C4CEFA; Mon, 12 May 2025 11:40:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1747050019; bh=3+mgovEH2U7GbbwYUPvC67milPze1pciOWU6d6iilto=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=avqs1XCHJl6ivrYl7leI2E1pFPlIXcyNPQIm1xjOVYCkUVeL6CtyRL982bThKjpOo m80UJLEobUCC/0ilsYNuOlNuHZAqYPEgMkCX2GCm7GHDzyUWSHfesLB8vPJkO3wcDL pnG/4aOyG/y2LAzf1M3WMg2SHcrzU6WTF0FK20sDJ90GAUc0oWUGeT9o4WGAs7qhxf Tm+y7Sa+d78ENKxpB8Ikc4M8N02SBIuMrWmuzmKYKmoU+nPl/h9/ajlWofsGYGu8Sp DMKt85MdOPRpYRNmlTua9RzakEP+teafsf9y6TCsQzHogcLFje1liB6dqrJlemi2pM hnHTReGK7klKQ== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 43C63C3ABD2; Mon, 12 May 2025 11:40:19 +0000 (UTC) From: Mahesh Rao via B4 Relay Date: Mon, 12 May 2025 19:39:57 +0800 Subject: [PATCH v2 7/7] firmware: stratix10-svc: Add support for HWMON temperature and voltage read command. Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250512-sip_svc_upstream-v2-7-fae5c45c059d@altera.com> References: <20250512-sip_svc_upstream-v2-0-fae5c45c059d@altera.com> In-Reply-To: <20250512-sip_svc_upstream-v2-0-fae5c45c059d@altera.com> To: Dinh Nguyen , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Mahesh Rao Cc: Matthew Gerlach , linux-kernel@vger.kernel.org, devicetree@vger.kernel.org X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1747050016; l=5773; i=mahesh.rao@altera.com; s=20250107; h=from:subject:message-id; bh=JivcqKDOJIt5kDrV3wGuv8X3Vtjgv7lk5n3TnWoduZM=; b=xvCa7P+zu3SXxb5VoGVvj7apxcDojRruWUKgEzgdh8aYApRyzNDxkENG3zTcShsT4DyjnpeCK qfg1wojZZApDLgXaEqOorsS42kjoujDCBlLzv7kivAD6JaEvej6cAs2 X-Developer-Key: i=mahesh.rao@altera.com; a=ed25519; pk=tQiFUzoKxHrQLDtWeEeaeTeJTl/UfclUHWZy1fjSiyg= X-Endpoint-Received: by B4 Relay for mahesh.rao@altera.com/20250107 with auth_id=337 X-Original-From: Mahesh Rao Reply-To: mahesh.rao@altera.com From: Mahesh Rao Add support for HWMON commands in stratix10 Asynchronous communication Signed-off-by: Mahesh Rao Reviewed-by: Matthew Gerlach --- drivers/firmware/stratix10-svc.c | 20 +++++++++++- include/linux/firmware/intel/stratix10-smc.h | 38 ++++++++++++++++++= ++++ .../linux/firmware/intel/stratix10-svc-client.h | 11 +++++++ 3 files changed, 68 insertions(+), 1 deletion(-) diff --git a/drivers/firmware/stratix10-svc.c b/drivers/firmware/stratix10-= svc.c index d60808cc077da6d88ca6cc1043f6da46df31ebad..4ee89980319dcde5198d7112d08= 708b543881f73 100644 --- a/drivers/firmware/stratix10-svc.c +++ b/drivers/firmware/stratix10-svc.c @@ -40,7 +40,7 @@ * timeout is set to 30 seconds (30 * 1000) at Intel Stratix10 SoC. */ #define SVC_NUM_DATA_IN_FIFO 32 -#define SVC_NUM_CHANNEL 3 +#define SVC_NUM_CHANNEL 4 #define FPGA_CONFIG_DATA_CLAIM_TIMEOUT_MS 200 #define FPGA_CONFIG_STATUS_TIMEOUT_SEC 30 #define BYTE_TO_WORD_SIZE 4 @@ -1429,6 +1429,14 @@ int stratix10_svc_async_send(struct stratix10_svc_ch= an *chan, void *msg, void ** STRATIX10_SIP_SMC_SET_TRANSACTIONID_X1(handle->transaction_id); =20 switch (p_msg->command) { + case COMMAND_HWMON_READTEMP: + args.a0 =3D INTEL_SIP_SMC_ASYNC_HWMON_READTEMP; + args.a2 =3D p_msg->arg[0]; + break; + case COMMAND_HWMON_READVOLT: + args.a0 =3D INTEL_SIP_SMC_ASYNC_HWMON_READVOLT; + args.a2 =3D p_msg->arg[0]; + break; default: dev_err(ctrl->dev, "Invalid command ,%d\n", p_msg->command); ret =3D -EINVAL; @@ -1508,6 +1516,11 @@ static int stratix10_svc_async_prepare_response(stru= ct stratix10_svc_chan *chan, data->status =3D STRATIX10_GET_SDM_STATUS_CODE(handle->res.a1); =20 switch (p_msg->command) { + case COMMAND_HWMON_READTEMP: + case COMMAND_HWMON_READVOLT: + data->kaddr1 =3D (void *)&handle->res.a2; + break; + default: dev_alert(ctrl->dev, "Invalid command\n ,%d", p_msg->command); return -ENOENT; @@ -2136,6 +2149,11 @@ static int stratix10_svc_drv_probe(struct platform_d= evice *pdev) chans[2].name =3D SVC_CLIENT_FCS; spin_lock_init(&chans[2].lock); =20 + chans[3].scl =3D NULL; + chans[3].ctrl =3D controller; + chans[3].name =3D SVC_CLIENT_HWMON; + spin_lock_init(&chans[3].lock); + list_add_tail(&controller->node, &svc_ctrl); platform_set_drvdata(pdev, controller); =20 diff --git a/include/linux/firmware/intel/stratix10-smc.h b/include/linux/f= irmware/intel/stratix10-smc.h index ee00f17ea9f6c7a1114fb617d4d6393f2c27e2a9..78055b0234cee990515f01a509a= 75e1c8142c68b 100644 --- a/include/linux/firmware/intel/stratix10-smc.h +++ b/include/linux/firmware/intel/stratix10-smc.h @@ -625,6 +625,44 @@ INTEL_SIP_SMC_FAST_CALL_VAL(INTEL_SIP_SMC_FUNCID_FPGA_= CONFIG_COMPLETED_WRITE) #define INTEL_SIP_SMC_FCS_GET_PROVISION_DATA \ INTEL_SIP_SMC_FAST_CALL_VAL(INTEL_SIP_SMC_FUNCID_FCS_GET_PROVISION_DATA) =20 +/** + * Request INTEL_SIP_SMC_ASYNC_HWMON_READTEMP + * Async call to request temperature + * + * Call register usage: + * a0 INTEL_SIP_SMC_ASYNC_FUNCID_HWMON_READTEMP + * a1 transaction job id + * a2 Temperature Channel + * a3-a17 not used + * + * Return status + * a0 INTEL_SIP_SMC_STATUS_OK ,INTEL_SIP_SMC_STATUS_REJECTED + * or INTEL_SIP_SMC_STATUS_BUSY + * a1-a17 not used + */ +#define INTEL_SIP_SMC_ASYNC_FUNCID_HWMON_READTEMP (0xE8) +#define INTEL_SIP_SMC_ASYNC_HWMON_READTEMP \ + INTEL_SIP_SMC_ASYNC_VAL(INTEL_SIP_SMC_ASYNC_FUNCID_HWMON_READTEMP) + +/** + * Request INTEL_SIP_SMC_ASYNC_HWMON_READVOLT + * Async call to request voltage + * + * Call register usage: + * a0 INTEL_SIP_SMC_ASYNC_HWMON_READVOLT + * a1 transaction job id + * a2 Voltage Channel + * a3-a17 not used + * + * Return status + * a0 INTEL_SIP_SMC_STATUS_OK ,INTEL_SIP_SMC_STATUS_REJECTED + * or INTEL_SIP_SMC_STATUS_BUSY + * a1-17 not used + */ +#define INTEL_SIP_SMC_ASYNC_FUNCID_HWMON_READVOLT (0xE9) +#define INTEL_SIP_SMC_ASYNC_HWMON_READVOLT \ + INTEL_SIP_SMC_ASYNC_VAL(INTEL_SIP_SMC_ASYNC_FUNCID_HWMON_READVOLT) + /** * Request INTEL_SIP_SMC_ASYNC_POLL * Async call used by service driver at EL1 to query mailbox response from= SDM. diff --git a/include/linux/firmware/intel/stratix10-svc-client.h b/include/= linux/firmware/intel/stratix10-svc-client.h index bda837815bae35fbf4df6280dba5bc02d747426e..032e780c7b545e2e238f9dea712= 779d979e491d6 100644 --- a/include/linux/firmware/intel/stratix10-svc-client.h +++ b/include/linux/firmware/intel/stratix10-svc-client.h @@ -16,6 +16,7 @@ #define SVC_CLIENT_FPGA "fpga" #define SVC_CLIENT_RSU "rsu" #define SVC_CLIENT_FCS "fcs" +#define SVC_CLIENT_HWMON "hwmon" =20 /* * Status of the sent command, in bit number @@ -71,6 +72,7 @@ #define SVC_RSU_REQUEST_TIMEOUT_MS 300 #define SVC_FCS_REQUEST_TIMEOUT_MS 2000 #define SVC_COMPLETED_TIMEOUT_MS 30000 +#define SVC_HWMON_REQUEST_TIMEOUT_MS 2000 =20 struct stratix10_svc_chan; =20 @@ -142,6 +144,12 @@ struct stratix10_svc_chan; * * @COMMAND_FCS_RANDOM_NUMBER_GEN: generate a random number, return status * is SVC_STATUS_OK, SVC_STATUS_ERROR + * + * @COMMAND_HWMON_READTEMP: read temperature from the hardware sensor conn= ected + * to the FPGA, return status is SVC_STATUS_OK, SVC_STATUS_ERROR + * + * @COMMAND_HWMON_READVOLT: read voltage from the hardware sensor connected + * to the FPGA, return status is SVC_STATUS_OK, SVC_STATUS_ERROR */ enum stratix10_svc_command_code { /* for FPGA */ @@ -172,6 +180,9 @@ enum stratix10_svc_command_code { COMMAND_MBOX_SEND_CMD =3D 100, /* Non-mailbox SMC Call */ COMMAND_SMC_SVC_VERSION =3D 200, + /* for HWMON */ + COMMAND_HWMON_READTEMP, + COMMAND_HWMON_READVOLT }; =20 /** --=20 2.35.3