📄 c-r4k.c
字号:
static void r4k_flush_page_to_ram_d32(struct page *page){ blast_dcache32_page((unsigned long)page_address(page));}static void r4k_flush_page_to_ram_d32_r4600(struct page *page){#ifdef R4600_V1_HIT_DCACHE_WAR unsigned long flags; __save_and_cli(flags); __asm__ __volatile__("nop;nop;nop;nop");#endif blast_dcache32_page((unsigned long)page_address(page));#ifdef R4600_V1_HIT_DCACHE_WAR __restore_flags(flags);#endif}static voidr4k_flush_icache_page_s(struct vm_area_struct *vma, struct page *page){ /* * We did an scache flush therefore PI is already clean. */}static voidr4k_flush_icache_range(unsigned long start, unsigned long end){ flush_cache_all();}/* * Ok, this seriously sucks. We use them to flush a user page but don't * know the virtual address, so we have to blast away the whole icache * which is significantly more expensive than the real thing. */static voidr4k_flush_icache_page_p(struct vm_area_struct *vma, struct page *page){ if (!(vma->vm_flags & VM_EXEC)) return; flush_cache_all();}static voidr4k_dma_cache_wback_inv_pc(unsigned long addr, unsigned long size){ unsigned long end, a; unsigned int flags; if (size >= dcache_size) { flush_cache_all(); } else {#ifdef R4600_V2_HIT_CACHEOP_WAR /* Workaround for R4600 bug. See comment in <asm/war>. */ __save_and_cli(flags); *(volatile unsigned long *)KSEG1;#endif a = addr & ~(dc_lsize - 1); end = (addr + size) & ~(dc_lsize - 1); while (1) { flush_dcache_line(a); /* Hit_Writeback_Inv_D */ if (a == end) break; a += dc_lsize; }#ifdef R4600_V2_HIT_CACHEOP_WAR __restore_flags(flags);#endif } bc_wback_inv(addr, size);}static voidr4k_dma_cache_wback_inv_sc(unsigned long addr, unsigned long size){ unsigned long end, a; if (size >= scache_size) { flush_cache_all(); return; } a = addr & ~(sc_lsize - 1); end = (addr + size) & ~(sc_lsize - 1); while (1) { flush_scache_line(a); /* Hit_Writeback_Inv_SD */ if (a == end) break; a += sc_lsize; }}static voidr4k_dma_cache_inv_pc(unsigned long addr, unsigned long size){ unsigned long end, a; unsigned int flags; if (size >= dcache_size) { flush_cache_all(); } else {#ifdef R4600_V2_HIT_CACHEOP_WAR /* Workaround for R4600 bug. See comment above. */ __save_and_cli(flags); *(volatile unsigned long *)KSEG1;#endif a = addr & ~(dc_lsize - 1); end = (addr + size) & ~(dc_lsize - 1); while (1) { flush_dcache_line(a); /* Hit_Writeback_Inv_D */ if (a == end) break; a += dc_lsize; }#ifdef R4600_V2_HIT_CACHEOP_WAR __restore_flags(flags);#endif } bc_inv(addr, size);}static voidr4k_dma_cache_inv_sc(unsigned long addr, unsigned long size){ unsigned long end, a; if (size >= scache_size) { flush_cache_all(); return; } a = addr & ~(sc_lsize - 1); end = (addr + size) & ~(sc_lsize - 1); while (1) { flush_scache_line(a); /* Hit_Writeback_Inv_SD */ if (a == end) break; a += sc_lsize; }}/* * While we're protected against bad userland addresses we don't care * very much about what happens in that case. Usually a segmentation * fault will dump the process later on anyway ... */static void r4k_flush_cache_sigtramp(unsigned long addr){#ifdef R4600_V1_HIT_DCACHE_WAR unsigned long flags; __save_and_cli(flags); __asm__ __volatile__("nop;nop;nop;nop");#endif protected_writeback_dcache_line(addr & ~(dc_lsize - 1)); protected_flush_icache_line(addr & ~(ic_lsize - 1));#ifdef R4600_V1_HIT_DCACHE_WAR __restore_flags(flags);#endif}static void r4600v20k_flush_cache_sigtramp(unsigned long addr){ unsigned int flags;#ifdef R4600_V2_HIT_CACHEOP_WAR __save_and_cli(flags); /* Clear internal cache refill buffer */ *(volatile unsigned int *)KSEG1;#endif protected_writeback_dcache_line(addr & ~(dc_lsize - 1)); protected_flush_icache_line(addr & ~(ic_lsize - 1));#ifdef R4600_V2_HIT_CACHEOP_WAR __restore_flags(flags);#endif}/* Detect and size the various r4k caches. */static void __init probe_icache(unsigned long config){ switch (mips_cpu.cputype) { case CPU_VR41XX: case CPU_VR4111: case CPU_VR4121: case CPU_VR4122: case CPU_VR4131: case CPU_VR4181: case CPU_VR4181A: icache_size = 1 << (10 + ((config >> 9) & 7)); break; default: icache_size = 1 << (12 + ((config >> 9) & 7)); break; } ic_lsize = 16 << ((config >> 5) & 1); printk("Primary instruction cache %dkb, linesize %d bytes.\n", icache_size >> 10, ic_lsize);}static void __init probe_dcache(unsigned long config){ switch (mips_cpu.cputype) { case CPU_VR41XX: case CPU_VR4111: case CPU_VR4121: case CPU_VR4122: case CPU_VR4131: case CPU_VR4181: case CPU_VR4181A: dcache_size = 1 << (10 + ((config >> 6) & 7)); break; default: dcache_size = 1 << (12 + ((config >> 6) & 7)); break; } dc_lsize = 16 << ((config >> 4) & 1); printk("Primary data cache %dkb, linesize %d bytes.\n", dcache_size >> 10, dc_lsize);}/* If you even _breathe_ on this function, look at the gcc output * and make sure it does not pop things on and off the stack for * the cache sizing loop that executes in KSEG1 space or else * you will crash and burn badly. You have been warned. */static int __init probe_scache(unsigned long config){ extern unsigned long stext; unsigned long flags, addr, begin, end, pow2; int tmp; tmp = ((config >> 17) & 1); if(tmp) return 0; tmp = ((config >> 22) & 3); switch(tmp) { case 0: sc_lsize = 16; break; case 1: sc_lsize = 32; break; case 2: sc_lsize = 64; break; case 3: sc_lsize = 128; break; } begin = (unsigned long) &stext; begin &= ~((4 * 1024 * 1024) - 1); end = begin + (4 * 1024 * 1024); /* This is such a bitch, you'd think they would make it * easy to do this. Away you daemons of stupidity! */ __save_and_cli(flags); /* Fill each size-multiple cache line with a valid tag. */ pow2 = (64 * 1024); for(addr = begin; addr < end; addr = (begin + pow2)) { unsigned long *p = (unsigned long *) addr; __asm__ __volatile__("nop" : : "r" (*p)); /* whee... */ pow2 <<= 1; } /* Load first line with zero (therefore invalid) tag. */ set_taglo(0); set_taghi(0); __asm__ __volatile__("nop; nop; nop; nop;"); /* avoid the hazard */ __asm__ __volatile__("\n\t.set noreorder\n\t" ".set mips3\n\t" "cache 8, (%0)\n\t" ".set mips0\n\t" ".set reorder\n\t" : : "r" (begin)); __asm__ __volatile__("\n\t.set noreorder\n\t" ".set mips3\n\t" "cache 9, (%0)\n\t" ".set mips0\n\t" ".set reorder\n\t" : : "r" (begin)); __asm__ __volatile__("\n\t.set noreorder\n\t" ".set mips3\n\t" "cache 11, (%0)\n\t" ".set mips0\n\t" ".set reorder\n\t" : : "r" (begin)); /* Now search for the wrap around point. */ pow2 = (128 * 1024); tmp = 0; for(addr = (begin + (128 * 1024)); addr < (end); addr = (begin + pow2)) { __asm__ __volatile__("\n\t.set noreorder\n\t" ".set mips3\n\t" "cache 7, (%0)\n\t" ".set mips0\n\t" ".set reorder\n\t" : : "r" (addr)); __asm__ __volatile__("nop; nop; nop; nop;"); /* hazard... */ if(!get_taglo()) break; pow2 <<= 1; } __restore_flags(flags); addr -= begin; printk("Secondary cache sized at %dK linesize %d bytes.\n", (int) (addr >> 10), sc_lsize); scache_size = addr; return 1;}static void __init setup_noscache_funcs(void){ unsigned int prid; switch(dc_lsize) { case 16: _clear_page = r4k_clear_page_d16; _copy_page = r4k_copy_page_d16; _flush_cache_all = r4k_flush_cache_all_d16i16; _flush_cache_mm = r4k_flush_cache_mm_d16i16; _flush_cache_range = r4k_flush_cache_range_d16i16; _flush_cache_page = r4k_flush_cache_page_d16i16; _flush_page_to_ram = r4k_flush_page_to_ram_d16; break; case 32: prid = read_32bit_cp0_register(CP0_PRID) & 0xfff0; if (prid == 0x2010) { /* R4600 V1.7 */ _clear_page = r4k_clear_page_r4600_v1; _copy_page = r4k_copy_page_r4600_v1; _flush_page_to_ram = r4k_flush_page_to_ram_d32_r4600; } else if (prid == 0x2020) { /* R4600 V2.0 */ _clear_page = r4k_clear_page_r4600_v2; _copy_page = r4k_copy_page_r4600_v2; _flush_page_to_ram = r4k_flush_page_to_ram_d32; } else { _clear_page = r4k_clear_page_d32; _copy_page = r4k_copy_page_d32; _flush_page_to_ram = r4k_flush_page_to_ram_d32; } _flush_cache_all = r4k_flush_cache_all_d32i32; _flush_cache_mm = r4k_flush_cache_mm_d32i32; _flush_cache_range = r4k_flush_cache_range_d32i32; _flush_cache_page = r4k_flush_cache_page_d32i32; break; } ___flush_cache_all = _flush_cache_all; _flush_icache_page = r4k_flush_icache_page_p; _dma_cache_wback_inv = r4k_dma_cache_wback_inv_pc; _dma_cache_wback = r4k_dma_cache_wback_inv_pc; _dma_cache_inv = r4k_dma_cache_inv_pc;}static void __init setup_scache_funcs(void){ switch(sc_lsize) { case 16: switch(dc_lsize) { case 16: _flush_cache_all = r4k_flush_cache_all_s16d16i16; _flush_cache_mm = r4k_flush_cache_mm_s16d16i16; _flush_cache_range = r4k_flush_cache_range_s16d16i16; _flush_cache_page = r4k_flush_cache_page_s16d16i16; break; case 32: panic("Invalid cache configuration detected"); }; _flush_page_to_ram = r4k_flush_page_to_ram_s16; _clear_page = r4k_clear_page_s16; _copy_page = r4k_copy_page_s16; break; case 32: switch(dc_lsize) { case 16: _flush_cache_all = r4k_flush_cache_all_s32d16i16; _flush_cache_mm = r4k_flush_cache_mm_s32d16i16; _flush_cache_range = r4k_flush_cache_range_s32d16i16; _flush_cache_page = r4k_flush_cache_page_s32d16i16; break; case 32: _flush_cache_all = r4k_flush_cache_all_s32d32i32; _flush_cache_mm = r4k_flush_cache_mm_s32d32i32; _flush_cache_range = r4k_flush_cache_range_s32d32i32; _flush_cache_page = r4k_flush_cache_page_s32d32i32; break; }; _flush_page_to_ram = r4k_flush_page_to_ram_s32; _clear_page = r4k_clear_page_s32; _copy_page = r4k_copy_page_s32; break; case 64: switch(dc_lsize) { case 16: _flush_cache_all = r4k_flush_cache_all_s64d16i16; _flush_cache_mm = r4k_flush_cache_mm_s64d16i16; _flush_cache_range = r4k_flush_cache_range_s64d16i16; _flush_cache_page = r4k_flush_cache_page_s64d16i16; break; case 32: _flush_cache_all = r4k_flush_cache_all_s64d32i32; _flush_cache_mm = r4k_flush_cache_mm_s64d32i32; _flush_cache_range = r4k_flush_cache_range_s64d32i32; _flush_cache_page = r4k_flush_cache_page_s64d32i32; break; }; _flush_page_to_ram = r4k_flush_page_to_ram_s64; _clear_page = r4k_clear_page_s64; _copy_page = r4k_copy_page_s64; break; case 128: switch(dc_lsize) { case 16: _flush_cache_all = r4k_flush_cache_all_s128d16i16; _flush_cache_mm = r4k_flush_cache_mm_s128d16i16; _flush_cache_range = r4k_flush_cache_range_s128d16i16; _flush_cache_page = r4k_flush_cache_page_s128d16i16; break; case 32: _flush_cache_all = r4k_flush_cache_all_s128d32i32; _flush_cache_mm = r4k_flush_cache_mm_s128d32i32; _flush_cache_range = r4k_flush_cache_range_s128d32i32; _flush_cache_page = r4k_flush_cache_page_s128d32i32; break; }; _flush_page_to_ram = r4k_flush_page_to_ram_s128; _clear_page = r4k_clear_page_s128; _copy_page = r4k_copy_page_s128; break; } ___flush_cache_all = _flush_cache_all; _flush_icache_page = r4k_flush_icache_page_s; _dma_cache_wback_inv = r4k_dma_cache_wback_inv_sc; _dma_cache_wback = r4k_dma_cache_wback_inv_sc; _dma_cache_inv = r4k_dma_cache_inv_sc;}typedef int (*probe_func_t)(unsigned long);static inline void __init setup_scache(unsigned int config){ probe_func_t probe_scache_kseg1; int sc_present = 0; /* Maybe the cpu knows about a l2 cache? */ probe_scache_kseg1 = (probe_func_t) (KSEG1ADDR(&probe_scache)); sc_present = probe_scache_kseg1(config); if (!sc_present) { setup_noscache_funcs(); return; } switch(mips_cpu.cputype) { case CPU_R5000: case CPU_NEVADA: setup_noscache_funcs();#if defined(CONFIG_CPU_R5000) || defined(CONFIG_CPU_NEVADA) r5k_sc_init();#endif break; default: setup_scache_funcs(); }}void __init ld_mmu_r4xx0(void){ unsigned long config = read_32bit_cp0_register(CP0_CONFIG); change_cp0_config(CONF_CM_CMASK | CONF_CU, CONF_CM_DEFAULT); probe_icache(config); probe_dcache(config); setup_scache(config); switch(mips_cpu.cputype) { case CPU_R4600: /* QED style two way caches? */ case CPU_R4700: case CPU_R5000: case CPU_NEVADA: _flush_cache_page = r4k_flush_cache_page_d32i32_r4600; } _flush_cache_sigtramp = r4k_flush_cache_sigtramp; _flush_icache_range = r4k_flush_icache_range; /* Ouch */ if ((read_32bit_cp0_register(CP0_PRID) & 0xfff0) == 0x2020) { _flush_cache_sigtramp = r4600v20k_flush_cache_sigtramp; } __flush_cache_all();}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -