| Ralf Baechle | c78cbf4 | 2005-09-30 13:59:37 +0100 | [diff] [blame] | 1 | /* | 
 | 2 |  * Copyright (C) 2005 MIPS Technologies, Inc.  All rights reserved. | 
 | 3 |  * | 
 | 4 |  *  This program is free software; you can distribute it and/or modify it | 
 | 5 |  *  under the terms of the GNU General Public License (Version 2) as | 
 | 6 |  *  published by the Free Software Foundation. | 
 | 7 |  * | 
 | 8 |  *  This program is distributed in the hope it will be useful, but WITHOUT | 
 | 9 |  *  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | 
 | 10 |  *  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License | 
 | 11 |  *  for more details. | 
 | 12 |  * | 
 | 13 |  *  You should have received a copy of the GNU General Public License along | 
 | 14 |  *  with this program; if not, write to the Free Software Foundation, Inc., | 
 | 15 |  *  59 Temple Place - Suite 330, Boston MA 02111-1307, USA. | 
 | 16 |  * | 
 | 17 |  */ | 
 | 18 | #include <linux/init.h> | 
 | 19 | #include <linux/mm.h> | 
 | 20 | #include <linux/bootmem.h> | 
| Ralf Baechle | fde3505 | 2006-04-03 14:44:50 +0100 | [diff] [blame] | 21 | #include <linux/pfn.h> | 
| Ralf Baechle | c78cbf4 | 2005-09-30 13:59:37 +0100 | [diff] [blame] | 22 |  | 
 | 23 | #include <asm/bootinfo.h> | 
 | 24 | #include <asm/page.h> | 
| Ralf Baechle | 9c1f125 | 2006-04-03 10:17:21 +0100 | [diff] [blame] | 25 | #include <asm/sections.h> | 
| Ralf Baechle | c78cbf4 | 2005-09-30 13:59:37 +0100 | [diff] [blame] | 26 |  | 
 | 27 | #include <asm/mips-boards/prom.h> | 
 | 28 |  | 
 | 29 | /*#define DEBUG*/ | 
 | 30 |  | 
 | 31 | enum simmem_memtypes { | 
 | 32 | 	simmem_reserved = 0, | 
 | 33 | 	simmem_free, | 
 | 34 | }; | 
 | 35 | struct prom_pmemblock mdesc[PROM_MAX_PMEMBLOCKS]; | 
 | 36 |  | 
 | 37 | #ifdef DEBUG | 
 | 38 | static char *mtypes[3] = { | 
 | 39 | 	"SIM reserved memory", | 
 | 40 | 	"SIM free memory", | 
 | 41 | }; | 
 | 42 | #endif | 
 | 43 |  | 
| Ralf Baechle | c78cbf4 | 2005-09-30 13:59:37 +0100 | [diff] [blame] | 44 | struct prom_pmemblock * __init prom_getmdesc(void) | 
 | 45 | { | 
 | 46 | 	unsigned int memsize; | 
 | 47 |  | 
 | 48 | 	memsize = 0x02000000; | 
| Ralf Baechle | 36a8853 | 2007-03-01 11:56:43 +0000 | [diff] [blame] | 49 | 	pr_info("Setting default memory size 0x%08x\n", memsize); | 
| Ralf Baechle | c78cbf4 | 2005-09-30 13:59:37 +0100 | [diff] [blame] | 50 |  | 
 | 51 | 	memset(mdesc, 0, sizeof(mdesc)); | 
 | 52 |  | 
 | 53 | 	mdesc[0].type = simmem_reserved; | 
 | 54 | 	mdesc[0].base = 0x00000000; | 
 | 55 | 	mdesc[0].size = 0x00001000; | 
 | 56 |  | 
 | 57 | 	mdesc[1].type = simmem_free; | 
 | 58 | 	mdesc[1].base = 0x00001000; | 
 | 59 | 	mdesc[1].size = 0x000ff000; | 
 | 60 |  | 
 | 61 | 	mdesc[2].type = simmem_reserved; | 
 | 62 | 	mdesc[2].base = 0x00100000; | 
| Ralf Baechle | fde3505 | 2006-04-03 14:44:50 +0100 | [diff] [blame] | 63 | 	mdesc[2].size = CPHYSADDR(PFN_ALIGN(&_end)) - mdesc[2].base; | 
| Ralf Baechle | c78cbf4 | 2005-09-30 13:59:37 +0100 | [diff] [blame] | 64 |  | 
 | 65 | 	mdesc[3].type = simmem_free; | 
| Ralf Baechle | fde3505 | 2006-04-03 14:44:50 +0100 | [diff] [blame] | 66 | 	mdesc[3].base = CPHYSADDR(PFN_ALIGN(&_end)); | 
| Ralf Baechle | c78cbf4 | 2005-09-30 13:59:37 +0100 | [diff] [blame] | 67 | 	mdesc[3].size = memsize - mdesc[3].base; | 
 | 68 |  | 
 | 69 | 	return &mdesc[0]; | 
 | 70 | } | 
 | 71 |  | 
