srmmu.c 49 KB

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