srmmu.c 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743
  1. /*
  2. * srmmu.c: SRMMU specific routines for memory management.
  3. *
  4. * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
  5. * Copyright (C) 1995,2002 Pete Zaitcev (zaitcev@yahoo.com)
  6. * Copyright (C) 1996 Eddie C. Dost (ecd@skynet.be)
  7. * Copyright (C) 1997,1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
  8. * Copyright (C) 1999,2000 Anton Blanchard (anton@samba.org)
  9. */
  10. #include <linux/kernel.h>
  11. #include <linux/mm.h>
  12. #include <linux/vmalloc.h>
  13. #include <linux/pagemap.h>
  14. #include <linux/init.h>
  15. #include <linux/spinlock.h>
  16. #include <linux/bootmem.h>
  17. #include <linux/fs.h>
  18. #include <linux/seq_file.h>
  19. #include <linux/kdebug.h>
  20. #include <linux/log2.h>
  21. #include <linux/gfp.h>
  22. #include <asm/bitext.h>
  23. #include <asm/page.h>
  24. #include <asm/pgalloc.h>
  25. #include <asm/pgtable.h>
  26. #include <asm/io.h>
  27. #include <asm/vaddrs.h>
  28. #include <asm/traps.h>
  29. #include <asm/smp.h>
  30. #include <asm/mbus.h>
  31. #include <asm/cache.h>
  32. #include <asm/oplib.h>
  33. #include <asm/asi.h>
  34. #include <asm/msi.h>
  35. #include <asm/mmu_context.h>
  36. #include <asm/io-unit.h>
  37. #include <asm/cacheflush.h>
  38. #include <asm/tlbflush.h>
  39. /* Now the cpu specific definitions. */
  40. #include <asm/viking.h>
  41. #include <asm/mxcc.h>
  42. #include <asm/ross.h>
  43. #include <asm/tsunami.h>
  44. #include <asm/swift.h>
  45. #include <asm/turbosparc.h>
  46. #include <asm/leon.h>
  47. #include "srmmu.h"
  48. enum mbus_module srmmu_modtype;
  49. static unsigned int hwbug_bitmask;
  50. int vac_cache_size;
  51. int vac_line_size;
  52. struct ctx_list *ctx_list_pool;
  53. struct ctx_list ctx_free;
  54. struct ctx_list ctx_used;
  55. extern struct resource sparc_iomap;
  56. extern unsigned long last_valid_pfn;
  57. static pgd_t *srmmu_swapper_pg_dir;
  58. const struct sparc32_cachetlb_ops *sparc32_cachetlb_ops;
  59. #ifdef CONFIG_SMP
  60. const struct sparc32_cachetlb_ops *local_ops;
  61. #define FLUSH_BEGIN(mm)
  62. #define FLUSH_END
  63. #else
  64. #define FLUSH_BEGIN(mm) if ((mm)->context != NO_CONTEXT) {
  65. #define FLUSH_END }
  66. #endif
  67. int flush_page_for_dma_global = 1;
  68. char *srmmu_name;
  69. ctxd_t *srmmu_ctx_table_phys;
  70. static ctxd_t *srmmu_context_table;
  71. int viking_mxcc_present;
  72. static DEFINE_SPINLOCK(srmmu_context_spinlock);
  73. static int is_hypersparc;
  74. static int srmmu_cache_pagetables;
  75. /* these will be initialized in srmmu_nocache_calcsize() */
  76. static unsigned long srmmu_nocache_size;
  77. static unsigned long srmmu_nocache_end;
  78. /* 1 bit <=> 256 bytes of nocache <=> 64 PTEs */
  79. #define SRMMU_NOCACHE_BITMAP_SHIFT (PAGE_SHIFT - 4)
  80. /* The context table is a nocache user with the biggest alignment needs. */
  81. #define SRMMU_NOCACHE_ALIGN_MAX (sizeof(ctxd_t)*SRMMU_MAX_CONTEXTS)
  82. void *srmmu_nocache_pool;
  83. void *srmmu_nocache_bitmap;
  84. static struct bit_map srmmu_nocache_map;
  85. static inline int srmmu_pmd_none(pmd_t pmd)
  86. { return !(pmd_val(pmd) & 0xFFFFFFF); }
  87. /* XXX should we hyper_flush_whole_icache here - Anton */
  88. static inline void srmmu_ctxd_set(ctxd_t *ctxp, pgd_t *pgdp)
  89. { set_pte((pte_t *)ctxp, (SRMMU_ET_PTD | (__nocache_pa((unsigned long) pgdp) >> 4))); }
  90. void pmd_set(pmd_t *pmdp, pte_t *ptep)
  91. {
  92. unsigned long ptp; /* Physical address, shifted right by 4 */
  93. int i;
  94. ptp = __nocache_pa((unsigned long) ptep) >> 4;
  95. for (i = 0; i < PTRS_PER_PTE/SRMMU_REAL_PTRS_PER_PTE; i++) {
  96. set_pte((pte_t *)&pmdp->pmdv[i], SRMMU_ET_PTD | ptp);
  97. ptp += (SRMMU_REAL_PTRS_PER_PTE*sizeof(pte_t) >> 4);
  98. }
  99. }
  100. void pmd_populate(struct mm_struct *mm, pmd_t *pmdp, struct page *ptep)
  101. {
  102. unsigned long ptp; /* Physical address, shifted right by 4 */
  103. int i;
  104. ptp = page_to_pfn(ptep) << (PAGE_SHIFT-4); /* watch for overflow */
  105. for (i = 0; i < PTRS_PER_PTE/SRMMU_REAL_PTRS_PER_PTE; i++) {
  106. set_pte((pte_t *)&pmdp->pmdv[i], SRMMU_ET_PTD | ptp);
  107. ptp += (SRMMU_REAL_PTRS_PER_PTE*sizeof(pte_t) >> 4);
  108. }
  109. }
  110. /* Find an entry in the third-level page table.. */
  111. pte_t *pte_offset_kernel(pmd_t * dir, unsigned long address)
  112. {
  113. void *pte;
  114. pte = __nocache_va((dir->pmdv[0] & SRMMU_PTD_PMASK) << 4);
  115. return (pte_t *) pte +
  116. ((address >> PAGE_SHIFT) & (PTRS_PER_PTE - 1));
  117. }
  118. /*
  119. * size: bytes to allocate in the nocache area.
  120. * align: bytes, number to align at.
  121. * Returns the virtual address of the allocated area.
  122. */
  123. static unsigned long __srmmu_get_nocache(int size, int align)
  124. {
  125. int offset;
  126. if (size < SRMMU_NOCACHE_BITMAP_SHIFT) {
  127. printk("Size 0x%x too small for nocache request\n", size);
  128. size = SRMMU_NOCACHE_BITMAP_SHIFT;
  129. }
  130. if (size & (SRMMU_NOCACHE_BITMAP_SHIFT-1)) {
  131. printk("Size 0x%x unaligned int nocache request\n", size);
  132. size += SRMMU_NOCACHE_BITMAP_SHIFT-1;
  133. }
  134. BUG_ON(align > SRMMU_NOCACHE_ALIGN_MAX);
  135. offset = bit_map_string_get(&srmmu_nocache_map,
  136. size >> SRMMU_NOCACHE_BITMAP_SHIFT,
  137. align >> SRMMU_NOCACHE_BITMAP_SHIFT);
  138. if (offset == -1) {
  139. printk("srmmu: out of nocache %d: %d/%d\n",
  140. size, (int) srmmu_nocache_size,
  141. srmmu_nocache_map.used << SRMMU_NOCACHE_BITMAP_SHIFT);
  142. return 0;
  143. }
  144. return (SRMMU_NOCACHE_VADDR + (offset << SRMMU_NOCACHE_BITMAP_SHIFT));
  145. }
  146. unsigned long srmmu_get_nocache(int size, int align)
  147. {
  148. unsigned long tmp;
  149. tmp = __srmmu_get_nocache(size, align);
  150. if (tmp)
  151. memset((void *)tmp, 0, size);
  152. return tmp;
  153. }
  154. void srmmu_free_nocache(unsigned long vaddr, int size)
  155. {
  156. int offset;
  157. if (vaddr < SRMMU_NOCACHE_VADDR) {
  158. printk("Vaddr %lx is smaller than nocache base 0x%lx\n",
  159. vaddr, (unsigned long)SRMMU_NOCACHE_VADDR);
  160. BUG();
  161. }
  162. if (vaddr+size > srmmu_nocache_end) {
  163. printk("Vaddr %lx is bigger than nocache end 0x%lx\n",
  164. vaddr, srmmu_nocache_end);
  165. BUG();
  166. }
  167. if (!is_power_of_2(size)) {
  168. printk("Size 0x%x is not a power of 2\n", size);
  169. BUG();
  170. }
  171. if (size < SRMMU_NOCACHE_BITMAP_SHIFT) {
  172. printk("Size 0x%x is too small\n", size);
  173. BUG();
  174. }
  175. if (vaddr & (size-1)) {
  176. printk("Vaddr %lx is not aligned to size 0x%x\n", vaddr, size);
  177. BUG();
  178. }
  179. offset = (vaddr - SRMMU_NOCACHE_VADDR) >> SRMMU_NOCACHE_BITMAP_SHIFT;
  180. size = size >> SRMMU_NOCACHE_BITMAP_SHIFT;
  181. bit_map_clear(&srmmu_nocache_map, offset, size);
  182. }
  183. static void srmmu_early_allocate_ptable_skeleton(unsigned long start,
  184. unsigned long end);
  185. extern unsigned long probe_memory(void); /* in fault.c */
  186. /*
  187. * Reserve nocache dynamically proportionally to the amount of
  188. * system RAM. -- Tomas Szepe <szepe@pinerecords.com>, June 2002
  189. */
  190. static void srmmu_nocache_calcsize(void)
  191. {
  192. unsigned long sysmemavail = probe_memory() / 1024;
  193. int srmmu_nocache_npages;
  194. srmmu_nocache_npages =
  195. sysmemavail / SRMMU_NOCACHE_ALCRATIO / 1024 * 256;
  196. /* P3 XXX The 4x overuse: corroborated by /proc/meminfo. */
  197. // if (srmmu_nocache_npages < 256) srmmu_nocache_npages = 256;
  198. if (srmmu_nocache_npages < SRMMU_MIN_NOCACHE_PAGES)
  199. srmmu_nocache_npages = SRMMU_MIN_NOCACHE_PAGES;
  200. /* anything above 1280 blows up */
  201. if (srmmu_nocache_npages > SRMMU_MAX_NOCACHE_PAGES)
  202. srmmu_nocache_npages = SRMMU_MAX_NOCACHE_PAGES;
  203. srmmu_nocache_size = srmmu_nocache_npages * PAGE_SIZE;
  204. srmmu_nocache_end = SRMMU_NOCACHE_VADDR + srmmu_nocache_size;
  205. }
  206. static void __init srmmu_nocache_init(void)
  207. {
  208. unsigned int bitmap_bits;
  209. pgd_t *pgd;
  210. pmd_t *pmd;
  211. pte_t *pte;
  212. unsigned long paddr, vaddr;
  213. unsigned long pteval;
  214. bitmap_bits = srmmu_nocache_size >> SRMMU_NOCACHE_BITMAP_SHIFT;
  215. srmmu_nocache_pool = __alloc_bootmem(srmmu_nocache_size,
  216. SRMMU_NOCACHE_ALIGN_MAX, 0UL);
  217. memset(srmmu_nocache_pool, 0, srmmu_nocache_size);
  218. srmmu_nocache_bitmap = __alloc_bootmem(bitmap_bits >> 3, SMP_CACHE_BYTES, 0UL);
  219. bit_map_init(&srmmu_nocache_map, srmmu_nocache_bitmap, bitmap_bits);
  220. srmmu_swapper_pg_dir = (pgd_t *)__srmmu_get_nocache(SRMMU_PGD_TABLE_SIZE, SRMMU_PGD_TABLE_SIZE);
  221. memset(__nocache_fix(srmmu_swapper_pg_dir), 0, SRMMU_PGD_TABLE_SIZE);
  222. init_mm.pgd = srmmu_swapper_pg_dir;
  223. srmmu_early_allocate_ptable_skeleton(SRMMU_NOCACHE_VADDR, srmmu_nocache_end);
  224. paddr = __pa((unsigned long)srmmu_nocache_pool);
  225. vaddr = SRMMU_NOCACHE_VADDR;
  226. while (vaddr < srmmu_nocache_end) {
  227. pgd = pgd_offset_k(vaddr);
  228. pmd = pmd_offset(__nocache_fix(pgd), vaddr);
  229. pte = pte_offset_kernel(__nocache_fix(pmd), vaddr);
  230. pteval = ((paddr >> 4) | SRMMU_ET_PTE | SRMMU_PRIV);
  231. if (srmmu_cache_pagetables)
  232. pteval |= SRMMU_CACHE;
  233. set_pte(__nocache_fix(pte), __pte(pteval));
  234. vaddr += PAGE_SIZE;
  235. paddr += PAGE_SIZE;
  236. }
  237. flush_cache_all();
  238. flush_tlb_all();
  239. }
  240. pgd_t *get_pgd_fast(void)
  241. {
  242. pgd_t *pgd = NULL;
  243. pgd = (pgd_t *)__srmmu_get_nocache(SRMMU_PGD_TABLE_SIZE, SRMMU_PGD_TABLE_SIZE);
  244. if (pgd) {
  245. pgd_t *init = pgd_offset_k(0);
  246. memset(pgd, 0, USER_PTRS_PER_PGD * sizeof(pgd_t));
  247. memcpy(pgd + USER_PTRS_PER_PGD, init + USER_PTRS_PER_PGD,
  248. (PTRS_PER_PGD - USER_PTRS_PER_PGD) * sizeof(pgd_t));
  249. }
  250. return pgd;
  251. }
  252. /*
  253. * Hardware needs alignment to 256 only, but we align to whole page size
  254. * to reduce fragmentation problems due to the buddy principle.
  255. * XXX Provide actual fragmentation statistics in /proc.
  256. *
  257. * Alignments up to the page size are the same for physical and virtual
  258. * addresses of the nocache area.
  259. */
  260. pgtable_t pte_alloc_one(struct mm_struct *mm, unsigned long address)
  261. {
  262. unsigned long pte;
  263. struct page *page;
  264. if ((pte = (unsigned long)pte_alloc_one_kernel(mm, address)) == 0)
  265. return NULL;
  266. page = pfn_to_page( __nocache_pa(pte) >> PAGE_SHIFT );
  267. pgtable_page_ctor(page);
  268. return page;
  269. }
  270. void pte_free(struct mm_struct *mm, pgtable_t pte)
  271. {
  272. unsigned long p;
  273. pgtable_page_dtor(pte);
  274. p = (unsigned long)page_address(pte); /* Cached address (for test) */
  275. if (p == 0)
  276. BUG();
  277. p = page_to_pfn(pte) << PAGE_SHIFT; /* Physical address */
  278. p = (unsigned long) __nocache_va(p); /* Nocached virtual */
  279. srmmu_free_nocache(p, PTE_SIZE);
  280. }
  281. /*
  282. */
  283. static inline void alloc_context(struct mm_struct *old_mm, struct mm_struct *mm)
  284. {
  285. struct ctx_list *ctxp;
  286. ctxp = ctx_free.next;
  287. if(ctxp != &ctx_free) {
  288. remove_from_ctx_list(ctxp);
  289. add_to_used_ctxlist(ctxp);
  290. mm->context = ctxp->ctx_number;
  291. ctxp->ctx_mm = mm;
  292. return;
  293. }
  294. ctxp = ctx_used.next;
  295. if(ctxp->ctx_mm == old_mm)
  296. ctxp = ctxp->next;
  297. if(ctxp == &ctx_used)
  298. panic("out of mmu contexts");
  299. flush_cache_mm(ctxp->ctx_mm);
  300. flush_tlb_mm(ctxp->ctx_mm);
  301. remove_from_ctx_list(ctxp);
  302. add_to_used_ctxlist(ctxp);
  303. ctxp->ctx_mm->context = NO_CONTEXT;
  304. ctxp->ctx_mm = mm;
  305. mm->context = ctxp->ctx_number;
  306. }
  307. static inline void free_context(int context)
  308. {
  309. struct ctx_list *ctx_old;
  310. ctx_old = ctx_list_pool + context;
  311. remove_from_ctx_list(ctx_old);
  312. add_to_free_ctxlist(ctx_old);
  313. }
  314. void switch_mm(struct mm_struct *old_mm, struct mm_struct *mm,
  315. struct task_struct *tsk)
  316. {
  317. if(mm->context == NO_CONTEXT) {
  318. spin_lock(&srmmu_context_spinlock);
  319. alloc_context(old_mm, mm);
  320. spin_unlock(&srmmu_context_spinlock);
  321. srmmu_ctxd_set(&srmmu_context_table[mm->context], mm->pgd);
  322. }
  323. if (sparc_cpu_model == sparc_leon)
  324. leon_switch_mm();
  325. if (is_hypersparc)
  326. hyper_flush_whole_icache();
  327. srmmu_set_context(mm->context);
  328. }
  329. /* Low level IO area allocation on the SRMMU. */
  330. static inline void srmmu_mapioaddr(unsigned long physaddr,
  331. unsigned long virt_addr, int bus_type)
  332. {
  333. pgd_t *pgdp;
  334. pmd_t *pmdp;
  335. pte_t *ptep;
  336. unsigned long tmp;
  337. physaddr &= PAGE_MASK;
  338. pgdp = pgd_offset_k(virt_addr);
  339. pmdp = pmd_offset(pgdp, virt_addr);
  340. ptep = pte_offset_kernel(pmdp, virt_addr);
  341. tmp = (physaddr >> 4) | SRMMU_ET_PTE;
  342. /*
  343. * I need to test whether this is consistent over all
  344. * sun4m's. The bus_type represents the upper 4 bits of
  345. * 36-bit physical address on the I/O space lines...
  346. */
  347. tmp |= (bus_type << 28);
  348. tmp |= SRMMU_PRIV;
  349. __flush_page_to_ram(virt_addr);
  350. set_pte(ptep, __pte(tmp));
  351. }
  352. void srmmu_mapiorange(unsigned int bus, unsigned long xpa,
  353. unsigned long xva, unsigned int len)
  354. {
  355. while (len != 0) {
  356. len -= PAGE_SIZE;
  357. srmmu_mapioaddr(xpa, xva, bus);
  358. xva += PAGE_SIZE;
  359. xpa += PAGE_SIZE;
  360. }
  361. flush_tlb_all();
  362. }
  363. static inline void srmmu_unmapioaddr(unsigned long virt_addr)
  364. {
  365. pgd_t *pgdp;
  366. pmd_t *pmdp;
  367. pte_t *ptep;
  368. pgdp = pgd_offset_k(virt_addr);
  369. pmdp = pmd_offset(pgdp, virt_addr);
  370. ptep = pte_offset_kernel(pmdp, virt_addr);
  371. /* No need to flush uncacheable page. */
  372. __pte_clear(ptep);
  373. }
  374. void srmmu_unmapiorange(unsigned long virt_addr, unsigned int len)
  375. {
  376. while (len != 0) {
  377. len -= PAGE_SIZE;
  378. srmmu_unmapioaddr(virt_addr);
  379. virt_addr += PAGE_SIZE;
  380. }
  381. flush_tlb_all();
  382. }
  383. /* tsunami.S */
  384. extern void tsunami_flush_cache_all(void);
  385. extern void tsunami_flush_cache_mm(struct mm_struct *mm);
  386. extern void tsunami_flush_cache_range(struct vm_area_struct *vma, unsigned long start, unsigned long end);
  387. extern void tsunami_flush_cache_page(struct vm_area_struct *vma, unsigned long page);
  388. extern void tsunami_flush_page_to_ram(unsigned long page);
  389. extern void tsunami_flush_page_for_dma(unsigned long page);
  390. extern void tsunami_flush_sig_insns(struct mm_struct *mm, unsigned long insn_addr);
  391. extern void tsunami_flush_tlb_all(void);
  392. extern void tsunami_flush_tlb_mm(struct mm_struct *mm);
  393. extern void tsunami_flush_tlb_range(struct vm_area_struct *vma, unsigned long start, unsigned long end);
  394. extern void tsunami_flush_tlb_page(struct vm_area_struct *vma, unsigned long page);
  395. extern void tsunami_setup_blockops(void);
  396. /* swift.S */
  397. extern void swift_flush_cache_all(void);
  398. extern void swift_flush_cache_mm(struct mm_struct *mm);
  399. extern void swift_flush_cache_range(struct vm_area_struct *vma,
  400. unsigned long start, unsigned long end);
  401. extern void swift_flush_cache_page(struct vm_area_struct *vma, unsigned long page);
  402. extern void swift_flush_page_to_ram(unsigned long page);
  403. extern void swift_flush_page_for_dma(unsigned long page);
  404. extern void swift_flush_sig_insns(struct mm_struct *mm, unsigned long insn_addr);
  405. extern void swift_flush_tlb_all(void);
  406. extern void swift_flush_tlb_mm(struct mm_struct *mm);
  407. extern void swift_flush_tlb_range(struct vm_area_struct *vma,
  408. unsigned long start, unsigned long end);
  409. extern void swift_flush_tlb_page(struct vm_area_struct *vma, unsigned long page);
  410. #if 0 /* P3: deadwood to debug precise flushes on Swift. */
  411. void swift_flush_tlb_page(struct vm_area_struct *vma, unsigned long page)
  412. {
  413. int cctx, ctx1;
  414. page &= PAGE_MASK;
  415. if ((ctx1 = vma->vm_mm->context) != -1) {
  416. cctx = srmmu_get_context();
  417. /* Is context # ever different from current context? P3 */
  418. if (cctx != ctx1) {
  419. printk("flush ctx %02x curr %02x\n", ctx1, cctx);
  420. srmmu_set_context(ctx1);
  421. swift_flush_page(page);
  422. __asm__ __volatile__("sta %%g0, [%0] %1\n\t" : :
  423. "r" (page), "i" (ASI_M_FLUSH_PROBE));
  424. srmmu_set_context(cctx);
  425. } else {
  426. /* Rm. prot. bits from virt. c. */
  427. /* swift_flush_cache_all(); */
  428. /* swift_flush_cache_page(vma, page); */
  429. swift_flush_page(page);
  430. __asm__ __volatile__("sta %%g0, [%0] %1\n\t" : :
  431. "r" (page), "i" (ASI_M_FLUSH_PROBE));
  432. /* same as above: srmmu_flush_tlb_page() */
  433. }
  434. }
  435. }
  436. #endif
  437. /*
  438. * The following are all MBUS based SRMMU modules, and therefore could
  439. * be found in a multiprocessor configuration. On the whole, these
  440. * chips seems to be much more touchy about DVMA and page tables
  441. * with respect to cache coherency.
  442. */
  443. /* viking.S */
  444. extern void viking_flush_cache_all(void);
  445. extern void viking_flush_cache_mm(struct mm_struct *mm);
  446. extern void viking_flush_cache_range(struct vm_area_struct *vma, unsigned long start,
  447. unsigned long end);
  448. extern void viking_flush_cache_page(struct vm_area_struct *vma, unsigned long page);
  449. extern void viking_flush_page_to_ram(unsigned long page);
  450. extern void viking_flush_page_for_dma(unsigned long page);
  451. extern void viking_flush_sig_insns(struct mm_struct *mm, unsigned long addr);
  452. extern void viking_flush_page(unsigned long page);
  453. extern void viking_mxcc_flush_page(unsigned long page);
  454. extern void viking_flush_tlb_all(void);
  455. extern void viking_flush_tlb_mm(struct mm_struct *mm);
  456. extern void viking_flush_tlb_range(struct vm_area_struct *vma, unsigned long start,
  457. unsigned long end);
  458. extern void viking_flush_tlb_page(struct vm_area_struct *vma,
  459. unsigned long page);
  460. extern void sun4dsmp_flush_tlb_all(void);
  461. extern void sun4dsmp_flush_tlb_mm(struct mm_struct *mm);
  462. extern void sun4dsmp_flush_tlb_range(struct vm_area_struct *vma, unsigned long start,
  463. unsigned long end);
  464. extern void sun4dsmp_flush_tlb_page(struct vm_area_struct *vma,
  465. unsigned long page);
  466. /* hypersparc.S */
  467. extern void hypersparc_flush_cache_all(void);
  468. extern void hypersparc_flush_cache_mm(struct mm_struct *mm);
  469. extern void hypersparc_flush_cache_range(struct vm_area_struct *vma, unsigned long start, unsigned long end);
  470. extern void hypersparc_flush_cache_page(struct vm_area_struct *vma, unsigned long page);
  471. extern void hypersparc_flush_page_to_ram(unsigned long page);
  472. extern void hypersparc_flush_page_for_dma(unsigned long page);
  473. extern void hypersparc_flush_sig_insns(struct mm_struct *mm, unsigned long insn_addr);
  474. extern void hypersparc_flush_tlb_all(void);
  475. extern void hypersparc_flush_tlb_mm(struct mm_struct *mm);
  476. extern void hypersparc_flush_tlb_range(struct vm_area_struct *vma, unsigned long start, unsigned long end);
  477. extern void hypersparc_flush_tlb_page(struct vm_area_struct *vma, unsigned long page);
  478. extern void hypersparc_setup_blockops(void);
  479. /*
  480. * NOTE: All of this startup code assumes the low 16mb (approx.) of
  481. * kernel mappings are done with one single contiguous chunk of
  482. * ram. On small ram machines (classics mainly) we only get
  483. * around 8mb mapped for us.
  484. */
  485. static void __init early_pgtable_allocfail(char *type)
  486. {
  487. prom_printf("inherit_prom_mappings: Cannot alloc kernel %s.\n", type);
  488. prom_halt();
  489. }
  490. static void __init srmmu_early_allocate_ptable_skeleton(unsigned long start,
  491. unsigned long end)
  492. {
  493. pgd_t *pgdp;
  494. pmd_t *pmdp;
  495. pte_t *ptep;
  496. while(start < end) {
  497. pgdp = pgd_offset_k(start);
  498. if (pgd_none(*(pgd_t *)__nocache_fix(pgdp))) {
  499. pmdp = (pmd_t *) __srmmu_get_nocache(
  500. SRMMU_PMD_TABLE_SIZE, SRMMU_PMD_TABLE_SIZE);
  501. if (pmdp == NULL)
  502. early_pgtable_allocfail("pmd");
  503. memset(__nocache_fix(pmdp), 0, SRMMU_PMD_TABLE_SIZE);
  504. pgd_set(__nocache_fix(pgdp), pmdp);
  505. }
  506. pmdp = pmd_offset(__nocache_fix(pgdp), start);
  507. if(srmmu_pmd_none(*(pmd_t *)__nocache_fix(pmdp))) {
  508. ptep = (pte_t *)__srmmu_get_nocache(PTE_SIZE, PTE_SIZE);
  509. if (ptep == NULL)
  510. early_pgtable_allocfail("pte");
  511. memset(__nocache_fix(ptep), 0, PTE_SIZE);
  512. pmd_set(__nocache_fix(pmdp), ptep);
  513. }
  514. if (start > (0xffffffffUL - PMD_SIZE))
  515. break;
  516. start = (start + PMD_SIZE) & PMD_MASK;
  517. }
  518. }
  519. static void __init srmmu_allocate_ptable_skeleton(unsigned long start,
  520. unsigned long end)
  521. {
  522. pgd_t *pgdp;
  523. pmd_t *pmdp;
  524. pte_t *ptep;
  525. while(start < end) {
  526. pgdp = pgd_offset_k(start);
  527. if (pgd_none(*pgdp)) {
  528. pmdp = (pmd_t *)__srmmu_get_nocache(SRMMU_PMD_TABLE_SIZE, SRMMU_PMD_TABLE_SIZE);
  529. if (pmdp == NULL)
  530. early_pgtable_allocfail("pmd");
  531. memset(pmdp, 0, SRMMU_PMD_TABLE_SIZE);
  532. pgd_set(pgdp, pmdp);
  533. }
  534. pmdp = pmd_offset(pgdp, start);
  535. if(srmmu_pmd_none(*pmdp)) {
  536. ptep = (pte_t *) __srmmu_get_nocache(PTE_SIZE,
  537. PTE_SIZE);
  538. if (ptep == NULL)
  539. early_pgtable_allocfail("pte");
  540. memset(ptep, 0, PTE_SIZE);
  541. pmd_set(pmdp, ptep);
  542. }
  543. if (start > (0xffffffffUL - PMD_SIZE))
  544. break;
  545. start = (start + PMD_SIZE) & PMD_MASK;
  546. }
  547. }
  548. /* These flush types are not available on all chips... */
  549. static inline unsigned long srmmu_probe(unsigned long vaddr)
  550. {
  551. unsigned long retval;
  552. if (sparc_cpu_model != sparc_leon) {
  553. vaddr &= PAGE_MASK;
  554. __asm__ __volatile__("lda [%1] %2, %0\n\t" :
  555. "=r" (retval) :
  556. "r" (vaddr | 0x400), "i" (ASI_M_FLUSH_PROBE));
  557. } else {
  558. retval = leon_swprobe(vaddr, 0);
  559. }
  560. return retval;
  561. }
  562. /*
  563. * This is much cleaner than poking around physical address space
  564. * looking at the prom's page table directly which is what most
  565. * other OS's do. Yuck... this is much better.
  566. */
  567. static void __init srmmu_inherit_prom_mappings(unsigned long start,
  568. unsigned long end)
  569. {
  570. pgd_t *pgdp;
  571. pmd_t *pmdp;
  572. pte_t *ptep;
  573. int what = 0; /* 0 = normal-pte, 1 = pmd-level pte, 2 = pgd-level pte */
  574. unsigned long prompte;
  575. while(start <= end) {
  576. if (start == 0)
  577. break; /* probably wrap around */
  578. if(start == 0xfef00000)
  579. start = KADB_DEBUGGER_BEGVM;
  580. if(!(prompte = srmmu_probe(start))) {
  581. start += PAGE_SIZE;
  582. continue;
  583. }
  584. /* A red snapper, see what it really is. */
  585. what = 0;
  586. if(!(start & ~(SRMMU_REAL_PMD_MASK))) {
  587. if(srmmu_probe((start-PAGE_SIZE) + SRMMU_REAL_PMD_SIZE) == prompte)
  588. what = 1;
  589. }
  590. if(!(start & ~(SRMMU_PGDIR_MASK))) {
  591. if(srmmu_probe((start-PAGE_SIZE) + SRMMU_PGDIR_SIZE) ==
  592. prompte)
  593. what = 2;
  594. }
  595. pgdp = pgd_offset_k(start);
  596. if(what == 2) {
  597. *(pgd_t *)__nocache_fix(pgdp) = __pgd(prompte);
  598. start += SRMMU_PGDIR_SIZE;
  599. continue;
  600. }
  601. if (pgd_none(*(pgd_t *)__nocache_fix(pgdp))) {
  602. pmdp = (pmd_t *)__srmmu_get_nocache(SRMMU_PMD_TABLE_SIZE, SRMMU_PMD_TABLE_SIZE);
  603. if (pmdp == NULL)
  604. early_pgtable_allocfail("pmd");
  605. memset(__nocache_fix(pmdp), 0, SRMMU_PMD_TABLE_SIZE);
  606. pgd_set(__nocache_fix(pgdp), pmdp);
  607. }
  608. pmdp = pmd_offset(__nocache_fix(pgdp), start);
  609. if(srmmu_pmd_none(*(pmd_t *)__nocache_fix(pmdp))) {
  610. ptep = (pte_t *) __srmmu_get_nocache(PTE_SIZE,
  611. PTE_SIZE);
  612. if (ptep == NULL)
  613. early_pgtable_allocfail("pte");
  614. memset(__nocache_fix(ptep), 0, PTE_SIZE);
  615. pmd_set(__nocache_fix(pmdp), ptep);
  616. }
  617. if(what == 1) {
  618. /*
  619. * We bend the rule where all 16 PTPs in a pmd_t point
  620. * inside the same PTE page, and we leak a perfectly
  621. * good hardware PTE piece. Alternatives seem worse.
  622. */
  623. unsigned int x; /* Index of HW PMD in soft cluster */
  624. x = (start >> PMD_SHIFT) & 15;
  625. *(unsigned long *)__nocache_fix(&pmdp->pmdv[x]) = prompte;
  626. start += SRMMU_REAL_PMD_SIZE;
  627. continue;
  628. }
  629. ptep = pte_offset_kernel(__nocache_fix(pmdp), start);
  630. *(pte_t *)__nocache_fix(ptep) = __pte(prompte);
  631. start += PAGE_SIZE;
  632. }
  633. }
  634. #define KERNEL_PTE(page_shifted) ((page_shifted)|SRMMU_CACHE|SRMMU_PRIV|SRMMU_VALID)
  635. /* Create a third-level SRMMU 16MB page mapping. */
  636. static void __init do_large_mapping(unsigned long vaddr, unsigned long phys_base)
  637. {
  638. pgd_t *pgdp = pgd_offset_k(vaddr);
  639. unsigned long big_pte;
  640. big_pte = KERNEL_PTE(phys_base >> 4);
  641. *(pgd_t *)__nocache_fix(pgdp) = __pgd(big_pte);
  642. }
  643. /* Map sp_bank entry SP_ENTRY, starting at virtual address VBASE. */
  644. static unsigned long __init map_spbank(unsigned long vbase, int sp_entry)
  645. {
  646. unsigned long pstart = (sp_banks[sp_entry].base_addr & SRMMU_PGDIR_MASK);
  647. unsigned long vstart = (vbase & SRMMU_PGDIR_MASK);
  648. unsigned long vend = SRMMU_PGDIR_ALIGN(vbase + sp_banks[sp_entry].num_bytes);
  649. /* Map "low" memory only */
  650. const unsigned long min_vaddr = PAGE_OFFSET;
  651. const unsigned long max_vaddr = PAGE_OFFSET + SRMMU_MAXMEM;
  652. if (vstart < min_vaddr || vstart >= max_vaddr)
  653. return vstart;
  654. if (vend > max_vaddr || vend < min_vaddr)
  655. vend = max_vaddr;
  656. while(vstart < vend) {
  657. do_large_mapping(vstart, pstart);
  658. vstart += SRMMU_PGDIR_SIZE; pstart += SRMMU_PGDIR_SIZE;
  659. }
  660. return vstart;
  661. }
  662. static inline void map_kernel(void)
  663. {
  664. int i;
  665. if (phys_base > 0) {
  666. do_large_mapping(PAGE_OFFSET, phys_base);
  667. }
  668. for (i = 0; sp_banks[i].num_bytes != 0; i++) {
  669. map_spbank((unsigned long)__va(sp_banks[i].base_addr), i);
  670. }
  671. }
  672. /* Paging initialization on the Sparc Reference MMU. */
  673. extern void sparc_context_init(int);
  674. void (*poke_srmmu)(void) __cpuinitdata = NULL;
  675. extern unsigned long bootmem_init(unsigned long *pages_avail);
  676. void __init srmmu_paging_init(void)
  677. {
  678. int i;
  679. phandle cpunode;
  680. char node_str[128];
  681. pgd_t *pgd;
  682. pmd_t *pmd;
  683. pte_t *pte;
  684. unsigned long pages_avail;
  685. sparc_iomap.start = SUN4M_IOBASE_VADDR; /* 16MB of IOSPACE on all sun4m's. */
  686. if (sparc_cpu_model == sun4d)
  687. num_contexts = 65536; /* We know it is Viking */
  688. else {
  689. /* Find the number of contexts on the srmmu. */
  690. cpunode = prom_getchild(prom_root_node);
  691. num_contexts = 0;
  692. while(cpunode != 0) {
  693. prom_getstring(cpunode, "device_type", node_str, sizeof(node_str));
  694. if(!strcmp(node_str, "cpu")) {
  695. num_contexts = prom_getintdefault(cpunode, "mmu-nctx", 0x8);
  696. break;
  697. }
  698. cpunode = prom_getsibling(cpunode);
  699. }
  700. }
  701. if(!num_contexts) {
  702. prom_printf("Something wrong, can't find cpu node in paging_init.\n");
  703. prom_halt();
  704. }
  705. pages_avail = 0;
  706. last_valid_pfn = bootmem_init(&pages_avail);
  707. srmmu_nocache_calcsize();
  708. srmmu_nocache_init();
  709. srmmu_inherit_prom_mappings(0xfe400000,(LINUX_OPPROM_ENDVM-PAGE_SIZE));
  710. map_kernel();
  711. /* ctx table has to be physically aligned to its size */
  712. srmmu_context_table = (ctxd_t *)__srmmu_get_nocache(num_contexts*sizeof(ctxd_t), num_contexts*sizeof(ctxd_t));
  713. srmmu_ctx_table_phys = (ctxd_t *)__nocache_pa((unsigned long)srmmu_context_table);
  714. for(i = 0; i < num_contexts; i++)
  715. srmmu_ctxd_set((ctxd_t *)__nocache_fix(&srmmu_context_table[i]), srmmu_swapper_pg_dir);
  716. flush_cache_all();
  717. srmmu_set_ctable_ptr((unsigned long)srmmu_ctx_table_phys);
  718. #ifdef CONFIG_SMP
  719. /* Stop from hanging here... */
  720. local_ops->tlb_all();
  721. #else
  722. flush_tlb_all();
  723. #endif
  724. poke_srmmu();
  725. srmmu_allocate_ptable_skeleton(sparc_iomap.start, IOBASE_END);
  726. srmmu_allocate_ptable_skeleton(DVMA_VADDR, DVMA_END);
  727. srmmu_allocate_ptable_skeleton(
  728. __fix_to_virt(__end_of_fixed_addresses - 1), FIXADDR_TOP);
  729. srmmu_allocate_ptable_skeleton(PKMAP_BASE, PKMAP_END);
  730. pgd = pgd_offset_k(PKMAP_BASE);
  731. pmd = pmd_offset(pgd, PKMAP_BASE);
  732. pte = pte_offset_kernel(pmd, PKMAP_BASE);
  733. pkmap_page_table = pte;
  734. flush_cache_all();
  735. flush_tlb_all();
  736. sparc_context_init(num_contexts);
  737. kmap_init();
  738. {
  739. unsigned long zones_size[MAX_NR_ZONES];
  740. unsigned long zholes_size[MAX_NR_ZONES];
  741. unsigned long npages;
  742. int znum;
  743. for (znum = 0; znum < MAX_NR_ZONES; znum++)
  744. zones_size[znum] = zholes_size[znum] = 0;
  745. npages = max_low_pfn - pfn_base;
  746. zones_size[ZONE_DMA] = npages;
  747. zholes_size[ZONE_DMA] = npages - pages_avail;
  748. npages = highend_pfn - max_low_pfn;
  749. zones_size[ZONE_HIGHMEM] = npages;
  750. zholes_size[ZONE_HIGHMEM] = npages - calc_highpages();
  751. free_area_init_node(0, zones_size, pfn_base, zholes_size);
  752. }
  753. }
  754. void mmu_info(struct seq_file *m)
  755. {
  756. seq_printf(m,
  757. "MMU type\t: %s\n"
  758. "contexts\t: %d\n"
  759. "nocache total\t: %ld\n"
  760. "nocache used\t: %d\n",
  761. srmmu_name,
  762. num_contexts,
  763. srmmu_nocache_size,
  764. srmmu_nocache_map.used << SRMMU_NOCACHE_BITMAP_SHIFT);
  765. }
  766. void destroy_context(struct mm_struct *mm)
  767. {
  768. if(mm->context != NO_CONTEXT) {
  769. flush_cache_mm(mm);
  770. srmmu_ctxd_set(&srmmu_context_table[mm->context], srmmu_swapper_pg_dir);
  771. flush_tlb_mm(mm);
  772. spin_lock(&srmmu_context_spinlock);
  773. free_context(mm->context);
  774. spin_unlock(&srmmu_context_spinlock);
  775. mm->context = NO_CONTEXT;
  776. }
  777. }
  778. /* Init various srmmu chip types. */
  779. static void __init srmmu_is_bad(void)
  780. {
  781. prom_printf("Could not determine SRMMU chip type.\n");
  782. prom_halt();
  783. }
  784. static void __init init_vac_layout(void)
  785. {
  786. phandle nd;
  787. int cache_lines;
  788. char node_str[128];
  789. #ifdef CONFIG_SMP
  790. int cpu = 0;
  791. unsigned long max_size = 0;
  792. unsigned long min_line_size = 0x10000000;
  793. #endif
  794. nd = prom_getchild(prom_root_node);
  795. while((nd = prom_getsibling(nd)) != 0) {
  796. prom_getstring(nd, "device_type", node_str, sizeof(node_str));
  797. if(!strcmp(node_str, "cpu")) {
  798. vac_line_size = prom_getint(nd, "cache-line-size");
  799. if (vac_line_size == -1) {
  800. prom_printf("can't determine cache-line-size, "
  801. "halting.\n");
  802. prom_halt();
  803. }
  804. cache_lines = prom_getint(nd, "cache-nlines");
  805. if (cache_lines == -1) {
  806. prom_printf("can't determine cache-nlines, halting.\n");
  807. prom_halt();
  808. }
  809. vac_cache_size = cache_lines * vac_line_size;
  810. #ifdef CONFIG_SMP
  811. if(vac_cache_size > max_size)
  812. max_size = vac_cache_size;
  813. if(vac_line_size < min_line_size)
  814. min_line_size = vac_line_size;
  815. //FIXME: cpus not contiguous!!
  816. cpu++;
  817. if (cpu >= nr_cpu_ids || !cpu_online(cpu))
  818. break;
  819. #else
  820. break;
  821. #endif
  822. }
  823. }
  824. if(nd == 0) {
  825. prom_printf("No CPU nodes found, halting.\n");
  826. prom_halt();
  827. }
  828. #ifdef CONFIG_SMP
  829. vac_cache_size = max_size;
  830. vac_line_size = min_line_size;
  831. #endif
  832. printk("SRMMU: Using VAC size of %d bytes, line size %d bytes.\n",
  833. (int)vac_cache_size, (int)vac_line_size);
  834. }
  835. static void __cpuinit poke_hypersparc(void)
  836. {
  837. volatile unsigned long clear;
  838. unsigned long mreg = srmmu_get_mmureg();
  839. hyper_flush_unconditional_combined();
  840. mreg &= ~(HYPERSPARC_CWENABLE);
  841. mreg |= (HYPERSPARC_CENABLE | HYPERSPARC_WBENABLE);
  842. mreg |= (HYPERSPARC_CMODE);
  843. srmmu_set_mmureg(mreg);
  844. #if 0 /* XXX I think this is bad news... -DaveM */
  845. hyper_clear_all_tags();
  846. #endif
  847. put_ross_icr(HYPERSPARC_ICCR_FTD | HYPERSPARC_ICCR_ICE);
  848. hyper_flush_whole_icache();
  849. clear = srmmu_get_faddr();
  850. clear = srmmu_get_fstatus();
  851. }
  852. static const struct sparc32_cachetlb_ops hypersparc_ops = {
  853. .cache_all = hypersparc_flush_cache_all,
  854. .cache_mm = hypersparc_flush_cache_mm,
  855. .cache_page = hypersparc_flush_cache_page,
  856. .cache_range = hypersparc_flush_cache_range,
  857. .tlb_all = hypersparc_flush_tlb_all,
  858. .tlb_mm = hypersparc_flush_tlb_mm,
  859. .tlb_page = hypersparc_flush_tlb_page,
  860. .tlb_range = hypersparc_flush_tlb_range,
  861. .page_to_ram = hypersparc_flush_page_to_ram,
  862. .sig_insns = hypersparc_flush_sig_insns,
  863. .page_for_dma = hypersparc_flush_page_for_dma,
  864. };
  865. static void __init init_hypersparc(void)
  866. {
  867. srmmu_name = "ROSS HyperSparc";
  868. srmmu_modtype = HyperSparc;
  869. init_vac_layout();
  870. is_hypersparc = 1;
  871. sparc32_cachetlb_ops = &hypersparc_ops;
  872. poke_srmmu = poke_hypersparc;
  873. hypersparc_setup_blockops();
  874. }
  875. static void __cpuinit poke_swift(void)
  876. {
  877. unsigned long mreg;
  878. /* Clear any crap from the cache or else... */
  879. swift_flush_cache_all();
  880. /* Enable I & D caches */
  881. mreg = srmmu_get_mmureg();
  882. mreg |= (SWIFT_IE | SWIFT_DE);
  883. /*
  884. * The Swift branch folding logic is completely broken. At
  885. * trap time, if things are just right, if can mistakenly
  886. * think that a trap is coming from kernel mode when in fact
  887. * it is coming from user mode (it mis-executes the branch in
  888. * the trap code). So you see things like crashme completely
  889. * hosing your machine which is completely unacceptable. Turn
  890. * this shit off... nice job Fujitsu.
  891. */
  892. mreg &= ~(SWIFT_BF);
  893. srmmu_set_mmureg(mreg);
  894. }
  895. static const struct sparc32_cachetlb_ops swift_ops = {
  896. .cache_all = swift_flush_cache_all,
  897. .cache_mm = swift_flush_cache_mm,
  898. .cache_page = swift_flush_cache_page,
  899. .cache_range = swift_flush_cache_range,
  900. .tlb_all = swift_flush_tlb_all,
  901. .tlb_mm = swift_flush_tlb_mm,
  902. .tlb_page = swift_flush_tlb_page,
  903. .tlb_range = swift_flush_tlb_range,
  904. .page_to_ram = swift_flush_page_to_ram,
  905. .sig_insns = swift_flush_sig_insns,
  906. .page_for_dma = swift_flush_page_for_dma,
  907. };
  908. #define SWIFT_MASKID_ADDR 0x10003018
  909. static void __init init_swift(void)
  910. {
  911. unsigned long swift_rev;
  912. __asm__ __volatile__("lda [%1] %2, %0\n\t"
  913. "srl %0, 0x18, %0\n\t" :
  914. "=r" (swift_rev) :
  915. "r" (SWIFT_MASKID_ADDR), "i" (ASI_M_BYPASS));
  916. srmmu_name = "Fujitsu Swift";
  917. switch(swift_rev) {
  918. case 0x11:
  919. case 0x20:
  920. case 0x23:
  921. case 0x30:
  922. srmmu_modtype = Swift_lots_o_bugs;
  923. hwbug_bitmask |= (HWBUG_KERN_ACCBROKEN | HWBUG_KERN_CBITBROKEN);
  924. /*
  925. * Gee george, I wonder why Sun is so hush hush about
  926. * this hardware bug... really braindamage stuff going
  927. * on here. However I think we can find a way to avoid
  928. * all of the workaround overhead under Linux. Basically,
  929. * any page fault can cause kernel pages to become user
  930. * accessible (the mmu gets confused and clears some of
  931. * the ACC bits in kernel ptes). Aha, sounds pretty
  932. * horrible eh? But wait, after extensive testing it appears
  933. * that if you use pgd_t level large kernel pte's (like the
  934. * 4MB pages on the Pentium) the bug does not get tripped
  935. * at all. This avoids almost all of the major overhead.
  936. * Welcome to a world where your vendor tells you to,
  937. * "apply this kernel patch" instead of "sorry for the
  938. * broken hardware, send it back and we'll give you
  939. * properly functioning parts"
  940. */
  941. break;
  942. case 0x25:
  943. case 0x31:
  944. srmmu_modtype = Swift_bad_c;
  945. hwbug_bitmask |= HWBUG_KERN_CBITBROKEN;
  946. /*
  947. * You see Sun allude to this hardware bug but never
  948. * admit things directly, they'll say things like,
  949. * "the Swift chip cache problems" or similar.
  950. */
  951. break;
  952. default:
  953. srmmu_modtype = Swift_ok;
  954. break;
  955. }
  956. sparc32_cachetlb_ops = &swift_ops;
  957. flush_page_for_dma_global = 0;
  958. /*
  959. * Are you now convinced that the Swift is one of the
  960. * biggest VLSI abortions of all time? Bravo Fujitsu!
  961. * Fujitsu, the !#?!%$'d up processor people. I bet if
  962. * you examined the microcode of the Swift you'd find
  963. * XXX's all over the place.
  964. */
  965. poke_srmmu = poke_swift;
  966. }
  967. static void turbosparc_flush_cache_all(void)
  968. {
  969. flush_user_windows();
  970. turbosparc_idflash_clear();
  971. }
  972. static void turbosparc_flush_cache_mm(struct mm_struct *mm)
  973. {
  974. FLUSH_BEGIN(mm)
  975. flush_user_windows();
  976. turbosparc_idflash_clear();
  977. FLUSH_END
  978. }
  979. static void turbosparc_flush_cache_range(struct vm_area_struct *vma, unsigned long start, unsigned long end)
  980. {
  981. FLUSH_BEGIN(vma->vm_mm)
  982. flush_user_windows();
  983. turbosparc_idflash_clear();
  984. FLUSH_END
  985. }
  986. static void turbosparc_flush_cache_page(struct vm_area_struct *vma, unsigned long page)
  987. {
  988. FLUSH_BEGIN(vma->vm_mm)
  989. flush_user_windows();
  990. if (vma->vm_flags & VM_EXEC)
  991. turbosparc_flush_icache();
  992. turbosparc_flush_dcache();
  993. FLUSH_END
  994. }
  995. /* TurboSparc is copy-back, if we turn it on, but this does not work. */
  996. static void turbosparc_flush_page_to_ram(unsigned long page)
  997. {
  998. #ifdef TURBOSPARC_WRITEBACK
  999. volatile unsigned long clear;
  1000. if (srmmu_probe(page))
  1001. turbosparc_flush_page_cache(page);
  1002. clear = srmmu_get_fstatus();
  1003. #endif
  1004. }
  1005. static void turbosparc_flush_sig_insns(struct mm_struct *mm, unsigned long insn_addr)
  1006. {
  1007. }
  1008. static void turbosparc_flush_page_for_dma(unsigned long page)
  1009. {
  1010. turbosparc_flush_dcache();
  1011. }
  1012. static void turbosparc_flush_tlb_all(void)
  1013. {
  1014. srmmu_flush_whole_tlb();
  1015. }
  1016. static void turbosparc_flush_tlb_mm(struct mm_struct *mm)
  1017. {
  1018. FLUSH_BEGIN(mm)
  1019. srmmu_flush_whole_tlb();
  1020. FLUSH_END
  1021. }
  1022. static void turbosparc_flush_tlb_range(struct vm_area_struct *vma, unsigned long start, unsigned long end)
  1023. {
  1024. FLUSH_BEGIN(vma->vm_mm)
  1025. srmmu_flush_whole_tlb();
  1026. FLUSH_END
  1027. }
  1028. static void turbosparc_flush_tlb_page(struct vm_area_struct *vma, unsigned long page)
  1029. {
  1030. FLUSH_BEGIN(vma->vm_mm)
  1031. srmmu_flush_whole_tlb();
  1032. FLUSH_END
  1033. }
  1034. static void __cpuinit poke_turbosparc(void)
  1035. {
  1036. unsigned long mreg = srmmu_get_mmureg();
  1037. unsigned long ccreg;
  1038. /* Clear any crap from the cache or else... */
  1039. turbosparc_flush_cache_all();
  1040. mreg &= ~(TURBOSPARC_ICENABLE | TURBOSPARC_DCENABLE); /* Temporarily disable I & D caches */
  1041. mreg &= ~(TURBOSPARC_PCENABLE); /* Don't check parity */
  1042. srmmu_set_mmureg(mreg);
  1043. ccreg = turbosparc_get_ccreg();
  1044. #ifdef TURBOSPARC_WRITEBACK
  1045. ccreg |= (TURBOSPARC_SNENABLE); /* Do DVMA snooping in Dcache */
  1046. ccreg &= ~(TURBOSPARC_uS2 | TURBOSPARC_WTENABLE);
  1047. /* Write-back D-cache, emulate VLSI
  1048. * abortion number three, not number one */
  1049. #else
  1050. /* For now let's play safe, optimize later */
  1051. ccreg |= (TURBOSPARC_SNENABLE | TURBOSPARC_WTENABLE);
  1052. /* Do DVMA snooping in Dcache, Write-thru D-cache */
  1053. ccreg &= ~(TURBOSPARC_uS2);
  1054. /* Emulate VLSI abortion number three, not number one */
  1055. #endif
  1056. switch (ccreg & 7) {
  1057. case 0: /* No SE cache */
  1058. case 7: /* Test mode */
  1059. break;
  1060. default:
  1061. ccreg |= (TURBOSPARC_SCENABLE);
  1062. }
  1063. turbosparc_set_ccreg (ccreg);
  1064. mreg |= (TURBOSPARC_ICENABLE | TURBOSPARC_DCENABLE); /* I & D caches on */
  1065. mreg |= (TURBOSPARC_ICSNOOP); /* Icache snooping on */
  1066. srmmu_set_mmureg(mreg);
  1067. }
  1068. static const struct sparc32_cachetlb_ops turbosparc_ops = {
  1069. .cache_all = turbosparc_flush_cache_all,
  1070. .cache_mm = turbosparc_flush_cache_mm,
  1071. .cache_page = turbosparc_flush_cache_page,
  1072. .cache_range = turbosparc_flush_cache_range,
  1073. .tlb_all = turbosparc_flush_tlb_all,
  1074. .tlb_mm = turbosparc_flush_tlb_mm,
  1075. .tlb_page = turbosparc_flush_tlb_page,
  1076. .tlb_range = turbosparc_flush_tlb_range,
  1077. .page_to_ram = turbosparc_flush_page_to_ram,
  1078. .sig_insns = turbosparc_flush_sig_insns,
  1079. .page_for_dma = turbosparc_flush_page_for_dma,
  1080. };
  1081. static void __init init_turbosparc(void)
  1082. {
  1083. srmmu_name = "Fujitsu TurboSparc";
  1084. srmmu_modtype = TurboSparc;
  1085. sparc32_cachetlb_ops = &turbosparc_ops;
  1086. poke_srmmu = poke_turbosparc;
  1087. }
  1088. static void __cpuinit poke_tsunami(void)
  1089. {
  1090. unsigned long mreg = srmmu_get_mmureg();
  1091. tsunami_flush_icache();
  1092. tsunami_flush_dcache();
  1093. mreg &= ~TSUNAMI_ITD;
  1094. mreg |= (TSUNAMI_IENAB | TSUNAMI_DENAB);
  1095. srmmu_set_mmureg(mreg);
  1096. }
  1097. static const struct sparc32_cachetlb_ops tsunami_ops = {
  1098. .cache_all = tsunami_flush_cache_all,
  1099. .cache_mm = tsunami_flush_cache_mm,
  1100. .cache_page = tsunami_flush_cache_page,
  1101. .cache_range = tsunami_flush_cache_range,
  1102. .tlb_all = tsunami_flush_tlb_all,
  1103. .tlb_mm = tsunami_flush_tlb_mm,
  1104. .tlb_page = tsunami_flush_tlb_page,
  1105. .tlb_range = tsunami_flush_tlb_range,
  1106. .page_to_ram = tsunami_flush_page_to_ram,
  1107. .sig_insns = tsunami_flush_sig_insns,
  1108. .page_for_dma = tsunami_flush_page_for_dma,
  1109. };
  1110. static void __init init_tsunami(void)
  1111. {
  1112. /*
  1113. * Tsunami's pretty sane, Sun and TI actually got it
  1114. * somewhat right this time. Fujitsu should have
  1115. * taken some lessons from them.
  1116. */
  1117. srmmu_name = "TI Tsunami";
  1118. srmmu_modtype = Tsunami;
  1119. sparc32_cachetlb_ops = &tsunami_ops;
  1120. poke_srmmu = poke_tsunami;
  1121. tsunami_setup_blockops();
  1122. }
  1123. static void __cpuinit poke_viking(void)
  1124. {
  1125. unsigned long mreg = srmmu_get_mmureg();
  1126. static int smp_catch;
  1127. if (viking_mxcc_present) {
  1128. unsigned long mxcc_control = mxcc_get_creg();
  1129. mxcc_control |= (MXCC_CTL_ECE | MXCC_CTL_PRE | MXCC_CTL_MCE);
  1130. mxcc_control &= ~(MXCC_CTL_RRC);
  1131. mxcc_set_creg(mxcc_control);
  1132. /*
  1133. * We don't need memory parity checks.
  1134. * XXX This is a mess, have to dig out later. ecd.
  1135. viking_mxcc_turn_off_parity(&mreg, &mxcc_control);
  1136. */
  1137. /* We do cache ptables on MXCC. */
  1138. mreg |= VIKING_TCENABLE;
  1139. } else {
  1140. unsigned long bpreg;
  1141. mreg &= ~(VIKING_TCENABLE);
  1142. if(smp_catch++) {
  1143. /* Must disable mixed-cmd mode here for other cpu's. */
  1144. bpreg = viking_get_bpreg();
  1145. bpreg &= ~(VIKING_ACTION_MIX);
  1146. viking_set_bpreg(bpreg);
  1147. /* Just in case PROM does something funny. */
  1148. msi_set_sync();
  1149. }
  1150. }
  1151. mreg |= VIKING_SPENABLE;
  1152. mreg |= (VIKING_ICENABLE | VIKING_DCENABLE);
  1153. mreg |= VIKING_SBENABLE;
  1154. mreg &= ~(VIKING_ACENABLE);
  1155. srmmu_set_mmureg(mreg);
  1156. }
  1157. static struct sparc32_cachetlb_ops viking_ops = {
  1158. .cache_all = viking_flush_cache_all,
  1159. .cache_mm = viking_flush_cache_mm,
  1160. .cache_page = viking_flush_cache_page,
  1161. .cache_range = viking_flush_cache_range,
  1162. .tlb_all = viking_flush_tlb_all,
  1163. .tlb_mm = viking_flush_tlb_mm,
  1164. .tlb_page = viking_flush_tlb_page,
  1165. .tlb_range = viking_flush_tlb_range,
  1166. .page_to_ram = viking_flush_page_to_ram,
  1167. .sig_insns = viking_flush_sig_insns,
  1168. .page_for_dma = viking_flush_page_for_dma,
  1169. };
  1170. #ifdef CONFIG_SMP
  1171. /* On sun4d the cpu broadcasts local TLB flushes, so we can just
  1172. * perform the local TLB flush and all the other cpus will see it.
  1173. * But, unfortunately, there is a bug in the sun4d XBUS backplane
  1174. * that requires that we add some synchronization to these flushes.
  1175. *
  1176. * The bug is that the fifo which keeps track of all the pending TLB
  1177. * broadcasts in the system is an entry or two too small, so if we
  1178. * have too many going at once we'll overflow that fifo and lose a TLB
  1179. * flush resulting in corruption.
  1180. *
  1181. * Our workaround is to take a global spinlock around the TLB flushes,
  1182. * which guarentees we won't ever have too many pending. It's a big
  1183. * hammer, but a semaphore like system to make sure we only have N TLB
  1184. * flushes going at once will require SMP locking anyways so there's
  1185. * no real value in trying any harder than this.
  1186. */
  1187. static struct sparc32_cachetlb_ops viking_sun4d_smp_ops = {
  1188. .cache_all = viking_flush_cache_all,
  1189. .cache_mm = viking_flush_cache_mm,
  1190. .cache_page = viking_flush_cache_page,
  1191. .cache_range = viking_flush_cache_range,
  1192. .tlb_all = sun4dsmp_flush_tlb_all,
  1193. .tlb_mm = sun4dsmp_flush_tlb_mm,
  1194. .tlb_page = sun4dsmp_flush_tlb_page,
  1195. .tlb_range = sun4dsmp_flush_tlb_range,
  1196. .page_to_ram = viking_flush_page_to_ram,
  1197. .sig_insns = viking_flush_sig_insns,
  1198. .page_for_dma = viking_flush_page_for_dma,
  1199. };
  1200. #endif
  1201. static void __init init_viking(void)
  1202. {
  1203. unsigned long mreg = srmmu_get_mmureg();
  1204. /* Ahhh, the viking. SRMMU VLSI abortion number two... */
  1205. if(mreg & VIKING_MMODE) {
  1206. srmmu_name = "TI Viking";
  1207. viking_mxcc_present = 0;
  1208. msi_set_sync();
  1209. /*
  1210. * We need this to make sure old viking takes no hits
  1211. * on it's cache for dma snoops to workaround the
  1212. * "load from non-cacheable memory" interrupt bug.
  1213. * This is only necessary because of the new way in
  1214. * which we use the IOMMU.
  1215. */
  1216. viking_ops.page_for_dma = viking_flush_page;
  1217. #ifdef CONFIG_SMP
  1218. viking_sun4d_smp_ops.page_for_dma = viking_flush_page;
  1219. #endif
  1220. flush_page_for_dma_global = 0;
  1221. } else {
  1222. srmmu_name = "TI Viking/MXCC";
  1223. viking_mxcc_present = 1;
  1224. srmmu_cache_pagetables = 1;
  1225. }
  1226. sparc32_cachetlb_ops = (const struct sparc32_cachetlb_ops *)
  1227. &viking_ops;
  1228. #ifdef CONFIG_SMP
  1229. if (sparc_cpu_model == sun4d)
  1230. sparc32_cachetlb_ops = (const struct sparc32_cachetlb_ops *)
  1231. &viking_sun4d_smp_ops;
  1232. #endif
  1233. poke_srmmu = poke_viking;
  1234. }
  1235. /* Probe for the srmmu chip version. */
  1236. static void __init get_srmmu_type(void)
  1237. {
  1238. unsigned long mreg, psr;
  1239. unsigned long mod_typ, mod_rev, psr_typ, psr_vers;
  1240. srmmu_modtype = SRMMU_INVAL_MOD;
  1241. hwbug_bitmask = 0;
  1242. mreg = srmmu_get_mmureg(); psr = get_psr();
  1243. mod_typ = (mreg & 0xf0000000) >> 28;
  1244. mod_rev = (mreg & 0x0f000000) >> 24;
  1245. psr_typ = (psr >> 28) & 0xf;
  1246. psr_vers = (psr >> 24) & 0xf;
  1247. /* First, check for sparc-leon. */
  1248. if (sparc_cpu_model == sparc_leon) {
  1249. init_leon();
  1250. return;
  1251. }
  1252. /* Second, check for HyperSparc or Cypress. */
  1253. if(mod_typ == 1) {
  1254. switch(mod_rev) {
  1255. case 7:
  1256. /* UP or MP Hypersparc */
  1257. init_hypersparc();
  1258. break;
  1259. case 0:
  1260. case 2:
  1261. case 10:
  1262. case 11:
  1263. case 12:
  1264. case 13:
  1265. case 14:
  1266. case 15:
  1267. default:
  1268. prom_printf("Sparc-Linux Cypress support does not longer exit.\n");
  1269. prom_halt();
  1270. break;
  1271. }
  1272. return;
  1273. }
  1274. /*
  1275. * Now Fujitsu TurboSparc. It might happen that it is
  1276. * in Swift emulation mode, so we will check later...
  1277. */
  1278. if (psr_typ == 0 && psr_vers == 5) {
  1279. init_turbosparc();
  1280. return;
  1281. }
  1282. /* Next check for Fujitsu Swift. */
  1283. if(psr_typ == 0 && psr_vers == 4) {
  1284. phandle cpunode;
  1285. char node_str[128];
  1286. /* Look if it is not a TurboSparc emulating Swift... */
  1287. cpunode = prom_getchild(prom_root_node);
  1288. while((cpunode = prom_getsibling(cpunode)) != 0) {
  1289. prom_getstring(cpunode, "device_type", node_str, sizeof(node_str));
  1290. if(!strcmp(node_str, "cpu")) {
  1291. if (!prom_getintdefault(cpunode, "psr-implementation", 1) &&
  1292. prom_getintdefault(cpunode, "psr-version", 1) == 5) {
  1293. init_turbosparc();
  1294. return;
  1295. }
  1296. break;
  1297. }
  1298. }
  1299. init_swift();
  1300. return;
  1301. }
  1302. /* Now the Viking family of srmmu. */
  1303. if(psr_typ == 4 &&
  1304. ((psr_vers == 0) ||
  1305. ((psr_vers == 1) && (mod_typ == 0) && (mod_rev == 0)))) {
  1306. init_viking();
  1307. return;
  1308. }
  1309. /* Finally the Tsunami. */
  1310. if(psr_typ == 4 && psr_vers == 1 && (mod_typ || mod_rev)) {
  1311. init_tsunami();
  1312. return;
  1313. }
  1314. /* Oh well */
  1315. srmmu_is_bad();
  1316. }
  1317. #ifdef CONFIG_SMP
  1318. /* Local cross-calls. */
  1319. static void smp_flush_page_for_dma(unsigned long page)
  1320. {
  1321. xc1((smpfunc_t) local_ops->page_for_dma, page);
  1322. local_ops->page_for_dma(page);
  1323. }
  1324. static void smp_flush_cache_all(void)
  1325. {
  1326. xc0((smpfunc_t) local_ops->cache_all);
  1327. local_ops->cache_all();
  1328. }
  1329. static void smp_flush_tlb_all(void)
  1330. {
  1331. xc0((smpfunc_t) local_ops->tlb_all);
  1332. local_ops->tlb_all();
  1333. }
  1334. static void smp_flush_cache_mm(struct mm_struct *mm)
  1335. {
  1336. if (mm->context != NO_CONTEXT) {
  1337. cpumask_t cpu_mask;
  1338. cpumask_copy(&cpu_mask, mm_cpumask(mm));
  1339. cpumask_clear_cpu(smp_processor_id(), &cpu_mask);
  1340. if (!cpumask_empty(&cpu_mask))
  1341. xc1((smpfunc_t) local_ops->cache_mm, (unsigned long) mm);
  1342. local_ops->cache_mm(mm);
  1343. }
  1344. }
  1345. static void smp_flush_tlb_mm(struct mm_struct *mm)
  1346. {
  1347. if (mm->context != NO_CONTEXT) {
  1348. cpumask_t cpu_mask;
  1349. cpumask_copy(&cpu_mask, mm_cpumask(mm));
  1350. cpumask_clear_cpu(smp_processor_id(), &cpu_mask);
  1351. if (!cpumask_empty(&cpu_mask)) {
  1352. xc1((smpfunc_t) local_ops->tlb_mm, (unsigned long) mm);
  1353. if (atomic_read(&mm->mm_users) == 1 && current->active_mm == mm)
  1354. cpumask_copy(mm_cpumask(mm),
  1355. cpumask_of(smp_processor_id()));
  1356. }
  1357. local_ops->tlb_mm(mm);
  1358. }
  1359. }
  1360. static void smp_flush_cache_range(struct vm_area_struct *vma,
  1361. unsigned long start,
  1362. unsigned long end)
  1363. {
  1364. struct mm_struct *mm = vma->vm_mm;
  1365. if (mm->context != NO_CONTEXT) {
  1366. cpumask_t cpu_mask;
  1367. cpumask_copy(&cpu_mask, mm_cpumask(mm));
  1368. cpumask_clear_cpu(smp_processor_id(), &cpu_mask);
  1369. if (!cpumask_empty(&cpu_mask))
  1370. xc3((smpfunc_t) local_ops->cache_range,
  1371. (unsigned long) vma, start, end);
  1372. local_ops->cache_range(vma, start, end);
  1373. }
  1374. }
  1375. static void smp_flush_tlb_range(struct vm_area_struct *vma,
  1376. unsigned long start,
  1377. unsigned long end)
  1378. {
  1379. struct mm_struct *mm = vma->vm_mm;
  1380. if (mm->context != NO_CONTEXT) {
  1381. cpumask_t cpu_mask;
  1382. cpumask_copy(&cpu_mask, mm_cpumask(mm));
  1383. cpumask_clear_cpu(smp_processor_id(), &cpu_mask);
  1384. if (!cpumask_empty(&cpu_mask))
  1385. xc3((smpfunc_t) local_ops->tlb_range,
  1386. (unsigned long) vma, start, end);
  1387. local_ops->tlb_range(vma, start, end);
  1388. }
  1389. }
  1390. static void smp_flush_cache_page(struct vm_area_struct *vma, unsigned long page)
  1391. {
  1392. struct mm_struct *mm = vma->vm_mm;
  1393. if (mm->context != NO_CONTEXT) {
  1394. cpumask_t cpu_mask;
  1395. cpumask_copy(&cpu_mask, mm_cpumask(mm));
  1396. cpumask_clear_cpu(smp_processor_id(), &cpu_mask);
  1397. if (!cpumask_empty(&cpu_mask))
  1398. xc2((smpfunc_t) local_ops->cache_page,
  1399. (unsigned long) vma, page);
  1400. local_ops->cache_page(vma, page);
  1401. }
  1402. }
  1403. static void smp_flush_tlb_page(struct vm_area_struct *vma, unsigned long page)
  1404. {
  1405. struct mm_struct *mm = vma->vm_mm;
  1406. if (mm->context != NO_CONTEXT) {
  1407. cpumask_t cpu_mask;
  1408. cpumask_copy(&cpu_mask, mm_cpumask(mm));
  1409. cpumask_clear_cpu(smp_processor_id(), &cpu_mask);
  1410. if (!cpumask_empty(&cpu_mask))
  1411. xc2((smpfunc_t) local_ops->tlb_page,
  1412. (unsigned long) vma, page);
  1413. local_ops->tlb_page(vma, page);
  1414. }
  1415. }
  1416. static void smp_flush_page_to_ram(unsigned long page)
  1417. {
  1418. /* Current theory is that those who call this are the one's
  1419. * who have just dirtied their cache with the pages contents
  1420. * in kernel space, therefore we only run this on local cpu.
  1421. *
  1422. * XXX This experiment failed, research further... -DaveM
  1423. */
  1424. #if 1
  1425. xc1((smpfunc_t) local_ops->page_to_ram, page);
  1426. #endif
  1427. local_ops->page_to_ram(page);
  1428. }
  1429. static void smp_flush_sig_insns(struct mm_struct *mm, unsigned long insn_addr)
  1430. {
  1431. cpumask_t cpu_mask;
  1432. cpumask_copy(&cpu_mask, mm_cpumask(mm));
  1433. cpumask_clear_cpu(smp_processor_id(), &cpu_mask);
  1434. if (!cpumask_empty(&cpu_mask))
  1435. xc2((smpfunc_t) local_ops->sig_insns,
  1436. (unsigned long) mm, insn_addr);
  1437. local_ops->sig_insns(mm, insn_addr);
  1438. }
  1439. static struct sparc32_cachetlb_ops smp_cachetlb_ops = {
  1440. .cache_all = smp_flush_cache_all,
  1441. .cache_mm = smp_flush_cache_mm,
  1442. .cache_page = smp_flush_cache_page,
  1443. .cache_range = smp_flush_cache_range,
  1444. .tlb_all = smp_flush_tlb_all,
  1445. .tlb_mm = smp_flush_tlb_mm,
  1446. .tlb_page = smp_flush_tlb_page,
  1447. .tlb_range = smp_flush_tlb_range,
  1448. .page_to_ram = smp_flush_page_to_ram,
  1449. .sig_insns = smp_flush_sig_insns,
  1450. .page_for_dma = smp_flush_page_for_dma,
  1451. };
  1452. #endif
  1453. /* Load up routines and constants for sun4m and sun4d mmu */
  1454. void __init load_mmu(void)
  1455. {
  1456. extern void ld_mmu_iommu(void);
  1457. extern void ld_mmu_iounit(void);
  1458. /* Functions */
  1459. get_srmmu_type();
  1460. #ifdef CONFIG_SMP
  1461. /* El switcheroo... */
  1462. local_ops = sparc32_cachetlb_ops;
  1463. if (sparc_cpu_model == sun4d || sparc_cpu_model == sparc_leon) {
  1464. smp_cachetlb_ops.tlb_all = local_ops->tlb_all;
  1465. smp_cachetlb_ops.tlb_mm = local_ops->tlb_mm;
  1466. smp_cachetlb_ops.tlb_range = local_ops->tlb_range;
  1467. smp_cachetlb_ops.tlb_page = local_ops->tlb_page;
  1468. }
  1469. if (poke_srmmu == poke_viking) {
  1470. /* Avoid unnecessary cross calls. */
  1471. smp_cachetlb_ops.cache_all = local_ops->cache_all;
  1472. smp_cachetlb_ops.cache_mm = local_ops->cache_mm;
  1473. smp_cachetlb_ops.cache_range = local_ops->cache_range;
  1474. smp_cachetlb_ops.cache_page = local_ops->cache_page;
  1475. smp_cachetlb_ops.page_to_ram = local_ops->page_to_ram;
  1476. smp_cachetlb_ops.sig_insns = local_ops->sig_insns;
  1477. smp_cachetlb_ops.page_for_dma = local_ops->page_for_dma;
  1478. }
  1479. /* It really is const after this point. */
  1480. sparc32_cachetlb_ops = (const struct sparc32_cachetlb_ops *)
  1481. &smp_cachetlb_ops;
  1482. #endif
  1483. if (sparc_cpu_model == sun4d)
  1484. ld_mmu_iounit();
  1485. else
  1486. ld_mmu_iommu();
  1487. #ifdef CONFIG_SMP
  1488. if (sparc_cpu_model == sun4d)
  1489. sun4d_init_smp();
  1490. else if (sparc_cpu_model == sparc_leon)
  1491. leon_init_smp();
  1492. else
  1493. sun4m_init_smp();
  1494. #endif
  1495. }