Uwe Hermann | b80dbf0 | 2007-04-22 19:08:13 +0000 | [diff] [blame] | 1 | /* |
Stefan Reinauer | 7e61e45 | 2008-01-18 10:35:56 +0000 | [diff] [blame] | 2 | * This file is part of the coreboot project. |
Uwe Hermann | b80dbf0 | 2007-04-22 19:08:13 +0000 | [diff] [blame] | 3 | * |
| 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 |
| 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 19 | */ |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 20 | |
| 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 | |
| 27 | |
| 28 | static void pcix_tune_dev(device_t dev) |
| 29 | { |
| 30 | unsigned cap; |
| 31 | unsigned status, orig_cmd, cmd; |
| 32 | unsigned max_read, max_tran; |
| 33 | |
| 34 | if (dev->hdr_type != PCI_HEADER_TYPE_NORMAL) { |
| 35 | return; |
| 36 | } |
| 37 | cap = pci_find_capability(dev, PCI_CAP_ID_PCIX); |
| 38 | if (!cap) { |
| 39 | return; |
| 40 | } |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 41 | printk(BIOS_DEBUG, "%s PCI-X tuning\n", dev_path(dev)); |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 42 | status = pci_read_config32(dev, cap + PCI_X_STATUS); |
| 43 | orig_cmd = cmd = pci_read_config16(dev,cap + PCI_X_CMD); |
| 44 | |
| 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 | } |
| 55 | /* Don't attempt to handle PCI-X errors */ |
| 56 | cmd &= ~PCI_X_CMD_DPERR_E; |
| 57 | /* Enable Relaxed Ordering */ |
| 58 | cmd |= PCI_X_CMD_ERO; |
| 59 | if (orig_cmd != cmd) { |
| 60 | pci_write_config16(dev, cap + PCI_X_CMD, cmd); |
| 61 | } |
| 62 | } |
| 63 | |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 64 | static void pcix_tune_bus(struct bus *bus) |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 65 | { |
| 66 | device_t child; |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 67 | for(child = bus->children; child; child = child->sibling) |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 68 | pcix_tune_dev(child); |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | const char *pcix_speed(unsigned sstatus) |
| 72 | { |
| 73 | static const char conventional[] = "Conventional PCI"; |
| 74 | static const char pcix_66mhz[] = "66MHz PCI-X"; |
| 75 | static const char pcix_100mhz[] = "100MHz PCI-X"; |
| 76 | static const char pcix_133mhz[] = "133MHz PCI-X"; |
| 77 | static const char pcix_266mhz[] = "266MHz PCI-X"; |
| 78 | static const char pcix_533mhz[] = "533MHZ PCI-X"; |
| 79 | static const char unknown[] = "Unknown"; |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 80 | |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 81 | const char *result; |
| 82 | result = unknown; |
| 83 | switch(PCI_X_SSTATUS_MFREQ(sstatus)) { |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 84 | case PCI_X_SSTATUS_CONVENTIONAL_PCI: |
| 85 | result = conventional; |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 86 | break; |
| 87 | case PCI_X_SSTATUS_MODE1_66MHZ: |
| 88 | result = pcix_66mhz; |
| 89 | break; |
| 90 | case PCI_X_SSTATUS_MODE1_100MHZ: |
| 91 | result = pcix_100mhz; |
| 92 | break; |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 93 | |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 94 | case PCI_X_SSTATUS_MODE1_133MHZ: |
| 95 | result = pcix_133mhz; |
| 96 | break; |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 97 | |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 98 | case PCI_X_SSTATUS_MODE2_266MHZ_REF_66MHZ: |
| 99 | case PCI_X_SSTATUS_MODE2_266MHZ_REF_100MHZ: |
| 100 | case PCI_X_SSTATUS_MODE2_266MHZ_REF_133MHZ: |
| 101 | result = pcix_266mhz; |
| 102 | break; |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 103 | |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 104 | case PCI_X_SSTATUS_MODE2_533MHZ_REF_66MHZ: |
| 105 | case PCI_X_SSTATUS_MODE2_533MHZ_REF_100MHZ: |
| 106 | case PCI_X_SSTATUS_MODE2_533MHZ_REF_133MHZ: |
| 107 | result = pcix_533mhz; |
| 108 | break; |
| 109 | } |
| 110 | return result; |
| 111 | } |
| 112 | |
| 113 | unsigned int pcix_scan_bridge(device_t dev, unsigned int max) |
| 114 | { |
| 115 | unsigned pos; |
| 116 | unsigned sstatus; |
| 117 | |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 118 | max = do_pci_scan_bridge(dev, max, pci_scan_bus); |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 119 | /* Find the PCI-X capability */ |
| 120 | pos = pci_find_capability(dev, PCI_CAP_ID_PCIX); |
| 121 | sstatus = pci_read_config16(dev, pos + PCI_X_SEC_STATUS); |
| 122 | |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 123 | if (PCI_X_SSTATUS_MFREQ(sstatus) != PCI_X_SSTATUS_CONVENTIONAL_PCI) { |
| 124 | pcix_tune_bus(dev->link_list); |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | /* Print the PCI-X bus speed */ |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 128 | printk(BIOS_DEBUG, "PCI: %02x: %s\n", dev->link_list->secondary, pcix_speed(sstatus)); |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 129 | |
| 130 | return max; |
| 131 | } |
| 132 | |
| 133 | |
| 134 | /** Default device operations for PCI-X bridges */ |
| 135 | static struct pci_operations pcix_bus_ops_pci = { |
| 136 | .set_subsystem = 0, |
| 137 | }; |
| 138 | |
| 139 | struct device_operations default_pcix_ops_bus = { |
| 140 | .read_resources = pci_bus_read_resources, |
| 141 | .set_resources = pci_dev_set_resources, |
| 142 | .enable_resources = pci_bus_enable_resources, |
| 143 | .init = 0, |
| 144 | .scan_bus = pcix_scan_bridge, |
| 145 | .enable = 0, |
| 146 | .reset_bus = pci_bus_reset, |
| 147 | .ops_pci = &pcix_bus_ops_pci, |
| 148 | }; |