|
68 | 68 | #include <linux/mmu_context.h> |
69 | 69 | #include <linux/syscalls.h> |
70 | 70 | #include <linux/uaccess.h> |
| 71 | +#include <linux/pagemap.h> |
71 | 72 | #include <asm/cacheflush.h> |
72 | 73 | #include <asm/cachectl.h> |
73 | 74 | #include <asm/setup.h> |
@@ -138,6 +139,7 @@ void __cpuinit arc_cache_init(void) |
138 | 139 | struct cpuinfo_arc_cache *ic = &cpuinfo_arc700[cpu].icache; |
139 | 140 | struct cpuinfo_arc_cache *dc = &cpuinfo_arc700[cpu].dcache; |
140 | 141 | int way_pg_ratio = way_pg_ratio; |
| 142 | + int dcache_does_alias; |
141 | 143 | char str[256]; |
142 | 144 |
|
143 | 145 | printk(arc_cache_mumbojumbo(0, str, sizeof(str))); |
@@ -184,9 +186,13 @@ void __cpuinit arc_cache_init(void) |
184 | 186 | panic("Cache H/W doesn't match kernel Config"); |
185 | 187 | } |
186 | 188 |
|
| 189 | + dcache_does_alias = (dc->sz / ARC_DCACHE_WAYS) > PAGE_SIZE; |
| 190 | + |
187 | 191 | /* check for D-Cache aliasing */ |
188 | | - if ((dc->sz / ARC_DCACHE_WAYS) > PAGE_SIZE) |
189 | | - panic("D$ aliasing not handled right now\n"); |
| 192 | + if (dcache_does_alias && !cache_is_vipt_aliasing()) |
| 193 | + panic("Enable CONFIG_ARC_CACHE_VIPT_ALIASING\n"); |
| 194 | + else if (!dcache_does_alias && cache_is_vipt_aliasing()) |
| 195 | + panic("Don't need CONFIG_ARC_CACHE_VIPT_ALIASING\n"); |
190 | 196 | #endif |
191 | 197 |
|
192 | 198 | /* Set the default Invalidate Mode to "simpy discard dirty lines" |
@@ -312,7 +318,7 @@ static inline void __dc_line_loop(unsigned long paddr, unsigned long vaddr, |
312 | 318 | } |
313 | 319 | } |
314 | 320 |
|
315 | | -/* For kernel mappings cache op index is same as paddr */ |
| 321 | +/* For kernel mappings cache operation: index is same as paddr */ |
316 | 322 | #define __dc_line_op_k(p, sz, op) __dc_line_op(p, p, sz, op) |
317 | 323 |
|
318 | 324 | /* |
@@ -464,10 +470,47 @@ static void __ic_line_inv_vaddr(unsigned long paddr, unsigned long vaddr, |
464 | 470 | * Exported APIs |
465 | 471 | */ |
466 | 472 |
|
| 473 | +/* |
| 474 | + * Handle cache congruency of kernel and userspace mappings of page when kernel |
| 475 | + * writes-to/reads-from |
| 476 | + * |
| 477 | + * The idea is to defer flushing of kernel mapping after a WRITE, possible if: |
| 478 | + * -dcache is NOT aliasing, hence any U/K-mappings of page are congruent |
| 479 | + * -U-mapping doesn't exist yet for page (finalised in update_mmu_cache) |
| 480 | + * -In SMP, if hardware caches are coherent |
| 481 | + * |
| 482 | + * There's a corollary case, where kernel READs from a userspace mapped page. |
| 483 | + * If the U-mapping is not congruent to to K-mapping, former needs flushing. |
| 484 | + */ |
467 | 485 | void flush_dcache_page(struct page *page) |
468 | 486 | { |
469 | | - /* Make a note that dcache is not yet flushed for this page */ |
470 | | - set_bit(PG_arch_1, &page->flags); |
| 487 | + struct address_space *mapping; |
| 488 | + |
| 489 | + if (!cache_is_vipt_aliasing()) { |
| 490 | + set_bit(PG_arch_1, &page->flags); |
| 491 | + return; |
| 492 | + } |
| 493 | + |
| 494 | + /* don't handle anon pages here */ |
| 495 | + mapping = page_mapping(page); |
| 496 | + if (!mapping) |
| 497 | + return; |
| 498 | + |
| 499 | + /* |
| 500 | + * pagecache page, file not yet mapped to userspace |
| 501 | + * Make a note that K-mapping is dirty |
| 502 | + */ |
| 503 | + if (!mapping_mapped(mapping)) { |
| 504 | + set_bit(PG_arch_1, &page->flags); |
| 505 | + } else if (page_mapped(page)) { |
| 506 | + |
| 507 | + /* kernel reading from page with U-mapping */ |
| 508 | + void *paddr = page_address(page); |
| 509 | + unsigned long vaddr = page->index << PAGE_CACHE_SHIFT; |
| 510 | + |
| 511 | + if (addr_not_cache_congruent(paddr, vaddr)) |
| 512 | + __flush_dcache_page(paddr, vaddr); |
| 513 | + } |
471 | 514 | } |
472 | 515 | EXPORT_SYMBOL(flush_dcache_page); |
473 | 516 |
|
@@ -612,6 +655,87 @@ noinline void flush_cache_all(void) |
612 | 655 |
|
613 | 656 | } |
614 | 657 |
|
| 658 | +#ifdef CONFIG_ARC_CACHE_VIPT_ALIASING |
| 659 | + |
| 660 | +void flush_cache_mm(struct mm_struct *mm) |
| 661 | +{ |
| 662 | + flush_cache_all(); |
| 663 | +} |
| 664 | + |
| 665 | +void flush_cache_page(struct vm_area_struct *vma, unsigned long u_vaddr, |
| 666 | + unsigned long pfn) |
| 667 | +{ |
| 668 | + unsigned int paddr = pfn << PAGE_SHIFT; |
| 669 | + |
| 670 | + __sync_icache_dcache(paddr, u_vaddr, PAGE_SIZE); |
| 671 | +} |
| 672 | + |
| 673 | +void flush_cache_range(struct vm_area_struct *vma, unsigned long start, |
| 674 | + unsigned long end) |
| 675 | +{ |
| 676 | + flush_cache_all(); |
| 677 | +} |
| 678 | + |
| 679 | +void copy_user_highpage(struct page *to, struct page *from, |
| 680 | + unsigned long u_vaddr, struct vm_area_struct *vma) |
| 681 | +{ |
| 682 | + void *kfrom = page_address(from); |
| 683 | + void *kto = page_address(to); |
| 684 | + int clean_src_k_mappings = 0; |
| 685 | + |
| 686 | + /* |
| 687 | + * If SRC page was already mapped in userspace AND it's U-mapping is |
| 688 | + * not congruent with K-mapping, sync former to physical page so that |
| 689 | + * K-mapping in memcpy below, sees the right data |
| 690 | + * |
| 691 | + * Note that while @u_vaddr refers to DST page's userspace vaddr, it is |
| 692 | + * equally valid for SRC page as well |
| 693 | + */ |
| 694 | + if (page_mapped(from) && addr_not_cache_congruent(kfrom, u_vaddr)) { |
| 695 | + __flush_dcache_page(kfrom, u_vaddr); |
| 696 | + clean_src_k_mappings = 1; |
| 697 | + } |
| 698 | + |
| 699 | + copy_page(kto, kfrom); |
| 700 | + |
| 701 | + /* |
| 702 | + * Mark DST page K-mapping as dirty for a later finalization by |
| 703 | + * update_mmu_cache(). Although the finalization could have been done |
| 704 | + * here as well (given that both vaddr/paddr are available). |
| 705 | + * But update_mmu_cache() already has code to do that for other |
| 706 | + * non copied user pages (e.g. read faults which wire in pagecache page |
| 707 | + * directly). |
| 708 | + */ |
| 709 | + set_bit(PG_arch_1, &to->flags); |
| 710 | + |
| 711 | + /* |
| 712 | + * if SRC was already usermapped and non-congruent to kernel mapping |
| 713 | + * sync the kernel mapping back to physical page |
| 714 | + */ |
| 715 | + if (clean_src_k_mappings) { |
| 716 | + __flush_dcache_page(kfrom, kfrom); |
| 717 | + } else { |
| 718 | + set_bit(PG_arch_1, &from->flags); |
| 719 | + } |
| 720 | +} |
| 721 | + |
| 722 | +void clear_user_page(void *to, unsigned long u_vaddr, struct page *page) |
| 723 | +{ |
| 724 | + clear_page(to); |
| 725 | + set_bit(PG_arch_1, &page->flags); |
| 726 | +} |
| 727 | + |
| 728 | +void flush_anon_page(struct vm_area_struct *vma, struct page *page, |
| 729 | + unsigned long u_vaddr) |
| 730 | +{ |
| 731 | + /* TBD: do we really need to clear the kernel mapping */ |
| 732 | + __flush_dcache_page(page_address(page), u_vaddr); |
| 733 | + __flush_dcache_page(page_address(page), page_address(page)); |
| 734 | + |
| 735 | +} |
| 736 | + |
| 737 | +#endif |
| 738 | + |
615 | 739 | /********************************************************************** |
616 | 740 | * Explicit Cache flush request from user space via syscall |
617 | 741 | * Needed for JITs which generate code on the fly |
|
0 commit comments