srmmu.c 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820
  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 "srmmu.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. void *srmmu_nocache_bitmap;
  83. static struct bit_map srmmu_nocache_map;
  84. static inline int srmmu_pmd_none(pmd_t pmd)
  85. { return !(pmd_val(pmd) & 0xFFFFFFF); }
  86. /* XXX should we hyper_flush_whole_icache here - Anton */
  87. static inline void srmmu_ctxd_set(ctxd_t *ctxp, pgd_t *pgdp)
  88. { set_pte((pte_t *)ctxp, (SRMMU_ET_PTD | (__nocache_pa((unsigned long) pgdp) >> 4))); }
  89. void pmd_set(pmd_t *pmdp, pte_t *ptep)
  90. {
  91. unsigned long ptp; /* Physical address, shifted right by 4 */
  92. int i;
  93. ptp = __nocache_pa((unsigned long) ptep) >> 4;
  94. for (i = 0; i < PTRS_PER_PTE/SRMMU_REAL_PTRS_PER_PTE; i++) {
  95. set_pte((pte_t *)&pmdp->pmdv[i], SRMMU_ET_PTD | ptp);
  96. ptp += (SRMMU_REAL_PTRS_PER_PTE*sizeof(pte_t) >> 4);
  97. }
  98. }
  99. void pmd_populate(struct mm_struct *mm, pmd_t *pmdp, struct page *ptep)
  100. {
  101. unsigned long ptp; /* Physical address, shifted right by 4 */
  102. int i;
  103. ptp = page_to_pfn(ptep) << (PAGE_SHIFT-4); /* watch for overflow */
  104. for (i = 0; i < PTRS_PER_PTE/SRMMU_REAL_PTRS_PER_PTE; i++) {
  105. set_pte((pte_t *)&pmdp->pmdv[i], SRMMU_ET_PTD | ptp);
  106. ptp += (SRMMU_REAL_PTRS_PER_PTE*sizeof(pte_t) >> 4);
  107. }
  108. }
  109. /* Find an entry in the third-level page table.. */
  110. pte_t *pte_offset_kernel(pmd_t *dir, unsigned long address)
  111. {
  112. void *pte;
  113. pte = __nocache_va((dir->pmdv[0] & SRMMU_PTD_PMASK) << 4);
  114. return (pte_t *) pte +
  115. ((address >> PAGE_SHIFT) & (PTRS_PER_PTE - 1));
  116. }
  117. /*
  118. * size: bytes to allocate in the nocache area.
  119. * align: bytes, number to align at.
  120. * Returns the virtual address of the allocated area.
  121. */
  122. static void *__srmmu_get_nocache(int size, int align)
  123. {
  124. int offset;
  125. unsigned long addr;
  126. if (size < SRMMU_NOCACHE_BITMAP_SHIFT) {
  127. printk(KERN_ERR "Size 0x%x too small for nocache request\n",
  128. size);
  129. size = SRMMU_NOCACHE_BITMAP_SHIFT;
  130. }
  131. if (size & (SRMMU_NOCACHE_BITMAP_SHIFT - 1)) {
  132. printk(KERN_ERR "Size 0x%x unaligned int nocache request\n",
  133. size);
  134. size += SRMMU_NOCACHE_BITMAP_SHIFT - 1;
  135. }
  136. BUG_ON(align > SRMMU_NOCACHE_ALIGN_MAX);
  137. offset = bit_map_string_get(&srmmu_nocache_map,
  138. size >> SRMMU_NOCACHE_BITMAP_SHIFT,
  139. align >> SRMMU_NOCACHE_BITMAP_SHIFT);
  140. if (offset == -1) {
  141. printk(KERN_ERR "srmmu: out of nocache %d: %d/%d\n",
  142. size, (int) srmmu_nocache_size,
  143. srmmu_nocache_map.used << SRMMU_NOCACHE_BITMAP_SHIFT);
  144. return 0;
  145. }
  146. addr = SRMMU_NOCACHE_VADDR + (offset << SRMMU_NOCACHE_BITMAP_SHIFT);
  147. return (void *)addr;
  148. }
  149. void *srmmu_get_nocache(int size, int align)
  150. {
  151. void *tmp;
  152. tmp = __srmmu_get_nocache(size, align);
  153. if (tmp)
  154. memset(tmp, 0, size);
  155. return tmp;
  156. }
  157. void srmmu_free_nocache(void *addr, int size)
  158. {
  159. unsigned long vaddr;
  160. int offset;
  161. vaddr = (unsigned long)addr;
  162. if (vaddr < SRMMU_NOCACHE_VADDR) {
  163. printk("Vaddr %lx is smaller than nocache base 0x%lx\n",
  164. vaddr, (unsigned long)SRMMU_NOCACHE_VADDR);
  165. BUG();
  166. }
  167. if (vaddr + size > srmmu_nocache_end) {
  168. printk("Vaddr %lx is bigger than nocache end 0x%lx\n",
  169. vaddr, srmmu_nocache_end);
  170. BUG();
  171. }
  172. if (!is_power_of_2(size)) {
  173. printk("Size 0x%x is not a power of 2\n", size);
  174. BUG();
  175. }
  176. if (size < SRMMU_NOCACHE_BITMAP_SHIFT) {
  177. printk("Size 0x%x is too small\n", size);
  178. BUG();
  179. }
  180. if (vaddr & (size - 1)) {
  181. printk("Vaddr %lx is not aligned to size 0x%x\n", vaddr, size);
  182. BUG();
  183. }
  184. offset = (vaddr - SRMMU_NOCACHE_VADDR) >> SRMMU_NOCACHE_BITMAP_SHIFT;
  185. size = size >> SRMMU_NOCACHE_BITMAP_SHIFT;
  186. bit_map_clear(&srmmu_nocache_map, offset, size);
  187. }
  188. static void srmmu_early_allocate_ptable_skeleton(unsigned long start,
  189. unsigned long end);
  190. /* Return how much physical memory we have. */
  191. static unsigned long __init probe_memory(void)
  192. {
  193. unsigned long total = 0;
  194. int i;
  195. for (i = 0; sp_banks[i].num_bytes; i++)
  196. total += sp_banks[i].num_bytes;
  197. return total;
  198. }
  199. /*
  200. * Reserve nocache dynamically proportionally to the amount of
  201. * system RAM. -- Tomas Szepe <szepe@pinerecords.com>, June 2002
  202. */
  203. static void __init srmmu_nocache_calcsize(void)
  204. {
  205. unsigned long sysmemavail = probe_memory() / 1024;
  206. int srmmu_nocache_npages;
  207. srmmu_nocache_npages =
  208. sysmemavail / SRMMU_NOCACHE_ALCRATIO / 1024 * 256;
  209. /* P3 XXX The 4x overuse: corroborated by /proc/meminfo. */
  210. // if (srmmu_nocache_npages < 256) srmmu_nocache_npages = 256;
  211. if (srmmu_nocache_npages < SRMMU_MIN_NOCACHE_PAGES)
  212. srmmu_nocache_npages = SRMMU_MIN_NOCACHE_PAGES;
  213. /* anything above 1280 blows up */
  214. if (srmmu_nocache_npages > SRMMU_MAX_NOCACHE_PAGES)
  215. srmmu_nocache_npages = SRMMU_MAX_NOCACHE_PAGES;
  216. srmmu_nocache_size = srmmu_nocache_npages * PAGE_SIZE;
  217. srmmu_nocache_end = SRMMU_NOCACHE_VADDR + srmmu_nocache_size;
  218. }
  219. static void __init srmmu_nocache_init(void)
  220. {
  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, 0);
  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. extern unsigned long bootmem_init(unsigned long *pages_avail);
  736. void __init srmmu_paging_init(void)
  737. {
  738. int i;
  739. phandle cpunode;
  740. char node_str[128];
  741. pgd_t *pgd;
  742. pmd_t *pmd;
  743. pte_t *pte;
  744. unsigned long pages_avail;
  745. init_mm.context = (unsigned long) NO_CONTEXT;
  746. sparc_iomap.start = SUN4M_IOBASE_VADDR; /* 16MB of IOSPACE on all sun4m's. */
  747. if (sparc_cpu_model == sun4d)
  748. num_contexts = 65536; /* We know it is Viking */
  749. else {
  750. /* Find the number of contexts on the srmmu. */
  751. cpunode = prom_getchild(prom_root_node);
  752. num_contexts = 0;
  753. while (cpunode != 0) {
  754. prom_getstring(cpunode, "device_type", node_str, sizeof(node_str));
  755. if (!strcmp(node_str, "cpu")) {
  756. num_contexts = prom_getintdefault(cpunode, "mmu-nctx", 0x8);
  757. break;
  758. }
  759. cpunode = prom_getsibling(cpunode);
  760. }
  761. }
  762. if (!num_contexts) {
  763. prom_printf("Something wrong, can't find cpu node in paging_init.\n");
  764. prom_halt();
  765. }
  766. pages_avail = 0;
  767. last_valid_pfn = bootmem_init(&pages_avail);
  768. srmmu_nocache_calcsize();
  769. srmmu_nocache_init();
  770. srmmu_inherit_prom_mappings(0xfe400000, (LINUX_OPPROM_ENDVM - PAGE_SIZE));
  771. map_kernel();
  772. /* ctx table has to be physically aligned to its size */
  773. srmmu_context_table = __srmmu_get_nocache(num_contexts * sizeof(ctxd_t), num_contexts * sizeof(ctxd_t));
  774. srmmu_ctx_table_phys = (ctxd_t *)__nocache_pa((unsigned long)srmmu_context_table);
  775. for (i = 0; i < num_contexts; i++)
  776. srmmu_ctxd_set((ctxd_t *)__nocache_fix(&srmmu_context_table[i]), srmmu_swapper_pg_dir);
  777. flush_cache_all();
  778. srmmu_set_ctable_ptr((unsigned long)srmmu_ctx_table_phys);
  779. #ifdef CONFIG_SMP
  780. /* Stop from hanging here... */
  781. local_ops->tlb_all();
  782. #else
  783. flush_tlb_all();
  784. #endif
  785. poke_srmmu();
  786. srmmu_allocate_ptable_skeleton(sparc_iomap.start, IOBASE_END);
  787. srmmu_allocate_ptable_skeleton(DVMA_VADDR, DVMA_END);
  788. srmmu_allocate_ptable_skeleton(
  789. __fix_to_virt(__end_of_fixed_addresses - 1), FIXADDR_TOP);
  790. srmmu_allocate_ptable_skeleton(PKMAP_BASE, PKMAP_END);
  791. pgd = pgd_offset_k(PKMAP_BASE);
  792. pmd = pmd_offset(pgd, PKMAP_BASE);
  793. pte = pte_offset_kernel(pmd, PKMAP_BASE);
  794. pkmap_page_table = pte;
  795. flush_cache_all();
  796. flush_tlb_all();
  797. sparc_context_init(num_contexts);
  798. kmap_init();
  799. {
  800. unsigned long zones_size[MAX_NR_ZONES];
  801. unsigned long zholes_size[MAX_NR_ZONES];
  802. unsigned long npages;
  803. int znum;
  804. for (znum = 0; znum < MAX_NR_ZONES; znum++)
  805. zones_size[znum] = zholes_size[znum] = 0;
  806. npages = max_low_pfn - pfn_base;
  807. zones_size[ZONE_DMA] = npages;
  808. zholes_size[ZONE_DMA] = npages - pages_avail;
  809. npages = highend_pfn - max_low_pfn;
  810. zones_size[ZONE_HIGHMEM] = npages;
  811. zholes_size[ZONE_HIGHMEM] = npages - calc_highpages();
  812. free_area_init_node(0, zones_size, pfn_base, zholes_size);
  813. }
  814. }
  815. void mmu_info(struct seq_file *m)
  816. {
  817. seq_printf(m,
  818. "MMU type\t: %s\n"
  819. "contexts\t: %d\n"
  820. "nocache total\t: %ld\n"
  821. "nocache used\t: %d\n",
  822. srmmu_name,
  823. num_contexts,
  824. srmmu_nocache_size,
  825. srmmu_nocache_map.used << SRMMU_NOCACHE_BITMAP_SHIFT);
  826. }
  827. int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
  828. {
  829. mm->context = NO_CONTEXT;
  830. return 0;
  831. }
  832. void destroy_context(struct mm_struct *mm)
  833. {
  834. if (mm->context != NO_CONTEXT) {
  835. flush_cache_mm(mm);
  836. srmmu_ctxd_set(&srmmu_context_table[mm->context], srmmu_swapper_pg_dir);
  837. flush_tlb_mm(mm);
  838. spin_lock(&srmmu_context_spinlock);
  839. free_context(mm->context);
  840. spin_unlock(&srmmu_context_spinlock);
  841. mm->context = NO_CONTEXT;
  842. }
  843. }
  844. /* Init various srmmu chip types. */
  845. static void __init srmmu_is_bad(void)
  846. {
  847. prom_printf("Could not determine SRMMU chip type.\n");
  848. prom_halt();
  849. }
  850. static void __init init_vac_layout(void)
  851. {
  852. phandle nd;
  853. int cache_lines;
  854. char node_str[128];
  855. #ifdef CONFIG_SMP
  856. int cpu = 0;
  857. unsigned long max_size = 0;
  858. unsigned long min_line_size = 0x10000000;
  859. #endif
  860. nd = prom_getchild(prom_root_node);
  861. while ((nd = prom_getsibling(nd)) != 0) {
  862. prom_getstring(nd, "device_type", node_str, sizeof(node_str));
  863. if (!strcmp(node_str, "cpu")) {
  864. vac_line_size = prom_getint(nd, "cache-line-size");
  865. if (vac_line_size == -1) {
  866. prom_printf("can't determine cache-line-size, halting.\n");
  867. prom_halt();
  868. }
  869. cache_lines = prom_getint(nd, "cache-nlines");
  870. if (cache_lines == -1) {
  871. prom_printf("can't determine cache-nlines, halting.\n");
  872. prom_halt();
  873. }
  874. vac_cache_size = cache_lines * vac_line_size;
  875. #ifdef CONFIG_SMP
  876. if (vac_cache_size > max_size)
  877. max_size = vac_cache_size;
  878. if (vac_line_size < min_line_size)
  879. min_line_size = vac_line_size;
  880. //FIXME: cpus not contiguous!!
  881. cpu++;
  882. if (cpu >= nr_cpu_ids || !cpu_online(cpu))
  883. break;
  884. #else
  885. break;
  886. #endif
  887. }
  888. }
  889. if (nd == 0) {
  890. prom_printf("No CPU nodes found, halting.\n");
  891. prom_halt();
  892. }
  893. #ifdef CONFIG_SMP
  894. vac_cache_size = max_size;
  895. vac_line_size = min_line_size;
  896. #endif
  897. printk("SRMMU: Using VAC size of %d bytes, line size %d bytes.\n",
  898. (int)vac_cache_size, (int)vac_line_size);
  899. }
  900. static void poke_hypersparc(void)
  901. {
  902. volatile unsigned long clear;
  903. unsigned long mreg = srmmu_get_mmureg();
  904. hyper_flush_unconditional_combined();
  905. mreg &= ~(HYPERSPARC_CWENABLE);
  906. mreg |= (HYPERSPARC_CENABLE | HYPERSPARC_WBENABLE);
  907. mreg |= (HYPERSPARC_CMODE);
  908. srmmu_set_mmureg(mreg);
  909. #if 0 /* XXX I think this is bad news... -DaveM */
  910. hyper_clear_all_tags();
  911. #endif
  912. put_ross_icr(HYPERSPARC_ICCR_FTD | HYPERSPARC_ICCR_ICE);
  913. hyper_flush_whole_icache();
  914. clear = srmmu_get_faddr();
  915. clear = srmmu_get_fstatus();
  916. }
  917. static const struct sparc32_cachetlb_ops hypersparc_ops = {
  918. .cache_all = hypersparc_flush_cache_all,
  919. .cache_mm = hypersparc_flush_cache_mm,
  920. .cache_page = hypersparc_flush_cache_page,
  921. .cache_range = hypersparc_flush_cache_range,
  922. .tlb_all = hypersparc_flush_tlb_all,
  923. .tlb_mm = hypersparc_flush_tlb_mm,
  924. .tlb_page = hypersparc_flush_tlb_page,
  925. .tlb_range = hypersparc_flush_tlb_range,
  926. .page_to_ram = hypersparc_flush_page_to_ram,
  927. .sig_insns = hypersparc_flush_sig_insns,
  928. .page_for_dma = hypersparc_flush_page_for_dma,
  929. };
  930. static void __init init_hypersparc(void)
  931. {
  932. srmmu_name = "ROSS HyperSparc";
  933. srmmu_modtype = HyperSparc;
  934. init_vac_layout();
  935. is_hypersparc = 1;
  936. sparc32_cachetlb_ops = &hypersparc_ops;
  937. poke_srmmu = poke_hypersparc;
  938. hypersparc_setup_blockops();
  939. }
  940. static void poke_swift(void)
  941. {
  942. unsigned long mreg;
  943. /* Clear any crap from the cache or else... */
  944. swift_flush_cache_all();
  945. /* Enable I & D caches */
  946. mreg = srmmu_get_mmureg();
  947. mreg |= (SWIFT_IE | SWIFT_DE);
  948. /*
  949. * The Swift branch folding logic is completely broken. At
  950. * trap time, if things are just right, if can mistakenly
  951. * think that a trap is coming from kernel mode when in fact
  952. * it is coming from user mode (it mis-executes the branch in
  953. * the trap code). So you see things like crashme completely
  954. * hosing your machine which is completely unacceptable. Turn
  955. * this shit off... nice job Fujitsu.
  956. */
  957. mreg &= ~(SWIFT_BF);
  958. srmmu_set_mmureg(mreg);
  959. }
  960. static const struct sparc32_cachetlb_ops swift_ops = {
  961. .cache_all = swift_flush_cache_all,
  962. .cache_mm = swift_flush_cache_mm,
  963. .cache_page = swift_flush_cache_page,
  964. .cache_range = swift_flush_cache_range,
  965. .tlb_all = swift_flush_tlb_all,
  966. .tlb_mm = swift_flush_tlb_mm,
  967. .tlb_page = swift_flush_tlb_page,
  968. .tlb_range = swift_flush_tlb_range,
  969. .page_to_ram = swift_flush_page_to_ram,
  970. .sig_insns = swift_flush_sig_insns,
  971. .page_for_dma = swift_flush_page_for_dma,
  972. };
  973. #define SWIFT_MASKID_ADDR 0x10003018
  974. static void __init init_swift(void)
  975. {
  976. unsigned long swift_rev;
  977. __asm__ __volatile__("lda [%1] %2, %0\n\t"
  978. "srl %0, 0x18, %0\n\t" :
  979. "=r" (swift_rev) :
  980. "r" (SWIFT_MASKID_ADDR), "i" (ASI_M_BYPASS));
  981. srmmu_name = "Fujitsu Swift";
  982. switch (swift_rev) {
  983. case 0x11:
  984. case 0x20:
  985. case 0x23:
  986. case 0x30:
  987. srmmu_modtype = Swift_lots_o_bugs;
  988. hwbug_bitmask |= (HWBUG_KERN_ACCBROKEN | HWBUG_KERN_CBITBROKEN);
  989. /*
  990. * Gee george, I wonder why Sun is so hush hush about
  991. * this hardware bug... really braindamage stuff going
  992. * on here. However I think we can find a way to avoid
  993. * all of the workaround overhead under Linux. Basically,
  994. * any page fault can cause kernel pages to become user
  995. * accessible (the mmu gets confused and clears some of
  996. * the ACC bits in kernel ptes). Aha, sounds pretty
  997. * horrible eh? But wait, after extensive testing it appears
  998. * that if you use pgd_t level large kernel pte's (like the
  999. * 4MB pages on the Pentium) the bug does not get tripped
  1000. * at all. This avoids almost all of the major overhead.
  1001. * Welcome to a world where your vendor tells you to,
  1002. * "apply this kernel patch" instead of "sorry for the
  1003. * broken hardware, send it back and we'll give you
  1004. * properly functioning parts"
  1005. */
  1006. break;
  1007. case 0x25:
  1008. case 0x31:
  1009. srmmu_modtype = Swift_bad_c;
  1010. hwbug_bitmask |= HWBUG_KERN_CBITBROKEN;
  1011. /*
  1012. * You see Sun allude to this hardware bug but never
  1013. * admit things directly, they'll say things like,
  1014. * "the Swift chip cache problems" or similar.
  1015. */
  1016. break;
  1017. default:
  1018. srmmu_modtype = Swift_ok;
  1019. break;
  1020. }
  1021. sparc32_cachetlb_ops = &swift_ops;
  1022. flush_page_for_dma_global = 0;
  1023. /*
  1024. * Are you now convinced that the Swift is one of the
  1025. * biggest VLSI abortions of all time? Bravo Fujitsu!
  1026. * Fujitsu, the !#?!%$'d up processor people. I bet if
  1027. * you examined the microcode of the Swift you'd find
  1028. * XXX's all over the place.
  1029. */
  1030. poke_srmmu = poke_swift;
  1031. }
  1032. static void turbosparc_flush_cache_all(void)
  1033. {
  1034. flush_user_windows();
  1035. turbosparc_idflash_clear();
  1036. }
  1037. static void turbosparc_flush_cache_mm(struct mm_struct *mm)
  1038. {
  1039. FLUSH_BEGIN(mm)
  1040. flush_user_windows();
  1041. turbosparc_idflash_clear();
  1042. FLUSH_END
  1043. }
  1044. static void turbosparc_flush_cache_range(struct vm_area_struct *vma, unsigned long start, unsigned long end)
  1045. {
  1046. FLUSH_BEGIN(vma->vm_mm)
  1047. flush_user_windows();
  1048. turbosparc_idflash_clear();
  1049. FLUSH_END
  1050. }
  1051. static void turbosparc_flush_cache_page(struct vm_area_struct *vma, unsigned long page)
  1052. {
  1053. FLUSH_BEGIN(vma->vm_mm)
  1054. flush_user_windows();
  1055. if (vma->vm_flags & VM_EXEC)
  1056. turbosparc_flush_icache();
  1057. turbosparc_flush_dcache();
  1058. FLUSH_END
  1059. }
  1060. /* TurboSparc is copy-back, if we turn it on, but this does not work. */
  1061. static void turbosparc_flush_page_to_ram(unsigned long page)
  1062. {
  1063. #ifdef TURBOSPARC_WRITEBACK
  1064. volatile unsigned long clear;
  1065. if (srmmu_probe(page))
  1066. turbosparc_flush_page_cache(page);
  1067. clear = srmmu_get_fstatus();
  1068. #endif
  1069. }
  1070. static void turbosparc_flush_sig_insns(struct mm_struct *mm, unsigned long insn_addr)
  1071. {
  1072. }
  1073. static void turbosparc_flush_page_for_dma(unsigned long page)
  1074. {
  1075. turbosparc_flush_dcache();
  1076. }
  1077. static void turbosparc_flush_tlb_all(void)
  1078. {
  1079. srmmu_flush_whole_tlb();
  1080. }
  1081. static void turbosparc_flush_tlb_mm(struct mm_struct *mm)
  1082. {
  1083. FLUSH_BEGIN(mm)
  1084. srmmu_flush_whole_tlb();
  1085. FLUSH_END
  1086. }
  1087. static void turbosparc_flush_tlb_range(struct vm_area_struct *vma, unsigned long start, unsigned long end)
  1088. {
  1089. FLUSH_BEGIN(vma->vm_mm)
  1090. srmmu_flush_whole_tlb();
  1091. FLUSH_END
  1092. }
  1093. static void turbosparc_flush_tlb_page(struct vm_area_struct *vma, unsigned long page)
  1094. {
  1095. FLUSH_BEGIN(vma->vm_mm)
  1096. srmmu_flush_whole_tlb();
  1097. FLUSH_END
  1098. }
  1099. static void poke_turbosparc(void)
  1100. {
  1101. unsigned long mreg = srmmu_get_mmureg();
  1102. unsigned long ccreg;
  1103. /* Clear any crap from the cache or else... */
  1104. turbosparc_flush_cache_all();
  1105. /* Temporarily disable I & D caches */
  1106. mreg &= ~(TURBOSPARC_ICENABLE | TURBOSPARC_DCENABLE);
  1107. mreg &= ~(TURBOSPARC_PCENABLE); /* Don't check parity */
  1108. srmmu_set_mmureg(mreg);
  1109. ccreg = turbosparc_get_ccreg();
  1110. #ifdef TURBOSPARC_WRITEBACK
  1111. ccreg |= (TURBOSPARC_SNENABLE); /* Do DVMA snooping in Dcache */
  1112. ccreg &= ~(TURBOSPARC_uS2 | TURBOSPARC_WTENABLE);
  1113. /* Write-back D-cache, emulate VLSI
  1114. * abortion number three, not number one */
  1115. #else
  1116. /* For now let's play safe, optimize later */
  1117. ccreg |= (TURBOSPARC_SNENABLE | TURBOSPARC_WTENABLE);
  1118. /* Do DVMA snooping in Dcache, Write-thru D-cache */
  1119. ccreg &= ~(TURBOSPARC_uS2);
  1120. /* Emulate VLSI abortion number three, not number one */
  1121. #endif
  1122. switch (ccreg & 7) {
  1123. case 0: /* No SE cache */
  1124. case 7: /* Test mode */
  1125. break;
  1126. default:
  1127. ccreg |= (TURBOSPARC_SCENABLE);
  1128. }
  1129. turbosparc_set_ccreg(ccreg);
  1130. mreg |= (TURBOSPARC_ICENABLE | TURBOSPARC_DCENABLE); /* I & D caches on */
  1131. mreg |= (TURBOSPARC_ICSNOOP); /* Icache snooping on */
  1132. srmmu_set_mmureg(mreg);
  1133. }
  1134. static const struct sparc32_cachetlb_ops turbosparc_ops = {
  1135. .cache_all = turbosparc_flush_cache_all,
  1136. .cache_mm = turbosparc_flush_cache_mm,
  1137. .cache_page = turbosparc_flush_cache_page,
  1138. .cache_range = turbosparc_flush_cache_range,
  1139. .tlb_all = turbosparc_flush_tlb_all,
  1140. .tlb_mm = turbosparc_flush_tlb_mm,
  1141. .tlb_page = turbosparc_flush_tlb_page,
  1142. .tlb_range = turbosparc_flush_tlb_range,
  1143. .page_to_ram = turbosparc_flush_page_to_ram,
  1144. .sig_insns = turbosparc_flush_sig_insns,
  1145. .page_for_dma = turbosparc_flush_page_for_dma,
  1146. };
  1147. static void __init init_turbosparc(void)
  1148. {
  1149. srmmu_name = "Fujitsu TurboSparc";
  1150. srmmu_modtype = TurboSparc;
  1151. sparc32_cachetlb_ops = &turbosparc_ops;
  1152. poke_srmmu = poke_turbosparc;
  1153. }
  1154. static void poke_tsunami(void)
  1155. {
  1156. unsigned long mreg = srmmu_get_mmureg();
  1157. tsunami_flush_icache();
  1158. tsunami_flush_dcache();
  1159. mreg &= ~TSUNAMI_ITD;
  1160. mreg |= (TSUNAMI_IENAB | TSUNAMI_DENAB);
  1161. srmmu_set_mmureg(mreg);
  1162. }
  1163. static const struct sparc32_cachetlb_ops tsunami_ops = {
  1164. .cache_all = tsunami_flush_cache_all,
  1165. .cache_mm = tsunami_flush_cache_mm,
  1166. .cache_page = tsunami_flush_cache_page,
  1167. .cache_range = tsunami_flush_cache_range,
  1168. .tlb_all = tsunami_flush_tlb_all,
  1169. .tlb_mm = tsunami_flush_tlb_mm,
  1170. .tlb_page = tsunami_flush_tlb_page,
  1171. .tlb_range = tsunami_flush_tlb_range,
  1172. .page_to_ram = tsunami_flush_page_to_ram,
  1173. .sig_insns = tsunami_flush_sig_insns,
  1174. .page_for_dma = tsunami_flush_page_for_dma,
  1175. };
  1176. static void __init init_tsunami(void)
  1177. {
  1178. /*
  1179. * Tsunami's pretty sane, Sun and TI actually got it
  1180. * somewhat right this time. Fujitsu should have
  1181. * taken some lessons from them.
  1182. */
  1183. srmmu_name = "TI Tsunami";
  1184. srmmu_modtype = Tsunami;
  1185. sparc32_cachetlb_ops = &tsunami_ops;
  1186. poke_srmmu = poke_tsunami;
  1187. tsunami_setup_blockops();
  1188. }
  1189. static void poke_viking(void)
  1190. {
  1191. unsigned long mreg = srmmu_get_mmureg();
  1192. static int smp_catch;
  1193. if (viking_mxcc_present) {
  1194. unsigned long mxcc_control = mxcc_get_creg();
  1195. mxcc_control |= (MXCC_CTL_ECE | MXCC_CTL_PRE | MXCC_CTL_MCE);
  1196. mxcc_control &= ~(MXCC_CTL_RRC);
  1197. mxcc_set_creg(mxcc_control);
  1198. /*
  1199. * We don't need memory parity checks.
  1200. * XXX This is a mess, have to dig out later. ecd.
  1201. viking_mxcc_turn_off_parity(&mreg, &mxcc_control);
  1202. */
  1203. /* We do cache ptables on MXCC. */
  1204. mreg |= VIKING_TCENABLE;
  1205. } else {
  1206. unsigned long bpreg;
  1207. mreg &= ~(VIKING_TCENABLE);
  1208. if (smp_catch++) {
  1209. /* Must disable mixed-cmd mode here for other cpu's. */
  1210. bpreg = viking_get_bpreg();
  1211. bpreg &= ~(VIKING_ACTION_MIX);
  1212. viking_set_bpreg(bpreg);
  1213. /* Just in case PROM does something funny. */
  1214. msi_set_sync();
  1215. }
  1216. }
  1217. mreg |= VIKING_SPENABLE;
  1218. mreg |= (VIKING_ICENABLE | VIKING_DCENABLE);
  1219. mreg |= VIKING_SBENABLE;
  1220. mreg &= ~(VIKING_ACENABLE);
  1221. srmmu_set_mmureg(mreg);
  1222. }
  1223. static struct sparc32_cachetlb_ops viking_ops = {
  1224. .cache_all = viking_flush_cache_all,
  1225. .cache_mm = viking_flush_cache_mm,
  1226. .cache_page = viking_flush_cache_page,
  1227. .cache_range = viking_flush_cache_range,
  1228. .tlb_all = viking_flush_tlb_all,
  1229. .tlb_mm = viking_flush_tlb_mm,
  1230. .tlb_page = viking_flush_tlb_page,
  1231. .tlb_range = viking_flush_tlb_range,
  1232. .page_to_ram = viking_flush_page_to_ram,
  1233. .sig_insns = viking_flush_sig_insns,
  1234. .page_for_dma = viking_flush_page_for_dma,
  1235. };
  1236. #ifdef CONFIG_SMP
  1237. /* On sun4d the cpu broadcasts local TLB flushes, so we can just
  1238. * perform the local TLB flush and all the other cpus will see it.
  1239. * But, unfortunately, there is a bug in the sun4d XBUS backplane
  1240. * that requires that we add some synchronization to these flushes.
  1241. *
  1242. * The bug is that the fifo which keeps track of all the pending TLB
  1243. * broadcasts in the system is an entry or two too small, so if we
  1244. * have too many going at once we'll overflow that fifo and lose a TLB
  1245. * flush resulting in corruption.
  1246. *
  1247. * Our workaround is to take a global spinlock around the TLB flushes,
  1248. * which guarentees we won't ever have too many pending. It's a big
  1249. * hammer, but a semaphore like system to make sure we only have N TLB
  1250. * flushes going at once will require SMP locking anyways so there's
  1251. * no real value in trying any harder than this.
  1252. */
  1253. static struct sparc32_cachetlb_ops viking_sun4d_smp_ops = {
  1254. .cache_all = viking_flush_cache_all,
  1255. .cache_mm = viking_flush_cache_mm,
  1256. .cache_page = viking_flush_cache_page,
  1257. .cache_range = viking_flush_cache_range,
  1258. .tlb_all = sun4dsmp_flush_tlb_all,
  1259. .tlb_mm = sun4dsmp_flush_tlb_mm,
  1260. .tlb_page = sun4dsmp_flush_tlb_page,
  1261. .tlb_range = sun4dsmp_flush_tlb_range,
  1262. .page_to_ram = viking_flush_page_to_ram,
  1263. .sig_insns = viking_flush_sig_insns,
  1264. .page_for_dma = viking_flush_page_for_dma,
  1265. };
  1266. #endif
  1267. static void __init init_viking(void)
  1268. {
  1269. unsigned long mreg = srmmu_get_mmureg();
  1270. /* Ahhh, the viking. SRMMU VLSI abortion number two... */
  1271. if (mreg & VIKING_MMODE) {
  1272. srmmu_name = "TI Viking";
  1273. viking_mxcc_present = 0;
  1274. msi_set_sync();
  1275. /*
  1276. * We need this to make sure old viking takes no hits
  1277. * on it's cache for dma snoops to workaround the
  1278. * "load from non-cacheable memory" interrupt bug.
  1279. * This is only necessary because of the new way in
  1280. * which we use the IOMMU.
  1281. */
  1282. viking_ops.page_for_dma = viking_flush_page;
  1283. #ifdef CONFIG_SMP
  1284. viking_sun4d_smp_ops.page_for_dma = viking_flush_page;
  1285. #endif
  1286. flush_page_for_dma_global = 0;
  1287. } else {
  1288. srmmu_name = "TI Viking/MXCC";
  1289. viking_mxcc_present = 1;
  1290. srmmu_cache_pagetables = 1;
  1291. }
  1292. sparc32_cachetlb_ops = (const struct sparc32_cachetlb_ops *)
  1293. &viking_ops;
  1294. #ifdef CONFIG_SMP
  1295. if (sparc_cpu_model == sun4d)
  1296. sparc32_cachetlb_ops = (const struct sparc32_cachetlb_ops *)
  1297. &viking_sun4d_smp_ops;
  1298. #endif
  1299. poke_srmmu = poke_viking;
  1300. }
  1301. /* Probe for the srmmu chip version. */
  1302. static void __init get_srmmu_type(void)
  1303. {
  1304. unsigned long mreg, psr;
  1305. unsigned long mod_typ, mod_rev, psr_typ, psr_vers;
  1306. srmmu_modtype = SRMMU_INVAL_MOD;
  1307. hwbug_bitmask = 0;
  1308. mreg = srmmu_get_mmureg(); psr = get_psr();
  1309. mod_typ = (mreg & 0xf0000000) >> 28;
  1310. mod_rev = (mreg & 0x0f000000) >> 24;
  1311. psr_typ = (psr >> 28) & 0xf;
  1312. psr_vers = (psr >> 24) & 0xf;
  1313. /* First, check for sparc-leon. */
  1314. if (sparc_cpu_model == sparc_leon) {
  1315. init_leon();
  1316. return;
  1317. }
  1318. /* Second, check for HyperSparc or Cypress. */
  1319. if (mod_typ == 1) {
  1320. switch (mod_rev) {
  1321. case 7:
  1322. /* UP or MP Hypersparc */
  1323. init_hypersparc();
  1324. break;
  1325. case 0:
  1326. case 2:
  1327. case 10:
  1328. case 11:
  1329. case 12:
  1330. case 13:
  1331. case 14:
  1332. case 15:
  1333. default:
  1334. prom_printf("Sparc-Linux Cypress support does not longer exit.\n");
  1335. prom_halt();
  1336. break;
  1337. }
  1338. return;
  1339. }
  1340. /* Now Fujitsu TurboSparc. It might happen that it is
  1341. * in Swift emulation mode, so we will check later...
  1342. */
  1343. if (psr_typ == 0 && psr_vers == 5) {
  1344. init_turbosparc();
  1345. return;
  1346. }
  1347. /* Next check for Fujitsu Swift. */
  1348. if (psr_typ == 0 && psr_vers == 4) {
  1349. phandle cpunode;
  1350. char node_str[128];
  1351. /* Look if it is not a TurboSparc emulating Swift... */
  1352. cpunode = prom_getchild(prom_root_node);
  1353. while ((cpunode = prom_getsibling(cpunode)) != 0) {
  1354. prom_getstring(cpunode, "device_type", node_str, sizeof(node_str));
  1355. if (!strcmp(node_str, "cpu")) {
  1356. if (!prom_getintdefault(cpunode, "psr-implementation", 1) &&
  1357. prom_getintdefault(cpunode, "psr-version", 1) == 5) {
  1358. init_turbosparc();
  1359. return;
  1360. }
  1361. break;
  1362. }
  1363. }
  1364. init_swift();
  1365. return;
  1366. }
  1367. /* Now the Viking family of srmmu. */
  1368. if (psr_typ == 4 &&
  1369. ((psr_vers == 0) ||
  1370. ((psr_vers == 1) && (mod_typ == 0) && (mod_rev == 0)))) {
  1371. init_viking();
  1372. return;
  1373. }
  1374. /* Finally the Tsunami. */
  1375. if (psr_typ == 4 && psr_vers == 1 && (mod_typ || mod_rev)) {
  1376. init_tsunami();
  1377. return;
  1378. }
  1379. /* Oh well */
  1380. srmmu_is_bad();
  1381. }
  1382. #ifdef CONFIG_SMP
  1383. /* Local cross-calls. */
  1384. static void smp_flush_page_for_dma(unsigned long page)
  1385. {
  1386. xc1((smpfunc_t) local_ops->page_for_dma, page);
  1387. local_ops->page_for_dma(page);
  1388. }
  1389. static void smp_flush_cache_all(void)
  1390. {
  1391. xc0((smpfunc_t) local_ops->cache_all);
  1392. local_ops->cache_all();
  1393. }
  1394. static void smp_flush_tlb_all(void)
  1395. {
  1396. xc0((smpfunc_t) local_ops->tlb_all);
  1397. local_ops->tlb_all();
  1398. }
  1399. static void smp_flush_cache_mm(struct mm_struct *mm)
  1400. {
  1401. if (mm->context != NO_CONTEXT) {
  1402. cpumask_t cpu_mask;
  1403. cpumask_copy(&cpu_mask, mm_cpumask(mm));
  1404. cpumask_clear_cpu(smp_processor_id(), &cpu_mask);
  1405. if (!cpumask_empty(&cpu_mask))
  1406. xc1((smpfunc_t) local_ops->cache_mm, (unsigned long) mm);
  1407. local_ops->cache_mm(mm);
  1408. }
  1409. }
  1410. static void smp_flush_tlb_mm(struct mm_struct *mm)
  1411. {
  1412. if (mm->context != NO_CONTEXT) {
  1413. cpumask_t cpu_mask;
  1414. cpumask_copy(&cpu_mask, mm_cpumask(mm));
  1415. cpumask_clear_cpu(smp_processor_id(), &cpu_mask);
  1416. if (!cpumask_empty(&cpu_mask)) {
  1417. xc1((smpfunc_t) local_ops->tlb_mm, (unsigned long) mm);
  1418. if (atomic_read(&mm->mm_users) == 1 && current->active_mm == mm)
  1419. cpumask_copy(mm_cpumask(mm),
  1420. cpumask_of(smp_processor_id()));
  1421. }
  1422. local_ops->tlb_mm(mm);
  1423. }
  1424. }
  1425. static void smp_flush_cache_range(struct vm_area_struct *vma,
  1426. unsigned long start,
  1427. unsigned long end)
  1428. {
  1429. struct mm_struct *mm = vma->vm_mm;
  1430. if (mm->context != NO_CONTEXT) {
  1431. cpumask_t cpu_mask;
  1432. cpumask_copy(&cpu_mask, mm_cpumask(mm));
  1433. cpumask_clear_cpu(smp_processor_id(), &cpu_mask);
  1434. if (!cpumask_empty(&cpu_mask))
  1435. xc3((smpfunc_t) local_ops->cache_range,
  1436. (unsigned long) vma, start, end);
  1437. local_ops->cache_range(vma, start, end);
  1438. }
  1439. }
  1440. static void smp_flush_tlb_range(struct vm_area_struct *vma,
  1441. unsigned long start,
  1442. unsigned long end)
  1443. {
  1444. struct mm_struct *mm = vma->vm_mm;
  1445. if (mm->context != NO_CONTEXT) {
  1446. cpumask_t cpu_mask;
  1447. cpumask_copy(&cpu_mask, mm_cpumask(mm));
  1448. cpumask_clear_cpu(smp_processor_id(), &cpu_mask);
  1449. if (!cpumask_empty(&cpu_mask))
  1450. xc3((smpfunc_t) local_ops->tlb_range,
  1451. (unsigned long) vma, start, end);
  1452. local_ops->tlb_range(vma, start, end);
  1453. }
  1454. }
  1455. static void smp_flush_cache_page(struct vm_area_struct *vma, unsigned long page)
  1456. {
  1457. struct mm_struct *mm = vma->vm_mm;
  1458. if (mm->context != NO_CONTEXT) {
  1459. cpumask_t cpu_mask;
  1460. cpumask_copy(&cpu_mask, mm_cpumask(mm));
  1461. cpumask_clear_cpu(smp_processor_id(), &cpu_mask);
  1462. if (!cpumask_empty(&cpu_mask))
  1463. xc2((smpfunc_t) local_ops->cache_page,
  1464. (unsigned long) vma, page);
  1465. local_ops->cache_page(vma, page);
  1466. }
  1467. }
  1468. static void smp_flush_tlb_page(struct vm_area_struct *vma, unsigned long page)
  1469. {
  1470. struct mm_struct *mm = vma->vm_mm;
  1471. if (mm->context != NO_CONTEXT) {
  1472. cpumask_t cpu_mask;
  1473. cpumask_copy(&cpu_mask, mm_cpumask(mm));
  1474. cpumask_clear_cpu(smp_processor_id(), &cpu_mask);
  1475. if (!cpumask_empty(&cpu_mask))
  1476. xc2((smpfunc_t) local_ops->tlb_page,
  1477. (unsigned long) vma, page);
  1478. local_ops->tlb_page(vma, page);
  1479. }
  1480. }
  1481. static void smp_flush_page_to_ram(unsigned long page)
  1482. {
  1483. /* Current theory is that those who call this are the one's
  1484. * who have just dirtied their cache with the pages contents
  1485. * in kernel space, therefore we only run this on local cpu.
  1486. *
  1487. * XXX This experiment failed, research further... -DaveM
  1488. */
  1489. #if 1
  1490. xc1((smpfunc_t) local_ops->page_to_ram, page);
  1491. #endif
  1492. local_ops->page_to_ram(page);
  1493. }
  1494. static void smp_flush_sig_insns(struct mm_struct *mm, unsigned long insn_addr)
  1495. {
  1496. cpumask_t cpu_mask;
  1497. cpumask_copy(&cpu_mask, mm_cpumask(mm));
  1498. cpumask_clear_cpu(smp_processor_id(), &cpu_mask);
  1499. if (!cpumask_empty(&cpu_mask))
  1500. xc2((smpfunc_t) local_ops->sig_insns,
  1501. (unsigned long) mm, insn_addr);
  1502. local_ops->sig_insns(mm, insn_addr);
  1503. }
  1504. static struct sparc32_cachetlb_ops smp_cachetlb_ops = {
  1505. .cache_all = smp_flush_cache_all,
  1506. .cache_mm = smp_flush_cache_mm,
  1507. .cache_page = smp_flush_cache_page,
  1508. .cache_range = smp_flush_cache_range,
  1509. .tlb_all = smp_flush_tlb_all,
  1510. .tlb_mm = smp_flush_tlb_mm,
  1511. .tlb_page = smp_flush_tlb_page,
  1512. .tlb_range = smp_flush_tlb_range,
  1513. .page_to_ram = smp_flush_page_to_ram,
  1514. .sig_insns = smp_flush_sig_insns,
  1515. .page_for_dma = smp_flush_page_for_dma,
  1516. };
  1517. #endif
  1518. /* Load up routines and constants for sun4m and sun4d mmu */
  1519. void __init load_mmu(void)
  1520. {
  1521. extern void ld_mmu_iommu(void);
  1522. extern void ld_mmu_iounit(void);
  1523. /* Functions */
  1524. get_srmmu_type();
  1525. #ifdef CONFIG_SMP
  1526. /* El switcheroo... */
  1527. local_ops = sparc32_cachetlb_ops;
  1528. if (sparc_cpu_model == sun4d || sparc_cpu_model == sparc_leon) {
  1529. smp_cachetlb_ops.tlb_all = local_ops->tlb_all;
  1530. smp_cachetlb_ops.tlb_mm = local_ops->tlb_mm;
  1531. smp_cachetlb_ops.tlb_range = local_ops->tlb_range;
  1532. smp_cachetlb_ops.tlb_page = local_ops->tlb_page;
  1533. }
  1534. if (poke_srmmu == poke_viking) {
  1535. /* Avoid unnecessary cross calls. */
  1536. smp_cachetlb_ops.cache_all = local_ops->cache_all;
  1537. smp_cachetlb_ops.cache_mm = local_ops->cache_mm;
  1538. smp_cachetlb_ops.cache_range = local_ops->cache_range;
  1539. smp_cachetlb_ops.cache_page = local_ops->cache_page;
  1540. smp_cachetlb_ops.page_to_ram = local_ops->page_to_ram;
  1541. smp_cachetlb_ops.sig_insns = local_ops->sig_insns;
  1542. smp_cachetlb_ops.page_for_dma = local_ops->page_for_dma;
  1543. }
  1544. /* It really is const after this point. */
  1545. sparc32_cachetlb_ops = (const struct sparc32_cachetlb_ops *)
  1546. &smp_cachetlb_ops;
  1547. #endif
  1548. if (sparc_cpu_model == sun4d)
  1549. ld_mmu_iounit();
  1550. else
  1551. ld_mmu_iommu();
  1552. #ifdef CONFIG_SMP
  1553. if (sparc_cpu_model == sun4d)
  1554. sun4d_init_smp();
  1555. else if (sparc_cpu_model == sparc_leon)
  1556. leon_init_smp();
  1557. else
  1558. sun4m_init_smp();
  1559. #endif
  1560. }