2005-12-02 22:52:30 +01:00
|
|
|
/*
|
2007-04-22 21:08:13 +02:00
|
|
|
* This file is part of the LinuxBIOS project.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2003-2004 Linux Networx
|
|
|
|
* (Written by Eric Biederman <ebiederman@lnxi.com> for Linux Networx)
|
|
|
|
* Copyright (C) 2004 David Hendricks <sc@flagen.com>
|
|
|
|
* Copyright (C) 2004 Li-Ta Lo <ollie@lanl.gov>
|
|
|
|
* Copyright (C) 2005-2006 Tyan
|
|
|
|
* (Written by Yinghai Lu <yhlu@tyan.com> for Tyan)
|
|
|
|
* Copyright (C) 2005-2006 Stefan Reinauer <stepan@openbios.org>
|
|
|
|
*
|
|
|
|
* 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; version 2 of the License.
|
|
|
|
*
|
|
|
|
* 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. 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
2005-12-02 22:52:30 +01:00
|
|
|
|
2007-04-22 21:08:13 +02:00
|
|
|
/*
|
|
|
|
2005.11 yhlu add let the real sb to use small uintid
|
2005-12-02 22:52:30 +01:00
|
|
|
*/
|
|
|
|
|
2003-09-02 19:16:48 +02:00
|
|
|
#include <bitops.h>
|
|
|
|
#include <console/console.h>
|
|
|
|
#include <device/device.h>
|
|
|
|
#include <device/path.h>
|
|
|
|
#include <device/pci.h>
|
2004-03-11 16:01:31 +01:00
|
|
|
#include <device/pci_ids.h>
|
2003-09-04 05:00:54 +02:00
|
|
|
#include <device/hypertransport.h>
|
2003-09-02 19:16:48 +02:00
|
|
|
#include <part/hard_reset.h>
|
|
|
|
#include <part/fallback_boot.h>
|
|
|
|
|
2007-10-24 00:17:45 +02:00
|
|
|
/* The hypertransport link is already optimized in pre-ram code
|
|
|
|
* so don't do it again
|
|
|
|
*/
|
2005-01-26 23:00:20 +01:00
|
|
|
#define OPT_HT_LINK 0
|
2005-07-08 04:49:49 +02:00
|
|
|
|
2005-07-06 19:15:30 +02:00
|
|
|
#if OPT_HT_LINK == 1
|
2005-12-02 22:52:30 +01:00
|
|
|
#include <cpu/amd/model_fxx_rev.h>
|
2005-07-06 19:15:30 +02:00
|
|
|
#endif
|
|
|
|
|
2003-09-02 19:16:48 +02:00
|
|
|
static device_t ht_scan_get_devs(device_t *old_devices)
|
|
|
|
{
|
|
|
|
device_t first, last;
|
|
|
|
first = *old_devices;
|
|
|
|
last = first;
|
2005-07-08 04:49:49 +02:00
|
|
|
/* Extract the chain of devices to (first through last)
|
|
|
|
* for the next hypertransport device.
|
|
|
|
*/
|
2004-10-14 23:25:53 +02:00
|
|
|
while(last && last->sibling &&
|
|
|
|
(last->sibling->path.type == DEVICE_PATH_PCI) &&
|
2005-07-08 04:49:49 +02:00
|
|
|
(last->sibling->path.u.pci.devfn > last->path.u.pci.devfn))
|
|
|
|
{
|
2003-09-02 19:16:48 +02:00
|
|
|
last = last->sibling;
|
|
|
|
}
|
|
|
|
if (first) {
|
2005-07-08 04:49:49 +02:00
|
|
|
device_t child;
|
|
|
|
/* Unlink the chain from the list of old devices */
|
2003-09-02 19:16:48 +02:00
|
|
|
*old_devices = last->sibling;
|
|
|
|
last->sibling = 0;
|
2005-07-08 04:49:49 +02:00
|
|
|
|
|
|
|
/* Now add the device to the list of devices on the bus.
|
|
|
|
*/
|
|
|
|
/* Find the last child of our parent */
|
|
|
|
for(child = first->bus->children; child && child->sibling; ) {
|
|
|
|
child = child->sibling;
|
|
|
|
}
|
|
|
|
/* Place the chain on the list of children of their parent. */
|
|
|
|
if (child) {
|
|
|
|
child->sibling = first;
|
|
|
|
} else {
|
|
|
|
first->bus->children = first;
|
|
|
|
}
|
2003-09-02 19:16:48 +02:00
|
|
|
}
|
|
|
|
return first;
|
|
|
|
}
|
2005-07-08 04:49:49 +02:00
|
|
|
|
2005-01-26 23:00:20 +01:00
|
|
|
#if OPT_HT_LINK == 1
|
2004-03-11 16:01:31 +01:00
|
|
|
static unsigned ht_read_freq_cap(device_t dev, unsigned pos)
|
|
|
|
{
|
|
|
|
/* Handle bugs in valid hypertransport frequency reporting */
|
|
|
|
unsigned freq_cap;
|
|
|
|
|
|
|
|
freq_cap = pci_read_config16(dev, pos);
|
|
|
|
freq_cap &= ~(1 << HT_FREQ_VENDOR); /* Ignore Vendor HT frequencies */
|
|
|
|
|
|
|
|
/* AMD 8131 Errata 48 */
|
|
|
|
if ((dev->vendor == PCI_VENDOR_ID_AMD) &&
|
|
|
|
(dev->device == PCI_DEVICE_ID_AMD_8131_PCIX)) {
|
|
|
|
freq_cap &= ~(1 << HT_FREQ_800Mhz);
|
2005-07-08 04:49:49 +02:00
|
|
|
}
|
2004-03-11 16:01:31 +01:00
|
|
|
/* AMD 8151 Errata 23 */
|
|
|
|
if ((dev->vendor == PCI_VENDOR_ID_AMD) &&
|
|
|
|
(dev->device == PCI_DEVICE_ID_AMD_8151_SYSCTRL)) {
|
|
|
|
freq_cap &= ~(1 << HT_FREQ_800Mhz);
|
2005-07-08 04:49:49 +02:00
|
|
|
}
|
2004-03-11 16:01:31 +01:00
|
|
|
/* AMD K8 Unsupported 1Ghz? */
|
|
|
|
if ((dev->vendor == PCI_VENDOR_ID_AMD) && (dev->device == 0x1100)) {
|
2005-12-02 22:52:30 +01:00
|
|
|
#if K8_HT_FREQ_1G_SUPPORT == 1
|
2006-10-04 22:46:15 +02:00
|
|
|
#if K8_REV_F_SUPPORT == 0
|
2005-12-02 22:52:30 +01:00
|
|
|
if (is_cpu_pre_e0()) { // only e0 later suupport 1GHz HT
|
2005-01-26 23:00:20 +01:00
|
|
|
freq_cap &= ~(1 << HT_FREQ_1000Mhz);
|
2005-12-02 22:52:30 +01:00
|
|
|
}
|
2006-10-04 22:46:15 +02:00
|
|
|
#endif
|
2005-12-02 22:52:30 +01:00
|
|
|
#else
|
|
|
|
freq_cap &= ~(1 << HT_FREQ_1000Mhz);
|
|
|
|
#endif
|
2005-07-08 04:49:49 +02:00
|
|
|
|
2004-03-11 16:01:31 +01:00
|
|
|
}
|
|
|
|
return freq_cap;
|
|
|
|
}
|
2005-07-08 04:49:49 +02:00
|
|
|
#endif
|
2003-09-02 19:16:48 +02:00
|
|
|
|
2005-07-08 04:49:49 +02:00
|
|
|
struct ht_link {
|
2003-09-02 19:16:48 +02:00
|
|
|
struct device *dev;
|
|
|
|
unsigned pos;
|
2005-07-08 04:49:49 +02:00
|
|
|
unsigned char ctrl_off, config_off, freq_off, freq_cap_off;
|
2003-09-02 19:16:48 +02:00
|
|
|
};
|
|
|
|
|
2005-07-08 04:49:49 +02:00
|
|
|
static int ht_setup_link(struct ht_link *prev, device_t dev, unsigned pos)
|
2003-09-02 19:16:48 +02:00
|
|
|
{
|
2007-10-24 00:17:45 +02:00
|
|
|
#if OPT_HT_LINK == 1
|
2003-09-02 19:16:48 +02:00
|
|
|
static const uint8_t link_width_to_pow2[]= { 3, 4, 0, 5, 1, 2, 0, 0 };
|
|
|
|
static const uint8_t pow2_to_link_width[] = { 0x7, 4, 5, 0, 1, 3 };
|
|
|
|
unsigned present_width_cap, upstream_width_cap;
|
|
|
|
unsigned present_freq_cap, upstream_freq_cap;
|
|
|
|
unsigned ln_present_width_in, ln_upstream_width_in;
|
|
|
|
unsigned ln_present_width_out, ln_upstream_width_out;
|
|
|
|
unsigned freq, old_freq;
|
|
|
|
unsigned present_width, upstream_width, old_width;
|
2007-10-24 00:17:45 +02:00
|
|
|
#endif
|
|
|
|
struct ht_link cur[1];
|
2003-09-02 19:16:48 +02:00
|
|
|
int reset_needed;
|
2005-01-17 22:37:12 +01:00
|
|
|
int linkb_to_host;
|
2003-09-02 19:16:48 +02:00
|
|
|
|
|
|
|
/* Set the hypertransport link width and frequency */
|
|
|
|
reset_needed = 0;
|
2005-07-08 04:49:49 +02:00
|
|
|
/* See which side of the device our previous write to
|
|
|
|
* set the unitid came from.
|
|
|
|
*/
|
|
|
|
cur->dev = dev;
|
|
|
|
cur->pos = pos;
|
|
|
|
linkb_to_host = (pci_read_config16(cur->dev, cur->pos + PCI_CAP_FLAGS) >> 10) & 1;
|
|
|
|
if (!linkb_to_host) {
|
|
|
|
cur->ctrl_off = PCI_HT_CAP_SLAVE_CTRL0;
|
|
|
|
cur->config_off = PCI_HT_CAP_SLAVE_WIDTH0;
|
|
|
|
cur->freq_off = PCI_HT_CAP_SLAVE_FREQ0;
|
|
|
|
cur->freq_cap_off = PCI_HT_CAP_SLAVE_FREQ_CAP0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
cur->ctrl_off = PCI_HT_CAP_SLAVE_CTRL1;
|
|
|
|
cur->config_off = PCI_HT_CAP_SLAVE_WIDTH1;
|
|
|
|
cur->freq_off = PCI_HT_CAP_SLAVE_FREQ1;
|
|
|
|
cur->freq_cap_off = PCI_HT_CAP_SLAVE_FREQ_CAP1;
|
|
|
|
}
|
|
|
|
#if OPT_HT_LINK == 1
|
2003-09-02 19:16:48 +02:00
|
|
|
/* Read the capabilities */
|
2005-07-08 04:49:49 +02:00
|
|
|
present_freq_cap = ht_read_freq_cap(cur->dev, cur->pos + cur->freq_cap_off);
|
2004-03-11 16:01:31 +01:00
|
|
|
upstream_freq_cap = ht_read_freq_cap(prev->dev, prev->pos + prev->freq_cap_off);
|
2005-07-08 04:49:49 +02:00
|
|
|
present_width_cap = pci_read_config8(cur->dev, cur->pos + cur->config_off);
|
|
|
|
upstream_width_cap = pci_read_config8(prev->dev, prev->pos + prev->config_off);
|
2003-09-02 19:16:48 +02:00
|
|
|
|
|
|
|
/* Calculate the highest useable frequency */
|
|
|
|
freq = log2(present_freq_cap & upstream_freq_cap);
|
|
|
|
|
|
|
|
/* Calculate the highest width */
|
|
|
|
ln_upstream_width_in = link_width_to_pow2[upstream_width_cap & 7];
|
|
|
|
ln_present_width_out = link_width_to_pow2[(present_width_cap >> 4) & 7];
|
|
|
|
if (ln_upstream_width_in > ln_present_width_out) {
|
|
|
|
ln_upstream_width_in = ln_present_width_out;
|
|
|
|
}
|
|
|
|
upstream_width = pow2_to_link_width[ln_upstream_width_in];
|
|
|
|
present_width = pow2_to_link_width[ln_upstream_width_in] << 4;
|
|
|
|
|
|
|
|
ln_upstream_width_out = link_width_to_pow2[(upstream_width_cap >> 4) & 7];
|
|
|
|
ln_present_width_in = link_width_to_pow2[present_width_cap & 7];
|
|
|
|
if (ln_upstream_width_out > ln_present_width_in) {
|
|
|
|
ln_upstream_width_out = ln_present_width_in;
|
|
|
|
}
|
|
|
|
upstream_width |= pow2_to_link_width[ln_upstream_width_out] << 4;
|
|
|
|
present_width |= pow2_to_link_width[ln_upstream_width_out];
|
|
|
|
|
|
|
|
/* Set the current device */
|
2005-07-08 04:49:49 +02:00
|
|
|
old_freq = pci_read_config8(cur->dev, cur->pos + cur->freq_off);
|
|
|
|
old_freq &= 0x0f;
|
2003-09-02 19:16:48 +02:00
|
|
|
if (freq != old_freq) {
|
2005-07-08 04:49:49 +02:00
|
|
|
unsigned new_freq;
|
|
|
|
pci_write_config8(cur->dev, cur->pos + cur->freq_off, freq);
|
2003-09-02 19:16:48 +02:00
|
|
|
reset_needed = 1;
|
|
|
|
printk_spew("HyperT FreqP old %x new %x\n",old_freq,freq);
|
2005-07-08 04:49:49 +02:00
|
|
|
new_freq = pci_read_config8(cur->dev, cur->pos + cur->freq_off);
|
|
|
|
new_freq &= 0x0f;
|
|
|
|
if (new_freq != freq) {
|
|
|
|
printk_err("%s Hypertransport frequency would not set wanted: %x got: %x\n",
|
|
|
|
dev_path(dev), freq, new_freq);
|
|
|
|
}
|
2003-09-02 19:16:48 +02:00
|
|
|
}
|
2005-07-08 04:49:49 +02:00
|
|
|
old_width = pci_read_config8(cur->dev, cur->pos + cur->config_off + 1);
|
2003-09-02 19:16:48 +02:00
|
|
|
if (present_width != old_width) {
|
2005-07-08 04:49:49 +02:00
|
|
|
unsigned new_width;
|
|
|
|
pci_write_config8(cur->dev, cur->pos + cur->config_off + 1,
|
|
|
|
present_width);
|
2003-09-02 19:16:48 +02:00
|
|
|
reset_needed = 1;
|
|
|
|
printk_spew("HyperT widthP old %x new %x\n",old_width, present_width);
|
2005-07-08 04:49:49 +02:00
|
|
|
new_width = pci_read_config8(cur->dev, cur->pos + cur->config_off + 1);
|
|
|
|
if (new_width != present_width) {
|
|
|
|
printk_err("%s Hypertransport width would not set wanted: %x got: %x\n",
|
|
|
|
dev_path(dev), present_width, new_width);
|
|
|
|
}
|
2003-09-02 19:16:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the upstream device */
|
|
|
|
old_freq = pci_read_config8(prev->dev, prev->pos + prev->freq_off);
|
|
|
|
old_freq &= 0x0f;
|
|
|
|
if (freq != old_freq) {
|
2005-07-08 04:49:49 +02:00
|
|
|
unsigned new_freq;
|
2003-09-02 19:16:48 +02:00
|
|
|
pci_write_config8(prev->dev, prev->pos + prev->freq_off, freq);
|
|
|
|
reset_needed = 1;
|
|
|
|
printk_spew("HyperT freqU old %x new %x\n", old_freq, freq);
|
2005-07-08 04:49:49 +02:00
|
|
|
new_freq = pci_read_config8(prev->dev, prev->pos + prev->freq_off);
|
|
|
|
new_freq &= 0x0f;
|
|
|
|
if (new_freq != freq) {
|
|
|
|
printk_err("%s Hypertransport frequency would not set wanted: %x got: %x\n",
|
|
|
|
dev_path(prev->dev), freq, new_freq);
|
|
|
|
}
|
2003-09-02 19:16:48 +02:00
|
|
|
}
|
|
|
|
old_width = pci_read_config8(prev->dev, prev->pos + prev->config_off + 1);
|
|
|
|
if (upstream_width != old_width) {
|
2005-07-08 04:49:49 +02:00
|
|
|
unsigned new_width;
|
2003-09-02 19:16:48 +02:00
|
|
|
pci_write_config8(prev->dev, prev->pos + prev->config_off + 1, upstream_width);
|
|
|
|
reset_needed = 1;
|
|
|
|
printk_spew("HyperT widthU old %x new %x\n", old_width, upstream_width);
|
2005-07-08 04:49:49 +02:00
|
|
|
new_width = pci_read_config8(prev->dev, prev->pos + prev->config_off + 1);
|
|
|
|
if (new_width != upstream_width) {
|
|
|
|
printk_err("%s Hypertransport width would not set wanted: %x got: %x\n",
|
|
|
|
dev_path(prev->dev), upstream_width, new_width);
|
|
|
|
}
|
2003-09-02 19:16:48 +02:00
|
|
|
}
|
2005-07-08 04:49:49 +02:00
|
|
|
#endif
|
2003-09-02 19:16:48 +02:00
|
|
|
|
2005-07-08 04:49:49 +02:00
|
|
|
/* Remember the current link as the previous link,
|
|
|
|
* But look at the other offsets.
|
|
|
|
*/
|
|
|
|
prev->dev = cur->dev;
|
|
|
|
prev->pos = cur->pos;
|
|
|
|
if (cur->ctrl_off == PCI_HT_CAP_SLAVE_CTRL0) {
|
|
|
|
prev->ctrl_off = PCI_HT_CAP_SLAVE_CTRL1;
|
|
|
|
prev->config_off = PCI_HT_CAP_SLAVE_WIDTH1;
|
|
|
|
prev->freq_off = PCI_HT_CAP_SLAVE_FREQ1;
|
|
|
|
prev->freq_cap_off = PCI_HT_CAP_SLAVE_FREQ_CAP1;
|
|
|
|
} else {
|
|
|
|
prev->ctrl_off = PCI_HT_CAP_SLAVE_CTRL0;
|
|
|
|
prev->config_off = PCI_HT_CAP_SLAVE_WIDTH0;
|
|
|
|
prev->freq_off = PCI_HT_CAP_SLAVE_FREQ0;
|
|
|
|
prev->freq_cap_off = PCI_HT_CAP_SLAVE_FREQ_CAP0;
|
|
|
|
}
|
2003-09-02 19:16:48 +02:00
|
|
|
|
|
|
|
return reset_needed;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned ht_lookup_slave_capability(struct device *dev)
|
|
|
|
{
|
|
|
|
unsigned pos;
|
|
|
|
pos = 0;
|
2005-07-08 04:49:49 +02:00
|
|
|
do {
|
|
|
|
pos = pci_find_next_capability(dev, PCI_CAP_ID_HT, pos);
|
|
|
|
if (pos) {
|
2003-09-02 19:16:48 +02:00
|
|
|
unsigned flags;
|
|
|
|
flags = pci_read_config16(dev, pos + PCI_CAP_FLAGS);
|
2005-07-08 04:49:49 +02:00
|
|
|
printk_spew("flags: 0x%04x\n", flags);
|
2003-09-02 19:16:48 +02:00
|
|
|
if ((flags >> 13) == 0) {
|
2005-07-08 04:49:49 +02:00
|
|
|
/* Entry is a Slave secondary, success... */
|
2003-09-02 19:16:48 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2005-07-08 04:49:49 +02:00
|
|
|
} while(pos);
|
2003-09-02 19:16:48 +02:00
|
|
|
return pos;
|
|
|
|
}
|
|
|
|
|
2005-12-02 22:52:30 +01:00
|
|
|
static void ht_collapse_early_enumeration(struct bus *bus, unsigned offset_unitid)
|
2003-09-02 19:16:48 +02:00
|
|
|
{
|
|
|
|
unsigned int devfn;
|
2005-07-08 04:49:49 +02:00
|
|
|
struct ht_link prev;
|
|
|
|
unsigned ctrl;
|
|
|
|
|
|
|
|
/* Initialize the hypertransport enumeration state */
|
|
|
|
prev.dev = bus->dev;
|
|
|
|
prev.pos = bus->cap;
|
|
|
|
prev.ctrl_off = PCI_HT_CAP_HOST_CTRL;
|
|
|
|
prev.config_off = PCI_HT_CAP_HOST_WIDTH;
|
|
|
|
prev.freq_off = PCI_HT_CAP_HOST_FREQ;
|
|
|
|
prev.freq_cap_off = PCI_HT_CAP_HOST_FREQ_CAP;
|
|
|
|
|
|
|
|
/* Wait until the link initialization is complete */
|
|
|
|
do {
|
|
|
|
ctrl = pci_read_config16(prev.dev, prev.pos + prev.ctrl_off);
|
|
|
|
/* Is this the end of the hypertransport chain */
|
|
|
|
if (ctrl & (1 << 6)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* Has the link failed? */
|
|
|
|
if (ctrl & (1 << 4)) {
|
2006-04-11 21:23:57 +02:00
|
|
|
/*
|
|
|
|
* Either the link has failed, or we have
|
|
|
|
* a CRC error.
|
|
|
|
* Sometimes this can happen due to link
|
|
|
|
* retrain, so lets knock it down and see
|
|
|
|
* if its transient
|
|
|
|
*/
|
|
|
|
ctrl |= ((1 << 4) | (1 <<8)); // Link fail + Crc
|
|
|
|
pci_write_config16(prev.dev, prev.pos + prev.ctrl_off, ctrl);
|
|
|
|
ctrl = pci_read_config16(prev.dev, prev.pos + prev.ctrl_off);
|
|
|
|
if (ctrl & ((1 << 4) | (1 << 8))) {
|
|
|
|
printk_alert("Detected error on Hypertransport Link\n");
|
|
|
|
return;
|
|
|
|
}
|
2005-07-08 04:49:49 +02:00
|
|
|
}
|
|
|
|
} while((ctrl & (1 << 5)) == 0);
|
|
|
|
|
2005-12-02 22:52:30 +01:00
|
|
|
//actually, only for one HT device HT chain, and unitid is 0
|
|
|
|
#if HT_CHAIN_UNITID_BASE == 0
|
|
|
|
if(offset_unitid) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Check if is already collapsed */
|
|
|
|
if((!offset_unitid)|| (offset_unitid && (!((HT_CHAIN_END_UNITID_BASE == 0) && (HT_CHAIN_END_UNITID_BASE <HT_CHAIN_UNITID_BASE))))) {
|
|
|
|
struct device dummy;
|
|
|
|
uint32_t id;
|
|
|
|
dummy.bus = bus;
|
|
|
|
dummy.path.type = DEVICE_PATH_PCI;
|
|
|
|
dummy.path.u.pci.devfn = PCI_DEVFN(0, 0);
|
|
|
|
id = pci_read_config32(&dummy, PCI_VENDOR_ID);
|
|
|
|
if ( ! ( (id == 0xffffffff) || (id == 0x00000000) ||
|
|
|
|
(id == 0x0000ffff) || (id == 0xffff0000) ) ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2003-09-02 19:16:48 +02:00
|
|
|
|
|
|
|
/* Spin through the devices and collapse any early
|
|
|
|
* hypertransport enumeration.
|
|
|
|
*/
|
2005-01-17 22:37:12 +01:00
|
|
|
for(devfn = PCI_DEVFN(1, 0); devfn <= 0xff; devfn += 8) {
|
2003-09-02 19:16:48 +02:00
|
|
|
struct device dummy;
|
|
|
|
uint32_t id;
|
|
|
|
unsigned pos, flags;
|
|
|
|
dummy.bus = bus;
|
|
|
|
dummy.path.type = DEVICE_PATH_PCI;
|
|
|
|
dummy.path.u.pci.devfn = devfn;
|
|
|
|
id = pci_read_config32(&dummy, PCI_VENDOR_ID);
|
2005-07-08 04:49:49 +02:00
|
|
|
if ( (id == 0xffffffff) || (id == 0x00000000) ||
|
|
|
|
(id == 0x0000ffff) || (id == 0xffff0000)) {
|
2003-09-02 19:16:48 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
dummy.vendor = id & 0xffff;
|
|
|
|
dummy.device = (id >> 16) & 0xffff;
|
|
|
|
dummy.hdr_type = pci_read_config8(&dummy, PCI_HEADER_TYPE);
|
|
|
|
pos = ht_lookup_slave_capability(&dummy);
|
|
|
|
if (!pos){
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Clear the unitid */
|
|
|
|
flags = pci_read_config16(&dummy, pos + PCI_CAP_FLAGS);
|
|
|
|
flags &= ~0x1f;
|
|
|
|
pci_write_config16(&dummy, pos + PCI_CAP_FLAGS, flags);
|
|
|
|
printk_spew("Collapsing %s [%04x/%04x]\n",
|
|
|
|
dev_path(&dummy), dummy.vendor, dummy.device);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-07-08 04:49:49 +02:00
|
|
|
unsigned int hypertransport_scan_chain(struct bus *bus,
|
2005-12-04 22:52:58 +01:00
|
|
|
unsigned min_devfn, unsigned max_devfn, unsigned int max, unsigned *ht_unitid_base, unsigned offset_unitid)
|
2003-09-02 19:16:48 +02:00
|
|
|
{
|
2005-12-02 22:52:30 +01:00
|
|
|
//even HT_CHAIN_UNITID_BASE == 0, we still can go through this function, because of end_of_chain check, also We need it to optimize link
|
2005-07-08 04:49:49 +02:00
|
|
|
unsigned next_unitid, last_unitid;
|
|
|
|
device_t old_devices, dev, func;
|
2005-12-02 22:52:30 +01:00
|
|
|
unsigned min_unitid = (offset_unitid) ? HT_CHAIN_UNITID_BASE:1;
|
2005-07-08 04:49:49 +02:00
|
|
|
struct ht_link prev;
|
2005-12-02 22:52:30 +01:00
|
|
|
device_t last_func = 0;
|
2005-12-04 22:52:58 +01:00
|
|
|
int ht_dev_num = 0;
|
2007-09-14 16:58:33 +02:00
|
|
|
unsigned max_unitid;
|
2005-12-02 22:52:30 +01:00
|
|
|
|
2007-09-14 16:58:33 +02:00
|
|
|
#if HT_CHAIN_END_UNITID_BASE != 0x20
|
2005-12-02 22:52:30 +01:00
|
|
|
//let't record the device of last ht device, So we can set the Unitid to HT_CHAIN_END_UNITID_BASE
|
|
|
|
unsigned real_last_unitid;
|
|
|
|
uint8_t real_last_pos;
|
|
|
|
device_t real_last_dev;
|
2007-09-14 16:58:33 +02:00
|
|
|
unsigned end_used = 0;
|
2005-12-02 22:52:30 +01:00
|
|
|
#endif
|
2003-09-02 19:16:48 +02:00
|
|
|
|
|
|
|
/* Restore the hypertransport chain to it's unitialized state */
|
2005-12-02 22:52:30 +01:00
|
|
|
ht_collapse_early_enumeration(bus, offset_unitid);
|
2003-09-02 19:16:48 +02:00
|
|
|
|
|
|
|
/* See which static device nodes I have */
|
|
|
|
old_devices = bus->children;
|
|
|
|
bus->children = 0;
|
|
|
|
|
|
|
|
/* Initialize the hypertransport enumeration state */
|
|
|
|
prev.dev = bus->dev;
|
|
|
|
prev.pos = bus->cap;
|
2005-07-08 04:49:49 +02:00
|
|
|
prev.ctrl_off = PCI_HT_CAP_HOST_CTRL;
|
2003-09-02 19:16:48 +02:00
|
|
|
prev.config_off = PCI_HT_CAP_HOST_WIDTH;
|
|
|
|
prev.freq_off = PCI_HT_CAP_HOST_FREQ;
|
|
|
|
prev.freq_cap_off = PCI_HT_CAP_HOST_FREQ_CAP;
|
|
|
|
|
|
|
|
/* If present assign unitid to a hypertransport chain */
|
|
|
|
last_unitid = min_unitid -1;
|
2007-09-14 16:58:33 +02:00
|
|
|
max_unitid = next_unitid = min_unitid;
|
2003-09-02 19:16:48 +02:00
|
|
|
do {
|
2005-07-08 04:49:49 +02:00
|
|
|
uint8_t pos;
|
2003-09-02 19:16:48 +02:00
|
|
|
uint16_t flags;
|
|
|
|
unsigned count, static_count;
|
2005-07-08 04:49:49 +02:00
|
|
|
unsigned ctrl;
|
2003-09-02 19:16:48 +02:00
|
|
|
|
|
|
|
last_unitid = next_unitid;
|
|
|
|
|
2005-07-08 04:49:49 +02:00
|
|
|
/* Wait until the link initialization is complete */
|
|
|
|
do {
|
|
|
|
ctrl = pci_read_config16(prev.dev, prev.pos + prev.ctrl_off);
|
2006-04-11 21:23:57 +02:00
|
|
|
|
|
|
|
if (ctrl & (1 << 6))
|
|
|
|
goto end_of_chain; // End of chain
|
|
|
|
|
|
|
|
if (ctrl & ((1 << 4) | (1 << 8))) {
|
|
|
|
/*
|
|
|
|
* Either the link has failed, or we have
|
|
|
|
* a CRC error.
|
|
|
|
* Sometimes this can happen due to link
|
|
|
|
* retrain, so lets knock it down and see
|
|
|
|
* if its transient
|
|
|
|
*/
|
|
|
|
ctrl |= ((1 << 4) | (1 <<8)); // Link fail + Crc
|
|
|
|
pci_write_config16(prev.dev, prev.pos + prev.ctrl_off, ctrl);
|
|
|
|
ctrl = pci_read_config16(prev.dev, prev.pos + prev.ctrl_off);
|
|
|
|
if (ctrl & ((1 << 4) | (1 << 8))) {
|
|
|
|
printk_alert("Detected error on Hypertransport Link\n");
|
|
|
|
goto end_of_chain;
|
|
|
|
}
|
2005-07-08 04:49:49 +02:00
|
|
|
}
|
|
|
|
} while((ctrl & (1 << 5)) == 0);
|
|
|
|
|
|
|
|
|
|
|
|
/* Get and setup the device_structure */
|
2003-09-02 19:16:48 +02:00
|
|
|
dev = ht_scan_get_devs(&old_devices);
|
|
|
|
|
2005-07-08 04:49:49 +02:00
|
|
|
/* See if a device is present and setup the
|
|
|
|
* device structure.
|
|
|
|
*/
|
|
|
|
dev = pci_probe_dev(dev, bus, 0);
|
|
|
|
if (!dev || !dev->enabled) {
|
|
|
|
break;
|
2003-09-02 19:16:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Find the hypertransport link capability */
|
|
|
|
pos = ht_lookup_slave_capability(dev);
|
|
|
|
if (pos == 0) {
|
2003-10-11 08:20:25 +02:00
|
|
|
printk_err("%s Hypertransport link capability not found",
|
|
|
|
dev_path(dev));
|
2003-09-02 19:16:48 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Update the Unitid of the current device */
|
|
|
|
flags = pci_read_config16(dev, pos + PCI_CAP_FLAGS);
|
2005-07-08 04:49:49 +02:00
|
|
|
|
|
|
|
/* If the devices has a unitid set and is at devfn 0 we are done.
|
|
|
|
* This can happen with shadow hypertransport devices,
|
|
|
|
* or if we have reached the bottom of a
|
|
|
|
* hypertransport device chain.
|
|
|
|
*/
|
|
|
|
if (flags & 0x1f) {
|
|
|
|
break;
|
|
|
|
}
|
2003-09-02 19:16:48 +02:00
|
|
|
flags &= ~0x1f; /* mask out base Unit ID */
|
2007-05-21 20:11:17 +02:00
|
|
|
|
|
|
|
count = (flags >> 5) & 0x1f; /* get unit count */
|
2007-09-14 16:58:33 +02:00
|
|
|
#if HT_CHAIN_END_UNITID_BASE != 0x20
|
2007-05-21 20:11:17 +02:00
|
|
|
if(offset_unitid) {
|
2007-09-14 16:58:33 +02:00
|
|
|
if(next_unitid > (max_devfn>>3)) { // max_devfn will be (0x17<<3)|7 or (0x1f<<3)|7
|
|
|
|
if(!end_used) {
|
|
|
|
next_unitid = HT_CHAIN_END_UNITID_BASE;
|
|
|
|
end_used = 1;
|
|
|
|
} else {
|
2007-10-24 00:17:45 +02:00
|
|
|
goto end_of_chain;
|
2007-09-14 16:58:33 +02:00
|
|
|
}
|
2007-05-21 20:11:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-09-14 16:58:33 +02:00
|
|
|
flags |= next_unitid & 0x1f;
|
2006-10-04 22:46:15 +02:00
|
|
|
pci_write_config16(dev, pos + PCI_CAP_FLAGS, flags);
|
2003-09-02 19:16:48 +02:00
|
|
|
|
|
|
|
/* Update the Unitd id in the device structure */
|
|
|
|
static_count = 1;
|
|
|
|
for(func = dev; func; func = func->sibling) {
|
2007-09-14 16:58:33 +02:00
|
|
|
func->path.u.pci.devfn += (next_unitid << 3);
|
2003-09-02 19:16:48 +02:00
|
|
|
static_count = (func->path.u.pci.devfn >> 3)
|
|
|
|
- (dev->path.u.pci.devfn >> 3) + 1;
|
2005-12-02 22:52:30 +01:00
|
|
|
last_func = func;
|
2003-09-02 19:16:48 +02:00
|
|
|
}
|
|
|
|
/* Compute the number of unitids consumed */
|
|
|
|
printk_spew("%s count: %04x static_count: %04x\n",
|
|
|
|
dev_path(dev), count, static_count);
|
|
|
|
if (count < static_count) {
|
|
|
|
count = static_count;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Update the Unitid of the next device */
|
2007-09-14 16:58:33 +02:00
|
|
|
ht_unitid_base[ht_dev_num] = next_unitid;
|
2005-12-04 22:52:58 +01:00
|
|
|
ht_dev_num++;
|
2007-05-21 20:11:17 +02:00
|
|
|
|
2007-09-14 16:58:33 +02:00
|
|
|
#if HT_CHAIN_END_UNITID_BASE != 0x20
|
|
|
|
if (offset_unitid) {
|
2005-12-02 22:52:30 +01:00
|
|
|
real_last_pos = pos;
|
2007-09-14 16:58:33 +02:00
|
|
|
real_last_unitid = next_unitid;
|
2005-12-02 22:52:30 +01:00
|
|
|
real_last_dev = dev;
|
|
|
|
}
|
|
|
|
#endif
|
2007-09-14 16:58:33 +02:00
|
|
|
next_unitid += count;
|
|
|
|
if (next_unitid > max_unitid) {
|
|
|
|
max_unitid = next_unitid;
|
|
|
|
}
|
2003-09-02 19:16:48 +02:00
|
|
|
|
|
|
|
/* Setup the hypetransport link */
|
2005-07-08 04:49:49 +02:00
|
|
|
bus->reset_needed |= ht_setup_link(&prev, dev, pos);
|
2003-09-02 19:16:48 +02:00
|
|
|
|
|
|
|
printk_debug("%s [%04x/%04x] %s next_unitid: %04x\n",
|
|
|
|
dev_path(dev),
|
|
|
|
dev->vendor, dev->device,
|
2004-04-29 22:08:54 +02:00
|
|
|
(dev->enabled? "enabled": "disabled"), next_unitid);
|
2005-07-08 04:49:49 +02:00
|
|
|
|
2007-09-14 16:58:33 +02:00
|
|
|
} while (last_unitid != next_unitid);
|
2005-07-08 04:49:49 +02:00
|
|
|
end_of_chain:
|
2005-01-26 23:00:20 +01:00
|
|
|
#if OPT_HT_LINK == 1
|
2005-07-08 04:49:49 +02:00
|
|
|
if(bus->reset_needed) {
|
2003-09-02 19:16:48 +02:00
|
|
|
printk_info("HyperT reset needed\n");
|
2004-03-11 16:01:31 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
printk_debug("HyperT reset not needed\n");
|
|
|
|
}
|
2003-09-02 19:16:48 +02:00
|
|
|
#endif
|
2005-12-02 22:52:30 +01:00
|
|
|
|
2007-09-14 16:58:33 +02:00
|
|
|
#if HT_CHAIN_END_UNITID_BASE != 0x20
|
|
|
|
if(offset_unitid && (ht_dev_num>1) && (real_last_unitid != HT_CHAIN_END_UNITID_BASE) && !end_used) {
|
2005-12-02 22:52:30 +01:00
|
|
|
uint16_t flags;
|
|
|
|
int i;
|
|
|
|
device_t last_func = 0;
|
|
|
|
flags = pci_read_config16(real_last_dev, real_last_pos + PCI_CAP_FLAGS);
|
|
|
|
flags &= ~0x1f;
|
|
|
|
flags |= HT_CHAIN_END_UNITID_BASE & 0x1f;
|
|
|
|
pci_write_config16(real_last_dev, real_last_pos + PCI_CAP_FLAGS, flags);
|
|
|
|
|
|
|
|
for(func = real_last_dev; func; func = func->sibling) {
|
|
|
|
func->path.u.pci.devfn -= ((real_last_unitid - HT_CHAIN_END_UNITID_BASE) << 3);
|
|
|
|
last_func = func;
|
|
|
|
}
|
2007-05-21 20:11:17 +02:00
|
|
|
|
2005-12-04 22:52:58 +01:00
|
|
|
ht_unitid_base[ht_dev_num-1] = HT_CHAIN_END_UNITID_BASE; // update last one
|
|
|
|
|
2007-09-14 16:58:33 +02:00
|
|
|
printk_debug(" unitid: %04x --> %04x\n",
|
|
|
|
real_last_unitid, HT_CHAIN_END_UNITID_BASE);
|
|
|
|
|
2005-12-02 22:52:30 +01:00
|
|
|
}
|
|
|
|
#endif
|
2007-09-14 16:58:33 +02:00
|
|
|
next_unitid = max_unitid;
|
2005-12-02 22:52:30 +01:00
|
|
|
|
2007-09-14 16:58:33 +02:00
|
|
|
if (next_unitid > 0x20) {
|
|
|
|
next_unitid = 0x20;
|
2003-09-02 19:16:48 +02:00
|
|
|
}
|
2007-09-14 16:58:33 +02:00
|
|
|
if( (bus->secondary == 0) && (next_unitid > 0x18)) {
|
|
|
|
next_unitid = 0x18; /* avoid K8 on bus 0 */
|
2007-05-21 20:11:17 +02:00
|
|
|
}
|
2005-07-08 04:49:49 +02:00
|
|
|
|
|
|
|
/* Die if any leftover Static devices are are found.
|
|
|
|
* There's probably a problem in the Config.lb.
|
|
|
|
*/
|
|
|
|
if(old_devices) {
|
|
|
|
device_t left;
|
|
|
|
for(left = old_devices; left; left = left->sibling) {
|
|
|
|
printk_debug("%s\n", dev_path(left));
|
|
|
|
}
|
2005-12-02 22:52:30 +01:00
|
|
|
printk_err("HT: Left over static devices. Check your Config.lb\n");
|
|
|
|
if(last_func && !last_func->sibling) // put back the left over static device, and let pci_scan_bus disable it
|
|
|
|
last_func->sibling = old_devices;
|
2005-07-08 04:49:49 +02:00
|
|
|
}
|
2005-12-02 22:52:30 +01:00
|
|
|
|
2005-07-08 04:49:49 +02:00
|
|
|
/* Now that nothing is overlapping it is safe to scan the
|
|
|
|
* children.
|
|
|
|
*/
|
2007-05-21 20:11:17 +02:00
|
|
|
max = pci_scan_bus(bus, 0x00, ((next_unitid-1) << 3)|7, max);
|
2005-07-08 04:49:49 +02:00
|
|
|
return max;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Scan a PCI bridge and the buses behind the bridge.
|
|
|
|
*
|
|
|
|
* Determine the existence of buses behind the bridge. Set up the bridge
|
|
|
|
* according to the result of the scan.
|
|
|
|
*
|
|
|
|
* This function is the default scan_bus() method for PCI bridge devices.
|
|
|
|
*
|
|
|
|
* @param dev pointer to the bridge device
|
|
|
|
* @param max the highest bus number assgined up to now
|
|
|
|
*
|
|
|
|
* @return The maximum bus number found, after scanning all subordinate busses
|
|
|
|
*/
|
2006-10-04 22:46:15 +02:00
|
|
|
unsigned int hypertransport_scan_chain_x(struct bus *bus,
|
|
|
|
unsigned min_devfn, unsigned max_devfn, unsigned int max)
|
|
|
|
{
|
|
|
|
unsigned ht_unitid_base[4];
|
|
|
|
unsigned offset_unitid = 1;
|
|
|
|
return hypertransport_scan_chain(bus, min_devfn, max_devfn, max, ht_unitid_base, offset_unitid);
|
|
|
|
}
|
|
|
|
|
2005-07-08 04:49:49 +02:00
|
|
|
unsigned int ht_scan_bridge(struct device *dev, unsigned int max)
|
|
|
|
{
|
2006-10-04 22:46:15 +02:00
|
|
|
return do_pci_scan_bridge(dev, max, hypertransport_scan_chain_x);
|
2003-09-02 19:16:48 +02:00
|
|
|
}
|
2005-07-08 04:49:49 +02:00
|
|
|
|
|
|
|
|
|
|
|
/** Default device operations for hypertransport bridges */
|
|
|
|
static struct pci_operations ht_bus_ops_pci = {
|
|
|
|
.set_subsystem = 0,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct device_operations default_ht_ops_bus = {
|
|
|
|
.read_resources = pci_bus_read_resources,
|
|
|
|
.set_resources = pci_dev_set_resources,
|
|
|
|
.enable_resources = pci_bus_enable_resources,
|
|
|
|
.init = 0,
|
|
|
|
.scan_bus = ht_scan_bridge,
|
|
|
|
.enable = 0,
|
|
|
|
.reset_bus = pci_bus_reset,
|
|
|
|
.ops_pci = &ht_bus_ops_pci,
|
|
|
|
};
|