Fix memory detection and hcd compilation, thanks Gabor ! (closes #1813)
[openwrt/openwrt.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/mach-adm5120/adm5120_info.h>
39 #include <asm-mips/mips-boards/prom.h>
40
41 #define PFN_ALIGN(x) (((unsigned long)(x) + (PAGE_SIZE - 1)) & PAGE_MASK)
42
43 struct prom_pmemblock mdesc[PROM_MAX_PMEMBLOCKS];
44
45 struct prom_pmemblock * __init prom_getmdesc(void)
46 {
47 unsigned int memsize;
48 char cmdline[CL_SIZE], *ptr;
49
50 memsize = adm5120_memsize;
51 /* Check the command line for a memsize directive that overrides
52 * the physical/default amount */
53 strcpy(cmdline, arcs_cmdline);
54 ptr = strstr(cmdline, "memsize=");
55 if (ptr && (ptr != cmdline) && (*(ptr - 1) != ' '))
56 ptr = strstr(ptr, " memsize=");
57
58 if (ptr)
59 memsize = memparse(ptr + 8, &ptr);
60
61 memset(mdesc, 0, sizeof(mdesc));
62 mdesc[0].type = BOOT_MEM_RAM;
63 mdesc[0].base = CPHYSADDR(PFN_ALIGN(&_end));
64 mdesc[0].size = memsize - mdesc[0].base;
65
66 return &mdesc[0];
67 }
68
69 void __init prom_meminit(void)
70 {
71 struct prom_pmemblock *p;
72
73 p = prom_getmdesc();
74
75 while (p->size)
76 {
77 long type;
78 unsigned long base, size;
79 base = p->base;
80 type = p->type,
81 size = p->size;
82 add_memory_region(base, size, type);
83 p++;
84 }
85 }
86
87 void __init prom_free_prom_memory(void)
88 {
89 /* We do not have to prom memory to free */
90 }