blob: ae751094eba99754b47482aac7bab45d6dd40875 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Dave Jones835c34a2007-10-12 21:10:53 -04002 * IBM Summit-Specific Code
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
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>
Akinobu Mita356fa0c2008-04-19 23:55:20 +090032#include <asm/bios_ebda.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include <asm/mach-summit/mach_mpparse.h>
34
35static struct rio_table_hdr *rio_table_hdr __initdata;
36static struct scal_detail *scal_devs[MAX_NUMNODES] __initdata;
37static struct rio_detail *rio_devs[MAX_NUMNODES*4] __initdata;
38
Alexey Starikovskiy037cab02008-03-11 22:55:48 +030039static int mp_bus_id_to_node[MAX_MP_BUSSES] __initdata;
40
Linus Torvalds1da177e2005-04-16 15:20:36 -070041static int __init setup_pci_node_map_for_wpeg(int wpeg_num, int last_bus)
42{
43 int twister = 0, node = 0;
44 int i, bus, num_buses;
45
Paolo Ciarrocchi60e11742008-02-22 23:09:34 +010046 for (i = 0; i < rio_table_hdr->num_rio_dev; i++) {
47 if (rio_devs[i]->node_id == rio_devs[wpeg_num]->owner_id) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070048 twister = rio_devs[i]->owner_id;
49 break;
50 }
51 }
Paolo Ciarrocchi60e11742008-02-22 23:09:34 +010052 if (i == rio_table_hdr->num_rio_dev) {
Harvey Harrison77bf90e2008-03-03 11:37:23 -080053 printk(KERN_ERR "%s: Couldn't find owner Cyclone for Winnipeg!\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -070054 return last_bus;
55 }
56
Paolo Ciarrocchi60e11742008-02-22 23:09:34 +010057 for (i = 0; i < rio_table_hdr->num_scal_dev; i++) {
58 if (scal_devs[i]->node_id == twister) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070059 node = scal_devs[i]->node_id;
60 break;
61 }
62 }
Paolo Ciarrocchi60e11742008-02-22 23:09:34 +010063 if (i == rio_table_hdr->num_scal_dev) {
Harvey Harrison77bf90e2008-03-03 11:37:23 -080064 printk(KERN_ERR "%s: Couldn't find owner Twister for Cyclone!\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -070065 return last_bus;
66 }
67
Paolo Ciarrocchi60e11742008-02-22 23:09:34 +010068 switch (rio_devs[wpeg_num]->type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 case CompatWPEG:
Paolo Ciarrocchi60e11742008-02-22 23:09:34 +010070 /*
71 * The Compatibility Winnipeg controls the 2 legacy buses,
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 * the 66MHz PCI bus [2 slots] and the 2 "extra" buses in case
73 * a PCI-PCI bridge card is used in either slot: total 5 buses.
74 */
75 num_buses = 5;
76 break;
77 case AltWPEG:
Paolo Ciarrocchi60e11742008-02-22 23:09:34 +010078 /*
79 * The Alternate Winnipeg controls the 2 133MHz buses [1 slot
Linus Torvalds1da177e2005-04-16 15:20:36 -070080 * each], their 2 "extra" buses, the 100MHz bus [2 slots] and
81 * the "extra" buses for each of those slots: total 7 buses.
82 */
83 num_buses = 7;
84 break;
85 case LookOutAWPEG:
86 case LookOutBWPEG:
Paolo Ciarrocchi60e11742008-02-22 23:09:34 +010087 /*
88 * A Lookout Winnipeg controls 3 100MHz buses [2 slots each]
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 * & the "extra" buses for each of those slots: total 9 buses.
90 */
91 num_buses = 9;
92 break;
93 default:
Harvey Harrison77bf90e2008-03-03 11:37:23 -080094 printk(KERN_INFO "%s: Unsupported Winnipeg type!\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 return last_bus;
96 }
97
Paolo Ciarrocchi60e11742008-02-22 23:09:34 +010098 for (bus = last_bus; bus < last_bus + num_buses; bus++)
Linus Torvalds1da177e2005-04-16 15:20:36 -070099 mp_bus_id_to_node[bus] = node;
100 return bus;
101}
102
103static int __init build_detail_arrays(void)
104{
105 unsigned long ptr;
106 int i, scal_detail_size, rio_detail_size;
107
Paolo Ciarrocchi60e11742008-02-22 23:09:34 +0100108 if (rio_table_hdr->num_scal_dev > MAX_NUMNODES) {
Harvey Harrison77bf90e2008-03-03 11:37:23 -0800109 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);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 return 0;
111 }
112
Paolo Ciarrocchi60e11742008-02-22 23:09:34 +0100113 switch (rio_table_hdr->version) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 default:
Harvey Harrison77bf90e2008-03-03 11:37:23 -0800115 printk(KERN_WARNING "%s: Invalid Rio Grande Table Version: %d\n", __func__, rio_table_hdr->version);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 return 0;
117 case 2:
118 scal_detail_size = 11;
119 rio_detail_size = 13;
120 break;
121 case 3:
122 scal_detail_size = 12;
123 rio_detail_size = 15;
124 break;
125 }
126
127 ptr = (unsigned long)rio_table_hdr + 3;
Paolo Ciarrocchi60e11742008-02-22 23:09:34 +0100128 for (i = 0; i < rio_table_hdr->num_scal_dev; i++, ptr += scal_detail_size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 scal_devs[i] = (struct scal_detail *)ptr;
130
Paolo Ciarrocchi60e11742008-02-22 23:09:34 +0100131 for (i = 0; i < rio_table_hdr->num_rio_dev; i++, ptr += rio_detail_size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 rio_devs[i] = (struct rio_detail *)ptr;
133
134 return 1;
135}
136
137void __init setup_summit(void)
138{
139 unsigned long ptr;
140 unsigned short offset;
141 int i, next_wpeg, next_bus = 0;
142
143 /* The pointer to the EBDA is stored in the word @ phys 0x40E(40:0E) */
Akinobu Mita356fa0c2008-04-19 23:55:20 +0900144 ptr = get_bios_ebda();
145 ptr = (unsigned long)phys_to_virt(ptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146
147 rio_table_hdr = NULL;
148 offset = 0x180;
Paolo Ciarrocchi60e11742008-02-22 23:09:34 +0100149 while (offset) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 /* The block id is stored in the 2nd word */
Paolo Ciarrocchi60e11742008-02-22 23:09:34 +0100151 if (*((unsigned short *)(ptr + offset + 2)) == 0x4752) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152 /* set the pointer past the offset & block id */
153 rio_table_hdr = (struct rio_table_hdr *)(ptr + offset + 4);
154 break;
155 }
156 /* The next offset is stored in the 1st word. 0 means no more */
157 offset = *((unsigned short *)(ptr + offset));
158 }
Paolo Ciarrocchi60e11742008-02-22 23:09:34 +0100159 if (!rio_table_hdr) {
Harvey Harrison77bf90e2008-03-03 11:37:23 -0800160 printk(KERN_ERR "%s: Unable to locate Rio Grande Table in EBDA - bailing!\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 return;
162 }
163
164 if (!build_detail_arrays())
165 return;
166
167 /* The first Winnipeg we're looking for has an index of 0 */
168 next_wpeg = 0;
169 do {
Paolo Ciarrocchi60e11742008-02-22 23:09:34 +0100170 for (i = 0; i < rio_table_hdr->num_rio_dev; i++) {
171 if (is_WPEG(rio_devs[i]) && rio_devs[i]->WP_index == next_wpeg) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172 /* It's the Winnipeg we're looking for! */
173 next_bus = setup_pci_node_map_for_wpeg(i, next_bus);
174 next_wpeg++;
175 break;
176 }
177 }
178 /*
179 * If we go through all Rio devices and don't find one with
180 * the next index, it means we've found all the Winnipegs,
181 * and thus all the PCI buses.
182 */
183 if (i == rio_table_hdr->num_rio_dev)
184 next_wpeg = 0;
185 } while (next_wpeg != 0);
186}