1 /*****************************************************************************
2 * Carsten Langgaard, carstenl@mips.com
3 * Copyright (C) 1999,2000 MIPS Technologies, Inc. All rights reserved.
4 * Copyright (C) 2003 ADMtek Incorporated.
5 * daniell@admtek.com.tw
6 * Copyright (C) 2005 Jeroen Vreeken (pe1rxq@amsat.org)
8 * ########################################################################
10 * This program is free software; you can distribute it and/or modify it
11 * under the terms of the GNU General Public License (Version 2) as
12 * published by the Free Software Foundation.
14 * This program is distributed in the hope it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
23 * ########################################################################
25 *****************************************************************************/
27 #include <linux/autoconf.h>
28 #include <linux/init.h>
30 #include <linux/bootmem.h>
31 #include <linux/pfn.h>
32 #include <linux/string.h>
34 #include <asm/bootinfo.h>
36 #include <asm/sections.h>
38 #include <asm-mips/mips-boards/prom.h>
40 extern char *prom_getenv(char *envname);
42 #define PFN_ALIGN(x) (((unsigned long)(x) + (PAGE_SIZE - 1)) & PAGE_MASK)
44 #define ADM5120_MEMCTRL 0x1200001c
45 #define ADM5120_MEMCTRL_SDRAM_MASK 0x7
47 static const unsigned long adm_sdramsize[] __initdata = {
53 0x8000000, /* 128Mb */
56 /* determined physical memory size, not overridden by command line args */
57 unsigned long physical_memsize = 0L;
59 struct prom_pmemblock mdesc[PROM_MAX_PMEMBLOCKS];
61 struct prom_pmemblock * __init prom_getmdesc(void)
65 char cmdline[CL_SIZE], *ptr;
67 memsize_str = prom_getenv("memsize");
71 prom_printf("memsize not set in boot prom, set to default (8Mb)\n");
72 physical_memsize = 0x00800000;
76 prom_printf("prom_memsize = %s\n", memsize_str);
78 physical_memsize = simple_strtol(memsize_str, NULL, 0);
80 /* Check the command line for a memsize directive that overrides
81 * the physical/default amount */
82 strcpy(cmdline, arcs_cmdline);
83 ptr = strstr(cmdline, "memsize=");
84 if (ptr && (ptr != cmdline) && (*(ptr - 1) != ' '))
85 ptr = strstr(ptr, " memsize=");
88 memsize = memparse(ptr + 8, &ptr);
90 memsize = physical_memsize;
92 memset(mdesc, 0, sizeof(mdesc));
94 mdesc[0].type = BOOT_MEM_RAM;
95 mdesc[0].base = CPHYSADDR(PFN_ALIGN(&_end));
96 mdesc[0].size = memsize - mdesc[0].base;
101 void __init prom_meminit(void)
103 struct prom_pmemblock *p;
110 unsigned long base, size;
114 add_memory_region(base, size, type);
120 void __init prom_meminit(void)
122 unsigned long base = CPHYSADDR(PFN_ALIGN(&_end));
125 u32 memctrl = *(u32*)KSEG1ADDR(ADM5120_MEMCTRL);
126 size = adm_sdramsize[memctrl & ADM5120_MEMCTRL_SDRAM_MASK];
127 add_memory_region(base, size-base, BOOT_MEM_RAM);
131 unsigned long __init prom_free_prom_memory(void)
133 unsigned long freed = 0;
137 for (i = 0; i < boot_mem_map.nr_map; i++) {
138 if (boot_mem_map.map[i].type != BOOT_MEM_ROM_DATA)
141 addr = PAGE_ALIGN(boot_mem_map.map[i].addr);
142 while (addr < boot_mem_map.map[i].addr
143 + boot_mem_map.map[i].size) {
144 ClearPageReserved(virt_to_page(__va(addr)));
145 init_page_count(virt_to_page(__va(addr)));
146 free_page((unsigned long)__va(addr));
151 printk("Freeing prom memory: %ldkb freed\n", freed >> 10);