blob: a20c3bff531f6c0beb72e3f7027aa2634bd3d598 [file] [log] [blame]
Uwe Hermannb80dbf02007-04-22 19:08:13 +00001/*
Stefan Reinauer7e61e452008-01-18 10:35:56 +00002 * This file is part of the coreboot project.
Uwe Hermannb80dbf02007-04-22 19:08:13 +00003 *
4 * Copyright (C) 2005 Linux Networx
5 * (Written by Eric Biederman <ebiederman@lnxi.com> for Linux Networx)
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
Paul Menzela46a7122013-02-23 18:37:27 +010018 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Uwe Hermannb80dbf02007-04-22 19:08:13 +000019 */
Yinghai Lu13f1c2a2005-07-08 02:49:49 +000020
21#include <console/console.h>
22#include <device/device.h>
23#include <device/pci.h>
24#include <device/pci_ids.h>
25#include <device/pcix.h>
26
Yinghai Lu13f1c2a2005-07-08 02:49:49 +000027static void pcix_tune_dev(device_t dev)
28{
Uwe Hermannd453dd02010-10-18 00:00:57 +000029 u32 status;
30 u16 orig_cmd, cmd;
31 unsigned int cap, max_read, max_tran;
Yinghai Lu13f1c2a2005-07-08 02:49:49 +000032
Uwe Hermannd453dd02010-10-18 00:00:57 +000033 if (dev->hdr_type != PCI_HEADER_TYPE_NORMAL)
Yinghai Lu13f1c2a2005-07-08 02:49:49 +000034 return;
Uwe Hermannd453dd02010-10-18 00:00:57 +000035
Yinghai Lu13f1c2a2005-07-08 02:49:49 +000036 cap = pci_find_capability(dev, PCI_CAP_ID_PCIX);
Uwe Hermannd453dd02010-10-18 00:00:57 +000037 if (!cap)
Yinghai Lu13f1c2a2005-07-08 02:49:49 +000038 return;
Uwe Hermannd453dd02010-10-18 00:00:57 +000039
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000040 printk(BIOS_DEBUG, "%s PCI-X tuning\n", dev_path(dev));
Uwe Hermannd453dd02010-10-18 00:00:57 +000041
Yinghai Lu13f1c2a2005-07-08 02:49:49 +000042 status = pci_read_config32(dev, cap + PCI_X_STATUS);
Uwe Hermannd453dd02010-10-18 00:00:57 +000043 orig_cmd = cmd = pci_read_config16(dev, cap + PCI_X_CMD);
Yinghai Lu13f1c2a2005-07-08 02:49:49 +000044
45 max_read = (status & PCI_X_STATUS_MAX_READ) >> 21;
46 max_tran = (status & PCI_X_STATUS_MAX_SPLIT) >> 23;
47 if (max_read != ((cmd & PCI_X_CMD_MAX_READ) >> 2)) {
48 cmd &= ~PCI_X_CMD_MAX_READ;
49 cmd |= max_read << 2;
50 }
51 if (max_tran != ((cmd & PCI_X_CMD_MAX_SPLIT) >> 4)) {
52 cmd &= ~PCI_X_CMD_MAX_SPLIT;
53 cmd |= max_tran << 4;
54 }
Uwe Hermannd453dd02010-10-18 00:00:57 +000055
56 /* Don't attempt to handle PCI-X errors. */
Yinghai Lu13f1c2a2005-07-08 02:49:49 +000057 cmd &= ~PCI_X_CMD_DPERR_E;
Uwe Hermannd453dd02010-10-18 00:00:57 +000058
Uwe Hermanne4870472010-11-04 23:23:47 +000059 /* Enable relaxed ordering. */
Yinghai Lu13f1c2a2005-07-08 02:49:49 +000060 cmd |= PCI_X_CMD_ERO;
Uwe Hermannd453dd02010-10-18 00:00:57 +000061
62 if (orig_cmd != cmd)
Yinghai Lu13f1c2a2005-07-08 02:49:49 +000063 pci_write_config16(dev, cap + PCI_X_CMD, cmd);
Yinghai Lu13f1c2a2005-07-08 02:49:49 +000064}
65
Myles Watson894a3472010-06-09 22:41:35 +000066static void pcix_tune_bus(struct bus *bus)
Yinghai Lu13f1c2a2005-07-08 02:49:49 +000067{
68 device_t child;
Uwe Hermannd453dd02010-10-18 00:00:57 +000069
70 for (child = bus->children; child; child = child->sibling)
Yinghai Lu13f1c2a2005-07-08 02:49:49 +000071 pcix_tune_dev(child);
Yinghai Lu13f1c2a2005-07-08 02:49:49 +000072}
73
Uwe Hermannd453dd02010-10-18 00:00:57 +000074const char *pcix_speed(u16 sstatus)
Yinghai Lu13f1c2a2005-07-08 02:49:49 +000075{
76 static const char conventional[] = "Conventional PCI";
77 static const char pcix_66mhz[] = "66MHz PCI-X";
78 static const char pcix_100mhz[] = "100MHz PCI-X";
79 static const char pcix_133mhz[] = "133MHz PCI-X";
80 static const char pcix_266mhz[] = "266MHz PCI-X";
81 static const char pcix_533mhz[] = "533MHZ PCI-X";
82 static const char unknown[] = "Unknown";
Yinghai Lu13f1c2a2005-07-08 02:49:49 +000083 const char *result;
Uwe Hermannd453dd02010-10-18 00:00:57 +000084
Yinghai Lu13f1c2a2005-07-08 02:49:49 +000085 result = unknown;
Uwe Hermannd453dd02010-10-18 00:00:57 +000086
87 switch (PCI_X_SSTATUS_MFREQ(sstatus)) {
Stefan Reinauer14e22772010-04-27 06:56:47 +000088 case PCI_X_SSTATUS_CONVENTIONAL_PCI:
89 result = conventional;
Yinghai Lu13f1c2a2005-07-08 02:49:49 +000090 break;
91 case PCI_X_SSTATUS_MODE1_66MHZ:
92 result = pcix_66mhz;
93 break;
94 case PCI_X_SSTATUS_MODE1_100MHZ:
95 result = pcix_100mhz;
96 break;
Yinghai Lu13f1c2a2005-07-08 02:49:49 +000097 case PCI_X_SSTATUS_MODE1_133MHZ:
98 result = pcix_133mhz;
99 break;
Yinghai Lu13f1c2a2005-07-08 02:49:49 +0000100 case PCI_X_SSTATUS_MODE2_266MHZ_REF_66MHZ:
101 case PCI_X_SSTATUS_MODE2_266MHZ_REF_100MHZ:
102 case PCI_X_SSTATUS_MODE2_266MHZ_REF_133MHZ:
103 result = pcix_266mhz;
104 break;
Yinghai Lu13f1c2a2005-07-08 02:49:49 +0000105 case PCI_X_SSTATUS_MODE2_533MHZ_REF_66MHZ:
106 case PCI_X_SSTATUS_MODE2_533MHZ_REF_100MHZ:
107 case PCI_X_SSTATUS_MODE2_533MHZ_REF_133MHZ:
108 result = pcix_533mhz;
109 break;
110 }
Uwe Hermanne4870472010-11-04 23:23:47 +0000111
Yinghai Lu13f1c2a2005-07-08 02:49:49 +0000112 return result;
113}
114
115unsigned int pcix_scan_bridge(device_t dev, unsigned int max)
116{
Uwe Hermannd453dd02010-10-18 00:00:57 +0000117 unsigned int pos;
118 u16 sstatus;
Yinghai Lu13f1c2a2005-07-08 02:49:49 +0000119
Myles Watson894a3472010-06-09 22:41:35 +0000120 max = do_pci_scan_bridge(dev, max, pci_scan_bus);
Uwe Hermannd453dd02010-10-18 00:00:57 +0000121
122 /* Find the PCI-X capability. */
Yinghai Lu13f1c2a2005-07-08 02:49:49 +0000123 pos = pci_find_capability(dev, PCI_CAP_ID_PCIX);
124 sstatus = pci_read_config16(dev, pos + PCI_X_SEC_STATUS);
125
Uwe Hermannd453dd02010-10-18 00:00:57 +0000126 if (PCI_X_SSTATUS_MFREQ(sstatus) != PCI_X_SSTATUS_CONVENTIONAL_PCI)
Myles Watson894a3472010-06-09 22:41:35 +0000127 pcix_tune_bus(dev->link_list);
Yinghai Lu13f1c2a2005-07-08 02:49:49 +0000128
Uwe Hermannd453dd02010-10-18 00:00:57 +0000129 /* Print the PCI-X bus speed. */
130 printk(BIOS_DEBUG, "PCI: %02x: %s\n", dev->link_list->secondary,
131 pcix_speed(sstatus));
Yinghai Lu13f1c2a2005-07-08 02:49:49 +0000132
133 return max;
134}
135
Yinghai Lu13f1c2a2005-07-08 02:49:49 +0000136/** Default device operations for PCI-X bridges */
137static struct pci_operations pcix_bus_ops_pci = {
138 .set_subsystem = 0,
139};
140
141struct device_operations default_pcix_ops_bus = {
142 .read_resources = pci_bus_read_resources,
143 .set_resources = pci_dev_set_resources,
144 .enable_resources = pci_bus_enable_resources,
Uwe Hermannd453dd02010-10-18 00:00:57 +0000145 .init = 0,
146 .scan_bus = pcix_scan_bridge,
Yinghai Lu13f1c2a2005-07-08 02:49:49 +0000147 .enable = 0,
148 .reset_bus = pci_bus_reset,
149 .ops_pci = &pcix_bus_ops_pci,
150};