]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - arch/mips/mti-malta/malta-memory.c
MIPS: Malta: Remove fw_memblock_t abstraction
[karo-tx-linux.git] / arch / mips / mti-malta / malta-memory.c
1 /*
2  * This file is subject to the terms and conditions of the GNU General Public
3  * License.  See the file "COPYING" in the main directory of this archive
4  * for more details.
5  *
6  * PROM library functions for acquiring/using memory descriptors given to
7  * us from the YAMON.
8  *
9  * Copyright (C) 1999,2000,2012  MIPS Technologies, Inc.
10  * All rights reserved.
11  * Authors: Carsten Langgaard <carstenl@mips.com>
12  *          Steven J. Hill <sjhill@mips.com>
13  */
14 #include <linux/init.h>
15 #include <linux/bootmem.h>
16 #include <linux/string.h>
17
18 #include <asm/bootinfo.h>
19 #include <asm/cdmm.h>
20 #include <asm/maar.h>
21 #include <asm/sections.h>
22 #include <asm/fw/fw.h>
23
24 /* determined physical memory size, not overridden by command line args  */
25 unsigned long physical_memsize = 0L;
26
27 static void free_init_pages_eva_malta(void *begin, void *end)
28 {
29         free_init_pages("unused kernel", __pa_symbol((unsigned long *)begin),
30                         __pa_symbol((unsigned long *)end));
31 }
32
33 void __init fw_meminit(void)
34 {
35         char *memsize_str, *ememsize_str = NULL, *ptr;
36         unsigned long memsize = 0, ememsize = 0;
37         unsigned long kernel_start_phys, kernel_end_phys;
38         static char cmdline[COMMAND_LINE_SIZE] __initdata;
39         bool eva = config_enabled(CONFIG_EVA);
40         int tmp;
41
42         free_init_pages_eva = eva ? free_init_pages_eva_malta : NULL;
43
44         memsize_str = fw_getenv("memsize");
45         if (memsize_str) {
46                 tmp = kstrtoul(memsize_str, 0, &memsize);
47                 if (tmp)
48                         pr_warn("Failed to read the 'memsize' env variable.\n");
49         }
50         if (eva) {
51         /* Look for ememsize for EVA */
52                 ememsize_str = fw_getenv("ememsize");
53                 if (ememsize_str) {
54                         tmp = kstrtoul(ememsize_str, 0, &ememsize);
55                         if (tmp)
56                                 pr_warn("Failed to read the 'ememsize' env variable.\n");
57                 }
58         }
59         if (!memsize && !ememsize) {
60                 pr_warn("memsize not set in YAMON, set to default (32Mb)\n");
61                 physical_memsize = 0x02000000;
62         } else {
63                 if (memsize > (256 << 20)) { /* memsize should be capped to 256M */
64                         pr_warn("Unsupported memsize value (0x%lx) detected! "
65                                 "Using 0x10000000 (256M) instead\n",
66                                 memsize);
67                         memsize = 256 << 20;
68                 }
69                 /* If ememsize is set, then set physical_memsize to that */
70                 physical_memsize = ememsize ? : memsize;
71         }
72
73 #ifdef CONFIG_CPU_BIG_ENDIAN
74         /* SOC-it swaps, or perhaps doesn't swap, when DMA'ing the last
75            word of physical memory */
76         physical_memsize -= PAGE_SIZE;
77 #endif
78
79         /* Check the command line for a memsize directive that overrides
80            the physical/default amount */
81         strcpy(cmdline, arcs_cmdline);
82         ptr = strstr(cmdline, "memsize=");
83         if (ptr && (ptr != cmdline) && (*(ptr - 1) != ' '))
84                 ptr = strstr(ptr, " memsize=");
85         /* And now look for ememsize */
86         if (eva) {
87                 ptr = strstr(cmdline, "ememsize=");
88                 if (ptr && (ptr != cmdline) && (*(ptr - 1) != ' '))
89                         ptr = strstr(ptr, " ememsize=");
90         }
91
92         if (ptr)
93                 memsize = memparse(ptr + 8 + (eva ? 1 : 0), &ptr);
94         else
95                 memsize = physical_memsize;
96
97         /* Last 64K for HIGHMEM arithmetics */
98         if (memsize > 0x7fff0000)
99                 memsize = 0x7fff0000;
100
101         add_memory_region(PHYS_OFFSET, 0x00001000, BOOT_MEM_RESERVED);
102
103         /*
104          * YAMON may still be using the region of memory from 0x1000 to 0xfffff
105          * if it has started secondary CPUs.
106          */
107         add_memory_region(PHYS_OFFSET + 0x00001000, 0x000ef000,
108                           BOOT_MEM_ROM_DATA);
109
110         /*
111          * The area 0x000f0000-0x000fffff is allocated for BIOS memory by the
112          * south bridge and PCI access always forwarded to the ISA Bus and
113          * BIOSCS# is always generated.
114          * This mean that this area can't be used as DMA memory for PCI
115          * devices.
116          */
117         add_memory_region(PHYS_OFFSET + 0x000f0000, 0x00010000,
118                           BOOT_MEM_RESERVED);
119
120         /*
121          * Reserve the memory used by kernel code, and allow the rest of RAM to
122          * be used.
123          */
124         kernel_start_phys = PHYS_OFFSET + 0x00100000;
125         kernel_end_phys = PHYS_OFFSET + CPHYSADDR(PFN_ALIGN(&_end));
126         add_memory_region(kernel_start_phys, kernel_end_phys,
127                           BOOT_MEM_RESERVED);
128         add_memory_region(kernel_end_phys, memsize - kernel_end_phys,
129                           BOOT_MEM_RAM);
130 }
131
132 void __init prom_free_prom_memory(void)
133 {
134         unsigned long addr;
135         int i;
136
137         for (i = 0; i < boot_mem_map.nr_map; i++) {
138                 if (boot_mem_map.map[i].type != BOOT_MEM_ROM_DATA)
139                         continue;
140
141                 addr = boot_mem_map.map[i].addr;
142                 free_init_pages("YAMON memory",
143                                 addr, addr + boot_mem_map.map[i].size);
144         }
145 }
146
147 phys_addr_t mips_cdmm_phys_base(void)
148 {
149         /* This address is "typically unused" */
150         return 0x1fc10000;
151 }