Skip to contentSkip to conversation

x86: truncate ISA addresses to unsigned int

tip:x86/headers James Bottomley 3 participants 3 messages Feb 17, 2009 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw
Quoted 28 lines · H. Peter Anvin
Author:     H. Peter Anvin <[email protected]>
AuthorDate: Tue, 17 Feb 2009 13:01:51 -0800
Commit:     H. Peter Anvin <[email protected]>
CommitDate: Tue, 17 Feb 2009 13:01:51 -0800

x86: truncate ISA addresses to unsigned int

Impact: Cleanup; fix inappropriate macro use

ISA addresses on x86 are mapped 1:1 with the physical address space. Since the ISA address space is only 24 bits (32 for VLB or LPC) it will always fit in an unsigned int, and at least in the aha1542 driver using a wider type would cause an undesirable promotion. Hence explicitly cast the ISA bus addresses to unsigned int.

---
 arch/x86/include/asm/io.h |   11 ++++++++---
 1 files changed, 8 insertions(+), 3 deletions(-)
arch/x86/include/asm/io.h +0 -0
index 4f8e820..683d0b4 100644

arch/x86/include/asm/io.h static inline void *phys_to_virt(phys_addr_t address) · line 130

Quoted 10 lines
arch/x86/include/asm/io.h +3 -3
@@ -124,10 +124,15 @@ static inline void *phys_to_virt(phys_addr_t address)
 
 /*
  * ISA I/O bus memory addresses are 1:1 with the physical address.
+ * However, we truncate the address to unsigned int to avoid undesirable
+ * promitions in legacy drivers.
  */
-#define isa_virt_to_bus (unsigned long)virt_to_phys
-#define isa_page_to_bus page_to_phys
-#define isa_bus_to_virt phys_to_virt
+static inline unsigned int isa_virt_to_bus(volatile void *address)

The rest looks fine, but why is the address volatile? The macro below never actually dereferences it.

arch/x86/include/asm/io.h static inline void *phys_to_virt(phys_addr_t address) · line 138

Quoted 8 lines
arch/x86/include/asm/io.h +5 -0
+{
+	return (unsigned int)virt_to_phys(address);
+}
+#define isa_page_to_bus(page)	((unsigned int)page_to_phys(page))
+#define isa_bus_to_virt		phys_to_virt
 
 /*
  * However PCI ones are not necessarily 1:1 and therefore these interfaces

James

#2 lore raw
Quoted 5 lines · James Bottomley
Quoted 1 line

+static inline unsigned int isa_virt_to_bus(volatile void *address)

The rest looks fine, but why is the address volatile? The macro below never actually dereferences it.

Because a volatile is permitted. virt_to_phys() takes a volatile pointer for that reason.

-hpa

#3 lore raw
In reply to James Bottomley
Quoted 30 lines · James Bottomley
Quoted 29 lines · H. Peter Anvin
Author:     H. Peter Anvin <[email protected]>
AuthorDate: Tue, 17 Feb 2009 13:01:51 -0800
Commit:     H. Peter Anvin <[email protected]>
CommitDate: Tue, 17 Feb 2009 13:01:51 -0800

x86: truncate ISA addresses to unsigned int

Impact: Cleanup; fix inappropriate macro use

ISA addresses on x86 are mapped 1:1 with the physical address space. Since the ISA address space is only 24 bits (32 for VLB or LPC) it will always fit in an unsigned int, and at least in the aha1542 driver using a wider type would cause an undesirable promotion. Hence explicitly cast the ISA bus addresses to unsigned int.

---
 arch/x86/include/asm/io.h |   11 ++++++++---
 1 files changed, 8 insertions(+), 3 deletions(-)
arch/x86/include/asm/io.h +0 -0
index 4f8e820..683d0b4 100644
@@ -124,10 +124,15 @@ static inline void *phys_to_virt(phys_addr_t address)
 
Quoted 12 lines

arch/x86/include/asm/io.h static inline void *phys_to_virt(phys_addr_t address) · line 130

Quoted 9 lines
arch/x86/include/asm/io.h +3 -3
 /*
  * ISA I/O bus memory addresses are 1:1 with the physical address.
+ * However, we truncate the address to unsigned int to avoid undesirable
+ * promitions in legacy drivers.
  */
-#define isa_virt_to_bus (unsigned long)virt_to_phys
-#define isa_page_to_bus page_to_phys
-#define isa_bus_to_virt phys_to_virt
+static inline unsigned int isa_virt_to_bus(volatile void *address)

The rest looks fine, but why is the address volatile? The macro below never actually dereferences it.

That is because the volatile keyword here broadens the permitted _input_ type.

Ingo