srmmu.c 50 KB

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