init.c 46 KB

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