This commit was manufactured by cvs2svn to create branch 'vserver'.
[linux-2.6.git] / arch / ppc64 / kernel / maple_setup.c
1 /*
2  *  arch/ppc64/kernel/maple_setup.c
3  *
4  *  (c) Copyright 2004 Benjamin Herrenschmidt (benh@kernel.crashing.org),
5  *                     IBM Corp. 
6  *
7  *  This program is free software; you can redistribute it and/or
8  *  modify it under the terms of the GNU General Public License
9  *  as published by the Free Software Foundation; either version
10  *  2 of the License, or (at your option) any later version.
11  *
12  */
13
14 #define DEBUG
15
16 #include <linux/config.h>
17 #include <linux/init.h>
18 #include <linux/errno.h>
19 #include <linux/sched.h>
20 #include <linux/kernel.h>
21 #include <linux/mm.h>
22 #include <linux/stddef.h>
23 #include <linux/unistd.h>
24 #include <linux/ptrace.h>
25 #include <linux/slab.h>
26 #include <linux/user.h>
27 #include <linux/a.out.h>
28 #include <linux/tty.h>
29 #include <linux/string.h>
30 #include <linux/delay.h>
31 #include <linux/ioport.h>
32 #include <linux/major.h>
33 #include <linux/initrd.h>
34 #include <linux/vt_kern.h>
35 #include <linux/console.h>
36 #include <linux/ide.h>
37 #include <linux/pci.h>
38 #include <linux/adb.h>
39 #include <linux/cuda.h>
40 #include <linux/pmu.h>
41 #include <linux/irq.h>
42 #include <linux/seq_file.h>
43 #include <linux/root_dev.h>
44 #include <linux/serial.h>
45 #include <linux/smp.h>
46
47 #include <asm/processor.h>
48 #include <asm/sections.h>
49 #include <asm/prom.h>
50 #include <asm/system.h>
51 #include <asm/pgtable.h>
52 #include <asm/bitops.h>
53 #include <asm/io.h>
54 #include <asm/pci-bridge.h>
55 #include <asm/iommu.h>
56 #include <asm/machdep.h>
57 #include <asm/dma.h>
58 #include <asm/cputable.h>
59 #include <asm/time.h>
60 #include <asm/of_device.h>
61 #include <asm/lmb.h>
62
63 #include "mpic.h"
64
65 #ifdef DEBUG
66 #define DBG(fmt...) udbg_printf(fmt)
67 #else
68 #define DBG(fmt...)
69 #endif
70
71 extern int maple_set_rtc_time(struct rtc_time *tm);
72 extern void maple_get_rtc_time(struct rtc_time *tm);
73 extern void maple_get_boot_time(struct rtc_time *tm);
74 extern void maple_calibrate_decr(void);
75 extern void maple_pci_init(void);
76 extern void maple_pcibios_fixup(void);
77 extern int maple_pci_get_legacy_ide_irq(struct pci_dev *dev, int channel);
78 extern void generic_find_legacy_serial_ports(unsigned int *default_speed);
79
80
81 static void maple_restart(char *cmd)
82 {
83 }
84
85 static void maple_power_off(void)
86 {
87 }
88
89 static void maple_halt(void)
90 {
91 }
92
93 #ifdef CONFIG_SMP
94 struct smp_ops_t maple_smp_ops = {
95         .probe          = smp_mpic_probe,
96         .message_pass   = smp_mpic_message_pass,
97         .kick_cpu       = smp_generic_kick_cpu,
98         .setup_cpu      = smp_mpic_setup_cpu,
99         .give_timebase  = smp_generic_give_timebase,
100         .take_timebase  = smp_generic_take_timebase,
101 };
102 #endif /* CONFIG_SMP */
103
104 void __init maple_setup_arch(void)
105 {
106         /* init to some ~sane value until calibrate_delay() runs */
107         loops_per_jiffy = 50000000;
108
109         /* Setup SMP callback */
110 #ifdef CONFIG_SMP
111         smp_ops = &maple_smp_ops;
112 #endif
113         /* Setup the PCI DMA to "direct" by default. May be overriden
114          * by iommu later on
115          */
116         pci_dma_init_direct();
117
118         /* Lookup PCI hosts */
119         maple_pci_init();
120
121 #ifdef CONFIG_DUMMY_CONSOLE
122         conswitchp = &dummy_con;
123 #endif
124 }
125
126 /* 
127  * Early initialization.
128  */
129 static void __init maple_init_early(void)
130 {
131         unsigned int default_speed;
132
133         DBG(" -> maple_init_early\n");
134
135         /* Initialize hash table, from now on, we can take hash faults
136          * and call ioremap
137          */
138         hpte_init_native();
139
140         /* Find the serial port */
141         generic_find_legacy_serial_ports(&default_speed);
142
143         DBG("naca->serialPortAddr: %lx\n", (long)naca->serialPortAddr);
144
145         if (naca->serialPortAddr) {
146                 void *comport;
147                 /* Map the uart for udbg. */
148                 comport = (void *)__ioremap(naca->serialPortAddr, 16, _PAGE_NO_CACHE);
149                 udbg_init_uart(comport, default_speed);
150
151                 ppc_md.udbg_putc = udbg_putc;
152                 ppc_md.udbg_getc = udbg_getc;
153                 ppc_md.udbg_getc_poll = udbg_getc_poll;
154                 DBG("Hello World !\n");
155         }
156
157         /* Setup interrupt mapping options */
158         naca->interrupt_controller = IC_OPEN_PIC;
159
160         DBG(" <- maple_init_early\n");
161 }
162
163
164 static __init void maple_init_IRQ(void)
165 {
166         struct device_node *root;
167         unsigned int *opprop;
168         unsigned long opic_addr;
169         struct mpic *mpic;
170         unsigned char senses[128];
171         int n;
172
173         DBG(" -> maple_init_IRQ\n");
174
175         /* XXX: Non standard, replace that with a proper openpic/mpic node
176          * in the device-tree. Find the Open PIC if present */
177         root = of_find_node_by_path("/");
178         opprop = (unsigned int *) get_property(root,
179                                 "platform-open-pic", NULL);
180         if (opprop == 0)
181                 panic("OpenPIC not found !\n");
182
183         n = prom_n_addr_cells(root);
184         for (opic_addr = 0; n > 0; --n)
185                 opic_addr = (opic_addr << 32) + *opprop++;
186         of_node_put(root);
187
188         /* Obtain sense values from device-tree */
189         prom_get_irq_senses(senses, 0, 128);
190
191         mpic = mpic_alloc(opic_addr,
192                           MPIC_PRIMARY | MPIC_BIG_ENDIAN |
193                           MPIC_BROKEN_U3 | MPIC_WANTS_RESET,
194                           0, 0, 128, 128, senses, 128, "U3-MPIC");
195         BUG_ON(mpic == NULL);
196         mpic_init(mpic);
197
198         DBG(" <- maple_init_IRQ\n");
199 }
200
201 static void __init maple_progress(char *s, unsigned short hex)
202 {
203         printk("*** %04x : %s\n", hex, s ? s : "");
204 }
205
206
207 /*
208  * Called very early, MMU is off, device-tree isn't unflattened
209  */
210 static int __init maple_probe(int platform)
211 {
212         if (platform != PLATFORM_MAPLE)
213                 return 0;
214         /*
215          * On U3, the DART (iommu) must be allocated now since it
216          * has an impact on htab_initialize (due to the large page it
217          * occupies having to be broken up so the DART itself is not
218          * part of the cacheable linar mapping
219          */
220         alloc_u3_dart_table();
221
222         return 1;
223 }
224
225 struct machdep_calls __initdata maple_md = {
226         .probe                  = maple_probe,
227         .setup_arch             = maple_setup_arch,
228         .init_early             = maple_init_early,
229         .init_IRQ               = maple_init_IRQ,
230         .get_irq                = mpic_get_irq,
231         .pcibios_fixup          = maple_pcibios_fixup,
232         .pci_get_legacy_ide_irq = maple_pci_get_legacy_ide_irq,
233         .restart                = maple_restart,
234         .power_off              = maple_power_off,
235         .halt                   = maple_halt,
236         .get_boot_time          = maple_get_boot_time,
237         .set_rtc_time           = maple_set_rtc_time,
238         .get_rtc_time           = maple_get_rtc_time,
239         .calibrate_decr         = maple_calibrate_decr,
240         .progress               = maple_progress,
241 };