summaryrefslogtreecommitdiffstats
path: root/arch/sh64/kernel/setup.c
blob: b9e7d54d7b8553d89d2c9988c561f4227d38d19b (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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
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
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
/*
 * This file is subject to the terms and conditions of the GNU General Public
 * License.  See the file "COPYING" in the main directory of this archive
 * for more details.
 *
 * arch/sh64/kernel/setup.c
 *
 * sh64 Arch Support
 *
 * This file handles the architecture-dependent parts of initialization
 *
 * Copyright (C) 2000, 2001  Paolo Alberelli
 * Copyright (C) 2003, 2004  Paul Mundt
 *
 * benedict.gaster@superh.com:   2nd May 2002
 *    Modified to use the empty_zero_page to pass command line arguments.
 *
 * benedict.gaster@superh.com:	 3rd May 2002
 *    Added support for ramdisk, removing statically linked romfs at the same time.
 *
 * lethal@linux-sh.org:          15th May 2003
 *    Added generic procfs cpuinfo reporting. Make boards just export their name.
 *
 * lethal@linux-sh.org:          25th May 2003
 *    Added generic get_cpu_subtype() for subtype reporting from cpu_data->type.
 *
 */
#include <linux/errno.h>
#include <linux/rwsem.h>
#include <linux/sched.h>
#include <linux/kernel.h>
#include <linux/mm.h>
#include <linux/stddef.h>
#include <linux/unistd.h>
#include <linux/ptrace.h>
#include <linux/slab.h>
#include <linux/user.h>
#include <linux/a.out.h>
#include <linux/screen_info.h>
#include <linux/ioport.h>
#include <linux/delay.h>
#include <linux/init.h>
#include <linux/seq_file.h>
#include <linux/blkdev.h>
#include <linux/bootmem.h>
#include <linux/console.h>
#include <linux/root_dev.h>
#include <linux/cpu.h>
#include <linux/initrd.h>
#include <linux/pfn.h>
#include <asm/processor.h>
#include <asm/page.h>
#include <asm/pgtable.h>
#include <asm/platform.h>
#include <asm/uaccess.h>
#include <asm/system.h>
#include <asm/io.h>
#include <asm/sections.h>
#include <asm/setup.h>
#include <asm/smp.h>

#ifdef CONFIG_VT
#include <linux/console.h>
#endif

struct screen_info screen_info;

#ifdef CONFIG_BLK_DEV_RAM
extern int rd_doload;		/* 1 = load ramdisk, 0 = don't load */
extern int rd_prompt;		/* 1 = prompt for ramdisk, 0 = don't prompt */
extern int rd_image_start;	/* starting block # of image */
#endif

extern int root_mountflags;
extern char *get_system_type(void);
extern void platform_setup(void);
extern void platform_monitor(void);
extern void platform_reserve(void);
extern int sh64_cache_init(void);
extern int sh64_tlb_init(void);

#define RAMDISK_IMAGE_START_MASK	0x07FF
#define RAMDISK_PROMPT_FLAG		0x8000
#define RAMDISK_LOAD_FLAG		0x4000

static char command_line[COMMAND_LINE_SIZE] = { 0, };
unsigned long long memory_start = CONFIG_MEMORY_START;
unsigned long long memory_end = CONFIG_MEMORY_START + (CONFIG_MEMORY_SIZE_IN_MB * 1024 * 1024);

struct sh_cpuinfo boot_cpu_data;

static inline void parse_mem_cmdline (char ** cmdline_p)
{
        char c = ' ', *to = command_line, *from = COMMAND_LINE;
	int len = 0;

	/* Save unparsed command line copy for /proc/cmdline */
	memcpy(saved_command_line, COMMAND_LINE, COMMAND_LINE_SIZE);
	saved_command_line[COMMAND_LINE_SIZE-1] = '\0';

	for (;;) {
	  /*
	   * "mem=XXX[kKmM]" defines a size of memory.
	   */
	        if (c == ' ' && !memcmp(from, "mem=", 4)) {
		      if (to != command_line)
			to--;
		      {
			unsigned long mem_size;

			mem_size = memparse(from+4, &from);
			memory_end = memory_start + mem_size;
		      }
		}
		c = *(from++);
		if (!c)
		  break;
		if (COMMAND_LINE_SIZE <= ++len)
		  break;
		*(to++) = c;
	}
	*to = '\0';

	*cmdline_p = command_line;
}

static void __init sh64_cpu_type_detect(void)
{
	extern unsigned long long peek_real_address_q(unsigned long long addr);
	unsigned long long cir;
	/* Do peeks in real mode to avoid having to set up a mapping for the
	   WPC registers.  On SH5-101 cut2, such a mapping would be exposed to
	   an address translation erratum which would make it hard to set up
	   correctly. */
	cir = peek_real_address_q(0x0d000008);

	if ((cir & 0xffff) == 0x5103) {
		boot_cpu_data.type = CPU_SH5_103;
	} else if (((cir >> 32) & 0xffff) == 0x51e2) {
		/* CPU.VCR aliased at CIR address on SH5-101 */
		boot_cpu_data.type = CPU_SH5_101;
	} else {
		boot_cpu_data.type = CPU_SH_NONE;
	}
}

void __init setup_arch(char **cmdline_p)
{
	unsigned long bootmap_size, i;
	unsigned long first_pfn, start_pfn, last_pfn, pages;

#ifdef CONFIG_EARLY_PRINTK
	extern void enable_early_printk(void);

	/*
	 * Setup Early SCIF console
	 */
	enable_early_printk();
#endif

	/*
	 * Setup TLB mappings
	 */
	sh64_tlb_init();

	/*
	 * Caches are already initialized by the time we get here, so we just
	 * fill in cpu_data info for the caches.
	 */
	sh64_cache_init();

	platform_setup();
	platform_monitor();

	sh64_cpu_type_detect();

	ROOT_DEV = old_decode_dev(ORIG_ROOT_DEV);

#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 = __pa(_text);
	code_resource.end = __pa(_etext)-1;
	data_resource.start = __pa(_etext);
	data_resource.end = __pa(_edata)-1;

	parse_mem_cmdline(cmdline_p);

	/*
	 * Find the lowest and highest page frame numbers we have available
	 */
	first_pfn = PFN_DOWN(memory_start);
	last_pfn = PFN_DOWN(memory_end);
	pages = last_pfn - first_pfn;

	/*
	 * Partially used pages are not usable - thus
	 * we are rounding upwards:
	 */
	start_pfn = PFN_UP(__pa(_end));

	/*
	 * Find a proper area for the bootmem bitmap. After this
	 * bootstrap step all allocations (until the page allocator
	 * is intact) must be done via bootmem_alloc().
	 */
	bootmap_size = init_bootmem_node(NODE_DATA(0), start_pfn,
					 first_pfn,
					 last_pfn);
        /*
         * Round it up.
         */
        bootmap_size = PFN_PHYS(PFN_UP(bootmap_size));

	/*
	 * Register fully available RAM pages with the bootmem allocator.
	 */
	free_bootmem_node(NODE_DATA(0), PFN_PHYS(first_pfn), PFN_PHYS(pages));

	/*
	 * Reserve all kernel sections + bootmem bitmap + a guard page.
	 */
	reserve_bootmem_node(NODE_DATA(0), PFN_PHYS(first_pfn),
		        (PFN_PHYS(start_pfn) + bootmap_size + PAGE_SIZE) - PFN_PHYS(first_pfn));

	/*
	 * Reserve platform dependent sections
	 */
	platform_reserve();

#ifdef CONFIG_BLK_DEV_INITRD
	if (LOADER_TYPE && INITRD_START) {
		if (INITRD_START + INITRD_SIZE <= (PFN_PHYS(last_pfn))) {
		        reserve_bootmem_node(NODE_DATA(0), INITRD_START + __MEMORY_START, INITRD_SIZE);

			initrd_start = (long) INITRD_START + PAGE_OFFSET + __MEMORY_START;
			initrd_end = initrd_start + INITRD_SIZE;
		} else {
			printk("initrd extends beyond end of memory "
			    "(0x%08lx > 0x%08lx)\ndisabling initrd\n",
				    (long) INITRD_START + INITRD_SIZE,
				    PFN_PHYS(last_pfn));
			initrd_start = 0;
		}
	}
#endif

	/*
	 * Claim all RAM, ROM, and I/O resources.
	 */

	/* Kernel RAM */
	request_resource(&iomem_resource, &code_resource);
	request_resource(&iomem_resource, &data_resource);

	/* Other KRAM space */
	for (i = 0; i < STANDARD_KRAM_RESOURCES - 2; i++)
		request_resource(&iomem_resource,
				 &platform_parms.kram_res_p[i]);

	/* XRAM space */
	for (i = 0; i < STANDARD_XRAM_RESOURCES; i++)
		request_resource(&iomem_resource,
				 &platform_parms.xram_res_p[i]);

	/* ROM space */
	for (i = 0; i < STANDARD_ROM_RESOURCES; i++)
		request_resource(&iomem_resource,
				 &platform_parms.rom_res_p[i]);

	/* I/O space */
	for (i = 0; i < STANDARD_IO_RESOURCES; i++)
		request_resource(&ioport_resource,
				 &platform_parms.io_res_p[i]);


#ifdef CONFIG_VT
#if defined(CONFIG_VGA_CONSOLE)
	conswitchp = &vga_con;
#elif defined(CONFIG_DUMMY_CONSOLE)
	conswitchp = &dummy_con;
#endif
#endif

	printk("Hardware FPU: %s\n", fpu_in_use ? "enabled" : "disabled");

	paging_init();
}

void __xchg_called_with_bad_pointer(void)
{
	printk(KERN_EMERG "xchg() called with bad pointer !\n");
}

static struct cpu cpu[1];

static int __init topology_init(void)
{
	return register_cpu(cpu, 0);
}

subsys_initcall(topology_init);

/*
 *	Get CPU information
 */
static const char *cpu_name[] = {
	[CPU_SH5_101]	= "SH5-101",
	[CPU_SH5_103]	= "SH5-103",
	[CPU_SH_NONE]	= "Unknown",
};

const char *get_cpu_subtype(void)
{
	return cpu_name[boot_cpu_data.type];
}

#ifdef CONFIG_PROC_FS
static int show_cpuinfo(struct seq_file *m,void *v)
{
	unsigned int cpu = smp_processor_id();

	if (!cpu)
		seq_printf(m, "machine\t\t: %s\n", get_system_type());

	seq_printf(m, "processor\t: %d\n", cpu);
	seq_printf(m, "cpu family\t: SH-5\n");
	seq_printf(m, "cpu type\t: %s\n", get_cpu_subtype());

	seq_printf(m, "icache size\t: %dK-bytes\n",
		   (boot_cpu_data.icache.ways *
		    boot_cpu_data.icache.sets *
		    boot_cpu_data.icache.linesz) >> 10);
	seq_printf(m, "dcache size\t: %dK-bytes\n",
		   (boot_cpu_data.dcache.ways *
		    boot_cpu_data.dcache.sets *
		    boot_cpu_data.dcache.linesz) >> 10);
	seq_printf(m, "itlb entries\t: %d\n", boot_cpu_data.itlb.entries);
	seq_printf(m, "dtlb entries\t: %d\n", boot_cpu_data.dtlb.entries);

#define PRINT_CLOCK(name, value) \
	seq_printf(m, name " clock\t: %d.%02dMHz\n", \
		     ((value) / 1000000), ((value) % 1000000)/10000)

	PRINT_CLOCK("cpu", boot_cpu_data.cpu_clock);
	PRINT_CLOCK("bus", boot_cpu_data.bus_clock);
	PRINT_CLOCK("module", boot_cpu_data.module_clock);

        seq_printf(m, "bogomips\t: %lu.%02lu\n\n",
		     (loops_per_jiffy*HZ+2500)/500000,
		     ((loops_per_jiffy*HZ+2500)/5000) % 100);

	return 0;
}

static void *c_start(struct seq_file *m, loff_t *pos)
{
	return (void*)(*pos == 0);
}
static void *c_next(struct seq_file *m, void *v, loff_t *pos)
{
	return NULL;
}
static void c_stop(struct seq_file *m, void *v)
{
}
struct seq_operations cpuinfo_op = {
	.start	= c_start,
	.next	= c_next,
	.stop	= c_stop,
	.show	= show_cpuinfo,
};
#endif /* CONFIG_PROC_FS */