Re: [PATCH] isa_{read,write}{w,l} fixed

From: Russell King (rmk@arm.linux.org.uk)
Date: Sat Feb 12 2000 - 10:00:22 EST


Jeff Garzik writes:
> * You can never directly use a struct to access an offset in MMIO
> space. To do so is broken and bad bad bad. The only acceptable way is
>
> my_struct = ioremap (...);
> my_reg = readb(&my_struct->foo_register);

Err, but that's not guaranteed to produce what you expect. Although GCC
(and ANSI compilers) are not allowed to re-order the elements of a
structure, they are allowed to add padding (unused bytes) between elements
of the structure. (Yes, we've encountered this before).

The only truely portable way of doing this type of thing is to use either
integer or char arrays.

> I much prefer to avoid structs, and use macros to access registers
> instead:
>
> my_reg = RTL_R8 (FooRegisterConstant);

>From reading IO-mapping.txt, it appears that the correct way is to:

        char *my_ptr;
        my_ptr = ioremap(...);
        my_reg = readb(my_ptr + reg_offset);

BTW, isn't it about time this document was updated wrt the isa_* macros?
It currently implies that it's ok to do:

        reg = readb(0xc0000)

to read ISA address 0xc0000, which seems it should now be:

        reg = isa_readb(0xc0000)

at the very least.
   _____
  |_____| ------------------------------------------------- ---+---+-
  | | Russell King rmk@arm.linux.org.uk --- ---
  | | | | http://www.arm.linux.org.uk/~rmk/aboutme.html / / |
  | +-+-+ --- -+-
  / | THE developer of ARM Linux |+| /|\
 / | | | --- |
    +-+-+ ------------------------------------------------- /\\\ |

-
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 Feb 15 2000 - 21:00:23 EST