All of lore.kernel.org
 help / color / mirror / Atom feed
From: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] I/O accessors on SuperH and endianness
Date: Mon, 28 Aug 2017 14:32:49 +0200	[thread overview]
Message-ID: <20170828143249.4c0791df@windsurf> (raw)

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));
 }



-- 
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com

             reply	other threads:[~2017-08-28 12:32 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-28 12:32 Thomas Petazzoni [this message]
2017-09-13 22:28 ` [U-Boot] I/O accessors on SuperH and endianness Thomas Petazzoni

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170828143249.4c0791df@windsurf \
    --to=thomas.petazzoni@free-electrons.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.