lkml.org 
[lkml]   [2001]   [May]   [3]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: unsigned long ioremap()?
On Thu, 3 May 2001, Jonathan Lundell wrote:
> At 3:18 AM -0400 2001-05-03, Jeff Garzik wrote:
> >"David S. Miller" wrote:
> >> There is a school of thought which believes that:
> >>
> > > struct xdev_regs {
> >> u32 reg1;
> >> u32 reg2;
> >> };
> > >
> >> val = readl(&regs->reg2);
> >>
> >> is cleaner than:
> >>
> >> #define REG1 0x00
> >> #define REG2 0x04
> >>
> >> val = readl(regs + REG2);
> >>
> >> I'm personally ambivalent and believe that both cases should be allowed.
> >
> >Agreed... Tangent a bit, I wanted to plug using macros which IMHO make
> >code even more readable:
> >
> > val = RTL_R32(REG2);
> > RTL_W32(REG2, val);
> >
> >Since these are driver-private, if you are only dealing with one chip
> >you could even shorten things to "R32" and "W32", if that doesn't offend
> >any sensibilities :)
>
> With a little arithmetic behind the scenes and a NULL pointer to the
> struct xdev, you could have:
>
> struct xdev_regs {
> u32 reg1;
> u32 reg2;
> } *xdr = 0;
>
> #define RTL_R32(REG) readl(cookie+(unsigned long)(&xdr->REG))

You can easily get rid of the xdr variable by s/xdr/((struct xdev_regs *)0)/.

> cookie = ioremap(blah, blah);
>
> val = RTL_R32(reg2);
>
> ...and have the benefits of the R32 macro as well as the use of
> structure members.

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 12:52    [W:0.056 / U:6.820 seconds]
©2003-2017 Jasper Spaans. hosted at Digital OceanAdvertise on this site