public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Nick Hu <nick.hu@sifive.com>
To: u-boot@lists.denx.de, rick@andestech.com, ycliang@andestech.com,
	greentime.hu@sifive.com, zong.li@sifive.com,
	vincent.chen@sifive.com
Cc: Nick Hu <nick.hu@sifive.com>
Subject: [PATCH] riscv: Avoid io read/write cause wrong result
Date: Mon, 18 Oct 2021 11:50:05 +0800	[thread overview]
Message-ID: <20211018035005.16842-1-nick.hu@sifive.com> (raw)

io read/write may cause wrong result because they may read/write data
from/to register instead of memory. Add 'volatile' to avoid it.

Signed-off-by: Nick Hu <nick.hu@sifive.com>
---
 arch/riscv/include/asm/io.h | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/arch/riscv/include/asm/io.h b/arch/riscv/include/asm/io.h
index acf5a96449..3540773c4f 100644
--- a/arch/riscv/include/asm/io.h
+++ b/arch/riscv/include/asm/io.h
@@ -44,15 +44,15 @@ static inline phys_addr_t map_to_sysmem(const void *ptr)
  * read/writes.  We define __arch_*[bl] here, and leave __arch_*w
  * to the architecture specific code.
  */
-#define __arch_getb(a)			(*(unsigned char *)(a))
-#define __arch_getw(a)			(*(unsigned short *)(a))
-#define __arch_getl(a)			(*(unsigned int *)(a))
-#define __arch_getq(a)			(*(unsigned long long *)(a))
-
-#define __arch_putb(v, a)		(*(unsigned char *)(a) = (v))
-#define __arch_putw(v, a)		(*(unsigned short *)(a) = (v))
-#define __arch_putl(v, a)		(*(unsigned int *)(a) = (v))
-#define __arch_putq(v, a)		(*(unsigned long long *)(a) = (v))
+#define __arch_getb(a)			(*(volatile unsigned char *)(a))
+#define __arch_getw(a)			(*(volatile unsigned short *)(a))
+#define __arch_getl(a)			(*(volatile unsigned int *)(a))
+#define __arch_getq(a)			(*(volatile unsigned long long *)(a))
+
+#define __arch_putb(v, a)		(*(volatile unsigned char *)(a) = (v))
+#define __arch_putw(v, a)		(*(volatile unsigned short *)(a) = (v))
+#define __arch_putl(v, a)		(*(volatile unsigned int *)(a) = (v))
+#define __arch_putq(v, a)		(*(volatile unsigned long long *)(a) = (v))
 
 #define __raw_writeb(v, a)		__arch_putb(v, a)
 #define __raw_writew(v, a)		__arch_putw(v, a)
-- 
2.31.1


             reply	other threads:[~2021-10-18 11:31 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-18  3:50 Nick Hu [this message]
2021-10-19  8:30 ` [PATCH] riscv: Avoid io read/write cause wrong result Leo Liang
2021-10-19  8:59 ` Bin Meng

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=20211018035005.16842-1-nick.hu@sifive.com \
    --to=nick.hu@sifive.com \
    --cc=greentime.hu@sifive.com \
    --cc=rick@andestech.com \
    --cc=u-boot@lists.denx.de \
    --cc=vincent.chen@sifive.com \
    --cc=ycliang@andestech.com \
    --cc=zong.li@sifive.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox