Skip to contentSkip to conversation

x86/early_printk: Use __iomem address space for IO

PATCH Superseded Andy Shevchenko 2 participants 5 messages Oct 9, 2015 – Oct 12, 2015 x86

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 x86/early_printk: Use __iomem address space for IO

There are following warnings on unpatched code:

arch/x86/kernel/early_printk.c:198:32: warning: incorrect type in initializer (different address spaces)
arch/x86/kernel/early_printk.c:198:32: expected void [noderef] <asn:2>*vaddr
arch/x86/kernel/early_printk.c:198:32: got unsigned int [usertype] *<noident>
arch/x86/kernel/early_printk.c:205:32: warning: incorrect type in initializer (different address spaces)
arch/x86/kernel/early_printk.c:205:32: expected void [noderef] <asn:2>*vaddr
arch/x86/kernel/early_printk.c:205:32: got unsigned int [usertype] *<noident>

---
v2:
- amend subject line

 arch/x86/kernel/early_printk.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/kernel/early_printk.c +2 -2
index 076a4a7..77f2f5c 100644
@@ -195,14 +195,14 @@ static __init void early_serial_init(char *s)
 #ifdef CONFIG_PCI
 static void mem32_serial_out(unsigned long addr, int offset, int value)
 {
-	u32 *vaddr = (u32 *)addr;
+	void __iomem *vaddr = (void __iomem *)addr;
 	/* shift implied by pointer type */
 	writel(value, vaddr + offset);
 }
 
 static unsigned int mem32_serial_in(unsigned long addr, int offset)
 {
-	u32 *vaddr = (u32 *)addr;
+	void __iomem *vaddr = (void __iomem *)addr;
 	/* shift implied by pointer type */
 	return readl(vaddr + offset);
 }
Signature · 1 line
2.5.3
#1 lore raw
Quoted 14 lines · Andy Shevchenko

There are following warnings on unpatched code:

arch/x86/kernel/early_printk.c:198:32: warning: incorrect type in initializer (different address spaces)
arch/x86/kernel/early_printk.c:198:32: expected void [noderef]
<asn:2>*vaddr
arch/x86/kernel/early_printk.c:198:32: got unsigned int [usertype]
*<noident>
arch/x86/kernel/early_printk.c:205:32: warning: incorrect type in initializer (different address spaces)
arch/x86/kernel/early_printk.c:205:32: expected void [noderef]
<asn:2>*vaddr
arch/x86/kernel/early_printk.c:205:32: got unsigned int [usertype]
*<noident>

This one is wrong, sorry for noise.

Quoted 31 lines

---
v2:
- amend subject line

 arch/x86/kernel/early_printk.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/kernel/early_printk.c +2 -2
index 076a4a7..77f2f5c 100644
@@ -195,14 +195,14 @@ static __init void early_serial_init(char *s)
 #ifdef CONFIG_PCI
 static void mem32_serial_out(unsigned long addr, int offset, int 
 value)
 {
-	u32 *vaddr = (u32 *)addr;
+	void __iomem *vaddr = (void __iomem *)addr;
 	/* shift implied by pointer type */
 	writel(value, vaddr + offset);
 }
 
 static unsigned int mem32_serial_in(unsigned long addr, int offset)
 {
-	u32 *vaddr = (u32 *)addr;
+	void __iomem *vaddr = (void __iomem *)addr;
 	/* shift implied by pointer type */
 	return readl(vaddr + offset);

}

Signature · 2 lines
Andy Shevchenko <[email protected]>
Intel Finland Oy
#2 lore raw
In reply to Andy Shevchenko

Andy,

arch/x86/kernel/early_printk.c static __init void early_serial_init(char *s) · line 200

Quoted 7 lines · Andy Shevchenko

#ifdef CONFIG_PCI
static void mem32_serial_out(unsigned long addr, int offset, int value) {

arch/x86/kernel/early_printk.c +1 -1
-	u32 *vaddr = (u32 *)addr;
+	void __iomem *vaddr = (void __iomem *)addr;
 	/* shift implied by pointer type */
 	writel(value, vaddr + offset);

This is broken. Assume vaddr = 0x1000 and offset = 1

==> u32 *vaddr = 0x1000;
==> vaddr + offset = 0x1004

with your change

==> void __iomem *vaddr = 0x1000;

==> vaddr + offset = 0x1001

This comment is there for a reason:

Quoted 1 line

/* shift implied by pointer type */

Thanks,

tglx

#3 lore raw
Quoted 5 lines · Thomas Gleixner

Andy,

Quoted 2 lines · Andy Shevchenko

#ifdef CONFIG_PCI
static void mem32_serial_out(unsigned long addr, int offset, int

Quoted 8 lines

value)

arch/x86/kernel/early_printk.c static __init void early_serial_init(char *s) · line 200

Quoted 5 lines

{

arch/x86/kernel/early_printk.c +1 -1
-     u32 *vaddr = (u32 *)addr;
+     void __iomem *vaddr = (void __iomem *)addr;
      /* shift implied by pointer type */
      writel(value, vaddr + offset);

This is broken. Assume vaddr = 0x1000 and offset = 1

Yes, I noticed in reply to myself
http://www.spinics.net/lists/kernel/msg2094143.html

Tests were okay because platform I have is using 8-bit I/O.

Does it make sense to use the following approach?

void __iomem *vaddr = (void __iomem *)addr;
writel(value, vaddr + offset << 2);

Quoted 16 lines

==> u32 *vaddr = 0x1000;
==> vaddr + offset = 0x1004

with your change

==> void __iomem *vaddr = 0x1000;

==> vaddr + offset = 0x1001

This comment is there for a reason:

Quoted 1 line
      /* shift implied by pointer type */

Thanks,

tglx

Signature · 2 lines
Andy Shevchenko <[email protected]>
Intel Finland Oy
#4 lore raw
Quoted 18 lines · Andy Shevchenko
Quoted 5 lines · Thomas Gleixner

Andy,

Quoted 2 lines · Andy Shevchenko

#ifdef CONFIG_PCI
static void mem32_serial_out(unsigned long addr, int offset, int

Quoted 8 lines

value)

arch/x86/kernel/early_printk.c static __init void early_serial_init(char *s) · line 200

Quoted 5 lines

{

arch/x86/kernel/early_printk.c +1 -1
-     u32 *vaddr = (u32 *)addr;
+     void __iomem *vaddr = (void __iomem *)addr;
      /* shift implied by pointer type */
      writel(value, vaddr + offset);

This is broken. Assume vaddr = 0x1000 and offset = 1

Yes, I noticed in reply to myself
http://www.spinics.net/lists/kernel/msg2094143.html

Quoted 6 lines

Tests were okay because platform I have is using 8-bit I/O.

Does it make sense to use the following approach?

void __iomem *vaddr = (void __iomem *)addr;
writel(value, vaddr + offset << 2);

What's wrong with: u32 __iomem *vaddr ?

Thanks,

tglx