srmmu.c 67 KB

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