setup.c 8.41 KB
Newer Older
Paul Mundt's avatar
Paul Mundt committed
1
/*
2
 * arch/sh/kernel/setup.c
Linus Torvalds's avatar
Linus Torvalds committed
3
4
 *
 * This file handles the architecture-dependent parts of initialization
5
6
 *
 *  Copyright (C) 1999  Niibe Yutaka
7
 *  Copyright (C) 2002 - 2010 Paul Mundt
Linus Torvalds's avatar
Linus Torvalds committed
8
 */
9
#include <linux/screen_info.h>
Linus Torvalds's avatar
Linus Torvalds committed
10
11
12
13
14
15
16
#include <linux/ioport.h>
#include <linux/init.h>
#include <linux/initrd.h>
#include <linux/bootmem.h>
#include <linux/console.h>
#include <linux/root_dev.h>
#include <linux/utsname.h>
17
#include <linux/nodemask.h>
Linus Torvalds's avatar
Linus Torvalds committed
18
#include <linux/cpu.h>
Dave Hansen's avatar
Dave Hansen committed
19
#include <linux/pfn.h>
Paul Mundt's avatar
Paul Mundt committed
20
#include <linux/fs.h>
21
#include <linux/mm.h>
Paul Mundt's avatar
Paul Mundt committed
22
#include <linux/kexec.h>
23
#include <linux/module.h>
24
#include <linux/smp.h>
Paul Mundt's avatar
Paul Mundt committed
25
#include <linux/err.h>
26
#include <linux/crash_dump.h>
Paul Mundt's avatar
Paul Mundt committed
27
#include <linux/mmzone.h>
28
29
#include <linux/clk.h>
#include <linux/delay.h>
30
#include <linux/platform_device.h>
Yinghai Lu's avatar
Yinghai Lu committed
31
#include <linux/memblock.h>
32
33
#include <linux/of.h>
#include <linux/of_fdt.h>
Linus Torvalds's avatar
Linus Torvalds committed
34
35
#include <asm/uaccess.h>
#include <asm/io.h>
36
#include <asm/page.h>
37
#include <asm/elf.h>
Linus Torvalds's avatar
Linus Torvalds committed
38
39
40
#include <asm/sections.h>
#include <asm/irq.h>
#include <asm/setup.h>
41
#include <asm/clock.h>
42
#include <asm/smp.h>
43
#include <asm/mmu_context.h>
44
#include <asm/mmzone.h>
45
#include <asm/sparsemem.h>
Linus Torvalds's avatar
Linus Torvalds committed
46
47
48
49
50
51

/*
 * Initialize loops_per_jiffy as 10000000 (1000MIPS).
 * This value will be used at the very early stage of serial setup.
 * The bigger value means no problem.
 */
52
53
54
struct sh_cpuinfo cpu_data[NR_CPUS] __read_mostly = {
	[0] = {
		.type			= CPU_SH_NONE,
55
		.family			= CPU_FAMILY_UNKNOWN,
56
		.loops_per_jiffy	= 10000000,
57
		.phys_bits		= MAX_PHYSMEM_BITS,
58
59
60
	},
};
EXPORT_SYMBOL(cpu_data);
Paul Mundt's avatar
Paul Mundt committed
61
62
63
64
65

/*
 * The machine vector. First entry in .machvec.init, or clobbered by
 * sh_mv= on the command line, prior to .machvec.init teardown.
 */
66
struct sh_machine_vector sh_mv = { .mv_name = "generic", };
67
EXPORT_SYMBOL(sh_mv);
Paul Mundt's avatar
Paul Mundt committed
68

Paul Mundt's avatar
Paul Mundt committed
69
#ifdef CONFIG_VT
Linus Torvalds's avatar
Linus Torvalds committed
70
struct screen_info screen_info;
Paul Mundt's avatar
Paul Mundt committed
71
#endif
Linus Torvalds's avatar
Linus Torvalds committed
72
73
74

extern int root_mountflags;

