Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | #include <linux/init.h> |
| 22 | #include <linux/mm.h> |
| 23 | #include <linux/bootmem.h> |
Ralf Baechle | fde3505 | 2006-04-03 14:44:50 +0100 | [diff] [blame] | 24 | #include <linux/pfn.h> |
Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 25 | #include <linux/string.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | |
| 27 | #include <asm/bootinfo.h> |
| 28 | #include <asm/page.h> |
Ralf Baechle | 9c1f125 | 2006-04-03 10:17:21 +0100 | [diff] [blame] | 29 | #include <asm/sections.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | |
| 31 | #include <asm/mips-boards/prom.h> |
| 32 | |
| 33 | /*#define DEBUG*/ |
| 34 | |
| 35 | enum yamon_memtypes { |
| 36 | yamon_dontuse, |
| 37 | yamon_prom, |
| 38 | yamon_free, |
| 39 | }; |
| 40 | struct prom_pmemblock mdesc[PROM_MAX_PMEMBLOCKS]; |
| 41 | |
| 42 | #ifdef DEBUG |
| 43 | static char *mtypes[3] = { |
| 44 | "Dont use memory", |
| 45 | "YAMON PROM memory", |
| 46 | "Free memmory", |
| 47 | }; |
| 48 | #endif |
| 49 | |
Ralf Baechle | e1a4e46 | 2006-07-03 17:02:35 +0100 | [diff] [blame^] | 50 | /* determined physical memory size, not overridden by command line args */ |
| 51 | unsigned long physical_memsize = 0L; |
| 52 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | struct prom_pmemblock * __init prom_getmdesc(void) |
| 54 | { |
| 55 | char *memsize_str; |
| 56 | unsigned int memsize; |
Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 57 | char cmdline[CL_SIZE], *ptr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | |
Ralf Baechle | e1a4e46 | 2006-07-03 17:02:35 +0100 | [diff] [blame^] | 59 | /* otherwise look in the environment */ |
| 60 | memsize_str = prom_getenv("memsize"); |
| 61 | if (!memsize_str) { |
| 62 | prom_printf("memsize not set in boot prom, set to default (32Mb)\n"); |
| 63 | physical_memsize = 0x02000000; |
| 64 | } else { |
| 65 | #ifdef DEBUG |
| 66 | prom_printf("prom_memsize = %s\n", memsize_str); |
| 67 | #endif |
| 68 | physical_memsize = simple_strtol(memsize_str, NULL, 0); |
| 69 | } |
| 70 | |
| 71 | #ifdef CONFIG_CPU_BIG_ENDIAN |
| 72 | /* SOC-it swaps, or perhaps doesn't swap, when DMA'ing the last |
| 73 | word of physical memory */ |
| 74 | physical_memsize -= PAGE_SIZE; |
| 75 | #endif |
| 76 | |
| 77 | /* Check the command line for a memsize directive that overrides |
| 78 | the physical/default amount */ |
Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 79 | strcpy(cmdline, arcs_cmdline); |
| 80 | ptr = strstr(cmdline, "memsize="); |
| 81 | if (ptr && (ptr != cmdline) && (*(ptr - 1) != ' ')) |
| 82 | ptr = strstr(ptr, " memsize="); |
| 83 | |
Ralf Baechle | e1a4e46 | 2006-07-03 17:02:35 +0100 | [diff] [blame^] | 84 | if (ptr) |
Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 85 | memsize = memparse(ptr + 8, &ptr); |
Ralf Baechle | e1a4e46 | 2006-07-03 17:02:35 +0100 | [diff] [blame^] | 86 | else |
| 87 | memsize = physical_memsize; |
Elizabeth Oldham | 7349968 | 2006-06-06 10:57:09 +0100 | [diff] [blame] | 88 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | memset(mdesc, 0, sizeof(mdesc)); |
| 90 | |
| 91 | mdesc[0].type = yamon_dontuse; |
| 92 | mdesc[0].base = 0x00000000; |
| 93 | mdesc[0].size = 0x00001000; |
| 94 | |
| 95 | mdesc[1].type = yamon_prom; |
| 96 | mdesc[1].base = 0x00001000; |
| 97 | mdesc[1].size = 0x000ef000; |
| 98 | |
| 99 | #ifdef CONFIG_MIPS_MALTA |
| 100 | /* |
| 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; |
| 110 | #else |
| 111 | mdesc[2].type = yamon_prom; |
| 112 | mdesc[2].base = 0x000f0000; |
| 113 | mdesc[2].size = 0x00010000; |
| 114 | #endif |
| 115 | |
| 116 | mdesc[3].type = yamon_dontuse; |
| 117 | mdesc[3].base = 0x00100000; |
Ralf Baechle | fde3505 | 2006-04-03 14:44:50 +0100 | [diff] [blame] | 118 | mdesc[3].size = CPHYSADDR(PFN_ALIGN((unsigned long)&_end)) - mdesc[3].base; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | |
| 120 | mdesc[4].type = yamon_free; |
Ralf Baechle | fde3505 | 2006-04-03 14:44:50 +0100 | [diff] [blame] | 121 | mdesc[4].base = CPHYSADDR(PFN_ALIGN(&_end)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | mdesc[4].size = memsize - mdesc[4].base; |
| 123 | |
| 124 | return &mdesc[0]; |
| 125 | } |
| 126 | |
| 127 | static int __init prom_memtype_classify (unsigned int type) |
| 128 | { |
| 129 | switch (type) { |
| 130 | case yamon_free: |
| 131 | return BOOT_MEM_RAM; |
| 132 | case yamon_prom: |
| 133 | return BOOT_MEM_ROM_DATA; |
| 134 | default: |
| 135 | return BOOT_MEM_RESERVED; |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | void __init prom_meminit(void) |
| 140 | { |
| 141 | struct prom_pmemblock *p; |
| 142 | |
| 143 | #ifdef DEBUG |
| 144 | prom_printf("YAMON MEMORY DESCRIPTOR dump:\n"); |
| 145 | p = prom_getmdesc(); |
| 146 | while (p->size) { |
| 147 | int i = 0; |
| 148 | prom_printf("[%d,%p]: base<%08lx> size<%08lx> type<%s>\n", |
| 149 | i, p, p->base, p->size, mtypes[p->type]); |
| 150 | p++; |
| 151 | i++; |
| 152 | } |
| 153 | #endif |
| 154 | p = prom_getmdesc(); |
| 155 | |
| 156 | while (p->size) { |
| 157 | long type; |
| 158 | unsigned long base, size; |
| 159 | |
| 160 | type = prom_memtype_classify (p->type); |
| 161 | base = p->base; |
| 162 | size = p->size; |
| 163 | |
| 164 | add_memory_region(base, size, type); |
| 165 | p++; |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | unsigned long __init prom_free_prom_memory(void) |
| 170 | { |
| 171 | unsigned long freed = 0; |
| 172 | unsigned long addr; |
| 173 | int i; |
| 174 | |
| 175 | for (i = 0; i < boot_mem_map.nr_map; i++) { |
| 176 | if (boot_mem_map.map[i].type != BOOT_MEM_ROM_DATA) |
| 177 | continue; |
| 178 | |
| 179 | addr = boot_mem_map.map[i].addr; |
| 180 | while (addr < boot_mem_map.map[i].addr |
| 181 | + boot_mem_map.map[i].size) { |
| 182 | ClearPageReserved(virt_to_page(__va(addr))); |
Nick Piggin | 7835e98 | 2006-03-22 00:08:40 -0800 | [diff] [blame] | 183 | init_page_count(virt_to_page(__va(addr))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | free_page((unsigned long)__va(addr)); |
| 185 | addr += PAGE_SIZE; |
| 186 | freed += PAGE_SIZE; |
| 187 | } |
| 188 | } |
| 189 | printk("Freeing prom memory: %ldkb freed\n", freed >> 10); |
| 190 | |
| 191 | return freed; |
| 192 | } |