1 /* $Id: generic.c,v 1.18 2001/12/21 04:56:15 davem Exp $
2 * generic.c: Generic Sparc mm routines that are not dependent upon
3 * MMU type but are Sparc specific.
5 * Copyright (C) 1996 David S. Miller (davem@caip.rutgers.edu)
8 #include <linux/kernel.h>
10 #include <linux/swap.h>
11 #include <linux/pagemap.h>
13 #include <asm/pgalloc.h>
14 #include <asm/pgtable.h>
16 #include <asm/tlbflush.h>
18 static inline void forget_pte(pte_t page)
20 if (!pte_none(page)) {
21 printk("forget_pte: old mapping existed!\n");
26 /* Remap IO memory, the same way as remap_page_range(), but use
27 * the obio memory space.
29 * They use a pgprot that sets PAGE_IO and does not check the
30 * mem_map table as this is independent of normal memory.
32 * As a special hack if the lowest bit of offset is set the
33 * side-effect bit will be turned off. This is used as a
34 * performance improvement on FFB/AFB. -DaveM
36 static inline void io_remap_pte_range(pte_t * pte, unsigned long address, unsigned long size,
37 unsigned long offset, pgprot_t prot, int space)
48 unsigned long curend = address + PAGE_SIZE;
50 entry = mk_pte_io((offset & ~(0x1UL)), prot, space);
51 if (!(address & 0xffff)) {
52 if (!(address & 0x3fffff) && !(offset & 0x3ffffe) && end >= address + 0x400000) {
53 entry = mk_pte_io((offset & ~(0x1UL)),
54 __pgprot(pgprot_val (prot) | _PAGE_SZ4MB),
56 curend = address + 0x400000;
58 } else if (!(address & 0x7ffff) && !(offset & 0x7fffe) && end >= address + 0x80000) {
59 entry = mk_pte_io((offset & ~(0x1UL)),
60 __pgprot(pgprot_val (prot) | _PAGE_SZ512K),
62 curend = address + 0x80000;
64 } else if (!(offset & 0xfffe) && end >= address + 0x10000) {
65 entry = mk_pte_io((offset & ~(0x1UL)),
66 __pgprot(pgprot_val (prot) | _PAGE_SZ64K),
68 curend = address + 0x10000;
76 pte_val(entry) &= ~(_PAGE_E);
84 } while (address < curend);
85 } while (address < end);
88 static inline int io_remap_pmd_range(pmd_t * pmd, unsigned long address, unsigned long size,
89 unsigned long offset, pgprot_t prot, int space)
93 address &= ~PGDIR_MASK;
99 pte_t * pte = pte_alloc_map(current->mm, pmd, address);
102 io_remap_pte_range(pte, address, end - address, address + offset, prot, space);
104 address = (address + PMD_SIZE) & PMD_MASK;
106 } while (address < end);
110 int io_remap_page_range(struct vm_area_struct *vma, unsigned long from, unsigned long offset, unsigned long size, pgprot_t prot, int space)
114 unsigned long beg = from;
115 unsigned long end = from + size;
116 struct mm_struct *mm = vma->vm_mm;
118 prot = __pgprot(pg_iobits);
120 dir = pgd_offset(mm, from);
121 flush_cache_range(vma, beg, end);
123 spin_lock(&mm->page_table_lock);
125 pmd_t *pmd = pmd_alloc(current->mm, dir, from);
129 error = io_remap_pmd_range(pmd, from, end - from, offset + from, prot, space);
132 from = (from + PGDIR_SIZE) & PGDIR_MASK;
135 spin_unlock(&mm->page_table_lock);
137 flush_tlb_range(vma, beg, end);