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 #include <asm/sn/simulator.h>
21 
22 extern void init_all_devices(void);
23 extern void klhwg_add_all_modules(vertex_hdl_t);
24 extern void klhwg_add_all_nodes(vertex_hdl_t);
25 
26 extern int init_hcl(void);
27 extern vertex_hdl_t hwgraph_root;
28 extern void io_module_init(void);
29 extern int pci_bus_to_hcl_cvlink(void);
30 
31 char arg_maxnodes[4];
32 char master_baseio_wid;
33 nasid_t master_baseio_nasid;
34 nasid_t master_nasid = INVALID_NASID;           /* This is the partition master nasid */
35 nasid_t console_nasid = (nasid_t)-1;
36 
37 /*
38  * Return non-zero if the given variable was specified
39  */
40 int
is_specified(char * s)41 is_specified(char *s)
42 {
43 	return (strlen(s) != 0);
44 }
45 
46 int
check_nasid_equiv(nasid_t nasida,nasid_t nasidb)47 check_nasid_equiv(nasid_t nasida, nasid_t nasidb)
48 {
49 	if ((nasida == nasidb) || (nasida == NODEPDA(NASID_TO_COMPACT_NODEID(nasidb))->xbow_peer))
50 		return 1;
51 	else
52 		return 0;
53 }
54 
55 int
is_master_baseio_nasid_widget(nasid_t test_nasid,xwidgetnum_t test_wid)56 is_master_baseio_nasid_widget(nasid_t test_nasid, xwidgetnum_t test_wid)
57 {
58 
59 	/*
60 	 * If the widget numbers are different, we're not the master.
61 	 */
62 	if (test_wid != (xwidgetnum_t)master_baseio_wid) {
63 		return 0;
64 	}
65 
66 	/*
67 	 * If the NASIDs are the same or equivalent, we're the master.
68 	 */
69 	if (check_nasid_equiv(test_nasid, master_baseio_nasid)) {
70 		return 1;
71 	} else {
72 		return 0;
73 	}
74 }
75 
76 /*
77  * This routine is responsible for the setup of all the IRIX hwgraph style
78  * stuff that's been pulled into linux.  It's called by sn_pci_find_bios which
79  * is called just before the generic Linux PCI layer does its probing (by
80  * platform_pci_fixup aka sn_pci_fixup).
81  *
82  * It is very IMPORTANT that this call is only made by the Master CPU!
83  *
84  */
85 
86 void
sgi_master_io_infr_init(void)87 sgi_master_io_infr_init(void)
88 {
89 	cnodeid_t cnode;
90 
91 	init_hcl(); /* Sets up the hwgraph compatibility layer */
92 
93         /*
94          * Initialize platform-dependent vertices in the hwgraph:
95          *      module
96          *      node
97          *      cpu
98          *      memory
99          *      slot
100          *      hub
101          *      router
102          *      xbow
103          */
104 
105         io_module_init(); /* Use to be called module_init() .. */
106         klhwg_add_all_modules(hwgraph_root);
107         klhwg_add_all_nodes(hwgraph_root);
108 
109 	for (cnode = 0; cnode < numnodes; cnode++) {
110 		extern void per_hub_init(cnodeid_t);
111 		per_hub_init(cnode);
112 	}
113 
114 	/* We can do headless hub cnodes here .. */
115 
116 	/* Initialize ICE for TIO Nodes. */
117 	for (cnode = numnodes; cnode < numionodes; cnode++) {
118 		extern void per_ice_init(cnodeid_t);
119 		per_ice_init(cnode);
120 	}
121 
122 	/*
123 	 *
124 	 * Our IO Infrastructure drivers are in place ..
125 	 * Initialize the whole IO Infrastructure .. xwidget/device probes.
126 	 *
127 	 */
128 	init_all_devices();
129 	pci_bus_to_hcl_cvlink();
130 
131 #ifdef  CONFIG_KDB
132         {
133                 extern void kdba_io_init(void);
134                 kdba_io_init();
135         }
136 #endif
137 
138 }
139