sun4c.c 62 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275
  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(struct device *dev, 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 void sun4c_unmap_dma_area(struct device *dev, unsigned long busa, int len)
  497. {
  498. /* Fortunately for us, bus_addr == uncached_virt in sun4c. */
  499. /* XXX Implement this */
  500. }
  501. /* TLB management. */
  502. /* Don't change this struct without changing entry.S. This is used
  503. * in the in-window kernel fault handler, and you don't want to mess
  504. * with that. (See sun4c_fault in entry.S).
  505. */
  506. struct sun4c_mmu_entry {
  507. struct sun4c_mmu_entry *next;
  508. struct sun4c_mmu_entry *prev;
  509. unsigned long vaddr;
  510. unsigned char pseg;
  511. unsigned char locked;
  512. /* For user mappings only, and completely hidden from kernel
  513. * TLB miss code.
  514. */
  515. unsigned char ctx;
  516. struct sun4c_mmu_entry *lru_next;
  517. struct sun4c_mmu_entry *lru_prev;
  518. };
  519. static struct sun4c_mmu_entry mmu_entry_pool[SUN4C_MAX_SEGMAPS];
  520. static void __init sun4c_init_mmu_entry_pool(void)
  521. {
  522. int i;
  523. for (i=0; i < SUN4C_MAX_SEGMAPS; i++) {
  524. mmu_entry_pool[i].pseg = i;
  525. mmu_entry_pool[i].next = NULL;
  526. mmu_entry_pool[i].prev = NULL;
  527. mmu_entry_pool[i].vaddr = 0;
  528. mmu_entry_pool[i].locked = 0;
  529. mmu_entry_pool[i].ctx = 0;
  530. mmu_entry_pool[i].lru_next = NULL;
  531. mmu_entry_pool[i].lru_prev = NULL;
  532. }
  533. mmu_entry_pool[invalid_segment].locked = 1;
  534. }
  535. static inline void fix_permissions(unsigned long vaddr, unsigned long bits_on,
  536. unsigned long bits_off)
  537. {
  538. unsigned long start, end;
  539. end = vaddr + SUN4C_REAL_PGDIR_SIZE;
  540. for (start = vaddr; start < end; start += PAGE_SIZE)
  541. if (sun4c_get_pte(start) & _SUN4C_PAGE_VALID)
  542. sun4c_put_pte(start, (sun4c_get_pte(start) | bits_on) &
  543. ~bits_off);
  544. }
  545. static inline void sun4c_init_map_kernelprom(unsigned long kernel_end)
  546. {
  547. unsigned long vaddr;
  548. unsigned char pseg, ctx;
  549. #ifdef CONFIG_SUN4
  550. /* sun4/110 and 260 have no kadb. */
  551. if ((idprom->id_machtype != (SM_SUN4 | SM_4_260)) &&
  552. (idprom->id_machtype != (SM_SUN4 | SM_4_110))) {
  553. #endif
  554. for (vaddr = KADB_DEBUGGER_BEGVM;
  555. vaddr < LINUX_OPPROM_ENDVM;
  556. vaddr += SUN4C_REAL_PGDIR_SIZE) {
  557. pseg = sun4c_get_segmap(vaddr);
  558. if (pseg != invalid_segment) {
  559. mmu_entry_pool[pseg].locked = 1;
  560. for (ctx = 0; ctx < num_contexts; ctx++)
  561. prom_putsegment(ctx, vaddr, pseg);
  562. fix_permissions(vaddr, _SUN4C_PAGE_PRIV, 0);
  563. }
  564. }
  565. #ifdef CONFIG_SUN4
  566. }
  567. #endif
  568. for (vaddr = KERNBASE; vaddr < kernel_end; vaddr += SUN4C_REAL_PGDIR_SIZE) {
  569. pseg = sun4c_get_segmap(vaddr);
  570. mmu_entry_pool[pseg].locked = 1;
  571. for (ctx = 0; ctx < num_contexts; ctx++)
  572. prom_putsegment(ctx, vaddr, pseg);
  573. fix_permissions(vaddr, _SUN4C_PAGE_PRIV, _SUN4C_PAGE_NOCACHE);
  574. }
  575. }
  576. static void __init sun4c_init_lock_area(unsigned long start, unsigned long end)
  577. {
  578. int i, ctx;
  579. while (start < end) {
  580. for (i = 0; i < invalid_segment; i++)
  581. if (!mmu_entry_pool[i].locked)
  582. break;
  583. mmu_entry_pool[i].locked = 1;
  584. sun4c_init_clean_segmap(i);
  585. for (ctx = 0; ctx < num_contexts; ctx++)
  586. prom_putsegment(ctx, start, mmu_entry_pool[i].pseg);
  587. start += SUN4C_REAL_PGDIR_SIZE;
  588. }
  589. }
  590. /* Don't change this struct without changing entry.S. This is used
  591. * in the in-window kernel fault handler, and you don't want to mess
  592. * with that. (See sun4c_fault in entry.S).
  593. */
  594. struct sun4c_mmu_ring {
  595. struct sun4c_mmu_entry ringhd;
  596. int num_entries;
  597. };
  598. static struct sun4c_mmu_ring sun4c_context_ring[SUN4C_MAX_CONTEXTS]; /* used user entries */
  599. static struct sun4c_mmu_ring sun4c_ufree_ring; /* free user entries */
  600. static struct sun4c_mmu_ring sun4c_ulru_ring; /* LRU user entries */
  601. struct sun4c_mmu_ring sun4c_kernel_ring; /* used kernel entries */
  602. struct sun4c_mmu_ring sun4c_kfree_ring; /* free kernel entries */
  603. static inline void sun4c_init_rings(void)
  604. {
  605. int i;
  606. for (i = 0; i < SUN4C_MAX_CONTEXTS; i++) {
  607. sun4c_context_ring[i].ringhd.next =
  608. sun4c_context_ring[i].ringhd.prev =
  609. &sun4c_context_ring[i].ringhd;
  610. sun4c_context_ring[i].num_entries = 0;
  611. }
  612. sun4c_ufree_ring.ringhd.next = sun4c_ufree_ring.ringhd.prev =
  613. &sun4c_ufree_ring.ringhd;
  614. sun4c_ufree_ring.num_entries = 0;
  615. sun4c_ulru_ring.ringhd.lru_next = sun4c_ulru_ring.ringhd.lru_prev =
  616. &sun4c_ulru_ring.ringhd;
  617. sun4c_ulru_ring.num_entries = 0;
  618. sun4c_kernel_ring.ringhd.next = sun4c_kernel_ring.ringhd.prev =
  619. &sun4c_kernel_ring.ringhd;
  620. sun4c_kernel_ring.num_entries = 0;
  621. sun4c_kfree_ring.ringhd.next = sun4c_kfree_ring.ringhd.prev =
  622. &sun4c_kfree_ring.ringhd;
  623. sun4c_kfree_ring.num_entries = 0;
  624. }
  625. static void add_ring(struct sun4c_mmu_ring *ring,
  626. struct sun4c_mmu_entry *entry)
  627. {
  628. struct sun4c_mmu_entry *head = &ring->ringhd;
  629. entry->prev = head;
  630. (entry->next = head->next)->prev = entry;
  631. head->next = entry;
  632. ring->num_entries++;
  633. }
  634. static inline void add_lru(struct sun4c_mmu_entry *entry)
  635. {
  636. struct sun4c_mmu_ring *ring = &sun4c_ulru_ring;
  637. struct sun4c_mmu_entry *head = &ring->ringhd;
  638. entry->lru_next = head;
  639. (entry->lru_prev = head->lru_prev)->lru_next = entry;
  640. head->lru_prev = entry;
  641. }
  642. static void add_ring_ordered(struct sun4c_mmu_ring *ring,
  643. struct sun4c_mmu_entry *entry)
  644. {
  645. struct sun4c_mmu_entry *head = &ring->ringhd;
  646. unsigned long addr = entry->vaddr;
  647. while ((head->next != &ring->ringhd) && (head->next->vaddr < addr))
  648. head = head->next;
  649. entry->prev = head;
  650. (entry->next = head->next)->prev = entry;
  651. head->next = entry;
  652. ring->num_entries++;
  653. add_lru(entry);
  654. }
  655. static inline void remove_ring(struct sun4c_mmu_ring *ring,
  656. struct sun4c_mmu_entry *entry)
  657. {
  658. struct sun4c_mmu_entry *next = entry->next;
  659. (next->prev = entry->prev)->next = next;
  660. ring->num_entries--;
  661. }
  662. static void remove_lru(struct sun4c_mmu_entry *entry)
  663. {
  664. struct sun4c_mmu_entry *next = entry->lru_next;
  665. (next->lru_prev = entry->lru_prev)->lru_next = next;
  666. }
  667. static void free_user_entry(int ctx, struct sun4c_mmu_entry *entry)
  668. {
  669. remove_ring(sun4c_context_ring+ctx, entry);
  670. remove_lru(entry);
  671. add_ring(&sun4c_ufree_ring, entry);
  672. }
  673. static void free_kernel_entry(struct sun4c_mmu_entry *entry,
  674. struct sun4c_mmu_ring *ring)
  675. {
  676. remove_ring(ring, entry);
  677. add_ring(&sun4c_kfree_ring, entry);
  678. }
  679. static void __init sun4c_init_fill_kernel_ring(int howmany)
  680. {
  681. int i;
  682. while (howmany) {
  683. for (i = 0; i < invalid_segment; i++)
  684. if (!mmu_entry_pool[i].locked)
  685. break;
  686. mmu_entry_pool[i].locked = 1;
  687. sun4c_init_clean_segmap(i);
  688. add_ring(&sun4c_kfree_ring, &mmu_entry_pool[i]);
  689. howmany--;
  690. }
  691. }
  692. static void __init sun4c_init_fill_user_ring(void)
  693. {
  694. int i;
  695. for (i = 0; i < invalid_segment; i++) {
  696. if (mmu_entry_pool[i].locked)
  697. continue;
  698. sun4c_init_clean_segmap(i);
  699. add_ring(&sun4c_ufree_ring, &mmu_entry_pool[i]);
  700. }
  701. }
  702. static void sun4c_kernel_unmap(struct sun4c_mmu_entry *kentry)
  703. {
  704. int savectx, ctx;
  705. savectx = sun4c_get_context();
  706. for (ctx = 0; ctx < num_contexts; ctx++) {
  707. sun4c_set_context(ctx);
  708. sun4c_put_segmap(kentry->vaddr, invalid_segment);
  709. }
  710. sun4c_set_context(savectx);
  711. }
  712. static void sun4c_kernel_map(struct sun4c_mmu_entry *kentry)
  713. {
  714. int savectx, ctx;
  715. savectx = sun4c_get_context();
  716. for (ctx = 0; ctx < num_contexts; ctx++) {
  717. sun4c_set_context(ctx);
  718. sun4c_put_segmap(kentry->vaddr, kentry->pseg);
  719. }
  720. sun4c_set_context(savectx);
  721. }
  722. #define sun4c_user_unmap(__entry) \
  723. sun4c_put_segmap((__entry)->vaddr, invalid_segment)
  724. static void sun4c_demap_context(struct sun4c_mmu_ring *crp, unsigned char ctx)
  725. {
  726. struct sun4c_mmu_entry *head = &crp->ringhd;
  727. unsigned long flags;
  728. local_irq_save(flags);
  729. if (head->next != head) {
  730. struct sun4c_mmu_entry *entry = head->next;
  731. int savectx = sun4c_get_context();
  732. flush_user_windows();
  733. sun4c_set_context(ctx);
  734. sun4c_flush_context();
  735. do {
  736. struct sun4c_mmu_entry *next = entry->next;
  737. sun4c_user_unmap(entry);
  738. free_user_entry(ctx, entry);
  739. entry = next;
  740. } while (entry != head);
  741. sun4c_set_context(savectx);
  742. }
  743. local_irq_restore(flags);
  744. }
  745. static int sun4c_user_taken_entries; /* This is how much we have. */
  746. static int max_user_taken_entries; /* This limits us and prevents deadlock. */
  747. static struct sun4c_mmu_entry *sun4c_kernel_strategy(void)
  748. {
  749. struct sun4c_mmu_entry *this_entry;
  750. /* If some are free, return first one. */
  751. if (sun4c_kfree_ring.num_entries) {
  752. this_entry = sun4c_kfree_ring.ringhd.next;
  753. return this_entry;
  754. }
  755. /* Else free one up. */
  756. this_entry = sun4c_kernel_ring.ringhd.prev;
  757. sun4c_flush_segment(this_entry->vaddr);
  758. sun4c_kernel_unmap(this_entry);
  759. free_kernel_entry(this_entry, &sun4c_kernel_ring);
  760. this_entry = sun4c_kfree_ring.ringhd.next;
  761. return this_entry;
  762. }
  763. /* Using this method to free up mmu entries eliminates a lot of
  764. * potential races since we have a kernel that incurs tlb
  765. * replacement faults. There may be performance penalties.
  766. *
  767. * NOTE: Must be called with interrupts disabled.
  768. */
  769. static struct sun4c_mmu_entry *sun4c_user_strategy(void)
  770. {
  771. struct sun4c_mmu_entry *entry;
  772. unsigned char ctx;
  773. int savectx;
  774. /* If some are free, return first one. */
  775. if (sun4c_ufree_ring.num_entries) {
  776. entry = sun4c_ufree_ring.ringhd.next;
  777. goto unlink_out;
  778. }
  779. if (sun4c_user_taken_entries) {
  780. entry = sun4c_kernel_strategy();
  781. sun4c_user_taken_entries--;
  782. goto kunlink_out;
  783. }
  784. /* Grab from the beginning of the LRU list. */
  785. entry = sun4c_ulru_ring.ringhd.lru_next;
  786. ctx = entry->ctx;
  787. savectx = sun4c_get_context();
  788. flush_user_windows();
  789. sun4c_set_context(ctx);
  790. sun4c_flush_segment(entry->vaddr);
  791. sun4c_user_unmap(entry);
  792. remove_ring(sun4c_context_ring + ctx, entry);
  793. remove_lru(entry);
  794. sun4c_set_context(savectx);
  795. return entry;
  796. unlink_out:
  797. remove_ring(&sun4c_ufree_ring, entry);
  798. return entry;
  799. kunlink_out:
  800. remove_ring(&sun4c_kfree_ring, entry);
  801. return entry;
  802. }
  803. /* NOTE: Must be called with interrupts disabled. */
  804. void sun4c_grow_kernel_ring(void)
  805. {
  806. struct sun4c_mmu_entry *entry;
  807. /* Prevent deadlock condition. */
  808. if (sun4c_user_taken_entries >= max_user_taken_entries)
  809. return;
  810. if (sun4c_ufree_ring.num_entries) {
  811. entry = sun4c_ufree_ring.ringhd.next;
  812. remove_ring(&sun4c_ufree_ring, entry);
  813. add_ring(&sun4c_kfree_ring, entry);
  814. sun4c_user_taken_entries++;
  815. }
  816. }
  817. /* 2 page buckets for task struct and kernel stack allocation.
  818. *
  819. * TASK_STACK_BEGIN
  820. * bucket[0]
  821. * bucket[1]
  822. * [ ... ]
  823. * bucket[NR_TASK_BUCKETS-1]
  824. * TASK_STACK_BEGIN + (sizeof(struct task_bucket) * NR_TASK_BUCKETS)
  825. *
  826. * Each slot looks like:
  827. *
  828. * page 1 -- task struct + beginning of kernel stack
  829. * page 2 -- rest of kernel stack
  830. */
  831. union task_union *sun4c_bucket[NR_TASK_BUCKETS];
  832. static int sun4c_lowbucket_avail;
  833. #define BUCKET_EMPTY ((union task_union *) 0)
  834. #define BUCKET_SHIFT (PAGE_SHIFT + 1) /* log2(sizeof(struct task_bucket)) */
  835. #define BUCKET_SIZE (1 << BUCKET_SHIFT)
  836. #define BUCKET_NUM(addr) ((((addr) - SUN4C_LOCK_VADDR) >> BUCKET_SHIFT))
  837. #define BUCKET_ADDR(num) (((num) << BUCKET_SHIFT) + SUN4C_LOCK_VADDR)
  838. #define BUCKET_PTE(page) \
  839. ((((page) - PAGE_OFFSET) >> PAGE_SHIFT) | pgprot_val(SUN4C_PAGE_KERNEL))
  840. #define BUCKET_PTE_PAGE(pte) \
  841. (PAGE_OFFSET + (((pte) & SUN4C_PFN_MASK) << PAGE_SHIFT))
  842. static void get_locked_segment(unsigned long addr)
  843. {
  844. struct sun4c_mmu_entry *stolen;
  845. unsigned long flags;
  846. local_irq_save(flags);
  847. addr &= SUN4C_REAL_PGDIR_MASK;
  848. stolen = sun4c_user_strategy();
  849. max_user_taken_entries--;
  850. stolen->vaddr = addr;
  851. flush_user_windows();
  852. sun4c_kernel_map(stolen);
  853. local_irq_restore(flags);
  854. }
  855. static void free_locked_segment(unsigned long addr)
  856. {
  857. struct sun4c_mmu_entry *entry;
  858. unsigned long flags;
  859. unsigned char pseg;
  860. local_irq_save(flags);
  861. addr &= SUN4C_REAL_PGDIR_MASK;
  862. pseg = sun4c_get_segmap(addr);
  863. entry = &mmu_entry_pool[pseg];
  864. flush_user_windows();
  865. sun4c_flush_segment(addr);
  866. sun4c_kernel_unmap(entry);
  867. add_ring(&sun4c_ufree_ring, entry);
  868. max_user_taken_entries++;
  869. local_irq_restore(flags);
  870. }
  871. static inline void garbage_collect(int entry)
  872. {
  873. int start, end;
  874. /* 32 buckets per segment... */
  875. entry &= ~31;
  876. start = entry;
  877. for (end = (start + 32); start < end; start++)
  878. if (sun4c_bucket[start] != BUCKET_EMPTY)
  879. return;
  880. /* Entire segment empty, release it. */
  881. free_locked_segment(BUCKET_ADDR(entry));
  882. }
  883. static struct thread_info *sun4c_alloc_thread_info(void)
  884. {
  885. unsigned long addr, pages;
  886. int entry;
  887. pages = __get_free_pages(GFP_KERNEL, THREAD_INFO_ORDER);
  888. if (!pages)
  889. return NULL;
  890. for (entry = sun4c_lowbucket_avail; entry < NR_TASK_BUCKETS; entry++)
  891. if (sun4c_bucket[entry] == BUCKET_EMPTY)
  892. break;
  893. if (entry == NR_TASK_BUCKETS) {
  894. free_pages(pages, THREAD_INFO_ORDER);
  895. return NULL;
  896. }
  897. if (entry >= sun4c_lowbucket_avail)
  898. sun4c_lowbucket_avail = entry + 1;
  899. addr = BUCKET_ADDR(entry);
  900. sun4c_bucket[entry] = (union task_union *) addr;
  901. if(sun4c_get_segmap(addr) == invalid_segment)
  902. get_locked_segment(addr);
  903. /* We are changing the virtual color of the page(s)
  904. * so we must flush the cache to guarantee consistency.
  905. */
  906. sun4c_flush_page(pages);
  907. #ifndef CONFIG_SUN4
  908. sun4c_flush_page(pages + PAGE_SIZE);
  909. #endif
  910. sun4c_put_pte(addr, BUCKET_PTE(pages));
  911. #ifndef CONFIG_SUN4
  912. sun4c_put_pte(addr + PAGE_SIZE, BUCKET_PTE(pages + PAGE_SIZE));
  913. #endif
  914. #ifdef CONFIG_DEBUG_STACK_USAGE
  915. memset((void *)addr, 0, PAGE_SIZE << THREAD_INFO_ORDER);
  916. #endif /* DEBUG_STACK_USAGE */
  917. return (struct thread_info *) addr;
  918. }
  919. static void sun4c_free_thread_info(struct thread_info *ti)
  920. {
  921. unsigned long tiaddr = (unsigned long) ti;
  922. unsigned long pages = BUCKET_PTE_PAGE(sun4c_get_pte(tiaddr));
  923. int entry = BUCKET_NUM(tiaddr);
  924. /* We are deleting a mapping, so the flush here is mandatory. */
  925. sun4c_flush_page(tiaddr);
  926. #ifndef CONFIG_SUN4
  927. sun4c_flush_page(tiaddr + PAGE_SIZE);
  928. #endif
  929. sun4c_put_pte(tiaddr, 0);
  930. #ifndef CONFIG_SUN4
  931. sun4c_put_pte(tiaddr + PAGE_SIZE, 0);
  932. #endif
  933. sun4c_bucket[entry] = BUCKET_EMPTY;
  934. if (entry < sun4c_lowbucket_avail)
  935. sun4c_lowbucket_avail = entry;
  936. free_pages(pages, THREAD_INFO_ORDER);
  937. garbage_collect(entry);
  938. }
  939. static void __init sun4c_init_buckets(void)
  940. {
  941. int entry;
  942. if (sizeof(union thread_union) != (PAGE_SIZE << THREAD_INFO_ORDER)) {
  943. extern void thread_info_size_is_bolixed_pete(void);
  944. thread_info_size_is_bolixed_pete();
  945. }
  946. for (entry = 0; entry < NR_TASK_BUCKETS; entry++)
  947. sun4c_bucket[entry] = BUCKET_EMPTY;
  948. sun4c_lowbucket_avail = 0;
  949. }
  950. static unsigned long sun4c_iobuffer_start;
  951. static unsigned long sun4c_iobuffer_end;
  952. static unsigned long sun4c_iobuffer_high;
  953. static unsigned long *sun4c_iobuffer_map;
  954. static int iobuffer_map_size;
  955. /*
  956. * Alias our pages so they do not cause a trap.
  957. * Also one page may be aliased into several I/O areas and we may
  958. * finish these I/O separately.
  959. */
  960. static char *sun4c_lockarea(char *vaddr, unsigned long size)
  961. {
  962. unsigned long base, scan;
  963. unsigned long npages;
  964. unsigned long vpage;
  965. unsigned long pte;
  966. unsigned long apage;
  967. unsigned long high;
  968. unsigned long flags;
  969. npages = (((unsigned long)vaddr & ~PAGE_MASK) +
  970. size + (PAGE_SIZE-1)) >> PAGE_SHIFT;
  971. scan = 0;
  972. local_irq_save(flags);
  973. for (;;) {
  974. scan = find_next_zero_bit(sun4c_iobuffer_map,
  975. iobuffer_map_size, scan);
  976. if ((base = scan) + npages > iobuffer_map_size) goto abend;
  977. for (;;) {
  978. if (scan >= base + npages) goto found;
  979. if (test_bit(scan, sun4c_iobuffer_map)) break;
  980. scan++;
  981. }
  982. }
  983. found:
  984. high = ((base + npages) << PAGE_SHIFT) + sun4c_iobuffer_start;
  985. high = SUN4C_REAL_PGDIR_ALIGN(high);
  986. while (high > sun4c_iobuffer_high) {
  987. get_locked_segment(sun4c_iobuffer_high);
  988. sun4c_iobuffer_high += SUN4C_REAL_PGDIR_SIZE;
  989. }
  990. vpage = ((unsigned long) vaddr) & PAGE_MASK;
  991. for (scan = base; scan < base+npages; scan++) {
  992. pte = ((vpage-PAGE_OFFSET) >> PAGE_SHIFT);
  993. pte |= pgprot_val(SUN4C_PAGE_KERNEL);
  994. pte |= _SUN4C_PAGE_NOCACHE;
  995. set_bit(scan, sun4c_iobuffer_map);
  996. apage = (scan << PAGE_SHIFT) + sun4c_iobuffer_start;
  997. /* Flush original mapping so we see the right things later. */
  998. sun4c_flush_page(vpage);
  999. sun4c_put_pte(apage, pte);
  1000. vpage += PAGE_SIZE;
  1001. }
  1002. local_irq_restore(flags);
  1003. return (char *) ((base << PAGE_SHIFT) + sun4c_iobuffer_start +
  1004. (((unsigned long) vaddr) & ~PAGE_MASK));
  1005. abend:
  1006. local_irq_restore(flags);
  1007. printk("DMA vaddr=0x%p size=%08lx\n", vaddr, size);
  1008. panic("Out of iobuffer table");
  1009. return NULL;
  1010. }
  1011. static void sun4c_unlockarea(char *vaddr, unsigned long size)
  1012. {
  1013. unsigned long vpage, npages;
  1014. unsigned long flags;
  1015. int scan, high;
  1016. vpage = (unsigned long)vaddr & PAGE_MASK;
  1017. npages = (((unsigned long)vaddr & ~PAGE_MASK) +
  1018. size + (PAGE_SIZE-1)) >> PAGE_SHIFT;
  1019. local_irq_save(flags);
  1020. while (npages != 0) {
  1021. --npages;
  1022. /* This mapping is marked non-cachable, no flush necessary. */
  1023. sun4c_put_pte(vpage, 0);
  1024. clear_bit((vpage - sun4c_iobuffer_start) >> PAGE_SHIFT,
  1025. sun4c_iobuffer_map);
  1026. vpage += PAGE_SIZE;
  1027. }
  1028. /* garbage collect */
  1029. scan = (sun4c_iobuffer_high - sun4c_iobuffer_start) >> PAGE_SHIFT;
  1030. while (scan >= 0 && !sun4c_iobuffer_map[scan >> 5])
  1031. scan -= 32;
  1032. scan += 32;
  1033. high = sun4c_iobuffer_start + (scan << PAGE_SHIFT);
  1034. high = SUN4C_REAL_PGDIR_ALIGN(high) + SUN4C_REAL_PGDIR_SIZE;
  1035. while (high < sun4c_iobuffer_high) {
  1036. sun4c_iobuffer_high -= SUN4C_REAL_PGDIR_SIZE;
  1037. free_locked_segment(sun4c_iobuffer_high);
  1038. }
  1039. local_irq_restore(flags);
  1040. }
  1041. /* Note the scsi code at init time passes to here buffers
  1042. * which sit on the kernel stack, those are already locked
  1043. * by implication and fool the page locking code above
  1044. * if passed to by mistake.
  1045. */
  1046. static __u32 sun4c_get_scsi_one(char *bufptr, unsigned long len, struct sbus_bus *sbus)
  1047. {
  1048. unsigned long page;
  1049. page = ((unsigned long)bufptr) & PAGE_MASK;
  1050. if (!virt_addr_valid(page)) {
  1051. sun4c_flush_page(page);
  1052. return (__u32)bufptr; /* already locked */
  1053. }
  1054. return (__u32)sun4c_lockarea(bufptr, len);
  1055. }
  1056. static void sun4c_get_scsi_sgl(struct scatterlist *sg, int sz, struct sbus_bus *sbus)
  1057. {
  1058. while (sz != 0) {
  1059. --sz;
  1060. sg->dvma_address = (__u32)sun4c_lockarea(sg_virt(sg), sg->length);
  1061. sg->dvma_length = sg->length;
  1062. sg = sg_next(sg);
  1063. }
  1064. }
  1065. static void sun4c_release_scsi_one(__u32 bufptr, unsigned long len, struct sbus_bus *sbus)
  1066. {
  1067. if (bufptr < sun4c_iobuffer_start)
  1068. return; /* On kernel stack or similar, see above */
  1069. sun4c_unlockarea((char *)bufptr, len);
  1070. }
  1071. static void sun4c_release_scsi_sgl(struct scatterlist *sg, int sz, struct sbus_bus *sbus)
  1072. {
  1073. while (sz != 0) {
  1074. --sz;
  1075. sun4c_unlockarea((char *)sg->dvma_address, sg->length);
  1076. sg = sg_next(sg);
  1077. }
  1078. }
  1079. #define TASK_ENTRY_SIZE BUCKET_SIZE /* see above */
  1080. #define LONG_ALIGN(x) (((x)+(sizeof(long))-1)&~((sizeof(long))-1))
  1081. struct vm_area_struct sun4c_kstack_vma;
  1082. static void __init sun4c_init_lock_areas(void)
  1083. {
  1084. unsigned long sun4c_taskstack_start;
  1085. unsigned long sun4c_taskstack_end;
  1086. int bitmap_size;
  1087. sun4c_init_buckets();
  1088. sun4c_taskstack_start = SUN4C_LOCK_VADDR;
  1089. sun4c_taskstack_end = (sun4c_taskstack_start +
  1090. (TASK_ENTRY_SIZE * NR_TASK_BUCKETS));
  1091. if (sun4c_taskstack_end >= SUN4C_LOCK_END) {
  1092. prom_printf("Too many tasks, decrease NR_TASK_BUCKETS please.\n");
  1093. prom_halt();
  1094. }
  1095. sun4c_iobuffer_start = sun4c_iobuffer_high =
  1096. SUN4C_REAL_PGDIR_ALIGN(sun4c_taskstack_end);
  1097. sun4c_iobuffer_end = SUN4C_LOCK_END;
  1098. bitmap_size = (sun4c_iobuffer_end - sun4c_iobuffer_start) >> PAGE_SHIFT;
  1099. bitmap_size = (bitmap_size + 7) >> 3;
  1100. bitmap_size = LONG_ALIGN(bitmap_size);
  1101. iobuffer_map_size = bitmap_size << 3;
  1102. sun4c_iobuffer_map = __alloc_bootmem(bitmap_size, SMP_CACHE_BYTES, 0UL);
  1103. memset((void *) sun4c_iobuffer_map, 0, bitmap_size);
  1104. sun4c_kstack_vma.vm_mm = &init_mm;
  1105. sun4c_kstack_vma.vm_start = sun4c_taskstack_start;
  1106. sun4c_kstack_vma.vm_end = sun4c_taskstack_end;
  1107. sun4c_kstack_vma.vm_page_prot = PAGE_SHARED;
  1108. sun4c_kstack_vma.vm_flags = VM_READ | VM_WRITE | VM_EXEC;
  1109. insert_vm_struct(&init_mm, &sun4c_kstack_vma);
  1110. }
  1111. /* Cache flushing on the sun4c. */
  1112. static void sun4c_flush_cache_all(void)
  1113. {
  1114. unsigned long begin, end;
  1115. flush_user_windows();
  1116. begin = (KERNBASE + SUN4C_REAL_PGDIR_SIZE);
  1117. end = (begin + SUN4C_VAC_SIZE);
  1118. if (sun4c_vacinfo.linesize == 32) {
  1119. while (begin < end) {
  1120. __asm__ __volatile__(
  1121. "ld [%0 + 0x00], %%g0\n\t"
  1122. "ld [%0 + 0x20], %%g0\n\t"
  1123. "ld [%0 + 0x40], %%g0\n\t"
  1124. "ld [%0 + 0x60], %%g0\n\t"
  1125. "ld [%0 + 0x80], %%g0\n\t"
  1126. "ld [%0 + 0xa0], %%g0\n\t"
  1127. "ld [%0 + 0xc0], %%g0\n\t"
  1128. "ld [%0 + 0xe0], %%g0\n\t"
  1129. "ld [%0 + 0x100], %%g0\n\t"
  1130. "ld [%0 + 0x120], %%g0\n\t"
  1131. "ld [%0 + 0x140], %%g0\n\t"
  1132. "ld [%0 + 0x160], %%g0\n\t"
  1133. "ld [%0 + 0x180], %%g0\n\t"
  1134. "ld [%0 + 0x1a0], %%g0\n\t"
  1135. "ld [%0 + 0x1c0], %%g0\n\t"
  1136. "ld [%0 + 0x1e0], %%g0\n"
  1137. : : "r" (begin));
  1138. begin += 512;
  1139. }
  1140. } else {
  1141. while (begin < end) {
  1142. __asm__ __volatile__(
  1143. "ld [%0 + 0x00], %%g0\n\t"
  1144. "ld [%0 + 0x10], %%g0\n\t"
  1145. "ld [%0 + 0x20], %%g0\n\t"
  1146. "ld [%0 + 0x30], %%g0\n\t"
  1147. "ld [%0 + 0x40], %%g0\n\t"
  1148. "ld [%0 + 0x50], %%g0\n\t"
  1149. "ld [%0 + 0x60], %%g0\n\t"
  1150. "ld [%0 + 0x70], %%g0\n\t"
  1151. "ld [%0 + 0x80], %%g0\n\t"
  1152. "ld [%0 + 0x90], %%g0\n\t"
  1153. "ld [%0 + 0xa0], %%g0\n\t"
  1154. "ld [%0 + 0xb0], %%g0\n\t"
  1155. "ld [%0 + 0xc0], %%g0\n\t"
  1156. "ld [%0 + 0xd0], %%g0\n\t"
  1157. "ld [%0 + 0xe0], %%g0\n\t"
  1158. "ld [%0 + 0xf0], %%g0\n"
  1159. : : "r" (begin));
  1160. begin += 256;
  1161. }
  1162. }
  1163. }
  1164. static void sun4c_flush_cache_mm(struct mm_struct *mm)
  1165. {
  1166. int new_ctx = mm->context;
  1167. if (new_ctx != NO_CONTEXT) {
  1168. flush_user_windows();
  1169. if (sun4c_context_ring[new_ctx].num_entries) {
  1170. struct sun4c_mmu_entry *head = &sun4c_context_ring[new_ctx].ringhd;
  1171. unsigned long flags;
  1172. local_irq_save(flags);
  1173. if (head->next != head) {
  1174. struct sun4c_mmu_entry *entry = head->next;
  1175. int savectx = sun4c_get_context();
  1176. sun4c_set_context(new_ctx);
  1177. sun4c_flush_context();
  1178. do {
  1179. struct sun4c_mmu_entry *next = entry->next;
  1180. sun4c_user_unmap(entry);
  1181. free_user_entry(new_ctx, entry);
  1182. entry = next;
  1183. } while (entry != head);
  1184. sun4c_set_context(savectx);
  1185. }
  1186. local_irq_restore(flags);
  1187. }
  1188. }
  1189. }
  1190. static void sun4c_flush_cache_range(struct vm_area_struct *vma, unsigned long start, unsigned long end)
  1191. {
  1192. struct mm_struct *mm = vma->vm_mm;
  1193. int new_ctx = mm->context;
  1194. if (new_ctx != NO_CONTEXT) {
  1195. struct sun4c_mmu_entry *head = &sun4c_context_ring[new_ctx].ringhd;
  1196. struct sun4c_mmu_entry *entry;
  1197. unsigned long flags;
  1198. flush_user_windows();
  1199. local_irq_save(flags);
  1200. /* All user segmap chains are ordered on entry->vaddr. */
  1201. for (entry = head->next;
  1202. (entry != head) && ((entry->vaddr+SUN4C_REAL_PGDIR_SIZE) < start);
  1203. entry = entry->next)
  1204. ;
  1205. /* Tracing various job mixtures showed that this conditional
  1206. * only passes ~35% of the time for most worse case situations,
  1207. * therefore we avoid all of this gross overhead ~65% of the time.
  1208. */
  1209. if ((entry != head) && (entry->vaddr < end)) {
  1210. int octx = sun4c_get_context();
  1211. sun4c_set_context(new_ctx);
  1212. /* At this point, always, (start >= entry->vaddr) and
  1213. * (entry->vaddr < end), once the latter condition
  1214. * ceases to hold, or we hit the end of the list, we
  1215. * exit the loop. The ordering of all user allocated
  1216. * segmaps makes this all work out so beautifully.
  1217. */
  1218. do {
  1219. struct sun4c_mmu_entry *next = entry->next;
  1220. unsigned long realend;
  1221. /* "realstart" is always >= entry->vaddr */
  1222. realend = entry->vaddr + SUN4C_REAL_PGDIR_SIZE;
  1223. if (end < realend)
  1224. realend = end;
  1225. if ((realend - entry->vaddr) <= (PAGE_SIZE << 3)) {
  1226. unsigned long page = entry->vaddr;
  1227. while (page < realend) {
  1228. sun4c_flush_page(page);
  1229. page += PAGE_SIZE;
  1230. }
  1231. } else {
  1232. sun4c_flush_segment(entry->vaddr);
  1233. sun4c_user_unmap(entry);
  1234. free_user_entry(new_ctx, entry);
  1235. }
  1236. entry = next;
  1237. } while ((entry != head) && (entry->vaddr < end));
  1238. sun4c_set_context(octx);
  1239. }
  1240. local_irq_restore(flags);
  1241. }
  1242. }
  1243. static void sun4c_flush_cache_page(struct vm_area_struct *vma, unsigned long page)
  1244. {
  1245. struct mm_struct *mm = vma->vm_mm;
  1246. int new_ctx = mm->context;
  1247. /* Sun4c has no separate I/D caches so cannot optimize for non
  1248. * text page flushes.
  1249. */
  1250. if (new_ctx != NO_CONTEXT) {
  1251. int octx = sun4c_get_context();
  1252. unsigned long flags;
  1253. flush_user_windows();
  1254. local_irq_save(flags);
  1255. sun4c_set_context(new_ctx);
  1256. sun4c_flush_page(page);
  1257. sun4c_set_context(octx);
  1258. local_irq_restore(flags);
  1259. }
  1260. }
  1261. static void sun4c_flush_page_to_ram(unsigned long page)
  1262. {
  1263. unsigned long flags;
  1264. local_irq_save(flags);
  1265. sun4c_flush_page(page);
  1266. local_irq_restore(flags);
  1267. }
  1268. /* Sun4c cache is unified, both instructions and data live there, so
  1269. * no need to flush the on-stack instructions for new signal handlers.
  1270. */
  1271. static void sun4c_flush_sig_insns(struct mm_struct *mm, unsigned long insn_addr)
  1272. {
  1273. }
  1274. /* TLB flushing on the sun4c. These routines count on the cache
  1275. * flushing code to flush the user register windows so that we need
  1276. * not do so when we get here.
  1277. */
  1278. static void sun4c_flush_tlb_all(void)
  1279. {
  1280. struct sun4c_mmu_entry *this_entry, *next_entry;
  1281. unsigned long flags;
  1282. int savectx, ctx;
  1283. local_irq_save(flags);
  1284. this_entry = sun4c_kernel_ring.ringhd.next;
  1285. savectx = sun4c_get_context();
  1286. flush_user_windows();
  1287. while (sun4c_kernel_ring.num_entries) {
  1288. next_entry = this_entry->next;
  1289. sun4c_flush_segment(this_entry->vaddr);
  1290. for (ctx = 0; ctx < num_contexts; ctx++) {
  1291. sun4c_set_context(ctx);
  1292. sun4c_put_segmap(this_entry->vaddr, invalid_segment);
  1293. }
  1294. free_kernel_entry(this_entry, &sun4c_kernel_ring);
  1295. this_entry = next_entry;
  1296. }
  1297. sun4c_set_context(savectx);
  1298. local_irq_restore(flags);
  1299. }
  1300. static void sun4c_flush_tlb_mm(struct mm_struct *mm)
  1301. {
  1302. int new_ctx = mm->context;
  1303. if (new_ctx != NO_CONTEXT) {
  1304. struct sun4c_mmu_entry *head = &sun4c_context_ring[new_ctx].ringhd;
  1305. unsigned long flags;
  1306. local_irq_save(flags);
  1307. if (head->next != head) {
  1308. struct sun4c_mmu_entry *entry = head->next;
  1309. int savectx = sun4c_get_context();
  1310. sun4c_set_context(new_ctx);
  1311. sun4c_flush_context();
  1312. do {
  1313. struct sun4c_mmu_entry *next = entry->next;
  1314. sun4c_user_unmap(entry);
  1315. free_user_entry(new_ctx, entry);
  1316. entry = next;
  1317. } while (entry != head);
  1318. sun4c_set_context(savectx);
  1319. }
  1320. local_irq_restore(flags);
  1321. }
  1322. }
  1323. static void sun4c_flush_tlb_range(struct vm_area_struct *vma, unsigned long start, unsigned long end)
  1324. {
  1325. struct mm_struct *mm = vma->vm_mm;
  1326. int new_ctx = mm->context;
  1327. if (new_ctx != NO_CONTEXT) {
  1328. struct sun4c_mmu_entry *head = &sun4c_context_ring[new_ctx].ringhd;
  1329. struct sun4c_mmu_entry *entry;
  1330. unsigned long flags;
  1331. local_irq_save(flags);
  1332. /* See commentary in sun4c_flush_cache_range(). */
  1333. for (entry = head->next;
  1334. (entry != head) && ((entry->vaddr+SUN4C_REAL_PGDIR_SIZE) < start);
  1335. entry = entry->next)
  1336. ;
  1337. if ((entry != head) && (entry->vaddr < end)) {
  1338. int octx = sun4c_get_context();
  1339. sun4c_set_context(new_ctx);
  1340. do {
  1341. struct sun4c_mmu_entry *next = entry->next;
  1342. sun4c_flush_segment(entry->vaddr);
  1343. sun4c_user_unmap(entry);
  1344. free_user_entry(new_ctx, entry);
  1345. entry = next;
  1346. } while ((entry != head) && (entry->vaddr < end));
  1347. sun4c_set_context(octx);
  1348. }
  1349. local_irq_restore(flags);
  1350. }
  1351. }
  1352. static void sun4c_flush_tlb_page(struct vm_area_struct *vma, unsigned long page)
  1353. {
  1354. struct mm_struct *mm = vma->vm_mm;
  1355. int new_ctx = mm->context;
  1356. if (new_ctx != NO_CONTEXT) {
  1357. int savectx = sun4c_get_context();
  1358. unsigned long flags;
  1359. local_irq_save(flags);
  1360. sun4c_set_context(new_ctx);
  1361. page &= PAGE_MASK;
  1362. sun4c_flush_page(page);
  1363. sun4c_put_pte(page, 0);
  1364. sun4c_set_context(savectx);
  1365. local_irq_restore(flags);
  1366. }
  1367. }
  1368. static inline void sun4c_mapioaddr(unsigned long physaddr, unsigned long virt_addr)
  1369. {
  1370. unsigned long page_entry, pg_iobits;
  1371. pg_iobits = _SUN4C_PAGE_PRESENT | _SUN4C_READABLE | _SUN4C_WRITEABLE |
  1372. _SUN4C_PAGE_IO | _SUN4C_PAGE_NOCACHE;
  1373. page_entry = ((physaddr >> PAGE_SHIFT) & SUN4C_PFN_MASK);
  1374. page_entry |= ((pg_iobits | _SUN4C_PAGE_PRIV) & ~(_SUN4C_PAGE_PRESENT));
  1375. sun4c_put_pte(virt_addr, page_entry);
  1376. }
  1377. static void sun4c_mapiorange(unsigned int bus, unsigned long xpa,
  1378. unsigned long xva, unsigned int len)
  1379. {
  1380. while (len != 0) {
  1381. len -= PAGE_SIZE;
  1382. sun4c_mapioaddr(xpa, xva);
  1383. xva += PAGE_SIZE;
  1384. xpa += PAGE_SIZE;
  1385. }
  1386. }
  1387. static void sun4c_unmapiorange(unsigned long virt_addr, unsigned int len)
  1388. {
  1389. while (len != 0) {
  1390. len -= PAGE_SIZE;
  1391. sun4c_put_pte(virt_addr, 0);
  1392. virt_addr += PAGE_SIZE;
  1393. }
  1394. }
  1395. static void sun4c_alloc_context(struct mm_struct *old_mm, struct mm_struct *mm)
  1396. {
  1397. struct ctx_list *ctxp;
  1398. ctxp = ctx_free.next;
  1399. if (ctxp != &ctx_free) {
  1400. remove_from_ctx_list(ctxp);
  1401. add_to_used_ctxlist(ctxp);
  1402. mm->context = ctxp->ctx_number;
  1403. ctxp->ctx_mm = mm;
  1404. return;
  1405. }
  1406. ctxp = ctx_used.next;
  1407. if (ctxp->ctx_mm == old_mm)
  1408. ctxp = ctxp->next;
  1409. remove_from_ctx_list(ctxp);
  1410. add_to_used_ctxlist(ctxp);
  1411. ctxp->ctx_mm->context = NO_CONTEXT;
  1412. ctxp->ctx_mm = mm;
  1413. mm->context = ctxp->ctx_number;
  1414. sun4c_demap_context(&sun4c_context_ring[ctxp->ctx_number],
  1415. ctxp->ctx_number);
  1416. }
  1417. /* Switch the current MM context. */
  1418. static void sun4c_switch_mm(struct mm_struct *old_mm, struct mm_struct *mm, struct task_struct *tsk, int cpu)
  1419. {
  1420. struct ctx_list *ctx;
  1421. int dirty = 0;
  1422. if (mm->context == NO_CONTEXT) {
  1423. dirty = 1;
  1424. sun4c_alloc_context(old_mm, mm);
  1425. } else {
  1426. /* Update the LRU ring of contexts. */
  1427. ctx = ctx_list_pool + mm->context;
  1428. remove_from_ctx_list(ctx);
  1429. add_to_used_ctxlist(ctx);
  1430. }
  1431. if (dirty || old_mm != mm)
  1432. sun4c_set_context(mm->context);
  1433. }
  1434. static void sun4c_destroy_context(struct mm_struct *mm)
  1435. {
  1436. struct ctx_list *ctx_old;
  1437. if (mm->context != NO_CONTEXT) {
  1438. sun4c_demap_context(&sun4c_context_ring[mm->context], mm->context);
  1439. ctx_old = ctx_list_pool + mm->context;
  1440. remove_from_ctx_list(ctx_old);
  1441. add_to_free_ctxlist(ctx_old);
  1442. mm->context = NO_CONTEXT;
  1443. }
  1444. }
  1445. static void sun4c_mmu_info(struct seq_file *m)
  1446. {
  1447. int used_user_entries, i;
  1448. used_user_entries = 0;
  1449. for (i = 0; i < num_contexts; i++)
  1450. used_user_entries += sun4c_context_ring[i].num_entries;
  1451. seq_printf(m,
  1452. "vacsize\t\t: %d bytes\n"
  1453. "vachwflush\t: %s\n"
  1454. "vaclinesize\t: %d bytes\n"
  1455. "mmuctxs\t\t: %d\n"
  1456. "mmupsegs\t: %d\n"
  1457. "kernelpsegs\t: %d\n"
  1458. "kfreepsegs\t: %d\n"
  1459. "usedpsegs\t: %d\n"
  1460. "ufreepsegs\t: %d\n"
  1461. "user_taken\t: %d\n"
  1462. "max_taken\t: %d\n",
  1463. sun4c_vacinfo.num_bytes,
  1464. (sun4c_vacinfo.do_hwflushes ? "yes" : "no"),
  1465. sun4c_vacinfo.linesize,
  1466. num_contexts,
  1467. (invalid_segment + 1),
  1468. sun4c_kernel_ring.num_entries,
  1469. sun4c_kfree_ring.num_entries,
  1470. used_user_entries,
  1471. sun4c_ufree_ring.num_entries,
  1472. sun4c_user_taken_entries,
  1473. max_user_taken_entries);
  1474. }
  1475. /* Nothing below here should touch the mmu hardware nor the mmu_entry
  1476. * data structures.
  1477. */
  1478. /* First the functions which the mid-level code uses to directly
  1479. * manipulate the software page tables. Some defines since we are
  1480. * emulating the i386 page directory layout.
  1481. */
  1482. #define PGD_PRESENT 0x001
  1483. #define PGD_RW 0x002
  1484. #define PGD_USER 0x004
  1485. #define PGD_ACCESSED 0x020
  1486. #define PGD_DIRTY 0x040
  1487. #define PGD_TABLE (PGD_PRESENT | PGD_RW | PGD_USER | PGD_ACCESSED | PGD_DIRTY)
  1488. static void sun4c_set_pte(pte_t *ptep, pte_t pte)
  1489. {
  1490. *ptep = pte;
  1491. }
  1492. static void sun4c_pgd_set(pgd_t * pgdp, pmd_t * pmdp)
  1493. {
  1494. }
  1495. static void sun4c_pmd_set(pmd_t * pmdp, pte_t * ptep)
  1496. {
  1497. pmdp->pmdv[0] = PGD_TABLE | (unsigned long) ptep;
  1498. }
  1499. static void sun4c_pmd_populate(pmd_t * pmdp, struct page * ptep)
  1500. {
  1501. if (page_address(ptep) == NULL) BUG(); /* No highmem on sun4c */
  1502. pmdp->pmdv[0] = PGD_TABLE | (unsigned long) page_address(ptep);
  1503. }
  1504. static int sun4c_pte_present(pte_t pte)
  1505. {
  1506. return ((pte_val(pte) & (_SUN4C_PAGE_PRESENT | _SUN4C_PAGE_PRIV)) != 0);
  1507. }
  1508. static void sun4c_pte_clear(pte_t *ptep) { *ptep = __pte(0); }
  1509. static int sun4c_pmd_bad(pmd_t pmd)
  1510. {
  1511. return (((pmd_val(pmd) & ~PAGE_MASK) != PGD_TABLE) ||
  1512. (!virt_addr_valid(pmd_val(pmd))));
  1513. }
  1514. static int sun4c_pmd_present(pmd_t pmd)
  1515. {
  1516. return ((pmd_val(pmd) & PGD_PRESENT) != 0);
  1517. }
  1518. #if 0 /* if PMD takes one word */
  1519. static void sun4c_pmd_clear(pmd_t *pmdp) { *pmdp = __pmd(0); }
  1520. #else /* if pmd_t is a longish aggregate */
  1521. static void sun4c_pmd_clear(pmd_t *pmdp) {
  1522. memset((void *)pmdp, 0, sizeof(pmd_t));
  1523. }
  1524. #endif
  1525. static int sun4c_pgd_none(pgd_t pgd) { return 0; }
  1526. static int sun4c_pgd_bad(pgd_t pgd) { return 0; }
  1527. static int sun4c_pgd_present(pgd_t pgd) { return 1; }
  1528. static void sun4c_pgd_clear(pgd_t * pgdp) { }
  1529. /*
  1530. * The following only work if pte_present() is true.
  1531. * Undefined behaviour if not..
  1532. */
  1533. static pte_t sun4c_pte_mkwrite(pte_t pte)
  1534. {
  1535. pte = __pte(pte_val(pte) | _SUN4C_PAGE_WRITE);
  1536. if (pte_val(pte) & _SUN4C_PAGE_MODIFIED)
  1537. pte = __pte(pte_val(pte) | _SUN4C_PAGE_SILENT_WRITE);
  1538. return pte;
  1539. }
  1540. static pte_t sun4c_pte_mkdirty(pte_t pte)
  1541. {
  1542. pte = __pte(pte_val(pte) | _SUN4C_PAGE_MODIFIED);
  1543. if (pte_val(pte) & _SUN4C_PAGE_WRITE)
  1544. pte = __pte(pte_val(pte) | _SUN4C_PAGE_SILENT_WRITE);
  1545. return pte;
  1546. }
  1547. static pte_t sun4c_pte_mkyoung(pte_t pte)
  1548. {
  1549. pte = __pte(pte_val(pte) | _SUN4C_PAGE_ACCESSED);
  1550. if (pte_val(pte) & _SUN4C_PAGE_READ)
  1551. pte = __pte(pte_val(pte) | _SUN4C_PAGE_SILENT_READ);
  1552. return pte;
  1553. }
  1554. /*
  1555. * Conversion functions: convert a page and protection to a page entry,
  1556. * and a page entry and page directory to the page they refer to.
  1557. */
  1558. static pte_t sun4c_mk_pte(struct page *page, pgprot_t pgprot)
  1559. {
  1560. return __pte(page_to_pfn(page) | pgprot_val(pgprot));
  1561. }
  1562. static pte_t sun4c_mk_pte_phys(unsigned long phys_page, pgprot_t pgprot)
  1563. {
  1564. return __pte((phys_page >> PAGE_SHIFT) | pgprot_val(pgprot));
  1565. }
  1566. static pte_t sun4c_mk_pte_io(unsigned long page, pgprot_t pgprot, int space)
  1567. {
  1568. return __pte(((page - PAGE_OFFSET) >> PAGE_SHIFT) | pgprot_val(pgprot));
  1569. }
  1570. static unsigned long sun4c_pte_pfn(pte_t pte)
  1571. {
  1572. return pte_val(pte) & SUN4C_PFN_MASK;
  1573. }
  1574. static pte_t sun4c_pgoff_to_pte(unsigned long pgoff)
  1575. {
  1576. return __pte(pgoff | _SUN4C_PAGE_FILE);
  1577. }
  1578. static unsigned long sun4c_pte_to_pgoff(pte_t pte)
  1579. {
  1580. return pte_val(pte) & ((1UL << PTE_FILE_MAX_BITS) - 1);
  1581. }
  1582. static inline unsigned long sun4c_pmd_page_v(pmd_t pmd)
  1583. {
  1584. return (pmd_val(pmd) & PAGE_MASK);
  1585. }
  1586. static struct page *sun4c_pmd_page(pmd_t pmd)
  1587. {
  1588. return virt_to_page(sun4c_pmd_page_v(pmd));
  1589. }
  1590. static unsigned long sun4c_pgd_page(pgd_t pgd) { return 0; }
  1591. /* to find an entry in a page-table-directory */
  1592. static inline pgd_t *sun4c_pgd_offset(struct mm_struct * mm, unsigned long address)
  1593. {
  1594. return mm->pgd + (address >> SUN4C_PGDIR_SHIFT);
  1595. }
  1596. /* Find an entry in the second-level page table.. */
  1597. static pmd_t *sun4c_pmd_offset(pgd_t * dir, unsigned long address)
  1598. {
  1599. return (pmd_t *) dir;
  1600. }
  1601. /* Find an entry in the third-level page table.. */
  1602. pte_t *sun4c_pte_offset_kernel(pmd_t * dir, unsigned long address)
  1603. {
  1604. return (pte_t *) sun4c_pmd_page_v(*dir) +
  1605. ((address >> PAGE_SHIFT) & (SUN4C_PTRS_PER_PTE - 1));
  1606. }
  1607. static unsigned long sun4c_swp_type(swp_entry_t entry)
  1608. {
  1609. return (entry.val & SUN4C_SWP_TYPE_MASK);
  1610. }
  1611. static unsigned long sun4c_swp_offset(swp_entry_t entry)
  1612. {
  1613. return (entry.val >> SUN4C_SWP_OFF_SHIFT) & SUN4C_SWP_OFF_MASK;
  1614. }
  1615. static swp_entry_t sun4c_swp_entry(unsigned long type, unsigned long offset)
  1616. {
  1617. return (swp_entry_t) {
  1618. (offset & SUN4C_SWP_OFF_MASK) << SUN4C_SWP_OFF_SHIFT
  1619. | (type & SUN4C_SWP_TYPE_MASK) };
  1620. }
  1621. static void sun4c_free_pte_slow(pte_t *pte)
  1622. {
  1623. free_page((unsigned long)pte);
  1624. }
  1625. static void sun4c_free_pgd_slow(pgd_t *pgd)
  1626. {
  1627. free_page((unsigned long)pgd);
  1628. }
  1629. static pgd_t *sun4c_get_pgd_fast(void)
  1630. {
  1631. unsigned long *ret;
  1632. if ((ret = pgd_quicklist) != NULL) {
  1633. pgd_quicklist = (unsigned long *)(*ret);
  1634. ret[0] = ret[1];
  1635. pgtable_cache_size--;
  1636. } else {
  1637. pgd_t *init;
  1638. ret = (unsigned long *)__get_free_page(GFP_KERNEL);
  1639. memset (ret, 0, (KERNBASE / SUN4C_PGDIR_SIZE) * sizeof(pgd_t));
  1640. init = sun4c_pgd_offset(&init_mm, 0);
  1641. memcpy (((pgd_t *)ret) + USER_PTRS_PER_PGD, init + USER_PTRS_PER_PGD,
  1642. (PTRS_PER_PGD - USER_PTRS_PER_PGD) * sizeof(pgd_t));
  1643. }
  1644. return (pgd_t *)ret;
  1645. }
  1646. static void sun4c_free_pgd_fast(pgd_t *pgd)
  1647. {
  1648. *(unsigned long *)pgd = (unsigned long) pgd_quicklist;
  1649. pgd_quicklist = (unsigned long *) pgd;
  1650. pgtable_cache_size++;
  1651. }
  1652. static inline pte_t *
  1653. sun4c_pte_alloc_one_fast(struct mm_struct *mm, unsigned long address)
  1654. {
  1655. unsigned long *ret;
  1656. if ((ret = (unsigned long *)pte_quicklist) != NULL) {
  1657. pte_quicklist = (unsigned long *)(*ret);
  1658. ret[0] = ret[1];
  1659. pgtable_cache_size--;
  1660. }
  1661. return (pte_t *)ret;
  1662. }
  1663. static pte_t *sun4c_pte_alloc_one_kernel(struct mm_struct *mm, unsigned long address)
  1664. {
  1665. pte_t *pte;
  1666. if ((pte = sun4c_pte_alloc_one_fast(mm, address)) != NULL)
  1667. return pte;
  1668. pte = (pte_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
  1669. return pte;
  1670. }
  1671. static pgtable_t sun4c_pte_alloc_one(struct mm_struct *mm, unsigned long address)
  1672. {
  1673. pte_t *pte;
  1674. struct page *page;
  1675. pte = sun4c_pte_alloc_one_kernel(mm, address);
  1676. if (pte == NULL)
  1677. return NULL;
  1678. page = virt_to_page(pte);
  1679. pgtable_page_ctor(page);
  1680. return page;
  1681. }
  1682. static inline void sun4c_free_pte_fast(pte_t *pte)
  1683. {
  1684. *(unsigned long *)pte = (unsigned long) pte_quicklist;
  1685. pte_quicklist = (unsigned long *) pte;
  1686. pgtable_cache_size++;
  1687. }
  1688. static void sun4c_pte_free(pgtable_t pte)
  1689. {
  1690. pgtable_page_dtor(pte);
  1691. sun4c_free_pte_fast(page_address(pte));
  1692. }
  1693. /*
  1694. * allocating and freeing a pmd is trivial: the 1-entry pmd is
  1695. * inside the pgd, so has no extra memory associated with it.
  1696. */
  1697. static pmd_t *sun4c_pmd_alloc_one(struct mm_struct *mm, unsigned long address)
  1698. {
  1699. BUG();
  1700. return NULL;
  1701. }
  1702. static void sun4c_free_pmd_fast(pmd_t * pmd) { }
  1703. static void sun4c_check_pgt_cache(int low, int high)
  1704. {
  1705. if (pgtable_cache_size > high) {
  1706. do {
  1707. if (pgd_quicklist)
  1708. sun4c_free_pgd_slow(sun4c_get_pgd_fast());
  1709. if (pte_quicklist)
  1710. sun4c_free_pte_slow(sun4c_pte_alloc_one_fast(NULL, 0));
  1711. } while (pgtable_cache_size > low);
  1712. }
  1713. }
  1714. /* An experiment, turn off by default for now... -DaveM */
  1715. #define SUN4C_PRELOAD_PSEG
  1716. void sun4c_update_mmu_cache(struct vm_area_struct *vma, unsigned long address, pte_t pte)
  1717. {
  1718. unsigned long flags;
  1719. int pseg;
  1720. if (vma->vm_mm->context == NO_CONTEXT)
  1721. return;
  1722. local_irq_save(flags);
  1723. address &= PAGE_MASK;
  1724. if ((pseg = sun4c_get_segmap(address)) == invalid_segment) {
  1725. struct sun4c_mmu_entry *entry = sun4c_user_strategy();
  1726. struct mm_struct *mm = vma->vm_mm;
  1727. unsigned long start, end;
  1728. entry->vaddr = start = (address & SUN4C_REAL_PGDIR_MASK);
  1729. entry->ctx = mm->context;
  1730. add_ring_ordered(sun4c_context_ring + mm->context, entry);
  1731. sun4c_put_segmap(entry->vaddr, entry->pseg);
  1732. end = start + SUN4C_REAL_PGDIR_SIZE;
  1733. while (start < end) {
  1734. #ifdef SUN4C_PRELOAD_PSEG
  1735. pgd_t *pgdp = sun4c_pgd_offset(mm, start);
  1736. pte_t *ptep;
  1737. if (!pgdp)
  1738. goto no_mapping;
  1739. ptep = sun4c_pte_offset_kernel((pmd_t *) pgdp, start);
  1740. if (!ptep || !(pte_val(*ptep) & _SUN4C_PAGE_PRESENT))
  1741. goto no_mapping;
  1742. sun4c_put_pte(start, pte_val(*ptep));
  1743. goto next;
  1744. no_mapping:
  1745. #endif
  1746. sun4c_put_pte(start, 0);
  1747. #ifdef SUN4C_PRELOAD_PSEG
  1748. next:
  1749. #endif
  1750. start += PAGE_SIZE;
  1751. }
  1752. #ifndef SUN4C_PRELOAD_PSEG
  1753. sun4c_put_pte(address, pte_val(pte));
  1754. #endif
  1755. local_irq_restore(flags);
  1756. return;
  1757. } else {
  1758. struct sun4c_mmu_entry *entry = &mmu_entry_pool[pseg];
  1759. remove_lru(entry);
  1760. add_lru(entry);
  1761. }
  1762. sun4c_put_pte(address, pte_val(pte));
  1763. local_irq_restore(flags);
  1764. }
  1765. extern void sparc_context_init(int);
  1766. extern unsigned long end;
  1767. extern unsigned long bootmem_init(unsigned long *pages_avail);
  1768. extern unsigned long last_valid_pfn;
  1769. void __init sun4c_paging_init(void)
  1770. {
  1771. int i, cnt;
  1772. unsigned long kernel_end, vaddr;
  1773. extern struct resource sparc_iomap;
  1774. unsigned long end_pfn, pages_avail;
  1775. kernel_end = (unsigned long) &end;
  1776. kernel_end = SUN4C_REAL_PGDIR_ALIGN(kernel_end);
  1777. pages_avail = 0;
  1778. last_valid_pfn = bootmem_init(&pages_avail);
  1779. end_pfn = last_valid_pfn;
  1780. sun4c_probe_mmu();
  1781. invalid_segment = (num_segmaps - 1);
  1782. sun4c_init_mmu_entry_pool();
  1783. sun4c_init_rings();
  1784. sun4c_init_map_kernelprom(kernel_end);
  1785. sun4c_init_clean_mmu(kernel_end);
  1786. sun4c_init_fill_kernel_ring(SUN4C_KERNEL_BUCKETS);
  1787. sun4c_init_lock_area(sparc_iomap.start, IOBASE_END);
  1788. sun4c_init_lock_area(DVMA_VADDR, DVMA_END);
  1789. sun4c_init_lock_areas();
  1790. sun4c_init_fill_user_ring();
  1791. sun4c_set_context(0);
  1792. memset(swapper_pg_dir, 0, PAGE_SIZE);
  1793. memset(pg0, 0, PAGE_SIZE);
  1794. memset(pg1, 0, PAGE_SIZE);
  1795. memset(pg2, 0, PAGE_SIZE);
  1796. memset(pg3, 0, PAGE_SIZE);
  1797. /* Save work later. */
  1798. vaddr = VMALLOC_START;
  1799. swapper_pg_dir[vaddr>>SUN4C_PGDIR_SHIFT] = __pgd(PGD_TABLE | (unsigned long) pg0);
  1800. vaddr += SUN4C_PGDIR_SIZE;
  1801. swapper_pg_dir[vaddr>>SUN4C_PGDIR_SHIFT] = __pgd(PGD_TABLE | (unsigned long) pg1);
  1802. vaddr += SUN4C_PGDIR_SIZE;
  1803. swapper_pg_dir[vaddr>>SUN4C_PGDIR_SHIFT] = __pgd(PGD_TABLE | (unsigned long) pg2);
  1804. vaddr += SUN4C_PGDIR_SIZE;
  1805. swapper_pg_dir[vaddr>>SUN4C_PGDIR_SHIFT] = __pgd(PGD_TABLE | (unsigned long) pg3);
  1806. sun4c_init_ss2_cache_bug();
  1807. sparc_context_init(num_contexts);
  1808. {
  1809. unsigned long zones_size[MAX_NR_ZONES];
  1810. unsigned long zholes_size[MAX_NR_ZONES];
  1811. unsigned long npages;
  1812. int znum;
  1813. for (znum = 0; znum < MAX_NR_ZONES; znum++)
  1814. zones_size[znum] = zholes_size[znum] = 0;
  1815. npages = max_low_pfn - pfn_base;
  1816. zones_size[ZONE_DMA] = npages;
  1817. zholes_size[ZONE_DMA] = npages - pages_avail;
  1818. npages = highend_pfn - max_low_pfn;
  1819. zones_size[ZONE_HIGHMEM] = npages;
  1820. zholes_size[ZONE_HIGHMEM] = npages - calc_highpages();
  1821. free_area_init_node(0, zones_size, pfn_base, zholes_size);
  1822. }
  1823. cnt = 0;
  1824. for (i = 0; i < num_segmaps; i++)
  1825. if (mmu_entry_pool[i].locked)
  1826. cnt++;
  1827. max_user_taken_entries = num_segmaps - cnt - 40 - 1;
  1828. printk("SUN4C: %d mmu entries for the kernel\n", cnt);
  1829. }
  1830. static pgprot_t sun4c_pgprot_noncached(pgprot_t prot)
  1831. {
  1832. prot |= __pgprot(_SUN4C_PAGE_IO | _SUN4C_PAGE_NOCACHE);
  1833. return prot;
  1834. }
  1835. /* Load up routines and constants for sun4c mmu */
  1836. void __init ld_mmu_sun4c(void)
  1837. {
  1838. extern void ___xchg32_sun4c(void);
  1839. printk("Loading sun4c MMU routines\n");
  1840. /* First the constants */
  1841. BTFIXUPSET_SIMM13(pgdir_shift, SUN4C_PGDIR_SHIFT);
  1842. BTFIXUPSET_SETHI(pgdir_size, SUN4C_PGDIR_SIZE);
  1843. BTFIXUPSET_SETHI(pgdir_mask, SUN4C_PGDIR_MASK);
  1844. BTFIXUPSET_SIMM13(ptrs_per_pmd, SUN4C_PTRS_PER_PMD);
  1845. BTFIXUPSET_SIMM13(ptrs_per_pgd, SUN4C_PTRS_PER_PGD);
  1846. BTFIXUPSET_SIMM13(user_ptrs_per_pgd, KERNBASE / SUN4C_PGDIR_SIZE);
  1847. BTFIXUPSET_INT(page_none, pgprot_val(SUN4C_PAGE_NONE));
  1848. PAGE_SHARED = pgprot_val(SUN4C_PAGE_SHARED);
  1849. BTFIXUPSET_INT(page_copy, pgprot_val(SUN4C_PAGE_COPY));
  1850. BTFIXUPSET_INT(page_readonly, pgprot_val(SUN4C_PAGE_READONLY));
  1851. BTFIXUPSET_INT(page_kernel, pgprot_val(SUN4C_PAGE_KERNEL));
  1852. page_kernel = pgprot_val(SUN4C_PAGE_KERNEL);
  1853. /* Functions */
  1854. BTFIXUPSET_CALL(pgprot_noncached, sun4c_pgprot_noncached, BTFIXUPCALL_NORM);
  1855. BTFIXUPSET_CALL(___xchg32, ___xchg32_sun4c, BTFIXUPCALL_NORM);
  1856. BTFIXUPSET_CALL(do_check_pgt_cache, sun4c_check_pgt_cache, BTFIXUPCALL_NORM);
  1857. BTFIXUPSET_CALL(flush_cache_all, sun4c_flush_cache_all, BTFIXUPCALL_NORM);
  1858. if (sun4c_vacinfo.do_hwflushes) {
  1859. BTFIXUPSET_CALL(sun4c_flush_page, sun4c_flush_page_hw, BTFIXUPCALL_NORM);
  1860. BTFIXUPSET_CALL(sun4c_flush_segment, sun4c_flush_segment_hw, BTFIXUPCALL_NORM);
  1861. BTFIXUPSET_CALL(sun4c_flush_context, sun4c_flush_context_hw, BTFIXUPCALL_NORM);
  1862. } else {
  1863. BTFIXUPSET_CALL(sun4c_flush_page, sun4c_flush_page_sw, BTFIXUPCALL_NORM);
  1864. BTFIXUPSET_CALL(sun4c_flush_segment, sun4c_flush_segment_sw, BTFIXUPCALL_NORM);
  1865. BTFIXUPSET_CALL(sun4c_flush_context, sun4c_flush_context_sw, BTFIXUPCALL_NORM);
  1866. }
  1867. BTFIXUPSET_CALL(flush_tlb_mm, sun4c_flush_tlb_mm, BTFIXUPCALL_NORM);
  1868. BTFIXUPSET_CALL(flush_cache_mm, sun4c_flush_cache_mm, BTFIXUPCALL_NORM);
  1869. BTFIXUPSET_CALL(destroy_context, sun4c_destroy_context, BTFIXUPCALL_NORM);
  1870. BTFIXUPSET_CALL(switch_mm, sun4c_switch_mm, BTFIXUPCALL_NORM);
  1871. BTFIXUPSET_CALL(flush_cache_page, sun4c_flush_cache_page, BTFIXUPCALL_NORM);
  1872. BTFIXUPSET_CALL(flush_tlb_page, sun4c_flush_tlb_page, BTFIXUPCALL_NORM);
  1873. BTFIXUPSET_CALL(flush_tlb_range, sun4c_flush_tlb_range, BTFIXUPCALL_NORM);
  1874. BTFIXUPSET_CALL(flush_cache_range, sun4c_flush_cache_range, BTFIXUPCALL_NORM);
  1875. BTFIXUPSET_CALL(__flush_page_to_ram, sun4c_flush_page_to_ram, BTFIXUPCALL_NORM);
  1876. BTFIXUPSET_CALL(flush_tlb_all, sun4c_flush_tlb_all, BTFIXUPCALL_NORM);
  1877. BTFIXUPSET_CALL(flush_sig_insns, sun4c_flush_sig_insns, BTFIXUPCALL_NOP);
  1878. BTFIXUPSET_CALL(set_pte, sun4c_set_pte, BTFIXUPCALL_STO1O0);
  1879. /* The 2.4.18 code does not set this on sun4c, how does it work? XXX */
  1880. /* BTFIXUPSET_SETHI(none_mask, 0x00000000); */ /* Defaults to zero? */
  1881. BTFIXUPSET_CALL(pte_pfn, sun4c_pte_pfn, BTFIXUPCALL_NORM);
  1882. #if 0 /* PAGE_SHIFT <= 12 */ /* Eek. Investigate. XXX */
  1883. BTFIXUPSET_CALL(pmd_page, sun4c_pmd_page, BTFIXUPCALL_ANDNINT(PAGE_SIZE - 1));
  1884. #else
  1885. BTFIXUPSET_CALL(pmd_page, sun4c_pmd_page, BTFIXUPCALL_NORM);
  1886. #endif
  1887. BTFIXUPSET_CALL(pmd_set, sun4c_pmd_set, BTFIXUPCALL_NORM);
  1888. BTFIXUPSET_CALL(pmd_populate, sun4c_pmd_populate, BTFIXUPCALL_NORM);
  1889. BTFIXUPSET_CALL(pte_present, sun4c_pte_present, BTFIXUPCALL_NORM);
  1890. BTFIXUPSET_CALL(pte_clear, sun4c_pte_clear, BTFIXUPCALL_STG0O0);
  1891. BTFIXUPSET_CALL(pmd_bad, sun4c_pmd_bad, BTFIXUPCALL_NORM);
  1892. BTFIXUPSET_CALL(pmd_present, sun4c_pmd_present, BTFIXUPCALL_NORM);
  1893. BTFIXUPSET_CALL(pmd_clear, sun4c_pmd_clear, BTFIXUPCALL_STG0O0);
  1894. BTFIXUPSET_CALL(pgd_none, sun4c_pgd_none, BTFIXUPCALL_RETINT(0));
  1895. BTFIXUPSET_CALL(pgd_bad, sun4c_pgd_bad, BTFIXUPCALL_RETINT(0));
  1896. BTFIXUPSET_CALL(pgd_present, sun4c_pgd_present, BTFIXUPCALL_RETINT(1));
  1897. BTFIXUPSET_CALL(pgd_clear, sun4c_pgd_clear, BTFIXUPCALL_NOP);
  1898. BTFIXUPSET_CALL(mk_pte, sun4c_mk_pte, BTFIXUPCALL_NORM);
  1899. BTFIXUPSET_CALL(mk_pte_phys, sun4c_mk_pte_phys, BTFIXUPCALL_NORM);
  1900. BTFIXUPSET_CALL(mk_pte_io, sun4c_mk_pte_io, BTFIXUPCALL_NORM);
  1901. BTFIXUPSET_INT(pte_modify_mask, _SUN4C_PAGE_CHG_MASK);
  1902. BTFIXUPSET_CALL(pmd_offset, sun4c_pmd_offset, BTFIXUPCALL_NORM);
  1903. BTFIXUPSET_CALL(pte_offset_kernel, sun4c_pte_offset_kernel, BTFIXUPCALL_NORM);
  1904. BTFIXUPSET_CALL(free_pte_fast, sun4c_free_pte_fast, BTFIXUPCALL_NORM);
  1905. BTFIXUPSET_CALL(pte_free, sun4c_pte_free, BTFIXUPCALL_NORM);
  1906. BTFIXUPSET_CALL(pte_alloc_one_kernel, sun4c_pte_alloc_one_kernel, BTFIXUPCALL_NORM);
  1907. BTFIXUPSET_CALL(pte_alloc_one, sun4c_pte_alloc_one, BTFIXUPCALL_NORM);
  1908. BTFIXUPSET_CALL(free_pmd_fast, sun4c_free_pmd_fast, BTFIXUPCALL_NOP);
  1909. BTFIXUPSET_CALL(pmd_alloc_one, sun4c_pmd_alloc_one, BTFIXUPCALL_RETO0);
  1910. BTFIXUPSET_CALL(free_pgd_fast, sun4c_free_pgd_fast, BTFIXUPCALL_NORM);
  1911. BTFIXUPSET_CALL(get_pgd_fast, sun4c_get_pgd_fast, BTFIXUPCALL_NORM);
  1912. BTFIXUPSET_HALF(pte_writei, _SUN4C_PAGE_WRITE);
  1913. BTFIXUPSET_HALF(pte_dirtyi, _SUN4C_PAGE_MODIFIED);
  1914. BTFIXUPSET_HALF(pte_youngi, _SUN4C_PAGE_ACCESSED);
  1915. BTFIXUPSET_HALF(pte_filei, _SUN4C_PAGE_FILE);
  1916. BTFIXUPSET_HALF(pte_wrprotecti, _SUN4C_PAGE_WRITE|_SUN4C_PAGE_SILENT_WRITE);
  1917. BTFIXUPSET_HALF(pte_mkcleani, _SUN4C_PAGE_MODIFIED|_SUN4C_PAGE_SILENT_WRITE);
  1918. BTFIXUPSET_HALF(pte_mkoldi, _SUN4C_PAGE_ACCESSED|_SUN4C_PAGE_SILENT_READ);
  1919. BTFIXUPSET_CALL(pte_mkwrite, sun4c_pte_mkwrite, BTFIXUPCALL_NORM);
  1920. BTFIXUPSET_CALL(pte_mkdirty, sun4c_pte_mkdirty, BTFIXUPCALL_NORM);
  1921. BTFIXUPSET_CALL(pte_mkyoung, sun4c_pte_mkyoung, BTFIXUPCALL_NORM);
  1922. BTFIXUPSET_CALL(update_mmu_cache, sun4c_update_mmu_cache, BTFIXUPCALL_NORM);
  1923. BTFIXUPSET_CALL(pte_to_pgoff, sun4c_pte_to_pgoff, BTFIXUPCALL_NORM);
  1924. BTFIXUPSET_CALL(pgoff_to_pte, sun4c_pgoff_to_pte, BTFIXUPCALL_NORM);
  1925. BTFIXUPSET_CALL(mmu_lockarea, sun4c_lockarea, BTFIXUPCALL_NORM);
  1926. BTFIXUPSET_CALL(mmu_unlockarea, sun4c_unlockarea, BTFIXUPCALL_NORM);
  1927. BTFIXUPSET_CALL(mmu_get_scsi_one, sun4c_get_scsi_one, BTFIXUPCALL_NORM);
  1928. BTFIXUPSET_CALL(mmu_get_scsi_sgl, sun4c_get_scsi_sgl, BTFIXUPCALL_NORM);
  1929. BTFIXUPSET_CALL(mmu_release_scsi_one, sun4c_release_scsi_one, BTFIXUPCALL_NORM);
  1930. BTFIXUPSET_CALL(mmu_release_scsi_sgl, sun4c_release_scsi_sgl, BTFIXUPCALL_NORM);
  1931. BTFIXUPSET_CALL(mmu_map_dma_area, sun4c_map_dma_area, BTFIXUPCALL_NORM);
  1932. BTFIXUPSET_CALL(mmu_unmap_dma_area, sun4c_unmap_dma_area, BTFIXUPCALL_NORM);
  1933. BTFIXUPSET_CALL(sparc_mapiorange, sun4c_mapiorange, BTFIXUPCALL_NORM);
  1934. BTFIXUPSET_CALL(sparc_unmapiorange, sun4c_unmapiorange, BTFIXUPCALL_NORM);
  1935. BTFIXUPSET_CALL(__swp_type, sun4c_swp_type, BTFIXUPCALL_NORM);
  1936. BTFIXUPSET_CALL(__swp_offset, sun4c_swp_offset, BTFIXUPCALL_NORM);
  1937. BTFIXUPSET_CALL(__swp_entry, sun4c_swp_entry, BTFIXUPCALL_NORM);
  1938. BTFIXUPSET_CALL(alloc_thread_info, sun4c_alloc_thread_info, BTFIXUPCALL_NORM);
  1939. BTFIXUPSET_CALL(free_thread_info, sun4c_free_thread_info, BTFIXUPCALL_NORM);
  1940. BTFIXUPSET_CALL(mmu_info, sun4c_mmu_info, BTFIXUPCALL_NORM);
  1941. /* These should _never_ get called with two level tables. */
  1942. BTFIXUPSET_CALL(pgd_set, sun4c_pgd_set, BTFIXUPCALL_NOP);
  1943. BTFIXUPSET_CALL(pgd_page_vaddr, sun4c_pgd_page, BTFIXUPCALL_RETO0);
  1944. }