[U-Boot] [PATCH] MIPS: Fix compile warning in au1x00_eth.c

This patch fixes this compilation warning:
./MAKEALL dbau1000 Configuring for dbau1x00 board... au1x00_eth.c: In function 'au1x00_send': au1x00_eth.c:158: warning: passing argument 1 of 'virt_to_phys' discards qualifiers from pointer target type ...
Seens with ELDK 4.2 (GCC 4.2.2).
Signed-off-by: Stefan Roese sr@denx.de --- cpu/mips/au1x00_eth.c | 8 +++++--- 1 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/cpu/mips/au1x00_eth.c b/cpu/mips/au1x00_eth.c index 6272a3a..5546800 100644 --- a/cpu/mips/au1x00_eth.c +++ b/cpu/mips/au1x00_eth.c @@ -155,7 +155,7 @@ static int au1x00_send(struct eth_device* dev, volatile void *packet, int length
/* tx fifo should always be idle */ fifo_tx[next_tx].len = length; - fifo_tx[next_tx].addr = (virt_to_phys(packet))|TX_DMA_ENABLE; + fifo_tx[next_tx].addr = (virt_to_phys((void *)packet))|TX_DMA_ENABLE; au_sync();
udelay(1); @@ -208,7 +208,8 @@ static int au1x00_recv(struct eth_device* dev){ NetReceive(NetRxPackets[next_rx], length - 4); }
- fifo_rx[next_rx].addr = (virt_to_phys(NetRxPackets[next_rx]))|RX_DMA_ENABLE; + fifo_rx[next_rx].addr = + virt_to_phys((void *)NetRxPackets[next_rx])|RX_DMA_ENABLE;
next_rx++; if(next_rx>=NO_OF_FIFOS){ @@ -249,7 +250,8 @@ static int au1x00_init(struct eth_device* dev, bd_t * bd){ for(i=0;i<NO_OF_FIFOS;i++){ fifo_tx[i].len = 0; fifo_tx[i].addr = virt_to_phys(&txbuf[0]); - fifo_rx[i].addr = (virt_to_phys(NetRxPackets[i]))|RX_DMA_ENABLE; + fifo_rx[i].addr = + virt_to_phys((void *)NetRxPackets[i])|RX_DMA_ENABLE; }
/* Put mac addr in little endian */

Stefan Roese wrote:
This patch fixes this compilation warning:
./MAKEALL dbau1000 Configuring for dbau1x00 board... au1x00_eth.c: In function 'au1x00_send': au1x00_eth.c:158: warning: passing argument 1 of 'virt_to_phys' discards qualifiers from pointer target type ...
Seens with ELDK 4.2 (GCC 4.2.2).
Signed-off-by: Stefan Roese sr@denx.de
The number of warnings decreases by half, but we're still warned. Comments? I've not took a look of the patch itself, yet. Just let you know.
skuribay@ubuntu:u-boot.git$ mips-linux-gnu-gcc --version mips-linux-gnu-gcc (Sourcery G++ Lite 4.2-177) 4.2.3 Copyright (C) 2007 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
skuribay@ubuntu:u-boot.git$ skuribay@ubuntu:u-boot.git$ CROSS_COMPILE=mips-linux-gnu- ./MAKEALL dbau1000 Configuring for dbau1x00 board... au1x00_eth.c: In function 'au1x00_send': au1x00_eth.c:158: warning: passing argument 1 of 'virt_to_phys' discards qualifiers from pointer target type au1x00_eth.c: In function 'au1x00_recv': au1x00_eth.c:211: warning: passing argument 1 of 'virt_to_phys' discards qualifiers from pointer target type au1x00_eth.c: In function 'au1x00_init': au1x00_eth.c:252: warning: passing argument 1 of 'virt_to_phys' discards qualifiers from pointer target type au1x00_eth.c: In function 'au1x00_recv': au1x00_eth.c:211: warning: passing argument 1 of 'virt_to_phys' discards qualifiers from pointer target type au1x00_eth.c: In function 'au1x00_init': au1x00_eth.c:252: warning: passing argument 1 of 'virt_to_phys' discards qualifiers from pointer target type au1x00_eth.c: In function 'au1x00_send': au1x00_eth.c:158: warning: passing argument 1 of 'virt_to_phys' discards qualifiers from pointer target type text data bss dec hex filename 118780 5264 20648 144692 23534 ./u-boot skuribay@ubuntu:u-boot.git$ skuribay@ubuntu:u-boot.git$ skuribay@ubuntu:u-boot.git$ stg push Checking for changes in the working directory ... done Fast-forwarded patch "mips-fix-dbau1000-warning.patch" Now at patch "mips-fix-dbau1000-warning.patch" skuribay@ubuntu:u-boot.git$ skuribay@ubuntu:u-boot.git$ CROSS_COMPILE=mips-linux-gnu- ./MAKEALL dbau1000 Configuring for dbau1x00 board... au1x00_eth.c: In function 'au1x00_recv': au1x00_eth.c:211: warning: passing argument 1 of 'virt_to_phys' discards qualifiers from pointer target type au1x00_eth.c: In function 'au1x00_init': au1x00_eth.c:253: warning: passing argument 1 of 'virt_to_phys' discards qualifiers from pointer target type au1x00_eth.c: In function 'au1x00_send': au1x00_eth.c:158: warning: passing argument 1 of 'virt_to_phys' discards qualifiers from pointer target type text data bss dec hex filename 118780 5264 20648 144692 23534 ./u-boot skuribay@ubuntu:u-boot.git$

On Wednesday 28 January 2009, Shinya Kuribayashi wrote:
Stefan Roese wrote:
This patch fixes this compilation warning:
./MAKEALL dbau1000 Configuring for dbau1x00 board... au1x00_eth.c: In function 'au1x00_send': au1x00_eth.c:158: warning: passing argument 1 of 'virt_to_phys' discards qualifiers from pointer target type ...
Seens with ELDK 4.2 (GCC 4.2.2).
Signed-off-by: Stefan Roese sr@denx.de
The number of warnings decreases by half, but we're still warned. Comments? I've not took a look of the patch itself, yet. Just let you know.
Hmmm, strange. I only see 3 warnings which are resolved with my patch:
[stefan@kubuntu u-boot (master)]$ ./MAKEALL dbau1000 Configuring for dbau1x00 board... au1x00_eth.c: In function 'au1x00_send': au1x00_eth.c:158: warning: passing argument 1 of 'virt_to_phys' discards qualifiers from pointer target type au1x00_eth.c: In function 'au1x00_recv': au1x00_eth.c:211: warning: passing argument 1 of 'virt_to_phys' discards qualifiers from pointer target type au1x00_eth.c: In function 'au1x00_init': au1x00_eth.c:252: warning: passing argument 1 of 'virt_to_phys' discards qualifiers from pointer target type text data bss dec hex filename 120028 5408 20648 146084 23aa4 ./u-boot [stefan@kubuntu u-boot (master)]$ git am patches_stefan/0001-MIPS-Fix-compile-warning-in-au1x00_eth.c.patch Applying: MIPS: Fix compile warning in au1x00_eth.c [stefan@kubuntu u-boot (master)]$ ./MAKEALL dbau1000 Configuring for dbau1x00 board... text data bss dec hex filename 120028 5408 20648 146084 23aa4 ./u-boot
This is on TOT (git ID 2b6fd5c77db9c6ed3cea9799c86ff922cf0107b2).
Ah, there's something I noticed in your test. Please see below.
skuribay@ubuntu:u-boot.git$ mips-linux-gnu-gcc --version mips-linux-gnu-gcc (Sourcery G++ Lite 4.2-177) 4.2.3 Copyright (C) 2007 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
skuribay@ubuntu:u-boot.git$ skuribay@ubuntu:u-boot.git$ CROSS_COMPILE=mips-linux-gnu- ./MAKEALL dbau1000 Configuring for dbau1x00 board... au1x00_eth.c: In function 'au1x00_send': au1x00_eth.c:158: warning: passing argument 1 of 'virt_to_phys' discards qualifiers from pointer target type au1x00_eth.c: In function 'au1x00_recv': au1x00_eth.c:211: warning: passing argument 1 of 'virt_to_phys' discards qualifiers from pointer target type au1x00_eth.c: In function 'au1x00_init': au1x00_eth.c:252: warning: passing argument 1 of 'virt_to_phys' discards qualifiers from pointer target type au1x00_eth.c: In function 'au1x00_recv': au1x00_eth.c:211: warning: passing argument 1 of 'virt_to_phys' discards qualifiers from pointer target type au1x00_eth.c: In function 'au1x00_init': au1x00_eth.c:252: warning: passing argument 1 of 'virt_to_phys' discards qualifiers from pointer target type au1x00_eth.c: In function 'au1x00_send': au1x00_eth.c:158: warning: passing argument 1 of 'virt_to_phys' discards qualifiers from pointer target type text data bss dec hex filename 118780 5264 20648 144692 23534 ./u-boot
Those errors occur twice. Seems that you are compiling this file twice. Any idea why?
skuribay@ubuntu:u-boot.git$ skuribay@ubuntu:u-boot.git$ skuribay@ubuntu:u-boot.git$ stg push Checking for changes in the working directory ... done Fast-forwarded patch "mips-fix-dbau1000-warning.patch" Now at patch "mips-fix-dbau1000-warning.patch" skuribay@ubuntu:u-boot.git$ skuribay@ubuntu:u-boot.git$ CROSS_COMPILE=mips-linux-gnu- ./MAKEALL dbau1000 Configuring for dbau1x00 board... au1x00_eth.c: In function 'au1x00_recv': au1x00_eth.c:211: warning: passing argument 1 of 'virt_to_phys' discards qualifiers from pointer target type au1x00_eth.c: In function 'au1x00_init': au1x00_eth.c:253: warning: passing argument 1 of 'virt_to_phys' discards qualifiers from pointer target type au1x00_eth.c: In function 'au1x00_send': au1x00_eth.c:158: warning: passing argument 1 of 'virt_to_phys' discards qualifiers from pointer target type text data bss dec hex filename 118780 5264 20648 144692 23534 ./u-boot skuribay@ubuntu:u-boot.git$
And now one version of the errors are solved, only one is remaining. Perhaps you are compiling a 2nd version of this driver again. Just guessing...
Best regards, Stefan
===================================================================== DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: +49-8142-66989-0 Fax: +49-8142-66989-80 Email: office@denx.de =====================================================================

Stefan Roese wrote:
skuribay@ubuntu:u-boot.git$ mips-linux-gnu-gcc --version mips-linux-gnu-gcc (Sourcery G++ Lite 4.2-177) 4.2.3 Copyright (C) 2007 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
skuribay@ubuntu:u-boot.git$ skuribay@ubuntu:u-boot.git$ CROSS_COMPILE=mips-linux-gnu- ./MAKEALL dbau1000 Configuring for dbau1x00 board... au1x00_eth.c: In function 'au1x00_send': au1x00_eth.c:158: warning: passing argument 1 of 'virt_to_phys' discards qualifiers from pointer target type au1x00_eth.c: In function 'au1x00_recv': au1x00_eth.c:211: warning: passing argument 1 of 'virt_to_phys' discards qualifiers from pointer target type au1x00_eth.c: In function 'au1x00_init': au1x00_eth.c:252: warning: passing argument 1 of 'virt_to_phys' discards qualifiers from pointer target type au1x00_eth.c: In function 'au1x00_recv': au1x00_eth.c:211: warning: passing argument 1 of 'virt_to_phys' discards qualifiers from pointer target type au1x00_eth.c: In function 'au1x00_init': au1x00_eth.c:252: warning: passing argument 1 of 'virt_to_phys' discards qualifiers from pointer target type au1x00_eth.c: In function 'au1x00_send': au1x00_eth.c:158: warning: passing argument 1 of 'virt_to_phys' discards qualifiers from pointer target type text data bss dec hex filename 118780 5264 20648 144692 23534 ./u-boot
Those errors occur twice. Seems that you are compiling this file twice. Any idea why?
Probably it's due to the GCC 4.2.x minor version difference.
Googling[1][2] and playing for a while, I finally managed to quiet the GCC with the following patch.
diff --git a/cpu/mips/au1x00_eth.c b/cpu/mips/au1x00_eth.c index 6272a3a..c2c76ac 100644 --- a/cpu/mips/au1x00_eth.c +++ b/cpu/mips/au1x00_eth.c @@ -155,7 +155,7 @@ static int au1x00_send(struct eth_device* dev, volatile void *packet, int length
/* tx fifo should always be idle */ fifo_tx[next_tx].len = length; - fifo_tx[next_tx].addr = (virt_to_phys(packet))|TX_DMA_ENABLE; + fifo_tx[next_tx].addr = (virt_to_phys((void *)(unsigned long)packet))|TX_DMA_ENABLE; au_sync();
udelay(1); @@ -208,7 +208,7 @@ static int au1x00_recv(struct eth_device* dev){ NetReceive(NetRxPackets[next_rx], length - 4); }
- fifo_rx[next_rx].addr = (virt_to_phys(NetRxPackets[next_rx]))|RX_DMA_ENABLE; + fifo_rx[next_rx].addr = (virt_to_phys((void *)(unsigned long)NetRxPackets[next_rx]))|RX_DMA_ENABLE;
next_rx++; if(next_rx>=NO_OF_FIFOS){ @@ -249,7 +249,7 @@ static int au1x00_init(struct eth_device* dev, bd_t * bd){ for(i=0;i<NO_OF_FIFOS;i++){ fifo_tx[i].len = 0; fifo_tx[i].addr = virt_to_phys(&txbuf[0]); - fifo_rx[i].addr = (virt_to_phys(NetRxPackets[i]))|RX_DMA_ENABLE; + fifo_rx[i].addr = (virt_to_phys((void *)(unsigned long)NetRxPackets[i]))|RX_DMA_ENABLE; }
/* Put mac addr in little endian */
Well, what will we do? Are there any othrer desirable fixes?
[1] http://lists.denx.de/pipermail/u-boot/2008-December/044960.html [PATCH 01/11] powerpc: fix io.h build warning with CONFIG_PHYS_64BIT
[2] http://lkml.org/lkml/2009/1/27/67 Interestingly, this only happens with gcc-4.2; gcc <= 4.1 and gcc-4.3 are OK.

On Friday 30 January 2009, Shinya Kuribayashi wrote:
@@ -249,7 +249,7 @@ static int au1x00_init(struct eth_device* dev, bd_t * bd){ for(i=0;i<NO_OF_FIFOS;i++){ fifo_tx[i].len = 0; fifo_tx[i].addr = virt_to_phys(&txbuf[0]);
fifo_rx[i].addr = (virt_to_phys(NetRxPackets[i]))|RX_DMA_ENABLE;
fifo_rx[i].addr = (virt_to_phys((void *)(unsigned
long)NetRxPackets[i]))|RX_DMA_ENABLE; }
/* Put mac addr in little endian */
Well, what will we do? Are there any othrer desirable fixes?
Hmmm, strange that such a double cast is really needed.
BTW: I'm beginning to wonder if we really need the "volatile" in the net related parameters. Perhaps this should be reviewed again.
PS: I'm leaving for a short vacation in a few hours. I'll be back on Thursday next week.
Best regards, Stefan
===================================================================== DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: +49-8142-66989-0 Fax: +49-8142-66989-80 Email: office@denx.de =====================================================================

Compiling dbau1x00 and gth2 boards with GCC-4.2, you would see new warnings like this:
skuribay@ubuntu:u-boot.git$ ./MAKEALL dbau1000 Configuring for dbau1x00 board... au1x00_eth.c: In function 'au1x00_send': au1x00_eth.c:158: warning: passing argument 1 of 'virt_to_phys' discards qualifiers from pointer target type au1x00_eth.c: In function 'au1x00_recv': au1x00_eth.c:211: warning: passing argument 1 of 'virt_to_phys' discards qualifiers from pointer target type au1x00_eth.c: In function 'au1x00_init': au1x00_eth.c:252: warning: passing argument 1 of 'virt_to_phys' discards qualifiers from pointer target type au1x00_eth.c: In function 'au1x00_recv': au1x00_eth.c:211: warning: passing argument 1 of 'virt_to_phys' discards qualifiers from pointer target type au1x00_eth.c: In function 'au1x00_init': au1x00_eth.c:252: warning: passing argument 1 of 'virt_to_phys' discards qualifiers from pointer target type au1x00_eth.c: In function 'au1x00_send': au1x00_eth.c:158: warning: passing argument 1 of 'virt_to_phys' discards qualifiers from pointer target type
We're passing a volatile pointer to a function which is expecting a non- volatile pointer. That's potentially dangerous, so gcc warns about it. Confirmed with ELDK 4.2 (GCC 4.2.2) and Sourcey G++ 4.2 (GCC 4.2.3).
To fix this, we add a volatile attribute to the argument in question. The virt_to_phys function in Linux kernel also does the same thing.
Signed-off-by: Stefan Roese sr@denx.de Signed-off-by: Shinya Kuribayashi skuribay@ruby.dti.ne.jp --- Sorry for late reply,
Stefan: I think this is a reasonable fix. I believe this works for ELDK as well, of course.
Walfgang: Please pick this up directly, thanks in advance.
include/asm-mips/io.h | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/include/asm-mips/io.h b/include/asm-mips/io.h index 031186d..025012a 100644 --- a/include/asm-mips/io.h +++ b/include/asm-mips/io.h @@ -118,7 +118,7 @@ static inline void set_io_port_base(unsigned long base) * Change virtual addresses to physical addresses and vv. * These are trivial on the 1:1 Linux/MIPS mapping */ -extern inline phys_addr_t virt_to_phys(void * address) +extern inline phys_addr_t virt_to_phys(volatile void * address) { return CPHYSADDR(address); }

Dear Shinya Kuribayashi,
In message 49A0E17B.9090300@ruby.dti.ne.jp you wrote:
Compiling dbau1x00 and gth2 boards with GCC-4.2, you would see new warnings like this:
skuribay@ubuntu:u-boot.git$ ./MAKEALL dbau1000 Configuring for dbau1x00 board... au1x00_eth.c: In function 'au1x00_send': au1x00_eth.c:158: warning: passing argument 1 of 'virt_to_phys' discards qualifiers from pointer target type au1x00_eth.c: In function 'au1x00_recv': au1x00_eth.c:211: warning: passing argument 1 of 'virt_to_phys' discards qualifiers from pointer target type au1x00_eth.c: In function 'au1x00_init': au1x00_eth.c:252: warning: passing argument 1 of 'virt_to_phys' discards qualifiers from pointer target type au1x00_eth.c: In function 'au1x00_recv': au1x00_eth.c:211: warning: passing argument 1 of 'virt_to_phys' discards qualifiers from pointer target type au1x00_eth.c: In function 'au1x00_init': au1x00_eth.c:252: warning: passing argument 1 of 'virt_to_phys' discards qualifiers from pointer target type au1x00_eth.c: In function 'au1x00_send': au1x00_eth.c:158: warning: passing argument 1 of 'virt_to_phys' discards qualifiers from pointer target type
We're passing a volatile pointer to a function which is expecting a non- volatile pointer. That's potentially dangerous, so gcc warns about it. Confirmed with ELDK 4.2 (GCC 4.2.2) and Sourcey G++ 4.2 (GCC 4.2.3).
To fix this, we add a volatile attribute to the argument in question. The virt_to_phys function in Linux kernel also does the same thing.
Signed-off-by: Stefan Roese sr@denx.de Signed-off-by: Shinya Kuribayashi skuribay@ruby.dti.ne.jp
Sorry for late reply,
Stefan: I think this is a reasonable fix. I believe this works for ELDK as well, of course.
Walfgang: Please pick this up directly, thanks in advance.
include/asm-mips/io.h | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
Applied, thanks.
Best regards,
Wolfgang Denk
participants (4)
-
Shinya Kuribayashi
-
Shinya Kuribayashi
-
Stefan Roese
-
Wolfgang Denk