| 
									
										
										
										
											2005-09-30 13:59:37 +01:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Copyright (C) 2005 MIPS Technologies, Inc.  All rights reserved. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  *  This program is free software; you can distribute it and/or modify it | 
					
						
							|  |  |  |  *  under the terms of the GNU General Public License (Version 2) as | 
					
						
							|  |  |  |  *  published by the Free Software Foundation. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  *  This program is distributed in the hope it will be useful, but WITHOUT | 
					
						
							|  |  |  |  *  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | 
					
						
							|  |  |  |  *  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License | 
					
						
							|  |  |  |  *  for more details. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  *  You should have received a copy of the GNU General Public License along | 
					
						
							|  |  |  |  *  with this program; if not, write to the Free Software Foundation, Inc., | 
					
						
							|  |  |  |  *  59 Temple Place - Suite 330, Boston MA 02111-1307, USA. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | #include <linux/init.h>
 | 
					
						
							|  |  |  | #include <linux/mm.h>
 | 
					
						
							|  |  |  | #include <linux/bootmem.h>
 | 
					
						
							| 
									
										
										
										
											2006-04-03 14:44:50 +01:00
										 |  |  | #include <linux/pfn.h>
 | 
					
						
							| 
									
										
										
										
											2005-09-30 13:59:37 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include <asm/bootinfo.h>
 | 
					
						
							|  |  |  | #include <asm/page.h>
 | 
					
						
							| 
									
										
										
										
											2006-04-03 10:17:21 +01:00
										 |  |  | #include <asm/sections.h>
 | 
					
						
							| 
									
										
										
										
											2005-09-30 13:59:37 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include <asm/mips-boards/prom.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*#define DEBUG*/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | enum simmem_memtypes { | 
					
						
							|  |  |  | 	simmem_reserved = 0, | 
					
						
							|  |  |  | 	simmem_free, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | struct prom_pmemblock mdesc[PROM_MAX_PMEMBLOCKS]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifdef DEBUG
 | 
					
						
							|  |  |  | static char *mtypes[3] = { | 
					
						
							|  |  |  | 	"SIM reserved memory", | 
					
						
							|  |  |  | 	"SIM free memory", | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | struct prom_pmemblock * __init prom_getmdesc(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	unsigned int memsize; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	memsize = 0x02000000; | 
					
						
							| 
									
										
										
										
											2007-03-01 11:56:43 +00:00
										 |  |  | 	pr_info("Setting default memory size 0x%08x\n", memsize); | 
					
						
							| 
									
										
										
										
											2005-09-30 13:59:37 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	memset(mdesc, 0, sizeof(mdesc)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	mdesc[0].type = simmem_reserved; | 
					
						
							|  |  |  | 	mdesc[0].base = 0x00000000; | 
					
						
							|  |  |  | 	mdesc[0].size = 0x00001000; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	mdesc[1].type = simmem_free; | 
					
						
							|  |  |  | 	mdesc[1].base = 0x00001000; | 
					
						
							|  |  |  | 	mdesc[1].size = 0x000ff000; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	mdesc[2].type = simmem_reserved; | 
					
						
							|  |  |  | 	mdesc[2].base = 0x00100000; | 
					
						
							| 
									
										
										
										
											2006-04-03 14:44:50 +01:00
										 |  |  | 	mdesc[2].size = CPHYSADDR(PFN_ALIGN(&_end)) - mdesc[2].base; | 
					
						
							| 
									
										
										
										
											2005-09-30 13:59:37 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	mdesc[3].type = simmem_free; | 
					
						
							| 
									
										
										
										
											2006-04-03 14:44:50 +01:00
										 |  |  | 	mdesc[3].base = CPHYSADDR(PFN_ALIGN(&_end)); | 
					
						
							| 
									
										
										
										
											2005-09-30 13:59:37 +01:00
										 |  |  | 	mdesc[3].size = memsize - mdesc[3].base; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return &mdesc[0]; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-10-11 23:46:15 +01:00
										 |  |  | static int __init prom_memtype_classify(unsigned int type) | 
					
						
							| 
									
										
										
										
											2005-09-30 13:59:37 +01:00
										 |  |  | { | 
					
						
							|  |  |  | 	switch (type) { | 
					
						
							|  |  |  | 	case simmem_free: | 
					
						
							|  |  |  | 		return BOOT_MEM_RAM; | 
					
						
							|  |  |  | 	case simmem_reserved: | 
					
						
							|  |  |  | 	default: | 
					
						
							|  |  |  | 		return BOOT_MEM_RESERVED; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void __init prom_meminit(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct prom_pmemblock *p; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	p = prom_getmdesc(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	while (p->size) { | 
					
						
							|  |  |  | 		long type; | 
					
						
							|  |  |  | 		unsigned long base, size; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-10-11 23:46:15 +01:00
										 |  |  | 		type = prom_memtype_classify(p->type); | 
					
						
							| 
									
										
										
										
											2005-09-30 13:59:37 +01:00
										 |  |  | 		base = p->base; | 
					
						
							|  |  |  | 		size = p->size; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		add_memory_region(base, size, type); | 
					
						
							| 
									
										
										
										
											2007-07-10 17:32:56 +01:00
										 |  |  | 		p++; | 
					
						
							| 
									
										
										
										
											2005-09-30 13:59:37 +01:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-12-30 00:43:59 +09:00
										 |  |  | void __init prom_free_prom_memory(void) | 
					
						
							| 
									
										
										
										
											2005-09-30 13:59:37 +01:00
										 |  |  | { | 
					
						
							|  |  |  | 	int i; | 
					
						
							|  |  |  | 	unsigned long addr; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (i = 0; i < boot_mem_map.nr_map; i++) { | 
					
						
							|  |  |  | 		if (boot_mem_map.map[i].type != BOOT_MEM_ROM_DATA) | 
					
						
							|  |  |  | 			continue; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		addr = boot_mem_map.map[i].addr; | 
					
						
							| 
									
										
										
										
											2006-12-30 00:43:59 +09:00
										 |  |  | 		free_init_pages("prom memory", | 
					
						
							|  |  |  | 				addr, addr + boot_mem_map.map[i].size); | 
					
						
							| 
									
										
										
										
											2005-09-30 13:59:37 +01:00
										 |  |  | 	} | 
					
						
							|  |  |  | } |