summaryrefslogtreecommitdiff
path: root/arch/mips/powertv/memory.c
blob: 28d06605fff62178ae91644a8edbbc4f86129a01 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
/*
 * Carsten Langgaard, carstenl@mips.com
 * Copyright (C) 1999,2000 MIPS Technologies, Inc.  All rights reserved.
 * Portions copyright (C) 2009 Cisco Systems, Inc.
 *
 *  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.
 *
 * Apparently originally from arch/mips/malta-memory.c. Modified to work
 * with the PowerTV bootloader.
 */
#include <linux/init.h>
#include <linux/mm.h>
#include <linux/bootmem.h>
#include <linux/pfn.h>
#include <linux/string.h>

#include <asm/bootinfo.h>
#include <asm/page.h>
#include <asm/sections.h>

#include <asm/mips-boards/prom.h>

#include "init.h"

/* Memory constants */
#define KIBIBYTE(n)		((n) * 1024)	/* Number of kibibytes */
#define MEBIBYTE(n)		((n) * KIBIBYTE(1024)) /* Number of mebibytes */
#define DEFAULT_MEMSIZE		MEBIBYTE(256)	/* If no memsize provided */
#define LOW_MEM_MAX		MEBIBYTE(252)	/* Max usable low mem */
#define RES_BOOTLDR_MEMSIZE	MEBIBYTE(1)	/* Memory reserved for bldr */
#define BOOT_MEM_SIZE		KIBIBYTE(256)	/* Memory reserved for bldr */
#define PHYS_MEM_START		0x10000000	/* Start of physical memory */

unsigned long ptv_memsize;

char __initdata cmdline[COMMAND_LINE_SIZE];

void __init prom_meminit(void)
{
	char *memsize_str;
	unsigned long memsize = 0;
	unsigned int physend;
	char *ptr;
	int low_mem;
	int high_mem;

	/* Check the command line first for a memsize directive */
	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 {
		/* otherwise look in the environment */
		memsize_str = prom_getenv("memsize");

		if (memsize_str != NULL) {
			pr_info("prom memsize = %s\n", memsize_str);
			memsize = simple_strtol(memsize_str, NULL, 0);
		}

		if (memsize == 0) {
			if (_prom_memsize != 0) {
				memsize = _prom_memsize;
				pr_info("_prom_memsize = 0x%lx\n", memsize);
				/* add in memory that the bootloader doesn't
				 * report */
				memsize += BOOT_MEM_SIZE;
			} else {
				memsize = DEFAULT_MEMSIZE;
				pr_info("Memsize not passed by bootloader, "
					"defaulting to 0x%lx\n", memsize);
			}
		}
	}

	/* Store memsize for diagnostic purposes */
	ptv_memsize = memsize;

	physend = PFN_ALIGN(&_end) - 0x80000000;
	if (memsize > LOW_MEM_MAX) {
		low_mem = LOW_MEM_MAX;
		high_mem = memsize - low_mem;
	} else {
		low_mem = memsize;
		high_mem = 0;
	}

/*
 * TODO: We will use the hard code for memory configuration until
 * the bootloader releases their device tree to us.
 */
	/*
	 * Add the memory reserved for use by the bootloader to the
	 * memory map.
	 */
	add_memory_region(PHYS_MEM_START, RES_BOOTLDR_MEMSIZE,
		BOOT_MEM_RESERVED);
#ifdef CONFIG_HIGHMEM_256_128
	/*
	 * Add memory in low for general use by the kernel and its friends
	 * (like drivers, applications, etc).
	 */
	add_memory_region(PHYS_MEM_START + RES_BOOTLDR_MEMSIZE,
		LOW_MEM_MAX - RES_BOOTLDR_MEMSIZE, BOOT_MEM_RAM);
	/*
	 * Add the memory reserved for reset vector.
	 */
	add_memory_region(0x1fc00000, MEBIBYTE(4), BOOT_MEM_RESERVED);
	/*
	 * Add the memory reserved.
	 */
	add_memory_region(0x20000000, MEBIBYTE(1024 + 75), BOOT_MEM_RESERVED);
	/*
	 * Add memory in high for general use by the kernel and its friends
	 * (like drivers, applications, etc).
	 *
	 * 75MB is reserved for devices which are using the memory in high.
	 */
	add_memory_region(0x60000000 + MEBIBYTE(75), MEBIBYTE(128 - 75),
		BOOT_MEM_RAM);
#elif defined CONFIG_HIGHMEM_128_128
	/*
	 * Add memory in low for general use by the kernel and its friends
	 * (like drivers, applications, etc).
	 */
	add_memory_region(PHYS_MEM_START + RES_BOOTLDR_MEMSIZE,
		MEBIBYTE(128) - RES_BOOTLDR_MEMSIZE, BOOT_MEM_RAM);
	/*
	 * Add the memory reserved.
	 */
	add_memory_region(PHYS_MEM_START + MEBIBYTE(128),
		MEBIBYTE(128 + 1024 + 75), BOOT_MEM_RESERVED);
	/*
	 * Add memory in high for general use by the kernel and its friends
	 * (like drivers, applications, etc).
	 *
	 * 75MB is reserved for devices which are using the memory in high.
	 */
	add_memory_region(0x60000000 + MEBIBYTE(75), MEBIBYTE(128 - 75),
		BOOT_MEM_RAM);
#else
	/* Add low memory regions for either:
	 *   - no-highmemory configuration case -OR-
	 *   - highmemory "HIGHMEM_LOWBANK_ONLY" case
	 */
	/*
	 * Add memory for general use by the kernel and its friends
	 * (like drivers, applications, etc).
	 */
	add_memory_region(PHYS_MEM_START + RES_BOOTLDR_MEMSIZE,
		low_mem - RES_BOOTLDR_MEMSIZE, BOOT_MEM_RAM);
	/*
	 * Add the memory reserved for reset vector.
	 */
	add_memory_region(0x1fc00000, MEBIBYTE(4), BOOT_MEM_RESERVED);
#endif
}

void __init prom_free_prom_memory(void)
{
	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;

		addr = boot_mem_map.map[i].addr;
		free_init_pages("prom memory",
				addr, addr + boot_mem_map.map[i].size);
	}
}