setup.c 7.9 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>
L
Linus Torvalds 已提交
32 33
#include <asm/uaccess.h>
#include <asm/io.h>
34
#include <asm/page.h>
35
#include <asm/elf.h>
L
Linus Torvalds 已提交
36 37 38
#include <asm/sections.h>
#include <asm/irq.h>
#include <asm/setup.h>
39
#include <asm/clock.h>
40
#include <asm/smp.h>
41
#include <asm/mmu_context.h>
42
#include <asm/mmzone.h>
P
Paul Mundt 已提交
43
#include <asm/sparsemem.h>
L
Linus Torvalds 已提交
44 45 46 47 48 49

/*
 * 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 已提交
50 51 52
struct sh_cpuinfo cpu_data[NR_CPUS] __read_mostly = {
	[0] = {
		.type			= CPU_SH_NONE,
53
		.family			= CPU_FAMILY_UNKNOWN,
P
Paul Mundt 已提交
54
		.loops_per_jiffy	= 10000000,
55
		.phys_bits		= MAX_PHYSMEM_BITS,
P
Paul Mundt 已提交
56 57 58
	},
};
EXPORT_SYMBOL(cpu_data);
P
Paul Mundt 已提交
59 60 61 62 63

/*
 * The machine vector. First entry in .machvec.init, or clobbered by
 * sh_mv= on the command line, prior to .machvec.init teardown.
 */
64
struct sh_machine_vector sh_mv = { .mv_name = "generic", };
65
EXPORT_SYMBOL(sh_mv);
P
Paul Mundt 已提交
66

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

extern int root_mountflags;

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

77
static char __initdata command_line[COMMAND_LINE_SIZE] = { 0, };
L
Linus Torvalds 已提交
78

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

static struct resource data_resource = {
	.name = "Kernel data",
	.flags = IORESOURCE_BUSY | IORESOURCE_MEM,
};
L
Linus Torvalds 已提交
88

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

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

100 101
static struct resource mem_resources[MAX_NUMNODES];

102 103
int l1i_cache_shape, l1d_cache_shape, l2_cache_shape;

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

109
	memory_limit = PAGE_ALIGN(memparse(p, &p));
110

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

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

P
Paul Mundt 已提交
117
void __init check_for_initrd(void)
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
{
#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;
	}

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

Y
Yinghai Lu 已提交
145
	if (unlikely(end > memblock_end_of_DRAM())) {
146 147
		pr_err("initrd extends beyond end of memory "
		       "(0x%08lx > 0x%08lx)\ndisabling initrd\n",
Y
Yinghai Lu 已提交
148
		       end, (unsigned long)memblock_end_of_DRAM());
149 150 151 152
		goto disable;
	}

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

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

Y
Yinghai Lu 已提交
165
	memblock_reserve(__pa(initrd_start), INITRD_SIZE);
166 167 168 169 170 171 172 173 174

	return;

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

175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190
void __cpuinit calibrate_delay(void)
{
	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);
}

191 192 193 194
void __init __add_active_range(unsigned int nid, unsigned long start_pfn,
						unsigned long end_pfn)
{
	struct resource *res = &mem_resources[nid];
195
	unsigned long start, end;
196 197 198

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

199 200 201
	start = start_pfn << PAGE_SHIFT;
	end = end_pfn << PAGE_SHIFT;

202
	res->name = "System RAM";
203 204
	res->start = start;
	res->end = end - 1;
205
	res->flags = IORESOURCE_MEM | IORESOURCE_BUSY;
206

207 208 209 210 211 212 213
	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 已提交
214 215 216
	 * 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.
217 218 219 220
	 */
	request_resource(res, &code_resource);
	request_resource(res, &data_resource);
	request_resource(res, &bss_resource);
S
Simon Horman 已提交
221 222 223
#ifdef CONFIG_KEXEC
	request_resource(res, &crashk_res);
#endif
224

L
Linus Torvalds 已提交
225
	/*
226 227 228
	 * 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 已提交
229
	 */
230 231
	pmb_bolt_mapping((unsigned long)__va(start), start, end - start,
			 PAGE_KERNEL);
M
Matt Fleming 已提交
232

T
Tejun Heo 已提交
233 234
	memblock_set_node(PFN_PHYS(start_pfn),
			  PFN_PHYS(end_pfn - start_pfn), nid);
235 236
}

237
void __init __weak plat_early_device_setup(void)
M
Magnus Damm 已提交
238 239 240
{
}

241 242 243 244 245 246
void __init setup_arch(char **cmdline_p)
{
	enable_mmu();

	ROOT_DEV = old_decode_dev(ORIG_ROOT_DEV);

247 248 249 250 251 252 253 254 255 256 257
	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);

258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274
#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 已提交
275 276
	bss_resource.start = virt_to_phys(__bss_start);
	bss_resource.end = virt_to_phys(_ebss)-1;
277

278
#ifdef CONFIG_CMDLINE_OVERWRITE
279 280 281
	strlcpy(command_line, CONFIG_CMDLINE, sizeof(command_line));
#else
	strlcpy(command_line, COMMAND_LINE, sizeof(command_line));
282 283 284 285
#ifdef CONFIG_CMDLINE_EXTEND
	strlcat(command_line, " ", sizeof(command_line));
	strlcat(command_line, CONFIG_CMDLINE, sizeof(command_line));
#endif
286
#endif
P
Paul Mundt 已提交
287

288 289
	/* Save unparsed command line copy for /proc/cmdline */
	memcpy(boot_command_line, command_line, COMMAND_LINE_SIZE);
P
Paul Mundt 已提交
290 291
	*cmdline_p = command_line;

292 293
	parse_early_param();

M
Magnus Damm 已提交
294 295
	plat_early_device_setup();

P
Paul Mundt 已提交
296
	sh_mv_setup();
297

P
Paul Mundt 已提交
298 299
	/* Let earlyprintk output early console messages */
	early_platform_driver_probe("earlyprintk", 1, 1);
P
Paul Mundt 已提交
300

P
Paul Mundt 已提交
301
	paging_init();
L
Linus Torvalds 已提交
302 303 304 305 306 307

#ifdef CONFIG_DUMMY_CONSOLE
	conswitchp = &dummy_con;
#endif

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

311
	plat_smp_setup();
P
Paul Mundt 已提交
312
}
L
Linus Torvalds 已提交
313

314 315 316 317 318 319 320 321 322
/* 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 已提交
323
	return sh_mv.mv_mode_pins() & pin;
324
}