| Ralf Baechle | 49a89ef | 2007-10-11 23:46:15 +0100 | [diff] [blame] | 72 | static int __init prom_memtype_classify(unsigned int type) | 
| Ralf Baechle | c78cbf4 | 2005-09-30 13:59:37 +0100 | [diff] [blame] | 73 | { | 
 | 74 | 	switch (type) { | 
 | 75 | 	case simmem_free: | 
 | 76 | 		return BOOT_MEM_RAM; | 
 | 77 | 	case simmem_reserved: | 
 | 78 | 	default: | 
 | 79 | 		return BOOT_MEM_RESERVED; | 
 | 80 | 	} | 
 | 81 | } | 
 | 82 |  | 
 | 83 | void __init prom_meminit(void) | 
 | 84 | { | 
 | 85 | 	struct prom_pmemblock *p; | 
 | 86 |  | 
 | 87 | 	p = prom_getmdesc(); | 
 | 88 |  | 
 | 89 | 	while (p->size) { | 
 | 90 | 		long type; | 
 | 91 | 		unsigned long base, size; | 
 | 92 |  | 
| Ralf Baechle | 49a89ef | 2007-10-11 23:46:15 +0100 | [diff] [blame] | 93 | 		type = prom_memtype_classify(p->type); | 
| Ralf Baechle | c78cbf4 | 2005-09-30 13:59:37 +0100 | [diff] [blame] | 94 | 		base = p->base; | 
 | 95 | 		size = p->size; | 
 | 96 |  | 
 | 97 | 		add_memory_region(base, size, type); | 
| Ralf Baechle | f6e2373 | 2007-07-10 17:32:56 +0100 | [diff] [blame] | 98 | 		p++; | 
| Ralf Baechle | c78cbf4 | 2005-09-30 13:59:37 +0100 | [diff] [blame] | 99 | 	} | 
 | 100 | } | 
 | 101 |  | 
| Atsushi Nemoto | c44e8d5 | 2006-12-30 00:43:59 +0900 | [diff] [blame] | 102 | void __init prom_free_prom_memory(void) | 
| Ralf Baechle | c78cbf4 | 2005-09-30 13:59:37 +0100 | [diff] [blame] | 103 | { | 
 | 104 | 	int i; | 
| Ralf Baechle | c78cbf4 | 2005-09-30 13:59:37 +0100 | [diff] [blame] | 105 | 	unsigned long addr; | 
 | 106 |  | 
 | 107 | 	for (i = 0; i < boot_mem_map.nr_map; i++) { | 
 | 108 | 		if (boot_mem_map.map[i].type != BOOT_MEM_ROM_DATA) | 
 | 109 | 			continue; | 
 | 110 |  | 
 | 111 | 		addr = boot_mem_map.map[i].addr; | 
| Atsushi Nemoto | c44e8d5 | 2006-12-30 00:43:59 +0900 | [diff] [blame] | 112 | 		free_init_pages("prom memory", | 
 | 113 | 				addr, addr + boot_mem_map.map[i].size); | 
| Ralf Baechle | c78cbf4 | 2005-09-30 13:59:37 +0100 | [diff] [blame] | 114 | 	} | 
| Ralf Baechle | c78cbf4 | 2005-09-30 13:59:37 +0100 | [diff] [blame] | 115 | } |