srmmu.c 63 KB

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