Merge branch 'linus' into cpus4096
[pandora-kernel.git] / arch / x86 / kernel / summit_32.c
1 /*
2  * IBM Summit-Specific Code
3  *
4  * Written By: Matthew Dobson, IBM Corporation
5  *
6  * Copyright (c) 2003 IBM Corp.
7  *
8  * All rights reserved.
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or (at
13  * your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful, but
16  * WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
18  * NON INFRINGEMENT.  See the GNU General Public License for more
19  * details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24  *
25  * Send feedback to <colpatch@us.ibm.com>
26  *
27  */
28
29 #include <linux/mm.h>
30 #include <linux/init.h>
31 #include <asm/io.h>
32 #include <asm/bios_ebda.h>
33 #include <asm/mach-summit/mach_mpparse.h>
34
35 static struct rio_table_hdr *rio_table_hdr __initdata;
36 static struct scal_detail   *scal_devs[MAX_NUMNODES] __initdata;
37 static struct rio_detail    *rio_devs[MAX_NUMNODES*4] __initdata;
38
39 #ifndef CONFIG_X86_NUMAQ
40 static int mp_bus_id_to_node[MAX_MP_BUSSES] __initdata;
41 #endif
42
43 static int __init setup_pci_node_map_for_wpeg(int wpeg_num, int last_bus)
44 {
45         int twister = 0, node = 0;
46         int i, bus, num_buses;
47
48         for (i = 0; i < rio_table_hdr->num_rio_dev; i++) {
49                 if (rio_devs[i]->node_id == rio_devs[wpeg_num]->owner_id) {
50                         twister = rio_devs[i]->owner_id;
51                         break;
52                 }
53         }
54         if (i == rio_table_hdr->num_rio_dev) {
55                 printk(KERN_ERR "%s: Couldn't find owner Cyclone for Winnipeg!\n", __func__);
56                 return last_bus;
57         }
58
59         for (i = 0; i < rio_table_hdr->num_scal_dev; i++) {
60                 if (scal_devs[i]->node_id == twister) {
61                         node = scal_devs[i]->node_id;
62                         break;
63                 }
64         }
65         if (i == rio_table_hdr->num_scal_dev) {
66                 printk(KERN_ERR "%s: Couldn't find owner Twister for Cyclone!\n", __func__);
67                 return last_bus;
68         }
69
70         switch (rio_devs[wpeg_num]->type) {
71         case CompatWPEG:
72                 /*
73                  * The Compatibility Winnipeg controls the 2 legacy buses,
74                  * the 66MHz PCI bus [2 slots] and the 2 "extra" buses in case
75                  * a PCI-PCI bridge card is used in either slot: total 5 buses.
76                  */
77                 num_buses = 5;
78                 break;
79         case AltWPEG:
80                 /*
81                  * The Alternate Winnipeg controls the 2 133MHz buses [1 slot
82                  * each], their 2 "extra" buses, the 100MHz bus [2 slots] and
83                  * the "extra" buses for each of those slots: total 7 buses.
84                  */
85                 num_buses = 7;
86                 break;
87         case LookOutAWPEG:
88         case LookOutBWPEG:
89                 /*
90                  * A Lookout Winnipeg controls 3 100MHz buses [2 slots each]
91                  * & the "extra" buses for each of those slots: total 9 buses.
92                  */
93                 num_buses = 9;
94                 break;
95         default:
96                 printk(KERN_INFO "%s: Unsupported Winnipeg type!\n", __func__);
97                 return last_bus;
98         }
99
100         for (bus = last_bus; bus < last_bus + num_buses; bus++)
101                 mp_bus_id_to_node[bus] = node;
102         return bus;
103 }
104
105 static int __init build_detail_arrays(void)
106 {
107         unsigned long ptr;
108         int i, scal_detail_size, rio_detail_size;
109
110         if (rio_table_hdr->num_scal_dev > MAX_NUMNODES) {
111                 printk(KERN_WARNING "%s: MAX_NUMNODES too low!  Defined as %d, but system has %d nodes.\n", __func__, MAX_NUMNODES, rio_table_hdr->num_scal_dev);
112                 return 0;
113         }
114
115         switch (rio_table_hdr->version) {
116         default:
117                 printk(KERN_WARNING "%s: Invalid Rio Grande Table Version: %d\n", __func__, rio_table_hdr->version);
118                 return 0;
119         case 2:
120                 scal_detail_size = 11;
121                 rio_detail_size = 13;
122                 break;
123         case 3:
124                 scal_detail_size = 12;
125                 rio_detail_size = 15;
126                 break;
127         }
128
129         ptr = (unsigned long)rio_table_hdr + 3;
130         for (i = 0; i < rio_table_hdr->num_scal_dev; i++, ptr += scal_detail_size)
131                 scal_devs[i] = (struct scal_detail *)ptr;
132
133         for (i = 0; i < rio_table_hdr->num_rio_dev; i++, ptr += rio_detail_size)
134                 rio_devs[i] = (struct rio_detail *)ptr;
135
136         return 1;
137 }
138
139 void __init setup_summit(void)
140 {
141         unsigned long           ptr;
142         unsigned short          offset;
143         int                     i, next_wpeg, next_bus = 0;
144
145         /* The pointer to the EBDA is stored in the word @ phys 0x40E(40:0E) */
146         ptr = get_bios_ebda();
147         ptr = (unsigned long)phys_to_virt(ptr);
148
149         rio_table_hdr = NULL;
150         offset = 0x180;
151         while (offset) {
152                 /* The block id is stored in the 2nd word */
153                 if (*((unsigned short *)(ptr + offset + 2)) == 0x4752) {
154                         /* set the pointer past the offset & block id */
155                         rio_table_hdr = (struct rio_table_hdr *)(ptr + offset + 4);
156                         break;
157                 }
158                 /* The next offset is stored in the 1st word.  0 means no more */
159                 offset = *((unsigned short *)(ptr + offset));
160         }
161         if (!rio_table_hdr) {
162                 printk(KERN_ERR "%s: Unable to locate Rio Grande Table in EBDA - bailing!\n", __func__);
163                 return;
164         }
165
166         if (!build_detail_arrays())
167                 return;
168
169         /* The first Winnipeg we're looking for has an index of 0 */
170         next_wpeg = 0;
171         do {
172                 for (i = 0; i < rio_table_hdr->num_rio_dev; i++) {
173                         if (is_WPEG(rio_devs[i]) && rio_devs[i]->WP_index == next_wpeg) {
174                                 /* It's the Winnipeg we're looking for! */
175                                 next_bus = setup_pci_node_map_for_wpeg(i, next_bus);
176                                 next_wpeg++;
177                                 break;
178                         }
179                 }
180                 /*
181                  * If we go through all Rio devices and don't find one with
182                  * the next index, it means we've found all the Winnipegs,
183                  * and thus all the PCI buses.
184                  */
185                 if (i == rio_table_hdr->num_rio_dev)
186                         next_wpeg = 0;
187         } while (next_wpeg != 0);
188 }