init.c 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268
  1. /* $Id: init.c,v 1.209 2002/02/09 19:49:31 davem Exp $
  2. * arch/sparc64/mm/init.c
  3. *
  4. * Copyright (C) 1996-1999 David S. Miller (davem@caip.rutgers.edu)
  5. * Copyright (C) 1997-1999 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
  6. */
  7. #include <linux/config.h>
  8. #include <linux/kernel.h>
  9. #include <linux/sched.h>
  10. #include <linux/string.h>
  11. #include <linux/init.h>
  12. #include <linux/bootmem.h>
  13. #include <linux/mm.h>
  14. #include <linux/hugetlb.h>
  15. #include <linux/slab.h>
  16. #include <linux/initrd.h>
  17. #include <linux/swap.h>
  18. #include <linux/pagemap.h>
  19. #include <linux/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 <asm/head.h>
  25. #include <asm/system.h>
  26. #include <asm/page.h>
  27. #include <asm/pgalloc.h>
  28. #include <asm/pgtable.h>
  29. #include <asm/oplib.h>
  30. #include <asm/iommu.h>
  31. #include <asm/io.h>
  32. #include <asm/uaccess.h>
  33. #include <asm/mmu_context.h>
  34. #include <asm/tlbflush.h>
  35. #include <asm/dma.h>
  36. #include <asm/starfire.h>
  37. #include <asm/tlb.h>
  38. #include <asm/spitfire.h>
  39. #include <asm/sections.h>
  40. extern void device_scan(void);
  41. #define MAX_BANKS 32
  42. static struct linux_prom64_registers pavail[MAX_BANKS] __initdata;
  43. static struct linux_prom64_registers pavail_rescan[MAX_BANKS] __initdata;
  44. static int pavail_ents __initdata;
  45. static int pavail_rescan_ents __initdata;
  46. static int cmp_p64(const void *a, const void *b)
  47. {
  48. const struct linux_prom64_registers *x = a, *y = b;
  49. if (x->phys_addr > y->phys_addr)
  50. return 1;
  51. if (x->phys_addr < y->phys_addr)
  52. return -1;
  53. return 0;
  54. }
  55. static void __init read_obp_memory(const char *property,
  56. struct linux_prom64_registers *regs,
  57. int *num_ents)
  58. {
  59. int node = prom_finddevice("/memory");
  60. int prop_size = prom_getproplen(node, property);
  61. int ents, ret, i;
  62. ents = prop_size / sizeof(struct linux_prom64_registers);
  63. if (ents > MAX_BANKS) {
  64. prom_printf("The machine has more %s property entries than "
  65. "this kernel can support (%d).\n",
  66. property, MAX_BANKS);
  67. prom_halt();
  68. }
  69. ret = prom_getproperty(node, property, (char *) regs, prop_size);
  70. if (ret == -1) {
  71. prom_printf("Couldn't get %s property from /memory.\n");
  72. prom_halt();
  73. }
  74. *num_ents = ents;
  75. /* Sanitize what we got from the firmware, by page aligning
  76. * everything.
  77. */
  78. for (i = 0; i < ents; i++) {
  79. unsigned long base, size;
  80. base = regs[i].phys_addr;
  81. size = regs[i].reg_size;
  82. size &= PAGE_MASK;
  83. if (base & ~PAGE_MASK) {
  84. unsigned long new_base = PAGE_ALIGN(base);
  85. size -= new_base - base;
  86. if ((long) size < 0L)
  87. size = 0UL;
  88. base = new_base;
  89. }
  90. regs[i].phys_addr = base;
  91. regs[i].reg_size = size;
  92. }
  93. sort(regs, ents, sizeof(struct linux_prom64_registers),
  94. cmp_p64, NULL);
  95. }
  96. unsigned long *sparc64_valid_addr_bitmap __read_mostly;
  97. /* Ugly, but necessary... -DaveM */
  98. unsigned long phys_base __read_mostly;
  99. unsigned long kern_base __read_mostly;
  100. unsigned long kern_size __read_mostly;
  101. unsigned long pfn_base __read_mostly;
  102. /* get_new_mmu_context() uses "cache + 1". */
  103. DEFINE_SPINLOCK(ctx_alloc_lock);
  104. unsigned long tlb_context_cache = CTX_FIRST_VERSION - 1;
  105. #define CTX_BMAP_SLOTS (1UL << (CTX_NR_BITS - 6))
  106. unsigned long mmu_context_bmap[CTX_BMAP_SLOTS];
  107. /* References to special section boundaries */
  108. extern char _start[], _end[];
  109. /* Initial ramdisk setup */
  110. extern unsigned long sparc_ramdisk_image64;
  111. extern unsigned int sparc_ramdisk_image;
  112. extern unsigned int sparc_ramdisk_size;
  113. struct page *mem_map_zero __read_mostly;
  114. unsigned int sparc64_highest_unlocked_tlb_ent __read_mostly;
  115. unsigned long sparc64_kern_pri_context __read_mostly;
  116. unsigned long sparc64_kern_pri_nuc_bits __read_mostly;
  117. unsigned long sparc64_kern_sec_context __read_mostly;
  118. int bigkernel = 0;
  119. kmem_cache_t *pgtable_cache __read_mostly;
  120. static void zero_ctor(void *addr, kmem_cache_t *cache, unsigned long flags)
  121. {
  122. clear_page(addr);
  123. }
  124. void pgtable_cache_init(void)
  125. {
  126. pgtable_cache = kmem_cache_create("pgtable_cache",
  127. PAGE_SIZE, PAGE_SIZE,
  128. SLAB_HWCACHE_ALIGN |
  129. SLAB_MUST_HWCACHE_ALIGN,
  130. zero_ctor,
  131. NULL);
  132. if (!pgtable_cache) {
  133. prom_printf("pgtable_cache_init(): Could not create!\n");
  134. prom_halt();
  135. }
  136. }
  137. #ifdef CONFIG_DEBUG_DCFLUSH
  138. atomic_t dcpage_flushes = ATOMIC_INIT(0);
  139. #ifdef CONFIG_SMP
  140. atomic_t dcpage_flushes_xcall = ATOMIC_INIT(0);
  141. #endif
  142. #endif
  143. __inline__ void flush_dcache_page_impl(struct page *page)
  144. {
  145. #ifdef CONFIG_DEBUG_DCFLUSH
  146. atomic_inc(&dcpage_flushes);
  147. #endif
  148. #ifdef DCACHE_ALIASING_POSSIBLE
  149. __flush_dcache_page(page_address(page),
  150. ((tlb_type == spitfire) &&
  151. page_mapping(page) != NULL));
  152. #else
  153. if (page_mapping(page) != NULL &&
  154. tlb_type == spitfire)
  155. __flush_icache_page(__pa(page_address(page)));
  156. #endif
  157. }
  158. #define PG_dcache_dirty PG_arch_1
  159. #define PG_dcache_cpu_shift 24
  160. #define PG_dcache_cpu_mask (256 - 1)
  161. #if NR_CPUS > 256
  162. #error D-cache dirty tracking and thread_info->cpu need fixing for > 256 cpus
  163. #endif
  164. #define dcache_dirty_cpu(page) \
  165. (((page)->flags >> PG_dcache_cpu_shift) & PG_dcache_cpu_mask)
  166. static __inline__ void set_dcache_dirty(struct page *page, int this_cpu)
  167. {
  168. unsigned long mask = this_cpu;
  169. unsigned long non_cpu_bits;
  170. non_cpu_bits = ~(PG_dcache_cpu_mask << PG_dcache_cpu_shift);
  171. mask = (mask << PG_dcache_cpu_shift) | (1UL << PG_dcache_dirty);
  172. __asm__ __volatile__("1:\n\t"
  173. "ldx [%2], %%g7\n\t"
  174. "and %%g7, %1, %%g1\n\t"
  175. "or %%g1, %0, %%g1\n\t"
  176. "casx [%2], %%g7, %%g1\n\t"
  177. "cmp %%g7, %%g1\n\t"
  178. "membar #StoreLoad | #StoreStore\n\t"
  179. "bne,pn %%xcc, 1b\n\t"
  180. " nop"
  181. : /* no outputs */
  182. : "r" (mask), "r" (non_cpu_bits), "r" (&page->flags)
  183. : "g1", "g7");
  184. }
  185. static __inline__ void clear_dcache_dirty_cpu(struct page *page, unsigned long cpu)
  186. {
  187. unsigned long mask = (1UL << PG_dcache_dirty);
  188. __asm__ __volatile__("! test_and_clear_dcache_dirty\n"
  189. "1:\n\t"
  190. "ldx [%2], %%g7\n\t"
  191. "srlx %%g7, %4, %%g1\n\t"
  192. "and %%g1, %3, %%g1\n\t"
  193. "cmp %%g1, %0\n\t"
  194. "bne,pn %%icc, 2f\n\t"
  195. " andn %%g7, %1, %%g1\n\t"
  196. "casx [%2], %%g7, %%g1\n\t"
  197. "cmp %%g7, %%g1\n\t"
  198. "membar #StoreLoad | #StoreStore\n\t"
  199. "bne,pn %%xcc, 1b\n\t"
  200. " nop\n"
  201. "2:"
  202. : /* no outputs */
  203. : "r" (cpu), "r" (mask), "r" (&page->flags),
  204. "i" (PG_dcache_cpu_mask),
  205. "i" (PG_dcache_cpu_shift)
  206. : "g1", "g7");
  207. }
  208. void update_mmu_cache(struct vm_area_struct *vma, unsigned long address, pte_t pte)
  209. {
  210. struct mm_struct *mm;
  211. struct page *page;
  212. unsigned long pfn;
  213. unsigned long pg_flags;
  214. unsigned long mm_rss;
  215. pfn = pte_pfn(pte);
  216. if (pfn_valid(pfn) &&
  217. (page = pfn_to_page(pfn), page_mapping(page)) &&
  218. ((pg_flags = page->flags) & (1UL << PG_dcache_dirty))) {
  219. int cpu = ((pg_flags >> PG_dcache_cpu_shift) &
  220. PG_dcache_cpu_mask);
  221. int this_cpu = get_cpu();
  222. /* This is just to optimize away some function calls
  223. * in the SMP case.
  224. */
  225. if (cpu == this_cpu)
  226. flush_dcache_page_impl(page);
  227. else
  228. smp_flush_dcache_page_impl(page, cpu);
  229. clear_dcache_dirty_cpu(page, cpu);
  230. put_cpu();
  231. }
  232. mm = vma->vm_mm;
  233. mm_rss = get_mm_rss(mm);
  234. if (mm_rss >= mm->context.tsb_rss_limit)
  235. tsb_grow(mm, mm_rss, GFP_ATOMIC);
  236. if ((pte_val(pte) & _PAGE_ALL_SZ_BITS) == _PAGE_SZBITS) {
  237. struct tsb *tsb;
  238. unsigned long tag;
  239. tsb = &mm->context.tsb[(address >> PAGE_SHIFT) &
  240. (mm->context.tsb_nentries - 1UL)];
  241. tag = (address >> 22UL) | CTX_HWBITS(mm->context) << 48UL;
  242. tsb_insert(tsb, tag, pte_val(pte));
  243. }
  244. }
  245. void flush_dcache_page(struct page *page)
  246. {
  247. struct address_space *mapping;
  248. int this_cpu;
  249. /* Do not bother with the expensive D-cache flush if it
  250. * is merely the zero page. The 'bigcore' testcase in GDB
  251. * causes this case to run millions of times.
  252. */
  253. if (page == ZERO_PAGE(0))
  254. return;
  255. this_cpu = get_cpu();
  256. mapping = page_mapping(page);
  257. if (mapping && !mapping_mapped(mapping)) {
  258. int dirty = test_bit(PG_dcache_dirty, &page->flags);
  259. if (dirty) {
  260. int dirty_cpu = dcache_dirty_cpu(page);
  261. if (dirty_cpu == this_cpu)
  262. goto out;
  263. smp_flush_dcache_page_impl(page, dirty_cpu);
  264. }
  265. set_dcache_dirty(page, this_cpu);
  266. } else {
  267. /* We could delay the flush for the !page_mapping
  268. * case too. But that case is for exec env/arg
  269. * pages and those are %99 certainly going to get
  270. * faulted into the tlb (and thus flushed) anyways.
  271. */
  272. flush_dcache_page_impl(page);
  273. }
  274. out:
  275. put_cpu();
  276. }
  277. void __kprobes flush_icache_range(unsigned long start, unsigned long end)
  278. {
  279. /* Cheetah has coherent I-cache. */
  280. if (tlb_type == spitfire) {
  281. unsigned long kaddr;
  282. for (kaddr = start; kaddr < end; kaddr += PAGE_SIZE)
  283. __flush_icache_page(__get_phys(kaddr));
  284. }
  285. }
  286. unsigned long page_to_pfn(struct page *page)
  287. {
  288. return (unsigned long) ((page - mem_map) + pfn_base);
  289. }
  290. struct page *pfn_to_page(unsigned long pfn)
  291. {
  292. return (mem_map + (pfn - pfn_base));
  293. }
  294. void show_mem(void)
  295. {
  296. printk("Mem-info:\n");
  297. show_free_areas();
  298. printk("Free swap: %6ldkB\n",
  299. nr_swap_pages << (PAGE_SHIFT-10));
  300. printk("%ld pages of RAM\n", num_physpages);
  301. printk("%d free pages\n", nr_free_pages());
  302. }
  303. void mmu_info(struct seq_file *m)
  304. {
  305. if (tlb_type == cheetah)
  306. seq_printf(m, "MMU Type\t: Cheetah\n");
  307. else if (tlb_type == cheetah_plus)
  308. seq_printf(m, "MMU Type\t: Cheetah+\n");
  309. else if (tlb_type == spitfire)
  310. seq_printf(m, "MMU Type\t: Spitfire\n");
  311. else
  312. seq_printf(m, "MMU Type\t: ???\n");
  313. #ifdef CONFIG_DEBUG_DCFLUSH
  314. seq_printf(m, "DCPageFlushes\t: %d\n",
  315. atomic_read(&dcpage_flushes));
  316. #ifdef CONFIG_SMP
  317. seq_printf(m, "DCPageFlushesXC\t: %d\n",
  318. atomic_read(&dcpage_flushes_xcall));
  319. #endif /* CONFIG_SMP */
  320. #endif /* CONFIG_DEBUG_DCFLUSH */
  321. }
  322. struct linux_prom_translation {
  323. unsigned long virt;
  324. unsigned long size;
  325. unsigned long data;
  326. };
  327. /* Exported for kernel TLB miss handling in ktlb.S */
  328. struct linux_prom_translation prom_trans[512] __read_mostly;
  329. unsigned int prom_trans_ents __read_mostly;
  330. extern unsigned long prom_boot_page;
  331. extern void prom_remap(unsigned long physpage, unsigned long virtpage, int mmu_ihandle);
  332. extern int prom_get_mmu_ihandle(void);
  333. extern void register_prom_callbacks(void);
  334. /* Exported for SMP bootup purposes. */
  335. unsigned long kern_locked_tte_data;
  336. /*
  337. * Translate PROM's mapping we capture at boot time into physical address.
  338. * The second parameter is only set from prom_callback() invocations.
  339. */
  340. unsigned long prom_virt_to_phys(unsigned long promva, int *error)
  341. {
  342. int i;
  343. for (i = 0; i < prom_trans_ents; i++) {
  344. struct linux_prom_translation *p = &prom_trans[i];
  345. if (promva >= p->virt &&
  346. promva < (p->virt + p->size)) {
  347. unsigned long base = p->data & _PAGE_PADDR;
  348. if (error)
  349. *error = 0;
  350. return base + (promva & (8192 - 1));
  351. }
  352. }
  353. if (error)
  354. *error = 1;
  355. return 0UL;
  356. }
  357. /* The obp translations are saved based on 8k pagesize, since obp can
  358. * use a mixture of pagesizes. Misses to the LOW_OBP_ADDRESS ->
  359. * HI_OBP_ADDRESS range are handled in ktlb.S.
  360. */
  361. static inline int in_obp_range(unsigned long vaddr)
  362. {
  363. return (vaddr >= LOW_OBP_ADDRESS &&
  364. vaddr < HI_OBP_ADDRESS);
  365. }
  366. static int cmp_ptrans(const void *a, const void *b)
  367. {
  368. const struct linux_prom_translation *x = a, *y = b;
  369. if (x->virt > y->virt)
  370. return 1;
  371. if (x->virt < y->virt)
  372. return -1;
  373. return 0;
  374. }
  375. /* Read OBP translations property into 'prom_trans[]'. */
  376. static void __init read_obp_translations(void)
  377. {
  378. int n, node, ents, first, last, i;
  379. node = prom_finddevice("/virtual-memory");
  380. n = prom_getproplen(node, "translations");
  381. if (unlikely(n == 0 || n == -1)) {
  382. prom_printf("prom_mappings: Couldn't get size.\n");
  383. prom_halt();
  384. }
  385. if (unlikely(n > sizeof(prom_trans))) {
  386. prom_printf("prom_mappings: Size %Zd is too big.\n", n);
  387. prom_halt();
  388. }
  389. if ((n = prom_getproperty(node, "translations",
  390. (char *)&prom_trans[0],
  391. sizeof(prom_trans))) == -1) {
  392. prom_printf("prom_mappings: Couldn't get property.\n");
  393. prom_halt();
  394. }
  395. n = n / sizeof(struct linux_prom_translation);
  396. ents = n;
  397. sort(prom_trans, ents, sizeof(struct linux_prom_translation),
  398. cmp_ptrans, NULL);
  399. /* Now kick out all the non-OBP entries. */
  400. for (i = 0; i < ents; i++) {
  401. if (in_obp_range(prom_trans[i].virt))
  402. break;
  403. }
  404. first = i;
  405. for (; i < ents; i++) {
  406. if (!in_obp_range(prom_trans[i].virt))
  407. break;
  408. }
  409. last = i;
  410. for (i = 0; i < (last - first); i++) {
  411. struct linux_prom_translation *src = &prom_trans[i + first];
  412. struct linux_prom_translation *dest = &prom_trans[i];
  413. *dest = *src;
  414. }
  415. for (; i < ents; i++) {
  416. struct linux_prom_translation *dest = &prom_trans[i];
  417. dest->virt = dest->size = dest->data = 0x0UL;
  418. }
  419. prom_trans_ents = last - first;
  420. if (tlb_type == spitfire) {
  421. /* Clear diag TTE bits. */
  422. for (i = 0; i < prom_trans_ents; i++)
  423. prom_trans[i].data &= ~0x0003fe0000000000UL;
  424. }
  425. }
  426. static void __init remap_kernel(void)
  427. {
  428. unsigned long phys_page, tte_vaddr, tte_data;
  429. int tlb_ent = sparc64_highest_locked_tlbent();
  430. tte_vaddr = (unsigned long) KERNBASE;
  431. phys_page = (prom_boot_mapping_phys_low >> 22UL) << 22UL;
  432. tte_data = (phys_page | (_PAGE_VALID | _PAGE_SZ4MB |
  433. _PAGE_CP | _PAGE_CV | _PAGE_P |
  434. _PAGE_L | _PAGE_W));
  435. kern_locked_tte_data = tte_data;
  436. /* Now lock us into the TLBs via OBP. */
  437. prom_dtlb_load(tlb_ent, tte_data, tte_vaddr);
  438. prom_itlb_load(tlb_ent, tte_data, tte_vaddr);
  439. if (bigkernel) {
  440. tlb_ent -= 1;
  441. prom_dtlb_load(tlb_ent,
  442. tte_data + 0x400000,
  443. tte_vaddr + 0x400000);
  444. prom_itlb_load(tlb_ent,
  445. tte_data + 0x400000,
  446. tte_vaddr + 0x400000);
  447. }
  448. sparc64_highest_unlocked_tlb_ent = tlb_ent - 1;
  449. if (tlb_type == cheetah_plus) {
  450. sparc64_kern_pri_context = (CTX_CHEETAH_PLUS_CTX0 |
  451. CTX_CHEETAH_PLUS_NUC);
  452. sparc64_kern_pri_nuc_bits = CTX_CHEETAH_PLUS_NUC;
  453. sparc64_kern_sec_context = CTX_CHEETAH_PLUS_CTX0;
  454. }
  455. }
  456. static void __init inherit_prom_mappings(void)
  457. {
  458. read_obp_translations();
  459. /* Now fixup OBP's idea about where we really are mapped. */
  460. prom_printf("Remapping the kernel... ");
  461. remap_kernel();
  462. prom_printf("done.\n");
  463. prom_printf("Registering callbacks... ");
  464. register_prom_callbacks();
  465. prom_printf("done.\n");
  466. }
  467. void prom_world(int enter)
  468. {
  469. if (!enter)
  470. set_fs((mm_segment_t) { get_thread_current_ds() });
  471. __asm__ __volatile__("flushw");
  472. }
  473. #ifdef DCACHE_ALIASING_POSSIBLE
  474. void __flush_dcache_range(unsigned long start, unsigned long end)
  475. {
  476. unsigned long va;
  477. if (tlb_type == spitfire) {
  478. int n = 0;
  479. for (va = start; va < end; va += 32) {
  480. spitfire_put_dcache_tag(va & 0x3fe0, 0x0);
  481. if (++n >= 512)
  482. break;
  483. }
  484. } else {
  485. start = __pa(start);
  486. end = __pa(end);
  487. for (va = start; va < end; va += 32)
  488. __asm__ __volatile__("stxa %%g0, [%0] %1\n\t"
  489. "membar #Sync"
  490. : /* no outputs */
  491. : "r" (va),
  492. "i" (ASI_DCACHE_INVALIDATE));
  493. }
  494. }
  495. #endif /* DCACHE_ALIASING_POSSIBLE */
  496. /* If not locked, zap it. */
  497. void __flush_tlb_all(void)
  498. {
  499. unsigned long pstate;
  500. int i;
  501. __asm__ __volatile__("flushw\n\t"
  502. "rdpr %%pstate, %0\n\t"
  503. "wrpr %0, %1, %%pstate"
  504. : "=r" (pstate)
  505. : "i" (PSTATE_IE));
  506. if (tlb_type == spitfire) {
  507. for (i = 0; i < 64; i++) {
  508. /* Spitfire Errata #32 workaround */
  509. /* NOTE: Always runs on spitfire, so no
  510. * cheetah+ page size encodings.
  511. */
  512. __asm__ __volatile__("stxa %0, [%1] %2\n\t"
  513. "flush %%g6"
  514. : /* No outputs */
  515. : "r" (0),
  516. "r" (PRIMARY_CONTEXT), "i" (ASI_DMMU));
  517. if (!(spitfire_get_dtlb_data(i) & _PAGE_L)) {
  518. __asm__ __volatile__("stxa %%g0, [%0] %1\n\t"
  519. "membar #Sync"
  520. : /* no outputs */
  521. : "r" (TLB_TAG_ACCESS), "i" (ASI_DMMU));
  522. spitfire_put_dtlb_data(i, 0x0UL);
  523. }
  524. /* Spitfire Errata #32 workaround */
  525. /* NOTE: Always runs on spitfire, so no
  526. * cheetah+ page size encodings.
  527. */
  528. __asm__ __volatile__("stxa %0, [%1] %2\n\t"
  529. "flush %%g6"
  530. : /* No outputs */
  531. : "r" (0),
  532. "r" (PRIMARY_CONTEXT), "i" (ASI_DMMU));
  533. if (!(spitfire_get_itlb_data(i) & _PAGE_L)) {
  534. __asm__ __volatile__("stxa %%g0, [%0] %1\n\t"
  535. "membar #Sync"
  536. : /* no outputs */
  537. : "r" (TLB_TAG_ACCESS), "i" (ASI_IMMU));
  538. spitfire_put_itlb_data(i, 0x0UL);
  539. }
  540. }
  541. } else if (tlb_type == cheetah || tlb_type == cheetah_plus) {
  542. cheetah_flush_dtlb_all();
  543. cheetah_flush_itlb_all();
  544. }
  545. __asm__ __volatile__("wrpr %0, 0, %%pstate"
  546. : : "r" (pstate));
  547. }
  548. /* Caller does TLB context flushing on local CPU if necessary.
  549. * The caller also ensures that CTX_VALID(mm->context) is false.
  550. *
  551. * We must be careful about boundary cases so that we never
  552. * let the user have CTX 0 (nucleus) or we ever use a CTX
  553. * version of zero (and thus NO_CONTEXT would not be caught
  554. * by version mis-match tests in mmu_context.h).
  555. */
  556. void get_new_mmu_context(struct mm_struct *mm)
  557. {
  558. unsigned long ctx, new_ctx;
  559. unsigned long orig_pgsz_bits;
  560. spin_lock(&ctx_alloc_lock);
  561. orig_pgsz_bits = (mm->context.sparc64_ctx_val & CTX_PGSZ_MASK);
  562. ctx = (tlb_context_cache + 1) & CTX_NR_MASK;
  563. new_ctx = find_next_zero_bit(mmu_context_bmap, 1 << CTX_NR_BITS, ctx);
  564. if (new_ctx >= (1 << CTX_NR_BITS)) {
  565. new_ctx = find_next_zero_bit(mmu_context_bmap, ctx, 1);
  566. if (new_ctx >= ctx) {
  567. int i;
  568. new_ctx = (tlb_context_cache & CTX_VERSION_MASK) +
  569. CTX_FIRST_VERSION;
  570. if (new_ctx == 1)
  571. new_ctx = CTX_FIRST_VERSION;
  572. /* Don't call memset, for 16 entries that's just
  573. * plain silly...
  574. */
  575. mmu_context_bmap[0] = 3;
  576. mmu_context_bmap[1] = 0;
  577. mmu_context_bmap[2] = 0;
  578. mmu_context_bmap[3] = 0;
  579. for (i = 4; i < CTX_BMAP_SLOTS; i += 4) {
  580. mmu_context_bmap[i + 0] = 0;
  581. mmu_context_bmap[i + 1] = 0;
  582. mmu_context_bmap[i + 2] = 0;
  583. mmu_context_bmap[i + 3] = 0;
  584. }
  585. goto out;
  586. }
  587. }
  588. mmu_context_bmap[new_ctx>>6] |= (1UL << (new_ctx & 63));
  589. new_ctx |= (tlb_context_cache & CTX_VERSION_MASK);
  590. out:
  591. tlb_context_cache = new_ctx;
  592. mm->context.sparc64_ctx_val = new_ctx | orig_pgsz_bits;
  593. spin_unlock(&ctx_alloc_lock);
  594. }
  595. void sparc_ultra_dump_itlb(void)
  596. {
  597. int slot;
  598. if (tlb_type == spitfire) {
  599. printk ("Contents of itlb: ");
  600. for (slot = 0; slot < 14; slot++) printk (" ");
  601. printk ("%2x:%016lx,%016lx\n",
  602. 0,
  603. spitfire_get_itlb_tag(0), spitfire_get_itlb_data(0));
  604. for (slot = 1; slot < 64; slot+=3) {
  605. printk ("%2x:%016lx,%016lx %2x:%016lx,%016lx %2x:%016lx,%016lx\n",
  606. slot,
  607. spitfire_get_itlb_tag(slot), spitfire_get_itlb_data(slot),
  608. slot+1,
  609. spitfire_get_itlb_tag(slot+1), spitfire_get_itlb_data(slot+1),
  610. slot+2,
  611. spitfire_get_itlb_tag(slot+2), spitfire_get_itlb_data(slot+2));
  612. }
  613. } else if (tlb_type == cheetah || tlb_type == cheetah_plus) {
  614. printk ("Contents of itlb0:\n");
  615. for (slot = 0; slot < 16; slot+=2) {
  616. printk ("%2x:%016lx,%016lx %2x:%016lx,%016lx\n",
  617. slot,
  618. cheetah_get_litlb_tag(slot), cheetah_get_litlb_data(slot),
  619. slot+1,
  620. cheetah_get_litlb_tag(slot+1), cheetah_get_litlb_data(slot+1));
  621. }
  622. printk ("Contents of itlb2:\n");
  623. for (slot = 0; slot < 128; slot+=2) {
  624. printk ("%2x:%016lx,%016lx %2x:%016lx,%016lx\n",
  625. slot,
  626. cheetah_get_itlb_tag(slot), cheetah_get_itlb_data(slot),
  627. slot+1,
  628. cheetah_get_itlb_tag(slot+1), cheetah_get_itlb_data(slot+1));
  629. }
  630. }
  631. }
  632. void sparc_ultra_dump_dtlb(void)
  633. {
  634. int slot;
  635. if (tlb_type == spitfire) {
  636. printk ("Contents of dtlb: ");
  637. for (slot = 0; slot < 14; slot++) printk (" ");
  638. printk ("%2x:%016lx,%016lx\n", 0,
  639. spitfire_get_dtlb_tag(0), spitfire_get_dtlb_data(0));
  640. for (slot = 1; slot < 64; slot+=3) {
  641. printk ("%2x:%016lx,%016lx %2x:%016lx,%016lx %2x:%016lx,%016lx\n",
  642. slot,
  643. spitfire_get_dtlb_tag(slot), spitfire_get_dtlb_data(slot),
  644. slot+1,
  645. spitfire_get_dtlb_tag(slot+1), spitfire_get_dtlb_data(slot+1),
  646. slot+2,
  647. spitfire_get_dtlb_tag(slot+2), spitfire_get_dtlb_data(slot+2));
  648. }
  649. } else if (tlb_type == cheetah || tlb_type == cheetah_plus) {
  650. printk ("Contents of dtlb0:\n");
  651. for (slot = 0; slot < 16; slot+=2) {
  652. printk ("%2x:%016lx,%016lx %2x:%016lx,%016lx\n",
  653. slot,
  654. cheetah_get_ldtlb_tag(slot), cheetah_get_ldtlb_data(slot),
  655. slot+1,
  656. cheetah_get_ldtlb_tag(slot+1), cheetah_get_ldtlb_data(slot+1));
  657. }
  658. printk ("Contents of dtlb2:\n");
  659. for (slot = 0; slot < 512; slot+=2) {
  660. printk ("%2x:%016lx,%016lx %2x:%016lx,%016lx\n",
  661. slot,
  662. cheetah_get_dtlb_tag(slot, 2), cheetah_get_dtlb_data(slot, 2),
  663. slot+1,
  664. cheetah_get_dtlb_tag(slot+1, 2), cheetah_get_dtlb_data(slot+1, 2));
  665. }
  666. if (tlb_type == cheetah_plus) {
  667. printk ("Contents of dtlb3:\n");
  668. for (slot = 0; slot < 512; slot+=2) {
  669. printk ("%2x:%016lx,%016lx %2x:%016lx,%016lx\n",
  670. slot,
  671. cheetah_get_dtlb_tag(slot, 3), cheetah_get_dtlb_data(slot, 3),
  672. slot+1,
  673. cheetah_get_dtlb_tag(slot+1, 3), cheetah_get_dtlb_data(slot+1, 3));
  674. }
  675. }
  676. }
  677. }
  678. static inline void spitfire_errata32(void)
  679. {
  680. __asm__ __volatile__("stxa %0, [%1] %2\n\t"
  681. "flush %%g6"
  682. : /* No outputs */
  683. : "r" (0),
  684. "r" (PRIMARY_CONTEXT), "i" (ASI_DMMU));
  685. }
  686. extern unsigned long cmdline_memory_size;
  687. unsigned long __init bootmem_init(unsigned long *pages_avail)
  688. {
  689. unsigned long bootmap_size, start_pfn, end_pfn;
  690. unsigned long end_of_phys_memory = 0UL;
  691. unsigned long bootmap_pfn, bytes_avail, size;
  692. int i;
  693. #ifdef CONFIG_DEBUG_BOOTMEM
  694. prom_printf("bootmem_init: Scan pavail, ");
  695. #endif
  696. bytes_avail = 0UL;
  697. for (i = 0; i < pavail_ents; i++) {
  698. end_of_phys_memory = pavail[i].phys_addr +
  699. pavail[i].reg_size;
  700. bytes_avail += pavail[i].reg_size;
  701. if (cmdline_memory_size) {
  702. if (bytes_avail > cmdline_memory_size) {
  703. unsigned long slack = bytes_avail - cmdline_memory_size;
  704. bytes_avail -= slack;
  705. end_of_phys_memory -= slack;
  706. pavail[i].reg_size -= slack;
  707. if ((long)pavail[i].reg_size <= 0L) {
  708. pavail[i].phys_addr = 0xdeadbeefUL;
  709. pavail[i].reg_size = 0UL;
  710. pavail_ents = i;
  711. } else {
  712. pavail[i+1].reg_size = 0Ul;
  713. pavail[i+1].phys_addr = 0xdeadbeefUL;
  714. pavail_ents = i + 1;
  715. }
  716. break;
  717. }
  718. }
  719. }
  720. *pages_avail = bytes_avail >> PAGE_SHIFT;
  721. /* Start with page aligned address of last symbol in kernel
  722. * image. The kernel is hard mapped below PAGE_OFFSET in a
  723. * 4MB locked TLB translation.
  724. */
  725. start_pfn = PAGE_ALIGN(kern_base + kern_size) >> PAGE_SHIFT;
  726. bootmap_pfn = start_pfn;
  727. end_pfn = end_of_phys_memory >> PAGE_SHIFT;
  728. #ifdef CONFIG_BLK_DEV_INITRD
  729. /* Now have to check initial ramdisk, so that bootmap does not overwrite it */
  730. if (sparc_ramdisk_image || sparc_ramdisk_image64) {
  731. unsigned long ramdisk_image = sparc_ramdisk_image ?
  732. sparc_ramdisk_image : sparc_ramdisk_image64;
  733. if (ramdisk_image >= (unsigned long)_end - 2 * PAGE_SIZE)
  734. ramdisk_image -= KERNBASE;
  735. initrd_start = ramdisk_image + phys_base;
  736. initrd_end = initrd_start + sparc_ramdisk_size;
  737. if (initrd_end > end_of_phys_memory) {
  738. printk(KERN_CRIT "initrd extends beyond end of memory "
  739. "(0x%016lx > 0x%016lx)\ndisabling initrd\n",
  740. initrd_end, end_of_phys_memory);
  741. initrd_start = 0;
  742. }
  743. if (initrd_start) {
  744. if (initrd_start >= (start_pfn << PAGE_SHIFT) &&
  745. initrd_start < (start_pfn << PAGE_SHIFT) + 2 * PAGE_SIZE)
  746. bootmap_pfn = PAGE_ALIGN (initrd_end) >> PAGE_SHIFT;
  747. }
  748. }
  749. #endif
  750. /* Initialize the boot-time allocator. */
  751. max_pfn = max_low_pfn = end_pfn;
  752. min_low_pfn = pfn_base;
  753. #ifdef CONFIG_DEBUG_BOOTMEM
  754. prom_printf("init_bootmem(min[%lx], bootmap[%lx], max[%lx])\n",
  755. min_low_pfn, bootmap_pfn, max_low_pfn);
  756. #endif
  757. bootmap_size = init_bootmem_node(NODE_DATA(0), bootmap_pfn, pfn_base, end_pfn);
  758. /* Now register the available physical memory with the
  759. * allocator.
  760. */
  761. for (i = 0; i < pavail_ents; i++) {
  762. #ifdef CONFIG_DEBUG_BOOTMEM
  763. prom_printf("free_bootmem(pavail:%d): base[%lx] size[%lx]\n",
  764. i, pavail[i].phys_addr, pavail[i].reg_size);
  765. #endif
  766. free_bootmem(pavail[i].phys_addr, pavail[i].reg_size);
  767. }
  768. #ifdef CONFIG_BLK_DEV_INITRD
  769. if (initrd_start) {
  770. size = initrd_end - initrd_start;
  771. /* Resert the initrd image area. */
  772. #ifdef CONFIG_DEBUG_BOOTMEM
  773. prom_printf("reserve_bootmem(initrd): base[%llx] size[%lx]\n",
  774. initrd_start, initrd_end);
  775. #endif
  776. reserve_bootmem(initrd_start, size);
  777. *pages_avail -= PAGE_ALIGN(size) >> PAGE_SHIFT;
  778. initrd_start += PAGE_OFFSET;
  779. initrd_end += PAGE_OFFSET;
  780. }
  781. #endif
  782. /* Reserve the kernel text/data/bss. */
  783. #ifdef CONFIG_DEBUG_BOOTMEM
  784. prom_printf("reserve_bootmem(kernel): base[%lx] size[%lx]\n", kern_base, kern_size);
  785. #endif
  786. reserve_bootmem(kern_base, kern_size);
  787. *pages_avail -= PAGE_ALIGN(kern_size) >> PAGE_SHIFT;
  788. /* Reserve the bootmem map. We do not account for it
  789. * in pages_avail because we will release that memory
  790. * in free_all_bootmem.
  791. */
  792. size = bootmap_size;
  793. #ifdef CONFIG_DEBUG_BOOTMEM
  794. prom_printf("reserve_bootmem(bootmap): base[%lx] size[%lx]\n",
  795. (bootmap_pfn << PAGE_SHIFT), size);
  796. #endif
  797. reserve_bootmem((bootmap_pfn << PAGE_SHIFT), size);
  798. *pages_avail -= PAGE_ALIGN(size) >> PAGE_SHIFT;
  799. return end_pfn;
  800. }
  801. #ifdef CONFIG_DEBUG_PAGEALLOC
  802. static unsigned long kernel_map_range(unsigned long pstart, unsigned long pend, pgprot_t prot)
  803. {
  804. unsigned long vstart = PAGE_OFFSET + pstart;
  805. unsigned long vend = PAGE_OFFSET + pend;
  806. unsigned long alloc_bytes = 0UL;
  807. if ((vstart & ~PAGE_MASK) || (vend & ~PAGE_MASK)) {
  808. prom_printf("kernel_map: Unaligned physmem[%lx:%lx]\n",
  809. vstart, vend);
  810. prom_halt();
  811. }
  812. while (vstart < vend) {
  813. unsigned long this_end, paddr = __pa(vstart);
  814. pgd_t *pgd = pgd_offset_k(vstart);
  815. pud_t *pud;
  816. pmd_t *pmd;
  817. pte_t *pte;
  818. pud = pud_offset(pgd, vstart);
  819. if (pud_none(*pud)) {
  820. pmd_t *new;
  821. new = __alloc_bootmem(PAGE_SIZE, PAGE_SIZE, PAGE_SIZE);
  822. alloc_bytes += PAGE_SIZE;
  823. pud_populate(&init_mm, pud, new);
  824. }
  825. pmd = pmd_offset(pud, vstart);
  826. if (!pmd_present(*pmd)) {
  827. pte_t *new;
  828. new = __alloc_bootmem(PAGE_SIZE, PAGE_SIZE, PAGE_SIZE);
  829. alloc_bytes += PAGE_SIZE;
  830. pmd_populate_kernel(&init_mm, pmd, new);
  831. }
  832. pte = pte_offset_kernel(pmd, vstart);
  833. this_end = (vstart + PMD_SIZE) & PMD_MASK;
  834. if (this_end > vend)
  835. this_end = vend;
  836. while (vstart < this_end) {
  837. pte_val(*pte) = (paddr | pgprot_val(prot));
  838. vstart += PAGE_SIZE;
  839. paddr += PAGE_SIZE;
  840. pte++;
  841. }
  842. }
  843. return alloc_bytes;
  844. }
  845. static struct linux_prom64_registers pall[MAX_BANKS] __initdata;
  846. static int pall_ents __initdata;
  847. extern unsigned int kvmap_linear_patch[1];
  848. static void __init kernel_physical_mapping_init(void)
  849. {
  850. unsigned long i, mem_alloced = 0UL;
  851. read_obp_memory("reg", &pall[0], &pall_ents);
  852. for (i = 0; i < pall_ents; i++) {
  853. unsigned long phys_start, phys_end;
  854. phys_start = pall[i].phys_addr;
  855. phys_end = phys_start + pall[i].reg_size;
  856. mem_alloced += kernel_map_range(phys_start, phys_end,
  857. PAGE_KERNEL);
  858. }
  859. printk("Allocated %ld bytes for kernel page tables.\n",
  860. mem_alloced);
  861. kvmap_linear_patch[0] = 0x01000000; /* nop */
  862. flushi(&kvmap_linear_patch[0]);
  863. __flush_tlb_all();
  864. }
  865. void kernel_map_pages(struct page *page, int numpages, int enable)
  866. {
  867. unsigned long phys_start = page_to_pfn(page) << PAGE_SHIFT;
  868. unsigned long phys_end = phys_start + (numpages * PAGE_SIZE);
  869. kernel_map_range(phys_start, phys_end,
  870. (enable ? PAGE_KERNEL : __pgprot(0)));
  871. flush_tsb_kernel_range(PAGE_OFFSET + phys_start,
  872. PAGE_OFFSET + phys_end);
  873. /* we should perform an IPI and flush all tlbs,
  874. * but that can deadlock->flush only current cpu.
  875. */
  876. __flush_tlb_kernel_range(PAGE_OFFSET + phys_start,
  877. PAGE_OFFSET + phys_end);
  878. }
  879. #endif
  880. unsigned long __init find_ecache_flush_span(unsigned long size)
  881. {
  882. int i;
  883. for (i = 0; i < pavail_ents; i++) {
  884. if (pavail[i].reg_size >= size)
  885. return pavail[i].phys_addr;
  886. }
  887. return ~0UL;
  888. }
  889. /* paging_init() sets up the page tables */
  890. extern void cheetah_ecache_flush_init(void);
  891. static unsigned long last_valid_pfn;
  892. pgd_t swapper_pg_dir[2048];
  893. void __init paging_init(void)
  894. {
  895. unsigned long end_pfn, pages_avail, shift;
  896. unsigned long real_end, i;
  897. /* Find available physical memory... */
  898. read_obp_memory("available", &pavail[0], &pavail_ents);
  899. phys_base = 0xffffffffffffffffUL;
  900. for (i = 0; i < pavail_ents; i++)
  901. phys_base = min(phys_base, pavail[i].phys_addr);
  902. pfn_base = phys_base >> PAGE_SHIFT;
  903. kern_base = (prom_boot_mapping_phys_low >> 22UL) << 22UL;
  904. kern_size = (unsigned long)&_end - (unsigned long)KERNBASE;
  905. set_bit(0, mmu_context_bmap);
  906. shift = kern_base + PAGE_OFFSET - ((unsigned long)KERNBASE);
  907. real_end = (unsigned long)_end;
  908. if ((real_end > ((unsigned long)KERNBASE + 0x400000)))
  909. bigkernel = 1;
  910. if ((real_end > ((unsigned long)KERNBASE + 0x800000))) {
  911. prom_printf("paging_init: Kernel > 8MB, too large.\n");
  912. prom_halt();
  913. }
  914. /* Set kernel pgd to upper alias so physical page computations
  915. * work.
  916. */
  917. init_mm.pgd += ((shift) / (sizeof(pgd_t)));
  918. memset(swapper_low_pmd_dir, 0, sizeof(swapper_low_pmd_dir));
  919. /* Now can init the kernel/bad page tables. */
  920. pud_set(pud_offset(&swapper_pg_dir[0], 0),
  921. swapper_low_pmd_dir + (shift / sizeof(pgd_t)));
  922. inherit_prom_mappings();
  923. /* Ok, we can use our TLB miss and window trap handlers safely. */
  924. setup_tba();
  925. __flush_tlb_all();
  926. /* Setup bootmem... */
  927. pages_avail = 0;
  928. last_valid_pfn = end_pfn = bootmem_init(&pages_avail);
  929. #ifdef CONFIG_DEBUG_PAGEALLOC
  930. kernel_physical_mapping_init();
  931. #endif
  932. {
  933. unsigned long zones_size[MAX_NR_ZONES];
  934. unsigned long zholes_size[MAX_NR_ZONES];
  935. unsigned long npages;
  936. int znum;
  937. for (znum = 0; znum < MAX_NR_ZONES; znum++)
  938. zones_size[znum] = zholes_size[znum] = 0;
  939. npages = end_pfn - pfn_base;
  940. zones_size[ZONE_DMA] = npages;
  941. zholes_size[ZONE_DMA] = npages - pages_avail;
  942. free_area_init_node(0, &contig_page_data, zones_size,
  943. phys_base >> PAGE_SHIFT, zholes_size);
  944. }
  945. device_scan();
  946. }
  947. static void __init taint_real_pages(void)
  948. {
  949. int i;
  950. read_obp_memory("available", &pavail_rescan[0], &pavail_rescan_ents);
  951. /* Find changes discovered in the physmem available rescan and
  952. * reserve the lost portions in the bootmem maps.
  953. */
  954. for (i = 0; i < pavail_ents; i++) {
  955. unsigned long old_start, old_end;
  956. old_start = pavail[i].phys_addr;
  957. old_end = old_start +
  958. pavail[i].reg_size;
  959. while (old_start < old_end) {
  960. int n;
  961. for (n = 0; pavail_rescan_ents; n++) {
  962. unsigned long new_start, new_end;
  963. new_start = pavail_rescan[n].phys_addr;
  964. new_end = new_start +
  965. pavail_rescan[n].reg_size;
  966. if (new_start <= old_start &&
  967. new_end >= (old_start + PAGE_SIZE)) {
  968. set_bit(old_start >> 22,
  969. sparc64_valid_addr_bitmap);
  970. goto do_next_page;
  971. }
  972. }
  973. reserve_bootmem(old_start, PAGE_SIZE);
  974. do_next_page:
  975. old_start += PAGE_SIZE;
  976. }
  977. }
  978. }
  979. void __init mem_init(void)
  980. {
  981. unsigned long codepages, datapages, initpages;
  982. unsigned long addr, last;
  983. int i;
  984. i = last_valid_pfn >> ((22 - PAGE_SHIFT) + 6);
  985. i += 1;
  986. sparc64_valid_addr_bitmap = (unsigned long *) alloc_bootmem(i << 3);
  987. if (sparc64_valid_addr_bitmap == NULL) {
  988. prom_printf("mem_init: Cannot alloc valid_addr_bitmap.\n");
  989. prom_halt();
  990. }
  991. memset(sparc64_valid_addr_bitmap, 0, i << 3);
  992. addr = PAGE_OFFSET + kern_base;
  993. last = PAGE_ALIGN(kern_size) + addr;
  994. while (addr < last) {
  995. set_bit(__pa(addr) >> 22, sparc64_valid_addr_bitmap);
  996. addr += PAGE_SIZE;
  997. }
  998. taint_real_pages();
  999. max_mapnr = last_valid_pfn - pfn_base;
  1000. high_memory = __va(last_valid_pfn << PAGE_SHIFT);
  1001. #ifdef CONFIG_DEBUG_BOOTMEM
  1002. prom_printf("mem_init: Calling free_all_bootmem().\n");
  1003. #endif
  1004. totalram_pages = num_physpages = free_all_bootmem() - 1;
  1005. /*
  1006. * Set up the zero page, mark it reserved, so that page count
  1007. * is not manipulated when freeing the page from user ptes.
  1008. */
  1009. mem_map_zero = alloc_pages(GFP_KERNEL|__GFP_ZERO, 0);
  1010. if (mem_map_zero == NULL) {
  1011. prom_printf("paging_init: Cannot alloc zero page.\n");
  1012. prom_halt();
  1013. }
  1014. SetPageReserved(mem_map_zero);
  1015. codepages = (((unsigned long) _etext) - ((unsigned long) _start));
  1016. codepages = PAGE_ALIGN(codepages) >> PAGE_SHIFT;
  1017. datapages = (((unsigned long) _edata) - ((unsigned long) _etext));
  1018. datapages = PAGE_ALIGN(datapages) >> PAGE_SHIFT;
  1019. initpages = (((unsigned long) __init_end) - ((unsigned long) __init_begin));
  1020. initpages = PAGE_ALIGN(initpages) >> PAGE_SHIFT;
  1021. printk("Memory: %uk available (%ldk kernel code, %ldk data, %ldk init) [%016lx,%016lx]\n",
  1022. nr_free_pages() << (PAGE_SHIFT-10),
  1023. codepages << (PAGE_SHIFT-10),
  1024. datapages << (PAGE_SHIFT-10),
  1025. initpages << (PAGE_SHIFT-10),
  1026. PAGE_OFFSET, (last_valid_pfn << PAGE_SHIFT));
  1027. if (tlb_type == cheetah || tlb_type == cheetah_plus)
  1028. cheetah_ecache_flush_init();
  1029. }
  1030. void free_initmem(void)
  1031. {
  1032. unsigned long addr, initend;
  1033. /*
  1034. * The init section is aligned to 8k in vmlinux.lds. Page align for >8k pagesizes.
  1035. */
  1036. addr = PAGE_ALIGN((unsigned long)(__init_begin));
  1037. initend = (unsigned long)(__init_end) & PAGE_MASK;
  1038. for (; addr < initend; addr += PAGE_SIZE) {
  1039. unsigned long page;
  1040. struct page *p;
  1041. page = (addr +
  1042. ((unsigned long) __va(kern_base)) -
  1043. ((unsigned long) KERNBASE));
  1044. memset((void *)addr, 0xcc, PAGE_SIZE);
  1045. p = virt_to_page(page);
  1046. ClearPageReserved(p);
  1047. set_page_count(p, 1);
  1048. __free_page(p);
  1049. num_physpages++;
  1050. totalram_pages++;
  1051. }
  1052. }
  1053. #ifdef CONFIG_BLK_DEV_INITRD
  1054. void free_initrd_mem(unsigned long start, unsigned long end)
  1055. {
  1056. if (start < end)
  1057. printk ("Freeing initrd memory: %ldk freed\n", (end - start) >> 10);
  1058. for (; start < end; start += PAGE_SIZE) {
  1059. struct page *p = virt_to_page(start);
  1060. ClearPageReserved(p);
  1061. set_page_count(p, 1);
  1062. __free_page(p);
  1063. num_physpages++;
  1064. totalram_pages++;
  1065. }
  1066. }
  1067. #endif