Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp712646ybh; Wed, 11 Mar 2020 09:18:16 -0700 (PDT) X-Google-Smtp-Source: ADFU+vvezzeZt/ZOmOM1Jiq4kxZvsOEl/Kbz0H6v2S1dKkiR2E/KKN+e1I+J6p1MtRgI1t+19mae X-Received: by 2002:a9d:3ae:: with SMTP id f43mr2883022otf.159.1583943496003; Wed, 11 Mar 2020 09:18:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1583943495; cv=none; d=google.com; s=arc-20160816; b=i8BYm0yXj1eTF0qsQ6onTfDhFI6eNhNVyR/TzGKZ8exZDSSJ3Abe8l07zwy71zZZsT fkPGCcgWrvFB6hL64how2x5IT2OuyD9ruDVhxealjr+iobkYaOyepJViq19xGReODY4b Cj5bQOQCQ5jEYddWA+AqrsE+yPUVEfl07UHd5fFlsjEpkxrEAtyID/3GXKsETecosu3c WJZogqpybaC81dGWv2QrCLGQFgc7P6upanO6tMxprXhik4msTjxW6jVn8dARAhPdeBiJ qkVhMWyGf50t3sz3ahHvad40Jq+7I2KjdYPa69vBOT6KwtPU4cOlFEsA/HGskQAF+PLi i3hA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=eGB8HLn34Ay+oTWhql5ATheorHKXdDNb1Y38OeMfZ0w=; b=cTzhVzgmpCYLPxhq+DkHBK5ui4wRLclKhDDMPSO/Q0GZ+N1kTQ5gKEEU6GckGS6Uvs SDWNHisammYd6GSYMl6+362iPX2Vdl+fGloB3kk+v5pCvtUqyxSyQv3UoM5FWzqMZF4G wuqoEO+9Qw/llvx/JgqYbZZbue7D1Da/DQmqbvsKHfsEAvhf+KFum2Zk/d7h39wvevgp Wv7gfhGet6mnbF03+Rr/eQ5v7qHs+IlfEFsQMFVKJsM3itdGhspX8DpRr4+cS3K64pOx W+CcYCyi0bFCKEmM+3KkcnNWjmA0YPiI9VuPw7ctEb7k+doljQ4W2K0ZRiyZCw8x15Oh 1m+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=V1FnRQ1L; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 48si1441385otv.320.2020.03.11.09.18.03; Wed, 11 Mar 2020 09:18:15 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=V1FnRQ1L; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730099AbgCKQRb (ORCPT + 99 others); Wed, 11 Mar 2020 12:17:31 -0400 Received: from mail-pl1-f195.google.com ([209.85.214.195]:39416 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729921AbgCKQRa (ORCPT ); Wed, 11 Mar 2020 12:17:30 -0400 Received: by mail-pl1-f195.google.com with SMTP id j20so1323224pll.6 for ; Wed, 11 Mar 2020 09:17:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=eGB8HLn34Ay+oTWhql5ATheorHKXdDNb1Y38OeMfZ0w=; b=V1FnRQ1L3bblXi4JseWibpSlMPHSWCCa8FQHLozbgJBRgDgqs1i34nh150UBybDfY9 qpz1rYB7r8IltEW2bXAEI/YQh4n3irUfxn+TD5jdeT7sggcxFuUDoHr9TSSeKip0NXWo wDOPA2JYHFO211/0qHHCmU8ivE9ZRdPuIggeU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=eGB8HLn34Ay+oTWhql5ATheorHKXdDNb1Y38OeMfZ0w=; b=ZxSLVkyt/TkHvVZO1NJ+8gnKrTDf0hbimHOsNj1Lgn0nVs3KQEsMj/bFfbBfzzHjJg GRqxx21u+RqjGAe/pMin6HJCuV9e8oQ5eFGesGgPIYZgCU9dnj0nX/wl/Qrw1hqVoTc7 /Ub/tJm7qYuCsODQ4m/iy65mp2Aacrrndm2ahucgb43Z9kf1dPkPRm3zgAjAg8YCc8Nr ZlSfCwXhml6g1mSrxBOpKOmXeBpH5n/mKmrXvJ5UzAKC1N9LdB6MjZz0Bf00v1Oue78k SpX7Y1kNGMUKzXvaLuTt/tB0+ylmvSWCVZ+c/7SVh7i4sGg0jE8mz2GLJz1hiHExwvTF 9ZYQ== X-Gm-Message-State: ANhLgQ2ydDmHRm/BAepRlW9hYMpyqE72bn0XvqS5Jri0F82hutXxvzRB IO28goFZn8YAPdbNbF6YWY3hiw== X-Received: by 2002:a17:902:528:: with SMTP id 37mr3891621plf.322.1583943449493; Wed, 11 Mar 2020 09:17:29 -0700 (PDT) Received: from localhost ([2620:15c:202:1:4fff:7a6b:a335:8fde]) by smtp.gmail.com with ESMTPSA id bb13sm6129763pjb.43.2020.03.11.09.17.27 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 11 Mar 2020 09:17:28 -0700 (PDT) Date: Wed, 11 Mar 2020 09:17:26 -0700 From: Matthias Kaehlcke To: Doug Anderson Cc: Maulik Shah , Andy Gross , Bjorn Andersson , Rajendra Nayak , Evan Green , Stephen Boyd , Lina Iyer , linux-arm-msm , LKML Subject: Re: [RFT PATCH 1/9] drivers: qcom: rpmh-rsc: Clean code reading/writing regs/cmds Message-ID: <20200311161726.GA144492@google.com> References: <20200306235951.214678-1-dianders@chromium.org> <20200306155707.RFT.1.I1b754137e8089e46cf33fc2ea270734ec3847ec4@changeid> <85758e97-8c0c-5c4e-24ad-d3e8b2b01d3c@codeaurora.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.12.2 (2019-09-21) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On Wed, Mar 11, 2020 at 08:03:27AM -0700, Doug Anderson wrote: > Hi, > > On Wed, Mar 11, 2020 at 1:47 AM Maulik Shah wrote: > > > > Hi, > > > > On 3/7/2020 5:29 AM, Douglas Anderson wrote: > > > This patch makes two changes, both of which should be no-ops: > > > > > > 1. Make read_tcs_reg() / read_tcs_cmd() symmetric to write_tcs_reg() / > > > write_tcs_cmd(). > > > > i agree that there are two different write function doing same thing except last addition (RSC_DRV_CMD_OFFSET * cmd_id) > > > > can you please rename write_tcs_cmd() to write_tcs_reg(), add above operation in it, and then remove existing write_tcs_reg(). > > this way we have only one read and one write function. > > > > so at the end we will two function as, > > > > static u32 read_tcs_reg(struct rsc_drv *drv, int reg, int tcs_id, int cmd_id) > > { > > return readl_relaxed(drv->tcs_base + reg + RSC_DRV_TCS_OFFSET * tcs_id + > > RSC_DRV_CMD_OFFSET * cmd_id); > > } > > > > static void write_tcs_reg(struct rsc_drv *drv, int reg, int tcs_id, int cmd_id, > > u32 data) > > { > > writel_relaxed(data, drv->tcs_base + reg + RSC_DRV_TCS_OFFSET * tcs_id + > > RSC_DRV_CMD_OFFSET * cmd_id); > > } > > I can if you insist and this is still better than the existing > (inconsistent) code. > > ...but I still feel that having two functions adds value here. > > > Anyone else who is CCed want to weigh in and tie break? I agree with Doug, having two functions makes the code that calls them clearer. It makes it evident when a command is read/written and doesn't require a useless extra parameter when accessing a non-command register. > > > 2. Change the order of operations in the above functions to make it > > > more obvious to me what the math is doing. Specifically first you > > > want to find the right TCS, then the right register, and then > > > multiply by the command ID if necessary. > > With above change, i don't think you need to re-order this. > > specifically from tcs->base, we find right "reg" first and if it happens to be tcs then intended tcs, and then cmd inside tcs. > > There was never any "need" to re-order. That math works out to be the > same. This is just clearer. > > As an example, let's look at this: > > struct point { > int x; > int y; > }; > struct point points[10]; > > Let's say you have: > void *points_base = &(points[0]); > > ...and now you want to find &(points[5].y). What does your math look like? > > a) points_base + (sizeof(struct point) * 5) + 4 ; > > ...or... > > b) points_base + 4 + (sizeof(struct point) * 5); > > > Both calculations give the same result, but I am arguring that "a)" is > more intuitive. Specifically you deal with the array access first and > then deal with the offset within the structure that you found. +1