| Aurelien Jacquiot | 14aa7e8 | 2011-10-04 12:17:19 -0400 | [diff] [blame] | 1 | /* | 
 | 2 |  *  Port on Texas Instruments TMS320C6x architecture | 
 | 3 |  * | 
 | 4 |  *  Copyright (C) 2004, 2009, 2010, 2011 Texas Instruments Incorporated | 
 | 5 |  *  Author: Aurelien Jacquiot (aurelien.jacquiot@jaluna.com) | 
 | 6 |  * | 
 | 7 |  *  This program is free software; you can redistribute it and/or modify | 
 | 8 |  *  it under the terms of the GNU General Public License version 2 as | 
 | 9 |  *  published by the Free Software Foundation. | 
 | 10 |  */ | 
 | 11 | #include <linux/mm.h> | 
 | 12 | #include <linux/swap.h> | 
 | 13 | #include <linux/module.h> | 
 | 14 | #include <linux/bootmem.h> | 
 | 15 | #ifdef CONFIG_BLK_DEV_RAM | 
 | 16 | #include <linux/blkdev.h> | 
 | 17 | #endif | 
 | 18 | #include <linux/initrd.h> | 
 | 19 |  | 
 | 20 | #include <asm/sections.h> | 
 | 21 |  | 
 | 22 | /* | 
 | 23 |  * ZERO_PAGE is a special page that is used for zero-initialized | 
 | 24 |  * data and COW. | 
 | 25 |  */ | 
 | 26 | unsigned long empty_zero_page; | 
 | 27 | EXPORT_SYMBOL(empty_zero_page); | 
 | 28 |  | 
 | 29 | /* | 
 | 30 |  * paging_init() continues the virtual memory environment setup which | 
 | 31 |  * was begun by the code in arch/head.S. | 
 | 32 |  * The parameters are pointers to where to stick the starting and ending | 
 | 33 |  * addresses  of available kernel virtual memory. | 
 | 34 |  */ | 
 | 35 | void __init paging_init(void) | 
 | 36 | { | 
 | 37 | 	struct pglist_data *pgdat = NODE_DATA(0); | 
 | 38 | 	unsigned long zones_size[MAX_NR_ZONES] = {0, }; | 
 | 39 |  | 
 | 40 | 	empty_zero_page      = (unsigned long) alloc_bootmem_pages(PAGE_SIZE); | 
 | 41 | 	memset((void *)empty_zero_page, 0, PAGE_SIZE); | 
 | 42 |  | 
 | 43 | 	/* | 
 | 44 | 	 * Set up user data space | 
 | 45 | 	 */ | 
 | 46 | 	set_fs(KERNEL_DS); | 
 | 47 |  | 
 | 48 | 	/* | 
 | 49 | 	 * Define zones | 
 | 50 | 	 */ | 
 | 51 | 	zones_size[ZONE_NORMAL] = (memory_end - PAGE_OFFSET) >> PAGE_SHIFT; | 
 | 52 | 	pgdat->node_zones[ZONE_NORMAL].zone_start_pfn = | 
 | 53 | 		__pa(PAGE_OFFSET) >> PAGE_SHIFT; | 
 | 54 |  | 
 | 55 | 	free_area_init(zones_size); | 
 | 56 | } | 
 | 57 |  | 
 | 58 | void __init mem_init(void) | 
 | 59 | { | 
 | 60 | 	int codek, datak; | 
 | 61 | 	unsigned long tmp; | 
 | 62 | 	unsigned long len = memory_end - memory_start; | 
 | 63 |  | 
 | 64 | 	high_memory = (void *)(memory_end & PAGE_MASK); | 
 | 65 |  | 
 | 66 | 	/* this will put all memory onto the freelists */ | 
 | 67 | 	totalram_pages = free_all_bootmem(); | 
 | 68 |  | 
 | 69 | 	codek = (_etext - _stext) >> 10; | 
 | 70 | 	datak = (_end - _sdata) >> 10; | 
 | 71 |  | 
 | 72 | 	tmp = nr_free_pages() << PAGE_SHIFT; | 
 | 73 | 	printk(KERN_INFO "Memory: %luk/%luk RAM (%dk kernel code, %dk data)\n", | 
 | 74 | 	       tmp >> 10, len >> 10, codek, datak); | 
 | 75 | } | 
 | 76 |  | 
 | 77 | #ifdef CONFIG_BLK_DEV_INITRD | 
 | 78 | void __init free_initrd_mem(unsigned long start, unsigned long end) | 
 | 79 | { | 
 | 80 | 	int pages = 0; | 
 | 81 | 	for (; start < end; start += PAGE_SIZE) { | 
 | 82 | 		ClearPageReserved(virt_to_page(start)); | 
 | 83 | 		init_page_count(virt_to_page(start)); | 
 | 84 | 		free_page(start); | 
 | 85 | 		totalram_pages++; | 
 | 86 | 		pages++; | 
 | 87 | 	} | 
 | 88 | 	printk(KERN_INFO "Freeing initrd memory: %luk freed\n", | 
 | 89 | 	       (pages * PAGE_SIZE) >> 10); | 
 | 90 | } | 
 | 91 | #endif | 
 | 92 |  | 
 | 93 | void __init free_initmem(void) | 
 | 94 | { | 
 | 95 | 	unsigned long addr; | 
 | 96 |  | 
 | 97 | 	/* | 
 | 98 | 	 * The following code should be cool even if these sections | 
 | 99 | 	 * are not page aligned. | 
 | 100 | 	 */ | 
 | 101 | 	addr = PAGE_ALIGN((unsigned long)(__init_begin)); | 
 | 102 |  | 
 | 103 | 	/* next to check that the page we free is not a partial page */ | 
 | 104 | 	for (; addr + PAGE_SIZE < (unsigned long)(__init_end); | 
 | 105 | 	     addr += PAGE_SIZE) { | 
 | 106 | 		ClearPageReserved(virt_to_page(addr)); | 
 | 107 | 		init_page_count(virt_to_page(addr)); | 
 | 108 | 		free_page(addr); | 
 | 109 | 		totalram_pages++; | 
 | 110 | 	} | 
 | 111 | 	printk(KERN_INFO "Freeing unused kernel memory: %dK freed\n", | 
 | 112 | 	       (int) ((addr - PAGE_ALIGN((long) &__init_begin)) >> 10)); | 
 | 113 | } |