Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Dave Jones | 835c34a | 2007-10-12 21:10:53 -0400 | [diff] [blame] | 2 | * IBM Summit-Specific Code |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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/mach-summit/mach_mpparse.h> |
| 33 | |
| 34 | static struct rio_table_hdr *rio_table_hdr __initdata; |
| 35 | static struct scal_detail *scal_devs[MAX_NUMNODES] __initdata; |
| 36 | static struct rio_detail *rio_devs[MAX_NUMNODES*4] __initdata; |
| 37 | |
| 38 | static int __init setup_pci_node_map_for_wpeg(int wpeg_num, int last_bus) |
| 39 | { |
| 40 | int twister = 0, node = 0; |
| 41 | int i, bus, num_buses; |
| 42 | |
Paolo Ciarrocchi | 60e1174 | 2008-02-22 23:09:34 +0100 | [diff] [blame] | 43 | for (i = 0; i < rio_table_hdr->num_rio_dev; i++) { |
| 44 | if (rio_devs[i]->node_id == rio_devs[wpeg_num]->owner_id) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | twister = rio_devs[i]->owner_id; |
| 46 | break; |
| 47 | } |
| 48 | } |
Paolo Ciarrocchi | 60e1174 | 2008-02-22 23:09:34 +0100 | [diff] [blame] | 49 | if (i == rio_table_hdr->num_rio_dev) { |
Harvey Harrison | 77bf90e | 2008-03-03 11:37:23 -0800 | [diff] [blame^] | 50 | printk(KERN_ERR "%s: Couldn't find owner Cyclone for Winnipeg!\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | return last_bus; |
| 52 | } |
| 53 | |
Paolo Ciarrocchi | 60e1174 | 2008-02-22 23:09:34 +0100 | [diff] [blame] | 54 | for (i = 0; i < rio_table_hdr->num_scal_dev; i++) { |
| 55 | if (scal_devs[i]->node_id == twister) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | node = scal_devs[i]->node_id; |
| 57 | break; |
| 58 | } |
| 59 | } |
Paolo Ciarrocchi | 60e1174 | 2008-02-22 23:09:34 +0100 | [diff] [blame] | 60 | if (i == rio_table_hdr->num_scal_dev) { |
Harvey Harrison | 77bf90e | 2008-03-03 11:37:23 -0800 | [diff] [blame^] | 61 | printk(KERN_ERR "%s: Couldn't find owner Twister for Cyclone!\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | return last_bus; |
| 63 | } |
| 64 | |
Paolo Ciarrocchi | 60e1174 | 2008-02-22 23:09:34 +0100 | [diff] [blame] | 65 | switch (rio_devs[wpeg_num]->type) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | case CompatWPEG: |
Paolo Ciarrocchi | 60e1174 | 2008-02-22 23:09:34 +0100 | [diff] [blame] | 67 | /* |
| 68 | * The Compatibility Winnipeg controls the 2 legacy buses, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | * the 66MHz PCI bus [2 slots] and the 2 "extra" buses in case |
| 70 | * a PCI-PCI bridge card is used in either slot: total 5 buses. |
| 71 | */ |
| 72 | num_buses = 5; |
| 73 | break; |
| 74 | case AltWPEG: |
Paolo Ciarrocchi | 60e1174 | 2008-02-22 23:09:34 +0100 | [diff] [blame] | 75 | /* |
| 76 | * The Alternate Winnipeg controls the 2 133MHz buses [1 slot |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | * each], their 2 "extra" buses, the 100MHz bus [2 slots] and |
| 78 | * the "extra" buses for each of those slots: total 7 buses. |
| 79 | */ |
| 80 | num_buses = 7; |
| 81 | break; |
| 82 | case LookOutAWPEG: |
| 83 | case LookOutBWPEG: |
Paolo Ciarrocchi | 60e1174 | 2008-02-22 23:09:34 +0100 | [diff] [blame] | 84 | /* |
| 85 | * A Lookout Winnipeg controls 3 100MHz buses [2 slots each] |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | * & the "extra" buses for each of those slots: total 9 buses. |
| 87 | */ |
| 88 | num_buses = 9; |
| 89 | break; |
| 90 | default: |
Harvey Harrison | 77bf90e | 2008-03-03 11:37:23 -0800 | [diff] [blame^] | 91 | printk(KERN_INFO "%s: Unsupported Winnipeg type!\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | return last_bus; |
| 93 | } |
| 94 | |
Paolo Ciarrocchi | 60e1174 | 2008-02-22 23:09:34 +0100 | [diff] [blame] | 95 | for (bus = last_bus; bus < last_bus + num_buses; bus++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | mp_bus_id_to_node[bus] = node; |
| 97 | return bus; |
| 98 | } |
| 99 | |
| 100 | static int __init build_detail_arrays(void) |
| 101 | { |
| 102 | unsigned long ptr; |
| 103 | int i, scal_detail_size, rio_detail_size; |
| 104 | |
Paolo Ciarrocchi | 60e1174 | 2008-02-22 23:09:34 +0100 | [diff] [blame] | 105 | if (rio_table_hdr->num_scal_dev > MAX_NUMNODES) { |
Harvey Harrison | 77bf90e | 2008-03-03 11:37:23 -0800 | [diff] [blame^] | 106 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | return 0; |
| 108 | } |
| 109 | |
Paolo Ciarrocchi | 60e1174 | 2008-02-22 23:09:34 +0100 | [diff] [blame] | 110 | switch (rio_table_hdr->version) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | default: |
Harvey Harrison | 77bf90e | 2008-03-03 11:37:23 -0800 | [diff] [blame^] | 112 | printk(KERN_WARNING "%s: Invalid Rio Grande Table Version: %d\n", __func__, rio_table_hdr->version); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | return 0; |
| 114 | case 2: |
| 115 | scal_detail_size = 11; |
| 116 | rio_detail_size = 13; |
| 117 | break; |
| 118 | case 3: |
| 119 | scal_detail_size = 12; |
| 120 | rio_detail_size = 15; |
| 121 | break; |
| 122 | } |
| 123 | |
| 124 | ptr = (unsigned long)rio_table_hdr + 3; |
Paolo Ciarrocchi | 60e1174 | 2008-02-22 23:09:34 +0100 | [diff] [blame] | 125 | for (i = 0; i < rio_table_hdr->num_scal_dev; i++, ptr += scal_detail_size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | scal_devs[i] = (struct scal_detail *)ptr; |
| 127 | |
Paolo Ciarrocchi | 60e1174 | 2008-02-22 23:09:34 +0100 | [diff] [blame] | 128 | for (i = 0; i < rio_table_hdr->num_rio_dev; i++, ptr += rio_detail_size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | rio_devs[i] = (struct rio_detail *)ptr; |
| 130 | |
| 131 | return 1; |
| 132 | } |
| 133 | |
| 134 | void __init setup_summit(void) |
| 135 | { |
| 136 | unsigned long ptr; |
| 137 | unsigned short offset; |
| 138 | int i, next_wpeg, next_bus = 0; |
| 139 | |
| 140 | /* The pointer to the EBDA is stored in the word @ phys 0x40E(40:0E) */ |
| 141 | ptr = *(unsigned short *)phys_to_virt(0x40Eul); |
| 142 | ptr = (unsigned long)phys_to_virt(ptr << 4); |
| 143 | |
| 144 | rio_table_hdr = NULL; |
| 145 | offset = 0x180; |
Paolo Ciarrocchi | 60e1174 | 2008-02-22 23:09:34 +0100 | [diff] [blame] | 146 | while (offset) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | /* The block id is stored in the 2nd word */ |
Paolo Ciarrocchi | 60e1174 | 2008-02-22 23:09:34 +0100 | [diff] [blame] | 148 | if (*((unsigned short *)(ptr + offset + 2)) == 0x4752) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | /* set the pointer past the offset & block id */ |
| 150 | rio_table_hdr = (struct rio_table_hdr *)(ptr + offset + 4); |
| 151 | break; |
| 152 | } |
| 153 | /* The next offset is stored in the 1st word. 0 means no more */ |
| 154 | offset = *((unsigned short *)(ptr + offset)); |
| 155 | } |
Paolo Ciarrocchi | 60e1174 | 2008-02-22 23:09:34 +0100 | [diff] [blame] | 156 | if (!rio_table_hdr) { |
Harvey Harrison | 77bf90e | 2008-03-03 11:37:23 -0800 | [diff] [blame^] | 157 | printk(KERN_ERR "%s: Unable to locate Rio Grande Table in EBDA - bailing!\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | return; |
| 159 | } |
| 160 | |
| 161 | if (!build_detail_arrays()) |
| 162 | return; |
| 163 | |
| 164 | /* The first Winnipeg we're looking for has an index of 0 */ |
| 165 | next_wpeg = 0; |
| 166 | do { |
Paolo Ciarrocchi | 60e1174 | 2008-02-22 23:09:34 +0100 | [diff] [blame] | 167 | for (i = 0; i < rio_table_hdr->num_rio_dev; i++) { |
| 168 | if (is_WPEG(rio_devs[i]) && rio_devs[i]->WP_index == next_wpeg) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | /* It's the Winnipeg we're looking for! */ |
| 170 | next_bus = setup_pci_node_map_for_wpeg(i, next_bus); |
| 171 | next_wpeg++; |
| 172 | break; |
| 173 | } |
| 174 | } |
| 175 | /* |
| 176 | * If we go through all Rio devices and don't find one with |
| 177 | * the next index, it means we've found all the Winnipegs, |
| 178 | * and thus all the PCI buses. |
| 179 | */ |
| 180 | if (i == rio_table_hdr->num_rio_dev) |
| 181 | next_wpeg = 0; |
| 182 | } while (next_wpeg != 0); |
| 183 | } |