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 | */ |
| 21 | #include <linux/config.h> |
| 22 | #include <linux/init.h> |
| 23 | #include <linux/mm.h> |
| 24 | #include <linux/bootmem.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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | struct prom_pmemblock * __init prom_getmdesc(void) |
| 51 | { |
| 52 | char *memsize_str; |
| 53 | unsigned int memsize; |
Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 54 | char cmdline[CL_SIZE], *ptr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | |
Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 56 | /* Check the command line first for a memsize directive */ |
| 57 | strcpy(cmdline, arcs_cmdline); |
| 58 | ptr = strstr(cmdline, "memsize="); |
| 59 | if (ptr && (ptr != cmdline) && (*(ptr - 1) != ' ')) |
| 60 | ptr = strstr(ptr, " memsize="); |
| 61 | |
| 62 | if (ptr) { |
| 63 | memsize = memparse(ptr + 8, &ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | } |
Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 65 | else { |
| 66 | /* otherwise look in the environment */ |
| 67 | memsize_str = prom_getenv("memsize"); |
| 68 | if (!memsize_str) { |
| 69 | prom_printf("memsize not set in boot prom, set to default (32Mb)\n"); |
| 70 | memsize = 0x02000000; |
| 71 | } else { |
| 72 | #ifdef DEBUG |
| 73 | prom_printf("prom_memsize = %s\n", memsize_str); |
| 74 | #endif |
| 75 | memsize = simple_strtol(memsize_str, NULL, 0); |
| 76 | } |
| 77 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | memset(mdesc, 0, sizeof(mdesc)); |
| 79 | |
| 80 | mdesc[0].type = yamon_dontuse; |
| 81 | mdesc[0].base = 0x00000000; |
| 82 | mdesc[0].size = 0x00001000; |
| 83 | |
| 84 | mdesc[1].type = yamon_prom; |
| 85 | mdesc[1].base = 0x00001000; |
| 86 | mdesc[1].size = 0x000ef000; |
| 87 | |
| 88 | #ifdef CONFIG_MIPS_MALTA |
| 89 | /* |
| 90 | * The area 0x000f0000-0x000fffff is allocated for BIOS memory by the |
| 91 | * south bridge and PCI access always forwarded to the ISA Bus and |
| 92 | * BIOSCS# is always generated. |
| 93 | * This mean that this area can't be used as DMA memory for PCI |
| 94 | * devices. |
| 95 | */ |
| 96 | mdesc[2].type = yamon_dontuse; |
| 97 | mdesc[2].base = 0x000f0000; |
| 98 | mdesc[2].size = 0x00010000; |
| 99 | #else |
| 100 | mdesc[2].type = yamon_prom; |
| 101 | mdesc[2].base = 0x000f0000; |
| 102 | mdesc[2].size = 0x00010000; |
| 103 | #endif |
| 104 | |
| 105 | mdesc[3].type = yamon_dontuse; |
| 106 | mdesc[3].base = 0x00100000; |
Ralf Baechle | 9c1f125 | 2006-04-03 10:17:21 +0100 | [diff] [blame^] | 107 | mdesc[3].size = CPHYSADDR(PAGE_ALIGN((unsigned long)&_end)) - mdesc[3].base; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | |
| 109 | mdesc[4].type = yamon_free; |
Dave Hansen | 22a9835 | 2006-03-27 01:16:04 -0800 | [diff] [blame] | 110 | mdesc[4].base = CPHYSADDR(PAGE_ALIGN(&_end)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | mdesc[4].size = memsize - mdesc[4].base; |
| 112 | |
| 113 | return &mdesc[0]; |
| 114 | } |
| 115 | |
| 116 | static int __init prom_memtype_classify (unsigned int type) |
| 117 | { |
| 118 | switch (type) { |
| 119 | case yamon_free: |
| 120 | return BOOT_MEM_RAM; |
| 121 | case yamon_prom: |
| 122 | return BOOT_MEM_ROM_DATA; |
| 123 | default: |
| 124 | return BOOT_MEM_RESERVED; |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | void __init prom_meminit(void) |
| 129 | { |
| 130 | struct prom_pmemblock *p; |
| 131 | |
| 132 | #ifdef DEBUG |
| 133 | prom_printf("YAMON MEMORY DESCRIPTOR dump:\n"); |
| 134 | p = prom_getmdesc(); |
| 135 | while (p->size) { |
| 136 | int i = 0; |
| 137 | prom_printf("[%d,%p]: base<%08lx> size<%08lx> type<%s>\n", |
| 138 | i, p, p->base, p->size, mtypes[p->type]); |
| 139 | p++; |
| 140 | i++; |
| 141 | } |
| 142 | #endif |
| 143 | p = prom_getmdesc(); |
| 144 | |
| 145 | while (p->size) { |
| 146 | long type; |
| 147 | unsigned long base, size; |
| 148 | |
| 149 | type = prom_memtype_classify (p->type); |
| 150 | base = p->base; |
| 151 | size = p->size; |
| 152 | |
| 153 | add_memory_region(base, size, type); |
| 154 | p++; |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | unsigned long __init prom_free_prom_memory(void) |
| 159 | { |
| 160 | unsigned long freed = 0; |
| 161 | unsigned long addr; |
| 162 | int i; |
| 163 | |
| 164 | for (i = 0; i < boot_mem_map.nr_map; i++) { |
| 165 | if (boot_mem_map.map[i].type != BOOT_MEM_ROM_DATA) |
| 166 | continue; |
| 167 | |
| 168 | addr = boot_mem_map.map[i].addr; |
| 169 | while (addr < boot_mem_map.map[i].addr |
| 170 | + boot_mem_map.map[i].size) { |
| 171 | ClearPageReserved(virt_to_page(__va(addr))); |
Nick Piggin | 7835e98 | 2006-03-22 00:08:40 -0800 | [diff] [blame] | 172 | init_page_count(virt_to_page(__va(addr))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | free_page((unsigned long)__va(addr)); |
| 174 | addr += PAGE_SIZE; |
| 175 | freed += PAGE_SIZE; |
| 176 | } |
| 177 | } |
| 178 | printk("Freeing prom memory: %ldkb freed\n", freed >> 10); |
| 179 | |
| 180 | return freed; |
| 181 | } |