1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16#include <linux/module.h>
17#include <linux/signal.h>
18#include <linux/sched.h>
19#include <linux/kernel.h>
20#include <linux/errno.h>
21#include <linux/string.h>
22#include <linux/types.h>
23#include <linux/ptrace.h>
24#include <linux/mman.h>
25#include <linux/mm.h>
26#include <linux/hugetlb.h>
27#include <linux/swap.h>
28#include <linux/smp.h>
29#include <linux/init.h>
30#include <linux/highmem.h>
31#include <linux/pagemap.h>
32#include <linux/poison.h>
33#include <linux/bootmem.h>
34#include <linux/slab.h>
35#include <linux/proc_fs.h>
36#include <linux/efi.h>
37#include <linux/memory_hotplug.h>
38#include <linux/uaccess.h>
39#include <asm/mmu_context.h>
40#include <asm/processor.h>
41#include <asm/pgtable.h>
42#include <asm/pgalloc.h>
43#include <asm/dma.h>
44#include <asm/fixmap.h>
45#include <asm/tlb.h>
46#include <asm/tlbflush.h>
47#include <asm/sections.h>
48#include <asm/setup.h>
49#include <asm/homecache.h>
50#include <hv/hypervisor.h>
51#include <arch/chip.h>
52
53#include "migrate.h"
54
55#define clear_pgd(pmdptr) (*(pmdptr) = hv_pte(0))
56
57#ifndef __tilegx__
58unsigned long VMALLOC_RESERVE = CONFIG_VMALLOC_RESERVE;
59EXPORT_SYMBOL(VMALLOC_RESERVE);
60#endif
61
62
63static pte_t * __init alloc_pte(void)
64{
65 return __alloc_bootmem(L2_KERNEL_PGTABLE_SIZE, HV_PAGE_TABLE_ALIGN, 0);
66}
67
68
69
70
71
72
73
74
75
76
77
78
79
80static pte_t *l2_ptes[MAX_NUMNODES];
81static int num_l2_ptes[MAX_NUMNODES];
82
83static void init_prealloc_ptes(int node, int pages)
84{
85 BUG_ON(pages & (PTRS_PER_PTE - 1));
86 if (pages) {
87 num_l2_ptes[node] = pages;
88 l2_ptes[node] = __alloc_bootmem(pages * sizeof(pte_t),
89 HV_PAGE_TABLE_ALIGN, 0);
90 }
91}
92
93pte_t *get_prealloc_pte(unsigned long pfn)
94{
95 int node = pfn_to_nid(pfn);
96 pfn &= ~(-1UL << (NR_PA_HIGHBIT_SHIFT - PAGE_SHIFT));
97 BUG_ON(node >= MAX_NUMNODES);
98 BUG_ON(pfn >= num_l2_ptes[node]);
99 return &l2_ptes[node][pfn];
100}
101
102
103
104
105
106
107static int initial_heap_home(void)
108{
109#if CHIP_HAS_CBOX_HOME_MAP()
110 if (hash_default)
111 return PAGE_HOME_HASH;
112#endif
113 return smp_processor_id();
114}
115
116
117
118
119
120static void __init assign_pte(pmd_t *pmd, pte_t *page_table)
121{
122 phys_addr_t pa = __pa(page_table);
123 unsigned long l2_ptfn = pa >> HV_LOG2_PAGE_TABLE_ALIGN;
124 pte_t pteval = hv_pte_set_ptfn(__pgprot(_PAGE_TABLE), l2_ptfn);
125 BUG_ON((pa & (HV_PAGE_TABLE_ALIGN-1)) != 0);
126 pteval = pte_set_home(pteval, initial_heap_home());
127 *(pte_t *)pmd = pteval;
128 if (page_table != (pte_t *)pmd_page_vaddr(*pmd))
129 BUG();
130}
131
132#ifdef __tilegx__
133
134static inline pmd_t *alloc_pmd(void)
135{
136 return __alloc_bootmem(L1_KERNEL_PGTABLE_SIZE, HV_PAGE_TABLE_ALIGN, 0);
137}
138
139static inline void assign_pmd(pud_t *pud, pmd_t *pmd)
140{
141 assign_pte((pmd_t *)pud, (pte_t *)pmd);
142}
143
144#endif
145
146
147void __init shatter_pmd(pmd_t *pmd)
148{
149 pte_t *pte = get_prealloc_pte(pte_pfn(*(pte_t *)pmd));
150 assign_pte(pmd, pte);
151}
152
153#ifdef __tilegx__
154static pmd_t *__init get_pmd(pgd_t pgtables[], unsigned long va)
155{
156 pud_t *pud = pud_offset(&pgtables[pgd_index(va)], va);
157 if (pud_none(*pud))
158 assign_pmd(pud, alloc_pmd());
159 return pmd_offset(pud, va);
160}
161#else
162static pmd_t *__init get_pmd(pgd_t pgtables[], unsigned long va)
163{
164 return pmd_offset(pud_offset(&pgtables[pgd_index(va)], va), va);
165}
166#endif
167
168
169
170
171
172
173
174
175
176
177
178
179static void __init page_table_range_init(unsigned long start,
180 unsigned long end, pgd_t *pgd)
181{
182 unsigned long vaddr;
183 start = round_down(start, PMD_SIZE);
184 end = round_up(end, PMD_SIZE);
185 for (vaddr = start; vaddr < end; vaddr += PMD_SIZE) {
186 pmd_t *pmd = get_pmd(pgd, vaddr);
187 if (pmd_none(*pmd))
188 assign_pte(pmd, alloc_pte());
189 }
190}
191
192
193#if CHIP_HAS_CBOX_HOME_MAP()
194
195static int __initdata ktext_hash = 1;
196static int __initdata kdata_hash = 1;
197int __write_once hash_default = 1;
198EXPORT_SYMBOL(hash_default);
199int __write_once kstack_hash = 1;
200#endif
201
202
203
204
205
206
207
208static __initdata struct cpumask kdata_mask;
209static __initdata int kdata_arg_seen;
210
211int __write_once kdata_huge;
212
213
214
215static pgprot_t __init construct_pgprot(pgprot_t prot, int home)
216{
217 prot = pte_set_home(prot, home);
218#if CHIP_HAS_CBOX_HOME_MAP()
219 if (home == PAGE_HOME_IMMUTABLE) {
220 if (ktext_hash)
221 prot = hv_pte_set_mode(prot, HV_PTE_MODE_CACHE_HASH_L3);
222 else
223 prot = hv_pte_set_mode(prot, HV_PTE_MODE_CACHE_NO_L3);
224 }
225#endif
226 return prot;
227}
228
229
230
231
232
233static pgprot_t __init init_pgprot(ulong address)
234{
235 int cpu;
236 unsigned long page;
237 enum { CODE_DELTA = MEM_SV_INTRPT - PAGE_OFFSET };
238
239#if CHIP_HAS_CBOX_HOME_MAP()
240
241 if (kdata_huge)
242 return construct_pgprot(PAGE_KERNEL, PAGE_HOME_HASH);
243#endif
244
245
246 if (address < (ulong) _sinittext - CODE_DELTA)
247 return PAGE_NONE;
248
249
250
251
252
253 if ((address >= (ulong) __start_rodata &&
254 address < (ulong) __end_rodata) ||
255 address == (ulong) empty_zero_page) {
256 return construct_pgprot(PAGE_KERNEL_RO, PAGE_HOME_IMMUTABLE);
257 }
258
259#ifndef __tilegx__
260#if !ATOMIC_LOCKS_FOUND_VIA_TABLE()
261
262 if (address == (ulong) atomic_locks)
263 return construct_pgprot(PAGE_KERNEL, PAGE_HOME_HASH);
264#endif
265#endif
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280 if (address >= (ulong) _end || address < (ulong) _einitdata)
281 return construct_pgprot(PAGE_KERNEL, initial_heap_home());
282
283#if CHIP_HAS_CBOX_HOME_MAP()
284
285 if (kdata_hash)
286 return construct_pgprot(PAGE_KERNEL, PAGE_HOME_HASH);
287#endif
288
289
290
291
292
293
294 if (address >= (ulong)__w1data_begin && address < (ulong)__w1data_end)
295 return construct_pgprot(PAGE_KERNEL, initial_heap_home());
296
297
298
299
300
301
302
303
304 page = (((ulong)__w1data_end) + PAGE_SIZE - 1) & PAGE_MASK;
305 BUG_ON(address < page || address >= (ulong)_end);
306 cpu = cpumask_first(&kdata_mask);
307 for (; page < address; page += PAGE_SIZE) {
308 if (page >= (ulong)&init_thread_union &&
309 page < (ulong)&init_thread_union + THREAD_SIZE)
310 continue;
311 if (page == (ulong)empty_zero_page)
312 continue;
313#ifndef __tilegx__
314#if !ATOMIC_LOCKS_FOUND_VIA_TABLE()
315 if (page == (ulong)atomic_locks)
316 continue;
317#endif
318#endif
319 cpu = cpumask_next(cpu, &kdata_mask);
320 if (cpu == NR_CPUS)
321 cpu = cpumask_first(&kdata_mask);
322 }
323 return construct_pgprot(PAGE_KERNEL, cpu);
324}
325
326
327
328
329
330
331
332
333
334
335static int __initdata ktext_arg_seen;
336static int __initdata ktext_small;
337static int __initdata ktext_local;
338static int __initdata ktext_all;
339static int __initdata ktext_nondataplane;
340static int __initdata ktext_nocache;
341static struct cpumask __initdata ktext_mask;
342
343static int __init setup_ktext(char *str)
344{
345 if (str == NULL)
346 return -EINVAL;
347
348
349 if (strncmp(str, "nocache", 7) == 0) {
350 ktext_nocache = 1;
351 pr_info("ktext: disabling local caching of kernel text\n");
352 str += 7;
353 if (*str == ',')
354 ++str;
355 if (*str == '\0')
356 return 0;
357 }
358
359 ktext_arg_seen = 1;
360
361
362 if (strcmp(str, "huge") == 0)
363 pr_info("ktext: using one huge locally cached page\n");
364
365
366 else if (strcmp(str, "local") == 0) {
367 ktext_small = 1;
368 ktext_local = 1;
369 pr_info("ktext: using small pages with local caching\n");
370 }
371
372
373 else if (strcmp(str, "all") == 0) {
374 ktext_small = 1;
375 ktext_all = 1;
376 pr_info("ktext: using maximal caching neighborhood\n");
377 }
378
379
380
381 else if (cpulist_parse(str, &ktext_mask) == 0) {
382 char buf[NR_CPUS * 5];
383 cpulist_scnprintf(buf, sizeof(buf), &ktext_mask);
384 if (cpumask_weight(&ktext_mask) > 1) {
385 ktext_small = 1;
386 pr_info("ktext: using caching neighborhood %s "
387 "with small pages\n", buf);
388 } else {
389 pr_info("ktext: caching on cpu %s with one huge page\n",
390 buf);
391 }
392 }
393
394 else if (*str)
395 return -EINVAL;
396
397 return 0;
398}
399
400early_param("ktext", setup_ktext);
401
402
403static inline pgprot_t ktext_set_nocache(pgprot_t prot)
404{
405 if (!ktext_nocache)
406 prot = hv_pte_set_nc(prot);
407#if CHIP_HAS_NC_AND_NOALLOC_BITS()
408 else
409 prot = hv_pte_set_no_alloc_l2(prot);
410#endif
411 return prot;
412}
413
414
415static pgd_t pgtables[PTRS_PER_PGD]
416 __attribute__((aligned(HV_PAGE_TABLE_ALIGN)));
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432static void __init kernel_physical_mapping_init(pgd_t *pgd_base)
433{
434 unsigned long long irqmask;
435 unsigned long address, pfn;
436 pmd_t *pmd;
437 pte_t *pte;
438 int pte_ofs;
439 const struct cpumask *my_cpu_mask = cpumask_of(smp_processor_id());
440 struct cpumask kstripe_mask;
441 int rc, i;
442
443#if CHIP_HAS_CBOX_HOME_MAP()
444 if (ktext_arg_seen && ktext_hash) {
445 pr_warning("warning: \"ktext\" boot argument ignored"
446 " if \"kcache_hash\" sets up text hash-for-home\n");
447 ktext_small = 0;
448 }
449
450 if (kdata_arg_seen && kdata_hash) {
451 pr_warning("warning: \"kdata\" boot argument ignored"
452 " if \"kcache_hash\" sets up data hash-for-home\n");
453 }
454
455 if (kdata_huge && !hash_default) {
456 pr_warning("warning: disabling \"kdata=huge\"; requires"
457 " kcache_hash=all or =allbutstack\n");
458 kdata_huge = 0;
459 }
460#endif
461
462
463
464
465
466
467
468 cpumask_copy(&kstripe_mask, cpu_possible_mask);
469 if (!kdata_arg_seen)
470 kdata_mask = kstripe_mask;
471
472
473 for (i = 0; i < MAX_NUMNODES; ++i) {
474#ifdef CONFIG_HIGHMEM
475 unsigned long end_pfn = node_lowmem_end_pfn[i];
476#else
477 unsigned long end_pfn = node_end_pfn[i];
478#endif
479 unsigned long end_huge_pfn = 0;
480
481
482 if (kdata_huge)
483 end_huge_pfn = end_pfn - (HPAGE_SIZE >> PAGE_SHIFT);
484
485 pfn = node_start_pfn[i];
486
487
488 init_prealloc_ptes(i, end_pfn - pfn);
489
490 address = (unsigned long) pfn_to_kaddr(pfn);
491 while (pfn < end_pfn) {
492 BUG_ON(address & (HPAGE_SIZE-1));
493 pmd = get_pmd(pgtables, address);
494 pte = get_prealloc_pte(pfn);
495 if (pfn < end_huge_pfn) {
496 pgprot_t prot = init_pgprot(address);
497 *(pte_t *)pmd = pte_mkhuge(pfn_pte(pfn, prot));
498 for (pte_ofs = 0; pte_ofs < PTRS_PER_PTE;
499 pfn++, pte_ofs++, address += PAGE_SIZE)
500 pte[pte_ofs] = pfn_pte(pfn, prot);
501 } else {
502 if (kdata_huge)
503 printk(KERN_DEBUG "pre-shattered huge"
504 " page at %#lx\n", address);
505 for (pte_ofs = 0; pte_ofs < PTRS_PER_PTE;
506 pfn++, pte_ofs++, address += PAGE_SIZE) {
507 pgprot_t prot = init_pgprot(address);
508 pte[pte_ofs] = pfn_pte(pfn, prot);
509 }
510 assign_pte(pmd, pte);
511 }
512 }
513 }
514
515
516
517
518
519 if (ktext_all)
520 cpumask_copy(&ktext_mask, cpu_possible_mask);
521 else if (ktext_nondataplane)
522 ktext_mask = kstripe_mask;
523 else if (!cpumask_empty(&ktext_mask)) {
524
525 struct cpumask bad;
526 cpumask_andnot(&bad, &ktext_mask, cpu_possible_mask);
527 cpumask_and(&ktext_mask, &ktext_mask, cpu_possible_mask);
528 if (!cpumask_empty(&bad)) {
529 char buf[NR_CPUS * 5];
530 cpulist_scnprintf(buf, sizeof(buf), &bad);
531 pr_info("ktext: not using unavailable cpus %s\n", buf);
532 }
533 if (cpumask_empty(&ktext_mask)) {
534 pr_warning("ktext: no valid cpus; caching on %d.\n",
535 smp_processor_id());
536 cpumask_copy(&ktext_mask,
537 cpumask_of(smp_processor_id()));
538 }
539 }
540
541 address = MEM_SV_INTRPT;
542 pmd = get_pmd(pgtables, address);
543 pfn = 0;
544 if (ktext_small) {
545
546 int cpu = 0;
547 pgprot_t prot = construct_pgprot(PAGE_KERNEL_EXEC,
548 PAGE_HOME_IMMUTABLE);
549
550 if (ktext_local) {
551 if (ktext_nocache)
552 prot = hv_pte_set_mode(prot,
553 HV_PTE_MODE_UNCACHED);
554 else
555 prot = hv_pte_set_mode(prot,
556 HV_PTE_MODE_CACHE_NO_L3);
557 } else {
558 prot = hv_pte_set_mode(prot,
559 HV_PTE_MODE_CACHE_TILE_L3);
560 cpu = cpumask_first(&ktext_mask);
561
562 prot = ktext_set_nocache(prot);
563 }
564
565 BUG_ON(address != (unsigned long)_stext);
566 pte = NULL;
567 for (; address < (unsigned long)_einittext;
568 pfn++, address += PAGE_SIZE) {
569 pte_ofs = pte_index(address);
570 if (pte_ofs == 0) {
571 if (pte)
572 assign_pte(pmd++, pte);
573 pte = alloc_pte();
574 }
575 if (!ktext_local) {
576 prot = set_remote_cache_cpu(prot, cpu);
577 cpu = cpumask_next(cpu, &ktext_mask);
578 if (cpu == NR_CPUS)
579 cpu = cpumask_first(&ktext_mask);
580 }
581 pte[pte_ofs] = pfn_pte(pfn, prot);
582 }
583 if (pte)
584 assign_pte(pmd, pte);
585 } else {
586 pte_t pteval = pfn_pte(0, PAGE_KERNEL_EXEC);
587 pteval = pte_mkhuge(pteval);
588#if CHIP_HAS_CBOX_HOME_MAP()
589 if (ktext_hash) {
590 pteval = hv_pte_set_mode(pteval,
591 HV_PTE_MODE_CACHE_HASH_L3);
592 pteval = ktext_set_nocache(pteval);
593 } else
594#endif
595 if (cpumask_weight(&ktext_mask) == 1) {
596 pteval = set_remote_cache_cpu(pteval,
597 cpumask_first(&ktext_mask));
598 pteval = hv_pte_set_mode(pteval,
599 HV_PTE_MODE_CACHE_TILE_L3);
600 pteval = ktext_set_nocache(pteval);
601 } else if (ktext_nocache)
602 pteval = hv_pte_set_mode(pteval,
603 HV_PTE_MODE_UNCACHED);
604 else
605 pteval = hv_pte_set_mode(pteval,
606 HV_PTE_MODE_CACHE_NO_L3);
607 for (; address < (unsigned long)_einittext;
608 pfn += PFN_DOWN(HPAGE_SIZE), address += HPAGE_SIZE)
609 *(pte_t *)(pmd++) = pfn_pte(pfn, pteval);
610 }
611
612
613 swapper_pgprot = init_pgprot((unsigned long)swapper_pg_dir);
614
615
616
617
618
619
620
621
622
623
624 irqmask = interrupt_mask_save_mask();
625 interrupt_mask_set_mask(-1ULL);
626 rc = flush_and_install_context(__pa(pgtables),
627 init_pgprot((unsigned long)pgtables),
628 __get_cpu_var(current_asid),
629 cpumask_bits(my_cpu_mask));
630 interrupt_mask_restore_mask(irqmask);
631 BUG_ON(rc != 0);
632
633
634 memcpy(pgd_base, pgtables, sizeof(pgtables));
635 __install_page_table(pgd_base, __get_cpu_var(current_asid),
636 swapper_pgprot);
637
638
639
640
641
642
643
644
645
646
647 __insn_finv(&swapper_pgprot);
648}
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663int devmem_is_allowed(unsigned long pagenr)
664{
665 return pagenr < kaddr_to_pfn(_end) &&
666 !(pagenr >= kaddr_to_pfn(&init_thread_union) ||
667 pagenr < kaddr_to_pfn(_einitdata)) &&
668 !(pagenr >= kaddr_to_pfn(_sinittext) ||
669 pagenr <= kaddr_to_pfn(_einittext-1));
670}
671
672#ifdef CONFIG_HIGHMEM
673static void __init permanent_kmaps_init(pgd_t *pgd_base)
674{
675 pgd_t *pgd;
676 pud_t *pud;
677 pmd_t *pmd;
678 pte_t *pte;
679 unsigned long vaddr;
680
681 vaddr = PKMAP_BASE;
682 page_table_range_init(vaddr, vaddr + PAGE_SIZE*LAST_PKMAP, pgd_base);
683
684 pgd = swapper_pg_dir + pgd_index(vaddr);
685 pud = pud_offset(pgd, vaddr);
686 pmd = pmd_offset(pud, vaddr);
687 pte = pte_offset_kernel(pmd, vaddr);
688 pkmap_page_table = pte;
689}
690#endif
691
692
693#ifndef CONFIG_64BIT
694static void __init init_free_pfn_range(unsigned long start, unsigned long end)
695{
696 unsigned long pfn;
697 struct page *page = pfn_to_page(start);
698
699 for (pfn = start; pfn < end; ) {
700
701 int order = __ffs(pfn);
702 int count, i;
703 struct page *p;
704
705 if (order >= MAX_ORDER)
706 order = MAX_ORDER-1;
707 count = 1 << order;
708 while (pfn + count > end) {
709 count >>= 1;
710 --order;
711 }
712 for (p = page, i = 0; i < count; ++i, ++p) {
713 __ClearPageReserved(p);
714
715
716
717
718 p->_count.counter = 0;
719 p->_mapcount.counter = -1;
720 }
721 init_page_count(page);
722 __free_pages(page, order);
723 totalram_pages += count;
724
725 page += count;
726 pfn += count;
727 }
728}
729
730static void __init set_non_bootmem_pages_init(void)
731{
732 struct zone *z;
733 for_each_zone(z) {
734 unsigned long start, end;
735 int nid = z->zone_pgdat->node_id;
736#ifdef CONFIG_HIGHMEM
737 int idx = zone_idx(z);
738#endif
739
740 start = z->zone_start_pfn;
741 end = start + z->spanned_pages;
742 start = max(start, node_free_pfn[nid]);
743 start = max(start, max_low_pfn);
744
745#ifdef CONFIG_HIGHMEM
746 if (idx == ZONE_HIGHMEM)
747 totalhigh_pages += z->spanned_pages;
748#endif
749 if (kdata_huge) {
750 unsigned long percpu_pfn = node_percpu_pfn[nid];
751 if (start < percpu_pfn && end > percpu_pfn)
752 end = percpu_pfn;
753 }
754#ifdef CONFIG_PCI
755 if (start <= pci_reserve_start_pfn &&
756 end > pci_reserve_start_pfn) {
757 if (end > pci_reserve_end_pfn)
758 init_free_pfn_range(pci_reserve_end_pfn, end);
759 end = pci_reserve_start_pfn;
760 }
761#endif
762 init_free_pfn_range(start, end);
763 }
764}
765#endif
766
767
768
769
770
771void __init paging_init(void)
772{
773#ifdef __tilegx__
774 pud_t *pud;
775#endif
776 pgd_t *pgd_base = swapper_pg_dir;
777
778 kernel_physical_mapping_init(pgd_base);
779
780
781
782
783
784 page_table_range_init(fix_to_virt(__end_of_fixed_addresses - 1),
785 FIXADDR_TOP, pgd_base);
786
787#ifdef CONFIG_HIGHMEM
788 permanent_kmaps_init(pgd_base);
789#endif
790
791#ifdef __tilegx__
792
793
794
795
796
797
798
799 BUILD_BUG_ON(pgd_index(VMALLOC_START) != pgd_index(VMALLOC_END - 1));
800 pud = pud_offset(pgd_base + pgd_index(VMALLOC_START), VMALLOC_START);
801 assign_pmd(pud, alloc_pmd());
802#endif
803}
804
805
806
807
808
809
810
811void __init set_page_homes(void)
812{
813}
814
815static void __init set_max_mapnr_init(void)
816{
817#ifdef CONFIG_FLATMEM
818 max_mapnr = max_low_pfn;
819#endif
820}
821
822void __init mem_init(void)
823{
824 int codesize, datasize, initsize;
825 int i;
826#ifndef __tilegx__
827 void *last;
828#endif
829
830#ifdef CONFIG_FLATMEM
831 BUG_ON(!mem_map);
832#endif
833
834#ifdef CONFIG_HIGHMEM
835
836 if (PKMAP_ADDR(LAST_PKMAP-1) >= FIXADDR_START) {
837 pr_err("fixmap and kmap areas overlap"
838 " - this will crash\n");
839 pr_err("pkstart: %lxh pkend: %lxh fixstart %lxh\n",
840 PKMAP_BASE, PKMAP_ADDR(LAST_PKMAP-1),
841 FIXADDR_START);
842 BUG();
843 }
844#endif
845
846 set_max_mapnr_init();
847
848
849 totalram_pages += free_all_bootmem();
850
851#ifndef CONFIG_64BIT
852
853 set_non_bootmem_pages_init();
854#endif
855
856 codesize = (unsigned long)&_etext - (unsigned long)&_text;
857 datasize = (unsigned long)&_end - (unsigned long)&_sdata;
858 initsize = (unsigned long)&_einittext - (unsigned long)&_sinittext;
859 initsize += (unsigned long)&_einitdata - (unsigned long)&_sinitdata;
860
861 pr_info("Memory: %luk/%luk available (%dk kernel code, %dk data, %dk init, %ldk highmem)\n",
862 (unsigned long) nr_free_pages() << (PAGE_SHIFT-10),
863 num_physpages << (PAGE_SHIFT-10),
864 codesize >> 10,
865 datasize >> 10,
866 initsize >> 10,
867 (unsigned long) (totalhigh_pages << (PAGE_SHIFT-10))
868 );
869
870
871
872
873#ifdef CONFIG_HIGHMEM
874 printk(KERN_DEBUG " KMAP %#lx - %#lx\n",
875 FIXADDR_START, FIXADDR_TOP + PAGE_SIZE - 1);
876 printk(KERN_DEBUG " PKMAP %#lx - %#lx\n",
877 PKMAP_BASE, PKMAP_ADDR(LAST_PKMAP) - 1);
878#endif
879#ifdef CONFIG_HUGEVMAP
880 printk(KERN_DEBUG " HUGEMAP %#lx - %#lx\n",
881 HUGE_VMAP_BASE, HUGE_VMAP_END - 1);
882#endif
883 printk(KERN_DEBUG " VMALLOC %#lx - %#lx\n",
884 _VMALLOC_START, _VMALLOC_END - 1);
885#ifdef __tilegx__
886 for (i = MAX_NUMNODES-1; i >= 0; --i) {
887 struct pglist_data *node = &node_data[i];
888 if (node->node_present_pages) {
889 unsigned long start = (unsigned long)
890 pfn_to_kaddr(node->node_start_pfn);
891 unsigned long end = start +
892 (node->node_present_pages << PAGE_SHIFT);
893 printk(KERN_DEBUG " MEM%d %#lx - %#lx\n",
894 i, start, end - 1);
895 }
896 }
897#else
898 last = high_memory;
899 for (i = MAX_NUMNODES-1; i >= 0; --i) {
900 if ((unsigned long)vbase_map[i] != -1UL) {
901 printk(KERN_DEBUG " LOWMEM%d %#lx - %#lx\n",
902 i, (unsigned long) (vbase_map[i]),
903 (unsigned long) (last-1));
904 last = vbase_map[i];
905 }
906 }
907#endif
908
909#ifndef __tilegx__
910
911
912
913
914 __init_atomic_per_cpu();
915#endif
916}
917
918
919
920
921
922
923#ifndef CONFIG_NEED_MULTIPLE_NODES
924int arch_add_memory(u64 start, u64 size)
925{
926 struct pglist_data *pgdata = &contig_page_data;
927 struct zone *zone = pgdata->node_zones + MAX_NR_ZONES-1;
928 unsigned long start_pfn = start >> PAGE_SHIFT;
929 unsigned long nr_pages = size >> PAGE_SHIFT;
930
931 return __add_pages(zone, start_pfn, nr_pages);
932}
933
934int remove_memory(u64 start, u64 size)
935{
936 return -EINVAL;
937}
938
939#ifdef CONFIG_MEMORY_HOTREMOVE
940int arch_remove_memory(u64 start, u64 size)
941{
942
943 return -EBUSY;
944}
945#endif
946#endif
947
948struct kmem_cache *pgd_cache;
949
950void __init pgtable_cache_init(void)
951{
952 pgd_cache = kmem_cache_create("pgd", SIZEOF_PGD, SIZEOF_PGD, 0, NULL);
953 if (!pgd_cache)
954 panic("pgtable_cache_init(): Cannot create pgd cache");
955}
956
957#if !CHIP_HAS_COHERENT_LOCAL_CACHE()
958
959
960
961
962
963static void mark_w1data_ro(void)
964{
965
966 unsigned long addr = (unsigned long)__w1data_begin;
967 BUG_ON((addr & (PAGE_SIZE-1)) != 0);
968 for (; addr <= (unsigned long)__w1data_end - 1; addr += PAGE_SIZE) {
969 unsigned long pfn = kaddr_to_pfn((void *)addr);
970 pte_t *ptep = virt_to_pte(NULL, addr);
971 BUG_ON(pte_huge(*ptep));
972 set_pte_at(&init_mm, addr, ptep, pfn_pte(pfn, PAGE_KERNEL_RO));
973 }
974}
975#endif
976
977#ifdef CONFIG_DEBUG_PAGEALLOC
978static long __write_once initfree;
979#else
980static long __write_once initfree = 1;
981#endif
982
983
984static int __init set_initfree(char *str)
985{
986 long val;
987 if (strict_strtol(str, 0, &val) == 0) {
988 initfree = val;
989 pr_info("initfree: %s free init pages\n",
990 initfree ? "will" : "won't");
991 }
992 return 1;
993}
994__setup("initfree=", set_initfree);
995
996static void free_init_pages(char *what, unsigned long begin, unsigned long end)
997{
998 unsigned long addr = (unsigned long) begin;
999
1000 if (kdata_huge && !initfree) {
1001 pr_warning("Warning: ignoring initfree=0:"
1002 " incompatible with kdata=huge\n");
1003 initfree = 1;
1004 }
1005 end = (end + PAGE_SIZE - 1) & PAGE_MASK;
1006 local_flush_tlb_pages(NULL, begin, PAGE_SIZE, end - begin);
1007 for (addr = begin; addr < end; addr += PAGE_SIZE) {
1008
1009
1010
1011
1012
1013
1014 int pfn = kaddr_to_pfn((void *)addr);
1015 struct page *page = pfn_to_page(pfn);
1016 pte_t *ptep = virt_to_pte(NULL, addr);
1017 if (!initfree) {
1018
1019
1020
1021
1022
1023
1024 pte_clear(&init_mm, addr, ptep);
1025 continue;
1026 }
1027 __ClearPageReserved(page);
1028 init_page_count(page);
1029 if (pte_huge(*ptep))
1030 BUG_ON(!kdata_huge);
1031 else
1032 set_pte_at(&init_mm, addr, ptep,
1033 pfn_pte(pfn, PAGE_KERNEL));
1034 memset((void *)addr, POISON_FREE_INITMEM, PAGE_SIZE);
1035 free_page(addr);
1036 totalram_pages++;
1037 }
1038 pr_info("Freeing %s: %ldk freed\n", what, (end - begin) >> 10);
1039}
1040
1041void free_initmem(void)
1042{
1043 const unsigned long text_delta = MEM_SV_INTRPT - PAGE_OFFSET;
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053 homecache_evict(&cpu_cacheable_map);
1054
1055
1056 free_init_pages("unused kernel data",
1057 (unsigned long)_sinitdata,
1058 (unsigned long)_einitdata);
1059
1060
1061
1062
1063
1064 free_init_pages("unused kernel text",
1065 (unsigned long)_sinittext - text_delta,
1066 (unsigned long)_einittext - text_delta);
1067
1068#if !CHIP_HAS_COHERENT_LOCAL_CACHE()
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079 mark_w1data_ro();
1080#endif
1081
1082
1083 flush_tlb_all();
1084}
1085