blob: 61888ff72c87ce7bb56c3ea6c269f9a8a801ce8d [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Carsten Langgaard, carstenl@mips.com
3 * Copyright (C) 1999,2000 MIPS Technologies, Inc. All rights reserved.
4 *
5 * This program is free software; you can distribute it and/or modify it
6 * under the terms of the GNU General Public License (Version 2) as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
17 *
18 * PROM library functions for acquiring/using memory descriptors given to
19 * us from the YAMON.
20 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <linux/init.h>
22#include <linux/mm.h>
23#include <linux/bootmem.h>
Ralf Baechlefde35052006-04-03 14:44:50 +010024#include <linux/pfn.h>
Ralf Baechlee01402b2005-07-14 15:57:16 +000025#include <linux/string.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070026
27#include <asm/bootinfo.h>
28#include <asm/page.h>
Ralf Baechle9c1f1252006-04-03 10:17:21 +010029#include <asm/sections.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030
31#include <asm/mips-boards/prom.h>
32
33/*#define DEBUG*/
34
35enum yamon_memtypes {
36 yamon_dontuse,
37 yamon_prom,
38 yamon_free,
39};
Dmitri Vorobievddaf5742008-04-01 02:03:22 +040040static struct prom_pmemblock mdesc[PROM_MAX_PMEMBLOCKS];
Linus Torvalds1da177e2005-04-16 15:20:36 -070041
42#ifdef DEBUG
43static char *mtypes[3] = {
44 "Dont use memory",
45 "YAMON PROM memory",
46 "Free memmory",
47};
48#endif
49
Ralf Baechlee1a4e462006-07-03 17:02:35 +010050/* determined physical memory size, not overridden by command line args */
51unsigned long physical_memsize = 0L;
52
Dmitri Vorobievddaf5742008-04-01 02:03:22 +040053static struct prom_pmemblock * __init prom_getmdesc(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070054{
55 char *memsize_str;
56 unsigned int memsize;
Ralf Baechlee01402b2005-07-14 15:57:16 +000057 char cmdline[CL_SIZE], *ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -070058
Ralf Baechlee1a4e462006-07-03 17:02:35 +010059 /* otherwise look in the environment */
60 memsize_str = prom_getenv("memsize");
61 if (!memsize_str) {
Ralf Baechle36a88532007-03-01 11:56:43 +000062 printk(KERN_WARNING
63 "memsize not set in boot prom, set to default (32Mb)\n");
Ralf Baechlee1a4e462006-07-03 17:02:35 +010064 physical_memsize = 0x02000000;
65 } else {
66#ifdef DEBUG
Ralf Baechle36a88532007-03-01 11:56:43 +000067 pr_debug("prom_memsize = %s\n", memsize_str);
Ralf Baechlee1a4e462006-07-03 17:02:35 +010068#endif
69 physical_memsize = simple_strtol(memsize_str, NULL, 0);
70 }
71
72#ifdef CONFIG_CPU_BIG_ENDIAN
73 /* SOC-it swaps, or perhaps doesn't swap, when DMA'ing the last
74 word of physical memory */
75 physical_memsize -= PAGE_SIZE;
76#endif
77
78 /* Check the command line for a memsize directive that overrides
79 the physical/default amount */
Ralf Baechlee01402b2005-07-14 15:57:16 +000080 strcpy(cmdline, arcs_cmdline);
81 ptr = strstr(cmdline, "memsize=");
82 if (ptr && (ptr != cmdline) && (*(ptr - 1) != ' '))
83 ptr = strstr(ptr, " memsize=");
84
Ralf Baechlee1a4e462006-07-03 17:02:35 +010085 if (ptr)
Ralf Baechlee01402b2005-07-14 15:57:16 +000086 memsize = memparse(ptr + 8, &ptr);
Ralf Baechlee1a4e462006-07-03 17:02:35 +010087 else
88 memsize = physical_memsize;
Elizabeth Oldham73499682006-06-06 10:57:09 +010089
Linus Torvalds1da177e2005-04-16 15:20:36 -070090 memset(mdesc, 0, sizeof(mdesc));
91
92 mdesc[0].type = yamon_dontuse;
93 mdesc[0].base = 0x00000000;
94 mdesc[0].size = 0x00001000;
95
96 mdesc[1].type = yamon_prom;
97 mdesc[1].base = 0x00001000;
98 mdesc[1].size = 0x000ef000;
99
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100 /*
101 * The area 0x000f0000-0x000fffff is allocated for BIOS memory by the
102 * south bridge and PCI access always forwarded to the ISA Bus and
103 * BIOSCS# is always generated.
104 * This mean that this area can't be used as DMA memory for PCI
105 * devices.
106 */
107 mdesc[2].type = yamon_dontuse;
108 mdesc[2].base = 0x000f0000;
109 mdesc[2].size = 0x00010000;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110
111 mdesc[3].type = yamon_dontuse;
112 mdesc[3].base = 0x00100000;
Ralf Baechlefde35052006-04-03 14:44:50 +0100113 mdesc[3].size = CPHYSADDR(PFN_ALIGN((unsigned long)&_end)) - mdesc[3].base;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114
115 mdesc[4].type = yamon_free;
Ralf Baechlefde35052006-04-03 14:44:50 +0100116 mdesc[4].base = CPHYSADDR(PFN_ALIGN(&_end));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 mdesc[4].size = memsize - mdesc[4].base;
118
119 return &mdesc[0];
120}
121
Ralf Baechle49a89ef2007-10-11 23:46:15 +0100122static int __init prom_memtype_classify(unsigned int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123{
124 switch (type) {
125 case yamon_free:
126 return BOOT_MEM_RAM;
127 case yamon_prom:
128 return BOOT_MEM_ROM_DATA;
129 default:
130 return BOOT_MEM_RESERVED;
131 }
132}
133
134void __init prom_meminit(void)
135{
136 struct prom_pmemblock *p;
137
138#ifdef DEBUG
Ralf Baechle36a88532007-03-01 11:56:43 +0000139 pr_debug("YAMON MEMORY DESCRIPTOR dump:\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 p = prom_getmdesc();
141 while (p->size) {
142 int i = 0;
Ralf Baechle36a88532007-03-01 11:56:43 +0000143 pr_debug("[%d,%p]: base<%08lx> size<%08lx> type<%s>\n",
144 i, p, p->base, p->size, mtypes[p->type]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 p++;
146 i++;
147 }
148#endif
149 p = prom_getmdesc();
150
151 while (p->size) {
152 long type;
153 unsigned long base, size;
154
Ralf Baechle49a89ef2007-10-11 23:46:15 +0100155 type = prom_memtype_classify(p->type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 base = p->base;
157 size = p->size;
158
159 add_memory_region(base, size, type);
160 p++;
161 }
162}
163
Atsushi Nemotoc44e8d52006-12-30 00:43:59 +0900164void __init prom_free_prom_memory(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 unsigned long addr;
167 int i;
168
169 for (i = 0; i < boot_mem_map.nr_map; i++) {
170 if (boot_mem_map.map[i].type != BOOT_MEM_ROM_DATA)
171 continue;
172
Atsushi Nemotoc44e8d52006-12-30 00:43:59 +0900173 addr = boot_mem_map.map[i].addr;
174 free_init_pages("prom memory",
175 addr, addr + boot_mem_map.map[i].size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177}