srmmu.c 67 KB

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