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 pte_t mk_pte_io(unsigned long page, pgprot_t prot, int space)
21 pte_val(pte) = (((page) | pgprot_val(prot) | _PAGE_E) &
22 ~(unsigned long)_PAGE_CACHE);
23 pte_val(pte) |= (((unsigned long)space) << 32);
27 /* Remap IO memory, the same way as remap_pfn_range(), but use
28 * the obio memory space.
30 * They use a pgprot that sets PAGE_IO and does not check the
31 * mem_map table as this is independent of normal memory.
33 static inline void io_remap_pte_range(struct mm_struct *mm, pte_t * pte,
34 unsigned long address,
36 unsigned long offset, pgprot_t prot,
41 /* clear hack bit that was used as a write_combine side-effect flag */
49 unsigned long curend = address + PAGE_SIZE;
51 entry = mk_pte_io(offset, prot, space);
52 if (!(address & 0xffff)) {
53 if (!(address & 0x3fffff) && !(offset & 0x3ffffe) && end >= address + 0x400000) {
54 entry = mk_pte_io(offset,
55 __pgprot(pgprot_val (prot) | _PAGE_SZ4MB),
57 curend = address + 0x400000;
59 } else if (!(address & 0x7ffff) && !(offset & 0x7fffe) && end >= address + 0x80000) {
60 entry = mk_pte_io(offset,
61 __pgprot(pgprot_val (prot) | _PAGE_SZ512K),
63 curend = address + 0x80000;
65 } else if (!(offset & 0xfffe) && end >= address + 0x10000) {
66 entry = mk_pte_io(offset,
67 __pgprot(pgprot_val (prot) | _PAGE_SZ64K),
69 curend = address + 0x10000;
77 BUG_ON(!pte_none(*pte));
78 set_pte_at(mm, address, pte, entry);
80 pte_val(entry) += PAGE_SIZE;
82 } while (address < curend);
83 } while (address < end);
86 static inline int io_remap_pmd_range(struct mm_struct *mm, pmd_t * pmd, unsigned long address, unsigned long size,
87 unsigned long offset, pgprot_t prot, int space)
91 address &= ~PGDIR_MASK;
97 pte_t * pte = pte_alloc_map(mm, pmd, address);
100 io_remap_pte_range(mm, pte, address, end - address, address + offset, prot, space);
102 address = (address + PMD_SIZE) & PMD_MASK;
104 } while (address < end);
108 static inline int io_remap_pud_range(struct mm_struct *mm, pud_t * pud, unsigned long address, unsigned long size,
109 unsigned long offset, pgprot_t prot, int space)
113 address &= ~PUD_MASK;
114 end = address + size;
119 pmd_t *pmd = pmd_alloc(mm, pud, address);
122 io_remap_pmd_range(mm, pmd, address, end - address, address + offset, prot, space);
123 address = (address + PUD_SIZE) & PUD_MASK;
125 } while (address < end);
129 int io_remap_pfn_range(struct vm_area_struct *vma, unsigned long from,
130 unsigned long pfn, unsigned long size, pgprot_t prot)
134 unsigned long beg = from;
135 unsigned long end = from + size;
136 struct mm_struct *mm = vma->vm_mm;
137 int space = GET_IOSPACE(pfn);
138 unsigned long offset = GET_PFN(pfn) << PAGE_SHIFT;
139 unsigned long phys_base;
141 phys_base = offset | (((unsigned long) space) << 32UL);
143 /* See comment in mm/memory.c remap_pfn_range */
144 vma->vm_flags |= VM_IO | VM_RESERVED | VM_PFNMAP;
145 vma->vm_pgoff = phys_base >> PAGE_SHIFT;
147 prot = __pgprot(pg_iobits);
149 dir = pgd_offset(mm, from);
150 flush_cache_range(vma, beg, end);
153 pud_t *pud = pud_alloc(mm, dir, from);
157 error = io_remap_pud_range(mm, pud, from, end - from, offset + from, prot, space);
160 from = (from + PGDIR_SIZE) & PGDIR_MASK;
164 flush_tlb_range(vma, beg, end);