From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755031AbdKCWEr (ORCPT ); Fri, 3 Nov 2017 18:04:47 -0400 Received: from mail-qt0-f194.google.com ([209.85.216.194]:47201 "EHLO mail-qt0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751451AbdKCWEo (ORCPT ); Fri, 3 Nov 2017 18:04:44 -0400 X-Google-Smtp-Source: ABhQp+SVTy2p8bWM430AQnNEbGHipFxHDbZZv3g9B507PLXhjNeDnukoE/j/e41Jv1mtbkIRVslD3A== Subject: Re: [PATCH 08/12] hwrng: bcm2835-rng: Abstract I/O accessors To: Eric Anholt , linux-kernel@vger.kernel.org Cc: Matt Mackall , Herbert Xu , Rob Herring , Mark Rutland , Ray Jui , Scott Branden , "maintainer:BROADCOM BCM281XX/BCM11XXX/BCM216XX ARM ARCHITE..." , Stefan Wahren , PrasannaKumar Muralidharan , Russell King , Krzysztof Kozlowski , Harald Freudenberger , Sean Wang , Martin Kaiser , Steffen Trumtrar , "open list:HARDWARE RANDOM NUMBER GENERATOR CORE" , "open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS" , "moderated list:BROADCOM BCM2835 ARM ARCHITECTURE" , "moderated list:BRO ADCOM BCM2835 ARM ARCHITECTURE" References: <20171102010408.27736-1-f.fainelli@gmail.com> <20171102010408.27736-9-f.fainelli@gmail.com> <874lqbru7i.fsf@anholt.net> From: Florian Fainelli Message-ID: <58741f71-38f9-f81f-916e-aa14b6ea899b@gmail.com> Date: Fri, 3 Nov 2017 15:04:38 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 In-Reply-To: <874lqbru7i.fsf@anholt.net> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 11/03/2017 01:19 PM, Eric Anholt wrote: > Florian Fainelli writes: > >> In preparation for allowing BCM63xx to use this driver, we abstract I/O >> accessors such that we can easily change those later on. >> >> Signed-off-by: Florian Fainelli >> --- >> drivers/char/hw_random/bcm2835-rng.c | 27 +++++++++++++++++++-------- >> 1 file changed, 19 insertions(+), 8 deletions(-) >> >> diff --git a/drivers/char/hw_random/bcm2835-rng.c b/drivers/char/hw_random/bcm2835-rng.c >> index 35928efb52e7..500275d55044 100644 >> --- a/drivers/char/hw_random/bcm2835-rng.c >> +++ b/drivers/char/hw_random/bcm2835-rng.c >> @@ -42,6 +42,17 @@ static inline struct bcm2835_rng_priv *to_rng_priv(struct hwrng *rng) >> return container_of(rng, struct bcm2835_rng_priv, rng); >> } >> >> +static inline u32 rng_readl(struct bcm2835_rng_priv *priv, u32 offset) >> +{ >> + return readl(priv->base + offset); >> +} >> + >> +static inline void rng_writel(struct bcm2835_rng_priv *priv, u32 val, >> + u32 offset) >> +{ >> + writel(val, priv->base + offset); >> +} >> + >> static int bcm2835_rng_read(struct hwrng *rng, void *buf, size_t max, >> bool wait) >> { >> @@ -49,18 +60,18 @@ static int bcm2835_rng_read(struct hwrng *rng, void *buf, size_t max, >> u32 max_words = max / sizeof(u32); >> u32 num_words, count; >> >> - while ((__raw_readl(priv->base + RNG_STATUS) >> 24) == 0) { >> + while ((rng_readl(priv, RNG_STATUS) >> 24) == 0) { >> if (!wait) >> return 0; >> cpu_relax(); >> } > > What was the difference between the __raw_readl and readl that's now > being done in the new call? Is it important? readl() on ARM contains a memory barrier, which has therefore stronger ordering guarantees than __raw_readl() which does not. In practice I don't think this makes a whole lot of difference in that the above loop does not even have a barrier outside of it to try to have any sort of ordering guarantee so it seems to me like this may be an oversight. I took the liberty to use the stronger operation here because it seems to me like this is what is desired, or at least won't cause functional problems, and because I am not intimately familiar with the 2835 busing architecture. I know for a thing that the Broadcom STB and DSL busses (named GISB and UBUS respectively) do not require such barriers since they do not re-order transactions and are non-posted. > >> /* set warm-up count & enable */ >> - __raw_writel(RNG_WARMUP_COUNT, priv->base + RNG_STATUS); >> - __raw_writel(RNG_RBGEN, priv->base + RNG_CTRL); >> + rng_writel(priv, RNG_WARMUP_COUNT, RNG_STATUS); >> + rng_writel(priv, RNG_RBGEN, RNG_CTRL); > > Similar question. And here we definitively are not in a hot-path so the more "ordered" variant is acceptable it seems. -- Florian