init.c 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747
  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. int bigkernel = 0;
  115. /* XXX Tune this... */
  116. #define PGT_CACHE_LOW 25
  117. #define PGT_CACHE_HIGH 50
  118. void check_pgt_cache(void)
  119. {
  120. preempt_disable();
  121. if (pgtable_cache_size > PGT_CACHE_HIGH) {
  122. do {
  123. if (pgd_quicklist)
  124. free_pgd_slow(get_pgd_fast());
  125. if (pte_quicklist[0])
  126. free_pte_slow(pte_alloc_one_fast(NULL, 0));
  127. if (pte_quicklist[1])
  128. free_pte_slow(pte_alloc_one_fast(NULL, 1 << (PAGE_SHIFT + 10)));
  129. } while (pgtable_cache_size > PGT_CACHE_LOW);
  130. }
  131. preempt_enable();
  132. }
  133. #ifdef CONFIG_DEBUG_DCFLUSH
  134. atomic_t dcpage_flushes = ATOMIC_INIT(0);
  135. #ifdef CONFIG_SMP
  136. atomic_t dcpage_flushes_xcall = ATOMIC_INIT(0);
  137. #endif
  138. #endif
  139. __inline__ void flush_dcache_page_impl(struct page *page)
  140. {
  141. #ifdef CONFIG_DEBUG_DCFLUSH
  142. atomic_inc(&dcpage_flushes);
  143. #endif
  144. #ifdef DCACHE_ALIASING_POSSIBLE
  145. __flush_dcache_page(page_address(page),
  146. ((tlb_type == spitfire) &&
  147. page_mapping(page) != NULL));
  148. #else
  149. if (page_mapping(page) != NULL &&
  150. tlb_type == spitfire)
  151. __flush_icache_page(__pa(page_address(page)));
  152. #endif
  153. }
  154. #define PG_dcache_dirty PG_arch_1
  155. #define PG_dcache_cpu_shift 24
  156. #define PG_dcache_cpu_mask (256 - 1)
  157. #if NR_CPUS > 256
  158. #error D-cache dirty tracking and thread_info->cpu need fixing for > 256 cpus
  159. #endif
  160. #define dcache_dirty_cpu(page) \
  161. (((page)->flags >> PG_dcache_cpu_shift) & PG_dcache_cpu_mask)
  162. static __inline__ void set_dcache_dirty(struct page *page, int this_cpu)
  163. {
  164. unsigned long mask = this_cpu;
  165. unsigned long non_cpu_bits;
  166. non_cpu_bits = ~(PG_dcache_cpu_mask << PG_dcache_cpu_shift);
  167. mask = (mask << PG_dcache_cpu_shift) | (1UL << PG_dcache_dirty);
  168. __asm__ __volatile__("1:\n\t"
  169. "ldx [%2], %%g7\n\t"
  170. "and %%g7, %1, %%g1\n\t"
  171. "or %%g1, %0, %%g1\n\t"
  172. "casx [%2], %%g7, %%g1\n\t"
  173. "cmp %%g7, %%g1\n\t"
  174. "membar #StoreLoad | #StoreStore\n\t"
  175. "bne,pn %%xcc, 1b\n\t"
  176. " nop"
  177. : /* no outputs */
  178. : "r" (mask), "r" (non_cpu_bits), "r" (&page->flags)
  179. : "g1", "g7");
  180. }
  181. static __inline__ void clear_dcache_dirty_cpu(struct page *page, unsigned long cpu)
  182. {
  183. unsigned long mask = (1UL << PG_dcache_dirty);
  184. __asm__ __volatile__("! test_and_clear_dcache_dirty\n"
  185. "1:\n\t"
  186. "ldx [%2], %%g7\n\t"
  187. "srlx %%g7, %4, %%g1\n\t"
  188. "and %%g1, %3, %%g1\n\t"
  189. "cmp %%g1, %0\n\t"
  190. "bne,pn %%icc, 2f\n\t"
  191. " andn %%g7, %1, %%g1\n\t"
  192. "casx [%2], %%g7, %%g1\n\t"
  193. "cmp %%g7, %%g1\n\t"
  194. "membar #StoreLoad | #StoreStore\n\t"
  195. "bne,pn %%xcc, 1b\n\t"
  196. " nop\n"
  197. "2:"
  198. : /* no outputs */
  199. : "r" (cpu), "r" (mask), "r" (&page->flags),
  200. "i" (PG_dcache_cpu_mask),
  201. "i" (PG_dcache_cpu_shift)
  202. : "g1", "g7");
  203. }
  204. void update_mmu_cache(struct vm_area_struct *vma, unsigned long address, pte_t pte)
  205. {
  206. struct page *page;
  207. unsigned long pfn;
  208. unsigned long pg_flags;
  209. pfn = pte_pfn(pte);
  210. if (pfn_valid(pfn) &&
  211. (page = pfn_to_page(pfn), page_mapping(page)) &&
  212. ((pg_flags = page->flags) & (1UL << PG_dcache_dirty))) {
  213. int cpu = ((pg_flags >> PG_dcache_cpu_shift) &
  214. PG_dcache_cpu_mask);
  215. int this_cpu = get_cpu();
  216. /* This is just to optimize away some function calls
  217. * in the SMP case.
  218. */
  219. if (cpu == this_cpu)
  220. flush_dcache_page_impl(page);
  221. else
  222. smp_flush_dcache_page_impl(page, cpu);
  223. clear_dcache_dirty_cpu(page, cpu);
  224. put_cpu();
  225. }
  226. }
  227. void flush_dcache_page(struct page *page)
  228. {
  229. struct address_space *mapping;
  230. int this_cpu;
  231. /* Do not bother with the expensive D-cache flush if it
  232. * is merely the zero page. The 'bigcore' testcase in GDB
  233. * causes this case to run millions of times.
  234. */
  235. if (page == ZERO_PAGE(0))
  236. return;
  237. this_cpu = get_cpu();
  238. mapping = page_mapping(page);
  239. if (mapping && !mapping_mapped(mapping)) {
  240. int dirty = test_bit(PG_dcache_dirty, &page->flags);
  241. if (dirty) {
  242. int dirty_cpu = dcache_dirty_cpu(page);
  243. if (dirty_cpu == this_cpu)
  244. goto out;
  245. smp_flush_dcache_page_impl(page, dirty_cpu);
  246. }
  247. set_dcache_dirty(page, this_cpu);
  248. } else {
  249. /* We could delay the flush for the !page_mapping
  250. * case too. But that case is for exec env/arg
  251. * pages and those are %99 certainly going to get
  252. * faulted into the tlb (and thus flushed) anyways.
  253. */
  254. flush_dcache_page_impl(page);
  255. }
  256. out:
  257. put_cpu();
  258. }
  259. void __kprobes flush_icache_range(unsigned long start, unsigned long end)
  260. {
  261. /* Cheetah has coherent I-cache. */
  262. if (tlb_type == spitfire) {
  263. unsigned long kaddr;
  264. for (kaddr = start; kaddr < end; kaddr += PAGE_SIZE)
  265. __flush_icache_page(__get_phys(kaddr));
  266. }
  267. }
  268. unsigned long page_to_pfn(struct page *page)
  269. {
  270. return (unsigned long) ((page - mem_map) + pfn_base);
  271. }
  272. struct page *pfn_to_page(unsigned long pfn)
  273. {
  274. return (mem_map + (pfn - pfn_base));
  275. }
  276. void show_mem(void)
  277. {
  278. printk("Mem-info:\n");
  279. show_free_areas();
  280. printk("Free swap: %6ldkB\n",
  281. nr_swap_pages << (PAGE_SHIFT-10));
  282. printk("%ld pages of RAM\n", num_physpages);
  283. printk("%d free pages\n", nr_free_pages());
  284. printk("%d pages in page table cache\n",pgtable_cache_size);
  285. }
  286. void mmu_info(struct seq_file *m)
  287. {
  288. if (tlb_type == cheetah)
  289. seq_printf(m, "MMU Type\t: Cheetah\n");
  290. else if (tlb_type == cheetah_plus)
  291. seq_printf(m, "MMU Type\t: Cheetah+\n");
  292. else if (tlb_type == spitfire)
  293. seq_printf(m, "MMU Type\t: Spitfire\n");
  294. else
  295. seq_printf(m, "MMU Type\t: ???\n");
  296. #ifdef CONFIG_DEBUG_DCFLUSH
  297. seq_printf(m, "DCPageFlushes\t: %d\n",
  298. atomic_read(&dcpage_flushes));
  299. #ifdef CONFIG_SMP
  300. seq_printf(m, "DCPageFlushesXC\t: %d\n",
  301. atomic_read(&dcpage_flushes_xcall));
  302. #endif /* CONFIG_SMP */
  303. #endif /* CONFIG_DEBUG_DCFLUSH */
  304. }
  305. struct linux_prom_translation {
  306. unsigned long virt;
  307. unsigned long size;
  308. unsigned long data;
  309. };
  310. static struct linux_prom_translation prom_trans[512] __initdata;
  311. extern unsigned long prom_boot_page;
  312. extern void prom_remap(unsigned long physpage, unsigned long virtpage, int mmu_ihandle);
  313. extern int prom_get_mmu_ihandle(void);
  314. extern void register_prom_callbacks(void);
  315. /* Exported for SMP bootup purposes. */
  316. unsigned long kern_locked_tte_data;
  317. /* Exported for kernel TLB miss handling in ktlb.S */
  318. unsigned long prom_pmd_phys __read_mostly;
  319. unsigned int swapper_pgd_zero __read_mostly;
  320. /* Allocate power-of-2 aligned chunks from the end of the
  321. * kernel image. Return physical address.
  322. */
  323. static inline unsigned long early_alloc_phys(unsigned long size)
  324. {
  325. unsigned long base;
  326. BUILD_BUG_ON(size & (size - 1));
  327. kern_size = (kern_size + (size - 1)) & ~(size - 1);
  328. base = kern_base + kern_size;
  329. kern_size += size;
  330. return base;
  331. }
  332. static inline unsigned long load_phys32(unsigned long pa)
  333. {
  334. unsigned long val;
  335. __asm__ __volatile__("lduwa [%1] %2, %0"
  336. : "=&r" (val)
  337. : "r" (pa), "i" (ASI_PHYS_USE_EC));
  338. return val;
  339. }
  340. static inline unsigned long load_phys64(unsigned long pa)
  341. {
  342. unsigned long val;
  343. __asm__ __volatile__("ldxa [%1] %2, %0"
  344. : "=&r" (val)
  345. : "r" (pa), "i" (ASI_PHYS_USE_EC));
  346. return val;
  347. }
  348. static inline void store_phys32(unsigned long pa, unsigned long val)
  349. {
  350. __asm__ __volatile__("stwa %0, [%1] %2"
  351. : /* no outputs */
  352. : "r" (val), "r" (pa), "i" (ASI_PHYS_USE_EC));
  353. }
  354. static inline void store_phys64(unsigned long pa, unsigned long val)
  355. {
  356. __asm__ __volatile__("stxa %0, [%1] %2"
  357. : /* no outputs */
  358. : "r" (val), "r" (pa), "i" (ASI_PHYS_USE_EC));
  359. }
  360. #define BASE_PAGE_SIZE 8192
  361. /*
  362. * Translate PROM's mapping we capture at boot time into physical address.
  363. * The second parameter is only set from prom_callback() invocations.
  364. */
  365. unsigned long prom_virt_to_phys(unsigned long promva, int *error)
  366. {
  367. unsigned long pmd_phys = (prom_pmd_phys +
  368. ((promva >> 23) & 0x7ff) * sizeof(pmd_t));
  369. unsigned long pte_phys;
  370. pmd_t pmd_ent;
  371. pte_t pte_ent;
  372. unsigned long base;
  373. pmd_val(pmd_ent) = load_phys32(pmd_phys);
  374. if (pmd_none(pmd_ent)) {
  375. if (error)
  376. *error = 1;
  377. return 0;
  378. }
  379. pte_phys = (unsigned long)pmd_val(pmd_ent) << 11UL;
  380. pte_phys += ((promva >> 13) & 0x3ff) * sizeof(pte_t);
  381. pte_val(pte_ent) = load_phys64(pte_phys);
  382. if (!pte_present(pte_ent)) {
  383. if (error)
  384. *error = 1;
  385. return 0;
  386. }
  387. if (error) {
  388. *error = 0;
  389. return pte_val(pte_ent);
  390. }
  391. base = pte_val(pte_ent) & _PAGE_PADDR;
  392. return (base + (promva & (BASE_PAGE_SIZE - 1)));
  393. }
  394. /* The obp translations are saved based on 8k pagesize, since obp can
  395. * use a mixture of pagesizes. Misses to the LOW_OBP_ADDRESS ->
  396. * HI_OBP_ADDRESS range are handled in entry.S and do not use the vpte
  397. * scheme (also, see rant in inherit_locked_prom_mappings()).
  398. */
  399. static void __init build_obp_range(unsigned long start, unsigned long end, unsigned long data)
  400. {
  401. unsigned long vaddr;
  402. for (vaddr = start; vaddr < end; vaddr += BASE_PAGE_SIZE) {
  403. unsigned long val, pte_phys, pmd_phys;
  404. pmd_t pmd_ent;
  405. int i;
  406. pmd_phys = (prom_pmd_phys +
  407. (((vaddr >> 23) & 0x7ff) * sizeof(pmd_t)));
  408. pmd_val(pmd_ent) = load_phys32(pmd_phys);
  409. if (pmd_none(pmd_ent)) {
  410. pte_phys = early_alloc_phys(BASE_PAGE_SIZE);
  411. for (i = 0; i < BASE_PAGE_SIZE / sizeof(pte_t); i++)
  412. store_phys64(pte_phys+i*sizeof(pte_t),0);
  413. pmd_val(pmd_ent) = pte_phys >> 11UL;
  414. store_phys32(pmd_phys, pmd_val(pmd_ent));
  415. }
  416. pte_phys = (unsigned long)pmd_val(pmd_ent) << 11UL;
  417. pte_phys += (((vaddr >> 13) & 0x3ff) * sizeof(pte_t));
  418. val = data;
  419. /* Clear diag TTE bits. */
  420. if (tlb_type == spitfire)
  421. val &= ~0x0003fe0000000000UL;
  422. store_phys64(pte_phys, val | _PAGE_MODIFIED);
  423. data += BASE_PAGE_SIZE;
  424. }
  425. }
  426. static inline int in_obp_range(unsigned long vaddr)
  427. {
  428. return (vaddr >= LOW_OBP_ADDRESS &&
  429. vaddr < HI_OBP_ADDRESS);
  430. }
  431. #define OBP_PMD_SIZE 2048
  432. static void __init build_obp_pgtable(int prom_trans_ents)
  433. {
  434. unsigned long i;
  435. prom_pmd_phys = early_alloc_phys(OBP_PMD_SIZE);
  436. for (i = 0; i < OBP_PMD_SIZE; i += 4)
  437. store_phys32(prom_pmd_phys + i, 0);
  438. for (i = 0; i < prom_trans_ents; i++) {
  439. unsigned long start, end;
  440. if (!in_obp_range(prom_trans[i].virt))
  441. continue;
  442. start = prom_trans[i].virt;
  443. end = start + prom_trans[i].size;
  444. if (end > HI_OBP_ADDRESS)
  445. end = HI_OBP_ADDRESS;
  446. build_obp_range(start, end, prom_trans[i].data);
  447. }
  448. }
  449. /* Read OBP translations property into 'prom_trans[]'.
  450. * Return the number of entries.
  451. */
  452. static int __init read_obp_translations(void)
  453. {
  454. int n, node;
  455. node = prom_finddevice("/virtual-memory");
  456. n = prom_getproplen(node, "translations");
  457. if (unlikely(n == 0 || n == -1)) {
  458. prom_printf("prom_mappings: Couldn't get size.\n");
  459. prom_halt();
  460. }
  461. if (unlikely(n > sizeof(prom_trans))) {
  462. prom_printf("prom_mappings: Size %Zd is too big.\n", n);
  463. prom_halt();
  464. }
  465. if ((n = prom_getproperty(node, "translations",
  466. (char *)&prom_trans[0],
  467. sizeof(prom_trans))) == -1) {
  468. prom_printf("prom_mappings: Couldn't get property.\n");
  469. prom_halt();
  470. }
  471. n = n / sizeof(struct linux_prom_translation);
  472. return n;
  473. }
  474. static void __init remap_kernel(void)
  475. {
  476. unsigned long phys_page, tte_vaddr, tte_data;
  477. int tlb_ent = sparc64_highest_locked_tlbent();
  478. tte_vaddr = (unsigned long) KERNBASE;
  479. phys_page = (prom_boot_mapping_phys_low >> 22UL) << 22UL;
  480. tte_data = (phys_page | (_PAGE_VALID | _PAGE_SZ4MB |
  481. _PAGE_CP | _PAGE_CV | _PAGE_P |
  482. _PAGE_L | _PAGE_W));
  483. kern_locked_tte_data = tte_data;
  484. /* Now lock us into the TLBs via OBP. */
  485. prom_dtlb_load(tlb_ent, tte_data, tte_vaddr);
  486. prom_itlb_load(tlb_ent, tte_data, tte_vaddr);
  487. if (bigkernel) {
  488. prom_dtlb_load(tlb_ent - 1,
  489. tte_data + 0x400000,
  490. tte_vaddr + 0x400000);
  491. prom_itlb_load(tlb_ent - 1,
  492. tte_data + 0x400000,
  493. tte_vaddr + 0x400000);
  494. }
  495. }
  496. static void __init inherit_prom_mappings(void)
  497. {
  498. int n;
  499. n = read_obp_translations();
  500. build_obp_pgtable(n);
  501. /* Now fixup OBP's idea about where we really are mapped. */
  502. prom_printf("Remapping the kernel... ");
  503. remap_kernel();
  504. prom_printf("done.\n");
  505. register_prom_callbacks();
  506. }
  507. /* The OBP specifications for sun4u mark 0xfffffffc00000000 and
  508. * upwards as reserved for use by the firmware (I wonder if this
  509. * will be the same on Cheetah...). We use this virtual address
  510. * range for the VPTE table mappings of the nucleus so we need
  511. * to zap them when we enter the PROM. -DaveM
  512. */
  513. static void __flush_nucleus_vptes(void)
  514. {
  515. unsigned long prom_reserved_base = 0xfffffffc00000000UL;
  516. int i;
  517. /* Only DTLB must be checked for VPTE entries. */
  518. if (tlb_type == spitfire) {
  519. for (i = 0; i < 63; i++) {
  520. unsigned long tag;
  521. /* Spitfire Errata #32 workaround */
  522. /* NOTE: Always runs on spitfire, so no cheetah+
  523. * page size encodings.
  524. */
  525. __asm__ __volatile__("stxa %0, [%1] %2\n\t"
  526. "flush %%g6"
  527. : /* No outputs */
  528. : "r" (0),
  529. "r" (PRIMARY_CONTEXT), "i" (ASI_DMMU));
  530. tag = spitfire_get_dtlb_tag(i);
  531. if (((tag & ~(PAGE_MASK)) == 0) &&
  532. ((tag & (PAGE_MASK)) >= prom_reserved_base)) {
  533. __asm__ __volatile__("stxa %%g0, [%0] %1\n\t"
  534. "membar #Sync"
  535. : /* no outputs */
  536. : "r" (TLB_TAG_ACCESS), "i" (ASI_DMMU));
  537. spitfire_put_dtlb_data(i, 0x0UL);
  538. }
  539. }
  540. } else if (tlb_type == cheetah || tlb_type == cheetah_plus) {
  541. for (i = 0; i < 512; i++) {
  542. unsigned long tag = cheetah_get_dtlb_tag(i, 2);
  543. if ((tag & ~PAGE_MASK) == 0 &&
  544. (tag & PAGE_MASK) >= prom_reserved_base) {
  545. __asm__ __volatile__("stxa %%g0, [%0] %1\n\t"
  546. "membar #Sync"
  547. : /* no outputs */
  548. : "r" (TLB_TAG_ACCESS), "i" (ASI_DMMU));
  549. cheetah_put_dtlb_data(i, 0x0UL, 2);
  550. }
  551. if (tlb_type != cheetah_plus)
  552. continue;
  553. tag = cheetah_get_dtlb_tag(i, 3);
  554. if ((tag & ~PAGE_MASK) == 0 &&
  555. (tag & PAGE_MASK) >= prom_reserved_base) {
  556. __asm__ __volatile__("stxa %%g0, [%0] %1\n\t"
  557. "membar #Sync"
  558. : /* no outputs */
  559. : "r" (TLB_TAG_ACCESS), "i" (ASI_DMMU));
  560. cheetah_put_dtlb_data(i, 0x0UL, 3);
  561. }
  562. }
  563. } else {
  564. /* Implement me :-) */
  565. BUG();
  566. }
  567. }
  568. static int prom_ditlb_set;
  569. struct prom_tlb_entry {
  570. int tlb_ent;
  571. unsigned long tlb_tag;
  572. unsigned long tlb_data;
  573. };
  574. struct prom_tlb_entry prom_itlb[16], prom_dtlb[16];
  575. void prom_world(int enter)
  576. {
  577. unsigned long pstate;
  578. int i;
  579. if (!enter)
  580. set_fs((mm_segment_t) { get_thread_current_ds() });
  581. if (!prom_ditlb_set)
  582. return;
  583. /* Make sure the following runs atomically. */
  584. __asm__ __volatile__("flushw\n\t"
  585. "rdpr %%pstate, %0\n\t"
  586. "wrpr %0, %1, %%pstate"
  587. : "=r" (pstate)
  588. : "i" (PSTATE_IE));
  589. if (enter) {
  590. /* Kick out nucleus VPTEs. */
  591. __flush_nucleus_vptes();
  592. /* Install PROM world. */
  593. for (i = 0; i < 16; i++) {
  594. if (prom_dtlb[i].tlb_ent != -1) {
  595. __asm__ __volatile__("stxa %0, [%1] %2\n\t"
  596. "membar #Sync"
  597. : : "r" (prom_dtlb[i].tlb_tag), "r" (TLB_TAG_ACCESS),
  598. "i" (ASI_DMMU));
  599. if (tlb_type == spitfire)
  600. spitfire_put_dtlb_data(prom_dtlb[i].tlb_ent,
  601. prom_dtlb[i].tlb_data);
  602. else if (tlb_type == cheetah || tlb_type == cheetah_plus)
  603. cheetah_put_ldtlb_data(prom_dtlb[i].tlb_ent,
  604. prom_dtlb[i].tlb_data);
  605. }
  606. if (prom_itlb[i].tlb_ent != -1) {
  607. __asm__ __volatile__("stxa %0, [%1] %2\n\t"
  608. "membar #Sync"
  609. : : "r" (prom_itlb[i].tlb_tag),
  610. "r" (TLB_TAG_ACCESS),
  611. "i" (ASI_IMMU));
  612. if (tlb_type == spitfire)
  613. spitfire_put_itlb_data(prom_itlb[i].tlb_ent,
  614. prom_itlb[i].tlb_data);
  615. else if (tlb_type == cheetah || tlb_type == cheetah_plus)
  616. cheetah_put_litlb_data(prom_itlb[i].tlb_ent,
  617. prom_itlb[i].tlb_data);
  618. }
  619. }
  620. } else {
  621. for (i = 0; i < 16; i++) {
  622. if (prom_dtlb[i].tlb_ent != -1) {
  623. __asm__ __volatile__("stxa %%g0, [%0] %1\n\t"
  624. "membar #Sync"
  625. : : "r" (TLB_TAG_ACCESS), "i" (ASI_DMMU));
  626. if (tlb_type == spitfire)
  627. spitfire_put_dtlb_data(prom_dtlb[i].tlb_ent, 0x0UL);
  628. else
  629. cheetah_put_ldtlb_data(prom_dtlb[i].tlb_ent, 0x0UL);
  630. }
  631. if (prom_itlb[i].tlb_ent != -1) {
  632. __asm__ __volatile__("stxa %%g0, [%0] %1\n\t"
  633. "membar #Sync"
  634. : : "r" (TLB_TAG_ACCESS),
  635. "i" (ASI_IMMU));
  636. if (tlb_type == spitfire)
  637. spitfire_put_itlb_data(prom_itlb[i].tlb_ent, 0x0UL);
  638. else
  639. cheetah_put_litlb_data(prom_itlb[i].tlb_ent, 0x0UL);
  640. }
  641. }
  642. }
  643. __asm__ __volatile__("wrpr %0, 0, %%pstate"
  644. : : "r" (pstate));
  645. }
  646. void inherit_locked_prom_mappings(int save_p)
  647. {
  648. int i;
  649. int dtlb_seen = 0;
  650. int itlb_seen = 0;
  651. /* Fucking losing PROM has more mappings in the TLB, but
  652. * it (conveniently) fails to mention any of these in the
  653. * translations property. The only ones that matter are
  654. * the locked PROM tlb entries, so we impose the following
  655. * irrecovable rule on the PROM, it is allowed 8 locked
  656. * entries in the ITLB and 8 in the DTLB.
  657. *
  658. * Supposedly the upper 16GB of the address space is
  659. * reserved for OBP, BUT I WISH THIS WAS DOCUMENTED
  660. * SOMEWHERE!!!!!!!!!!!!!!!!! Furthermore the entire interface
  661. * used between the client program and the firmware on sun5
  662. * systems to coordinate mmu mappings is also COMPLETELY
  663. * UNDOCUMENTED!!!!!! Thanks S(t)un!
  664. */
  665. if (save_p) {
  666. for (i = 0; i < 16; i++) {
  667. prom_itlb[i].tlb_ent = -1;
  668. prom_dtlb[i].tlb_ent = -1;
  669. }
  670. }
  671. if (tlb_type == spitfire) {
  672. int high = SPITFIRE_HIGHEST_LOCKED_TLBENT - bigkernel;
  673. for (i = 0; i < high; i++) {
  674. unsigned long data;
  675. /* Spitfire Errata #32 workaround */
  676. /* NOTE: Always runs on spitfire, so no cheetah+
  677. * page size encodings.
  678. */
  679. __asm__ __volatile__("stxa %0, [%1] %2\n\t"
  680. "flush %%g6"
  681. : /* No outputs */
  682. : "r" (0),
  683. "r" (PRIMARY_CONTEXT), "i" (ASI_DMMU));
  684. data = spitfire_get_dtlb_data(i);
  685. if ((data & (_PAGE_L|_PAGE_VALID)) == (_PAGE_L|_PAGE_VALID)) {
  686. unsigned long tag;
  687. /* Spitfire Errata #32 workaround */
  688. /* NOTE: Always runs on spitfire, so no
  689. * cheetah+ page size encodings.
  690. */
  691. __asm__ __volatile__("stxa %0, [%1] %2\n\t"
  692. "flush %%g6"
  693. : /* No outputs */
  694. : "r" (0),
  695. "r" (PRIMARY_CONTEXT), "i" (ASI_DMMU));
  696. tag = spitfire_get_dtlb_tag(i);
  697. if (save_p) {
  698. prom_dtlb[dtlb_seen].tlb_ent = i;
  699. prom_dtlb[dtlb_seen].tlb_tag = tag;
  700. prom_dtlb[dtlb_seen].tlb_data = data;
  701. }
  702. __asm__ __volatile__("stxa %%g0, [%0] %1\n\t"
  703. "membar #Sync"
  704. : : "r" (TLB_TAG_ACCESS), "i" (ASI_DMMU));
  705. spitfire_put_dtlb_data(i, 0x0UL);
  706. dtlb_seen++;
  707. if (dtlb_seen > 15)
  708. break;
  709. }
  710. }
  711. for (i = 0; i < high; i++) {
  712. unsigned long data;
  713. /* Spitfire Errata #32 workaround */
  714. /* NOTE: Always runs on spitfire, so no
  715. * cheetah+ page size encodings.
  716. */
  717. __asm__ __volatile__("stxa %0, [%1] %2\n\t"
  718. "flush %%g6"
  719. : /* No outputs */
  720. : "r" (0),
  721. "r" (PRIMARY_CONTEXT), "i" (ASI_DMMU));
  722. data = spitfire_get_itlb_data(i);
  723. if ((data & (_PAGE_L|_PAGE_VALID)) == (_PAGE_L|_PAGE_VALID)) {
  724. unsigned long tag;
  725. /* Spitfire Errata #32 workaround */
  726. /* NOTE: Always runs on spitfire, so no
  727. * cheetah+ page size encodings.
  728. */
  729. __asm__ __volatile__("stxa %0, [%1] %2\n\t"
  730. "flush %%g6"
  731. : /* No outputs */
  732. : "r" (0),
  733. "r" (PRIMARY_CONTEXT), "i" (ASI_DMMU));
  734. tag = spitfire_get_itlb_tag(i);
  735. if (save_p) {
  736. prom_itlb[itlb_seen].tlb_ent = i;
  737. prom_itlb[itlb_seen].tlb_tag = tag;
  738. prom_itlb[itlb_seen].tlb_data = data;
  739. }
  740. __asm__ __volatile__("stxa %%g0, [%0] %1\n\t"
  741. "membar #Sync"
  742. : : "r" (TLB_TAG_ACCESS), "i" (ASI_IMMU));
  743. spitfire_put_itlb_data(i, 0x0UL);
  744. itlb_seen++;
  745. if (itlb_seen > 15)
  746. break;
  747. }
  748. }
  749. } else if (tlb_type == cheetah || tlb_type == cheetah_plus) {
  750. int high = CHEETAH_HIGHEST_LOCKED_TLBENT - bigkernel;
  751. for (i = 0; i < high; i++) {
  752. unsigned long data;
  753. data = cheetah_get_ldtlb_data(i);
  754. if ((data & (_PAGE_L|_PAGE_VALID)) == (_PAGE_L|_PAGE_VALID)) {
  755. unsigned long tag;
  756. tag = cheetah_get_ldtlb_tag(i);
  757. if (save_p) {
  758. prom_dtlb[dtlb_seen].tlb_ent = i;
  759. prom_dtlb[dtlb_seen].tlb_tag = tag;
  760. prom_dtlb[dtlb_seen].tlb_data = data;
  761. }
  762. __asm__ __volatile__("stxa %%g0, [%0] %1\n\t"
  763. "membar #Sync"
  764. : : "r" (TLB_TAG_ACCESS), "i" (ASI_DMMU));
  765. cheetah_put_ldtlb_data(i, 0x0UL);
  766. dtlb_seen++;
  767. if (dtlb_seen > 15)
  768. break;
  769. }
  770. }
  771. for (i = 0; i < high; i++) {
  772. unsigned long data;
  773. data = cheetah_get_litlb_data(i);
  774. if ((data & (_PAGE_L|_PAGE_VALID)) == (_PAGE_L|_PAGE_VALID)) {
  775. unsigned long tag;
  776. tag = cheetah_get_litlb_tag(i);
  777. if (save_p) {
  778. prom_itlb[itlb_seen].tlb_ent = i;
  779. prom_itlb[itlb_seen].tlb_tag = tag;
  780. prom_itlb[itlb_seen].tlb_data = data;
  781. }
  782. __asm__ __volatile__("stxa %%g0, [%0] %1\n\t"
  783. "membar #Sync"
  784. : : "r" (TLB_TAG_ACCESS), "i" (ASI_IMMU));
  785. cheetah_put_litlb_data(i, 0x0UL);
  786. itlb_seen++;
  787. if (itlb_seen > 15)
  788. break;
  789. }
  790. }
  791. } else {
  792. /* Implement me :-) */
  793. BUG();
  794. }
  795. if (save_p)
  796. prom_ditlb_set = 1;
  797. }
  798. /* Give PROM back his world, done during reboots... */
  799. void prom_reload_locked(void)
  800. {
  801. int i;
  802. for (i = 0; i < 16; i++) {
  803. if (prom_dtlb[i].tlb_ent != -1) {
  804. __asm__ __volatile__("stxa %0, [%1] %2\n\t"
  805. "membar #Sync"
  806. : : "r" (prom_dtlb[i].tlb_tag), "r" (TLB_TAG_ACCESS),
  807. "i" (ASI_DMMU));
  808. if (tlb_type == spitfire)
  809. spitfire_put_dtlb_data(prom_dtlb[i].tlb_ent,
  810. prom_dtlb[i].tlb_data);
  811. else if (tlb_type == cheetah || tlb_type == cheetah_plus)
  812. cheetah_put_ldtlb_data(prom_dtlb[i].tlb_ent,
  813. prom_dtlb[i].tlb_data);
  814. }
  815. if (prom_itlb[i].tlb_ent != -1) {
  816. __asm__ __volatile__("stxa %0, [%1] %2\n\t"
  817. "membar #Sync"
  818. : : "r" (prom_itlb[i].tlb_tag),
  819. "r" (TLB_TAG_ACCESS),
  820. "i" (ASI_IMMU));
  821. if (tlb_type == spitfire)
  822. spitfire_put_itlb_data(prom_itlb[i].tlb_ent,
  823. prom_itlb[i].tlb_data);
  824. else
  825. cheetah_put_litlb_data(prom_itlb[i].tlb_ent,
  826. prom_itlb[i].tlb_data);
  827. }
  828. }
  829. }
  830. #ifdef DCACHE_ALIASING_POSSIBLE
  831. void __flush_dcache_range(unsigned long start, unsigned long end)
  832. {
  833. unsigned long va;
  834. if (tlb_type == spitfire) {
  835. int n = 0;
  836. for (va = start; va < end; va += 32) {
  837. spitfire_put_dcache_tag(va & 0x3fe0, 0x0);
  838. if (++n >= 512)
  839. break;
  840. }
  841. } else {
  842. start = __pa(start);
  843. end = __pa(end);
  844. for (va = start; va < end; va += 32)
  845. __asm__ __volatile__("stxa %%g0, [%0] %1\n\t"
  846. "membar #Sync"
  847. : /* no outputs */
  848. : "r" (va),
  849. "i" (ASI_DCACHE_INVALIDATE));
  850. }
  851. }
  852. #endif /* DCACHE_ALIASING_POSSIBLE */
  853. /* If not locked, zap it. */
  854. void __flush_tlb_all(void)
  855. {
  856. unsigned long pstate;
  857. int i;
  858. __asm__ __volatile__("flushw\n\t"
  859. "rdpr %%pstate, %0\n\t"
  860. "wrpr %0, %1, %%pstate"
  861. : "=r" (pstate)
  862. : "i" (PSTATE_IE));
  863. if (tlb_type == spitfire) {
  864. for (i = 0; i < 64; i++) {
  865. /* Spitfire Errata #32 workaround */
  866. /* NOTE: Always runs on spitfire, so no
  867. * cheetah+ page size encodings.
  868. */
  869. __asm__ __volatile__("stxa %0, [%1] %2\n\t"
  870. "flush %%g6"
  871. : /* No outputs */
  872. : "r" (0),
  873. "r" (PRIMARY_CONTEXT), "i" (ASI_DMMU));
  874. if (!(spitfire_get_dtlb_data(i) & _PAGE_L)) {
  875. __asm__ __volatile__("stxa %%g0, [%0] %1\n\t"
  876. "membar #Sync"
  877. : /* no outputs */
  878. : "r" (TLB_TAG_ACCESS), "i" (ASI_DMMU));
  879. spitfire_put_dtlb_data(i, 0x0UL);
  880. }
  881. /* Spitfire Errata #32 workaround */
  882. /* NOTE: Always runs on spitfire, so no
  883. * cheetah+ page size encodings.
  884. */
  885. __asm__ __volatile__("stxa %0, [%1] %2\n\t"
  886. "flush %%g6"
  887. : /* No outputs */
  888. : "r" (0),
  889. "r" (PRIMARY_CONTEXT), "i" (ASI_DMMU));
  890. if (!(spitfire_get_itlb_data(i) & _PAGE_L)) {
  891. __asm__ __volatile__("stxa %%g0, [%0] %1\n\t"
  892. "membar #Sync"
  893. : /* no outputs */
  894. : "r" (TLB_TAG_ACCESS), "i" (ASI_IMMU));
  895. spitfire_put_itlb_data(i, 0x0UL);
  896. }
  897. }
  898. } else if (tlb_type == cheetah || tlb_type == cheetah_plus) {
  899. cheetah_flush_dtlb_all();
  900. cheetah_flush_itlb_all();
  901. }
  902. __asm__ __volatile__("wrpr %0, 0, %%pstate"
  903. : : "r" (pstate));
  904. }
  905. /* Caller does TLB context flushing on local CPU if necessary.
  906. * The caller also ensures that CTX_VALID(mm->context) is false.
  907. *
  908. * We must be careful about boundary cases so that we never
  909. * let the user have CTX 0 (nucleus) or we ever use a CTX
  910. * version of zero (and thus NO_CONTEXT would not be caught
  911. * by version mis-match tests in mmu_context.h).
  912. */
  913. void get_new_mmu_context(struct mm_struct *mm)
  914. {
  915. unsigned long ctx, new_ctx;
  916. unsigned long orig_pgsz_bits;
  917. spin_lock(&ctx_alloc_lock);
  918. orig_pgsz_bits = (mm->context.sparc64_ctx_val & CTX_PGSZ_MASK);
  919. ctx = (tlb_context_cache + 1) & CTX_NR_MASK;
  920. new_ctx = find_next_zero_bit(mmu_context_bmap, 1 << CTX_NR_BITS, ctx);
  921. if (new_ctx >= (1 << CTX_NR_BITS)) {
  922. new_ctx = find_next_zero_bit(mmu_context_bmap, ctx, 1);
  923. if (new_ctx >= ctx) {
  924. int i;
  925. new_ctx = (tlb_context_cache & CTX_VERSION_MASK) +
  926. CTX_FIRST_VERSION;
  927. if (new_ctx == 1)
  928. new_ctx = CTX_FIRST_VERSION;
  929. /* Don't call memset, for 16 entries that's just
  930. * plain silly...
  931. */
  932. mmu_context_bmap[0] = 3;
  933. mmu_context_bmap[1] = 0;
  934. mmu_context_bmap[2] = 0;
  935. mmu_context_bmap[3] = 0;
  936. for (i = 4; i < CTX_BMAP_SLOTS; i += 4) {
  937. mmu_context_bmap[i + 0] = 0;
  938. mmu_context_bmap[i + 1] = 0;
  939. mmu_context_bmap[i + 2] = 0;
  940. mmu_context_bmap[i + 3] = 0;
  941. }
  942. goto out;
  943. }
  944. }
  945. mmu_context_bmap[new_ctx>>6] |= (1UL << (new_ctx & 63));
  946. new_ctx |= (tlb_context_cache & CTX_VERSION_MASK);
  947. out:
  948. tlb_context_cache = new_ctx;
  949. mm->context.sparc64_ctx_val = new_ctx | orig_pgsz_bits;
  950. spin_unlock(&ctx_alloc_lock);
  951. }
  952. #ifndef CONFIG_SMP
  953. struct pgtable_cache_struct pgt_quicklists;
  954. #endif
  955. /* OK, we have to color these pages. The page tables are accessed
  956. * by non-Dcache enabled mapping in the VPTE area by the dtlb_backend.S
  957. * code, as well as by PAGE_OFFSET range direct-mapped addresses by
  958. * other parts of the kernel. By coloring, we make sure that the tlbmiss
  959. * fast handlers do not get data from old/garbage dcache lines that
  960. * correspond to an old/stale virtual address (user/kernel) that
  961. * previously mapped the pagetable page while accessing vpte range
  962. * addresses. The idea is that if the vpte color and PAGE_OFFSET range
  963. * color is the same, then when the kernel initializes the pagetable
  964. * using the later address range, accesses with the first address
  965. * range will see the newly initialized data rather than the garbage.
  966. */
  967. #ifdef DCACHE_ALIASING_POSSIBLE
  968. #define DC_ALIAS_SHIFT 1
  969. #else
  970. #define DC_ALIAS_SHIFT 0
  971. #endif
  972. pte_t *pte_alloc_one_kernel(struct mm_struct *mm, unsigned long address)
  973. {
  974. struct page *page;
  975. unsigned long color;
  976. {
  977. pte_t *ptep = pte_alloc_one_fast(mm, address);
  978. if (ptep)
  979. return ptep;
  980. }
  981. color = VPTE_COLOR(address);
  982. page = alloc_pages(GFP_KERNEL|__GFP_REPEAT, DC_ALIAS_SHIFT);
  983. if (page) {
  984. unsigned long *to_free;
  985. unsigned long paddr;
  986. pte_t *pte;
  987. #ifdef DCACHE_ALIASING_POSSIBLE
  988. set_page_count(page, 1);
  989. ClearPageCompound(page);
  990. set_page_count((page + 1), 1);
  991. ClearPageCompound(page + 1);
  992. #endif
  993. paddr = (unsigned long) page_address(page);
  994. memset((char *)paddr, 0, (PAGE_SIZE << DC_ALIAS_SHIFT));
  995. if (!color) {
  996. pte = (pte_t *) paddr;
  997. to_free = (unsigned long *) (paddr + PAGE_SIZE);
  998. } else {
  999. pte = (pte_t *) (paddr + PAGE_SIZE);
  1000. to_free = (unsigned long *) paddr;
  1001. }
  1002. #ifdef DCACHE_ALIASING_POSSIBLE
  1003. /* Now free the other one up, adjust cache size. */
  1004. preempt_disable();
  1005. *to_free = (unsigned long) pte_quicklist[color ^ 0x1];
  1006. pte_quicklist[color ^ 0x1] = to_free;
  1007. pgtable_cache_size++;
  1008. preempt_enable();
  1009. #endif
  1010. return pte;
  1011. }
  1012. return NULL;
  1013. }
  1014. void sparc_ultra_dump_itlb(void)
  1015. {
  1016. int slot;
  1017. if (tlb_type == spitfire) {
  1018. printk ("Contents of itlb: ");
  1019. for (slot = 0; slot < 14; slot++) printk (" ");
  1020. printk ("%2x:%016lx,%016lx\n",
  1021. 0,
  1022. spitfire_get_itlb_tag(0), spitfire_get_itlb_data(0));
  1023. for (slot = 1; slot < 64; slot+=3) {
  1024. printk ("%2x:%016lx,%016lx %2x:%016lx,%016lx %2x:%016lx,%016lx\n",
  1025. slot,
  1026. spitfire_get_itlb_tag(slot), spitfire_get_itlb_data(slot),
  1027. slot+1,
  1028. spitfire_get_itlb_tag(slot+1), spitfire_get_itlb_data(slot+1),
  1029. slot+2,
  1030. spitfire_get_itlb_tag(slot+2), spitfire_get_itlb_data(slot+2));
  1031. }
  1032. } else if (tlb_type == cheetah || tlb_type == cheetah_plus) {
  1033. printk ("Contents of itlb0:\n");
  1034. for (slot = 0; slot < 16; slot+=2) {
  1035. printk ("%2x:%016lx,%016lx %2x:%016lx,%016lx\n",
  1036. slot,
  1037. cheetah_get_litlb_tag(slot), cheetah_get_litlb_data(slot),
  1038. slot+1,
  1039. cheetah_get_litlb_tag(slot+1), cheetah_get_litlb_data(slot+1));
  1040. }
  1041. printk ("Contents of itlb2:\n");
  1042. for (slot = 0; slot < 128; slot+=2) {
  1043. printk ("%2x:%016lx,%016lx %2x:%016lx,%016lx\n",
  1044. slot,
  1045. cheetah_get_itlb_tag(slot), cheetah_get_itlb_data(slot),
  1046. slot+1,
  1047. cheetah_get_itlb_tag(slot+1), cheetah_get_itlb_data(slot+1));
  1048. }
  1049. }
  1050. }
  1051. void sparc_ultra_dump_dtlb(void)
  1052. {
  1053. int slot;
  1054. if (tlb_type == spitfire) {
  1055. printk ("Contents of dtlb: ");
  1056. for (slot = 0; slot < 14; slot++) printk (" ");
  1057. printk ("%2x:%016lx,%016lx\n", 0,
  1058. spitfire_get_dtlb_tag(0), spitfire_get_dtlb_data(0));
  1059. for (slot = 1; slot < 64; slot+=3) {
  1060. printk ("%2x:%016lx,%016lx %2x:%016lx,%016lx %2x:%016lx,%016lx\n",
  1061. slot,
  1062. spitfire_get_dtlb_tag(slot), spitfire_get_dtlb_data(slot),
  1063. slot+1,
  1064. spitfire_get_dtlb_tag(slot+1), spitfire_get_dtlb_data(slot+1),
  1065. slot+2,
  1066. spitfire_get_dtlb_tag(slot+2), spitfire_get_dtlb_data(slot+2));
  1067. }
  1068. } else if (tlb_type == cheetah || tlb_type == cheetah_plus) {
  1069. printk ("Contents of dtlb0:\n");
  1070. for (slot = 0; slot < 16; slot+=2) {
  1071. printk ("%2x:%016lx,%016lx %2x:%016lx,%016lx\n",
  1072. slot,
  1073. cheetah_get_ldtlb_tag(slot), cheetah_get_ldtlb_data(slot),
  1074. slot+1,
  1075. cheetah_get_ldtlb_tag(slot+1), cheetah_get_ldtlb_data(slot+1));
  1076. }
  1077. printk ("Contents of dtlb2:\n");
  1078. for (slot = 0; slot < 512; slot+=2) {
  1079. printk ("%2x:%016lx,%016lx %2x:%016lx,%016lx\n",
  1080. slot,
  1081. cheetah_get_dtlb_tag(slot, 2), cheetah_get_dtlb_data(slot, 2),
  1082. slot+1,
  1083. cheetah_get_dtlb_tag(slot+1, 2), cheetah_get_dtlb_data(slot+1, 2));
  1084. }
  1085. if (tlb_type == cheetah_plus) {
  1086. printk ("Contents of dtlb3:\n");
  1087. for (slot = 0; slot < 512; slot+=2) {
  1088. printk ("%2x:%016lx,%016lx %2x:%016lx,%016lx\n",
  1089. slot,
  1090. cheetah_get_dtlb_tag(slot, 3), cheetah_get_dtlb_data(slot, 3),
  1091. slot+1,
  1092. cheetah_get_dtlb_tag(slot+1, 3), cheetah_get_dtlb_data(slot+1, 3));
  1093. }
  1094. }
  1095. }
  1096. }
  1097. extern unsigned long cmdline_memory_size;
  1098. unsigned long __init bootmem_init(unsigned long *pages_avail)
  1099. {
  1100. unsigned long bootmap_size, start_pfn, end_pfn;
  1101. unsigned long end_of_phys_memory = 0UL;
  1102. unsigned long bootmap_pfn, bytes_avail, size;
  1103. int i;
  1104. #ifdef CONFIG_DEBUG_BOOTMEM
  1105. prom_printf("bootmem_init: Scan pavail, ");
  1106. #endif
  1107. bytes_avail = 0UL;
  1108. for (i = 0; i < pavail_ents; i++) {
  1109. end_of_phys_memory = pavail[i].phys_addr +
  1110. pavail[i].reg_size;
  1111. bytes_avail += pavail[i].reg_size;
  1112. if (cmdline_memory_size) {
  1113. if (bytes_avail > cmdline_memory_size) {
  1114. unsigned long slack = bytes_avail - cmdline_memory_size;
  1115. bytes_avail -= slack;
  1116. end_of_phys_memory -= slack;
  1117. pavail[i].reg_size -= slack;
  1118. if ((long)pavail[i].reg_size <= 0L) {
  1119. pavail[i].phys_addr = 0xdeadbeefUL;
  1120. pavail[i].reg_size = 0UL;
  1121. pavail_ents = i;
  1122. } else {
  1123. pavail[i+1].reg_size = 0Ul;
  1124. pavail[i+1].phys_addr = 0xdeadbeefUL;
  1125. pavail_ents = i + 1;
  1126. }
  1127. break;
  1128. }
  1129. }
  1130. }
  1131. *pages_avail = bytes_avail >> PAGE_SHIFT;
  1132. /* Start with page aligned address of last symbol in kernel
  1133. * image. The kernel is hard mapped below PAGE_OFFSET in a
  1134. * 4MB locked TLB translation.
  1135. */
  1136. start_pfn = PAGE_ALIGN(kern_base + kern_size) >> PAGE_SHIFT;
  1137. bootmap_pfn = start_pfn;
  1138. end_pfn = end_of_phys_memory >> PAGE_SHIFT;
  1139. #ifdef CONFIG_BLK_DEV_INITRD
  1140. /* Now have to check initial ramdisk, so that bootmap does not overwrite it */
  1141. if (sparc_ramdisk_image || sparc_ramdisk_image64) {
  1142. unsigned long ramdisk_image = sparc_ramdisk_image ?
  1143. sparc_ramdisk_image : sparc_ramdisk_image64;
  1144. if (ramdisk_image >= (unsigned long)_end - 2 * PAGE_SIZE)
  1145. ramdisk_image -= KERNBASE;
  1146. initrd_start = ramdisk_image + phys_base;
  1147. initrd_end = initrd_start + sparc_ramdisk_size;
  1148. if (initrd_end > end_of_phys_memory) {
  1149. printk(KERN_CRIT "initrd extends beyond end of memory "
  1150. "(0x%016lx > 0x%016lx)\ndisabling initrd\n",
  1151. initrd_end, end_of_phys_memory);
  1152. initrd_start = 0;
  1153. }
  1154. if (initrd_start) {
  1155. if (initrd_start >= (start_pfn << PAGE_SHIFT) &&
  1156. initrd_start < (start_pfn << PAGE_SHIFT) + 2 * PAGE_SIZE)
  1157. bootmap_pfn = PAGE_ALIGN (initrd_end) >> PAGE_SHIFT;
  1158. }
  1159. }
  1160. #endif
  1161. /* Initialize the boot-time allocator. */
  1162. max_pfn = max_low_pfn = end_pfn;
  1163. min_low_pfn = pfn_base;
  1164. #ifdef CONFIG_DEBUG_BOOTMEM
  1165. prom_printf("init_bootmem(min[%lx], bootmap[%lx], max[%lx])\n",
  1166. min_low_pfn, bootmap_pfn, max_low_pfn);
  1167. #endif
  1168. bootmap_size = init_bootmem_node(NODE_DATA(0), bootmap_pfn, pfn_base, end_pfn);
  1169. /* Now register the available physical memory with the
  1170. * allocator.
  1171. */
  1172. for (i = 0; i < pavail_ents; i++) {
  1173. #ifdef CONFIG_DEBUG_BOOTMEM
  1174. prom_printf("free_bootmem(pavail:%d): base[%lx] size[%lx]\n",
  1175. i, pavail[i].phys_addr, pavail[i].reg_size);
  1176. #endif
  1177. free_bootmem(pavail[i].phys_addr, pavail[i].reg_size);
  1178. }
  1179. #ifdef CONFIG_BLK_DEV_INITRD
  1180. if (initrd_start) {
  1181. size = initrd_end - initrd_start;
  1182. /* Resert the initrd image area. */
  1183. #ifdef CONFIG_DEBUG_BOOTMEM
  1184. prom_printf("reserve_bootmem(initrd): base[%llx] size[%lx]\n",
  1185. initrd_start, initrd_end);
  1186. #endif
  1187. reserve_bootmem(initrd_start, size);
  1188. *pages_avail -= PAGE_ALIGN(size) >> PAGE_SHIFT;
  1189. initrd_start += PAGE_OFFSET;
  1190. initrd_end += PAGE_OFFSET;
  1191. }
  1192. #endif
  1193. /* Reserve the kernel text/data/bss. */
  1194. #ifdef CONFIG_DEBUG_BOOTMEM
  1195. prom_printf("reserve_bootmem(kernel): base[%lx] size[%lx]\n", kern_base, kern_size);
  1196. #endif
  1197. reserve_bootmem(kern_base, kern_size);
  1198. *pages_avail -= PAGE_ALIGN(kern_size) >> PAGE_SHIFT;
  1199. /* Reserve the bootmem map. We do not account for it
  1200. * in pages_avail because we will release that memory
  1201. * in free_all_bootmem.
  1202. */
  1203. size = bootmap_size;
  1204. #ifdef CONFIG_DEBUG_BOOTMEM
  1205. prom_printf("reserve_bootmem(bootmap): base[%lx] size[%lx]\n",
  1206. (bootmap_pfn << PAGE_SHIFT), size);
  1207. #endif
  1208. reserve_bootmem((bootmap_pfn << PAGE_SHIFT), size);
  1209. *pages_avail -= PAGE_ALIGN(size) >> PAGE_SHIFT;
  1210. return end_pfn;
  1211. }
  1212. #ifdef CONFIG_DEBUG_PAGEALLOC
  1213. static unsigned long kernel_map_range(unsigned long pstart, unsigned long pend, pgprot_t prot)
  1214. {
  1215. unsigned long vstart = PAGE_OFFSET + pstart;
  1216. unsigned long vend = PAGE_OFFSET + pend;
  1217. unsigned long alloc_bytes = 0UL;
  1218. if ((vstart & ~PAGE_MASK) || (vend & ~PAGE_MASK)) {
  1219. prom_printf("kernel_map: Unaligned physmem[%lx:%lx]\n",
  1220. vstart, vend);
  1221. prom_halt();
  1222. }
  1223. while (vstart < vend) {
  1224. unsigned long this_end, paddr = __pa(vstart);
  1225. pgd_t *pgd = pgd_offset_k(vstart);
  1226. pud_t *pud;
  1227. pmd_t *pmd;
  1228. pte_t *pte;
  1229. pud = pud_offset(pgd, vstart);
  1230. if (pud_none(*pud)) {
  1231. pmd_t *new;
  1232. new = __alloc_bootmem(PAGE_SIZE, PAGE_SIZE, PAGE_SIZE);
  1233. alloc_bytes += PAGE_SIZE;
  1234. pud_populate(&init_mm, pud, new);
  1235. }
  1236. pmd = pmd_offset(pud, vstart);
  1237. if (!pmd_present(*pmd)) {
  1238. pte_t *new;
  1239. new = __alloc_bootmem(PAGE_SIZE, PAGE_SIZE, PAGE_SIZE);
  1240. alloc_bytes += PAGE_SIZE;
  1241. pmd_populate_kernel(&init_mm, pmd, new);
  1242. }
  1243. pte = pte_offset_kernel(pmd, vstart);
  1244. this_end = (vstart + PMD_SIZE) & PMD_MASK;
  1245. if (this_end > vend)
  1246. this_end = vend;
  1247. while (vstart < this_end) {
  1248. pte_val(*pte) = (paddr | pgprot_val(prot));
  1249. vstart += PAGE_SIZE;
  1250. paddr += PAGE_SIZE;
  1251. pte++;
  1252. }
  1253. }
  1254. return alloc_bytes;
  1255. }
  1256. static struct linux_prom64_registers pall[MAX_BANKS] __initdata;
  1257. static int pall_ents __initdata;
  1258. extern unsigned int kvmap_linear_patch[1];
  1259. static void __init kernel_physical_mapping_init(void)
  1260. {
  1261. unsigned long i, mem_alloced = 0UL;
  1262. read_obp_memory("reg", &pall[0], &pall_ents);
  1263. for (i = 0; i < pall_ents; i++) {
  1264. unsigned long phys_start, phys_end;
  1265. phys_start = pall[i].phys_addr;
  1266. phys_end = phys_start + pall[i].reg_size;
  1267. mem_alloced += kernel_map_range(phys_start, phys_end,
  1268. PAGE_KERNEL);
  1269. }
  1270. printk("Allocated %ld bytes for kernel page tables.\n",
  1271. mem_alloced);
  1272. kvmap_linear_patch[0] = 0x01000000; /* nop */
  1273. flushi(&kvmap_linear_patch[0]);
  1274. __flush_tlb_all();
  1275. }
  1276. void kernel_map_pages(struct page *page, int numpages, int enable)
  1277. {
  1278. unsigned long phys_start = page_to_pfn(page) << PAGE_SHIFT;
  1279. unsigned long phys_end = phys_start + (numpages * PAGE_SIZE);
  1280. kernel_map_range(phys_start, phys_end,
  1281. (enable ? PAGE_KERNEL : __pgprot(0)));
  1282. /* we should perform an IPI and flush all tlbs,
  1283. * but that can deadlock->flush only current cpu.
  1284. */
  1285. __flush_tlb_kernel_range(PAGE_OFFSET + phys_start,
  1286. PAGE_OFFSET + phys_end);
  1287. }
  1288. #endif
  1289. unsigned long __init find_ecache_flush_span(unsigned long size)
  1290. {
  1291. int i;
  1292. for (i = 0; i < pavail_ents; i++) {
  1293. if (pavail[i].reg_size >= size)
  1294. return pavail[i].phys_addr;
  1295. }
  1296. return ~0UL;
  1297. }
  1298. /* paging_init() sets up the page tables */
  1299. extern void cheetah_ecache_flush_init(void);
  1300. static unsigned long last_valid_pfn;
  1301. pgd_t swapper_pg_dir[2048];
  1302. void __init paging_init(void)
  1303. {
  1304. unsigned long end_pfn, pages_avail, shift;
  1305. unsigned long real_end, i;
  1306. /* Find available physical memory... */
  1307. read_obp_memory("available", &pavail[0], &pavail_ents);
  1308. phys_base = 0xffffffffffffffffUL;
  1309. for (i = 0; i < pavail_ents; i++)
  1310. phys_base = min(phys_base, pavail[i].phys_addr);
  1311. pfn_base = phys_base >> PAGE_SHIFT;
  1312. kern_base = (prom_boot_mapping_phys_low >> 22UL) << 22UL;
  1313. kern_size = (unsigned long)&_end - (unsigned long)KERNBASE;
  1314. set_bit(0, mmu_context_bmap);
  1315. shift = kern_base + PAGE_OFFSET - ((unsigned long)KERNBASE);
  1316. real_end = (unsigned long)_end;
  1317. if ((real_end > ((unsigned long)KERNBASE + 0x400000)))
  1318. bigkernel = 1;
  1319. if ((real_end > ((unsigned long)KERNBASE + 0x800000))) {
  1320. prom_printf("paging_init: Kernel > 8MB, too large.\n");
  1321. prom_halt();
  1322. }
  1323. /* Set kernel pgd to upper alias so physical page computations
  1324. * work.
  1325. */
  1326. init_mm.pgd += ((shift) / (sizeof(pgd_t)));
  1327. memset(swapper_low_pmd_dir, 0, sizeof(swapper_low_pmd_dir));
  1328. /* Now can init the kernel/bad page tables. */
  1329. pud_set(pud_offset(&swapper_pg_dir[0], 0),
  1330. swapper_low_pmd_dir + (shift / sizeof(pgd_t)));
  1331. swapper_pgd_zero = pgd_val(swapper_pg_dir[0]);
  1332. /* Inherit non-locked OBP mappings. */
  1333. inherit_prom_mappings();
  1334. /* Ok, we can use our TLB miss and window trap handlers safely.
  1335. * We need to do a quick peek here to see if we are on StarFire
  1336. * or not, so setup_tba can setup the IRQ globals correctly (it
  1337. * needs to get the hard smp processor id correctly).
  1338. */
  1339. {
  1340. extern void setup_tba(int);
  1341. setup_tba(this_is_starfire);
  1342. }
  1343. inherit_locked_prom_mappings(1);
  1344. __flush_tlb_all();
  1345. /* Setup bootmem... */
  1346. pages_avail = 0;
  1347. last_valid_pfn = end_pfn = bootmem_init(&pages_avail);
  1348. #ifdef CONFIG_DEBUG_PAGEALLOC
  1349. kernel_physical_mapping_init();
  1350. #endif
  1351. {
  1352. unsigned long zones_size[MAX_NR_ZONES];
  1353. unsigned long zholes_size[MAX_NR_ZONES];
  1354. unsigned long npages;
  1355. int znum;
  1356. for (znum = 0; znum < MAX_NR_ZONES; znum++)
  1357. zones_size[znum] = zholes_size[znum] = 0;
  1358. npages = end_pfn - pfn_base;
  1359. zones_size[ZONE_DMA] = npages;
  1360. zholes_size[ZONE_DMA] = npages - pages_avail;
  1361. free_area_init_node(0, &contig_page_data, zones_size,
  1362. phys_base >> PAGE_SHIFT, zholes_size);
  1363. }
  1364. device_scan();
  1365. }
  1366. static void __init taint_real_pages(void)
  1367. {
  1368. int i;
  1369. read_obp_memory("available", &pavail_rescan[0], &pavail_rescan_ents);
  1370. /* Find changes discovered in the physmem available rescan and
  1371. * reserve the lost portions in the bootmem maps.
  1372. */
  1373. for (i = 0; i < pavail_ents; i++) {
  1374. unsigned long old_start, old_end;
  1375. old_start = pavail[i].phys_addr;
  1376. old_end = old_start +
  1377. pavail[i].reg_size;
  1378. while (old_start < old_end) {
  1379. int n;
  1380. for (n = 0; pavail_rescan_ents; n++) {
  1381. unsigned long new_start, new_end;
  1382. new_start = pavail_rescan[n].phys_addr;
  1383. new_end = new_start +
  1384. pavail_rescan[n].reg_size;
  1385. if (new_start <= old_start &&
  1386. new_end >= (old_start + PAGE_SIZE)) {
  1387. set_bit(old_start >> 22,
  1388. sparc64_valid_addr_bitmap);
  1389. goto do_next_page;
  1390. }
  1391. }
  1392. reserve_bootmem(old_start, PAGE_SIZE);
  1393. do_next_page:
  1394. old_start += PAGE_SIZE;
  1395. }
  1396. }
  1397. }
  1398. void __init mem_init(void)
  1399. {
  1400. unsigned long codepages, datapages, initpages;
  1401. unsigned long addr, last;
  1402. int i;
  1403. i = last_valid_pfn >> ((22 - PAGE_SHIFT) + 6);
  1404. i += 1;
  1405. sparc64_valid_addr_bitmap = (unsigned long *) alloc_bootmem(i << 3);
  1406. if (sparc64_valid_addr_bitmap == NULL) {
  1407. prom_printf("mem_init: Cannot alloc valid_addr_bitmap.\n");
  1408. prom_halt();
  1409. }
  1410. memset(sparc64_valid_addr_bitmap, 0, i << 3);
  1411. addr = PAGE_OFFSET + kern_base;
  1412. last = PAGE_ALIGN(kern_size) + addr;
  1413. while (addr < last) {
  1414. set_bit(__pa(addr) >> 22, sparc64_valid_addr_bitmap);
  1415. addr += PAGE_SIZE;
  1416. }
  1417. taint_real_pages();
  1418. max_mapnr = last_valid_pfn - pfn_base;
  1419. high_memory = __va(last_valid_pfn << PAGE_SHIFT);
  1420. #ifdef CONFIG_DEBUG_BOOTMEM
  1421. prom_printf("mem_init: Calling free_all_bootmem().\n");
  1422. #endif
  1423. totalram_pages = num_physpages = free_all_bootmem() - 1;
  1424. /*
  1425. * Set up the zero page, mark it reserved, so that page count
  1426. * is not manipulated when freeing the page from user ptes.
  1427. */
  1428. mem_map_zero = alloc_pages(GFP_KERNEL|__GFP_ZERO, 0);
  1429. if (mem_map_zero == NULL) {
  1430. prom_printf("paging_init: Cannot alloc zero page.\n");
  1431. prom_halt();
  1432. }
  1433. SetPageReserved(mem_map_zero);
  1434. codepages = (((unsigned long) _etext) - ((unsigned long) _start));
  1435. codepages = PAGE_ALIGN(codepages) >> PAGE_SHIFT;
  1436. datapages = (((unsigned long) _edata) - ((unsigned long) _etext));
  1437. datapages = PAGE_ALIGN(datapages) >> PAGE_SHIFT;
  1438. initpages = (((unsigned long) __init_end) - ((unsigned long) __init_begin));
  1439. initpages = PAGE_ALIGN(initpages) >> PAGE_SHIFT;
  1440. printk("Memory: %uk available (%ldk kernel code, %ldk data, %ldk init) [%016lx,%016lx]\n",
  1441. nr_free_pages() << (PAGE_SHIFT-10),
  1442. codepages << (PAGE_SHIFT-10),
  1443. datapages << (PAGE_SHIFT-10),
  1444. initpages << (PAGE_SHIFT-10),
  1445. PAGE_OFFSET, (last_valid_pfn << PAGE_SHIFT));
  1446. if (tlb_type == cheetah || tlb_type == cheetah_plus)
  1447. cheetah_ecache_flush_init();
  1448. }
  1449. void free_initmem(void)
  1450. {
  1451. unsigned long addr, initend;
  1452. /*
  1453. * The init section is aligned to 8k in vmlinux.lds. Page align for >8k pagesizes.
  1454. */
  1455. addr = PAGE_ALIGN((unsigned long)(__init_begin));
  1456. initend = (unsigned long)(__init_end) & PAGE_MASK;
  1457. for (; addr < initend; addr += PAGE_SIZE) {
  1458. unsigned long page;
  1459. struct page *p;
  1460. page = (addr +
  1461. ((unsigned long) __va(kern_base)) -
  1462. ((unsigned long) KERNBASE));
  1463. memset((void *)addr, 0xcc, PAGE_SIZE);
  1464. p = virt_to_page(page);
  1465. ClearPageReserved(p);
  1466. set_page_count(p, 1);
  1467. __free_page(p);
  1468. num_physpages++;
  1469. totalram_pages++;
  1470. }
  1471. }
  1472. #ifdef CONFIG_BLK_DEV_INITRD
  1473. void free_initrd_mem(unsigned long start, unsigned long end)
  1474. {
  1475. if (start < end)
  1476. printk ("Freeing initrd memory: %ldk freed\n", (end - start) >> 10);
  1477. for (; start < end; start += PAGE_SIZE) {
  1478. struct page *p = virt_to_page(start);
  1479. ClearPageReserved(p);
  1480. set_page_count(p, 1);
  1481. __free_page(p);
  1482. num_physpages++;
  1483. totalram_pages++;
  1484. }
  1485. }
  1486. #endif