sun4c.c 63 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279
  1. /* $Id: sun4c.c,v 1.212 2001/12/21 04:56:15 davem Exp $
  2. * sun4c.c: Doing in software what should be done in hardware.
  3. *
  4. * Copyright (C) 1996 David S. Miller (davem@caip.rutgers.edu)
  5. * Copyright (C) 1996 Eddie C. Dost (ecd@skynet.be)
  6. * Copyright (C) 1996 Andrew Tridgell (Andrew.Tridgell@anu.edu.au)
  7. * Copyright (C) 1997-2000 Anton Blanchard (anton@samba.org)
  8. * Copyright (C) 1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
  9. */
  10. #define NR_TASK_BUCKETS 512
  11. #include <linux/kernel.h>
  12. #include <linux/mm.h>
  13. #include <linux/init.h>
  14. #include <linux/bootmem.h>
  15. #include <linux/highmem.h>
  16. #include <linux/fs.h>
  17. #include <linux/seq_file.h>
  18. #include <asm/scatterlist.h>
  19. #include <asm/page.h>
  20. #include <asm/pgalloc.h>
  21. #include <asm/pgtable.h>
  22. #include <asm/vaddrs.h>
  23. #include <asm/idprom.h>
  24. #include <asm/machines.h>
  25. #include <asm/memreg.h>
  26. #include <asm/processor.h>
  27. #include <asm/auxio.h>
  28. #include <asm/io.h>
  29. #include <asm/oplib.h>
  30. #include <asm/openprom.h>
  31. #include <asm/mmu_context.h>
  32. #include <asm/sun4paddr.h>
  33. #include <asm/highmem.h>
  34. #include <asm/btfixup.h>
  35. #include <asm/cacheflush.h>
  36. #include <asm/tlbflush.h>
  37. /* Because of our dynamic kernel TLB miss strategy, and how
  38. * our DVMA mapping allocation works, you _MUST_:
  39. *
  40. * 1) Disable interrupts _and_ not touch any dynamic kernel
  41. * memory while messing with kernel MMU state. By
  42. * dynamic memory I mean any object which is not in
  43. * the kernel image itself or a thread_union (both of
  44. * which are locked into the MMU).
  45. * 2) Disable interrupts while messing with user MMU state.
  46. */
  47. extern int num_segmaps, num_contexts;
  48. extern unsigned long page_kernel;
  49. #ifdef CONFIG_SUN4
  50. #define SUN4C_VAC_SIZE sun4c_vacinfo.num_bytes
  51. #else
  52. /* That's it, we prom_halt() on sun4c if the cache size is something other than 65536.
  53. * So let's save some cycles and just use that everywhere except for that bootup
  54. * sanity check.
  55. */
  56. #define SUN4C_VAC_SIZE 65536
  57. #endif
  58. #define SUN4C_KERNEL_BUCKETS 32
  59. /* Flushing the cache. */
  60. struct sun4c_vac_props sun4c_vacinfo;
  61. unsigned long sun4c_kernel_faults;
  62. /* Invalidate every sun4c cache line tag. */
  63. static void __init sun4c_flush_all(void)
  64. {
  65. unsigned long begin, end;
  66. if (sun4c_vacinfo.on)
  67. panic("SUN4C: AIEEE, trying to invalidate vac while it is on.");
  68. /* Clear 'valid' bit in all cache line tags */
  69. begin = AC_CACHETAGS;
  70. end = (AC_CACHETAGS + SUN4C_VAC_SIZE);
  71. while (begin < end) {
  72. __asm__ __volatile__("sta %%g0, [%0] %1\n\t" : :
  73. "r" (begin), "i" (ASI_CONTROL));
  74. begin += sun4c_vacinfo.linesize;
  75. }
  76. }
  77. static void sun4c_flush_context_hw(void)
  78. {
  79. unsigned long end = SUN4C_VAC_SIZE;
  80. __asm__ __volatile__(
  81. "1: addcc %0, -4096, %0\n\t"
  82. " bne 1b\n\t"
  83. " sta %%g0, [%0] %2"
  84. : "=&r" (end)
  85. : "0" (end), "i" (ASI_HWFLUSHCONTEXT)
  86. : "cc");
  87. }
  88. /* Must be called minimally with IRQs disabled. */
  89. static void sun4c_flush_segment_hw(unsigned long addr)
  90. {
  91. if (sun4c_get_segmap(addr) != invalid_segment) {
  92. unsigned long vac_size = SUN4C_VAC_SIZE;
  93. __asm__ __volatile__(
  94. "1: addcc %0, -4096, %0\n\t"
  95. " bne 1b\n\t"
  96. " sta %%g0, [%2 + %0] %3"
  97. : "=&r" (vac_size)
  98. : "0" (vac_size), "r" (addr), "i" (ASI_HWFLUSHSEG)
  99. : "cc");
  100. }
  101. }
  102. /* File local boot time fixups. */
  103. BTFIXUPDEF_CALL(void, sun4c_flush_page, unsigned long)
  104. BTFIXUPDEF_CALL(void, sun4c_flush_segment, unsigned long)
  105. BTFIXUPDEF_CALL(void, sun4c_flush_context, void)
  106. #define sun4c_flush_page(addr) BTFIXUP_CALL(sun4c_flush_page)(addr)
  107. #define sun4c_flush_segment(addr) BTFIXUP_CALL(sun4c_flush_segment)(addr)
  108. #define sun4c_flush_context() BTFIXUP_CALL(sun4c_flush_context)()
  109. /* Must be called minimally with interrupts disabled. */
  110. static void sun4c_flush_page_hw(unsigned long addr)
  111. {
  112. addr &= PAGE_MASK;
  113. if ((int)sun4c_get_pte(addr) < 0)
  114. __asm__ __volatile__("sta %%g0, [%0] %1"
  115. : : "r" (addr), "i" (ASI_HWFLUSHPAGE));
  116. }
  117. /* Don't inline the software version as it eats too many cache lines if expanded. */
  118. static void sun4c_flush_context_sw(void)
  119. {
  120. unsigned long nbytes = SUN4C_VAC_SIZE;
  121. unsigned long lsize = sun4c_vacinfo.linesize;
  122. __asm__ __volatile__(
  123. "add %2, %2, %%g1\n\t"
  124. "add %2, %%g1, %%g2\n\t"
  125. "add %2, %%g2, %%g3\n\t"
  126. "add %2, %%g3, %%g4\n\t"
  127. "add %2, %%g4, %%g5\n\t"
  128. "add %2, %%g5, %%o4\n\t"
  129. "add %2, %%o4, %%o5\n"
  130. "1:\n\t"
  131. "subcc %0, %%o5, %0\n\t"
  132. "sta %%g0, [%0] %3\n\t"
  133. "sta %%g0, [%0 + %2] %3\n\t"
  134. "sta %%g0, [%0 + %%g1] %3\n\t"
  135. "sta %%g0, [%0 + %%g2] %3\n\t"
  136. "sta %%g0, [%0 + %%g3] %3\n\t"
  137. "sta %%g0, [%0 + %%g4] %3\n\t"
  138. "sta %%g0, [%0 + %%g5] %3\n\t"
  139. "bg 1b\n\t"
  140. " sta %%g0, [%1 + %%o4] %3\n"
  141. : "=&r" (nbytes)
  142. : "0" (nbytes), "r" (lsize), "i" (ASI_FLUSHCTX)
  143. : "g1", "g2", "g3", "g4", "g5", "o4", "o5", "cc");
  144. }
  145. /* Don't inline the software version as it eats too many cache lines if expanded. */
  146. static void sun4c_flush_segment_sw(unsigned long addr)
  147. {
  148. if (sun4c_get_segmap(addr) != invalid_segment) {
  149. unsigned long nbytes = SUN4C_VAC_SIZE;
  150. unsigned long lsize = sun4c_vacinfo.linesize;
  151. __asm__ __volatile__(
  152. "add %2, %2, %%g1\n\t"
  153. "add %2, %%g1, %%g2\n\t"
  154. "add %2, %%g2, %%g3\n\t"
  155. "add %2, %%g3, %%g4\n\t"
  156. "add %2, %%g4, %%g5\n\t"
  157. "add %2, %%g5, %%o4\n\t"
  158. "add %2, %%o4, %%o5\n"
  159. "1:\n\t"
  160. "subcc %1, %%o5, %1\n\t"
  161. "sta %%g0, [%0] %6\n\t"
  162. "sta %%g0, [%0 + %2] %6\n\t"
  163. "sta %%g0, [%0 + %%g1] %6\n\t"
  164. "sta %%g0, [%0 + %%g2] %6\n\t"
  165. "sta %%g0, [%0 + %%g3] %6\n\t"
  166. "sta %%g0, [%0 + %%g4] %6\n\t"
  167. "sta %%g0, [%0 + %%g5] %6\n\t"
  168. "sta %%g0, [%0 + %%o4] %6\n\t"
  169. "bg 1b\n\t"
  170. " add %0, %%o5, %0\n"
  171. : "=&r" (addr), "=&r" (nbytes), "=&r" (lsize)
  172. : "0" (addr), "1" (nbytes), "2" (lsize),
  173. "i" (ASI_FLUSHSEG)
  174. : "g1", "g2", "g3", "g4", "g5", "o4", "o5", "cc");
  175. }
  176. }
  177. /* Don't inline the software version as it eats too many cache lines if expanded. */
  178. static void sun4c_flush_page_sw(unsigned long addr)
  179. {
  180. addr &= PAGE_MASK;
  181. if ((sun4c_get_pte(addr) & (_SUN4C_PAGE_NOCACHE | _SUN4C_PAGE_VALID)) ==
  182. _SUN4C_PAGE_VALID) {
  183. unsigned long left = PAGE_SIZE;
  184. unsigned long lsize = sun4c_vacinfo.linesize;
  185. __asm__ __volatile__(
  186. "add %2, %2, %%g1\n\t"
  187. "add %2, %%g1, %%g2\n\t"
  188. "add %2, %%g2, %%g3\n\t"
  189. "add %2, %%g3, %%g4\n\t"
  190. "add %2, %%g4, %%g5\n\t"
  191. "add %2, %%g5, %%o4\n\t"
  192. "add %2, %%o4, %%o5\n"
  193. "1:\n\t"
  194. "subcc %1, %%o5, %1\n\t"
  195. "sta %%g0, [%0] %6\n\t"
  196. "sta %%g0, [%0 + %2] %6\n\t"
  197. "sta %%g0, [%0 + %%g1] %6\n\t"
  198. "sta %%g0, [%0 + %%g2] %6\n\t"
  199. "sta %%g0, [%0 + %%g3] %6\n\t"
  200. "sta %%g0, [%0 + %%g4] %6\n\t"
  201. "sta %%g0, [%0 + %%g5] %6\n\t"
  202. "sta %%g0, [%0 + %%o4] %6\n\t"
  203. "bg 1b\n\t"
  204. " add %0, %%o5, %0\n"
  205. : "=&r" (addr), "=&r" (left), "=&r" (lsize)
  206. : "0" (addr), "1" (left), "2" (lsize),
  207. "i" (ASI_FLUSHPG)
  208. : "g1", "g2", "g3", "g4", "g5", "o4", "o5", "cc");
  209. }
  210. }
  211. /* The sun4c's do have an on chip store buffer. And the way you
  212. * clear them out isn't so obvious. The only way I can think of
  213. * to accomplish this is to read the current context register,
  214. * store the same value there, then read an external hardware
  215. * register.
  216. */
  217. void sun4c_complete_all_stores(void)
  218. {
  219. volatile int _unused;
  220. _unused = sun4c_get_context();
  221. sun4c_set_context(_unused);
  222. #ifdef CONFIG_SUN_AUXIO
  223. _unused = get_auxio();
  224. #endif
  225. }
  226. /* Bootup utility functions. */
  227. static inline void sun4c_init_clean_segmap(unsigned char pseg)
  228. {
  229. unsigned long vaddr;
  230. sun4c_put_segmap(0, pseg);
  231. for (vaddr = 0; vaddr < SUN4C_REAL_PGDIR_SIZE; vaddr += PAGE_SIZE)
  232. sun4c_put_pte(vaddr, 0);
  233. sun4c_put_segmap(0, invalid_segment);
  234. }
  235. static inline void sun4c_init_clean_mmu(unsigned long kernel_end)
  236. {
  237. unsigned long vaddr;
  238. unsigned char savectx, ctx;
  239. savectx = sun4c_get_context();
  240. for (ctx = 0; ctx < num_contexts; ctx++) {
  241. sun4c_set_context(ctx);
  242. for (vaddr = 0; vaddr < 0x20000000; vaddr += SUN4C_REAL_PGDIR_SIZE)
  243. sun4c_put_segmap(vaddr, invalid_segment);
  244. for (vaddr = 0xe0000000; vaddr < KERNBASE; vaddr += SUN4C_REAL_PGDIR_SIZE)
  245. sun4c_put_segmap(vaddr, invalid_segment);
  246. for (vaddr = kernel_end; vaddr < KADB_DEBUGGER_BEGVM; vaddr += SUN4C_REAL_PGDIR_SIZE)
  247. sun4c_put_segmap(vaddr, invalid_segment);
  248. for (vaddr = LINUX_OPPROM_ENDVM; vaddr; vaddr += SUN4C_REAL_PGDIR_SIZE)
  249. sun4c_put_segmap(vaddr, invalid_segment);
  250. }
  251. sun4c_set_context(savectx);
  252. }
  253. void __init sun4c_probe_vac(void)
  254. {
  255. sun4c_disable_vac();
  256. if (ARCH_SUN4) {
  257. switch (idprom->id_machtype) {
  258. case (SM_SUN4|SM_4_110):
  259. sun4c_vacinfo.type = VAC_NONE;
  260. sun4c_vacinfo.num_bytes = 0;
  261. sun4c_vacinfo.linesize = 0;
  262. sun4c_vacinfo.do_hwflushes = 0;
  263. prom_printf("No VAC. Get some bucks and buy a real computer.");
  264. prom_halt();
  265. break;
  266. case (SM_SUN4|SM_4_260):
  267. sun4c_vacinfo.type = VAC_WRITE_BACK;
  268. sun4c_vacinfo.num_bytes = 128 * 1024;
  269. sun4c_vacinfo.linesize = 16;
  270. sun4c_vacinfo.do_hwflushes = 0;
  271. break;
  272. case (SM_SUN4|SM_4_330):
  273. sun4c_vacinfo.type = VAC_WRITE_THROUGH;
  274. sun4c_vacinfo.num_bytes = 128 * 1024;
  275. sun4c_vacinfo.linesize = 16;
  276. sun4c_vacinfo.do_hwflushes = 0;
  277. break;
  278. case (SM_SUN4|SM_4_470):
  279. sun4c_vacinfo.type = VAC_WRITE_BACK;
  280. sun4c_vacinfo.num_bytes = 128 * 1024;
  281. sun4c_vacinfo.linesize = 32;
  282. sun4c_vacinfo.do_hwflushes = 0;
  283. break;
  284. default:
  285. prom_printf("Cannot initialize VAC - weird sun4 model idprom->id_machtype = %d", idprom->id_machtype);
  286. prom_halt();
  287. };
  288. } else {
  289. sun4c_vacinfo.type = VAC_WRITE_THROUGH;
  290. if ((idprom->id_machtype == (SM_SUN4C | SM_4C_SS1)) ||
  291. (idprom->id_machtype == (SM_SUN4C | SM_4C_SS1PLUS))) {
  292. /* PROM on SS1 lacks this info, to be super safe we
  293. * hard code it here since this arch is cast in stone.
  294. */
  295. sun4c_vacinfo.num_bytes = 65536;
  296. sun4c_vacinfo.linesize = 16;
  297. } else {
  298. sun4c_vacinfo.num_bytes =
  299. prom_getintdefault(prom_root_node, "vac-size", 65536);
  300. sun4c_vacinfo.linesize =
  301. prom_getintdefault(prom_root_node, "vac-linesize", 16);
  302. }
  303. sun4c_vacinfo.do_hwflushes =
  304. prom_getintdefault(prom_root_node, "vac-hwflush", 0);
  305. if (sun4c_vacinfo.do_hwflushes == 0)
  306. sun4c_vacinfo.do_hwflushes =
  307. prom_getintdefault(prom_root_node, "vac_hwflush", 0);
  308. if (sun4c_vacinfo.num_bytes != 65536) {
  309. prom_printf("WEIRD Sun4C VAC cache size, "
  310. "tell sparclinux@vger.kernel.org");
  311. prom_halt();
  312. }
  313. }
  314. sun4c_vacinfo.num_lines =
  315. (sun4c_vacinfo.num_bytes / sun4c_vacinfo.linesize);
  316. switch (sun4c_vacinfo.linesize) {
  317. case 16:
  318. sun4c_vacinfo.log2lsize = 4;
  319. break;
  320. case 32:
  321. sun4c_vacinfo.log2lsize = 5;
  322. break;
  323. default:
  324. prom_printf("probe_vac: Didn't expect vac-linesize of %d, halting\n",
  325. sun4c_vacinfo.linesize);
  326. prom_halt();
  327. };
  328. sun4c_flush_all();
  329. sun4c_enable_vac();
  330. }
  331. /* Patch instructions for the low level kernel fault handler. */
  332. extern unsigned long invalid_segment_patch1, invalid_segment_patch1_ff;
  333. extern unsigned long invalid_segment_patch2, invalid_segment_patch2_ff;
  334. extern unsigned long invalid_segment_patch1_1ff, invalid_segment_patch2_1ff;
  335. extern unsigned long num_context_patch1, num_context_patch1_16;
  336. extern unsigned long num_context_patch2_16;
  337. extern unsigned long vac_linesize_patch, vac_linesize_patch_32;
  338. extern unsigned long vac_hwflush_patch1, vac_hwflush_patch1_on;
  339. extern unsigned long vac_hwflush_patch2, vac_hwflush_patch2_on;
  340. #define PATCH_INSN(src, dst) do { \
  341. daddr = &(dst); \
  342. iaddr = &(src); \
  343. *daddr = *iaddr; \
  344. } while (0)
  345. static void __init patch_kernel_fault_handler(void)
  346. {
  347. unsigned long *iaddr, *daddr;
  348. switch (num_segmaps) {
  349. case 128:
  350. /* Default, nothing to do. */
  351. break;
  352. case 256:
  353. PATCH_INSN(invalid_segment_patch1_ff,
  354. invalid_segment_patch1);
  355. PATCH_INSN(invalid_segment_patch2_ff,
  356. invalid_segment_patch2);
  357. break;
  358. case 512:
  359. PATCH_INSN(invalid_segment_patch1_1ff,
  360. invalid_segment_patch1);
  361. PATCH_INSN(invalid_segment_patch2_1ff,
  362. invalid_segment_patch2);
  363. break;
  364. default:
  365. prom_printf("Unhandled number of segmaps: %d\n",
  366. num_segmaps);
  367. prom_halt();
  368. };
  369. switch (num_contexts) {
  370. case 8:
  371. /* Default, nothing to do. */
  372. break;
  373. case 16:
  374. PATCH_INSN(num_context_patch1_16,
  375. num_context_patch1);
  376. break;
  377. default:
  378. prom_printf("Unhandled number of contexts: %d\n",
  379. num_contexts);
  380. prom_halt();
  381. };
  382. if (sun4c_vacinfo.do_hwflushes != 0) {
  383. PATCH_INSN(vac_hwflush_patch1_on, vac_hwflush_patch1);
  384. PATCH_INSN(vac_hwflush_patch2_on, vac_hwflush_patch2);
  385. } else {
  386. switch (sun4c_vacinfo.linesize) {
  387. case 16:
  388. /* Default, nothing to do. */
  389. break;
  390. case 32:
  391. PATCH_INSN(vac_linesize_patch_32, vac_linesize_patch);
  392. break;
  393. default:
  394. prom_printf("Impossible VAC linesize %d, halting...\n",
  395. sun4c_vacinfo.linesize);
  396. prom_halt();
  397. };
  398. }
  399. }
  400. static void __init sun4c_probe_mmu(void)
  401. {
  402. if (ARCH_SUN4) {
  403. switch (idprom->id_machtype) {
  404. case (SM_SUN4|SM_4_110):
  405. prom_printf("No support for 4100 yet\n");
  406. prom_halt();
  407. num_segmaps = 256;
  408. num_contexts = 8;
  409. break;
  410. case (SM_SUN4|SM_4_260):
  411. /* should be 512 segmaps. when it get fixed */
  412. num_segmaps = 256;
  413. num_contexts = 16;
  414. break;
  415. case (SM_SUN4|SM_4_330):
  416. num_segmaps = 256;
  417. num_contexts = 16;
  418. break;
  419. case (SM_SUN4|SM_4_470):
  420. /* should be 1024 segmaps. when it get fixed */
  421. num_segmaps = 256;
  422. num_contexts = 64;
  423. break;
  424. default:
  425. prom_printf("Invalid SUN4 model\n");
  426. prom_halt();
  427. };
  428. } else {
  429. if ((idprom->id_machtype == (SM_SUN4C | SM_4C_SS1)) ||
  430. (idprom->id_machtype == (SM_SUN4C | SM_4C_SS1PLUS))) {
  431. /* Hardcode these just to be safe, PROM on SS1 does
  432. * not have this info available in the root node.
  433. */
  434. num_segmaps = 128;
  435. num_contexts = 8;
  436. } else {
  437. num_segmaps =
  438. prom_getintdefault(prom_root_node, "mmu-npmg", 128);
  439. num_contexts =
  440. prom_getintdefault(prom_root_node, "mmu-nctx", 0x8);
  441. }
  442. }
  443. patch_kernel_fault_handler();
  444. }
  445. volatile unsigned long __iomem *sun4c_memerr_reg = NULL;
  446. void __init sun4c_probe_memerr_reg(void)
  447. {
  448. int node;
  449. struct linux_prom_registers regs[1];
  450. if (ARCH_SUN4) {
  451. sun4c_memerr_reg = ioremap(sun4_memreg_physaddr, PAGE_SIZE);
  452. } else {
  453. node = prom_getchild(prom_root_node);
  454. node = prom_searchsiblings(prom_root_node, "memory-error");
  455. if (!node)
  456. return;
  457. if (prom_getproperty(node, "reg", (char *)regs, sizeof(regs)) <= 0)
  458. return;
  459. /* hmm I think regs[0].which_io is zero here anyways */
  460. sun4c_memerr_reg = ioremap(regs[0].phys_addr, regs[0].reg_size);
  461. }
  462. }
  463. static inline void sun4c_init_ss2_cache_bug(void)
  464. {
  465. extern unsigned long start;
  466. if ((idprom->id_machtype == (SM_SUN4C | SM_4C_SS2)) ||
  467. (idprom->id_machtype == (SM_SUN4C | SM_4C_IPX)) ||
  468. (idprom->id_machtype == (SM_SUN4 | SM_4_330)) ||
  469. (idprom->id_machtype == (SM_SUN4C | SM_4C_ELC))) {
  470. /* Whee.. */
  471. printk("SS2 cache bug detected, uncaching trap table page\n");
  472. sun4c_flush_page((unsigned int) &start);
  473. sun4c_put_pte(((unsigned long) &start),
  474. (sun4c_get_pte((unsigned long) &start) | _SUN4C_PAGE_NOCACHE));
  475. }
  476. }
  477. /* Addr is always aligned on a page boundary for us already. */
  478. static int sun4c_map_dma_area(dma_addr_t *pba, unsigned long va,
  479. unsigned long addr, int len)
  480. {
  481. unsigned long page, end;
  482. *pba = addr;
  483. end = PAGE_ALIGN((addr + len));
  484. while (addr < end) {
  485. page = va;
  486. sun4c_flush_page(page);
  487. page -= PAGE_OFFSET;
  488. page >>= PAGE_SHIFT;
  489. page |= (_SUN4C_PAGE_VALID | _SUN4C_PAGE_DIRTY |
  490. _SUN4C_PAGE_NOCACHE | _SUN4C_PAGE_PRIV);
  491. sun4c_put_pte(addr, page);
  492. addr += PAGE_SIZE;
  493. va += PAGE_SIZE;
  494. }
  495. return 0;
  496. }
  497. static struct page *sun4c_translate_dvma(unsigned long busa)
  498. {
  499. /* Fortunately for us, bus_addr == uncached_virt in sun4c. */
  500. unsigned long pte = sun4c_get_pte(busa);
  501. return pfn_to_page(pte & SUN4C_PFN_MASK);
  502. }
  503. static void sun4c_unmap_dma_area(unsigned long busa, int len)
  504. {
  505. /* Fortunately for us, bus_addr == uncached_virt in sun4c. */
  506. /* XXX Implement this */
  507. }
  508. /* TLB management. */
  509. /* Don't change this struct without changing entry.S. This is used
  510. * in the in-window kernel fault handler, and you don't want to mess
  511. * with that. (See sun4c_fault in entry.S).
  512. */
  513. struct sun4c_mmu_entry {
  514. struct sun4c_mmu_entry *next;
  515. struct sun4c_mmu_entry *prev;
  516. unsigned long vaddr;
  517. unsigned char pseg;
  518. unsigned char locked;
  519. /* For user mappings only, and completely hidden from kernel
  520. * TLB miss code.
  521. */
  522. unsigned char ctx;
  523. struct sun4c_mmu_entry *lru_next;
  524. struct sun4c_mmu_entry *lru_prev;
  525. };
  526. static struct sun4c_mmu_entry mmu_entry_pool[SUN4C_MAX_SEGMAPS];
  527. static void __init sun4c_init_mmu_entry_pool(void)
  528. {
  529. int i;
  530. for (i=0; i < SUN4C_MAX_SEGMAPS; i++) {
  531. mmu_entry_pool[i].pseg = i;
  532. mmu_entry_pool[i].next = NULL;
  533. mmu_entry_pool[i].prev = NULL;
  534. mmu_entry_pool[i].vaddr = 0;
  535. mmu_entry_pool[i].locked = 0;
  536. mmu_entry_pool[i].ctx = 0;
  537. mmu_entry_pool[i].lru_next = NULL;
  538. mmu_entry_pool[i].lru_prev = NULL;
  539. }
  540. mmu_entry_pool[invalid_segment].locked = 1;
  541. }
  542. static inline void fix_permissions(unsigned long vaddr, unsigned long bits_on,
  543. unsigned long bits_off)
  544. {
  545. unsigned long start, end;
  546. end = vaddr + SUN4C_REAL_PGDIR_SIZE;
  547. for (start = vaddr; start < end; start += PAGE_SIZE)
  548. if (sun4c_get_pte(start) & _SUN4C_PAGE_VALID)
  549. sun4c_put_pte(start, (sun4c_get_pte(start) | bits_on) &
  550. ~bits_off);
  551. }
  552. static inline void sun4c_init_map_kernelprom(unsigned long kernel_end)
  553. {
  554. unsigned long vaddr;
  555. unsigned char pseg, ctx;
  556. #ifdef CONFIG_SUN4
  557. /* sun4/110 and 260 have no kadb. */
  558. if ((idprom->id_machtype != (SM_SUN4 | SM_4_260)) &&
  559. (idprom->id_machtype != (SM_SUN4 | SM_4_110))) {
  560. #endif
  561. for (vaddr = KADB_DEBUGGER_BEGVM;
  562. vaddr < LINUX_OPPROM_ENDVM;
  563. vaddr += SUN4C_REAL_PGDIR_SIZE) {
  564. pseg = sun4c_get_segmap(vaddr);
  565. if (pseg != invalid_segment) {
  566. mmu_entry_pool[pseg].locked = 1;
  567. for (ctx = 0; ctx < num_contexts; ctx++)
  568. prom_putsegment(ctx, vaddr, pseg);
  569. fix_permissions(vaddr, _SUN4C_PAGE_PRIV, 0);
  570. }
  571. }
  572. #ifdef CONFIG_SUN4
  573. }
  574. #endif
  575. for (vaddr = KERNBASE; vaddr < kernel_end; vaddr += SUN4C_REAL_PGDIR_SIZE) {
  576. pseg = sun4c_get_segmap(vaddr);
  577. mmu_entry_pool[pseg].locked = 1;
  578. for (ctx = 0; ctx < num_contexts; ctx++)
  579. prom_putsegment(ctx, vaddr, pseg);
  580. fix_permissions(vaddr, _SUN4C_PAGE_PRIV, _SUN4C_PAGE_NOCACHE);
  581. }
  582. }
  583. static void __init sun4c_init_lock_area(unsigned long start, unsigned long end)
  584. {
  585. int i, ctx;
  586. while (start < end) {
  587. for (i = 0; i < invalid_segment; i++)
  588. if (!mmu_entry_pool[i].locked)
  589. break;
  590. mmu_entry_pool[i].locked = 1;
  591. sun4c_init_clean_segmap(i);
  592. for (ctx = 0; ctx < num_contexts; ctx++)
  593. prom_putsegment(ctx, start, mmu_entry_pool[i].pseg);
  594. start += SUN4C_REAL_PGDIR_SIZE;
  595. }
  596. }
  597. /* Don't change this struct without changing entry.S. This is used
  598. * in the in-window kernel fault handler, and you don't want to mess
  599. * with that. (See sun4c_fault in entry.S).
  600. */
  601. struct sun4c_mmu_ring {
  602. struct sun4c_mmu_entry ringhd;
  603. int num_entries;
  604. };
  605. static struct sun4c_mmu_ring sun4c_context_ring[SUN4C_MAX_CONTEXTS]; /* used user entries */
  606. static struct sun4c_mmu_ring sun4c_ufree_ring; /* free user entries */
  607. static struct sun4c_mmu_ring sun4c_ulru_ring; /* LRU user entries */
  608. struct sun4c_mmu_ring sun4c_kernel_ring; /* used kernel entries */
  609. struct sun4c_mmu_ring sun4c_kfree_ring; /* free kernel entries */
  610. static inline void sun4c_init_rings(void)
  611. {
  612. int i;
  613. for (i = 0; i < SUN4C_MAX_CONTEXTS; i++) {
  614. sun4c_context_ring[i].ringhd.next =
  615. sun4c_context_ring[i].ringhd.prev =
  616. &sun4c_context_ring[i].ringhd;
  617. sun4c_context_ring[i].num_entries = 0;
  618. }
  619. sun4c_ufree_ring.ringhd.next = sun4c_ufree_ring.ringhd.prev =
  620. &sun4c_ufree_ring.ringhd;
  621. sun4c_ufree_ring.num_entries = 0;
  622. sun4c_ulru_ring.ringhd.lru_next = sun4c_ulru_ring.ringhd.lru_prev =
  623. &sun4c_ulru_ring.ringhd;
  624. sun4c_ulru_ring.num_entries = 0;
  625. sun4c_kernel_ring.ringhd.next = sun4c_kernel_ring.ringhd.prev =
  626. &sun4c_kernel_ring.ringhd;
  627. sun4c_kernel_ring.num_entries = 0;
  628. sun4c_kfree_ring.ringhd.next = sun4c_kfree_ring.ringhd.prev =
  629. &sun4c_kfree_ring.ringhd;
  630. sun4c_kfree_ring.num_entries = 0;
  631. }
  632. static void add_ring(struct sun4c_mmu_ring *ring,
  633. struct sun4c_mmu_entry *entry)
  634. {
  635. struct sun4c_mmu_entry *head = &ring->ringhd;
  636. entry->prev = head;
  637. (entry->next = head->next)->prev = entry;
  638. head->next = entry;
  639. ring->num_entries++;
  640. }
  641. static __inline__ void add_lru(struct sun4c_mmu_entry *entry)
  642. {
  643. struct sun4c_mmu_ring *ring = &sun4c_ulru_ring;
  644. struct sun4c_mmu_entry *head = &ring->ringhd;
  645. entry->lru_next = head;
  646. (entry->lru_prev = head->lru_prev)->lru_next = entry;
  647. head->lru_prev = entry;
  648. }
  649. static void add_ring_ordered(struct sun4c_mmu_ring *ring,
  650. struct sun4c_mmu_entry *entry)
  651. {
  652. struct sun4c_mmu_entry *head = &ring->ringhd;
  653. unsigned long addr = entry->vaddr;
  654. while ((head->next != &ring->ringhd) && (head->next->vaddr < addr))
  655. head = head->next;
  656. entry->prev = head;
  657. (entry->next = head->next)->prev = entry;
  658. head->next = entry;
  659. ring->num_entries++;
  660. add_lru(entry);
  661. }
  662. static __inline__ void remove_ring(struct sun4c_mmu_ring *ring,
  663. struct sun4c_mmu_entry *entry)
  664. {
  665. struct sun4c_mmu_entry *next = entry->next;
  666. (next->prev = entry->prev)->next = next;
  667. ring->num_entries--;
  668. }
  669. static void remove_lru(struct sun4c_mmu_entry *entry)
  670. {
  671. struct sun4c_mmu_entry *next = entry->lru_next;
  672. (next->lru_prev = entry->lru_prev)->lru_next = next;
  673. }
  674. static void free_user_entry(int ctx, struct sun4c_mmu_entry *entry)
  675. {
  676. remove_ring(sun4c_context_ring+ctx, entry);
  677. remove_lru(entry);
  678. add_ring(&sun4c_ufree_ring, entry);
  679. }
  680. static void free_kernel_entry(struct sun4c_mmu_entry *entry,
  681. struct sun4c_mmu_ring *ring)
  682. {
  683. remove_ring(ring, entry);
  684. add_ring(&sun4c_kfree_ring, entry);
  685. }
  686. static void __init sun4c_init_fill_kernel_ring(int howmany)
  687. {
  688. int i;
  689. while (howmany) {
  690. for (i = 0; i < invalid_segment; i++)
  691. if (!mmu_entry_pool[i].locked)
  692. break;
  693. mmu_entry_pool[i].locked = 1;
  694. sun4c_init_clean_segmap(i);
  695. add_ring(&sun4c_kfree_ring, &mmu_entry_pool[i]);
  696. howmany--;
  697. }
  698. }
  699. static void __init sun4c_init_fill_user_ring(void)
  700. {
  701. int i;
  702. for (i = 0; i < invalid_segment; i++) {
  703. if (mmu_entry_pool[i].locked)
  704. continue;
  705. sun4c_init_clean_segmap(i);
  706. add_ring(&sun4c_ufree_ring, &mmu_entry_pool[i]);
  707. }
  708. }
  709. static void sun4c_kernel_unmap(struct sun4c_mmu_entry *kentry)
  710. {
  711. int savectx, ctx;
  712. savectx = sun4c_get_context();
  713. for (ctx = 0; ctx < num_contexts; ctx++) {
  714. sun4c_set_context(ctx);
  715. sun4c_put_segmap(kentry->vaddr, invalid_segment);
  716. }
  717. sun4c_set_context(savectx);
  718. }
  719. static void sun4c_kernel_map(struct sun4c_mmu_entry *kentry)
  720. {
  721. int savectx, ctx;
  722. savectx = sun4c_get_context();
  723. for (ctx = 0; ctx < num_contexts; ctx++) {
  724. sun4c_set_context(ctx);
  725. sun4c_put_segmap(kentry->vaddr, kentry->pseg);
  726. }
  727. sun4c_set_context(savectx);
  728. }
  729. #define sun4c_user_unmap(__entry) \
  730. sun4c_put_segmap((__entry)->vaddr, invalid_segment)
  731. static void sun4c_demap_context(struct sun4c_mmu_ring *crp, unsigned char ctx)
  732. {
  733. struct sun4c_mmu_entry *head = &crp->ringhd;
  734. unsigned long flags;
  735. local_irq_save(flags);
  736. if (head->next != head) {
  737. struct sun4c_mmu_entry *entry = head->next;
  738. int savectx = sun4c_get_context();
  739. flush_user_windows();
  740. sun4c_set_context(ctx);
  741. sun4c_flush_context();
  742. do {
  743. struct sun4c_mmu_entry *next = entry->next;
  744. sun4c_user_unmap(entry);
  745. free_user_entry(ctx, entry);
  746. entry = next;
  747. } while (entry != head);
  748. sun4c_set_context(savectx);
  749. }
  750. local_irq_restore(flags);
  751. }
  752. static int sun4c_user_taken_entries; /* This is how much we have. */
  753. static int max_user_taken_entries; /* This limits us and prevents deadlock. */
  754. static struct sun4c_mmu_entry *sun4c_kernel_strategy(void)
  755. {
  756. struct sun4c_mmu_entry *this_entry;
  757. /* If some are free, return first one. */
  758. if (sun4c_kfree_ring.num_entries) {
  759. this_entry = sun4c_kfree_ring.ringhd.next;
  760. return this_entry;
  761. }
  762. /* Else free one up. */
  763. this_entry = sun4c_kernel_ring.ringhd.prev;
  764. sun4c_flush_segment(this_entry->vaddr);
  765. sun4c_kernel_unmap(this_entry);
  766. free_kernel_entry(this_entry, &sun4c_kernel_ring);
  767. this_entry = sun4c_kfree_ring.ringhd.next;
  768. return this_entry;
  769. }
  770. /* Using this method to free up mmu entries eliminates a lot of
  771. * potential races since we have a kernel that incurs tlb
  772. * replacement faults. There may be performance penalties.
  773. *
  774. * NOTE: Must be called with interrupts disabled.
  775. */
  776. static struct sun4c_mmu_entry *sun4c_user_strategy(void)
  777. {
  778. struct sun4c_mmu_entry *entry;
  779. unsigned char ctx;
  780. int savectx;
  781. /* If some are free, return first one. */
  782. if (sun4c_ufree_ring.num_entries) {
  783. entry = sun4c_ufree_ring.ringhd.next;
  784. goto unlink_out;
  785. }
  786. if (sun4c_user_taken_entries) {
  787. entry = sun4c_kernel_strategy();
  788. sun4c_user_taken_entries--;
  789. goto kunlink_out;
  790. }
  791. /* Grab from the beginning of the LRU list. */
  792. entry = sun4c_ulru_ring.ringhd.lru_next;
  793. ctx = entry->ctx;
  794. savectx = sun4c_get_context();
  795. flush_user_windows();
  796. sun4c_set_context(ctx);
  797. sun4c_flush_segment(entry->vaddr);
  798. sun4c_user_unmap(entry);
  799. remove_ring(sun4c_context_ring + ctx, entry);
  800. remove_lru(entry);
  801. sun4c_set_context(savectx);
  802. return entry;
  803. unlink_out:
  804. remove_ring(&sun4c_ufree_ring, entry);
  805. return entry;
  806. kunlink_out:
  807. remove_ring(&sun4c_kfree_ring, entry);
  808. return entry;
  809. }
  810. /* NOTE: Must be called with interrupts disabled. */
  811. void sun4c_grow_kernel_ring(void)
  812. {
  813. struct sun4c_mmu_entry *entry;
  814. /* Prevent deadlock condition. */
  815. if (sun4c_user_taken_entries >= max_user_taken_entries)
  816. return;
  817. if (sun4c_ufree_ring.num_entries) {
  818. entry = sun4c_ufree_ring.ringhd.next;
  819. remove_ring(&sun4c_ufree_ring, entry);
  820. add_ring(&sun4c_kfree_ring, entry);
  821. sun4c_user_taken_entries++;
  822. }
  823. }
  824. /* 2 page buckets for task struct and kernel stack allocation.
  825. *
  826. * TASK_STACK_BEGIN
  827. * bucket[0]
  828. * bucket[1]
  829. * [ ... ]
  830. * bucket[NR_TASK_BUCKETS-1]
  831. * TASK_STACK_BEGIN + (sizeof(struct task_bucket) * NR_TASK_BUCKETS)
  832. *
  833. * Each slot looks like:
  834. *
  835. * page 1 -- task struct + beginning of kernel stack
  836. * page 2 -- rest of kernel stack
  837. */
  838. union task_union *sun4c_bucket[NR_TASK_BUCKETS];
  839. static int sun4c_lowbucket_avail;
  840. #define BUCKET_EMPTY ((union task_union *) 0)
  841. #define BUCKET_SHIFT (PAGE_SHIFT + 1) /* log2(sizeof(struct task_bucket)) */
  842. #define BUCKET_SIZE (1 << BUCKET_SHIFT)
  843. #define BUCKET_NUM(addr) ((((addr) - SUN4C_LOCK_VADDR) >> BUCKET_SHIFT))
  844. #define BUCKET_ADDR(num) (((num) << BUCKET_SHIFT) + SUN4C_LOCK_VADDR)
  845. #define BUCKET_PTE(page) \
  846. ((((page) - PAGE_OFFSET) >> PAGE_SHIFT) | pgprot_val(SUN4C_PAGE_KERNEL))
  847. #define BUCKET_PTE_PAGE(pte) \
  848. (PAGE_OFFSET + (((pte) & SUN4C_PFN_MASK) << PAGE_SHIFT))
  849. static void get_locked_segment(unsigned long addr)
  850. {
  851. struct sun4c_mmu_entry *stolen;
  852. unsigned long flags;
  853. local_irq_save(flags);
  854. addr &= SUN4C_REAL_PGDIR_MASK;
  855. stolen = sun4c_user_strategy();
  856. max_user_taken_entries--;
  857. stolen->vaddr = addr;
  858. flush_user_windows();
  859. sun4c_kernel_map(stolen);
  860. local_irq_restore(flags);
  861. }
  862. static void free_locked_segment(unsigned long addr)
  863. {
  864. struct sun4c_mmu_entry *entry;
  865. unsigned long flags;
  866. unsigned char pseg;
  867. local_irq_save(flags);
  868. addr &= SUN4C_REAL_PGDIR_MASK;
  869. pseg = sun4c_get_segmap(addr);
  870. entry = &mmu_entry_pool[pseg];
  871. flush_user_windows();
  872. sun4c_flush_segment(addr);
  873. sun4c_kernel_unmap(entry);
  874. add_ring(&sun4c_ufree_ring, entry);
  875. max_user_taken_entries++;
  876. local_irq_restore(flags);
  877. }
  878. static inline void garbage_collect(int entry)
  879. {
  880. int start, end;
  881. /* 32 buckets per segment... */
  882. entry &= ~31;
  883. start = entry;
  884. for (end = (start + 32); start < end; start++)
  885. if (sun4c_bucket[start] != BUCKET_EMPTY)
  886. return;
  887. /* Entire segment empty, release it. */
  888. free_locked_segment(BUCKET_ADDR(entry));
  889. }
  890. static struct thread_info *sun4c_alloc_thread_info(void)
  891. {
  892. unsigned long addr, pages;
  893. int entry;
  894. pages = __get_free_pages(GFP_KERNEL, THREAD_INFO_ORDER);
  895. if (!pages)
  896. return NULL;
  897. for (entry = sun4c_lowbucket_avail; entry < NR_TASK_BUCKETS; entry++)
  898. if (sun4c_bucket[entry] == BUCKET_EMPTY)
  899. break;
  900. if (entry == NR_TASK_BUCKETS) {
  901. free_pages(pages, THREAD_INFO_ORDER);
  902. return NULL;
  903. }
  904. if (entry >= sun4c_lowbucket_avail)
  905. sun4c_lowbucket_avail = entry + 1;
  906. addr = BUCKET_ADDR(entry);
  907. sun4c_bucket[entry] = (union task_union *) addr;
  908. if(sun4c_get_segmap(addr) == invalid_segment)
  909. get_locked_segment(addr);
  910. /* We are changing the virtual color of the page(s)
  911. * so we must flush the cache to guarantee consistency.
  912. */
  913. sun4c_flush_page(pages);
  914. #ifndef CONFIG_SUN4
  915. sun4c_flush_page(pages + PAGE_SIZE);
  916. #endif
  917. sun4c_put_pte(addr, BUCKET_PTE(pages));
  918. #ifndef CONFIG_SUN4
  919. sun4c_put_pte(addr + PAGE_SIZE, BUCKET_PTE(pages + PAGE_SIZE));
  920. #endif
  921. #ifdef CONFIG_DEBUG_STACK_USAGE
  922. memset((void *)addr, 0, PAGE_SIZE << THREAD_INFO_ORDER);
  923. #endif /* DEBUG_STACK_USAGE */
  924. return (struct thread_info *) addr;
  925. }
  926. static void sun4c_free_thread_info(struct thread_info *ti)
  927. {
  928. unsigned long tiaddr = (unsigned long) ti;
  929. unsigned long pages = BUCKET_PTE_PAGE(sun4c_get_pte(tiaddr));
  930. int entry = BUCKET_NUM(tiaddr);
  931. /* We are deleting a mapping, so the flush here is mandatory. */
  932. sun4c_flush_page(tiaddr);
  933. #ifndef CONFIG_SUN4
  934. sun4c_flush_page(tiaddr + PAGE_SIZE);
  935. #endif
  936. sun4c_put_pte(tiaddr, 0);
  937. #ifndef CONFIG_SUN4
  938. sun4c_put_pte(tiaddr + PAGE_SIZE, 0);
  939. #endif
  940. sun4c_bucket[entry] = BUCKET_EMPTY;
  941. if (entry < sun4c_lowbucket_avail)
  942. sun4c_lowbucket_avail = entry;
  943. free_pages(pages, THREAD_INFO_ORDER);
  944. garbage_collect(entry);
  945. }
  946. static void __init sun4c_init_buckets(void)
  947. {
  948. int entry;
  949. if (sizeof(union thread_union) != (PAGE_SIZE << THREAD_INFO_ORDER)) {
  950. extern void thread_info_size_is_bolixed_pete(void);
  951. thread_info_size_is_bolixed_pete();
  952. }
  953. for (entry = 0; entry < NR_TASK_BUCKETS; entry++)
  954. sun4c_bucket[entry] = BUCKET_EMPTY;
  955. sun4c_lowbucket_avail = 0;
  956. }
  957. static unsigned long sun4c_iobuffer_start;
  958. static unsigned long sun4c_iobuffer_end;
  959. static unsigned long sun4c_iobuffer_high;
  960. static unsigned long *sun4c_iobuffer_map;
  961. static int iobuffer_map_size;
  962. /*
  963. * Alias our pages so they do not cause a trap.
  964. * Also one page may be aliased into several I/O areas and we may
  965. * finish these I/O separately.
  966. */
  967. static char *sun4c_lockarea(char *vaddr, unsigned long size)
  968. {
  969. unsigned long base, scan;
  970. unsigned long npages;
  971. unsigned long vpage;
  972. unsigned long pte;
  973. unsigned long apage;
  974. unsigned long high;
  975. unsigned long flags;
  976. npages = (((unsigned long)vaddr & ~PAGE_MASK) +
  977. size + (PAGE_SIZE-1)) >> PAGE_SHIFT;
  978. scan = 0;
  979. local_irq_save(flags);
  980. for (;;) {
  981. scan = find_next_zero_bit(sun4c_iobuffer_map,
  982. iobuffer_map_size, scan);
  983. if ((base = scan) + npages > iobuffer_map_size) goto abend;
  984. for (;;) {
  985. if (scan >= base + npages) goto found;
  986. if (test_bit(scan, sun4c_iobuffer_map)) break;
  987. scan++;
  988. }
  989. }
  990. found:
  991. high = ((base + npages) << PAGE_SHIFT) + sun4c_iobuffer_start;
  992. high = SUN4C_REAL_PGDIR_ALIGN(high);
  993. while (high > sun4c_iobuffer_high) {
  994. get_locked_segment(sun4c_iobuffer_high);
  995. sun4c_iobuffer_high += SUN4C_REAL_PGDIR_SIZE;
  996. }
  997. vpage = ((unsigned long) vaddr) & PAGE_MASK;
  998. for (scan = base; scan < base+npages; scan++) {
  999. pte = ((vpage-PAGE_OFFSET) >> PAGE_SHIFT);
  1000. pte |= pgprot_val(SUN4C_PAGE_KERNEL);
  1001. pte |= _SUN4C_PAGE_NOCACHE;
  1002. set_bit(scan, sun4c_iobuffer_map);
  1003. apage = (scan << PAGE_SHIFT) + sun4c_iobuffer_start;
  1004. /* Flush original mapping so we see the right things later. */
  1005. sun4c_flush_page(vpage);
  1006. sun4c_put_pte(apage, pte);
  1007. vpage += PAGE_SIZE;
  1008. }
  1009. local_irq_restore(flags);
  1010. return (char *) ((base << PAGE_SHIFT) + sun4c_iobuffer_start +
  1011. (((unsigned long) vaddr) & ~PAGE_MASK));
  1012. abend:
  1013. local_irq_restore(flags);
  1014. printk("DMA vaddr=0x%p size=%08lx\n", vaddr, size);
  1015. panic("Out of iobuffer table");
  1016. return NULL;
  1017. }
  1018. static void sun4c_unlockarea(char *vaddr, unsigned long size)
  1019. {
  1020. unsigned long vpage, npages;
  1021. unsigned long flags;
  1022. int scan, high;
  1023. vpage = (unsigned long)vaddr & PAGE_MASK;
  1024. npages = (((unsigned long)vaddr & ~PAGE_MASK) +
  1025. size + (PAGE_SIZE-1)) >> PAGE_SHIFT;
  1026. local_irq_save(flags);
  1027. while (npages != 0) {
  1028. --npages;
  1029. /* This mapping is marked non-cachable, no flush necessary. */
  1030. sun4c_put_pte(vpage, 0);
  1031. clear_bit((vpage - sun4c_iobuffer_start) >> PAGE_SHIFT,
  1032. sun4c_iobuffer_map);
  1033. vpage += PAGE_SIZE;
  1034. }
  1035. /* garbage collect */
  1036. scan = (sun4c_iobuffer_high - sun4c_iobuffer_start) >> PAGE_SHIFT;
  1037. while (scan >= 0 && !sun4c_iobuffer_map[scan >> 5])
  1038. scan -= 32;
  1039. scan += 32;
  1040. high = sun4c_iobuffer_start + (scan << PAGE_SHIFT);
  1041. high = SUN4C_REAL_PGDIR_ALIGN(high) + SUN4C_REAL_PGDIR_SIZE;
  1042. while (high < sun4c_iobuffer_high) {
  1043. sun4c_iobuffer_high -= SUN4C_REAL_PGDIR_SIZE;
  1044. free_locked_segment(sun4c_iobuffer_high);
  1045. }
  1046. local_irq_restore(flags);
  1047. }
  1048. /* Note the scsi code at init time passes to here buffers
  1049. * which sit on the kernel stack, those are already locked
  1050. * by implication and fool the page locking code above
  1051. * if passed to by mistake.
  1052. */
  1053. static __u32 sun4c_get_scsi_one(char *bufptr, unsigned long len, struct sbus_bus *sbus)
  1054. {
  1055. unsigned long page;
  1056. page = ((unsigned long)bufptr) & PAGE_MASK;
  1057. if (!virt_addr_valid(page)) {
  1058. sun4c_flush_page(page);
  1059. return (__u32)bufptr; /* already locked */
  1060. }
  1061. return (__u32)sun4c_lockarea(bufptr, len);
  1062. }
  1063. static void sun4c_get_scsi_sgl(struct scatterlist *sg, int sz, struct sbus_bus *sbus)
  1064. {
  1065. while (sz != 0) {
  1066. --sz;
  1067. sg[sz].dvma_address = (__u32)sun4c_lockarea(page_address(sg[sz].page) + sg[sz].offset, sg[sz].length);
  1068. sg[sz].dvma_length = sg[sz].length;
  1069. }
  1070. }
  1071. static void sun4c_release_scsi_one(__u32 bufptr, unsigned long len, struct sbus_bus *sbus)
  1072. {
  1073. if (bufptr < sun4c_iobuffer_start)
  1074. return; /* On kernel stack or similar, see above */
  1075. sun4c_unlockarea((char *)bufptr, len);
  1076. }
  1077. static void sun4c_release_scsi_sgl(struct scatterlist *sg, int sz, struct sbus_bus *sbus)
  1078. {
  1079. while (sz != 0) {
  1080. --sz;
  1081. sun4c_unlockarea((char *)sg[sz].dvma_address, sg[sz].length);
  1082. }
  1083. }
  1084. #define TASK_ENTRY_SIZE BUCKET_SIZE /* see above */
  1085. #define LONG_ALIGN(x) (((x)+(sizeof(long))-1)&~((sizeof(long))-1))
  1086. struct vm_area_struct sun4c_kstack_vma;
  1087. static void __init sun4c_init_lock_areas(void)
  1088. {
  1089. unsigned long sun4c_taskstack_start;
  1090. unsigned long sun4c_taskstack_end;
  1091. int bitmap_size;
  1092. sun4c_init_buckets();
  1093. sun4c_taskstack_start = SUN4C_LOCK_VADDR;
  1094. sun4c_taskstack_end = (sun4c_taskstack_start +
  1095. (TASK_ENTRY_SIZE * NR_TASK_BUCKETS));
  1096. if (sun4c_taskstack_end >= SUN4C_LOCK_END) {
  1097. prom_printf("Too many tasks, decrease NR_TASK_BUCKETS please.\n");
  1098. prom_halt();
  1099. }
  1100. sun4c_iobuffer_start = sun4c_iobuffer_high =
  1101. SUN4C_REAL_PGDIR_ALIGN(sun4c_taskstack_end);
  1102. sun4c_iobuffer_end = SUN4C_LOCK_END;
  1103. bitmap_size = (sun4c_iobuffer_end - sun4c_iobuffer_start) >> PAGE_SHIFT;
  1104. bitmap_size = (bitmap_size + 7) >> 3;
  1105. bitmap_size = LONG_ALIGN(bitmap_size);
  1106. iobuffer_map_size = bitmap_size << 3;
  1107. sun4c_iobuffer_map = __alloc_bootmem(bitmap_size, SMP_CACHE_BYTES, 0UL);
  1108. memset((void *) sun4c_iobuffer_map, 0, bitmap_size);
  1109. sun4c_kstack_vma.vm_mm = &init_mm;
  1110. sun4c_kstack_vma.vm_start = sun4c_taskstack_start;
  1111. sun4c_kstack_vma.vm_end = sun4c_taskstack_end;
  1112. sun4c_kstack_vma.vm_page_prot = PAGE_SHARED;
  1113. sun4c_kstack_vma.vm_flags = VM_READ | VM_WRITE | VM_EXEC;
  1114. insert_vm_struct(&init_mm, &sun4c_kstack_vma);
  1115. }
  1116. /* Cache flushing on the sun4c. */
  1117. static void sun4c_flush_cache_all(void)
  1118. {
  1119. unsigned long begin, end;
  1120. flush_user_windows();
  1121. begin = (KERNBASE + SUN4C_REAL_PGDIR_SIZE);
  1122. end = (begin + SUN4C_VAC_SIZE);
  1123. if (sun4c_vacinfo.linesize == 32) {
  1124. while (begin < end) {
  1125. __asm__ __volatile__(
  1126. "ld [%0 + 0x00], %%g0\n\t"
  1127. "ld [%0 + 0x20], %%g0\n\t"
  1128. "ld [%0 + 0x40], %%g0\n\t"
  1129. "ld [%0 + 0x60], %%g0\n\t"
  1130. "ld [%0 + 0x80], %%g0\n\t"
  1131. "ld [%0 + 0xa0], %%g0\n\t"
  1132. "ld [%0 + 0xc0], %%g0\n\t"
  1133. "ld [%0 + 0xe0], %%g0\n\t"
  1134. "ld [%0 + 0x100], %%g0\n\t"
  1135. "ld [%0 + 0x120], %%g0\n\t"
  1136. "ld [%0 + 0x140], %%g0\n\t"
  1137. "ld [%0 + 0x160], %%g0\n\t"
  1138. "ld [%0 + 0x180], %%g0\n\t"
  1139. "ld [%0 + 0x1a0], %%g0\n\t"
  1140. "ld [%0 + 0x1c0], %%g0\n\t"
  1141. "ld [%0 + 0x1e0], %%g0\n"
  1142. : : "r" (begin));
  1143. begin += 512;
  1144. }
  1145. } else {
  1146. while (begin < end) {
  1147. __asm__ __volatile__(
  1148. "ld [%0 + 0x00], %%g0\n\t"
  1149. "ld [%0 + 0x10], %%g0\n\t"
  1150. "ld [%0 + 0x20], %%g0\n\t"
  1151. "ld [%0 + 0x30], %%g0\n\t"
  1152. "ld [%0 + 0x40], %%g0\n\t"
  1153. "ld [%0 + 0x50], %%g0\n\t"
  1154. "ld [%0 + 0x60], %%g0\n\t"
  1155. "ld [%0 + 0x70], %%g0\n\t"
  1156. "ld [%0 + 0x80], %%g0\n\t"
  1157. "ld [%0 + 0x90], %%g0\n\t"
  1158. "ld [%0 + 0xa0], %%g0\n\t"
  1159. "ld [%0 + 0xb0], %%g0\n\t"
  1160. "ld [%0 + 0xc0], %%g0\n\t"
  1161. "ld [%0 + 0xd0], %%g0\n\t"
  1162. "ld [%0 + 0xe0], %%g0\n\t"
  1163. "ld [%0 + 0xf0], %%g0\n"
  1164. : : "r" (begin));
  1165. begin += 256;
  1166. }
  1167. }
  1168. }
  1169. static void sun4c_flush_cache_mm(struct mm_struct *mm)
  1170. {
  1171. int new_ctx = mm->context;
  1172. if (new_ctx != NO_CONTEXT) {
  1173. flush_user_windows();
  1174. if (sun4c_context_ring[new_ctx].num_entries) {
  1175. struct sun4c_mmu_entry *head = &sun4c_context_ring[new_ctx].ringhd;
  1176. unsigned long flags;
  1177. local_irq_save(flags);
  1178. if (head->next != head) {
  1179. struct sun4c_mmu_entry *entry = head->next;
  1180. int savectx = sun4c_get_context();
  1181. sun4c_set_context(new_ctx);
  1182. sun4c_flush_context();
  1183. do {
  1184. struct sun4c_mmu_entry *next = entry->next;
  1185. sun4c_user_unmap(entry);
  1186. free_user_entry(new_ctx, entry);
  1187. entry = next;
  1188. } while (entry != head);
  1189. sun4c_set_context(savectx);
  1190. }
  1191. local_irq_restore(flags);
  1192. }
  1193. }
  1194. }
  1195. static void sun4c_flush_cache_range(struct vm_area_struct *vma, unsigned long start, unsigned long end)
  1196. {
  1197. struct mm_struct *mm = vma->vm_mm;
  1198. int new_ctx = mm->context;
  1199. if (new_ctx != NO_CONTEXT) {
  1200. struct sun4c_mmu_entry *head = &sun4c_context_ring[new_ctx].ringhd;
  1201. struct sun4c_mmu_entry *entry;
  1202. unsigned long flags;
  1203. flush_user_windows();
  1204. local_irq_save(flags);
  1205. /* All user segmap chains are ordered on entry->vaddr. */
  1206. for (entry = head->next;
  1207. (entry != head) && ((entry->vaddr+SUN4C_REAL_PGDIR_SIZE) < start);
  1208. entry = entry->next)
  1209. ;
  1210. /* Tracing various job mixtures showed that this conditional
  1211. * only passes ~35% of the time for most worse case situations,
  1212. * therefore we avoid all of this gross overhead ~65% of the time.
  1213. */
  1214. if ((entry != head) && (entry->vaddr < end)) {
  1215. int octx = sun4c_get_context();
  1216. sun4c_set_context(new_ctx);
  1217. /* At this point, always, (start >= entry->vaddr) and
  1218. * (entry->vaddr < end), once the latter condition
  1219. * ceases to hold, or we hit the end of the list, we
  1220. * exit the loop. The ordering of all user allocated
  1221. * segmaps makes this all work out so beautifully.
  1222. */
  1223. do {
  1224. struct sun4c_mmu_entry *next = entry->next;
  1225. unsigned long realend;
  1226. /* "realstart" is always >= entry->vaddr */
  1227. realend = entry->vaddr + SUN4C_REAL_PGDIR_SIZE;
  1228. if (end < realend)
  1229. realend = end;
  1230. if ((realend - entry->vaddr) <= (PAGE_SIZE << 3)) {
  1231. unsigned long page = entry->vaddr;
  1232. while (page < realend) {
  1233. sun4c_flush_page(page);
  1234. page += PAGE_SIZE;
  1235. }
  1236. } else {
  1237. sun4c_flush_segment(entry->vaddr);
  1238. sun4c_user_unmap(entry);
  1239. free_user_entry(new_ctx, entry);
  1240. }
  1241. entry = next;
  1242. } while ((entry != head) && (entry->vaddr < end));
  1243. sun4c_set_context(octx);
  1244. }
  1245. local_irq_restore(flags);
  1246. }
  1247. }
  1248. static void sun4c_flush_cache_page(struct vm_area_struct *vma, unsigned long page)
  1249. {
  1250. struct mm_struct *mm = vma->vm_mm;
  1251. int new_ctx = mm->context;
  1252. /* Sun4c has no separate I/D caches so cannot optimize for non
  1253. * text page flushes.
  1254. */
  1255. if (new_ctx != NO_CONTEXT) {
  1256. int octx = sun4c_get_context();
  1257. unsigned long flags;
  1258. flush_user_windows();
  1259. local_irq_save(flags);
  1260. sun4c_set_context(new_ctx);
  1261. sun4c_flush_page(page);
  1262. sun4c_set_context(octx);
  1263. local_irq_restore(flags);
  1264. }
  1265. }
  1266. static void sun4c_flush_page_to_ram(unsigned long page)
  1267. {
  1268. unsigned long flags;
  1269. local_irq_save(flags);
  1270. sun4c_flush_page(page);
  1271. local_irq_restore(flags);
  1272. }
  1273. /* Sun4c cache is unified, both instructions and data live there, so
  1274. * no need to flush the on-stack instructions for new signal handlers.
  1275. */
  1276. static void sun4c_flush_sig_insns(struct mm_struct *mm, unsigned long insn_addr)
  1277. {
  1278. }
  1279. /* TLB flushing on the sun4c. These routines count on the cache
  1280. * flushing code to flush the user register windows so that we need
  1281. * not do so when we get here.
  1282. */
  1283. static void sun4c_flush_tlb_all(void)
  1284. {
  1285. struct sun4c_mmu_entry *this_entry, *next_entry;
  1286. unsigned long flags;
  1287. int savectx, ctx;
  1288. local_irq_save(flags);
  1289. this_entry = sun4c_kernel_ring.ringhd.next;
  1290. savectx = sun4c_get_context();
  1291. flush_user_windows();
  1292. while (sun4c_kernel_ring.num_entries) {
  1293. next_entry = this_entry->next;
  1294. sun4c_flush_segment(this_entry->vaddr);
  1295. for (ctx = 0; ctx < num_contexts; ctx++) {
  1296. sun4c_set_context(ctx);
  1297. sun4c_put_segmap(this_entry->vaddr, invalid_segment);
  1298. }
  1299. free_kernel_entry(this_entry, &sun4c_kernel_ring);
  1300. this_entry = next_entry;
  1301. }
  1302. sun4c_set_context(savectx);
  1303. local_irq_restore(flags);
  1304. }
  1305. static void sun4c_flush_tlb_mm(struct mm_struct *mm)
  1306. {
  1307. int new_ctx = mm->context;
  1308. if (new_ctx != NO_CONTEXT) {
  1309. struct sun4c_mmu_entry *head = &sun4c_context_ring[new_ctx].ringhd;
  1310. unsigned long flags;
  1311. local_irq_save(flags);
  1312. if (head->next != head) {
  1313. struct sun4c_mmu_entry *entry = head->next;
  1314. int savectx = sun4c_get_context();
  1315. sun4c_set_context(new_ctx);
  1316. sun4c_flush_context();
  1317. do {
  1318. struct sun4c_mmu_entry *next = entry->next;
  1319. sun4c_user_unmap(entry);
  1320. free_user_entry(new_ctx, entry);
  1321. entry = next;
  1322. } while (entry != head);
  1323. sun4c_set_context(savectx);
  1324. }
  1325. local_irq_restore(flags);
  1326. }
  1327. }
  1328. static void sun4c_flush_tlb_range(struct vm_area_struct *vma, unsigned long start, unsigned long end)
  1329. {
  1330. struct mm_struct *mm = vma->vm_mm;
  1331. int new_ctx = mm->context;
  1332. if (new_ctx != NO_CONTEXT) {
  1333. struct sun4c_mmu_entry *head = &sun4c_context_ring[new_ctx].ringhd;
  1334. struct sun4c_mmu_entry *entry;
  1335. unsigned long flags;
  1336. local_irq_save(flags);
  1337. /* See commentary in sun4c_flush_cache_range(). */
  1338. for (entry = head->next;
  1339. (entry != head) && ((entry->vaddr+SUN4C_REAL_PGDIR_SIZE) < start);
  1340. entry = entry->next)
  1341. ;
  1342. if ((entry != head) && (entry->vaddr < end)) {
  1343. int octx = sun4c_get_context();
  1344. sun4c_set_context(new_ctx);
  1345. do {
  1346. struct sun4c_mmu_entry *next = entry->next;
  1347. sun4c_flush_segment(entry->vaddr);
  1348. sun4c_user_unmap(entry);
  1349. free_user_entry(new_ctx, entry);
  1350. entry = next;
  1351. } while ((entry != head) && (entry->vaddr < end));
  1352. sun4c_set_context(octx);
  1353. }
  1354. local_irq_restore(flags);
  1355. }
  1356. }
  1357. static void sun4c_flush_tlb_page(struct vm_area_struct *vma, unsigned long page)
  1358. {
  1359. struct mm_struct *mm = vma->vm_mm;
  1360. int new_ctx = mm->context;
  1361. if (new_ctx != NO_CONTEXT) {
  1362. int savectx = sun4c_get_context();
  1363. unsigned long flags;
  1364. local_irq_save(flags);
  1365. sun4c_set_context(new_ctx);
  1366. page &= PAGE_MASK;
  1367. sun4c_flush_page(page);
  1368. sun4c_put_pte(page, 0);
  1369. sun4c_set_context(savectx);
  1370. local_irq_restore(flags);
  1371. }
  1372. }
  1373. static inline void sun4c_mapioaddr(unsigned long physaddr, unsigned long virt_addr)
  1374. {
  1375. unsigned long page_entry, pg_iobits;
  1376. pg_iobits = _SUN4C_PAGE_PRESENT | _SUN4C_READABLE | _SUN4C_WRITEABLE |
  1377. _SUN4C_PAGE_IO | _SUN4C_PAGE_NOCACHE;
  1378. page_entry = ((physaddr >> PAGE_SHIFT) & SUN4C_PFN_MASK);
  1379. page_entry |= ((pg_iobits | _SUN4C_PAGE_PRIV) & ~(_SUN4C_PAGE_PRESENT));
  1380. sun4c_put_pte(virt_addr, page_entry);
  1381. }
  1382. static void sun4c_mapiorange(unsigned int bus, unsigned long xpa,
  1383. unsigned long xva, unsigned int len)
  1384. {
  1385. while (len != 0) {
  1386. len -= PAGE_SIZE;
  1387. sun4c_mapioaddr(xpa, xva);
  1388. xva += PAGE_SIZE;
  1389. xpa += PAGE_SIZE;
  1390. }
  1391. }
  1392. static void sun4c_unmapiorange(unsigned long virt_addr, unsigned int len)
  1393. {
  1394. while (len != 0) {
  1395. len -= PAGE_SIZE;
  1396. sun4c_put_pte(virt_addr, 0);
  1397. virt_addr += PAGE_SIZE;
  1398. }
  1399. }
  1400. static void sun4c_alloc_context(struct mm_struct *old_mm, struct mm_struct *mm)
  1401. {
  1402. struct ctx_list *ctxp;
  1403. ctxp = ctx_free.next;
  1404. if (ctxp != &ctx_free) {
  1405. remove_from_ctx_list(ctxp);
  1406. add_to_used_ctxlist(ctxp);
  1407. mm->context = ctxp->ctx_number;
  1408. ctxp->ctx_mm = mm;
  1409. return;
  1410. }
  1411. ctxp = ctx_used.next;
  1412. if (ctxp->ctx_mm == old_mm)
  1413. ctxp = ctxp->next;
  1414. remove_from_ctx_list(ctxp);
  1415. add_to_used_ctxlist(ctxp);
  1416. ctxp->ctx_mm->context = NO_CONTEXT;
  1417. ctxp->ctx_mm = mm;
  1418. mm->context = ctxp->ctx_number;
  1419. sun4c_demap_context(&sun4c_context_ring[ctxp->ctx_number],
  1420. ctxp->ctx_number);
  1421. }
  1422. /* Switch the current MM context. */
  1423. static void sun4c_switch_mm(struct mm_struct *old_mm, struct mm_struct *mm, struct task_struct *tsk, int cpu)
  1424. {
  1425. struct ctx_list *ctx;
  1426. int dirty = 0;
  1427. if (mm->context == NO_CONTEXT) {
  1428. dirty = 1;
  1429. sun4c_alloc_context(old_mm, mm);
  1430. } else {
  1431. /* Update the LRU ring of contexts. */
  1432. ctx = ctx_list_pool + mm->context;
  1433. remove_from_ctx_list(ctx);
  1434. add_to_used_ctxlist(ctx);
  1435. }
  1436. if (dirty || old_mm != mm)
  1437. sun4c_set_context(mm->context);
  1438. }
  1439. static void sun4c_destroy_context(struct mm_struct *mm)
  1440. {
  1441. struct ctx_list *ctx_old;
  1442. if (mm->context != NO_CONTEXT) {
  1443. sun4c_demap_context(&sun4c_context_ring[mm->context], mm->context);
  1444. ctx_old = ctx_list_pool + mm->context;
  1445. remove_from_ctx_list(ctx_old);
  1446. add_to_free_ctxlist(ctx_old);
  1447. mm->context = NO_CONTEXT;
  1448. }
  1449. }
  1450. static void sun4c_mmu_info(struct seq_file *m)
  1451. {
  1452. int used_user_entries, i;
  1453. used_user_entries = 0;
  1454. for (i = 0; i < num_contexts; i++)
  1455. used_user_entries += sun4c_context_ring[i].num_entries;
  1456. seq_printf(m,
  1457. "vacsize\t\t: %d bytes\n"
  1458. "vachwflush\t: %s\n"
  1459. "vaclinesize\t: %d bytes\n"
  1460. "mmuctxs\t\t: %d\n"
  1461. "mmupsegs\t: %d\n"
  1462. "kernelpsegs\t: %d\n"
  1463. "kfreepsegs\t: %d\n"
  1464. "usedpsegs\t: %d\n"
  1465. "ufreepsegs\t: %d\n"
  1466. "user_taken\t: %d\n"
  1467. "max_taken\t: %d\n",
  1468. sun4c_vacinfo.num_bytes,
  1469. (sun4c_vacinfo.do_hwflushes ? "yes" : "no"),
  1470. sun4c_vacinfo.linesize,
  1471. num_contexts,
  1472. (invalid_segment + 1),
  1473. sun4c_kernel_ring.num_entries,
  1474. sun4c_kfree_ring.num_entries,
  1475. used_user_entries,
  1476. sun4c_ufree_ring.num_entries,
  1477. sun4c_user_taken_entries,
  1478. max_user_taken_entries);
  1479. }
  1480. /* Nothing below here should touch the mmu hardware nor the mmu_entry
  1481. * data structures.
  1482. */
  1483. /* First the functions which the mid-level code uses to directly
  1484. * manipulate the software page tables. Some defines since we are
  1485. * emulating the i386 page directory layout.
  1486. */
  1487. #define PGD_PRESENT 0x001
  1488. #define PGD_RW 0x002
  1489. #define PGD_USER 0x004
  1490. #define PGD_ACCESSED 0x020
  1491. #define PGD_DIRTY 0x040
  1492. #define PGD_TABLE (PGD_PRESENT | PGD_RW | PGD_USER | PGD_ACCESSED | PGD_DIRTY)
  1493. static void sun4c_set_pte(pte_t *ptep, pte_t pte)
  1494. {
  1495. *ptep = pte;
  1496. }
  1497. static void sun4c_pgd_set(pgd_t * pgdp, pmd_t * pmdp)
  1498. {
  1499. }
  1500. static void sun4c_pmd_set(pmd_t * pmdp, pte_t * ptep)
  1501. {
  1502. pmdp->pmdv[0] = PGD_TABLE | (unsigned long) ptep;
  1503. }
  1504. static void sun4c_pmd_populate(pmd_t * pmdp, struct page * ptep)
  1505. {
  1506. if (page_address(ptep) == NULL) BUG(); /* No highmem on sun4c */
  1507. pmdp->pmdv[0] = PGD_TABLE | (unsigned long) page_address(ptep);
  1508. }
  1509. static int sun4c_pte_present(pte_t pte)
  1510. {
  1511. return ((pte_val(pte) & (_SUN4C_PAGE_PRESENT | _SUN4C_PAGE_PRIV)) != 0);
  1512. }
  1513. static void sun4c_pte_clear(pte_t *ptep) { *ptep = __pte(0); }
  1514. static int sun4c_pmd_bad(pmd_t pmd)
  1515. {
  1516. return (((pmd_val(pmd) & ~PAGE_MASK) != PGD_TABLE) ||
  1517. (!virt_addr_valid(pmd_val(pmd))));
  1518. }
  1519. static int sun4c_pmd_present(pmd_t pmd)
  1520. {
  1521. return ((pmd_val(pmd) & PGD_PRESENT) != 0);
  1522. }
  1523. #if 0 /* if PMD takes one word */
  1524. static void sun4c_pmd_clear(pmd_t *pmdp) { *pmdp = __pmd(0); }
  1525. #else /* if pmd_t is a longish aggregate */
  1526. static void sun4c_pmd_clear(pmd_t *pmdp) {
  1527. memset((void *)pmdp, 0, sizeof(pmd_t));
  1528. }
  1529. #endif
  1530. static int sun4c_pgd_none(pgd_t pgd) { return 0; }
  1531. static int sun4c_pgd_bad(pgd_t pgd) { return 0; }
  1532. static int sun4c_pgd_present(pgd_t pgd) { return 1; }
  1533. static void sun4c_pgd_clear(pgd_t * pgdp) { }
  1534. /*
  1535. * The following only work if pte_present() is true.
  1536. * Undefined behaviour if not..
  1537. */
  1538. static pte_t sun4c_pte_mkwrite(pte_t pte)
  1539. {
  1540. pte = __pte(pte_val(pte) | _SUN4C_PAGE_WRITE);
  1541. if (pte_val(pte) & _SUN4C_PAGE_MODIFIED)
  1542. pte = __pte(pte_val(pte) | _SUN4C_PAGE_SILENT_WRITE);
  1543. return pte;
  1544. }
  1545. static pte_t sun4c_pte_mkdirty(pte_t pte)
  1546. {
  1547. pte = __pte(pte_val(pte) | _SUN4C_PAGE_MODIFIED);
  1548. if (pte_val(pte) & _SUN4C_PAGE_WRITE)
  1549. pte = __pte(pte_val(pte) | _SUN4C_PAGE_SILENT_WRITE);
  1550. return pte;
  1551. }
  1552. static pte_t sun4c_pte_mkyoung(pte_t pte)
  1553. {
  1554. pte = __pte(pte_val(pte) | _SUN4C_PAGE_ACCESSED);
  1555. if (pte_val(pte) & _SUN4C_PAGE_READ)
  1556. pte = __pte(pte_val(pte) | _SUN4C_PAGE_SILENT_READ);
  1557. return pte;
  1558. }
  1559. /*
  1560. * Conversion functions: convert a page and protection to a page entry,
  1561. * and a page entry and page directory to the page they refer to.
  1562. */
  1563. static pte_t sun4c_mk_pte(struct page *page, pgprot_t pgprot)
  1564. {
  1565. return __pte(page_to_pfn(page) | pgprot_val(pgprot));
  1566. }
  1567. static pte_t sun4c_mk_pte_phys(unsigned long phys_page, pgprot_t pgprot)
  1568. {
  1569. return __pte((phys_page >> PAGE_SHIFT) | pgprot_val(pgprot));
  1570. }
  1571. static pte_t sun4c_mk_pte_io(unsigned long page, pgprot_t pgprot, int space)
  1572. {
  1573. return __pte(((page - PAGE_OFFSET) >> PAGE_SHIFT) | pgprot_val(pgprot));
  1574. }
  1575. static unsigned long sun4c_pte_pfn(pte_t pte)
  1576. {
  1577. return pte_val(pte) & SUN4C_PFN_MASK;
  1578. }
  1579. static pte_t sun4c_pgoff_to_pte(unsigned long pgoff)
  1580. {
  1581. return __pte(pgoff | _SUN4C_PAGE_FILE);
  1582. }
  1583. static unsigned long sun4c_pte_to_pgoff(pte_t pte)
  1584. {
  1585. return pte_val(pte) & ((1UL << PTE_FILE_MAX_BITS) - 1);
  1586. }
  1587. static __inline__ unsigned long sun4c_pmd_page_v(pmd_t pmd)
  1588. {
  1589. return (pmd_val(pmd) & PAGE_MASK);
  1590. }
  1591. static struct page *sun4c_pmd_page(pmd_t pmd)
  1592. {
  1593. return virt_to_page(sun4c_pmd_page_v(pmd));
  1594. }
  1595. static unsigned long sun4c_pgd_page(pgd_t pgd) { return 0; }
  1596. /* to find an entry in a page-table-directory */
  1597. static inline pgd_t *sun4c_pgd_offset(struct mm_struct * mm, unsigned long address)
  1598. {
  1599. return mm->pgd + (address >> SUN4C_PGDIR_SHIFT);
  1600. }
  1601. /* Find an entry in the second-level page table.. */
  1602. static pmd_t *sun4c_pmd_offset(pgd_t * dir, unsigned long address)
  1603. {
  1604. return (pmd_t *) dir;
  1605. }
  1606. /* Find an entry in the third-level page table.. */
  1607. pte_t *sun4c_pte_offset_kernel(pmd_t * dir, unsigned long address)
  1608. {
  1609. return (pte_t *) sun4c_pmd_page_v(*dir) +
  1610. ((address >> PAGE_SHIFT) & (SUN4C_PTRS_PER_PTE - 1));
  1611. }
  1612. static unsigned long sun4c_swp_type(swp_entry_t entry)
  1613. {
  1614. return (entry.val & SUN4C_SWP_TYPE_MASK);
  1615. }
  1616. static unsigned long sun4c_swp_offset(swp_entry_t entry)
  1617. {
  1618. return (entry.val >> SUN4C_SWP_OFF_SHIFT) & SUN4C_SWP_OFF_MASK;
  1619. }
  1620. static swp_entry_t sun4c_swp_entry(unsigned long type, unsigned long offset)
  1621. {
  1622. return (swp_entry_t) {
  1623. (offset & SUN4C_SWP_OFF_MASK) << SUN4C_SWP_OFF_SHIFT
  1624. | (type & SUN4C_SWP_TYPE_MASK) };
  1625. }
  1626. static void sun4c_free_pte_slow(pte_t *pte)
  1627. {
  1628. free_page((unsigned long)pte);
  1629. }
  1630. static void sun4c_free_pgd_slow(pgd_t *pgd)
  1631. {
  1632. free_page((unsigned long)pgd);
  1633. }
  1634. static pgd_t *sun4c_get_pgd_fast(void)
  1635. {
  1636. unsigned long *ret;
  1637. if ((ret = pgd_quicklist) != NULL) {
  1638. pgd_quicklist = (unsigned long *)(*ret);
  1639. ret[0] = ret[1];
  1640. pgtable_cache_size--;
  1641. } else {
  1642. pgd_t *init;
  1643. ret = (unsigned long *)__get_free_page(GFP_KERNEL);
  1644. memset (ret, 0, (KERNBASE / SUN4C_PGDIR_SIZE) * sizeof(pgd_t));
  1645. init = sun4c_pgd_offset(&init_mm, 0);
  1646. memcpy (((pgd_t *)ret) + USER_PTRS_PER_PGD, init + USER_PTRS_PER_PGD,
  1647. (PTRS_PER_PGD - USER_PTRS_PER_PGD) * sizeof(pgd_t));
  1648. }
  1649. return (pgd_t *)ret;
  1650. }
  1651. static void sun4c_free_pgd_fast(pgd_t *pgd)
  1652. {
  1653. *(unsigned long *)pgd = (unsigned long) pgd_quicklist;
  1654. pgd_quicklist = (unsigned long *) pgd;
  1655. pgtable_cache_size++;
  1656. }
  1657. static __inline__ pte_t *
  1658. sun4c_pte_alloc_one_fast(struct mm_struct *mm, unsigned long address)
  1659. {
  1660. unsigned long *ret;
  1661. if ((ret = (unsigned long *)pte_quicklist) != NULL) {
  1662. pte_quicklist = (unsigned long *)(*ret);
  1663. ret[0] = ret[1];
  1664. pgtable_cache_size--;
  1665. }
  1666. return (pte_t *)ret;
  1667. }
  1668. static pte_t *sun4c_pte_alloc_one_kernel(struct mm_struct *mm, unsigned long address)
  1669. {
  1670. pte_t *pte;
  1671. if ((pte = sun4c_pte_alloc_one_fast(mm, address)) != NULL)
  1672. return pte;
  1673. pte = (pte_t *)__get_free_page(GFP_KERNEL|__GFP_REPEAT);
  1674. if (pte)
  1675. memset(pte, 0, PAGE_SIZE);
  1676. return pte;
  1677. }
  1678. static struct page *sun4c_pte_alloc_one(struct mm_struct *mm, unsigned long address)
  1679. {
  1680. pte_t *pte = sun4c_pte_alloc_one_kernel(mm, address);
  1681. if (pte == NULL)
  1682. return NULL;
  1683. return virt_to_page(pte);
  1684. }
  1685. static __inline__ void sun4c_free_pte_fast(pte_t *pte)
  1686. {
  1687. *(unsigned long *)pte = (unsigned long) pte_quicklist;
  1688. pte_quicklist = (unsigned long *) pte;
  1689. pgtable_cache_size++;
  1690. }
  1691. static void sun4c_pte_free(struct page *pte)
  1692. {
  1693. sun4c_free_pte_fast(page_address(pte));
  1694. }
  1695. /*
  1696. * allocating and freeing a pmd is trivial: the 1-entry pmd is
  1697. * inside the pgd, so has no extra memory associated with it.
  1698. */
  1699. static pmd_t *sun4c_pmd_alloc_one(struct mm_struct *mm, unsigned long address)
  1700. {
  1701. BUG();
  1702. return NULL;
  1703. }
  1704. static void sun4c_free_pmd_fast(pmd_t * pmd) { }
  1705. static void sun4c_check_pgt_cache(int low, int high)
  1706. {
  1707. if (pgtable_cache_size > high) {
  1708. do {
  1709. if (pgd_quicklist)
  1710. sun4c_free_pgd_slow(sun4c_get_pgd_fast());
  1711. if (pte_quicklist)
  1712. sun4c_free_pte_slow(sun4c_pte_alloc_one_fast(NULL, 0));
  1713. } while (pgtable_cache_size > low);
  1714. }
  1715. }
  1716. /* An experiment, turn off by default for now... -DaveM */
  1717. #define SUN4C_PRELOAD_PSEG
  1718. void sun4c_update_mmu_cache(struct vm_area_struct *vma, unsigned long address, pte_t pte)
  1719. {
  1720. unsigned long flags;
  1721. int pseg;
  1722. if (vma->vm_mm->context == NO_CONTEXT)
  1723. return;
  1724. local_irq_save(flags);
  1725. address &= PAGE_MASK;
  1726. if ((pseg = sun4c_get_segmap(address)) == invalid_segment) {
  1727. struct sun4c_mmu_entry *entry = sun4c_user_strategy();
  1728. struct mm_struct *mm = vma->vm_mm;
  1729. unsigned long start, end;
  1730. entry->vaddr = start = (address & SUN4C_REAL_PGDIR_MASK);
  1731. entry->ctx = mm->context;
  1732. add_ring_ordered(sun4c_context_ring + mm->context, entry);
  1733. sun4c_put_segmap(entry->vaddr, entry->pseg);
  1734. end = start + SUN4C_REAL_PGDIR_SIZE;
  1735. while (start < end) {
  1736. #ifdef SUN4C_PRELOAD_PSEG
  1737. pgd_t *pgdp = sun4c_pgd_offset(mm, start);
  1738. pte_t *ptep;
  1739. if (!pgdp)
  1740. goto no_mapping;
  1741. ptep = sun4c_pte_offset_kernel((pmd_t *) pgdp, start);
  1742. if (!ptep || !(pte_val(*ptep) & _SUN4C_PAGE_PRESENT))
  1743. goto no_mapping;
  1744. sun4c_put_pte(start, pte_val(*ptep));
  1745. goto next;
  1746. no_mapping:
  1747. #endif
  1748. sun4c_put_pte(start, 0);
  1749. #ifdef SUN4C_PRELOAD_PSEG
  1750. next:
  1751. #endif
  1752. start += PAGE_SIZE;
  1753. }
  1754. #ifndef SUN4C_PRELOAD_PSEG
  1755. sun4c_put_pte(address, pte_val(pte));
  1756. #endif
  1757. local_irq_restore(flags);
  1758. return;
  1759. } else {
  1760. struct sun4c_mmu_entry *entry = &mmu_entry_pool[pseg];
  1761. remove_lru(entry);
  1762. add_lru(entry);
  1763. }
  1764. sun4c_put_pte(address, pte_val(pte));
  1765. local_irq_restore(flags);
  1766. }
  1767. extern void sparc_context_init(int);
  1768. extern unsigned long end;
  1769. extern unsigned long bootmem_init(unsigned long *pages_avail);
  1770. extern unsigned long last_valid_pfn;
  1771. void __init sun4c_paging_init(void)
  1772. {
  1773. int i, cnt;
  1774. unsigned long kernel_end, vaddr;
  1775. extern struct resource sparc_iomap;
  1776. unsigned long end_pfn, pages_avail;
  1777. kernel_end = (unsigned long) &end;
  1778. kernel_end = SUN4C_REAL_PGDIR_ALIGN(kernel_end);
  1779. pages_avail = 0;
  1780. last_valid_pfn = bootmem_init(&pages_avail);
  1781. end_pfn = last_valid_pfn;
  1782. sun4c_probe_mmu();
  1783. invalid_segment = (num_segmaps - 1);
  1784. sun4c_init_mmu_entry_pool();
  1785. sun4c_init_rings();
  1786. sun4c_init_map_kernelprom(kernel_end);
  1787. sun4c_init_clean_mmu(kernel_end);
  1788. sun4c_init_fill_kernel_ring(SUN4C_KERNEL_BUCKETS);
  1789. sun4c_init_lock_area(sparc_iomap.start, IOBASE_END);
  1790. sun4c_init_lock_area(DVMA_VADDR, DVMA_END);
  1791. sun4c_init_lock_areas();
  1792. sun4c_init_fill_user_ring();
  1793. sun4c_set_context(0);
  1794. memset(swapper_pg_dir, 0, PAGE_SIZE);
  1795. memset(pg0, 0, PAGE_SIZE);
  1796. memset(pg1, 0, PAGE_SIZE);
  1797. memset(pg2, 0, PAGE_SIZE);
  1798. memset(pg3, 0, PAGE_SIZE);
  1799. /* Save work later. */
  1800. vaddr = VMALLOC_START;
  1801. swapper_pg_dir[vaddr>>SUN4C_PGDIR_SHIFT] = __pgd(PGD_TABLE | (unsigned long) pg0);
  1802. vaddr += SUN4C_PGDIR_SIZE;
  1803. swapper_pg_dir[vaddr>>SUN4C_PGDIR_SHIFT] = __pgd(PGD_TABLE | (unsigned long) pg1);
  1804. vaddr += SUN4C_PGDIR_SIZE;
  1805. swapper_pg_dir[vaddr>>SUN4C_PGDIR_SHIFT] = __pgd(PGD_TABLE | (unsigned long) pg2);
  1806. vaddr += SUN4C_PGDIR_SIZE;
  1807. swapper_pg_dir[vaddr>>SUN4C_PGDIR_SHIFT] = __pgd(PGD_TABLE | (unsigned long) pg3);
  1808. sun4c_init_ss2_cache_bug();
  1809. sparc_context_init(num_contexts);
  1810. {
  1811. unsigned long zones_size[MAX_NR_ZONES];
  1812. unsigned long zholes_size[MAX_NR_ZONES];
  1813. unsigned long npages;
  1814. int znum;
  1815. for (znum = 0; znum < MAX_NR_ZONES; znum++)
  1816. zones_size[znum] = zholes_size[znum] = 0;
  1817. npages = max_low_pfn - pfn_base;
  1818. zones_size[ZONE_DMA] = npages;
  1819. zholes_size[ZONE_DMA] = npages - pages_avail;
  1820. npages = highend_pfn - max_low_pfn;
  1821. zones_size[ZONE_HIGHMEM] = npages;
  1822. zholes_size[ZONE_HIGHMEM] = npages - calc_highpages();
  1823. free_area_init_node(0, &contig_page_data, zones_size,
  1824. pfn_base, zholes_size);
  1825. }
  1826. cnt = 0;
  1827. for (i = 0; i < num_segmaps; i++)
  1828. if (mmu_entry_pool[i].locked)
  1829. cnt++;
  1830. max_user_taken_entries = num_segmaps - cnt - 40 - 1;
  1831. printk("SUN4C: %d mmu entries for the kernel\n", cnt);
  1832. }
  1833. static pgprot_t sun4c_pgprot_noncached(pgprot_t prot)
  1834. {
  1835. prot |= __pgprot(_SUN4C_PAGE_IO | _SUN4C_PAGE_NOCACHE);
  1836. return prot;
  1837. }
  1838. /* Load up routines and constants for sun4c mmu */
  1839. void __init ld_mmu_sun4c(void)
  1840. {
  1841. extern void ___xchg32_sun4c(void);
  1842. printk("Loading sun4c MMU routines\n");
  1843. /* First the constants */
  1844. BTFIXUPSET_SIMM13(pgdir_shift, SUN4C_PGDIR_SHIFT);
  1845. BTFIXUPSET_SETHI(pgdir_size, SUN4C_PGDIR_SIZE);
  1846. BTFIXUPSET_SETHI(pgdir_mask, SUN4C_PGDIR_MASK);
  1847. BTFIXUPSET_SIMM13(ptrs_per_pmd, SUN4C_PTRS_PER_PMD);
  1848. BTFIXUPSET_SIMM13(ptrs_per_pgd, SUN4C_PTRS_PER_PGD);
  1849. BTFIXUPSET_SIMM13(user_ptrs_per_pgd, KERNBASE / SUN4C_PGDIR_SIZE);
  1850. BTFIXUPSET_INT(page_none, pgprot_val(SUN4C_PAGE_NONE));
  1851. PAGE_SHARED = pgprot_val(SUN4C_PAGE_SHARED);
  1852. BTFIXUPSET_INT(page_copy, pgprot_val(SUN4C_PAGE_COPY));
  1853. BTFIXUPSET_INT(page_readonly, pgprot_val(SUN4C_PAGE_READONLY));
  1854. BTFIXUPSET_INT(page_kernel, pgprot_val(SUN4C_PAGE_KERNEL));
  1855. page_kernel = pgprot_val(SUN4C_PAGE_KERNEL);
  1856. /* Functions */
  1857. BTFIXUPSET_CALL(pgprot_noncached, sun4c_pgprot_noncached, BTFIXUPCALL_NORM);
  1858. BTFIXUPSET_CALL(___xchg32, ___xchg32_sun4c, BTFIXUPCALL_NORM);
  1859. BTFIXUPSET_CALL(do_check_pgt_cache, sun4c_check_pgt_cache, BTFIXUPCALL_NORM);
  1860. BTFIXUPSET_CALL(flush_cache_all, sun4c_flush_cache_all, BTFIXUPCALL_NORM);
  1861. if (sun4c_vacinfo.do_hwflushes) {
  1862. BTFIXUPSET_CALL(sun4c_flush_page, sun4c_flush_page_hw, BTFIXUPCALL_NORM);
  1863. BTFIXUPSET_CALL(sun4c_flush_segment, sun4c_flush_segment_hw, BTFIXUPCALL_NORM);
  1864. BTFIXUPSET_CALL(sun4c_flush_context, sun4c_flush_context_hw, BTFIXUPCALL_NORM);
  1865. } else {
  1866. BTFIXUPSET_CALL(sun4c_flush_page, sun4c_flush_page_sw, BTFIXUPCALL_NORM);
  1867. BTFIXUPSET_CALL(sun4c_flush_segment, sun4c_flush_segment_sw, BTFIXUPCALL_NORM);
  1868. BTFIXUPSET_CALL(sun4c_flush_context, sun4c_flush_context_sw, BTFIXUPCALL_NORM);
  1869. }
  1870. BTFIXUPSET_CALL(flush_tlb_mm, sun4c_flush_tlb_mm, BTFIXUPCALL_NORM);
  1871. BTFIXUPSET_CALL(flush_cache_mm, sun4c_flush_cache_mm, BTFIXUPCALL_NORM);
  1872. BTFIXUPSET_CALL(destroy_context, sun4c_destroy_context, BTFIXUPCALL_NORM);
  1873. BTFIXUPSET_CALL(switch_mm, sun4c_switch_mm, BTFIXUPCALL_NORM);
  1874. BTFIXUPSET_CALL(flush_cache_page, sun4c_flush_cache_page, BTFIXUPCALL_NORM);
  1875. BTFIXUPSET_CALL(flush_tlb_page, sun4c_flush_tlb_page, BTFIXUPCALL_NORM);
  1876. BTFIXUPSET_CALL(flush_tlb_range, sun4c_flush_tlb_range, BTFIXUPCALL_NORM);
  1877. BTFIXUPSET_CALL(flush_cache_range, sun4c_flush_cache_range, BTFIXUPCALL_NORM);
  1878. BTFIXUPSET_CALL(__flush_page_to_ram, sun4c_flush_page_to_ram, BTFIXUPCALL_NORM);
  1879. BTFIXUPSET_CALL(flush_tlb_all, sun4c_flush_tlb_all, BTFIXUPCALL_NORM);
  1880. BTFIXUPSET_CALL(flush_sig_insns, sun4c_flush_sig_insns, BTFIXUPCALL_NOP);
  1881. BTFIXUPSET_CALL(set_pte, sun4c_set_pte, BTFIXUPCALL_STO1O0);
  1882. /* The 2.4.18 code does not set this on sun4c, how does it work? XXX */
  1883. /* BTFIXUPSET_SETHI(none_mask, 0x00000000); */ /* Defaults to zero? */
  1884. BTFIXUPSET_CALL(pte_pfn, sun4c_pte_pfn, BTFIXUPCALL_NORM);
  1885. #if 0 /* PAGE_SHIFT <= 12 */ /* Eek. Investigate. XXX */
  1886. BTFIXUPSET_CALL(pmd_page, sun4c_pmd_page, BTFIXUPCALL_ANDNINT(PAGE_SIZE - 1));
  1887. #else
  1888. BTFIXUPSET_CALL(pmd_page, sun4c_pmd_page, BTFIXUPCALL_NORM);
  1889. #endif
  1890. BTFIXUPSET_CALL(pmd_set, sun4c_pmd_set, BTFIXUPCALL_NORM);
  1891. BTFIXUPSET_CALL(pmd_populate, sun4c_pmd_populate, BTFIXUPCALL_NORM);
  1892. BTFIXUPSET_CALL(pte_present, sun4c_pte_present, BTFIXUPCALL_NORM);
  1893. BTFIXUPSET_CALL(pte_clear, sun4c_pte_clear, BTFIXUPCALL_STG0O0);
  1894. BTFIXUPSET_CALL(pmd_bad, sun4c_pmd_bad, BTFIXUPCALL_NORM);
  1895. BTFIXUPSET_CALL(pmd_present, sun4c_pmd_present, BTFIXUPCALL_NORM);
  1896. BTFIXUPSET_CALL(pmd_clear, sun4c_pmd_clear, BTFIXUPCALL_STG0O0);
  1897. BTFIXUPSET_CALL(pgd_none, sun4c_pgd_none, BTFIXUPCALL_RETINT(0));
  1898. BTFIXUPSET_CALL(pgd_bad, sun4c_pgd_bad, BTFIXUPCALL_RETINT(0));
  1899. BTFIXUPSET_CALL(pgd_present, sun4c_pgd_present, BTFIXUPCALL_RETINT(1));
  1900. BTFIXUPSET_CALL(pgd_clear, sun4c_pgd_clear, BTFIXUPCALL_NOP);
  1901. BTFIXUPSET_CALL(mk_pte, sun4c_mk_pte, BTFIXUPCALL_NORM);
  1902. BTFIXUPSET_CALL(mk_pte_phys, sun4c_mk_pte_phys, BTFIXUPCALL_NORM);
  1903. BTFIXUPSET_CALL(mk_pte_io, sun4c_mk_pte_io, BTFIXUPCALL_NORM);
  1904. BTFIXUPSET_INT(pte_modify_mask, _SUN4C_PAGE_CHG_MASK);
  1905. BTFIXUPSET_CALL(pmd_offset, sun4c_pmd_offset, BTFIXUPCALL_NORM);
  1906. BTFIXUPSET_CALL(pte_offset_kernel, sun4c_pte_offset_kernel, BTFIXUPCALL_NORM);
  1907. BTFIXUPSET_CALL(free_pte_fast, sun4c_free_pte_fast, BTFIXUPCALL_NORM);
  1908. BTFIXUPSET_CALL(pte_free, sun4c_pte_free, BTFIXUPCALL_NORM);
  1909. BTFIXUPSET_CALL(pte_alloc_one_kernel, sun4c_pte_alloc_one_kernel, BTFIXUPCALL_NORM);
  1910. BTFIXUPSET_CALL(pte_alloc_one, sun4c_pte_alloc_one, BTFIXUPCALL_NORM);
  1911. BTFIXUPSET_CALL(free_pmd_fast, sun4c_free_pmd_fast, BTFIXUPCALL_NOP);
  1912. BTFIXUPSET_CALL(pmd_alloc_one, sun4c_pmd_alloc_one, BTFIXUPCALL_RETO0);
  1913. BTFIXUPSET_CALL(free_pgd_fast, sun4c_free_pgd_fast, BTFIXUPCALL_NORM);
  1914. BTFIXUPSET_CALL(get_pgd_fast, sun4c_get_pgd_fast, BTFIXUPCALL_NORM);
  1915. BTFIXUPSET_HALF(pte_writei, _SUN4C_PAGE_WRITE);
  1916. BTFIXUPSET_HALF(pte_dirtyi, _SUN4C_PAGE_MODIFIED);
  1917. BTFIXUPSET_HALF(pte_youngi, _SUN4C_PAGE_ACCESSED);
  1918. BTFIXUPSET_HALF(pte_filei, _SUN4C_PAGE_FILE);
  1919. BTFIXUPSET_HALF(pte_wrprotecti, _SUN4C_PAGE_WRITE|_SUN4C_PAGE_SILENT_WRITE);
  1920. BTFIXUPSET_HALF(pte_mkcleani, _SUN4C_PAGE_MODIFIED|_SUN4C_PAGE_SILENT_WRITE);
  1921. BTFIXUPSET_HALF(pte_mkoldi, _SUN4C_PAGE_ACCESSED|_SUN4C_PAGE_SILENT_READ);
  1922. BTFIXUPSET_CALL(pte_mkwrite, sun4c_pte_mkwrite, BTFIXUPCALL_NORM);
  1923. BTFIXUPSET_CALL(pte_mkdirty, sun4c_pte_mkdirty, BTFIXUPCALL_NORM);
  1924. BTFIXUPSET_CALL(pte_mkyoung, sun4c_pte_mkyoung, BTFIXUPCALL_NORM);
  1925. BTFIXUPSET_CALL(update_mmu_cache, sun4c_update_mmu_cache, BTFIXUPCALL_NORM);
  1926. BTFIXUPSET_CALL(pte_to_pgoff, sun4c_pte_to_pgoff, BTFIXUPCALL_NORM);
  1927. BTFIXUPSET_CALL(pgoff_to_pte, sun4c_pgoff_to_pte, BTFIXUPCALL_NORM);
  1928. BTFIXUPSET_CALL(mmu_lockarea, sun4c_lockarea, BTFIXUPCALL_NORM);
  1929. BTFIXUPSET_CALL(mmu_unlockarea, sun4c_unlockarea, BTFIXUPCALL_NORM);
  1930. BTFIXUPSET_CALL(mmu_get_scsi_one, sun4c_get_scsi_one, BTFIXUPCALL_NORM);
  1931. BTFIXUPSET_CALL(mmu_get_scsi_sgl, sun4c_get_scsi_sgl, BTFIXUPCALL_NORM);
  1932. BTFIXUPSET_CALL(mmu_release_scsi_one, sun4c_release_scsi_one, BTFIXUPCALL_NORM);
  1933. BTFIXUPSET_CALL(mmu_release_scsi_sgl, sun4c_release_scsi_sgl, BTFIXUPCALL_NORM);
  1934. BTFIXUPSET_CALL(mmu_map_dma_area, sun4c_map_dma_area, BTFIXUPCALL_NORM);
  1935. BTFIXUPSET_CALL(mmu_unmap_dma_area, sun4c_unmap_dma_area, BTFIXUPCALL_NORM);
  1936. BTFIXUPSET_CALL(mmu_translate_dvma, sun4c_translate_dvma, BTFIXUPCALL_NORM);
  1937. BTFIXUPSET_CALL(sparc_mapiorange, sun4c_mapiorange, BTFIXUPCALL_NORM);
  1938. BTFIXUPSET_CALL(sparc_unmapiorange, sun4c_unmapiorange, BTFIXUPCALL_NORM);
  1939. BTFIXUPSET_CALL(__swp_type, sun4c_swp_type, BTFIXUPCALL_NORM);
  1940. BTFIXUPSET_CALL(__swp_offset, sun4c_swp_offset, BTFIXUPCALL_NORM);
  1941. BTFIXUPSET_CALL(__swp_entry, sun4c_swp_entry, BTFIXUPCALL_NORM);
  1942. BTFIXUPSET_CALL(alloc_thread_info, sun4c_alloc_thread_info, BTFIXUPCALL_NORM);
  1943. BTFIXUPSET_CALL(free_thread_info, sun4c_free_thread_info, BTFIXUPCALL_NORM);
  1944. BTFIXUPSET_CALL(mmu_info, sun4c_mmu_info, BTFIXUPCALL_NORM);
  1945. /* These should _never_ get called with two level tables. */
  1946. BTFIXUPSET_CALL(pgd_set, sun4c_pgd_set, BTFIXUPCALL_NOP);
  1947. BTFIXUPSET_CALL(pgd_page_vaddr, sun4c_pgd_page, BTFIXUPCALL_RETO0);
  1948. }