sun4c.c 60 KB

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