1 /*
2  * This file is subject to the terms and conditions of the GNU General Public
3  * License.  See the file "COPYING" in the main directory of this archive
4  * for more details.
5  *
6  * arch/sh64/kernel/setup.c
7  *
8  * SH-5 Arch Support
9  *
10  * This file handles the architecture-dependent parts of initialization
11  *
12  * Copyright (C) 2000, 2001  Paolo Alberelli
13  *
14  * benedict.gaster@superh.com:   2nd May 2002
15  *    Modified to use the empty_zero_page to pass command line arguments.
16  *
17  * benedict.gaster@superh.com:	 3rd May 2002
18  *    Added support for ramdisk, removing statically linked romfs at the same time.
19  *
20  * lethal@linux-sh.org:          15th May 2003
21  *    Added generic procfs cpuinfo reporting. Make boards just export their name.
22  *
23  * lethal@linux-sh.org:          25th May 2003
24  *    Added generic get_cpu_subtype() for subtype reporting from cpu_data->type.
25  *
26  */
27 #include <linux/errno.h>
28 #include <linux/sched.h>
29 #include <linux/kernel.h>
30 #include <linux/mm.h>
31 #include <linux/stddef.h>
32 #include <linux/unistd.h>
33 #include <linux/ptrace.h>
34 #include <linux/slab.h>
35 #include <linux/user.h>
36 #include <linux/a.out.h>
37 #include <linux/tty.h>
38 #include <linux/ioport.h>
39 #include <linux/delay.h>
40 #include <linux/config.h>
41 #include <linux/init.h>
42 #include <linux/seq_file.h>
43 #ifdef CONFIG_BLK_DEV_RAM
44 #include <linux/blk.h>
45 #endif
46 #include <linux/bootmem.h>
47 #include <linux/console.h>
48 #include <asm/processor.h>
49 #include <asm/page.h>
50 #include <asm/pgtable.h>
51 #include <asm/platform.h>
52 #include <asm/uaccess.h>
53 #include <asm/system.h>
54 #include <asm/io.h>
55 #include <asm/smp.h>
56 
57 #ifdef CONFIG_VT
58 #include <linux/console.h>
59 #endif
60 
61 struct screen_info screen_info;
62 
63 /* On a PC this would be initialised as a result of the BIOS detecting the
64  * mouse. */
65 unsigned char aux_device_present = 0xaa;
66 
67 #ifdef CONFIG_BLK_DEV_RAM
68 extern int rd_doload;		/* 1 = load ramdisk, 0 = don't load */
69 extern int rd_prompt;		/* 1 = prompt for ramdisk, 0 = don't prompt */
70 extern int rd_image_start;	/* starting block # of image */
71 #endif
72 
73 extern int root_mountflags;
74 extern int _text, _etext, _edata, _end;
75 extern char *get_system_type(void);
76 extern void platform_setup(void);
77 extern void platform_monitor(void);
78 extern void platform_reserve(void);
79 extern int sh64_cache_init(void);
80 extern int sh64_tlb_init(void);
81 
82 #define RAMDISK_IMAGE_START_MASK  	0x07FF
83 #define RAMDISK_PROMPT_FLAG		0x8000
84 #define RAMDISK_LOAD_FLAG		0x4000
85 
86 #define PARAM ((unsigned char *)empty_zero_page)
87 #define MOUNT_ROOT_RDONLY (*(unsigned long *) (PARAM+0x000))
88 #define RAMDISK_FLAGS (*(unsigned long *) (PARAM+0x004))
89 #define ORIG_ROOT_DEV (*(unsigned long *) (PARAM+0x008))
90 #define LOADER_TYPE (*(unsigned long *) (PARAM+0x00c))
91 #define INITRD_START (*(unsigned long *) (PARAM+0x010))
92 #define INITRD_SIZE (*(unsigned long *) (PARAM+0x014))
93 
94 #define COMMAND_LINE ((char *) (PARAM+256))
95 #define COMMAND_LINE_SIZE 256
96 
97 static char command_line[COMMAND_LINE_SIZE] = { 0, };
98        char saved_command_line[COMMAND_LINE_SIZE];
99 unsigned long long memory_start = CONFIG_MEMORY_START;
100 unsigned long long memory_end = CONFIG_MEMORY_START + (CONFIG_MEMORY_SIZE_IN_MB * 1024 * 1024);
101 
102 struct sh_cpuinfo boot_cpu_data = {
103 	.type = CPU_SH5_101,
104 };
105 
parse_mem_cmdline(char ** cmdline_p)106 static inline void parse_mem_cmdline (char ** cmdline_p)
107 {
108         char c = ' ', *to = command_line, *from = COMMAND_LINE;
109 	int len = 0;
110 
111 	/* Save unparsed command line copy for /proc/cmdline */
112 	memcpy(saved_command_line, COMMAND_LINE, COMMAND_LINE_SIZE);
113 	saved_command_line[COMMAND_LINE_SIZE-1] = '\0';
114 
115 	for (;;) {
116 	  /*
117 	   * "mem=XXX[kKmM]" defines a size of memory.
118 	   */
119 	        if (c == ' ' && !memcmp(from, "mem=", 4)) {
120 		      if (to != command_line)
121 			to--;
122 		      {
123 			unsigned long mem_size;
124 
125 			mem_size = memparse(from+4, &from);
126 			memory_end = memory_start + mem_size;
127 		      }
128 		}
129 		c = *(from++);
130 		if (!c)
131 		  break;
132 		if (COMMAND_LINE_SIZE <= ++len)
133 		  break;
134 		*(to++) = c;
135 	}
136 	*to = '\0';
137 
138 	*cmdline_p = command_line;
139 }
140 
cpu_relax(void)141 void cpu_relax(void)
142 {
143 }
144 
setup_arch(char ** cmdline_p)145 void __init setup_arch(char **cmdline_p)
146 {
147 	unsigned long bootmap_size, i;
148 	unsigned long first_pfn, start_pfn, last_pfn, pages;
149 
150 	/*
151 	 * Setup TLB mappings
152 	 */
153 	sh64_tlb_init();
154 
155 	/*
156 	 * Caches are already initialized by the time we get here, so we just
157 	 * fill in cpu_data info for the caches.
158 	 */
159 	sh64_cache_init();
160 
161 	platform_setup();
162 	platform_monitor();
163 
164 	ROOT_DEV = to_kdev_t(ORIG_ROOT_DEV);
165 
166 #ifdef CONFIG_BLK_DEV_RAM
167 	rd_image_start = RAMDISK_FLAGS & RAMDISK_IMAGE_START_MASK;
168 	rd_prompt = ((RAMDISK_FLAGS & RAMDISK_PROMPT_FLAG) != 0);
169 	rd_doload = ((RAMDISK_FLAGS & RAMDISK_LOAD_FLAG) != 0);
170 #endif
171 
172 	if (!MOUNT_ROOT_RDONLY)
173 		root_mountflags &= ~MS_RDONLY;
174 	init_mm.start_code = (unsigned long)&_text;
175 	init_mm.end_code = (unsigned long) &_etext;
176 	init_mm.end_data = (unsigned long) &_edata;
177 	init_mm.brk = (unsigned long) &_end;
178 
179 	code_resource.start = __pa(&_text);
180 	code_resource.end = __pa(&_etext)-1;
181 	data_resource.start = __pa(&_etext);
182 	data_resource.end = __pa(&_edata)-1;
183 
184 	parse_mem_cmdline(cmdline_p);
185 
186 	/*
187 	 * Find the lowest and highest page frame numbers we have available
188 	 */
189 	first_pfn = PFN_DOWN(memory_start);
190 	last_pfn = PFN_DOWN(memory_end);
191 	pages = last_pfn - first_pfn;
192 
193  	/*
194 	 * Partially used pages are not usable - thus
195 	 * we are rounding upwards:
196  	 */
197 	start_pfn = PFN_UP(__pa(&_end));
198 	/*
199 	 * Find a proper area for the bootmem bitmap. After this
200 	 * bootstrap step all allocations (until the page allocator
201 	 * is intact) must be done via bootmem_alloc().
202 	 */
203 	bootmap_size = init_bootmem_node(NODE_DATA(0), start_pfn,
204 					 first_pfn,
205 					 last_pfn);
206         /*
207          * Round it up.
208          */
209         bootmap_size = PFN_PHYS(PFN_UP(bootmap_size));
210 
211 	/*
212 	 * Register fully available RAM pages with the bootmem allocator.
213 	 */
214 	free_bootmem(PFN_PHYS(first_pfn), PFN_PHYS(pages));
215 
216 	/*
217 	 * Reserve all kernel sections + bootmem bitmap + a guard page.
218 	 */
219 	reserve_bootmem(PFN_PHYS(first_pfn),
220 		        (PFN_PHYS(start_pfn) + bootmap_size + PAGE_SIZE) - PFN_PHYS(first_pfn));
221 
222 	/*
223 	 * Reserve platform dependent sections
224 	 */
225 	platform_reserve();
226 
227 #ifdef CONFIG_BLK_DEV_INITRD
228 	if (LOADER_TYPE && INITRD_START) {
229 		if (INITRD_START + INITRD_SIZE <= (PFN_PHYS(last_pfn))) {
230 		        reserve_bootmem(INITRD_START + __MEMORY_START, INITRD_SIZE);
231 
232 			initrd_start =
233 			  (long) INITRD_START ? INITRD_START + PAGE_OFFSET +  __MEMORY_START : 0;
234 
235 			initrd_end = initrd_start + INITRD_SIZE;
236 		} else {
237 			printk("initrd extends beyond end of memory "
238 			    "(0x%08lx > 0x%08lx)\ndisabling initrd\n",
239 				    (long) INITRD_START + INITRD_SIZE,
240 				    PFN_PHYS(last_pfn));
241 			initrd_start = 0;
242 		}
243 	}
244 #endif
245 
246 	/*
247 	 * Claim all RAM, ROM, and I/O resources.
248 	 */
249 
250 	/* Kernel RAM */
251 	request_resource(&iomem_resource, &code_resource);
252 	request_resource(&iomem_resource, &data_resource);
253 
254 	/* Other KRAM space */
255 	for (i = 0; i < STANDARD_KRAM_RESOURCES - 2; i++)
256 		request_resource(&iomem_resource,
257 				 &platform_parms.kram_res_p[i]);
258 
259 	/* XRAM space */
260 	for (i = 0; i < STANDARD_XRAM_RESOURCES; i++)
261 		request_resource(&iomem_resource,
262 				 &platform_parms.xram_res_p[i]);
263 
264 	/* ROM space */
265 	for (i = 0; i < STANDARD_ROM_RESOURCES; i++)
266 		request_resource(&iomem_resource,
267 				 &platform_parms.rom_res_p[i]);
268 
269 	/* I/O space */
270 	for (i = 0; i < STANDARD_IO_RESOURCES; i++)
271 		request_resource(&ioport_resource,
272 				 &platform_parms.io_res_p[i]);
273 
274 
275 #ifdef CONFIG_VT
276 #if defined(CONFIG_VGA_CONSOLE)
277 	conswitchp = &vga_con;
278 #elif defined(CONFIG_DUMMY_CONSOLE)
279 	conswitchp = &dummy_con;
280 #endif
281 #endif
282 
283 	printk("Hardware FPU: %s\n", fpu_in_use ? "enabled" : "disabled");
284 
285 	paging_init();
286 }
287 
__xchg_called_with_bad_pointer(void)288 void __xchg_called_with_bad_pointer(void)
289 {
290 	printk(KERN_EMERG "xchg() called with bad pointer !\n");
291 }
292 
293 /*
294  *	Get CPU information
295  */
296 static const char *cpu_name[] = {
297 	[CPU_SH5_101]	"SH5-101",
298 	[CPU_SH5_103]	"SH5-103",
299 	[CPU_SH_NONE]	"Unknown",
300 };
301 
get_cpu_subtype(void)302 const char *get_cpu_subtype(void)
303 {
304 	return cpu_name[boot_cpu_data.type];
305 }
306 
307 #ifdef CONFIG_PROC_FS
show_cpuinfo(struct seq_file * m,void * v)308 static int show_cpuinfo(struct seq_file *m,void *v)
309 {
310 	unsigned int cpu = smp_processor_id();
311 
312 	if (!cpu)
313 		seq_printf(m, "machine\t\t: %s\n", get_system_type());
314 
315 	seq_printf(m, "processor\t: %d\n", cpu);
316 	seq_printf(m, "cpu family\t: SH-5\n");
317 	seq_printf(m, "cpu type\t: %s\n", get_cpu_subtype());
318 
319 	seq_printf(m, "icache size\t: %dK-bytes\n",
320 		   (boot_cpu_data.icache.ways *
321 		    boot_cpu_data.icache.sets *
322 		    boot_cpu_data.icache.linesz) >> 10);
323 	seq_printf(m, "dcache size\t: %dK-bytes\n",
324 		   (boot_cpu_data.dcache.ways *
325 		    boot_cpu_data.dcache.sets *
326 		    boot_cpu_data.dcache.linesz) >> 10);
327 	seq_printf(m, "itlb entries\t: %d\n", boot_cpu_data.itlb.entries);
328 	seq_printf(m, "dtlb entries\t: %d\n", boot_cpu_data.dtlb.entries);
329 
330 #define PRINT_CLOCK(name, value) \
331 	seq_printf(m, name " clock\t: %d.%02dMHz\n", \
332 		     ((value) / 1000000), ((value) % 1000000)/10000)
333 
334 	PRINT_CLOCK("cpu", boot_cpu_data.cpu_clock);
335 	PRINT_CLOCK("bus", boot_cpu_data.bus_clock);
336 	PRINT_CLOCK("module", boot_cpu_data.module_clock);
337 
338         seq_printf(m, "bogomips\t: %lu.%02lu\n\n",
339 		     (loops_per_jiffy*HZ+2500)/500000,
340 		     ((loops_per_jiffy*HZ+2500)/5000) % 100);
341 
342 	return 0;
343 }
344 
c_start(struct seq_file * m,loff_t * pos)345 static void *c_start(struct seq_file *m, loff_t *pos)
346 {
347 	return (void*)(*pos == 0);
348 }
c_next(struct seq_file * m,void * v,loff_t * pos)349 static void *c_next(struct seq_file *m, void *v, loff_t *pos)
350 {
351 	return NULL;
352 }
c_stop(struct seq_file * m,void * v)353 static void c_stop(struct seq_file *m, void *v)
354 {
355 }
356 struct seq_operations cpuinfo_op = {
357 	start:	c_start,
358 	next:	c_next,
359 	stop:	c_stop,
360 	show:	show_cpuinfo,
361 };
362 #endif /* CONFIG_PROC_FS */
363