| Florian Fainelli | 7ca5dc1 | 2009-06-24 11:12:57 +0200 | [diff] [blame] | 1 | /* | 
 | 2 |  * Copyright (C) 2007 Felix Fietkau <nbd@openwrt.org> | 
 | 3 |  * Copyright (C) 2007 Eugene Konev <ejka@openwrt.org> | 
 | 4 |  * | 
 | 5 |  * This program is free software; you can redistribute it and/or modify | 
 | 6 |  * it under the terms of the GNU General Public License as published by | 
 | 7 |  * the Free Software Foundation; either version 2 of the License, or | 
 | 8 |  * (at your option) any later version. | 
 | 9 |  * | 
 | 10 |  * This program is distributed in the hope that it will be useful, | 
 | 11 |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
 | 12 |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
 | 13 |  * GNU General Public License for more details. | 
 | 14 |  * | 
 | 15 |  * You should have received a copy of the GNU General Public License | 
 | 16 |  * along with this program; if not, write to the Free Software | 
 | 17 |  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA | 
 | 18 |  */ | 
 | 19 | #include <linux/bootmem.h> | 
 | 20 | #include <linux/init.h> | 
 | 21 | #include <linux/mm.h> | 
 | 22 | #include <linux/module.h> | 
 | 23 | #include <linux/pfn.h> | 
 | 24 | #include <linux/proc_fs.h> | 
 | 25 | #include <linux/string.h> | 
 | 26 | #include <linux/swap.h> | 
 | 27 |  | 
 | 28 | #include <asm/bootinfo.h> | 
 | 29 | #include <asm/page.h> | 
 | 30 | #include <asm/sections.h> | 
 | 31 |  | 
 | 32 | #include <asm/mach-ar7/ar7.h> | 
 | 33 | #include <asm/mips-boards/prom.h> | 
 | 34 |  | 
 | 35 | static int __init memsize(void) | 
 | 36 | { | 
 | 37 | 	u32 size = (64 << 20); | 
 | 38 | 	u32 *addr = (u32 *)KSEG1ADDR(AR7_SDRAM_BASE + size - 4); | 
 | 39 | 	u32 *kernel_end = (u32 *)KSEG1ADDR(CPHYSADDR((u32)&_end)); | 
 | 40 | 	u32 *tmpaddr = addr; | 
 | 41 |  | 
 | 42 | 	while (tmpaddr > kernel_end) { | 
 | 43 | 		*tmpaddr = (u32)tmpaddr; | 
 | 44 | 		size >>= 1; | 
 | 45 | 		tmpaddr -= size >> 2; | 
 | 46 | 	} | 
 | 47 |  | 
 | 48 | 	do { | 
 | 49 | 		tmpaddr += size >> 2; | 
 | 50 | 		if (*tmpaddr != (u32)tmpaddr) | 
 | 51 | 			break; | 
 | 52 | 		size <<= 1; | 
 | 53 | 	} while (size < (64 << 20)); | 
 | 54 |  | 
| Florian Fainelli | dd34b5a | 2009-07-21 12:38:10 +0200 | [diff] [blame] | 55 | 	writel((u32)tmpaddr, &addr); | 
| Florian Fainelli | 7ca5dc1 | 2009-06-24 11:12:57 +0200 | [diff] [blame] | 56 |  | 
 | 57 | 	return size; | 
 | 58 | } | 
 | 59 |  | 
 | 60 | void __init prom_meminit(void) | 
 | 61 | { | 
 | 62 | 	unsigned long pages; | 
 | 63 |  | 
 | 64 | 	pages = memsize() >> PAGE_SHIFT; | 
| Alexander Clouter | 4d1da8c | 2010-01-31 19:38:19 +0000 | [diff] [blame] | 65 | 	add_memory_region(PHYS_OFFSET, pages << PAGE_SHIFT, BOOT_MEM_RAM); | 
| Florian Fainelli | 7ca5dc1 | 2009-06-24 11:12:57 +0200 | [diff] [blame] | 66 | } | 
 | 67 |  | 
 | 68 | void __init prom_free_prom_memory(void) | 
 | 69 | { | 
 | 70 | 	/* Nothing to free */ | 
 | 71 | } |