srmmu.c 62 KB

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