75
#define RAMDISK_IMAGE_START_MASK	0x07FF
Linus Torvalds's avatar
Linus Torvalds committed
76
#define RAMDISK_PROMPT_FLAG		0x8000
77
#define RAMDISK_LOAD_FLAG		0x4000
Linus Torvalds's avatar
Linus Torvalds committed
78

79
static char __initdata command_line[COMMAND_LINE_SIZE] = { 0, };
Linus Torvalds's avatar
Linus Torvalds committed
80

81
82
static struct resource code_resource = {
	.name = "Kernel code",
83
	.flags = IORESOURCE_BUSY | IORESOURCE_SYSTEM_RAM,
84
85
86
87
};

static struct resource data_resource = {
	.name = "Kernel data",
88
	.flags = IORESOURCE_BUSY | IORESOURCE_SYSTEM_RAM,
89
};
Linus Torvalds's avatar
Linus Torvalds committed
90

Magnus Damm's avatar
Magnus Damm committed
91
92
static struct resource bss_resource = {
	.name	= "Kernel bss",
93
	.flags	= IORESOURCE_BUSY | IORESOURCE_SYSTEM_RAM,
Magnus Damm's avatar
Magnus Damm committed
94
95
};

96
97
unsigned long memory_start;
EXPORT_SYMBOL(memory_start);
98
unsigned long memory_end = 0;
99
EXPORT_SYMBOL(memory_end);
100
unsigned long memory_limit = 0;
Linus Torvalds's avatar
Linus Torvalds committed
101

102
103
static struct resource mem_resources[MAX_NUMNODES];

104
105
int l1i_cache_shape, l1d_cache_shape, l2_cache_shape;

Paul Mundt's avatar
Paul Mundt committed
106
static int __init early_parse_mem(char *p)
Linus Torvalds's avatar
Linus Torvalds committed
107
{
108
109
	if (!p)
		return 1;
Linus Torvalds's avatar
Linus Torvalds committed
110

111
	memory_limit = PAGE_ALIGN(memparse(p, &p));
112

113
	pr_notice("Memory limited to %ldMB\n", memory_limit >> 20);
Paul Mundt's avatar
Paul Mundt committed
114

Linus Torvalds's avatar
Linus Torvalds committed
115
116
	return 0;
}
Paul Mundt's avatar
Paul Mundt committed
117
early_param("mem", early_parse_mem);
Linus Torvalds's avatar
Linus Torvalds committed
118

Paul Mundt's avatar
Paul Mundt committed
119
void __init check_for_initrd(void)
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
{
#ifdef CONFIG_BLK_DEV_INITRD
	unsigned long start, end;

	/*
	 * Check for the rare cases where boot loaders adhere to the boot
	 * ABI.
	 */
	if (!LOADER_TYPE || !INITRD_START || !INITRD_SIZE)
		goto disable;

	start = INITRD_START + __MEMORY_START;
	end = start + INITRD_SIZE;

	if (unlikely(end <= start))
		goto disable;
	if (unlikely(start & ~PAGE_MASK)) {
		pr_err("initrd must be page aligned\n");
		goto disable;
	}

141
142
143
	if (unlikely(start < __MEMORY_START)) {
		pr_err("initrd start (%08lx) < __MEMORY_START(%x)\n",
			start, __MEMORY_START);
144
145
146
		goto disable;
	}

Yinghai Lu's avatar
Yinghai Lu committed
147
	if (unlikely(end > memblock_end_of_DRAM())) {
148
149
		pr_err("initrd extends beyond end of memory "
		       "(0x%08lx > 0x%08lx)\ndisabling initrd\n",
Yinghai Lu's avatar
Yinghai Lu committed
150
		       end, (unsigned long)memblock_end_of_DRAM());
151
152
153
154
		goto disable;
	}

	/*
Lucas De Marchi's avatar
Lucas De Marchi committed
155
	 * If we got this far in spite of the boot loader's best efforts
156
157
158
159
160
161
162
163
	 * to the contrary, assume we actually have a valid initrd and
	 * fix up the root dev.
	 */
	ROOT_DEV = Root_RAM0;

	/*
	 * Address sanitization
	 */
164
	initrd_start = (unsigned long)__va(start);
165
166
	initrd_end = initrd_start + INITRD_SIZE;

Yinghai Lu's avatar
Yinghai Lu committed
167
	memblock_reserve(__pa(initrd_start), INITRD_SIZE);
168
169
170
171
172
173
174
175
176

	return;

disable:
	pr_info("initrd disabled\n");
	initrd_start = initrd_end = 0;
#endif
}

