Minor fixes, do not count interrupts without interrupt source as spurious (#1755)
[openwrt/svn-archive/archive.git] / target / linux / adm5120-2.6 / files / arch / mips / adm5120 / memory.c
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)
7 *
8 * ########################################################################
9 *
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.
13 *
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
17 * for more details.
18 *
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.
22 *
23 * ########################################################################
24 *
25 *****************************************************************************/
26
27 #include <linux/autoconf.h>
28 #include <linux/init.h>
29 #include <linux/mm.h>
30 #include <linux/bootmem.h>
31 #include <linux/pfn.h>
32 #include <linux/string.h>
33
34 #include <asm/bootinfo.h>
35 #include <asm/page.h>
36 #include <asm/sections.h>
37
38 #include <asm-mips/mips-boards/prom.h>
39
40 extern char *prom_getenv(char *envname);
41 void prom_printf(char *, ...);
42
43 #define PFN_ALIGN(x) (((unsigned long)(x) + (PAGE_SIZE - 1)) & PAGE_MASK)
44
45 #define ADM5120_MEMCTRL 0x1200001c
46 #define ADM5120_MEMCTRL_SDRAM_MASK 0x7
47
48 static const unsigned long adm_sdramsize[] __initdata = {
49 0x0, /* Reserved */
50 0x0400000, /* 4Mb */
51 0x0800000, /* 8Mb */
52 0x1000000, /* 16Mb */
53 0x4000000, /* 64Mb */
54 0x8000000, /* 128Mb */
55 };
56
57 /* determined physical memory size, not overridden by command line args */
58 unsigned long physical_memsize = 0L;
59
60 struct prom_pmemblock mdesc[PROM_MAX_PMEMBLOCKS];
61
62 struct prom_pmemblock * __init prom_getmdesc(void)
63 {
64 char *memsize_str;
65 unsigned int memsize;
66 char cmdline[CL_SIZE], *ptr;
67
68 memsize_str = prom_getenv("memsize");
69
70 if (!memsize_str)
71 {
72 prom_printf("memsize not set in boot prom, set to default (8Mb)\n");
73 physical_memsize = 0x00800000;
74 }
75 else
76 #ifdef DEBUG
77 prom_printf("prom_memsize = %s\n", memsize_str);
78 #endif
79 physical_memsize = simple_strtol(memsize_str, NULL, 0);
80
81 /* Check the command line for a memsize directive that overrides
82 * the physical/default amount */
83 strcpy(cmdline, arcs_cmdline);
84 ptr = strstr(cmdline, "memsize=");
85 if (ptr && (ptr != cmdline) && (*(ptr - 1) != ' '))
86 ptr = strstr(ptr, " memsize=");
87
88 if (ptr)
89 memsize = memparse(ptr + 8, &ptr);
90 else
91 memsize = physical_memsize;
92
93 memset(mdesc, 0, sizeof(mdesc));
94
95 mdesc[0].type = BOOT_MEM_RAM;
96 mdesc[0].base = CPHYSADDR(PFN_ALIGN(&_end));
97 mdesc[0].size = memsize - mdesc[0].base;
98
99 return &mdesc[0];
100 }
101
102 void __init prom_meminit(void)
103 {
104 struct prom_pmemblock *p;
105
106 p = prom_getmdesc();
107
108 while (p->size)
109 {
110 long type;
111 unsigned long base, size;
112 base = p->base;
113 type = p->type,
114 size = p->size;
115 add_memory_region(base, size, type);
116 p++;
117 }
118 }
119
120 #if 0
121 void __init prom_meminit(void)
122 {
123 unsigned long base = CPHYSADDR(PFN_ALIGN(&_end));
124 unsigned long size;
125
126 u32 memctrl = *(u32*)KSEG1ADDR(ADM5120_MEMCTRL);
127 size = adm_sdramsize[memctrl & ADM5120_MEMCTRL_SDRAM_MASK];
128 add_memory_region(base, size-base, BOOT_MEM_RAM);
129 }
130 #endif
131
132 void __init prom_free_prom_memory(void)
133 {
134 /* We do not have to prom memory to free */
135 }