more changes on original files
[linux-2.4.git] / arch / ppc64 / kernel / chrp_setup.c
1 /*
2  *  linux/arch/ppc/kernel/setup.c
3  *
4  *  Copyright (C) 1995  Linus Torvalds
5  *  Adapted from 'alpha' version by Gary Thomas
6  *  Modified by Cort Dougan (cort@cs.nmt.edu)
7  *  Modified by PPC64 Team, IBM Corp
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version
12  * 2 of the License, or (at your option) any later version.
13  */
14
15 /*
16  * bootup setup stuff..
17  */
18
19 #include <linux/config.h>
20 #include <linux/errno.h>
21 #include <linux/sched.h>
22 #include <linux/kernel.h>
23 #include <linux/mm.h>
24 #include <linux/stddef.h>
25 #include <linux/unistd.h>
26 #include <linux/ptrace.h>
27 #include <linux/slab.h>
28 #include <linux/user.h>
29 #include <linux/a.out.h>
30 #include <linux/tty.h>
31 #include <linux/major.h>
32 #include <linux/interrupt.h>
33 #include <linux/reboot.h>
34 #include <linux/init.h>
35 #include <linux/blk.h>
36 #include <linux/ioport.h>
37 #include <linux/console.h>
38 #include <linux/pci.h>
39 #include <linux/version.h>
40 #include <linux/adb.h>
41 #include <linux/module.h>
42 #include <linux/delay.h>
43
44 #include <linux/irq.h>
45 #include <linux/seq_file.h>
46
47 #include <asm/mmu.h>
48 #include <asm/processor.h>
49 #include <asm/io.h>
50 #include <asm/pgtable.h>
51 #include <asm/prom.h>
52 #include <asm/rtas.h>
53 #include <asm/pci-bridge.h>
54 #include <asm/pci_dma.h>
55 #include <asm/dma.h>
56 #include <asm/machdep.h>
57 #include <asm/irq.h>
58 #include <asm/keyboard.h>
59 #include <asm/init.h>
60 #include <asm/naca.h>
61 #include <asm/time.h>
62
63 #include "local_irq.h"
64 #include "i8259.h"
65 #include "open_pic.h"
66 #include "xics.h"
67 #include <asm/ppcdebug.h>
68 #include <asm/cputable.h>
69
70 extern volatile unsigned char *chrp_int_ack_special;
71
72 void chrp_setup_pci_ptrs(void);
73 void chrp_progress(char *, unsigned short);
74 void chrp_request_regions(void);
75
76 extern int pckbd_setkeycode(unsigned int scancode, unsigned int keycode);
77 extern int pckbd_getkeycode(unsigned int scancode);
78 extern int pckbd_translate(unsigned char scancode, unsigned char *keycode,
79                            char raw_mode);
80 extern char pckbd_unexpected_up(unsigned char keycode);
81 extern void pckbd_leds(unsigned char leds);
82 extern void pckbd_init_hw(void);
83 extern unsigned char pckbd_sysrq_xlate[128];
84 extern void openpic_init_IRQ(void);
85 extern void openpic_init_irq_desc(irq_desc_t *);
86 extern void init_ras_IRQ(void);
87
88 extern void find_and_init_phbs(void);
89 extern void pSeries_pcibios_fixup(void);
90 extern void iSeries_pcibios_fixup(void);
91
92 extern void pSeries_get_boot_time(struct rtc_time *rtc_time);
93 extern void pSeries_get_rtc_time(struct rtc_time *rtc_time);
94 extern int  pSeries_set_rtc_time(struct rtc_time *rtc_time);
95 void pSeries_calibrate_decr(void);
96 static void machine_check_init(void);
97 extern void SystemReset_FWNMI(void), MachineCheck_FWNMI(void);  /* from head.S */
98 int fwnmi_active = 0;  /* TRUE if an FWNMI handler is present */
99 int check_exception_flag = 0;  /* TRUE if a check-exception handler present */
100
101 kdev_t boot_dev;
102 unsigned long  virtPython0Facilities = 0;  // python0 facility area (memory mapped io) (64-bit format) VIRTUAL address.
103
104 extern HPTE *Hash, *Hash_end;
105 extern unsigned long Hash_size, Hash_mask;
106 extern int probingmem;
107 extern unsigned long loops_per_jiffy;
108
109 extern unsigned long ppc_proc_freq;
110 extern unsigned long ppc_tb_freq;
111 #ifdef CONFIG_BLK_DEV_RAM
112 extern int rd_doload;           /* 1 = load ramdisk, 0 = don't load */
113 extern int rd_prompt;           /* 1 = prompt for ramdisk, 0 = don't prompt */
114 extern int rd_image_start;      /* starting block # of image */
115 #endif
116
117 void 
118 chrp_get_cpuinfo(struct seq_file *m)
119 {
120         struct device_node *root;
121         const char *model = "";
122
123         seq_printf(m, "timebase\t: %lu\n", ppc_tb_freq);
124
125         root = find_path_device("/");
126         if (root)
127                 model = get_property(root, "model", NULL);
128         seq_printf(m, "machine\t\t: CHRP %s\n", model);
129 }
130
131 void __init chrp_request_regions(void) {
132         request_region(0x20,0x20,"pic1");
133         request_region(0xa0,0x20,"pic2");
134         request_region(0x00,0x20,"dma1");
135         request_region(0x40,0x20,"timer");
136         request_region(0x80,0x10,"dma page reg");
137         request_region(0xc0,0x20,"dma2");
138 }
139
140 void __init
141 chrp_setup_arch(void)
142 {
143         struct device_node *root;
144         unsigned int *opprop;
145         
146         /* openpic global configuration register (64-bit format). */
147         /* openpic Interrupt Source Unit pointer (64-bit format). */
148         /* python0 facility area (mmio) (64-bit format) REAL address. */
149
150         /* init to some ~sane value until calibrate_delay() runs */
151         loops_per_jiffy = 50000000;
152
153 #ifdef CONFIG_BLK_DEV_INITRD
154         /* this is fine for chrp */
155         initrd_below_start_ok = 1;
156         
157         if (initrd_start)
158                 ROOT_DEV = MKDEV(RAMDISK_MAJOR, 0);
159         else
160 #endif
161         ROOT_DEV = to_kdev_t(0x0803); /* sda3 (sda1 is for the kernel or the bootloader) */
162
163         machine_check_init();
164
165 #ifndef CONFIG_PPC_ISERIES
166         /* Find and initialize PCI host bridges */
167         /* iSeries needs to be done much later. */
168         eeh_init();
169         find_and_init_phbs();
170 #endif
171
172         /* Find the Open PIC if present */
173         root = find_path_device("/");
174         opprop = (unsigned int *) get_property(root,
175                                 "platform-open-pic", NULL);
176         if (opprop != 0) {
177                 int n = prom_n_addr_cells(root);
178                 unsigned long openpic;
179
180                 for (openpic = 0; n > 0; --n)
181                         openpic = (openpic << 32) + *opprop++;
182                 printk(KERN_DEBUG "OpenPIC addr: %lx\n", openpic);
183                 OpenPIC_Addr = __ioremap(openpic, 0x40000, _PAGE_NO_CACHE);
184         }
185
186 #ifdef CONFIG_DUMMY_CONSOLE
187         conswitchp = &dummy_con;
188 #endif
189 }
190
191 void __init
192 chrp_init2(void)
193 {
194         /*
195          * It is sensitive, when this is called (not too earlu)
196          * -- tibit
197          */
198         chrp_request_regions();
199         /* Manually leave the kernel version on the panel. */
200         ppc_md.progress("Linux ppc64\n", 0);
201         ppc_md.progress(UTS_RELEASE, 0);
202 }
203
204 /* Initialize firmware assisted non-maskable interrupts if
205  * the firmware supports this feature.  If it does not,
206  * look for the check-exception property.
207  */
208 static void __init machine_check_init(void)
209 {
210         long ret;
211         int check_ex_token;
212         int ibm_nmi_register = rtas_token("ibm,nmi-register");
213
214         if (ibm_nmi_register != RTAS_UNKNOWN_SERVICE) {
215                 ret = rtas_call(ibm_nmi_register, 2, 1, NULL,
216                                 __pa((unsigned long)SystemReset_FWNMI),
217                                 __pa((unsigned long)MachineCheck_FWNMI));
218                 if (ret == 0)
219                         fwnmi_active = 1;
220         } else {
221                 check_ex_token = rtas_token("check-exception");
222                 if (check_ex_token != RTAS_UNKNOWN_SERVICE)
223                         check_exception_flag = 1;
224         }
225 }
226
227
228 /* Early initialization.  Relocation is on but do not reference unbolted pages */
229 void __init pSeries_init_early(void)
230 {
231 #ifdef CONFIG_PPC_PSERIES       /* This ifdef should go away */
232         void *comport;
233
234         hpte_init_pSeries();
235         tce_init_pSeries();
236         pSeries_pcibios_init_early();
237
238 #ifdef CONFIG_SMP
239         smp_init_pSeries();
240 #endif
241
242         /* Map the uart for udbg. */
243         comport = (void *)__ioremap(naca->serialPortAddr, 16, _PAGE_NO_CACHE);
244         udbg_init_uart(comport);
245
246         ppc_md.udbg_putc = udbg_putc;
247         ppc_md.udbg_getc = udbg_getc;
248         ppc_md.udbg_getc_poll = udbg_getc_poll;
249 #endif
250 }
251
252 void __init
253 chrp_init(unsigned long r3, unsigned long r4, unsigned long r5,
254           unsigned long r6, unsigned long r7)
255 {
256 #if 0 /* PPPBBB remove this later... -Peter */
257 #ifdef CONFIG_BLK_DEV_INITRD
258         /* take care of initrd if we have one */
259         if ( r6 )
260         {
261                 initrd_start = __va(r6);
262                 initrd_end = __va(r6 + r7);
263         }
264 #endif /* CONFIG_BLK_DEV_INITRD */
265 #endif
266
267         ppc_md.ppc_machine = systemcfg->platform;
268
269         ppc_md.setup_arch     = chrp_setup_arch;
270         ppc_md.setup_residual = NULL;
271         ppc_md.get_cpuinfo    = chrp_get_cpuinfo;
272         if(naca->interrupt_controller == IC_OPEN_PIC) {
273                 ppc_md.init_IRQ       = openpic_init_IRQ;
274                 ppc_md.init_irq_desc  = openpic_init_irq_desc;
275                 ppc_md.get_irq        = openpic_get_irq;
276         } else {
277                 ppc_md.init_IRQ       = xics_init_IRQ;
278                 ppc_md.init_irq_desc  = xics_init_irq_desc;
279                 ppc_md.get_irq        = xics_get_irq;
280         }
281         ppc_md.init_ras_IRQ = init_ras_IRQ;
282
283         #ifndef CONFIG_PPC_ISERIES
284                 ppc_md.pcibios_fixup = pSeries_pcibios_fixup;
285                 ppc_md.log_error     = pSeries_log_error;
286         #else 
287                 ppc_md.pcibios_fixup = NULL;
288                 // ppc_md.pcibios_fixup = iSeries_pcibios_fixup;
289                 ppc_md.log_error     = NULL;
290         #endif
291
292
293         ppc_md.init           = chrp_init2;
294
295         ppc_md.restart        = rtas_restart;
296         ppc_md.power_off      = rtas_power_off;
297         ppc_md.halt           = rtas_halt;
298
299         ppc_md.time_init      = NULL;
300         ppc_md.get_boot_time  = pSeries_get_boot_time;
301         ppc_md.get_rtc_time   = pSeries_get_rtc_time;
302         ppc_md.set_rtc_time   = pSeries_set_rtc_time;
303         ppc_md.calibrate_decr = pSeries_calibrate_decr;
304
305         ppc_md.progress = chrp_progress;
306
307 #ifdef CONFIG_VT
308         ppc_md.kbd_setkeycode    = pckbd_setkeycode;
309         ppc_md.kbd_getkeycode    = pckbd_getkeycode;
310         ppc_md.kbd_translate     = pckbd_translate;
311         ppc_md.kbd_unexpected_up = pckbd_unexpected_up;
312         ppc_md.kbd_leds          = pckbd_leds;
313         ppc_md.kbd_init_hw       = pckbd_init_hw;
314 #ifdef CONFIG_MAGIC_SYSRQ
315         ppc_md.ppc_kbd_sysrq_xlate = pckbd_sysrq_xlate;
316         SYSRQ_KEY = 0x63;       /* Print Screen */
317 #endif
318 #endif
319         /* Build up the firmware_features bitmask field
320          * using contents of device-tree/ibm,hypertas-functions.
321          * Ultimately this functionality may be moved into prom.c prom_init().
322          */
323         struct device_node * dn;
324         char * hypertas;
325         unsigned int len;
326         dn = find_path_device("/rtas");
327         cur_cpu_spec->firmware_features=0;
328         hypertas = get_property(dn, "ibm,hypertas-functions", &len);
329         if (hypertas) {
330                 while (len > 0) {
331                         int i, hypertas_len;
332                         /* check value against table of strings */
333                         for(i=0; i < FIRMWARE_MAX_FEATURES; i++) {
334                                 if ((firmware_features_table[i].name) &&
335                                     (strcmp(firmware_features_table[i].name,hypertas))==0) {
336                                         /* we have a match */
337                                         cur_cpu_spec->firmware_features |=
338                                                 (firmware_features_table[i].val);
339                                         break;
340                                 }
341                         }
342                         hypertas_len = strlen(hypertas);
343                         len -= hypertas_len +1;
344                         hypertas+= hypertas_len +1;
345                 }
346         }
347
348         printk(KERN_INFO "firmware_features = 0x%lx\n",
349                cur_cpu_spec->firmware_features);
350 }
351
352 void __chrp
353 chrp_progress(char *s, unsigned short hex)
354 {
355         struct device_node *root;
356         int width, *p;
357         char *os;
358         static int display_character, set_indicator;
359         static int max_width;
360         static spinlock_t progress_lock = SPIN_LOCK_UNLOCKED;
361         static int pending_newline = 0;  /* did last write end with unprinted newline? */
362
363         if (!rtas.base)
364                 return;
365
366         if (max_width == 0) {
367                 if ( (root = find_path_device("/rtas")) &&
368                      (p = (unsigned int *)get_property(root,
369                                                        "ibm,display-line-length",
370                                                        NULL)) )
371                         max_width = *p;
372                 else
373                         max_width = 0x10;
374                 display_character = rtas_token("display-character");
375                 set_indicator = rtas_token("set-indicator");
376         }
377
378         if(display_character == RTAS_UNKNOWN_SERVICE) {
379                 /* use hex display if available */
380                 if(set_indicator != RTAS_UNKNOWN_SERVICE)
381                         rtas_call(set_indicator, 3, 1, NULL, 6, 0, hex);
382                 return;
383         }
384
385         spin_lock(&progress_lock);
386
387         /* Last write ended with newline, but we didn't print it since
388          * it would just clear the bottom line of output. Print it now
389          * instead.
390          *
391          * If no newline is pending, print a CR to start output at the
392          * beginning of the line.
393          */
394         if(pending_newline) {
395                 rtas_call(display_character, 1, 1, NULL, '\r');
396                 rtas_call(display_character, 1, 1, NULL, '\n');
397                 pending_newline = 0;
398         } else
399                 rtas_call(display_character, 1, 1, NULL, '\r');
400  
401         width = max_width;
402         os = s;
403         while (*os) {
404                 if(*os == '\n' || *os == '\r') {
405                         /* Blank to end of line. */
406                         while(width-- > 0)
407                                 rtas_call(display_character, 1, 1, NULL, ' ');
408  
409                         /* If newline is the last character, save it
410                          * until next call to avoid bumping up the
411                          * display output.
412                          */
413                         if(*os == '\n' && !os[1]) {
414                                 pending_newline = 1;
415                                 spin_unlock(&progress_lock);
416                                 return;
417                         }
418  
419                         /* RTAS wants CR-LF, not just LF */
420  
421                         if(*os == '\n') {
422                                 rtas_call(display_character, 1, 1, NULL, '\r');
423                                 rtas_call(display_character, 1, 1, NULL, '\n');
424                         } else {
425                                 /* CR might be used to re-draw a line, so we'll
426                                  * leave it alone and not add LF.
427                                  */
428                                 rtas_call(display_character, 1, 1, NULL, *os);
429                         }
430  
431                         width = max_width;
432                 } else {
433                         width--;
434                         rtas_call(display_character, 1, 1, NULL, *os);
435                 }
436  
437                 os++;
438  
439                 /* if we overwrite the screen length */
440                 if ( width <= 0 )
441                         while ( (*os != 0) && (*os != '\n') && (*os != '\r') )
442                                 os++;
443         }
444  
445         /* Blank to end of line. */
446         while ( width-- > 0 )
447                 rtas_call(display_character, 1, 1, NULL, ' ' );
448
449         spin_unlock(&progress_lock);
450 }
451
452 extern void setup_default_decr(void);
453
454 void __init pSeries_calibrate_decr(void)
455 {
456         struct device_node *cpu;
457         struct div_result divres;
458         int *fp;
459         unsigned long freq, processor_freq;
460
461         /*
462          * The cpu node should have a timebase-frequency property
463          * to tell us the rate at which the decrementer counts. 
464          */
465         freq = 16666000;        /* hardcoded default */
466         cpu = find_type_devices("cpu");
467         if (cpu != 0) { 
468                 fp = (int *) get_property(cpu, "timebase-frequency", NULL);
469                 if (fp != 0)
470                         freq = *fp;
471         }
472         ppc_tb_freq = freq;
473         processor_freq = freq;
474         if (cpu != 0) {
475                 fp = (int *) get_property(cpu, "clock-frequency", NULL);
476                 if (fp != 0)
477                         processor_freq = *fp;
478         }
479         ppc_proc_freq = processor_freq;
480         
481         printk("time_init: decrementer frequency = %lu.%.6lu MHz\n", 
482                freq/1000000, freq%1000000 );
483         printk("time_init: processor frequency   = %lu.%.6lu MHz\n",
484                 processor_freq/1000000, processor_freq%1000000 );
485
486         tb_ticks_per_jiffy = freq / HZ;
487         tb_ticks_per_sec = tb_ticks_per_jiffy * HZ;
488         tb_ticks_per_usec = freq / 1000000;
489         div128_by_32( 1024*1024, 0, tb_ticks_per_sec, &divres );
490         tb_to_xs = divres.result_low;
491
492         setup_default_decr();
493 }
494