[SPARC32]: Fix sparc32 modpost warnings with sunzilog
[firefly-linux-kernel-4.4.55.git] / arch / sparc64 / kernel / setup.c
1 /*  $Id: setup.c,v 1.72 2002/02/09 19:49:30 davem Exp $
2  *  linux/arch/sparc64/kernel/setup.c
3  *
4  *  Copyright (C) 1995,1996  David S. Miller (davem@caip.rutgers.edu)
5  *  Copyright (C) 1997       Jakub Jelinek (jj@sunsite.mff.cuni.cz)
6  */
7
8 #include <linux/errno.h>
9 #include <linux/sched.h>
10 #include <linux/kernel.h>
11 #include <linux/mm.h>
12 #include <linux/stddef.h>
13 #include <linux/unistd.h>
14 #include <linux/ptrace.h>
15 #include <linux/slab.h>
16 #include <asm/smp.h>
17 #include <linux/user.h>
18 #include <linux/a.out.h>
19 #include <linux/screen_info.h>
20 #include <linux/delay.h>
21 #include <linux/fs.h>
22 #include <linux/seq_file.h>
23 #include <linux/syscalls.h>
24 #include <linux/kdev_t.h>
25 #include <linux/major.h>
26 #include <linux/string.h>
27 #include <linux/init.h>
28 #include <linux/inet.h>
29 #include <linux/console.h>
30 #include <linux/root_dev.h>
31 #include <linux/interrupt.h>
32 #include <linux/cpu.h>
33 #include <linux/initrd.h>
34
35 #include <asm/system.h>
36 #include <asm/io.h>
37 #include <asm/processor.h>
38 #include <asm/oplib.h>
39 #include <asm/page.h>
40 #include <asm/pgtable.h>
41 #include <asm/idprom.h>
42 #include <asm/head.h>
43 #include <asm/starfire.h>
44 #include <asm/mmu_context.h>
45 #include <asm/timer.h>
46 #include <asm/sections.h>
47 #include <asm/setup.h>
48 #include <asm/mmu.h>
49
50 #ifdef CONFIG_IP_PNP
51 #include <net/ipconfig.h>
52 #endif
53
54 struct screen_info screen_info = {
55         0, 0,                   /* orig-x, orig-y */
56         0,                      /* unused */
57         0,                      /* orig-video-page */
58         0,                      /* orig-video-mode */
59         128,                    /* orig-video-cols */
60         0, 0, 0,                /* unused, ega_bx, unused */
61         54,                     /* orig-video-lines */
62         0,                      /* orig-video-isVGA */
63         16                      /* orig-video-points */
64 };
65
66 void (*prom_palette)(int);
67 void (*prom_keyboard)(void);
68
69 static void
70 prom_console_write(struct console *con, const char *s, unsigned n)
71 {
72         prom_write(s, n);
73 }
74
75 unsigned int boot_flags = 0;
76 #define BOOTME_DEBUG  0x1
77 #define BOOTME_SINGLE 0x2
78
79 /* Exported for mm/init.c:paging_init. */
80 unsigned long cmdline_memory_size = 0;
81
82 static struct console prom_debug_console = {
83         .name =         "debug",
84         .write =        prom_console_write,
85         .flags =        CON_PRINTBUFFER,
86         .index =        -1,
87 };
88
89 /* XXX Implement this at some point... */
90 void kernel_enter_debugger(void)
91 {
92 }
93
94 /* 
95  * Process kernel command line switches that are specific to the
96  * SPARC or that require special low-level processing.
97  */
98 static void __init process_switch(char c)
99 {
100         switch (c) {
101         case 'd':
102                 boot_flags |= BOOTME_DEBUG;
103                 break;
104         case 's':
105                 boot_flags |= BOOTME_SINGLE;
106                 break;
107         case 'h':
108                 prom_printf("boot_flags_init: Halt!\n");
109                 prom_halt();
110                 break;
111         case 'p':
112                 /* Use PROM debug console. */
113                 register_console(&prom_debug_console);
114                 break;
115         case 'P':
116                 /* Force UltraSPARC-III P-Cache on. */
117                 if (tlb_type != cheetah) {
118                         printk("BOOT: Ignoring P-Cache force option.\n");
119                         break;
120                 }
121                 cheetah_pcache_forced_on = 1;
122                 add_taint(TAINT_MACHINE_CHECK);
123                 cheetah_enable_pcache();
124                 break;
125
126         default:
127                 printk("Unknown boot switch (-%c)\n", c);
128                 break;
129         }
130 }
131
132 static void __init process_console(char *commands)
133 {
134         serial_console = 0;
135         commands += 8;
136         /* Linux-style serial */
137         if (!strncmp(commands, "ttyS", 4))
138                 serial_console = simple_strtoul(commands + 4, NULL, 10) + 1;
139         else if (!strncmp(commands, "tty", 3)) {
140                 char c = *(commands + 3);
141                 /* Solaris-style serial */
142                 if (c == 'a' || c == 'b') {
143                         serial_console = c - 'a' + 1;
144                         prom_printf ("Using /dev/tty%c as console.\n", c);
145                 }
146                 /* else Linux-style fbcon, not serial */
147         }
148 #if defined(CONFIG_PROM_CONSOLE)
149         if (!strncmp(commands, "prom", 4)) {
150                 char *p;
151
152                 for (p = commands - 8; *p && *p != ' '; p++)
153                         *p = ' ';
154                 conswitchp = &prom_con;
155         }
156 #endif
157 }
158
159 static void __init boot_flags_init(char *commands)
160 {
161         while (*commands) {
162                 /* Move to the start of the next "argument". */
163                 while (*commands && *commands == ' ')
164                         commands++;
165
166                 /* Process any command switches, otherwise skip it. */
167                 if (*commands == '\0')
168                         break;
169                 if (*commands == '-') {
170                         commands++;
171                         while (*commands && *commands != ' ')
172                                 process_switch(*commands++);
173                         continue;
174                 }
175                 if (!strncmp(commands, "console=", 8)) {
176                         process_console(commands);
177                 } else if (!strncmp(commands, "mem=", 4)) {
178                         /*
179                          * "mem=XXX[kKmM]" overrides the PROM-reported
180                          * memory size.
181                          */
182                         cmdline_memory_size = simple_strtoul(commands + 4,
183                                                              &commands, 0);
184                         if (*commands == 'K' || *commands == 'k') {
185                                 cmdline_memory_size <<= 10;
186                                 commands++;
187                         } else if (*commands=='M' || *commands=='m') {
188                                 cmdline_memory_size <<= 20;
189                                 commands++;
190                         }
191                 }
192                 while (*commands && *commands != ' ')
193                         commands++;
194         }
195 }
196
197 extern void panic_setup(char *, int *);
198
199 extern unsigned short root_flags;
200 extern unsigned short root_dev;
201 extern unsigned short ram_flags;
202 #define RAMDISK_IMAGE_START_MASK        0x07FF
203 #define RAMDISK_PROMPT_FLAG             0x8000
204 #define RAMDISK_LOAD_FLAG               0x4000
205
206 extern int root_mountflags;
207
208 char reboot_command[COMMAND_LINE_SIZE];
209
210 static struct pt_regs fake_swapper_regs = { { 0, }, 0, 0, 0, 0 };
211
212 void __init per_cpu_patch(void)
213 {
214         struct cpuid_patch_entry *p;
215         unsigned long ver;
216         int is_jbus;
217
218         if (tlb_type == spitfire && !this_is_starfire)
219                 return;
220
221         is_jbus = 0;
222         if (tlb_type != hypervisor) {
223                 __asm__ ("rdpr %%ver, %0" : "=r" (ver));
224                 is_jbus = ((ver >> 32UL) == __JALAPENO_ID ||
225                            (ver >> 32UL) == __SERRANO_ID);
226         }
227
228         p = &__cpuid_patch;
229         while (p < &__cpuid_patch_end) {
230                 unsigned long addr = p->addr;
231                 unsigned int *insns;
232
233                 switch (tlb_type) {
234                 case spitfire:
235                         insns = &p->starfire[0];
236                         break;
237                 case cheetah:
238                 case cheetah_plus:
239                         if (is_jbus)
240                                 insns = &p->cheetah_jbus[0];
241                         else
242                                 insns = &p->cheetah_safari[0];
243                         break;
244                 case hypervisor:
245                         insns = &p->sun4v[0];
246                         break;
247                 default:
248                         prom_printf("Unknown cpu type, halting.\n");
249                         prom_halt();
250                 };
251
252                 *(unsigned int *) (addr +  0) = insns[0];
253                 wmb();
254                 __asm__ __volatile__("flush     %0" : : "r" (addr +  0));
255
256                 *(unsigned int *) (addr +  4) = insns[1];
257                 wmb();
258                 __asm__ __volatile__("flush     %0" : : "r" (addr +  4));
259
260                 *(unsigned int *) (addr +  8) = insns[2];
261                 wmb();
262                 __asm__ __volatile__("flush     %0" : : "r" (addr +  8));
263
264                 *(unsigned int *) (addr + 12) = insns[3];
265                 wmb();
266                 __asm__ __volatile__("flush     %0" : : "r" (addr + 12));
267
268                 p++;
269         }
270 }
271
272 void __init sun4v_patch(void)
273 {
274         struct sun4v_1insn_patch_entry *p1;
275         struct sun4v_2insn_patch_entry *p2;
276
277         if (tlb_type != hypervisor)
278                 return;
279
280         p1 = &__sun4v_1insn_patch;
281         while (p1 < &__sun4v_1insn_patch_end) {
282                 unsigned long addr = p1->addr;
283
284                 *(unsigned int *) (addr +  0) = p1->insn;
285                 wmb();
286                 __asm__ __volatile__("flush     %0" : : "r" (addr +  0));
287
288                 p1++;
289         }
290
291         p2 = &__sun4v_2insn_patch;
292         while (p2 < &__sun4v_2insn_patch_end) {
293                 unsigned long addr = p2->addr;
294
295                 *(unsigned int *) (addr +  0) = p2->insns[0];
296                 wmb();
297                 __asm__ __volatile__("flush     %0" : : "r" (addr +  0));
298
299                 *(unsigned int *) (addr +  4) = p2->insns[1];
300                 wmb();
301                 __asm__ __volatile__("flush     %0" : : "r" (addr +  4));
302
303                 p2++;
304         }
305 }
306
307 #ifdef CONFIG_SMP
308 void __init boot_cpu_id_too_large(int cpu)
309 {
310         prom_printf("Serious problem, boot cpu id (%d) >= NR_CPUS (%d)\n",
311                     cpu, NR_CPUS);
312         prom_halt();
313 }
314 #endif
315
316 void __init setup_arch(char **cmdline_p)
317 {
318         /* Initialize PROM console and command line. */
319         *cmdline_p = prom_getbootargs();
320         strcpy(saved_command_line, *cmdline_p);
321
322         if (tlb_type == hypervisor)
323                 printk("ARCH: SUN4V\n");
324         else
325                 printk("ARCH: SUN4U\n");
326
327 #ifdef CONFIG_DUMMY_CONSOLE
328         conswitchp = &dummy_con;
329 #elif defined(CONFIG_PROM_CONSOLE)
330         conswitchp = &prom_con;
331 #endif
332
333         boot_flags_init(*cmdline_p);
334
335         idprom_init();
336
337         if (!root_flags)
338                 root_mountflags &= ~MS_RDONLY;
339         ROOT_DEV = old_decode_dev(root_dev);
340 #ifdef CONFIG_BLK_DEV_RAM
341         rd_image_start = ram_flags & RAMDISK_IMAGE_START_MASK;
342         rd_prompt = ((ram_flags & RAMDISK_PROMPT_FLAG) != 0);
343         rd_doload = ((ram_flags & RAMDISK_LOAD_FLAG) != 0);     
344 #endif
345
346         task_thread_info(&init_task)->kregs = &fake_swapper_regs;
347
348 #ifdef CONFIG_IP_PNP
349         if (!ic_set_manually) {
350                 int chosen = prom_finddevice ("/chosen");
351                 u32 cl, sv, gw;
352                 
353                 cl = prom_getintdefault (chosen, "client-ip", 0);
354                 sv = prom_getintdefault (chosen, "server-ip", 0);
355                 gw = prom_getintdefault (chosen, "gateway-ip", 0);
356                 if (cl && sv) {
357                         ic_myaddr = cl;
358                         ic_servaddr = sv;
359                         if (gw)
360                                 ic_gateway = gw;
361 #if defined(CONFIG_IP_PNP_BOOTP) || defined(CONFIG_IP_PNP_RARP)
362                         ic_proto_enabled = 0;
363 #endif
364                 }
365         }
366 #endif
367
368         /* Get boot processor trap_block[] setup.  */
369         init_cur_cpu_trap(current_thread_info());
370
371         paging_init();
372
373         smp_setup_cpu_possible_map();
374 }
375
376 static int __init set_preferred_console(void)
377 {
378         int idev, odev;
379
380         /* The user has requested a console so this is already set up. */
381         if (serial_console >= 0)
382                 return -EBUSY;
383
384         idev = prom_query_input_device();
385         odev = prom_query_output_device();
386         if (idev == PROMDEV_IKBD && odev == PROMDEV_OSCREEN) {
387                 serial_console = 0;
388         } else if (idev == PROMDEV_ITTYA && odev == PROMDEV_OTTYA) {
389                 serial_console = 1;
390         } else if (idev == PROMDEV_ITTYB && odev == PROMDEV_OTTYB) {
391                 serial_console = 2;
392         } else if (idev == PROMDEV_IRSC && odev == PROMDEV_ORSC) {
393                 serial_console = 3;
394         } else if (idev == PROMDEV_IVCONS && odev == PROMDEV_OVCONS) {
395                 /* sunhv_console_init() doesn't check the serial_console
396                  * value anyways...
397                  */
398                 serial_console = 4;
399                 return add_preferred_console("ttyHV", 0, NULL);
400         } else {
401                 prom_printf("Inconsistent console: "
402                             "input %d, output %d\n",
403                             idev, odev);
404                 prom_halt();
405         }
406
407         if (serial_console)
408                 return add_preferred_console("ttyS", serial_console - 1, NULL);
409
410         return -ENODEV;
411 }
412 console_initcall(set_preferred_console);
413
414 /* BUFFER is PAGE_SIZE bytes long. */
415
416 extern char *sparc_cpu_type;
417 extern char *sparc_fpu_type;
418
419 extern void smp_info(struct seq_file *);
420 extern void smp_bogo(struct seq_file *);
421 extern void mmu_info(struct seq_file *);
422
423 unsigned int dcache_parity_tl1_occurred;
424 unsigned int icache_parity_tl1_occurred;
425
426 static int ncpus_probed;
427
428 static int show_cpuinfo(struct seq_file *m, void *__unused)
429 {
430         seq_printf(m, 
431                    "cpu\t\t: %s\n"
432                    "fpu\t\t: %s\n"
433                    "prom\t\t: %s\n"
434                    "type\t\t: %s\n"
435                    "ncpus probed\t: %d\n"
436                    "ncpus active\t: %d\n"
437                    "D$ parity tl1\t: %u\n"
438                    "I$ parity tl1\t: %u\n"
439 #ifndef CONFIG_SMP
440                    "Cpu0Bogo\t: %lu.%02lu\n"
441                    "Cpu0ClkTck\t: %016lx\n"
442 #endif
443                    ,
444                    sparc_cpu_type,
445                    sparc_fpu_type,
446                    prom_version,
447                    ((tlb_type == hypervisor) ?
448                     "sun4v" :
449                     "sun4u"),
450                    ncpus_probed,
451                    num_online_cpus(),
452                    dcache_parity_tl1_occurred,
453                    icache_parity_tl1_occurred
454 #ifndef CONFIG_SMP
455                    , cpu_data(0).udelay_val/(500000/HZ),
456                    (cpu_data(0).udelay_val/(5000/HZ)) % 100,
457                    cpu_data(0).clock_tick
458 #endif
459                 );
460 #ifdef CONFIG_SMP
461         smp_bogo(m);
462 #endif
463         mmu_info(m);
464 #ifdef CONFIG_SMP
465         smp_info(m);
466 #endif
467         return 0;
468 }
469
470 static void *c_start(struct seq_file *m, loff_t *pos)
471 {
472         /* The pointer we are returning is arbitrary,
473          * it just has to be non-NULL and not IS_ERR
474          * in the success case.
475          */
476         return *pos == 0 ? &c_start : NULL;
477 }
478
479 static void *c_next(struct seq_file *m, void *v, loff_t *pos)
480 {
481         ++*pos;
482         return c_start(m, pos);
483 }
484
485 static void c_stop(struct seq_file *m, void *v)
486 {
487 }
488
489 struct seq_operations cpuinfo_op = {
490         .start =c_start,
491         .next = c_next,
492         .stop = c_stop,
493         .show = show_cpuinfo,
494 };
495
496 extern int stop_a_enabled;
497
498 void sun_do_break(void)
499 {
500         if (!stop_a_enabled)
501                 return;
502
503         prom_printf("\n");
504         flush_user_windows();
505
506         prom_cmdline();
507 }
508
509 int serial_console = -1;
510 int stop_a_enabled = 1;
511
512 static int __init topology_init(void)
513 {
514         int i, err;
515
516         err = -ENOMEM;
517
518         /* Count the number of physically present processors in
519          * the machine, even on uniprocessor, so that /proc/cpuinfo
520          * output is consistent with 2.4.x
521          */
522         ncpus_probed = 0;
523         while (!cpu_find_by_instance(ncpus_probed, NULL, NULL))
524                 ncpus_probed++;
525
526         for_each_possible_cpu(i) {
527                 struct cpu *p = kzalloc(sizeof(*p), GFP_KERNEL);
528                 if (p) {
529                         register_cpu(p, i);
530                         err = 0;
531                 }
532         }
533
534         return err;
535 }
536
537 subsys_initcall(topology_init);