setup.c 8.5 KB
Newer Older
P
Paul Mundt 已提交
1
/*
2
 * arch/sh/kernel/setup.c
L
Linus Torvalds 已提交
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
L
Linus Torvalds 已提交
8
 */
9
#include <linux/screen_info.h>
L
Linus Torvalds 已提交
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>
L
Linus Torvalds 已提交
18
#include <linux/cpu.h>
D
Dave Hansen 已提交
19
#include <linux/pfn.h>
P
Paul Mundt 已提交
20
#include <linux/fs.h>
21
#include <linux/mm.h>
P
Paul Mundt 已提交
22
#include <linux/kexec.h>
23
#include <linux/module.h>
24
#include <linux/smp.h>
P
Paul Mundt 已提交
25
#include <linux/err.h>
26
#include <linux/crash_dump.h>
P
Paul Mundt 已提交
27
#include <linux/mmzone.h>
28 29
#include <linux/clk.h>
#include <linux/delay.h>
M
Magnus Damm 已提交
30
#include <linux/platform_device.h>
Y
Yinghai Lu 已提交
31
#include <linux/memblock.h>
32 33
#include <linux/of.h>
#include <linux/of_fdt.h>
L
Linus Torvalds 已提交
34 35
#include <asm/uaccess.h>
#include <asm/io.h>
36
#include <asm/page.h>
37
#include <asm/elf.h>
L
Linus Torvalds 已提交
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>
P
Paul Mundt 已提交
45
#include <asm/sparsemem.h>
L
Linus Torvalds 已提交
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.
 */
P
Paul Mundt 已提交
52 53 54
struct sh_cpuinfo cpu_data[NR_CPUS] __read_mostly = {
	[0] = {
		.type			= CPU_SH_NONE,
55
		.family			= CPU_FAMILY_UNKNOWN,
P
Paul Mundt 已提交
56
		.loops_per_jiffy	= 10000000,
57
		.phys_bits		= MAX_PHYSMEM_BITS,
P
Paul Mundt 已提交
58 59 60
	},
};
EXPORT_SYMBOL(cpu_data);
P
Paul Mundt 已提交
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);
P
Paul Mundt 已提交
68

P
Paul Mundt 已提交
69
#ifdef CONFIG_VT
L
Linus Torvalds 已提交
70
struct screen_info screen_info;
P
Paul Mundt 已提交
71
#endif
L
Linus Torvalds 已提交
72 73 74

extern int root_mountflags;

75
#define RAMDISK_IMAGE_START_MASK	0x07FF
L
Linus Torvalds 已提交
76
#define RAMDISK_PROMPT_FLAG		0x8000
77
#define RAMDISK_LOAD_FLAG		0x4000
L
Linus Torvalds 已提交
78

79
static char __initdata command_line[COMMAND_LINE_SIZE] = { 0, };
L
Linus Torvalds 已提交
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
};
L
Linus Torvalds 已提交
90

M
Magnus Damm 已提交
91 92
static struct resource bss_resource = {
	.name	= "Kernel bss",
93
	.flags	= IORESOURCE_BUSY | IORESOURCE_SYSTEM_RAM,
M
Magnus Damm 已提交
94 95
};

96 97
unsigned long memory_start;
EXPORT_SYMBOL(memory_start);
P
Paul Mundt 已提交
98
unsigned long memory_end = 0;
99
EXPORT_SYMBOL(memory_end);
100
unsigned long memory_limit = 0;
L
Linus Torvalds 已提交
101

102 103
static struct resource mem_resources[MAX_NUMNODES];

104 105
int l1i_cache_shape, l1d_cache_shape, l2_cache_shape;

