init_64.c 59 KB

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