Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp146761ybz; Tue, 28 Apr 2020 20:24:21 -0700 (PDT) X-Google-Smtp-Source: APiQypKAh1M4ETTuU85qk0rYckYBV7qWMgs+0OGhqW3eRclQYA8RECsRf67qOI4cdsDfafMZ+dhV X-Received: by 2002:a05:6402:1d15:: with SMTP id dg21mr765305edb.13.1588130661380; Tue, 28 Apr 2020 20:24:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588130661; cv=none; d=google.com; s=arc-20160816; b=hmVf+GaJZuwIjQUPLqpIS9Z+Tsyt6zfSEfMprxjeJvHh+jbmY4mibV4nXcpnnWPnT+ 69k6yYMbM4TCSerSSJAuCjFWcZaL7TMWuAgSCH6/loU0EP0aIpIyBjLfF/zqHMIbbSHV MSuWBhfXTZc15ovx917NTFReQvcHjhZVckJM1rW7Rj7025EUueH2E7gw0V/JeiypOfYv IGoggWocuPkLShS8qwz85pWYEEragAgzam0RkOChutGRukgRq+ZEatxfqBvcid1GhLB+ 2ydXD7nkLrDNUQu/n1xwI9zmO0tCN7g9z5uL5aNF8Deya4aKYL29Isl6aIT1kqu+pwLV doJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:date:cc:to:from:subject:message-id; bh=EupDaGj4Uw6uR9ctZd4QKHmvff2fXDXL7jCEDM50vvc=; b=VsYEBR6DKRXx3vZrJsL8B3NWeDx0aheaspbq6+vEyUwzUIOy2EORBITUh8IFt4Bo03 MQzAcoJUDAEdDycmgsBAbJbHalFILLGWdeN6KsoburBL+bdAIRGp7KChmCqjN6k5iN3K 88jc9lyTulHSUb/8AgBUzwv+b+tBXqLAP1sb3MkdwSd0LpnWysdgDBrPeVdFTyAosP9o QP8zMYCgp4HHgSi36WHRtfb68VqfiajTpfWLFAAT1sVdGd6FIBj3DGCg2LXmCknh8aYS 2c3MA7+LwckTGo0FGwF+X0VWA5NcM9pbh4p2oGfXJ+d1/SlkUe/jfarcj1YJx8+/FJgb Z2GQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x21si3099657ejs.38.2020.04.28.20.23.55; Tue, 28 Apr 2020 20:24:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726662AbgD2DWW (ORCPT + 99 others); Tue, 28 Apr 2020 23:22:22 -0400 Received: from kernel.crashing.org ([76.164.61.194]:49566 "EHLO kernel.crashing.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726560AbgD2DWW (ORCPT ); Tue, 28 Apr 2020 23:22:22 -0400 X-Greylist: delayed 532 seconds by postgrey-1.27 at vger.kernel.org; Tue, 28 Apr 2020 23:22:21 EDT Received: from localhost (gate.crashing.org [63.228.1.57]) (authenticated bits=0) by kernel.crashing.org (8.14.7/8.14.7) with ESMTP id 03T3LD4u008600 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Tue, 28 Apr 2020 22:21:16 -0500 Message-ID: <55e1e941457cd596c4273e9c55dc2cfc9027c5ba.camel@kernel.crashing.org> Subject: Re: [PATCH v5 3/5] drivers/soc/litex: add LiteX SoC Controller driver From: Benjamin Herrenschmidt To: Mateusz Holenko , Rob Herring , Mark Rutland , Greg Kroah-Hartman , Jiri Slaby , devicetree@vger.kernel.org, "open list:SERIAL DRIVERS" Cc: Stafford Horne , Karol Gugala , Mauro Carvalho Chehab , "David S. Miller" , "Paul E. McKenney" , Filip Kokosinski , Pawel Czarnecki , Joel Stanley , Jonathan Cameron , Maxime Ripard , Shawn Guo , Heiko Stuebner , Sam Ravnborg , Icenowy Zheng , Laurent Pinchart , linux-kernel@vger.kernel.org, "Gabriel L. Somlo" Date: Wed, 29 Apr 2020 13:21:11 +1000 In-Reply-To: References: <20200425133939.3508912-0-mholenko@antmicro.com> <20200425133939.3508912-3-mholenko@antmicro.com> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.28.5-0ubuntu0.18.04.2 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 2020-04-27 at 11:13 +0200, Mateusz Holenko wrote: > As Gabriel Somlo suggested to me, I could still use > readl/writel/ioread/iowrite() standard functions providing memory > barriers *and* have values in CPU native endianness by using the > following constructs: > > `le32_to_cpu(readl(addr))` > > and > > `writel(cpu_to_le32(value), addr)` > > as le32_to_cpu/cpu_to_le32(): > - does nothing on LE CPUs and > - reorders bytes on BE CPUs which in turn reverts swapping made by > readl() resulting in returning the original value. It's a bit sad... I don't understand why you need this. The HW has a fied endian has you have mentioned earlier (and that is a good design). The fact that you are trying to shove things into a "smaller pipe" than the actual register shouldn't affect at what address the MSB and LSB reside. And readl/writel (or ioread32/iowrite32) will always be LE as well, so will match the HW layout. Thus I don't see why you need to play swapping games here. This however would be avoided completely if the HW was a tiny bit smarter and would do the multi-beat access for you which shouldn't be terribly hard to implement. That said, it would be even clearer if you just open coded the 2 or 3 useful cases: 32/8, 32/16 and 32/32. The loop with calculated shifts (and no masks) makes the code hard to understand. Cheers, Ben.