From patchwork Fri Apr 24 04:54:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 11507069 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 77E2F1575 for ; Fri, 24 Apr 2020 04:54:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5A7232084D for ; Fri, 24 Apr 2020 04:54:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="SZCr2vhV" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726317AbgDXEyS (ORCPT ); Fri, 24 Apr 2020 00:54:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37490 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725554AbgDXEyR (ORCPT ); Fri, 24 Apr 2020 00:54:17 -0400 Received: from mail-pl1-x642.google.com (mail-pl1-x642.google.com [IPv6:2607:f8b0:4864:20::642]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DBAB9C09B045 for ; Thu, 23 Apr 2020 21:54:16 -0700 (PDT) Received: by mail-pl1-x642.google.com with SMTP id f8so3314448plt.2 for ; Thu, 23 Apr 2020 21:54:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=P/87mFoNmKxK7YfbOWtdLLTzzatK113qb2wR23Q9p78=; b=SZCr2vhVURBX5fJemEcrimD6OrciAmkYuSRentJXKzegReuReDPH8cRjEHP4AANTxr nbEd4Uasqrn0x3OC2KwW6F8NyTctBcZURzadQg1s/WuzBA/UKtZU9ojVrZS2b6qpxxRn 6fb1itDIsCQl67yiNkLklbBzcWUAn4UhyOziQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=P/87mFoNmKxK7YfbOWtdLLTzzatK113qb2wR23Q9p78=; b=d7bUUPk/Ci3opyxvQDK71Em1yQ1S4c1POnU/Hhh9dJ3UY44kcRlU3xA+gKQ7OlE1rH /JV2TqyUWkBt3pnsdFD1hvwxQoynz9ddANex89nqKhQc8K02SGBDXJoLOQUkEKRlsGg6 Y9bjYahLThOIEW88JQA82sbf0mpbBhAEGwbaiqMaNAaizT+ONqd72/wFvEw9xokOzVkA O9eq0vBsqOBzqXDPxY/qSW9W9bXe0N8lvJ81QBCW3KzDMVdg+3E+b36DN68mwlkoAX4F j3zR96G2CGAg3DzoOSF3V6TFl9B6dO4qMMaRvV32kL2Tw5zY2maX4/DQrttvcpo5HVl+ fwOw== X-Gm-Message-State: AGi0PuZKju9tZi+stAdhsbt2qrkzLjZXLkE6top9aeTRnzu54sc4Yiap CIOgAWkV/8iNtbl9OncAuQ4pjA== X-Google-Smtp-Source: APiQypKhOofMDS9TPyKVgPgTHKmvZcFdTNPJm97HwmnYJKZBRHLJlJsGQ1KNLkJRA7UIIZy1eUNe8w== X-Received: by 2002:a17:90a:328f:: with SMTP id l15mr4502518pjb.77.1587704056390; Thu, 23 Apr 2020 21:54:16 -0700 (PDT) Received: from smtp.gmail.com ([2620:15c:202:1:fa53:7765:582b:82b9]) by smtp.gmail.com with ESMTPSA id 62sm4344680pfu.181.2020.04.23.21.54.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Apr 2020 21:54:15 -0700 (PDT) From: Stephen Boyd To: Andy Gross , Bjorn Andersson Cc: linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, Maulik Shah , Douglas Anderson Subject: [PATCH 1/3] soc: qcom: rpmh-rsc: Remove tcs_is_free() API Date: Thu, 23 Apr 2020 21:54:12 -0700 Message-Id: <20200424045414.133381-2-swboyd@chromium.org> X-Mailer: git-send-email 2.26.2.303.gf8c07b1a785-goog In-Reply-To: <20200424045414.133381-1-swboyd@chromium.org> References: <20200424045414.133381-1-swboyd@chromium.org> MIME-Version: 1.0 Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org This API does very little. Let's replace all the callsites with the normal operations that would be done on top of the bitmap that tcs_in_use is. This simplifies and reduces the code size. Cc: Maulik Shah Cc: Douglas Anderson Signed-off-by: Stephen Boyd --- drivers/soc/qcom/rpmh-rsc.c | 56 +++++++++++-------------------------- 1 file changed, 17 insertions(+), 39 deletions(-) diff --git a/drivers/soc/qcom/rpmh-rsc.c b/drivers/soc/qcom/rpmh-rsc.c index 060be10bc491..76e0294a672c 100644 --- a/drivers/soc/qcom/rpmh-rsc.c +++ b/drivers/soc/qcom/rpmh-rsc.c @@ -172,22 +172,6 @@ static void write_tcs_reg_sync(struct rsc_drv *drv, int reg, int tcs_id, } } -/** - * tcs_is_free() - Return if a TCS is totally free. - * @drv: The RSC controller. - * @tcs_id: The global ID of this TCS. - * - * Returns true if nobody has claimed this TCS (by setting tcs_in_use). - * - * Context: Must be called with the drv->lock held. - * - * Return: true if the given TCS is free. - */ -static bool tcs_is_free(struct rsc_drv *drv, int tcs_id) -{ - return !test_bit(tcs_id, drv->tcs_in_use); -} - /** * tcs_invalidate() - Invalidate all TCSes of the given type (sleep or wake). * @drv: The RSC controller. @@ -500,7 +484,7 @@ static void __tcs_buffer_write(struct rsc_drv *drv, int tcs_id, int cmd_id, * * Return: 0 if nothing in flight or -EBUSY if we should try again later. * The caller must re-enable interrupts between tries since that's - * the only way tcs_is_free() will ever return true and the only way + * the only way tcs_in_use will ever be updated and the only way * RSC_DRV_CMD_ENABLE will ever be cleared. */ static int check_for_req_inflight(struct rsc_drv *drv, struct tcs_group *tcs, @@ -508,17 +492,14 @@ static int check_for_req_inflight(struct rsc_drv *drv, struct tcs_group *tcs, { unsigned long curr_enabled; u32 addr; - int i, j, k; - int tcs_id = tcs->offset; + int j, k; + int i = tcs->offset; - for (i = 0; i < tcs->num_tcs; i++, tcs_id++) { - if (tcs_is_free(drv, tcs_id)) - continue; - - curr_enabled = read_tcs_reg(drv, RSC_DRV_CMD_ENABLE, tcs_id); + for_each_set_bit_from(i, drv->tcs_in_use, tcs->offset + tcs->num_tcs) { + curr_enabled = read_tcs_reg(drv, RSC_DRV_CMD_ENABLE, i); for_each_set_bit(j, &curr_enabled, MAX_CMDS_PER_TCS) { - addr = read_tcs_cmd(drv, RSC_DRV_CMD_ADDR, tcs_id, j); + addr = read_tcs_cmd(drv, RSC_DRV_CMD_ADDR, i, j); for (k = 0; k < msg->num_cmds; k++) { if (addr == msg->cmds[k].addr) return -EBUSY; @@ -536,18 +517,18 @@ static int check_for_req_inflight(struct rsc_drv *drv, struct tcs_group *tcs, * * Must be called with the drv->lock held since that protects tcs_in_use. * - * Return: The first tcs that's free. + * Return: The first tcs that's free or -EBUSY if all in use. */ static int find_free_tcs(struct tcs_group *tcs) { - int i; + const struct rsc_drv *drv = tcs->drv; + unsigned long i; - for (i = 0; i < tcs->num_tcs; i++) { - if (tcs_is_free(tcs->drv, tcs->offset + i)) - return tcs->offset + i; - } + i = find_next_zero_bit(drv->tcs_in_use, MAX_TCS_NR, tcs->offset); + if (i > tcs->offset + tcs->num_tcs) + return -EBUSY; - return -EBUSY; + return i; } /** @@ -744,8 +725,8 @@ int rpmh_rsc_write_ctrl_data(struct rsc_drv *drv, const struct tcs_request *msg) */ static bool rpmh_rsc_ctrlr_is_busy(struct rsc_drv *drv) { - int m; - struct tcs_group *tcs = &drv->tcs[ACTIVE_TCS]; + unsigned long set; + const struct tcs_group *tcs = &drv->tcs[ACTIVE_TCS]; /* * If we made an active request on a RSC that does not have a @@ -756,12 +737,9 @@ static bool rpmh_rsc_ctrlr_is_busy(struct rsc_drv *drv) if (!tcs->num_tcs) tcs = &drv->tcs[WAKE_TCS]; - for (m = tcs->offset; m < tcs->offset + tcs->num_tcs; m++) { - if (!tcs_is_free(drv, m)) - return true; - } + set = find_next_bit(drv->tcs_in_use, MAX_TCS_NR, tcs->offset); - return false; + return set < tcs->offset + tcs->num_tcs; } /** From patchwork Fri Apr 24 04:54:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 11507075 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 959C315AB for ; Fri, 24 Apr 2020 04:54:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7779F20774 for ; Fri, 24 Apr 2020 04:54:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="Qn5e5cwa" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726436AbgDXEyZ (ORCPT ); Fri, 24 Apr 2020 00:54:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37500 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726304AbgDXEyS (ORCPT ); Fri, 24 Apr 2020 00:54:18 -0400 Received: from mail-pj1-x1044.google.com (mail-pj1-x1044.google.com [IPv6:2607:f8b0:4864:20::1044]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EA659C09B046 for ; Thu, 23 Apr 2020 21:54:17 -0700 (PDT) Received: by mail-pj1-x1044.google.com with SMTP id fu13so2889940pjb.5 for ; Thu, 23 Apr 2020 21:54:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=xgfluhA4o9GgClkBYCNW13vXSmjjsiy2AV2QktrmyMU=; b=Qn5e5cwaikIVGeMNavK2TKUVwo1B7GSRSSg9PjyR5r7ZDh6ETN9O2fpo7NDnLJpB16 rOWcqxfVvmwTn04Ahy1q4fx6A5mudVuiLfXDQ4EMpNWDyc/UrQpaqh36SqJSPEbzBuvx dINlawAr2BIOGBdL6IHoXO19ofPaoSoo0gbRQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=xgfluhA4o9GgClkBYCNW13vXSmjjsiy2AV2QktrmyMU=; b=S0WvOzAq88Idvi9FZJYSo5RmN9aiEfPeQ7OQaid+8qZidirQvJwGCZ2BU/NLhxsvCw K3ouyQgakTnXmZdTwOFgRsOV+JE4IaIM/ZqCrB43scrJoqOW/McO17oIc9MRA4FQm8VZ GSo7/wQcIZay+QH0OQQJ9LCTYp/b4AKI3aTMv4cGfK9RArPaZFX5IbkWxcmcCbco6H2r NA0DdDGLW/sARON3Ud7q/rZLsg+4n0mYIaQeMTwrbexjG+uV6u3ZbSRzNOaNMOiFP9Sl 2hVprOnRcBlPHWQAe/G2hsu5YVPCrO1ef990ygtpkGeQa8+Dioz8b9tt8AZ6fJNl8j84 b4jg== X-Gm-Message-State: AGi0Pub5R2Qn+g6ldGos0/wVIBWRBbVDErJWNcRbM8ATIzFpvYmmpYeb 9V6LiPu/wPs7kFQduqjkZF7Ufg== X-Google-Smtp-Source: APiQypL1nl3kPHkvfAWu17BMV6TTkR+DpK5VuCgPjoEHDgHOfIy8cu8QESaFg4V7vDVkBKQZlk4ywg== X-Received: by 2002:a17:90a:1955:: with SMTP id 21mr4358869pjh.133.1587704057460; Thu, 23 Apr 2020 21:54:17 -0700 (PDT) Received: from smtp.gmail.com ([2620:15c:202:1:fa53:7765:582b:82b9]) by smtp.gmail.com with ESMTPSA id 62sm4344680pfu.181.2020.04.23.21.54.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Apr 2020 21:54:16 -0700 (PDT) From: Stephen Boyd To: Andy Gross , Bjorn Andersson Cc: linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, Maulik Shah , Douglas Anderson Subject: [PATCH 2/3] soc: qcom: rpmh-rsc: Loop over less bits in irq handler Date: Thu, 23 Apr 2020 21:54:13 -0700 Message-Id: <20200424045414.133381-3-swboyd@chromium.org> X-Mailer: git-send-email 2.26.2.303.gf8c07b1a785-goog In-Reply-To: <20200424045414.133381-1-swboyd@chromium.org> References: <20200424045414.133381-1-swboyd@chromium.org> MIME-Version: 1.0 Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org readl returns a u32, and BITS_PER_LONG is different on 32-bit vs. 64-bit architectures. Let's make the type we stash the readl into a u32 and then loop over the bits set in that type instead of potentially looping over more bits than we will ever need to. Cc: Maulik Shah Cc: Douglas Anderson Signed-off-by: Stephen Boyd Reviewed-by: Bjorn Andersson Reviewed-by: Douglas Anderson --- drivers/soc/qcom/rpmh-rsc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/soc/qcom/rpmh-rsc.c b/drivers/soc/qcom/rpmh-rsc.c index 76e0294a672c..462dd267afef 100644 --- a/drivers/soc/qcom/rpmh-rsc.c +++ b/drivers/soc/qcom/rpmh-rsc.c @@ -365,13 +365,13 @@ static irqreturn_t tcs_tx_done(int irq, void *p) { struct rsc_drv *drv = p; int i, j, err = 0; - unsigned long irq_status; + u32 irq_status; const struct tcs_request *req; struct tcs_cmd *cmd; irq_status = readl_relaxed(drv->tcs_base + RSC_DRV_IRQ_STATUS); - for_each_set_bit(i, &irq_status, BITS_PER_LONG) { + for_each_set_bit(i, &irq_status, BITS_PER_TYPE(u32)) { req = get_req_from_tcs(drv, i); if (!req) { WARN_ON(1); From patchwork Fri Apr 24 04:54:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 11507071 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 124261575 for ; Fri, 24 Apr 2020 04:54:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EEE7C20774 for ; Fri, 24 Apr 2020 04:54:21 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="VU1s+LT3" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726399AbgDXEyV (ORCPT ); Fri, 24 Apr 2020 00:54:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37502 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726295AbgDXEyU (ORCPT ); Fri, 24 Apr 2020 00:54:20 -0400 Received: from mail-pl1-x644.google.com (mail-pl1-x644.google.com [IPv6:2607:f8b0:4864:20::644]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BE45CC09B047 for ; Thu, 23 Apr 2020 21:54:18 -0700 (PDT) Received: by mail-pl1-x644.google.com with SMTP id t16so3306510plo.7 for ; Thu, 23 Apr 2020 21:54:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Z/YsFv/10NhkBeiZjaV6l6O7A2swaX/eVpoeaYwPiNg=; b=VU1s+LT31TEalxhE+dHeMgtEMRrST5oIP96hg6VW4pHGnP+qE7kUxu38tEe52CypLI xuKf3XnGnEDYe3ajNmaDD67pxCiXLlDvRJ5Fxn4hSq61lETE0fcgJ4nc9BHFQegGTQZk Q6saQBat6gqeg9CpStPfAtuouhMP8wx4u6uhk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Z/YsFv/10NhkBeiZjaV6l6O7A2swaX/eVpoeaYwPiNg=; b=OO9I5VgA9+KgAVHSMJHaNXo6SF60by82BkN+WAR5UkWrNn3WAyL6vETTAums2xPV0k 1fv50FjtXPOdWYFGLXR2FE25mIjG1ostrvhV6znzjRwsWHeheeSpaIPx7n8dOMlM96qD Xz/WBdDdPFFte5iZqCJd1VRuPSTtw6ex9eoRj5RmINyGy0g6PB8PfChOM4sbHGfqme84 em2qBVhPBsVX88WLaTjLjCl6jDZkcOsESu63pfrJyWI77zlV7b4sRZ1t+OcrfDVXHR7V Sab/gwWTAHTIdJdyz8zxhPUlbkel3+VJq/2XDI4M/kBsAn6j+2EuV6D97YP0hNsq5cLI yFwQ== X-Gm-Message-State: AGi0PuaHmNpCzuzMkdVJQumBlCjSYvKOYKcUxixQHYb6mR+N1sx/4cq8 KOqaE3W+bco3mvjSwfOU54kqFQ== X-Google-Smtp-Source: APiQypI6m7J+NqwxX2iu4a6RtckM854S3bBsQf98LAgWiQRqbCtnJRyA11TOuBgHg51CtgGWm2KTmQ== X-Received: by 2002:a17:902:7148:: with SMTP id u8mr6922882plm.13.1587704058295; Thu, 23 Apr 2020 21:54:18 -0700 (PDT) Received: from smtp.gmail.com ([2620:15c:202:1:fa53:7765:582b:82b9]) by smtp.gmail.com with ESMTPSA id 62sm4344680pfu.181.2020.04.23.21.54.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Apr 2020 21:54:17 -0700 (PDT) From: Stephen Boyd To: Andy Gross , Bjorn Andersson Cc: linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, Maulik Shah , Douglas Anderson Subject: [PATCH 3/3] soc: qcom: rpmh-rsc: Fold WARN_ON() into if condition Date: Thu, 23 Apr 2020 21:54:14 -0700 Message-Id: <20200424045414.133381-4-swboyd@chromium.org> X-Mailer: git-send-email 2.26.2.303.gf8c07b1a785-goog In-Reply-To: <20200424045414.133381-1-swboyd@chromium.org> References: <20200424045414.133381-1-swboyd@chromium.org> MIME-Version: 1.0 Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org Move the WARN_ON() into the if condition so the compiler can see that the branch is unlikely() and possibly optimize it better. Cc: Maulik Shah Cc: Douglas Anderson Signed-off-by: Stephen Boyd Reviewed-by: Bjorn Andersson Reviewed-by: Douglas Anderson --- drivers/soc/qcom/rpmh-rsc.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/soc/qcom/rpmh-rsc.c b/drivers/soc/qcom/rpmh-rsc.c index 462dd267afef..f7763f008e03 100644 --- a/drivers/soc/qcom/rpmh-rsc.c +++ b/drivers/soc/qcom/rpmh-rsc.c @@ -373,10 +373,8 @@ static irqreturn_t tcs_tx_done(int irq, void *p) for_each_set_bit(i, &irq_status, BITS_PER_TYPE(u32)) { req = get_req_from_tcs(drv, i); - if (!req) { - WARN_ON(1); + if (WARN_ON(!req)) goto skip; - } err = 0; for (j = 0; j < req->num_cmds; j++) {