1/*
2 *  linux/arch/arm26/kernel/setup.c
3 *
4 *  Copyright (C) 1995-2001 Russell King
5 *  Copyright (C) 2003 Ian Molton
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11#include <linux/kernel.h>
12#include <linux/stddef.h>
13#include <linux/ioport.h>
14#include <linux/delay.h>
15#include <linux/utsname.h>
16#include <linux/blkdev.h>
17#include <linux/console.h>
18#include <linux/bootmem.h>
19#include <linux/seq_file.h>
20#include <linux/screen_info.h>
21#include <linux/init.h>
22#include <linux/root_dev.h>
23
24#include <asm/elf.h>
25#include <asm/hardware.h>
26#include <asm/io.h>
27#include <asm/procinfo.h>
28#include <asm/setup.h>
29#include <asm/mach-types.h>
30#include <asm/tlbflush.h>
31
32#include <asm/irqchip.h>
33
34#ifndef MEM_SIZE
35#define MEM_SIZE	(16*1024*1024)
36#endif
37
38#ifdef CONFIG_PREEMPT
39DEFINE_SPINLOCK(kernel_flag);
40#endif
41
42#if defined(CONFIG_FPE_NWFPE)
43char fpe_type[8];
44
45static int __init fpe_setup(char *line)
46{
47	memcpy(fpe_type, line, 8);
48	return 1;
49}
50
51__setup("fpe=", fpe_setup);
52#endif
53
54extern void paging_init(struct meminfo *);
55extern void convert_to_tag_list(struct tag *tags);
56extern void squash_mem_tags(struct tag *tag);
57extern void bootmem_init(struct meminfo *);
58extern int root_mountflags;
59extern int _stext, _text, _etext, _edata, _end;
60#ifdef CONFIG_XIP_KERNEL
61extern int _endtext, _sdata;
62#endif
63
64
65unsigned int processor_id;
66unsigned int __machine_arch_type;
67unsigned int system_rev;
68unsigned int system_serial_low;
69unsigned int system_serial_high;
70unsigned int elf_hwcap;
71unsigned int memc_ctrl_reg;
72unsigned int number_mfm_drives;
73
74struct processor processor;
75
76char elf_platform[ELF_PLATFORM_SIZE];
77
78unsigned long phys_initrd_start __initdata = 0;
79unsigned long phys_initrd_size __initdata = 0;
80static struct meminfo meminfo __initdata = { 0, };
81static struct proc_info_item proc_info;
82static const char *machine_name;
83static char __initdata command_line[COMMAND_LINE_SIZE];
84
85static char default_command_line[COMMAND_LINE_SIZE] __initdata = CONFIG_CMDLINE;
86
87/*
88 * Standard memory resources
89 */
90static struct resource mem_res[] = {
91	{ "Video RAM",   0,     0,     IORESOURCE_MEM			},
92	{ "Kernel code", 0,     0,     IORESOURCE_MEM			},
93	{ "Kernel data", 0,     0,     IORESOURCE_MEM			}
94};
95
96#define video_ram   mem_res[0]
97#define kernel_code mem_res[1]
98#define kernel_data mem_res[2]
99
100static struct resource io_res[] = {
101	{ "reserved",    0x3bc, 0x3be, IORESOURCE_IO | IORESOURCE_BUSY },
102	{ "reserved",    0x378, 0x37f, IORESOURCE_IO | IORESOURCE_BUSY },
103	{ "reserved",    0x278, 0x27f, IORESOURCE_IO | IORESOURCE_BUSY }
104};
105
106#define lp0 io_res[0]
107#define lp1 io_res[1]
108#define lp2 io_res[2]
109
110#define dump_cpu_info() do { } while (0)
111
112static void __init setup_processor(void)
113{
114	extern struct proc_info_list __proc_info_begin, __proc_info_end;
115	struct proc_info_list *list;
116
117	/*
118	 * locate processor in the list of supported processor
119	 * types.  The linker builds this table for us from the
120	 * entries in arch/arm26/mm/proc-*.S
121	 */
122	for (list = &__proc_info_begin; list < &__proc_info_end ; list++)
123		if ((processor_id & list->cpu_mask) == list->cpu_val)
124			break;
125
126	/*
127	 * If processor type is unrecognised, then we
128	 * can do nothing...
129	 */
130	if (list >= &__proc_info_end) {
131		printk("CPU configuration botched (ID %08x), unable "
132		       "to continue.\n", processor_id);
133		while (1);
134	}
135
136	proc_info = *list->info;
137	processor = *list->proc;
138
139
140	printk("CPU: %s %s revision %d\n",
141	       proc_info.manufacturer, proc_info.cpu_name,
142	       (int)processor_id & 15);
143
144	dump_cpu_info();
145
146	sprintf(init_utsname()->machine, "%s", list->arch_name);
147	sprintf(elf_platform, "%s", list->elf_name);
148	elf_hwcap = list->elf_hwcap;
149
150	cpu_proc_init();
151}
152
153/*
154 * Initial parsing of the command line.  We need to pick out the
155 * memory size.  We look for mem=size@start, where start and size
156 * are "size[KkMm]"
157 */
158static void __init
159parse_cmdline(struct meminfo *mi, char **cmdline_p, char *from)
160{
161	char c = ' ', *to = command_line;
162	int usermem = 0, len = 0;
163
164	for (;;) {
165		if (c == ' ' && !memcmp(from, "mem=", 4)) {
166			unsigned long size, start;
167
168			if (to != command_line)
169				to -= 1;
170
171			/*
172			 * If the user specifies memory size, we
173			 * blow away any automatically generated
174			 * size.
175			 */
176			if (usermem == 0) {
177				usermem = 1;
178				mi->nr_banks = 0;
179			}
180
181			start = PHYS_OFFSET;
182			size  = memparse(from + 4, &from);
183			if (*from == '@')
184				start = memparse(from + 1, &from);
185
186			mi->bank[mi->nr_banks].start = start;
187			mi->bank[mi->nr_banks].size  = size;
188			mi->bank[mi->nr_banks].node  = PHYS_TO_NID(start);
189			mi->nr_banks += 1;
190		}
191		c = *from++;
192		if (!c)
193			break;
194		if (COMMAND_LINE_SIZE <= ++len)
195			break;
196		*to++ = c;
197	}
198	*to = '\0';
199	*cmdline_p = command_line;
200}
201
202static void __init
203setup_ramdisk(int doload, int prompt, int image_start, unsigned int rd_sz)
204{
205#ifdef CONFIG_BLK_DEV_RAM
206	extern int rd_size, rd_image_start, rd_prompt, rd_doload;
207
208	rd_image_start = image_start;
209	rd_prompt = prompt;
210	rd_doload = doload;
211
212	if (rd_sz)
213		rd_size = rd_sz;
214#endif
215}
216
217static void __init
218request_standard_resources(struct meminfo *mi)
219{
220	struct resource *res;
221	int i;
222
223	kernel_code.start  = init_mm.start_code;
224	kernel_code.end    = init_mm.end_code - 1;
225#ifdef CONFIG_XIP_KERNEL
226	kernel_data.start  = init_mm.start_data;
227#else
228	kernel_data.start  = init_mm.end_code;
229#endif
230	kernel_data.end    = init_mm.brk - 1;
231
232	for (i = 0; i < mi->nr_banks; i++) {
233		unsigned long virt_start, virt_end;
234
235		if (mi->bank[i].size == 0)
236			continue;
237
238		virt_start = mi->bank[i].start;
239		virt_end   = virt_start + mi->bank[i].size - 1;
240
241		res = alloc_bootmem_low(sizeof(*res));
242		res->name  = "System RAM";
243		res->start = virt_start;
244		res->end   = virt_end;
245		res->flags = IORESOURCE_MEM | IORESOURCE_BUSY;
246
247		request_resource(&iomem_resource, res);
248
249		if (kernel_code.start >= res->start &&
250		    kernel_code.end <= res->end)
251			request_resource(res, &kernel_code);
252		if (kernel_data.start >= res->start &&
253		    kernel_data.end <= res->end)
254			request_resource(res, &kernel_data);
255	}
256
257
258	/*
259	 * Some machines don't have the possibility of ever
260	 * possessing lp1 or lp2
261	 */
262	if (0)
263		request_resource(&ioport_resource, &lp0);
264}
265
266/*
267 *  Tag parsing.
268 *
269 * This is the new way of passing data to the kernel at boot time.  Rather
270 * than passing a fixed inflexible structure to the kernel, we pass a list
271 * of variable-sized tags to the kernel.  The first tag must be a ATAG_CORE
272 * tag for the list to be recognised (to distinguish the tagged list from
273 * a param_struct).  The list is terminated with a zero-length tag (this tag
274 * is not parsed in any way).
275 */
276static int __init parse_tag_core(const struct tag *tag)
277{
278	if (tag->hdr.size > 2) {
279		if ((tag->u.core.flags & 1) == 0)
280			root_mountflags &= ~MS_RDONLY;
281		ROOT_DEV = old_decode_dev(tag->u.core.rootdev);
282	}
283	return 0;
284}
285
286__tagtable(ATAG_CORE, parse_tag_core);
287
288static int __init parse_tag_mem32(const struct tag *tag)
289{
290	if (meminfo.nr_banks >= NR_BANKS) {
291		printk(KERN_WARNING
292		       "Ignoring memory bank 0x%08x size %dKB\n",
293			tag->u.mem.start, tag->u.mem.size / 1024);
294		return -EINVAL;
295	}
296	meminfo.bank[meminfo.nr_banks].start = tag->u.mem.start;
297	meminfo.bank[meminfo.nr_banks].size  = tag->u.mem.size;
298	meminfo.bank[meminfo.nr_banks].node  = PHYS_TO_NID(tag->u.mem.start);
299	meminfo.nr_banks += 1;
300
301	return 0;
302}
303
304__tagtable(ATAG_MEM, parse_tag_mem32);
305
306#if defined(CONFIG_DUMMY_CONSOLE)
307struct screen_info screen_info = {
308 .orig_video_lines	= 30,
309 .orig_video_cols	= 80,
310 .orig_video_mode	= 0,
311 .orig_video_ega_bx	= 0,
312 .orig_video_isVGA	= 1,
313 .orig_video_points	= 8
314};
315
316static int __init parse_tag_videotext(const struct tag *tag)
317{
318	screen_info.orig_x            = tag->u.videotext.x;
319	screen_info.orig_y            = tag->u.videotext.y;
320	screen_info.orig_video_page   = tag->u.videotext.video_page;
321	screen_info.orig_video_mode   = tag->u.videotext.video_mode;
322	screen_info.orig_video_cols   = tag->u.videotext.video_cols;
323	screen_info.orig_video_ega_bx = tag->u.videotext.video_ega_bx;
324	screen_info.orig_video_lines  = tag->u.videotext.video_lines;
325	screen_info.orig_video_isVGA  = tag->u.videotext.video_isvga;
326	screen_info.orig_video_points = tag->u.videotext.video_points;
327	return 0;
328}
329
330__tagtable(ATAG_VIDEOTEXT, parse_tag_videotext);
331#endif
332
333static int __init parse_tag_acorn(const struct tag *tag)
334{
335        memc_ctrl_reg = tag->u.acorn.memc_control_reg;
336        number_mfm_drives = tag->u.acorn.adfsdrives;
337        return 0;
338}
339
340__tagtable(ATAG_ACORN, parse_tag_acorn);
341
342static int __init parse_tag_ramdisk(const struct tag *tag)
343{
344	setup_ramdisk((tag->u.ramdisk.flags & 1) == 0,
345		      (tag->u.ramdisk.flags & 2) == 0,
346		      tag->u.ramdisk.start, tag->u.ramdisk.size);
347	return 0;
348}
349
350__tagtable(ATAG_RAMDISK, parse_tag_ramdisk);
351
352static int __init parse_tag_initrd(const struct tag *tag)
353{
354	printk(KERN_WARNING "ATAG_INITRD is deprecated; please update your bootloader. \n");
355        phys_initrd_start = (unsigned long)tag->u.initrd.start;
356        phys_initrd_size = (unsigned long)tag->u.initrd.size;
357	return 0;
358}
359
360__tagtable(ATAG_INITRD, parse_tag_initrd);
361
362static int __init parse_tag_initrd2(const struct tag *tag)
363{
364	printk(KERN_WARNING "ATAG_INITRD is deprecated; please update your bootloader. \n");
365	phys_initrd_start = (unsigned long)tag->u.initrd.start;
366	phys_initrd_size = (unsigned long)tag->u.initrd.size;
367	return 0;
368}
369
370__tagtable(ATAG_INITRD2, parse_tag_initrd2);
371
372static int __init parse_tag_serialnr(const struct tag *tag)
373{
374	system_serial_low = tag->u.serialnr.low;
375	system_serial_high = tag->u.serialnr.high;
376	return 0;
377}
378
379__tagtable(ATAG_SERIAL, parse_tag_serialnr);
380
381static int __init parse_tag_revision(const struct tag *tag)
382{
383	system_rev = tag->u.revision.rev;
384	return 0;
385}
386
387__tagtable(ATAG_REVISION, parse_tag_revision);
388
389static int __init parse_tag_cmdline(const struct tag *tag)
390{
391	strncpy(default_command_line, tag->u.cmdline.cmdline, COMMAND_LINE_SIZE);
392	default_command_line[COMMAND_LINE_SIZE - 1] = '\0';
393	return 0;
394}
395
396__tagtable(ATAG_CMDLINE, parse_tag_cmdline);
397
398/*
399 * Scan the tag table for this tag, and call its parse function.
400 * The tag table is built by the linker from all the __tagtable
401 * declarations.
402 */
403static int __init parse_tag(const struct tag *tag)
404{
405	extern struct tagtable __tagtable_begin, __tagtable_end;
406	struct tagtable *t;
407
408	for (t = &__tagtable_begin; t < &__tagtable_end; t++)
409		if (tag->hdr.tag == t->tag) {
410			t->parse(tag);
411			break;
412		}
413
414	return t < &__tagtable_end;
415}
416
417/*
418 * Parse all tags in the list, checking both the global and architecture
419 * specific tag tables.
420 */
421static void __init parse_tags(const struct tag *t)
422{
423	for (; t->hdr.size; t = tag_next(t))
424		if (!parse_tag(t))
425			printk(KERN_WARNING
426				"Ignoring unrecognised tag 0x%08x\n",
427				t->hdr.tag);
428}
429
430/*
431 * This holds our defaults.
432 */
433static struct init_tags {
434	struct tag_header hdr1;
435	struct tag_core   core;
436	struct tag_header hdr2;
437	struct tag_mem32  mem;
438	struct tag_header hdr3;
439} init_tags __initdata = {
440	{ tag_size(tag_core), ATAG_CORE },
441	{ 1, PAGE_SIZE, 0xff },
442	{ tag_size(tag_mem32), ATAG_MEM },
443	{ MEM_SIZE, PHYS_OFFSET },
444	{ 0, ATAG_NONE }
445};
446
447void __init setup_arch(char **cmdline_p)
448{
449	struct tag *tags = (struct tag *)&init_tags;
450	char *from = default_command_line;
451
452	setup_processor();
453	if(machine_arch_type == MACH_TYPE_A5K)
454		machine_name = "A5000";
455	else if(machine_arch_type == MACH_TYPE_ARCHIMEDES)
456		machine_name = "Archimedes";
457	else
458		machine_name = "UNKNOWN";
459
460	// of RAM that is accidentally reserved along with video RAM. perhaps
461	// it would be a good idea to explicitly reserve this?
462
463	tags = (struct tag *)0x0207c000;
464
465	/*
466	 * If we have the old style parameters, convert them to
467	 * a tag list.
468	 */
469	if (tags->hdr.tag != ATAG_CORE)
470		convert_to_tag_list(tags);
471	if (tags->hdr.tag != ATAG_CORE)
472		tags = (struct tag *)&init_tags;
473	if (tags->hdr.tag == ATAG_CORE) {
474		if (meminfo.nr_banks != 0)
475			squash_mem_tags(tags);
476		parse_tags(tags);
477	}
478
479	init_mm.start_code = (unsigned long) &_text;
480#ifndef CONFIG_XIP_KERNEL
481	init_mm.end_code   = (unsigned long) &_etext;
482#else
483	init_mm.end_code   = (unsigned long) &_endtext;
484	init_mm.start_data   = (unsigned long) &_sdata;
485#endif
486	init_mm.end_data   = (unsigned long) &_edata;
487	init_mm.brk	   = (unsigned long) &_end;
488
489	memcpy(boot_command_line, from, COMMAND_LINE_SIZE);
490	boot_command_line[COMMAND_LINE_SIZE-1] = '\0';
491	parse_cmdline(&meminfo, cmdline_p, from);
492	bootmem_init(&meminfo);
493	paging_init(&meminfo);
494	request_standard_resources(&meminfo);
495
496#ifdef CONFIG_VT
497#if defined(CONFIG_DUMMY_CONSOLE)
498	conswitchp = &dummy_con;
499#endif
500#endif
501}
502
503static const char *hwcap_str[] = {
504	"swp",
505	"half",
506	"thumb",
507	"26bit",
508	"fastmult",
509	"fpa",
510	"vfp",
511	"edsp",
512	NULL
513};
514
515static int c_show(struct seq_file *m, void *v)
516{
517	int i;
518
519	seq_printf(m, "Processor\t: %s %s rev %d (%s)\n",
520		   proc_info.manufacturer, proc_info.cpu_name,
521		   (int)processor_id & 15, elf_platform);
522
523	seq_printf(m, "BogoMIPS\t: %lu.%02lu\n",
524		   loops_per_jiffy / (500000/HZ),
525		   (loops_per_jiffy / (5000/HZ)) % 100);
526
527	/* dump out the processor features */
528	seq_puts(m, "Features\t: ");
529
530	for (i = 0; hwcap_str[i]; i++)
531		if (elf_hwcap & (1 << i))
532			seq_printf(m, "%s ", hwcap_str[i]);
533
534	seq_puts(m, "\n");
535
536	seq_printf(m, "CPU part\t\t: %07x\n", processor_id >> 4);
537	seq_printf(m, "CPU revision\t: %d\n\n", processor_id & 15);
538	seq_printf(m, "Hardware\t: %s\n", machine_name);
539	seq_printf(m, "Revision\t: %04x\n", system_rev);
540	seq_printf(m, "Serial\t\t: %08x%08x\n",
541		   system_serial_high, system_serial_low);
542
543	return 0;
544}
545
546static void *c_start(struct seq_file *m, loff_t *pos)
547{
548	return *pos < 1 ? (void *)1 : NULL;
549}
550
551static void *c_next(struct seq_file *m, void *v, loff_t *pos)
552{
553	++*pos;
554	return NULL;
555}
556
557static void c_stop(struct seq_file *m, void *v)
558{
559}
560
561struct seq_operations cpuinfo_op = {
562	.start	= c_start,
563	.next	= c_next,
564	.stop	= c_stop,
565	.show	= c_show
566};
567