init.c 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707
  1. /* $Id: init.c,v 1.209 2002/02/09 19:49:31 davem Exp $
  2. * arch/sparc64/mm/init.c
  3. *
  4. * Copyright (C) 1996-1999 David S. Miller (davem@caip.rutgers.edu)
  5. * Copyright (C) 1997-1999 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
  6. */
  7. #include <linux/config.h>
  8. #include <linux/module.h>
  9. #include <linux/kernel.h>
  10. #include <linux/sched.h>
  11. #include <linux/string.h>
  12. #include <linux/init.h>
  13. #include <linux/bootmem.h>
  14. #include <linux/mm.h>
  15. #include <linux/hugetlb.h>
  16. #include <linux/slab.h>
  17. #include <linux/initrd.h>
  18. #include <linux/swap.h>
  19. #include <linux/pagemap.h>
  20. #include <linux/fs.h>
  21. #include <linux/seq_file.h>
  22. #include <linux/kprobes.h>
  23. #include <linux/cache.h>
  24. #include <linux/sort.h>
  25. #include <asm/head.h>
  26. #include <asm/system.h>
  27. #include <asm/page.h>
  28. #include <asm/pgalloc.h>
  29. #include <asm/pgtable.h>
  30. #include <asm/oplib.h>
  31. #include <asm/iommu.h>
  32. #include <asm/io.h>
  33. #include <asm/uaccess.h>
  34. #include <asm/mmu_context.h>
  35. #include <asm/tlbflush.h>
  36. #include <asm/dma.h>
  37. #include <asm/starfire.h>
  38. #include <asm/tlb.h>
  39. #include <asm/spitfire.h>
  40. #include <asm/sections.h>
  41. #include <asm/tsb.h>
  42. #include <asm/hypervisor.h>
  43. extern void device_scan(void);
  44. #define MAX_PHYS_ADDRESS (1UL << 42UL)
  45. #define KPTE_BITMAP_CHUNK_SZ (256UL * 1024UL * 1024UL)
  46. #define KPTE_BITMAP_BYTES \
  47. ((MAX_PHYS_ADDRESS / KPTE_BITMAP_CHUNK_SZ) / 8)
  48. unsigned long kern_linear_pte_xor[2] __read_mostly;
  49. /* A bitmap, one bit for every 256MB of physical memory. If the bit
  50. * is clear, we should use a 4MB page (via kern_linear_pte_xor[0]) else
  51. * if set we should use a 256MB page (via kern_linear_pte_xor[1]).
  52. */
  53. unsigned long kpte_linear_bitmap[KPTE_BITMAP_BYTES / sizeof(unsigned long)];
  54. #define MAX_BANKS 32
  55. static struct linux_prom64_registers pavail[MAX_BANKS] __initdata;
  56. static struct linux_prom64_registers pavail_rescan[MAX_BANKS] __initdata;
  57. static int pavail_ents __initdata;
  58. static int pavail_rescan_ents __initdata;
  59. static int cmp_p64(const void *a, const void *b)
  60. {
  61. const struct linux_prom64_registers *x = a, *y = b;
  62. if (x->phys_addr > y->phys_addr)
  63. return 1;
  64. if (x->phys_addr < y->phys_addr)
  65. return -1;
  66. return 0;
  67. }
  68. static void __init read_obp_memory(const char *property,
  69. struct linux_prom64_registers *regs,
  70. int *num_ents)
  71. {
  72. int node = prom_finddevice("/memory");
  73. int prop_size = prom_getproplen(node, property);
  74. int ents, ret, i;
  75. ents = prop_size / sizeof(struct linux_prom64_registers);
  76. if (ents > MAX_BANKS) {
  77. prom_printf("The machine has more %s property entries than "
  78. "this kernel can support (%d).\n",
  79. property, MAX_BANKS);
  80. prom_halt();
  81. }
  82. ret = prom_getproperty(node, property, (char *) regs, prop_size);
  83. if (ret == -1) {
  84. prom_printf("Couldn't get %s property from /memory.\n");
  85. prom_halt();
  86. }
  87. *num_ents = ents;
  88. /* Sanitize what we got from the firmware, by page aligning
  89. * everything.
  90. */
  91. for (i = 0; i < ents; i++) {
  92. unsigned long base, size;
  93. base = regs[i].phys_addr;
  94. size = regs[i].reg_size;
  95. size &= PAGE_MASK;
  96. if (base & ~PAGE_MASK) {
  97. unsigned long new_base = PAGE_ALIGN(base);
  98. size -= new_base - base;
  99. if ((long) size < 0L)
  100. size = 0UL;
  101. base = new_base;
  102. }
  103. regs[i].phys_addr = base;
  104. regs[i].reg_size = size;
  105. }
  106. sort(regs, ents, sizeof(struct linux_prom64_registers),
  107. cmp_p64, NULL);
  108. }
  109. unsigned long *sparc64_valid_addr_bitmap __read_mostly;
  110. /* Ugly, but necessary... -DaveM */
  111. unsigned long phys_base __read_mostly;
  112. unsigned long kern_base __read_mostly;
  113. unsigned long kern_size __read_mostly;
  114. unsigned long pfn_base __read_mostly;
  115. /* get_new_mmu_context() uses "cache + 1". */
  116. DEFINE_SPINLOCK(ctx_alloc_lock);
  117. unsigned long tlb_context_cache = CTX_FIRST_VERSION - 1;
  118. #define CTX_BMAP_SLOTS (1UL << (CTX_NR_BITS - 6))
  119. unsigned long mmu_context_bmap[CTX_BMAP_SLOTS];
  120. /* References to special section boundaries */
  121. extern char _start[], _end[];
  122. /* Initial ramdisk setup */
  123. extern unsigned long sparc_ramdisk_image64;
  124. extern unsigned int sparc_ramdisk_image;
  125. extern unsigned int sparc_ramdisk_size;
  126. struct page *mem_map_zero __read_mostly;
  127. unsigned int sparc64_highest_unlocked_tlb_ent __read_mostly;
  128. unsigned long sparc64_kern_pri_context __read_mostly;
  129. unsigned long sparc64_kern_pri_nuc_bits __read_mostly;
  130. unsigned long sparc64_kern_sec_context __read_mostly;
  131. int bigkernel = 0;
  132. kmem_cache_t *pgtable_cache __read_mostly;
  133. static void zero_ctor(void *addr, kmem_cache_t *cache, unsigned long flags)
  134. {
  135. clear_page(addr);
  136. }
  137. void pgtable_cache_init(void)
  138. {
  139. pgtable_cache = kmem_cache_create("pgtable_cache",
  140. PAGE_SIZE, PAGE_SIZE,
  141. SLAB_HWCACHE_ALIGN |
  142. SLAB_MUST_HWCACHE_ALIGN,
  143. zero_ctor,
  144. NULL);
  145. if (!pgtable_cache) {
  146. prom_printf("pgtable_cache_init(): Could not create!\n");
  147. prom_halt();
  148. }
  149. }
  150. #ifdef CONFIG_DEBUG_DCFLUSH
  151. atomic_t dcpage_flushes = ATOMIC_INIT(0);
  152. #ifdef CONFIG_SMP
  153. atomic_t dcpage_flushes_xcall = ATOMIC_INIT(0);
  154. #endif
  155. #endif
  156. __inline__ void flush_dcache_page_impl(struct page *page)
  157. {
  158. #ifdef CONFIG_DEBUG_DCFLUSH
  159. atomic_inc(&dcpage_flushes);
  160. #endif
  161. #ifdef DCACHE_ALIASING_POSSIBLE
  162. __flush_dcache_page(page_address(page),
  163. ((tlb_type == spitfire) &&
  164. page_mapping(page) != NULL));
  165. #else
  166. if (page_mapping(page) != NULL &&
  167. tlb_type == spitfire)
  168. __flush_icache_page(__pa(page_address(page)));
  169. #endif
  170. }
  171. #define PG_dcache_dirty PG_arch_1
  172. #define PG_dcache_cpu_shift 24
  173. #define PG_dcache_cpu_mask (256 - 1)
  174. #if NR_CPUS > 256
  175. #error D-cache dirty tracking and thread_info->cpu need fixing for > 256 cpus
  176. #endif
  177. #define dcache_dirty_cpu(page) \
  178. (((page)->flags >> PG_dcache_cpu_shift) & PG_dcache_cpu_mask)
  179. static __inline__ void set_dcache_dirty(struct page *page, int this_cpu)
  180. {
  181. unsigned long mask = this_cpu;
  182. unsigned long non_cpu_bits;
  183. non_cpu_bits = ~(PG_dcache_cpu_mask << PG_dcache_cpu_shift);
  184. mask = (mask << PG_dcache_cpu_shift) | (1UL << PG_dcache_dirty);
  185. __asm__ __volatile__("1:\n\t"
  186. "ldx [%2], %%g7\n\t"
  187. "and %%g7, %1, %%g1\n\t"
  188. "or %%g1, %0, %%g1\n\t"
  189. "casx [%2], %%g7, %%g1\n\t"
  190. "cmp %%g7, %%g1\n\t"
  191. "membar #StoreLoad | #StoreStore\n\t"
  192. "bne,pn %%xcc, 1b\n\t"
  193. " nop"
  194. : /* no outputs */
  195. : "r" (mask), "r" (non_cpu_bits), "r" (&page->flags)
  196. : "g1", "g7");
  197. }
  198. static __inline__ void clear_dcache_dirty_cpu(struct page *page, unsigned long cpu)
  199. {
  200. unsigned long mask = (1UL << PG_dcache_dirty);
  201. __asm__ __volatile__("! test_and_clear_dcache_dirty\n"
  202. "1:\n\t"
  203. "ldx [%2], %%g7\n\t"
  204. "srlx %%g7, %4, %%g1\n\t"
  205. "and %%g1, %3, %%g1\n\t"
  206. "cmp %%g1, %0\n\t"
  207. "bne,pn %%icc, 2f\n\t"
  208. " andn %%g7, %1, %%g1\n\t"
  209. "casx [%2], %%g7, %%g1\n\t"
  210. "cmp %%g7, %%g1\n\t"
  211. "membar #StoreLoad | #StoreStore\n\t"
  212. "bne,pn %%xcc, 1b\n\t"
  213. " nop\n"
  214. "2:"
  215. : /* no outputs */
  216. : "r" (cpu), "r" (mask), "r" (&page->flags),
  217. "i" (PG_dcache_cpu_mask),
  218. "i" (PG_dcache_cpu_shift)
  219. : "g1", "g7");
  220. }
  221. static inline void tsb_insert(struct tsb *ent, unsigned long tag, unsigned long pte)
  222. {
  223. unsigned long tsb_addr = (unsigned long) ent;
  224. if (tlb_type == cheetah_plus || tlb_type == hypervisor)
  225. tsb_addr = __pa(tsb_addr);
  226. __tsb_insert(tsb_addr, tag, pte);
  227. }
  228. unsigned long _PAGE_ALL_SZ_BITS __read_mostly;
  229. unsigned long _PAGE_SZBITS __read_mostly;
  230. void update_mmu_cache(struct vm_area_struct *vma, unsigned long address, pte_t pte)
  231. {
  232. struct mm_struct *mm;
  233. struct page *page;
  234. unsigned long pfn;
  235. unsigned long pg_flags;
  236. pfn = pte_pfn(pte);
  237. if (pfn_valid(pfn) &&
  238. (page = pfn_to_page(pfn), page_mapping(page)) &&
  239. ((pg_flags = page->flags) & (1UL << PG_dcache_dirty))) {
  240. int cpu = ((pg_flags >> PG_dcache_cpu_shift) &
  241. PG_dcache_cpu_mask);
  242. int this_cpu = get_cpu();
  243. /* This is just to optimize away some function calls
  244. * in the SMP case.
  245. */
  246. if (cpu == this_cpu)
  247. flush_dcache_page_impl(page);
  248. else
  249. smp_flush_dcache_page_impl(page, cpu);
  250. clear_dcache_dirty_cpu(page, cpu);
  251. put_cpu();
  252. }
  253. mm = vma->vm_mm;
  254. if ((pte_val(pte) & _PAGE_ALL_SZ_BITS) == _PAGE_SZBITS) {
  255. struct tsb *tsb;
  256. unsigned long tag;
  257. tsb = &mm->context.tsb[(address >> PAGE_SHIFT) &
  258. (mm->context.tsb_nentries - 1UL)];
  259. tag = (address >> 22UL);
  260. tsb_insert(tsb, tag, pte_val(pte));
  261. }
  262. }
  263. void flush_dcache_page(struct page *page)
  264. {
  265. struct address_space *mapping;
  266. int this_cpu;
  267. /* Do not bother with the expensive D-cache flush if it
  268. * is merely the zero page. The 'bigcore' testcase in GDB
  269. * causes this case to run millions of times.
  270. */
  271. if (page == ZERO_PAGE(0))
  272. return;
  273. this_cpu = get_cpu();
  274. mapping = page_mapping(page);
  275. if (mapping && !mapping_mapped(mapping)) {
  276. int dirty = test_bit(PG_dcache_dirty, &page->flags);
  277. if (dirty) {
  278. int dirty_cpu = dcache_dirty_cpu(page);
  279. if (dirty_cpu == this_cpu)
  280. goto out;
  281. smp_flush_dcache_page_impl(page, dirty_cpu);
  282. }
  283. set_dcache_dirty(page, this_cpu);
  284. } else {
  285. /* We could delay the flush for the !page_mapping
  286. * case too. But that case is for exec env/arg
  287. * pages and those are %99 certainly going to get
  288. * faulted into the tlb (and thus flushed) anyways.
  289. */
  290. flush_dcache_page_impl(page);
  291. }
  292. out:
  293. put_cpu();
  294. }
  295. void __kprobes flush_icache_range(unsigned long start, unsigned long end)
  296. {
  297. /* Cheetah and Hypervisor platform cpus have coherent I-cache. */
  298. if (tlb_type == spitfire) {
  299. unsigned long kaddr;
  300. for (kaddr = start; kaddr < end; kaddr += PAGE_SIZE)
  301. __flush_icache_page(__get_phys(kaddr));
  302. }
  303. }
  304. unsigned long page_to_pfn(struct page *page)
  305. {
  306. return (unsigned long) ((page - mem_map) + pfn_base);
  307. }
  308. struct page *pfn_to_page(unsigned long pfn)
  309. {
  310. return (mem_map + (pfn - pfn_base));
  311. }
  312. void show_mem(void)
  313. {
  314. printk("Mem-info:\n");
  315. show_free_areas();
  316. printk("Free swap: %6ldkB\n",
  317. nr_swap_pages << (PAGE_SHIFT-10));
  318. printk("%ld pages of RAM\n", num_physpages);
  319. printk("%d free pages\n", nr_free_pages());
  320. }
  321. void mmu_info(struct seq_file *m)
  322. {
  323. if (tlb_type == cheetah)
  324. seq_printf(m, "MMU Type\t: Cheetah\n");
  325. else if (tlb_type == cheetah_plus)
  326. seq_printf(m, "MMU Type\t: Cheetah+\n");
  327. else if (tlb_type == spitfire)
  328. seq_printf(m, "MMU Type\t: Spitfire\n");
  329. else if (tlb_type == hypervisor)
  330. seq_printf(m, "MMU Type\t: Hypervisor (sun4v)\n");
  331. else
  332. seq_printf(m, "MMU Type\t: ???\n");
  333. #ifdef CONFIG_DEBUG_DCFLUSH
  334. seq_printf(m, "DCPageFlushes\t: %d\n",
  335. atomic_read(&dcpage_flushes));
  336. #ifdef CONFIG_SMP
  337. seq_printf(m, "DCPageFlushesXC\t: %d\n",
  338. atomic_read(&dcpage_flushes_xcall));
  339. #endif /* CONFIG_SMP */
  340. #endif /* CONFIG_DEBUG_DCFLUSH */
  341. }
  342. struct linux_prom_translation {
  343. unsigned long virt;
  344. unsigned long size;
  345. unsigned long data;
  346. };
  347. /* Exported for kernel TLB miss handling in ktlb.S */
  348. struct linux_prom_translation prom_trans[512] __read_mostly;
  349. unsigned int prom_trans_ents __read_mostly;
  350. /* Exported for SMP bootup purposes. */
  351. unsigned long kern_locked_tte_data;
  352. /* The obp translations are saved based on 8k pagesize, since obp can
  353. * use a mixture of pagesizes. Misses to the LOW_OBP_ADDRESS ->
  354. * HI_OBP_ADDRESS range are handled in ktlb.S.
  355. */
  356. static inline int in_obp_range(unsigned long vaddr)
  357. {
  358. return (vaddr >= LOW_OBP_ADDRESS &&
  359. vaddr < HI_OBP_ADDRESS);
  360. }
  361. static int cmp_ptrans(const void *a, const void *b)
  362. {
  363. const struct linux_prom_translation *x = a, *y = b;
  364. if (x->virt > y->virt)
  365. return 1;
  366. if (x->virt < y->virt)
  367. return -1;
  368. return 0;
  369. }
  370. /* Read OBP translations property into 'prom_trans[]'. */
  371. static void __init read_obp_translations(void)
  372. {
  373. int n, node, ents, first, last, i;
  374. node = prom_finddevice("/virtual-memory");
  375. n = prom_getproplen(node, "translations");
  376. if (unlikely(n == 0 || n == -1)) {
  377. prom_printf("prom_mappings: Couldn't get size.\n");
  378. prom_halt();
  379. }
  380. if (unlikely(n > sizeof(prom_trans))) {
  381. prom_printf("prom_mappings: Size %Zd is too big.\n", n);
  382. prom_halt();
  383. }
  384. if ((n = prom_getproperty(node, "translations",
  385. (char *)&prom_trans[0],
  386. sizeof(prom_trans))) == -1) {
  387. prom_printf("prom_mappings: Couldn't get property.\n");
  388. prom_halt();
  389. }
  390. n = n / sizeof(struct linux_prom_translation);
  391. ents = n;
  392. sort(prom_trans, ents, sizeof(struct linux_prom_translation),
  393. cmp_ptrans, NULL);
  394. /* Now kick out all the non-OBP entries. */
  395. for (i = 0; i < ents; i++) {
  396. if (in_obp_range(prom_trans[i].virt))
  397. break;
  398. }
  399. first = i;
  400. for (; i < ents; i++) {
  401. if (!in_obp_range(prom_trans[i].virt))
  402. break;
  403. }
  404. last = i;
  405. for (i = 0; i < (last - first); i++) {
  406. struct linux_prom_translation *src = &prom_trans[i + first];
  407. struct linux_prom_translation *dest = &prom_trans[i];
  408. *dest = *src;
  409. }
  410. for (; i < ents; i++) {
  411. struct linux_prom_translation *dest = &prom_trans[i];
  412. dest->virt = dest->size = dest->data = 0x0UL;
  413. }
  414. prom_trans_ents = last - first;
  415. if (tlb_type == spitfire) {
  416. /* Clear diag TTE bits. */
  417. for (i = 0; i < prom_trans_ents; i++)
  418. prom_trans[i].data &= ~0x0003fe0000000000UL;
  419. }
  420. }
  421. static void __init hypervisor_tlb_lock(unsigned long vaddr,
  422. unsigned long pte,
  423. unsigned long mmu)
  424. {
  425. register unsigned long func asm("%o5");
  426. register unsigned long arg0 asm("%o0");
  427. register unsigned long arg1 asm("%o1");
  428. register unsigned long arg2 asm("%o2");
  429. register unsigned long arg3 asm("%o3");
  430. func = HV_FAST_MMU_MAP_PERM_ADDR;
  431. arg0 = vaddr;
  432. arg1 = 0;
  433. arg2 = pte;
  434. arg3 = mmu;
  435. __asm__ __volatile__("ta 0x80"
  436. : "=&r" (func), "=&r" (arg0),
  437. "=&r" (arg1), "=&r" (arg2),
  438. "=&r" (arg3)
  439. : "0" (func), "1" (arg0), "2" (arg1),
  440. "3" (arg2), "4" (arg3));
  441. if (arg0 != 0) {
  442. prom_printf("hypervisor_tlb_lock[%lx:%lx:%lx:%lx]: "
  443. "errors with %lx\n", vaddr, 0, pte, mmu, arg0);
  444. prom_halt();
  445. }
  446. }
  447. static unsigned long kern_large_tte(unsigned long paddr);
  448. static void __init remap_kernel(void)
  449. {
  450. unsigned long phys_page, tte_vaddr, tte_data;
  451. int tlb_ent = sparc64_highest_locked_tlbent();
  452. tte_vaddr = (unsigned long) KERNBASE;
  453. phys_page = (prom_boot_mapping_phys_low >> 22UL) << 22UL;
  454. tte_data = kern_large_tte(phys_page);
  455. kern_locked_tte_data = tte_data;
  456. /* Now lock us into the TLBs via Hypervisor or OBP. */
  457. if (tlb_type == hypervisor) {
  458. hypervisor_tlb_lock(tte_vaddr, tte_data, HV_MMU_DMMU);
  459. hypervisor_tlb_lock(tte_vaddr, tte_data, HV_MMU_IMMU);
  460. if (bigkernel) {
  461. tte_vaddr += 0x400000;
  462. tte_data += 0x400000;
  463. hypervisor_tlb_lock(tte_vaddr, tte_data, HV_MMU_DMMU);
  464. hypervisor_tlb_lock(tte_vaddr, tte_data, HV_MMU_IMMU);
  465. }
  466. } else {
  467. prom_dtlb_load(tlb_ent, tte_data, tte_vaddr);
  468. prom_itlb_load(tlb_ent, tte_data, tte_vaddr);
  469. if (bigkernel) {
  470. tlb_ent -= 1;
  471. prom_dtlb_load(tlb_ent,
  472. tte_data + 0x400000,
  473. tte_vaddr + 0x400000);
  474. prom_itlb_load(tlb_ent,
  475. tte_data + 0x400000,
  476. tte_vaddr + 0x400000);
  477. }
  478. sparc64_highest_unlocked_tlb_ent = tlb_ent - 1;
  479. }
  480. if (tlb_type == cheetah_plus) {
  481. sparc64_kern_pri_context = (CTX_CHEETAH_PLUS_CTX0 |
  482. CTX_CHEETAH_PLUS_NUC);
  483. sparc64_kern_pri_nuc_bits = CTX_CHEETAH_PLUS_NUC;
  484. sparc64_kern_sec_context = CTX_CHEETAH_PLUS_CTX0;
  485. }
  486. }
  487. static void __init inherit_prom_mappings(void)
  488. {
  489. read_obp_translations();
  490. /* Now fixup OBP's idea about where we really are mapped. */
  491. prom_printf("Remapping the kernel... ");
  492. remap_kernel();
  493. prom_printf("done.\n");
  494. }
  495. void prom_world(int enter)
  496. {
  497. if (!enter)
  498. set_fs((mm_segment_t) { get_thread_current_ds() });
  499. __asm__ __volatile__("flushw");
  500. }
  501. #ifdef DCACHE_ALIASING_POSSIBLE
  502. void __flush_dcache_range(unsigned long start, unsigned long end)
  503. {
  504. unsigned long va;
  505. if (tlb_type == spitfire) {
  506. int n = 0;
  507. for (va = start; va < end; va += 32) {
  508. spitfire_put_dcache_tag(va & 0x3fe0, 0x0);
  509. if (++n >= 512)
  510. break;
  511. }
  512. } else if (tlb_type == cheetah || tlb_type == cheetah_plus) {
  513. start = __pa(start);
  514. end = __pa(end);
  515. for (va = start; va < end; va += 32)
  516. __asm__ __volatile__("stxa %%g0, [%0] %1\n\t"
  517. "membar #Sync"
  518. : /* no outputs */
  519. : "r" (va),
  520. "i" (ASI_DCACHE_INVALIDATE));
  521. }
  522. }
  523. #endif /* DCACHE_ALIASING_POSSIBLE */
  524. /* Caller does TLB context flushing on local CPU if necessary.
  525. * The caller also ensures that CTX_VALID(mm->context) is false.
  526. *
  527. * We must be careful about boundary cases so that we never
  528. * let the user have CTX 0 (nucleus) or we ever use a CTX
  529. * version of zero (and thus NO_CONTEXT would not be caught
  530. * by version mis-match tests in mmu_context.h).
  531. */
  532. void get_new_mmu_context(struct mm_struct *mm)
  533. {
  534. unsigned long ctx, new_ctx;
  535. unsigned long orig_pgsz_bits;
  536. spin_lock(&ctx_alloc_lock);
  537. orig_pgsz_bits = (mm->context.sparc64_ctx_val & CTX_PGSZ_MASK);
  538. ctx = (tlb_context_cache + 1) & CTX_NR_MASK;
  539. new_ctx = find_next_zero_bit(mmu_context_bmap, 1 << CTX_NR_BITS, ctx);
  540. if (new_ctx >= (1 << CTX_NR_BITS)) {
  541. new_ctx = find_next_zero_bit(mmu_context_bmap, ctx, 1);
  542. if (new_ctx >= ctx) {
  543. int i;
  544. new_ctx = (tlb_context_cache & CTX_VERSION_MASK) +
  545. CTX_FIRST_VERSION;
  546. if (new_ctx == 1)
  547. new_ctx = CTX_FIRST_VERSION;
  548. /* Don't call memset, for 16 entries that's just
  549. * plain silly...
  550. */
  551. mmu_context_bmap[0] = 3;
  552. mmu_context_bmap[1] = 0;
  553. mmu_context_bmap[2] = 0;
  554. mmu_context_bmap[3] = 0;
  555. for (i = 4; i < CTX_BMAP_SLOTS; i += 4) {
  556. mmu_context_bmap[i + 0] = 0;
  557. mmu_context_bmap[i + 1] = 0;
  558. mmu_context_bmap[i + 2] = 0;
  559. mmu_context_bmap[i + 3] = 0;
  560. }
  561. goto out;
  562. }
  563. }
  564. mmu_context_bmap[new_ctx>>6] |= (1UL << (new_ctx & 63));
  565. new_ctx |= (tlb_context_cache & CTX_VERSION_MASK);
  566. out:
  567. tlb_context_cache = new_ctx;
  568. mm->context.sparc64_ctx_val = new_ctx | orig_pgsz_bits;
  569. spin_unlock(&ctx_alloc_lock);
  570. }
  571. void sparc_ultra_dump_itlb(void)
  572. {
  573. int slot;
  574. if (tlb_type == spitfire) {
  575. printk ("Contents of itlb: ");
  576. for (slot = 0; slot < 14; slot++) printk (" ");
  577. printk ("%2x:%016lx,%016lx\n",
  578. 0,
  579. spitfire_get_itlb_tag(0), spitfire_get_itlb_data(0));
  580. for (slot = 1; slot < 64; slot+=3) {
  581. printk ("%2x:%016lx,%016lx %2x:%016lx,%016lx %2x:%016lx,%016lx\n",
  582. slot,
  583. spitfire_get_itlb_tag(slot), spitfire_get_itlb_data(slot),
  584. slot+1,
  585. spitfire_get_itlb_tag(slot+1), spitfire_get_itlb_data(slot+1),
  586. slot+2,
  587. spitfire_get_itlb_tag(slot+2), spitfire_get_itlb_data(slot+2));
  588. }
  589. } else if (tlb_type == cheetah || tlb_type == cheetah_plus) {
  590. printk ("Contents of itlb0:\n");
  591. for (slot = 0; slot < 16; slot+=2) {
  592. printk ("%2x:%016lx,%016lx %2x:%016lx,%016lx\n",
  593. slot,
  594. cheetah_get_litlb_tag(slot), cheetah_get_litlb_data(slot),
  595. slot+1,
  596. cheetah_get_litlb_tag(slot+1), cheetah_get_litlb_data(slot+1));
  597. }
  598. printk ("Contents of itlb2:\n");
  599. for (slot = 0; slot < 128; slot+=2) {
  600. printk ("%2x:%016lx,%016lx %2x:%016lx,%016lx\n",
  601. slot,
  602. cheetah_get_itlb_tag(slot), cheetah_get_itlb_data(slot),
  603. slot+1,
  604. cheetah_get_itlb_tag(slot+1), cheetah_get_itlb_data(slot+1));
  605. }
  606. }
  607. }
  608. void sparc_ultra_dump_dtlb(void)
  609. {
  610. int slot;
  611. if (tlb_type == spitfire) {
  612. printk ("Contents of dtlb: ");
  613. for (slot = 0; slot < 14; slot++) printk (" ");
  614. printk ("%2x:%016lx,%016lx\n", 0,
  615. spitfire_get_dtlb_tag(0), spitfire_get_dtlb_data(0));
  616. for (slot = 1; slot < 64; slot+=3) {
  617. printk ("%2x:%016lx,%016lx %2x:%016lx,%016lx %2x:%016lx,%016lx\n",
  618. slot,
  619. spitfire_get_dtlb_tag(slot), spitfire_get_dtlb_data(slot),
  620. slot+1,
  621. spitfire_get_dtlb_tag(slot+1), spitfire_get_dtlb_data(slot+1),
  622. slot+2,
  623. spitfire_get_dtlb_tag(slot+2), spitfire_get_dtlb_data(slot+2));
  624. }
  625. } else if (tlb_type == cheetah || tlb_type == cheetah_plus) {
  626. printk ("Contents of dtlb0:\n");
  627. for (slot = 0; slot < 16; slot+=2) {
  628. printk ("%2x:%016lx,%016lx %2x:%016lx,%016lx\n",
  629. slot,
  630. cheetah_get_ldtlb_tag(slot), cheetah_get_ldtlb_data(slot),
  631. slot+1,
  632. cheetah_get_ldtlb_tag(slot+1), cheetah_get_ldtlb_data(slot+1));
  633. }
  634. printk ("Contents of dtlb2:\n");
  635. for (slot = 0; slot < 512; slot+=2) {
  636. printk ("%2x:%016lx,%016lx %2x:%016lx,%016lx\n",
  637. slot,
  638. cheetah_get_dtlb_tag(slot, 2), cheetah_get_dtlb_data(slot, 2),
  639. slot+1,
  640. cheetah_get_dtlb_tag(slot+1, 2), cheetah_get_dtlb_data(slot+1, 2));
  641. }
  642. if (tlb_type == cheetah_plus) {
  643. printk ("Contents of dtlb3:\n");
  644. for (slot = 0; slot < 512; slot+=2) {
  645. printk ("%2x:%016lx,%016lx %2x:%016lx,%016lx\n",
  646. slot,
  647. cheetah_get_dtlb_tag(slot, 3), cheetah_get_dtlb_data(slot, 3),
  648. slot+1,
  649. cheetah_get_dtlb_tag(slot+1, 3), cheetah_get_dtlb_data(slot+1, 3));
  650. }
  651. }
  652. }
  653. }
  654. extern unsigned long cmdline_memory_size;
  655. unsigned long __init bootmem_init(unsigned long *pages_avail)
  656. {
  657. unsigned long bootmap_size, start_pfn, end_pfn;
  658. unsigned long end_of_phys_memory = 0UL;
  659. unsigned long bootmap_pfn, bytes_avail, size;
  660. int i;
  661. #ifdef CONFIG_DEBUG_BOOTMEM
  662. prom_printf("bootmem_init: Scan pavail, ");
  663. #endif
  664. bytes_avail = 0UL;
  665. for (i = 0; i < pavail_ents; i++) {
  666. end_of_phys_memory = pavail[i].phys_addr +
  667. pavail[i].reg_size;
  668. bytes_avail += pavail[i].reg_size;
  669. if (cmdline_memory_size) {
  670. if (bytes_avail > cmdline_memory_size) {
  671. unsigned long slack = bytes_avail - cmdline_memory_size;
  672. bytes_avail -= slack;
  673. end_of_phys_memory -= slack;
  674. pavail[i].reg_size -= slack;
  675. if ((long)pavail[i].reg_size <= 0L) {
  676. pavail[i].phys_addr = 0xdeadbeefUL;
  677. pavail[i].reg_size = 0UL;
  678. pavail_ents = i;
  679. } else {
  680. pavail[i+1].reg_size = 0Ul;
  681. pavail[i+1].phys_addr = 0xdeadbeefUL;
  682. pavail_ents = i + 1;
  683. }
  684. break;
  685. }
  686. }
  687. }
  688. *pages_avail = bytes_avail >> PAGE_SHIFT;
  689. /* Start with page aligned address of last symbol in kernel
  690. * image. The kernel is hard mapped below PAGE_OFFSET in a
  691. * 4MB locked TLB translation.
  692. */
  693. start_pfn = PAGE_ALIGN(kern_base + kern_size) >> PAGE_SHIFT;
  694. bootmap_pfn = start_pfn;
  695. end_pfn = end_of_phys_memory >> PAGE_SHIFT;
  696. #ifdef CONFIG_BLK_DEV_INITRD
  697. /* Now have to check initial ramdisk, so that bootmap does not overwrite it */
  698. if (sparc_ramdisk_image || sparc_ramdisk_image64) {
  699. unsigned long ramdisk_image = sparc_ramdisk_image ?
  700. sparc_ramdisk_image : sparc_ramdisk_image64;
  701. if (ramdisk_image >= (unsigned long)_end - 2 * PAGE_SIZE)
  702. ramdisk_image -= KERNBASE;
  703. initrd_start = ramdisk_image + phys_base;
  704. initrd_end = initrd_start + sparc_ramdisk_size;
  705. if (initrd_end > end_of_phys_memory) {
  706. printk(KERN_CRIT "initrd extends beyond end of memory "
  707. "(0x%016lx > 0x%016lx)\ndisabling initrd\n",
  708. initrd_end, end_of_phys_memory);
  709. initrd_start = 0;
  710. }
  711. if (initrd_start) {
  712. if (initrd_start >= (start_pfn << PAGE_SHIFT) &&
  713. initrd_start < (start_pfn << PAGE_SHIFT) + 2 * PAGE_SIZE)
  714. bootmap_pfn = PAGE_ALIGN (initrd_end) >> PAGE_SHIFT;
  715. }
  716. }
  717. #endif
  718. /* Initialize the boot-time allocator. */
  719. max_pfn = max_low_pfn = end_pfn;
  720. min_low_pfn = pfn_base;
  721. #ifdef CONFIG_DEBUG_BOOTMEM
  722. prom_printf("init_bootmem(min[%lx], bootmap[%lx], max[%lx])\n",
  723. min_low_pfn, bootmap_pfn, max_low_pfn);
  724. #endif
  725. bootmap_size = init_bootmem_node(NODE_DATA(0), bootmap_pfn, pfn_base, end_pfn);
  726. /* Now register the available physical memory with the
  727. * allocator.
  728. */
  729. for (i = 0; i < pavail_ents; i++) {
  730. #ifdef CONFIG_DEBUG_BOOTMEM
  731. prom_printf("free_bootmem(pavail:%d): base[%lx] size[%lx]\n",
  732. i, pavail[i].phys_addr, pavail[i].reg_size);
  733. #endif
  734. free_bootmem(pavail[i].phys_addr, pavail[i].reg_size);
  735. }
  736. #ifdef CONFIG_BLK_DEV_INITRD
  737. if (initrd_start) {
  738. size = initrd_end - initrd_start;
  739. /* Resert the initrd image area. */
  740. #ifdef CONFIG_DEBUG_BOOTMEM
  741. prom_printf("reserve_bootmem(initrd): base[%llx] size[%lx]\n",
  742. initrd_start, initrd_end);
  743. #endif
  744. reserve_bootmem(initrd_start, size);
  745. *pages_avail -= PAGE_ALIGN(size) >> PAGE_SHIFT;
  746. initrd_start += PAGE_OFFSET;
  747. initrd_end += PAGE_OFFSET;
  748. }
  749. #endif
  750. /* Reserve the kernel text/data/bss. */
  751. #ifdef CONFIG_DEBUG_BOOTMEM
  752. prom_printf("reserve_bootmem(kernel): base[%lx] size[%lx]\n", kern_base, kern_size);
  753. #endif
  754. reserve_bootmem(kern_base, kern_size);
  755. *pages_avail -= PAGE_ALIGN(kern_size) >> PAGE_SHIFT;
  756. /* Reserve the bootmem map. We do not account for it
  757. * in pages_avail because we will release that memory
  758. * in free_all_bootmem.
  759. */
  760. size = bootmap_size;
  761. #ifdef CONFIG_DEBUG_BOOTMEM
  762. prom_printf("reserve_bootmem(bootmap): base[%lx] size[%lx]\n",
  763. (bootmap_pfn << PAGE_SHIFT), size);
  764. #endif
  765. reserve_bootmem((bootmap_pfn << PAGE_SHIFT), size);
  766. *pages_avail -= PAGE_ALIGN(size) >> PAGE_SHIFT;
  767. return end_pfn;
  768. }
  769. static struct linux_prom64_registers pall[MAX_BANKS] __initdata;
  770. static int pall_ents __initdata;
  771. #ifdef CONFIG_DEBUG_PAGEALLOC
  772. static unsigned long kernel_map_range(unsigned long pstart, unsigned long pend, pgprot_t prot)
  773. {
  774. unsigned long vstart = PAGE_OFFSET + pstart;
  775. unsigned long vend = PAGE_OFFSET + pend;
  776. unsigned long alloc_bytes = 0UL;
  777. if ((vstart & ~PAGE_MASK) || (vend & ~PAGE_MASK)) {
  778. prom_printf("kernel_map: Unaligned physmem[%lx:%lx]\n",
  779. vstart, vend);
  780. prom_halt();
  781. }
  782. while (vstart < vend) {
  783. unsigned long this_end, paddr = __pa(vstart);
  784. pgd_t *pgd = pgd_offset_k(vstart);
  785. pud_t *pud;
  786. pmd_t *pmd;
  787. pte_t *pte;
  788. pud = pud_offset(pgd, vstart);
  789. if (pud_none(*pud)) {
  790. pmd_t *new;
  791. new = __alloc_bootmem(PAGE_SIZE, PAGE_SIZE, PAGE_SIZE);
  792. alloc_bytes += PAGE_SIZE;
  793. pud_populate(&init_mm, pud, new);
  794. }
  795. pmd = pmd_offset(pud, vstart);
  796. if (!pmd_present(*pmd)) {
  797. pte_t *new;
  798. new = __alloc_bootmem(PAGE_SIZE, PAGE_SIZE, PAGE_SIZE);
  799. alloc_bytes += PAGE_SIZE;
  800. pmd_populate_kernel(&init_mm, pmd, new);
  801. }
  802. pte = pte_offset_kernel(pmd, vstart);
  803. this_end = (vstart + PMD_SIZE) & PMD_MASK;
  804. if (this_end > vend)
  805. this_end = vend;
  806. while (vstart < this_end) {
  807. pte_val(*pte) = (paddr | pgprot_val(prot));
  808. vstart += PAGE_SIZE;
  809. paddr += PAGE_SIZE;
  810. pte++;
  811. }
  812. }
  813. return alloc_bytes;
  814. }
  815. extern unsigned int kvmap_linear_patch[1];
  816. #endif /* CONFIG_DEBUG_PAGEALLOC */
  817. static void __init mark_kpte_bitmap(unsigned long start, unsigned long end)
  818. {
  819. const unsigned long shift_256MB = 28;
  820. const unsigned long mask_256MB = ((1UL << shift_256MB) - 1UL);
  821. const unsigned long size_256MB = (1UL << shift_256MB);
  822. while (start < end) {
  823. long remains;
  824. if (start & mask_256MB) {
  825. start = (start + size_256MB) & ~mask_256MB;
  826. continue;
  827. }
  828. remains = end - start;
  829. while (remains >= size_256MB) {
  830. unsigned long index = start >> shift_256MB;
  831. __set_bit(index, kpte_linear_bitmap);
  832. start += size_256MB;
  833. remains -= size_256MB;
  834. }
  835. }
  836. }
  837. static void __init kernel_physical_mapping_init(void)
  838. {
  839. unsigned long i;
  840. #ifdef CONFIG_DEBUG_PAGEALLOC
  841. unsigned long mem_alloced = 0UL;
  842. #endif
  843. read_obp_memory("reg", &pall[0], &pall_ents);
  844. for (i = 0; i < pall_ents; i++) {
  845. unsigned long phys_start, phys_end;
  846. phys_start = pall[i].phys_addr;
  847. phys_end = phys_start + pall[i].reg_size;
  848. mark_kpte_bitmap(phys_start, phys_end);
  849. #ifdef CONFIG_DEBUG_PAGEALLOC
  850. mem_alloced += kernel_map_range(phys_start, phys_end,
  851. PAGE_KERNEL);
  852. #endif
  853. }
  854. #ifdef CONFIG_DEBUG_PAGEALLOC
  855. printk("Allocated %ld bytes for kernel page tables.\n",
  856. mem_alloced);
  857. kvmap_linear_patch[0] = 0x01000000; /* nop */
  858. flushi(&kvmap_linear_patch[0]);
  859. __flush_tlb_all();
  860. #endif
  861. }
  862. #ifdef CONFIG_DEBUG_PAGEALLOC
  863. void kernel_map_pages(struct page *page, int numpages, int enable)
  864. {
  865. unsigned long phys_start = page_to_pfn(page) << PAGE_SHIFT;
  866. unsigned long phys_end = phys_start + (numpages * PAGE_SIZE);
  867. kernel_map_range(phys_start, phys_end,
  868. (enable ? PAGE_KERNEL : __pgprot(0)));
  869. flush_tsb_kernel_range(PAGE_OFFSET + phys_start,
  870. PAGE_OFFSET + phys_end);
  871. /* we should perform an IPI and flush all tlbs,
  872. * but that can deadlock->flush only current cpu.
  873. */
  874. __flush_tlb_kernel_range(PAGE_OFFSET + phys_start,
  875. PAGE_OFFSET + phys_end);
  876. }
  877. #endif
  878. unsigned long __init find_ecache_flush_span(unsigned long size)
  879. {
  880. int i;
  881. for (i = 0; i < pavail_ents; i++) {
  882. if (pavail[i].reg_size >= size)
  883. return pavail[i].phys_addr;
  884. }
  885. return ~0UL;
  886. }
  887. static void __init tsb_phys_patch(void)
  888. {
  889. struct tsb_ldquad_phys_patch_entry *pquad;
  890. struct tsb_phys_patch_entry *p;
  891. pquad = &__tsb_ldquad_phys_patch;
  892. while (pquad < &__tsb_ldquad_phys_patch_end) {
  893. unsigned long addr = pquad->addr;
  894. if (tlb_type == hypervisor)
  895. *(unsigned int *) addr = pquad->sun4v_insn;
  896. else
  897. *(unsigned int *) addr = pquad->sun4u_insn;
  898. wmb();
  899. __asm__ __volatile__("flush %0"
  900. : /* no outputs */
  901. : "r" (addr));
  902. pquad++;
  903. }
  904. p = &__tsb_phys_patch;
  905. while (p < &__tsb_phys_patch_end) {
  906. unsigned long addr = p->addr;
  907. *(unsigned int *) addr = p->insn;
  908. wmb();
  909. __asm__ __volatile__("flush %0"
  910. : /* no outputs */
  911. : "r" (addr));
  912. p++;
  913. }
  914. }
  915. /* Don't mark as init, we give this to the Hypervisor. */
  916. static struct hv_tsb_descr ktsb_descr[2];
  917. extern struct tsb swapper_tsb[KERNEL_TSB_NENTRIES];
  918. static void __init sun4v_ktsb_init(void)
  919. {
  920. unsigned long ktsb_pa;
  921. ktsb_pa = kern_base + ((unsigned long)&swapper_tsb[0] - KERNBASE);
  922. switch (PAGE_SIZE) {
  923. case 8 * 1024:
  924. default:
  925. ktsb_descr[0].pgsz_idx = HV_PGSZ_IDX_8K;
  926. ktsb_descr[0].pgsz_mask = HV_PGSZ_MASK_8K;
  927. break;
  928. case 64 * 1024:
  929. ktsb_descr[0].pgsz_idx = HV_PGSZ_IDX_64K;
  930. ktsb_descr[0].pgsz_mask = HV_PGSZ_MASK_64K;
  931. break;
  932. case 512 * 1024:
  933. ktsb_descr[0].pgsz_idx = HV_PGSZ_IDX_512K;
  934. ktsb_descr[0].pgsz_mask = HV_PGSZ_MASK_512K;
  935. break;
  936. case 4 * 1024 * 1024:
  937. ktsb_descr[0].pgsz_idx = HV_PGSZ_IDX_4MB;
  938. ktsb_descr[0].pgsz_mask = HV_PGSZ_MASK_4MB;
  939. break;
  940. };
  941. ktsb_descr[0].assoc = 1;
  942. ktsb_descr[0].num_ttes = KERNEL_TSB_NENTRIES;
  943. ktsb_descr[0].ctx_idx = 0;
  944. ktsb_descr[0].tsb_base = ktsb_pa;
  945. ktsb_descr[0].resv = 0;
  946. /* XXX When we have a kernel large page size TSB, describe
  947. * XXX it in ktsb_descr[1] here.
  948. */
  949. }
  950. void __cpuinit sun4v_ktsb_register(void)
  951. {
  952. register unsigned long func asm("%o5");
  953. register unsigned long arg0 asm("%o0");
  954. register unsigned long arg1 asm("%o1");
  955. unsigned long pa;
  956. pa = kern_base + ((unsigned long)&ktsb_descr[0] - KERNBASE);
  957. func = HV_FAST_MMU_TSB_CTX0;
  958. /* XXX set arg0 to 2 when we use ktsb_descr[1], see above XXX */
  959. arg0 = 1;
  960. arg1 = pa;
  961. __asm__ __volatile__("ta %6"
  962. : "=&r" (func), "=&r" (arg0), "=&r" (arg1)
  963. : "0" (func), "1" (arg0), "2" (arg1),
  964. "i" (HV_FAST_TRAP));
  965. }
  966. /* paging_init() sets up the page tables */
  967. extern void cheetah_ecache_flush_init(void);
  968. extern void sun4v_patch_tlb_handlers(void);
  969. static unsigned long last_valid_pfn;
  970. pgd_t swapper_pg_dir[2048];
  971. static void sun4u_pgprot_init(void);
  972. static void sun4v_pgprot_init(void);
  973. void __init paging_init(void)
  974. {
  975. unsigned long end_pfn, pages_avail, shift;
  976. unsigned long real_end, i;
  977. kern_base = (prom_boot_mapping_phys_low >> 22UL) << 22UL;
  978. kern_size = (unsigned long)&_end - (unsigned long)KERNBASE;
  979. memset(swapper_tsb, 0x40, sizeof(swapper_tsb));
  980. if (tlb_type == hypervisor)
  981. sun4v_pgprot_init();
  982. else
  983. sun4u_pgprot_init();
  984. if (tlb_type == cheetah_plus ||
  985. tlb_type == hypervisor)
  986. tsb_phys_patch();
  987. if (tlb_type == hypervisor) {
  988. sun4v_patch_tlb_handlers();
  989. sun4v_ktsb_init();
  990. }
  991. /* Find available physical memory... */
  992. read_obp_memory("available", &pavail[0], &pavail_ents);
  993. phys_base = 0xffffffffffffffffUL;
  994. for (i = 0; i < pavail_ents; i++)
  995. phys_base = min(phys_base, pavail[i].phys_addr);
  996. pfn_base = phys_base >> PAGE_SHIFT;
  997. set_bit(0, mmu_context_bmap);
  998. shift = kern_base + PAGE_OFFSET - ((unsigned long)KERNBASE);
  999. real_end = (unsigned long)_end;
  1000. if ((real_end > ((unsigned long)KERNBASE + 0x400000)))
  1001. bigkernel = 1;
  1002. if ((real_end > ((unsigned long)KERNBASE + 0x800000))) {
  1003. prom_printf("paging_init: Kernel > 8MB, too large.\n");
  1004. prom_halt();
  1005. }
  1006. /* Set kernel pgd to upper alias so physical page computations
  1007. * work.
  1008. */
  1009. init_mm.pgd += ((shift) / (sizeof(pgd_t)));
  1010. memset(swapper_low_pmd_dir, 0, sizeof(swapper_low_pmd_dir));
  1011. /* Now can init the kernel/bad page tables. */
  1012. pud_set(pud_offset(&swapper_pg_dir[0], 0),
  1013. swapper_low_pmd_dir + (shift / sizeof(pgd_t)));
  1014. inherit_prom_mappings();
  1015. /* Ok, we can use our TLB miss and window trap handlers safely. */
  1016. setup_tba();
  1017. __flush_tlb_all();
  1018. if (tlb_type == hypervisor)
  1019. sun4v_ktsb_register();
  1020. /* Setup bootmem... */
  1021. pages_avail = 0;
  1022. last_valid_pfn = end_pfn = bootmem_init(&pages_avail);
  1023. kernel_physical_mapping_init();
  1024. {
  1025. unsigned long zones_size[MAX_NR_ZONES];
  1026. unsigned long zholes_size[MAX_NR_ZONES];
  1027. unsigned long npages;
  1028. int znum;
  1029. for (znum = 0; znum < MAX_NR_ZONES; znum++)
  1030. zones_size[znum] = zholes_size[znum] = 0;
  1031. npages = end_pfn - pfn_base;
  1032. zones_size[ZONE_DMA] = npages;
  1033. zholes_size[ZONE_DMA] = npages - pages_avail;
  1034. free_area_init_node(0, &contig_page_data, zones_size,
  1035. phys_base >> PAGE_SHIFT, zholes_size);
  1036. }
  1037. device_scan();
  1038. }
  1039. static void __init taint_real_pages(void)
  1040. {
  1041. int i;
  1042. read_obp_memory("available", &pavail_rescan[0], &pavail_rescan_ents);
  1043. /* Find changes discovered in the physmem available rescan and
  1044. * reserve the lost portions in the bootmem maps.
  1045. */
  1046. for (i = 0; i < pavail_ents; i++) {
  1047. unsigned long old_start, old_end;
  1048. old_start = pavail[i].phys_addr;
  1049. old_end = old_start +
  1050. pavail[i].reg_size;
  1051. while (old_start < old_end) {
  1052. int n;
  1053. for (n = 0; pavail_rescan_ents; n++) {
  1054. unsigned long new_start, new_end;
  1055. new_start = pavail_rescan[n].phys_addr;
  1056. new_end = new_start +
  1057. pavail_rescan[n].reg_size;
  1058. if (new_start <= old_start &&
  1059. new_end >= (old_start + PAGE_SIZE)) {
  1060. set_bit(old_start >> 22,
  1061. sparc64_valid_addr_bitmap);
  1062. goto do_next_page;
  1063. }
  1064. }
  1065. reserve_bootmem(old_start, PAGE_SIZE);
  1066. do_next_page:
  1067. old_start += PAGE_SIZE;
  1068. }
  1069. }
  1070. }
  1071. void __init mem_init(void)
  1072. {
  1073. unsigned long codepages, datapages, initpages;
  1074. unsigned long addr, last;
  1075. int i;
  1076. i = last_valid_pfn >> ((22 - PAGE_SHIFT) + 6);
  1077. i += 1;
  1078. sparc64_valid_addr_bitmap = (unsigned long *) alloc_bootmem(i << 3);
  1079. if (sparc64_valid_addr_bitmap == NULL) {
  1080. prom_printf("mem_init: Cannot alloc valid_addr_bitmap.\n");
  1081. prom_halt();
  1082. }
  1083. memset(sparc64_valid_addr_bitmap, 0, i << 3);
  1084. addr = PAGE_OFFSET + kern_base;
  1085. last = PAGE_ALIGN(kern_size) + addr;
  1086. while (addr < last) {
  1087. set_bit(__pa(addr) >> 22, sparc64_valid_addr_bitmap);
  1088. addr += PAGE_SIZE;
  1089. }
  1090. taint_real_pages();
  1091. max_mapnr = last_valid_pfn - pfn_base;
  1092. high_memory = __va(last_valid_pfn << PAGE_SHIFT);
  1093. #ifdef CONFIG_DEBUG_BOOTMEM
  1094. prom_printf("mem_init: Calling free_all_bootmem().\n");
  1095. #endif
  1096. totalram_pages = num_physpages = free_all_bootmem() - 1;
  1097. /*
  1098. * Set up the zero page, mark it reserved, so that page count
  1099. * is not manipulated when freeing the page from user ptes.
  1100. */
  1101. mem_map_zero = alloc_pages(GFP_KERNEL|__GFP_ZERO, 0);
  1102. if (mem_map_zero == NULL) {
  1103. prom_printf("paging_init: Cannot alloc zero page.\n");
  1104. prom_halt();
  1105. }
  1106. SetPageReserved(mem_map_zero);
  1107. codepages = (((unsigned long) _etext) - ((unsigned long) _start));
  1108. codepages = PAGE_ALIGN(codepages) >> PAGE_SHIFT;
  1109. datapages = (((unsigned long) _edata) - ((unsigned long) _etext));
  1110. datapages = PAGE_ALIGN(datapages) >> PAGE_SHIFT;
  1111. initpages = (((unsigned long) __init_end) - ((unsigned long) __init_begin));
  1112. initpages = PAGE_ALIGN(initpages) >> PAGE_SHIFT;
  1113. printk("Memory: %uk available (%ldk kernel code, %ldk data, %ldk init) [%016lx,%016lx]\n",
  1114. nr_free_pages() << (PAGE_SHIFT-10),
  1115. codepages << (PAGE_SHIFT-10),
  1116. datapages << (PAGE_SHIFT-10),
  1117. initpages << (PAGE_SHIFT-10),
  1118. PAGE_OFFSET, (last_valid_pfn << PAGE_SHIFT));
  1119. if (tlb_type == cheetah || tlb_type == cheetah_plus)
  1120. cheetah_ecache_flush_init();
  1121. }
  1122. void free_initmem(void)
  1123. {
  1124. unsigned long addr, initend;
  1125. /*
  1126. * The init section is aligned to 8k in vmlinux.lds. Page align for >8k pagesizes.
  1127. */
  1128. addr = PAGE_ALIGN((unsigned long)(__init_begin));
  1129. initend = (unsigned long)(__init_end) & PAGE_MASK;
  1130. for (; addr < initend; addr += PAGE_SIZE) {
  1131. unsigned long page;
  1132. struct page *p;
  1133. page = (addr +
  1134. ((unsigned long) __va(kern_base)) -
  1135. ((unsigned long) KERNBASE));
  1136. memset((void *)addr, 0xcc, PAGE_SIZE);
  1137. p = virt_to_page(page);
  1138. ClearPageReserved(p);
  1139. set_page_count(p, 1);
  1140. __free_page(p);
  1141. num_physpages++;
  1142. totalram_pages++;
  1143. }
  1144. }
  1145. #ifdef CONFIG_BLK_DEV_INITRD
  1146. void free_initrd_mem(unsigned long start, unsigned long end)
  1147. {
  1148. if (start < end)
  1149. printk ("Freeing initrd memory: %ldk freed\n", (end - start) >> 10);
  1150. for (; start < end; start += PAGE_SIZE) {
  1151. struct page *p = virt_to_page(start);
  1152. ClearPageReserved(p);
  1153. set_page_count(p, 1);
  1154. __free_page(p);
  1155. num_physpages++;
  1156. totalram_pages++;
  1157. }
  1158. }
  1159. #endif
  1160. #define _PAGE_CACHE_4U (_PAGE_CP_4U | _PAGE_CV_4U)
  1161. #define _PAGE_CACHE_4V (_PAGE_CP_4V | _PAGE_CV_4V)
  1162. #define __DIRTY_BITS_4U (_PAGE_MODIFIED_4U | _PAGE_WRITE_4U | _PAGE_W_4U)
  1163. #define __DIRTY_BITS_4V (_PAGE_MODIFIED_4V | _PAGE_WRITE_4V | _PAGE_W_4V)
  1164. #define __ACCESS_BITS_4U (_PAGE_ACCESSED_4U | _PAGE_READ_4U | _PAGE_R)
  1165. #define __ACCESS_BITS_4V (_PAGE_ACCESSED_4V | _PAGE_READ_4V | _PAGE_R)
  1166. pgprot_t PAGE_KERNEL __read_mostly;
  1167. EXPORT_SYMBOL(PAGE_KERNEL);
  1168. pgprot_t PAGE_KERNEL_LOCKED __read_mostly;
  1169. pgprot_t PAGE_COPY __read_mostly;
  1170. pgprot_t PAGE_SHARED __read_mostly;
  1171. EXPORT_SYMBOL(PAGE_SHARED);
  1172. pgprot_t PAGE_EXEC __read_mostly;
  1173. unsigned long pg_iobits __read_mostly;
  1174. unsigned long _PAGE_IE __read_mostly;
  1175. unsigned long _PAGE_E __read_mostly;
  1176. unsigned long _PAGE_CACHE __read_mostly;
  1177. static void prot_init_common(unsigned long page_none,
  1178. unsigned long page_shared,
  1179. unsigned long page_copy,
  1180. unsigned long page_readonly,
  1181. unsigned long page_exec_bit)
  1182. {
  1183. PAGE_COPY = __pgprot(page_copy);
  1184. PAGE_SHARED = __pgprot(page_shared);
  1185. protection_map[0x0] = __pgprot(page_none);
  1186. protection_map[0x1] = __pgprot(page_readonly & ~page_exec_bit);
  1187. protection_map[0x2] = __pgprot(page_copy & ~page_exec_bit);
  1188. protection_map[0x3] = __pgprot(page_copy & ~page_exec_bit);
  1189. protection_map[0x4] = __pgprot(page_readonly);
  1190. protection_map[0x5] = __pgprot(page_readonly);
  1191. protection_map[0x6] = __pgprot(page_copy);
  1192. protection_map[0x7] = __pgprot(page_copy);
  1193. protection_map[0x8] = __pgprot(page_none);
  1194. protection_map[0x9] = __pgprot(page_readonly & ~page_exec_bit);
  1195. protection_map[0xa] = __pgprot(page_shared & ~page_exec_bit);
  1196. protection_map[0xb] = __pgprot(page_shared & ~page_exec_bit);
  1197. protection_map[0xc] = __pgprot(page_readonly);
  1198. protection_map[0xd] = __pgprot(page_readonly);
  1199. protection_map[0xe] = __pgprot(page_shared);
  1200. protection_map[0xf] = __pgprot(page_shared);
  1201. }
  1202. static void __init sun4u_pgprot_init(void)
  1203. {
  1204. unsigned long page_none, page_shared, page_copy, page_readonly;
  1205. unsigned long page_exec_bit;
  1206. PAGE_KERNEL = __pgprot (_PAGE_PRESENT_4U | _PAGE_VALID |
  1207. _PAGE_CACHE_4U | _PAGE_P_4U |
  1208. __ACCESS_BITS_4U | __DIRTY_BITS_4U |
  1209. _PAGE_EXEC_4U);
  1210. PAGE_KERNEL_LOCKED = __pgprot (_PAGE_PRESENT_4U | _PAGE_VALID |
  1211. _PAGE_CACHE_4U | _PAGE_P_4U |
  1212. __ACCESS_BITS_4U | __DIRTY_BITS_4U |
  1213. _PAGE_EXEC_4U | _PAGE_L_4U);
  1214. PAGE_EXEC = __pgprot(_PAGE_EXEC_4U);
  1215. _PAGE_IE = _PAGE_IE_4U;
  1216. _PAGE_E = _PAGE_E_4U;
  1217. _PAGE_CACHE = _PAGE_CACHE_4U;
  1218. pg_iobits = (_PAGE_VALID | _PAGE_PRESENT_4U | __DIRTY_BITS_4U |
  1219. __ACCESS_BITS_4U | _PAGE_E_4U);
  1220. kern_linear_pte_xor[0] = (_PAGE_VALID | _PAGE_SZ4MB_4U) ^
  1221. 0xfffff80000000000;
  1222. kern_linear_pte_xor[0] |= (_PAGE_CP_4U | _PAGE_CV_4U |
  1223. _PAGE_P_4U | _PAGE_W_4U);
  1224. /* XXX Should use 256MB on Panther. XXX */
  1225. kern_linear_pte_xor[1] = kern_linear_pte_xor[0];
  1226. _PAGE_SZBITS = _PAGE_SZBITS_4U;
  1227. _PAGE_ALL_SZ_BITS = (_PAGE_SZ4MB_4U | _PAGE_SZ512K_4U |
  1228. _PAGE_SZ64K_4U | _PAGE_SZ8K_4U |
  1229. _PAGE_SZ32MB_4U | _PAGE_SZ256MB_4U);
  1230. page_none = _PAGE_PRESENT_4U | _PAGE_ACCESSED_4U | _PAGE_CACHE_4U;
  1231. page_shared = (_PAGE_VALID | _PAGE_PRESENT_4U | _PAGE_CACHE_4U |
  1232. __ACCESS_BITS_4U | _PAGE_WRITE_4U | _PAGE_EXEC_4U);
  1233. page_copy = (_PAGE_VALID | _PAGE_PRESENT_4U | _PAGE_CACHE_4U |
  1234. __ACCESS_BITS_4U | _PAGE_EXEC_4U);
  1235. page_readonly = (_PAGE_VALID | _PAGE_PRESENT_4U | _PAGE_CACHE_4U |
  1236. __ACCESS_BITS_4U | _PAGE_EXEC_4U);
  1237. page_exec_bit = _PAGE_EXEC_4U;
  1238. prot_init_common(page_none, page_shared, page_copy, page_readonly,
  1239. page_exec_bit);
  1240. }
  1241. static void __init sun4v_pgprot_init(void)
  1242. {
  1243. unsigned long page_none, page_shared, page_copy, page_readonly;
  1244. unsigned long page_exec_bit;
  1245. PAGE_KERNEL = __pgprot (_PAGE_PRESENT_4V | _PAGE_VALID |
  1246. _PAGE_CACHE_4V | _PAGE_P_4V |
  1247. __ACCESS_BITS_4V | __DIRTY_BITS_4V |
  1248. _PAGE_EXEC_4V);
  1249. PAGE_KERNEL_LOCKED = PAGE_KERNEL;
  1250. PAGE_EXEC = __pgprot(_PAGE_EXEC_4V);
  1251. _PAGE_IE = _PAGE_IE_4V;
  1252. _PAGE_E = _PAGE_E_4V;
  1253. _PAGE_CACHE = _PAGE_CACHE_4V;
  1254. kern_linear_pte_xor[0] = (_PAGE_VALID | _PAGE_SZ4MB_4V) ^
  1255. 0xfffff80000000000;
  1256. kern_linear_pte_xor[0] |= (_PAGE_CP_4V | _PAGE_CV_4V |
  1257. _PAGE_P_4V | _PAGE_W_4V);
  1258. kern_linear_pte_xor[1] = (_PAGE_VALID | _PAGE_SZ256MB_4V) ^
  1259. 0xfffff80000000000;
  1260. kern_linear_pte_xor[1] |= (_PAGE_CP_4V | _PAGE_CV_4V |
  1261. _PAGE_P_4V | _PAGE_W_4V);
  1262. pg_iobits = (_PAGE_VALID | _PAGE_PRESENT_4V | __DIRTY_BITS_4V |
  1263. __ACCESS_BITS_4V | _PAGE_E_4V);
  1264. _PAGE_SZBITS = _PAGE_SZBITS_4V;
  1265. _PAGE_ALL_SZ_BITS = (_PAGE_SZ16GB_4V | _PAGE_SZ2GB_4V |
  1266. _PAGE_SZ256MB_4V | _PAGE_SZ32MB_4V |
  1267. _PAGE_SZ4MB_4V | _PAGE_SZ512K_4V |
  1268. _PAGE_SZ64K_4V | _PAGE_SZ8K_4V);
  1269. page_none = _PAGE_PRESENT_4V | _PAGE_ACCESSED_4V | _PAGE_CACHE_4V;
  1270. page_shared = (_PAGE_VALID | _PAGE_PRESENT_4V | _PAGE_CACHE_4V |
  1271. __ACCESS_BITS_4V | _PAGE_WRITE_4V | _PAGE_EXEC_4V);
  1272. page_copy = (_PAGE_VALID | _PAGE_PRESENT_4V | _PAGE_CACHE_4V |
  1273. __ACCESS_BITS_4V | _PAGE_EXEC_4V);
  1274. page_readonly = (_PAGE_VALID | _PAGE_PRESENT_4V | _PAGE_CACHE_4V |
  1275. __ACCESS_BITS_4V | _PAGE_EXEC_4V);
  1276. page_exec_bit = _PAGE_EXEC_4V;
  1277. prot_init_common(page_none, page_shared, page_copy, page_readonly,
  1278. page_exec_bit);
  1279. }
  1280. unsigned long pte_sz_bits(unsigned long sz)
  1281. {
  1282. if (tlb_type == hypervisor) {
  1283. switch (sz) {
  1284. case 8 * 1024:
  1285. default:
  1286. return _PAGE_SZ8K_4V;
  1287. case 64 * 1024:
  1288. return _PAGE_SZ64K_4V;
  1289. case 512 * 1024:
  1290. return _PAGE_SZ512K_4V;
  1291. case 4 * 1024 * 1024:
  1292. return _PAGE_SZ4MB_4V;
  1293. };
  1294. } else {
  1295. switch (sz) {
  1296. case 8 * 1024:
  1297. default:
  1298. return _PAGE_SZ8K_4U;
  1299. case 64 * 1024:
  1300. return _PAGE_SZ64K_4U;
  1301. case 512 * 1024:
  1302. return _PAGE_SZ512K_4U;
  1303. case 4 * 1024 * 1024:
  1304. return _PAGE_SZ4MB_4U;
  1305. };
  1306. }
  1307. }
  1308. pte_t mk_pte_io(unsigned long page, pgprot_t prot, int space, unsigned long page_size)
  1309. {
  1310. pte_t pte;
  1311. pte_val(pte) = page | pgprot_val(pgprot_noncached(prot));
  1312. pte_val(pte) |= (((unsigned long)space) << 32);
  1313. pte_val(pte) |= pte_sz_bits(page_size);
  1314. return pte;
  1315. }
  1316. static unsigned long kern_large_tte(unsigned long paddr)
  1317. {
  1318. unsigned long val;
  1319. val = (_PAGE_VALID | _PAGE_SZ4MB_4U |
  1320. _PAGE_CP_4U | _PAGE_CV_4U | _PAGE_P_4U |
  1321. _PAGE_EXEC_4U | _PAGE_L_4U | _PAGE_W_4U);
  1322. if (tlb_type == hypervisor)
  1323. val = (_PAGE_VALID | _PAGE_SZ4MB_4V |
  1324. _PAGE_CP_4V | _PAGE_CV_4V | _PAGE_P_4V |
  1325. _PAGE_EXEC_4V | _PAGE_W_4V);
  1326. return val | paddr;
  1327. }
  1328. /*
  1329. * Translate PROM's mapping we capture at boot time into physical address.
  1330. * The second parameter is only set from prom_callback() invocations.
  1331. */
  1332. unsigned long prom_virt_to_phys(unsigned long promva, int *error)
  1333. {
  1334. unsigned long mask;
  1335. int i;
  1336. mask = _PAGE_PADDR_4U;
  1337. if (tlb_type == hypervisor)
  1338. mask = _PAGE_PADDR_4V;
  1339. for (i = 0; i < prom_trans_ents; i++) {
  1340. struct linux_prom_translation *p = &prom_trans[i];
  1341. if (promva >= p->virt &&
  1342. promva < (p->virt + p->size)) {
  1343. unsigned long base = p->data & mask;
  1344. if (error)
  1345. *error = 0;
  1346. return base + (promva & (8192 - 1));
  1347. }
  1348. }
  1349. if (error)
  1350. *error = 1;
  1351. return 0UL;
  1352. }
  1353. /* XXX We should kill off this ugly thing at so me point. XXX */
  1354. unsigned long sun4u_get_pte(unsigned long addr)
  1355. {
  1356. pgd_t *pgdp;
  1357. pud_t *pudp;
  1358. pmd_t *pmdp;
  1359. pte_t *ptep;
  1360. unsigned long mask = _PAGE_PADDR_4U;
  1361. if (tlb_type == hypervisor)
  1362. mask = _PAGE_PADDR_4V;
  1363. if (addr >= PAGE_OFFSET)
  1364. return addr & mask;
  1365. if ((addr >= LOW_OBP_ADDRESS) && (addr < HI_OBP_ADDRESS))
  1366. return prom_virt_to_phys(addr, NULL);
  1367. pgdp = pgd_offset_k(addr);
  1368. pudp = pud_offset(pgdp, addr);
  1369. pmdp = pmd_offset(pudp, addr);
  1370. ptep = pte_offset_kernel(pmdp, addr);
  1371. return pte_val(*ptep) & mask;
  1372. }
  1373. /* If not locked, zap it. */
  1374. void __flush_tlb_all(void)
  1375. {
  1376. unsigned long pstate;
  1377. int i;
  1378. __asm__ __volatile__("flushw\n\t"
  1379. "rdpr %%pstate, %0\n\t"
  1380. "wrpr %0, %1, %%pstate"
  1381. : "=r" (pstate)
  1382. : "i" (PSTATE_IE));
  1383. if (tlb_type == spitfire) {
  1384. for (i = 0; i < 64; i++) {
  1385. /* Spitfire Errata #32 workaround */
  1386. /* NOTE: Always runs on spitfire, so no
  1387. * cheetah+ page size encodings.
  1388. */
  1389. __asm__ __volatile__("stxa %0, [%1] %2\n\t"
  1390. "flush %%g6"
  1391. : /* No outputs */
  1392. : "r" (0),
  1393. "r" (PRIMARY_CONTEXT), "i" (ASI_DMMU));
  1394. if (!(spitfire_get_dtlb_data(i) & _PAGE_L_4U)) {
  1395. __asm__ __volatile__("stxa %%g0, [%0] %1\n\t"
  1396. "membar #Sync"
  1397. : /* no outputs */
  1398. : "r" (TLB_TAG_ACCESS), "i" (ASI_DMMU));
  1399. spitfire_put_dtlb_data(i, 0x0UL);
  1400. }
  1401. /* Spitfire Errata #32 workaround */
  1402. /* NOTE: Always runs on spitfire, so no
  1403. * cheetah+ page size encodings.
  1404. */
  1405. __asm__ __volatile__("stxa %0, [%1] %2\n\t"
  1406. "flush %%g6"
  1407. : /* No outputs */
  1408. : "r" (0),
  1409. "r" (PRIMARY_CONTEXT), "i" (ASI_DMMU));
  1410. if (!(spitfire_get_itlb_data(i) & _PAGE_L_4U)) {
  1411. __asm__ __volatile__("stxa %%g0, [%0] %1\n\t"
  1412. "membar #Sync"
  1413. : /* no outputs */
  1414. : "r" (TLB_TAG_ACCESS), "i" (ASI_IMMU));
  1415. spitfire_put_itlb_data(i, 0x0UL);
  1416. }
  1417. }
  1418. } else if (tlb_type == cheetah || tlb_type == cheetah_plus) {
  1419. cheetah_flush_dtlb_all();
  1420. cheetah_flush_itlb_all();
  1421. }
  1422. __asm__ __volatile__("wrpr %0, 0, %%pstate"
  1423. : : "r" (pstate));
  1424. }