summit_32.c 5.2 KB
Newer Older
L
Linus Torvalds 已提交
1
/*
D
Dave Jones 已提交
2
 * IBM Summit-Specific Code
L
Linus Torvalds 已提交
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
 *
 * Written By: Matthew Dobson, IBM Corporation
 *
 * Copyright (c) 2003 IBM Corp.
 *
 * All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or (at
 * your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
 * NON INFRINGEMENT.  See the GNU General Public License for more
 * details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 * Send feedback to <colpatch@us.ibm.com>
 *
 */

#include <linux/mm.h>
#include <linux/init.h>
#include <asm/io.h>
A
Akinobu Mita 已提交
32
#include <asm/bios_ebda.h>
L
Linus Torvalds 已提交
33 34 35 36 37 38
#include <asm/mach-summit/mach_mpparse.h>

static struct rio_table_hdr *rio_table_hdr __initdata;
static struct scal_detail   *scal_devs[MAX_NUMNODES] __initdata;
static struct rio_detail    *rio_devs[MAX_NUMNODES*4] __initdata;

39 40
static int mp_bus_id_to_node[MAX_MP_BUSSES] __initdata;

L
Linus Torvalds 已提交
41 42 43 44 45
static int __init setup_pci_node_map_for_wpeg(int wpeg_num, int last_bus)
{
	int twister = 0, node = 0;
	int i, bus, num_buses;

46 47
	for (i = 0; i < rio_table_hdr->num_rio_dev; i++) {
		if (rio_devs[i]->node_id == rio_devs[wpeg_num]->owner_id) {
L
Linus Torvalds 已提交
48 49 50 51
			twister = rio_devs[i]->owner_id;
			break;
		}
	}
52
	if (i == rio_table_hdr->num_rio_dev) {
53
		printk(KERN_ERR "%s: Couldn't find owner Cyclone for Winnipeg!\n", __func__);
L
Linus Torvalds 已提交
54 55 56
		return last_bus;
	}

57 58
	for (i = 0; i < rio_table_hdr->num_scal_dev; i++) {
		if (scal_devs[i]->node_id == twister) {
L
Linus Torvalds 已提交
59 60 61 62
			node = scal_devs[i]->node_id;
			break;
		}
	}
63
	if (i == rio_table_hdr->num_scal_dev) {
64
		printk(KERN_ERR "%s: Couldn't find owner Twister for Cyclone!\n", __func__);
L
Linus Torvalds 已提交
65 66 67
		return last_bus;
	}

68
	switch (rio_devs[wpeg_num]->type) {
L
Linus Torvalds 已提交
69
	case CompatWPEG:
70 71
		/*
		 * The Compatibility Winnipeg controls the 2 legacy buses,
L
Linus Torvalds 已提交
72 73 74 75 76 77
		 * the 66MHz PCI bus [2 slots] and the 2 "extra" buses in case
		 * a PCI-PCI bridge card is used in either slot: total 5 buses.
		 */
		num_buses = 5;
		break;
	case AltWPEG:
78 79
		/*
		 * The Alternate Winnipeg controls the 2 133MHz buses [1 slot
L
Linus Torvalds 已提交
80 81 82 83 84 85 86
		 * each], their 2 "extra" buses, the 100MHz bus [2 slots] and
		 * the "extra" buses for each of those slots: total 7 buses.
		 */
		num_buses = 7;
		break;
	case LookOutAWPEG:
	case LookOutBWPEG:
87 88
		/*
		 * A Lookout Winnipeg controls 3 100MHz buses [2 slots each]
L
Linus Torvalds 已提交
89 90 91 92 93
		 * & the "extra" buses for each of those slots: total 9 buses.
		 */
		num_buses = 9;
		break;
	default:
94
		printk(KERN_INFO "%s: Unsupported Winnipeg type!\n", __func__);
L
Linus Torvalds 已提交
95 96 97
		return last_bus;
	}

98
	for (bus = last_bus; bus < last_bus + num_buses; bus++)
L
Linus Torvalds 已提交
99 100 101 102 103 104 105 106 107
		mp_bus_id_to_node[bus] = node;
	return bus;
}

