srmmu.c 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815
  1. /*
  2. * srmmu.c: SRMMU specific routines for memory management.
  3. *
  4. * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
  5. * Copyright (C) 1995,2002 Pete Zaitcev (zaitcev@yahoo.com)
  6. * Copyright (C) 1996 Eddie C. Dost (ecd@skynet.be)
  7. * Copyright (C) 1997,1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
  8. * Copyright (C) 1999,2000 Anton Blanchard (anton@samba.org)
  9. */
  10. #include <linux/seq_file.h>
  11. #include <linux/spinlock.h>
  12. #include <linux/bootmem.h>
  13. #include <linux/pagemap.h>
  14. #include <linux/vmalloc.h>
  15. #include <linux/kdebug.h>
  16. #include <linux/kernel.h>
  17. #include <linux/init.h>
  18. #include <linux/log2.h>
  19. #include <linux/gfp.h>
  20. #include <linux/fs.h>
  21. #include <linux/mm.h>
  22. #include <asm/mmu_context.h>
  23. #include <asm/cacheflush.h>
  24. #include <asm/tlbflush.h>
  25. #include <asm/io-unit.h>
  26. #include <asm/pgalloc.h>
  27. #include <asm/pgtable.h>
  28. #include <asm/bitext.h>
  29. #include <asm/vaddrs.h>
  30. #include <asm/cache.h>
  31. #include <asm/traps.h>
  32. #include <asm/oplib.h>
  33. #include <asm/mbus.h>
  34. #include <asm/page.h>
  35. #include <asm/asi.h>
  36. #include <asm/msi.h>
  37. #include <asm/smp.h>
  38. #include <asm/io.h>
  39. /* Now the cpu specific definitions. */
  40. #include <asm/turbosparc.h>
  41. #include <asm/tsunami.h>
  42. #include <asm/viking.h>
  43. #include <asm/swift.h>
  44. #include <asm/leon.h>
  45. #include <asm/mxcc.h>
  46. #include <asm/ross.h>
  47. #include "srmmu.h"
  48. enum mbus_module srmmu_modtype;
  49. static unsigned int hwbug_bitmask;
  50. int vac_cache_size;
  51. int vac_line_size;
  52. extern struct resource sparc_iomap;
  53. extern unsigned long last_valid_pfn;
  54. static pgd_t *srmmu_swapper_pg_dir;
  55. const struct sparc32_cachetlb_ops *sparc32_cachetlb_ops;
  56. #ifdef CONFIG_SMP
  57. const struct sparc32_cachetlb_ops *local_ops;
  58. #define FLUSH_BEGIN(mm)
  59. #define FLUSH_END
  60. #else
  61. #define FLUSH_BEGIN(mm) if ((mm)->context != NO_CONTEXT) {
  62. #define FLUSH_END }
  63. #endif
  64. int flush_page_for_dma_global = 1;
  65. char *srmmu_name;
  66. ctxd_t *srmmu_ctx_table_phys;
  67. static ctxd_t *srmmu_context_table;
  68. int viking_mxcc_present;
  69. static DEFINE_SPINLOCK(srmmu_context_spinlock);
  70. static int is_hypersparc;
  71. static int srmmu_cache_pagetables;
  72. /* these will be initialized in srmmu_nocache_calcsize() */
  73. static unsigned long srmmu_nocache_size;
  74. static unsigned long srmmu_nocache_end;
  75. /* 1 bit <=> 256 bytes of nocache <=> 64 PTEs */
  76. #define SRMMU_NOCACHE_BITMAP_SHIFT (PAGE_SHIFT - 4)
  77. /* The context table is a nocache user with the biggest alignment needs. */
  78. #define SRMMU_NOCACHE_ALIGN_MAX (sizeof(ctxd_t)*SRMMU_MAX_CONTEXTS)
  79. void *srmmu_nocache_pool;
  80. void *srmmu_nocache_bitmap;
  81. static struct bit_map srmmu_nocache_map;
  82. static inline int srmmu_pmd_none(pmd_t pmd)
  83. { return !(pmd_val(pmd) & 0xFFFFFFF); }
  84. /* XXX should we hyper_flush_whole_icache here - Anton */
  85. static inline void srmmu_ctxd_set(ctxd_t *ctxp, pgd_t *pgdp)
  86. { set_pte((pte_t *)ctxp, (SRMMU_ET_PTD | (__nocache_pa((unsigned long) pgdp) >> 4))); }
  87. void pmd_set(pmd_t *pmdp, pte_t *ptep)
  88. {
  89. unsigned long ptp; /* Physical address, shifted right by 4 */
  90. int i;
  91. ptp = __nocache_pa((unsigned long) ptep) >> 4;
  92. for (i = 0; i < PTRS_PER_PTE/SRMMU_REAL_PTRS_PER_PTE; i++) {
  93. set_pte((pte_t *)&pmdp->pmdv[i], SRMMU_ET_PTD | ptp);
  94. ptp += (SRMMU_REAL_PTRS_PER_PTE*sizeof(pte_t) >> 4);
  95. }
  96. }
  97. void pmd_populate(struct mm_struct *mm, pmd_t *pmdp, struct page *ptep)
  98. {
  99. unsigned long ptp; /* Physical address, shifted right by 4 */
  100. int i;
  101. ptp = page_to_pfn(ptep) << (PAGE_SHIFT-4); /* watch for overflow */
  102. for (i = 0; i < PTRS_PER_PTE/SRMMU_REAL_PTRS_PER_PTE; i++) {
  103. set_pte((pte_t *)&pmdp->pmdv[i], SRMMU_ET_PTD | ptp);
  104. ptp += (SRMMU_REAL_PTRS_PER_PTE*sizeof(pte_t) >> 4);
  105. }
  106. }
  107. /* Find an entry in the third-level page table.. */
  108. pte_t *pte_offset_kernel(pmd_t *dir, unsigned long address)
  109. {
  110. void *pte;
  111. pte = __nocache_va((dir->pmdv[0] & SRMMU_PTD_PMASK) << 4);
  112. return (pte_t *) pte +
  113. ((address >> PAGE_SHIFT) & (PTRS_PER_PTE - 1));
  114. }
  115. /*
  116. * size: bytes to allocate in the nocache area.
  117. * align: bytes, number to align at.
  118. * Returns the virtual address of the allocated area.
  119. */
  120. static void *__srmmu_get_nocache(int size, int align)
  121. {
  122. int offset;
  123. unsigned long addr;
  124. if (size < SRMMU_NOCACHE_BITMAP_SHIFT) {
  125. printk(KERN_ERR "Size 0x%x too small for nocache request\n",
  126. size);
  127. size = SRMMU_NOCACHE_BITMAP_SHIFT;
  128. }
  129. if (size & (SRMMU_NOCACHE_BITMAP_SHIFT - 1)) {
  130. printk(KERN_ERR "Size 0x%x unaligned int nocache request\n",
  131. size);
  132. size += SRMMU_NOCACHE_BITMAP_SHIFT - 1;
  133. }
  134. BUG_ON(align > SRMMU_NOCACHE_ALIGN_MAX);
  135. offset = bit_map_string_get(&srmmu_nocache_map,
  136. size >> SRMMU_NOCACHE_BITMAP_SHIFT,
  137. align >> SRMMU_NOCACHE_BITMAP_SHIFT);
  138. if (offset == -1) {
  139. printk(KERN_ERR "srmmu: out of nocache %d: %d/%d\n",
  140. size, (int) srmmu_nocache_size,
  141. srmmu_nocache_map.used << SRMMU_NOCACHE_BITMAP_SHIFT);
  142. return 0;
  143. }
  144. addr = SRMMU_NOCACHE_VADDR + (offset << SRMMU_NOCACHE_BITMAP_SHIFT);
  145. return (void *)addr;
  146. }
  147. void *srmmu_get_nocache(int size, int align)
  148. {
  149. void *tmp;
  150. tmp = __srmmu_get_nocache(size, align);
  151. if (tmp)
  152. memset(tmp, 0, size);
  153. return tmp;
  154. }
  155. void srmmu_free_nocache(void *addr, int size)
  156. {
  157. unsigned long vaddr;
  158. int offset;
  159. vaddr = (unsigned long)addr;
  160. if (vaddr < SRMMU_NOCACHE_VADDR) {
  161. printk("Vaddr %lx is smaller than nocache base 0x%lx\n",
  162. vaddr, (unsigned long)SRMMU_NOCACHE_VADDR);
  163. BUG();
  164. }
  165. if (vaddr + size > srmmu_nocache_end) {
  166. printk("Vaddr %lx is bigger than nocache end 0x%lx\n",
  167. vaddr, srmmu_nocache_end);
  168. BUG();
  169. }
  170. if (!is_power_of_2(size)) {
  171. printk("Size 0x%x is not a power of 2\n", size);
  172. BUG();
  173. }
  174. if (size < SRMMU_NOCACHE_BITMAP_SHIFT) {
  175. printk("Size 0x%x is too small\n", size);
  176. BUG();
  177. }
  178. if (vaddr & (size - 1)) {
  179. printk("Vaddr %lx is not aligned to size 0x%x\n", vaddr, size);
  180. BUG();
  181. }
  182. offset = (vaddr - SRMMU_NOCACHE_VADDR) >> SRMMU_NOCACHE_BITMAP_SHIFT;
  183. size = size >> SRMMU_NOCACHE_BITMAP_SHIFT;
  184. bit_map_clear(&srmmu_nocache_map, offset, size);
  185. }
  186. static void srmmu_early_allocate_ptable_skeleton(unsigned long start,
  187. unsigned long end);
  188. /* Return how much physical memory we have. */
  189. static unsigned long __init probe_memory(void)
  190. {
  191. unsigned long total = 0;
  192. int i;
  193. for (i = 0; sp_banks[i].num_bytes; i++)
  194. total += sp_banks[i].num_bytes;
  195. return total;
  196. }
  197. /*
  198. * Reserve nocache dynamically proportionally to the amount of
  199. * system RAM. -- Tomas Szepe <szepe@pinerecords.com>, June 2002
  200. */
  201. static void __init srmmu_nocache_calcsize(void)
  202. {
  203. unsigned long sysmemavail = probe_memory() / 1024;
  204. int srmmu_nocache_npages;
  205. srmmu_nocache_npages =
  206. sysmemavail / SRMMU_NOCACHE_ALCRATIO / 1024 * 256;
  207. /* P3 XXX The 4x overuse: corroborated by /proc/meminfo. */
  208. // if (srmmu_nocache_npages < 256) srmmu_nocache_npages = 256;
  209. if (srmmu_nocache_npages < SRMMU_MIN_NOCACHE_PAGES)
  210. srmmu_nocache_npages = SRMMU_MIN_NOCACHE_PAGES;
  211. /* anything above 1280 blows up */
  212. if (srmmu_nocache_npages > SRMMU_MAX_NOCACHE_PAGES)
  213. srmmu_nocache_npages = SRMMU_MAX_NOCACHE_PAGES;
  214. srmmu_nocache_size = srmmu_nocache_npages * PAGE_SIZE;
  215. srmmu_nocache_end = SRMMU_NOCACHE_VADDR + srmmu_nocache_size;
  216. }
  217. static void __init srmmu_nocache_init(void)
  218. {
  219. unsigned int bitmap_bits;
  220. pgd_t *pgd;
  221. pmd_t *pmd;
  222. pte_t *pte;
  223. unsigned long paddr, vaddr;
  224. unsigned long pteval;
  225. bitmap_bits = srmmu_nocache_size >> SRMMU_NOCACHE_BITMAP_SHIFT;
  226. srmmu_nocache_pool = __alloc_bootmem(srmmu_nocache_size,
  227. SRMMU_NOCACHE_ALIGN_MAX, 0UL);
  228. memset(srmmu_nocache_pool, 0, srmmu_nocache_size);
  229. srmmu_nocache_bitmap =
  230. __alloc_bootmem(BITS_TO_LONGS(bitmap_bits) * sizeof(long),
  231. SMP_CACHE_BYTES, 0UL);
  232. bit_map_init(&srmmu_nocache_map, srmmu_nocache_bitmap, bitmap_bits);
  233. srmmu_swapper_pg_dir = __srmmu_get_nocache(SRMMU_PGD_TABLE_SIZE, SRMMU_PGD_TABLE_SIZE);
  234. memset(__nocache_fix(srmmu_swapper_pg_dir), 0, SRMMU_PGD_TABLE_SIZE);
  235. init_mm.pgd = srmmu_swapper_pg_dir;
  236. srmmu_early_allocate_ptable_skeleton(SRMMU_NOCACHE_VADDR, srmmu_nocache_end);
  237. paddr = __pa((unsigned long)srmmu_nocache_pool);
  238. vaddr = SRMMU_NOCACHE_VADDR;
  239. while (vaddr < srmmu_nocache_end) {
  240. pgd = pgd_offset_k(vaddr);
  241. pmd = pmd_offset(__nocache_fix(pgd), vaddr);
  242. pte = pte_offset_kernel(__nocache_fix(pmd), vaddr);
  243. pteval = ((paddr >> 4) | SRMMU_ET_PTE | SRMMU_PRIV);
  244. if (srmmu_cache_pagetables)
  245. pteval |= SRMMU_CACHE;
  246. set_pte(__nocache_fix(pte), __pte(pteval));
  247. vaddr += PAGE_SIZE;
  248. paddr += PAGE_SIZE;
  249. }
  250. flush_cache_all();
  251. flush_tlb_all();
  252. }
  253. pgd_t *get_pgd_fast(void)
  254. {
  255. pgd_t *pgd = NULL;
  256. pgd = __srmmu_get_nocache(SRMMU_PGD_TABLE_SIZE, SRMMU_PGD_TABLE_SIZE);
  257. if (pgd) {
  258. pgd_t *init = pgd_offset_k(0);
  259. memset(pgd, 0, USER_PTRS_PER_PGD * sizeof(pgd_t));
  260. memcpy(pgd + USER_PTRS_PER_PGD, init + USER_PTRS_PER_PGD,
  261. (PTRS_PER_PGD - USER_PTRS_PER_PGD) * sizeof(pgd_t));
  262. }
  263. return pgd;
  264. }
  265. /*
  266. * Hardware needs alignment to 256 only, but we align to whole page size
  267. * to reduce fragmentation problems due to the buddy principle.
  268. * XXX Provide actual fragmentation statistics in /proc.
  269. *
  270. * Alignments up to the page size are the same for physical and virtual
  271. * addresses of the nocache area.
  272. */
  273. pgtable_t pte_alloc_one(struct mm_struct *mm, unsigned long address)
  274. {
  275. unsigned long pte;
  276. struct page *page;
  277. if ((pte = (unsigned long)pte_alloc_one_kernel(mm, address)) == 0)
  278. return NULL;
  279. page = pfn_to_page(__nocache_pa(pte) >> PAGE_SHIFT);
  280. pgtable_page_ctor(page);
  281. return page;
  282. }
  283. void pte_free(struct mm_struct *mm, pgtable_t pte)
  284. {
  285. unsigned long p;
  286. pgtable_page_dtor(pte);
  287. p = (unsigned long)page_address(pte); /* Cached address (for test) */
  288. if (p == 0)
  289. BUG();
  290. p = page_to_pfn(pte) << PAGE_SHIFT; /* Physical address */
  291. /* free non cached virtual address*/
  292. srmmu_free_nocache(__nocache_va(p), PTE_SIZE);
  293. }
  294. /* context handling - a dynamically sized pool is used */
  295. #define NO_CONTEXT -1
  296. struct ctx_list {
  297. struct ctx_list *next;
  298. struct ctx_list *prev;
  299. unsigned int ctx_number;
  300. struct mm_struct *ctx_mm;
  301. };
  302. static struct ctx_list *ctx_list_pool;
  303. static struct ctx_list ctx_free;
  304. static struct ctx_list ctx_used;
  305. /* At boot time we determine the number of contexts */
  306. static int num_contexts;
  307. static inline void remove_from_ctx_list(struct ctx_list *entry)
  308. {
  309. entry->next->prev = entry->prev;
  310. entry->prev->next = entry->next;
  311. }
  312. static inline void add_to_ctx_list(struct ctx_list *head, struct ctx_list *entry)
  313. {
  314. entry->next = head;
  315. (entry->prev = head->prev)->next = entry;
  316. head->prev = entry;
  317. }
  318. #define add_to_free_ctxlist(entry) add_to_ctx_list(&ctx_free, entry)
  319. #define add_to_used_ctxlist(entry) add_to_ctx_list(&ctx_used, entry)
  320. static inline void alloc_context(struct mm_struct *old_mm, struct mm_struct *mm)
  321. {
  322. struct ctx_list *ctxp;
  323. ctxp = ctx_free.next;
  324. if (ctxp != &ctx_free) {
  325. remove_from_ctx_list(ctxp);
  326. add_to_used_ctxlist(ctxp);
  327. mm->context = ctxp->ctx_number;
  328. ctxp->ctx_mm = mm;
  329. return;
  330. }
  331. ctxp = ctx_used.next;
  332. if (ctxp->ctx_mm == old_mm)
  333. ctxp = ctxp->next;
  334. if (ctxp == &ctx_used)
  335. panic("out of mmu contexts");
  336. flush_cache_mm(ctxp->ctx_mm);
  337. flush_tlb_mm(ctxp->ctx_mm);
  338. remove_from_ctx_list(ctxp);
  339. add_to_used_ctxlist(ctxp);
  340. ctxp->ctx_mm->context = NO_CONTEXT;
  341. ctxp->ctx_mm = mm;
  342. mm->context = ctxp->ctx_number;
  343. }
  344. static inline void free_context(int context)
  345. {
  346. struct ctx_list *ctx_old;
  347. ctx_old = ctx_list_pool + context;
  348. remove_from_ctx_list(ctx_old);
  349. add_to_free_ctxlist(ctx_old);
  350. }
  351. static void __init sparc_context_init(int numctx)
  352. {
  353. int ctx;
  354. unsigned long size;
  355. size = numctx * sizeof(struct ctx_list);
  356. ctx_list_pool = __alloc_bootmem(size, SMP_CACHE_BYTES, 0UL);
  357. for (ctx = 0; ctx < numctx; ctx++) {
  358. struct ctx_list *clist;
  359. clist = (ctx_list_pool + ctx);
  360. clist->ctx_number = ctx;
  361. clist->ctx_mm = NULL;
  362. }
  363. ctx_free.next = ctx_free.prev = &ctx_free;
  364. ctx_used.next = ctx_used.prev = &ctx_used;
  365. for (ctx = 0; ctx < numctx; ctx++)
  366. add_to_free_ctxlist(ctx_list_pool + ctx);
  367. }
  368. void switch_mm(struct mm_struct *old_mm, struct mm_struct *mm,
  369. struct task_struct *tsk)
  370. {
  371. if (mm->context == NO_CONTEXT) {
  372. spin_lock(&srmmu_context_spinlock);
  373. alloc_context(old_mm, mm);
  374. spin_unlock(&srmmu_context_spinlock);
  375. srmmu_ctxd_set(&srmmu_context_table[mm->context], mm->pgd);
  376. }
  377. if (sparc_cpu_model == sparc_leon)
  378. leon_switch_mm();
  379. if (is_hypersparc)
  380. hyper_flush_whole_icache();
  381. srmmu_set_context(mm->context);
  382. }
  383. /* Low level IO area allocation on the SRMMU. */
  384. static inline void srmmu_mapioaddr(unsigned long physaddr,
  385. unsigned long virt_addr, int bus_type)
  386. {
  387. pgd_t *pgdp;
  388. pmd_t *pmdp;
  389. pte_t *ptep;
  390. unsigned long tmp;
  391. physaddr &= PAGE_MASK;
  392. pgdp = pgd_offset_k(virt_addr);
  393. pmdp = pmd_offset(pgdp, virt_addr);
  394. ptep = pte_offset_kernel(pmdp, virt_addr);
  395. tmp = (physaddr >> 4) | SRMMU_ET_PTE;
  396. /* I need to test whether this is consistent over all
  397. * sun4m's. The bus_type represents the upper 4 bits of
  398. * 36-bit physical address on the I/O space lines...
  399. */
  400. tmp |= (bus_type << 28);
  401. tmp |= SRMMU_PRIV;
  402. __flush_page_to_ram(virt_addr);
  403. set_pte(ptep, __pte(tmp));
  404. }
  405. void srmmu_mapiorange(unsigned int bus, unsigned long xpa,
  406. unsigned long xva, unsigned int len)
  407. {
  408. while (len != 0) {
  409. len -= PAGE_SIZE;
  410. srmmu_mapioaddr(xpa, xva, bus);
  411. xva += PAGE_SIZE;
  412. xpa += PAGE_SIZE;
  413. }
  414. flush_tlb_all();
  415. }
  416. static inline void srmmu_unmapioaddr(unsigned long virt_addr)
  417. {
  418. pgd_t *pgdp;
  419. pmd_t *pmdp;
  420. pte_t *ptep;
  421. pgdp = pgd_offset_k(virt_addr);
  422. pmdp = pmd_offset(pgdp, virt_addr);
  423. ptep = pte_offset_kernel(pmdp, virt_addr);
  424. /* No need to flush uncacheable page. */
  425. __pte_clear(ptep);
  426. }
  427. void srmmu_unmapiorange(unsigned long virt_addr, unsigned int len)
  428. {
  429. while (len != 0) {
  430. len -= PAGE_SIZE;
  431. srmmu_unmapioaddr(virt_addr);
  432. virt_addr += PAGE_SIZE;
  433. }
  434. flush_tlb_all();
  435. }
  436. /* tsunami.S */
  437. extern void tsunami_flush_cache_all(void);
  438. extern void tsunami_flush_cache_mm(struct mm_struct *mm);
  439. extern void tsunami_flush_cache_range(struct vm_area_struct *vma, unsigned long start, unsigned long end);
  440. extern void tsunami_flush_cache_page(struct vm_area_struct *vma, unsigned long page);
  441. extern void tsunami_flush_page_to_ram(unsigned long page);
  442. extern void tsunami_flush_page_for_dma(unsigned long page);
  443. extern void tsunami_flush_sig_insns(struct mm_struct *mm, unsigned long insn_addr);
  444. extern void tsunami_flush_tlb_all(void);
  445. extern void tsunami_flush_tlb_mm(struct mm_struct *mm);
  446. extern void tsunami_flush_tlb_range(struct vm_area_struct *vma, unsigned long start, unsigned long end);
  447. extern void tsunami_flush_tlb_page(struct vm_area_struct *vma, unsigned long page);
  448. extern void tsunami_setup_blockops(void);
  449. /* swift.S */
  450. extern void swift_flush_cache_all(void);
  451. extern void swift_flush_cache_mm(struct mm_struct *mm);
  452. extern void swift_flush_cache_range(struct vm_area_struct *vma,
  453. unsigned long start, unsigned long end);
  454. extern void swift_flush_cache_page(struct vm_area_struct *vma, unsigned long page);
  455. extern void swift_flush_page_to_ram(unsigned long page);
  456. extern void swift_flush_page_for_dma(unsigned long page);
  457. extern void swift_flush_sig_insns(struct mm_struct *mm, unsigned long insn_addr);
  458. extern void swift_flush_tlb_all(void);
  459. extern void swift_flush_tlb_mm(struct mm_struct *mm);
  460. extern void swift_flush_tlb_range(struct vm_area_struct *vma,
  461. unsigned long start, unsigned long end);
  462. extern void swift_flush_tlb_page(struct vm_area_struct *vma, unsigned long page);
  463. #if 0 /* P3: deadwood to debug precise flushes on Swift. */
  464. void swift_flush_tlb_page(struct vm_area_struct *vma, unsigned long page)
  465. {
  466. int cctx, ctx1;
  467. page &= PAGE_MASK;
  468. if ((ctx1 = vma->vm_mm->context) != -1) {
  469. cctx = srmmu_get_context();
  470. /* Is context # ever different from current context? P3 */
  471. if (cctx != ctx1) {
  472. printk("flush ctx %02x curr %02x\n", ctx1, cctx);
  473. srmmu_set_context(ctx1);
  474. swift_flush_page(page);
  475. __asm__ __volatile__("sta %%g0, [%0] %1\n\t" : :
  476. "r" (page), "i" (ASI_M_FLUSH_PROBE));
  477. srmmu_set_context(cctx);
  478. } else {
  479. /* Rm. prot. bits from virt. c. */
  480. /* swift_flush_cache_all(); */
  481. /* swift_flush_cache_page(vma, page); */
  482. swift_flush_page(page);
  483. __asm__ __volatile__("sta %%g0, [%0] %1\n\t" : :
  484. "r" (page), "i" (ASI_M_FLUSH_PROBE));
  485. /* same as above: srmmu_flush_tlb_page() */
  486. }
  487. }
  488. }
  489. #endif
  490. /*
  491. * The following are all MBUS based SRMMU modules, and therefore could
  492. * be found in a multiprocessor configuration. On the whole, these
  493. * chips seems to be much more touchy about DVMA and page tables
  494. * with respect to cache coherency.
  495. */
  496. /* viking.S */
  497. extern void viking_flush_cache_all(void);
  498. extern void viking_flush_cache_mm(struct mm_struct *mm);
  499. extern void viking_flush_cache_range(struct vm_area_struct *vma, unsigned long start,
  500. unsigned long end);
  501. extern void viking_flush_cache_page(struct vm_area_struct *vma, unsigned long page);
  502. extern void viking_flush_page_to_ram(unsigned long page);
  503. extern void viking_flush_page_for_dma(unsigned long page);
  504. extern void viking_flush_sig_insns(struct mm_struct *mm, unsigned long addr);
  505. extern void viking_flush_page(unsigned long page);
  506. extern void viking_mxcc_flush_page(unsigned long page);
  507. extern void viking_flush_tlb_all(void);
  508. extern void viking_flush_tlb_mm(struct mm_struct *mm);
  509. extern void viking_flush_tlb_range(struct vm_area_struct *vma, unsigned long start,
  510. unsigned long end);
  511. extern void viking_flush_tlb_page(struct vm_area_struct *vma,
  512. unsigned long page);
  513. extern void sun4dsmp_flush_tlb_all(void);
  514. extern void sun4dsmp_flush_tlb_mm(struct mm_struct *mm);
  515. extern void sun4dsmp_flush_tlb_range(struct vm_area_struct *vma, unsigned long start,
  516. unsigned long end);
  517. extern void sun4dsmp_flush_tlb_page(struct vm_area_struct *vma,
  518. unsigned long page);
  519. /* hypersparc.S */
  520. extern void hypersparc_flush_cache_all(void);
  521. extern void hypersparc_flush_cache_mm(struct mm_struct *mm);
  522. extern void hypersparc_flush_cache_range(struct vm_area_struct *vma, unsigned long start, unsigned long end);
  523. extern void hypersparc_flush_cache_page(struct vm_area_struct *vma, unsigned long page);
  524. extern void hypersparc_flush_page_to_ram(unsigned long page);
  525. extern void hypersparc_flush_page_for_dma(unsigned long page);
  526. extern void hypersparc_flush_sig_insns(struct mm_struct *mm, unsigned long insn_addr);
  527. extern void hypersparc_flush_tlb_all(void);
  528. extern void hypersparc_flush_tlb_mm(struct mm_struct *mm);
  529. extern void hypersparc_flush_tlb_range(struct vm_area_struct *vma, unsigned long start, unsigned long end);
  530. extern void hypersparc_flush_tlb_page(struct vm_area_struct *vma, unsigned long page);
  531. extern void hypersparc_setup_blockops(void);
  532. /*
  533. * NOTE: All of this startup code assumes the low 16mb (approx.) of
  534. * kernel mappings are done with one single contiguous chunk of
  535. * ram. On small ram machines (classics mainly) we only get
  536. * around 8mb mapped for us.
  537. */
  538. static void __init early_pgtable_allocfail(char *type)
  539. {
  540. prom_printf("inherit_prom_mappings: Cannot alloc kernel %s.\n", type);
  541. prom_halt();
  542. }
  543. static void __init srmmu_early_allocate_ptable_skeleton(unsigned long start,
  544. unsigned long end)
  545. {
  546. pgd_t *pgdp;
  547. pmd_t *pmdp;
  548. pte_t *ptep;
  549. while (start < end) {
  550. pgdp = pgd_offset_k(start);
  551. if (pgd_none(*(pgd_t *)__nocache_fix(pgdp))) {
  552. pmdp = __srmmu_get_nocache(
  553. SRMMU_PMD_TABLE_SIZE, SRMMU_PMD_TABLE_SIZE);
  554. if (pmdp == NULL)
  555. early_pgtable_allocfail("pmd");
  556. memset(__nocache_fix(pmdp), 0, SRMMU_PMD_TABLE_SIZE);
  557. pgd_set(__nocache_fix(pgdp), pmdp);
  558. }
  559. pmdp = pmd_offset(__nocache_fix(pgdp), start);
  560. if (srmmu_pmd_none(*(pmd_t *)__nocache_fix(pmdp))) {
  561. ptep = __srmmu_get_nocache(PTE_SIZE, PTE_SIZE);
  562. if (ptep == NULL)
  563. early_pgtable_allocfail("pte");
  564. memset(__nocache_fix(ptep), 0, PTE_SIZE);
  565. pmd_set(__nocache_fix(pmdp), ptep);
  566. }
  567. if (start > (0xffffffffUL - PMD_SIZE))
  568. break;
  569. start = (start + PMD_SIZE) & PMD_MASK;
  570. }
  571. }
  572. static void __init srmmu_allocate_ptable_skeleton(unsigned long start,
  573. unsigned long end)
  574. {
  575. pgd_t *pgdp;
  576. pmd_t *pmdp;
  577. pte_t *ptep;
  578. while (start < end) {
  579. pgdp = pgd_offset_k(start);
  580. if (pgd_none(*pgdp)) {
  581. pmdp = __srmmu_get_nocache(SRMMU_PMD_TABLE_SIZE, SRMMU_PMD_TABLE_SIZE);
  582. if (pmdp == NULL)
  583. early_pgtable_allocfail("pmd");
  584. memset(pmdp, 0, SRMMU_PMD_TABLE_SIZE);
  585. pgd_set(pgdp, pmdp);
  586. }
  587. pmdp = pmd_offset(pgdp, start);
  588. if (srmmu_pmd_none(*pmdp)) {
  589. ptep = __srmmu_get_nocache(PTE_SIZE,
  590. PTE_SIZE);
  591. if (ptep == NULL)
  592. early_pgtable_allocfail("pte");
  593. memset(ptep, 0, PTE_SIZE);
  594. pmd_set(pmdp, ptep);
  595. }
  596. if (start > (0xffffffffUL - PMD_SIZE))
  597. break;
  598. start = (start + PMD_SIZE) & PMD_MASK;
  599. }
  600. }
  601. /* These flush types are not available on all chips... */
  602. static inline unsigned long srmmu_probe(unsigned long vaddr)
  603. {
  604. unsigned long retval;
  605. if (sparc_cpu_model != sparc_leon) {
  606. vaddr &= PAGE_MASK;
  607. __asm__ __volatile__("lda [%1] %2, %0\n\t" :
  608. "=r" (retval) :
  609. "r" (vaddr | 0x400), "i" (ASI_M_FLUSH_PROBE));
  610. } else {
  611. retval = leon_swprobe(vaddr, 0);
  612. }
  613. return retval;
  614. }
  615. /*
  616. * This is much cleaner than poking around physical address space
  617. * looking at the prom's page table directly which is what most
  618. * other OS's do. Yuck... this is much better.
  619. */
  620. static void __init srmmu_inherit_prom_mappings(unsigned long start,
  621. unsigned long end)
  622. {
  623. unsigned long probed;
  624. unsigned long addr;
  625. pgd_t *pgdp;
  626. pmd_t *pmdp;
  627. pte_t *ptep;
  628. int what; /* 0 = normal-pte, 1 = pmd-level pte, 2 = pgd-level pte */
  629. while (start <= end) {
  630. if (start == 0)
  631. break; /* probably wrap around */
  632. if (start == 0xfef00000)
  633. start = KADB_DEBUGGER_BEGVM;
  634. probed = srmmu_probe(start);
  635. if (!probed) {
  636. /* continue probing until we find an entry */
  637. start += PAGE_SIZE;
  638. continue;
  639. }
  640. /* A red snapper, see what it really is. */
  641. what = 0;
  642. addr = start - PAGE_SIZE;
  643. if (!(start & ~(SRMMU_REAL_PMD_MASK))) {
  644. if (srmmu_probe(addr + SRMMU_REAL_PMD_SIZE) == probed)
  645. what = 1;
  646. }
  647. if (!(start & ~(SRMMU_PGDIR_MASK))) {
  648. if (srmmu_probe(addr + SRMMU_PGDIR_SIZE) == probed)
  649. what = 2;
  650. }
  651. pgdp = pgd_offset_k(start);
  652. if (what == 2) {
  653. *(pgd_t *)__nocache_fix(pgdp) = __pgd(probed);
  654. start += SRMMU_PGDIR_SIZE;
  655. continue;
  656. }
  657. if (pgd_none(*(pgd_t *)__nocache_fix(pgdp))) {
  658. pmdp = __srmmu_get_nocache(SRMMU_PMD_TABLE_SIZE,
  659. SRMMU_PMD_TABLE_SIZE);
  660. if (pmdp == NULL)
  661. early_pgtable_allocfail("pmd");
  662. memset(__nocache_fix(pmdp), 0, SRMMU_PMD_TABLE_SIZE);
  663. pgd_set(__nocache_fix(pgdp), pmdp);
  664. }
  665. pmdp = pmd_offset(__nocache_fix(pgdp), start);
  666. if (srmmu_pmd_none(*(pmd_t *)__nocache_fix(pmdp))) {
  667. ptep = __srmmu_get_nocache(PTE_SIZE, PTE_SIZE);
  668. if (ptep == NULL)
  669. early_pgtable_allocfail("pte");
  670. memset(__nocache_fix(ptep), 0, PTE_SIZE);
  671. pmd_set(__nocache_fix(pmdp), ptep);
  672. }
  673. if (what == 1) {
  674. /* We bend the rule where all 16 PTPs in a pmd_t point
  675. * inside the same PTE page, and we leak a perfectly
  676. * good hardware PTE piece. Alternatives seem worse.
  677. */
  678. unsigned int x; /* Index of HW PMD in soft cluster */
  679. unsigned long *val;
  680. x = (start >> PMD_SHIFT) & 15;
  681. val = &pmdp->pmdv[x];
  682. *(unsigned long *)__nocache_fix(val) = probed;
  683. start += SRMMU_REAL_PMD_SIZE;
  684. continue;
  685. }
  686. ptep = pte_offset_kernel(__nocache_fix(pmdp), start);
  687. *(pte_t *)__nocache_fix(ptep) = __pte(probed);
  688. start += PAGE_SIZE;
  689. }
  690. }
  691. #define KERNEL_PTE(page_shifted) ((page_shifted)|SRMMU_CACHE|SRMMU_PRIV|SRMMU_VALID)
  692. /* Create a third-level SRMMU 16MB page mapping. */
  693. static void __init do_large_mapping(unsigned long vaddr, unsigned long phys_base)
  694. {
  695. pgd_t *pgdp = pgd_offset_k(vaddr);
  696. unsigned long big_pte;
  697. big_pte = KERNEL_PTE(phys_base >> 4);
  698. *(pgd_t *)__nocache_fix(pgdp) = __pgd(big_pte);
  699. }
  700. /* Map sp_bank entry SP_ENTRY, starting at virtual address VBASE. */
  701. static unsigned long __init map_spbank(unsigned long vbase, int sp_entry)
  702. {
  703. unsigned long pstart = (sp_banks[sp_entry].base_addr & SRMMU_PGDIR_MASK);
  704. unsigned long vstart = (vbase & SRMMU_PGDIR_MASK);
  705. unsigned long vend = SRMMU_PGDIR_ALIGN(vbase + sp_banks[sp_entry].num_bytes);
  706. /* Map "low" memory only */
  707. const unsigned long min_vaddr = PAGE_OFFSET;
  708. const unsigned long max_vaddr = PAGE_OFFSET + SRMMU_MAXMEM;
  709. if (vstart < min_vaddr || vstart >= max_vaddr)
  710. return vstart;
  711. if (vend > max_vaddr || vend < min_vaddr)
  712. vend = max_vaddr;
  713. while (vstart < vend) {
  714. do_large_mapping(vstart, pstart);
  715. vstart += SRMMU_PGDIR_SIZE; pstart += SRMMU_PGDIR_SIZE;
  716. }
  717. return vstart;
  718. }
  719. static void __init map_kernel(void)
  720. {
  721. int i;
  722. if (phys_base > 0) {
  723. do_large_mapping(PAGE_OFFSET, phys_base);
  724. }
  725. for (i = 0; sp_banks[i].num_bytes != 0; i++) {
  726. map_spbank((unsigned long)__va(sp_banks[i].base_addr), i);
  727. }
  728. }
  729. void (*poke_srmmu)(void) __cpuinitdata = NULL;
  730. extern unsigned long bootmem_init(unsigned long *pages_avail);
  731. void __init srmmu_paging_init(void)
  732. {
  733. int i;
  734. phandle cpunode;
  735. char node_str[128];
  736. pgd_t *pgd;
  737. pmd_t *pmd;
  738. pte_t *pte;
  739. unsigned long pages_avail;
  740. init_mm.context = (unsigned long) NO_CONTEXT;
  741. sparc_iomap.start = SUN4M_IOBASE_VADDR; /* 16MB of IOSPACE on all sun4m's. */
  742. if (sparc_cpu_model == sun4d)
  743. num_contexts = 65536; /* We know it is Viking */
  744. else {
  745. /* Find the number of contexts on the srmmu. */
  746. cpunode = prom_getchild(prom_root_node);
  747. num_contexts = 0;
  748. while (cpunode != 0) {
  749. prom_getstring(cpunode, "device_type", node_str, sizeof(node_str));
  750. if (!strcmp(node_str, "cpu")) {
  751. num_contexts = prom_getintdefault(cpunode, "mmu-nctx", 0x8);
  752. break;
  753. }
  754. cpunode = prom_getsibling(cpunode);
  755. }
  756. }
  757. if (!num_contexts) {
  758. prom_printf("Something wrong, can't find cpu node in paging_init.\n");
  759. prom_halt();
  760. }
  761. pages_avail = 0;
  762. last_valid_pfn = bootmem_init(&pages_avail);
  763. srmmu_nocache_calcsize();
  764. srmmu_nocache_init();
  765. srmmu_inherit_prom_mappings(0xfe400000, (LINUX_OPPROM_ENDVM - PAGE_SIZE));
  766. map_kernel();
  767. /* ctx table has to be physically aligned to its size */
  768. srmmu_context_table = __srmmu_get_nocache(num_contexts * sizeof(ctxd_t), num_contexts * sizeof(ctxd_t));
  769. srmmu_ctx_table_phys = (ctxd_t *)__nocache_pa((unsigned long)srmmu_context_table);
  770. for (i = 0; i < num_contexts; i++)
  771. srmmu_ctxd_set((ctxd_t *)__nocache_fix(&srmmu_context_table[i]), srmmu_swapper_pg_dir);
  772. flush_cache_all();
  773. srmmu_set_ctable_ptr((unsigned long)srmmu_ctx_table_phys);
  774. #ifdef CONFIG_SMP
  775. /* Stop from hanging here... */
  776. local_ops->tlb_all();
  777. #else
  778. flush_tlb_all();
  779. #endif
  780. poke_srmmu();
  781. srmmu_allocate_ptable_skeleton(sparc_iomap.start, IOBASE_END);
  782. srmmu_allocate_ptable_skeleton(DVMA_VADDR, DVMA_END);
  783. srmmu_allocate_ptable_skeleton(
  784. __fix_to_virt(__end_of_fixed_addresses - 1), FIXADDR_TOP);
  785. srmmu_allocate_ptable_skeleton(PKMAP_BASE, PKMAP_END);
  786. pgd = pgd_offset_k(PKMAP_BASE);
  787. pmd = pmd_offset(pgd, PKMAP_BASE);
  788. pte = pte_offset_kernel(pmd, PKMAP_BASE);
  789. pkmap_page_table = pte;
  790. flush_cache_all();
  791. flush_tlb_all();
  792. sparc_context_init(num_contexts);
  793. kmap_init();
  794. {
  795. unsigned long zones_size[MAX_NR_ZONES];
  796. unsigned long zholes_size[MAX_NR_ZONES];
  797. unsigned long npages;
  798. int znum;
  799. for (znum = 0; znum < MAX_NR_ZONES; znum++)
  800. zones_size[znum] = zholes_size[znum] = 0;
  801. npages = max_low_pfn - pfn_base;
  802. zones_size[ZONE_DMA] = npages;
  803. zholes_size[ZONE_DMA] = npages - pages_avail;
  804. npages = highend_pfn - max_low_pfn;
  805. zones_size[ZONE_HIGHMEM] = npages;
  806. zholes_size[ZONE_HIGHMEM] = npages - calc_highpages();
  807. free_area_init_node(0, zones_size, pfn_base, zholes_size);
  808. }
  809. }
  810. void mmu_info(struct seq_file *m)
  811. {
  812. seq_printf(m,
  813. "MMU type\t: %s\n"
  814. "contexts\t: %d\n"
  815. "nocache total\t: %ld\n"
  816. "nocache used\t: %d\n",
  817. srmmu_name,
  818. num_contexts,
  819. srmmu_nocache_size,
  820. srmmu_nocache_map.used << SRMMU_NOCACHE_BITMAP_SHIFT);
  821. }
  822. int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
  823. {
  824. mm->context = NO_CONTEXT;
  825. return 0;
  826. }
  827. void destroy_context(struct mm_struct *mm)
  828. {
  829. if (mm->context != NO_CONTEXT) {
  830. flush_cache_mm(mm);
  831. srmmu_ctxd_set(&srmmu_context_table[mm->context], srmmu_swapper_pg_dir);
  832. flush_tlb_mm(mm);
  833. spin_lock(&srmmu_context_spinlock);
  834. free_context(mm->context);
  835. spin_unlock(&srmmu_context_spinlock);
  836. mm->context = NO_CONTEXT;
  837. }
  838. }
  839. /* Init various srmmu chip types. */
  840. static void __init srmmu_is_bad(void)
  841. {
  842. prom_printf("Could not determine SRMMU chip type.\n");
  843. prom_halt();
  844. }
  845. static void __init init_vac_layout(void)
  846. {
  847. phandle nd;
  848. int cache_lines;
  849. char node_str[128];
  850. #ifdef CONFIG_SMP
  851. int cpu = 0;
  852. unsigned long max_size = 0;
  853. unsigned long min_line_size = 0x10000000;
  854. #endif
  855. nd = prom_getchild(prom_root_node);
  856. while ((nd = prom_getsibling(nd)) != 0) {
  857. prom_getstring(nd, "device_type", node_str, sizeof(node_str));
  858. if (!strcmp(node_str, "cpu")) {
  859. vac_line_size = prom_getint(nd, "cache-line-size");
  860. if (vac_line_size == -1) {
  861. prom_printf("can't determine cache-line-size, halting.\n");
  862. prom_halt();
  863. }
  864. cache_lines = prom_getint(nd, "cache-nlines");
  865. if (cache_lines == -1) {
  866. prom_printf("can't determine cache-nlines, halting.\n");
  867. prom_halt();
  868. }
  869. vac_cache_size = cache_lines * vac_line_size;
  870. #ifdef CONFIG_SMP
  871. if (vac_cache_size > max_size)
  872. max_size = vac_cache_size;
  873. if (vac_line_size < min_line_size)
  874. min_line_size = vac_line_size;
  875. //FIXME: cpus not contiguous!!
  876. cpu++;
  877. if (cpu >= nr_cpu_ids || !cpu_online(cpu))
  878. break;
  879. #else
  880. break;
  881. #endif
  882. }
  883. }
  884. if (nd == 0) {
  885. prom_printf("No CPU nodes found, halting.\n");
  886. prom_halt();
  887. }
  888. #ifdef CONFIG_SMP
  889. vac_cache_size = max_size;
  890. vac_line_size = min_line_size;
  891. #endif
  892. printk("SRMMU: Using VAC size of %d bytes, line size %d bytes.\n",
  893. (int)vac_cache_size, (int)vac_line_size);
  894. }
  895. static void __cpuinit poke_hypersparc(void)
  896. {
  897. volatile unsigned long clear;
  898. unsigned long mreg = srmmu_get_mmureg();
  899. hyper_flush_unconditional_combined();
  900. mreg &= ~(HYPERSPARC_CWENABLE);
  901. mreg |= (HYPERSPARC_CENABLE | HYPERSPARC_WBENABLE);
  902. mreg |= (HYPERSPARC_CMODE);
  903. srmmu_set_mmureg(mreg);
  904. #if 0 /* XXX I think this is bad news... -DaveM */
  905. hyper_clear_all_tags();
  906. #endif
  907. put_ross_icr(HYPERSPARC_ICCR_FTD | HYPERSPARC_ICCR_ICE);
  908. hyper_flush_whole_icache();
  909. clear = srmmu_get_faddr();
  910. clear = srmmu_get_fstatus();
  911. }
  912. static const struct sparc32_cachetlb_ops hypersparc_ops = {
  913. .cache_all = hypersparc_flush_cache_all,
  914. .cache_mm = hypersparc_flush_cache_mm,
  915. .cache_page = hypersparc_flush_cache_page,
  916. .cache_range = hypersparc_flush_cache_range,
  917. .tlb_all = hypersparc_flush_tlb_all,
  918. .tlb_mm = hypersparc_flush_tlb_mm,
  919. .tlb_page = hypersparc_flush_tlb_page,
  920. .tlb_range = hypersparc_flush_tlb_range,
  921. .page_to_ram = hypersparc_flush_page_to_ram,
  922. .sig_insns = hypersparc_flush_sig_insns,
  923. .page_for_dma = hypersparc_flush_page_for_dma,
  924. };
  925. static void __init init_hypersparc(void)
  926. {
  927. srmmu_name = "ROSS HyperSparc";
  928. srmmu_modtype = HyperSparc;
  929. init_vac_layout();
  930. is_hypersparc = 1;
  931. sparc32_cachetlb_ops = &hypersparc_ops;
  932. poke_srmmu = poke_hypersparc;
  933. hypersparc_setup_blockops();
  934. }
  935. static void __cpuinit poke_swift(void)
  936. {
  937. unsigned long mreg;
  938. /* Clear any crap from the cache or else... */
  939. swift_flush_cache_all();
  940. /* Enable I & D caches */
  941. mreg = srmmu_get_mmureg();
  942. mreg |= (SWIFT_IE | SWIFT_DE);
  943. /*
  944. * The Swift branch folding logic is completely broken. At
  945. * trap time, if things are just right, if can mistakenly
  946. * think that a trap is coming from kernel mode when in fact
  947. * it is coming from user mode (it mis-executes the branch in
  948. * the trap code). So you see things like crashme completely
  949. * hosing your machine which is completely unacceptable. Turn
  950. * this shit off... nice job Fujitsu.
  951. */
  952. mreg &= ~(SWIFT_BF);
  953. srmmu_set_mmureg(mreg);
  954. }
  955. static const struct sparc32_cachetlb_ops swift_ops = {
  956. .cache_all = swift_flush_cache_all,
  957. .cache_mm = swift_flush_cache_mm,
  958. .cache_page = swift_flush_cache_page,
  959. .cache_range = swift_flush_cache_range,
  960. .tlb_all = swift_flush_tlb_all,
  961. .tlb_mm = swift_flush_tlb_mm,
  962. .tlb_page = swift_flush_tlb_page,
  963. .tlb_range = swift_flush_tlb_range,
  964. .page_to_ram = swift_flush_page_to_ram,
  965. .sig_insns = swift_flush_sig_insns,
  966. .page_for_dma = swift_flush_page_for_dma,
  967. };
  968. #define SWIFT_MASKID_ADDR 0x10003018
  969. static void __init init_swift(void)
  970. {
  971. unsigned long swift_rev;
  972. __asm__ __volatile__("lda [%1] %2, %0\n\t"
  973. "srl %0, 0x18, %0\n\t" :
  974. "=r" (swift_rev) :
  975. "r" (SWIFT_MASKID_ADDR), "i" (ASI_M_BYPASS));
  976. srmmu_name = "Fujitsu Swift";
  977. switch (swift_rev) {
  978. case 0x11:
  979. case 0x20:
  980. case 0x23:
  981. case 0x30:
  982. srmmu_modtype = Swift_lots_o_bugs;
  983. hwbug_bitmask |= (HWBUG_KERN_ACCBROKEN | HWBUG_KERN_CBITBROKEN);
  984. /*
  985. * Gee george, I wonder why Sun is so hush hush about
  986. * this hardware bug... really braindamage stuff going
  987. * on here. However I think we can find a way to avoid
  988. * all of the workaround overhead under Linux. Basically,
  989. * any page fault can cause kernel pages to become user
  990. * accessible (the mmu gets confused and clears some of
  991. * the ACC bits in kernel ptes). Aha, sounds pretty
  992. * horrible eh? But wait, after extensive testing it appears
  993. * that if you use pgd_t level large kernel pte's (like the
  994. * 4MB pages on the Pentium) the bug does not get tripped
  995. * at all. This avoids almost all of the major overhead.
  996. * Welcome to a world where your vendor tells you to,
  997. * "apply this kernel patch" instead of "sorry for the
  998. * broken hardware, send it back and we'll give you
  999. * properly functioning parts"
  1000. */
  1001. break;
  1002. case 0x25:
  1003. case 0x31:
  1004. srmmu_modtype = Swift_bad_c;
  1005. hwbug_bitmask |= HWBUG_KERN_CBITBROKEN;
  1006. /*
  1007. * You see Sun allude to this hardware bug but never
  1008. * admit things directly, they'll say things like,
  1009. * "the Swift chip cache problems" or similar.
  1010. */
  1011. break;
  1012. default:
  1013. srmmu_modtype = Swift_ok;
  1014. break;
  1015. }
  1016. sparc32_cachetlb_ops = &swift_ops;
  1017. flush_page_for_dma_global = 0;
  1018. /*
  1019. * Are you now convinced that the Swift is one of the
  1020. * biggest VLSI abortions of all time? Bravo Fujitsu!
  1021. * Fujitsu, the !#?!%$'d up processor people. I bet if
  1022. * you examined the microcode of the Swift you'd find
  1023. * XXX's all over the place.
  1024. */
  1025. poke_srmmu = poke_swift;
  1026. }
  1027. static void turbosparc_flush_cache_all(void)
  1028. {
  1029. flush_user_windows();
  1030. turbosparc_idflash_clear();
  1031. }
  1032. static void turbosparc_flush_cache_mm(struct mm_struct *mm)
  1033. {
  1034. FLUSH_BEGIN(mm)
  1035. flush_user_windows();
  1036. turbosparc_idflash_clear();
  1037. FLUSH_END
  1038. }
  1039. static void turbosparc_flush_cache_range(struct vm_area_struct *vma, unsigned long start, unsigned long end)
  1040. {
  1041. FLUSH_BEGIN(vma->vm_mm)
  1042. flush_user_windows();
  1043. turbosparc_idflash_clear();
  1044. FLUSH_END
  1045. }
  1046. static void turbosparc_flush_cache_page(struct vm_area_struct *vma, unsigned long page)
  1047. {
  1048. FLUSH_BEGIN(vma->vm_mm)
  1049. flush_user_windows();
  1050. if (vma->vm_flags & VM_EXEC)
  1051. turbosparc_flush_icache();
  1052. turbosparc_flush_dcache();
  1053. FLUSH_END
  1054. }
  1055. /* TurboSparc is copy-back, if we turn it on, but this does not work. */
  1056. static void turbosparc_flush_page_to_ram(unsigned long page)
  1057. {
  1058. #ifdef TURBOSPARC_WRITEBACK
  1059. volatile unsigned long clear;
  1060. if (srmmu_probe(page))
  1061. turbosparc_flush_page_cache(page);
  1062. clear = srmmu_get_fstatus();
  1063. #endif
  1064. }
  1065. static void turbosparc_flush_sig_insns(struct mm_struct *mm, unsigned long insn_addr)
  1066. {
  1067. }
  1068. static void turbosparc_flush_page_for_dma(unsigned long page)
  1069. {
  1070. turbosparc_flush_dcache();
  1071. }
  1072. static void turbosparc_flush_tlb_all(void)
  1073. {
  1074. srmmu_flush_whole_tlb();
  1075. }
  1076. static void turbosparc_flush_tlb_mm(struct mm_struct *mm)
  1077. {
  1078. FLUSH_BEGIN(mm)
  1079. srmmu_flush_whole_tlb();
  1080. FLUSH_END
  1081. }
  1082. static void turbosparc_flush_tlb_range(struct vm_area_struct *vma, unsigned long start, unsigned long end)
  1083. {
  1084. FLUSH_BEGIN(vma->vm_mm)
  1085. srmmu_flush_whole_tlb();
  1086. FLUSH_END
  1087. }
  1088. static void turbosparc_flush_tlb_page(struct vm_area_struct *vma, unsigned long page)
  1089. {
  1090. FLUSH_BEGIN(vma->vm_mm)
  1091. srmmu_flush_whole_tlb();
  1092. FLUSH_END
  1093. }
  1094. static void __cpuinit poke_turbosparc(void)
  1095. {
  1096. unsigned long mreg = srmmu_get_mmureg();
  1097. unsigned long ccreg;
  1098. /* Clear any crap from the cache or else... */
  1099. turbosparc_flush_cache_all();
  1100. /* Temporarily disable I & D caches */
  1101. mreg &= ~(TURBOSPARC_ICENABLE | TURBOSPARC_DCENABLE);
  1102. mreg &= ~(TURBOSPARC_PCENABLE); /* Don't check parity */
  1103. srmmu_set_mmureg(mreg);
  1104. ccreg = turbosparc_get_ccreg();
  1105. #ifdef TURBOSPARC_WRITEBACK
  1106. ccreg |= (TURBOSPARC_SNENABLE); /* Do DVMA snooping in Dcache */
  1107. ccreg &= ~(TURBOSPARC_uS2 | TURBOSPARC_WTENABLE);
  1108. /* Write-back D-cache, emulate VLSI
  1109. * abortion number three, not number one */
  1110. #else
  1111. /* For now let's play safe, optimize later */
  1112. ccreg |= (TURBOSPARC_SNENABLE | TURBOSPARC_WTENABLE);
  1113. /* Do DVMA snooping in Dcache, Write-thru D-cache */
  1114. ccreg &= ~(TURBOSPARC_uS2);
  1115. /* Emulate VLSI abortion number three, not number one */
  1116. #endif
  1117. switch (ccreg & 7) {
  1118. case 0: /* No SE cache */
  1119. case 7: /* Test mode */
  1120. break;
  1121. default:
  1122. ccreg |= (TURBOSPARC_SCENABLE);
  1123. }
  1124. turbosparc_set_ccreg(ccreg);
  1125. mreg |= (TURBOSPARC_ICENABLE | TURBOSPARC_DCENABLE); /* I & D caches on */
  1126. mreg |= (TURBOSPARC_ICSNOOP); /* Icache snooping on */
  1127. srmmu_set_mmureg(mreg);
  1128. }
  1129. static const struct sparc32_cachetlb_ops turbosparc_ops = {
  1130. .cache_all = turbosparc_flush_cache_all,
  1131. .cache_mm = turbosparc_flush_cache_mm,
  1132. .cache_page = turbosparc_flush_cache_page,
  1133. .cache_range = turbosparc_flush_cache_range,
  1134. .tlb_all = turbosparc_flush_tlb_all,
  1135. .tlb_mm = turbosparc_flush_tlb_mm,
  1136. .tlb_page = turbosparc_flush_tlb_page,
  1137. .tlb_range = turbosparc_flush_tlb_range,
  1138. .page_to_ram = turbosparc_flush_page_to_ram,
  1139. .sig_insns = turbosparc_flush_sig_insns,
  1140. .page_for_dma = turbosparc_flush_page_for_dma,
  1141. };
  1142. static void __init init_turbosparc(void)
  1143. {
  1144. srmmu_name = "Fujitsu TurboSparc";
  1145. srmmu_modtype = TurboSparc;
  1146. sparc32_cachetlb_ops = &turbosparc_ops;
  1147. poke_srmmu = poke_turbosparc;
  1148. }
  1149. static void __cpuinit poke_tsunami(void)
  1150. {
  1151. unsigned long mreg = srmmu_get_mmureg();
  1152. tsunami_flush_icache();
  1153. tsunami_flush_dcache();
  1154. mreg &= ~TSUNAMI_ITD;
  1155. mreg |= (TSUNAMI_IENAB | TSUNAMI_DENAB);
  1156. srmmu_set_mmureg(mreg);
  1157. }
  1158. static const struct sparc32_cachetlb_ops tsunami_ops = {
  1159. .cache_all = tsunami_flush_cache_all,
  1160. .cache_mm = tsunami_flush_cache_mm,
  1161. .cache_page = tsunami_flush_cache_page,
  1162. .cache_range = tsunami_flush_cache_range,
  1163. .tlb_all = tsunami_flush_tlb_all,
  1164. .tlb_mm = tsunami_flush_tlb_mm,
  1165. .tlb_page = tsunami_flush_tlb_page,
  1166. .tlb_range = tsunami_flush_tlb_range,
  1167. .page_to_ram = tsunami_flush_page_to_ram,
  1168. .sig_insns = tsunami_flush_sig_insns,
  1169. .page_for_dma = tsunami_flush_page_for_dma,
  1170. };
  1171. static void __init init_tsunami(void)
  1172. {
  1173. /*
  1174. * Tsunami's pretty sane, Sun and TI actually got it
  1175. * somewhat right this time. Fujitsu should have
  1176. * taken some lessons from them.
  1177. */
  1178. srmmu_name = "TI Tsunami";
  1179. srmmu_modtype = Tsunami;
  1180. sparc32_cachetlb_ops = &tsunami_ops;
  1181. poke_srmmu = poke_tsunami;
  1182. tsunami_setup_blockops();
  1183. }
  1184. static void __cpuinit poke_viking(void)
  1185. {
  1186. unsigned long mreg = srmmu_get_mmureg();
  1187. static int smp_catch;
  1188. if (viking_mxcc_present) {
  1189. unsigned long mxcc_control = mxcc_get_creg();
  1190. mxcc_control |= (MXCC_CTL_ECE | MXCC_CTL_PRE | MXCC_CTL_MCE);
  1191. mxcc_control &= ~(MXCC_CTL_RRC);
  1192. mxcc_set_creg(mxcc_control);
  1193. /*
  1194. * We don't need memory parity checks.
  1195. * XXX This is a mess, have to dig out later. ecd.
  1196. viking_mxcc_turn_off_parity(&mreg, &mxcc_control);
  1197. */
  1198. /* We do cache ptables on MXCC. */
  1199. mreg |= VIKING_TCENABLE;
  1200. } else {
  1201. unsigned long bpreg;
  1202. mreg &= ~(VIKING_TCENABLE);
  1203. if (smp_catch++) {
  1204. /* Must disable mixed-cmd mode here for other cpu's. */
  1205. bpreg = viking_get_bpreg();
  1206. bpreg &= ~(VIKING_ACTION_MIX);
  1207. viking_set_bpreg(bpreg);
  1208. /* Just in case PROM does something funny. */
  1209. msi_set_sync();
  1210. }
  1211. }
  1212. mreg |= VIKING_SPENABLE;
  1213. mreg |= (VIKING_ICENABLE | VIKING_DCENABLE);
  1214. mreg |= VIKING_SBENABLE;
  1215. mreg &= ~(VIKING_ACENABLE);
  1216. srmmu_set_mmureg(mreg);
  1217. }
  1218. static struct sparc32_cachetlb_ops viking_ops = {
  1219. .cache_all = viking_flush_cache_all,
  1220. .cache_mm = viking_flush_cache_mm,
  1221. .cache_page = viking_flush_cache_page,
  1222. .cache_range = viking_flush_cache_range,
  1223. .tlb_all = viking_flush_tlb_all,
  1224. .tlb_mm = viking_flush_tlb_mm,
  1225. .tlb_page = viking_flush_tlb_page,
  1226. .tlb_range = viking_flush_tlb_range,
  1227. .page_to_ram = viking_flush_page_to_ram,
  1228. .sig_insns = viking_flush_sig_insns,
  1229. .page_for_dma = viking_flush_page_for_dma,
  1230. };
  1231. #ifdef CONFIG_SMP
  1232. /* On sun4d the cpu broadcasts local TLB flushes, so we can just
  1233. * perform the local TLB flush and all the other cpus will see it.
  1234. * But, unfortunately, there is a bug in the sun4d XBUS backplane
  1235. * that requires that we add some synchronization to these flushes.
  1236. *
  1237. * The bug is that the fifo which keeps track of all the pending TLB
  1238. * broadcasts in the system is an entry or two too small, so if we
  1239. * have too many going at once we'll overflow that fifo and lose a TLB
  1240. * flush resulting in corruption.
  1241. *
  1242. * Our workaround is to take a global spinlock around the TLB flushes,
  1243. * which guarentees we won't ever have too many pending. It's a big
  1244. * hammer, but a semaphore like system to make sure we only have N TLB
  1245. * flushes going at once will require SMP locking anyways so there's
  1246. * no real value in trying any harder than this.
  1247. */
  1248. static struct sparc32_cachetlb_ops viking_sun4d_smp_ops = {
  1249. .cache_all = viking_flush_cache_all,
  1250. .cache_mm = viking_flush_cache_mm,
  1251. .cache_page = viking_flush_cache_page,
  1252. .cache_range = viking_flush_cache_range,
  1253. .tlb_all = sun4dsmp_flush_tlb_all,
  1254. .tlb_mm = sun4dsmp_flush_tlb_mm,
  1255. .tlb_page = sun4dsmp_flush_tlb_page,
  1256. .tlb_range = sun4dsmp_flush_tlb_range,
  1257. .page_to_ram = viking_flush_page_to_ram,
  1258. .sig_insns = viking_flush_sig_insns,
  1259. .page_for_dma = viking_flush_page_for_dma,
  1260. };
  1261. #endif
  1262. static void __init init_viking(void)
  1263. {
  1264. unsigned long mreg = srmmu_get_mmureg();
  1265. /* Ahhh, the viking. SRMMU VLSI abortion number two... */
  1266. if (mreg & VIKING_MMODE) {
  1267. srmmu_name = "TI Viking";
  1268. viking_mxcc_present = 0;
  1269. msi_set_sync();
  1270. /*
  1271. * We need this to make sure old viking takes no hits
  1272. * on it's cache for dma snoops to workaround the
  1273. * "load from non-cacheable memory" interrupt bug.
  1274. * This is only necessary because of the new way in
  1275. * which we use the IOMMU.
  1276. */
  1277. viking_ops.page_for_dma = viking_flush_page;
  1278. #ifdef CONFIG_SMP
  1279. viking_sun4d_smp_ops.page_for_dma = viking_flush_page;
  1280. #endif
  1281. flush_page_for_dma_global = 0;
  1282. } else {
  1283. srmmu_name = "TI Viking/MXCC";
  1284. viking_mxcc_present = 1;
  1285. srmmu_cache_pagetables = 1;
  1286. }
  1287. sparc32_cachetlb_ops = (const struct sparc32_cachetlb_ops *)
  1288. &viking_ops;
  1289. #ifdef CONFIG_SMP
  1290. if (sparc_cpu_model == sun4d)
  1291. sparc32_cachetlb_ops = (const struct sparc32_cachetlb_ops *)
  1292. &viking_sun4d_smp_ops;
  1293. #endif
  1294. poke_srmmu = poke_viking;
  1295. }
  1296. /* Probe for the srmmu chip version. */
  1297. static void __init get_srmmu_type(void)
  1298. {
  1299. unsigned long mreg, psr;
  1300. unsigned long mod_typ, mod_rev, psr_typ, psr_vers;
  1301. srmmu_modtype = SRMMU_INVAL_MOD;
  1302. hwbug_bitmask = 0;
  1303. mreg = srmmu_get_mmureg(); psr = get_psr();
  1304. mod_typ = (mreg & 0xf0000000) >> 28;
  1305. mod_rev = (mreg & 0x0f000000) >> 24;
  1306. psr_typ = (psr >> 28) & 0xf;
  1307. psr_vers = (psr >> 24) & 0xf;
  1308. /* First, check for sparc-leon. */
  1309. if (sparc_cpu_model == sparc_leon) {
  1310. init_leon();
  1311. return;
  1312. }
  1313. /* Second, check for HyperSparc or Cypress. */
  1314. if (mod_typ == 1) {
  1315. switch (mod_rev) {
  1316. case 7:
  1317. /* UP or MP Hypersparc */
  1318. init_hypersparc();
  1319. break;
  1320. case 0:
  1321. case 2:
  1322. case 10:
  1323. case 11:
  1324. case 12:
  1325. case 13:
  1326. case 14:
  1327. case 15:
  1328. default:
  1329. prom_printf("Sparc-Linux Cypress support does not longer exit.\n");
  1330. prom_halt();
  1331. break;
  1332. }
  1333. return;
  1334. }
  1335. /* Now Fujitsu TurboSparc. It might happen that it is
  1336. * in Swift emulation mode, so we will check later...
  1337. */
  1338. if (psr_typ == 0 && psr_vers == 5) {
  1339. init_turbosparc();
  1340. return;
  1341. }
  1342. /* Next check for Fujitsu Swift. */
  1343. if (psr_typ == 0 && psr_vers == 4) {
  1344. phandle cpunode;
  1345. char node_str[128];
  1346. /* Look if it is not a TurboSparc emulating Swift... */
  1347. cpunode = prom_getchild(prom_root_node);
  1348. while ((cpunode = prom_getsibling(cpunode)) != 0) {
  1349. prom_getstring(cpunode, "device_type", node_str, sizeof(node_str));
  1350. if (!strcmp(node_str, "cpu")) {
  1351. if (!prom_getintdefault(cpunode, "psr-implementation", 1) &&
  1352. prom_getintdefault(cpunode, "psr-version", 1) == 5) {
  1353. init_turbosparc();
  1354. return;
  1355. }
  1356. break;
  1357. }
  1358. }
  1359. init_swift();
  1360. return;
  1361. }
  1362. /* Now the Viking family of srmmu. */
  1363. if (psr_typ == 4 &&
  1364. ((psr_vers == 0) ||
  1365. ((psr_vers == 1) && (mod_typ == 0) && (mod_rev == 0)))) {
  1366. init_viking();
  1367. return;
  1368. }
  1369. /* Finally the Tsunami. */
  1370. if (psr_typ == 4 && psr_vers == 1 && (mod_typ || mod_rev)) {
  1371. init_tsunami();
  1372. return;
  1373. }
  1374. /* Oh well */
  1375. srmmu_is_bad();
  1376. }
  1377. #ifdef CONFIG_SMP
  1378. /* Local cross-calls. */
  1379. static void smp_flush_page_for_dma(unsigned long page)
  1380. {
  1381. xc1((smpfunc_t) local_ops->page_for_dma, page);
  1382. local_ops->page_for_dma(page);
  1383. }
  1384. static void smp_flush_cache_all(void)
  1385. {
  1386. xc0((smpfunc_t) local_ops->cache_all);
  1387. local_ops->cache_all();
  1388. }
  1389. static void smp_flush_tlb_all(void)
  1390. {
  1391. xc0((smpfunc_t) local_ops->tlb_all);
  1392. local_ops->tlb_all();
  1393. }
  1394. static void smp_flush_cache_mm(struct mm_struct *mm)
  1395. {
  1396. if (mm->context != NO_CONTEXT) {
  1397. cpumask_t cpu_mask;
  1398. cpumask_copy(&cpu_mask, mm_cpumask(mm));
  1399. cpumask_clear_cpu(smp_processor_id(), &cpu_mask);
  1400. if (!cpumask_empty(&cpu_mask))
  1401. xc1((smpfunc_t) local_ops->cache_mm, (unsigned long) mm);
  1402. local_ops->cache_mm(mm);
  1403. }
  1404. }
  1405. static void smp_flush_tlb_mm(struct mm_struct *mm)
  1406. {
  1407. if (mm->context != NO_CONTEXT) {
  1408. cpumask_t cpu_mask;
  1409. cpumask_copy(&cpu_mask, mm_cpumask(mm));
  1410. cpumask_clear_cpu(smp_processor_id(), &cpu_mask);
  1411. if (!cpumask_empty(&cpu_mask)) {
  1412. xc1((smpfunc_t) local_ops->tlb_mm, (unsigned long) mm);
  1413. if (atomic_read(&mm->mm_users) == 1 && current->active_mm == mm)
  1414. cpumask_copy(mm_cpumask(mm),
  1415. cpumask_of(smp_processor_id()));
  1416. }
  1417. local_ops->tlb_mm(mm);
  1418. }
  1419. }
  1420. static void smp_flush_cache_range(struct vm_area_struct *vma,
  1421. unsigned long start,
  1422. unsigned long end)
  1423. {
  1424. struct mm_struct *mm = vma->vm_mm;
  1425. if (mm->context != NO_CONTEXT) {
  1426. cpumask_t cpu_mask;
  1427. cpumask_copy(&cpu_mask, mm_cpumask(mm));
  1428. cpumask_clear_cpu(smp_processor_id(), &cpu_mask);
  1429. if (!cpumask_empty(&cpu_mask))
  1430. xc3((smpfunc_t) local_ops->cache_range,
  1431. (unsigned long) vma, start, end);
  1432. local_ops->cache_range(vma, start, end);
  1433. }
  1434. }
  1435. static void smp_flush_tlb_range(struct vm_area_struct *vma,
  1436. unsigned long start,
  1437. unsigned long end)
  1438. {
  1439. struct mm_struct *mm = vma->vm_mm;
  1440. if (mm->context != NO_CONTEXT) {
  1441. cpumask_t cpu_mask;
  1442. cpumask_copy(&cpu_mask, mm_cpumask(mm));
  1443. cpumask_clear_cpu(smp_processor_id(), &cpu_mask);
  1444. if (!cpumask_empty(&cpu_mask))
  1445. xc3((smpfunc_t) local_ops->tlb_range,
  1446. (unsigned long) vma, start, end);
  1447. local_ops->tlb_range(vma, start, end);
  1448. }
  1449. }
  1450. static void smp_flush_cache_page(struct vm_area_struct *vma, unsigned long page)
  1451. {
  1452. struct mm_struct *mm = vma->vm_mm;
  1453. if (mm->context != NO_CONTEXT) {
  1454. cpumask_t cpu_mask;
  1455. cpumask_copy(&cpu_mask, mm_cpumask(mm));
  1456. cpumask_clear_cpu(smp_processor_id(), &cpu_mask);
  1457. if (!cpumask_empty(&cpu_mask))
  1458. xc2((smpfunc_t) local_ops->cache_page,
  1459. (unsigned long) vma, page);
  1460. local_ops->cache_page(vma, page);
  1461. }
  1462. }
  1463. static void smp_flush_tlb_page(struct vm_area_struct *vma, unsigned long page)
  1464. {
  1465. struct mm_struct *mm = vma->vm_mm;
  1466. if (mm->context != NO_CONTEXT) {
  1467. cpumask_t cpu_mask;
  1468. cpumask_copy(&cpu_mask, mm_cpumask(mm));
  1469. cpumask_clear_cpu(smp_processor_id(), &cpu_mask);
  1470. if (!cpumask_empty(&cpu_mask))
  1471. xc2((smpfunc_t) local_ops->tlb_page,
  1472. (unsigned long) vma, page);
  1473. local_ops->tlb_page(vma, page);
  1474. }
  1475. }
  1476. static void smp_flush_page_to_ram(unsigned long page)
  1477. {
  1478. /* Current theory is that those who call this are the one's
  1479. * who have just dirtied their cache with the pages contents
  1480. * in kernel space, therefore we only run this on local cpu.
  1481. *
  1482. * XXX This experiment failed, research further... -DaveM
  1483. */
  1484. #if 1
  1485. xc1((smpfunc_t) local_ops->page_to_ram, page);
  1486. #endif
  1487. local_ops->page_to_ram(page);
  1488. }
  1489. static void smp_flush_sig_insns(struct mm_struct *mm, unsigned long insn_addr)
  1490. {
  1491. cpumask_t cpu_mask;
  1492. cpumask_copy(&cpu_mask, mm_cpumask(mm));
  1493. cpumask_clear_cpu(smp_processor_id(), &cpu_mask);
  1494. if (!cpumask_empty(&cpu_mask))
  1495. xc2((smpfunc_t) local_ops->sig_insns,
  1496. (unsigned long) mm, insn_addr);
  1497. local_ops->sig_insns(mm, insn_addr);
  1498. }
  1499. static struct sparc32_cachetlb_ops smp_cachetlb_ops = {
  1500. .cache_all = smp_flush_cache_all,
  1501. .cache_mm = smp_flush_cache_mm,
  1502. .cache_page = smp_flush_cache_page,
  1503. .cache_range = smp_flush_cache_range,
  1504. .tlb_all = smp_flush_tlb_all,
  1505. .tlb_mm = smp_flush_tlb_mm,
  1506. .tlb_page = smp_flush_tlb_page,
  1507. .tlb_range = smp_flush_tlb_range,
  1508. .page_to_ram = smp_flush_page_to_ram,
  1509. .sig_insns = smp_flush_sig_insns,
  1510. .page_for_dma = smp_flush_page_for_dma,
  1511. };
  1512. #endif
  1513. /* Load up routines and constants for sun4m and sun4d mmu */
  1514. void __init load_mmu(void)
  1515. {
  1516. extern void ld_mmu_iommu(void);
  1517. extern void ld_mmu_iounit(void);
  1518. /* Functions */
  1519. get_srmmu_type();
  1520. #ifdef CONFIG_SMP
  1521. /* El switcheroo... */
  1522. local_ops = sparc32_cachetlb_ops;
  1523. if (sparc_cpu_model == sun4d || sparc_cpu_model == sparc_leon) {
  1524. smp_cachetlb_ops.tlb_all = local_ops->tlb_all;
  1525. smp_cachetlb_ops.tlb_mm = local_ops->tlb_mm;
  1526. smp_cachetlb_ops.tlb_range = local_ops->tlb_range;
  1527. smp_cachetlb_ops.tlb_page = local_ops->tlb_page;
  1528. }
  1529. if (poke_srmmu == poke_viking) {
  1530. /* Avoid unnecessary cross calls. */
  1531. smp_cachetlb_ops.cache_all = local_ops->cache_all;
  1532. smp_cachetlb_ops.cache_mm = local_ops->cache_mm;
  1533. smp_cachetlb_ops.cache_range = local_ops->cache_range;
  1534. smp_cachetlb_ops.cache_page = local_ops->cache_page;
  1535. smp_cachetlb_ops.page_to_ram = local_ops->page_to_ram;
  1536. smp_cachetlb_ops.sig_insns = local_ops->sig_insns;
  1537. smp_cachetlb_ops.page_for_dma = local_ops->page_for_dma;
  1538. }
  1539. /* It really is const after this point. */
  1540. sparc32_cachetlb_ops = (const struct sparc32_cachetlb_ops *)
  1541. &smp_cachetlb_ops;
  1542. #endif
  1543. if (sparc_cpu_model == sun4d)
  1544. ld_mmu_iounit();
  1545. else
  1546. ld_mmu_iommu();
  1547. #ifdef CONFIG_SMP
  1548. if (sparc_cpu_model == sun4d)
  1549. sun4d_init_smp();
  1550. else if (sparc_cpu_model == sparc_leon)
  1551. leon_init_smp();
  1552. else
  1553. sun4m_init_smp();
  1554. #endif
  1555. }