2 * arch/s390/kernel/setup.c
5 * Copyright (C) 1999,2000 IBM Deutschland Entwicklung GmbH, IBM Corporation
6 * Author(s): Hartmut Penner (hp@de.ibm.com),
7 * Martin Schwidefsky (schwidefsky@de.ibm.com)
9 * Derived from "arch/i386/kernel/setup.c"
10 * Copyright (C) 1995, Linus Torvalds
14 * This file handles the architecture-dependent parts of initialization
17 #include <linux/errno.h>
18 #include <linux/sched.h>
19 #include <linux/kernel.h>
21 #include <linux/stddef.h>
22 #include <linux/unistd.h>
23 #include <linux/ptrace.h>
24 #include <linux/slab.h>
25 #include <linux/user.h>
26 #include <linux/a.out.h>
27 #include <linux/tty.h>
28 #include <linux/ioport.h>
29 #include <linux/delay.h>
30 #include <linux/config.h>
31 #include <linux/init.h>
32 #ifdef CONFIG_BLK_DEV_RAM
33 #include <linux/blk.h>
35 #include <linux/bootmem.h>
36 #include <linux/root_dev.h>
37 #include <linux/console.h>
38 #include <linux/seq_file.h>
39 #include <asm/uaccess.h>
40 #include <asm/system.h>
42 #include <asm/mmu_context.h>
43 #include <asm/cpcmd.h>
48 unsigned int console_mode
= 0;
49 unsigned int console_device
= -1;
50 unsigned long memory_size
= 0;
51 unsigned long machine_flags
= 0;
52 struct { unsigned long addr
, size
, type
; } memory_chunk
[16] = { { 0 } };
53 #define CHUNK_READ_WRITE 0
54 #define CHUNK_READ_ONLY 1
55 int cpus_initialized
= 0;
56 unsigned long cpu_initialized
= 0;
57 volatile int __cpu_logical_map
[NR_CPUS
]; /* logical cpu to cpu address */
62 extern int _text
,_etext
, _edata
, _end
;
65 * This is set up by the setup-routine at boot-time
66 * for S390 need to find out, what we have to setup
67 * using address 0x10400 ...
70 #include <asm/setup.h>
72 static char command_line
[COMMAND_LINE_SIZE
] = { 0, };
73 char saved_command_line
[COMMAND_LINE_SIZE
];
75 static struct resource code_resource
= { "Kernel code", 0x100000, 0 };
76 static struct resource data_resource
= { "Kernel data", 0, 0 };
79 * cpu_init() initializes state that is per-CPU.
81 void __devinit
cpu_init (void)
83 int nr
= smp_processor_id();
84 int addr
= hard_smp_processor_id();
86 if (test_and_set_bit(nr
,&cpu_initialized
)) {
87 printk("CPU#%d ALREADY INITIALIZED!!!!!!!!!\n", nr
);
88 for (;;) local_irq_enable();
93 * Store processor id in lowcore (used e.g. in timer_interrupt)
95 asm volatile ("stidp %0": "=m" (S390_lowcore
.cpu_data
.cpu_id
));
96 S390_lowcore
.cpu_data
.cpu_addr
= addr
;
97 S390_lowcore
.cpu_data
.cpu_nr
= nr
;
100 * Force FPU initialization:
102 clear_thread_flag(TIF_USEDFPU
);
103 current
->used_math
= 0;
105 /* Setup active_mm for idle_task */
106 atomic_inc(&init_mm
.mm_count
);
107 current
->active_mm
= &init_mm
;
110 enter_lazy_tlb(&init_mm
, current
, nr
);
114 * VM halt and poweroff setup routines
116 char vmhalt_cmd
[128] = "";
117 char vmpoff_cmd
[128] = "";
119 static inline void strncpy_skip_quote(char *dst
, char *src
, int n
)
124 for (sx
= 0; src
[sx
] != 0; sx
++) {
125 if (src
[sx
] == '"') continue;
131 static int __init
vmhalt_setup(char *str
)
133 strncpy_skip_quote(vmhalt_cmd
, str
, 127);
138 __setup("vmhalt=", vmhalt_setup
);
140 static int __init
vmpoff_setup(char *str
)
142 strncpy_skip_quote(vmpoff_cmd
, str
, 127);
147 __setup("vmpoff=", vmpoff_setup
);
150 * condev= and conmode= setup parameter.
153 static int __init
condev_setup(char *str
)
157 vdev
= simple_strtoul(str
, &str
, 0);
158 if (vdev
>= 0 && vdev
< 65536)
159 console_device
= vdev
;
163 __setup("condev=", condev_setup
);
165 static int __init
conmode_setup(char *str
)
167 #if defined(CONFIG_HWC_CONSOLE)
168 if (strncmp(str
, "hwc", 4) == 0)
171 #if defined(CONFIG_TN3215_CONSOLE)
172 if (strncmp(str
, "3215", 5) == 0)
175 #if defined(CONFIG_TN3270_CONSOLE)
176 if (strncmp(str
, "3270", 5) == 0)
182 __setup("conmode=", conmode_setup
);
184 static void __init
conmode_default(void)
186 char query_buffer
[1024];
190 cpcmd("QUERY TERM", query_buffer
, 1024);
191 ptr
= strstr(query_buffer
, "CONMODE");
193 * Set the conmode to 3215 so that the device recognition
194 * will set the cu_type of the console to 3215. If the
195 * conmode is 3270 and we don't set it back then both
196 * 3215 and the 3270 driver will try to access the console
197 * device (3215 as console and 3270 as normal tty).
199 cpcmd("TERM CONMODE 3215", NULL
, 0);
201 #if defined(CONFIG_HWC_CONSOLE)
206 if (strncmp(ptr
+ 8, "3270", 4) == 0) {
207 #if defined(CONFIG_TN3270_CONSOLE)
209 #elif defined(CONFIG_TN3215_CONSOLE)
211 #elif defined(CONFIG_HWC_CONSOLE)
214 } else if (strncmp(ptr
+ 8, "3215", 4) == 0) {
215 #if defined(CONFIG_TN3215_CONSOLE)
217 #elif defined(CONFIG_TN3270_CONSOLE)
219 #elif defined(CONFIG_HWC_CONSOLE)
223 } else if (MACHINE_IS_P390
) {
224 #if defined(CONFIG_TN3215_CONSOLE)
226 #elif defined(CONFIG_TN3270_CONSOLE)
230 #if defined(CONFIG_HWC_CONSOLE)
237 extern void machine_restart_smp(char *);
238 extern void machine_halt_smp(void);
239 extern void machine_power_off_smp(void);
241 void (*_machine_restart
)(char *command
) = machine_restart_smp
;
242 void (*_machine_halt
)(void) = machine_halt_smp
;
243 void (*_machine_power_off
)(void) = machine_power_off_smp
;
246 * Reboot, halt and power_off routines for non SMP.
248 static void do_machine_restart_nonsmp(char * __unused
)
250 reipl(S390_lowcore
.ipl_device
);
253 static void do_machine_halt_nonsmp(void)
255 if (MACHINE_IS_VM
&& strlen(vmhalt_cmd
) > 0)
256 cpcmd(vmhalt_cmd
, NULL
, 0);
257 signal_processor(smp_processor_id(), sigp_stop_and_store_status
);
260 static void do_machine_power_off_nonsmp(void)
262 if (MACHINE_IS_VM
&& strlen(vmpoff_cmd
) > 0)
263 cpcmd(vmpoff_cmd
, NULL
, 0);
264 signal_processor(smp_processor_id(), sigp_stop_and_store_status
);
267 void (*_machine_restart
)(char *command
) = do_machine_restart_nonsmp
;
268 void (*_machine_halt
)(void) = do_machine_halt_nonsmp
;
269 void (*_machine_power_off
)(void) = do_machine_power_off_nonsmp
;
273 * Reboot, halt and power_off stubs. They just call _machine_restart,
274 * _machine_halt or _machine_power_off.
277 void machine_restart(char *command
)
279 _machine_restart(command
);
282 void machine_halt(void)
287 void machine_power_off(void)
289 _machine_power_off();
293 * Setup function called from init/main.c just after the banner
296 extern char _pstart
, _pend
, _stext
;
298 void __init
setup_arch(char **cmdline_p
)
300 unsigned long bootmap_size
;
301 unsigned long memory_start
, memory_end
;
302 char c
= ' ', cn
, *to
= command_line
, *from
= COMMAND_LINE
;
303 struct resource
*res
;
304 unsigned long start_pfn
, end_pfn
;
305 static unsigned int smptrap
=0;
306 unsigned long delay
= 0;
315 * print what head.S has found out about the machine
317 printk((MACHINE_IS_VM
) ?
318 "We are running under VM (64 bit mode)\n" :
319 "We are running native (64 bit mode)\n");
321 ROOT_DEV
= Root_RAM0
;
322 memory_start
= (unsigned long) &_end
; /* fixit if use $CODELO etc*/
323 memory_end
= memory_size
& ~0x200000UL
; /* detected in head.s */
324 init_mm
.start_code
= PAGE_OFFSET
;
325 init_mm
.end_code
= (unsigned long) &_etext
;
326 init_mm
.end_data
= (unsigned long) &_edata
;
327 init_mm
.brk
= (unsigned long) &_end
;
329 code_resource
.start
= (unsigned long) &_text
;
330 code_resource
.end
= (unsigned long) &_etext
- 1;
331 data_resource
.start
= (unsigned long) &_etext
;
332 data_resource
.end
= (unsigned long) &_edata
- 1;
334 /* Save unparsed command line copy for /proc/cmdline */
335 memcpy(saved_command_line
, COMMAND_LINE
, COMMAND_LINE_SIZE
);
336 saved_command_line
[COMMAND_LINE_SIZE
-1] = '\0';
340 * "mem=XXX[kKmM]" sets memsize
342 if (c
== ' ' && strncmp(from
, "mem=", 4) == 0) {
343 memory_end
= simple_strtoul(from
+4, &from
, 0);
344 if ( *from
== 'K' || *from
== 'k' ) {
345 memory_end
= memory_end
<< 10;
347 } else if ( *from
== 'M' || *from
== 'm' ) {
348 memory_end
= memory_end
<< 20;
353 * "ipldelay=XXX[sm]" sets ipl delay in seconds or minutes
355 if (c
== ' ' && strncmp(from
, "ipldelay=", 9) == 0) {
356 delay
= simple_strtoul(from
+9, &from
, 0);
357 if (*from
== 's' || *from
== 'S') {
358 delay
= delay
*1000000;
360 } else if (*from
== 'm' || *from
== 'M') {
361 delay
= delay
*60*1000000;
364 /* now wait for the requested amount of time */
371 cn
= ' '; /* replace newlines with space */
373 cn
= ' '; /* replace 0x0d with space */
374 if (cn
== ' ' && c
== ' ')
375 continue; /* remove additional spaces */
377 if (to
- command_line
>= COMMAND_LINE_SIZE
)
381 if (c
== ' ' && to
> command_line
) to
--;
383 *cmdline_p
= command_line
;
386 * partially used pages are not usable - thus
387 * we are rounding upwards:
389 start_pfn
= (__pa(&_end
) + PAGE_SIZE
- 1) >> PAGE_SHIFT
;
390 end_pfn
= memory_end
>> PAGE_SHIFT
;
393 * Initialize the boot-time allocator
395 bootmap_size
= init_bootmem(start_pfn
, end_pfn
);
398 * Register RAM areas with the bootmem allocator.
400 for (i
= 0; i
< 16 && memory_chunk
[i
].size
> 0; i
++) {
401 unsigned long start_chunk
, end_chunk
;
403 if (memory_chunk
[i
].type
!= CHUNK_READ_WRITE
)
405 start_chunk
= (memory_chunk
[i
].addr
+ PAGE_SIZE
- 1);
406 start_chunk
>>= PAGE_SHIFT
;
407 end_chunk
= (memory_chunk
[i
].addr
+ memory_chunk
[i
].size
);
408 end_chunk
>>= PAGE_SHIFT
;
409 if (start_chunk
< start_pfn
)
410 start_chunk
= start_pfn
;
411 if (end_chunk
> end_pfn
)
413 if (start_chunk
< end_chunk
)
414 free_bootmem(start_chunk
<< PAGE_SHIFT
,
415 (end_chunk
- start_chunk
) << PAGE_SHIFT
);
419 * Reserve the bootmem bitmap itself as well. We do this in two
420 * steps (first step was init_bootmem()) because this catches
421 * the (very unlikely) case of us accidentally initializing the
422 * bootmem allocator with an invalid RAM area.
424 reserve_bootmem(start_pfn
<< PAGE_SHIFT
, bootmap_size
);
426 #ifdef CONFIG_BLK_DEV_INITRD
428 if (INITRD_START
+ INITRD_SIZE
<= memory_end
) {
429 reserve_bootmem(INITRD_START
, INITRD_SIZE
);
430 initrd_start
= INITRD_START
;
431 initrd_end
= initrd_start
+ INITRD_SIZE
;
433 printk("initrd extends beyond end of memory "
434 "(0x%08lx > 0x%08lx)\ndisabling initrd\n",
435 initrd_start
+ INITRD_SIZE
, memory_end
);
436 initrd_start
= initrd_end
= 0;
442 * Setup lowcore for boot cpu
444 lc
= (struct _lowcore
*) __alloc_bootmem(2*PAGE_SIZE
, 2*PAGE_SIZE
, 0);
445 memset(lc
, 0, 2*PAGE_SIZE
);
446 lc
->restart_psw
.mask
= PSW_BASE_BITS
;
447 lc
->restart_psw
.addr
= (addr_t
) &restart_int_handler
;
448 lc
->external_new_psw
.mask
= PSW_KERNEL_BITS
;
449 lc
->external_new_psw
.addr
= (addr_t
) &ext_int_handler
;
450 lc
->svc_new_psw
.mask
= PSW_KERNEL_BITS
;
451 lc
->svc_new_psw
.addr
= (addr_t
) &system_call
;
452 lc
->program_new_psw
.mask
= PSW_KERNEL_BITS
;
453 lc
->program_new_psw
.addr
= (addr_t
) &pgm_check_handler
;
454 lc
->mcck_new_psw
.mask
= PSW_KERNEL_BITS
;
455 lc
->mcck_new_psw
.addr
= (addr_t
) &mcck_int_handler
;
456 lc
->io_new_psw
.mask
= PSW_KERNEL_BITS
;
457 lc
->io_new_psw
.addr
= (addr_t
) &io_int_handler
;
458 lc
->ipl_device
= S390_lowcore
.ipl_device
;
459 lc
->kernel_stack
= ((__u64
) &init_thread_union
) + 16384;
460 lc
->async_stack
= (__u64
)
461 __alloc_bootmem(4*PAGE_SIZE
, 4*PAGE_SIZE
, 0) + 16384;
462 lc
->jiffy_timer
= -1LL;
463 if (MACHINE_HAS_DIAG44
)
464 lc
->diag44_opcode
= 0x83000044;
466 lc
->diag44_opcode
= 0x07000700;
467 set_prefix((__u32
)(__u64
) lc
);
469 __cpu_logical_map
[0] = S390_lowcore
.cpu_data
.cpu_addr
;
472 * Create kernel page tables and switch to virtual addressing.
476 res
= alloc_bootmem_low(sizeof(struct resource
));
478 res
->end
= memory_end
;
479 res
->flags
= IORESOURCE_MEM
| IORESOURCE_BUSY
;
480 request_resource(&iomem_resource
, res
);
481 request_resource(res
, &code_resource
);
482 request_resource(res
, &data_resource
);
484 /* Setup default console */
488 void print_cpu_info(struct cpuinfo_S390
*cpuinfo
)
494 "vers=%02X ident=%06X machine=%04X unused=%04X\n",
499 cpuinfo
->cpu_id
.version
,
500 cpuinfo
->cpu_id
.ident
,
501 cpuinfo
->cpu_id
.machine
,
502 cpuinfo
->cpu_id
.unused
);
506 * show_cpuinfo - Get information on one CPU for use by procfs.
509 static int show_cpuinfo(struct seq_file
*m
, void *v
)
511 struct cpuinfo_S390
*cpuinfo
;
512 unsigned long n
= (unsigned long) v
- 1;
515 seq_printf(m
, "vendor_id : IBM/S390\n"
516 "# processors : %i\n"
517 "bogomips per cpu: %lu.%02lu\n",
518 num_online_cpus(), loops_per_jiffy
/(500000/HZ
),
519 (loops_per_jiffy
/(5000/HZ
))%100);
521 if (cpu_online_map
& (1 << n
)) {
522 if (smp_processor_id() == n
)
523 cpuinfo
= &S390_lowcore
.cpu_data
;
525 cpuinfo
= &lowcore_ptr
[n
]->cpu_data
;
526 seq_printf(m
, "processor %li: "
528 "identification = %06X, "
530 n
, cpuinfo
->cpu_id
.version
,
531 cpuinfo
->cpu_id
.ident
,
532 cpuinfo
->cpu_id
.machine
);
537 static void *c_start(struct seq_file
*m
, loff_t
*pos
)
539 return *pos
<= NR_CPUS
? (void *)((unsigned long) *pos
+ 1) : NULL
;
541 static void *c_next(struct seq_file
*m
, void *v
, loff_t
*pos
)
544 return c_start(m
, pos
);
546 static void c_stop(struct seq_file
*m
, void *v
)
549 struct seq_operations cpuinfo_op
= {
553 .show
= show_cpuinfo
,