sun4c.c 63 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284
  1. /* $Id: sun4c.c,v 1.212 2001/12/21 04:56:15 davem Exp $
  2. * sun4c.c: Doing in software what should be done in hardware.
  3. *
  4. * Copyright (C) 1996 David S. Miller (davem@caip.rutgers.edu)
  5. * Copyright (C) 1996 Eddie C. Dost (ecd@skynet.be)
  6. * Copyright (C) 1996 Andrew Tridgell (Andrew.Tridgell@anu.edu.au)
  7. * Copyright (C) 1997-2000 Anton Blanchard (anton@samba.org)
  8. * Copyright (C) 1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
  9. */
  10. #define NR_TASK_BUCKETS 512
  11. #include <linux/kernel.h>
  12. #include <linux/mm.h>
  13. #include <linux/init.h>
  14. #include <linux/bootmem.h>
  15. #include <linux/highmem.h>
  16. #include <linux/fs.h>
  17. #include <linux/seq_file.h>
  18. #include <asm/scatterlist.h>
  19. #include <asm/page.h>
  20. #include <asm/pgalloc.h>
  21. #include <asm/pgtable.h>
  22. #include <asm/vaddrs.h>
  23. #include <asm/idprom.h>
  24. #include <asm/machines.h>
  25. #include <asm/memreg.h>
  26. #include <asm/processor.h>
  27. #include <asm/auxio.h>
  28. #include <asm/io.h>
  29. #include <asm/oplib.h>
  30. #include <asm/openprom.h>
  31. #include <asm/mmu_context.h>
  32. #include <asm/sun4paddr.h>
  33. #include <asm/highmem.h>
  34. #include <asm/btfixup.h>
  35. #include <asm/cacheflush.h>
  36. #include <asm/tlbflush.h>
  37. /* Because of our dynamic kernel TLB miss strategy, and how
  38. * our DVMA mapping allocation works, you _MUST_:
  39. *
  40. * 1) Disable interrupts _and_ not touch any dynamic kernel
  41. * memory while messing with kernel MMU state. By
  42. * dynamic memory I mean any object which is not in
  43. * the kernel image itself or a thread_union (both of
  44. * which are locked into the MMU).
  45. * 2) Disable interrupts while messing with user MMU state.
  46. */
  47. extern int num_segmaps, num_contexts;
  48. extern unsigned long page_kernel;
  49. #ifdef CONFIG_SUN4
  50. #define SUN4C_VAC_SIZE sun4c_vacinfo.num_bytes
  51. #else
  52. /* That's it, we prom_halt() on sun4c if the cache size is something other than 65536.
  53. * So let's save some cycles and just use that everywhere except for that bootup
  54. * sanity check.
  55. */
  56. #define SUN4C_VAC_SIZE 65536
  57. #endif
  58. #define SUN4C_KERNEL_BUCKETS 32
  59. /* Flushing the cache. */
  60. struct sun4c_vac_props sun4c_vacinfo;
  61. unsigned long sun4c_kernel_faults;
  62. /* Invalidate every sun4c cache line tag. */
  63. static void __init sun4c_flush_all(void)
  64. {
  65. unsigned long begin, end;
  66. if (sun4c_vacinfo.on)
  67. panic("SUN4C: AIEEE, trying to invalidate vac while it is on.");
  68. /* Clear 'valid' bit in all cache line tags */
  69. begin = AC_CACHETAGS;
  70. end = (AC_CACHETAGS + SUN4C_VAC_SIZE);
  71. while (begin < end) {
  72. __asm__ __volatile__("sta %%g0, [%0] %1\n\t" : :
  73. "r" (begin), "i" (ASI_CONTROL));
  74. begin += sun4c_vacinfo.linesize;
  75. }
  76. }
  77. static void sun4c_flush_context_hw(void)
  78. {
  79. unsigned long end = SUN4C_VAC_SIZE;
  80. __asm__ __volatile__(
  81. "1: addcc %0, -4096, %0\n\t"
  82. " bne 1b\n\t"
  83. " sta %%g0, [%0] %2"
  84. : "=&r" (end)
  85. : "0" (end), "i" (ASI_HWFLUSHCONTEXT)
  86. : "cc");
  87. }
  88. /* Must be called minimally with IRQs disabled. */
  89. static void sun4c_flush_segment_hw(unsigned long addr)
  90. {
  91. if (sun4c_get_segmap(addr) != invalid_segment) {
  92. unsigned long vac_size = SUN4C_VAC_SIZE;
  93. __asm__ __volatile__(
  94. "1: addcc %0, -4096, %0\n\t"
  95. " bne 1b\n\t"
  96. " sta %%g0, [%2 + %0] %3"
  97. : "=&r" (vac_size)
  98. : "0" (vac_size), "r" (addr), "i" (ASI_HWFLUSHSEG)
  99. : "cc");
  100. }
  101. }
  102. /* File local boot time fixups. */
  103. BTFIXUPDEF_CALL(void, sun4c_flush_page, unsigned long)
  104. BTFIXUPDEF_CALL(void, sun4c_flush_segment, unsigned long)
  105. BTFIXUPDEF_CALL(void, sun4c_flush_context, void)
  106. #define sun4c_flush_page(addr) BTFIXUP_CALL(sun4c_flush_page)(addr)
  107. #define sun4c_flush_segment(addr) BTFIXUP_CALL(sun4c_flush_segment)(addr)
  108. #define sun4c_flush_context() BTFIXUP_CALL(sun4c_flush_context)()
  109. /* Must be called minimally with interrupts disabled. */
  110. static void sun4c_flush_page_hw(unsigned long addr)
  111. {
  112. addr &= PAGE_MASK;
  113. if ((int)sun4c_get_pte(addr) < 0)
  114. __asm__ __volatile__("sta %%g0, [%0] %1"
  115. : : "r" (addr), "i" (ASI_HWFLUSHPAGE));
  116. }
  117. /* Don't inline the software version as it eats too many cache lines if expanded. */
  118. static void sun4c_flush_context_sw(void)
  119. {
  120. unsigned long nbytes = SUN4C_VAC_SIZE;
  121. unsigned long lsize = sun4c_vacinfo.linesize;
  122. __asm__ __volatile__(
  123. "add %2, %2, %%g1\n\t"
  124. "add %2, %%g1, %%g2\n\t"
  125. "add %2, %%g2, %%g3\n\t"
  126. "add %2, %%g3, %%g4\n\t"
  127. "add %2, %%g4, %%g5\n\t"
  128. "add %2, %%g5, %%o4\n\t"
  129. "add %2, %%o4, %%o5\n"
  130. "1:\n\t"
  131. "subcc %0, %%o5, %0\n\t"
  132. "sta %%g0, [%0] %3\n\t"
  133. "sta %%g0, [%0 + %2] %3\n\t"
  134. "sta %%g0, [%0 + %%g1] %3\n\t"
  135. "sta %%g0, [%0 + %%g2] %3\n\t"
  136. "sta %%g0, [%0 + %%g3] %3\n\t"
  137. "sta %%g0, [%0 + %%g4] %3\n\t"
  138. "sta %%g0, [%0 + %%g5] %3\n\t"
  139. "bg 1b\n\t"
  140. " sta %%g0, [%1 + %%o4] %3\n"
  141. : "=&r" (nbytes)
  142. : "0" (nbytes), "r" (lsize), "i" (ASI_FLUSHCTX)
  143. : "g1", "g2", "g3", "g4", "g5", "o4", "o5", "cc");
  144. }
  145. /* Don't inline the software version as it eats too many cache lines if expanded. */
  146. static void sun4c_flush_segment_sw(unsigned long addr)
  147. {
  148. if (sun4c_get_segmap(addr) != invalid_segment) {
  149. unsigned long nbytes = SUN4C_VAC_SIZE;
  150. unsigned long lsize = sun4c_vacinfo.linesize;
  151. __asm__ __volatile__(
  152. "add %2, %2, %%g1\n\t"
  153. "add %2, %%g1, %%g2\n\t"
  154. "add %2, %%g2, %%g3\n\t"
  155. "add %2, %%g3, %%g4\n\t"
  156. "add %2, %%g4, %%g5\n\t"
  157. "add %2, %%g5, %%o4\n\t"
  158. "add %2, %%o4, %%o5\n"
  159. "1:\n\t"
  160. "subcc %1, %%o5, %1\n\t"
  161. "sta %%g0, [%0] %6\n\t"
  162. "sta %%g0, [%0 + %2] %6\n\t"
  163. "sta %%g0, [%0 + %%g1] %6\n\t"
  164. "sta %%g0, [%0 + %%g2] %6\n\t"
  165. "sta %%g0, [%0 + %%g3] %6\n\t"
  166. "sta %%g0, [%0 + %%g4] %6\n\t"
  167. "sta %%g0, [%0 + %%g5] %6\n\t"
  168. "sta %%g0, [%0 + %%o4] %6\n\t"
  169. "bg 1b\n\t"
  170. " add %0, %%o5, %0\n"
  171. : "=&r" (addr), "=&r" (nbytes), "=&r" (lsize)
  172. : "0" (addr), "1" (nbytes), "2" (lsize),
  173. "i" (ASI_FLUSHSEG)
  174. : "g1", "g2", "g3", "g4", "g5", "o4", "o5", "cc");
  175. }
  176. }
  177. /* Don't inline the software version as it eats too many cache lines if expanded. */
  178. static void sun4c_flush_page_sw(unsigned long addr)
  179. {
  180. addr &= PAGE_MASK;
  181. if ((sun4c_get_pte(addr) & (_SUN4C_PAGE_NOCACHE | _SUN4C_PAGE_VALID)) ==
  182. _SUN4C_PAGE_VALID) {
  183. unsigned long left = PAGE_SIZE;
  184. unsigned long lsize = sun4c_vacinfo.linesize;
  185. __asm__ __volatile__(
  186. "add %2, %2, %%g1\n\t"
  187. "add %2, %%g1, %%g2\n\t"
  188. "add %2, %%g2, %%g3\n\t"
  189. "add %2, %%g3, %%g4\n\t"
  190. "add %2, %%g4, %%g5\n\t"
  191. "add %2, %%g5, %%o4\n\t"
  192. "add %2, %%o4, %%o5\n"
  193. "1:\n\t"
  194. "subcc %1, %%o5, %1\n\t"
  195. "sta %%g0, [%0] %6\n\t"
  196. "sta %%g0, [%0 + %2] %6\n\t"
  197. "sta %%g0, [%0 + %%g1] %6\n\t"
  198. "sta %%g0, [%0 + %%g2] %6\n\t"
  199. "sta %%g0, [%0 + %%g3] %6\n\t"
  200. "sta %%g0, [%0 + %%g4] %6\n\t"
  201. "sta %%g0, [%0 + %%g5] %6\n\t"
  202. "sta %%g0, [%0 + %%o4] %6\n\t"
  203. "bg 1b\n\t"
  204. " add %0, %%o5, %0\n"
  205. : "=&r" (addr), "=&r" (left), "=&r" (lsize)
  206. : "0" (addr), "1" (left), "2" (lsize),
  207. "i" (ASI_FLUSHPG)
  208. : "g1", "g2", "g3", "g4", "g5", "o4", "o5", "cc");
  209. }
  210. }
  211. /* The sun4c's do have an on chip store buffer. And the way you
  212. * clear them out isn't so obvious. The only way I can think of
  213. * to accomplish this is to read the current context register,
  214. * store the same value there, then read an external hardware
  215. * register.
  216. */
  217. void sun4c_complete_all_stores(void)
  218. {
  219. volatile int _unused;
  220. _unused = sun4c_get_context();
  221. sun4c_set_context(_unused);
  222. #ifdef CONFIG_SUN_AUXIO
  223. _unused = get_auxio();
  224. #endif
  225. }
  226. /* Bootup utility functions. */
  227. static inline void sun4c_init_clean_segmap(unsigned char pseg)
  228. {
  229. unsigned long vaddr;
  230. sun4c_put_segmap(0, pseg);
  231. for (vaddr = 0; vaddr < SUN4C_REAL_PGDIR_SIZE; vaddr += PAGE_SIZE)
  232. sun4c_put_pte(vaddr, 0);
  233. sun4c_put_segmap(0, invalid_segment);
  234. }
  235. static inline void sun4c_init_clean_mmu(unsigned long kernel_end)
  236. {
  237. unsigned long vaddr;
  238. unsigned char savectx, ctx;
  239. savectx = sun4c_get_context();
  240. kernel_end = SUN4C_REAL_PGDIR_ALIGN(kernel_end);
  241. for (ctx = 0; ctx < num_contexts; ctx++) {
  242. sun4c_set_context(ctx);
  243. for (vaddr = 0; vaddr < 0x20000000; vaddr += SUN4C_REAL_PGDIR_SIZE)
  244. sun4c_put_segmap(vaddr, invalid_segment);
  245. for (vaddr = 0xe0000000; vaddr < KERNBASE; vaddr += SUN4C_REAL_PGDIR_SIZE)
  246. sun4c_put_segmap(vaddr, invalid_segment);
  247. for (vaddr = kernel_end; vaddr < KADB_DEBUGGER_BEGVM; vaddr += SUN4C_REAL_PGDIR_SIZE)
  248. sun4c_put_segmap(vaddr, invalid_segment);
  249. for (vaddr = LINUX_OPPROM_ENDVM; vaddr; vaddr += SUN4C_REAL_PGDIR_SIZE)
  250. sun4c_put_segmap(vaddr, invalid_segment);
  251. }
  252. sun4c_set_context(savectx);
  253. }
  254. void __init sun4c_probe_vac(void)
  255. {
  256. sun4c_disable_vac();
  257. if (ARCH_SUN4) {
  258. switch (idprom->id_machtype) {
  259. case (SM_SUN4|SM_4_110):
  260. sun4c_vacinfo.type = VAC_NONE;
  261. sun4c_vacinfo.num_bytes = 0;
  262. sun4c_vacinfo.linesize = 0;
  263. sun4c_vacinfo.do_hwflushes = 0;
  264. prom_printf("No VAC. Get some bucks and buy a real computer.");
  265. prom_halt();
  266. break;
  267. case (SM_SUN4|SM_4_260):
  268. sun4c_vacinfo.type = VAC_WRITE_BACK;
  269. sun4c_vacinfo.num_bytes = 128 * 1024;
  270. sun4c_vacinfo.linesize = 16;
  271. sun4c_vacinfo.do_hwflushes = 0;
  272. break;
  273. case (SM_SUN4|SM_4_330):
  274. sun4c_vacinfo.type = VAC_WRITE_THROUGH;
  275. sun4c_vacinfo.num_bytes = 128 * 1024;
  276. sun4c_vacinfo.linesize = 16;
  277. sun4c_vacinfo.do_hwflushes = 0;
  278. break;
  279. case (SM_SUN4|SM_4_470):
  280. sun4c_vacinfo.type = VAC_WRITE_BACK;
  281. sun4c_vacinfo.num_bytes = 128 * 1024;
  282. sun4c_vacinfo.linesize = 32;
  283. sun4c_vacinfo.do_hwflushes = 0;
  284. break;
  285. default:
  286. prom_printf("Cannot initialize VAC - weird sun4 model idprom->id_machtype = %d", idprom->id_machtype);
  287. prom_halt();
  288. };
  289. } else {
  290. sun4c_vacinfo.type = VAC_WRITE_THROUGH;
  291. if ((idprom->id_machtype == (SM_SUN4C | SM_4C_SS1)) ||
  292. (idprom->id_machtype == (SM_SUN4C | SM_4C_SS1PLUS))) {
  293. /* PROM on SS1 lacks this info, to be super safe we
  294. * hard code it here since this arch is cast in stone.
  295. */
  296. sun4c_vacinfo.num_bytes = 65536;
  297. sun4c_vacinfo.linesize = 16;
  298. } else {
  299. sun4c_vacinfo.num_bytes =
  300. prom_getintdefault(prom_root_node, "vac-size", 65536);
  301. sun4c_vacinfo.linesize =
  302. prom_getintdefault(prom_root_node, "vac-linesize", 16);
  303. }
  304. sun4c_vacinfo.do_hwflushes =
  305. prom_getintdefault(prom_root_node, "vac-hwflush", 0);
  306. if (sun4c_vacinfo.do_hwflushes == 0)
  307. sun4c_vacinfo.do_hwflushes =
  308. prom_getintdefault(prom_root_node, "vac_hwflush", 0);
  309. if (sun4c_vacinfo.num_bytes != 65536) {
  310. prom_printf("WEIRD Sun4C VAC cache size, "
  311. "tell sparclinux@vger.kernel.org");
  312. prom_halt();
  313. }
  314. }
  315. sun4c_vacinfo.num_lines =
  316. (sun4c_vacinfo.num_bytes / sun4c_vacinfo.linesize);
  317. switch (sun4c_vacinfo.linesize) {
  318. case 16:
  319. sun4c_vacinfo.log2lsize = 4;
  320. break;
  321. case 32:
  322. sun4c_vacinfo.log2lsize = 5;
  323. break;
  324. default:
  325. prom_printf("probe_vac: Didn't expect vac-linesize of %d, halting\n",
  326. sun4c_vacinfo.linesize);
  327. prom_halt();
  328. };
  329. sun4c_flush_all();
  330. sun4c_enable_vac();
  331. }
  332. /* Patch instructions for the low level kernel fault handler. */
  333. extern unsigned long invalid_segment_patch1, invalid_segment_patch1_ff;
  334. extern unsigned long invalid_segment_patch2, invalid_segment_patch2_ff;
  335. extern unsigned long invalid_segment_patch1_1ff, invalid_segment_patch2_1ff;
  336. extern unsigned long num_context_patch1, num_context_patch1_16;
  337. extern unsigned long num_context_patch2_16;
  338. extern unsigned long vac_linesize_patch, vac_linesize_patch_32;
  339. extern unsigned long vac_hwflush_patch1, vac_hwflush_patch1_on;
  340. extern unsigned long vac_hwflush_patch2, vac_hwflush_patch2_on;
  341. #define PATCH_INSN(src, dst) do { \
  342. daddr = &(dst); \
  343. iaddr = &(src); \
  344. *daddr = *iaddr; \
  345. } while (0)
  346. static void __init patch_kernel_fault_handler(void)
  347. {
  348. unsigned long *iaddr, *daddr;
  349. switch (num_segmaps) {
  350. case 128:
  351. /* Default, nothing to do. */
  352. break;
  353. case 256:
  354. PATCH_INSN(invalid_segment_patch1_ff,
  355. invalid_segment_patch1);
  356. PATCH_INSN(invalid_segment_patch2_ff,
  357. invalid_segment_patch2);
  358. break;
  359. case 512:
  360. PATCH_INSN(invalid_segment_patch1_1ff,
  361. invalid_segment_patch1);
  362. PATCH_INSN(invalid_segment_patch2_1ff,
  363. invalid_segment_patch2);
  364. break;
  365. default:
  366. prom_printf("Unhandled number of segmaps: %d\n",
  367. num_segmaps);
  368. prom_halt();
  369. };
  370. switch (num_contexts) {
  371. case 8:
  372. /* Default, nothing to do. */
  373. break;
  374. case 16:
  375. PATCH_INSN(num_context_patch1_16,
  376. num_context_patch1);
  377. break;
  378. default:
  379. prom_printf("Unhandled number of contexts: %d\n",
  380. num_contexts);
  381. prom_halt();
  382. };
  383. if (sun4c_vacinfo.do_hwflushes != 0) {
  384. PATCH_INSN(vac_hwflush_patch1_on, vac_hwflush_patch1);
  385. PATCH_INSN(vac_hwflush_patch2_on, vac_hwflush_patch2);
  386. } else {
  387. switch (sun4c_vacinfo.linesize) {
  388. case 16:
  389. /* Default, nothing to do. */
  390. break;
  391. case 32:
  392. PATCH_INSN(vac_linesize_patch_32, vac_linesize_patch);
  393. break;
  394. default:
  395. prom_printf("Impossible VAC linesize %d, halting...\n",
  396. sun4c_vacinfo.linesize);
  397. prom_halt();
  398. };
  399. }
  400. }
  401. static void __init sun4c_probe_mmu(void)
  402. {
  403. if (ARCH_SUN4) {
  404. switch (idprom->id_machtype) {
  405. case (SM_SUN4|SM_4_110):
  406. prom_printf("No support for 4100 yet\n");
  407. prom_halt();
  408. num_segmaps = 256;
  409. num_contexts = 8;
  410. break;
  411. case (SM_SUN4|SM_4_260):
  412. /* should be 512 segmaps. when it get fixed */
  413. num_segmaps = 256;
  414. num_contexts = 16;
  415. break;
  416. case (SM_SUN4|SM_4_330):
  417. num_segmaps = 256;
  418. num_contexts = 16;
  419. break;
  420. case (SM_SUN4|SM_4_470):
  421. /* should be 1024 segmaps. when it get fixed */
  422. num_segmaps = 256;
  423. num_contexts = 64;
  424. break;
  425. default:
  426. prom_printf("Invalid SUN4 model\n");
  427. prom_halt();
  428. };
  429. } else {
  430. if ((idprom->id_machtype == (SM_SUN4C | SM_4C_SS1)) ||
  431. (idprom->id_machtype == (SM_SUN4C | SM_4C_SS1PLUS))) {
  432. /* Hardcode these just to be safe, PROM on SS1 does
  433. * not have this info available in the root node.
  434. */
  435. num_segmaps = 128;
  436. num_contexts = 8;
  437. } else {
  438. num_segmaps =
  439. prom_getintdefault(prom_root_node, "mmu-npmg", 128);
  440. num_contexts =
  441. prom_getintdefault(prom_root_node, "mmu-nctx", 0x8);
  442. }
  443. }
  444. patch_kernel_fault_handler();
  445. }
  446. volatile unsigned long __iomem *sun4c_memerr_reg = NULL;
  447. void __init sun4c_probe_memerr_reg(void)
  448. {
  449. int node;
  450. struct linux_prom_registers regs[1];
  451. if (ARCH_SUN4) {
  452. sun4c_memerr_reg = ioremap(sun4_memreg_physaddr, PAGE_SIZE);
  453. } else {
  454. node = prom_getchild(prom_root_node);
  455. node = prom_searchsiblings(prom_root_node, "memory-error");
  456. if (!node)
  457. return;
  458. if (prom_getproperty(node, "reg", (char *)regs, sizeof(regs)) <= 0)
  459. return;
  460. /* hmm I think regs[0].which_io is zero here anyways */
  461. sun4c_memerr_reg = ioremap(regs[0].phys_addr, regs[0].reg_size);
  462. }
  463. }
  464. static inline void sun4c_init_ss2_cache_bug(void)
  465. {
  466. extern unsigned long start;
  467. if ((idprom->id_machtype == (SM_SUN4C | SM_4C_SS2)) ||
  468. (idprom->id_machtype == (SM_SUN4C | SM_4C_IPX)) ||
  469. (idprom->id_machtype == (SM_SUN4 | SM_4_330)) ||
  470. (idprom->id_machtype == (SM_SUN4C | SM_4C_ELC))) {
  471. /* Whee.. */
  472. printk("SS2 cache bug detected, uncaching trap table page\n");
  473. sun4c_flush_page((unsigned int) &start);
  474. sun4c_put_pte(((unsigned long) &start),
  475. (sun4c_get_pte((unsigned long) &start) | _SUN4C_PAGE_NOCACHE));
  476. }
  477. }
  478. /* Addr is always aligned on a page boundary for us already. */
  479. static int sun4c_map_dma_area(dma_addr_t *pba, unsigned long va,
  480. unsigned long addr, int len)
  481. {
  482. unsigned long page, end;
  483. *pba = addr;
  484. end = PAGE_ALIGN((addr + len));
  485. while (addr < end) {
  486. page = va;
  487. sun4c_flush_page(page);
  488. page -= PAGE_OFFSET;
  489. page >>= PAGE_SHIFT;
  490. page |= (_SUN4C_PAGE_VALID | _SUN4C_PAGE_DIRTY |
  491. _SUN4C_PAGE_NOCACHE | _SUN4C_PAGE_PRIV);
  492. sun4c_put_pte(addr, page);
  493. addr += PAGE_SIZE;
  494. va += PAGE_SIZE;
  495. }
  496. return 0;
  497. }
  498. static struct page *sun4c_translate_dvma(unsigned long busa)
  499. {
  500. /* Fortunately for us, bus_addr == uncached_virt in sun4c. */
  501. unsigned long pte = sun4c_get_pte(busa);
  502. return pfn_to_page(pte & SUN4C_PFN_MASK);
  503. }
  504. static void sun4c_unmap_dma_area(unsigned long busa, int len)
  505. {
  506. /* Fortunately for us, bus_addr == uncached_virt in sun4c. */
  507. /* XXX Implement this */
  508. }
  509. /* TLB management. */
  510. /* Don't change this struct without changing entry.S. This is used
  511. * in the in-window kernel fault handler, and you don't want to mess
  512. * with that. (See sun4c_fault in entry.S).
  513. */
  514. struct sun4c_mmu_entry {
  515. struct sun4c_mmu_entry *next;
  516. struct sun4c_mmu_entry *prev;
  517. unsigned long vaddr;
  518. unsigned char pseg;
  519. unsigned char locked;
  520. /* For user mappings only, and completely hidden from kernel
  521. * TLB miss code.
  522. */
  523. unsigned char ctx;
  524. struct sun4c_mmu_entry *lru_next;
  525. struct sun4c_mmu_entry *lru_prev;
  526. };
  527. static struct sun4c_mmu_entry mmu_entry_pool[SUN4C_MAX_SEGMAPS];
  528. static void __init sun4c_init_mmu_entry_pool(void)
  529. {
  530. int i;
  531. for (i=0; i < SUN4C_MAX_SEGMAPS; i++) {
  532. mmu_entry_pool[i].pseg = i;
  533. mmu_entry_pool[i].next = NULL;
  534. mmu_entry_pool[i].prev = NULL;
  535. mmu_entry_pool[i].vaddr = 0;
  536. mmu_entry_pool[i].locked = 0;
  537. mmu_entry_pool[i].ctx = 0;
  538. mmu_entry_pool[i].lru_next = NULL;
  539. mmu_entry_pool[i].lru_prev = NULL;
  540. }
  541. mmu_entry_pool[invalid_segment].locked = 1;
  542. }
  543. static inline void fix_permissions(unsigned long vaddr, unsigned long bits_on,
  544. unsigned long bits_off)
  545. {
  546. unsigned long start, end;
  547. end = vaddr + SUN4C_REAL_PGDIR_SIZE;
  548. for (start = vaddr; start < end; start += PAGE_SIZE)
  549. if (sun4c_get_pte(start) & _SUN4C_PAGE_VALID)
  550. sun4c_put_pte(start, (sun4c_get_pte(start) | bits_on) &
  551. ~bits_off);
  552. }
  553. static inline void sun4c_init_map_kernelprom(unsigned long kernel_end)
  554. {
  555. unsigned long vaddr;
  556. unsigned char pseg, ctx;
  557. #ifdef CONFIG_SUN4
  558. /* sun4/110 and 260 have no kadb. */
  559. if ((idprom->id_machtype != (SM_SUN4 | SM_4_260)) &&
  560. (idprom->id_machtype != (SM_SUN4 | SM_4_110))) {
  561. #endif
  562. for (vaddr = KADB_DEBUGGER_BEGVM;
  563. vaddr < LINUX_OPPROM_ENDVM;
  564. vaddr += SUN4C_REAL_PGDIR_SIZE) {
  565. pseg = sun4c_get_segmap(vaddr);
  566. if (pseg != invalid_segment) {
  567. mmu_entry_pool[pseg].locked = 1;
  568. for (ctx = 0; ctx < num_contexts; ctx++)
  569. prom_putsegment(ctx, vaddr, pseg);
  570. fix_permissions(vaddr, _SUN4C_PAGE_PRIV, 0);
  571. }
  572. }
  573. #ifdef CONFIG_SUN4
  574. }
  575. #endif
  576. for (vaddr = KERNBASE; vaddr < kernel_end; vaddr += SUN4C_REAL_PGDIR_SIZE) {
  577. pseg = sun4c_get_segmap(vaddr);
  578. mmu_entry_pool[pseg].locked = 1;
  579. for (ctx = 0; ctx < num_contexts; ctx++)
  580. prom_putsegment(ctx, vaddr, pseg);
  581. fix_permissions(vaddr, _SUN4C_PAGE_PRIV, _SUN4C_PAGE_NOCACHE);
  582. }
  583. }
  584. static void __init sun4c_init_lock_area(unsigned long start, unsigned long end)
  585. {
  586. int i, ctx;
  587. while (start < end) {
  588. for (i = 0; i < invalid_segment; i++)
  589. if (!mmu_entry_pool[i].locked)
  590. break;
  591. mmu_entry_pool[i].locked = 1;
  592. sun4c_init_clean_segmap(i);
  593. for (ctx = 0; ctx < num_contexts; ctx++)
  594. prom_putsegment(ctx, start, mmu_entry_pool[i].pseg);
  595. start += SUN4C_REAL_PGDIR_SIZE;
  596. }
  597. }
  598. /* Don't change this struct without changing entry.S. This is used
  599. * in the in-window kernel fault handler, and you don't want to mess
  600. * with that. (See sun4c_fault in entry.S).
  601. */
  602. struct sun4c_mmu_ring {
  603. struct sun4c_mmu_entry ringhd;
  604. int num_entries;
  605. };
  606. static struct sun4c_mmu_ring sun4c_context_ring[SUN4C_MAX_CONTEXTS]; /* used user entries */
  607. static struct sun4c_mmu_ring sun4c_ufree_ring; /* free user entries */
  608. static struct sun4c_mmu_ring sun4c_ulru_ring; /* LRU user entries */
  609. struct sun4c_mmu_ring sun4c_kernel_ring; /* used kernel entries */
  610. struct sun4c_mmu_ring sun4c_kfree_ring; /* free kernel entries */
  611. static inline void sun4c_init_rings(void)
  612. {
  613. int i;
  614. for (i = 0; i < SUN4C_MAX_CONTEXTS; i++) {
  615. sun4c_context_ring[i].ringhd.next =
  616. sun4c_context_ring[i].ringhd.prev =
  617. &sun4c_context_ring[i].ringhd;
  618. sun4c_context_ring[i].num_entries = 0;
  619. }
  620. sun4c_ufree_ring.ringhd.next = sun4c_ufree_ring.ringhd.prev =
  621. &sun4c_ufree_ring.ringhd;
  622. sun4c_ufree_ring.num_entries = 0;
  623. sun4c_ulru_ring.ringhd.lru_next = sun4c_ulru_ring.ringhd.lru_prev =
  624. &sun4c_ulru_ring.ringhd;
  625. sun4c_ulru_ring.num_entries = 0;
  626. sun4c_kernel_ring.ringhd.next = sun4c_kernel_ring.ringhd.prev =
  627. &sun4c_kernel_ring.ringhd;
  628. sun4c_kernel_ring.num_entries = 0;
  629. sun4c_kfree_ring.ringhd.next = sun4c_kfree_ring.ringhd.prev =
  630. &sun4c_kfree_ring.ringhd;
  631. sun4c_kfree_ring.num_entries = 0;
  632. }
  633. static void add_ring(struct sun4c_mmu_ring *ring,
  634. struct sun4c_mmu_entry *entry)
  635. {
  636. struct sun4c_mmu_entry *head = &ring->ringhd;
  637. entry->prev = head;
  638. (entry->next = head->next)->prev = entry;
  639. head->next = entry;
  640. ring->num_entries++;
  641. }
  642. static __inline__ void add_lru(struct sun4c_mmu_entry *entry)
  643. {
  644. struct sun4c_mmu_ring *ring = &sun4c_ulru_ring;
  645. struct sun4c_mmu_entry *head = &ring->ringhd;
  646. entry->lru_next = head;
  647. (entry->lru_prev = head->lru_prev)->lru_next = entry;
  648. head->lru_prev = entry;
  649. }
  650. static void add_ring_ordered(struct sun4c_mmu_ring *ring,
  651. struct sun4c_mmu_entry *entry)
  652. {
  653. struct sun4c_mmu_entry *head = &ring->ringhd;
  654. unsigned long addr = entry->vaddr;
  655. while ((head->next != &ring->ringhd) && (head->next->vaddr < addr))
  656. head = head->next;
  657. entry->prev = head;
  658. (entry->next = head->next)->prev = entry;
  659. head->next = entry;
  660. ring->num_entries++;
  661. add_lru(entry);
  662. }
  663. static __inline__ void remove_ring(struct sun4c_mmu_ring *ring,
  664. struct sun4c_mmu_entry *entry)
  665. {
  666. struct sun4c_mmu_entry *next = entry->next;
  667. (next->prev = entry->prev)->next = next;
  668. ring->num_entries--;
  669. }
  670. static void remove_lru(struct sun4c_mmu_entry *entry)
  671. {
  672. struct sun4c_mmu_entry *next = entry->lru_next;
  673. (next->lru_prev = entry->lru_prev)->lru_next = next;
  674. }
  675. static void free_user_entry(int ctx, struct sun4c_mmu_entry *entry)
  676. {
  677. remove_ring(sun4c_context_ring+ctx, entry);
  678. remove_lru(entry);
  679. add_ring(&sun4c_ufree_ring, entry);
  680. }
  681. static void free_kernel_entry(struct sun4c_mmu_entry *entry,
  682. struct sun4c_mmu_ring *ring)
  683. {
  684. remove_ring(ring, entry);
  685. add_ring(&sun4c_kfree_ring, entry);
  686. }
  687. static void __init sun4c_init_fill_kernel_ring(int howmany)
  688. {
  689. int i;
  690. while (howmany) {
  691. for (i = 0; i < invalid_segment; i++)
  692. if (!mmu_entry_pool[i].locked)
  693. break;
  694. mmu_entry_pool[i].locked = 1;
  695. sun4c_init_clean_segmap(i);
  696. add_ring(&sun4c_kfree_ring, &mmu_entry_pool[i]);
  697. howmany--;
  698. }
  699. }
  700. static void __init sun4c_init_fill_user_ring(void)
  701. {
  702. int i;
  703. for (i = 0; i < invalid_segment; i++) {
  704. if (mmu_entry_pool[i].locked)
  705. continue;
  706. sun4c_init_clean_segmap(i);
  707. add_ring(&sun4c_ufree_ring, &mmu_entry_pool[i]);
  708. }
  709. }
  710. static void sun4c_kernel_unmap(struct sun4c_mmu_entry *kentry)
  711. {
  712. int savectx, ctx;
  713. savectx = sun4c_get_context();
  714. for (ctx = 0; ctx < num_contexts; ctx++) {
  715. sun4c_set_context(ctx);
  716. sun4c_put_segmap(kentry->vaddr, invalid_segment);
  717. }
  718. sun4c_set_context(savectx);
  719. }
  720. static void sun4c_kernel_map(struct sun4c_mmu_entry *kentry)
  721. {
  722. int savectx, ctx;
  723. savectx = sun4c_get_context();
  724. for (ctx = 0; ctx < num_contexts; ctx++) {
  725. sun4c_set_context(ctx);
  726. sun4c_put_segmap(kentry->vaddr, kentry->pseg);
  727. }
  728. sun4c_set_context(savectx);
  729. }
  730. #define sun4c_user_unmap(__entry) \
  731. sun4c_put_segmap((__entry)->vaddr, invalid_segment)
  732. static void sun4c_demap_context(struct sun4c_mmu_ring *crp, unsigned char ctx)
  733. {
  734. struct sun4c_mmu_entry *head = &crp->ringhd;
  735. unsigned long flags;
  736. local_irq_save(flags);
  737. if (head->next != head) {
  738. struct sun4c_mmu_entry *entry = head->next;
  739. int savectx = sun4c_get_context();
  740. flush_user_windows();
  741. sun4c_set_context(ctx);
  742. sun4c_flush_context();
  743. do {
  744. struct sun4c_mmu_entry *next = entry->next;
  745. sun4c_user_unmap(entry);
  746. free_user_entry(ctx, entry);
  747. entry = next;
  748. } while (entry != head);
  749. sun4c_set_context(savectx);
  750. }
  751. local_irq_restore(flags);
  752. }
  753. static int sun4c_user_taken_entries; /* This is how much we have. */
  754. static int max_user_taken_entries; /* This limits us and prevents deadlock. */
  755. static struct sun4c_mmu_entry *sun4c_kernel_strategy(void)
  756. {
  757. struct sun4c_mmu_entry *this_entry;
  758. /* If some are free, return first one. */
  759. if (sun4c_kfree_ring.num_entries) {
  760. this_entry = sun4c_kfree_ring.ringhd.next;
  761. return this_entry;
  762. }
  763. /* Else free one up. */
  764. this_entry = sun4c_kernel_ring.ringhd.prev;
  765. sun4c_flush_segment(this_entry->vaddr);
  766. sun4c_kernel_unmap(this_entry);
  767. free_kernel_entry(this_entry, &sun4c_kernel_ring);
  768. this_entry = sun4c_kfree_ring.ringhd.next;
  769. return this_entry;
  770. }
  771. /* Using this method to free up mmu entries eliminates a lot of
  772. * potential races since we have a kernel that incurs tlb
  773. * replacement faults. There may be performance penalties.
  774. *
  775. * NOTE: Must be called with interrupts disabled.
  776. */
  777. static struct sun4c_mmu_entry *sun4c_user_strategy(void)
  778. {
  779. struct sun4c_mmu_entry *entry;
  780. unsigned char ctx;
  781. int savectx;
  782. /* If some are free, return first one. */
  783. if (sun4c_ufree_ring.num_entries) {
  784. entry = sun4c_ufree_ring.ringhd.next;
  785. goto unlink_out;
  786. }
  787. if (sun4c_user_taken_entries) {
  788. entry = sun4c_kernel_strategy();
  789. sun4c_user_taken_entries--;
  790. goto kunlink_out;
  791. }
  792. /* Grab from the beginning of the LRU list. */
  793. entry = sun4c_ulru_ring.ringhd.lru_next;
  794. ctx = entry->ctx;
  795. savectx = sun4c_get_context();
  796. flush_user_windows();
  797. sun4c_set_context(ctx);
  798. sun4c_flush_segment(entry->vaddr);
  799. sun4c_user_unmap(entry);
  800. remove_ring(sun4c_context_ring + ctx, entry);
  801. remove_lru(entry);
  802. sun4c_set_context(savectx);
  803. return entry;
  804. unlink_out:
  805. remove_ring(&sun4c_ufree_ring, entry);
  806. return entry;
  807. kunlink_out:
  808. remove_ring(&sun4c_kfree_ring, entry);
  809. return entry;
  810. }
  811. /* NOTE: Must be called with interrupts disabled. */
  812. void sun4c_grow_kernel_ring(void)
  813. {
  814. struct sun4c_mmu_entry *entry;
  815. /* Prevent deadlock condition. */
  816. if (sun4c_user_taken_entries >= max_user_taken_entries)
  817. return;
  818. if (sun4c_ufree_ring.num_entries) {
  819. entry = sun4c_ufree_ring.ringhd.next;
  820. remove_ring(&sun4c_ufree_ring, entry);
  821. add_ring(&sun4c_kfree_ring, entry);
  822. sun4c_user_taken_entries++;
  823. }
  824. }
  825. /* 2 page buckets for task struct and kernel stack allocation.
  826. *
  827. * TASK_STACK_BEGIN
  828. * bucket[0]
  829. * bucket[1]
  830. * [ ... ]
  831. * bucket[NR_TASK_BUCKETS-1]
  832. * TASK_STACK_BEGIN + (sizeof(struct task_bucket) * NR_TASK_BUCKETS)
  833. *
  834. * Each slot looks like:
  835. *
  836. * page 1 -- task struct + beginning of kernel stack
  837. * page 2 -- rest of kernel stack
  838. */
  839. union task_union *sun4c_bucket[NR_TASK_BUCKETS];
  840. static int sun4c_lowbucket_avail;
  841. #define BUCKET_EMPTY ((union task_union *) 0)
  842. #define BUCKET_SHIFT (PAGE_SHIFT + 1) /* log2(sizeof(struct task_bucket)) */
  843. #define BUCKET_SIZE (1 << BUCKET_SHIFT)
  844. #define BUCKET_NUM(addr) ((((addr) - SUN4C_LOCK_VADDR) >> BUCKET_SHIFT))
  845. #define BUCKET_ADDR(num) (((num) << BUCKET_SHIFT) + SUN4C_LOCK_VADDR)
  846. #define BUCKET_PTE(page) \
  847. ((((page) - PAGE_OFFSET) >> PAGE_SHIFT) | pgprot_val(SUN4C_PAGE_KERNEL))
  848. #define BUCKET_PTE_PAGE(pte) \
  849. (PAGE_OFFSET + (((pte) & SUN4C_PFN_MASK) << PAGE_SHIFT))
  850. static void get_locked_segment(unsigned long addr)
  851. {
  852. struct sun4c_mmu_entry *stolen;
  853. unsigned long flags;
  854. local_irq_save(flags);
  855. addr &= SUN4C_REAL_PGDIR_MASK;
  856. stolen = sun4c_user_strategy();
  857. max_user_taken_entries--;
  858. stolen->vaddr = addr;
  859. flush_user_windows();
  860. sun4c_kernel_map(stolen);
  861. local_irq_restore(flags);
  862. }
  863. static void free_locked_segment(unsigned long addr)
  864. {
  865. struct sun4c_mmu_entry *entry;
  866. unsigned long flags;
  867. unsigned char pseg;
  868. local_irq_save(flags);
  869. addr &= SUN4C_REAL_PGDIR_MASK;
  870. pseg = sun4c_get_segmap(addr);
  871. entry = &mmu_entry_pool[pseg];
  872. flush_user_windows();
  873. sun4c_flush_segment(addr);
  874. sun4c_kernel_unmap(entry);
  875. add_ring(&sun4c_ufree_ring, entry);
  876. max_user_taken_entries++;
  877. local_irq_restore(flags);
  878. }
  879. static inline void garbage_collect(int entry)
  880. {
  881. int start, end;
  882. /* 32 buckets per segment... */
  883. entry &= ~31;
  884. start = entry;
  885. for (end = (start + 32); start < end; start++)
  886. if (sun4c_bucket[start] != BUCKET_EMPTY)
  887. return;
  888. /* Entire segment empty, release it. */
  889. free_locked_segment(BUCKET_ADDR(entry));
  890. }
  891. static struct thread_info *sun4c_alloc_thread_info(void)
  892. {
  893. unsigned long addr, pages;
  894. int entry;
  895. pages = __get_free_pages(GFP_KERNEL, THREAD_INFO_ORDER);
  896. if (!pages)
  897. return NULL;
  898. for (entry = sun4c_lowbucket_avail; entry < NR_TASK_BUCKETS; entry++)
  899. if (sun4c_bucket[entry] == BUCKET_EMPTY)
  900. break;
  901. if (entry == NR_TASK_BUCKETS) {
  902. free_pages(pages, THREAD_INFO_ORDER);
  903. return NULL;
  904. }
  905. if (entry >= sun4c_lowbucket_avail)
  906. sun4c_lowbucket_avail = entry + 1;
  907. addr = BUCKET_ADDR(entry);
  908. sun4c_bucket[entry] = (union task_union *) addr;
  909. if(sun4c_get_segmap(addr) == invalid_segment)
  910. get_locked_segment(addr);
  911. /* We are changing the virtual color of the page(s)
  912. * so we must flush the cache to guarantee consistency.
  913. */
  914. sun4c_flush_page(pages);
  915. #ifndef CONFIG_SUN4
  916. sun4c_flush_page(pages + PAGE_SIZE);
  917. #endif
  918. sun4c_put_pte(addr, BUCKET_PTE(pages));
  919. #ifndef CONFIG_SUN4
  920. sun4c_put_pte(addr + PAGE_SIZE, BUCKET_PTE(pages + PAGE_SIZE));
  921. #endif
  922. #ifdef CONFIG_DEBUG_STACK_USAGE
  923. memset((void *)addr, 0, PAGE_SIZE << THREAD_INFO_ORDER);
  924. #endif /* DEBUG_STACK_USAGE */
  925. return (struct thread_info *) addr;
  926. }
  927. static void sun4c_free_thread_info(struct thread_info *ti)
  928. {
  929. unsigned long tiaddr = (unsigned long) ti;
  930. unsigned long pages = BUCKET_PTE_PAGE(sun4c_get_pte(tiaddr));
  931. int entry = BUCKET_NUM(tiaddr);
  932. /* We are deleting a mapping, so the flush here is mandatory. */
  933. sun4c_flush_page(tiaddr);
  934. #ifndef CONFIG_SUN4
  935. sun4c_flush_page(tiaddr + PAGE_SIZE);
  936. #endif
  937. sun4c_put_pte(tiaddr, 0);
  938. #ifndef CONFIG_SUN4
  939. sun4c_put_pte(tiaddr + PAGE_SIZE, 0);
  940. #endif
  941. sun4c_bucket[entry] = BUCKET_EMPTY;
  942. if (entry < sun4c_lowbucket_avail)
  943. sun4c_lowbucket_avail = entry;
  944. free_pages(pages, THREAD_INFO_ORDER);
  945. garbage_collect(entry);
  946. }
  947. static void __init sun4c_init_buckets(void)
  948. {
  949. int entry;
  950. if (sizeof(union thread_union) != (PAGE_SIZE << THREAD_INFO_ORDER)) {
  951. extern void thread_info_size_is_bolixed_pete(void);
  952. thread_info_size_is_bolixed_pete();
  953. }
  954. for (entry = 0; entry < NR_TASK_BUCKETS; entry++)
  955. sun4c_bucket[entry] = BUCKET_EMPTY;
  956. sun4c_lowbucket_avail = 0;
  957. }
  958. static unsigned long sun4c_iobuffer_start;
  959. static unsigned long sun4c_iobuffer_end;
  960. static unsigned long sun4c_iobuffer_high;
  961. static unsigned long *sun4c_iobuffer_map;
  962. static int iobuffer_map_size;
  963. /*
  964. * Alias our pages so they do not cause a trap.
  965. * Also one page may be aliased into several I/O areas and we may
  966. * finish these I/O separately.
  967. */
  968. static char *sun4c_lockarea(char *vaddr, unsigned long size)
  969. {
  970. unsigned long base, scan;
  971. unsigned long npages;
  972. unsigned long vpage;
  973. unsigned long pte;
  974. unsigned long apage;
  975. unsigned long high;
  976. unsigned long flags;
  977. npages = (((unsigned long)vaddr & ~PAGE_MASK) +
  978. size + (PAGE_SIZE-1)) >> PAGE_SHIFT;
  979. scan = 0;
  980. local_irq_save(flags);
  981. for (;;) {
  982. scan = find_next_zero_bit(sun4c_iobuffer_map,
  983. iobuffer_map_size, scan);
  984. if ((base = scan) + npages > iobuffer_map_size) goto abend;
  985. for (;;) {
  986. if (scan >= base + npages) goto found;
  987. if (test_bit(scan, sun4c_iobuffer_map)) break;
  988. scan++;
  989. }
  990. }
  991. found:
  992. high = ((base + npages) << PAGE_SHIFT) + sun4c_iobuffer_start;
  993. high = SUN4C_REAL_PGDIR_ALIGN(high);
  994. while (high > sun4c_iobuffer_high) {
  995. get_locked_segment(sun4c_iobuffer_high);
  996. sun4c_iobuffer_high += SUN4C_REAL_PGDIR_SIZE;
  997. }
  998. vpage = ((unsigned long) vaddr) & PAGE_MASK;
  999. for (scan = base; scan < base+npages; scan++) {
  1000. pte = ((vpage-PAGE_OFFSET) >> PAGE_SHIFT);
  1001. pte |= pgprot_val(SUN4C_PAGE_KERNEL);
  1002. pte |= _SUN4C_PAGE_NOCACHE;
  1003. set_bit(scan, sun4c_iobuffer_map);
  1004. apage = (scan << PAGE_SHIFT) + sun4c_iobuffer_start;
  1005. /* Flush original mapping so we see the right things later. */
  1006. sun4c_flush_page(vpage);
  1007. sun4c_put_pte(apage, pte);
  1008. vpage += PAGE_SIZE;
  1009. }
  1010. local_irq_restore(flags);
  1011. return (char *) ((base << PAGE_SHIFT) + sun4c_iobuffer_start +
  1012. (((unsigned long) vaddr) & ~PAGE_MASK));
  1013. abend:
  1014. local_irq_restore(flags);
  1015. printk("DMA vaddr=0x%p size=%08lx\n", vaddr, size);
  1016. panic("Out of iobuffer table");
  1017. return NULL;
  1018. }
  1019. static void sun4c_unlockarea(char *vaddr, unsigned long size)
  1020. {
  1021. unsigned long vpage, npages;
  1022. unsigned long flags;
  1023. int scan, high;
  1024. vpage = (unsigned long)vaddr & PAGE_MASK;
  1025. npages = (((unsigned long)vaddr & ~PAGE_MASK) +
  1026. size + (PAGE_SIZE-1)) >> PAGE_SHIFT;
  1027. local_irq_save(flags);
  1028. while (npages != 0) {
  1029. --npages;
  1030. /* This mapping is marked non-cachable, no flush necessary. */
  1031. sun4c_put_pte(vpage, 0);
  1032. clear_bit((vpage - sun4c_iobuffer_start) >> PAGE_SHIFT,
  1033. sun4c_iobuffer_map);
  1034. vpage += PAGE_SIZE;
  1035. }
  1036. /* garbage collect */
  1037. scan = (sun4c_iobuffer_high - sun4c_iobuffer_start) >> PAGE_SHIFT;
  1038. while (scan >= 0 && !sun4c_iobuffer_map[scan >> 5])
  1039. scan -= 32;
  1040. scan += 32;
  1041. high = sun4c_iobuffer_start + (scan << PAGE_SHIFT);
  1042. high = SUN4C_REAL_PGDIR_ALIGN(high) + SUN4C_REAL_PGDIR_SIZE;
  1043. while (high < sun4c_iobuffer_high) {
  1044. sun4c_iobuffer_high -= SUN4C_REAL_PGDIR_SIZE;
  1045. free_locked_segment(sun4c_iobuffer_high);
  1046. }
  1047. local_irq_restore(flags);
  1048. }
  1049. /* Note the scsi code at init time passes to here buffers
  1050. * which sit on the kernel stack, those are already locked
  1051. * by implication and fool the page locking code above
  1052. * if passed to by mistake.
  1053. */
  1054. static __u32 sun4c_get_scsi_one(char *bufptr, unsigned long len, struct sbus_bus *sbus)
  1055. {
  1056. unsigned long page;
  1057. page = ((unsigned long)bufptr) & PAGE_MASK;
  1058. if (!virt_addr_valid(page)) {
  1059. sun4c_flush_page(page);
  1060. return (__u32)bufptr; /* already locked */
  1061. }
  1062. return (__u32)sun4c_lockarea(bufptr, len);
  1063. }
  1064. static void sun4c_get_scsi_sgl(struct scatterlist *sg, int sz, struct sbus_bus *sbus)
  1065. {
  1066. while (sz != 0) {
  1067. --sz;
  1068. sg[sz].dvma_address = (__u32)sun4c_lockarea(page_address(sg[sz].page) + sg[sz].offset, sg[sz].length);
  1069. sg[sz].dvma_length = sg[sz].length;
  1070. }
  1071. }
  1072. static void sun4c_release_scsi_one(__u32 bufptr, unsigned long len, struct sbus_bus *sbus)
  1073. {
  1074. if (bufptr < sun4c_iobuffer_start)
  1075. return; /* On kernel stack or similar, see above */
  1076. sun4c_unlockarea((char *)bufptr, len);
  1077. }
  1078. static void sun4c_release_scsi_sgl(struct scatterlist *sg, int sz, struct sbus_bus *sbus)
  1079. {
  1080. while (sz != 0) {
  1081. --sz;
  1082. sun4c_unlockarea((char *)sg[sz].dvma_address, sg[sz].length);
  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_pte_read(pte_t pte)
  1516. {
  1517. return (pte_val(pte) & _SUN4C_PAGE_READ);
  1518. }
  1519. static int sun4c_pmd_bad(pmd_t pmd)
  1520. {
  1521. return (((pmd_val(pmd) & ~PAGE_MASK) != PGD_TABLE) ||
  1522. (!virt_addr_valid(pmd_val(pmd))));
  1523. }
  1524. static int sun4c_pmd_present(pmd_t pmd)
  1525. {
  1526. return ((pmd_val(pmd) & PGD_PRESENT) != 0);
  1527. }
  1528. #if 0 /* if PMD takes one word */
  1529. static void sun4c_pmd_clear(pmd_t *pmdp) { *pmdp = __pmd(0); }
  1530. #else /* if pmd_t is a longish aggregate */
  1531. static void sun4c_pmd_clear(pmd_t *pmdp) {
  1532. memset((void *)pmdp, 0, sizeof(pmd_t));
  1533. }
  1534. #endif
  1535. static int sun4c_pgd_none(pgd_t pgd) { return 0; }
  1536. static int sun4c_pgd_bad(pgd_t pgd) { return 0; }
  1537. static int sun4c_pgd_present(pgd_t pgd) { return 1; }
  1538. static void sun4c_pgd_clear(pgd_t * pgdp) { }
  1539. /*
  1540. * The following only work if pte_present() is true.
  1541. * Undefined behaviour if not..
  1542. */
  1543. static pte_t sun4c_pte_mkwrite(pte_t pte)
  1544. {
  1545. pte = __pte(pte_val(pte) | _SUN4C_PAGE_WRITE);
  1546. if (pte_val(pte) & _SUN4C_PAGE_MODIFIED)
  1547. pte = __pte(pte_val(pte) | _SUN4C_PAGE_SILENT_WRITE);
  1548. return pte;
  1549. }
  1550. static pte_t sun4c_pte_mkdirty(pte_t pte)
  1551. {
  1552. pte = __pte(pte_val(pte) | _SUN4C_PAGE_MODIFIED);
  1553. if (pte_val(pte) & _SUN4C_PAGE_WRITE)
  1554. pte = __pte(pte_val(pte) | _SUN4C_PAGE_SILENT_WRITE);
  1555. return pte;
  1556. }
  1557. static pte_t sun4c_pte_mkyoung(pte_t pte)
  1558. {
  1559. pte = __pte(pte_val(pte) | _SUN4C_PAGE_ACCESSED);
  1560. if (pte_val(pte) & _SUN4C_PAGE_READ)
  1561. pte = __pte(pte_val(pte) | _SUN4C_PAGE_SILENT_READ);
  1562. return pte;
  1563. }
  1564. /*
  1565. * Conversion functions: convert a page and protection to a page entry,
  1566. * and a page entry and page directory to the page they refer to.
  1567. */
  1568. static pte_t sun4c_mk_pte(struct page *page, pgprot_t pgprot)
  1569. {
  1570. return __pte(page_to_pfn(page) | pgprot_val(pgprot));
  1571. }
  1572. static pte_t sun4c_mk_pte_phys(unsigned long phys_page, pgprot_t pgprot)
  1573. {
  1574. return __pte((phys_page >> PAGE_SHIFT) | pgprot_val(pgprot));
  1575. }
  1576. static pte_t sun4c_mk_pte_io(unsigned long page, pgprot_t pgprot, int space)
  1577. {
  1578. return __pte(((page - PAGE_OFFSET) >> PAGE_SHIFT) | pgprot_val(pgprot));
  1579. }
  1580. static unsigned long sun4c_pte_pfn(pte_t pte)
  1581. {
  1582. return pte_val(pte) & SUN4C_PFN_MASK;
  1583. }
  1584. static pte_t sun4c_pgoff_to_pte(unsigned long pgoff)
  1585. {
  1586. return __pte(pgoff | _SUN4C_PAGE_FILE);
  1587. }
  1588. static unsigned long sun4c_pte_to_pgoff(pte_t pte)
  1589. {
  1590. return pte_val(pte) & ((1UL << PTE_FILE_MAX_BITS) - 1);
  1591. }
  1592. static __inline__ unsigned long sun4c_pmd_page_v(pmd_t pmd)
  1593. {
  1594. return (pmd_val(pmd) & PAGE_MASK);
  1595. }
  1596. static struct page *sun4c_pmd_page(pmd_t pmd)
  1597. {
  1598. return virt_to_page(sun4c_pmd_page_v(pmd));
  1599. }
  1600. static unsigned long sun4c_pgd_page(pgd_t pgd) { return 0; }
  1601. /* to find an entry in a page-table-directory */
  1602. static inline pgd_t *sun4c_pgd_offset(struct mm_struct * mm, unsigned long address)
  1603. {
  1604. return mm->pgd + (address >> SUN4C_PGDIR_SHIFT);
  1605. }
  1606. /* Find an entry in the second-level page table.. */
  1607. static pmd_t *sun4c_pmd_offset(pgd_t * dir, unsigned long address)
  1608. {
  1609. return (pmd_t *) dir;
  1610. }
  1611. /* Find an entry in the third-level page table.. */
  1612. pte_t *sun4c_pte_offset_kernel(pmd_t * dir, unsigned long address)
  1613. {
  1614. return (pte_t *) sun4c_pmd_page_v(*dir) +
  1615. ((address >> PAGE_SHIFT) & (SUN4C_PTRS_PER_PTE - 1));
  1616. }
  1617. static unsigned long sun4c_swp_type(swp_entry_t entry)
  1618. {
  1619. return (entry.val & SUN4C_SWP_TYPE_MASK);
  1620. }
  1621. static unsigned long sun4c_swp_offset(swp_entry_t entry)
  1622. {
  1623. return (entry.val >> SUN4C_SWP_OFF_SHIFT) & SUN4C_SWP_OFF_MASK;
  1624. }
  1625. static swp_entry_t sun4c_swp_entry(unsigned long type, unsigned long offset)
  1626. {
  1627. return (swp_entry_t) {
  1628. (offset & SUN4C_SWP_OFF_MASK) << SUN4C_SWP_OFF_SHIFT
  1629. | (type & SUN4C_SWP_TYPE_MASK) };
  1630. }
  1631. static void sun4c_free_pte_slow(pte_t *pte)
  1632. {
  1633. free_page((unsigned long)pte);
  1634. }
  1635. static void sun4c_free_pgd_slow(pgd_t *pgd)
  1636. {
  1637. free_page((unsigned long)pgd);
  1638. }
  1639. static pgd_t *sun4c_get_pgd_fast(void)
  1640. {
  1641. unsigned long *ret;
  1642. if ((ret = pgd_quicklist) != NULL) {
  1643. pgd_quicklist = (unsigned long *)(*ret);
  1644. ret[0] = ret[1];
  1645. pgtable_cache_size--;
  1646. } else {
  1647. pgd_t *init;
  1648. ret = (unsigned long *)__get_free_page(GFP_KERNEL);
  1649. memset (ret, 0, (KERNBASE / SUN4C_PGDIR_SIZE) * sizeof(pgd_t));
  1650. init = sun4c_pgd_offset(&init_mm, 0);
  1651. memcpy (((pgd_t *)ret) + USER_PTRS_PER_PGD, init + USER_PTRS_PER_PGD,
  1652. (PTRS_PER_PGD - USER_PTRS_PER_PGD) * sizeof(pgd_t));
  1653. }
  1654. return (pgd_t *)ret;
  1655. }
  1656. static void sun4c_free_pgd_fast(pgd_t *pgd)
  1657. {
  1658. *(unsigned long *)pgd = (unsigned long) pgd_quicklist;
  1659. pgd_quicklist = (unsigned long *) pgd;
  1660. pgtable_cache_size++;
  1661. }
  1662. static __inline__ pte_t *
  1663. sun4c_pte_alloc_one_fast(struct mm_struct *mm, unsigned long address)
  1664. {
  1665. unsigned long *ret;
  1666. if ((ret = (unsigned long *)pte_quicklist) != NULL) {
  1667. pte_quicklist = (unsigned long *)(*ret);
  1668. ret[0] = ret[1];
  1669. pgtable_cache_size--;
  1670. }
  1671. return (pte_t *)ret;
  1672. }
  1673. static pte_t *sun4c_pte_alloc_one_kernel(struct mm_struct *mm, unsigned long address)
  1674. {
  1675. pte_t *pte;
  1676. if ((pte = sun4c_pte_alloc_one_fast(mm, address)) != NULL)
  1677. return pte;
  1678. pte = (pte_t *)__get_free_page(GFP_KERNEL|__GFP_REPEAT);
  1679. if (pte)
  1680. memset(pte, 0, PAGE_SIZE);
  1681. return pte;
  1682. }
  1683. static struct page *sun4c_pte_alloc_one(struct mm_struct *mm, unsigned long address)
  1684. {
  1685. pte_t *pte = sun4c_pte_alloc_one_kernel(mm, address);
  1686. if (pte == NULL)
  1687. return NULL;
  1688. return virt_to_page(pte);
  1689. }
  1690. static __inline__ void sun4c_free_pte_fast(pte_t *pte)
  1691. {
  1692. *(unsigned long *)pte = (unsigned long) pte_quicklist;
  1693. pte_quicklist = (unsigned long *) pte;
  1694. pgtable_cache_size++;
  1695. }
  1696. static void sun4c_pte_free(struct page *pte)
  1697. {
  1698. sun4c_free_pte_fast(page_address(pte));
  1699. }
  1700. /*
  1701. * allocating and freeing a pmd is trivial: the 1-entry pmd is
  1702. * inside the pgd, so has no extra memory associated with it.
  1703. */
  1704. static pmd_t *sun4c_pmd_alloc_one(struct mm_struct *mm, unsigned long address)
  1705. {
  1706. BUG();
  1707. return NULL;
  1708. }
  1709. static void sun4c_free_pmd_fast(pmd_t * pmd) { }
  1710. static void sun4c_check_pgt_cache(int low, int high)
  1711. {
  1712. if (pgtable_cache_size > high) {
  1713. do {
  1714. if (pgd_quicklist)
  1715. sun4c_free_pgd_slow(sun4c_get_pgd_fast());
  1716. if (pte_quicklist)
  1717. sun4c_free_pte_slow(sun4c_pte_alloc_one_fast(NULL, 0));
  1718. } while (pgtable_cache_size > low);
  1719. }
  1720. }
  1721. /* An experiment, turn off by default for now... -DaveM */
  1722. #define SUN4C_PRELOAD_PSEG
  1723. void sun4c_update_mmu_cache(struct vm_area_struct *vma, unsigned long address, pte_t pte)
  1724. {
  1725. unsigned long flags;
  1726. int pseg;
  1727. local_irq_save(flags);
  1728. address &= PAGE_MASK;
  1729. if ((pseg = sun4c_get_segmap(address)) == invalid_segment) {
  1730. struct sun4c_mmu_entry *entry = sun4c_user_strategy();
  1731. struct mm_struct *mm = vma->vm_mm;
  1732. unsigned long start, end;
  1733. entry->vaddr = start = (address & SUN4C_REAL_PGDIR_MASK);
  1734. entry->ctx = mm->context;
  1735. add_ring_ordered(sun4c_context_ring + mm->context, entry);
  1736. sun4c_put_segmap(entry->vaddr, entry->pseg);
  1737. end = start + SUN4C_REAL_PGDIR_SIZE;
  1738. while (start < end) {
  1739. #ifdef SUN4C_PRELOAD_PSEG
  1740. pgd_t *pgdp = sun4c_pgd_offset(mm, start);
  1741. pte_t *ptep;
  1742. if (!pgdp)
  1743. goto no_mapping;
  1744. ptep = sun4c_pte_offset_kernel((pmd_t *) pgdp, start);
  1745. if (!ptep || !(pte_val(*ptep) & _SUN4C_PAGE_PRESENT))
  1746. goto no_mapping;
  1747. sun4c_put_pte(start, pte_val(*ptep));
  1748. goto next;
  1749. no_mapping:
  1750. #endif
  1751. sun4c_put_pte(start, 0);
  1752. #ifdef SUN4C_PRELOAD_PSEG
  1753. next:
  1754. #endif
  1755. start += PAGE_SIZE;
  1756. }
  1757. #ifndef SUN4C_PRELOAD_PSEG
  1758. sun4c_put_pte(address, pte_val(pte));
  1759. #endif
  1760. local_irq_restore(flags);
  1761. return;
  1762. } else {
  1763. struct sun4c_mmu_entry *entry = &mmu_entry_pool[pseg];
  1764. remove_lru(entry);
  1765. add_lru(entry);
  1766. }
  1767. sun4c_put_pte(address, pte_val(pte));
  1768. local_irq_restore(flags);
  1769. }
  1770. extern void sparc_context_init(int);
  1771. extern unsigned long end;
  1772. extern unsigned long bootmem_init(unsigned long *pages_avail);
  1773. extern unsigned long last_valid_pfn;
  1774. void __init sun4c_paging_init(void)
  1775. {
  1776. int i, cnt;
  1777. unsigned long kernel_end, vaddr;
  1778. extern struct resource sparc_iomap;
  1779. unsigned long end_pfn, pages_avail;
  1780. kernel_end = (unsigned long) &end;
  1781. kernel_end += (SUN4C_REAL_PGDIR_SIZE * 4);
  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, &contig_page_data, zones_size,
  1828. pfn_base, zholes_size);
  1829. }
  1830. cnt = 0;
  1831. for (i = 0; i < num_segmaps; i++)
  1832. if (mmu_entry_pool[i].locked)
  1833. cnt++;
  1834. max_user_taken_entries = num_segmaps - cnt - 40 - 1;
  1835. printk("SUN4C: %d mmu entries for the kernel\n", cnt);
  1836. }
  1837. static pgprot_t sun4c_pgprot_noncached(pgprot_t prot)
  1838. {
  1839. prot |= __pgprot(_SUN4C_PAGE_IO | _SUN4C_PAGE_NOCACHE);
  1840. return prot;
  1841. }
  1842. /* Load up routines and constants for sun4c mmu */
  1843. void __init ld_mmu_sun4c(void)
  1844. {
  1845. extern void ___xchg32_sun4c(void);
  1846. printk("Loading sun4c MMU routines\n");
  1847. /* First the constants */
  1848. BTFIXUPSET_SIMM13(pgdir_shift, SUN4C_PGDIR_SHIFT);
  1849. BTFIXUPSET_SETHI(pgdir_size, SUN4C_PGDIR_SIZE);
  1850. BTFIXUPSET_SETHI(pgdir_mask, SUN4C_PGDIR_MASK);
  1851. BTFIXUPSET_SIMM13(ptrs_per_pmd, SUN4C_PTRS_PER_PMD);
  1852. BTFIXUPSET_SIMM13(ptrs_per_pgd, SUN4C_PTRS_PER_PGD);
  1853. BTFIXUPSET_SIMM13(user_ptrs_per_pgd, KERNBASE / SUN4C_PGDIR_SIZE);
  1854. BTFIXUPSET_INT(page_none, pgprot_val(SUN4C_PAGE_NONE));
  1855. BTFIXUPSET_INT(page_shared, pgprot_val(SUN4C_PAGE_SHARED));
  1856. BTFIXUPSET_INT(page_copy, pgprot_val(SUN4C_PAGE_COPY));
  1857. BTFIXUPSET_INT(page_readonly, pgprot_val(SUN4C_PAGE_READONLY));
  1858. BTFIXUPSET_INT(page_kernel, pgprot_val(SUN4C_PAGE_KERNEL));
  1859. page_kernel = pgprot_val(SUN4C_PAGE_KERNEL);
  1860. /* Functions */
  1861. BTFIXUPSET_CALL(pgprot_noncached, sun4c_pgprot_noncached, BTFIXUPCALL_NORM);
  1862. BTFIXUPSET_CALL(___xchg32, ___xchg32_sun4c, BTFIXUPCALL_NORM);
  1863. BTFIXUPSET_CALL(do_check_pgt_cache, sun4c_check_pgt_cache, BTFIXUPCALL_NORM);
  1864. BTFIXUPSET_CALL(flush_cache_all, sun4c_flush_cache_all, BTFIXUPCALL_NORM);
  1865. if (sun4c_vacinfo.do_hwflushes) {
  1866. BTFIXUPSET_CALL(sun4c_flush_page, sun4c_flush_page_hw, BTFIXUPCALL_NORM);
  1867. BTFIXUPSET_CALL(sun4c_flush_segment, sun4c_flush_segment_hw, BTFIXUPCALL_NORM);
  1868. BTFIXUPSET_CALL(sun4c_flush_context, sun4c_flush_context_hw, BTFIXUPCALL_NORM);
  1869. } else {
  1870. BTFIXUPSET_CALL(sun4c_flush_page, sun4c_flush_page_sw, BTFIXUPCALL_NORM);
  1871. BTFIXUPSET_CALL(sun4c_flush_segment, sun4c_flush_segment_sw, BTFIXUPCALL_NORM);
  1872. BTFIXUPSET_CALL(sun4c_flush_context, sun4c_flush_context_sw, BTFIXUPCALL_NORM);
  1873. }
  1874. BTFIXUPSET_CALL(flush_tlb_mm, sun4c_flush_tlb_mm, BTFIXUPCALL_NORM);
  1875. BTFIXUPSET_CALL(flush_cache_mm, sun4c_flush_cache_mm, BTFIXUPCALL_NORM);
  1876. BTFIXUPSET_CALL(destroy_context, sun4c_destroy_context, BTFIXUPCALL_NORM);
  1877. BTFIXUPSET_CALL(switch_mm, sun4c_switch_mm, BTFIXUPCALL_NORM);
  1878. BTFIXUPSET_CALL(flush_cache_page, sun4c_flush_cache_page, BTFIXUPCALL_NORM);
  1879. BTFIXUPSET_CALL(flush_tlb_page, sun4c_flush_tlb_page, BTFIXUPCALL_NORM);
  1880. BTFIXUPSET_CALL(flush_tlb_range, sun4c_flush_tlb_range, BTFIXUPCALL_NORM);
  1881. BTFIXUPSET_CALL(flush_cache_range, sun4c_flush_cache_range, BTFIXUPCALL_NORM);
  1882. BTFIXUPSET_CALL(__flush_page_to_ram, sun4c_flush_page_to_ram, BTFIXUPCALL_NORM);
  1883. BTFIXUPSET_CALL(flush_tlb_all, sun4c_flush_tlb_all, BTFIXUPCALL_NORM);
  1884. BTFIXUPSET_CALL(flush_sig_insns, sun4c_flush_sig_insns, BTFIXUPCALL_NOP);
  1885. BTFIXUPSET_CALL(set_pte, sun4c_set_pte, BTFIXUPCALL_STO1O0);
  1886. /* The 2.4.18 code does not set this on sun4c, how does it work? XXX */
  1887. /* BTFIXUPSET_SETHI(none_mask, 0x00000000); */ /* Defaults to zero? */
  1888. BTFIXUPSET_CALL(pte_pfn, sun4c_pte_pfn, BTFIXUPCALL_NORM);
  1889. #if 0 /* PAGE_SHIFT <= 12 */ /* Eek. Investigate. XXX */
  1890. BTFIXUPSET_CALL(pmd_page, sun4c_pmd_page, BTFIXUPCALL_ANDNINT(PAGE_SIZE - 1));
  1891. #else
  1892. BTFIXUPSET_CALL(pmd_page, sun4c_pmd_page, BTFIXUPCALL_NORM);
  1893. #endif
  1894. BTFIXUPSET_CALL(pmd_set, sun4c_pmd_set, BTFIXUPCALL_NORM);
  1895. BTFIXUPSET_CALL(pmd_populate, sun4c_pmd_populate, BTFIXUPCALL_NORM);
  1896. BTFIXUPSET_CALL(pte_present, sun4c_pte_present, BTFIXUPCALL_NORM);
  1897. BTFIXUPSET_CALL(pte_clear, sun4c_pte_clear, BTFIXUPCALL_STG0O0);
  1898. BTFIXUPSET_CALL(pte_read, sun4c_pte_read, BTFIXUPCALL_NORM);
  1899. BTFIXUPSET_CALL(pmd_bad, sun4c_pmd_bad, BTFIXUPCALL_NORM);
  1900. BTFIXUPSET_CALL(pmd_present, sun4c_pmd_present, BTFIXUPCALL_NORM);
  1901. BTFIXUPSET_CALL(pmd_clear, sun4c_pmd_clear, BTFIXUPCALL_STG0O0);
  1902. BTFIXUPSET_CALL(pgd_none, sun4c_pgd_none, BTFIXUPCALL_RETINT(0));
  1903. BTFIXUPSET_CALL(pgd_bad, sun4c_pgd_bad, BTFIXUPCALL_RETINT(0));
  1904. BTFIXUPSET_CALL(pgd_present, sun4c_pgd_present, BTFIXUPCALL_RETINT(1));
  1905. BTFIXUPSET_CALL(pgd_clear, sun4c_pgd_clear, BTFIXUPCALL_NOP);
  1906. BTFIXUPSET_CALL(mk_pte, sun4c_mk_pte, BTFIXUPCALL_NORM);
  1907. BTFIXUPSET_CALL(mk_pte_phys, sun4c_mk_pte_phys, BTFIXUPCALL_NORM);
  1908. BTFIXUPSET_CALL(mk_pte_io, sun4c_mk_pte_io, BTFIXUPCALL_NORM);
  1909. BTFIXUPSET_INT(pte_modify_mask, _SUN4C_PAGE_CHG_MASK);
  1910. BTFIXUPSET_CALL(pmd_offset, sun4c_pmd_offset, BTFIXUPCALL_NORM);
  1911. BTFIXUPSET_CALL(pte_offset_kernel, sun4c_pte_offset_kernel, BTFIXUPCALL_NORM);
  1912. BTFIXUPSET_CALL(free_pte_fast, sun4c_free_pte_fast, BTFIXUPCALL_NORM);
  1913. BTFIXUPSET_CALL(pte_free, sun4c_pte_free, BTFIXUPCALL_NORM);
  1914. BTFIXUPSET_CALL(pte_alloc_one_kernel, sun4c_pte_alloc_one_kernel, BTFIXUPCALL_NORM);
  1915. BTFIXUPSET_CALL(pte_alloc_one, sun4c_pte_alloc_one, BTFIXUPCALL_NORM);
  1916. BTFIXUPSET_CALL(free_pmd_fast, sun4c_free_pmd_fast, BTFIXUPCALL_NOP);
  1917. BTFIXUPSET_CALL(pmd_alloc_one, sun4c_pmd_alloc_one, BTFIXUPCALL_RETO0);
  1918. BTFIXUPSET_CALL(free_pgd_fast, sun4c_free_pgd_fast, BTFIXUPCALL_NORM);
  1919. BTFIXUPSET_CALL(get_pgd_fast, sun4c_get_pgd_fast, BTFIXUPCALL_NORM);
  1920. BTFIXUPSET_HALF(pte_writei, _SUN4C_PAGE_WRITE);
  1921. BTFIXUPSET_HALF(pte_dirtyi, _SUN4C_PAGE_MODIFIED);
  1922. BTFIXUPSET_HALF(pte_youngi, _SUN4C_PAGE_ACCESSED);
  1923. BTFIXUPSET_HALF(pte_filei, _SUN4C_PAGE_FILE);
  1924. BTFIXUPSET_HALF(pte_wrprotecti, _SUN4C_PAGE_WRITE|_SUN4C_PAGE_SILENT_WRITE);
  1925. BTFIXUPSET_HALF(pte_mkcleani, _SUN4C_PAGE_MODIFIED|_SUN4C_PAGE_SILENT_WRITE);
  1926. BTFIXUPSET_HALF(pte_mkoldi, _SUN4C_PAGE_ACCESSED|_SUN4C_PAGE_SILENT_READ);
  1927. BTFIXUPSET_CALL(pte_mkwrite, sun4c_pte_mkwrite, BTFIXUPCALL_NORM);
  1928. BTFIXUPSET_CALL(pte_mkdirty, sun4c_pte_mkdirty, BTFIXUPCALL_NORM);
  1929. BTFIXUPSET_CALL(pte_mkyoung, sun4c_pte_mkyoung, BTFIXUPCALL_NORM);
  1930. BTFIXUPSET_CALL(update_mmu_cache, sun4c_update_mmu_cache, BTFIXUPCALL_NORM);
  1931. BTFIXUPSET_CALL(pte_to_pgoff, sun4c_pte_to_pgoff, BTFIXUPCALL_NORM);
  1932. BTFIXUPSET_CALL(pgoff_to_pte, sun4c_pgoff_to_pte, BTFIXUPCALL_NORM);
  1933. BTFIXUPSET_CALL(mmu_lockarea, sun4c_lockarea, BTFIXUPCALL_NORM);
  1934. BTFIXUPSET_CALL(mmu_unlockarea, sun4c_unlockarea, BTFIXUPCALL_NORM);
  1935. BTFIXUPSET_CALL(mmu_get_scsi_one, sun4c_get_scsi_one, BTFIXUPCALL_NORM);
  1936. BTFIXUPSET_CALL(mmu_get_scsi_sgl, sun4c_get_scsi_sgl, BTFIXUPCALL_NORM);
  1937. BTFIXUPSET_CALL(mmu_release_scsi_one, sun4c_release_scsi_one, BTFIXUPCALL_NORM);
  1938. BTFIXUPSET_CALL(mmu_release_scsi_sgl, sun4c_release_scsi_sgl, BTFIXUPCALL_NORM);
  1939. BTFIXUPSET_CALL(mmu_map_dma_area, sun4c_map_dma_area, BTFIXUPCALL_NORM);
  1940. BTFIXUPSET_CALL(mmu_unmap_dma_area, sun4c_unmap_dma_area, BTFIXUPCALL_NORM);
  1941. BTFIXUPSET_CALL(mmu_translate_dvma, sun4c_translate_dvma, BTFIXUPCALL_NORM);
  1942. BTFIXUPSET_CALL(sparc_mapiorange, sun4c_mapiorange, BTFIXUPCALL_NORM);
  1943. BTFIXUPSET_CALL(sparc_unmapiorange, sun4c_unmapiorange, BTFIXUPCALL_NORM);
  1944. BTFIXUPSET_CALL(__swp_type, sun4c_swp_type, BTFIXUPCALL_NORM);
  1945. BTFIXUPSET_CALL(__swp_offset, sun4c_swp_offset, BTFIXUPCALL_NORM);
  1946. BTFIXUPSET_CALL(__swp_entry, sun4c_swp_entry, BTFIXUPCALL_NORM);
  1947. BTFIXUPSET_CALL(alloc_thread_info, sun4c_alloc_thread_info, BTFIXUPCALL_NORM);
  1948. BTFIXUPSET_CALL(free_thread_info, sun4c_free_thread_info, BTFIXUPCALL_NORM);
  1949. BTFIXUPSET_CALL(mmu_info, sun4c_mmu_info, BTFIXUPCALL_NORM);
  1950. /* These should _never_ get called with two level tables. */
  1951. BTFIXUPSET_CALL(pgd_set, sun4c_pgd_set, BTFIXUPCALL_NOP);
  1952. BTFIXUPSET_CALL(pgd_page_vaddr, sun4c_pgd_page, BTFIXUPCALL_RETO0);
  1953. }