From nobody Sun May 10 18:34:09 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9029AC433F5 for ; Wed, 27 Apr 2022 07:48:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1359073AbiD0Hve (ORCPT ); Wed, 27 Apr 2022 03:51:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39752 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1359045AbiD0HvU (ORCPT ); Wed, 27 Apr 2022 03:51:20 -0400 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2071.outbound.protection.outlook.com [40.107.220.71]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 296FF113CB3 for ; Wed, 27 Apr 2022 00:48:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nqkOXEw25DuVHlsZc4texi4LIoqckg+T8W7sgl5p8eReR/W7iv2RqMVFtHxsNHvRYLtkfqHFdha8ugqAF3eXB5V1phULbhYCv3sJlo0W/H9yzmKFVkHtxapMkj8RHbfogVUCd12Fln7lNpVjNRSePP7dLqvI8poN/G8oIo8v9O6LpnrqWPbpddXnkWHNFc59jTTfBz74mBX68p9tE/GjFiIbJShS9s98HN/n8VVNmygELz2QlCn3g6sbrLLMaXRYlAsi/nS7uCBgZYKQeFasDyWn61exRPDTPd0g25T5kuRAIQVznFJDyAZ26KhB3TpeQno+XGBp5Eyk3JqWVqZlqw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=oqJKTFJ4bOYLDXbUVdmex7MMkbUlEIj2tIOXATlSP7c=; b=E0UlbFkv6zTwwgRdJq5theT5hEbzf9z1T4hKl6qvsS0cjFgRbVmf88nNB0EpRSAEPTTD5kv4bD6onX+wQf/X+qOLMk2Sbig7wvKWfpfJ59JxJgK70T4830IIXzIQ6UvXJofBFc+N2XTyvxq9zkf2fLCqK+sAxMEthCIBGbdhi2PxRfVvv572mSHTQlGX+aWADS6tHO+QKQQMgsWNHpstU6NhW333E7Kem1c/T3YpXsfXMLbQgFFi/+HnEqTlPAXoA/l7Rb6KDPbBhy3kyRYiqMNmB8lS4bCb+2TAiyzXeVZPlZoERnU6v+dvxu4uNH2t8eVcVc10rYEDqiaVG5caZg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 149.199.62.198) smtp.rcpttodomain=linuxfoundation.org smtp.mailfrom=xilinx.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=xilinx.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xilinx.onmicrosoft.com; s=selector2-xilinx-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=oqJKTFJ4bOYLDXbUVdmex7MMkbUlEIj2tIOXATlSP7c=; b=Ud17jaiILDy1ivYw8aZjcDgtvO/VrFzoPgK7YvsRjED1QwQrwcq/qOY5Pdrh877pCVyBbybJf7Pf4JfLOoEzx3fZ2K/vfsgQztVcrZIGoUYWH/yAFACDm6tBcTKB46mkHZKGFIk8eDXE+C8KlmFA73hrzYypKYC9YLn2wVcgoeI= Received: from SA9P221CA0001.NAMP221.PROD.OUTLOOK.COM (2603:10b6:806:25::6) by BN7PR02MB4065.namprd02.prod.outlook.com (2603:10b6:406:fe::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5186.15; Wed, 27 Apr 2022 07:48:06 +0000 Received: from SN1NAM02FT0024.eop-nam02.prod.protection.outlook.com (2603:10b6:806:25:cafe::67) by SA9P221CA0001.outlook.office365.com (2603:10b6:806:25::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.13 via Frontend Transport; Wed, 27 Apr 2022 07:48:06 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 149.199.62.198) smtp.mailfrom=xilinx.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=xilinx.com; Received-SPF: Pass (protection.outlook.com: domain of xilinx.com designates 149.199.62.198 as permitted sender) receiver=protection.outlook.com; client-ip=149.199.62.198; helo=xsj-pvapexch01.xlnx.xilinx.com; Received: from xsj-pvapexch01.xlnx.xilinx.com (149.199.62.198) by SN1NAM02FT0024.mail.protection.outlook.com (10.97.5.147) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5206.12 via Frontend Transport; Wed, 27 Apr 2022 07:48:06 +0000 Received: from xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) by xsj-pvapexch01.xlnx.xilinx.com (172.19.86.40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.14; Wed, 27 Apr 2022 00:48:04 -0700 Received: from smtp.xilinx.com (172.19.127.96) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server id 15.1.2176.14 via Frontend Transport; Wed, 27 Apr 2022 00:48:04 -0700 Envelope-to: gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Received: from [172.19.2.91] (port=54884 helo=xsjpmteam52.xilinx.com) by smtp.xilinx.com with esmtp (Exim 4.90) (envelope-from ) id 1njcP6-0002bP-N0; Wed, 27 Apr 2022 00:48:04 -0700 From: Abhyuday Godhasara To: CC: , , , , , , Subject: [PATCH 1/2] driver: soc: xilinx: Add support of multiple callbacks for same event in event management driver Date: Wed, 27 Apr 2022 00:48:02 -0700 Message-ID: <20220427074803.19009-2-abhyuday.godhasara@xilinx.com> X-Mailer: git-send-email 2.32.0.93.g670b81a In-Reply-To: <20220427074803.19009-1-abhyuday.godhasara@xilinx.com> References: <20220427074803.19009-1-abhyuday.godhasara@xilinx.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: bac0b324-430c-4169-c494-08da28224407 X-MS-TrafficTypeDiagnostic: BN7PR02MB4065:EE_ X-Microsoft-Antispam-PRVS: X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: wFHeObXBP9dunHQ+lRCo2E7QydQSAgsMjCoPouGPEuLMkPxIsFgzCor3IUUGHMxMXljDXrPTJHS54/rwS9bwP/HmeQWmfulwEQJa6i/Zu28yhZxeM69KVszpiD2qAIeyEOmTPTvY5rOp07zHwKpubIuLAj+suA9hnS/onSPjWi2oo3WSVm4oiF4Y6uVlAJlmPbiIbnoxblHaPojF0ZsdS0EldybO0KWv/WGPdUYAudSbajevyqPMeJiuIFJUtVzpxm+sJig7wb3pfQRCQI8IckxX8vwpDrN30wuf8m5GN+26zLNM3H8S+k/dqWFOAtn2/Beg0cAwPjuYcHEx36vEpajGRXuJi6Wk4f0OVBkJILFI+Y9T8zw6hFPrAa6Ju+JRE0k35RhbXxt7OXquEF1fxImkNB1FwxxAyhcYYw275u/3sXm/uWAkwzZwhiWr0xUimc9Ecso9j4HEmm8EE3A7k0ME3TbmOpFW7ZdMs7sgIDYBwDXwhqlbYVyC0lpJ5Rt5BDpKq2chMjcQImD6DioXprW6cXv4eShiCTxdJ2AZzUDuxrVLq80SLclxeYeTni9hcQY1ow6mFlXcf/StvHBjkMqhLKDQGgOx6UbiJ6drFj6icft/3u8cCDTTzOlTFuio4dtrk55wB+aq++W3XP5z5Cylb/idgZYz70p4qUwvPCCCHYvwqRck/1jxCoXHryGJwstioqWOYic3mMvnBQ3EBA== X-Forefront-Antispam-Report: CIP:149.199.62.198;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:xsj-pvapexch01.xlnx.xilinx.com;PTR:unknown-62-198.xilinx.com;CAT:NONE;SFS:(13230001)(4636009)(40470700004)(36840700001)(46966006)(426003)(186003)(356005)(47076005)(7636003)(7696005)(1076003)(2616005)(508600001)(336012)(6916009)(44832011)(8936002)(9786002)(4326008)(8676002)(82310400005)(36756003)(2906002)(5660300002)(316002)(70586007)(26005)(70206006)(36860700001)(54906003)(40460700003)(83380400001)(102446001);DIR:OUT;SFP:1101; X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Apr 2022 07:48:06.0924 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: bac0b324-430c-4169-c494-08da28224407 X-MS-Exchange-CrossTenant-Id: 657af505-d5df-48d0-8300-c31994686c5c X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=657af505-d5df-48d0-8300-c31994686c5c;Ip=[149.199.62.198];Helo=[xsj-pvapexch01.xlnx.xilinx.com] X-MS-Exchange-CrossTenant-AuthSource: SN1NAM02FT0024.eop-nam02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN7PR02MB4065 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" As per the current implementation of only single callback data gets saved per event, driver is throwing an error if try to register multiple callback for same event. Add support of multiple callbacks data for same event. So agent can register for same event with multiple callbacks. Here event management driver will store the callbacks as list in Hash table entry for that event. Here each callback data contain 2 element as callback handler and private data of agent driver. Signed-off-by: Abhyuday Godhasara --- drivers/soc/xilinx/xlnx_event_manager.c | 151 ++++++++++++++++++------ 1 file changed, 117 insertions(+), 34 deletions(-) diff --git a/drivers/soc/xilinx/xlnx_event_manager.c b/drivers/soc/xilinx/x= lnx_event_manager.c index b27f8853508e..f89000dc33a3 100644 --- a/drivers/soc/xilinx/xlnx_event_manager.c +++ b/drivers/soc/xilinx/xlnx_event_manager.c @@ -41,25 +41,35 @@ static int event_manager_availability =3D -EACCES; static DEFINE_HASHTABLE(reg_driver_map, REGISTERED_DRIVER_MAX_ORDER); static int sgi_num =3D XLNX_EVENT_SGI_NUM; =20 +/** + * struct agent_cb - Registered callback function and private data. + * @agent_data: Data passed back to handler function. + * @eve_cb: Function pointer to store the callback function. + * @list: member to create list. + */ +struct agent_cb { + void *agent_data; + event_cb_func_t eve_cb; + struct list_head list; +}; + /** * struct registered_event_data - Registered Event Data. * @key: key is the combine id(Node-Id | Event-Id) of type u64 * where upper u32 for Node-Id and lower u32 for Event-Id, * And this used as key to index into hashmap. - * @agent_data: Data passed back to handler function. * @cb_type: Type of Api callback, like PM_NOTIFY_CB, etc. - * @eve_cb: Function pointer to store the callback function. - * @wake: If this flag set, firmware will wakeup processor if is + * @wake: If this flag set, firmware will wake up processor if is * in sleep or power down state. + * @cb_list_head: Head of call back data list which contain the information + * about registered handler and private data. * @hentry: hlist_node that hooks this entry into hashtable. */ struct registered_event_data { u64 key; enum pm_api_cb_id cb_type; - void *agent_data; - - event_cb_func_t eve_cb; bool wake; + struct list_head cb_list_head; struct hlist_node hentry; }; =20 @@ -78,29 +88,60 @@ static int xlnx_add_cb_for_notify_event(const u32 node_= id, const u32 event, cons event_cb_func_t cb_fun, void *data) { u64 key =3D 0; + bool present_in_hash =3D false; struct registered_event_data *eve_data; + struct agent_cb *cb_data; + struct agent_cb *cb_pos; + struct agent_cb *cb_next; =20 key =3D ((u64)node_id << 32U) | (u64)event; /* Check for existing entry in hash table for given key id */ hash_for_each_possible(reg_driver_map, eve_data, hentry, key) { if (eve_data->key =3D=3D key) { - pr_err("Found as already registered\n"); - return -EINVAL; + present_in_hash =3D true; + break; } } =20 - /* Add new entry if not present */ - eve_data =3D kmalloc(sizeof(*eve_data), GFP_KERNEL); - if (!eve_data) - return -ENOMEM; + if (!present_in_hash) { + /* Add new entry if not present in HASH table */ + eve_data =3D kmalloc(sizeof(*eve_data), GFP_KERNEL); + if (!eve_data) + return -ENOMEM; + eve_data->key =3D key; + eve_data->cb_type =3D PM_NOTIFY_CB; + eve_data->wake =3D wake; + INIT_LIST_HEAD(&eve_data->cb_list_head); + + cb_data =3D kmalloc(sizeof(*cb_data), GFP_KERNEL); + if (!cb_data) + return -ENOMEM; + cb_data->eve_cb =3D cb_fun; + cb_data->agent_data =3D data; + + /* Add into callback list */ + list_add(&cb_data->list, &eve_data->cb_list_head); + + /* Add into HASH table */ + hash_add(reg_driver_map, &eve_data->hentry, key); + } else { + /* Search for callback function and private data in list */ + list_for_each_entry_safe(cb_pos, cb_next, &eve_data->cb_list_head, list)= { + if (cb_pos->eve_cb =3D=3D cb_fun && + cb_pos->agent_data =3D=3D data) { + return 0; + } + } =20 - eve_data->key =3D key; - eve_data->cb_type =3D PM_NOTIFY_CB; - eve_data->eve_cb =3D cb_fun; - eve_data->wake =3D wake; - eve_data->agent_data =3D data; + /* Add multiple handler and private data in list */ + cb_data =3D kmalloc(sizeof(*cb_data), GFP_KERNEL); + if (!cb_data) + return -ENOMEM; + cb_data->eve_cb =3D cb_fun; + cb_data->agent_data =3D data; =20 - hash_add(reg_driver_map, &eve_data->hentry, key); + list_add(&cb_data->list, &eve_data->cb_list_head); + } =20 return 0; } @@ -108,6 +149,7 @@ static int xlnx_add_cb_for_notify_event(const u32 node_= id, const u32 event, cons static int xlnx_add_cb_for_suspend(event_cb_func_t cb_fun, void *data) { struct registered_event_data *eve_data; + struct agent_cb *cb_data; =20 /* Check for existing entry in hash table for given cb_type */ hash_for_each_possible(reg_driver_map, eve_data, hentry, PM_INIT_SUSPEND_= CB) { @@ -124,8 +166,16 @@ static int xlnx_add_cb_for_suspend(event_cb_func_t cb_= fun, void *data) =20 eve_data->key =3D 0; eve_data->cb_type =3D PM_INIT_SUSPEND_CB; - eve_data->eve_cb =3D cb_fun; - eve_data->agent_data =3D data; + INIT_LIST_HEAD(&eve_data->cb_list_head); + + cb_data =3D kmalloc(sizeof(*cb_data), GFP_KERNEL); + if (!cb_data) + return -ENOMEM; + cb_data->eve_cb =3D cb_fun; + cb_data->agent_data =3D data; + + /* Add into callback list */ + list_add(&cb_data->list, &eve_data->cb_list_head); =20 hash_add(reg_driver_map, &eve_data->hentry, PM_INIT_SUSPEND_CB); =20 @@ -136,12 +186,20 @@ static int xlnx_remove_cb_for_suspend(event_cb_func_t= cb_fun) { bool is_callback_found =3D false; struct registered_event_data *eve_data; + struct agent_cb *cb_pos; + struct agent_cb *cb_next; =20 /* Check for existing entry in hash table for given cb_type */ hash_for_each_possible(reg_driver_map, eve_data, hentry, PM_INIT_SUSPEND_= CB) { - if (eve_data->cb_type =3D=3D PM_INIT_SUSPEND_CB && - eve_data->eve_cb =3D=3D cb_fun) { - is_callback_found =3D true; + if (eve_data->cb_type =3D=3D PM_INIT_SUSPEND_CB) { + /* Delete the list of callback */ + list_for_each_entry_safe(cb_pos, cb_next, &eve_data->cb_list_head, list= ) { + if (cb_pos->eve_cb =3D=3D cb_fun) { + is_callback_found =3D true; + list_del_init(&cb_pos->list); + kfree(cb_pos); + } + } /* remove an object from a hashtable */ hash_del(&eve_data->hentry); kfree(eve_data); @@ -161,13 +219,21 @@ static int xlnx_remove_cb_for_notify_event(const u32 = node_id, const u32 event, bool is_callback_found =3D false; struct registered_event_data *eve_data; u64 key =3D ((u64)node_id << 32U) | (u64)event; + struct agent_cb *cb_pos; + struct agent_cb *cb_next; =20 /* Check for existing entry in hash table for given key id */ hash_for_each_possible(reg_driver_map, eve_data, hentry, key) { - if (eve_data->key =3D=3D key && - eve_data->eve_cb =3D=3D cb_fun) { - is_callback_found =3D true; - /* remove an object from a hashtable */ + if (eve_data->key =3D=3D key) { + /* Delete the list of callback */ + list_for_each_entry_safe(cb_pos, cb_next, &eve_data->cb_list_head, list= ) { + if (cb_pos->eve_cb =3D=3D cb_fun) { + is_callback_found =3D true; + list_del_init(&cb_pos->list); + kfree(cb_pos); + } + } + /* remove an object from a HASH table */ hash_del(&eve_data->hentry); kfree(eve_data); } @@ -338,12 +404,16 @@ static void xlnx_call_suspend_cb_handler(const u32 *p= ayload) bool is_callback_found =3D false; struct registered_event_data *eve_data; u32 cb_type =3D payload[0]; + struct agent_cb *cb_pos; + struct agent_cb *cb_next; =20 /* Check for existing entry in hash table for given cb_type */ hash_for_each_possible(reg_driver_map, eve_data, hentry, cb_type) { if (eve_data->cb_type =3D=3D cb_type) { - eve_data->eve_cb(&payload[0], eve_data->agent_data); - is_callback_found =3D true; + list_for_each_entry_safe(cb_pos, cb_next, &eve_data->cb_list_head, list= ) { + cb_pos->eve_cb(&payload[0], cb_pos->agent_data); + is_callback_found =3D true; + } } } if (!is_callback_found) @@ -356,12 +426,16 @@ static void xlnx_call_notify_cb_handler(const u32 *pa= yload) struct registered_event_data *eve_data; u64 key =3D ((u64)payload[1] << 32U) | (u64)payload[2]; int ret; + struct agent_cb *cb_pos; + struct agent_cb *cb_next; =20 /* Check for existing entry in hash table for given key id */ hash_for_each_possible(reg_driver_map, eve_data, hentry, key) { if (eve_data->key =3D=3D key) { - eve_data->eve_cb(&payload[0], eve_data->agent_data); - is_callback_found =3D true; + list_for_each_entry_safe(cb_pos, cb_next, &eve_data->cb_list_head, list= ) { + cb_pos->eve_cb(&payload[0], cb_pos->agent_data); + is_callback_found =3D true; + } =20 /* re register with firmware to get future events */ ret =3D zynqmp_pm_register_notifier(payload[1], payload[2], @@ -369,9 +443,12 @@ static void xlnx_call_notify_cb_handler(const u32 *pay= load) if (ret) { pr_err("%s() failed for 0x%x and 0x%x: %d\r\n", __func__, payload[1], payload[2], ret); - /* Remove already registered event from hash table */ - xlnx_remove_cb_for_notify_event(payload[1], payload[2], - eve_data->eve_cb); + list_for_each_entry_safe(cb_pos, cb_next, &eve_data->cb_list_head, + list) { + /* Remove already registered event from hash table */ + xlnx_remove_cb_for_notify_event(payload[1], payload[2], + cb_pos->eve_cb); + } } } } @@ -572,8 +649,14 @@ static int xlnx_event_manager_remove(struct platform_d= evice *pdev) struct registered_event_data *eve_data; struct hlist_node *tmp; int ret; + struct agent_cb *cb_pos; + struct agent_cb *cb_next; =20 hash_for_each_safe(reg_driver_map, i, tmp, eve_data, hentry) { + list_for_each_entry_safe(cb_pos, cb_next, &eve_data->cb_list_head, list)= { + list_del_init(&cb_pos->list); + kfree(cb_pos); + } hash_del(&eve_data->hentry); kfree(eve_data); } --=20 2.32.0.93.g670b81a From nobody Sun May 10 18:34:09 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5AD50C433EF for ; Wed, 27 Apr 2022 07:48:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1359059AbiD0Hvb (ORCPT ); Wed, 27 Apr 2022 03:51:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39690 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1359039AbiD0HvT (ORCPT ); Wed, 27 Apr 2022 03:51:19 -0400 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2065.outbound.protection.outlook.com [40.107.220.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7D05A11379F for ; Wed, 27 Apr 2022 00:48:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lyyxN8UoKxpUUKIfA/gCM2/6AaiwyIzStR2ajESh6tKeOffppvsDh/Y++fctb62HoDkIgker6+XfRvzX9+52OStrNYh/kx0mQAAsYS1/ZEaLbv6lJ2nBb0Ej2W/gDwXWN0HvMH0wLDq+ubEzpOYfzHoEjBbZdlBPgPgCLNN9/WQ2g6IlRPDzHz5Jb4pLbiCzu6ZmJEK1FB3ECFHARZ6VYP5SEoimWgFLw8OH5m+lhdnhdxpTbx75nxI2yEhllzpC6HDh0i0q8D4Fzwpn7OdBizzILFfNkNM5prx2EZnxRIUvFPmxKGe3QL8nm3evZYiEgaPMMcGXn2EfRvyM5NAK1g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=geOI8YRxKJsqpY5LdH038fvqEhriYRA2X69C7YeZVmc=; b=RJqEjTx4FnEufes90NlK2/Pv9kf8k4zTzA62okcOfOIcIhwQDQriW9YZDa5P9SRXkm4k8ZUe+CDiybbtn429nW2pUba3ENA/pl6V4KEFpFM59L34TBuuFMh14wptwmiujJITMExSnWoKUNWd+MPVuXoWRIHXp0LTwxQmm+2e5qD54VmPLaCxWIN//LVg1QYoi1zSJNk+YdiEC/hb6IcikjrlbEX/Xvzl027zsKsepApukmCYsJHWS4+0lopR5qDtbzjTieWTmWJxu4KewzIJHHvUk+iMfISosI5m7wZheYkTJk2304lJzh6CyHepXGgr44xhMArJK5MaGUIDMf1ygA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 149.199.62.198) smtp.rcpttodomain=linuxfoundation.org smtp.mailfrom=xilinx.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=xilinx.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xilinx.onmicrosoft.com; s=selector2-xilinx-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=geOI8YRxKJsqpY5LdH038fvqEhriYRA2X69C7YeZVmc=; b=sr81v9U60wkdEXBfGdW9Y9cepLish4DCkcRZwRIixyZLHoLiGd+Le4Gs/RA+4v5VTNyw6Ch9IbAMazc2qZFoKok+S2XEU2fBgsICnjwc/oUMh28Vw+hKqL9VeozNaPPoPF2OCeRAI4SeVKxLshpBwggdUbzp0EHOh4yXZlAGYMw= Received: from SA9P221CA0004.NAMP221.PROD.OUTLOOK.COM (2603:10b6:806:25::9) by BL3PR02MB8236.namprd02.prod.outlook.com (2603:10b6:208:343::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5186.14; Wed, 27 Apr 2022 07:48:05 +0000 Received: from SN1NAM02FT0024.eop-nam02.prod.protection.outlook.com (2603:10b6:806:25:cafe::29) by SA9P221CA0004.outlook.office365.com (2603:10b6:806:25::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5186.14 via Frontend Transport; Wed, 27 Apr 2022 07:48:05 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 149.199.62.198) smtp.mailfrom=xilinx.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=xilinx.com; Received-SPF: Pass (protection.outlook.com: domain of xilinx.com designates 149.199.62.198 as permitted sender) receiver=protection.outlook.com; client-ip=149.199.62.198; helo=xsj-pvapexch01.xlnx.xilinx.com; Received: from xsj-pvapexch01.xlnx.xilinx.com (149.199.62.198) by SN1NAM02FT0024.mail.protection.outlook.com (10.97.5.147) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5206.12 via Frontend Transport; Wed, 27 Apr 2022 07:48:05 +0000 Received: from xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) by xsj-pvapexch01.xlnx.xilinx.com (172.19.86.40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.14; Wed, 27 Apr 2022 00:48:04 -0700 Received: from smtp.xilinx.com (172.19.127.96) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server id 15.1.2176.14 via Frontend Transport; Wed, 27 Apr 2022 00:48:04 -0700 Envelope-to: gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Received: from [172.19.2.91] (port=54884 helo=xsjpmteam52.xilinx.com) by smtp.xilinx.com with esmtp (Exim 4.90) (envelope-from ) id 1njcP6-0002bP-OG; Wed, 27 Apr 2022 00:48:04 -0700 From: Abhyuday Godhasara To: CC: , , , , , , Subject: [PATCH 2/2] driver: soc: xilinx: Update function prototype for xlnx_unregister_event Date: Wed, 27 Apr 2022 00:48:03 -0700 Message-ID: <20220427074803.19009-3-abhyuday.godhasara@xilinx.com> X-Mailer: git-send-email 2.32.0.93.g670b81a In-Reply-To: <20220427074803.19009-1-abhyuday.godhasara@xilinx.com> References: <20220427074803.19009-1-abhyuday.godhasara@xilinx.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: de752158-56ea-4946-f371-08da28224392 X-MS-TrafficTypeDiagnostic: BL3PR02MB8236:EE_ X-Microsoft-Antispam-PRVS: X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: tlhBD3k1lOp7FhaNd54Cxp4WKCNZielR9vc2kKpLvuPyGVR97tt4oZgFjwk4Xs5IYWaMDZQK6MKGLLDyT+0cAz9ax9WPXhm568bX5e562BUFXlQEFQTbZgeWYB64PjM36XuR9mIzl1DS09K0n9xSL5j54SI3Jbmyb/BFHbo+twB9qjSUGdMCMXDGP7GXJG4iYT1f9KmFwr29hAnXzeqS1lw0kk1gDpklGnK472iltsSgE4wLAjRMByqH5eaRIg0leFbua5kR373v6irxW9uBk5QWNtEyIebo5a44ehnSs/pyXJDkzxiKxsQLTDjN8L6FJ02PW3hEs2qJKInG43q6jA3Fo1FwuC0hmvEs3FO8KCk+EyyZph87n0uaqr/6XYnlzzJMXypYwwo/ODZfZsSgmn0XUXBHJe9RyMh64K1dQn1N4l7IMKTxbEaQcOZg2q6ELoQt1shDXFM9ksAMwdyaD8zVy/COmZKBat4WBD3GKNgiAotlqcmgI0WOVG9Uj+/2VzW7Zdme7cz4EugrdibOjppK8kUgkinJLI4UPWKeAG/Sf/3OVXhEEl93MTH8lprR4jopd9PNNYf+e3zEUXjoeqqgQlNLY+qhg6oV/4UxTHf4BC6EmgIq1IRy4zyagCdXx88lAEkZifcNanJxq1Jorm6TqP0uVDwiB9BRVyKZeKIRllr2YHrGnIGF+8zSeOExjAzcmX3ZXTLJhY17s6Se1g== X-Forefront-Antispam-Report: CIP:149.199.62.198;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:xsj-pvapexch01.xlnx.xilinx.com;PTR:unknown-62-198.xilinx.com;CAT:NONE;SFS:(13230001)(4636009)(46966006)(40470700004)(36840700001)(6916009)(70586007)(70206006)(8676002)(54906003)(356005)(4326008)(2616005)(7636003)(316002)(82310400005)(7696005)(26005)(40460700003)(36860700001)(426003)(1076003)(508600001)(186003)(47076005)(336012)(83380400001)(2906002)(15650500001)(44832011)(9786002)(5660300002)(8936002)(36756003)(102446001);DIR:OUT;SFP:1101; X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Apr 2022 07:48:05.3268 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: de752158-56ea-4946-f371-08da28224392 X-MS-Exchange-CrossTenant-Id: 657af505-d5df-48d0-8300-c31994686c5c X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=657af505-d5df-48d0-8300-c31994686c5c;Ip=[149.199.62.198];Helo=[xsj-pvapexch01.xlnx.xilinx.com] X-MS-Exchange-CrossTenant-AuthSource: SN1NAM02FT0024.eop-nam02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL3PR02MB8236 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" As per the current implementation only single callback data gets saved per event, driver is throwing an error if try to register multiple callback for same event. So at time of unregistration of any event required things are event details and callback handler as parameter of xlnx_unregister_event(). As part of adding support of multiple callbacks for same event also require change in prototype of xlnx_unregister_event(). During unregistration of any events, now required things are event details, callback handler and agent's private data as parameter of xlnx_unregister_event(). Also modify the usage of xlnx_unregister_event() in xilinx/zynqmp_power.c driver as per new implementation. Signed-off-by: Abhyuday Godhasara --- drivers/soc/xilinx/xlnx_event_manager.c | 58 ++++++++++++++------- drivers/soc/xilinx/zynqmp_power.c | 7 +-- include/linux/firmware/xlnx-event-manager.h | 4 +- 3 files changed, 45 insertions(+), 24 deletions(-) diff --git a/drivers/soc/xilinx/xlnx_event_manager.c b/drivers/soc/xilinx/x= lnx_event_manager.c index f89000dc33a3..5dcb7665fe22 100644 --- a/drivers/soc/xilinx/xlnx_event_manager.c +++ b/drivers/soc/xilinx/xlnx_event_manager.c @@ -41,6 +41,8 @@ static int event_manager_availability =3D -EACCES; static DEFINE_HASHTABLE(reg_driver_map, REGISTERED_DRIVER_MAX_ORDER); static int sgi_num =3D XLNX_EVENT_SGI_NUM; =20 +static bool is_need_to_unregister; + /** * struct agent_cb - Registered callback function and private data. * @agent_data: Data passed back to handler function. @@ -189,6 +191,8 @@ static int xlnx_remove_cb_for_suspend(event_cb_func_t c= b_fun) struct agent_cb *cb_pos; struct agent_cb *cb_next; =20 + is_need_to_unregister =3D false; + /* Check for existing entry in hash table for given cb_type */ hash_for_each_possible(reg_driver_map, eve_data, hentry, PM_INIT_SUSPEND_= CB) { if (eve_data->cb_type =3D=3D PM_INIT_SUSPEND_CB) { @@ -203,6 +207,7 @@ static int xlnx_remove_cb_for_suspend(event_cb_func_t c= b_fun) /* remove an object from a hashtable */ hash_del(&eve_data->hentry); kfree(eve_data); + is_need_to_unregister =3D true; } } if (!is_callback_found) { @@ -214,7 +219,7 @@ static int xlnx_remove_cb_for_suspend(event_cb_func_t c= b_fun) } =20 static int xlnx_remove_cb_for_notify_event(const u32 node_id, const u32 ev= ent, - event_cb_func_t cb_fun) + event_cb_func_t cb_fun, void *data) { bool is_callback_found =3D false; struct registered_event_data *eve_data; @@ -222,20 +227,28 @@ static int xlnx_remove_cb_for_notify_event(const u32 = node_id, const u32 event, struct agent_cb *cb_pos; struct agent_cb *cb_next; =20 + is_need_to_unregister =3D false; + /* Check for existing entry in hash table for given key id */ hash_for_each_possible(reg_driver_map, eve_data, hentry, key) { if (eve_data->key =3D=3D key) { /* Delete the list of callback */ list_for_each_entry_safe(cb_pos, cb_next, &eve_data->cb_list_head, list= ) { - if (cb_pos->eve_cb =3D=3D cb_fun) { + if (cb_pos->eve_cb =3D=3D cb_fun && + cb_pos->agent_data =3D=3D data) { is_callback_found =3D true; list_del_init(&cb_pos->list); kfree(cb_pos); } } - /* remove an object from a HASH table */ - hash_del(&eve_data->hentry); - kfree(eve_data); + + /* Remove HASH table if callback list is empty */ + if (list_empty(&eve_data->cb_list_head)) { + /* remove an object from a HASH table */ + hash_del(&eve_data->hentry); + kfree(eve_data); + is_need_to_unregister =3D true; + } } } if (!is_callback_found) { @@ -307,7 +320,7 @@ int xlnx_register_event(const enum pm_api_cb_id cb_type= , const u32 node_id, cons eve =3D event & (1 << pos); if (!eve) continue; - xlnx_remove_cb_for_notify_event(node_id, eve, cb_fun); + xlnx_remove_cb_for_notify_event(node_id, eve, cb_fun, data); } } } @@ -329,10 +342,10 @@ int xlnx_register_event(const enum pm_api_cb_id cb_ty= pe, const u32 node_id, cons eve =3D event & (1 << pos); if (!eve) continue; - xlnx_remove_cb_for_notify_event(node_id, eve, cb_fun); + xlnx_remove_cb_for_notify_event(node_id, eve, cb_fun, data); } } else { - xlnx_remove_cb_for_notify_event(node_id, event, cb_fun); + xlnx_remove_cb_for_notify_event(node_id, event, cb_fun, data); } return ret; } @@ -350,15 +363,18 @@ EXPORT_SYMBOL_GPL(xlnx_register_event); * @node_id: Node-Id related to event. * @event: Event Mask for the Error Event. * @cb_fun: Function pointer of callback function. + * @data: Pointer of agent's private data. * * Return: Returns 0 on successful unregistration else error code. */ int xlnx_unregister_event(const enum pm_api_cb_id cb_type, const u32 node_= id, const u32 event, - event_cb_func_t cb_fun) + event_cb_func_t cb_fun, void *data) { - int ret; + int ret =3D 0; u32 eve, pos; =20 + is_need_to_unregister =3D false; + if (event_manager_availability) return event_manager_availability; =20 @@ -375,23 +391,26 @@ int xlnx_unregister_event(const enum pm_api_cb_id cb_= type, const u32 node_id, co } else { /* Remove Node-Id/Event from hash table */ if (!xlnx_is_error_event(node_id)) { - xlnx_remove_cb_for_notify_event(node_id, event, cb_fun); + xlnx_remove_cb_for_notify_event(node_id, event, cb_fun, data); } else { for (pos =3D 0; pos < MAX_BITS; pos++) { eve =3D event & (1 << pos); if (!eve) continue; =20 - xlnx_remove_cb_for_notify_event(node_id, eve, cb_fun); + xlnx_remove_cb_for_notify_event(node_id, eve, cb_fun, data); } } =20 - /* Un-register for Node-Id/Event combination */ - ret =3D zynqmp_pm_register_notifier(node_id, event, false, false); - if (ret) { - pr_err("%s() failed for 0x%x and 0x%x: %d\n", - __func__, node_id, event, ret); - return ret; + /* Un-register if list is empty */ + if (is_need_to_unregister) { + /* Un-register for Node-Id/Event combination */ + ret =3D zynqmp_pm_register_notifier(node_id, event, false, false); + if (ret) { + pr_err("%s() failed for 0x%x and 0x%x: %d\n", + __func__, node_id, event, ret); + return ret; + } } } =20 @@ -447,7 +466,8 @@ static void xlnx_call_notify_cb_handler(const u32 *payl= oad) list) { /* Remove already registered event from hash table */ xlnx_remove_cb_for_notify_event(payload[1], payload[2], - cb_pos->eve_cb); + cb_pos->eve_cb, + cb_pos->agent_data); } } } diff --git a/drivers/soc/xilinx/zynqmp_power.c b/drivers/soc/xilinx/zynqmp_= power.c index 859dd31b6eff..78a8a7545d1e 100644 --- a/drivers/soc/xilinx/zynqmp_power.c +++ b/drivers/soc/xilinx/zynqmp_power.c @@ -208,7 +208,7 @@ static int zynqmp_pm_probe(struct platform_device *pdev) GFP_KERNEL); if (!zynqmp_pm_init_suspend_work) { xlnx_unregister_event(PM_INIT_SUSPEND_CB, 0, 0, - suspend_event_callback); + suspend_event_callback, NULL); return -ENOMEM; } event_registered =3D true; @@ -263,7 +263,8 @@ static int zynqmp_pm_probe(struct platform_device *pdev) ret =3D sysfs_create_file(&pdev->dev.kobj, &dev_attr_suspend_mode.attr); if (ret) { if (event_registered) { - xlnx_unregister_event(PM_INIT_SUSPEND_CB, 0, 0, suspend_event_callback); + xlnx_unregister_event(PM_INIT_SUSPEND_CB, 0, 0, suspend_event_callback, + NULL); event_registered =3D false; } dev_err(&pdev->dev, "unable to create sysfs interface\n"); @@ -277,7 +278,7 @@ static int zynqmp_pm_remove(struct platform_device *pde= v) { sysfs_remove_file(&pdev->dev.kobj, &dev_attr_suspend_mode.attr); if (event_registered) - xlnx_unregister_event(PM_INIT_SUSPEND_CB, 0, 0, suspend_event_callback); + xlnx_unregister_event(PM_INIT_SUSPEND_CB, 0, 0, suspend_event_callback, = NULL); =20 if (!rx_chan) mbox_free_channel(rx_chan); diff --git a/include/linux/firmware/xlnx-event-manager.h b/include/linux/fi= rmware/xlnx-event-manager.h index 3f87c4929d21..82e8254b0f80 100644 --- a/include/linux/firmware/xlnx-event-manager.h +++ b/include/linux/firmware/xlnx-event-manager.h @@ -17,7 +17,7 @@ int xlnx_register_event(const enum pm_api_cb_id cb_type, = const u32 node_id, event_cb_func_t cb_fun, void *data); =20 int xlnx_unregister_event(const enum pm_api_cb_id cb_type, const u32 node_= id, - const u32 event, event_cb_func_t cb_fun); + const u32 event, event_cb_func_t cb_fun, void *data); #else static inline int xlnx_register_event(const enum pm_api_cb_id cb_type, con= st u32 node_id, const u32 event, const bool wake, @@ -27,7 +27,7 @@ static inline int xlnx_register_event(const enum pm_api_c= b_id cb_type, const u32 } =20 static inline int xlnx_unregister_event(const enum pm_api_cb_id cb_type, c= onst u32 node_id, - const u32 event, event_cb_func_t cb_fun) + const u32 event, event_cb_func_t cb_fun, void *data) { return -ENODEV; } --=20 2.32.0.93.g670b81a