Skip to contentSkip to conversation

nios2: fix virt_to_phys for nios2 with MMU

PATCH Superseded Thomas Chou 3 participants 5 messages Oct 21, 2015 – Oct 23, 2015 NIOS2 architecture

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nios2: fix virt_to_phys for nios2 with MMU

As the virtual address and physical address mapping of nios2 with MMU are different. Add a check of MMU, and fix the mapping.

---
 arch/nios2/include/asm/io.h | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
arch/nios2/include/asm/io.h +5 -1
index d0adf08..fdfc14e 100644
@@ -39,7 +39,11 @@ static inline void unmap_physmem(void *vaddr, unsigned long flags)
 
 static inline phys_addr_t virt_to_phys(void * vaddr)
 {
-	return (phys_addr_t)(vaddr);
+	DECLARE_GLOBAL_DATA_PTR;
+	if (gd->arch.has_mmu)
+		return (phys_addr_t)(vaddr) & 0x1fffffff;
+	else
+		return (phys_addr_t)(vaddr) & 0x7fffffff;
 }
 
 static inline void *ioremap(unsigned long physaddr, unsigned long size)
Signature · 1 line
2.1.4
#1 lore raw

PATCH 1/1 nios2: fix virt_to_phys for nios2 with MMU

Quoted 13 lines · Thomas Chou

As the virtual address and physical address mapping of nios2 with MMU are different. Add a check of MMU, and fix the mapping.

---
 arch/nios2/include/asm/io.h | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
arch/nios2/include/asm/io.h +0 -0
index d0adf08..fdfc14e 100644

arch/nios2/include/asm/io.h static inline void unmap_physmem(void *vaddr, unsigned · line 47

Quoted 10 lines
arch/nios2/include/asm/io.h +5 -1
@@ -39,7 +39,11 @@ static inline void unmap_physmem(void *vaddr, unsigned
 long flags)
 
 static inline phys_addr_t virt_to_phys(void * vaddr)
 {
-	return (phys_addr_t)(vaddr);
+	DECLARE_GLOBAL_DATA_PTR;
+	if (gd->arch.has_mmu)
+		return (phys_addr_t)(vaddr) & 0x1fffffff;
+	else
+		return (phys_addr_t)(vaddr) & 0x7fffffff;

I _think_ the parenthesis around vaddr are not necessary, but otherwise, I really like to see this patch:

Quoted 3 lines
arch/nios2/include/asm/io.h +0 -0
 }
 

static inline void *ioremap(unsigned long physaddr, unsigned long size)

Best regards,
Marek Vasut

#2 lore raw

PATCH 1/1 nios2: fix virt_to_phys for nios2 with MMU

In reply to Thomas Chou
Quoted 13 lines · Thomas Chou

As the virtual address and physical address mapping of nios2 with MMU are different. Add a check of MMU, and fix the mapping.

---
 arch/nios2/include/asm/io.h | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
arch/nios2/include/asm/io.h +0 -0
index d0adf08..fdfc14e 100644

arch/nios2/include/asm/io.h static inline void unmap_physmem(void *vaddr, unsigned long flags) · line 47

Quoted 10 lines
arch/nios2/include/asm/io.h +5 -1
@@ -39,7 +39,11 @@ static inline void unmap_physmem(void *vaddr, unsigned long flags)
 
 static inline phys_addr_t virt_to_phys(void * vaddr)
 {
-       return (phys_addr_t)(vaddr);
+       DECLARE_GLOBAL_DATA_PTR;
+       if (gd->arch.has_mmu)
+               return (phys_addr_t)(vaddr) & 0x1fffffff;
+       else
+               return (phys_addr_t)(vaddr) & 0x7fffffff;
 }

Regards
Ley Foon

#3 lore raw

PATCH v2 1/1 nios2: fix virt_to_phys for nios2 with MMU

In reply to Thomas Chou

As the virtual address and physical address mapping of nios2 with MMU are different. Add a check of MMU, and fix the mapping.

---
v2
remove the parenthesis around vaddr as suggested by Marek.

 arch/nios2/include/asm/io.h | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
arch/nios2/include/asm/io.h +5 -1
index d0adf08..e7da35b 100644
@@ -39,7 +39,11 @@ static inline void unmap_physmem(void *vaddr, unsigned long flags)
 
 static inline phys_addr_t virt_to_phys(void * vaddr)
 {
-	return (phys_addr_t)(vaddr);
+	DECLARE_GLOBAL_DATA_PTR;
+	if (gd->arch.has_mmu)
+		return (phys_addr_t)vaddr & 0x1fffffff;
+	else
+		return (phys_addr_t)vaddr & 0x7fffffff;
 }
 
 static inline void *ioremap(unsigned long physaddr, unsigned long size)
Signature · 1 line
2.1.4
#4 lore raw

PATCH v2 1/1 nios2: fix virt_to_phys for nios2 with MMU

Quoted 6 lines · Thomas Chou

As the virtual address and physical address mapping of nios2 with MMU are different. Add a check of MMU, and fix the mapping.

Quoted 7 lines

---
v2
remove the parenthesis around vaddr as suggested by Marek.

  arch/nios2/include/asm/io.h | 6 +++++-
  1 file changed, 5 insertions(+), 1 deletion(-)

Applied to u-boot-nios.