📄 c-sb1.c
字号:
__sb1_writeback_inv_dcache_all(); else __sb1_writeback_inv_dcache_range(start, end); /* Just flush the whole icache if the range is big enough */ if ((end - start) > icache_range_cutoff) __sb1_flush_icache_all(); else __sb1_flush_icache_range(start, end);}#ifdef CONFIG_SMPstruct flush_icache_range_args { unsigned long start; unsigned long end;};static void sb1_flush_icache_range_ipi(void *info){ struct flush_icache_range_args *args = info; local_sb1_flush_icache_range(args->start, args->end);}void sb1_flush_icache_range(unsigned long start, unsigned long end){ struct flush_icache_range_args args; args.start = start; args.end = end; smp_call_function(sb1_flush_icache_range_ipi, &args, 1, 1); local_sb1_flush_icache_range(start, end);}#elsevoid sb1_flush_icache_range(unsigned long start, unsigned long end) __attribute__((alias("local_sb1_flush_icache_range")));#endif/* * Flush the icache for a given physical page. Need to writeback the * dcache first, then invalidate the icache. If the page isn't * executable, nothing is required. */static void local_sb1_flush_icache_page(struct vm_area_struct *vma, struct page *page){ unsigned long start; int cpu = smp_processor_id();#ifndef CONFIG_SMP if (!(vma->vm_flags & VM_EXEC)) return;#endif /* Need to writeback any dirty data for that page, we have the PA */ start = (unsigned long)(page-mem_map) << PAGE_SHIFT; __sb1_writeback_inv_dcache_phys_range(start, start + PAGE_SIZE); /* * If there's a context, bump the ASID (cheaper than a flush, * since we don't know VAs!) */ if (cpu_context(cpu, vma->vm_mm) != 0) { drop_mmu_context(vma->vm_mm, cpu); }}#ifdef CONFIG_SMPstruct flush_icache_page_args { struct vm_area_struct *vma; struct page *page;};static void sb1_flush_icache_page_ipi(void *info){ struct flush_icache_page_args *args = info; local_sb1_flush_icache_page(args->vma, args->page);}/* Dirty dcache could be on another CPU, so do the IPIs */static void sb1_flush_icache_page(struct vm_area_struct *vma, struct page *page){ struct flush_icache_page_args args; if (!(vma->vm_flags & VM_EXEC)) return; args.vma = vma; args.page = page; smp_call_function(sb1_flush_icache_page_ipi, (void *) &args, 1, 1); local_sb1_flush_icache_page(vma, page);}#elsevoid sb1_flush_icache_page(struct vm_area_struct *vma, struct page *page) __attribute__((alias("local_sb1_flush_icache_page")));#endif/* * A signal trampoline must fit into a single cacheline. */static void local_sb1_flush_cache_sigtramp(unsigned long addr){ __asm__ __volatile__ ( " .set push \n" " .set noreorder \n" " .set noat \n" " .set mips4 \n" " cache %2, (0<<13)(%0) \n" /* Index-inval this address */ " cache %2, (1<<13)(%0) \n" /* Index-inval this address */ " cache %2, (2<<13)(%0) \n" /* Index-inval this address */ " cache %2, (3<<13)(%0) \n" /* Index-inval this address */ " xori $1, %0, 1<<12 \n" /* Flip index bit 12 */ " cache %2, (0<<13)($1) \n" /* Index-inval this address */ " cache %2, (1<<13)($1) \n" /* Index-inval this address */ " cache %2, (2<<13)($1) \n" /* Index-inval this address */ " cache %2, (3<<13)($1) \n" /* Index-inval this address */ " cache %3, (0<<13)(%1) \n" /* Index-inval this address */ " cache %3, (1<<13)(%1) \n" /* Index-inval this address */ " cache %3, (2<<13)(%1) \n" /* Index-inval this address */ " cache %3, (3<<13)(%1) \n" /* Index-inval this address */ " bnezl $0, 1f \n" /* Force mispredict */ " nop \n" "1: \n" " .set pop \n" : : "r" (addr & dcache_index_mask), "r" (addr & icache_index_mask), "i" (Index_Writeback_Inv_D), "i" (Index_Invalidate_I));}#ifdef CONFIG_SMPstatic void sb1_flush_cache_sigtramp_ipi(void *info){ unsigned long iaddr = (unsigned long) info; local_sb1_flush_cache_sigtramp(iaddr);}static void sb1_flush_cache_sigtramp(unsigned long addr){ local_sb1_flush_cache_sigtramp(addr); smp_call_function(sb1_flush_cache_sigtramp_ipi, (void *) addr, 1, 1);}#elsevoid sb1_flush_cache_sigtramp(unsigned long addr) __attribute__((alias("local_sb1_flush_cache_sigtramp")));#endif/* * Anything that just flushes dcache state can be ignored, as we're always * coherent in dcache space. This is just a dummy function that all the * nop'ed routines point to */static void sb1_nop(void){}/* * Cache set values (from the mips64 spec) * 0 - 64 * 1 - 128 * 2 - 256 * 3 - 512 * 4 - 1024 * 5 - 2048 * 6 - 4096 * 7 - Reserved */static unsigned int decode_cache_sets(unsigned int config_field){ if (config_field == 7) { /* JDCXXX - Find a graceful way to abort. */ return 0; } return (1<<(config_field + 6));}/* * Cache line size values (from the mips64 spec) * 0 - No cache present. * 1 - 4 bytes * 2 - 8 bytes * 3 - 16 bytes * 4 - 32 bytes * 5 - 64 bytes * 6 - 128 bytes * 7 - Reserved */static unsigned int decode_cache_line_size(unsigned int config_field){ if (config_field == 0) { return 0; } else if (config_field == 7) { /* JDCXXX - Find a graceful way to abort. */ return 0; } return (1<<(config_field + 1));}/* * Relevant bits of the config1 register format (from the MIPS32/MIPS64 specs) * * 24:22 Icache sets per way * 21:19 Icache line size * 18:16 Icache Associativity * 15:13 Dcache sets per way * 12:10 Dcache line size * 9:7 Dcache Associativity */static char *way_string[] = { "direct mapped", "2-way", "3-way", "4-way", "5-way", "6-way", "7-way", "8-way",};static __init void probe_cache_sizes(void){ u32 config1; config1 = read_c0_config1(); icache_line_size = decode_cache_line_size((config1 >> 19) & 0x7); dcache_line_size = decode_cache_line_size((config1 >> 10) & 0x7); icache_sets = decode_cache_sets((config1 >> 22) & 0x7); dcache_sets = decode_cache_sets((config1 >> 13) & 0x7); icache_assoc = ((config1 >> 16) & 0x7) + 1; dcache_assoc = ((config1 >> 7) & 0x7) + 1; icache_size = icache_line_size * icache_sets * icache_assoc; dcache_size = dcache_line_size * dcache_sets * dcache_assoc; /* Need to remove non-index bits for index ops */ icache_index_mask = (icache_sets - 1) * icache_line_size; dcache_index_mask = (dcache_sets - 1) * dcache_line_size; /* * These are for choosing range (index ops) versus all. * icache flushes all ways for each set, so drop icache_assoc. * dcache flushes all ways and each setting of bit 12 for each * index, so drop dcache_assoc and halve the dcache_sets. */ icache_range_cutoff = icache_sets * icache_line_size; dcache_range_cutoff = (dcache_sets / 2) * icache_line_size; printk("Primary instruction cache %ldkB, %s, linesize %d bytes.\n", icache_size >> 10, way_string[icache_assoc - 1], icache_line_size); printk("Primary data cache %ldkB, %s, linesize %d bytes.\n", dcache_size >> 10, way_string[dcache_assoc - 1], dcache_line_size);}/* * This is called from loadmmu.c. We have to set up all the * memory management function pointers, as well as initialize * the caches and tlbs */void ld_mmu_sb1(void){ extern char except_vec2_sb1; extern char handle_vec2_sb1; unsigned long temp; /* Special cache error handler for SB1 */ memcpy((void *)(KSEG0 + 0x100), &except_vec2_sb1, 0x80); memcpy((void *)(KSEG1 + 0x100), &except_vec2_sb1, 0x80); memcpy((void *)KSEG1ADDR(&handle_vec2_sb1), &handle_vec2_sb1, 0x80); probe_cache_sizes();#ifdef CONFIG_SIBYTE_DMA_PAGEOPS sb1_dma_init();#endif /* * None of these are needed for the SB1 - the Dcache is * physically indexed and tagged, so no virtual aliasing can * occur */ _flush_cache_range = (void *) sb1_nop; _flush_cache_mm = (void (*)(struct mm_struct *))sb1_nop; _flush_cache_all = sb1_nop; /* These routines are for Icache coherence with the Dcache */ _flush_icache_range = sb1_flush_icache_range; _flush_icache_page = sb1_flush_icache_page; _flush_icache_all = __sb1_flush_icache_all; /* local only */ /* This implies an Icache flush too, so can't be nop'ed */ _flush_cache_page = sb1_flush_cache_page; _flush_cache_sigtramp = sb1_flush_cache_sigtramp; _flush_data_cache_page = (void *) sb1_nop; /* Full flush */ ___flush_cache_all = sb1___flush_cache_all; change_c0_config(CONF_CM_CMASK, CONF_CM_DEFAULT); /* * This is the only way to force the update of K0 to complete * before subsequent instruction fetch. */ __asm__ __volatile__ ( " .set push \n" " .set mips4 \n" " la %0, 1f \n" " mtc0 %0, $14 \n" " eret \n" "1: .set pop \n" : "=r" (temp)); flush_cache_all();}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -