fix ide-iops for big endian archs
PATCH 1/1 fix ide-iops for big endian archs
Curently in 2.5 (afaik in -ac too), the ide-iops "s" routines used to transfer datas in/out the data port are incorrect for big endian machines. They are implemented with a loop of inw/outw which are byteswapping, but a fifo transfer like that mustn't be swapped.
Here's a patch against current 2.5 (that should apply to 2.4 -ac too) that fixes those with a #define for now. I have done some further cleanup of the iops (removing the {IN,OUT}{BYTE,WORD,LONG} macros and removing the "P" iops from the hwif structure) too, but Alan didn't accept those yet.
I enclosed the patch as an attachement too in case the mailer screws it up...
===== drivers/ide/ide-iops.c 1.1 vs edited =====
drivers/ide/ide-iops.c +17 -1
@@ -54,12 +54,20 @@static inline void ide_insw (u32 port,void *addr,u32 count) { +#ifdef __BIG_ENDIAN +insw (port, addr, count); +#else while (count--) { *(u16 *)addr =IN_WORD (port); addr +=2 ; } +#endif }static inline void ide_insw_p (u32 port,void *addr,u32 count) { -while (count--) { *(u16 *)addr =IN_WORD_P (port); addr +=2 ; } +#ifdef __BIG_ENDIAN +insw (port, addr, count); +#else +while (count--) { *(u16 *)addr =IN_WORD (port); addr +=2 ; } +#endif }static inline u32 ide_inl (u32 port)
@@ -106,12 +114,20 @@static inline void ide_outsw (u32 port,void *addr,u32 count) { +#ifdef __BIG_ENDIAN +outsw (port, addr, count); +#else while (count--) {OUT_WORD (*(u16 *)addr, port); addr +=2 ; } +#endif }static inline void ide_outsw_p (u32 port,void *addr,u32 count) { +#ifdef __BIG_ENDIAN +outsw (port, addr, count); +#else while (count--) {OUT_WORD_P (*(u16 *)addr, port); addr +=2 ; } +#endif }static inline void ide_outl (u32 addr,u32 port)
===== drivers/ide/ide-iops.c 1.1 vs edited =====
drivers/ide/ide-iops.c +17 -1
@@ -54,12 +54,20 @@static inline void ide_insw (u32 port,void *addr,u32 count) { +#ifdef __BIG_ENDIAN +insw (port, addr, count); +#else while (count--) { *(u16 *)addr =IN_WORD (port); addr +=2 ; } +#endif }static inline void ide_insw_p (u32 port,void *addr,u32 count) { -while (count--) { *(u16 *)addr =IN_WORD_P (port); addr +=2 ; } +#ifdef __BIG_ENDIAN +insw (port, addr, count); +#else +while (count--) { *(u16 *)addr =IN_WORD (port); addr +=2 ; } +#endif }static inline u32 ide_inl (u32 port)
@@ -106,12 +114,20 @@static inline void ide_outsw (u32 port,void *addr,u32 count) { +#ifdef __BIG_ENDIAN +outsw (port, addr, count); +#else while (count--) {OUT_WORD (*(u16 *)addr, port); addr +=2 ; } +#endif }static inline void ide_outsw_p (u32 port,void *addr,u32 count) { +#ifdef __BIG_ENDIAN +outsw (port, addr, count); +#else while (count--) {OUT_WORD_P (*(u16 *)addr, port); addr +=2 ; } +#endif }static inline void ide_outl (u32 addr,u32 port)
drivers/ide/ide-iops.c line 61
Quoted 11 lines · Benjamin Herrenschmidt
drivers/ide/ide-iops.c +4
-0@@ -54,12 +54,20 @@static inline void ide_insw (u32 port,void *addr,u32 count) { +#ifdef __BIG_ENDIAN +insw (port, addr, count); +#else while (count--) { *(u16 *)addr =IN_WORD (port); addr +=2 ; } +#endif
If insw is correct on big-endian, then it sure as hell should be correct on little-endian. I don't understand why we wouldn't use insw on PC's, since it's smaller and much more traditional.
Linus
Quoted 6 lines · Benjamin Herrenschmidt
Quoted 4 lines
drivers/ide/ide-iops.c +0
-0@@ -54,12 +54,20 @@
Quoted 11 lines
drivers/ide/ide-iops.c line 61
Quoted 7 lines
drivers/ide/ide-iops.c +4
-0static inline void ide_insw (u32 port,void *addr,u32 count) { +#ifdef __BIG_ENDIAN +insw (port, addr, count); +#else while (count--) { *(u16 *)addr =IN_WORD (port); addr +=2 ; } +#endif If insw is correct on big-endian, then it sure as hell should be correct on little-endian. I don't understand why we wouldn't use insw on PC's, since it's smaller and much more traditional.
Well, i'm pretty sure it is, though I didn't want to post a patch affecting what currently work, I prefer letting you or other x86 addicts figure that out :)
In the case of ide_inswp though, there is a real problem as there is no equivalent of the "p" functions on non-x86 anyway, and you can't easily reproduce the "insw" semantics with {in,out}{w,l} without adding useless double-byteswap on BE. But on the other hand, the IDE layer doesn't use ide_inswp() callback, and the case where "p" functions are used is currently broken on BE as well (see ide_{input,output}_data when drive->slow is true).
I suggest that you get this patch in asap (eventually swithing to insw unconditionally in ide_insw) so at least 2.5 works again properly on BE, further cleanup of the iops is pending, I'm waiting for Alan own experiments before I push again my own that remove all "p" iops and all of the {IN,OUT}{BYTE,WORD,LONG} macros.
Ben.
Quoted 3 lines · Benjamin Herrenschmidt
properly on BE, further cleanup of the iops is pending, I'm waiting for Alan own experiments before I push again my own that remove all "p" iops and all of the {IN,OUT}{BYTE,WORD,LONG} macros.
Thats true in current -ac. I killed the _p crap. Nobody uses it, the switching for handling it is bogus anyway. If anyone has such broken code they can implement ide-iops-speak-slowly-after-the-tone.c
Quoted 3 lines
Thats true in current -ac. I killed the _p crap. Nobody uses it, the switching for handling it is bogus anyway. If anyone has such broken code they can implement
ide-iops-speak-slowly-after-the-tone.c
Ok, now go one step further and remove the {IN,OUT}{BYTE,WORD,LONG} macros and you'll end up with the stuff I had send you previously ;)
Regarding the MMIO ops, where indeed I had some #ifdef CONFIG_PPC crap, that was because we lack proper abstraction of either an MMIO version of insw/outsw, or of the barrier (see previous discussion we had on this issue). It is by no mean yet another PowerPC'ism ;)
Ben.
Quoted 7 lines
Quoted 3 lines
properly on BE, further cleanup of the iops is pending, I'm waiting for Alan own experiments before I push again my own that remove all "p" iops and all of the {IN,OUT}{BYTE,WORD,LONG} macros.
Thats true in current -ac. I killed the _p crap. Nobody uses it, the switching for handling it is bogus anyway. If anyone has such broken code they can implement
ide-iops-speak-slowly-after-the-tone.c
Ok, I finally went and looked at your tree for real and I see the cleanup is actually there, good :)
So now, let's see how to get rid of those CONFIG_PPC, either by having everybody define iobarrier_*() or having {read,write}s{b,w,l}, I just started a new thread on the list just about that.
Jens: can you look into merging -ac's iops change to 2.5 ? That would fix it.
Ben.
Quoted 2 lines · Benjamin Herrenschmidt
I enclosed the patch as an attachement too in case the mailer screws it up...
Please do one thing. For the stuff that needs weird powerpcisms put all the seperate stuff in one block with its own copy of the static inlines so we dont have in ifdef in half the functions in the file
Quoted 7 lines · Benjamin Herrenschmidt
Quoted 2 lines
I enclosed the patch as an attachement too in case the mailer screws it up...
Please do one thing. For the stuff that needs weird powerpcisms put all the seperate stuff in one block with its own copy of the static inlines so we dont have in ifdef in half the functions in the file
This is _NOT_ a weird PowerPC'ism !!!
It's just a matter of use the proper operation, that is "insw/outsw" instead of trying to re-implement it with a loop of basic inw/outw, which is wrong for _any_ BE arch (except maybe weird m68k'ism where IDE is wired the wrong way around)
Ben.
Quoted 8 lines · Benjamin Herrenschmidt
Quoted 7 lines · Benjamin Herrenschmidt
Quoted 2 lines
I enclosed the patch as an attachement too in case the mailer screws it up...
Please do one thing. For the stuff that needs weird powerpcisms put all the seperate stuff in one block with its own copy of the static inlines so we dont have in ifdef in half the functions in the file
Quoted 6 lines
This is _NOT_ a weird PowerPC'ism !!!
It's just a matter of use the proper operation, that is "insw/outsw" instead of trying to re-implement it with a loop of basic inw/outw, which is wrong for _any_ BE arch (except maybe weird m68k'ism where IDE is wired the wrong way around)
to put it a bit more precise, this is bus endianness, nothing to do with arch endianness.
Richard
Quoted 2 lines
to put it a bit more precise, this is bus endianness, nothing to do with arch endianness.
Well, right, though this is also the way a PCI bus is supposed to be wired to a BE CPU, and is the most common way to wire a bus with ISA-like chipsets (16 bits busses) on a BE core ;)
Ben.