PCI endianess

Armin Schindler mac at melware.de
Wed Sep 4 16:54:17 EST 2002


On Tue, 3 Sep 2002, Anil K Prasad wrote:
> >> >as far as I know, the PCI bus is little endian, even on big endian
> >> machines.
> >> >Is this true for RS6000 (44p/270) too ?
> >>
> >> Yes, even on RS6K machines its little endian.
> >> You should write to PCI mapped register in little endian byte order.
>
> >So commands/data to my memory-mapped PCI card need to be converted, right
> ?
> >E.g. if the cards memory has a structure like
> >struct {
> >  u16 command;
> >  u32 length;
> >  u32 data[128];
> >}
>
> >I need to convert all data to that structure ?
> If you need to copy this data from system memory to card memory (or other
> way), you need to convert it from big-endian to little-endian(or reverse).
> For example if structure is something like
>
> x.command = 0x1234;
> x.length = 0x567890AB;
> where is x is an instance of above struct.
>
> and assume X is at address 0x10000000 in system memory,
> Then following will give view of structure in system memory
>
> 0x10000000 --> 0x12
> 0x10000001 --> 0x34 (0x10000002 and 0x10000002 will unused because of
> padding)
> 0x10000004 --> 0x56
> 0x10000005 --> 0x78
> 0x10000006 --> 0x90
> 0x10000007 --> 0xAB;
>
>
> Inside Card memory  this structure should look like(lets assume address of
> structure is 0xf0000000)
>
> 0xf0000000 --> 0x34
> 0xf0000001 --> 0x12
>
> 0xf0000003 --> 0xAB
> 0xf0000004 --> 0x90
> 0xf0000005 --> 0x78
> 0xf0000006 --> 0x56

Do you mean this happens without conversion (e.g. read/write{bwl]) ?
Then it is exactly what I need.
If I do on my big endian machine:
 unsigned short val = 0x1234;
 x->command = val;
Is 0x1234 stored as little endian on the cards ram ?
Since my card needs little endian (the on card cpu is little endian)
this would be what I need and change of the existing code isn't
necessary. Or did I understand this completely wrong ?

You wrote that addresses 2 and 3 are not used because of padding, but
I didn't notice this before. My structure needs to be __packed__ which
does work without telling this the compiler. Or will GCC on PPC64 do it
different ?

Armin


** Sent via the linuxppc64-dev mail list. See http://lists.linuxppc.org/





More information about the Linuxppc64-dev mailing list