srmmu.c 49 KB

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