srmmu.c 67 KB

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