2005-04-17 05:20:36 +07:00
|
|
|
/* $Id: generic.c,v 1.18 2001/12/21 04:56:15 davem Exp $
|
|
|
|
* generic.c: Generic Sparc mm routines that are not dependent upon
|
|
|
|
* MMU type but are Sparc specific.
|
|
|
|
*
|
|
|
|
* Copyright (C) 1996 David S. Miller (davem@caip.rutgers.edu)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/mm.h>
|
|
|
|
#include <linux/swap.h>
|
|
|
|
#include <linux/pagemap.h>
|
|
|
|
|
|
|
|
#include <asm/pgalloc.h>
|
|
|
|
#include <asm/pgtable.h>
|
|
|
|
#include <asm/page.h>
|
|
|
|
#include <asm/tlbflush.h>
|
|
|
|
|
|
|
|
/* Remap IO memory, the same way as remap_pfn_range(), but use
|
|
|
|
* the obio memory space.
|
|
|
|
*
|
|
|
|
* They use a pgprot that sets PAGE_IO and does not check the
|
|
|
|
* mem_map table as this is independent of normal memory.
|
|
|
|
*/
|
|
|
|
static inline void io_remap_pte_range(struct mm_struct *mm, pte_t * pte,
|
|
|
|
unsigned long address,
|
|
|
|
unsigned long size,
|
|
|
|
unsigned long offset, pgprot_t prot,
|
|
|
|
int space)
|
|
|
|
{
|
|
|
|
unsigned long end;
|
|
|
|
|
|
|
|
/* clear hack bit that was used as a write_combine side-effect flag */
|
|
|
|
offset &= ~0x1UL;
|
|
|
|
address &= ~PMD_MASK;
|
|
|
|
end = address + size;
|
|
|
|
if (end > PMD_SIZE)
|
|
|
|
end = PMD_SIZE;
|
|
|
|
do {
|
|
|
|
pte_t entry;
|
|
|
|
unsigned long curend = address + PAGE_SIZE;
|
|
|
|
|
|
|
|
entry = mk_pte_io(offset, prot, space);
|
|
|
|
if (!(address & 0xffff)) {
|
|
|
|
if (!(address & 0x3fffff) && !(offset & 0x3ffffe) && end >= address + 0x400000) {
|
|
|
|
entry = mk_pte_io(offset,
|
|
|
|
__pgprot(pgprot_val (prot) | _PAGE_SZ4MB),
|
|
|
|
space);
|
|
|
|
curend = address + 0x400000;
|
|
|
|
offset += 0x400000;
|
|
|
|
} else if (!(address & 0x7ffff) && !(offset & 0x7fffe) && end >= address + 0x80000) {
|
|
|
|
entry = mk_pte_io(offset,
|
|
|
|
__pgprot(pgprot_val (prot) | _PAGE_SZ512K),
|
|
|
|
space);
|
|
|
|
curend = address + 0x80000;
|
|
|
|
offset += 0x80000;
|
|
|
|
} else if (!(offset & 0xfffe) && end >= address + 0x10000) {
|
|
|
|
entry = mk_pte_io(offset,
|
|
|
|
__pgprot(pgprot_val (prot) | _PAGE_SZ64K),
|
|
|
|
space);
|
|
|
|
curend = address + 0x10000;
|
|
|
|
offset += 0x10000;
|
|
|
|
} else
|
|
|
|
offset += PAGE_SIZE;
|
|
|
|
} else
|
|
|
|
offset += PAGE_SIZE;
|
|
|
|
|
|
|
|
do {
|
|
|
|
BUG_ON(!pte_none(*pte));
|
|
|
|
set_pte_at(mm, address, pte, entry);
|
|
|
|
address += PAGE_SIZE;
|
|
|
|
pte++;
|
|
|
|
} while (address < curend);
|
|
|
|
} while (address < end);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int io_remap_pmd_range(struct mm_struct *mm, pmd_t * pmd, unsigned long address, unsigned long size,
|
|
|
|
unsigned long offset, pgprot_t prot, int space)
|
|
|
|
{
|
|
|
|
unsigned long end;
|
|
|
|
|
|
|
|
address &= ~PGDIR_MASK;
|
|
|
|
end = address + size;
|
|
|
|
if (end > PGDIR_SIZE)
|
|
|
|
end = PGDIR_SIZE;
|
|
|
|
offset -= address;
|
|
|
|
do {
|
|
|
|
pte_t * pte = pte_alloc_map(mm, pmd, address);
|
|
|
|
if (!pte)
|
|
|
|
return -ENOMEM;
|
|
|
|
io_remap_pte_range(mm, pte, address, end - address, address + offset, prot, space);
|
|
|
|
pte_unmap(pte);
|
|
|
|
address = (address + PMD_SIZE) & PMD_MASK;
|
|
|
|
pmd++;
|
|
|
|
} while (address < end);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int io_remap_pud_range(struct mm_struct *mm, pud_t * pud, unsigned long address, unsigned long size,
|
|
|
|
unsigned long offset, pgprot_t prot, int space)
|
|
|
|
{
|
|
|
|
unsigned long end;
|
|
|
|
|
|
|
|
address &= ~PUD_MASK;
|
|
|
|
end = address + size;
|
|
|
|
if (end > PUD_SIZE)
|
|
|
|
end = PUD_SIZE;
|
|
|
|
offset -= address;
|
|
|
|
do {
|
|
|
|
pmd_t *pmd = pmd_alloc(mm, pud, address);
|
|
|
|
if (!pud)
|
|
|
|
return -ENOMEM;
|
|
|
|
io_remap_pmd_range(mm, pmd, address, end - address, address + offset, prot, space);
|
|
|
|
address = (address + PUD_SIZE) & PUD_MASK;
|
|
|
|
pud++;
|
|
|
|
} while (address < end);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int io_remap_pfn_range(struct vm_area_struct *vma, unsigned long from,
|
|
|
|
unsigned long pfn, unsigned long size, pgprot_t prot)
|
|
|
|
{
|
|
|
|
int error = 0;
|
|
|
|
pgd_t * dir;
|
|
|
|
unsigned long beg = from;
|
|
|
|
unsigned long end = from + size;
|
|
|
|
struct mm_struct *mm = vma->vm_mm;
|
|
|
|
int space = GET_IOSPACE(pfn);
|
|
|
|
unsigned long offset = GET_PFN(pfn) << PAGE_SHIFT;
|
|
|
|
|
2005-10-30 08:16:12 +07:00
|
|
|
/* See comment in mm/memory.c remap_pfn_range */
|
[PATCH] unpaged: VM_UNPAGED
Although we tend to associate VM_RESERVED with remap_pfn_range, quite a few
drivers set VM_RESERVED on areas which are then populated by nopage. The
PageReserved removal in 2.6.15-rc1 changed VM_RESERVED not to free pages in
zap_pte_range, without changing those drivers not to set it: so their pages
just leak away.
Let's not change miscellaneous drivers now: introduce VM_UNPAGED at the core,
to flag the special areas where the ptes may have no struct page, or if they
have then it's not to be touched. Replace most instances of VM_RESERVED in
core mm by VM_UNPAGED. Force it on in remap_pfn_range, and the sparc and
sparc64 io_remap_pfn_range.
Revert addition of VM_RESERVED to powerpc vdso, it's not needed there. Is it
needed anywhere? It still governs the mm->reserved_vm statistic, and special
vmas not to be merged, and areas not to be core dumped; but could probably be
eliminated later (the drivers are probably specifying it because in 2.4 it
kept swapout off the vma, but in 2.6 we work from the LRU, which these pages
don't get on).
Use the VM_SHM slot for VM_UNPAGED, and define VM_SHM to 0: it serves no
purpose whatsoever, and should be removed from drivers when we clean up.
Signed-off-by: Hugh Dickins <hugh@veritas.com>
Acked-by: William Irwin <wli@holomorphy.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2005-11-22 12:32:15 +07:00
|
|
|
vma->vm_flags |= VM_IO | VM_RESERVED | VM_UNPAGED;
|
2005-10-30 08:16:12 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
prot = __pgprot(pg_iobits);
|
|
|
|
offset -= from;
|
|
|
|
dir = pgd_offset(mm, from);
|
|
|
|
flush_cache_range(vma, beg, end);
|
|
|
|
|
|
|
|
while (from < end) {
|
2005-10-30 08:16:24 +07:00
|
|
|
pud_t *pud = pud_alloc(mm, dir, from);
|
2005-04-17 05:20:36 +07:00
|
|
|
error = -ENOMEM;
|
|
|
|
if (!pud)
|
|
|
|
break;
|
|
|
|
error = io_remap_pud_range(mm, pud, from, end - from, offset + from, prot, space);
|
|
|
|
if (error)
|
|
|
|
break;
|
|
|
|
from = (from + PGDIR_SIZE) & PGDIR_MASK;
|
|
|
|
dir++;
|
|
|
|
}
|
|
|
|
|
2005-10-30 08:16:24 +07:00
|
|
|
flush_tlb_range(vma, beg, end);
|
2005-04-17 05:20:36 +07:00
|
|
|
return error;
|
|
|
|
}
|