P
Paul Mundt 已提交
106
static int __init early_parse_mem(char *p)
L
Linus Torvalds 已提交
107
{
108 109
	if (!p)
		return 1;
L
Linus Torvalds 已提交
110

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

113
	pr_notice("Memory limited to %ldMB\n", memory_limit >> 20);
P
Paul Mundt 已提交
114

L
Linus Torvalds 已提交
115 116
	return 0;
}
P
Paul Mundt 已提交
117
early_param("mem", early_parse_mem);
L
Linus Torvalds 已提交
118

P
Paul Mundt 已提交
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;
	}

Y
Yinghai Lu 已提交
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",
Y
Yinghai Lu 已提交
150
		       end, (unsigned long)memblock_end_of_DRAM());
151 152 153 154
		goto disable;
	}

	/*
L
Lucas De Marchi 已提交
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;

Y
Yinghai Lu 已提交
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;
	}

	/*
S
Simon Horman 已提交
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);
S
Simon Horman 已提交
225 226 227
#ifdef CONFIG_KEXEC
	request_resource(res, &crashk_res);
#endif
228

L
Linus Torvalds 已提交
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.
L
Linus Torvalds 已提交
233
	 */
234 235
	pmb_bolt_mapping((unsigned long)__va(start), start, end - start,
			 PAGE_KERNEL);
M
Matt Fleming 已提交
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)
M
Magnus Damm 已提交
242 243 244
{
}

245
#ifdef CONFIG_OF_FLATTREE
246 247 248 249 250 251 252 253
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;

254 255 256
#ifdef CONFIG_USE_BUILTIN_DTB
	dt_virt = __dtb_start;
#else
257
	dt_virt = phys_to_virt(dt_phys);
258
#endif
259 260 261 262 263 264 265 266 267 268 269 270 271

	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

272 273 274 275 276 277
void __init setup_arch(char **cmdline_p)
{
	enable_mmu();

	ROOT_DEV = old_decode_dev(ORIG_ROOT_DEV);

278 279 280 281 282 283 284 285 286 287 288
	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);

289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305
#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;
M
Magnus Damm 已提交
306
	bss_resource.start = virt_to_phys(__bss_start);
307
	bss_resource.end = virt_to_phys(__bss_stop)-1;
308

309
#ifdef CONFIG_CMDLINE_OVERWRITE
310 311 312
	strlcpy(command_line, CONFIG_CMDLINE, sizeof(command_line));
#else
	strlcpy(command_line, COMMAND_LINE, sizeof(command_line));
313 314 315 316
#ifdef CONFIG_CMDLINE_EXTEND
	strlcat(command_line, " ", sizeof(command_line));
	strlcat(command_line, CONFIG_CMDLINE, sizeof(command_line));
#endif
317
#endif
P
Paul Mundt 已提交
318

319 320
	/* Save unparsed command line copy for /proc/cmdline */
	memcpy(boot_command_line, command_line, COMMAND_LINE_SIZE);
P
Paul Mundt 已提交
321 322
	*cmdline_p = command_line;

323 324
	parse_early_param();

M
Magnus Damm 已提交
325 326
	plat_early_device_setup();

P
Paul Mundt 已提交
327
	sh_mv_setup();
328

P
Paul Mundt 已提交
329 330
	/* Let earlyprintk output early console messages */
	early_platform_driver_probe("earlyprintk", 1, 1);
P
Paul Mundt 已提交
331

P
Paul Mundt 已提交
332
	paging_init();
L
Linus Torvalds 已提交
333 334 335 336 337 338

#ifdef CONFIG_DUMMY_CONSOLE
	conswitchp = &dummy_con;
#endif

	/* Perform the machine specific initialisation */
P
Paul Mundt 已提交
339 340
	if (likely(sh_mv.mv_setup))
		sh_mv.mv_setup(cmdline_p);
L
Linus Torvalds 已提交
341

342
	plat_smp_setup();
P
Paul Mundt 已提交
343
}
L
Linus Torvalds 已提交
344

345 346 347 348 349 350 351 352 353
/* 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)
{
M
Magnus Damm 已提交
354
	return sh_mv.mv_mode_pins() & pin;
355
}