malta-memory.c 4.2 KB
Newer Older
L
Linus Torvalds 已提交
1
/*
2 3 4
 * This file is subject to the terms and conditions of the GNU General Public
 * License.  See the file "COPYING" in the main directory of this archive
 * for more details.
L
Linus Torvalds 已提交
5 6 7
 *
 * PROM library functions for acquiring/using memory descriptors given to
 * us from the YAMON.
8 9 10 11 12
 *
 * Copyright (C) 1999,2000,2012  MIPS Technologies, Inc.
 * All rights reserved.
 * Authors: Carsten Langgaard <carstenl@mips.com>
 *          Steven J. Hill <sjhill@mips.com>
L
Linus Torvalds 已提交
13 14 15
 */
#include <linux/init.h>
#include <linux/bootmem.h>
16
#include <linux/string.h>
L
Linus Torvalds 已提交
17 18

#include <asm/bootinfo.h>
19
#include <asm/sections.h>
20
#include <asm/fw/fw.h>
L
Linus Torvalds 已提交
21

22
static fw_memblock_t mdesc[FW_MAX_MEMBLOCKS];
L
Linus Torvalds 已提交
23

R
Ralf Baechle 已提交
24
/* determined physical memory size, not overridden by command line args	 */
25 26
unsigned long physical_memsize = 0L;

27
fw_memblock_t * __init fw_getmdesc(int eva)
L
Linus Torvalds 已提交
28
{
29
	char *memsize_str, *ememsize_str __maybe_unused = NULL, *ptr;
30
	unsigned long memsize = 0, ememsize __maybe_unused = 0;
31
	static char cmdline[COMMAND_LINE_SIZE] __initdata;
32
	int tmp;
L
Linus Torvalds 已提交
33

34
	/* otherwise look in the environment */
35

36
	memsize_str = fw_getenv("memsize");
37 38 39 40 41 42 43 44 45
	if (memsize_str)
		tmp = kstrtol(memsize_str, 0, &memsize);
	if (eva) {
	/* Look for ememsize for EVA */
		ememsize_str = fw_getenv("ememsize");
		if (ememsize_str)
			tmp = kstrtol(ememsize_str, 0, &ememsize);
	}
	if (!memsize && !ememsize) {
46
		pr_warn("memsize not set in YAMON, set to default (32Mb)\n");
47 48
		physical_memsize = 0x02000000;
	} else {
49 50
		/* If ememsize is set, then set physical_memsize to that */
		physical_memsize = ememsize ? : memsize;
L
Linus Torvalds 已提交
51
	}
52 53

#ifdef CONFIG_CPU_BIG_ENDIAN
54 55 56
	/* SOC-it swaps, or perhaps doesn't swap, when DMA'ing the last
	   word of physical memory */
	physical_memsize -= PAGE_SIZE;
57 58
#endif

59 60 61 62 63 64
	/* Check the command line for a memsize directive that overrides
	   the physical/default amount */
	strcpy(cmdline, arcs_cmdline);
	ptr = strstr(cmdline, "memsize=");
	if (ptr && (ptr != cmdline) && (*(ptr - 1) != ' '))
		ptr = strstr(ptr, " memsize=");
65 66 67 68 69 70
	/* And now look for ememsize */
	if (eva) {
		ptr = strstr(cmdline, "ememsize=");
		if (ptr && (ptr != cmdline) && (*(ptr - 1) != ' '))
			ptr = strstr(ptr, " ememsize=");
	}
71 72

	if (ptr)
73
		memsize = memparse(ptr + 8 + (eva ? 1 : 0), &ptr);
74 75 76
	else
		memsize = physical_memsize;

77 78 79 80
	/* Last 64K for HIGHMEM arithmetics */
	if (memsize > 0x7fff0000)
		memsize = 0x7fff0000;

L
Linus Torvalds 已提交
81 82
	memset(mdesc, 0, sizeof(mdesc));

83
	mdesc[0].type = fw_dontuse;
84
	mdesc[0].base = PHYS_OFFSET;
L
Linus Torvalds 已提交
85 86
	mdesc[0].size = 0x00001000;

87
	mdesc[1].type = fw_code;
88
	mdesc[1].base = mdesc[0].base + 0x00001000UL;
L
Linus Torvalds 已提交
89 90 91 92 93 94 95 96 97
	mdesc[1].size = 0x000ef000;

	/*
	 * The area 0x000f0000-0x000fffff is allocated for BIOS memory by the
	 * south bridge and PCI access always forwarded to the ISA Bus and
	 * BIOSCS# is always generated.
	 * This mean that this area can't be used as DMA memory for PCI
	 * devices.
	 */
98
	mdesc[2].type = fw_dontuse;
99
	mdesc[2].base = mdesc[0].base + 0x000f0000UL;
L
Linus Torvalds 已提交
100 101
	mdesc[2].size = 0x00010000;

102
	mdesc[3].type = fw_dontuse;
103
	mdesc[3].base = mdesc[0].base + 0x00100000UL;
104
	mdesc[3].size = CPHYSADDR(PFN_ALIGN((unsigned long)&_end)) -
105
		0x00100000UL;
L
Linus Torvalds 已提交
106

107
	mdesc[4].type = fw_free;
108 109
	mdesc[4].base = mdesc[0].base + CPHYSADDR(PFN_ALIGN(&_end));
	mdesc[4].size = memsize - CPHYSADDR(mdesc[4].base);
L
Linus Torvalds 已提交
110 111 112 113

	return &mdesc[0];
}

114 115 116 117 118 119
static void free_init_pages_eva_malta(void *begin, void *end)
{
	free_init_pages("unused kernel", __pa_symbol((unsigned long *)begin),
			__pa_symbol((unsigned long *)end));
}

120
static int __init fw_memtype_classify(unsigned int type)
L
Linus Torvalds 已提交
121 122
{
	switch (type) {
123
	case fw_free:
L
Linus Torvalds 已提交
124
		return BOOT_MEM_RAM;
125
	case fw_code:
L
Linus Torvalds 已提交
126 127 128 129 130 131
		return BOOT_MEM_ROM_DATA;
	default:
		return BOOT_MEM_RESERVED;
	}
}

132
void __init fw_meminit(void)
L
Linus Torvalds 已提交
133
{
134
	fw_memblock_t *p;
L
Linus Torvalds 已提交
135

136
	p = fw_getmdesc(config_enabled(CONFIG_EVA));
137 138
	free_init_pages_eva = (config_enabled(CONFIG_EVA) ?
			       free_init_pages_eva_malta : NULL);
L
Linus Torvalds 已提交
139 140 141 142 143

	while (p->size) {
		long type;
		unsigned long base, size;

144
		type = fw_memtype_classify(p->type);
L
Linus Torvalds 已提交
145 146 147 148
		base = p->base;
		size = p->size;

		add_memory_region(base, size, type);
R
Ralf Baechle 已提交
149
		p++;
L
Linus Torvalds 已提交
150 151 152
	}
}

153
void __init prom_free_prom_memory(void)
L
Linus Torvalds 已提交
154 155 156 157 158 159 160 161
{
	unsigned long addr;
	int i;

	for (i = 0; i < boot_mem_map.nr_map; i++) {
		if (boot_mem_map.map[i].type != BOOT_MEM_ROM_DATA)
			continue;

162
		addr = boot_mem_map.map[i].addr;
163
		free_init_pages("YAMON memory",
164
				addr, addr + boot_mem_map.map[i].size);
L
Linus Torvalds 已提交
165 166
	}
}