srmmu.c 61 KB

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