Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #include <linux/sched.h> |
| 2 | #include <linux/kernel.h> |
| 3 | #include <linux/errno.h> |
| 4 | #include <linux/mm.h> |
Prarit Bhargava | 27eb0b2 | 2007-10-17 18:04:34 +0200 | [diff] [blame] | 5 | #include <linux/nmi.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | #include <linux/swap.h> |
| 7 | #include <linux/smp.h> |
| 8 | #include <linux/highmem.h> |
| 9 | #include <linux/slab.h> |
| 10 | #include <linux/pagemap.h> |
| 11 | #include <linux/spinlock.h> |
Jeremy Fitzhardinge | 052e799 | 2006-09-25 23:32:25 -0700 | [diff] [blame] | 12 | #include <linux/module.h> |
Christoph Lameter | f1d1a84 | 2007-05-12 11:15:24 -0700 | [diff] [blame] | 13 | #include <linux/quicklist.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | |
| 15 | #include <asm/system.h> |
| 16 | #include <asm/pgtable.h> |
| 17 | #include <asm/pgalloc.h> |
| 18 | #include <asm/fixmap.h> |
| 19 | #include <asm/e820.h> |
| 20 | #include <asm/tlb.h> |
| 21 | #include <asm/tlbflush.h> |
| 22 | |
| 23 | void show_mem(void) |
| 24 | { |
| 25 | int total = 0, reserved = 0; |
| 26 | int shared = 0, cached = 0; |
| 27 | int highmem = 0; |
| 28 | struct page *page; |
| 29 | pg_data_t *pgdat; |
| 30 | unsigned long i; |
Dave Hansen | 208d54e | 2005-10-29 18:16:52 -0700 | [diff] [blame] | 31 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | |
Christophe Lucas | f90e718 | 2005-06-25 14:59:24 -0700 | [diff] [blame] | 33 | printk(KERN_INFO "Mem-info:\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | show_free_areas(); |
KAMEZAWA Hiroyuki | ec936fc | 2006-03-27 01:15:59 -0800 | [diff] [blame] | 35 | for_each_online_pgdat(pgdat) { |
Dave Hansen | 208d54e | 2005-10-29 18:16:52 -0700 | [diff] [blame] | 36 | pgdat_resize_lock(pgdat, &flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | for (i = 0; i < pgdat->node_spanned_pages; ++i) { |
Prarit Bhargava | 27eb0b2 | 2007-10-17 18:04:34 +0200 | [diff] [blame] | 38 | if (unlikely(i % MAX_ORDER_NR_PAGES == 0)) |
| 39 | touch_nmi_watchdog(); |
Dave Hansen | 408fde8 | 2005-06-23 00:07:37 -0700 | [diff] [blame] | 40 | page = pgdat_page_nr(pgdat, i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | total++; |
| 42 | if (PageHighMem(page)) |
| 43 | highmem++; |
| 44 | if (PageReserved(page)) |
| 45 | reserved++; |
| 46 | else if (PageSwapCache(page)) |
| 47 | cached++; |
| 48 | else if (page_count(page)) |
| 49 | shared += page_count(page) - 1; |
| 50 | } |
Dave Hansen | 208d54e | 2005-10-29 18:16:52 -0700 | [diff] [blame] | 51 | pgdat_resize_unlock(pgdat, &flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | } |
Christophe Lucas | f90e718 | 2005-06-25 14:59:24 -0700 | [diff] [blame] | 53 | printk(KERN_INFO "%d pages of RAM\n", total); |
| 54 | printk(KERN_INFO "%d pages of HIGHMEM\n", highmem); |
| 55 | printk(KERN_INFO "%d reserved pages\n", reserved); |
| 56 | printk(KERN_INFO "%d pages shared\n", shared); |
| 57 | printk(KERN_INFO "%d pages swap cached\n", cached); |
Martin J. Bligh | 6f4e1e5 | 2005-06-23 00:08:08 -0700 | [diff] [blame] | 58 | |
Christoph Lameter | b1e7a8f | 2006-06-30 01:55:39 -0700 | [diff] [blame] | 59 | printk(KERN_INFO "%lu pages dirty\n", global_page_state(NR_FILE_DIRTY)); |
Christoph Lameter | ce866b3 | 2006-06-30 01:55:40 -0700 | [diff] [blame] | 60 | printk(KERN_INFO "%lu pages writeback\n", |
| 61 | global_page_state(NR_WRITEBACK)); |
Christoph Lameter | 65ba55f | 2006-06-30 01:55:34 -0700 | [diff] [blame] | 62 | printk(KERN_INFO "%lu pages mapped\n", global_page_state(NR_FILE_MAPPED)); |
Christoph Lameter | 972d1a7 | 2006-09-25 23:31:51 -0700 | [diff] [blame] | 63 | printk(KERN_INFO "%lu pages slab\n", |
| 64 | global_page_state(NR_SLAB_RECLAIMABLE) + |
| 65 | global_page_state(NR_SLAB_UNRECLAIMABLE)); |
Christoph Lameter | df849a1 | 2006-06-30 01:55:38 -0700 | [diff] [blame] | 66 | printk(KERN_INFO "%lu pages pagetables\n", |
| 67 | global_page_state(NR_PAGETABLE)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | /* |
| 71 | * Associate a virtual page frame with a given physical page frame |
| 72 | * and protection flags for that frame. |
| 73 | */ |
| 74 | static void set_pte_pfn(unsigned long vaddr, unsigned long pfn, pgprot_t flags) |
| 75 | { |
| 76 | pgd_t *pgd; |
| 77 | pud_t *pud; |
| 78 | pmd_t *pmd; |
| 79 | pte_t *pte; |
| 80 | |
| 81 | pgd = swapper_pg_dir + pgd_index(vaddr); |
| 82 | if (pgd_none(*pgd)) { |
| 83 | BUG(); |
| 84 | return; |
| 85 | } |
| 86 | pud = pud_offset(pgd, vaddr); |
| 87 | if (pud_none(*pud)) { |
| 88 | BUG(); |
| 89 | return; |
| 90 | } |
| 91 | pmd = pmd_offset(pud, vaddr); |
| 92 | if (pmd_none(*pmd)) { |
| 93 | BUG(); |
| 94 | return; |
| 95 | } |
| 96 | pte = pte_offset_kernel(pmd, vaddr); |
Jan Beulich | b0bfece | 2006-12-07 02:14:09 +0100 | [diff] [blame] | 97 | if (pgprot_val(flags)) |
Jan Beulich | aa506dc | 2007-10-17 18:04:33 +0200 | [diff] [blame] | 98 | set_pte_present(&init_mm, vaddr, pte, pfn_pte(pfn, flags)); |
Jan Beulich | b0bfece | 2006-12-07 02:14:09 +0100 | [diff] [blame] | 99 | else |
| 100 | pte_clear(&init_mm, vaddr, pte); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | |
| 102 | /* |
| 103 | * It's enough to flush this one mapping. |
| 104 | * (PGE mappings get flushed as well) |
| 105 | */ |
| 106 | __flush_tlb_one(vaddr); |
| 107 | } |
| 108 | |
| 109 | /* |
| 110 | * Associate a large virtual page frame with a given physical page frame |
| 111 | * and protection flags for that frame. pfn is for the base of the page, |
| 112 | * vaddr is what the page gets mapped to - both must be properly aligned. |
| 113 | * The pmd must already be instantiated. Assumes PAE mode. |
| 114 | */ |
| 115 | void set_pmd_pfn(unsigned long vaddr, unsigned long pfn, pgprot_t flags) |
| 116 | { |
| 117 | pgd_t *pgd; |
| 118 | pud_t *pud; |
| 119 | pmd_t *pmd; |
| 120 | |
| 121 | if (vaddr & (PMD_SIZE-1)) { /* vaddr is misaligned */ |
Christophe Lucas | f90e718 | 2005-06-25 14:59:24 -0700 | [diff] [blame] | 122 | printk(KERN_WARNING "set_pmd_pfn: vaddr misaligned\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | return; /* BUG(); */ |
| 124 | } |
| 125 | if (pfn & (PTRS_PER_PTE-1)) { /* pfn is misaligned */ |
Christophe Lucas | f90e718 | 2005-06-25 14:59:24 -0700 | [diff] [blame] | 126 | printk(KERN_WARNING "set_pmd_pfn: pfn misaligned\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | return; /* BUG(); */ |
| 128 | } |
| 129 | pgd = swapper_pg_dir + pgd_index(vaddr); |
| 130 | if (pgd_none(*pgd)) { |
Christophe Lucas | f90e718 | 2005-06-25 14:59:24 -0700 | [diff] [blame] | 131 | printk(KERN_WARNING "set_pmd_pfn: pgd_none\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | return; /* BUG(); */ |
| 133 | } |
| 134 | pud = pud_offset(pgd, vaddr); |
| 135 | pmd = pmd_offset(pud, vaddr); |
| 136 | set_pmd(pmd, pfn_pmd(pfn, flags)); |
| 137 | /* |
| 138 | * It's enough to flush this one mapping. |
| 139 | * (PGE mappings get flushed as well) |
| 140 | */ |
| 141 | __flush_tlb_one(vaddr); |
| 142 | } |
| 143 | |
Jeremy Fitzhardinge | 052e799 | 2006-09-25 23:32:25 -0700 | [diff] [blame] | 144 | static int fixmaps; |
Jeremy Fitzhardinge | 052e799 | 2006-09-25 23:32:25 -0700 | [diff] [blame] | 145 | unsigned long __FIXADDR_TOP = 0xfffff000; |
| 146 | EXPORT_SYMBOL(__FIXADDR_TOP); |
Jeremy Fitzhardinge | 052e799 | 2006-09-25 23:32:25 -0700 | [diff] [blame] | 147 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | void __set_fixmap (enum fixed_addresses idx, unsigned long phys, pgprot_t flags) |
| 149 | { |
| 150 | unsigned long address = __fix_to_virt(idx); |
| 151 | |
| 152 | if (idx >= __end_of_fixed_addresses) { |
| 153 | BUG(); |
| 154 | return; |
| 155 | } |
| 156 | set_pte_pfn(address, phys >> PAGE_SHIFT, flags); |
Jeremy Fitzhardinge | 052e799 | 2006-09-25 23:32:25 -0700 | [diff] [blame] | 157 | fixmaps++; |
| 158 | } |
| 159 | |
| 160 | /** |
| 161 | * reserve_top_address - reserves a hole in the top of kernel address space |
| 162 | * @reserve - size of hole to reserve |
| 163 | * |
| 164 | * Can be used to relocate the fixmap area and poke a hole in the top |
| 165 | * of kernel address space to make room for a hypervisor. |
| 166 | */ |
| 167 | void reserve_top_address(unsigned long reserve) |
| 168 | { |
| 169 | BUG_ON(fixmaps > 0); |
Zachary Amsden | 7ce0bcf | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 170 | printk(KERN_INFO "Reserving virtual address space above 0x%08x\n", |
| 171 | (int)-reserve); |
Jeremy Fitzhardinge | 052e799 | 2006-09-25 23:32:25 -0700 | [diff] [blame] | 172 | __FIXADDR_TOP = -reserve - PAGE_SIZE; |
| 173 | __VMALLOC_RESERVE += reserve; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | } |