OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [linux-2.4/] [arch/] [s390x/] [kernel/] [setup.c] - Blame information for rev 1275

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1275 phoenix
/*
2
 *  arch/s390/kernel/setup.c
3
 *
4
 *  S390 version
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)
8
 *
9
 *  Derived from "arch/i386/kernel/setup.c"
10
 *    Copyright (C) 1995, Linus Torvalds
11
 */
12
 
13
/*
14
 * This file handles the architecture-dependent parts of initialization
15
 */
16
 
17
#include <linux/errno.h>
18
#include <linux/sched.h>
19
#include <linux/kernel.h>
20
#include <linux/mm.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>
34
#endif
35
#include <linux/bootmem.h>
36
#include <linux/console.h>
37
#include <linux/seq_file.h>
38
#include <asm/uaccess.h>
39
#include <asm/system.h>
40
#include <asm/smp.h>
41
#include <asm/mmu_context.h>
42
#include <asm/cpcmd.h>
43
 
44
/*
45
 * Machine setup..
46
 */
47
unsigned int console_mode = 0;
48
unsigned int console_device = -1;
49
unsigned long memory_size = 0;
50
unsigned long machine_flags = 0;
51
struct { unsigned long addr, size, type; } memory_chunk[16] = { { 0 } };
52
#define CHUNK_READ_WRITE 0
53
#define CHUNK_READ_ONLY 1
54
__u16 boot_cpu_addr;
55
int cpus_initialized = 0;
56
unsigned long cpu_initialized = 0;
57
volatile int __cpu_logical_map[NR_CPUS]; /* logical cpu to cpu address */
58
 
59
/*
60
 * Setup options
61
 */
62
extern int _text,_etext, _edata, _end;
63
 
64
/*
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 ...
68
 */
69
 
70
#include <asm/setup.h>
71
 
72
static char command_line[COMMAND_LINE_SIZE] = { 0, };
73
       char saved_command_line[COMMAND_LINE_SIZE];
74
 
75
static struct resource code_resource = { "Kernel code", 0x100000, 0 };
76
static struct resource data_resource = { "Kernel data", 0, 0 };
77
 
78
/*
79
 * cpu_init() initializes state that is per-CPU.
80
 */
81
void __init cpu_init (void)
82
{
83
        int nr = smp_processor_id();
84
        int addr = hard_smp_processor_id();
85
 
86
        if (test_and_set_bit(nr,&cpu_initialized)) {
87
                printk("CPU#%d ALREADY INITIALIZED!!!!!!!!!\n", nr);
88
                for (;;) __sti();
89
        }
90
        cpus_initialized++;
91
 
92
        /*
93
         * Store processor id in lowcore (used e.g. in timer_interrupt)
94
         */
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;
98
 
99
        /*
100
         * Force FPU initialization:
101
         */
102
        current->flags &= ~PF_USEDFPU;
103
        current->used_math = 0;
104
 
105
        /* Setup active_mm for idle_task  */
106
        atomic_inc(&init_mm.mm_count);
107
        current->active_mm = &init_mm;
108
        if (current->mm)
109
                BUG();
110
        enter_lazy_tlb(&init_mm, current, nr);
111
}
112
 
113
/*
114
 * VM halt and poweroff setup routines
115
 */
116
char vmhalt_cmd[128] = "";
117
char vmpoff_cmd[128] = "";
118
 
119
static inline void strncpy_skip_quote(char *dst, char *src, int n)
120
{
121
        int sx, dx;
122
 
123
        dx = 0;
124
        for (sx = 0; src[sx] != 0; sx++) {
125
                if (src[sx] == '"') continue;
126
                dst[dx++] = src[sx];
127
                if (dx >= n) break;
128
        }
129
}
130
 
131
static int __init vmhalt_setup(char *str)
132
{
133
        strncpy_skip_quote(vmhalt_cmd, str, 127);
134
        vmhalt_cmd[127] = 0;
135
        return 1;
136
}
137
 
138
__setup("vmhalt=", vmhalt_setup);
139
 
140
static int __init vmpoff_setup(char *str)
141
{
142
        strncpy_skip_quote(vmpoff_cmd, str, 127);
143
        vmpoff_cmd[127] = 0;
144
        return 1;
145
}
146
 
147
__setup("vmpoff=", vmpoff_setup);
148
 
149
/*
150
 * condev= and conmode= setup parameter.
151
 */
152
 
153
static int __init condev_setup(char *str)
154
{
155
        int vdev;
156
 
157
        vdev = simple_strtoul(str, &str, 0);
158
        if (vdev >= 0 && vdev < 65536)
159
                console_device = vdev;
160
        return 1;
161
}
162
 
163
__setup("condev=", condev_setup);
164
 
165
static int __init conmode_setup(char *str)
166
{
167
#if defined(CONFIG_HWC_CONSOLE)
168
        if (strncmp(str, "hwc", 4) == 0)
169
                SET_CONSOLE_HWC;
170
#endif
171
#if defined(CONFIG_TN3215_CONSOLE)
172
        if (strncmp(str, "3215", 5) == 0)
173
                SET_CONSOLE_3215;
174
#endif
175
#if defined(CONFIG_TN3270_CONSOLE)
176
        if (strncmp(str, "3270", 5) == 0)
177
                SET_CONSOLE_3270;
178
#endif
179
        return 1;
180
}
181
 
182
__setup("conmode=", conmode_setup);
183
 
184
static void __init conmode_default(void)
185
{
186
        char query_buffer[1024];
187
        char *ptr;
188
 
189
        if (MACHINE_IS_VM) {
190
                cpcmd("QUERY TERM", query_buffer, 1024);
191
                ptr = strstr(query_buffer, "CONMODE");
192
                /*
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).
198
                 */
199
                cpcmd("TERM CONMODE 3215", NULL, 0);
200
                if (ptr == NULL) {
201
#if defined(CONFIG_HWC_CONSOLE)
202
                        SET_CONSOLE_HWC;
203
#endif
204
                        return;
205
                }
206
                if (strncmp(ptr + 8, "3270", 4) == 0) {
207
#if defined(CONFIG_TN3270_CONSOLE)
208
                        SET_CONSOLE_3270;
209
#elif defined(CONFIG_TN3215_CONSOLE)
210
                        SET_CONSOLE_3215;
211
#elif defined(CONFIG_HWC_CONSOLE)
212
                        SET_CONSOLE_HWC;
213
#endif
214
                } else if (strncmp(ptr + 8, "3215", 4) == 0) {
215
#if defined(CONFIG_TN3215_CONSOLE)
216
                        SET_CONSOLE_3215;
217
#elif defined(CONFIG_TN3270_CONSOLE)
218
                        SET_CONSOLE_3270;
219
#elif defined(CONFIG_HWC_CONSOLE)
220
                        SET_CONSOLE_HWC;
221
#endif
222
                }
223
        } else if (MACHINE_IS_P390) {
224
#if defined(CONFIG_TN3215_CONSOLE)
225
                SET_CONSOLE_3215;
226
#elif defined(CONFIG_TN3270_CONSOLE)
227
                SET_CONSOLE_3270;
228
#endif
229
        } else {
230
#if defined(CONFIG_HWC_CONSOLE)
231
                SET_CONSOLE_HWC;
232
#endif
233
        }
234
}
235
 
236
#ifdef CONFIG_SMP
237
extern void machine_restart_smp(char *);
238
extern void machine_halt_smp(void);
239
extern void machine_power_off_smp(void);
240
 
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;
244
#else
245
/*
246
 * Reboot, halt and power_off routines for non SMP.
247
 */
248
static void do_machine_restart_nonsmp(char * __unused)
249
{
250
        reipl(S390_lowcore.ipl_device);
251
}
252
 
253
static void do_machine_halt_nonsmp(void)
254
{
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);
258
}
259
 
260
static void do_machine_power_off_nonsmp(void)
261
{
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);
265
}
266
 
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;
270
#endif
271
 
272
/*
273
 * Reboot, halt and power_off stubs. They just call _machine_restart,
274
 * _machine_halt or _machine_power_off.
275
 */
276
 
277
void machine_restart(char *command)
278
{
279
        _machine_restart(command);
280
}
281
 
282
void machine_halt(void)
283
{
284
        _machine_halt();
285
}
286
 
287
void machine_power_off(void)
288
{
289
        _machine_power_off();
290
}
291
 
292
/*
293
 * Setup function called from init/main.c just after the banner
294
 * was printed.
295
 */
296
extern char _pstart, _pend, _stext;
297
 
298
void __init setup_arch(char **cmdline_p)
299
{
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;
307
        struct _lowcore *lowcore;
308
        int i;
309
 
310
        if (smptrap)
311
                return;
312
        smptrap=1;
313
 
314
        /*
315
         * print what head.S has found out about the machine
316
         */
317
        printk((MACHINE_IS_VM) ?
318
               "We are running under VM (64 bit mode)\n" :
319
               "We are running native (64 bit mode)\n");
320
 
321
        ROOT_DEV = to_kdev_t(0x0100);
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;
328
 
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;
333
 
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';
337
 
338
        for (;;) {
339
                /*
340
                 * "mem=XXX[kKmM]" sets memsize
341
                 */
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;
346
                                from++;
347
                        } else if ( *from == 'M' || *from == 'm' ) {
348
                                memory_end = memory_end << 20;
349
                                from++;
350
                        }
351
                }
352
                /*
353
                 * "ipldelay=XXX[sm]" sets ipl delay in seconds or minutes
354
                 */
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;
359
                                from++;
360
                        } else if (*from == 'm' || *from == 'M') {
361
                                delay = delay*60*1000000;
362
                                from++;
363
                        }
364
                        /* now wait for the requested amount of time */
365
                        udelay(delay);
366
                }
367
                cn = *(from++);
368
                if (!cn)
369
                        break;
370
                if (cn == '\n')
371
                        cn = ' ';  /* replace newlines with space */
372
                if (cn == 0x0d)
373
                        cn = ' ';  /* replace 0x0d with space */
374
                if (cn == ' ' && c == ' ')
375
                        continue;  /* remove additional spaces */
376
                c = cn;
377
                if (to - command_line >= COMMAND_LINE_SIZE)
378
                        break;
379
                *(to++) = c;
380
        }
381
        if (c == ' ' && to > command_line) to--;
382
        *to = '\0';
383
        *cmdline_p = command_line;
384
 
385
        /*
386
         * partially used pages are not usable - thus
387
         * we are rounding upwards:
388
         */
389
        start_pfn = (__pa(&_end) + PAGE_SIZE - 1) >> PAGE_SHIFT;
390
        end_pfn = memory_end >> PAGE_SHIFT;
391
 
392
        /*
393
         * Initialize the boot-time allocator
394
         */
395
        bootmap_size = init_bootmem(start_pfn, end_pfn);
396
 
397
        /*
398
         * Register RAM areas with the bootmem allocator.
399
         */
400
        for (i = 0; i < 16 && memory_chunk[i].size > 0; i++) {
401
                unsigned long start_chunk, end_chunk;
402
 
403
                if (memory_chunk[i].type != CHUNK_READ_WRITE)
404
                        continue;
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)
412
                        end_chunk = end_pfn;
413
                if (start_chunk < end_chunk)
414
                        free_bootmem(start_chunk << PAGE_SHIFT,
415
                                     (end_chunk - start_chunk) << PAGE_SHIFT);
416
        }
417
 
418
        /*
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.
423
         */
424
        reserve_bootmem(start_pfn << PAGE_SHIFT, bootmap_size);
425
 
426
#ifdef CONFIG_BLK_DEV_INITRD
427
        if (INITRD_START) {
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;
432
                } else {
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;
437
                }
438
        }
439
#endif
440
 
441
        /*
442
         * Setup lowcore for boot cpu
443
         */
444
        lowcore = (struct _lowcore *)
445
                __alloc_bootmem(2*PAGE_SIZE, 2*PAGE_SIZE, 0);
446
        memset(lowcore, 0, 2*PAGE_SIZE);
447
        lowcore->restart_psw.mask = _RESTART_PSW_MASK;
448
        lowcore->restart_psw.addr = (addr_t) &restart_int_handler;
449
        lowcore->external_new_psw.mask = _EXT_PSW_MASK;
450
        lowcore->external_new_psw.addr = (addr_t) &ext_int_handler;
451
        lowcore->svc_new_psw.mask = _SVC_PSW_MASK;
452
        lowcore->svc_new_psw.addr = (addr_t) &system_call;
453
        lowcore->program_new_psw.mask = _PGM_PSW_MASK;
454
        lowcore->program_new_psw.addr = (addr_t) &pgm_check_handler;
455
        lowcore->mcck_new_psw.mask = _MCCK_PSW_MASK;
456
        lowcore->mcck_new_psw.addr = (addr_t) &mcck_int_handler;
457
        lowcore->io_new_psw.mask = _IO_PSW_MASK;
458
        lowcore->io_new_psw.addr = (addr_t) &io_int_handler;
459
        lowcore->ipl_device = S390_lowcore.ipl_device;
460
        lowcore->kernel_stack = ((__u64) &init_task_union) + 16384;
461
        lowcore->async_stack = (__u64)
462
                __alloc_bootmem(4*PAGE_SIZE, 4*PAGE_SIZE, 0) + 16384;
463
        lowcore->jiffy_timer = -1LL;
464
        if (MACHINE_HAS_DIAG44)
465
                lowcore->diag44_opcode = 0x83000044;
466
        else
467
                lowcore->diag44_opcode = 0x07000700;
468
        set_prefix((__u32)(__u64) lowcore);
469
        cpu_init();
470
        boot_cpu_addr = S390_lowcore.cpu_data.cpu_addr;
471
        __cpu_logical_map[0] = boot_cpu_addr;
472
 
473
        /*
474
         * Create kernel page tables and switch to virtual addressing.
475
         */
476
        paging_init();
477
 
478
        res = alloc_bootmem_low(sizeof(struct resource));
479
        res->start = 0;
480
        res->end = memory_end;
481
        res->flags = IORESOURCE_MEM | IORESOURCE_BUSY;
482
        request_resource(&iomem_resource, res);
483
        request_resource(res, &code_resource);
484
        request_resource(res, &data_resource);
485
 
486
        /* Setup default console */
487
        conmode_default();
488
}
489
 
490
void print_cpu_info(struct cpuinfo_S390 *cpuinfo)
491
{
492
   printk("cpu %d "
493
#ifdef CONFIG_SMP
494
           "phys_idx=%d "
495
#endif
496
           "vers=%02X ident=%06X machine=%04X unused=%04X\n",
497
           cpuinfo->cpu_nr,
498
#ifdef CONFIG_SMP
499
           cpuinfo->cpu_addr,
500
#endif
501
           cpuinfo->cpu_id.version,
502
           cpuinfo->cpu_id.ident,
503
           cpuinfo->cpu_id.machine,
504
           cpuinfo->cpu_id.unused);
505
}
506
 
507
/*
508
 * show_cpuinfo - Get information on one CPU for use by procfs.
509
 */
510
 
511
static int show_cpuinfo(struct seq_file *m, void *v)
512
{
513
        struct cpuinfo_S390 *cpuinfo;
514
        unsigned long n = (unsigned long) v - 1;
515
 
516
        if (!n) {
517
                seq_printf(m, "vendor_id       : IBM/S390\n"
518
                                "# processors    : %i\n"
519
                                "bogomips per cpu: %lu.%02lu\n",
520
                                smp_num_cpus, loops_per_jiffy/(500000/HZ),
521
                                (loops_per_jiffy/(5000/HZ))%100);
522
        }
523
        if (cpu_online_map & (1 << n)) {
524
                cpuinfo = &safe_get_cpu_lowcore(n)->cpu_data;
525
                seq_printf(m, "processor %li: "
526
                                "version = %02X,  "
527
                                "identification = %06X,  "
528
                                "machine = %04X\n",
529
                                n, cpuinfo->cpu_id.version,
530
                                cpuinfo->cpu_id.ident,
531
                                cpuinfo->cpu_id.machine);
532
        }
533
        return 0;
534
}
535
 
536
static void *c_start(struct seq_file *m, loff_t *pos)
537
{
538
        return *pos <= NR_CPUS ? (void *)((unsigned long) *pos + 1) : NULL;
539
}
540
static void *c_next(struct seq_file *m, void *v, loff_t *pos)
541
{
542
        ++*pos;
543
        return c_start(m, pos);
544
}
545
static void c_stop(struct seq_file *m, void *v)
546
{
547
}
548
struct seq_operations cpuinfo_op = {
549
        start:  c_start,
550
        next:   c_next,
551
        stop:   c_stop,
552
        show:   show_cpuinfo,
553
};

powered by: WebSVN 2.1.0

© copyright 1999-2025 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.