init_64.c 59 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394
  1. /*
  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/initrd.h>
  16. #include <linux/swap.h>
  17. #include <linux/pagemap.h>
  18. #include <linux/poison.h>
  19. #include <linux/fs.h>
  20. #include <linux/seq_file.h>
  21. #include <linux/kprobes.h>
  22. #include <linux/cache.h>
  23. #include <linux/sort.h>
  24. #include <linux/percpu.h>
  25. #include <linux/memblock.h>
  26. #include <linux/mmzone.h>
  27. #include <linux/gfp.h>
  28. #include <asm/head.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/mdesc.h>
  47. #include <asm/cpudata.h>
  48. #include <asm/irq.h>
  49. #include "init_64.h"
  50. unsigned long kern_linear_pte_xor[2] __read_mostly;
  51. /* A bitmap, one bit for every 256MB of physical memory. If the bit
  52. * is clear, we should use a 4MB page (via kern_linear_pte_xor[0]) else
  53. * if set we should use a 256MB page (via kern_linear_pte_xor[1]).
  54. */
  55. unsigned long kpte_linear_bitmap[KPTE_BITMAP_BYTES / sizeof(unsigned long)];
  56. #ifndef CONFIG_DEBUG_PAGEALLOC
  57. /* A special kernel TSB for 4MB and 256MB linear mappings.
  58. * Space is allocated for this right after the trap table
  59. * in arch/sparc64/kernel/head.S
  60. */
  61. extern struct tsb swapper_4m_tsb[KERNEL_TSB4M_NENTRIES];
  62. #endif
  63. #define MAX_BANKS 32
  64. static struct linux_prom64_registers pavail[MAX_BANKS] __devinitdata;
  65. static int pavail_ents __devinitdata;
  66. static int cmp_p64(const void *a, const void *b)
  67. {
  68. const struct linux_prom64_registers *x = a, *y = b;
  69. if (x->phys_addr > y->phys_addr)
  70. return 1;
  71. if (x->phys_addr < y->phys_addr)
  72. return -1;
  73. return 0;
  74. }
  75. static void __init read_obp_memory(const char *property,
  76. struct linux_prom64_registers *regs,
  77. int *num_ents)
  78. {
  79. phandle node = prom_finddevice("/memory");
  80. int prop_size = prom_getproplen(node, property);
  81. int ents, ret, i;
  82. ents = prop_size / sizeof(struct linux_prom64_registers);
  83. if (ents > MAX_BANKS) {
  84. prom_printf("The machine has more %s property entries than "
  85. "this kernel can support (%d).\n",
  86. property, MAX_BANKS);
  87. prom_halt();
  88. }
  89. ret = prom_getproperty(node, property, (char *) regs, prop_size);
  90. if (ret == -1) {
  91. prom_printf("Couldn't get %s property from /memory.\n");
  92. prom_halt();
  93. }
  94. /* Sanitize what we got from the firmware, by page aligning
  95. * everything.
  96. */
  97. for (i = 0; i < ents; i++) {
  98. unsigned long base, size;
  99. base = regs[i].phys_addr;
  100. size = regs[i].reg_size;
  101. size &= PAGE_MASK;
  102. if (base & ~PAGE_MASK) {
  103. unsigned long new_base = PAGE_ALIGN(base);
  104. size -= new_base - base;
  105. if ((long) size < 0L)
  106. size = 0UL;
  107. base = new_base;
  108. }
  109. if (size == 0UL) {
  110. /* If it is empty, simply get rid of it.
  111. * This simplifies the logic of the other
  112. * functions that process these arrays.
  113. */
  114. memmove(&regs[i], &regs[i + 1],
  115. (ents - i - 1) * sizeof(regs[0]));
  116. i--;
  117. ents--;
  118. continue;
  119. }
  120. regs[i].phys_addr = base;
  121. regs[i].reg_size = size;
  122. }
  123. *num_ents = ents;
  124. sort(regs, ents, sizeof(struct linux_prom64_registers),
  125. cmp_p64, NULL);
  126. }
  127. unsigned long sparc64_valid_addr_bitmap[VALID_ADDR_BITMAP_BYTES /
  128. sizeof(unsigned long)];
  129. EXPORT_SYMBOL(sparc64_valid_addr_bitmap);
  130. /* Kernel physical address base and size in bytes. */
  131. unsigned long kern_base __read_mostly;
  132. unsigned long kern_size __read_mostly;
  133. /* Initial ramdisk setup */
  134. extern unsigned long sparc_ramdisk_image64;
  135. extern unsigned int sparc_ramdisk_image;
  136. extern unsigned int sparc_ramdisk_size;
  137. struct page *mem_map_zero __read_mostly;
  138. EXPORT_SYMBOL(mem_map_zero);
  139. unsigned int sparc64_highest_unlocked_tlb_ent __read_mostly;
  140. unsigned long sparc64_kern_pri_context __read_mostly;
  141. unsigned long sparc64_kern_pri_nuc_bits __read_mostly;
  142. unsigned long sparc64_kern_sec_context __read_mostly;
  143. int num_kernel_image_mappings;
  144. #ifdef CONFIG_DEBUG_DCFLUSH
  145. atomic_t dcpage_flushes = ATOMIC_INIT(0);
  146. #ifdef CONFIG_SMP
  147. atomic_t dcpage_flushes_xcall = ATOMIC_INIT(0);
  148. #endif
  149. #endif
  150. inline void flush_dcache_page_impl(struct page *page)
  151. {
  152. BUG_ON(tlb_type == hypervisor);
  153. #ifdef CONFIG_DEBUG_DCFLUSH
  154. atomic_inc(&dcpage_flushes);
  155. #endif
  156. #ifdef DCACHE_ALIASING_POSSIBLE
  157. __flush_dcache_page(page_address(page),
  158. ((tlb_type == spitfire) &&
  159. page_mapping(page) != NULL));
  160. #else
  161. if (page_mapping(page) != NULL &&
  162. tlb_type == spitfire)
  163. __flush_icache_page(__pa(page_address(page)));
  164. #endif
  165. }
  166. #define PG_dcache_dirty PG_arch_1
  167. #define PG_dcache_cpu_shift 32UL
  168. #define PG_dcache_cpu_mask \
  169. ((1UL<<ilog2(roundup_pow_of_two(NR_CPUS)))-1UL)
  170. #define dcache_dirty_cpu(page) \
  171. (((page)->flags >> PG_dcache_cpu_shift) & PG_dcache_cpu_mask)
  172. static inline void set_dcache_dirty(struct page *page, int this_cpu)
  173. {
  174. unsigned long mask = this_cpu;
  175. unsigned long non_cpu_bits;
  176. non_cpu_bits = ~(PG_dcache_cpu_mask << PG_dcache_cpu_shift);
  177. mask = (mask << PG_dcache_cpu_shift) | (1UL << PG_dcache_dirty);
  178. __asm__ __volatile__("1:\n\t"
  179. "ldx [%2], %%g7\n\t"
  180. "and %%g7, %1, %%g1\n\t"
  181. "or %%g1, %0, %%g1\n\t"
  182. "casx [%2], %%g7, %%g1\n\t"
  183. "cmp %%g7, %%g1\n\t"
  184. "bne,pn %%xcc, 1b\n\t"
  185. " nop"
  186. : /* no outputs */
  187. : "r" (mask), "r" (non_cpu_bits), "r" (&page->flags)
  188. : "g1", "g7");
  189. }
  190. static inline void clear_dcache_dirty_cpu(struct page *page, unsigned long cpu)
  191. {
  192. unsigned long mask = (1UL << PG_dcache_dirty);
  193. __asm__ __volatile__("! test_and_clear_dcache_dirty\n"
  194. "1:\n\t"
  195. "ldx [%2], %%g7\n\t"
  196. "srlx %%g7, %4, %%g1\n\t"
  197. "and %%g1, %3, %%g1\n\t"
  198. "cmp %%g1, %0\n\t"
  199. "bne,pn %%icc, 2f\n\t"
  200. " andn %%g7, %1, %%g1\n\t"
  201. "casx [%2], %%g7, %%g1\n\t"
  202. "cmp %%g7, %%g1\n\t"
  203. "bne,pn %%xcc, 1b\n\t"
  204. " nop\n"
  205. "2:"
  206. : /* no outputs */
  207. : "r" (cpu), "r" (mask), "r" (&page->flags),
  208. "i" (PG_dcache_cpu_mask),
  209. "i" (PG_dcache_cpu_shift)
  210. : "g1", "g7");
  211. }
  212. static inline void tsb_insert(struct tsb *ent, unsigned long tag, unsigned long pte)
  213. {
  214. unsigned long tsb_addr = (unsigned long) ent;
  215. if (tlb_type == cheetah_plus || tlb_type == hypervisor)
  216. tsb_addr = __pa(tsb_addr);
  217. __tsb_insert(tsb_addr, tag, pte);
  218. }
  219. unsigned long _PAGE_ALL_SZ_BITS __read_mostly;
  220. unsigned long _PAGE_SZBITS __read_mostly;
  221. static void flush_dcache(unsigned long pfn)
  222. {
  223. struct page *page;
  224. page = pfn_to_page(pfn);
  225. if (page) {
  226. unsigned long pg_flags;
  227. pg_flags = page->flags;
  228. if (pg_flags & (1UL << PG_dcache_dirty)) {
  229. int cpu = ((pg_flags >> PG_dcache_cpu_shift) &
  230. PG_dcache_cpu_mask);
  231. int this_cpu = get_cpu();
  232. /* This is just to optimize away some function calls
  233. * in the SMP case.
  234. */
  235. if (cpu == this_cpu)
  236. flush_dcache_page_impl(page);
  237. else
  238. smp_flush_dcache_page_impl(page, cpu);
  239. clear_dcache_dirty_cpu(page, cpu);
  240. put_cpu();
  241. }
  242. }
  243. }
  244. void update_mmu_cache(struct vm_area_struct *vma, unsigned long address, pte_t *ptep)
  245. {
  246. struct mm_struct *mm;
  247. struct tsb *tsb;
  248. unsigned long tag, flags;
  249. unsigned long tsb_index, tsb_hash_shift;
  250. pte_t pte = *ptep;
  251. if (tlb_type != hypervisor) {
  252. unsigned long pfn = pte_pfn(pte);
  253. if (pfn_valid(pfn))
  254. flush_dcache(pfn);
  255. }
  256. mm = vma->vm_mm;
  257. tsb_index = MM_TSB_BASE;
  258. tsb_hash_shift = PAGE_SHIFT;
  259. spin_lock_irqsave(&mm->context.lock, flags);
  260. #ifdef CONFIG_HUGETLB_PAGE
  261. if (mm->context.tsb_block[MM_TSB_HUGE].tsb != NULL) {
  262. if ((tlb_type == hypervisor &&
  263. (pte_val(pte) & _PAGE_SZALL_4V) == _PAGE_SZHUGE_4V) ||
  264. (tlb_type != hypervisor &&
  265. (pte_val(pte) & _PAGE_SZALL_4U) == _PAGE_SZHUGE_4U)) {
  266. tsb_index = MM_TSB_HUGE;
  267. tsb_hash_shift = HPAGE_SHIFT;
  268. }
  269. }
  270. #endif
  271. tsb = mm->context.tsb_block[tsb_index].tsb;
  272. tsb += ((address >> tsb_hash_shift) &
  273. (mm->context.tsb_block[tsb_index].tsb_nentries - 1UL));
  274. tag = (address >> 22UL);
  275. tsb_insert(tsb, tag, pte_val(pte));
  276. spin_unlock_irqrestore(&mm->context.lock, flags);
  277. }
  278. void flush_dcache_page(struct page *page)
  279. {
  280. struct address_space *mapping;
  281. int this_cpu;
  282. if (tlb_type == hypervisor)
  283. return;
  284. /* Do not bother with the expensive D-cache flush if it
  285. * is merely the zero page. The 'bigcore' testcase in GDB
  286. * causes this case to run millions of times.
  287. */
  288. if (page == ZERO_PAGE(0))
  289. return;
  290. this_cpu = get_cpu();
  291. mapping = page_mapping(page);
  292. if (mapping && !mapping_mapped(mapping)) {
  293. int dirty = test_bit(PG_dcache_dirty, &page->flags);
  294. if (dirty) {
  295. int dirty_cpu = dcache_dirty_cpu(page);
  296. if (dirty_cpu == this_cpu)
  297. goto out;
  298. smp_flush_dcache_page_impl(page, dirty_cpu);
  299. }
  300. set_dcache_dirty(page, this_cpu);
  301. } else {
  302. /* We could delay the flush for the !page_mapping
  303. * case too. But that case is for exec env/arg
  304. * pages and those are %99 certainly going to get
  305. * faulted into the tlb (and thus flushed) anyways.
  306. */
  307. flush_dcache_page_impl(page);
  308. }
  309. out:
  310. put_cpu();
  311. }
  312. EXPORT_SYMBOL(flush_dcache_page);
  313. void __kprobes flush_icache_range(unsigned long start, unsigned long end)
  314. {
  315. /* Cheetah and Hypervisor platform cpus have coherent I-cache. */
  316. if (tlb_type == spitfire) {
  317. unsigned long kaddr;
  318. /* This code only runs on Spitfire cpus so this is
  319. * why we can assume _PAGE_PADDR_4U.
  320. */
  321. for (kaddr = start; kaddr < end; kaddr += PAGE_SIZE) {
  322. unsigned long paddr, mask = _PAGE_PADDR_4U;
  323. if (kaddr >= PAGE_OFFSET)
  324. paddr = kaddr & mask;
  325. else {
  326. pgd_t *pgdp = pgd_offset_k(kaddr);
  327. pud_t *pudp = pud_offset(pgdp, kaddr);
  328. pmd_t *pmdp = pmd_offset(pudp, kaddr);
  329. pte_t *ptep = pte_offset_kernel(pmdp, kaddr);
  330. paddr = pte_val(*ptep) & mask;
  331. }
  332. __flush_icache_page(paddr);
  333. }
  334. }
  335. }
  336. EXPORT_SYMBOL(flush_icache_range);
  337. void mmu_info(struct seq_file *m)
  338. {
  339. if (tlb_type == cheetah)
  340. seq_printf(m, "MMU Type\t: Cheetah\n");
  341. else if (tlb_type == cheetah_plus)
  342. seq_printf(m, "MMU Type\t: Cheetah+\n");
  343. else if (tlb_type == spitfire)
  344. seq_printf(m, "MMU Type\t: Spitfire\n");
  345. else if (tlb_type == hypervisor)
  346. seq_printf(m, "MMU Type\t: Hypervisor (sun4v)\n");
  347. else
  348. seq_printf(m, "MMU Type\t: ???\n");
  349. #ifdef CONFIG_DEBUG_DCFLUSH
  350. seq_printf(m, "DCPageFlushes\t: %d\n",
  351. atomic_read(&dcpage_flushes));
  352. #ifdef CONFIG_SMP
  353. seq_printf(m, "DCPageFlushesXC\t: %d\n",
  354. atomic_read(&dcpage_flushes_xcall));
  355. #endif /* CONFIG_SMP */
  356. #endif /* CONFIG_DEBUG_DCFLUSH */
  357. }
  358. struct linux_prom_translation prom_trans[512] __read_mostly;
  359. unsigned int prom_trans_ents __read_mostly;
  360. unsigned long kern_locked_tte_data;
  361. /* The obp translations are saved based on 8k pagesize, since obp can
  362. * use a mixture of pagesizes. Misses to the LOW_OBP_ADDRESS ->
  363. * HI_OBP_ADDRESS range are handled in ktlb.S.
  364. */
  365. static inline int in_obp_range(unsigned long vaddr)
  366. {
  367. return (vaddr >= LOW_OBP_ADDRESS &&
  368. vaddr < HI_OBP_ADDRESS);
  369. }
  370. static int cmp_ptrans(const void *a, const void *b)
  371. {
  372. const struct linux_prom_translation *x = a, *y = b;
  373. if (x->virt > y->virt)
  374. return 1;
  375. if (x->virt < y->virt)
  376. return -1;
  377. return 0;
  378. }
  379. /* Read OBP translations property into 'prom_trans[]'. */
  380. static void __init read_obp_translations(void)
  381. {
  382. int n, node, ents, first, last, i;
  383. node = prom_finddevice("/virtual-memory");
  384. n = prom_getproplen(node, "translations");
  385. if (unlikely(n == 0 || n == -1)) {
  386. prom_printf("prom_mappings: Couldn't get size.\n");
  387. prom_halt();
  388. }
  389. if (unlikely(n > sizeof(prom_trans))) {
  390. prom_printf("prom_mappings: Size %Zd is too big.\n", n);
  391. prom_halt();
  392. }
  393. if ((n = prom_getproperty(node, "translations",
  394. (char *)&prom_trans[0],
  395. sizeof(prom_trans))) == -1) {
  396. prom_printf("prom_mappings: Couldn't get property.\n");
  397. prom_halt();
  398. }
  399. n = n / sizeof(struct linux_prom_translation);
  400. ents = n;
  401. sort(prom_trans, ents, sizeof(struct linux_prom_translation),
  402. cmp_ptrans, NULL);
  403. /* Now kick out all the non-OBP entries. */
  404. for (i = 0; i < ents; i++) {
  405. if (in_obp_range(prom_trans[i].virt))
  406. break;
  407. }
  408. first = i;
  409. for (; i < ents; i++) {
  410. if (!in_obp_range(prom_trans[i].virt))
  411. break;
  412. }
  413. last = i;
  414. for (i = 0; i < (last - first); i++) {
  415. struct linux_prom_translation *src = &prom_trans[i + first];
  416. struct linux_prom_translation *dest = &prom_trans[i];
  417. *dest = *src;
  418. }
  419. for (; i < ents; i++) {
  420. struct linux_prom_translation *dest = &prom_trans[i];
  421. dest->virt = dest->size = dest->data = 0x0UL;
  422. }
  423. prom_trans_ents = last - first;
  424. if (tlb_type == spitfire) {
  425. /* Clear diag TTE bits. */
  426. for (i = 0; i < prom_trans_ents; i++)
  427. prom_trans[i].data &= ~0x0003fe0000000000UL;
  428. }
  429. /* Force execute bit on. */
  430. for (i = 0; i < prom_trans_ents; i++)
  431. prom_trans[i].data |= (tlb_type == hypervisor ?
  432. _PAGE_EXEC_4V : _PAGE_EXEC_4U);
  433. }
  434. static void __init hypervisor_tlb_lock(unsigned long vaddr,
  435. unsigned long pte,
  436. unsigned long mmu)
  437. {
  438. unsigned long ret = sun4v_mmu_map_perm_addr(vaddr, 0, pte, mmu);
  439. if (ret != 0) {
  440. prom_printf("hypervisor_tlb_lock[%lx:%lx:%lx:%lx]: "
  441. "errors with %lx\n", vaddr, 0, pte, mmu, ret);
  442. prom_halt();
  443. }
  444. }
  445. static unsigned long kern_large_tte(unsigned long paddr);
  446. static void __init remap_kernel(void)
  447. {
  448. unsigned long phys_page, tte_vaddr, tte_data;
  449. int i, tlb_ent = sparc64_highest_locked_tlbent();
  450. tte_vaddr = (unsigned long) KERNBASE;
  451. phys_page = (prom_boot_mapping_phys_low >> 22UL) << 22UL;
  452. tte_data = kern_large_tte(phys_page);
  453. kern_locked_tte_data = tte_data;
  454. /* Now lock us into the TLBs via Hypervisor or OBP. */
  455. if (tlb_type == hypervisor) {
  456. for (i = 0; i < num_kernel_image_mappings; i++) {
  457. hypervisor_tlb_lock(tte_vaddr, tte_data, HV_MMU_DMMU);
  458. hypervisor_tlb_lock(tte_vaddr, tte_data, HV_MMU_IMMU);
  459. tte_vaddr += 0x400000;
  460. tte_data += 0x400000;
  461. }
  462. } else {
  463. for (i = 0; i < num_kernel_image_mappings; i++) {
  464. prom_dtlb_load(tlb_ent - i, tte_data, tte_vaddr);
  465. prom_itlb_load(tlb_ent - i, tte_data, tte_vaddr);
  466. tte_vaddr += 0x400000;
  467. tte_data += 0x400000;
  468. }
  469. sparc64_highest_unlocked_tlb_ent = tlb_ent - i;
  470. }
  471. if (tlb_type == cheetah_plus) {
  472. sparc64_kern_pri_context = (CTX_CHEETAH_PLUS_CTX0 |
  473. CTX_CHEETAH_PLUS_NUC);
  474. sparc64_kern_pri_nuc_bits = CTX_CHEETAH_PLUS_NUC;
  475. sparc64_kern_sec_context = CTX_CHEETAH_PLUS_CTX0;
  476. }
  477. }
  478. static void __init inherit_prom_mappings(void)
  479. {
  480. /* Now fixup OBP's idea about where we really are mapped. */
  481. printk("Remapping the kernel... ");
  482. remap_kernel();
  483. printk("done.\n");
  484. }
  485. void prom_world(int enter)
  486. {
  487. if (!enter)
  488. set_fs((mm_segment_t) { get_thread_current_ds() });
  489. __asm__ __volatile__("flushw");
  490. }
  491. void __flush_dcache_range(unsigned long start, unsigned long end)
  492. {
  493. unsigned long va;
  494. if (tlb_type == spitfire) {
  495. int n = 0;
  496. for (va = start; va < end; va += 32) {
  497. spitfire_put_dcache_tag(va & 0x3fe0, 0x0);
  498. if (++n >= 512)
  499. break;
  500. }
  501. } else if (tlb_type == cheetah || tlb_type == cheetah_plus) {
  502. start = __pa(start);
  503. end = __pa(end);
  504. for (va = start; va < end; va += 32)
  505. __asm__ __volatile__("stxa %%g0, [%0] %1\n\t"
  506. "membar #Sync"
  507. : /* no outputs */
  508. : "r" (va),
  509. "i" (ASI_DCACHE_INVALIDATE));
  510. }
  511. }
  512. EXPORT_SYMBOL(__flush_dcache_range);
  513. /* get_new_mmu_context() uses "cache + 1". */
  514. DEFINE_SPINLOCK(ctx_alloc_lock);
  515. unsigned long tlb_context_cache = CTX_FIRST_VERSION - 1;
  516. #define MAX_CTX_NR (1UL << CTX_NR_BITS)
  517. #define CTX_BMAP_SLOTS BITS_TO_LONGS(MAX_CTX_NR)
  518. DECLARE_BITMAP(mmu_context_bmap, MAX_CTX_NR);
  519. /* Caller does TLB context flushing on local CPU if necessary.
  520. * The caller also ensures that CTX_VALID(mm->context) is false.
  521. *
  522. * We must be careful about boundary cases so that we never
  523. * let the user have CTX 0 (nucleus) or we ever use a CTX
  524. * version of zero (and thus NO_CONTEXT would not be caught
  525. * by version mis-match tests in mmu_context.h).
  526. *
  527. * Always invoked with interrupts disabled.
  528. */
  529. void get_new_mmu_context(struct mm_struct *mm)
  530. {
  531. unsigned long ctx, new_ctx;
  532. unsigned long orig_pgsz_bits;
  533. unsigned long flags;
  534. int new_version;
  535. spin_lock_irqsave(&ctx_alloc_lock, flags);
  536. orig_pgsz_bits = (mm->context.sparc64_ctx_val & CTX_PGSZ_MASK);
  537. ctx = (tlb_context_cache + 1) & CTX_NR_MASK;
  538. new_ctx = find_next_zero_bit(mmu_context_bmap, 1 << CTX_NR_BITS, ctx);
  539. new_version = 0;
  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. new_version = 1;
  562. goto out;
  563. }
  564. }
  565. mmu_context_bmap[new_ctx>>6] |= (1UL << (new_ctx & 63));
  566. new_ctx |= (tlb_context_cache & CTX_VERSION_MASK);
  567. out:
  568. tlb_context_cache = new_ctx;
  569. mm->context.sparc64_ctx_val = new_ctx | orig_pgsz_bits;
  570. spin_unlock_irqrestore(&ctx_alloc_lock, flags);
  571. if (unlikely(new_version))
  572. smp_new_mmu_context_version();
  573. }
  574. static int numa_enabled = 1;
  575. static int numa_debug;
  576. static int __init early_numa(char *p)
  577. {
  578. if (!p)
  579. return 0;
  580. if (strstr(p, "off"))
  581. numa_enabled = 0;
  582. if (strstr(p, "debug"))
  583. numa_debug = 1;
  584. return 0;
  585. }
  586. early_param("numa", early_numa);
  587. #define numadbg(f, a...) \
  588. do { if (numa_debug) \
  589. printk(KERN_INFO f, ## a); \
  590. } while (0)
  591. static void __init find_ramdisk(unsigned long phys_base)
  592. {
  593. #ifdef CONFIG_BLK_DEV_INITRD
  594. if (sparc_ramdisk_image || sparc_ramdisk_image64) {
  595. unsigned long ramdisk_image;
  596. /* Older versions of the bootloader only supported a
  597. * 32-bit physical address for the ramdisk image
  598. * location, stored at sparc_ramdisk_image. Newer
  599. * SILO versions set sparc_ramdisk_image to zero and
  600. * provide a full 64-bit physical address at
  601. * sparc_ramdisk_image64.
  602. */
  603. ramdisk_image = sparc_ramdisk_image;
  604. if (!ramdisk_image)
  605. ramdisk_image = sparc_ramdisk_image64;
  606. /* Another bootloader quirk. The bootloader normalizes
  607. * the physical address to KERNBASE, so we have to
  608. * factor that back out and add in the lowest valid
  609. * physical page address to get the true physical address.
  610. */
  611. ramdisk_image -= KERNBASE;
  612. ramdisk_image += phys_base;
  613. numadbg("Found ramdisk at physical address 0x%lx, size %u\n",
  614. ramdisk_image, sparc_ramdisk_size);
  615. initrd_start = ramdisk_image;
  616. initrd_end = ramdisk_image + sparc_ramdisk_size;
  617. memblock_reserve(initrd_start, sparc_ramdisk_size);
  618. initrd_start += PAGE_OFFSET;
  619. initrd_end += PAGE_OFFSET;
  620. }
  621. #endif
  622. }
  623. struct node_mem_mask {
  624. unsigned long mask;
  625. unsigned long val;
  626. unsigned long bootmem_paddr;
  627. };
  628. static struct node_mem_mask node_masks[MAX_NUMNODES];
  629. static int num_node_masks;
  630. int numa_cpu_lookup_table[NR_CPUS];
  631. cpumask_t numa_cpumask_lookup_table[MAX_NUMNODES];
  632. #ifdef CONFIG_NEED_MULTIPLE_NODES
  633. struct mdesc_mblock {
  634. u64 base;
  635. u64 size;
  636. u64 offset; /* RA-to-PA */
  637. };
  638. static struct mdesc_mblock *mblocks;
  639. static int num_mblocks;
  640. static unsigned long ra_to_pa(unsigned long addr)
  641. {
  642. int i;
  643. for (i = 0; i < num_mblocks; i++) {
  644. struct mdesc_mblock *m = &mblocks[i];
  645. if (addr >= m->base &&
  646. addr < (m->base + m->size)) {
  647. addr += m->offset;
  648. break;
  649. }
  650. }
  651. return addr;
  652. }
  653. static int find_node(unsigned long addr)
  654. {
  655. int i;
  656. addr = ra_to_pa(addr);
  657. for (i = 0; i < num_node_masks; i++) {
  658. struct node_mem_mask *p = &node_masks[i];
  659. if ((addr & p->mask) == p->val)
  660. return i;
  661. }
  662. return -1;
  663. }
  664. static u64 memblock_nid_range(u64 start, u64 end, int *nid)
  665. {
  666. *nid = find_node(start);
  667. start += PAGE_SIZE;
  668. while (start < end) {
  669. int n = find_node(start);
  670. if (n != *nid)
  671. break;
  672. start += PAGE_SIZE;
  673. }
  674. if (start > end)
  675. start = end;
  676. return start;
  677. }
  678. #else
  679. static u64 memblock_nid_range(u64 start, u64 end, int *nid)
  680. {
  681. *nid = 0;
  682. return end;
  683. }
  684. #endif
  685. /* This must be invoked after performing all of the necessary
  686. * memblock_set_node() calls for 'nid'. We need to be able to get
  687. * correct data from get_pfn_range_for_nid().
  688. */
  689. static void __init allocate_node_data(int nid)
  690. {
  691. unsigned long paddr, num_pages, start_pfn, end_pfn;
  692. struct pglist_data *p;
  693. #ifdef CONFIG_NEED_MULTIPLE_NODES
  694. paddr = memblock_alloc_try_nid(sizeof(struct pglist_data), SMP_CACHE_BYTES, nid);
  695. if (!paddr) {
  696. prom_printf("Cannot allocate pglist_data for nid[%d]\n", nid);
  697. prom_halt();
  698. }
  699. NODE_DATA(nid) = __va(paddr);
  700. memset(NODE_DATA(nid), 0, sizeof(struct pglist_data));
  701. NODE_DATA(nid)->bdata = &bootmem_node_data[nid];
  702. #endif
  703. p = NODE_DATA(nid);
  704. get_pfn_range_for_nid(nid, &start_pfn, &end_pfn);
  705. p->node_start_pfn = start_pfn;
  706. p->node_spanned_pages = end_pfn - start_pfn;
  707. if (p->node_spanned_pages) {
  708. num_pages = bootmem_bootmap_pages(p->node_spanned_pages);
  709. paddr = memblock_alloc_try_nid(num_pages << PAGE_SHIFT, PAGE_SIZE, nid);
  710. if (!paddr) {
  711. prom_printf("Cannot allocate bootmap for nid[%d]\n",
  712. nid);
  713. prom_halt();
  714. }
  715. node_masks[nid].bootmem_paddr = paddr;
  716. }
  717. }
  718. static void init_node_masks_nonnuma(void)
  719. {
  720. int i;
  721. numadbg("Initializing tables for non-numa.\n");
  722. node_masks[0].mask = node_masks[0].val = 0;
  723. num_node_masks = 1;
  724. for (i = 0; i < NR_CPUS; i++)
  725. numa_cpu_lookup_table[i] = 0;
  726. cpumask_setall(&numa_cpumask_lookup_table[0]);
  727. }
  728. #ifdef CONFIG_NEED_MULTIPLE_NODES
  729. struct pglist_data *node_data[MAX_NUMNODES];
  730. EXPORT_SYMBOL(numa_cpu_lookup_table);
  731. EXPORT_SYMBOL(numa_cpumask_lookup_table);
  732. EXPORT_SYMBOL(node_data);
  733. struct mdesc_mlgroup {
  734. u64 node;
  735. u64 latency;
  736. u64 match;
  737. u64 mask;
  738. };
  739. static struct mdesc_mlgroup *mlgroups;
  740. static int num_mlgroups;
  741. static int scan_pio_for_cfg_handle(struct mdesc_handle *md, u64 pio,
  742. u32 cfg_handle)
  743. {
  744. u64 arc;
  745. mdesc_for_each_arc(arc, md, pio, MDESC_ARC_TYPE_FWD) {
  746. u64 target = mdesc_arc_target(md, arc);
  747. const u64 *val;
  748. val = mdesc_get_property(md, target,
  749. "cfg-handle", NULL);
  750. if (val && *val == cfg_handle)
  751. return 0;
  752. }
  753. return -ENODEV;
  754. }
  755. static int scan_arcs_for_cfg_handle(struct mdesc_handle *md, u64 grp,
  756. u32 cfg_handle)
  757. {
  758. u64 arc, candidate, best_latency = ~(u64)0;
  759. candidate = MDESC_NODE_NULL;
  760. mdesc_for_each_arc(arc, md, grp, MDESC_ARC_TYPE_FWD) {
  761. u64 target = mdesc_arc_target(md, arc);
  762. const char *name = mdesc_node_name(md, target);
  763. const u64 *val;
  764. if (strcmp(name, "pio-latency-group"))
  765. continue;
  766. val = mdesc_get_property(md, target, "latency", NULL);
  767. if (!val)
  768. continue;
  769. if (*val < best_latency) {
  770. candidate = target;
  771. best_latency = *val;
  772. }
  773. }
  774. if (candidate == MDESC_NODE_NULL)
  775. return -ENODEV;
  776. return scan_pio_for_cfg_handle(md, candidate, cfg_handle);
  777. }
  778. int of_node_to_nid(struct device_node *dp)
  779. {
  780. const struct linux_prom64_registers *regs;
  781. struct mdesc_handle *md;
  782. u32 cfg_handle;
  783. int count, nid;
  784. u64 grp;
  785. /* This is the right thing to do on currently supported
  786. * SUN4U NUMA platforms as well, as the PCI controller does
  787. * not sit behind any particular memory controller.
  788. */
  789. if (!mlgroups)
  790. return -1;
  791. regs = of_get_property(dp, "reg", NULL);
  792. if (!regs)
  793. return -1;
  794. cfg_handle = (regs->phys_addr >> 32UL) & 0x0fffffff;
  795. md = mdesc_grab();
  796. count = 0;
  797. nid = -1;
  798. mdesc_for_each_node_by_name(md, grp, "group") {
  799. if (!scan_arcs_for_cfg_handle(md, grp, cfg_handle)) {
  800. nid = count;
  801. break;
  802. }
  803. count++;
  804. }
  805. mdesc_release(md);
  806. return nid;
  807. }
  808. static void __init add_node_ranges(void)
  809. {
  810. struct memblock_region *reg;
  811. for_each_memblock(memory, reg) {
  812. unsigned long size = reg->size;
  813. unsigned long start, end;
  814. start = reg->base;
  815. end = start + size;
  816. while (start < end) {
  817. unsigned long this_end;
  818. int nid;
  819. this_end = memblock_nid_range(start, end, &nid);
  820. numadbg("Setting memblock NUMA node nid[%d] "
  821. "start[%lx] end[%lx]\n",
  822. nid, start, this_end);
  823. memblock_set_node(start, this_end - start, nid);
  824. start = this_end;
  825. }
  826. }
  827. }
  828. static int __init grab_mlgroups(struct mdesc_handle *md)
  829. {
  830. unsigned long paddr;
  831. int count = 0;
  832. u64 node;
  833. mdesc_for_each_node_by_name(md, node, "memory-latency-group")
  834. count++;
  835. if (!count)
  836. return -ENOENT;
  837. paddr = memblock_alloc(count * sizeof(struct mdesc_mlgroup),
  838. SMP_CACHE_BYTES);
  839. if (!paddr)
  840. return -ENOMEM;
  841. mlgroups = __va(paddr);
  842. num_mlgroups = count;
  843. count = 0;
  844. mdesc_for_each_node_by_name(md, node, "memory-latency-group") {
  845. struct mdesc_mlgroup *m = &mlgroups[count++];
  846. const u64 *val;
  847. m->node = node;
  848. val = mdesc_get_property(md, node, "latency", NULL);
  849. m->latency = *val;
  850. val = mdesc_get_property(md, node, "address-match", NULL);
  851. m->match = *val;
  852. val = mdesc_get_property(md, node, "address-mask", NULL);
  853. m->mask = *val;
  854. numadbg("MLGROUP[%d]: node[%llx] latency[%llx] "
  855. "match[%llx] mask[%llx]\n",
  856. count - 1, m->node, m->latency, m->match, m->mask);
  857. }
  858. return 0;
  859. }
  860. static int __init grab_mblocks(struct mdesc_handle *md)
  861. {
  862. unsigned long paddr;
  863. int count = 0;
  864. u64 node;
  865. mdesc_for_each_node_by_name(md, node, "mblock")
  866. count++;
  867. if (!count)
  868. return -ENOENT;
  869. paddr = memblock_alloc(count * sizeof(struct mdesc_mblock),
  870. SMP_CACHE_BYTES);
  871. if (!paddr)
  872. return -ENOMEM;
  873. mblocks = __va(paddr);
  874. num_mblocks = count;
  875. count = 0;
  876. mdesc_for_each_node_by_name(md, node, "mblock") {
  877. struct mdesc_mblock *m = &mblocks[count++];
  878. const u64 *val;
  879. val = mdesc_get_property(md, node, "base", NULL);
  880. m->base = *val;
  881. val = mdesc_get_property(md, node, "size", NULL);
  882. m->size = *val;
  883. val = mdesc_get_property(md, node,
  884. "address-congruence-offset", NULL);
  885. m->offset = *val;
  886. numadbg("MBLOCK[%d]: base[%llx] size[%llx] offset[%llx]\n",
  887. count - 1, m->base, m->size, m->offset);
  888. }
  889. return 0;
  890. }
  891. static void __init numa_parse_mdesc_group_cpus(struct mdesc_handle *md,
  892. u64 grp, cpumask_t *mask)
  893. {
  894. u64 arc;
  895. cpumask_clear(mask);
  896. mdesc_for_each_arc(arc, md, grp, MDESC_ARC_TYPE_BACK) {
  897. u64 target = mdesc_arc_target(md, arc);
  898. const char *name = mdesc_node_name(md, target);
  899. const u64 *id;
  900. if (strcmp(name, "cpu"))
  901. continue;
  902. id = mdesc_get_property(md, target, "id", NULL);
  903. if (*id < nr_cpu_ids)
  904. cpumask_set_cpu(*id, mask);
  905. }
  906. }
  907. static struct mdesc_mlgroup * __init find_mlgroup(u64 node)
  908. {
  909. int i;
  910. for (i = 0; i < num_mlgroups; i++) {
  911. struct mdesc_mlgroup *m = &mlgroups[i];
  912. if (m->node == node)
  913. return m;
  914. }
  915. return NULL;
  916. }
  917. static int __init numa_attach_mlgroup(struct mdesc_handle *md, u64 grp,
  918. int index)
  919. {
  920. struct mdesc_mlgroup *candidate = NULL;
  921. u64 arc, best_latency = ~(u64)0;
  922. struct node_mem_mask *n;
  923. mdesc_for_each_arc(arc, md, grp, MDESC_ARC_TYPE_FWD) {
  924. u64 target = mdesc_arc_target(md, arc);
  925. struct mdesc_mlgroup *m = find_mlgroup(target);
  926. if (!m)
  927. continue;
  928. if (m->latency < best_latency) {
  929. candidate = m;
  930. best_latency = m->latency;
  931. }
  932. }
  933. if (!candidate)
  934. return -ENOENT;
  935. if (num_node_masks != index) {
  936. printk(KERN_ERR "Inconsistent NUMA state, "
  937. "index[%d] != num_node_masks[%d]\n",
  938. index, num_node_masks);
  939. return -EINVAL;
  940. }
  941. n = &node_masks[num_node_masks++];
  942. n->mask = candidate->mask;
  943. n->val = candidate->match;
  944. numadbg("NUMA NODE[%d]: mask[%lx] val[%lx] (latency[%llx])\n",
  945. index, n->mask, n->val, candidate->latency);
  946. return 0;
  947. }
  948. static int __init numa_parse_mdesc_group(struct mdesc_handle *md, u64 grp,
  949. int index)
  950. {
  951. cpumask_t mask;
  952. int cpu;
  953. numa_parse_mdesc_group_cpus(md, grp, &mask);
  954. for_each_cpu(cpu, &mask)
  955. numa_cpu_lookup_table[cpu] = index;
  956. cpumask_copy(&numa_cpumask_lookup_table[index], &mask);
  957. if (numa_debug) {
  958. printk(KERN_INFO "NUMA GROUP[%d]: cpus [ ", index);
  959. for_each_cpu(cpu, &mask)
  960. printk("%d ", cpu);
  961. printk("]\n");
  962. }
  963. return numa_attach_mlgroup(md, grp, index);
  964. }
  965. static int __init numa_parse_mdesc(void)
  966. {
  967. struct mdesc_handle *md = mdesc_grab();
  968. int i, err, count;
  969. u64 node;
  970. node = mdesc_node_by_name(md, MDESC_NODE_NULL, "latency-groups");
  971. if (node == MDESC_NODE_NULL) {
  972. mdesc_release(md);
  973. return -ENOENT;
  974. }
  975. err = grab_mblocks(md);
  976. if (err < 0)
  977. goto out;
  978. err = grab_mlgroups(md);
  979. if (err < 0)
  980. goto out;
  981. count = 0;
  982. mdesc_for_each_node_by_name(md, node, "group") {
  983. err = numa_parse_mdesc_group(md, node, count);
  984. if (err < 0)
  985. break;
  986. count++;
  987. }
  988. add_node_ranges();
  989. for (i = 0; i < num_node_masks; i++) {
  990. allocate_node_data(i);
  991. node_set_online(i);
  992. }
  993. err = 0;
  994. out:
  995. mdesc_release(md);
  996. return err;
  997. }
  998. static int __init numa_parse_jbus(void)
  999. {
  1000. unsigned long cpu, index;
  1001. /* NUMA node id is encoded in bits 36 and higher, and there is
  1002. * a 1-to-1 mapping from CPU ID to NUMA node ID.
  1003. */
  1004. index = 0;
  1005. for_each_present_cpu(cpu) {
  1006. numa_cpu_lookup_table[cpu] = index;
  1007. cpumask_copy(&numa_cpumask_lookup_table[index], cpumask_of(cpu));
  1008. node_masks[index].mask = ~((1UL << 36UL) - 1UL);
  1009. node_masks[index].val = cpu << 36UL;
  1010. index++;
  1011. }
  1012. num_node_masks = index;
  1013. add_node_ranges();
  1014. for (index = 0; index < num_node_masks; index++) {
  1015. allocate_node_data(index);
  1016. node_set_online(index);
  1017. }
  1018. return 0;
  1019. }
  1020. static int __init numa_parse_sun4u(void)
  1021. {
  1022. if (tlb_type == cheetah || tlb_type == cheetah_plus) {
  1023. unsigned long ver;
  1024. __asm__ ("rdpr %%ver, %0" : "=r" (ver));
  1025. if ((ver >> 32UL) == __JALAPENO_ID ||
  1026. (ver >> 32UL) == __SERRANO_ID)
  1027. return numa_parse_jbus();
  1028. }
  1029. return -1;
  1030. }
  1031. static int __init bootmem_init_numa(void)
  1032. {
  1033. int err = -1;
  1034. numadbg("bootmem_init_numa()\n");
  1035. if (numa_enabled) {
  1036. if (tlb_type == hypervisor)
  1037. err = numa_parse_mdesc();
  1038. else
  1039. err = numa_parse_sun4u();
  1040. }
  1041. return err;
  1042. }
  1043. #else
  1044. static int bootmem_init_numa(void)
  1045. {
  1046. return -1;
  1047. }
  1048. #endif
  1049. static void __init bootmem_init_nonnuma(void)
  1050. {
  1051. unsigned long top_of_ram = memblock_end_of_DRAM();
  1052. unsigned long total_ram = memblock_phys_mem_size();
  1053. numadbg("bootmem_init_nonnuma()\n");
  1054. printk(KERN_INFO "Top of RAM: 0x%lx, Total RAM: 0x%lx\n",
  1055. top_of_ram, total_ram);
  1056. printk(KERN_INFO "Memory hole size: %ldMB\n",
  1057. (top_of_ram - total_ram) >> 20);
  1058. init_node_masks_nonnuma();
  1059. memblock_set_node(0, (phys_addr_t)ULLONG_MAX, 0);
  1060. allocate_node_data(0);
  1061. node_set_online(0);
  1062. }
  1063. static void __init reserve_range_in_node(int nid, unsigned long start,
  1064. unsigned long end)
  1065. {
  1066. numadbg(" reserve_range_in_node(nid[%d],start[%lx],end[%lx]\n",
  1067. nid, start, end);
  1068. while (start < end) {
  1069. unsigned long this_end;
  1070. int n;
  1071. this_end = memblock_nid_range(start, end, &n);
  1072. if (n == nid) {
  1073. numadbg(" MATCH reserving range [%lx:%lx]\n",
  1074. start, this_end);
  1075. reserve_bootmem_node(NODE_DATA(nid), start,
  1076. (this_end - start), BOOTMEM_DEFAULT);
  1077. } else
  1078. numadbg(" NO MATCH, advancing start to %lx\n",
  1079. this_end);
  1080. start = this_end;
  1081. }
  1082. }
  1083. static void __init trim_reserved_in_node(int nid)
  1084. {
  1085. struct memblock_region *reg;
  1086. numadbg(" trim_reserved_in_node(%d)\n", nid);
  1087. for_each_memblock(reserved, reg)
  1088. reserve_range_in_node(nid, reg->base, reg->base + reg->size);
  1089. }
  1090. static void __init bootmem_init_one_node(int nid)
  1091. {
  1092. struct pglist_data *p;
  1093. numadbg("bootmem_init_one_node(%d)\n", nid);
  1094. p = NODE_DATA(nid);
  1095. if (p->node_spanned_pages) {
  1096. unsigned long paddr = node_masks[nid].bootmem_paddr;
  1097. unsigned long end_pfn;
  1098. end_pfn = p->node_start_pfn + p->node_spanned_pages;
  1099. numadbg(" init_bootmem_node(%d, %lx, %lx, %lx)\n",
  1100. nid, paddr >> PAGE_SHIFT, p->node_start_pfn, end_pfn);
  1101. init_bootmem_node(p, paddr >> PAGE_SHIFT,
  1102. p->node_start_pfn, end_pfn);
  1103. numadbg(" free_bootmem_with_active_regions(%d, %lx)\n",
  1104. nid, end_pfn);
  1105. free_bootmem_with_active_regions(nid, end_pfn);
  1106. trim_reserved_in_node(nid);
  1107. numadbg(" sparse_memory_present_with_active_regions(%d)\n",
  1108. nid);
  1109. sparse_memory_present_with_active_regions(nid);
  1110. }
  1111. }
  1112. static unsigned long __init bootmem_init(unsigned long phys_base)
  1113. {
  1114. unsigned long end_pfn;
  1115. int nid;
  1116. end_pfn = memblock_end_of_DRAM() >> PAGE_SHIFT;
  1117. max_pfn = max_low_pfn = end_pfn;
  1118. min_low_pfn = (phys_base >> PAGE_SHIFT);
  1119. if (bootmem_init_numa() < 0)
  1120. bootmem_init_nonnuma();
  1121. /* XXX cpu notifier XXX */
  1122. for_each_online_node(nid)
  1123. bootmem_init_one_node(nid);
  1124. sparse_init();
  1125. return end_pfn;
  1126. }
  1127. static struct linux_prom64_registers pall[MAX_BANKS] __initdata;
  1128. static int pall_ents __initdata;
  1129. #ifdef CONFIG_DEBUG_PAGEALLOC
  1130. static unsigned long __ref kernel_map_range(unsigned long pstart,
  1131. unsigned long pend, pgprot_t prot)
  1132. {
  1133. unsigned long vstart = PAGE_OFFSET + pstart;
  1134. unsigned long vend = PAGE_OFFSET + pend;
  1135. unsigned long alloc_bytes = 0UL;
  1136. if ((vstart & ~PAGE_MASK) || (vend & ~PAGE_MASK)) {
  1137. prom_printf("kernel_map: Unaligned physmem[%lx:%lx]\n",
  1138. vstart, vend);
  1139. prom_halt();
  1140. }
  1141. while (vstart < vend) {
  1142. unsigned long this_end, paddr = __pa(vstart);
  1143. pgd_t *pgd = pgd_offset_k(vstart);
  1144. pud_t *pud;
  1145. pmd_t *pmd;
  1146. pte_t *pte;
  1147. pud = pud_offset(pgd, vstart);
  1148. if (pud_none(*pud)) {
  1149. pmd_t *new;
  1150. new = __alloc_bootmem(PAGE_SIZE, PAGE_SIZE, PAGE_SIZE);
  1151. alloc_bytes += PAGE_SIZE;
  1152. pud_populate(&init_mm, pud, new);
  1153. }
  1154. pmd = pmd_offset(pud, vstart);
  1155. if (!pmd_present(*pmd)) {
  1156. pte_t *new;
  1157. new = __alloc_bootmem(PAGE_SIZE, PAGE_SIZE, PAGE_SIZE);
  1158. alloc_bytes += PAGE_SIZE;
  1159. pmd_populate_kernel(&init_mm, pmd, new);
  1160. }
  1161. pte = pte_offset_kernel(pmd, vstart);
  1162. this_end = (vstart + PMD_SIZE) & PMD_MASK;
  1163. if (this_end > vend)
  1164. this_end = vend;
  1165. while (vstart < this_end) {
  1166. pte_val(*pte) = (paddr | pgprot_val(prot));
  1167. vstart += PAGE_SIZE;
  1168. paddr += PAGE_SIZE;
  1169. pte++;
  1170. }
  1171. }
  1172. return alloc_bytes;
  1173. }
  1174. extern unsigned int kvmap_linear_patch[1];
  1175. #endif /* CONFIG_DEBUG_PAGEALLOC */
  1176. static void __init mark_kpte_bitmap(unsigned long start, unsigned long end)
  1177. {
  1178. const unsigned long shift_256MB = 28;
  1179. const unsigned long mask_256MB = ((1UL << shift_256MB) - 1UL);
  1180. const unsigned long size_256MB = (1UL << shift_256MB);
  1181. while (start < end) {
  1182. long remains;
  1183. remains = end - start;
  1184. if (remains < size_256MB)
  1185. break;
  1186. if (start & mask_256MB) {
  1187. start = (start + size_256MB) & ~mask_256MB;
  1188. continue;
  1189. }
  1190. while (remains >= size_256MB) {
  1191. unsigned long index = start >> shift_256MB;
  1192. __set_bit(index, kpte_linear_bitmap);
  1193. start += size_256MB;
  1194. remains -= size_256MB;
  1195. }
  1196. }
  1197. }
  1198. static void __init init_kpte_bitmap(void)
  1199. {
  1200. unsigned long i;
  1201. for (i = 0; i < pall_ents; i++) {
  1202. unsigned long phys_start, phys_end;
  1203. phys_start = pall[i].phys_addr;
  1204. phys_end = phys_start + pall[i].reg_size;
  1205. mark_kpte_bitmap(phys_start, phys_end);
  1206. }
  1207. }
  1208. static void __init kernel_physical_mapping_init(void)
  1209. {
  1210. #ifdef CONFIG_DEBUG_PAGEALLOC
  1211. unsigned long i, mem_alloced = 0UL;
  1212. for (i = 0; i < pall_ents; i++) {
  1213. unsigned long phys_start, phys_end;
  1214. phys_start = pall[i].phys_addr;
  1215. phys_end = phys_start + pall[i].reg_size;
  1216. mem_alloced += kernel_map_range(phys_start, phys_end,
  1217. PAGE_KERNEL);
  1218. }
  1219. printk("Allocated %ld bytes for kernel page tables.\n",
  1220. mem_alloced);
  1221. kvmap_linear_patch[0] = 0x01000000; /* nop */
  1222. flushi(&kvmap_linear_patch[0]);
  1223. __flush_tlb_all();
  1224. #endif
  1225. }
  1226. #ifdef CONFIG_DEBUG_PAGEALLOC
  1227. void kernel_map_pages(struct page *page, int numpages, int enable)
  1228. {
  1229. unsigned long phys_start = page_to_pfn(page) << PAGE_SHIFT;
  1230. unsigned long phys_end = phys_start + (numpages * PAGE_SIZE);
  1231. kernel_map_range(phys_start, phys_end,
  1232. (enable ? PAGE_KERNEL : __pgprot(0)));
  1233. flush_tsb_kernel_range(PAGE_OFFSET + phys_start,
  1234. PAGE_OFFSET + phys_end);
  1235. /* we should perform an IPI and flush all tlbs,
  1236. * but that can deadlock->flush only current cpu.
  1237. */
  1238. __flush_tlb_kernel_range(PAGE_OFFSET + phys_start,
  1239. PAGE_OFFSET + phys_end);
  1240. }
  1241. #endif
  1242. unsigned long __init find_ecache_flush_span(unsigned long size)
  1243. {
  1244. int i;
  1245. for (i = 0; i < pavail_ents; i++) {
  1246. if (pavail[i].reg_size >= size)
  1247. return pavail[i].phys_addr;
  1248. }
  1249. return ~0UL;
  1250. }
  1251. static void __init tsb_phys_patch(void)
  1252. {
  1253. struct tsb_ldquad_phys_patch_entry *pquad;
  1254. struct tsb_phys_patch_entry *p;
  1255. pquad = &__tsb_ldquad_phys_patch;
  1256. while (pquad < &__tsb_ldquad_phys_patch_end) {
  1257. unsigned long addr = pquad->addr;
  1258. if (tlb_type == hypervisor)
  1259. *(unsigned int *) addr = pquad->sun4v_insn;
  1260. else
  1261. *(unsigned int *) addr = pquad->sun4u_insn;
  1262. wmb();
  1263. __asm__ __volatile__("flush %0"
  1264. : /* no outputs */
  1265. : "r" (addr));
  1266. pquad++;
  1267. }
  1268. p = &__tsb_phys_patch;
  1269. while (p < &__tsb_phys_patch_end) {
  1270. unsigned long addr = p->addr;
  1271. *(unsigned int *) addr = p->insn;
  1272. wmb();
  1273. __asm__ __volatile__("flush %0"
  1274. : /* no outputs */
  1275. : "r" (addr));
  1276. p++;
  1277. }
  1278. }
  1279. /* Don't mark as init, we give this to the Hypervisor. */
  1280. #ifndef CONFIG_DEBUG_PAGEALLOC
  1281. #define NUM_KTSB_DESCR 2
  1282. #else
  1283. #define NUM_KTSB_DESCR 1
  1284. #endif
  1285. static struct hv_tsb_descr ktsb_descr[NUM_KTSB_DESCR];
  1286. extern struct tsb swapper_tsb[KERNEL_TSB_NENTRIES];
  1287. static void patch_one_ktsb_phys(unsigned int *start, unsigned int *end, unsigned long pa)
  1288. {
  1289. pa >>= KTSB_PHYS_SHIFT;
  1290. while (start < end) {
  1291. unsigned int *ia = (unsigned int *)(unsigned long)*start;
  1292. ia[0] = (ia[0] & ~0x3fffff) | (pa >> 10);
  1293. __asm__ __volatile__("flush %0" : : "r" (ia));
  1294. ia[1] = (ia[1] & ~0x3ff) | (pa & 0x3ff);
  1295. __asm__ __volatile__("flush %0" : : "r" (ia + 1));
  1296. start++;
  1297. }
  1298. }
  1299. static void ktsb_phys_patch(void)
  1300. {
  1301. extern unsigned int __swapper_tsb_phys_patch;
  1302. extern unsigned int __swapper_tsb_phys_patch_end;
  1303. unsigned long ktsb_pa;
  1304. ktsb_pa = kern_base + ((unsigned long)&swapper_tsb[0] - KERNBASE);
  1305. patch_one_ktsb_phys(&__swapper_tsb_phys_patch,
  1306. &__swapper_tsb_phys_patch_end, ktsb_pa);
  1307. #ifndef CONFIG_DEBUG_PAGEALLOC
  1308. {
  1309. extern unsigned int __swapper_4m_tsb_phys_patch;
  1310. extern unsigned int __swapper_4m_tsb_phys_patch_end;
  1311. ktsb_pa = (kern_base +
  1312. ((unsigned long)&swapper_4m_tsb[0] - KERNBASE));
  1313. patch_one_ktsb_phys(&__swapper_4m_tsb_phys_patch,
  1314. &__swapper_4m_tsb_phys_patch_end, ktsb_pa);
  1315. }
  1316. #endif
  1317. }
  1318. static void __init sun4v_ktsb_init(void)
  1319. {
  1320. unsigned long ktsb_pa;
  1321. /* First KTSB for PAGE_SIZE mappings. */
  1322. ktsb_pa = kern_base + ((unsigned long)&swapper_tsb[0] - KERNBASE);
  1323. switch (PAGE_SIZE) {
  1324. case 8 * 1024:
  1325. default:
  1326. ktsb_descr[0].pgsz_idx = HV_PGSZ_IDX_8K;
  1327. ktsb_descr[0].pgsz_mask = HV_PGSZ_MASK_8K;
  1328. break;
  1329. case 64 * 1024:
  1330. ktsb_descr[0].pgsz_idx = HV_PGSZ_IDX_64K;
  1331. ktsb_descr[0].pgsz_mask = HV_PGSZ_MASK_64K;
  1332. break;
  1333. case 512 * 1024:
  1334. ktsb_descr[0].pgsz_idx = HV_PGSZ_IDX_512K;
  1335. ktsb_descr[0].pgsz_mask = HV_PGSZ_MASK_512K;
  1336. break;
  1337. case 4 * 1024 * 1024:
  1338. ktsb_descr[0].pgsz_idx = HV_PGSZ_IDX_4MB;
  1339. ktsb_descr[0].pgsz_mask = HV_PGSZ_MASK_4MB;
  1340. break;
  1341. }
  1342. ktsb_descr[0].assoc = 1;
  1343. ktsb_descr[0].num_ttes = KERNEL_TSB_NENTRIES;
  1344. ktsb_descr[0].ctx_idx = 0;
  1345. ktsb_descr[0].tsb_base = ktsb_pa;
  1346. ktsb_descr[0].resv = 0;
  1347. #ifndef CONFIG_DEBUG_PAGEALLOC
  1348. /* Second KTSB for 4MB/256MB mappings. */
  1349. ktsb_pa = (kern_base +
  1350. ((unsigned long)&swapper_4m_tsb[0] - KERNBASE));
  1351. ktsb_descr[1].pgsz_idx = HV_PGSZ_IDX_4MB;
  1352. ktsb_descr[1].pgsz_mask = (HV_PGSZ_MASK_4MB |
  1353. HV_PGSZ_MASK_256MB);
  1354. ktsb_descr[1].assoc = 1;
  1355. ktsb_descr[1].num_ttes = KERNEL_TSB4M_NENTRIES;
  1356. ktsb_descr[1].ctx_idx = 0;
  1357. ktsb_descr[1].tsb_base = ktsb_pa;
  1358. ktsb_descr[1].resv = 0;
  1359. #endif
  1360. }
  1361. void __cpuinit sun4v_ktsb_register(void)
  1362. {
  1363. unsigned long pa, ret;
  1364. pa = kern_base + ((unsigned long)&ktsb_descr[0] - KERNBASE);
  1365. ret = sun4v_mmu_tsb_ctx0(NUM_KTSB_DESCR, pa);
  1366. if (ret != 0) {
  1367. prom_printf("hypervisor_mmu_tsb_ctx0[%lx]: "
  1368. "errors with %lx\n", pa, ret);
  1369. prom_halt();
  1370. }
  1371. }
  1372. /* paging_init() sets up the page tables */
  1373. static unsigned long last_valid_pfn;
  1374. pgd_t swapper_pg_dir[2048];
  1375. static void sun4u_pgprot_init(void);
  1376. static void sun4v_pgprot_init(void);
  1377. void __init paging_init(void)
  1378. {
  1379. unsigned long end_pfn, shift, phys_base;
  1380. unsigned long real_end, i;
  1381. /* These build time checkes make sure that the dcache_dirty_cpu()
  1382. * page->flags usage will work.
  1383. *
  1384. * When a page gets marked as dcache-dirty, we store the
  1385. * cpu number starting at bit 32 in the page->flags. Also,
  1386. * functions like clear_dcache_dirty_cpu use the cpu mask
  1387. * in 13-bit signed-immediate instruction fields.
  1388. */
  1389. /*
  1390. * Page flags must not reach into upper 32 bits that are used
  1391. * for the cpu number
  1392. */
  1393. BUILD_BUG_ON(NR_PAGEFLAGS > 32);
  1394. /*
  1395. * The bit fields placed in the high range must not reach below
  1396. * the 32 bit boundary. Otherwise we cannot place the cpu field
  1397. * at the 32 bit boundary.
  1398. */
  1399. BUILD_BUG_ON(SECTIONS_WIDTH + NODES_WIDTH + ZONES_WIDTH +
  1400. ilog2(roundup_pow_of_two(NR_CPUS)) > 32);
  1401. BUILD_BUG_ON(NR_CPUS > 4096);
  1402. kern_base = (prom_boot_mapping_phys_low >> 22UL) << 22UL;
  1403. kern_size = (unsigned long)&_end - (unsigned long)KERNBASE;
  1404. /* Invalidate both kernel TSBs. */
  1405. memset(swapper_tsb, 0x40, sizeof(swapper_tsb));
  1406. #ifndef CONFIG_DEBUG_PAGEALLOC
  1407. memset(swapper_4m_tsb, 0x40, sizeof(swapper_4m_tsb));
  1408. #endif
  1409. if (tlb_type == hypervisor)
  1410. sun4v_pgprot_init();
  1411. else
  1412. sun4u_pgprot_init();
  1413. if (tlb_type == cheetah_plus ||
  1414. tlb_type == hypervisor) {
  1415. tsb_phys_patch();
  1416. ktsb_phys_patch();
  1417. }
  1418. if (tlb_type == hypervisor) {
  1419. sun4v_patch_tlb_handlers();
  1420. sun4v_ktsb_init();
  1421. }
  1422. /* Find available physical memory...
  1423. *
  1424. * Read it twice in order to work around a bug in openfirmware.
  1425. * The call to grab this table itself can cause openfirmware to
  1426. * allocate memory, which in turn can take away some space from
  1427. * the list of available memory. Reading it twice makes sure
  1428. * we really do get the final value.
  1429. */
  1430. read_obp_translations();
  1431. read_obp_memory("reg", &pall[0], &pall_ents);
  1432. read_obp_memory("available", &pavail[0], &pavail_ents);
  1433. read_obp_memory("available", &pavail[0], &pavail_ents);
  1434. phys_base = 0xffffffffffffffffUL;
  1435. for (i = 0; i < pavail_ents; i++) {
  1436. phys_base = min(phys_base, pavail[i].phys_addr);
  1437. memblock_add(pavail[i].phys_addr, pavail[i].reg_size);
  1438. }
  1439. memblock_reserve(kern_base, kern_size);
  1440. find_ramdisk(phys_base);
  1441. memblock_enforce_memory_limit(cmdline_memory_size);
  1442. memblock_allow_resize();
  1443. memblock_dump_all();
  1444. set_bit(0, mmu_context_bmap);
  1445. shift = kern_base + PAGE_OFFSET - ((unsigned long)KERNBASE);
  1446. real_end = (unsigned long)_end;
  1447. num_kernel_image_mappings = DIV_ROUND_UP(real_end - KERNBASE, 1 << 22);
  1448. printk("Kernel: Using %d locked TLB entries for main kernel image.\n",
  1449. num_kernel_image_mappings);
  1450. /* Set kernel pgd to upper alias so physical page computations
  1451. * work.
  1452. */
  1453. init_mm.pgd += ((shift) / (sizeof(pgd_t)));
  1454. memset(swapper_low_pmd_dir, 0, sizeof(swapper_low_pmd_dir));
  1455. /* Now can init the kernel/bad page tables. */
  1456. pud_set(pud_offset(&swapper_pg_dir[0], 0),
  1457. swapper_low_pmd_dir + (shift / sizeof(pgd_t)));
  1458. inherit_prom_mappings();
  1459. init_kpte_bitmap();
  1460. /* Ok, we can use our TLB miss and window trap handlers safely. */
  1461. setup_tba();
  1462. __flush_tlb_all();
  1463. if (tlb_type == hypervisor)
  1464. sun4v_ktsb_register();
  1465. prom_build_devicetree();
  1466. of_populate_present_mask();
  1467. #ifndef CONFIG_SMP
  1468. of_fill_in_cpu_data();
  1469. #endif
  1470. if (tlb_type == hypervisor) {
  1471. sun4v_mdesc_init();
  1472. mdesc_populate_present_mask(cpu_all_mask);
  1473. #ifndef CONFIG_SMP
  1474. mdesc_fill_in_cpu_data(cpu_all_mask);
  1475. #endif
  1476. }
  1477. /* Once the OF device tree and MDESC have been setup, we know
  1478. * the list of possible cpus. Therefore we can allocate the
  1479. * IRQ stacks.
  1480. */
  1481. for_each_possible_cpu(i) {
  1482. /* XXX Use node local allocations... XXX */
  1483. softirq_stack[i] = __va(memblock_alloc(THREAD_SIZE, THREAD_SIZE));
  1484. hardirq_stack[i] = __va(memblock_alloc(THREAD_SIZE, THREAD_SIZE));
  1485. }
  1486. /* Setup bootmem... */
  1487. last_valid_pfn = end_pfn = bootmem_init(phys_base);
  1488. #ifndef CONFIG_NEED_MULTIPLE_NODES
  1489. max_mapnr = last_valid_pfn;
  1490. #endif
  1491. kernel_physical_mapping_init();
  1492. {
  1493. unsigned long max_zone_pfns[MAX_NR_ZONES];
  1494. memset(max_zone_pfns, 0, sizeof(max_zone_pfns));
  1495. max_zone_pfns[ZONE_NORMAL] = end_pfn;
  1496. free_area_init_nodes(max_zone_pfns);
  1497. }
  1498. printk("Booting Linux...\n");
  1499. }
  1500. int __devinit page_in_phys_avail(unsigned long paddr)
  1501. {
  1502. int i;
  1503. paddr &= PAGE_MASK;
  1504. for (i = 0; i < pavail_ents; i++) {
  1505. unsigned long start, end;
  1506. start = pavail[i].phys_addr;
  1507. end = start + pavail[i].reg_size;
  1508. if (paddr >= start && paddr < end)
  1509. return 1;
  1510. }
  1511. if (paddr >= kern_base && paddr < (kern_base + kern_size))
  1512. return 1;
  1513. #ifdef CONFIG_BLK_DEV_INITRD
  1514. if (paddr >= __pa(initrd_start) &&
  1515. paddr < __pa(PAGE_ALIGN(initrd_end)))
  1516. return 1;
  1517. #endif
  1518. return 0;
  1519. }
  1520. static struct linux_prom64_registers pavail_rescan[MAX_BANKS] __initdata;
  1521. static int pavail_rescan_ents __initdata;
  1522. /* Certain OBP calls, such as fetching "available" properties, can
  1523. * claim physical memory. So, along with initializing the valid
  1524. * address bitmap, what we do here is refetch the physical available
  1525. * memory list again, and make sure it provides at least as much
  1526. * memory as 'pavail' does.
  1527. */
  1528. static void __init setup_valid_addr_bitmap_from_pavail(unsigned long *bitmap)
  1529. {
  1530. int i;
  1531. read_obp_memory("available", &pavail_rescan[0], &pavail_rescan_ents);
  1532. for (i = 0; i < pavail_ents; i++) {
  1533. unsigned long old_start, old_end;
  1534. old_start = pavail[i].phys_addr;
  1535. old_end = old_start + pavail[i].reg_size;
  1536. while (old_start < old_end) {
  1537. int n;
  1538. for (n = 0; n < pavail_rescan_ents; n++) {
  1539. unsigned long new_start, new_end;
  1540. new_start = pavail_rescan[n].phys_addr;
  1541. new_end = new_start +
  1542. pavail_rescan[n].reg_size;
  1543. if (new_start <= old_start &&
  1544. new_end >= (old_start + PAGE_SIZE)) {
  1545. set_bit(old_start >> 22, bitmap);
  1546. goto do_next_page;
  1547. }
  1548. }
  1549. prom_printf("mem_init: Lost memory in pavail\n");
  1550. prom_printf("mem_init: OLD start[%lx] size[%lx]\n",
  1551. pavail[i].phys_addr,
  1552. pavail[i].reg_size);
  1553. prom_printf("mem_init: NEW start[%lx] size[%lx]\n",
  1554. pavail_rescan[i].phys_addr,
  1555. pavail_rescan[i].reg_size);
  1556. prom_printf("mem_init: Cannot continue, aborting.\n");
  1557. prom_halt();
  1558. do_next_page:
  1559. old_start += PAGE_SIZE;
  1560. }
  1561. }
  1562. }
  1563. static void __init patch_tlb_miss_handler_bitmap(void)
  1564. {
  1565. extern unsigned int valid_addr_bitmap_insn[];
  1566. extern unsigned int valid_addr_bitmap_patch[];
  1567. valid_addr_bitmap_insn[1] = valid_addr_bitmap_patch[1];
  1568. mb();
  1569. valid_addr_bitmap_insn[0] = valid_addr_bitmap_patch[0];
  1570. flushi(&valid_addr_bitmap_insn[0]);
  1571. }
  1572. void __init mem_init(void)
  1573. {
  1574. unsigned long codepages, datapages, initpages;
  1575. unsigned long addr, last;
  1576. addr = PAGE_OFFSET + kern_base;
  1577. last = PAGE_ALIGN(kern_size) + addr;
  1578. while (addr < last) {
  1579. set_bit(__pa(addr) >> 22, sparc64_valid_addr_bitmap);
  1580. addr += PAGE_SIZE;
  1581. }
  1582. setup_valid_addr_bitmap_from_pavail(sparc64_valid_addr_bitmap);
  1583. patch_tlb_miss_handler_bitmap();
  1584. high_memory = __va(last_valid_pfn << PAGE_SHIFT);
  1585. #ifdef CONFIG_NEED_MULTIPLE_NODES
  1586. {
  1587. int i;
  1588. for_each_online_node(i) {
  1589. if (NODE_DATA(i)->node_spanned_pages != 0) {
  1590. totalram_pages +=
  1591. free_all_bootmem_node(NODE_DATA(i));
  1592. }
  1593. }
  1594. }
  1595. #else
  1596. totalram_pages = free_all_bootmem();
  1597. #endif
  1598. /* We subtract one to account for the mem_map_zero page
  1599. * allocated below.
  1600. */
  1601. totalram_pages -= 1;
  1602. num_physpages = totalram_pages;
  1603. /*
  1604. * Set up the zero page, mark it reserved, so that page count
  1605. * is not manipulated when freeing the page from user ptes.
  1606. */
  1607. mem_map_zero = alloc_pages(GFP_KERNEL|__GFP_ZERO, 0);
  1608. if (mem_map_zero == NULL) {
  1609. prom_printf("paging_init: Cannot alloc zero page.\n");
  1610. prom_halt();
  1611. }
  1612. SetPageReserved(mem_map_zero);
  1613. codepages = (((unsigned long) _etext) - ((unsigned long) _start));
  1614. codepages = PAGE_ALIGN(codepages) >> PAGE_SHIFT;
  1615. datapages = (((unsigned long) _edata) - ((unsigned long) _etext));
  1616. datapages = PAGE_ALIGN(datapages) >> PAGE_SHIFT;
  1617. initpages = (((unsigned long) __init_end) - ((unsigned long) __init_begin));
  1618. initpages = PAGE_ALIGN(initpages) >> PAGE_SHIFT;
  1619. printk("Memory: %luk available (%ldk kernel code, %ldk data, %ldk init) [%016lx,%016lx]\n",
  1620. nr_free_pages() << (PAGE_SHIFT-10),
  1621. codepages << (PAGE_SHIFT-10),
  1622. datapages << (PAGE_SHIFT-10),
  1623. initpages << (PAGE_SHIFT-10),
  1624. PAGE_OFFSET, (last_valid_pfn << PAGE_SHIFT));
  1625. if (tlb_type == cheetah || tlb_type == cheetah_plus)
  1626. cheetah_ecache_flush_init();
  1627. }
  1628. void free_initmem(void)
  1629. {
  1630. unsigned long addr, initend;
  1631. int do_free = 1;
  1632. /* If the physical memory maps were trimmed by kernel command
  1633. * line options, don't even try freeing this initmem stuff up.
  1634. * The kernel image could have been in the trimmed out region
  1635. * and if so the freeing below will free invalid page structs.
  1636. */
  1637. if (cmdline_memory_size)
  1638. do_free = 0;
  1639. /*
  1640. * The init section is aligned to 8k in vmlinux.lds. Page align for >8k pagesizes.
  1641. */
  1642. addr = PAGE_ALIGN((unsigned long)(__init_begin));
  1643. initend = (unsigned long)(__init_end) & PAGE_MASK;
  1644. for (; addr < initend; addr += PAGE_SIZE) {
  1645. unsigned long page;
  1646. struct page *p;
  1647. page = (addr +
  1648. ((unsigned long) __va(kern_base)) -
  1649. ((unsigned long) KERNBASE));
  1650. memset((void *)addr, POISON_FREE_INITMEM, PAGE_SIZE);
  1651. if (do_free) {
  1652. p = virt_to_page(page);
  1653. ClearPageReserved(p);
  1654. init_page_count(p);
  1655. __free_page(p);
  1656. num_physpages++;
  1657. totalram_pages++;
  1658. }
  1659. }
  1660. }
  1661. #ifdef CONFIG_BLK_DEV_INITRD
  1662. void free_initrd_mem(unsigned long start, unsigned long end)
  1663. {
  1664. if (start < end)
  1665. printk ("Freeing initrd memory: %ldk freed\n", (end - start) >> 10);
  1666. for (; start < end; start += PAGE_SIZE) {
  1667. struct page *p = virt_to_page(start);
  1668. ClearPageReserved(p);
  1669. init_page_count(p);
  1670. __free_page(p);
  1671. num_physpages++;
  1672. totalram_pages++;
  1673. }
  1674. }
  1675. #endif
  1676. #define _PAGE_CACHE_4U (_PAGE_CP_4U | _PAGE_CV_4U)
  1677. #define _PAGE_CACHE_4V (_PAGE_CP_4V | _PAGE_CV_4V)
  1678. #define __DIRTY_BITS_4U (_PAGE_MODIFIED_4U | _PAGE_WRITE_4U | _PAGE_W_4U)
  1679. #define __DIRTY_BITS_4V (_PAGE_MODIFIED_4V | _PAGE_WRITE_4V | _PAGE_W_4V)
  1680. #define __ACCESS_BITS_4U (_PAGE_ACCESSED_4U | _PAGE_READ_4U | _PAGE_R)
  1681. #define __ACCESS_BITS_4V (_PAGE_ACCESSED_4V | _PAGE_READ_4V | _PAGE_R)
  1682. pgprot_t PAGE_KERNEL __read_mostly;
  1683. EXPORT_SYMBOL(PAGE_KERNEL);
  1684. pgprot_t PAGE_KERNEL_LOCKED __read_mostly;
  1685. pgprot_t PAGE_COPY __read_mostly;
  1686. pgprot_t PAGE_SHARED __read_mostly;
  1687. EXPORT_SYMBOL(PAGE_SHARED);
  1688. unsigned long pg_iobits __read_mostly;
  1689. unsigned long _PAGE_IE __read_mostly;
  1690. EXPORT_SYMBOL(_PAGE_IE);
  1691. unsigned long _PAGE_E __read_mostly;
  1692. EXPORT_SYMBOL(_PAGE_E);
  1693. unsigned long _PAGE_CACHE __read_mostly;
  1694. EXPORT_SYMBOL(_PAGE_CACHE);
  1695. #ifdef CONFIG_SPARSEMEM_VMEMMAP
  1696. unsigned long vmemmap_table[VMEMMAP_SIZE];
  1697. int __meminit vmemmap_populate(struct page *start, unsigned long nr, int node)
  1698. {
  1699. unsigned long vstart = (unsigned long) start;
  1700. unsigned long vend = (unsigned long) (start + nr);
  1701. unsigned long phys_start = (vstart - VMEMMAP_BASE);
  1702. unsigned long phys_end = (vend - VMEMMAP_BASE);
  1703. unsigned long addr = phys_start & VMEMMAP_CHUNK_MASK;
  1704. unsigned long end = VMEMMAP_ALIGN(phys_end);
  1705. unsigned long pte_base;
  1706. pte_base = (_PAGE_VALID | _PAGE_SZ4MB_4U |
  1707. _PAGE_CP_4U | _PAGE_CV_4U |
  1708. _PAGE_P_4U | _PAGE_W_4U);
  1709. if (tlb_type == hypervisor)
  1710. pte_base = (_PAGE_VALID | _PAGE_SZ4MB_4V |
  1711. _PAGE_CP_4V | _PAGE_CV_4V |
  1712. _PAGE_P_4V | _PAGE_W_4V);
  1713. for (; addr < end; addr += VMEMMAP_CHUNK) {
  1714. unsigned long *vmem_pp =
  1715. vmemmap_table + (addr >> VMEMMAP_CHUNK_SHIFT);
  1716. void *block;
  1717. if (!(*vmem_pp & _PAGE_VALID)) {
  1718. block = vmemmap_alloc_block(1UL << 22, node);
  1719. if (!block)
  1720. return -ENOMEM;
  1721. *vmem_pp = pte_base | __pa(block);
  1722. printk(KERN_INFO "[%p-%p] page_structs=%lu "
  1723. "node=%d entry=%lu/%lu\n", start, block, nr,
  1724. node,
  1725. addr >> VMEMMAP_CHUNK_SHIFT,
  1726. VMEMMAP_SIZE);
  1727. }
  1728. }
  1729. return 0;
  1730. }
  1731. #endif /* CONFIG_SPARSEMEM_VMEMMAP */
  1732. static void prot_init_common(unsigned long page_none,
  1733. unsigned long page_shared,
  1734. unsigned long page_copy,
  1735. unsigned long page_readonly,
  1736. unsigned long page_exec_bit)
  1737. {
  1738. PAGE_COPY = __pgprot(page_copy);
  1739. PAGE_SHARED = __pgprot(page_shared);
  1740. protection_map[0x0] = __pgprot(page_none);
  1741. protection_map[0x1] = __pgprot(page_readonly & ~page_exec_bit);
  1742. protection_map[0x2] = __pgprot(page_copy & ~page_exec_bit);
  1743. protection_map[0x3] = __pgprot(page_copy & ~page_exec_bit);
  1744. protection_map[0x4] = __pgprot(page_readonly);
  1745. protection_map[0x5] = __pgprot(page_readonly);
  1746. protection_map[0x6] = __pgprot(page_copy);
  1747. protection_map[0x7] = __pgprot(page_copy);
  1748. protection_map[0x8] = __pgprot(page_none);
  1749. protection_map[0x9] = __pgprot(page_readonly & ~page_exec_bit);
  1750. protection_map[0xa] = __pgprot(page_shared & ~page_exec_bit);
  1751. protection_map[0xb] = __pgprot(page_shared & ~page_exec_bit);
  1752. protection_map[0xc] = __pgprot(page_readonly);
  1753. protection_map[0xd] = __pgprot(page_readonly);
  1754. protection_map[0xe] = __pgprot(page_shared);
  1755. protection_map[0xf] = __pgprot(page_shared);
  1756. }
  1757. static void __init sun4u_pgprot_init(void)
  1758. {
  1759. unsigned long page_none, page_shared, page_copy, page_readonly;
  1760. unsigned long page_exec_bit;
  1761. PAGE_KERNEL = __pgprot (_PAGE_PRESENT_4U | _PAGE_VALID |
  1762. _PAGE_CACHE_4U | _PAGE_P_4U |
  1763. __ACCESS_BITS_4U | __DIRTY_BITS_4U |
  1764. _PAGE_EXEC_4U);
  1765. PAGE_KERNEL_LOCKED = __pgprot (_PAGE_PRESENT_4U | _PAGE_VALID |
  1766. _PAGE_CACHE_4U | _PAGE_P_4U |
  1767. __ACCESS_BITS_4U | __DIRTY_BITS_4U |
  1768. _PAGE_EXEC_4U | _PAGE_L_4U);
  1769. _PAGE_IE = _PAGE_IE_4U;
  1770. _PAGE_E = _PAGE_E_4U;
  1771. _PAGE_CACHE = _PAGE_CACHE_4U;
  1772. pg_iobits = (_PAGE_VALID | _PAGE_PRESENT_4U | __DIRTY_BITS_4U |
  1773. __ACCESS_BITS_4U | _PAGE_E_4U);
  1774. #ifdef CONFIG_DEBUG_PAGEALLOC
  1775. kern_linear_pte_xor[0] = (_PAGE_VALID | _PAGE_SZBITS_4U) ^
  1776. 0xfffff80000000000UL;
  1777. #else
  1778. kern_linear_pte_xor[0] = (_PAGE_VALID | _PAGE_SZ4MB_4U) ^
  1779. 0xfffff80000000000UL;
  1780. #endif
  1781. kern_linear_pte_xor[0] |= (_PAGE_CP_4U | _PAGE_CV_4U |
  1782. _PAGE_P_4U | _PAGE_W_4U);
  1783. /* XXX Should use 256MB on Panther. XXX */
  1784. kern_linear_pte_xor[1] = kern_linear_pte_xor[0];
  1785. _PAGE_SZBITS = _PAGE_SZBITS_4U;
  1786. _PAGE_ALL_SZ_BITS = (_PAGE_SZ4MB_4U | _PAGE_SZ512K_4U |
  1787. _PAGE_SZ64K_4U | _PAGE_SZ8K_4U |
  1788. _PAGE_SZ32MB_4U | _PAGE_SZ256MB_4U);
  1789. page_none = _PAGE_PRESENT_4U | _PAGE_ACCESSED_4U | _PAGE_CACHE_4U;
  1790. page_shared = (_PAGE_VALID | _PAGE_PRESENT_4U | _PAGE_CACHE_4U |
  1791. __ACCESS_BITS_4U | _PAGE_WRITE_4U | _PAGE_EXEC_4U);
  1792. page_copy = (_PAGE_VALID | _PAGE_PRESENT_4U | _PAGE_CACHE_4U |
  1793. __ACCESS_BITS_4U | _PAGE_EXEC_4U);
  1794. page_readonly = (_PAGE_VALID | _PAGE_PRESENT_4U | _PAGE_CACHE_4U |
  1795. __ACCESS_BITS_4U | _PAGE_EXEC_4U);
  1796. page_exec_bit = _PAGE_EXEC_4U;
  1797. prot_init_common(page_none, page_shared, page_copy, page_readonly,
  1798. page_exec_bit);
  1799. }
  1800. static void __init sun4v_pgprot_init(void)
  1801. {
  1802. unsigned long page_none, page_shared, page_copy, page_readonly;
  1803. unsigned long page_exec_bit;
  1804. PAGE_KERNEL = __pgprot (_PAGE_PRESENT_4V | _PAGE_VALID |
  1805. _PAGE_CACHE_4V | _PAGE_P_4V |
  1806. __ACCESS_BITS_4V | __DIRTY_BITS_4V |
  1807. _PAGE_EXEC_4V);
  1808. PAGE_KERNEL_LOCKED = PAGE_KERNEL;
  1809. _PAGE_IE = _PAGE_IE_4V;
  1810. _PAGE_E = _PAGE_E_4V;
  1811. _PAGE_CACHE = _PAGE_CACHE_4V;
  1812. #ifdef CONFIG_DEBUG_PAGEALLOC
  1813. kern_linear_pte_xor[0] = (_PAGE_VALID | _PAGE_SZBITS_4V) ^
  1814. 0xfffff80000000000UL;
  1815. #else
  1816. kern_linear_pte_xor[0] = (_PAGE_VALID | _PAGE_SZ4MB_4V) ^
  1817. 0xfffff80000000000UL;
  1818. #endif
  1819. kern_linear_pte_xor[0] |= (_PAGE_CP_4V | _PAGE_CV_4V |
  1820. _PAGE_P_4V | _PAGE_W_4V);
  1821. #ifdef CONFIG_DEBUG_PAGEALLOC
  1822. kern_linear_pte_xor[1] = (_PAGE_VALID | _PAGE_SZBITS_4V) ^
  1823. 0xfffff80000000000UL;
  1824. #else
  1825. kern_linear_pte_xor[1] = (_PAGE_VALID | _PAGE_SZ256MB_4V) ^
  1826. 0xfffff80000000000UL;
  1827. #endif
  1828. kern_linear_pte_xor[1] |= (_PAGE_CP_4V | _PAGE_CV_4V |
  1829. _PAGE_P_4V | _PAGE_W_4V);
  1830. pg_iobits = (_PAGE_VALID | _PAGE_PRESENT_4V | __DIRTY_BITS_4V |
  1831. __ACCESS_BITS_4V | _PAGE_E_4V);
  1832. _PAGE_SZBITS = _PAGE_SZBITS_4V;
  1833. _PAGE_ALL_SZ_BITS = (_PAGE_SZ16GB_4V | _PAGE_SZ2GB_4V |
  1834. _PAGE_SZ256MB_4V | _PAGE_SZ32MB_4V |
  1835. _PAGE_SZ4MB_4V | _PAGE_SZ512K_4V |
  1836. _PAGE_SZ64K_4V | _PAGE_SZ8K_4V);
  1837. page_none = _PAGE_PRESENT_4V | _PAGE_ACCESSED_4V | _PAGE_CACHE_4V;
  1838. page_shared = (_PAGE_VALID | _PAGE_PRESENT_4V | _PAGE_CACHE_4V |
  1839. __ACCESS_BITS_4V | _PAGE_WRITE_4V | _PAGE_EXEC_4V);
  1840. page_copy = (_PAGE_VALID | _PAGE_PRESENT_4V | _PAGE_CACHE_4V |
  1841. __ACCESS_BITS_4V | _PAGE_EXEC_4V);
  1842. page_readonly = (_PAGE_VALID | _PAGE_PRESENT_4V | _PAGE_CACHE_4V |
  1843. __ACCESS_BITS_4V | _PAGE_EXEC_4V);
  1844. page_exec_bit = _PAGE_EXEC_4V;
  1845. prot_init_common(page_none, page_shared, page_copy, page_readonly,
  1846. page_exec_bit);
  1847. }
  1848. unsigned long pte_sz_bits(unsigned long sz)
  1849. {
  1850. if (tlb_type == hypervisor) {
  1851. switch (sz) {
  1852. case 8 * 1024:
  1853. default:
  1854. return _PAGE_SZ8K_4V;
  1855. case 64 * 1024:
  1856. return _PAGE_SZ64K_4V;
  1857. case 512 * 1024:
  1858. return _PAGE_SZ512K_4V;
  1859. case 4 * 1024 * 1024:
  1860. return _PAGE_SZ4MB_4V;
  1861. }
  1862. } else {
  1863. switch (sz) {
  1864. case 8 * 1024:
  1865. default:
  1866. return _PAGE_SZ8K_4U;
  1867. case 64 * 1024:
  1868. return _PAGE_SZ64K_4U;
  1869. case 512 * 1024:
  1870. return _PAGE_SZ512K_4U;
  1871. case 4 * 1024 * 1024:
  1872. return _PAGE_SZ4MB_4U;
  1873. }
  1874. }
  1875. }
  1876. pte_t mk_pte_io(unsigned long page, pgprot_t prot, int space, unsigned long page_size)
  1877. {
  1878. pte_t pte;
  1879. pte_val(pte) = page | pgprot_val(pgprot_noncached(prot));
  1880. pte_val(pte) |= (((unsigned long)space) << 32);
  1881. pte_val(pte) |= pte_sz_bits(page_size);
  1882. return pte;
  1883. }
  1884. static unsigned long kern_large_tte(unsigned long paddr)
  1885. {
  1886. unsigned long val;
  1887. val = (_PAGE_VALID | _PAGE_SZ4MB_4U |
  1888. _PAGE_CP_4U | _PAGE_CV_4U | _PAGE_P_4U |
  1889. _PAGE_EXEC_4U | _PAGE_L_4U | _PAGE_W_4U);
  1890. if (tlb_type == hypervisor)
  1891. val = (_PAGE_VALID | _PAGE_SZ4MB_4V |
  1892. _PAGE_CP_4V | _PAGE_CV_4V | _PAGE_P_4V |
  1893. _PAGE_EXEC_4V | _PAGE_W_4V);
  1894. return val | paddr;
  1895. }
  1896. /* If not locked, zap it. */
  1897. void __flush_tlb_all(void)
  1898. {
  1899. unsigned long pstate;
  1900. int i;
  1901. __asm__ __volatile__("flushw\n\t"
  1902. "rdpr %%pstate, %0\n\t"
  1903. "wrpr %0, %1, %%pstate"
  1904. : "=r" (pstate)
  1905. : "i" (PSTATE_IE));
  1906. if (tlb_type == hypervisor) {
  1907. sun4v_mmu_demap_all();
  1908. } else if (tlb_type == spitfire) {
  1909. for (i = 0; i < 64; i++) {
  1910. /* Spitfire Errata #32 workaround */
  1911. /* NOTE: Always runs on spitfire, so no
  1912. * cheetah+ page size encodings.
  1913. */
  1914. __asm__ __volatile__("stxa %0, [%1] %2\n\t"
  1915. "flush %%g6"
  1916. : /* No outputs */
  1917. : "r" (0),
  1918. "r" (PRIMARY_CONTEXT), "i" (ASI_DMMU));
  1919. if (!(spitfire_get_dtlb_data(i) & _PAGE_L_4U)) {
  1920. __asm__ __volatile__("stxa %%g0, [%0] %1\n\t"
  1921. "membar #Sync"
  1922. : /* no outputs */
  1923. : "r" (TLB_TAG_ACCESS), "i" (ASI_DMMU));
  1924. spitfire_put_dtlb_data(i, 0x0UL);
  1925. }
  1926. /* Spitfire Errata #32 workaround */
  1927. /* NOTE: Always runs on spitfire, so no
  1928. * cheetah+ page size encodings.
  1929. */
  1930. __asm__ __volatile__("stxa %0, [%1] %2\n\t"
  1931. "flush %%g6"
  1932. : /* No outputs */
  1933. : "r" (0),
  1934. "r" (PRIMARY_CONTEXT), "i" (ASI_DMMU));
  1935. if (!(spitfire_get_itlb_data(i) & _PAGE_L_4U)) {
  1936. __asm__ __volatile__("stxa %%g0, [%0] %1\n\t"
  1937. "membar #Sync"
  1938. : /* no outputs */
  1939. : "r" (TLB_TAG_ACCESS), "i" (ASI_IMMU));
  1940. spitfire_put_itlb_data(i, 0x0UL);
  1941. }
  1942. }
  1943. } else if (tlb_type == cheetah || tlb_type == cheetah_plus) {
  1944. cheetah_flush_dtlb_all();
  1945. cheetah_flush_itlb_all();
  1946. }
  1947. __asm__ __volatile__("wrpr %0, 0, %%pstate"
  1948. : : "r" (pstate));
  1949. }