srmmu.c 63 KB

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