From patchwork Mon Aug 28 12:32:49 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Petazzoni X-Patchwork-Id: 806557 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 3xgrlR5XTNz9sNn for ; Mon, 28 Aug 2017 22:33:07 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 5543EC224EF; Mon, 28 Aug 2017 12:32:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 6557AC224E3; Mon, 28 Aug 2017 12:32:54 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 3F6BBC224E8; Mon, 28 Aug 2017 12:32:52 +0000 (UTC) Received: from mail.free-electrons.com (mail.free-electrons.com [62.4.15.54]) by lists.denx.de (Postfix) with ESMTP id 000E9C224E1 for ; Mon, 28 Aug 2017 12:32:49 +0000 (UTC) Received: by mail.free-electrons.com (Postfix, from userid 110) id B15C821DEB; Mon, 28 Aug 2017 14:32:48 +0200 (CEST) Received: from windsurf (LStLambert-657-1-97-87.w90-63.abo.wanadoo.fr [90.63.216.87]) by mail.free-electrons.com (Postfix) with ESMTPSA id 8A36821DE9; Mon, 28 Aug 2017 14:32:48 +0200 (CEST) Date: Mon, 28 Aug 2017 14:32:49 +0200 From: Thomas Petazzoni To: Nobuhiro Iwamatsu , Vladimir Zapolskiy Message-ID: <20170828143249.4c0791df@windsurf> Organization: Free Electrons X-Mailer: Claws Mail 3.14.1 (GTK+ 2.24.31; x86_64-redhat-linux-gnu) MIME-Version: 1.0 Cc: u-boot@lists.denx.de Subject: [U-Boot] I/O accessors on SuperH and endianness X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Hello, As you've noticed, I'm porting U-Boot to a SH4 board running big-endian. The big-endian choice cannot be changed, because it's selected by the HW design: moving to little endian would require a modification of the board. The serial_sh driver was working fine in big endian, with no change. However, the sh_eth driver was not working in big endian mode. After investigation, I realized that: - sh_serial is using the read/write (readb, writeb, readw, writew, etc.) macros to access I/O registers - sh_eth is using the in/out macros to access I/O registers The in/out macros assume the device registers are little endian, so when the CPU is running big endian, they do an endianness conversion. However, on SuperH, when the CPU runs big endian, the device registers are also big endian, so there should be no endianness conversion. On the other hand, read/write, when __mem_pci is not defined, do not do any endianness conversion. And this is why sh_serial was working out of the box. Changing sh_eth to use read/write instead of in/out also made it work in big endian mode. However, if for some reason I enable PCI on this platform, __mem_pci will be defined, and read/write will perform endianness conversion, breaking support for the platform. So what is the appropriate solution here? Use read/write like sh_serial is doing today, and ignore the potential problem? Use __raw_*() variants everywhere? What if a driver is shared with another platform/architecture where the devices remain little endian even if the CPU is running big endian? Best regards, Thomas For the record, here is the current patch I have on sh_eth (a few other changes are needed, but not directly related) : diff --git a/drivers/net/sh_eth.h b/drivers/net/sh_eth.h index a09a6d7..0e65f97 100644 --- a/drivers/net/sh_eth.h +++ b/drivers/net/sh_eth.h @@ -675,11 +675,11 @@ static inline unsigned long sh_eth_reg_addr(struct sh_eth_dev *eth, static inline void sh_eth_write(struct sh_eth_dev *eth, unsigned long data, int enum_index) { - outl(data, sh_eth_reg_addr(eth, enum_index)); + writel(data, sh_eth_reg_addr(eth, enum_index)); } static inline unsigned long sh_eth_read(struct sh_eth_dev *eth, int enum_index) { - return inl(sh_eth_reg_addr(eth, enum_index)); + return readl(sh_eth_reg_addr(eth, enum_index)); }