177
#ifndef CONFIG_GENERIC_CALIBRATE_DELAY
178
void calibrate_delay(void)
179
180
181
182
183
184
185
186
187
188
189
190
191
192
{
	struct clk *clk = clk_get(NULL, "cpu_clk");

	if (IS_ERR(clk))
		panic("Need a sane CPU clock definition!");

	loops_per_jiffy = (clk_get_rate(clk) >> 1) / HZ;

	printk(KERN_INFO "Calibrating delay loop (skipped)... "
			 "%lu.%02lu BogoMIPS PRESET (lpj=%lu)\n",
			 loops_per_jiffy/(500000/HZ),
			 (loops_per_jiffy/(5000/HZ)) % 100,
			 loops_per_jiffy);
}
193
#endif
194

195
196
197
198
void __init __add_active_range(unsigned int nid, unsigned long start_pfn,
						unsigned long end_pfn)
{
	struct resource *res = &mem_resources[nid];
199
	unsigned long start, end;
200
201
202

	WARN_ON(res->name); /* max one active range per node for now */

203
204
205
	start = start_pfn << PAGE_SHIFT;
	end = end_pfn << PAGE_SHIFT;

206
	res->name = "System RAM";
207
208
	res->start = start;
	res->end = end - 1;
209
	res->flags = IORESOURCE_SYSTEM_RAM | IORESOURCE_BUSY;
210

211
212
213
214
215
216
217
	if (request_resource(&iomem_resource, res)) {
		pr_err("unable to request memory_resource 0x%lx 0x%lx\n",
		       start_pfn, end_pfn);
		return;
	}

	/*
Simon Horman's avatar
Simon Horman committed
218
219
220
	 * We don't know which RAM region contains kernel data or
	 * the reserved crashkernel region, so try it repeatedly
	 * and let the resource manager test it.
221
222
223
224
	 */
	request_resource(res, &code_resource);
	request_resource(res, &data_resource);
	request_resource(res, &bss_resource);
Simon Horman's avatar
Simon Horman committed
225
226
227
#ifdef CONFIG_KEXEC
	request_resource(res, &crashk_res);
#endif
228

Linus Torvalds's avatar
Linus Torvalds committed
229
	/*
230
231
232
	 * Also make sure that there is a PMB mapping that covers this
	 * range before we attempt to activate it, to avoid reset by MMU.
	 * We can hit this path with NUMA or memory hot-add.
Linus Torvalds's avatar
Linus Torvalds committed
233
	 */
234
235
	pmb_bolt_mapping((unsigned long)__va(start), start, end - start,
			 PAGE_KERNEL);
Matt Fleming's avatar
Matt Fleming committed
236

237
238
	memblock_set_node(PFN_PHYS(start_pfn), PFN_PHYS(end_pfn - start_pfn),
			  &memblock.memory, nid);
239
240
}

241
void __init __weak plat_early_device_setup(void)
242
243
244
{
}

245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
#ifdef CONFIG_OF
void __ref sh_fdt_init(phys_addr_t dt_phys)
{
	static int done = 0;
	void *dt_virt;

	/* Avoid calling an __init function on secondary cpus. */
	if (done) return;

	dt_virt = phys_to_virt(dt_phys);

	if (!dt_virt || !early_init_dt_scan(dt_virt)) {
		pr_crit("Error: invalid device tree blob"
			" at physical address %p\n", (void *)dt_phys);

		while (true)
			cpu_relax();
	}

	done = 1;
}
#endif

