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/cacheflush.h>
17 #include <asm/tlbflush.h>
19 /* Remap IO memory, the same way as remap_pfn_range(), but use
20 * the obio memory space.
22 * They use a pgprot that sets PAGE_IO and does not check the
23 * mem_map table as this is independent of normal memory.
25 static inline void io_remap_pte_range(struct mm_struct *mm, pte_t * pte, unsigned long address, unsigned long size,
26 unsigned long offset, pgprot_t prot, int space)
35 set_pte_at(mm, address, pte, mk_pte_io(offset, prot, space));
39 } while (address < end);
42 static inline int io_remap_pmd_range(struct mm_struct *mm, pmd_t * pmd, unsigned long address, unsigned long size,
43 unsigned long offset, pgprot_t prot, int space)
47 address &= ~PGDIR_MASK;
53 pte_t * pte = pte_alloc_map(mm, pmd, address);
56 io_remap_pte_range(mm, pte, address, end - address, address + offset, prot, space);
57 address = (address + PMD_SIZE) & PMD_MASK;
59 } while (address < end);
63 int io_remap_pfn_range(struct vm_area_struct *vma, unsigned long from,
64 unsigned long pfn, unsigned long size, pgprot_t prot)
68 unsigned long beg = from;
69 unsigned long end = from + size;
70 struct mm_struct *mm = vma->vm_mm;
71 int space = GET_IOSPACE(pfn);
72 unsigned long offset = GET_PFN(pfn) << PAGE_SHIFT;
74 /* See comment in mm/memory.c remap_pfn_range */
75 vma->vm_flags |= VM_IO | VM_RESERVED | VM_PFNMAP;
76 vma->vm_pgoff = (offset >> PAGE_SHIFT) |
77 ((unsigned long)space << 28UL);
80 dir = pgd_offset(mm, from);
81 flush_cache_range(vma, beg, end);
84 pmd_t *pmd = pmd_alloc(mm, dir, from);
88 error = io_remap_pmd_range(mm, pmd, from, end - from, offset + from, prot, space);
91 from = (from + PGDIR_SIZE) & PGDIR_MASK;
95 flush_tlb_range(vma, beg, end);
98 EXPORT_SYMBOL(io_remap_pfn_range);