upgrade to linux 2.6.10-1.12_FC2
[linux-2.6.git] / arch / arm / mm / mm-armv.c
1 /*
2  *  linux/arch/arm/mm/mm-armv.c
3  *
4  *  Copyright (C) 1998-2002 Russell King
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  *  Page table sludge for ARM v3 and v4 processor architectures.
11  */
12 #include <linux/config.h>
13 #include <linux/module.h>
14 #include <linux/mm.h>
15 #include <linux/init.h>
16 #include <linux/bootmem.h>
17 #include <linux/highmem.h>
18
19 #include <asm/pgalloc.h>
20 #include <asm/page.h>
21 #include <asm/io.h>
22 #include <asm/setup.h>
23 #include <asm/tlbflush.h>
24
25 #include <asm/mach/map.h>
26
27 #define CPOLICY_UNCACHED        0
28 #define CPOLICY_BUFFERED        1
29 #define CPOLICY_WRITETHROUGH    2
30 #define CPOLICY_WRITEBACK       3
31 #define CPOLICY_WRITEALLOC      4
32
33 static unsigned int cachepolicy __initdata = CPOLICY_WRITEBACK;
34 static unsigned int ecc_mask __initdata = 0;
35 pgprot_t pgprot_kernel;
36
37 EXPORT_SYMBOL(pgprot_kernel);
38
39 struct cachepolicy {
40         const char      policy[16];
41         unsigned int    cr_mask;
42         unsigned int    pmd;
43         unsigned int    pte;
44 };
45
46 static struct cachepolicy cache_policies[] __initdata = {
47         {
48                 .policy         = "uncached",
49                 .cr_mask        = CR_W|CR_C,
50                 .pmd            = PMD_SECT_UNCACHED,
51                 .pte            = 0,
52         }, {
53                 .policy         = "buffered",
54                 .cr_mask        = CR_C,
55                 .pmd            = PMD_SECT_BUFFERED,
56                 .pte            = PTE_BUFFERABLE,
57         }, {
58                 .policy         = "writethrough",
59                 .cr_mask        = 0,
60                 .pmd            = PMD_SECT_WT,
61                 .pte            = PTE_CACHEABLE,
62         }, {
63                 .policy         = "writeback",
64                 .cr_mask        = 0,
65                 .pmd            = PMD_SECT_WB,
66                 .pte            = PTE_BUFFERABLE|PTE_CACHEABLE,
67         }, {
68                 .policy         = "writealloc",
69                 .cr_mask        = 0,
70                 .pmd            = PMD_SECT_WBWA,
71                 .pte            = PTE_BUFFERABLE|PTE_CACHEABLE,
72         }
73 };
74
75 /*
76  * These are useful for identifing cache coherency
77  * problems by allowing the cache or the cache and
78  * writebuffer to be turned off.  (Note: the write
79  * buffer should not be on and the cache off).
80  */
81 static void __init early_cachepolicy(char **p)
82 {
83         int i;
84
85         for (i = 0; i < ARRAY_SIZE(cache_policies); i++) {
86                 int len = strlen(cache_policies[i].policy);
87
88                 if (memcmp(*p, cache_policies[i].policy, len) == 0) {
89                         cachepolicy = i;
90                         cr_alignment &= ~cache_policies[i].cr_mask;
91                         cr_no_alignment &= ~cache_policies[i].cr_mask;
92                         *p += len;
93                         break;
94                 }
95         }
96         if (i == ARRAY_SIZE(cache_policies))
97                 printk(KERN_ERR "ERROR: unknown or unsupported cache policy\n");
98         flush_cache_all();
99         set_cr(cr_alignment);
100 }
101
102 static void __init early_nocache(char **__unused)
103 {
104         char *p = "buffered";
105         printk(KERN_WARNING "nocache is deprecated; use cachepolicy=%s\n", p);
106         early_cachepolicy(&p);
107 }
108
109 static void __init early_nowrite(char **__unused)
110 {
111         char *p = "uncached";
112         printk(KERN_WARNING "nowb is deprecated; use cachepolicy=%s\n", p);
113         early_cachepolicy(&p);
114 }
115
116 static void __init early_ecc(char **p)
117 {
118         if (memcmp(*p, "on", 2) == 0) {
119                 ecc_mask = PMD_PROTECTION;
120                 *p += 2;
121         } else if (memcmp(*p, "off", 3) == 0) {
122                 ecc_mask = 0;
123                 *p += 3;
124         }
125 }
126
127 __early_param("nocache", early_nocache);
128 __early_param("nowb", early_nowrite);
129 __early_param("cachepolicy=", early_cachepolicy);
130 __early_param("ecc=", early_ecc);
131
132 static int __init noalign_setup(char *__unused)
133 {
134         cr_alignment &= ~CR_A;
135         cr_no_alignment &= ~CR_A;
136         set_cr(cr_alignment);
137         return 1;
138 }
139
140 __setup("noalign", noalign_setup);
141
142 #define FIRST_KERNEL_PGD_NR     (FIRST_USER_PGD_NR + USER_PTRS_PER_PGD)
143
144 /*
145  * need to get a 16k page for level 1
146  */
147 pgd_t *get_pgd_slow(struct mm_struct *mm)
148 {
149         pgd_t *new_pgd, *init_pgd;
150         pmd_t *new_pmd, *init_pmd;
151         pte_t *new_pte, *init_pte;
152
153         new_pgd = (pgd_t *)__get_free_pages(GFP_KERNEL, 2);
154         if (!new_pgd)
155                 goto no_pgd;
156
157         memzero(new_pgd, FIRST_KERNEL_PGD_NR * sizeof(pgd_t));
158
159         init_pgd = pgd_offset_k(0);
160
161         if (!vectors_high()) {
162                 /*
163                  * This lock is here just to satisfy pmd_alloc and pte_lock
164                  */
165                 spin_lock(&mm->page_table_lock);
166
167                 /*
168                  * On ARM, first page must always be allocated since it
169                  * contains the machine vectors.
170                  */
171                 new_pmd = pmd_alloc(mm, new_pgd, 0);
172                 if (!new_pmd)
173                         goto no_pmd;
174
175                 new_pte = pte_alloc_map(mm, new_pmd, 0);
176                 if (!new_pte)
177                         goto no_pte;
178
179                 init_pmd = pmd_offset(init_pgd, 0);
180                 init_pte = pte_offset_map_nested(init_pmd, 0);
181                 set_pte(new_pte, *init_pte);
182                 pte_unmap_nested(init_pte);
183                 pte_unmap(new_pte);
184
185                 spin_unlock(&mm->page_table_lock);
186         }
187
188         /*
189          * Copy over the kernel and IO PGD entries
190          */
191         memcpy(new_pgd + FIRST_KERNEL_PGD_NR, init_pgd + FIRST_KERNEL_PGD_NR,
192                        (PTRS_PER_PGD - FIRST_KERNEL_PGD_NR) * sizeof(pgd_t));
193
194         clean_dcache_area(new_pgd, PTRS_PER_PGD * sizeof(pgd_t));
195
196         return new_pgd;
197
198 no_pte:
199         spin_unlock(&mm->page_table_lock);
200         pmd_free(new_pmd);
201         free_pages((unsigned long)new_pgd, 2);
202         return NULL;
203
204 no_pmd:
205         spin_unlock(&mm->page_table_lock);
206         free_pages((unsigned long)new_pgd, 2);
207         return NULL;
208
209 no_pgd:
210         return NULL;
211 }
212
213 void free_pgd_slow(pgd_t *pgd)
214 {
215         pmd_t *pmd;
216         struct page *pte;
217
218         if (!pgd)
219                 return;
220
221         /* pgd is always present and good */
222         pmd = (pmd_t *)pgd;
223         if (pmd_none(*pmd))
224                 goto free;
225         if (pmd_bad(*pmd)) {
226                 pmd_ERROR(*pmd);
227                 pmd_clear(pmd);
228                 goto free;
229         }
230
231         pte = pmd_page(*pmd);
232         pmd_clear(pmd);
233         dec_page_state(nr_page_table_pages);
234         pte_free(pte);
235         pmd_free(pmd);
236 free:
237         free_pages((unsigned long) pgd, 2);
238 }
239
240 /*
241  * Create a SECTION PGD between VIRT and PHYS in domain
242  * DOMAIN with protection PROT
243  */
244 static inline void
245 alloc_init_section(unsigned long virt, unsigned long phys, int prot)
246 {
247         pmd_t *pmdp;
248
249         pmdp = pmd_offset(pgd_offset_k(virt), virt);
250         if (virt & (1 << 20))
251                 pmdp++;
252
253         set_pmd(pmdp, __pmd(phys | prot));
254 }
255
256 /*
257  * Add a PAGE mapping between VIRT and PHYS in domain
258  * DOMAIN with protection PROT.  Note that due to the
259  * way we map the PTEs, we must allocate two PTE_SIZE'd
260  * blocks - one for the Linux pte table, and one for
261  * the hardware pte table.
262  */
263 static inline void
264 alloc_init_page(unsigned long virt, unsigned long phys, unsigned int prot_l1, pgprot_t prot)
265 {
266         pmd_t *pmdp;
267         pte_t *ptep;
268
269         pmdp = pmd_offset(pgd_offset_k(virt), virt);
270
271         if (pmd_none(*pmdp)) {
272                 unsigned long pmdval;
273                 ptep = alloc_bootmem_low_pages(2 * PTRS_PER_PTE *
274                                                sizeof(pte_t));
275
276                 pmdval = __pa(ptep) | prot_l1;
277                 pmdp[0] = __pmd(pmdval);
278                 pmdp[1] = __pmd(pmdval + 256 * sizeof(pte_t));
279                 flush_pmd_entry(pmdp);
280         }
281         ptep = pte_offset_kernel(pmdp, virt);
282
283         set_pte(ptep, pfn_pte(phys >> PAGE_SHIFT, prot));
284 }
285
286 /*
287  * Clear any PGD mapping.  On a two-level page table system,
288  * the clearance is done by the middle-level functions (pmd)
289  * rather than the top-level (pgd) functions.
290  */
291 static inline void clear_mapping(unsigned long virt)
292 {
293         pmd_clear(pmd_offset(pgd_offset_k(virt), virt));
294 }
295
296 struct mem_types {
297         unsigned int    prot_pte;
298         unsigned int    prot_l1;
299         unsigned int    prot_sect;
300         unsigned int    domain;
301 };
302
303 static struct mem_types mem_types[] __initdata = {
304         [MT_DEVICE] = {
305                 .prot_pte  = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
306                                 L_PTE_WRITE,
307                 .prot_l1   = PMD_TYPE_TABLE,
308                 .prot_sect = PMD_TYPE_SECT | PMD_SECT_UNCACHED |
309                                 PMD_SECT_AP_WRITE,
310                 .domain    = DOMAIN_IO,
311         },
312         [MT_CACHECLEAN] = {
313                 .prot_sect = PMD_TYPE_SECT,
314                 .domain    = DOMAIN_KERNEL,
315         },
316         [MT_MINICLEAN] = {
317                 .prot_sect = PMD_TYPE_SECT | PMD_SECT_MINICACHE,
318                 .domain    = DOMAIN_KERNEL,
319         },
320         [MT_LOW_VECTORS] = {
321                 .prot_pte  = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
322                                 L_PTE_EXEC,
323                 .prot_l1   = PMD_TYPE_TABLE,
324                 .domain    = DOMAIN_USER,
325         },
326         [MT_HIGH_VECTORS] = {
327                 .prot_pte  = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
328                                 L_PTE_USER | L_PTE_EXEC,
329                 .prot_l1   = PMD_TYPE_TABLE,
330                 .domain    = DOMAIN_USER,
331         },
332         [MT_MEMORY] = {
333                 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
334                 .domain    = DOMAIN_KERNEL,
335         },
336         [MT_ROM] = {
337                 .prot_sect = PMD_TYPE_SECT,
338                 .domain    = DOMAIN_KERNEL,
339         }
340 };
341
342 /*
343  * Adjust the PMD section entries according to the CPU in use.
344  */
345 static void __init build_mem_type_table(void)
346 {
347         struct cachepolicy *cp;
348         unsigned int cr = get_cr();
349         int cpu_arch = cpu_architecture();
350         int i;
351
352 #if defined(CONFIG_CPU_DCACHE_DISABLE)
353         if (cachepolicy > CPOLICY_BUFFERED)
354                 cachepolicy = CPOLICY_BUFFERED;
355 #elif defined(CONFIG_CPU_DCACHE_WRITETHROUGH)
356         if (cachepolicy > CPOLICY_WRITETHROUGH)
357                 cachepolicy = CPOLICY_WRITETHROUGH;
358 #endif
359         if (cpu_arch < CPU_ARCH_ARMv5) {
360                 if (cachepolicy >= CPOLICY_WRITEALLOC)
361                         cachepolicy = CPOLICY_WRITEBACK;
362                 ecc_mask = 0;
363         }
364
365         if (cpu_arch <= CPU_ARCH_ARMv5) {
366                 for (i = 0; i < ARRAY_SIZE(mem_types); i++) {
367                         if (mem_types[i].prot_l1)
368                                 mem_types[i].prot_l1 |= PMD_BIT4;
369                         if (mem_types[i].prot_sect)
370                                 mem_types[i].prot_sect |= PMD_BIT4;
371                 }
372         }
373
374         /*
375          * ARMv6 and above have extended page tables.
376          */
377         if (cpu_arch >= CPU_ARCH_ARMv6 && (cr & CR_XP)) {
378                 /*
379                  * bit 4 becomes XN which we must clear for the
380                  * kernel memory mapping.
381                  */
382                 mem_types[MT_MEMORY].prot_sect &= ~PMD_BIT4;
383                 mem_types[MT_ROM].prot_sect &= ~PMD_BIT4;
384                 /*
385                  * Mark cache clean areas read only from SVC mode
386                  * and no access from userspace.
387                  */
388                 mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
389                 mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
390         }
391
392         cp = &cache_policies[cachepolicy];
393
394         if (cpu_arch >= CPU_ARCH_ARMv5) {
395                 mem_types[MT_LOW_VECTORS].prot_pte |= cp->pte & PTE_CACHEABLE;
396                 mem_types[MT_HIGH_VECTORS].prot_pte |= cp->pte & PTE_CACHEABLE;
397         } else {
398                 mem_types[MT_LOW_VECTORS].prot_pte |= cp->pte;
399                 mem_types[MT_HIGH_VECTORS].prot_pte |= cp->pte;
400                 mem_types[MT_MINICLEAN].prot_sect &= ~PMD_SECT_TEX(1);
401         }
402
403         mem_types[MT_LOW_VECTORS].prot_l1 |= ecc_mask;
404         mem_types[MT_HIGH_VECTORS].prot_l1 |= ecc_mask;
405         mem_types[MT_MEMORY].prot_sect |= ecc_mask | cp->pmd;
406         mem_types[MT_ROM].prot_sect |= cp->pmd;
407
408         for (i = 0; i < 16; i++) {
409                 unsigned long v = pgprot_val(protection_map[i]);
410                 v &= (~(PTE_BUFFERABLE|PTE_CACHEABLE)) | cp->pte;
411                 protection_map[i] = __pgprot(v);
412         }
413
414         pgprot_kernel = __pgprot(L_PTE_PRESENT | L_PTE_YOUNG |
415                                  L_PTE_DIRTY | L_PTE_WRITE |
416                                  L_PTE_EXEC | cp->pte);
417
418         switch (cp->pmd) {
419         case PMD_SECT_WT:
420                 mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_WT;
421                 break;
422         case PMD_SECT_WB:
423         case PMD_SECT_WBWA:
424                 mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_WB;
425                 break;
426         }
427         printk("Memory policy: ECC %sabled, Data cache %s\n",
428                 ecc_mask ? "en" : "dis", cp->policy);
429 }
430
431 #define vectors_base()  (vectors_high() ? 0xffff0000 : 0)
432
433 /*
434  * Create the page directory entries and any necessary
435  * page tables for the mapping specified by `md'.  We
436  * are able to cope here with varying sizes and address
437  * offsets, and we take full advantage of sections.
438  */
439 static void __init create_mapping(struct map_desc *md)
440 {
441         unsigned long virt, length;
442         int prot_sect, prot_l1, domain;
443         pgprot_t prot_pte;
444         long off;
445
446         if (md->virtual != vectors_base() && md->virtual < TASK_SIZE) {
447                 printk(KERN_WARNING "BUG: not creating mapping for "
448                        "0x%08lx at 0x%08lx in user region\n",
449                        md->physical, md->virtual);
450                 return;
451         }
452
453         if ((md->type == MT_DEVICE || md->type == MT_ROM) &&
454             md->virtual >= PAGE_OFFSET && md->virtual < VMALLOC_END) {
455                 printk(KERN_WARNING "BUG: mapping for 0x%08lx at 0x%08lx "
456                        "overlaps vmalloc space\n",
457                        md->physical, md->virtual);
458         }
459
460         domain    = mem_types[md->type].domain;
461         prot_pte  = __pgprot(mem_types[md->type].prot_pte);
462         prot_l1   = mem_types[md->type].prot_l1 | PMD_DOMAIN(domain);
463         prot_sect = mem_types[md->type].prot_sect | PMD_DOMAIN(domain);
464
465         virt   = md->virtual;
466         off    = md->physical - virt;
467         length = md->length;
468
469         if (mem_types[md->type].prot_l1 == 0 &&
470             (virt & 0xfffff || (virt + off) & 0xfffff || (virt + length) & 0xfffff)) {
471                 printk(KERN_WARNING "BUG: map for 0x%08lx at 0x%08lx can not "
472                        "be mapped using pages, ignoring.\n",
473                        md->physical, md->virtual);
474                 return;
475         }
476
477         while ((virt & 0xfffff || (virt + off) & 0xfffff) && length >= PAGE_SIZE) {
478                 alloc_init_page(virt, virt + off, prot_l1, prot_pte);
479
480                 virt   += PAGE_SIZE;
481                 length -= PAGE_SIZE;
482         }
483
484         while (length >= (PGDIR_SIZE / 2)) {
485                 alloc_init_section(virt, virt + off, prot_sect);
486
487                 virt   += (PGDIR_SIZE / 2);
488                 length -= (PGDIR_SIZE / 2);
489         }
490
491         while (length >= PAGE_SIZE) {
492                 alloc_init_page(virt, virt + off, prot_l1, prot_pte);
493
494                 virt   += PAGE_SIZE;
495                 length -= PAGE_SIZE;
496         }
497 }
498
499 /*
500  * In order to soft-boot, we need to insert a 1:1 mapping in place of
501  * the user-mode pages.  This will then ensure that we have predictable
502  * results when turning the mmu off
503  */
504 void setup_mm_for_reboot(char mode)
505 {
506         unsigned long pmdval;
507         pgd_t *pgd;
508         pmd_t *pmd;
509         int i;
510         int cpu_arch = cpu_architecture();
511
512         if (current->mm && current->mm->pgd)
513                 pgd = current->mm->pgd;
514         else
515                 pgd = init_mm.pgd;
516
517         for (i = 0; i < FIRST_USER_PGD_NR + USER_PTRS_PER_PGD; i++) {
518                 pmdval = (i << PGDIR_SHIFT) |
519                          PMD_SECT_AP_WRITE | PMD_SECT_AP_READ |
520                          PMD_TYPE_SECT;
521                 if (cpu_arch <= CPU_ARCH_ARMv5)
522                         pmdval |= PMD_BIT4;
523                 pmd = pmd_offset(pgd + i, i << PGDIR_SHIFT);
524                 set_pmd(pmd, __pmd(pmdval));
525         }
526 }
527
528 extern void _stext, _etext;
529
530 /*
531  * Setup initial mappings.  We use the page we allocated for zero page to hold
532  * the mappings, which will get overwritten by the vectors in traps_init().
533  * The mappings must be in virtual address order.
534  */
535 void __init memtable_init(struct meminfo *mi)
536 {
537         struct map_desc *init_maps, *p, *q;
538         unsigned long address = 0;
539         int i;
540
541         build_mem_type_table();
542
543         init_maps = p = alloc_bootmem_low_pages(PAGE_SIZE);
544
545 #ifdef CONFIG_XIP_KERNEL
546         p->physical   = CONFIG_XIP_PHYS_ADDR & PMD_MASK;
547         p->virtual    = (unsigned long)&_stext & PMD_MASK;
548         p->length     = ((unsigned long)&_etext - p->virtual + ~PMD_MASK) & PMD_MASK;
549         p->type       = MT_ROM;
550         p ++;
551 #endif
552
553         for (i = 0; i < mi->nr_banks; i++) {
554                 if (mi->bank[i].size == 0)
555                         continue;
556
557                 p->physical   = mi->bank[i].start;
558                 p->virtual    = __phys_to_virt(p->physical);
559                 p->length     = mi->bank[i].size;
560                 p->type       = MT_MEMORY;
561                 p ++;
562         }
563
564 #ifdef FLUSH_BASE
565         p->physical   = FLUSH_BASE_PHYS;
566         p->virtual    = FLUSH_BASE;
567         p->length     = PGDIR_SIZE;
568         p->type       = MT_CACHECLEAN;
569         p ++;
570 #endif
571
572 #ifdef FLUSH_BASE_MINICACHE
573         p->physical   = FLUSH_BASE_PHYS + PGDIR_SIZE;
574         p->virtual    = FLUSH_BASE_MINICACHE;
575         p->length     = PGDIR_SIZE;
576         p->type       = MT_MINICLEAN;
577         p ++;
578 #endif
579
580         /*
581          * Go through the initial mappings, but clear out any
582          * pgdir entries that are not in the description.
583          */
584         q = init_maps;
585         do {
586                 if (address < q->virtual || q == p) {
587                         clear_mapping(address);
588                         address += PGDIR_SIZE;
589                 } else {
590                         create_mapping(q);
591
592                         address = q->virtual + q->length;
593                         address = (address + PGDIR_SIZE - 1) & PGDIR_MASK;
594
595                         q ++;
596                 }
597         } while (address != 0);
598
599         /*
600          * Create a mapping for the machine vectors at the high-vectors
601          * location (0xffff0000).  If we aren't using high-vectors, also
602          * create a mapping at the low-vectors virtual address.
603          */
604         init_maps->physical   = virt_to_phys(init_maps);
605         init_maps->virtual    = 0xffff0000;
606         init_maps->length     = PAGE_SIZE;
607         init_maps->type       = MT_HIGH_VECTORS;
608         create_mapping(init_maps);
609
610         if (!vectors_high()) {
611                 init_maps->virtual = 0;
612                 init_maps->type = MT_LOW_VECTORS;
613                 create_mapping(init_maps);
614         }
615
616         flush_cache_all();
617         flush_tlb_all();
618 }
619
620 /*
621  * Create the architecture specific mappings
622  */
623 void __init iotable_init(struct map_desc *io_desc, int nr)
624 {
625         int i;
626
627         for (i = 0; i < nr; i++)
628                 create_mapping(io_desc + i);
629 }
630
631 static inline void
632 free_memmap(int node, unsigned long start_pfn, unsigned long end_pfn)
633 {
634         struct page *start_pg, *end_pg;
635         unsigned long pg, pgend;
636
637         /*
638          * Convert start_pfn/end_pfn to a struct page pointer.
639          */
640         start_pg = pfn_to_page(start_pfn);
641         end_pg = pfn_to_page(end_pfn);
642
643         /*
644          * Convert to physical addresses, and
645          * round start upwards and end downwards.
646          */
647         pg = PAGE_ALIGN(__pa(start_pg));
648         pgend = __pa(end_pg) & PAGE_MASK;
649
650         /*
651          * If there are free pages between these,
652          * free the section of the memmap array.
653          */
654         if (pg < pgend)
655                 free_bootmem_node(NODE_DATA(node), pg, pgend - pg);
656 }
657
658 static inline void free_unused_memmap_node(int node, struct meminfo *mi)
659 {
660         unsigned long bank_start, prev_bank_end = 0;
661         unsigned int i;
662
663         /*
664          * [FIXME] This relies on each bank being in address order.  This
665          * may not be the case, especially if the user has provided the
666          * information on the command line.
667          */
668         for (i = 0; i < mi->nr_banks; i++) {
669                 if (mi->bank[i].size == 0 || mi->bank[i].node != node)
670                         continue;
671
672                 bank_start = mi->bank[i].start >> PAGE_SHIFT;
673                 if (bank_start < prev_bank_end) {
674                         printk(KERN_ERR "MEM: unordered memory banks.  "
675                                 "Not freeing memmap.\n");
676                         break;
677                 }
678
679                 /*
680                  * If we had a previous bank, and there is a space
681                  * between the current bank and the previous, free it.
682                  */
683                 if (prev_bank_end && prev_bank_end != bank_start)
684                         free_memmap(node, prev_bank_end, bank_start);
685
686                 prev_bank_end = PAGE_ALIGN(mi->bank[i].start +
687                                            mi->bank[i].size) >> PAGE_SHIFT;
688         }
689 }
690
691 /*
692  * The mem_map array can get very big.  Free
693  * the unused area of the memory map.
694  */
695 void __init create_memmap_holes(struct meminfo *mi)
696 {
697         int node;
698
699         for (node = 0; node < numnodes; node++)
700                 free_unused_memmap_node(node, mi);
701 }