cache.c 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. /* $Id: cache.c,v 1.4 2000/01/25 00:11:38 prumpf Exp $
  2. *
  3. * This file is subject to the terms and conditions of the GNU General Public
  4. * License. See the file "COPYING" in the main directory of this archive
  5. * for more details.
  6. *
  7. * Copyright (C) 1999 Helge Deller (07-13-1999)
  8. * Copyright (C) 1999 SuSE GmbH Nuernberg
  9. * Copyright (C) 2000 Philipp Rumpf (prumpf@tux.org)
  10. *
  11. * Cache and TLB management
  12. *
  13. */
  14. #include <linux/init.h>
  15. #include <linux/kernel.h>
  16. #include <linux/mm.h>
  17. #include <linux/module.h>
  18. #include <linux/seq_file.h>
  19. #include <linux/pagemap.h>
  20. #include <asm/pdc.h>
  21. #include <asm/cache.h>
  22. #include <asm/cacheflush.h>
  23. #include <asm/tlbflush.h>
  24. #include <asm/system.h>
  25. #include <asm/page.h>
  26. #include <asm/pgalloc.h>
  27. #include <asm/processor.h>
  28. int split_tlb;
  29. int dcache_stride;
  30. int icache_stride;
  31. EXPORT_SYMBOL(dcache_stride);
  32. #if defined(CONFIG_SMP)
  33. /* On some machines (e.g. ones with the Merced bus), there can be
  34. * only a single PxTLB broadcast at a time; this must be guaranteed
  35. * by software. We put a spinlock around all TLB flushes to
  36. * ensure this.
  37. */
  38. DEFINE_SPINLOCK(pa_tlb_lock);
  39. EXPORT_SYMBOL(pa_tlb_lock);
  40. #endif
  41. struct pdc_cache_info cache_info;
  42. #ifndef CONFIG_PA20
  43. static struct pdc_btlb_info btlb_info;
  44. #endif
  45. #ifdef CONFIG_SMP
  46. void
  47. flush_data_cache(void)
  48. {
  49. on_each_cpu((void (*)(void *))flush_data_cache_local, NULL, 1, 1);
  50. }
  51. void
  52. flush_instruction_cache(void)
  53. {
  54. on_each_cpu((void (*)(void *))flush_instruction_cache_local, NULL, 1, 1);
  55. }
  56. #endif
  57. void
  58. flush_cache_all_local(void)
  59. {
  60. flush_instruction_cache_local();
  61. flush_data_cache_local();
  62. }
  63. EXPORT_SYMBOL(flush_cache_all_local);
  64. /* flushes EVERYTHING (tlb & cache) */
  65. void
  66. flush_all_caches(void)
  67. {
  68. flush_cache_all();
  69. flush_tlb_all();
  70. }
  71. EXPORT_SYMBOL(flush_all_caches);
  72. void
  73. update_mmu_cache(struct vm_area_struct *vma, unsigned long address, pte_t pte)
  74. {
  75. struct page *page = pte_page(pte);
  76. if (pfn_valid(page_to_pfn(page)) && page_mapping(page) &&
  77. test_bit(PG_dcache_dirty, &page->flags)) {
  78. flush_kernel_dcache_page(page_address(page));
  79. clear_bit(PG_dcache_dirty, &page->flags);
  80. }
  81. }
  82. void
  83. show_cache_info(struct seq_file *m)
  84. {
  85. seq_printf(m, "I-cache\t\t: %ld KB\n",
  86. cache_info.ic_size/1024 );
  87. seq_printf(m, "D-cache\t\t: %ld KB (%s%s, %d-way associative)\n",
  88. cache_info.dc_size/1024,
  89. (cache_info.dc_conf.cc_wt ? "WT":"WB"),
  90. (cache_info.dc_conf.cc_sh ? ", shared I/D":""),
  91. (cache_info.dc_conf.cc_assoc)
  92. );
  93. seq_printf(m, "ITLB entries\t: %ld\n" "DTLB entries\t: %ld%s\n",
  94. cache_info.it_size,
  95. cache_info.dt_size,
  96. cache_info.dt_conf.tc_sh ? " - shared with ITLB":""
  97. );
  98. #ifndef CONFIG_PA20
  99. /* BTLB - Block TLB */
  100. if (btlb_info.max_size==0) {
  101. seq_printf(m, "BTLB\t\t: not supported\n" );
  102. } else {
  103. seq_printf(m,
  104. "BTLB fixed\t: max. %d pages, pagesize=%d (%dMB)\n"
  105. "BTLB fix-entr.\t: %d instruction, %d data (%d combined)\n"
  106. "BTLB var-entr.\t: %d instruction, %d data (%d combined)\n",
  107. btlb_info.max_size, (int)4096,
  108. btlb_info.max_size>>8,
  109. btlb_info.fixed_range_info.num_i,
  110. btlb_info.fixed_range_info.num_d,
  111. btlb_info.fixed_range_info.num_comb,
  112. btlb_info.variable_range_info.num_i,
  113. btlb_info.variable_range_info.num_d,
  114. btlb_info.variable_range_info.num_comb
  115. );
  116. }
  117. #endif
  118. }
  119. void __init
  120. parisc_cache_init(void)
  121. {
  122. if (pdc_cache_info(&cache_info) < 0)
  123. panic("parisc_cache_init: pdc_cache_info failed");
  124. #if 0
  125. printk("ic_size %lx dc_size %lx it_size %lx\n",
  126. cache_info.ic_size,
  127. cache_info.dc_size,
  128. cache_info.it_size);
  129. printk("DC base 0x%lx stride 0x%lx count 0x%lx loop 0x%lx\n",
  130. cache_info.dc_base,
  131. cache_info.dc_stride,
  132. cache_info.dc_count,
  133. cache_info.dc_loop);
  134. printk("dc_conf = 0x%lx alias %d blk %d line %d shift %d\n",
  135. *(unsigned long *) (&cache_info.dc_conf),
  136. cache_info.dc_conf.cc_alias,
  137. cache_info.dc_conf.cc_block,
  138. cache_info.dc_conf.cc_line,
  139. cache_info.dc_conf.cc_shift);
  140. printk(" wt %d sh %d cst %d assoc %d\n",
  141. cache_info.dc_conf.cc_wt,
  142. cache_info.dc_conf.cc_sh,
  143. cache_info.dc_conf.cc_cst,
  144. cache_info.dc_conf.cc_assoc);
  145. printk("IC base 0x%lx stride 0x%lx count 0x%lx loop 0x%lx\n",
  146. cache_info.ic_base,
  147. cache_info.ic_stride,
  148. cache_info.ic_count,
  149. cache_info.ic_loop);
  150. printk("ic_conf = 0x%lx alias %d blk %d line %d shift %d\n",
  151. *(unsigned long *) (&cache_info.ic_conf),
  152. cache_info.ic_conf.cc_alias,
  153. cache_info.ic_conf.cc_block,
  154. cache_info.ic_conf.cc_line,
  155. cache_info.ic_conf.cc_shift);
  156. printk(" wt %d sh %d cst %d assoc %d\n",
  157. cache_info.ic_conf.cc_wt,
  158. cache_info.ic_conf.cc_sh,
  159. cache_info.ic_conf.cc_cst,
  160. cache_info.ic_conf.cc_assoc);
  161. printk("D-TLB conf: sh %d page %d cst %d aid %d pad1 %d \n",
  162. cache_info.dt_conf.tc_sh,
  163. cache_info.dt_conf.tc_page,
  164. cache_info.dt_conf.tc_cst,
  165. cache_info.dt_conf.tc_aid,
  166. cache_info.dt_conf.tc_pad1);
  167. printk("I-TLB conf: sh %d page %d cst %d aid %d pad1 %d \n",
  168. cache_info.it_conf.tc_sh,
  169. cache_info.it_conf.tc_page,
  170. cache_info.it_conf.tc_cst,
  171. cache_info.it_conf.tc_aid,
  172. cache_info.it_conf.tc_pad1);
  173. #endif
  174. split_tlb = 0;
  175. if (cache_info.dt_conf.tc_sh == 0 || cache_info.dt_conf.tc_sh == 2) {
  176. if (cache_info.dt_conf.tc_sh == 2)
  177. printk(KERN_WARNING "Unexpected TLB configuration. "
  178. "Will flush I/D separately (could be optimized).\n");
  179. split_tlb = 1;
  180. }
  181. /* "New and Improved" version from Jim Hull
  182. * (1 << (cc_block-1)) * (cc_line << (4 + cnf.cc_shift))
  183. */
  184. #define CAFL_STRIDE(cnf) (cnf.cc_line << (3 + cnf.cc_block + cnf.cc_shift))
  185. dcache_stride = CAFL_STRIDE(cache_info.dc_conf);
  186. icache_stride = CAFL_STRIDE(cache_info.ic_conf);
  187. #undef CAFL_STRIDE
  188. #ifndef CONFIG_PA20
  189. if (pdc_btlb_info(&btlb_info) < 0) {
  190. memset(&btlb_info, 0, sizeof btlb_info);
  191. }
  192. #endif
  193. if ((boot_cpu_data.pdc.capabilities & PDC_MODEL_NVA_MASK) ==
  194. PDC_MODEL_NVA_UNSUPPORTED) {
  195. printk(KERN_WARNING "parisc_cache_init: Only equivalent aliasing supported!\n");
  196. #if 0
  197. panic("SMP kernel required to avoid non-equivalent aliasing");
  198. #endif
  199. }
  200. }
  201. void disable_sr_hashing(void)
  202. {
  203. int srhash_type;
  204. switch (boot_cpu_data.cpu_type) {
  205. case pcx: /* We shouldn't get this far. setup.c should prevent it. */
  206. BUG();
  207. return;
  208. case pcxs:
  209. case pcxt:
  210. case pcxt_:
  211. srhash_type = SRHASH_PCXST;
  212. break;
  213. case pcxl:
  214. srhash_type = SRHASH_PCXL;
  215. break;
  216. case pcxl2: /* pcxl2 doesn't support space register hashing */
  217. return;
  218. default: /* Currently all PA2.0 machines use the same ins. sequence */
  219. srhash_type = SRHASH_PA20;
  220. break;
  221. }
  222. disable_sr_hashing_asm(srhash_type);
  223. }
  224. void flush_dcache_page(struct page *page)
  225. {
  226. struct address_space *mapping = page_mapping(page);
  227. struct vm_area_struct *mpnt;
  228. struct prio_tree_iter iter;
  229. unsigned long offset;
  230. unsigned long addr;
  231. pgoff_t pgoff;
  232. pte_t *pte;
  233. unsigned long pfn = page_to_pfn(page);
  234. if (mapping && !mapping_mapped(mapping)) {
  235. set_bit(PG_dcache_dirty, &page->flags);
  236. return;
  237. }
  238. flush_kernel_dcache_page(page_address(page));
  239. if (!mapping)
  240. return;
  241. pgoff = page->index << (PAGE_CACHE_SHIFT - PAGE_SHIFT);
  242. /* We have carefully arranged in arch_get_unmapped_area() that
  243. * *any* mappings of a file are always congruently mapped (whether
  244. * declared as MAP_PRIVATE or MAP_SHARED), so we only need
  245. * to flush one address here for them all to become coherent */
  246. flush_dcache_mmap_lock(mapping);
  247. vma_prio_tree_foreach(mpnt, &iter, &mapping->i_mmap, pgoff, pgoff) {
  248. offset = (pgoff - mpnt->vm_pgoff) << PAGE_SHIFT;
  249. addr = mpnt->vm_start + offset;
  250. /* Flush instructions produce non access tlb misses.
  251. * On PA, we nullify these instructions rather than
  252. * taking a page fault if the pte doesn't exist.
  253. * This is just for speed. If the page translation
  254. * isn't there, there's no point exciting the
  255. * nadtlb handler into a nullification frenzy */
  256. if(!(pte = translation_exists(mpnt, addr)))
  257. continue;
  258. /* make sure we really have this page: the private
  259. * mappings may cover this area but have COW'd this
  260. * particular page */
  261. if(pte_pfn(*pte) != pfn)
  262. continue;
  263. __flush_cache_page(mpnt, addr);
  264. break;
  265. }
  266. flush_dcache_mmap_unlock(mapping);
  267. }
  268. EXPORT_SYMBOL(flush_dcache_page);
  269. /* Defined in arch/parisc/kernel/pacache.S */
  270. EXPORT_SYMBOL(flush_kernel_dcache_range_asm);
  271. EXPORT_SYMBOL(flush_kernel_dcache_page);
  272. EXPORT_SYMBOL(flush_data_cache_local);
  273. EXPORT_SYMBOL(flush_kernel_icache_range_asm);
  274. void clear_user_page_asm(void *page, unsigned long vaddr)
  275. {
  276. /* This function is implemented in assembly in pacache.S */
  277. extern void __clear_user_page_asm(void *page, unsigned long vaddr);
  278. purge_tlb_start();
  279. __clear_user_page_asm(page, vaddr);
  280. purge_tlb_end();
  281. }
  282. #define FLUSH_THRESHOLD 0x80000 /* 0.5MB */
  283. int parisc_cache_flush_threshold = FLUSH_THRESHOLD;
  284. void parisc_setup_cache_timing(void)
  285. {
  286. unsigned long rangetime, alltime;
  287. extern char _text; /* start of kernel code, defined by linker */
  288. extern char _end; /* end of BSS, defined by linker */
  289. unsigned long size;
  290. alltime = mfctl(16);
  291. flush_data_cache();
  292. alltime = mfctl(16) - alltime;
  293. size = (unsigned long)(&_end - _text);
  294. rangetime = mfctl(16);
  295. flush_kernel_dcache_range((unsigned long)&_text, size);
  296. rangetime = mfctl(16) - rangetime;
  297. printk(KERN_DEBUG "Whole cache flush %lu cycles, flushing %lu bytes %lu cycles\n",
  298. alltime, size, rangetime);
  299. /* Racy, but if we see an intermediate value, it's ok too... */
  300. parisc_cache_flush_threshold = size * alltime / rangetime;
  301. parisc_cache_flush_threshold = (parisc_cache_flush_threshold + L1_CACHE_BYTES - 1) &~ (L1_CACHE_BYTES - 1);
  302. if (!parisc_cache_flush_threshold)
  303. parisc_cache_flush_threshold = FLUSH_THRESHOLD;
  304. printk("Setting cache flush threshold to %x (%d CPUs online)\n", parisc_cache_flush_threshold, num_online_cpus());
  305. }