Skip to contentSkip to conversation

Generic ioremap_page_range: introduction

PATCH In review Haavard Skinnemoen 6 participants 21 messages Aug 8, 2006

Subsystems (9)
Arm (32-bit) Library code MIPS s390 +5 more subsystems
lore
Share & tools
lore
#0 lore raw

cover Generic ioremap_page_range: introduction

Since no one seemed to have any serious objections, here's a complete patchset with an updated ioremap_page_range() based on suggestions from Dave Hansen, Paul Mackerras and David Miller.

This also updates all architectures that were relatively trivial to convert. Most of remaining architectures implement ioremap() as a no-op or something close. Exceptions are m68k, powerpc and sparc.

m68k has some CPU-dependent logic in the middle of the loop.

powerpc could probably use generic ioremap_page_range(), but doing so would probably increase the code size, as the map_page() functions have other users in addition to ioremap().

sparc seems to do something completely different than everyone else.

I'll post the implementation as well as one patch per architecture conversion right after this. I haven't compile-tested most of the architecture changes, but it compiles and runs on AVR32.

Overall diffstat below.

Haavard

 arch/alpha/kernel/proto.h |   15 +++++-
 arch/alpha/mm/Makefile    |    2 -
 arch/alpha/mm/remap.c     |   86 --------------------------------
 arch/arm/mm/ioremap.c     |   95 ++----------------------------------
 arch/avr32/mm/ioremap.c   |  120 ++-------------------------------------------
 arch/cris/mm/ioremap.c    |   88 +--------------------------------
 arch/i386/mm/ioremap.c    |   85 ++------------------------------
 arch/m32r/mm/ioremap.c    |   93 +++--------------------------------
 arch/mips/mm/ioremap.c    |   95 +++---------------------------------
 arch/parisc/mm/ioremap.c  |  111 +++---------------------------------------
 arch/s390/mm/ioremap.c    |   84 +-------------------------------
 arch/sh/mm/ioremap.c      |   97 +++---------------------------------
 arch/sh64/mm/ioremap.c    |  100 +++-----------------------------------
 arch/x86_64/mm/ioremap.c  |  110 ++---------------------------------------
 include/linux/io.h        |    4 ++
 lib/Makefile              |    2 -
 lib/ioremap.c             |   91 ++++++++++++++++++++++++++++++++++
 17 files changed, 174 insertions(+), 1104 deletions(-)
#3 lore raw

PATCH 3/13 Generic ioremap_page_range: arm conversion

In reply to Haavard Skinnemoen

Convert ARM to use generic ioremap_page_range()

---
 arch/arm/mm/ioremap.c |   95 +++----------------------------------------------
 1 files changed, 5 insertions(+), 90 deletions(-)
arch/arm/mm/ioremap.c +5 -90
index 88a999d..942a1ee 100644
@@ -22,11 +22,11 @@
  */
 #include <linux/module.h>
 #include <linux/errno.h>
+#include <linux/io.h>
 #include <linux/mm.h>
 #include <linux/vmalloc.h>
 
 #include <asm/cacheflush.h>
-#include <asm/io.h>
 #include <asm/mmu_context.h>
 #include <asm/pgalloc.h>
 #include <asm/tlbflush.h>
@@ -38,94 +38,6 @@ #include <asm/sizes.h>
  */
 #define VM_ARM_SECTION_MAPPING	0x80000000
 
-static inline void
-remap_area_pte(pte_t * pte, unsigned long address, unsigned long size,
-	       unsigned long phys_addr, pgprot_t pgprot)
-{
-	unsigned long end;
-
-	address &= ~PMD_MASK;
-	end = address + size;
-	if (end > PMD_SIZE)
-		end = PMD_SIZE;
-	BUG_ON(address >= end);
-	do {
-		if (!pte_none(*pte))
-			goto bad;
-
-		set_pte(pte, pfn_pte(phys_addr >> PAGE_SHIFT, pgprot));
-		address += PAGE_SIZE;
-		phys_addr += PAGE_SIZE;
-		pte++;
-	} while (address && (address < end));
-	return;
-
- bad:
-	printk("remap_area_pte: page already exists\n");
-	BUG();
-}
-
-static inline int
-remap_area_pmd(pmd_t * pmd, unsigned long address, unsigned long size,
-	       unsigned long phys_addr, unsigned long flags)
-{
-	unsigned long end;
-	pgprot_t pgprot;
-
-	address &= ~PGDIR_MASK;
-	end = address + size;
-
-	if (end > PGDIR_SIZE)
-		end = PGDIR_SIZE;
-
-	phys_addr -= address;
-	BUG_ON(address >= end);
-
-	pgprot = __pgprot(L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY | L_PTE_WRITE | flags);
-	do {
-		pte_t * pte = pte_alloc_kernel(pmd, address);
-		if (!pte)
-			return -ENOMEM;
-		remap_area_pte(pte, address, end - address, address + phys_addr, pgprot);
-		address = (address + PMD_SIZE) & PMD_MASK;
-		pmd++;
-	} while (address && (address < end));
-	return 0;
-}
-
-static int
-remap_area_pages(unsigned long start, unsigned long pfn,
-		 unsigned long size, unsigned long flags)
-{
-	unsigned long address = start;
-	unsigned long end = start + size;
-	unsigned long phys_addr = __pfn_to_phys(pfn);
-	int err = 0;
-	pgd_t * dir;
-
-	phys_addr -= address;
-	dir = pgd_offset(&init_mm, address);
-	BUG_ON(address >= end);
-	do {
-		pmd_t *pmd = pmd_alloc(&init_mm, dir, address);
-		if (!pmd) {
-			err = -ENOMEM;
-			break;
-		}
-		if (remap_area_pmd(pmd, address, end - address,
-					 phys_addr + address, flags)) {
-			err = -ENOMEM;
-			break;
-		}
-
-		address = (address + PGDIR_SIZE) & PGDIR_MASK;
-		dir++;
-	} while (address && (address < end));
-
-	return err;
-}
-
-
 void __check_kvm_seq(struct mm_struct *mm)
 {
 	unsigned int seq;
@@ -326,7 +238,10 @@ #ifndef CONFIG_SMP
 		err = remap_area_sections(addr, pfn, size, flags);
 	} else
 #endif
-		err = remap_area_pages(addr, pfn, size, flags);
+		err = ioremap_page_range(addr, addr + size, pfn << PAGE_SHIFT,
+					 __pgprot(L_PTE_PRESENT | L_PTE_YOUNG
+						  | L_PTE_DIRTY | L_PTE_WRITE
+						  | flags));
 
 	if (err) {
  		vunmap((void *)addr);
Signature · 1 line
1.4.0
#10 lore raw

PATCH 10/13 Generic ioremap_page_range: s390 conversion

In reply to Haavard Skinnemoen

Convert S390 to use generic ioremap_page_range()

---
 arch/s390/mm/ioremap.c |   84 ++----------------------------------------------
 1 files changed, 3 insertions(+), 81 deletions(-)
arch/s390/mm/ioremap.c +3 -81
index 0f6e9ec..3d2100a 100644
@@ -15,87 +15,8 @@
 
 #include <linux/vmalloc.h>
 #include <linux/mm.h>
-#include <asm/io.h>
+#include <linux/io.h>
 #include <asm/pgalloc.h>
-#include <asm/cacheflush.h>
-#include <asm/tlbflush.h>
-
-static inline void remap_area_pte(pte_t * pte, unsigned long address, unsigned long size,
-        unsigned long phys_addr, unsigned long flags)
-{
-        unsigned long end;
-        unsigned long pfn;
-
-        address &= ~PMD_MASK;
-        end = address + size;
-        if (end > PMD_SIZE)
-                end = PMD_SIZE;
-	if (address >= end)
-		BUG();
-        pfn = phys_addr >> PAGE_SHIFT;
-        do {
-                if (!pte_none(*pte)) {
-                        printk("remap_area_pte: page already exists\n");
-			BUG();
-		}
-                set_pte(pte, pfn_pte(pfn, __pgprot(flags)));
-                address += PAGE_SIZE;
-                pfn++;
-                pte++;
-        } while (address && (address < end));
-}
-
-static inline int remap_area_pmd(pmd_t * pmd, unsigned long address, unsigned long size,
-        unsigned long phys_addr, unsigned long flags)
-{
-	unsigned long end;
-
-	address &= ~PGDIR_MASK;
-	end = address + size;
-	if (end > PGDIR_SIZE)
-		end = PGDIR_SIZE;
-	phys_addr -= address;
-	if (address >= end)
-		BUG();
-	do {
-		pte_t * pte = pte_alloc_kernel(pmd, address);
-		if (!pte)
-			return -ENOMEM;
-		remap_area_pte(pte, address, end - address, address + phys_addr, flags);
-		address = (address + PMD_SIZE) & PMD_MASK;
-		pmd++;
-	} while (address && (address < end));
-	return 0;
-}
-
-static int remap_area_pages(unsigned long address, unsigned long phys_addr,
-				 unsigned long size, unsigned long flags)
-{
-	int error;
-	pgd_t * dir;
-	unsigned long end = address + size;
-
-	phys_addr -= address;
-	dir = pgd_offset(&init_mm, address);
-	flush_cache_all();
-	if (address >= end)
-		BUG();
-	do {
-		pmd_t *pmd;
-		pmd = pmd_alloc(&init_mm, dir, address);
-		error = -ENOMEM;
-		if (!pmd)
-			break;
-		if (remap_area_pmd(pmd, address, end - address,
-					 phys_addr + address, flags))
-			break;
-		error = 0;
-		address = (address + PGDIR_SIZE) & PGDIR_MASK;
-		dir++;
-	} while (address && (address < end));
-	flush_tlb_all();
-	return 0;
-}
 
 /*
  * Generic mapping function (not visible outside):
@@ -122,7 +43,8 @@ void * __ioremap(unsigned long phys_addr
 	if (!area)
 		return NULL;
 	addr = area->addr;
-	if (remap_area_pages((unsigned long) addr, phys_addr, size, flags)) {
+	if (ioremap_page_range((unsigned long)addr, (unsigned long)addr + size,
+			       phys_addr, __pgprot(flags))) {
 		vfree(addr);
 		return NULL;
 	}
Signature · 1 line
1.4.0
#11 lore raw

PATCH 11/13 Generic ioremap_page_range: sh conversion

Convert SH to use generic ioremap_page_range()

---
 arch/sh/mm/ioremap.c |   97 ++++----------------------------------------------
 1 files changed, 7 insertions(+), 90 deletions(-)
arch/sh/mm/ioremap.c +7 -90
index 96fa4a9..5ef9245 100644
@@ -15,98 +15,10 @@
 #include <linux/vmalloc.h>
 #include <linux/module.h>
 #include <linux/mm.h>
-#include <asm/io.h>
+#include <linux/io.h>
 #include <asm/page.h>
 #include <asm/pgalloc.h>
 #include <asm/addrspace.h>
-#include <asm/cacheflush.h>
-#include <asm/tlbflush.h>
-
-static inline void remap_area_pte(pte_t * pte, unsigned long address,
-	unsigned long size, unsigned long phys_addr, unsigned long flags)
-{
-	unsigned long end;
-	unsigned long pfn;
-	pgprot_t pgprot = __pgprot(_PAGE_PRESENT | _PAGE_RW |
-				   _PAGE_DIRTY | _PAGE_ACCESSED |
-				   _PAGE_HW_SHARED | _PAGE_FLAGS_HARD | flags);
-
-	address &= ~PMD_MASK;
-	end = address + size;
-	if (end > PMD_SIZE)
-		end = PMD_SIZE;
-	if (address >= end)
-		BUG();
-	pfn = phys_addr >> PAGE_SHIFT;
-	do {
-		if (!pte_none(*pte)) {
-			printk("remap_area_pte: page already exists\n");
-			BUG();
-		}
-		set_pte(pte, pfn_pte(pfn, pgprot));
-		address += PAGE_SIZE;
-		pfn++;
-		pte++;
-	} while (address && (address < end));
-}
-
-static inline int remap_area_pmd(pmd_t * pmd, unsigned long address,
-	unsigned long size, unsigned long phys_addr, unsigned long flags)
-{
-	unsigned long end;
-
-	address &= ~PGDIR_MASK;
-	end = address + size;
-	if (end > PGDIR_SIZE)
-		end = PGDIR_SIZE;
-	phys_addr -= address;
-	if (address >= end)
-		BUG();
-	do {
-		pte_t * pte = pte_alloc_kernel(pmd, address);
-		if (!pte)
-			return -ENOMEM;
-		remap_area_pte(pte, address, end - address, address + phys_addr, flags);
-		address = (address + PMD_SIZE) & PMD_MASK;
-		pmd++;
-	} while (address && (address < end));
-	return 0;
-}
-
-int remap_area_pages(unsigned long address, unsigned long phys_addr,
-		     unsigned long size, unsigned long flags)
-{
-	int error;
-	pgd_t * dir;
-	unsigned long end = address + size;
-
-	phys_addr -= address;
-	dir = pgd_offset_k(address);
-	flush_cache_all();
-	if (address >= end)
-		BUG();
-	do {
-		pud_t *pud;
-		pmd_t *pmd;
-
-		error = -ENOMEM;
-
-		pud = pud_alloc(&init_mm, dir, address);
-		if (!pud)
-			break;
-		pmd = pmd_alloc(&init_mm, pud, address);
-		if (!pmd)
-			break;
-		if (remap_area_pmd(pmd, address, end - address,
-					phys_addr + address, flags))
-			break;
-		error = 0;
-		address = (address + PGDIR_SIZE) & PGDIR_MASK;
-		dir++;
-	} while (address && (address < end));
-	flush_tlb_all();
-	return error;
-}
 
 /*
  * Remap an arbitrary physical address space into the kernel virtual
@@ -122,6 +34,7 @@ void __iomem *__ioremap(unsigned long ph
 {
 	struct vm_struct * area;
 	unsigned long offset, last_addr, addr, orig_addr;
+	pgprot_t pgprot;
 
 	/* Don't allow wraparound or zero size */
 	last_addr = phys_addr + size - 1;
@@ -177,8 +90,12 @@ #ifdef CONFIG_32BIT
 	}
 #endif
 
+	pgprot = __pgprot(_PAGE_PRESENT | _PAGE_RW |
+			  _PAGE_DIRTY | _PAGE_ACCESSED |
+			  _PAGE_HW_SHARED | _PAGE_FLAGS_HARD | flags);
+
 	if (likely(size))
-		if (remap_area_pages(addr, phys_addr, size, flags)) {
+		if (ioremap_page_range(addr, addr + size, phys_addr, pgprot)) {
 			vunmap((void *)orig_addr);
 			return NULL;
 		}
Signature · 1 line
1.4.0
#1 lore raw

PATCH 1/13 Generic ioremap_page_range: implementation

In reply to Haavard Skinnemoen

This patch adds a generic implementation of ioremap_page_range() in lib/ioremap.c based on the i386 implementation. It differs from the i386 version in the following ways:

* The PTE flags are passed as a pgprot_t argument and must be determined up front by the arch-specific code. No additional PTE flags are added.
* Uses set_pte_at() instead of set_pte()
* Doesn't call flush_cache_all() and flush_tlb_all(). Instead, it calls flush_cache_vmap() after all PTEs have been set up.

---
 include/linux/io.h |    4 ++
 lib/Makefile       |    2 +
 lib/ioremap.c      |   91 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 96 insertions(+), 1 deletions(-)
include/linux/io.h +4 -0
index 420e2fd..aa3f5af 100644
@@ -19,8 +19,12 @@ #ifndef _LINUX_IO_H
 #define _LINUX_IO_H
 
 #include <asm/io.h>
+#include <asm/page.h>
 
 void __iowrite32_copy(void __iomem *to, const void *from, size_t count);
 void __iowrite64_copy(void __iomem *to, const void *from, size_t count);
 
+int ioremap_page_range(unsigned long addr, unsigned long end,
+		       unsigned long phys_addr, pgprot_t prot);
+
 #endif /* _LINUX_IO_H */
lib/Makefile +1 -1
index be9719a..a4dcb07 100644
@@ -5,7 +5,7 @@ #
 lib-y := errno.o ctype.o string.o vsprintf.o cmdline.o \
 	 bust_spinlocks.o rbtree.o radix-tree.o dump_stack.o \
 	 idr.o div64.o int_sqrt.o bitmap.o extable.o prio_tree.o \
-	 sha1.o
+	 sha1.o ioremap.o
 
 lib-$(CONFIG_SMP) += cpumask.o
 
lib/ioremap.c new file +91 -0

91 lines not on this page · raw message

Signature · 1 line
1.4.0
#2 lore raw

PATCH 2/13 Generic ioremap_page_range: alpha conversion

Convert Alpha to use generic ioremap_page_range() by turning __alpha_remap_area_pages() into an inline wrapper around ioremap_page_range().

---
 arch/alpha/kernel/proto.h |   15 ++++++--
 arch/alpha/mm/Makefile    |    2 +
 arch/alpha/mm/remap.c     |   86 ---------------------------------------------
 3 files changed, 13 insertions(+), 90 deletions(-)
arch/alpha/kernel/proto.h +12 -3
index 2a6e3da..21f7128 100644
@@ -1,5 +1,7 @@
 #include <linux/interrupt.h>
+#include <linux/io.h>
 
+#include <asm/pgtable.h>
 
 /* Prototypes of functions used across modules here in this directory.  */
 
@@ -181,9 +183,16 @@ extern void titan_dispatch_irqs(u64, str
 extern void switch_to_system_map(void);
 extern void srm_paging_stop(void);
 
-/* ../mm/remap.c */
-extern int __alpha_remap_area_pages(unsigned long, unsigned long, 
-				    unsigned long, unsigned long);
+static inline int
+__alpha_remap_area_pages(unsigned long address, unsigned long phys_addr,
+			 unsigned long size, unsigned long flags)
+{
+	pgprot_t prot;
+
+	prot = __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE
+			| _PAGE_KWE | flags);
+	return ioremap_page_range(address, address + size, phys_addr, prot);
+}
 
 /* irq.c */
 
arch/alpha/mm/Makefile +1 -1
index 6edd9a0..09399c5 100644
@@ -4,6 +4,6 @@ #
 
 EXTRA_CFLAGS := -Werror
 
-obj-y	:= init.o fault.o extable.o remap.o
+obj-y	:= init.o fault.o extable.o
 
 obj-$(CONFIG_DISCONTIGMEM) += numa.o
arch/alpha/mm/remap.c deleted +0 -86

86 lines not on this page · raw message

Signature · 1 line
1.4.0
#4 lore raw

PATCH 4/13 Generic ioremap_page_range: avr32 conversion

In reply to Haavard Skinnemoen

Convert AVR32 to use generic ioremap_page_range()

---
 arch/avr32/mm/ioremap.c |  120 ++---------------------------------------------
 1 files changed, 6 insertions(+), 114 deletions(-)
arch/avr32/mm/ioremap.c +6 -114
index 5360218..8cfec65 100644
@@ -7,119 +7,11 @@
  */
 #include <linux/vmalloc.h>
 #include <linux/module.h>
+#include <linux/io.h>
 
-#include <asm/io.h>
 #include <asm/pgtable.h>
-#include <asm/cacheflush.h>
-#include <asm/tlbflush.h>
 #include <asm/addrspace.h>
 
-static inline int remap_area_pte(pte_t *pte, unsigned long address,
-				  unsigned long end, unsigned long phys_addr,
-				  pgprot_t prot)
-{
-	unsigned long pfn;
-
-	pfn = phys_addr >> PAGE_SHIFT;
-	do {
-		WARN_ON(!pte_none(*pte));
-
-		set_pte(pte, pfn_pte(pfn, prot));
-		address += PAGE_SIZE;
-		pfn++;
-		pte++;
-	} while (address && (address < end));
-
-	return 0;
-}
-
-static inline int remap_area_pmd(pmd_t *pmd, unsigned long address,
-				 unsigned long end, unsigned long phys_addr,
-				 pgprot_t prot)
-{
-	unsigned long next;
-
-	phys_addr -= address;
-
-	do {
-		pte_t *pte = pte_alloc_kernel(pmd, address);
-		if (!pte)
-			return -ENOMEM;
-
-		next = (address + PMD_SIZE) & PMD_MASK;
-		if (remap_area_pte(pte, address, next,
-				   address + phys_addr, prot))
-			return -ENOMEM;
-
-		address = next;
-		pmd++;
-	} while (address && (address < end));
-	return 0;
-}
-
-static int remap_area_pud(pud_t *pud, unsigned long address,
-			  unsigned long end, unsigned long phys_addr,
-			  pgprot_t prot)
-{
-	unsigned long next;
-
-	phys_addr -= address;
-
-	do {
-		pmd_t *pmd = pmd_alloc(&init_mm, pud, address);
-		if (!pmd)
-			return -ENOMEM;
-		next = (address + PUD_SIZE) & PUD_MASK;
-		if (remap_area_pmd(pmd, address, next,
-				   phys_addr + address, prot))
-			return -ENOMEM;
-
-		address = next;
-		pud++;
-	} while (address && address < end);
-
-	return 0;
-}
-
-static int remap_area_pages(unsigned long address, unsigned long phys_addr,
-			    size_t size, pgprot_t prot)
-{
-	unsigned long end = address + size;
-	unsigned long next;
-	pgd_t *pgd;
-	int err = 0;
-
-	phys_addr -= address;
-
-	pgd = pgd_offset_k(address);
-	flush_cache_all();
-	BUG_ON(address >= end);
-
-	spin_lock(&init_mm.page_table_lock);
-	do {
-		pud_t *pud = pud_alloc(&init_mm, pgd, address);
-
-		err = -ENOMEM;
-		if (!pud)
-			break;
-
-		next = (address + PGDIR_SIZE) & PGDIR_MASK;
-		if (next < address || next > end)
-			next = end;
-		err = remap_area_pud(pud, address, next,
-				     phys_addr + address, prot);
-		if (err)
-			break;
-
-		address = next;
-		pgd++;
-	} while (address && (address < end));
-
-	spin_unlock(&init_mm.page_table_lock);
-	flush_tlb_all();
-	return err;
-}
-
 /*
  * Re-map an arbitrary physical address space into the kernel virtual
  * address space. Needed when the kernel wants to access physical
@@ -128,7 +20,7 @@ static int remap_area_pages(unsigned lon
 void __iomem *__ioremap(unsigned long phys_addr, size_t size,
 			unsigned long flags)
 {
-	void *addr;
+	unsigned long addr;
 	struct vm_struct *area;
 	unsigned long offset, last_addr;
 	pgprot_t prot;
@@ -159,7 +51,7 @@ void __iomem *__ioremap(unsigned long ph
 	phys_addr &= PAGE_MASK;
 	size = PAGE_ALIGN(last_addr + 1) - phys_addr;
 
-	prot = __pgprot(_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY
+	prot = __pgprot(_PAGE_PRESENT | _PAGE_GLOBAL | _PAGE_RW | _PAGE_DIRTY
 			| _PAGE_ACCESSED | _PAGE_TYPE_SMALL | flags);
 
 	/*
@@ -169,9 +61,9 @@ void __iomem *__ioremap(unsigned long ph
 	if (!area)
 		return NULL;
 	area->phys_addr = phys_addr;
-	addr = area->addr;
-	if (remap_area_pages((unsigned long)addr, phys_addr, size, prot)) {
-		vunmap(addr);
+	addr = (unsigned long )area->addr;
+	if (ioremap_page_range(addr, addr + size, phys_addr, prot)) {
+		vunmap((void *)addr);
 		return NULL;
 	}
 
Signature · 1 line
1.4.0
#5 lore raw

PATCH 5/13 Generic ioremap_page_range: cris conversion

Convert CRIS to use generic ioremap_page_range()

---
 arch/cris/mm/ioremap.c |   88 ++----------------------------------------------
 1 files changed, 3 insertions(+), 85 deletions(-)
arch/cris/mm/ioremap.c +3 -85
index 1780df3..8b0b934 100644
@@ -10,93 +10,10 @@
  */
 
 #include <linux/vmalloc.h>
-#include <asm/io.h>
+#include <linux/io.h>
 #include <asm/pgalloc.h>
-#include <asm/cacheflush.h>
-#include <asm/tlbflush.h>
 #include <asm/arch/memmap.h>
 
-static inline void remap_area_pte(pte_t * pte, unsigned long address, unsigned long size,
-	unsigned long phys_addr, pgprot_t prot)
-{
-	unsigned long end;
-
-	address &= ~PMD_MASK;
-	end = address + size;
-	if (end > PMD_SIZE)
-		end = PMD_SIZE;
-	if (address >= end)
-		BUG();
-	do {
-		if (!pte_none(*pte)) {
-			printk("remap_area_pte: page already exists\n");
-			BUG();
-		}
-		set_pte(pte, mk_pte_phys(phys_addr, prot));
-		address += PAGE_SIZE;
-		phys_addr += PAGE_SIZE;
-		pte++;
-	} while (address && (address < end));
-}
-
-static inline int remap_area_pmd(pmd_t * pmd, unsigned long address, unsigned long size,
-	unsigned long phys_addr, pgprot_t prot)
-{
-	unsigned long end;
-
-	address &= ~PGDIR_MASK;
-	end = address + size;
-	if (end > PGDIR_SIZE)
-		end = PGDIR_SIZE;
-	phys_addr -= address;
-	if (address >= end)
-		BUG();
-	do {
-		pte_t * pte = pte_alloc_kernel(pmd, address);
-		if (!pte)
-			return -ENOMEM;
-		remap_area_pte(pte, address, end - address, address + phys_addr, prot);
-		address = (address + PMD_SIZE) & PMD_MASK;
-		pmd++;
-	} while (address && (address < end));
-	return 0;
-}
-
-static int remap_area_pages(unsigned long address, unsigned long phys_addr,
-				 unsigned long size, pgprot_t prot)
-{
-	int error;
-	pgd_t * dir;
-	unsigned long end = address + size;
-
-	phys_addr -= address;
-	dir = pgd_offset(&init_mm, address);
-	flush_cache_all();
-	if (address >= end)
-		BUG();
-	do {
-		pud_t *pud;
-		pmd_t *pmd;
-
-		error = -ENOMEM;
-		pud = pud_alloc(&init_mm, dir, address);
-		if (!pud)
-			break;
-		pmd = pmd_alloc(&init_mm, pud, address);
-
-		if (!pmd)
-			break;
-		if (remap_area_pmd(pmd, address, end - address,
-				   phys_addr + address, prot))
-			break;
-		error = 0;
-		address = (address + PGDIR_SIZE) & PGDIR_MASK;
-		dir++;
-	} while (address && (address < end));
-	flush_tlb_all();
-	return error;
-}
-
 /*
  * Generic mapping function (not visible outside):
  */
@@ -135,7 +52,8 @@ void __iomem * __ioremap_prot(unsigned l
 	if (!area)
 		return NULL;
 	addr = (void __iomem *)area->addr;
-	if (remap_area_pages((unsigned long) addr, phys_addr, size, prot)) {
+	if (ioremap_page_range((unsigned long)addr, (unsigned long)addr + size,
+			       phys_addr, prot)) {
 		vfree((void __force *)addr);
 		return NULL;
 	}
Signature · 1 line
1.4.0
#7 lore raw

PATCH 7/13 Generic ioremap_page_range: m32r conversion

In reply to Haavard Skinnemoen

Convert m32r to use generic ioremap_page_range()

---
 arch/m32r/mm/ioremap.c |   93 ++++--------------------------------------------
 1 files changed, 7 insertions(+), 86 deletions(-)
arch/m32r/mm/ioremap.c +7 -86
index a151849..5152c4e 100644
@@ -20,92 +20,8 @@ #include <asm/addrspace.h>
 #include <asm/byteorder.h>
 
 #include <linux/vmalloc.h>
-#include <asm/io.h>
+#include <linux/io.h>
 #include <asm/pgalloc.h>
-#include <asm/cacheflush.h>
-#include <asm/tlbflush.h>
-
-static inline void
-remap_area_pte(pte_t * pte, unsigned long address, unsigned long size,
-	       unsigned long phys_addr, unsigned long flags)
-{
-	unsigned long end;
-	unsigned long pfn;
-	pgprot_t pgprot = __pgprot(_PAGE_GLOBAL | _PAGE_PRESENT | _PAGE_READ
-	                           | _PAGE_WRITE | flags);
-
-	address &= ~PMD_MASK;
-	end = address + size;
-	if (end > PMD_SIZE)
-		end = PMD_SIZE;
-	if (address >= end)
-		BUG();
-	pfn = phys_addr >> PAGE_SHIFT;
-	do {
-		if (!pte_none(*pte)) {
-			printk("remap_area_pte: page already exists\n");
-			BUG();
-		}
-		set_pte(pte, pfn_pte(pfn, pgprot));
-		address += PAGE_SIZE;
-		pfn++;
-		pte++;
-	} while (address && (address < end));
-}
-
-static inline int
-remap_area_pmd(pmd_t * pmd, unsigned long address, unsigned long size,
-	       unsigned long phys_addr, unsigned long flags)
-{
-	unsigned long end;
-
-	address &= ~PGDIR_MASK;
-	end = address + size;
-	if (end > PGDIR_SIZE)
-		end = PGDIR_SIZE;
-	phys_addr -= address;
-	if (address >= end)
-		BUG();
-	do {
-		pte_t * pte = pte_alloc_kernel(pmd, address);
-		if (!pte)
-			return -ENOMEM;
-		remap_area_pte(pte, address, end - address, address + phys_addr, flags);
-		address = (address + PMD_SIZE) & PMD_MASK;
-		pmd++;
-	} while (address && (address < end));
-	return 0;
-}
-
-static int
-remap_area_pages(unsigned long address, unsigned long phys_addr,
-		 unsigned long size, unsigned long flags)
-{
-	int error;
-	pgd_t * dir;
-	unsigned long end = address + size;
-
-	phys_addr -= address;
-	dir = pgd_offset(&init_mm, address);
-	flush_cache_all();
-	if (address >= end)
-		BUG();
-	do {
-		pmd_t *pmd;
-		pmd = pmd_alloc(&init_mm, dir, address);
-		error = -ENOMEM;
-		if (!pmd)
-			break;
-		if (remap_area_pmd(pmd, address, end - address,
-					 phys_addr + address, flags))
-			break;
-		error = 0;
-		address = (address + PGDIR_SIZE) & PGDIR_MASK;
-		dir++;
-	} while (address && (address < end));
-	flush_tlb_all();
-	return error;
-}
 
 /*
  * Generic mapping function (not visible outside):
@@ -129,6 +45,7 @@ __ioremap(unsigned long phys_addr, unsig
 	void __iomem * addr;
 	struct vm_struct * area;
 	unsigned long offset, last_addr;
+	pgprot_t pgprot;
 
 	/* Don't allow wraparound or zero size */
 	last_addr = phys_addr + size - 1;
@@ -157,6 +74,9 @@ __ioremap(unsigned long phys_addr, unsig
 				return NULL;
 	}
 
+	pgprot = __pgprot(_PAGE_GLOBAL | _PAGE_PRESENT | _PAGE_READ
+			  | _PAGE_WRITE | flags);
+
 	/*
 	 * Mappings have to be page-aligned
 	 */
@@ -172,7 +92,8 @@ __ioremap(unsigned long phys_addr, unsig
 		return NULL;
 	area->phys_addr = phys_addr;
 	addr = (void __iomem *) area->addr;
-	if (remap_area_pages((unsigned long)addr, phys_addr, size, flags)) {
+	if (ioremap_page_range((unsigned long)addr, (unsigned long)addr + size,
+			       phys_addr, pgprot)) {
 		vunmap((void __force *) addr);
 		return NULL;
 	}
Signature · 1 line
1.4.0
#8 lore raw

PATCH 8/13 Generic ioremap_page_range: mips conversion

Convert MIPS to use generic ioremap_page_range()

---
 arch/mips/mm/ioremap.c |   95 ++++--------------------------------------------
 1 files changed, 7 insertions(+), 88 deletions(-)
arch/mips/mm/ioremap.c +7 -88
index 3101d1d..cac79ae 100644
@@ -11,93 +11,7 @@ #include <asm/addrspace.h>
 #include <asm/byteorder.h>
 
 #include <linux/vmalloc.h>
-#include <asm/cacheflush.h>
-#include <asm/io.h>
-#include <asm/tlbflush.h>
-
-static inline void remap_area_pte(pte_t * pte, unsigned long address,
-	phys_t size, phys_t phys_addr, unsigned long flags)
-{
-	phys_t end;
-	unsigned long pfn;
-	pgprot_t pgprot = __pgprot(_PAGE_GLOBAL | _PAGE_PRESENT | __READABLE
-	                           | __WRITEABLE | flags);
-
-	address &= ~PMD_MASK;
-	end = address + size;
-	if (end > PMD_SIZE)
-		end = PMD_SIZE;
-	if (address >= end)
-		BUG();
-	pfn = phys_addr >> PAGE_SHIFT;
-	do {
-		if (!pte_none(*pte)) {
-			printk("remap_area_pte: page already exists\n");
-			BUG();
-		}
-		set_pte(pte, pfn_pte(pfn, pgprot));
-		address += PAGE_SIZE;
-		pfn++;
-		pte++;
-	} while (address && (address < end));
-}
-
-static inline int remap_area_pmd(pmd_t * pmd, unsigned long address,
-	phys_t size, phys_t phys_addr, unsigned long flags)
-{
-	phys_t end;
-
-	address &= ~PGDIR_MASK;
-	end = address + size;
-	if (end > PGDIR_SIZE)
-		end = PGDIR_SIZE;
-	phys_addr -= address;
-	if (address >= end)
-		BUG();
-	do {
-		pte_t * pte = pte_alloc_kernel(pmd, address);
-		if (!pte)
-			return -ENOMEM;
-		remap_area_pte(pte, address, end - address, address + phys_addr, flags);
-		address = (address + PMD_SIZE) & PMD_MASK;
-		pmd++;
-	} while (address && (address < end));
-	return 0;
-}
-
-static int remap_area_pages(unsigned long address, phys_t phys_addr,
-	phys_t size, unsigned long flags)
-{
-	int error;
-	pgd_t * dir;
-	unsigned long end = address + size;
-
-	phys_addr -= address;
-	dir = pgd_offset(&init_mm, address);
-	flush_cache_all();
-	if (address >= end)
-		BUG();
-	do {
-		pud_t *pud;
-		pmd_t *pmd;
-
-		error = -ENOMEM;
-		pud = pud_alloc(&init_mm, dir, address);
-		if (!pud)
-			break;
-		pmd = pmd_alloc(&init_mm, pud, address);
-		if (!pmd)
-			break;
-		if (remap_area_pmd(pmd, address, end - address,
-					 phys_addr + address, flags))
-			break;
-		error = 0;
-		address = (address + PGDIR_SIZE) & PGDIR_MASK;
-		dir++;
-	} while (address && (address < end));
-	flush_tlb_all();
-	return error;
-}
+#include <linux/io.h>
 
 /*
  * Generic mapping function (not visible outside):
@@ -121,6 +35,7 @@ void __iomem * __ioremap(phys_t phys_add
 	unsigned long offset;
 	phys_t last_addr;
 	void * addr;
+	pgprot_t pgprot;
 
 	phys_addr = fixup_bigphys_addr(phys_addr, size);
 
@@ -152,6 +67,9 @@ void __iomem * __ioremap(phys_t phys_add
 				return NULL;
 	}
 
+	pgprot = __pgprot(_PAGE_GLOBAL | _PAGE_PRESENT | __READABLE
+			  | __WRITEABLE | flags);
+
 	/*
 	 * Mappings have to be page-aligned
 	 */
@@ -166,7 +84,8 @@ void __iomem * __ioremap(phys_t phys_add
 	if (!area)
 		return NULL;
 	addr = area->addr;
-	if (remap_area_pages((unsigned long) addr, phys_addr, size, flags)) {
+	if (ioremap_page_range((unsigned long)addr, (unsigned long)addr + size,
+			       phys_addr, pgprot)) {
 		vunmap(addr);
 		return NULL;
 	}
Signature · 1 line
1.4.0
#9 lore raw

PATCH 9/13 Generic ioremap_page_range: parisc conversion

Convert parisc to use generic ioremap_page_range()

---
 arch/parisc/mm/ioremap.c |  111 +++-------------------------------------------
 1 files changed, 7 insertions(+), 104 deletions(-)
arch/parisc/mm/ioremap.c +7 -104
index 2738456..a31da6c 100644
@@ -9,110 +9,8 @@
 #include <linux/vmalloc.h>
 #include <linux/errno.h>
 #include <linux/module.h>
-#include <asm/io.h>
+#include <linux/io.h>
 #include <asm/pgalloc.h>
-#include <asm/tlbflush.h>
-#include <asm/cacheflush.h>
-
-static inline void 
-remap_area_pte(pte_t *pte, unsigned long address, unsigned long size,
-	       unsigned long phys_addr, unsigned long flags)
-{
-	unsigned long end, pfn;
-	pgprot_t pgprot = __pgprot(_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY |
-				   _PAGE_ACCESSED | flags);
-
-	address &= ~PMD_MASK;
-
-	end = address + size;
-	if (end > PMD_SIZE)
-		end = PMD_SIZE;
-
-	BUG_ON(address >= end);
-
-	pfn = phys_addr >> PAGE_SHIFT;
-	do {
-		BUG_ON(!pte_none(*pte));
-
-		set_pte(pte, pfn_pte(pfn, pgprot));
-
-		address += PAGE_SIZE;
-		pfn++;
-		pte++;
-	} while (address && (address < end));
-}
-
-static inline int 
-remap_area_pmd(pmd_t *pmd, unsigned long address, unsigned long size,
-	       unsigned long phys_addr, unsigned long flags)
-{
-	unsigned long end;
-
-	address &= ~PGDIR_MASK;
-
-	end = address + size;
-	if (end > PGDIR_SIZE)
-		end = PGDIR_SIZE;
-
-	BUG_ON(address >= end);
-
-	phys_addr -= address;
-	do {
-		pte_t *pte = pte_alloc_kernel(pmd, address);
-		if (!pte)
-			return -ENOMEM;
-
-		remap_area_pte(pte, address, end - address, 
-			       address + phys_addr, flags);
-
-		address = (address + PMD_SIZE) & PMD_MASK;
-		pmd++;
-	} while (address && (address < end));
-
-	return 0;
-}
-
-static int 
-remap_area_pages(unsigned long address, unsigned long phys_addr,
-		 unsigned long size, unsigned long flags)
-{
-	pgd_t *dir;
-	int error = 0;
-	unsigned long end = address + size;
-
-	BUG_ON(address >= end);
-
-	phys_addr -= address;
-	dir = pgd_offset_k(address);
-
-	flush_cache_all();
-
-	do {
-		pud_t *pud;
-		pmd_t *pmd;
-
-		error = -ENOMEM;
-		pud = pud_alloc(&init_mm, dir, address);
-		if (!pud)
-			break;
-
-		pmd = pmd_alloc(&init_mm, pud, address);
-		if (!pmd)
-			break;
-
-		if (remap_area_pmd(pmd, address, end - address,
-				   phys_addr + address, flags))
-			break;
-
-		error = 0;
-		address = (address + PGDIR_SIZE) & PGDIR_MASK;
-		dir++;
-	} while (address && (address < end));
-
-	flush_tlb_all();
-
-	return error;
-}
 
 /*
  * Generic mapping function (not visible outside):
@@ -131,6 +29,7 @@ void __iomem * __ioremap(unsigned long p
 	void *addr;
 	struct vm_struct *area;
 	unsigned long offset, last_addr;
+	pgprot_t pgprot;
 
 #ifdef CONFIG_EISA
 	unsigned long end = phys_addr + size - 1;
@@ -164,6 +63,9 @@ #endif
 		}
 	}
 
+	pgprot = __pgprot(_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY |
+			  _PAGE_ACCESSED | flags);
+
 	/*
 	 * Mappings have to be page-aligned
 	 */
@@ -179,7 +81,8 @@ #endif
 		return NULL;
 
 	addr = area->addr;
-	if (remap_area_pages((unsigned long) addr, phys_addr, size, flags)) {
+	if (ioremap_page_range((unsigned long)addr, (unsigned long)addr + size,
+			       phys_addr, pgprot)) {
 		vfree(addr);
 		return NULL;
 	}
Signature · 1 line
1.4.0
#13 lore raw

PATCH 13/13 Generic ioremap_page_range: x86_64 conversion

In reply to Haavard Skinnemoen

Convert x86_64 to use generic ioremap_page_range()

---
 arch/x86_64/mm/ioremap.c |  110 +++-------------------------------------------
 1 files changed, 6 insertions(+), 104 deletions(-)
arch/x86_64/mm/ioremap.c +6 -104
index 45d7d82..6bb0712 100644
@@ -12,117 +12,15 @@ #include <linux/vmalloc.h>
 #include <linux/init.h>
 #include <linux/slab.h>
 #include <linux/module.h>
-#include <asm/io.h>
+#include <linux/io.h>
 #include <asm/pgalloc.h>
 #include <asm/fixmap.h>
-#include <asm/cacheflush.h>
 #include <asm/tlbflush.h>
 #include <asm/proto.h>
 
 #define ISA_START_ADDRESS      0xa0000
 #define ISA_END_ADDRESS                0x100000
 
-static inline void remap_area_pte(pte_t * pte, unsigned long address, unsigned long size,
-	unsigned long phys_addr, unsigned long flags)
-{
-	unsigned long end;
-	unsigned long pfn;
-
-	address &= ~PMD_MASK;
-	end = address + size;
-	if (end > PMD_SIZE)
-		end = PMD_SIZE;
-	if (address >= end)
-		BUG();
-	pfn = phys_addr >> PAGE_SHIFT;
-	do {
-		if (!pte_none(*pte)) {
-			printk("remap_area_pte: page already exists\n");
-			BUG();
-		}
-		set_pte(pte, pfn_pte(pfn, __pgprot(_PAGE_PRESENT | _PAGE_RW | 
-					_PAGE_GLOBAL | _PAGE_DIRTY | _PAGE_ACCESSED | flags)));
-		address += PAGE_SIZE;
-		pfn++;
-		pte++;
-	} while (address && (address < end));
-}
-
-static inline int remap_area_pmd(pmd_t * pmd, unsigned long address, unsigned long size,
-	unsigned long phys_addr, unsigned long flags)
-{
-	unsigned long end;
-
-	address &= ~PUD_MASK;
-	end = address + size;
-	if (end > PUD_SIZE)
-		end = PUD_SIZE;
-	phys_addr -= address;
-	if (address >= end)
-		BUG();
-	do {
-		pte_t * pte = pte_alloc_kernel(pmd, address);
-		if (!pte)
-			return -ENOMEM;
-		remap_area_pte(pte, address, end - address, address + phys_addr, flags);
-		address = (address + PMD_SIZE) & PMD_MASK;
-		pmd++;
-	} while (address && (address < end));
-	return 0;
-}
-
-static inline int remap_area_pud(pud_t * pud, unsigned long address, unsigned long size,
-	unsigned long phys_addr, unsigned long flags)
-{
-	unsigned long end;
-
-	address &= ~PGDIR_MASK;
-	end = address + size;
-	if (end > PGDIR_SIZE)
-		end = PGDIR_SIZE;
-	phys_addr -= address;
-	if (address >= end)
-		BUG();
-	do {
-		pmd_t * pmd = pmd_alloc(&init_mm, pud, address);
-		if (!pmd)
-			return -ENOMEM;
-		remap_area_pmd(pmd, address, end - address, address + phys_addr, flags);
-		address = (address + PUD_SIZE) & PUD_MASK;
-		pud++;
-	} while (address && (address < end));
-	return 0;
-}
-
-static int remap_area_pages(unsigned long address, unsigned long phys_addr,
-				 unsigned long size, unsigned long flags)
-{
-	int error;
-	pgd_t *pgd;
-	unsigned long end = address + size;
-
-	phys_addr -= address;
-	pgd = pgd_offset_k(address);
-	flush_cache_all();
-	if (address >= end)
-		BUG();
-	do {
-		pud_t *pud;
-		pud = pud_alloc(&init_mm, pgd, address);
-		error = -ENOMEM;
-		if (!pud)
-			break;
-		if (remap_area_pud(pud, address, end - address,
-					 phys_addr + address, flags))
-			break;
-		error = 0;
-		address = (address + PGDIR_SIZE) & PGDIR_MASK;
-		pgd++;
-	} while (address && (address < end));
-	flush_tlb_all();
-	return error;
-}
-
 /*
  * Fix up the linear direct mapping of the kernel to avoid cache attribute
  * conflicts.
@@ -165,6 +63,7 @@ void __iomem * __ioremap(unsigned long p
 	void * addr;
 	struct vm_struct * area;
 	unsigned long offset, last_addr;
+	pgprot_t pgprot;
 
 	/* Don't allow wraparound or zero size */
 	last_addr = phys_addr + size - 1;
@@ -194,6 +93,8 @@ #ifdef CONFIG_FLATMEM
 	}
 #endif
 
+	pgprot = __pgprot(_PAGE_PRESENT | _PAGE_RW | _PAGE_GLOBAL
+			  | _PAGE_DIRTY | _PAGE_ACCESSED | flags);
 	/*
 	 * Mappings have to be page-aligned
 	 */
@@ -209,7 +110,8 @@ #endif
 		return NULL;
 	area->phys_addr = phys_addr;
 	addr = area->addr;
-	if (remap_area_pages((unsigned long) addr, phys_addr, size, flags)) {
+	if (ioremap_page_range((unsigned long)addr, (unsigned long)addr + size,
+			       phys_addr, pgprot)) {
 		remove_vm_area((void *)(PAGE_MASK & (unsigned long) addr));
 		return NULL;
 	}
Signature · 1 line
1.4.0
#6 lore raw

PATCH 6/13 Generic ioremap_page_range: i386 conversion

In reply to Haavard Skinnemoen

Convert i386 to use generic ioremap_page_range()

---
 arch/i386/mm/ioremap.c |   85 +++---------------------------------------------
 1 files changed, 6 insertions(+), 79 deletions(-)
arch/i386/mm/ioremap.c +6 -79
index 247fde7..f773126 100644
@@ -12,91 +12,14 @@ #include <linux/vmalloc.h>
 #include <linux/init.h>
 #include <linux/slab.h>
 #include <linux/module.h>
-#include <asm/io.h>
+#include <linux/io.h>
 #include <asm/fixmap.h>
-#include <asm/cacheflush.h>
 #include <asm/tlbflush.h>
 #include <asm/pgtable.h>
 
 #define ISA_START_ADDRESS	0xa0000
 #define ISA_END_ADDRESS		0x100000
 
-static int ioremap_pte_range(pmd_t *pmd, unsigned long addr,
-		unsigned long end, unsigned long phys_addr, unsigned long flags)
-{
-	pte_t *pte;
-	unsigned long pfn;
-
-	pfn = phys_addr >> PAGE_SHIFT;
-	pte = pte_alloc_kernel(pmd, addr);
-	if (!pte)
-		return -ENOMEM;
-	do {
-		BUG_ON(!pte_none(*pte));
-		set_pte(pte, pfn_pte(pfn, __pgprot(_PAGE_PRESENT | _PAGE_RW | 
-					_PAGE_DIRTY | _PAGE_ACCESSED | flags)));
-		pfn++;
-	} while (pte++, addr += PAGE_SIZE, addr != end);
-	return 0;
-}
-
-static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
-		unsigned long end, unsigned long phys_addr, unsigned long flags)
-{
-	pmd_t *pmd;
-	unsigned long next;
-
-	phys_addr -= addr;
-	pmd = pmd_alloc(&init_mm, pud, addr);
-	if (!pmd)
-		return -ENOMEM;
-	do {
-		next = pmd_addr_end(addr, end);
-		if (ioremap_pte_range(pmd, addr, next, phys_addr + addr, flags))
-			return -ENOMEM;
-	} while (pmd++, addr = next, addr != end);
-	return 0;
-}
-
-static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
-		unsigned long end, unsigned long phys_addr, unsigned long flags)
-{
-	pud_t *pud;
-	unsigned long next;
-
-	phys_addr -= addr;
-	pud = pud_alloc(&init_mm, pgd, addr);
-	if (!pud)
-		return -ENOMEM;
-	do {
-		next = pud_addr_end(addr, end);
-		if (ioremap_pmd_range(pud, addr, next, phys_addr + addr, flags))
-			return -ENOMEM;
-	} while (pud++, addr = next, addr != end);
-	return 0;
-}
-
-static int ioremap_page_range(unsigned long addr,
-		unsigned long end, unsigned long phys_addr, unsigned long flags)
-{
-	pgd_t *pgd;
-	unsigned long next;
-	int err;
-
-	BUG_ON(addr >= end);
-	flush_cache_all();
-	phys_addr -= addr;
-	pgd = pgd_offset_k(addr);
-	do {
-		next = pgd_addr_end(addr, end);
-		err = ioremap_pud_range(pgd, addr, next, phys_addr+addr, flags);
-		if (err)
-			break;
-	} while (pgd++, addr = next, addr != end);
-	flush_tlb_all();
-	return err;
-}
-
 /*
  * Generic mapping function (not visible outside):
  */
@@ -115,6 +38,7 @@ void __iomem * __ioremap(unsigned long p
 	void __iomem * addr;
 	struct vm_struct * area;
 	unsigned long offset, last_addr;
+	pgprot_t prot;
 
 	/* Don't allow wraparound or zero size */
 	last_addr = phys_addr + size - 1;
@@ -142,6 +66,9 @@ void __iomem * __ioremap(unsigned long p
 				return NULL;
 	}
 
+	prot = __pgprot(_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY
+			| _PAGE_ACCESSED | flags);
+
 	/*
 	 * Mappings have to be page-aligned
 	 */
@@ -158,7 +85,7 @@ void __iomem * __ioremap(unsigned long p
 	area->phys_addr = phys_addr;
 	addr = (void __iomem *) area->addr;
 	if (ioremap_page_range((unsigned long) addr,
-			(unsigned long) addr + size, phys_addr, flags)) {
+			(unsigned long) addr + size, phys_addr, prot)) {
 		vunmap((void __force *) addr);
 		return NULL;
 	}
Signature · 1 line
1.4.0
#12 lore raw

PATCH 12/13 Generic ioremap_page_range: sh64 conversion

In reply to Haavard Skinnemoen

Convert SH64 to use generic ioremap_page_range()

---
 arch/sh64/mm/ioremap.c |  100 ++++--------------------------------------------
 1 files changed, 8 insertions(+), 92 deletions(-)
arch/sh64/mm/ioremap.c +8 -92
index fb1866f..e77d85f 100644
@@ -18,7 +18,7 @@ #include <linux/slab.h>
 #include <linux/vmalloc.h>
 #include <linux/sched.h>
 #include <linux/string.h>
-#include <asm/io.h>
+#include <linux/io.h>
 #include <asm/pgalloc.h>
 #include <asm/tlbflush.h>
 #include <linux/ioport.h>
@@ -28,96 +28,6 @@ #include <linux/proc_fs.h>
 static void shmedia_mapioaddr(unsigned long, unsigned long);
 static unsigned long shmedia_ioremap(struct resource *, u32, int);
 
-static inline void remap_area_pte(pte_t * pte, unsigned long address, unsigned long size,
-	unsigned long phys_addr, unsigned long flags)
-{
-	unsigned long end;
-	unsigned long pfn;
-	pgprot_t pgprot = __pgprot(_PAGE_PRESENT  | _PAGE_READ   |
-				   _PAGE_WRITE    | _PAGE_DIRTY  |
-				   _PAGE_ACCESSED | _PAGE_SHARED | flags);
-
-	address &= ~PMD_MASK;
-	end = address + size;
-	if (end > PMD_SIZE)
-		end = PMD_SIZE;
-	if (address >= end)
-		BUG();
-
-	pfn = phys_addr >> PAGE_SHIFT;
-
-	pr_debug("    %s: pte %p address %lx size %lx phys_addr %lx\n",
-		 __FUNCTION__,pte,address,size,phys_addr);
-
-	do {
-		if (!pte_none(*pte)) {
-			printk("remap_area_pte: page already exists\n");
-			BUG();
-		}
-
-		set_pte(pte, pfn_pte(pfn, pgprot));
-		address += PAGE_SIZE;
-		pfn++;
-		pte++;
-	} while (address && (address < end));
-}
-
-static inline int remap_area_pmd(pmd_t * pmd, unsigned long address, unsigned long size,
-	unsigned long phys_addr, unsigned long flags)
-{
-	unsigned long end;
-
-	address &= ~PGDIR_MASK;
-	end = address + size;
-
-	if (end > PGDIR_SIZE)
-		end = PGDIR_SIZE;
-
-	phys_addr -= address;
-
-	if (address >= end)
-		BUG();
-
-	do {
-		pte_t * pte = pte_alloc_kernel(pmd, address);
-		if (!pte)
-			return -ENOMEM;
-		remap_area_pte(pte, address, end - address, address + phys_addr, flags);
-		address = (address + PMD_SIZE) & PMD_MASK;
-		pmd++;
-	} while (address && (address < end));
-	return 0;
-}
-
-static int remap_area_pages(unsigned long address, unsigned long phys_addr,
-				 unsigned long size, unsigned long flags)
-{
-	int error;
-	pgd_t * dir;
-	unsigned long end = address + size;
-
-	phys_addr -= address;
-	dir = pgd_offset_k(address);
-	flush_cache_all();
-	if (address >= end)
-		BUG();
-	do {
-		pmd_t *pmd = pmd_alloc(&init_mm, dir, address);
-		error = -ENOMEM;
-		if (!pmd)
-			break;
-		if (remap_area_pmd(pmd, address, end - address,
-				   phys_addr + address, flags)) {
-			 break;
-		}
-		error = 0;
-		address = (address + PGDIR_SIZE) & PGDIR_MASK;
-		dir++;
-	} while (address && (address < end));
-	flush_tlb_all();
-	return 0;
-}
-
 /*
  * Generic mapping function (not visible outside):
  */
@@ -136,12 +46,17 @@ void * __ioremap(unsigned long phys_addr
 	void * addr;
 	struct vm_struct * area;
 	unsigned long offset, last_addr;
+	pgprot_t pgprot;
 
 	/* Don't allow wraparound or zero size */
 	last_addr = phys_addr + size - 1;
 	if (!size || last_addr < phys_addr)
 		return NULL;
 
+	pgprot = __pgprot(_PAGE_PRESENT  | _PAGE_READ   |
+			  _PAGE_WRITE    | _PAGE_DIRTY  |
+			  _PAGE_ACCESSED | _PAGE_SHARED | flags);
+
 	/*
 	 * Mappings have to be page-aligned
 	 */
@@ -158,7 +73,8 @@ void * __ioremap(unsigned long phys_addr
 		return NULL;
 	area->phys_addr = phys_addr;
 	addr = area->addr;
-	if (remap_area_pages((unsigned long)addr, phys_addr, size, flags)) {
+	if (ioremap_page_range((unsigned long)addr, (unsigned long)addr + size,
+			       phys_addr, pgprot)) {
 		vunmap(addr);
 		return NULL;
 	}
Signature · 1 line
1.4.0
#14 lore raw

Re: [PATCH 13/13] Generic ioremap_page_range: x86_64 conversion

In reply to Haavard Skinnemoen
Quoted 1 line · Haavard Skinnemoen

Convert x86_64 to use generic ioremap_page_range()

Ok for me. Also i386.

But linux-arch is normally not for patches, just for discussion. You should send the mails directly to the responsible people, probably cc l-k.

-Andi

#15 lore raw

Re: [PATCH 13/13] Generic ioremap_page_range: x86_64 conversion

Quoted 6 lines · Andi Kleen
Quoted 1 line · Haavard Skinnemoen

Convert x86_64 to use generic ioremap_page_range()

But linux-arch is normally not for patches, just for discussion. You should send the mails directly to the responsible people, probably cc l-k.

Erm, no, please let's continue posting patches like this to this list. For me, it's nice having the important stuff right here, so I don't need to search the archives.

MfG, JBG

Signature · 3 lines
       Jan-Benedict Glaw       [email protected]                +49-172-7608481
 Signature of:                     ...und wenn Du denkst, es geht nicht mehr,
 the second  :                            kommt irgendwo ein Lichtlein her.
#17 lore raw

Re: [PATCH 9/13] Generic ioremap_page_range: parisc conversion

In reply to Haavard Skinnemoen
Quoted 6 lines · Haavard Skinnemoen

Convert parisc to use generic ioremap_page_range()

arch/parisc/mm/ioremap.c +0 -4
-static int 
-remap_area_pages(unsigned long address, unsigned long phys_addr,
-		 unsigned long size, unsigned long flags)
-{

[...]

Quoted 2 lines
(quoted diff) +0 -2
-	flush_cache_all();
-

[..]

arch/parisc/mm/ioremap.c line 112

Quoted 4 lines
arch/parisc/mm/ioremap.c +0 -3
-	} while (address && (address < end));
-
-	flush_tlb_all();

On second thought, you've compressed two different flushes into flush_cache_vmap[1] where flush_tlb_all used to be...

I don't think this would be a problem because we're creating a new mapping, but James will probably prove my assumption wrong as usual. :)

[1 - flush_cache_vmap is just a flush_cache_all on the arches
I've looked at with VI-caches.]

Cheers,
Kyle M.

#18 lore raw

Re: [PATCH 9/13] Generic ioremap_page_range: parisc conversion

Quoted 2 lines · On Tue, 8 Aug 2006 10:48:50 -0400 Kyle McMartin <[email protected]> wrote:

On second thought, you've compressed two different flushes into flush_cache_vmap[1] where flush_tlb_all used to be...

Yes, that's intentional. I did mention this as one of the differences from i386 in the "implementation" part of this series, but I should perhaps have mentioned it explicitly in each of the arch-specific patches as well?

Quoted 3 lines

I don't think this would be a problem because we're creating a new mapping, but James will probably prove my assumption wrong as usual. :)

That's indeed the reasoning behind the change -- ioremap_pte_range() contains BUG_ON(!pte_none(*pte)) so we should never touch existing mappings.

Also, the only difference I can see between ioremap() and vmap() is that ioremap() maps a contiguous range of physical addresses while vmap() maps an array of 'struct page's. So the cache- and tlb-flushing requirements should be the same, right?

Haavard

#19 lore raw

Re: [PATCH 9/13] Generic ioremap_page_range: parisc conversion

In reply to Kyle McMartin
Quoted 9 lines · Kyle McMartin

On second thought, you've compressed two different flushes into flush_cache_vmap[1] where flush_tlb_all used to be...

I don't think this would be a problem because we're creating a new mapping, but James will probably prove my assumption wrong as usual. :)

[1 - flush_cache_vmap is just a flush_cache_all on the arches
I've looked at with VI-caches.]

The problem the flush_tlb_all() is trying to solve is to avoid stale tlb entries in the ioremap area. We're just being conservative by flushing on both map and unmap. Technically what vmalloc/vfree does (only flush the tlb on unmap) is just fine because it means that the only tlb entries in the remap area must belong to in-use mappings.

James

#20 lore raw
In reply to Haavard Skinnemoen

From: Haavard Skinnemoen <[email protected]>
Date: Tue, 08 Aug 2006 14:23:02 +0200

Quoted 1 line

sparc seems to do something completely different than everyone else.

Yes, we map in huge pages when possible.

I really don't expect you to try to abstract
that in your generic routines. :-)