2007-04-22 21:08:13 +02:00
|
|
|
/*
|
2008-01-18 11:35:56 +01:00
|
|
|
* This file is part of the coreboot project.
|
2007-04-22 21:08:13 +02:00
|
|
|
*
|
|
|
|
* Copyright (C) 2005 Linux Networx
|
|
|
|
* (Written by Eric Biederman <ebiederman@lnxi.com> for Linux Networx)
|
|
|
|
*
|
|
|
|
* 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-07-08 04:49:49 +02:00
|
|
|
|
|
|
|
#include <console/console.h>
|
|
|
|
#include <device/device.h>
|
|
|
|
#include <device/pci.h>
|
|
|
|
#include <device/pci_ids.h>
|
|
|
|
#include <device/pcix.h>
|
|
|
|
|
|
|
|
static void pcix_tune_dev(device_t dev)
|
|
|
|
{
|
2010-10-18 02:00:57 +02:00
|
|
|
u32 status;
|
|
|
|
u16 orig_cmd, cmd;
|
|
|
|
unsigned int cap, max_read, max_tran;
|
2005-07-08 04:49:49 +02:00
|
|
|
|
2010-10-18 02:00:57 +02:00
|
|
|
if (dev->hdr_type != PCI_HEADER_TYPE_NORMAL)
|
2005-07-08 04:49:49 +02:00
|
|
|
return;
|
2010-10-18 02:00:57 +02:00
|
|
|
|
2005-07-08 04:49:49 +02:00
|
|
|
cap = pci_find_capability(dev, PCI_CAP_ID_PCIX);
|
2010-10-18 02:00:57 +02:00
|
|
|
if (!cap)
|
2005-07-08 04:49:49 +02:00
|
|
|
return;
|
2010-10-18 02:00:57 +02:00
|
|
|
|
2010-03-22 12:42:32 +01:00
|
|
|
printk(BIOS_DEBUG, "%s PCI-X tuning\n", dev_path(dev));
|
2010-10-18 02:00:57 +02:00
|
|
|
|
2005-07-08 04:49:49 +02:00
|
|
|
status = pci_read_config32(dev, cap + PCI_X_STATUS);
|
2010-10-18 02:00:57 +02:00
|
|
|
orig_cmd = cmd = pci_read_config16(dev, cap + PCI_X_CMD);
|
2005-07-08 04:49:49 +02:00
|
|
|
|
|
|
|
max_read = (status & PCI_X_STATUS_MAX_READ) >> 21;
|
|
|
|
max_tran = (status & PCI_X_STATUS_MAX_SPLIT) >> 23;
|
|
|
|
if (max_read != ((cmd & PCI_X_CMD_MAX_READ) >> 2)) {
|
|
|
|
cmd &= ~PCI_X_CMD_MAX_READ;
|
|
|
|
cmd |= max_read << 2;
|
|
|
|
}
|
|
|
|
if (max_tran != ((cmd & PCI_X_CMD_MAX_SPLIT) >> 4)) {
|
|
|
|
cmd &= ~PCI_X_CMD_MAX_SPLIT;
|
|
|
|
cmd |= max_tran << 4;
|
|
|
|
}
|
2010-10-18 02:00:57 +02:00
|
|
|
|
|
|
|
/* Don't attempt to handle PCI-X errors. */
|
2005-07-08 04:49:49 +02:00
|
|
|
cmd &= ~PCI_X_CMD_DPERR_E;
|
2010-10-18 02:00:57 +02:00
|
|
|
|
2010-11-05 00:23:47 +01:00
|
|
|
/* Enable relaxed ordering. */
|
2005-07-08 04:49:49 +02:00
|
|
|
cmd |= PCI_X_CMD_ERO;
|
2010-10-18 02:00:57 +02:00
|
|
|
|
|
|
|
if (orig_cmd != cmd)
|
2005-07-08 04:49:49 +02:00
|
|
|
pci_write_config16(dev, cap + PCI_X_CMD, cmd);
|
|
|
|
}
|
|
|
|
|
2010-06-10 00:41:35 +02:00
|
|
|
static void pcix_tune_bus(struct bus *bus)
|
2005-07-08 04:49:49 +02:00
|
|
|
{
|
|
|
|
device_t child;
|
2010-10-18 02:00:57 +02:00
|
|
|
|
|
|
|
for (child = bus->children; child; child = child->sibling)
|
2005-07-08 04:49:49 +02:00
|
|
|
pcix_tune_dev(child);
|
|
|
|
}
|
|
|
|
|
2010-10-18 02:00:57 +02:00
|
|
|
const char *pcix_speed(u16 sstatus)
|
2005-07-08 04:49:49 +02:00
|
|
|
{
|
|
|
|
static const char conventional[] = "Conventional PCI";
|
|
|
|
static const char pcix_66mhz[] = "66MHz PCI-X";
|
|
|
|
static const char pcix_100mhz[] = "100MHz PCI-X";
|
|
|
|
static const char pcix_133mhz[] = "133MHz PCI-X";
|
|
|
|
static const char pcix_266mhz[] = "266MHz PCI-X";
|
|
|
|
static const char pcix_533mhz[] = "533MHZ PCI-X";
|
|
|
|
static const char unknown[] = "Unknown";
|
|
|
|
const char *result;
|
2010-10-18 02:00:57 +02:00
|
|
|
|
2005-07-08 04:49:49 +02:00
|
|
|
result = unknown;
|
2010-10-18 02:00:57 +02:00
|
|
|
|
|
|
|
switch (PCI_X_SSTATUS_MFREQ(sstatus)) {
|
2010-04-27 08:56:47 +02:00
|
|
|
case PCI_X_SSTATUS_CONVENTIONAL_PCI:
|
|
|
|
result = conventional;
|
2005-07-08 04:49:49 +02:00
|
|
|
break;
|
|
|
|
case PCI_X_SSTATUS_MODE1_66MHZ:
|
|
|
|
result = pcix_66mhz;
|
|
|
|
break;
|
|
|
|
case PCI_X_SSTATUS_MODE1_100MHZ:
|
|
|
|
result = pcix_100mhz;
|
|
|
|
break;
|
|
|
|
case PCI_X_SSTATUS_MODE1_133MHZ:
|
|
|
|
result = pcix_133mhz;
|
|
|
|
break;
|
|
|
|
case PCI_X_SSTATUS_MODE2_266MHZ_REF_66MHZ:
|
|
|
|
case PCI_X_SSTATUS_MODE2_266MHZ_REF_100MHZ:
|
|
|
|
case PCI_X_SSTATUS_MODE2_266MHZ_REF_133MHZ:
|
|
|
|
result = pcix_266mhz;
|
|
|
|
break;
|
|
|
|
case PCI_X_SSTATUS_MODE2_533MHZ_REF_66MHZ:
|
|
|
|
case PCI_X_SSTATUS_MODE2_533MHZ_REF_100MHZ:
|
|
|
|
case PCI_X_SSTATUS_MODE2_533MHZ_REF_133MHZ:
|
|
|
|
result = pcix_533mhz;
|
|
|
|
break;
|
|
|
|
}
|
2010-11-05 00:23:47 +01:00
|
|
|
|
2005-07-08 04:49:49 +02:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int pcix_scan_bridge(device_t dev, unsigned int max)
|
|
|
|
{
|
2010-10-18 02:00:57 +02:00
|
|
|
unsigned int pos;
|
|
|
|
u16 sstatus;
|
2005-07-08 04:49:49 +02:00
|
|
|
|
2010-06-10 00:41:35 +02:00
|
|
|
max = do_pci_scan_bridge(dev, max, pci_scan_bus);
|
2010-10-18 02:00:57 +02:00
|
|
|
|
|
|
|
/* Find the PCI-X capability. */
|
2005-07-08 04:49:49 +02:00
|
|
|
pos = pci_find_capability(dev, PCI_CAP_ID_PCIX);
|
|
|
|
sstatus = pci_read_config16(dev, pos + PCI_X_SEC_STATUS);
|
|
|
|
|
2010-10-18 02:00:57 +02:00
|
|
|
if (PCI_X_SSTATUS_MFREQ(sstatus) != PCI_X_SSTATUS_CONVENTIONAL_PCI)
|
2010-06-10 00:41:35 +02:00
|
|
|
pcix_tune_bus(dev->link_list);
|
2005-07-08 04:49:49 +02:00
|
|
|
|
2010-10-18 02:00:57 +02:00
|
|
|
/* Print the PCI-X bus speed. */
|
|
|
|
printk(BIOS_DEBUG, "PCI: %02x: %s\n", dev->link_list->secondary,
|
|
|
|
pcix_speed(sstatus));
|
2005-07-08 04:49:49 +02:00
|
|
|
|
|
|
|
return max;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Default device operations for PCI-X bridges */
|
|
|
|
static struct pci_operations pcix_bus_ops_pci = {
|
|
|
|
.set_subsystem = 0,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct device_operations default_pcix_ops_bus = {
|
|
|
|
.read_resources = pci_bus_read_resources,
|
|
|
|
.set_resources = pci_dev_set_resources,
|
|
|
|
.enable_resources = pci_bus_enable_resources,
|
2010-10-18 02:00:57 +02:00
|
|
|
.init = 0,
|
|
|
|
.scan_bus = pcix_scan_bridge,
|
2005-07-08 04:49:49 +02:00
|
|
|
.enable = 0,
|
|
|
|
.reset_bus = pci_bus_reset,
|
|
|
|
.ops_pci = &pcix_bus_ops_pci,
|
|
|
|
};
|