Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * arch/sh/mm/pg-sh4.c |
| 3 | * |
| 4 | * Copyright (C) 1999, 2000, 2002 Niibe Yutaka |
Paul Mundt | 8b39526 | 2006-09-27 14:38:02 +0900 | [diff] [blame] | 5 | * Copyright (C) 2002 - 2005 Paul Mundt |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | * |
| 7 | * Released under the terms of the GNU GPL v2.0. |
| 8 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | #include <linux/mm.h> |
Paul Mundt | 52e2778 | 2006-11-21 11:09:41 +0900 | [diff] [blame] | 10 | #include <linux/mutex.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | #include <asm/mmu_context.h> |
| 12 | #include <asm/cacheflush.h> |
| 13 | |
Paul Mundt | 52e2778 | 2006-11-21 11:09:41 +0900 | [diff] [blame] | 14 | extern struct mutex p3map_mutex[]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | |
Paul Mundt | 11c1965 | 2006-12-25 10:19:56 +0900 | [diff] [blame^] | 16 | #define CACHE_ALIAS (current_cpu_data.dcache.alias_mask) |
Paul Mundt | 8b39526 | 2006-09-27 14:38:02 +0900 | [diff] [blame] | 17 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | /* |
| 19 | * clear_user_page |
| 20 | * @to: P1 address |
| 21 | * @address: U0 address to be mapped |
| 22 | * @page: page (virt_to_page(to)) |
| 23 | */ |
| 24 | void clear_user_page(void *to, unsigned long address, struct page *page) |
| 25 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | if (((address ^ (unsigned long)to) & CACHE_ALIAS) == 0) |
| 27 | clear_page(to); |
| 28 | else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | unsigned long phys_addr = PHYSADDR(to); |
| 30 | unsigned long p3_addr = P3SEG + (address & CACHE_ALIAS); |
Paul Mundt | 8b39526 | 2006-09-27 14:38:02 +0900 | [diff] [blame] | 31 | pgd_t *pgd = pgd_offset_k(p3_addr); |
| 32 | pud_t *pud = pud_offset(pgd, p3_addr); |
| 33 | pmd_t *pmd = pmd_offset(pud, p3_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | pte_t *pte = pte_offset_kernel(pmd, p3_addr); |
| 35 | pte_t entry; |
| 36 | unsigned long flags; |
| 37 | |
Paul Mundt | 21440cf | 2006-11-20 14:30:26 +0900 | [diff] [blame] | 38 | entry = pfn_pte(phys_addr >> PAGE_SHIFT, PAGE_KERNEL); |
Paul Mundt | 52e2778 | 2006-11-21 11:09:41 +0900 | [diff] [blame] | 39 | mutex_lock(&p3map_mutex[(address & CACHE_ALIAS)>>12]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | set_pte(pte, entry); |
| 41 | local_irq_save(flags); |
| 42 | __flush_tlb_page(get_asid(), p3_addr); |
| 43 | local_irq_restore(flags); |
| 44 | update_mmu_cache(NULL, p3_addr, entry); |
| 45 | __clear_user_page((void *)p3_addr, to); |
| 46 | pte_clear(&init_mm, p3_addr, pte); |
Paul Mundt | 52e2778 | 2006-11-21 11:09:41 +0900 | [diff] [blame] | 47 | mutex_unlock(&p3map_mutex[(address & CACHE_ALIAS)>>12]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | } |
| 49 | } |
| 50 | |
| 51 | /* |
| 52 | * copy_user_page |
| 53 | * @to: P1 address |
| 54 | * @from: P1 address |
| 55 | * @address: U0 address to be mapped |
| 56 | * @page: page (virt_to_page(to)) |
| 57 | */ |
Paul Mundt | 8b39526 | 2006-09-27 14:38:02 +0900 | [diff] [blame] | 58 | void copy_user_page(void *to, void *from, unsigned long address, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | struct page *page) |
| 60 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | if (((address ^ (unsigned long)to) & CACHE_ALIAS) == 0) |
| 62 | copy_page(to, from); |
| 63 | else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | unsigned long phys_addr = PHYSADDR(to); |
| 65 | unsigned long p3_addr = P3SEG + (address & CACHE_ALIAS); |
Paul Mundt | 8b39526 | 2006-09-27 14:38:02 +0900 | [diff] [blame] | 66 | pgd_t *pgd = pgd_offset_k(p3_addr); |
| 67 | pud_t *pud = pud_offset(pgd, p3_addr); |
| 68 | pmd_t *pmd = pmd_offset(pud, p3_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | pte_t *pte = pte_offset_kernel(pmd, p3_addr); |
| 70 | pte_t entry; |
| 71 | unsigned long flags; |
| 72 | |
Paul Mundt | 21440cf | 2006-11-20 14:30:26 +0900 | [diff] [blame] | 73 | entry = pfn_pte(phys_addr >> PAGE_SHIFT, PAGE_KERNEL); |
Paul Mundt | 52e2778 | 2006-11-21 11:09:41 +0900 | [diff] [blame] | 74 | mutex_lock(&p3map_mutex[(address & CACHE_ALIAS)>>12]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | set_pte(pte, entry); |
| 76 | local_irq_save(flags); |
| 77 | __flush_tlb_page(get_asid(), p3_addr); |
| 78 | local_irq_restore(flags); |
| 79 | update_mmu_cache(NULL, p3_addr, entry); |
| 80 | __copy_user_page((void *)p3_addr, from, to); |
| 81 | pte_clear(&init_mm, p3_addr, pte); |
Paul Mundt | 52e2778 | 2006-11-21 11:09:41 +0900 | [diff] [blame] | 82 | mutex_unlock(&p3map_mutex[(address & CACHE_ALIAS)>>12]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | } |
| 84 | } |