srmmu.c 67 KB

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