malta-memory.c 3.7 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
/*
 * Carsten Langgaard, carstenl@mips.com
 * Copyright (C) 1999,2000 MIPS Technologies, Inc.  All rights reserved.
 *
 *  This program is free software; you can distribute it and/or modify it
 *  under the terms of the GNU General Public License (Version 2) as
 *  published by the Free Software Foundation.
 *
 *  This program is distributed in the hope it will be useful, but WITHOUT
 *  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 *  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 *  for more details.
 *
 *  You should have received a copy of the GNU General Public License along
 *  with this program; if not, write to the Free Software Foundation, Inc.,
 *  59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
 *
 * PROM library functions for acquiring/using memory descriptors given to
 * us from the YAMON.
 */
#include <linux/init.h>
#include <linux/mm.h>
#include <linux/bootmem.h>
24
#include <linux/pfn.h>
25
#include <linux/string.h>
L
Linus Torvalds 已提交
26 27 28

#include <asm/bootinfo.h>
#include <asm/page.h>
29
#include <asm/sections.h>
30
#include <asm/fw/fw.h>
L
Linus Torvalds 已提交
31

32
static fw_memblock_t mdesc[FW_MAX_MEMBLOCKS];
L
Linus Torvalds 已提交
33

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

37
fw_memblock_t * __init fw_getmdesc(void)
L
Linus Torvalds 已提交
38 39 40
{
	char *memsize_str;
	unsigned int memsize;
41
	char *ptr;
42
	static char cmdline[COMMAND_LINE_SIZE] __initdata;
L
Linus Torvalds 已提交
43

44
	/* otherwise look in the environment */
45
	memsize_str = fw_getenv("memsize");
46
	if (!memsize_str) {
47 48
		printk(KERN_WARNING
		       "memsize not set in boot prom, set to default (32Mb)\n");
49 50 51
		physical_memsize = 0x02000000;
	} else {
		physical_memsize = simple_strtol(memsize_str, NULL, 0);
L
Linus Torvalds 已提交
52
	}
53 54

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

60 61 62 63 64 65 66 67 68 69 70 71
	/* 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=");

	if (ptr)
		memsize = memparse(ptr + 8, &ptr);
	else
		memsize = physical_memsize;

L
Linus Torvalds 已提交
72 73
	memset(mdesc, 0, sizeof(mdesc));

74
	mdesc[0].type = fw_dontuse;
L
Linus Torvalds 已提交
75 76 77
	mdesc[0].base = 0x00000000;
	mdesc[0].size = 0x00001000;

78
	mdesc[1].type = fw_code;
L
Linus Torvalds 已提交
79 80 81 82 83 84 85 86 87 88
	mdesc[1].base = 0x00001000;
	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.
	 */
89
	mdesc[2].type = fw_dontuse;
L
Linus Torvalds 已提交
90 91 92
	mdesc[2].base = 0x000f0000;
	mdesc[2].size = 0x00010000;

93
	mdesc[3].type = fw_dontuse;
L
Linus Torvalds 已提交
94
	mdesc[3].base = 0x00100000;
95
	mdesc[3].size = CPHYSADDR(PFN_ALIGN((unsigned long)&_end)) - mdesc[3].base;
L
Linus Torvalds 已提交
96

97
	mdesc[4].type = fw_free;
98
	mdesc[4].base = CPHYSADDR(PFN_ALIGN(&_end));
L
Linus Torvalds 已提交
99 100 101 102 103
	mdesc[4].size = memsize - mdesc[4].base;

	return &mdesc[0];
}

104
static int __init fw_memtype_classify(unsigned int type)
L
Linus Torvalds 已提交
105 106
{
	switch (type) {
107
	case fw_free:
L
Linus Torvalds 已提交
108
		return BOOT_MEM_RAM;
109
	case fw_code:
L
Linus Torvalds 已提交
110 111 112 113 114 115
		return BOOT_MEM_ROM_DATA;
	default:
		return BOOT_MEM_RESERVED;
	}
}

116
void __init fw_meminit(void)
L
Linus Torvalds 已提交
117
{
118
	fw_memblock_t *p;
L
Linus Torvalds 已提交
119

120
	p = fw_getmdesc();
L
Linus Torvalds 已提交
121 122 123 124 125

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

126
		type = fw_memtype_classify(p->type);
L
Linus Torvalds 已提交
127 128 129 130
		base = p->base;
		size = p->size;

		add_memory_region(base, size, type);
R
Ralf Baechle 已提交
131
		p++;
L
Linus Torvalds 已提交
132 133 134
	}
}

135
void __init prom_free_prom_memory(void)
L
Linus Torvalds 已提交
136 137 138 139 140 141 142 143
{
	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;

144 145 146
		addr = boot_mem_map.map[i].addr;
		free_init_pages("prom memory",
				addr, addr + boot_mem_map.map[i].size);
L
Linus Torvalds 已提交
147 148
	}
}