2 * Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
3 * Copyright 2003 PathScale, Inc.
4 * Licensed under the GPL
7 #include "linux/stddef.h"
8 #include "linux/sched.h"
11 #include "asm/pgtable.h"
19 static int do_ops(union mm_context *mmu, struct host_vm_op *ops, int last,
20 int finished, void **flush)
22 struct host_vm_op *op;
25 for(i = 0; i <= last && !ret; i++){
29 ret = map(&mmu->skas.id, op->u.mmap.addr,
30 op->u.mmap.len, op->u.mmap.r, op->u.mmap.w,
31 op->u.mmap.x, op->u.mmap.fd,
32 op->u.mmap.offset, finished, flush);
35 ret = unmap(&mmu->skas.id, op->u.munmap.addr,
36 op->u.munmap.len, finished, flush);
39 ret = protect(&mmu->skas.id, op->u.mprotect.addr,
40 op->u.mprotect.len, op->u.mprotect.r,
41 op->u.mprotect.w, op->u.mprotect.x,
45 printk("Unknown op type %d in do_ops\n", op->type);
55 static void fix_range(struct mm_struct *mm, unsigned long start_addr,
56 unsigned long end_addr, int force)
58 if(!proc_mm && (end_addr > CONFIG_STUB_START))
59 end_addr = CONFIG_STUB_START;
61 fix_range_common(mm, start_addr, end_addr, force, do_ops);
64 void __flush_tlb_one_skas(unsigned long addr)
66 flush_tlb_kernel_range_common(addr, addr + PAGE_SIZE);
69 void flush_tlb_range_skas(struct vm_area_struct *vma, unsigned long start,
72 if(vma->vm_mm == NULL)
73 flush_tlb_kernel_range_common(start, end);
74 else fix_range(vma->vm_mm, start, end, 0);
77 void flush_tlb_mm_skas(struct mm_struct *mm)
81 /* Don't bother flushing if this address space is about to be
84 if(atomic_read(&mm->mm_users) == 0)
87 end = proc_mm ? task_size : CONFIG_STUB_START;
88 fix_range(mm, 0, end, 0);
91 void force_flush_all_skas(void)
93 unsigned long end = proc_mm ? task_size : CONFIG_STUB_START;
94 fix_range(current->mm, 0, end, 1);
97 void flush_tlb_page_skas(struct vm_area_struct *vma, unsigned long address)
103 struct mm_struct *mm = vma->vm_mm;
105 int r, w, x, err = 0;
108 pgd = pgd_offset(vma->vm_mm, address);
109 if(!pgd_present(*pgd))
112 pud = pud_offset(pgd, address);
113 if(!pud_present(*pud))
116 pmd = pmd_offset(pud, address);
117 if(!pmd_present(*pmd))
120 pte = pte_offset_kernel(pmd, address);
125 if (!pte_young(*pte)) {
128 } else if (!pte_dirty(*pte)) {
132 mm_id = &mm->context.skas.id;
133 if(pte_newpage(*pte)){
134 if(pte_present(*pte)){
135 unsigned long long offset;
138 fd = phys_mapping(pte_val(*pte) & PAGE_MASK, &offset);
139 err = map(mm_id, address, PAGE_SIZE, r, w, x, fd,
142 else err = unmap(mm_id, address, PAGE_SIZE, 1, &flush);
144 else if(pte_newprot(*pte))
145 err = protect(mm_id, address, PAGE_SIZE, r, w, x, 1, &flush);
150 *pte = pte_mkuptodate(*pte);
155 printk("Failed to flush page for address 0x%lx\n", address);
156 force_sig(SIGKILL, current);