srmmu.c 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726
  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. /*
  549. * This is much cleaner than poking around physical address space
  550. * looking at the prom's page table directly which is what most
  551. * other OS's do. Yuck... this is much better.
  552. */
  553. static void __init srmmu_inherit_prom_mappings(unsigned long start,
  554. unsigned long end)
  555. {
  556. pgd_t *pgdp;
  557. pmd_t *pmdp;
  558. pte_t *ptep;
  559. int what = 0; /* 0 = normal-pte, 1 = pmd-level pte, 2 = pgd-level pte */
  560. unsigned long prompte;
  561. while(start <= end) {
  562. if (start == 0)
  563. break; /* probably wrap around */
  564. if(start == 0xfef00000)
  565. start = KADB_DEBUGGER_BEGVM;
  566. if(!(prompte = srmmu_hwprobe(start))) {
  567. start += PAGE_SIZE;
  568. continue;
  569. }
  570. /* A red snapper, see what it really is. */
  571. what = 0;
  572. if(!(start & ~(SRMMU_REAL_PMD_MASK))) {
  573. if(srmmu_hwprobe((start-PAGE_SIZE) + SRMMU_REAL_PMD_SIZE) == prompte)
  574. what = 1;
  575. }
  576. if(!(start & ~(SRMMU_PGDIR_MASK))) {
  577. if(srmmu_hwprobe((start-PAGE_SIZE) + SRMMU_PGDIR_SIZE) ==
  578. prompte)
  579. what = 2;
  580. }
  581. pgdp = pgd_offset_k(start);
  582. if(what == 2) {
  583. *(pgd_t *)__nocache_fix(pgdp) = __pgd(prompte);
  584. start += SRMMU_PGDIR_SIZE;
  585. continue;
  586. }
  587. if (pgd_none(*(pgd_t *)__nocache_fix(pgdp))) {
  588. pmdp = (pmd_t *)__srmmu_get_nocache(SRMMU_PMD_TABLE_SIZE, SRMMU_PMD_TABLE_SIZE);
  589. if (pmdp == NULL)
  590. early_pgtable_allocfail("pmd");
  591. memset(__nocache_fix(pmdp), 0, SRMMU_PMD_TABLE_SIZE);
  592. pgd_set(__nocache_fix(pgdp), pmdp);
  593. }
  594. pmdp = pmd_offset(__nocache_fix(pgdp), start);
  595. if(srmmu_pmd_none(*(pmd_t *)__nocache_fix(pmdp))) {
  596. ptep = (pte_t *) __srmmu_get_nocache(PTE_SIZE,
  597. PTE_SIZE);
  598. if (ptep == NULL)
  599. early_pgtable_allocfail("pte");
  600. memset(__nocache_fix(ptep), 0, PTE_SIZE);
  601. pmd_set(__nocache_fix(pmdp), ptep);
  602. }
  603. if(what == 1) {
  604. /*
  605. * We bend the rule where all 16 PTPs in a pmd_t point
  606. * inside the same PTE page, and we leak a perfectly
  607. * good hardware PTE piece. Alternatives seem worse.
  608. */
  609. unsigned int x; /* Index of HW PMD in soft cluster */
  610. x = (start >> PMD_SHIFT) & 15;
  611. *(unsigned long *)__nocache_fix(&pmdp->pmdv[x]) = prompte;
  612. start += SRMMU_REAL_PMD_SIZE;
  613. continue;
  614. }
  615. ptep = pte_offset_kernel(__nocache_fix(pmdp), start);
  616. *(pte_t *)__nocache_fix(ptep) = __pte(prompte);
  617. start += PAGE_SIZE;
  618. }
  619. }
  620. #define KERNEL_PTE(page_shifted) ((page_shifted)|SRMMU_CACHE|SRMMU_PRIV|SRMMU_VALID)
  621. /* Create a third-level SRMMU 16MB page mapping. */
  622. static void __init do_large_mapping(unsigned long vaddr, unsigned long phys_base)
  623. {
  624. pgd_t *pgdp = pgd_offset_k(vaddr);
  625. unsigned long big_pte;
  626. big_pte = KERNEL_PTE(phys_base >> 4);
  627. *(pgd_t *)__nocache_fix(pgdp) = __pgd(big_pte);
  628. }
  629. /* Map sp_bank entry SP_ENTRY, starting at virtual address VBASE. */
  630. static unsigned long __init map_spbank(unsigned long vbase, int sp_entry)
  631. {
  632. unsigned long pstart = (sp_banks[sp_entry].base_addr & SRMMU_PGDIR_MASK);
  633. unsigned long vstart = (vbase & SRMMU_PGDIR_MASK);
  634. unsigned long vend = SRMMU_PGDIR_ALIGN(vbase + sp_banks[sp_entry].num_bytes);
  635. /* Map "low" memory only */
  636. const unsigned long min_vaddr = PAGE_OFFSET;
  637. const unsigned long max_vaddr = PAGE_OFFSET + SRMMU_MAXMEM;
  638. if (vstart < min_vaddr || vstart >= max_vaddr)
  639. return vstart;
  640. if (vend > max_vaddr || vend < min_vaddr)
  641. vend = max_vaddr;
  642. while(vstart < vend) {
  643. do_large_mapping(vstart, pstart);
  644. vstart += SRMMU_PGDIR_SIZE; pstart += SRMMU_PGDIR_SIZE;
  645. }
  646. return vstart;
  647. }
  648. static inline void map_kernel(void)
  649. {
  650. int i;
  651. if (phys_base > 0) {
  652. do_large_mapping(PAGE_OFFSET, phys_base);
  653. }
  654. for (i = 0; sp_banks[i].num_bytes != 0; i++) {
  655. map_spbank((unsigned long)__va(sp_banks[i].base_addr), i);
  656. }
  657. }
  658. /* Paging initialization on the Sparc Reference MMU. */
  659. extern void sparc_context_init(int);
  660. void (*poke_srmmu)(void) __cpuinitdata = NULL;
  661. extern unsigned long bootmem_init(unsigned long *pages_avail);
  662. void __init srmmu_paging_init(void)
  663. {
  664. int i;
  665. phandle cpunode;
  666. char node_str[128];
  667. pgd_t *pgd;
  668. pmd_t *pmd;
  669. pte_t *pte;
  670. unsigned long pages_avail;
  671. sparc_iomap.start = SUN4M_IOBASE_VADDR; /* 16MB of IOSPACE on all sun4m's. */
  672. if (sparc_cpu_model == sun4d)
  673. num_contexts = 65536; /* We know it is Viking */
  674. else {
  675. /* Find the number of contexts on the srmmu. */
  676. cpunode = prom_getchild(prom_root_node);
  677. num_contexts = 0;
  678. while(cpunode != 0) {
  679. prom_getstring(cpunode, "device_type", node_str, sizeof(node_str));
  680. if(!strcmp(node_str, "cpu")) {
  681. num_contexts = prom_getintdefault(cpunode, "mmu-nctx", 0x8);
  682. break;
  683. }
  684. cpunode = prom_getsibling(cpunode);
  685. }
  686. }
  687. if(!num_contexts) {
  688. prom_printf("Something wrong, can't find cpu node in paging_init.\n");
  689. prom_halt();
  690. }
  691. pages_avail = 0;
  692. last_valid_pfn = bootmem_init(&pages_avail);
  693. srmmu_nocache_calcsize();
  694. srmmu_nocache_init();
  695. srmmu_inherit_prom_mappings(0xfe400000,(LINUX_OPPROM_ENDVM-PAGE_SIZE));
  696. map_kernel();
  697. /* ctx table has to be physically aligned to its size */
  698. srmmu_context_table = (ctxd_t *)__srmmu_get_nocache(num_contexts*sizeof(ctxd_t), num_contexts*sizeof(ctxd_t));
  699. srmmu_ctx_table_phys = (ctxd_t *)__nocache_pa((unsigned long)srmmu_context_table);
  700. for(i = 0; i < num_contexts; i++)
  701. srmmu_ctxd_set((ctxd_t *)__nocache_fix(&srmmu_context_table[i]), srmmu_swapper_pg_dir);
  702. flush_cache_all();
  703. srmmu_set_ctable_ptr((unsigned long)srmmu_ctx_table_phys);
  704. #ifdef CONFIG_SMP
  705. /* Stop from hanging here... */
  706. local_ops->tlb_all();
  707. #else
  708. flush_tlb_all();
  709. #endif
  710. poke_srmmu();
  711. srmmu_allocate_ptable_skeleton(sparc_iomap.start, IOBASE_END);
  712. srmmu_allocate_ptable_skeleton(DVMA_VADDR, DVMA_END);
  713. srmmu_allocate_ptable_skeleton(
  714. __fix_to_virt(__end_of_fixed_addresses - 1), FIXADDR_TOP);
  715. srmmu_allocate_ptable_skeleton(PKMAP_BASE, PKMAP_END);
  716. pgd = pgd_offset_k(PKMAP_BASE);
  717. pmd = pmd_offset(pgd, PKMAP_BASE);
  718. pte = pte_offset_kernel(pmd, PKMAP_BASE);
  719. pkmap_page_table = pte;
  720. flush_cache_all();
  721. flush_tlb_all();
  722. sparc_context_init(num_contexts);
  723. kmap_init();
  724. {
  725. unsigned long zones_size[MAX_NR_ZONES];
  726. unsigned long zholes_size[MAX_NR_ZONES];
  727. unsigned long npages;
  728. int znum;
  729. for (znum = 0; znum < MAX_NR_ZONES; znum++)
  730. zones_size[znum] = zholes_size[znum] = 0;
  731. npages = max_low_pfn - pfn_base;
  732. zones_size[ZONE_DMA] = npages;
  733. zholes_size[ZONE_DMA] = npages - pages_avail;
  734. npages = highend_pfn - max_low_pfn;
  735. zones_size[ZONE_HIGHMEM] = npages;
  736. zholes_size[ZONE_HIGHMEM] = npages - calc_highpages();
  737. free_area_init_node(0, zones_size, pfn_base, zholes_size);
  738. }
  739. }
  740. void mmu_info(struct seq_file *m)
  741. {
  742. seq_printf(m,
  743. "MMU type\t: %s\n"
  744. "contexts\t: %d\n"
  745. "nocache total\t: %ld\n"
  746. "nocache used\t: %d\n",
  747. srmmu_name,
  748. num_contexts,
  749. srmmu_nocache_size,
  750. srmmu_nocache_map.used << SRMMU_NOCACHE_BITMAP_SHIFT);
  751. }
  752. void destroy_context(struct mm_struct *mm)
  753. {
  754. if(mm->context != NO_CONTEXT) {
  755. flush_cache_mm(mm);
  756. srmmu_ctxd_set(&srmmu_context_table[mm->context], srmmu_swapper_pg_dir);
  757. flush_tlb_mm(mm);
  758. spin_lock(&srmmu_context_spinlock);
  759. free_context(mm->context);
  760. spin_unlock(&srmmu_context_spinlock);
  761. mm->context = NO_CONTEXT;
  762. }
  763. }
  764. /* Init various srmmu chip types. */
  765. static void __init srmmu_is_bad(void)
  766. {
  767. prom_printf("Could not determine SRMMU chip type.\n");
  768. prom_halt();
  769. }
  770. static void __init init_vac_layout(void)
  771. {
  772. phandle nd;
  773. int cache_lines;
  774. char node_str[128];
  775. #ifdef CONFIG_SMP
  776. int cpu = 0;
  777. unsigned long max_size = 0;
  778. unsigned long min_line_size = 0x10000000;
  779. #endif
  780. nd = prom_getchild(prom_root_node);
  781. while((nd = prom_getsibling(nd)) != 0) {
  782. prom_getstring(nd, "device_type", node_str, sizeof(node_str));
  783. if(!strcmp(node_str, "cpu")) {
  784. vac_line_size = prom_getint(nd, "cache-line-size");
  785. if (vac_line_size == -1) {
  786. prom_printf("can't determine cache-line-size, "
  787. "halting.\n");
  788. prom_halt();
  789. }
  790. cache_lines = prom_getint(nd, "cache-nlines");
  791. if (cache_lines == -1) {
  792. prom_printf("can't determine cache-nlines, halting.\n");
  793. prom_halt();
  794. }
  795. vac_cache_size = cache_lines * vac_line_size;
  796. #ifdef CONFIG_SMP
  797. if(vac_cache_size > max_size)
  798. max_size = vac_cache_size;
  799. if(vac_line_size < min_line_size)
  800. min_line_size = vac_line_size;
  801. //FIXME: cpus not contiguous!!
  802. cpu++;
  803. if (cpu >= nr_cpu_ids || !cpu_online(cpu))
  804. break;
  805. #else
  806. break;
  807. #endif
  808. }
  809. }
  810. if(nd == 0) {
  811. prom_printf("No CPU nodes found, halting.\n");
  812. prom_halt();
  813. }
  814. #ifdef CONFIG_SMP
  815. vac_cache_size = max_size;
  816. vac_line_size = min_line_size;
  817. #endif
  818. printk("SRMMU: Using VAC size of %d bytes, line size %d bytes.\n",
  819. (int)vac_cache_size, (int)vac_line_size);
  820. }
  821. static void __cpuinit poke_hypersparc(void)
  822. {
  823. volatile unsigned long clear;
  824. unsigned long mreg = srmmu_get_mmureg();
  825. hyper_flush_unconditional_combined();
  826. mreg &= ~(HYPERSPARC_CWENABLE);
  827. mreg |= (HYPERSPARC_CENABLE | HYPERSPARC_WBENABLE);
  828. mreg |= (HYPERSPARC_CMODE);
  829. srmmu_set_mmureg(mreg);
  830. #if 0 /* XXX I think this is bad news... -DaveM */
  831. hyper_clear_all_tags();
  832. #endif
  833. put_ross_icr(HYPERSPARC_ICCR_FTD | HYPERSPARC_ICCR_ICE);
  834. hyper_flush_whole_icache();
  835. clear = srmmu_get_faddr();
  836. clear = srmmu_get_fstatus();
  837. }
  838. static const struct sparc32_cachetlb_ops hypersparc_ops = {
  839. .cache_all = hypersparc_flush_cache_all,
  840. .cache_mm = hypersparc_flush_cache_mm,
  841. .cache_page = hypersparc_flush_cache_page,
  842. .cache_range = hypersparc_flush_cache_range,
  843. .tlb_all = hypersparc_flush_tlb_all,
  844. .tlb_mm = hypersparc_flush_tlb_mm,
  845. .tlb_page = hypersparc_flush_tlb_page,
  846. .tlb_range = hypersparc_flush_tlb_range,
  847. .page_to_ram = hypersparc_flush_page_to_ram,
  848. .sig_insns = hypersparc_flush_sig_insns,
  849. .page_for_dma = hypersparc_flush_page_for_dma,
  850. };
  851. static void __init init_hypersparc(void)
  852. {
  853. srmmu_name = "ROSS HyperSparc";
  854. srmmu_modtype = HyperSparc;
  855. init_vac_layout();
  856. is_hypersparc = 1;
  857. sparc32_cachetlb_ops = &hypersparc_ops;
  858. poke_srmmu = poke_hypersparc;
  859. hypersparc_setup_blockops();
  860. }
  861. static void __cpuinit poke_swift(void)
  862. {
  863. unsigned long mreg;
  864. /* Clear any crap from the cache or else... */
  865. swift_flush_cache_all();
  866. /* Enable I & D caches */
  867. mreg = srmmu_get_mmureg();
  868. mreg |= (SWIFT_IE | SWIFT_DE);
  869. /*
  870. * The Swift branch folding logic is completely broken. At
  871. * trap time, if things are just right, if can mistakenly
  872. * think that a trap is coming from kernel mode when in fact
  873. * it is coming from user mode (it mis-executes the branch in
  874. * the trap code). So you see things like crashme completely
  875. * hosing your machine which is completely unacceptable. Turn
  876. * this shit off... nice job Fujitsu.
  877. */
  878. mreg &= ~(SWIFT_BF);
  879. srmmu_set_mmureg(mreg);
  880. }
  881. static const struct sparc32_cachetlb_ops swift_ops = {
  882. .cache_all = swift_flush_cache_all,
  883. .cache_mm = swift_flush_cache_mm,
  884. .cache_page = swift_flush_cache_page,
  885. .cache_range = swift_flush_cache_range,
  886. .tlb_all = swift_flush_tlb_all,
  887. .tlb_mm = swift_flush_tlb_mm,
  888. .tlb_page = swift_flush_tlb_page,
  889. .tlb_range = swift_flush_tlb_range,
  890. .page_to_ram = swift_flush_page_to_ram,
  891. .sig_insns = swift_flush_sig_insns,
  892. .page_for_dma = swift_flush_page_for_dma,
  893. };
  894. #define SWIFT_MASKID_ADDR 0x10003018
  895. static void __init init_swift(void)
  896. {
  897. unsigned long swift_rev;
  898. __asm__ __volatile__("lda [%1] %2, %0\n\t"
  899. "srl %0, 0x18, %0\n\t" :
  900. "=r" (swift_rev) :
  901. "r" (SWIFT_MASKID_ADDR), "i" (ASI_M_BYPASS));
  902. srmmu_name = "Fujitsu Swift";
  903. switch(swift_rev) {
  904. case 0x11:
  905. case 0x20:
  906. case 0x23:
  907. case 0x30:
  908. srmmu_modtype = Swift_lots_o_bugs;
  909. hwbug_bitmask |= (HWBUG_KERN_ACCBROKEN | HWBUG_KERN_CBITBROKEN);
  910. /*
  911. * Gee george, I wonder why Sun is so hush hush about
  912. * this hardware bug... really braindamage stuff going
  913. * on here. However I think we can find a way to avoid
  914. * all of the workaround overhead under Linux. Basically,
  915. * any page fault can cause kernel pages to become user
  916. * accessible (the mmu gets confused and clears some of
  917. * the ACC bits in kernel ptes). Aha, sounds pretty
  918. * horrible eh? But wait, after extensive testing it appears
  919. * that if you use pgd_t level large kernel pte's (like the
  920. * 4MB pages on the Pentium) the bug does not get tripped
  921. * at all. This avoids almost all of the major overhead.
  922. * Welcome to a world where your vendor tells you to,
  923. * "apply this kernel patch" instead of "sorry for the
  924. * broken hardware, send it back and we'll give you
  925. * properly functioning parts"
  926. */
  927. break;
  928. case 0x25:
  929. case 0x31:
  930. srmmu_modtype = Swift_bad_c;
  931. hwbug_bitmask |= HWBUG_KERN_CBITBROKEN;
  932. /*
  933. * You see Sun allude to this hardware bug but never
  934. * admit things directly, they'll say things like,
  935. * "the Swift chip cache problems" or similar.
  936. */
  937. break;
  938. default:
  939. srmmu_modtype = Swift_ok;
  940. break;
  941. }
  942. sparc32_cachetlb_ops = &swift_ops;
  943. flush_page_for_dma_global = 0;
  944. /*
  945. * Are you now convinced that the Swift is one of the
  946. * biggest VLSI abortions of all time? Bravo Fujitsu!
  947. * Fujitsu, the !#?!%$'d up processor people. I bet if
  948. * you examined the microcode of the Swift you'd find
  949. * XXX's all over the place.
  950. */
  951. poke_srmmu = poke_swift;
  952. }
  953. static void turbosparc_flush_cache_all(void)
  954. {
  955. flush_user_windows();
  956. turbosparc_idflash_clear();
  957. }
  958. static void turbosparc_flush_cache_mm(struct mm_struct *mm)
  959. {
  960. FLUSH_BEGIN(mm)
  961. flush_user_windows();
  962. turbosparc_idflash_clear();
  963. FLUSH_END
  964. }
  965. static void turbosparc_flush_cache_range(struct vm_area_struct *vma, unsigned long start, unsigned long end)
  966. {
  967. FLUSH_BEGIN(vma->vm_mm)
  968. flush_user_windows();
  969. turbosparc_idflash_clear();
  970. FLUSH_END
  971. }
  972. static void turbosparc_flush_cache_page(struct vm_area_struct *vma, unsigned long page)
  973. {
  974. FLUSH_BEGIN(vma->vm_mm)
  975. flush_user_windows();
  976. if (vma->vm_flags & VM_EXEC)
  977. turbosparc_flush_icache();
  978. turbosparc_flush_dcache();
  979. FLUSH_END
  980. }
  981. /* TurboSparc is copy-back, if we turn it on, but this does not work. */
  982. static void turbosparc_flush_page_to_ram(unsigned long page)
  983. {
  984. #ifdef TURBOSPARC_WRITEBACK
  985. volatile unsigned long clear;
  986. if (srmmu_hwprobe(page))
  987. turbosparc_flush_page_cache(page);
  988. clear = srmmu_get_fstatus();
  989. #endif
  990. }
  991. static void turbosparc_flush_sig_insns(struct mm_struct *mm, unsigned long insn_addr)
  992. {
  993. }
  994. static void turbosparc_flush_page_for_dma(unsigned long page)
  995. {
  996. turbosparc_flush_dcache();
  997. }
  998. static void turbosparc_flush_tlb_all(void)
  999. {
  1000. srmmu_flush_whole_tlb();
  1001. }
  1002. static void turbosparc_flush_tlb_mm(struct mm_struct *mm)
  1003. {
  1004. FLUSH_BEGIN(mm)
  1005. srmmu_flush_whole_tlb();
  1006. FLUSH_END
  1007. }
  1008. static void turbosparc_flush_tlb_range(struct vm_area_struct *vma, unsigned long start, unsigned long end)
  1009. {
  1010. FLUSH_BEGIN(vma->vm_mm)
  1011. srmmu_flush_whole_tlb();
  1012. FLUSH_END
  1013. }
  1014. static void turbosparc_flush_tlb_page(struct vm_area_struct *vma, unsigned long page)
  1015. {
  1016. FLUSH_BEGIN(vma->vm_mm)
  1017. srmmu_flush_whole_tlb();
  1018. FLUSH_END
  1019. }
  1020. static void __cpuinit poke_turbosparc(void)
  1021. {
  1022. unsigned long mreg = srmmu_get_mmureg();
  1023. unsigned long ccreg;
  1024. /* Clear any crap from the cache or else... */
  1025. turbosparc_flush_cache_all();
  1026. mreg &= ~(TURBOSPARC_ICENABLE | TURBOSPARC_DCENABLE); /* Temporarily disable I & D caches */
  1027. mreg &= ~(TURBOSPARC_PCENABLE); /* Don't check parity */
  1028. srmmu_set_mmureg(mreg);
  1029. ccreg = turbosparc_get_ccreg();
  1030. #ifdef TURBOSPARC_WRITEBACK
  1031. ccreg |= (TURBOSPARC_SNENABLE); /* Do DVMA snooping in Dcache */
  1032. ccreg &= ~(TURBOSPARC_uS2 | TURBOSPARC_WTENABLE);
  1033. /* Write-back D-cache, emulate VLSI
  1034. * abortion number three, not number one */
  1035. #else
  1036. /* For now let's play safe, optimize later */
  1037. ccreg |= (TURBOSPARC_SNENABLE | TURBOSPARC_WTENABLE);
  1038. /* Do DVMA snooping in Dcache, Write-thru D-cache */
  1039. ccreg &= ~(TURBOSPARC_uS2);
  1040. /* Emulate VLSI abortion number three, not number one */
  1041. #endif
  1042. switch (ccreg & 7) {
  1043. case 0: /* No SE cache */
  1044. case 7: /* Test mode */
  1045. break;
  1046. default:
  1047. ccreg |= (TURBOSPARC_SCENABLE);
  1048. }
  1049. turbosparc_set_ccreg (ccreg);
  1050. mreg |= (TURBOSPARC_ICENABLE | TURBOSPARC_DCENABLE); /* I & D caches on */
  1051. mreg |= (TURBOSPARC_ICSNOOP); /* Icache snooping on */
  1052. srmmu_set_mmureg(mreg);
  1053. }
  1054. static const struct sparc32_cachetlb_ops turbosparc_ops = {
  1055. .cache_all = turbosparc_flush_cache_all,
  1056. .cache_mm = turbosparc_flush_cache_mm,
  1057. .cache_page = turbosparc_flush_cache_page,
  1058. .cache_range = turbosparc_flush_cache_range,
  1059. .tlb_all = turbosparc_flush_tlb_all,
  1060. .tlb_mm = turbosparc_flush_tlb_mm,
  1061. .tlb_page = turbosparc_flush_tlb_page,
  1062. .tlb_range = turbosparc_flush_tlb_range,
  1063. .page_to_ram = turbosparc_flush_page_to_ram,
  1064. .sig_insns = turbosparc_flush_sig_insns,
  1065. .page_for_dma = turbosparc_flush_page_for_dma,
  1066. };
  1067. static void __init init_turbosparc(void)
  1068. {
  1069. srmmu_name = "Fujitsu TurboSparc";
  1070. srmmu_modtype = TurboSparc;
  1071. sparc32_cachetlb_ops = &turbosparc_ops;
  1072. poke_srmmu = poke_turbosparc;
  1073. }
  1074. static void __cpuinit poke_tsunami(void)
  1075. {
  1076. unsigned long mreg = srmmu_get_mmureg();
  1077. tsunami_flush_icache();
  1078. tsunami_flush_dcache();
  1079. mreg &= ~TSUNAMI_ITD;
  1080. mreg |= (TSUNAMI_IENAB | TSUNAMI_DENAB);
  1081. srmmu_set_mmureg(mreg);
  1082. }
  1083. static const struct sparc32_cachetlb_ops tsunami_ops = {
  1084. .cache_all = tsunami_flush_cache_all,
  1085. .cache_mm = tsunami_flush_cache_mm,
  1086. .cache_page = tsunami_flush_cache_page,
  1087. .cache_range = tsunami_flush_cache_range,
  1088. .tlb_all = tsunami_flush_tlb_all,
  1089. .tlb_mm = tsunami_flush_tlb_mm,
  1090. .tlb_page = tsunami_flush_tlb_page,
  1091. .tlb_range = tsunami_flush_tlb_range,
  1092. .page_to_ram = tsunami_flush_page_to_ram,
  1093. .sig_insns = tsunami_flush_sig_insns,
  1094. .page_for_dma = tsunami_flush_page_for_dma,
  1095. };
  1096. static void __init init_tsunami(void)
  1097. {
  1098. /*
  1099. * Tsunami's pretty sane, Sun and TI actually got it
  1100. * somewhat right this time. Fujitsu should have
  1101. * taken some lessons from them.
  1102. */
  1103. srmmu_name = "TI Tsunami";
  1104. srmmu_modtype = Tsunami;
  1105. sparc32_cachetlb_ops = &tsunami_ops;
  1106. poke_srmmu = poke_tsunami;
  1107. tsunami_setup_blockops();
  1108. }
  1109. static void __cpuinit poke_viking(void)
  1110. {
  1111. unsigned long mreg = srmmu_get_mmureg();
  1112. static int smp_catch;
  1113. if (viking_mxcc_present) {
  1114. unsigned long mxcc_control = mxcc_get_creg();
  1115. mxcc_control |= (MXCC_CTL_ECE | MXCC_CTL_PRE | MXCC_CTL_MCE);
  1116. mxcc_control &= ~(MXCC_CTL_RRC);
  1117. mxcc_set_creg(mxcc_control);
  1118. /*
  1119. * We don't need memory parity checks.
  1120. * XXX This is a mess, have to dig out later. ecd.
  1121. viking_mxcc_turn_off_parity(&mreg, &mxcc_control);
  1122. */
  1123. /* We do cache ptables on MXCC. */
  1124. mreg |= VIKING_TCENABLE;
  1125. } else {
  1126. unsigned long bpreg;
  1127. mreg &= ~(VIKING_TCENABLE);
  1128. if(smp_catch++) {
  1129. /* Must disable mixed-cmd mode here for other cpu's. */
  1130. bpreg = viking_get_bpreg();
  1131. bpreg &= ~(VIKING_ACTION_MIX);
  1132. viking_set_bpreg(bpreg);
  1133. /* Just in case PROM does something funny. */
  1134. msi_set_sync();
  1135. }
  1136. }
  1137. mreg |= VIKING_SPENABLE;
  1138. mreg |= (VIKING_ICENABLE | VIKING_DCENABLE);
  1139. mreg |= VIKING_SBENABLE;
  1140. mreg &= ~(VIKING_ACENABLE);
  1141. srmmu_set_mmureg(mreg);
  1142. }
  1143. static struct sparc32_cachetlb_ops viking_ops = {
  1144. .cache_all = viking_flush_cache_all,
  1145. .cache_mm = viking_flush_cache_mm,
  1146. .cache_page = viking_flush_cache_page,
  1147. .cache_range = viking_flush_cache_range,
  1148. .tlb_all = viking_flush_tlb_all,
  1149. .tlb_mm = viking_flush_tlb_mm,
  1150. .tlb_page = viking_flush_tlb_page,
  1151. .tlb_range = viking_flush_tlb_range,
  1152. .page_to_ram = viking_flush_page_to_ram,
  1153. .sig_insns = viking_flush_sig_insns,
  1154. .page_for_dma = viking_flush_page_for_dma,
  1155. };
  1156. #ifdef CONFIG_SMP
  1157. /* On sun4d the cpu broadcasts local TLB flushes, so we can just
  1158. * perform the local TLB flush and all the other cpus will see it.
  1159. * But, unfortunately, there is a bug in the sun4d XBUS backplane
  1160. * that requires that we add some synchronization to these flushes.
  1161. *
  1162. * The bug is that the fifo which keeps track of all the pending TLB
  1163. * broadcasts in the system is an entry or two too small, so if we
  1164. * have too many going at once we'll overflow that fifo and lose a TLB
  1165. * flush resulting in corruption.
  1166. *
  1167. * Our workaround is to take a global spinlock around the TLB flushes,
  1168. * which guarentees we won't ever have too many pending. It's a big
  1169. * hammer, but a semaphore like system to make sure we only have N TLB
  1170. * flushes going at once will require SMP locking anyways so there's
  1171. * no real value in trying any harder than this.
  1172. */
  1173. static struct sparc32_cachetlb_ops viking_sun4d_smp_ops = {
  1174. .cache_all = viking_flush_cache_all,
  1175. .cache_mm = viking_flush_cache_mm,
  1176. .cache_page = viking_flush_cache_page,
  1177. .cache_range = viking_flush_cache_range,
  1178. .tlb_all = sun4dsmp_flush_tlb_all,
  1179. .tlb_mm = sun4dsmp_flush_tlb_mm,
  1180. .tlb_page = sun4dsmp_flush_tlb_page,
  1181. .tlb_range = sun4dsmp_flush_tlb_range,
  1182. .page_to_ram = viking_flush_page_to_ram,
  1183. .sig_insns = viking_flush_sig_insns,
  1184. .page_for_dma = viking_flush_page_for_dma,
  1185. };
  1186. #endif
  1187. static void __init init_viking(void)
  1188. {
  1189. unsigned long mreg = srmmu_get_mmureg();
  1190. /* Ahhh, the viking. SRMMU VLSI abortion number two... */
  1191. if(mreg & VIKING_MMODE) {
  1192. srmmu_name = "TI Viking";
  1193. viking_mxcc_present = 0;
  1194. msi_set_sync();
  1195. /*
  1196. * We need this to make sure old viking takes no hits
  1197. * on it's cache for dma snoops to workaround the
  1198. * "load from non-cacheable memory" interrupt bug.
  1199. * This is only necessary because of the new way in
  1200. * which we use the IOMMU.
  1201. */
  1202. viking_ops.page_for_dma = viking_flush_page;
  1203. #ifdef CONFIG_SMP
  1204. viking_sun4d_smp_ops.page_for_dma = viking_flush_page;
  1205. #endif
  1206. flush_page_for_dma_global = 0;
  1207. } else {
  1208. srmmu_name = "TI Viking/MXCC";
  1209. viking_mxcc_present = 1;
  1210. srmmu_cache_pagetables = 1;
  1211. }
  1212. sparc32_cachetlb_ops = (const struct sparc32_cachetlb_ops *)
  1213. &viking_ops;
  1214. #ifdef CONFIG_SMP
  1215. if (sparc_cpu_model == sun4d)
  1216. sparc32_cachetlb_ops = (const struct sparc32_cachetlb_ops *)
  1217. &viking_sun4d_smp_ops;
  1218. #endif
  1219. poke_srmmu = poke_viking;
  1220. }
  1221. /* Probe for the srmmu chip version. */
  1222. static void __init get_srmmu_type(void)
  1223. {
  1224. unsigned long mreg, psr;
  1225. unsigned long mod_typ, mod_rev, psr_typ, psr_vers;
  1226. srmmu_modtype = SRMMU_INVAL_MOD;
  1227. hwbug_bitmask = 0;
  1228. mreg = srmmu_get_mmureg(); psr = get_psr();
  1229. mod_typ = (mreg & 0xf0000000) >> 28;
  1230. mod_rev = (mreg & 0x0f000000) >> 24;
  1231. psr_typ = (psr >> 28) & 0xf;
  1232. psr_vers = (psr >> 24) & 0xf;
  1233. /* First, check for sparc-leon. */
  1234. if (sparc_cpu_model == sparc_leon) {
  1235. init_leon();
  1236. return;
  1237. }
  1238. /* Second, check for HyperSparc or Cypress. */
  1239. if(mod_typ == 1) {
  1240. switch(mod_rev) {
  1241. case 7:
  1242. /* UP or MP Hypersparc */
  1243. init_hypersparc();
  1244. break;
  1245. case 0:
  1246. case 2:
  1247. case 10:
  1248. case 11:
  1249. case 12:
  1250. case 13:
  1251. case 14:
  1252. case 15:
  1253. default:
  1254. prom_printf("Sparc-Linux Cypress support does not longer exit.\n");
  1255. prom_halt();
  1256. break;
  1257. }
  1258. return;
  1259. }
  1260. /*
  1261. * Now Fujitsu TurboSparc. It might happen that it is
  1262. * in Swift emulation mode, so we will check later...
  1263. */
  1264. if (psr_typ == 0 && psr_vers == 5) {
  1265. init_turbosparc();
  1266. return;
  1267. }
  1268. /* Next check for Fujitsu Swift. */
  1269. if(psr_typ == 0 && psr_vers == 4) {
  1270. phandle cpunode;
  1271. char node_str[128];
  1272. /* Look if it is not a TurboSparc emulating Swift... */
  1273. cpunode = prom_getchild(prom_root_node);
  1274. while((cpunode = prom_getsibling(cpunode)) != 0) {
  1275. prom_getstring(cpunode, "device_type", node_str, sizeof(node_str));
  1276. if(!strcmp(node_str, "cpu")) {
  1277. if (!prom_getintdefault(cpunode, "psr-implementation", 1) &&
  1278. prom_getintdefault(cpunode, "psr-version", 1) == 5) {
  1279. init_turbosparc();
  1280. return;
  1281. }
  1282. break;
  1283. }
  1284. }
  1285. init_swift();
  1286. return;
  1287. }
  1288. /* Now the Viking family of srmmu. */
  1289. if(psr_typ == 4 &&
  1290. ((psr_vers == 0) ||
  1291. ((psr_vers == 1) && (mod_typ == 0) && (mod_rev == 0)))) {
  1292. init_viking();
  1293. return;
  1294. }
  1295. /* Finally the Tsunami. */
  1296. if(psr_typ == 4 && psr_vers == 1 && (mod_typ || mod_rev)) {
  1297. init_tsunami();
  1298. return;
  1299. }
  1300. /* Oh well */
  1301. srmmu_is_bad();
  1302. }
  1303. #ifdef CONFIG_SMP
  1304. /* Local cross-calls. */
  1305. static void smp_flush_page_for_dma(unsigned long page)
  1306. {
  1307. xc1((smpfunc_t) local_ops->page_for_dma, page);
  1308. local_ops->page_for_dma(page);
  1309. }
  1310. static void smp_flush_cache_all(void)
  1311. {
  1312. xc0((smpfunc_t) local_ops->cache_all);
  1313. local_ops->cache_all();
  1314. }
  1315. static void smp_flush_tlb_all(void)
  1316. {
  1317. xc0((smpfunc_t) local_ops->tlb_all);
  1318. local_ops->tlb_all();
  1319. }
  1320. static void smp_flush_cache_mm(struct mm_struct *mm)
  1321. {
  1322. if (mm->context != NO_CONTEXT) {
  1323. cpumask_t cpu_mask;
  1324. cpumask_copy(&cpu_mask, mm_cpumask(mm));
  1325. cpumask_clear_cpu(smp_processor_id(), &cpu_mask);
  1326. if (!cpumask_empty(&cpu_mask))
  1327. xc1((smpfunc_t) local_ops->cache_mm, (unsigned long) mm);
  1328. local_ops->cache_mm(mm);
  1329. }
  1330. }
  1331. static void smp_flush_tlb_mm(struct mm_struct *mm)
  1332. {
  1333. if (mm->context != NO_CONTEXT) {
  1334. cpumask_t cpu_mask;
  1335. cpumask_copy(&cpu_mask, mm_cpumask(mm));
  1336. cpumask_clear_cpu(smp_processor_id(), &cpu_mask);
  1337. if (!cpumask_empty(&cpu_mask)) {
  1338. xc1((smpfunc_t) local_ops->tlb_mm, (unsigned long) mm);
  1339. if (atomic_read(&mm->mm_users) == 1 && current->active_mm == mm)
  1340. cpumask_copy(mm_cpumask(mm),
  1341. cpumask_of(smp_processor_id()));
  1342. }
  1343. local_ops->tlb_mm(mm);
  1344. }
  1345. }
  1346. static void smp_flush_cache_range(struct vm_area_struct *vma,
  1347. unsigned long start,
  1348. unsigned long end)
  1349. {
  1350. struct mm_struct *mm = vma->vm_mm;
  1351. if (mm->context != NO_CONTEXT) {
  1352. cpumask_t cpu_mask;
  1353. cpumask_copy(&cpu_mask, mm_cpumask(mm));
  1354. cpumask_clear_cpu(smp_processor_id(), &cpu_mask);
  1355. if (!cpumask_empty(&cpu_mask))
  1356. xc3((smpfunc_t) local_ops->cache_range,
  1357. (unsigned long) vma, start, end);
  1358. local_ops->cache_range(vma, start, end);
  1359. }
  1360. }
  1361. static void smp_flush_tlb_range(struct vm_area_struct *vma,
  1362. unsigned long start,
  1363. unsigned long end)
  1364. {
  1365. struct mm_struct *mm = vma->vm_mm;
  1366. if (mm->context != NO_CONTEXT) {
  1367. cpumask_t cpu_mask;
  1368. cpumask_copy(&cpu_mask, mm_cpumask(mm));
  1369. cpumask_clear_cpu(smp_processor_id(), &cpu_mask);
  1370. if (!cpumask_empty(&cpu_mask))
  1371. xc3((smpfunc_t) local_ops->tlb_range,
  1372. (unsigned long) vma, start, end);
  1373. local_ops->tlb_range(vma, start, end);
  1374. }
  1375. }
  1376. static void smp_flush_cache_page(struct vm_area_struct *vma, unsigned long page)
  1377. {
  1378. struct mm_struct *mm = vma->vm_mm;
  1379. if (mm->context != NO_CONTEXT) {
  1380. cpumask_t cpu_mask;
  1381. cpumask_copy(&cpu_mask, mm_cpumask(mm));
  1382. cpumask_clear_cpu(smp_processor_id(), &cpu_mask);
  1383. if (!cpumask_empty(&cpu_mask))
  1384. xc2((smpfunc_t) local_ops->cache_page,
  1385. (unsigned long) vma, page);
  1386. local_ops->cache_page(vma, page);
  1387. }
  1388. }
  1389. static void smp_flush_tlb_page(struct vm_area_struct *vma, unsigned long page)
  1390. {
  1391. struct mm_struct *mm = vma->vm_mm;
  1392. if (mm->context != NO_CONTEXT) {
  1393. cpumask_t cpu_mask;
  1394. cpumask_copy(&cpu_mask, mm_cpumask(mm));
  1395. cpumask_clear_cpu(smp_processor_id(), &cpu_mask);
  1396. if (!cpumask_empty(&cpu_mask))
  1397. xc2((smpfunc_t) local_ops->tlb_page,
  1398. (unsigned long) vma, page);
  1399. local_ops->tlb_page(vma, page);
  1400. }
  1401. }
  1402. static void smp_flush_page_to_ram(unsigned long page)
  1403. {
  1404. /* Current theory is that those who call this are the one's
  1405. * who have just dirtied their cache with the pages contents
  1406. * in kernel space, therefore we only run this on local cpu.
  1407. *
  1408. * XXX This experiment failed, research further... -DaveM
  1409. */
  1410. #if 1
  1411. xc1((smpfunc_t) local_ops->page_to_ram, page);
  1412. #endif
  1413. local_ops->page_to_ram(page);
  1414. }
  1415. static void smp_flush_sig_insns(struct mm_struct *mm, unsigned long insn_addr)
  1416. {
  1417. cpumask_t cpu_mask;
  1418. cpumask_copy(&cpu_mask, mm_cpumask(mm));
  1419. cpumask_clear_cpu(smp_processor_id(), &cpu_mask);
  1420. if (!cpumask_empty(&cpu_mask))
  1421. xc2((smpfunc_t) local_ops->sig_insns,
  1422. (unsigned long) mm, insn_addr);
  1423. local_ops->sig_insns(mm, insn_addr);
  1424. }
  1425. static struct sparc32_cachetlb_ops smp_cachetlb_ops = {
  1426. .cache_all = smp_flush_cache_all,
  1427. .cache_mm = smp_flush_cache_mm,
  1428. .cache_page = smp_flush_cache_page,
  1429. .cache_range = smp_flush_cache_range,
  1430. .tlb_all = smp_flush_tlb_all,
  1431. .tlb_mm = smp_flush_tlb_mm,
  1432. .tlb_page = smp_flush_tlb_page,
  1433. .tlb_range = smp_flush_tlb_range,
  1434. .page_to_ram = smp_flush_page_to_ram,
  1435. .sig_insns = smp_flush_sig_insns,
  1436. .page_for_dma = smp_flush_page_for_dma,
  1437. };
  1438. #endif
  1439. /* Load up routines and constants for sun4m and sun4d mmu */
  1440. void __init load_mmu(void)
  1441. {
  1442. extern void ld_mmu_iommu(void);
  1443. extern void ld_mmu_iounit(void);
  1444. /* Functions */
  1445. get_srmmu_type();
  1446. #ifdef CONFIG_SMP
  1447. /* El switcheroo... */
  1448. local_ops = sparc32_cachetlb_ops;
  1449. if (sparc_cpu_model == sun4d || sparc_cpu_model == sparc_leon) {
  1450. smp_cachetlb_ops.tlb_all = local_ops->tlb_all;
  1451. smp_cachetlb_ops.tlb_mm = local_ops->tlb_mm;
  1452. smp_cachetlb_ops.tlb_range = local_ops->tlb_range;
  1453. smp_cachetlb_ops.tlb_page = local_ops->tlb_page;
  1454. }
  1455. if (poke_srmmu == poke_viking) {
  1456. /* Avoid unnecessary cross calls. */
  1457. smp_cachetlb_ops.cache_all = local_ops->cache_all;
  1458. smp_cachetlb_ops.cache_mm = local_ops->cache_mm;
  1459. smp_cachetlb_ops.cache_range = local_ops->cache_range;
  1460. smp_cachetlb_ops.cache_page = local_ops->cache_page;
  1461. smp_cachetlb_ops.page_to_ram = local_ops->page_to_ram;
  1462. smp_cachetlb_ops.sig_insns = local_ops->sig_insns;
  1463. smp_cachetlb_ops.page_for_dma = local_ops->page_for_dma;
  1464. }
  1465. /* It really is const after this point. */
  1466. sparc32_cachetlb_ops = (const struct sparc32_cachetlb_ops *)
  1467. &smp_cachetlb_ops;
  1468. #endif
  1469. if (sparc_cpu_model == sun4d)
  1470. ld_mmu_iounit();
  1471. else
  1472. ld_mmu_iommu();
  1473. #ifdef CONFIG_SMP
  1474. if (sparc_cpu_model == sun4d)
  1475. sun4d_init_smp();
  1476. else if (sparc_cpu_model == sparc_leon)
  1477. leon_init_smp();
  1478. else
  1479. sun4m_init_smp();
  1480. #endif
  1481. }