sun4c.c 63 KB

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