static int __init build_detail_arrays(void)
{
	unsigned long ptr;
	int i, scal_detail_size, rio_detail_size;

108
	if (rio_table_hdr->num_scal_dev > MAX_NUMNODES) {
109
		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);
L
Linus Torvalds 已提交
110 111 112
		return 0;
	}

113
	switch (rio_table_hdr->version) {
L
Linus Torvalds 已提交
114
	default:
115
		printk(KERN_WARNING "%s: Invalid Rio Grande Table Version: %d\n", __func__, rio_table_hdr->version);
L
Linus Torvalds 已提交
116 117 118 119 120 121 122 123 124 125 126 127
		return 0;
	case 2:
		scal_detail_size = 11;
		rio_detail_size = 13;
		break;
	case 3:
		scal_detail_size = 12;
		rio_detail_size = 15;
		break;
	}

	ptr = (unsigned long)rio_table_hdr + 3;
128
	for (i = 0; i < rio_table_hdr->num_scal_dev; i++, ptr += scal_detail_size)
L
Linus Torvalds 已提交
129 130
		scal_devs[i] = (struct scal_detail *)ptr;

131
	for (i = 0; i < rio_table_hdr->num_rio_dev; i++, ptr += rio_detail_size)
L
Linus Torvalds 已提交
132 133 134 135 136 137 138 139 140 141 142 143
		rio_devs[i] = (struct rio_detail *)ptr;

	return 1;
}

void __init setup_summit(void)
{
	unsigned long		ptr;
	unsigned short		offset;
	int			i, next_wpeg, next_bus = 0;

	/* The pointer to the EBDA is stored in the word @ phys 0x40E(40:0E) */
A
Akinobu Mita 已提交
144 145
	ptr = get_bios_ebda();
	ptr = (unsigned long)phys_to_virt(ptr);
L
Linus Torvalds 已提交
146 147 148

	rio_table_hdr = NULL;
	offset = 0x180;
149
	while (offset) {
L
Linus Torvalds 已提交
150
		/* The block id is stored in the 2nd word */
151
		if (*((unsigned short *)(ptr + offset + 2)) == 0x4752) {
L
Linus Torvalds 已提交
152 153 154 155 156 157 158
			/* set the pointer past the offset & block id */
			rio_table_hdr = (struct rio_table_hdr *)(ptr + offset + 4);
			break;
		}
		/* The next offset is stored in the 1st word.  0 means no more */
		offset = *((unsigned short *)(ptr + offset));
	}
159
	if (!rio_table_hdr) {
160
		printk(KERN_ERR "%s: Unable to locate Rio Grande Table in EBDA - bailing!\n", __func__);
L
Linus Torvalds 已提交
161 162 163 164 165 166 167 168 169
		return;
	}

	if (!build_detail_arrays())
		return;

	/* The first Winnipeg we're looking for has an index of 0 */
	next_wpeg = 0;
	do {
170 171
		for (i = 0; i < rio_table_hdr->num_rio_dev; i++) {
			if (is_WPEG(rio_devs[i]) && rio_devs[i]->WP_index == next_wpeg) {
L
Linus Torvalds 已提交
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
				/* It's the Winnipeg we're looking for! */
				next_bus = setup_pci_node_map_for_wpeg(i, next_bus);
				next_wpeg++;
				break;
			}
		}
		/*
		 * If we go through all Rio devices and don't find one with
		 * the next index, it means we've found all the Winnipegs,
		 * and thus all the PCI buses.
		 */
		if (i == rio_table_hdr->num_rio_dev)
			next_wpeg = 0;
	} while (next_wpeg != 0);
}