Heiko Carstens | f4eb07c | 2006-12-08 15:56:07 +0100 | [diff] [blame] | 1 | /* |
| 2 | * arch/s390/mm/vmem.c |
| 3 | * |
| 4 | * Copyright IBM Corp. 2006 |
| 5 | * Author(s): Heiko Carstens <heiko.carstens@de.ibm.com> |
| 6 | */ |
| 7 | |
| 8 | #include <linux/bootmem.h> |
| 9 | #include <linux/pfn.h> |
| 10 | #include <linux/mm.h> |
| 11 | #include <linux/module.h> |
| 12 | #include <linux/list.h> |
Gerald Schaefer | 53492b1 | 2008-04-30 13:38:46 +0200 | [diff] [blame] | 13 | #include <linux/hugetlb.h> |
Heiko Carstens | f4eb07c | 2006-12-08 15:56:07 +0100 | [diff] [blame] | 14 | #include <asm/pgalloc.h> |
| 15 | #include <asm/pgtable.h> |
| 16 | #include <asm/setup.h> |
| 17 | #include <asm/tlbflush.h> |
Gerald Schaefer | 53492b1 | 2008-04-30 13:38:46 +0200 | [diff] [blame] | 18 | #include <asm/sections.h> |
Heiko Carstens | f4eb07c | 2006-12-08 15:56:07 +0100 | [diff] [blame] | 19 | |
Heiko Carstens | f4eb07c | 2006-12-08 15:56:07 +0100 | [diff] [blame] | 20 | static DEFINE_MUTEX(vmem_mutex); |
| 21 | |
| 22 | struct memory_segment { |
| 23 | struct list_head list; |
| 24 | unsigned long start; |
| 25 | unsigned long size; |
| 26 | }; |
| 27 | |
| 28 | static LIST_HEAD(mem_segs); |
| 29 | |
Heiko Carstens | 67060d9 | 2008-05-30 10:03:27 +0200 | [diff] [blame] | 30 | static void __ref *vmem_alloc_pages(unsigned int order) |
| 31 | { |
| 32 | if (slab_is_available()) |
| 33 | return (void *)__get_free_pages(GFP_KERNEL, order); |
| 34 | return alloc_bootmem_pages((1 << order) * PAGE_SIZE); |
| 35 | } |
| 36 | |
| 37 | static inline pud_t *vmem_pud_alloc(void) |
Martin Schwidefsky | 5a216a2 | 2008-02-09 18:24:36 +0100 | [diff] [blame] | 38 | { |
| 39 | pud_t *pud = NULL; |
| 40 | |
| 41 | #ifdef CONFIG_64BIT |
Heiko Carstens | 67060d9 | 2008-05-30 10:03:27 +0200 | [diff] [blame] | 42 | pud = vmem_alloc_pages(2); |
Martin Schwidefsky | 5a216a2 | 2008-02-09 18:24:36 +0100 | [diff] [blame] | 43 | if (!pud) |
| 44 | return NULL; |
Heiko Carstens | 8fc6365 | 2008-04-30 13:38:44 +0200 | [diff] [blame] | 45 | clear_table((unsigned long *) pud, _REGION3_ENTRY_EMPTY, PAGE_SIZE * 4); |
Martin Schwidefsky | 5a216a2 | 2008-02-09 18:24:36 +0100 | [diff] [blame] | 46 | #endif |
| 47 | return pud; |
| 48 | } |
Martin Schwidefsky | 190a1d7 | 2007-10-22 12:52:48 +0200 | [diff] [blame] | 49 | |
Heiko Carstens | 67060d9 | 2008-05-30 10:03:27 +0200 | [diff] [blame] | 50 | static inline pmd_t *vmem_pmd_alloc(void) |
Heiko Carstens | f4eb07c | 2006-12-08 15:56:07 +0100 | [diff] [blame] | 51 | { |
Martin Schwidefsky | 3610cce | 2007-10-22 12:52:47 +0200 | [diff] [blame] | 52 | pmd_t *pmd = NULL; |
Heiko Carstens | f4eb07c | 2006-12-08 15:56:07 +0100 | [diff] [blame] | 53 | |
Martin Schwidefsky | 3610cce | 2007-10-22 12:52:47 +0200 | [diff] [blame] | 54 | #ifdef CONFIG_64BIT |
Heiko Carstens | 67060d9 | 2008-05-30 10:03:27 +0200 | [diff] [blame] | 55 | pmd = vmem_alloc_pages(2); |
Heiko Carstens | f4eb07c | 2006-12-08 15:56:07 +0100 | [diff] [blame] | 56 | if (!pmd) |
| 57 | return NULL; |
Heiko Carstens | 8fc6365 | 2008-04-30 13:38:44 +0200 | [diff] [blame] | 58 | clear_table((unsigned long *) pmd, _SEGMENT_ENTRY_EMPTY, PAGE_SIZE * 4); |
Martin Schwidefsky | 3610cce | 2007-10-22 12:52:47 +0200 | [diff] [blame] | 59 | #endif |
Heiko Carstens | f4eb07c | 2006-12-08 15:56:07 +0100 | [diff] [blame] | 60 | return pmd; |
| 61 | } |
| 62 | |
Heiko Carstens | 2069e97 | 2008-05-15 16:52:31 +0200 | [diff] [blame] | 63 | static pte_t __ref *vmem_pte_alloc(void) |
Heiko Carstens | f4eb07c | 2006-12-08 15:56:07 +0100 | [diff] [blame] | 64 | { |
Martin Schwidefsky | 146e4b3 | 2008-02-09 18:24:35 +0100 | [diff] [blame] | 65 | pte_t *pte; |
Heiko Carstens | f4eb07c | 2006-12-08 15:56:07 +0100 | [diff] [blame] | 66 | |
Martin Schwidefsky | 146e4b3 | 2008-02-09 18:24:35 +0100 | [diff] [blame] | 67 | if (slab_is_available()) |
| 68 | pte = (pte_t *) page_table_alloc(&init_mm); |
| 69 | else |
| 70 | pte = alloc_bootmem(PTRS_PER_PTE * sizeof(pte_t)); |
Heiko Carstens | f4eb07c | 2006-12-08 15:56:07 +0100 | [diff] [blame] | 71 | if (!pte) |
| 72 | return NULL; |
Martin Schwidefsky | 146e4b3 | 2008-02-09 18:24:35 +0100 | [diff] [blame] | 73 | clear_table((unsigned long *) pte, _PAGE_TYPE_EMPTY, |
| 74 | PTRS_PER_PTE * sizeof(pte_t)); |
Heiko Carstens | f4eb07c | 2006-12-08 15:56:07 +0100 | [diff] [blame] | 75 | return pte; |
| 76 | } |
| 77 | |
| 78 | /* |
| 79 | * Add a physical memory range to the 1:1 mapping. |
| 80 | */ |
Heiko Carstens | 17f3458 | 2008-04-30 13:38:47 +0200 | [diff] [blame] | 81 | static int vmem_add_mem(unsigned long start, unsigned long size, int ro) |
Heiko Carstens | f4eb07c | 2006-12-08 15:56:07 +0100 | [diff] [blame] | 82 | { |
| 83 | unsigned long address; |
| 84 | pgd_t *pg_dir; |
Martin Schwidefsky | 190a1d7 | 2007-10-22 12:52:48 +0200 | [diff] [blame] | 85 | pud_t *pu_dir; |
Heiko Carstens | f4eb07c | 2006-12-08 15:56:07 +0100 | [diff] [blame] | 86 | pmd_t *pm_dir; |
| 87 | pte_t *pt_dir; |
| 88 | pte_t pte; |
| 89 | int ret = -ENOMEM; |
| 90 | |
| 91 | for (address = start; address < start + size; address += PAGE_SIZE) { |
| 92 | pg_dir = pgd_offset_k(address); |
| 93 | if (pgd_none(*pg_dir)) { |
Martin Schwidefsky | 190a1d7 | 2007-10-22 12:52:48 +0200 | [diff] [blame] | 94 | pu_dir = vmem_pud_alloc(); |
| 95 | if (!pu_dir) |
| 96 | goto out; |
| 97 | pgd_populate_kernel(&init_mm, pg_dir, pu_dir); |
| 98 | } |
| 99 | |
| 100 | pu_dir = pud_offset(pg_dir, address); |
| 101 | if (pud_none(*pu_dir)) { |
Heiko Carstens | f4eb07c | 2006-12-08 15:56:07 +0100 | [diff] [blame] | 102 | pm_dir = vmem_pmd_alloc(); |
| 103 | if (!pm_dir) |
| 104 | goto out; |
Martin Schwidefsky | 190a1d7 | 2007-10-22 12:52:48 +0200 | [diff] [blame] | 105 | pud_populate_kernel(&init_mm, pu_dir, pm_dir); |
Heiko Carstens | f4eb07c | 2006-12-08 15:56:07 +0100 | [diff] [blame] | 106 | } |
| 107 | |
Gerald Schaefer | 53492b1 | 2008-04-30 13:38:46 +0200 | [diff] [blame] | 108 | pte = mk_pte_phys(address, __pgprot(ro ? _PAGE_RO : 0)); |
Martin Schwidefsky | 190a1d7 | 2007-10-22 12:52:48 +0200 | [diff] [blame] | 109 | pm_dir = pmd_offset(pu_dir, address); |
Gerald Schaefer | 53492b1 | 2008-04-30 13:38:46 +0200 | [diff] [blame] | 110 | |
| 111 | #ifdef __s390x__ |
| 112 | if (MACHINE_HAS_HPAGE && !(address & ~HPAGE_MASK) && |
| 113 | (address + HPAGE_SIZE <= start + size) && |
| 114 | (address >= HPAGE_SIZE)) { |
| 115 | pte_val(pte) |= _SEGMENT_ENTRY_LARGE; |
| 116 | pmd_val(*pm_dir) = pte_val(pte); |
| 117 | address += HPAGE_SIZE - PAGE_SIZE; |
| 118 | continue; |
| 119 | } |
| 120 | #endif |
Heiko Carstens | f4eb07c | 2006-12-08 15:56:07 +0100 | [diff] [blame] | 121 | if (pmd_none(*pm_dir)) { |
| 122 | pt_dir = vmem_pte_alloc(); |
| 123 | if (!pt_dir) |
| 124 | goto out; |
| 125 | pmd_populate_kernel(&init_mm, pm_dir, pt_dir); |
| 126 | } |
| 127 | |
| 128 | pt_dir = pte_offset_kernel(pm_dir, address); |
Gerald Schaefer | c1821c2 | 2007-02-05 21:18:17 +0100 | [diff] [blame] | 129 | *pt_dir = pte; |
Heiko Carstens | f4eb07c | 2006-12-08 15:56:07 +0100 | [diff] [blame] | 130 | } |
| 131 | ret = 0; |
| 132 | out: |
| 133 | flush_tlb_kernel_range(start, start + size); |
| 134 | return ret; |
| 135 | } |
| 136 | |
| 137 | /* |
| 138 | * Remove a physical memory range from the 1:1 mapping. |
| 139 | * Currently only invalidates page table entries. |
| 140 | */ |
| 141 | static void vmem_remove_range(unsigned long start, unsigned long size) |
| 142 | { |
| 143 | unsigned long address; |
| 144 | pgd_t *pg_dir; |
Martin Schwidefsky | 190a1d7 | 2007-10-22 12:52:48 +0200 | [diff] [blame] | 145 | pud_t *pu_dir; |
Heiko Carstens | f4eb07c | 2006-12-08 15:56:07 +0100 | [diff] [blame] | 146 | pmd_t *pm_dir; |
| 147 | pte_t *pt_dir; |
| 148 | pte_t pte; |
| 149 | |
| 150 | pte_val(pte) = _PAGE_TYPE_EMPTY; |
| 151 | for (address = start; address < start + size; address += PAGE_SIZE) { |
| 152 | pg_dir = pgd_offset_k(address); |
Martin Schwidefsky | 190a1d7 | 2007-10-22 12:52:48 +0200 | [diff] [blame] | 153 | pu_dir = pud_offset(pg_dir, address); |
| 154 | if (pud_none(*pu_dir)) |
Heiko Carstens | f4eb07c | 2006-12-08 15:56:07 +0100 | [diff] [blame] | 155 | continue; |
Martin Schwidefsky | 190a1d7 | 2007-10-22 12:52:48 +0200 | [diff] [blame] | 156 | pm_dir = pmd_offset(pu_dir, address); |
Heiko Carstens | f4eb07c | 2006-12-08 15:56:07 +0100 | [diff] [blame] | 157 | if (pmd_none(*pm_dir)) |
| 158 | continue; |
Gerald Schaefer | 53492b1 | 2008-04-30 13:38:46 +0200 | [diff] [blame] | 159 | |
| 160 | if (pmd_huge(*pm_dir)) { |
| 161 | pmd_clear_kernel(pm_dir); |
| 162 | address += HPAGE_SIZE - PAGE_SIZE; |
| 163 | continue; |
| 164 | } |
| 165 | |
Heiko Carstens | f4eb07c | 2006-12-08 15:56:07 +0100 | [diff] [blame] | 166 | pt_dir = pte_offset_kernel(pm_dir, address); |
Gerald Schaefer | c1821c2 | 2007-02-05 21:18:17 +0100 | [diff] [blame] | 167 | *pt_dir = pte; |
Heiko Carstens | f4eb07c | 2006-12-08 15:56:07 +0100 | [diff] [blame] | 168 | } |
| 169 | flush_tlb_kernel_range(start, start + size); |
| 170 | } |
| 171 | |
| 172 | /* |
| 173 | * Add a backed mem_map array to the virtual mem_map array. |
| 174 | */ |
Heiko Carstens | 17f3458 | 2008-04-30 13:38:47 +0200 | [diff] [blame] | 175 | int __meminit vmemmap_populate(struct page *start, unsigned long nr, int node) |
Heiko Carstens | f4eb07c | 2006-12-08 15:56:07 +0100 | [diff] [blame] | 176 | { |
| 177 | unsigned long address, start_addr, end_addr; |
Heiko Carstens | f4eb07c | 2006-12-08 15:56:07 +0100 | [diff] [blame] | 178 | pgd_t *pg_dir; |
Martin Schwidefsky | 190a1d7 | 2007-10-22 12:52:48 +0200 | [diff] [blame] | 179 | pud_t *pu_dir; |
Heiko Carstens | f4eb07c | 2006-12-08 15:56:07 +0100 | [diff] [blame] | 180 | pmd_t *pm_dir; |
| 181 | pte_t *pt_dir; |
| 182 | pte_t pte; |
| 183 | int ret = -ENOMEM; |
| 184 | |
Heiko Carstens | 17f3458 | 2008-04-30 13:38:47 +0200 | [diff] [blame] | 185 | start_addr = (unsigned long) start; |
| 186 | end_addr = (unsigned long) (start + nr); |
Heiko Carstens | f4eb07c | 2006-12-08 15:56:07 +0100 | [diff] [blame] | 187 | |
| 188 | for (address = start_addr; address < end_addr; address += PAGE_SIZE) { |
| 189 | pg_dir = pgd_offset_k(address); |
| 190 | if (pgd_none(*pg_dir)) { |
Martin Schwidefsky | 190a1d7 | 2007-10-22 12:52:48 +0200 | [diff] [blame] | 191 | pu_dir = vmem_pud_alloc(); |
| 192 | if (!pu_dir) |
| 193 | goto out; |
| 194 | pgd_populate_kernel(&init_mm, pg_dir, pu_dir); |
| 195 | } |
| 196 | |
| 197 | pu_dir = pud_offset(pg_dir, address); |
| 198 | if (pud_none(*pu_dir)) { |
Heiko Carstens | f4eb07c | 2006-12-08 15:56:07 +0100 | [diff] [blame] | 199 | pm_dir = vmem_pmd_alloc(); |
| 200 | if (!pm_dir) |
| 201 | goto out; |
Martin Schwidefsky | 190a1d7 | 2007-10-22 12:52:48 +0200 | [diff] [blame] | 202 | pud_populate_kernel(&init_mm, pu_dir, pm_dir); |
Heiko Carstens | f4eb07c | 2006-12-08 15:56:07 +0100 | [diff] [blame] | 203 | } |
| 204 | |
Martin Schwidefsky | 190a1d7 | 2007-10-22 12:52:48 +0200 | [diff] [blame] | 205 | pm_dir = pmd_offset(pu_dir, address); |
Heiko Carstens | f4eb07c | 2006-12-08 15:56:07 +0100 | [diff] [blame] | 206 | if (pmd_none(*pm_dir)) { |
| 207 | pt_dir = vmem_pte_alloc(); |
| 208 | if (!pt_dir) |
| 209 | goto out; |
| 210 | pmd_populate_kernel(&init_mm, pm_dir, pt_dir); |
| 211 | } |
| 212 | |
| 213 | pt_dir = pte_offset_kernel(pm_dir, address); |
| 214 | if (pte_none(*pt_dir)) { |
| 215 | unsigned long new_page; |
| 216 | |
Heiko Carstens | 67060d9 | 2008-05-30 10:03:27 +0200 | [diff] [blame] | 217 | new_page =__pa(vmem_alloc_pages(0)); |
Heiko Carstens | f4eb07c | 2006-12-08 15:56:07 +0100 | [diff] [blame] | 218 | if (!new_page) |
| 219 | goto out; |
| 220 | pte = pfn_pte(new_page >> PAGE_SHIFT, PAGE_KERNEL); |
Gerald Schaefer | c1821c2 | 2007-02-05 21:18:17 +0100 | [diff] [blame] | 221 | *pt_dir = pte; |
Heiko Carstens | f4eb07c | 2006-12-08 15:56:07 +0100 | [diff] [blame] | 222 | } |
| 223 | } |
Heiko Carstens | 67060d9 | 2008-05-30 10:03:27 +0200 | [diff] [blame] | 224 | memset(start, 0, nr * sizeof(struct page)); |
Heiko Carstens | f4eb07c | 2006-12-08 15:56:07 +0100 | [diff] [blame] | 225 | ret = 0; |
| 226 | out: |
| 227 | flush_tlb_kernel_range(start_addr, end_addr); |
| 228 | return ret; |
| 229 | } |
| 230 | |
Heiko Carstens | f4eb07c | 2006-12-08 15:56:07 +0100 | [diff] [blame] | 231 | /* |
| 232 | * Add memory segment to the segment list if it doesn't overlap with |
| 233 | * an already present segment. |
| 234 | */ |
| 235 | static int insert_memory_segment(struct memory_segment *seg) |
| 236 | { |
| 237 | struct memory_segment *tmp; |
| 238 | |
Heiko Carstens | ee0ddad | 2008-06-10 10:03:20 +0200 | [diff] [blame] | 239 | if (seg->start + seg->size > VMEM_MAX_PHYS || |
Heiko Carstens | f4eb07c | 2006-12-08 15:56:07 +0100 | [diff] [blame] | 240 | seg->start + seg->size < seg->start) |
| 241 | return -ERANGE; |
| 242 | |
| 243 | list_for_each_entry(tmp, &mem_segs, list) { |
| 244 | if (seg->start >= tmp->start + tmp->size) |
| 245 | continue; |
| 246 | if (seg->start + seg->size <= tmp->start) |
| 247 | continue; |
| 248 | return -ENOSPC; |
| 249 | } |
| 250 | list_add(&seg->list, &mem_segs); |
| 251 | return 0; |
| 252 | } |
| 253 | |
| 254 | /* |
| 255 | * Remove memory segment from the segment list. |
| 256 | */ |
| 257 | static void remove_memory_segment(struct memory_segment *seg) |
| 258 | { |
| 259 | list_del(&seg->list); |
| 260 | } |
| 261 | |
| 262 | static void __remove_shared_memory(struct memory_segment *seg) |
| 263 | { |
| 264 | remove_memory_segment(seg); |
| 265 | vmem_remove_range(seg->start, seg->size); |
| 266 | } |
| 267 | |
Heiko Carstens | 17f3458 | 2008-04-30 13:38:47 +0200 | [diff] [blame] | 268 | int vmem_remove_mapping(unsigned long start, unsigned long size) |
Heiko Carstens | f4eb07c | 2006-12-08 15:56:07 +0100 | [diff] [blame] | 269 | { |
| 270 | struct memory_segment *seg; |
| 271 | int ret; |
| 272 | |
| 273 | mutex_lock(&vmem_mutex); |
| 274 | |
| 275 | ret = -ENOENT; |
| 276 | list_for_each_entry(seg, &mem_segs, list) { |
| 277 | if (seg->start == start && seg->size == size) |
| 278 | break; |
| 279 | } |
| 280 | |
| 281 | if (seg->start != start || seg->size != size) |
| 282 | goto out; |
| 283 | |
| 284 | ret = 0; |
| 285 | __remove_shared_memory(seg); |
| 286 | kfree(seg); |
| 287 | out: |
| 288 | mutex_unlock(&vmem_mutex); |
| 289 | return ret; |
| 290 | } |
| 291 | |
Heiko Carstens | 17f3458 | 2008-04-30 13:38:47 +0200 | [diff] [blame] | 292 | int vmem_add_mapping(unsigned long start, unsigned long size) |
Heiko Carstens | f4eb07c | 2006-12-08 15:56:07 +0100 | [diff] [blame] | 293 | { |
| 294 | struct memory_segment *seg; |
Heiko Carstens | f4eb07c | 2006-12-08 15:56:07 +0100 | [diff] [blame] | 295 | int ret; |
| 296 | |
| 297 | mutex_lock(&vmem_mutex); |
| 298 | ret = -ENOMEM; |
| 299 | seg = kzalloc(sizeof(*seg), GFP_KERNEL); |
| 300 | if (!seg) |
| 301 | goto out; |
| 302 | seg->start = start; |
| 303 | seg->size = size; |
| 304 | |
| 305 | ret = insert_memory_segment(seg); |
| 306 | if (ret) |
| 307 | goto out_free; |
| 308 | |
Gerald Schaefer | 53492b1 | 2008-04-30 13:38:46 +0200 | [diff] [blame] | 309 | ret = vmem_add_mem(start, size, 0); |
Heiko Carstens | f4eb07c | 2006-12-08 15:56:07 +0100 | [diff] [blame] | 310 | if (ret) |
| 311 | goto out_remove; |
Heiko Carstens | f4eb07c | 2006-12-08 15:56:07 +0100 | [diff] [blame] | 312 | goto out; |
| 313 | |
| 314 | out_remove: |
| 315 | __remove_shared_memory(seg); |
| 316 | out_free: |
| 317 | kfree(seg); |
| 318 | out: |
| 319 | mutex_unlock(&vmem_mutex); |
| 320 | return ret; |
| 321 | } |
| 322 | |
| 323 | /* |
| 324 | * map whole physical memory to virtual memory (identity mapping) |
Christian Borntraeger | 5fd9c6e | 2008-01-26 14:11:00 +0100 | [diff] [blame] | 325 | * we reserve enough space in the vmalloc area for vmemmap to hotplug |
| 326 | * additional memory segments. |
Heiko Carstens | f4eb07c | 2006-12-08 15:56:07 +0100 | [diff] [blame] | 327 | */ |
| 328 | void __init vmem_map_init(void) |
| 329 | { |
Gerald Schaefer | 53492b1 | 2008-04-30 13:38:46 +0200 | [diff] [blame] | 330 | unsigned long ro_start, ro_end; |
| 331 | unsigned long start, end; |
Heiko Carstens | f4eb07c | 2006-12-08 15:56:07 +0100 | [diff] [blame] | 332 | int i; |
| 333 | |
Martin Schwidefsky | 50aa98b | 2009-09-11 10:28:57 +0200 | [diff] [blame] | 334 | spin_lock_init(&init_mm.context.list_lock); |
Martin Schwidefsky | 146e4b3 | 2008-02-09 18:24:35 +0100 | [diff] [blame] | 335 | INIT_LIST_HEAD(&init_mm.context.crst_list); |
| 336 | INIT_LIST_HEAD(&init_mm.context.pgtable_list); |
| 337 | init_mm.context.noexec = 0; |
Gerald Schaefer | 53492b1 | 2008-04-30 13:38:46 +0200 | [diff] [blame] | 338 | ro_start = ((unsigned long)&_stext) & PAGE_MASK; |
| 339 | ro_end = PFN_ALIGN((unsigned long)&_eshared); |
| 340 | for (i = 0; i < MEMORY_CHUNKS && memory_chunk[i].size > 0; i++) { |
| 341 | start = memory_chunk[i].addr; |
| 342 | end = memory_chunk[i].addr + memory_chunk[i].size; |
| 343 | if (start >= ro_end || end <= ro_start) |
| 344 | vmem_add_mem(start, end - start, 0); |
| 345 | else if (start >= ro_start && end <= ro_end) |
| 346 | vmem_add_mem(start, end - start, 1); |
| 347 | else if (start >= ro_start) { |
| 348 | vmem_add_mem(start, ro_end - start, 1); |
| 349 | vmem_add_mem(ro_end, end - ro_end, 0); |
| 350 | } else if (end < ro_end) { |
| 351 | vmem_add_mem(start, ro_start - start, 0); |
| 352 | vmem_add_mem(ro_start, end - ro_start, 1); |
| 353 | } else { |
| 354 | vmem_add_mem(start, ro_start - start, 0); |
| 355 | vmem_add_mem(ro_start, ro_end - ro_start, 1); |
| 356 | vmem_add_mem(ro_end, end - ro_end, 0); |
| 357 | } |
| 358 | } |
Heiko Carstens | f4eb07c | 2006-12-08 15:56:07 +0100 | [diff] [blame] | 359 | } |
| 360 | |
| 361 | /* |
| 362 | * Convert memory chunk array to a memory segment list so there is a single |
| 363 | * list that contains both r/w memory and shared memory segments. |
| 364 | */ |
| 365 | static int __init vmem_convert_memory_chunk(void) |
| 366 | { |
| 367 | struct memory_segment *seg; |
| 368 | int i; |
| 369 | |
| 370 | mutex_lock(&vmem_mutex); |
Heiko Carstens | 9f4b0ba | 2008-01-26 14:11:02 +0100 | [diff] [blame] | 371 | for (i = 0; i < MEMORY_CHUNKS; i++) { |
Heiko Carstens | f4eb07c | 2006-12-08 15:56:07 +0100 | [diff] [blame] | 372 | if (!memory_chunk[i].size) |
| 373 | continue; |
| 374 | seg = kzalloc(sizeof(*seg), GFP_KERNEL); |
| 375 | if (!seg) |
| 376 | panic("Out of memory...\n"); |
| 377 | seg->start = memory_chunk[i].addr; |
| 378 | seg->size = memory_chunk[i].size; |
| 379 | insert_memory_segment(seg); |
| 380 | } |
| 381 | mutex_unlock(&vmem_mutex); |
| 382 | return 0; |
| 383 | } |
| 384 | |
| 385 | core_initcall(vmem_convert_memory_chunk); |