blob: 1ca34887d990d3e5c8d636fe73c096330af5a174 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Steven J. Hill49bffbd2013-03-25 15:05:40 -05002 * 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.
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 *
6 * PROM library functions for acquiring/using memory descriptors given to
7 * us from the YAMON.
Steven J. Hill49bffbd2013-03-25 15:05:40 -05008 *
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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <linux/init.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <linux/bootmem.h>
Ralf Baechlee01402b2005-07-14 15:57:16 +000016#include <linux/string.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017
18#include <asm/bootinfo.h>
Ralf Baechle9c1f1252006-04-03 10:17:21 +010019#include <asm/sections.h>
Steven J. Hillb431f092013-03-25 14:47:05 -050020#include <asm/fw/fw.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021
Steven J. Hillb431f092013-03-25 14:47:05 -050022static fw_memblock_t mdesc[FW_MAX_MEMBLOCKS];
Linus Torvalds1da177e2005-04-16 15:20:36 -070023
Ralf Baechle70342282013-01-22 12:59:30 +010024/* determined physical memory size, not overridden by command line args */
Ralf Baechlee1a4e462006-07-03 17:02:35 +010025unsigned long physical_memsize = 0L;
26
Markos Chandrase6ca4e52014-01-15 13:55:07 +000027fw_memblock_t * __init fw_getmdesc(int eva)
Linus Torvalds1da177e2005-04-16 15:20:36 -070028{
Markos Chandrasacd8bc12014-05-23 13:31:32 +010029 char *memsize_str, *ememsize_str = NULL, *ptr;
30 unsigned long memsize, ememsize = 0;
Dmitri Vorobiev7580c9c2009-10-13 23:43:24 +030031 static char cmdline[COMMAND_LINE_SIZE] __initdata;
Steven J. Hill49bffbd2013-03-25 15:05:40 -050032 int tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -070033
Ralf Baechlee1a4e462006-07-03 17:02:35 +010034 /* otherwise look in the environment */
Markos Chandrase6ca4e52014-01-15 13:55:07 +000035
Steven J. Hillb431f092013-03-25 14:47:05 -050036 memsize_str = fw_getenv("memsize");
Markos Chandrase6ca4e52014-01-15 13:55:07 +000037 if (memsize_str)
38 tmp = kstrtol(memsize_str, 0, &memsize);
39 if (eva) {
40 /* Look for ememsize for EVA */
41 ememsize_str = fw_getenv("ememsize");
42 if (ememsize_str)
43 tmp = kstrtol(ememsize_str, 0, &ememsize);
44 }
45 if (!memsize && !ememsize) {
Steven J. Hill49bffbd2013-03-25 15:05:40 -050046 pr_warn("memsize not set in YAMON, set to default (32Mb)\n");
Ralf Baechlee1a4e462006-07-03 17:02:35 +010047 physical_memsize = 0x02000000;
48 } else {
Markos Chandrase6ca4e52014-01-15 13:55:07 +000049 /* If ememsize is set, then set physical_memsize to that */
50 physical_memsize = ememsize ? : memsize;
Ralf Baechlee1a4e462006-07-03 17:02:35 +010051 }
52
53#ifdef CONFIG_CPU_BIG_ENDIAN
54 /* SOC-it swaps, or perhaps doesn't swap, when DMA'ing the last
55 word of physical memory */
56 physical_memsize -= PAGE_SIZE;
57#endif
58
59 /* Check the command line for a memsize directive that overrides
60 the physical/default amount */
Ralf Baechlee01402b2005-07-14 15:57:16 +000061 strcpy(cmdline, arcs_cmdline);
62 ptr = strstr(cmdline, "memsize=");
63 if (ptr && (ptr != cmdline) && (*(ptr - 1) != ' '))
64 ptr = strstr(ptr, " memsize=");
Markos Chandrase6ca4e52014-01-15 13:55:07 +000065 /* And now look for ememsize */
66 if (eva) {
67 ptr = strstr(cmdline, "ememsize=");
68 if (ptr && (ptr != cmdline) && (*(ptr - 1) != ' '))
69 ptr = strstr(ptr, " ememsize=");
70 }
Ralf Baechlee01402b2005-07-14 15:57:16 +000071
Ralf Baechlee1a4e462006-07-03 17:02:35 +010072 if (ptr)
Markos Chandrase6ca4e52014-01-15 13:55:07 +000073 memsize = memparse(ptr + 8 + (eva ? 1 : 0), &ptr);
Ralf Baechlee1a4e462006-07-03 17:02:35 +010074 else
75 memsize = physical_memsize;
Elizabeth Oldham73499682006-06-06 10:57:09 +010076
Markos Chandrase6ca4e52014-01-15 13:55:07 +000077 /* Last 64K for HIGHMEM arithmetics */
78 if (memsize > 0x7fff0000)
79 memsize = 0x7fff0000;
80
Linus Torvalds1da177e2005-04-16 15:20:36 -070081 memset(mdesc, 0, sizeof(mdesc));
82
Steven J. Hillb431f092013-03-25 14:47:05 -050083 mdesc[0].type = fw_dontuse;
Markos Chandras3bdd8e62014-01-15 14:13:05 +000084 mdesc[0].base = PHYS_OFFSET;
Linus Torvalds1da177e2005-04-16 15:20:36 -070085 mdesc[0].size = 0x00001000;
86
Steven J. Hillb431f092013-03-25 14:47:05 -050087 mdesc[1].type = fw_code;
Markos Chandras3bdd8e62014-01-15 14:13:05 +000088 mdesc[1].base = mdesc[0].base + 0x00001000UL;
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 mdesc[1].size = 0x000ef000;
90
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 /*
92 * The area 0x000f0000-0x000fffff is allocated for BIOS memory by the
93 * south bridge and PCI access always forwarded to the ISA Bus and
94 * BIOSCS# is always generated.
95 * This mean that this area can't be used as DMA memory for PCI
96 * devices.
97 */
Steven J. Hillb431f092013-03-25 14:47:05 -050098 mdesc[2].type = fw_dontuse;
Markos Chandras3bdd8e62014-01-15 14:13:05 +000099 mdesc[2].base = mdesc[0].base + 0x000f0000UL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100 mdesc[2].size = 0x00010000;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101
Steven J. Hillb431f092013-03-25 14:47:05 -0500102 mdesc[3].type = fw_dontuse;
Markos Chandras3bdd8e62014-01-15 14:13:05 +0000103 mdesc[3].base = mdesc[0].base + 0x00100000UL;
Steven J. Hill49bffbd2013-03-25 15:05:40 -0500104 mdesc[3].size = CPHYSADDR(PFN_ALIGN((unsigned long)&_end)) -
Markos Chandras3bdd8e62014-01-15 14:13:05 +0000105 0x00100000UL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106
Steven J. Hillb431f092013-03-25 14:47:05 -0500107 mdesc[4].type = fw_free;
Markos Chandras3bdd8e62014-01-15 14:13:05 +0000108 mdesc[4].base = mdesc[0].base + CPHYSADDR(PFN_ALIGN(&_end));
109 mdesc[4].size = memsize - CPHYSADDR(mdesc[4].base);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110
111 return &mdesc[0];
112}
113
Markos Chandrasd1965c02014-01-15 14:07:57 +0000114static void free_init_pages_eva_malta(void *begin, void *end)
115{
116 free_init_pages("unused kernel", __pa_symbol((unsigned long *)begin),
117 __pa_symbol((unsigned long *)end));
118}
119
Steven J. Hillb431f092013-03-25 14:47:05 -0500120static int __init fw_memtype_classify(unsigned int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121{
122 switch (type) {
Steven J. Hillb431f092013-03-25 14:47:05 -0500123 case fw_free:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 return BOOT_MEM_RAM;
Steven J. Hillb431f092013-03-25 14:47:05 -0500125 case fw_code:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126 return BOOT_MEM_ROM_DATA;
127 default:
128 return BOOT_MEM_RESERVED;
129 }
130}
131
Steven J. Hillb431f092013-03-25 14:47:05 -0500132void __init fw_meminit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133{
Steven J. Hillb431f092013-03-25 14:47:05 -0500134 fw_memblock_t *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135
Markos Chandrase6ca4e52014-01-15 13:55:07 +0000136 p = fw_getmdesc(config_enabled(CONFIG_EVA));
Markos Chandrasd1965c02014-01-15 14:07:57 +0000137 free_init_pages_eva = (config_enabled(CONFIG_EVA) ?
138 free_init_pages_eva_malta : NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139
140 while (p->size) {
141 long type;
142 unsigned long base, size;
143
Steven J. Hillb431f092013-03-25 14:47:05 -0500144 type = fw_memtype_classify(p->type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 base = p->base;
146 size = p->size;
147
148 add_memory_region(base, size, type);
Ralf Baechle70342282013-01-22 12:59:30 +0100149 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 }
151}
152
Atsushi Nemotoc44e8d52006-12-30 00:43:59 +0900153void __init prom_free_prom_memory(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 unsigned long addr;
156 int i;
157
158 for (i = 0; i < boot_mem_map.nr_map; i++) {
159 if (boot_mem_map.map[i].type != BOOT_MEM_ROM_DATA)
160 continue;
161
Atsushi Nemotoc44e8d52006-12-30 00:43:59 +0900162 addr = boot_mem_map.map[i].addr;
Steven J. Hill49bffbd2013-03-25 15:05:40 -0500163 free_init_pages("YAMON memory",
Atsushi Nemotoc44e8d52006-12-30 00:43:59 +0900164 addr, addr + boot_mem_map.map[i].size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166}