mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Guan Xuetao" <gxt@mprc.pku.edu.cn>
To: "'Arnd Bergmann'" <arnd@arndb.de>
Cc: <linux-kernel@vger.kernel.org>, <linux-arch@vger.kernel.org>,
	"'Greg KH'" <greg@kroah.com>
Subject: RE: [PATCH 09/12] unicore32 machine related files: hardware registers
Date: Tue, 22 Feb 2011 22:09:05 +0800	[thread overview]
Message-ID: <018601cbd29a$118b27c0$34a17740$@mprc.pku.edu.cn> (raw)
In-Reply-To: <201102181142.42614.arnd@arndb.de>



> -----Original Message-----
> From: Arnd Bergmann [mailto:arnd@arndb.de]
> Sent: Friday, February 18, 2011 6:43 PM
> To: Guan Xuetao
> Cc: linux-kernel@vger.kernel.org; linux-arch@vger.kernel.org; 'Greg KH'
> Subject: Re: [PATCH 09/12] unicore32 machine related files: hardware registers
> 
> On Friday 18 February 2011 10:52:12 Guan Xuetao wrote:
> 
> > > On Wednesday 16 February 2011, Guan Xuetao wrote:
> > > > +#define io_p2v(x)      ((x) - PKUNITY_IOSPACE_BASE)
> > > > +#define io_v2p(x)      ((x) + PKUNITY_IOSPACE_BASE)
> > > > +
> > > > +#ifndef __ASSEMBLY__
> > > > +
> > > > +# define __REG(x)      (*((volatile unsigned long *)io_p2v(x)))
> > > > +# define __PREG(x)     (io_v2p((unsigned long)&(x)))
> > > > +
> > > > +#else
> > > > +
> > > > +# define __REG(x)      io_p2v(x)
> > > > +# define __PREG(x)     io_v2p(x)
> > >
> > > > #define PKUNITY_IOSPACE_BASE            0x80000000 /* 0x80000000 - 0xFFFFFFFF 2GB */
> > >
> > > The typecasts look wrong here:
> > >
> > > - "volatile unsigned long*" is not the right pointer type to do I/O on. It
> > >   should instead be "void __iomem *". Please use the "sparse" tool with "make C=1"
> > >   to get warnings about incorrect pointer type accesses.
> > __REG() macro could be used in both left and right sides of assignment sentence.
> > This idea is borrowed from arm/sa1100.
> >
> > When used in left side, __REG is a register port, and when used in right side,
> > __REG is just the value of the register.
> > It is a trick, but very useful. I'd like to remain the macros.
> 
> Ok, I didn't realize this. However, this is a really bad idea
> and I would strongly advise removing this throughout the code.
> 
> The only way we do MMIO accesses in Linux is through the
> readl()/writel() functions. On many architectures, these
> contain more than just a pointer dereference, and if you
> need that, you can change it in just one place.
> 
> Things that can go wrong with volatile pointer dereferences include:
> 
> * compiler turns 32 bit access into four 8-bit accesses
> * I/O bus reorders access and it moves outside of a spinlock
> * non-volatile accesses to system RAM get reordered around
>   MMIO access, which may break if the MMIO triggers a DMA.
> 
> > diff --git a/arch/unicore32/include/mach/PKUnity.h b/arch/unicore32/include/mach/PKUnity.h
> > index 1e13208..39f27f4 100644
> > --- a/arch/unicore32/include/mach/PKUnity.h
> > +++ b/arch/unicore32/include/mach/PKUnity.h
> > @@ -21,7 +21,7 @@
> >   * Memory Definitions
> >   */
> >  #define PKUNITY_SDRAM_BASE		0x00000000 /* 0x00000000 - 0x7FFFFFFF 2GB */
> > -#define PKUNITY_IOSPACE_BASE            0x80000000 /* 0x80000000 - 0xFFFFFFFF 2GB */
> > +#define PKUNITY_MMIO_BASE		0x80000000 /* 0x80000000 - 0xFFFFFFFF 2GB */
> >  #define PKUNITY_PCI_BASE		0x80000000 /* 0x80000000 - 0xBFFFFFFF 1GB */
> >  #include "regs-pci.h"
> >  #define PKUNITY_BOOT_ROM2_BASE		0xF4000000 /* 0xF4000000 - 0xF7FFFFFF 64MB */
> 
> This change is ok.
> 
> > diff --git a/arch/unicore32/include/mach/hardware.h b/arch/unicore32/include/mach/hardware.h
> > index 3fb7236..ebce7de 100644
> > --- a/arch/unicore32/include/mach/hardware.h
> > +++ b/arch/unicore32/include/mach/hardware.h
> > @@ -17,19 +17,14 @@
> >
> >  #include "PKUnity.h"
> >
> > -#define io_p2v(x)	((x) - PKUNITY_IOSPACE_BASE)
> > -#define io_v2p(x)	((x) + PKUNITY_IOSPACE_BASE)
> > +#define io_p2v(x)	((x) - PKUNITY_MMIO_BASE)
> > +#define io_v2p(x)	((x) + PKUNITY_MMIO_BASE)
> >
> >  #ifndef __ASSEMBLY__
> 
> The result of io_p2v really needs to be a (void __iomem *) pointer, not
> an integer, so the accesses can work.
> 
> >  # define __REG(x)	(*((volatile unsigned long *)io_p2v(x)))
> >  # define __PREG(x)	(io_v2p((unsigned long)&(x)))
> 
> And as explained, these should be removed and all users converted to
> use readl()/writel().
I see.
I apply the patch as following:
arch/unicore32/include/mach/hardware.h |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)

diff --git a/arch/unicore32/include/mach/hardware.h b/arch/unicore32/include/mach/hardware.h
index ebce7de..b71405a 100644
--- a/arch/unicore32/include/mach/hardware.h
+++ b/arch/unicore32/include/mach/hardware.h
@@ -22,8 +22,7 @@
 
 #ifndef __ASSEMBLY__
 
-# define __REG(x)	(*((volatile unsigned long *)io_p2v(x)))
-# define __PREG(x)	(io_v2p((unsigned long)&(x)))
+# define __REG(x)	(void __iomem *)io_p2v(x)
 
 #endif

---
__REG reserved only for all registers prefix.
And all using for __REG converted to readl/writel.

> 
> 	Arnd

Thanks Arnd

Guan Xuetao


  reply	other threads:[~2011-02-22 14:09 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-16  7:51 Guan Xuetao
2011-02-17 16:59 ` Arnd Bergmann
2011-02-18  9:52   ` Guan Xuetao
2011-02-18 10:42     ` Arnd Bergmann
2011-02-22 14:09       ` Guan Xuetao [this message]
2011-02-22 14:19         ` Arnd Bergmann
2011-02-26 12:23           ` Guan Xuetao
2011-02-26 13:16             ` Arnd Bergmann
2011-02-27  3:35               ` Guan Xuetao
2011-02-27 17:15                 ` Arnd Bergmann

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='018601cbd29a$118b27c0$34a17740$@mprc.pku.edu.cn' \
    --to=gxt@mprc.pku.edu.cn \
    --cc=arnd@arndb.de \
    --cc=greg@kroah.com \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /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

all inboxes | Powered by JetHome®