srmmu.c 69 KB

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