Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp619138img; Wed, 20 Mar 2019 07:31:21 -0700 (PDT) X-Google-Smtp-Source: APXvYqxdUCkpXkps64wypqGraaIY4MZYIHLNG84vEEiZq8pnFLTt9s/vgZhzh2TAZBqTlW3OJDE1 X-Received: by 2002:a17:902:248:: with SMTP id 66mr8448599plc.286.1553092281484; Wed, 20 Mar 2019 07:31:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553092281; cv=none; d=google.com; s=arc-20160816; b=FCSgIVo5XFbp/EsPFaqvuzAB4H28yuI5qi6IQSByiMLo87b6jkCQVPy8kmK2K4e5sO 7CAKmRTKet772hoxMr5ICDlmHWopTKc8Oasng8vJ37w3DA8mmQfBcTXvP5JDteFnXQ3c fnk97Umc18yRhLKvb3N9S3xaGDI8mg7RU5In+EQ+fIiOvfQ4vJBrBGl1XWOJI2QfnNDQ oAggMmidl9snC9lQFCn0YSKKG69A3VHvYk3AtmlrIj7+3rZXatbC/OoOA9oQNAL8sHwU 9aROCV5xbfyciotHZe2IKb8RFbKOwFjq4lYtt0ck2W0WY4yNsWXe9pVM4Vx32dxcrbzB CBHQ== 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=aIi4ddq5S6Ln3Ix0EW6HiRXfhoBMl6atbJ4RXLkwiyw=; b=fbIdfpwtBTYo+Z5vtLcODfx5GnZI4DfvXDDCaPr2ywcEWhDwWLjLcaAAT9XaHYa08G hludlS995UKzjBMUma4yKVocunCsrESbjvG6ZNYKSNMIZD8N/sytQQ9WFzEP9Rm6fmlM B5MnveD7l2+MPejpDHiCkHk0SozFJ+/dzD1mZhG1kGjD66F6DUJ1RKx8yfo03eD3L07K BcOHBN6McLGOjfN3XHKLieYgo5G54cz0GXaSoRGZwno23aXS5J3j7CfbK3P9xyZS2ueZ qT3wJ1w3vM7nGTmCCRcXwguJIhyJZTFMj4kKq8cvMyM8mpH67ymAbiq6gJsDPQ6PXz6a AjWw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=IzkUIuyS; 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=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r9si1740064pgp.193.2019.03.20.07.31.05; Wed, 20 Mar 2019 07:31:21 -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=@linaro.org header.s=google header.b=IzkUIuyS; 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=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727605AbfCTO3G (ORCPT + 99 others); Wed, 20 Mar 2019 10:29:06 -0400 Received: from mail-wm1-f65.google.com ([209.85.128.65]:34793 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726824AbfCTO3G (ORCPT ); Wed, 20 Mar 2019 10:29:06 -0400 Received: by mail-wm1-f65.google.com with SMTP id o10so19173224wmc.1 for ; Wed, 20 Mar 2019 07:29:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=aIi4ddq5S6Ln3Ix0EW6HiRXfhoBMl6atbJ4RXLkwiyw=; b=IzkUIuySj0uETdNAaEObKaquT0LojTU7HFpG4Af3Lo0iAeMmAZVD1eDbn0N0T34Y9r frtlanmOzAcQku9rUSRmsAmQdniEeXStZE+2l9e+csA8XyqRvfSST1q3s9oysHHyMYcs CM1AliW8vayRXhcGDpLJ5huEZ1/AKvDfyrE5tfNUqF6/j5mN9Fxa0J43YOjGJiVcAV+t uJZqw5nvWofzAsvjJiJUcR8nxgwKlb7+FJehAk66yC63MBn87zvq1pWWCKgfIRJO2bvo mfYqN3EHcYzuNNcM+LQLRu/J30ZDZ1HxXXDqSw/V0V1TkSVbFb99OxgakuJXt7lAYlWC 7XUg== 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=aIi4ddq5S6Ln3Ix0EW6HiRXfhoBMl6atbJ4RXLkwiyw=; b=Qsg2E4Hm4Aqd7pKI6imCuugnHP3yQC/Q3ka5W7U+k9Ny465oN2zkrPtS8rFRZfK/a6 sH2y/X0SyCStkRp3L6GFkBhD+MVgGpCpzRa9sEQWo0UagZM27RHcLW0E+xV1hIJEwVAe 4J7mrlk9kLLY7KYYoji9UnuhLTURXNlmjeL6FaGksq75fd/oBqFNTCjlteZScamOghhN jqVDBEQuRLP+ismXDYvbAmDil8VRWs3vmTQlakBlMEZVENABWK4FgshCBZhurES//X0t 1vfsOA2JsF/wPn2KWwY9/3nkkg5lx8sy+Jbw1mGbCDumvvlCKFqmecd7ZIxbx9io9m2f GbuQ== X-Gm-Message-State: APjAAAVhsScjZsvujEX7XrHYtkVxhv68js8Mri0CnjqjPrLwh5bXWyDl hq72JSrcqC3b7reAyXGta6ebPQ== X-Received: by 2002:a1c:d04a:: with SMTP id h71mr8407188wmg.120.1553092143257; Wed, 20 Mar 2019 07:29:03 -0700 (PDT) Received: from holly.lan (cpc141214-aztw34-2-0-cust773.18-1.cable.virginm.net. [86.9.19.6]) by smtp.gmail.com with ESMTPSA id g2sm4814210wrh.7.2019.03.20.07.29.01 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 20 Mar 2019 07:29:02 -0700 (PDT) Date: Wed, 20 Mar 2019 14:29:00 +0000 From: Daniel Thompson To: Manivannan Sadhasivam Cc: linux@armlinux.org.uk, xuwei5@hisilicon.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linus.walleij@linaro.org, peter.griffin@linaro.org, guodong.xu@linaro.org, haojian.zhuang@linaro.org, rmk+kernel@armlinux.org.uk Subject: Re: [PATCH 1/2] amba: Take device out of reset before reading pid and cid values Message-ID: <20190320142900.iblx4za3ivb5xpxd@holly.lan> References: <20190309015635.5401-1-manivannan.sadhasivam@linaro.org> <20190309015635.5401-2-manivannan.sadhasivam@linaro.org> <20190312122711.b2ibipico2dgavl7@holly.lan> <20190320065658.GA22381@Mani-XPS-13-9360> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190320065658.GA22381@Mani-XPS-13-9360> User-Agent: NeoMutt/20180716 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Mar 20, 2019 at 12:26:58PM +0530, Manivannan Sadhasivam wrote: > Hi Daniel, > > On Tue, Mar 12, 2019 at 12:27:11PM +0000, Daniel Thompson wrote: > > On Sat, Mar 09, 2019 at 07:26:34AM +0530, Manivannan Sadhasivam wrote: > > > For the AMBA Primecell devices having the reset lines wired, it is > > > necessary to take them out of reset before reading the pid and cid values. > > > Earlier we were dependent on the bootloader to do this but a more cleaner > > > approach would be to do it in the kernel itself. Hence, this commit > > > deasserts the reset line just before reading the pid and cid values. > > > > > > Suggested-by: Daniel Thompson > > > Signed-off-by: Manivannan Sadhasivam > > > --- > > > drivers/amba/bus.c | 9 +++++++++ > > > 1 file changed, 9 insertions(+) > > > > > > diff --git a/drivers/amba/bus.c b/drivers/amba/bus.c > > > index 41b706403ef7..da8f1aac5315 100644 > > > --- a/drivers/amba/bus.c > > > +++ b/drivers/amba/bus.c > > > @@ -21,6 +21,7 @@ > > > #include > > > #include > > > #include > > > +#include > > > > > > #include > > > > > > @@ -352,6 +353,7 @@ static void amba_device_release(struct device *dev) > > > > > > static int amba_device_try_add(struct amba_device *dev, struct resource *parent) > > > { > > > + struct reset_control *rst; > > > u32 size; > > > void __iomem *tmp; > > > int i, ret; > > > @@ -388,6 +390,13 @@ static int amba_device_try_add(struct amba_device *dev, struct resource *parent) > > > if (ret == 0) { > > > u32 pid, cid; > > > > > > + /* De-assert the reset line to take the device out of reset */ > > > + rst = reset_control_get_optional_exclusive(&dev->dev, NULL); > > > + if (IS_ERR(rst)) > > > + return PTR_ERR(rst); > > > > It is really correct to propagate an error if we cannot get exclusive > > ownership of the reset line. > > > > With drivers for vendor specific cells it is ok to "just know" that the > > reset line is never shared but we cannot know this for generic cells and > > we certainly can't know this for the bus. > > > > I think it *might* be OK to propagate an error if you used > > reset_control_get_optional_shared() instead because if that reports an > > error than arguably we have either a mistake in the DT or a bug in the > > driver we are sharing a reset with. > > > > Hmm. I'm not sure whether we can assume shared reset lines here or not! Maybe > Russell can share his opinion here. I didn't *assume* anything. I read about the difference between what a shared reset line does and an exclusive reset line. Providing the get/put is properly balanced it is both safe and correct to request shared access to the reset line. The question is whether it is OK to propagate an error code if another device has already requested exclusive access to the reset line (which would cause our request for shared access to fail) since this causes us to give up on adding the device. Here I concluded that it OK because a failure does indicates a bug in DT or other driver but added the "I think" because just-WARN_ON()-and-carry-on" is also a defensible recovery approach (and *much* less likely to provoke boot sequence regressions for existing systems). > > > + > > > + reset_control_deassert(rst); > > > > Perhaps we might also need to explain why we can ignore -ENOTSUPP > > here. Perhaps something like the following based on the comment > > found in in reset_control_deassert(): > > > > /* > > * -ENOTSUPP means occurs when the reset controller > > * does not implement .deassert(), in which case the > > * the reset lines should be self-deasserting (and > > * deasserted by default). > > */ > > WARN_ON(deassert did not return 0 or -ENOTSUPP); > > Ack. > > > > + > > > /* > > > * Read pid and cid based on size of resource > > > * they are located at end of region > > > > This looks like it will leak the control reference... shouldn't there > > be a put after you have read the pid/cid? > > > > Yes, but it can come before this as well. Right after deassert. No it can't. If the reset line really really is shared then another driver could but the cell back into the reset state before you have read the pid/cid. Daniel.