268
269
270
271
272
273
void __init setup_arch(char **cmdline_p)
{
	enable_mmu();

	ROOT_DEV = old_decode_dev(ORIG_ROOT_DEV);

274
275
276
277
278
279
280
281
282
283
284
	printk(KERN_NOTICE "Boot params:\n"
			   "... MOUNT_ROOT_RDONLY - %08lx\n"
			   "... RAMDISK_FLAGS     - %08lx\n"
			   "... ORIG_ROOT_DEV     - %08lx\n"
			   "... LOADER_TYPE       - %08lx\n"
			   "... INITRD_START      - %08lx\n"
			   "... INITRD_SIZE       - %08lx\n",
			   MOUNT_ROOT_RDONLY, RAMDISK_FLAGS,
			   ORIG_ROOT_DEV, LOADER_TYPE,
			   INITRD_START, INITRD_SIZE);

285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
#ifdef CONFIG_BLK_DEV_RAM
	rd_image_start = RAMDISK_FLAGS & RAMDISK_IMAGE_START_MASK;
	rd_prompt = ((RAMDISK_FLAGS & RAMDISK_PROMPT_FLAG) != 0);
	rd_doload = ((RAMDISK_FLAGS & RAMDISK_LOAD_FLAG) != 0);
#endif

	if (!MOUNT_ROOT_RDONLY)
		root_mountflags &= ~MS_RDONLY;
	init_mm.start_code = (unsigned long) _text;
	init_mm.end_code = (unsigned long) _etext;
	init_mm.end_data = (unsigned long) _edata;
	init_mm.brk = (unsigned long) _end;

	code_resource.start = virt_to_phys(_text);
	code_resource.end = virt_to_phys(_etext)-1;
	data_resource.start = virt_to_phys(_etext);
	data_resource.end = virt_to_phys(_edata)-1;
Magnus Damm's avatar
Magnus Damm committed
302
	bss_resource.start = virt_to_phys(__bss_start);
303
	bss_resource.end = virt_to_phys(__bss_stop)-1;
304

305
#ifdef CONFIG_CMDLINE_OVERWRITE
306
307
308
	strlcpy(command_line, CONFIG_CMDLINE, sizeof(command_line));
#else
	strlcpy(command_line, COMMAND_LINE, sizeof(command_line));
309
310
311
312
#ifdef CONFIG_CMDLINE_EXTEND
	strlcat(command_line, " ", sizeof(command_line));
	strlcat(command_line, CONFIG_CMDLINE, sizeof(command_line));
#endif
313
#endif
Paul Mundt's avatar
Paul Mundt committed
314

315
316
	/* Save unparsed command line copy for /proc/cmdline */
	memcpy(boot_command_line, command_line, COMMAND_LINE_SIZE);
Paul Mundt's avatar
Paul Mundt committed
317
318
	*cmdline_p = command_line;

319
320
	parse_early_param();

321
322
	plat_early_device_setup();

Paul Mundt's avatar
Paul Mundt committed
323
	sh_mv_setup();
324

Paul Mundt's avatar
Paul Mundt committed
325
326
	/* Let earlyprintk output early console messages */
	early_platform_driver_probe("earlyprintk", 1, 1);
Paul Mundt's avatar
Paul Mundt committed
327

Paul Mundt's avatar
Paul Mundt committed
328
	paging_init();
Linus Torvalds's avatar
Linus Torvalds committed
329
330
331
332
333
334

#ifdef CONFIG_DUMMY_CONSOLE
	conswitchp = &dummy_con;
#endif

	/* Perform the machine specific initialisation */
Paul Mundt's avatar
Paul Mundt committed
335
336
	if (likely(sh_mv.mv_setup))
		sh_mv.mv_setup(cmdline_p);
Linus Torvalds's avatar
Linus Torvalds committed
337

338
	plat_smp_setup();
Paul Mundt's avatar
Paul Mundt committed
339
}
Linus Torvalds's avatar
Linus Torvalds committed
340

341
342
343
344
345
346
347
348
349
/* processor boot mode configuration */
int generic_mode_pins(void)
{
	pr_warning("generic_mode_pins(): missing mode pin configuration\n");
	return 0;
}

int test_mode_pin(int pin)
{
Magnus Damm's avatar
Magnus Damm committed
350
	return sh_mv.mv_mode_pins() & pin;
351
}