srmmu.c 48 KB

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