1 /* $Id: generic.c,v 1.17 2001/04/09 04:08:06 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>
17 static inline void forget_pte(pte_t page)
21 if (pte_present(page)) {
22 struct page *ptpage = pte_page(page);
23 if ((!VALID_PAGE(ptpage)) || PageReserved(ptpage))
25 page_cache_release(ptpage);
28 swap_free(pte_to_swp_entry(page));
31 /* Remap IO memory, the same way as remap_page_range(), but use
32 * the obio memory space.
34 * They use a pgprot that sets PAGE_IO and does not check the
35 * mem_map table as this is independent of normal memory.
37 * As a special hack if the lowest bit of offset is set the
38 * side-effect bit will be turned off. This is used as a
39 * performance improvement on FFB/AFB. -DaveM
41 static inline void io_remap_pte_range(pte_t * pte, unsigned long address, unsigned long size,
42 unsigned long offset, pgprot_t prot, int space)
53 unsigned long curend = address + PAGE_SIZE;
55 entry = mk_pte_io((offset & ~(0x1UL)), prot, space);
56 if (!(address & 0xffff)) {
57 if (!(address & 0x3fffff) && !(offset & 0x3ffffe) && end >= address + 0x400000) {
58 entry = mk_pte_io((offset & ~(0x1UL)),
59 __pgprot(pgprot_val (prot) | _PAGE_SZ4MB),
61 curend = address + 0x400000;
63 } else if (!(address & 0x7ffff) && !(offset & 0x7fffe) && end >= address + 0x80000) {
64 entry = mk_pte_io((offset & ~(0x1UL)),
65 __pgprot(pgprot_val (prot) | _PAGE_SZ512K),
67 curend = address + 0x80000;
69 } else if (!(offset & 0xfffe) && end >= address + 0x10000) {
70 entry = mk_pte_io((offset & ~(0x1UL)),
71 __pgprot(pgprot_val (prot) | _PAGE_SZ64K),
73 curend = address + 0x10000;
81 pte_val(entry) &= ~(_PAGE_E);
89 } while (address < curend);
90 } while (address < end);
93 static inline int io_remap_pmd_range(pmd_t * pmd, unsigned long address, unsigned long size,
94 unsigned long offset, pgprot_t prot, int space)
98 address &= ~PGDIR_MASK;
100 if (end > PGDIR_SIZE)
104 pte_t * pte = pte_alloc(current->mm, pmd, address);
107 io_remap_pte_range(pte, address, end - address, address + offset, prot, space);
108 address = (address + PMD_SIZE) & PMD_MASK;
110 } while (address < end);
114 int io_remap_page_range(unsigned long from, unsigned long offset, unsigned long size, pgprot_t prot, int space)
118 unsigned long beg = from;
119 unsigned long end = from + size;
120 struct mm_struct *mm = current->mm;
122 prot = __pgprot(pg_iobits);
124 dir = pgd_offset(mm, from);
125 flush_cache_range(mm, beg, end);
127 spin_lock(&mm->page_table_lock);
129 pmd_t *pmd = pmd_alloc(current->mm, dir, from);
133 error = io_remap_pmd_range(pmd, from, end - from, offset + from, prot, space);
136 from = (from + PGDIR_SIZE) & PGDIR_MASK;
139 spin_unlock(&mm->page_table_lock);
141 flush_tlb_range(current->mm, beg, end);