Re: ioremap return type

From: Jamie Lokier (lk@tantalophile.demon.co.uk)
Date: Thu Aug 10 2000 - 08:38:20 EST


Malcolm Beattie wrote:
> Why not make the types opaque in the same way as ptes:
>
> typedef struct { unsigned long addr; } ioaddr_t;
> #define readl(ioaddr) __readl(ioaddr.addr)
> void *ioremap(ioaddr) {
> unsigned long addr = ioaddr.addr;
> ...
> }
> inline iooffset(ioaddr_t ioaddr, long delta) {
> ioaddr.addr += delta;
> return ioaddr;
> }
>
> Assuming gcc can generate the same code and doesn't get confused
> by any of the struct passing and manipulation.

(a) GCC has been known to generate worse code for this. But it's good
    for checking for misuse. Why do you think the pte structs aren't
    normally used?

(b) iooffset sucks -- you'd use it on nearly every readl/writel call.
    So build it in:

  #ifdef CHECK_IOCOOKIES
  #define readl(iomem, offset) __readl (iomem.addr, offset)
  #else
  #define readl(iomem, offset) __readl ((iomem) + (offset))
#endif

Drivers that use readl(MY_REG_1(dev)) and readl(MY_REG_2(dev))
constructs can still do so. But whereas before you had:

  #define MY_REG_1(dev) devinfo[dev]->iobase + 0x10
  #define MY_REG_2(dev) devinfo[dev]->iobase + 0x14

Now you have:

  #define MY_REG_1(dev) devinfo[dev]->iobase, 0x10
  #define MY_REG_1(dev) devinfo[dev]->iobase, 0x14

enjoy,
-- Jamie

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



This archive was generated by hypermail 2b29 : Tue Aug 15 2000 - 21:00:21 EST