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