2.5.70 update
[linux-flexiantxendom0-3.2.10.git] / arch / ia64 / sn / io / sn2 / sgi_io_init.c
1 /* $Id$
2  *
3  * This file is subject to the terms and conditions of the GNU General Public
4  * License.  See the file "COPYING" in the main directory of this archive
5  * for more details.
6  *
7  * Copyright (C) 1992 - 1997, 2000-2003 Silicon Graphics, Inc. All rights reserved.
8  */
9
10 #include <linux/types.h>
11 #include <linux/config.h>
12 #include <linux/slab.h>
13 #include <asm/sn/sgi.h>
14 #include <asm/sn/io.h>
15 #include <asm/sn/sn_cpuid.h>
16 #include <asm/sn/klconfig.h>
17 #include <asm/sn/sn_private.h>
18 #include <asm/sn/pci/pciba.h>
19 #include <linux/smp.h>
20
21 extern void mlreset(void);
22 extern int init_hcl(void);
23 extern void klgraph_hack_init(void);
24 extern void hubspc_init(void);
25 extern void pciio_init(void);
26 extern void pcibr_init(void);
27 extern void xtalk_init(void);
28 extern void xbow_init(void);
29 extern void xbmon_init(void);
30 extern void pciiox_init(void);
31 extern void pic_init(void);
32 extern void usrpci_init(void);
33 extern void ioc3_init(void);
34 extern void initialize_io(void);
35 extern void klhwg_add_all_modules(devfs_handle_t);
36 extern void klhwg_add_all_nodes(devfs_handle_t);
37
38 void sn_mp_setup(void);
39 extern devfs_handle_t hwgraph_root;
40 extern void io_module_init(void);
41 extern void pci_bus_cvlink_init(void);
42 extern void temp_hack(void);
43
44 extern int pci_bus_to_hcl_cvlink(void);
45
46 /* #define DEBUG_IO_INIT 1 */
47 #ifdef DEBUG_IO_INIT
48 #define DBG(x...) printk(x)
49 #else
50 #define DBG(x...)
51 #endif /* DEBUG_IO_INIT */
52
53 /*
54  * per_hub_init
55  *
56  *      This code is executed once for each Hub chip.
57  */
58 static void
59 per_hub_init(cnodeid_t cnode)
60 {
61         nasid_t         nasid;
62         nodepda_t       *npdap;
63         ii_icmr_u_t     ii_icmr;
64         ii_ibcr_u_t     ii_ibcr;
65
66         nasid = COMPACT_TO_NASID_NODEID(cnode);
67
68         ASSERT(nasid != INVALID_NASID);
69         ASSERT(NASID_TO_COMPACT_NODEID(nasid) == cnode);
70
71         npdap = NODEPDA(cnode);
72
73         REMOTE_HUB_S(nasid, IIO_IWEIM, 0x8000);
74
75         /*
76          * Set the total number of CRBs that can be used.
77          */
78         ii_icmr.ii_icmr_regval= 0x0;
79         ii_icmr.ii_icmr_fld_s.i_c_cnt = 0xf;
80         REMOTE_HUB_S(nasid, IIO_ICMR, ii_icmr.ii_icmr_regval);
81
82         /*
83          * Set the number of CRBs that both of the BTEs combined
84          * can use minus 1.
85          */
86         ii_ibcr.ii_ibcr_regval= 0x0;
87         ii_ibcr.ii_ibcr_fld_s.i_count = 0x8;
88         REMOTE_HUB_S(nasid, IIO_IBCR, ii_ibcr.ii_ibcr_regval);
89
90         /*
91          * Set CRB timeout to be 10ms.
92          */
93 #ifdef BRINGUP2
94         REMOTE_HUB_S(nasid, IIO_ICTP, 0xffffff );
95         REMOTE_HUB_S(nasid, IIO_ICTO, 0xff);
96         //REMOTE_HUB_S(nasid, IIO_IWI, 0x00FF00FF00FFFFFF);
97 #endif
98
99         /* Initialize error interrupts for this hub. */
100         hub_error_init(cnode);
101 }
102
103 /*
104  * This routine is responsible for the setup of all the IRIX hwgraph style
105  * stuff that's been pulled into linux.  It's called by sn_pci_find_bios which
106  * is called just before the generic Linux PCI layer does its probing (by 
107  * platform_pci_fixup aka sn_pci_fixup).
108  *
109  * It is very IMPORTANT that this call is only made by the Master CPU!
110  *
111  */
112
113 void
114 sgi_master_io_infr_init(void)
115 {
116         int cnode;
117         extern void kdba_io_init();
118
119         /*
120          * Do any early init stuff .. einit_tbl[] etc.
121          */
122         init_hcl(); /* Sets up the hwgraph compatibility layer with devfs */
123
124         /*
125          * initialize the Linux PCI to xwidget vertexes ..
126          */
127         pci_bus_cvlink_init();
128
129         kdba_io_init();
130
131 #ifdef BRINGUP
132         /*
133          * Hack to provide statically initialzed klgraph entries.
134          */
135         DBG("--> sgi_master_io_infr_init: calling klgraph_hack_init()\n");
136         klgraph_hack_init();
137 #endif /* BRINGUP */
138
139         /*
140          * This is the Master CPU.  Emulate mlsetup and main.c in Irix.
141          */
142         mlreset();
143
144         /*
145          * allowboot() is called by kern/os/main.c in main()
146          * Emulate allowboot() ...
147          *   per_cpu_init() - only need per_hub_init()
148          *   cpu_io_setup() - Nothing to do.
149          * 
150          */
151         sn_mp_setup();
152
153         for (cnode = 0; cnode < numnodes; cnode++) {
154                 per_hub_init(cnode);
155         }
156
157         /* We can do headless hub cnodes here .. */
158
159         /*
160          * io_init[] stuff.
161          *
162          * Get SGI IO Infrastructure drivers to init and register with 
163          * each other etc.
164          */
165
166         hubspc_init();
167         pciio_init();
168         pcibr_init();
169         pic_init();
170         xtalk_init();
171         xbow_init();
172         xbmon_init();
173         pciiox_init();
174         usrpci_init();
175         ioc3_init();
176
177         /*
178          *
179          * Our IO Infrastructure drivers are in place .. 
180          * Initialize the whole IO Infrastructure .. xwidget/device probes.
181          *
182          */
183         initialize_io();
184         pci_bus_to_hcl_cvlink();
185
186 #ifdef CONFIG_PCIBA
187         DBG("--> sgi_master_io_infr_init: calling pciba_init()\n");
188 #ifndef BRINGUP2
189         pciba_init();
190 #endif
191 #endif
192 }
193
194 /*
195  * One-time setup for MP SN.
196  * Allocate per-node data, slurp prom klconfig information and
197  * convert it to hwgraph information.
198  */
199 void
200 sn_mp_setup(void)
201 {
202         cpuid_t         cpu;
203
204         for (cpu = 0; cpu < NR_CPUS; cpu++) {
205                 /* Skip holes in CPU space */
206                 if (cpu_enabled(cpu)) {
207                         init_platform_pda(cpu);
208                 }
209         }
210
211         /*
212          * Initialize platform-dependent vertices in the hwgraph:
213          *      module
214          *      node
215          *      cpu
216          *      memory
217          *      slot
218          *      hub
219          *      router
220          *      xbow
221          */
222
223         io_module_init(); /* Use to be called module_init() .. */
224         klhwg_add_all_modules(hwgraph_root);
225         klhwg_add_all_nodes(hwgraph_root);
226 }