Stefan Reinauer | 7ce8c54 | 2005-12-02 21:52:30 +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) 2003-2004 Linux Networx |
| 5 | * (Written by Eric Biederman <ebiederman@lnxi.com> for Linux Networx) |
| 6 | * Copyright (C) 2004 David Hendricks <sc@flagen.com> |
| 7 | * Copyright (C) 2004 Li-Ta Lo <ollie@lanl.gov> |
| 8 | * Copyright (C) 2005-2006 Tyan |
| 9 | * (Written by Yinghai Lu <yhlu@tyan.com> for Tyan) |
| 10 | * Copyright (C) 2005-2006 Stefan Reinauer <stepan@openbios.org> |
| 11 | * |
| 12 | * This program is free software; you can redistribute it and/or modify |
| 13 | * it under the terms of the GNU General Public License as published by |
| 14 | * the Free Software Foundation; version 2 of the License. |
| 15 | * |
| 16 | * This program is distributed in the hope that it will be useful, |
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | * GNU General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU General Public License |
| 22 | * along with this program; if not, write to the Free Software |
Paul Menzel | a46a712 | 2013-02-23 18:37:27 +0100 | [diff] [blame] | 23 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
Uwe Hermann | b80dbf0 | 2007-04-22 19:08:13 +0000 | [diff] [blame] | 24 | */ |
Stefan Reinauer | 7ce8c54 | 2005-12-02 21:52:30 +0000 | [diff] [blame] | 25 | |
Ronald G. Minnich | 5079a0d | 2012-11-27 11:32:38 -0800 | [diff] [blame] | 26 | #include <lib.h> |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 27 | #include <console/console.h> |
| 28 | #include <device/device.h> |
| 29 | #include <device/path.h> |
| 30 | #include <device/pci.h> |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 31 | #include <device/pci_ids.h> |
Eric Biederman | ff0e846 | 2003-09-04 03:00:54 +0000 | [diff] [blame] | 32 | #include <device/hypertransport.h> |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 33 | |
Uwe Hermann | c1ee429 | 2010-10-17 19:01:48 +0000 | [diff] [blame] | 34 | /* |
| 35 | * The hypertransport link is already optimized in pre-RAM code so don't do |
| 36 | * it again. |
Stefan Reinauer | 0dff6e3 | 2007-10-23 22:17:45 +0000 | [diff] [blame] | 37 | */ |
Yinghai Lu | 90b3e09 | 2005-01-26 22:00:20 +0000 | [diff] [blame] | 38 | #define OPT_HT_LINK 0 |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 39 | |
arch import user (historical) | ef03afa | 2005-07-06 17:15:30 +0000 | [diff] [blame] | 40 | #if OPT_HT_LINK == 1 |
Stefan Reinauer | 7ce8c54 | 2005-12-02 21:52:30 +0000 | [diff] [blame] | 41 | #include <cpu/amd/model_fxx_rev.h> |
arch import user (historical) | ef03afa | 2005-07-06 17:15:30 +0000 | [diff] [blame] | 42 | #endif |
| 43 | |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 44 | static device_t ht_scan_get_devs(device_t *old_devices) |
| 45 | { |
| 46 | device_t first, last; |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 47 | |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 48 | first = *old_devices; |
| 49 | last = first; |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 50 | |
| 51 | /* |
| 52 | * Extract the chain of devices to (first through last) for the next |
| 53 | * hypertransport device. |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 54 | */ |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 55 | while (last && last->sibling && |
| 56 | (last->sibling->path.type == DEVICE_PATH_PCI) && |
| 57 | (last->sibling->path.pci.devfn > last->path.pci.devfn)) |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 58 | { |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 59 | last = last->sibling; |
| 60 | } |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 61 | |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 62 | if (first) { |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 63 | device_t child; |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 64 | |
| 65 | /* Unlink the chain from the list of old devices. */ |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 66 | *old_devices = last->sibling; |
| 67 | last->sibling = 0; |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 68 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 69 | /* Now add the device to the list of devices on the bus. */ |
| 70 | /* Find the last child of our parent. */ |
| 71 | for (child = first->bus->children; child && child->sibling; ) |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 72 | child = child->sibling; |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 73 | |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 74 | /* Place the chain on the list of children of their parent. */ |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 75 | if (child) |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 76 | child->sibling = first; |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 77 | else |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 78 | first->bus->children = first; |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 79 | } |
| 80 | return first; |
| 81 | } |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 82 | |
Yinghai Lu | 90b3e09 | 2005-01-26 22:00:20 +0000 | [diff] [blame] | 83 | #if OPT_HT_LINK == 1 |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 84 | static unsigned ht_read_freq_cap(device_t dev, unsigned pos) |
| 85 | { |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 86 | /* Handle bugs in valid hypertransport frequency reporting. */ |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 87 | unsigned freq_cap; |
| 88 | |
| 89 | freq_cap = pci_read_config16(dev, pos); |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 90 | freq_cap &= ~(1 << HT_FREQ_VENDOR); /* Ignore Vendor HT frequencies. */ |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 91 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 92 | /* AMD 8131 Errata 48. */ |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 93 | if ((dev->vendor == PCI_VENDOR_ID_AMD) && |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 94 | (dev->device == PCI_DEVICE_ID_AMD_8131_PCIX)) { |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 95 | freq_cap &= ~(1 << HT_FREQ_800Mhz); |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 96 | } |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 97 | |
| 98 | /* AMD 8151 Errata 23. */ |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 99 | if ((dev->vendor == PCI_VENDOR_ID_AMD) && |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 100 | (dev->device == PCI_DEVICE_ID_AMD_8151_SYSCTRL)) { |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 101 | freq_cap &= ~(1 << HT_FREQ_800Mhz); |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 102 | } |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 103 | |
| 104 | /* AMD K8 unsupported 1GHz? */ |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 105 | if ((dev->vendor == PCI_VENDOR_ID_AMD) && (dev->device == 0x1100)) { |
Patrick Georgi | e166782 | 2012-05-05 15:29:32 +0200 | [diff] [blame] | 106 | #if CONFIG_K8_HT_FREQ_1G_SUPPORT |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 107 | |
Patrick Georgi | e166782 | 2012-05-05 15:29:32 +0200 | [diff] [blame] | 108 | #if !CONFIG_K8_REV_F_SUPPORT |
Martin Roth | 63373ed | 2013-07-08 16:24:19 -0600 | [diff] [blame] | 109 | /* Only e0 later support 1GHz HT. */ |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 110 | if (is_cpu_pre_e0()) |
Yinghai Lu | 90b3e09 | 2005-01-26 22:00:20 +0000 | [diff] [blame] | 111 | freq_cap &= ~(1 << HT_FREQ_1000Mhz); |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 112 | #endif |
| 113 | |
Stefan Reinauer | 7ce8c54 | 2005-12-02 21:52:30 +0000 | [diff] [blame] | 114 | #else |
| 115 | freq_cap &= ~(1 << HT_FREQ_1000Mhz); |
| 116 | #endif |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 117 | } |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 118 | |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 119 | return freq_cap; |
| 120 | } |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 121 | #endif |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 122 | |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 123 | struct ht_link { |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 124 | struct device *dev; |
| 125 | unsigned pos; |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 126 | unsigned char ctrl_off, config_off, freq_off, freq_cap_off; |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 127 | }; |
| 128 | |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 129 | static int ht_setup_link(struct ht_link *prev, device_t dev, unsigned pos) |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 130 | { |
Stefan Reinauer | 0dff6e3 | 2007-10-23 22:17:45 +0000 | [diff] [blame] | 131 | #if OPT_HT_LINK == 1 |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 132 | static const u8 link_width_to_pow2[] = { 3, 4, 0, 5, 1, 2, 0, 0 }; |
| 133 | static const u8 pow2_to_link_width[] = { 7, 4, 5, 0, 1, 3 }; |
| 134 | unsigned present_width_cap, upstream_width_cap; |
| 135 | unsigned present_freq_cap, upstream_freq_cap; |
| 136 | unsigned ln_present_width_in, ln_upstream_width_in; |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 137 | unsigned ln_present_width_out, ln_upstream_width_out; |
| 138 | unsigned freq, old_freq; |
| 139 | unsigned present_width, upstream_width, old_width; |
Stefan Reinauer | 0dff6e3 | 2007-10-23 22:17:45 +0000 | [diff] [blame] | 140 | #endif |
| 141 | struct ht_link cur[1]; |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 142 | int reset_needed; |
Yinghai Lu | 1f1085b | 2005-01-17 21:37:12 +0000 | [diff] [blame] | 143 | int linkb_to_host; |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 144 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 145 | /* Set the hypertransport link width and frequency. */ |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 146 | reset_needed = 0; |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 147 | /* |
| 148 | * See which side of the device our previous write to set the unitid |
| 149 | * came from. |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 150 | */ |
| 151 | cur->dev = dev; |
| 152 | cur->pos = pos; |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 153 | linkb_to_host = |
| 154 | (pci_read_config16(cur->dev, cur->pos + PCI_CAP_FLAGS) >> 10) & 1; |
| 155 | |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 156 | if (!linkb_to_host) { |
| 157 | cur->ctrl_off = PCI_HT_CAP_SLAVE_CTRL0; |
| 158 | cur->config_off = PCI_HT_CAP_SLAVE_WIDTH0; |
| 159 | cur->freq_off = PCI_HT_CAP_SLAVE_FREQ0; |
| 160 | cur->freq_cap_off = PCI_HT_CAP_SLAVE_FREQ_CAP0; |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 161 | } else { |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 162 | cur->ctrl_off = PCI_HT_CAP_SLAVE_CTRL1; |
| 163 | cur->config_off = PCI_HT_CAP_SLAVE_WIDTH1; |
| 164 | cur->freq_off = PCI_HT_CAP_SLAVE_FREQ1; |
| 165 | cur->freq_cap_off = PCI_HT_CAP_SLAVE_FREQ_CAP1; |
| 166 | } |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 167 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 168 | #if OPT_HT_LINK == 1 |
| 169 | /* Read the capabilities. */ |
| 170 | present_freq_cap = |
| 171 | ht_read_freq_cap(cur->dev, cur->pos + cur->freq_cap_off); |
| 172 | upstream_freq_cap = |
| 173 | ht_read_freq_cap(prev->dev, prev->pos + prev->freq_cap_off); |
| 174 | present_width_cap = |
| 175 | pci_read_config8(cur->dev, cur->pos + cur->config_off); |
| 176 | upstream_width_cap = |
| 177 | pci_read_config8(prev->dev, prev->pos + prev->config_off); |
| 178 | |
Martin Roth | 63373ed | 2013-07-08 16:24:19 -0600 | [diff] [blame] | 179 | /* Calculate the highest usable frequency. */ |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 180 | freq = log2(present_freq_cap & upstream_freq_cap); |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 181 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 182 | /* Calculate the highest width. */ |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 183 | ln_upstream_width_in = link_width_to_pow2[upstream_width_cap & 7]; |
| 184 | ln_present_width_out = link_width_to_pow2[(present_width_cap >> 4) & 7]; |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 185 | if (ln_upstream_width_in > ln_present_width_out) |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 186 | ln_upstream_width_in = ln_present_width_out; |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 187 | upstream_width = pow2_to_link_width[ln_upstream_width_in]; |
| 188 | present_width = pow2_to_link_width[ln_upstream_width_in] << 4; |
| 189 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 190 | ln_upstream_width_out = |
| 191 | link_width_to_pow2[(upstream_width_cap >> 4) & 7]; |
| 192 | ln_present_width_in = link_width_to_pow2[present_width_cap & 7]; |
| 193 | if (ln_upstream_width_out > ln_present_width_in) |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 194 | ln_upstream_width_out = ln_present_width_in; |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 195 | upstream_width |= pow2_to_link_width[ln_upstream_width_out] << 4; |
| 196 | present_width |= pow2_to_link_width[ln_upstream_width_out]; |
| 197 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 198 | /* Set the current device. */ |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 199 | old_freq = pci_read_config8(cur->dev, cur->pos + cur->freq_off); |
| 200 | old_freq &= 0x0f; |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 201 | if (freq != old_freq) { |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 202 | unsigned new_freq; |
| 203 | pci_write_config8(cur->dev, cur->pos + cur->freq_off, freq); |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 204 | reset_needed = 1; |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 205 | printk(BIOS_SPEW, "HyperT FreqP old %x new %x\n",old_freq,freq); |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 206 | new_freq = pci_read_config8(cur->dev, cur->pos + cur->freq_off); |
| 207 | new_freq &= 0x0f; |
| 208 | if (new_freq != freq) { |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 209 | printk(BIOS_ERR, "%s Hypertransport frequency would " |
| 210 | "not set. Wanted: %x, got: %x\n", |
| 211 | dev_path(dev), freq, new_freq); |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 212 | } |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 213 | } |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 214 | old_width = pci_read_config8(cur->dev, cur->pos + cur->config_off + 1); |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 215 | if (present_width != old_width) { |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 216 | unsigned new_width; |
| 217 | pci_write_config8(cur->dev, cur->pos + cur->config_off + 1, |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 218 | present_width); |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 219 | reset_needed = 1; |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 220 | printk(BIOS_SPEW, "HyperT widthP old %x new %x\n", |
| 221 | old_width, present_width); |
| 222 | new_width = pci_read_config8(cur->dev, |
| 223 | cur->pos + cur->config_off + 1); |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 224 | if (new_width != present_width) { |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 225 | printk(BIOS_ERR, "%s Hypertransport width would not " |
| 226 | "set. Wanted: %x, got: %x\n", |
| 227 | dev_path(dev), present_width, new_width); |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 228 | } |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 229 | } |
| 230 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 231 | /* Set the upstream device. */ |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 232 | old_freq = pci_read_config8(prev->dev, prev->pos + prev->freq_off); |
| 233 | old_freq &= 0x0f; |
| 234 | if (freq != old_freq) { |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 235 | unsigned new_freq; |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 236 | pci_write_config8(prev->dev, prev->pos + prev->freq_off, freq); |
| 237 | reset_needed = 1; |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 238 | printk(BIOS_SPEW, "HyperT freqU old %x new %x\n", |
| 239 | old_freq, freq); |
| 240 | new_freq = |
| 241 | pci_read_config8(prev->dev, prev->pos + prev->freq_off); |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 242 | new_freq &= 0x0f; |
| 243 | if (new_freq != freq) { |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 244 | printk(BIOS_ERR, "%s Hypertransport frequency would " |
| 245 | "not set. Wanted: %x, got: %x\n", |
| 246 | dev_path(prev->dev), freq, new_freq); |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 247 | } |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 248 | } |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 249 | old_width = |
| 250 | pci_read_config8(prev->dev, prev->pos + prev->config_off + 1); |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 251 | if (upstream_width != old_width) { |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 252 | unsigned new_width; |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 253 | pci_write_config8(prev->dev, prev->pos + prev->config_off + 1, |
| 254 | upstream_width); |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 255 | reset_needed = 1; |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 256 | printk(BIOS_SPEW, "HyperT widthU old %x new %x\n", old_width, |
| 257 | upstream_width); |
| 258 | new_width = pci_read_config8(prev->dev, |
| 259 | prev->pos + prev->config_off + 1); |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 260 | if (new_width != upstream_width) { |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 261 | printk(BIOS_ERR, "%s Hypertransport width would not " |
| 262 | "set. Wanted: %x, got: %x\n", |
| 263 | dev_path(prev->dev), upstream_width, new_width); |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 264 | } |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 265 | } |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 266 | #endif |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 267 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 268 | /* |
| 269 | * Remember the current link as the previous link, but look at the |
| 270 | * other offsets. |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 271 | */ |
| 272 | prev->dev = cur->dev; |
| 273 | prev->pos = cur->pos; |
| 274 | if (cur->ctrl_off == PCI_HT_CAP_SLAVE_CTRL0) { |
| 275 | prev->ctrl_off = PCI_HT_CAP_SLAVE_CTRL1; |
| 276 | prev->config_off = PCI_HT_CAP_SLAVE_WIDTH1; |
| 277 | prev->freq_off = PCI_HT_CAP_SLAVE_FREQ1; |
| 278 | prev->freq_cap_off = PCI_HT_CAP_SLAVE_FREQ_CAP1; |
| 279 | } else { |
| 280 | prev->ctrl_off = PCI_HT_CAP_SLAVE_CTRL0; |
| 281 | prev->config_off = PCI_HT_CAP_SLAVE_WIDTH0; |
| 282 | prev->freq_off = PCI_HT_CAP_SLAVE_FREQ0; |
| 283 | prev->freq_cap_off = PCI_HT_CAP_SLAVE_FREQ_CAP0; |
| 284 | } |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 285 | |
| 286 | return reset_needed; |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | static unsigned ht_lookup_slave_capability(struct device *dev) |
| 290 | { |
| 291 | unsigned pos; |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 292 | |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 293 | pos = 0; |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 294 | do { |
| 295 | pos = pci_find_next_capability(dev, PCI_CAP_ID_HT, pos); |
| 296 | if (pos) { |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 297 | u16 flags; |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 298 | flags = pci_read_config16(dev, pos + PCI_CAP_FLAGS); |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 299 | printk(BIOS_SPEW, "flags: 0x%04x\n", flags); |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 300 | if ((flags >> 13) == 0) { |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 301 | /* Entry is a slave secondary, success... */ |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 302 | break; |
| 303 | } |
| 304 | } |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 305 | } while (pos); |
| 306 | |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 307 | return pos; |
| 308 | } |
| 309 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 310 | static void ht_collapse_early_enumeration(struct bus *bus, |
| 311 | unsigned offset_unitid) |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 312 | { |
| 313 | unsigned int devfn; |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 314 | struct ht_link prev; |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 315 | u16 ctrl; |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 316 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 317 | /* Initialize the hypertransport enumeration state. */ |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 318 | prev.dev = bus->dev; |
| 319 | prev.pos = bus->cap; |
| 320 | prev.ctrl_off = PCI_HT_CAP_HOST_CTRL; |
| 321 | prev.config_off = PCI_HT_CAP_HOST_WIDTH; |
| 322 | prev.freq_off = PCI_HT_CAP_HOST_FREQ; |
| 323 | prev.freq_cap_off = PCI_HT_CAP_HOST_FREQ_CAP; |
| 324 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 325 | /* Wait until the link initialization is complete. */ |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 326 | do { |
| 327 | ctrl = pci_read_config16(prev.dev, prev.pos + prev.ctrl_off); |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 328 | |
| 329 | /* Is this the end of the hypertransport chain? */ |
| 330 | if (ctrl & (1 << 6)) |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 331 | return; |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 332 | |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 333 | /* Has the link failed? */ |
| 334 | if (ctrl & (1 << 4)) { |
Stefan Reinauer | cf648c9 | 2006-04-11 19:23:57 +0000 | [diff] [blame] | 335 | /* |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 336 | * Either the link has failed, or we have a CRC error. |
| 337 | * Sometimes this can happen due to link retrain, so |
| 338 | * lets knock it down and see if its transient. |
Stefan Reinauer | cf648c9 | 2006-04-11 19:23:57 +0000 | [diff] [blame] | 339 | */ |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 340 | ctrl |= ((1 << 4) | (1 << 8)); /* Link fail + CRC */ |
| 341 | pci_write_config16(prev.dev, prev.pos + prev.ctrl_off, |
| 342 | ctrl); |
| 343 | ctrl = pci_read_config16(prev.dev, |
| 344 | prev.pos + prev.ctrl_off); |
Stefan Reinauer | cf648c9 | 2006-04-11 19:23:57 +0000 | [diff] [blame] | 345 | if (ctrl & ((1 << 4) | (1 << 8))) { |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 346 | printk(BIOS_ALERT, "Detected error on " |
| 347 | "Hypertransport link\n"); |
Stefan Reinauer | cf648c9 | 2006-04-11 19:23:57 +0000 | [diff] [blame] | 348 | return; |
| 349 | } |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 350 | } |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 351 | } while ((ctrl & (1 << 5)) == 0); |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 352 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 353 | /* Actually, only for one HT device HT chain, and unitid is 0. */ |
Patrick Georgi | e166782 | 2012-05-05 15:29:32 +0200 | [diff] [blame] | 354 | #if !CONFIG_HT_CHAIN_UNITID_BASE |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 355 | if (offset_unitid) |
| 356 | return; |
Stefan Reinauer | 7ce8c54 | 2005-12-02 21:52:30 +0000 | [diff] [blame] | 357 | #endif |
| 358 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 359 | /* Check if is already collapsed. */ |
| 360 | if ((!offset_unitid) || (offset_unitid |
| 361 | && (!((CONFIG_HT_CHAIN_END_UNITID_BASE == 0) |
| 362 | && (CONFIG_HT_CHAIN_END_UNITID_BASE |
| 363 | < CONFIG_HT_CHAIN_UNITID_BASE))))) { |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 364 | |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 365 | struct device dummy; |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 366 | u32 id; |
| 367 | |
| 368 | dummy.bus = bus; |
| 369 | dummy.path.type = DEVICE_PATH_PCI; |
| 370 | dummy.path.pci.devfn = PCI_DEVFN(0, 0); |
| 371 | |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 372 | id = pci_read_config32(&dummy, PCI_VENDOR_ID); |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 373 | if (!((id == 0xffffffff) || (id == 0x00000000) |
| 374 | || (id == 0x0000ffff) || (id == 0xffff0000))) { |
| 375 | return; |
| 376 | } |
| 377 | } |
| 378 | |
| 379 | /* Spin through the devices and collapse any early HT enumeration. */ |
| 380 | for (devfn = PCI_DEVFN(1, 0); devfn <= 0xff; devfn += 8) { |
| 381 | struct device dummy; |
| 382 | u32 id; |
| 383 | unsigned pos, flags; |
| 384 | |
| 385 | dummy.bus = bus; |
| 386 | dummy.path.type = DEVICE_PATH_PCI; |
| 387 | dummy.path.pci.devfn = devfn; |
| 388 | |
| 389 | id = pci_read_config32(&dummy, PCI_VENDOR_ID); |
| 390 | if ((id == 0xffffffff) || (id == 0x00000000) |
| 391 | || (id == 0x0000ffff) || (id == 0xffff0000)) { |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 392 | continue; |
| 393 | } |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 394 | |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 395 | dummy.vendor = id & 0xffff; |
| 396 | dummy.device = (id >> 16) & 0xffff; |
| 397 | dummy.hdr_type = pci_read_config8(&dummy, PCI_HEADER_TYPE); |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 398 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 399 | pos = ht_lookup_slave_capability(&dummy); |
| 400 | if (!pos) |
| 401 | continue; |
| 402 | |
| 403 | /* Clear the unitid. */ |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 404 | flags = pci_read_config16(&dummy, pos + PCI_CAP_FLAGS); |
| 405 | flags &= ~0x1f; |
| 406 | pci_write_config16(&dummy, pos + PCI_CAP_FLAGS, flags); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 407 | printk(BIOS_SPEW, "Collapsing %s [%04x/%04x]\n", |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 408 | dev_path(&dummy), dummy.vendor, dummy.device); |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 409 | } |
| 410 | } |
| 411 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 412 | unsigned int hypertransport_scan_chain(struct bus *bus, unsigned min_devfn, |
| 413 | unsigned max_devfn, unsigned int max, |
| 414 | unsigned *ht_unitid_base, |
| 415 | unsigned offset_unitid) |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 416 | { |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 417 | /* |
| 418 | * Even CONFIG_HT_CHAIN_UNITID_BASE == 0, we still can go through this |
| 419 | * function, because of end_of_chain check. Also, we need it to |
| 420 | * optimize link. |
| 421 | */ |
| 422 | unsigned int next_unitid, last_unitid, min_unitid, max_unitid; |
| 423 | device_t old_devices, dev, func, last_func = 0; |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 424 | struct ht_link prev; |
Stefan Reinauer | bbdd8f4 | 2005-12-04 21:52:58 +0000 | [diff] [blame] | 425 | int ht_dev_num = 0; |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 426 | |
| 427 | min_unitid = (offset_unitid) ? CONFIG_HT_CHAIN_UNITID_BASE : 1; |
Stefan Reinauer | 7ce8c54 | 2005-12-02 21:52:30 +0000 | [diff] [blame] | 428 | |
Stefan Reinauer | 0867062 | 2009-06-30 15:17:49 +0000 | [diff] [blame] | 429 | #if CONFIG_HT_CHAIN_END_UNITID_BASE != 0x20 |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 430 | /* |
| 431 | * Let's record the device of last HT device, so we can set the unitid |
| 432 | * to CONFIG_HT_CHAIN_END_UNITID_BASE. |
| 433 | */ |
| 434 | unsigned int real_last_unitid = 0, end_used = 0; |
| 435 | u8 real_last_pos = 0; |
| 436 | device_t real_last_dev = NULL; |
Stefan Reinauer | 7ce8c54 | 2005-12-02 21:52:30 +0000 | [diff] [blame] | 437 | #endif |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 438 | |
Martin Roth | 63373ed | 2013-07-08 16:24:19 -0600 | [diff] [blame] | 439 | /* Restore the hypertransport chain to it's uninitialized state. */ |
Stefan Reinauer | 7ce8c54 | 2005-12-02 21:52:30 +0000 | [diff] [blame] | 440 | ht_collapse_early_enumeration(bus, offset_unitid); |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 441 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 442 | /* See which static device nodes I have. */ |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 443 | old_devices = bus->children; |
| 444 | bus->children = 0; |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 445 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 446 | /* Initialize the hypertransport enumeration state. */ |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 447 | prev.dev = bus->dev; |
| 448 | prev.pos = bus->cap; |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 449 | |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 450 | prev.ctrl_off = PCI_HT_CAP_HOST_CTRL; |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 451 | prev.config_off = PCI_HT_CAP_HOST_WIDTH; |
| 452 | prev.freq_off = PCI_HT_CAP_HOST_FREQ; |
| 453 | prev.freq_cap_off = PCI_HT_CAP_HOST_FREQ_CAP; |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 454 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 455 | /* If present, assign unitid to a hypertransport chain. */ |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 456 | last_unitid = min_unitid -1; |
Yinghai Lu | 18c70d7 | 2007-09-14 14:58:33 +0000 | [diff] [blame] | 457 | max_unitid = next_unitid = min_unitid; |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 458 | do { |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 459 | u8 pos; |
| 460 | u16 flags, ctrl; |
| 461 | unsigned int count, static_count; |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 462 | |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 463 | last_unitid = next_unitid; |
| 464 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 465 | /* Wait until the link initialization is complete. */ |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 466 | do { |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 467 | ctrl = pci_read_config16(prev.dev, |
| 468 | prev.pos + prev.ctrl_off); |
Stefan Reinauer | cf648c9 | 2006-04-11 19:23:57 +0000 | [diff] [blame] | 469 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 470 | /* End of chain? */ |
Stefan Reinauer | cf648c9 | 2006-04-11 19:23:57 +0000 | [diff] [blame] | 471 | if (ctrl & (1 << 6)) |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 472 | goto end_of_chain; |
Stefan Reinauer | cf648c9 | 2006-04-11 19:23:57 +0000 | [diff] [blame] | 473 | |
| 474 | if (ctrl & ((1 << 4) | (1 << 8))) { |
| 475 | /* |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 476 | * Either the link has failed, or we have a CRC |
| 477 | * error. Sometimes this can happen due to link |
| 478 | * retrain, so lets knock it down and see if |
| 479 | * it's transient. |
Stefan Reinauer | cf648c9 | 2006-04-11 19:23:57 +0000 | [diff] [blame] | 480 | */ |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 481 | ctrl |= ((1 << 4) | (1 <<8)); // Link fail + CRC |
| 482 | pci_write_config16(prev.dev, |
| 483 | prev.pos + prev.ctrl_off, ctrl); |
| 484 | ctrl = pci_read_config16(prev.dev, |
| 485 | prev.pos + prev.ctrl_off); |
Stefan Reinauer | cf648c9 | 2006-04-11 19:23:57 +0000 | [diff] [blame] | 486 | if (ctrl & ((1 << 4) | (1 << 8))) { |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 487 | printk(BIOS_ALERT, "Detected error on " |
| 488 | "hypertransport link\n"); |
Stefan Reinauer | cf648c9 | 2006-04-11 19:23:57 +0000 | [diff] [blame] | 489 | goto end_of_chain; |
| 490 | } |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 491 | } |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 492 | } while ((ctrl & (1 << 5)) == 0); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 493 | |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 494 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 495 | /* Get and setup the device_structure. */ |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 496 | dev = ht_scan_get_devs(&old_devices); |
| 497 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 498 | /* See if a device is present and setup the device structure. */ |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 499 | dev = pci_probe_dev(dev, bus, 0); |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 500 | if (!dev || !dev->enabled) |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 501 | break; |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 502 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 503 | /* Find the hypertransport link capability. */ |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 504 | pos = ht_lookup_slave_capability(dev); |
| 505 | if (pos == 0) { |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 506 | printk(BIOS_ERR, "%s Hypertransport link capability " |
| 507 | "not found", dev_path(dev)); |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 508 | break; |
| 509 | } |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 510 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 511 | /* Update the unitid of the current device. */ |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 512 | flags = pci_read_config16(dev, pos + PCI_CAP_FLAGS); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 513 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 514 | /* |
Timothy Pearson | d0c1dd0 | 2015-01-23 20:22:56 -0600 | [diff] [blame] | 515 | * If the device has a unitid set and is at devfn 0 we are |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 516 | * done. This can happen with shadow hypertransport devices, |
| 517 | * or if we have reached the bottom of a HT device chain. |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 518 | */ |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 519 | if (flags & 0x1f) |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 520 | break; |
Yinghai Lu | ecad5df | 2007-05-21 18:11:17 +0000 | [diff] [blame] | 521 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 522 | flags &= ~0x1f; /* Mask out base Unit ID. */ |
| 523 | |
| 524 | count = (flags >> 5) & 0x1f; /* Het unit count. */ |
| 525 | |
Stefan Reinauer | 0867062 | 2009-06-30 15:17:49 +0000 | [diff] [blame] | 526 | #if CONFIG_HT_CHAIN_END_UNITID_BASE != 0x20 |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 527 | if (offset_unitid) { |
| 528 | /* max_devfn will be (0x17<<3)|7 or (0x1f<<3)|7. */ |
| 529 | if (next_unitid > (max_devfn >> 3)) { |
| 530 | if (!end_used) { |
| 531 | next_unitid = |
| 532 | CONFIG_HT_CHAIN_END_UNITID_BASE; |
Yinghai Lu | 18c70d7 | 2007-09-14 14:58:33 +0000 | [diff] [blame] | 533 | end_used = 1; |
| 534 | } else { |
Stefan Reinauer | 0dff6e3 | 2007-10-23 22:17:45 +0000 | [diff] [blame] | 535 | goto end_of_chain; |
Yinghai Lu | 18c70d7 | 2007-09-14 14:58:33 +0000 | [diff] [blame] | 536 | } |
Yinghai Lu | ecad5df | 2007-05-21 18:11:17 +0000 | [diff] [blame] | 537 | } |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 538 | } |
Yinghai Lu | ecad5df | 2007-05-21 18:11:17 +0000 | [diff] [blame] | 539 | #endif |
| 540 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 541 | flags |= next_unitid & 0x1f; |
| 542 | pci_write_config16(dev, pos + PCI_CAP_FLAGS, flags); |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 543 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 544 | /* Update the unitid in the device structure. */ |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 545 | static_count = 1; |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 546 | for (func = dev; func; func = func->sibling) { |
Stefan Reinauer | 2b34db8 | 2009-02-28 20:10:20 +0000 | [diff] [blame] | 547 | func->path.pci.devfn += (next_unitid << 3); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 548 | static_count = (func->path.pci.devfn >> 3) |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 549 | - (dev->path.pci.devfn >> 3) + 1; |
Stefan Reinauer | 7ce8c54 | 2005-12-02 21:52:30 +0000 | [diff] [blame] | 550 | last_func = func; |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 551 | } |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 552 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 553 | /* Compute the number of unitids consumed. */ |
| 554 | printk(BIOS_SPEW, "%s count: %04x static_count: %04x\n", |
| 555 | dev_path(dev), count, static_count); |
| 556 | if (count < static_count) |
| 557 | count = static_count; |
| 558 | |
| 559 | /* Update the unitid of the next device. */ |
Yinghai Lu | 18c70d7 | 2007-09-14 14:58:33 +0000 | [diff] [blame] | 560 | ht_unitid_base[ht_dev_num] = next_unitid; |
Stefan Reinauer | bbdd8f4 | 2005-12-04 21:52:58 +0000 | [diff] [blame] | 561 | ht_dev_num++; |
Yinghai Lu | ecad5df | 2007-05-21 18:11:17 +0000 | [diff] [blame] | 562 | |
Stefan Reinauer | 0867062 | 2009-06-30 15:17:49 +0000 | [diff] [blame] | 563 | #if CONFIG_HT_CHAIN_END_UNITID_BASE != 0x20 |
Yinghai Lu | 18c70d7 | 2007-09-14 14:58:33 +0000 | [diff] [blame] | 564 | if (offset_unitid) { |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 565 | real_last_pos = pos; |
Yinghai Lu | 18c70d7 | 2007-09-14 14:58:33 +0000 | [diff] [blame] | 566 | real_last_unitid = next_unitid; |
Stefan Reinauer | 7ce8c54 | 2005-12-02 21:52:30 +0000 | [diff] [blame] | 567 | real_last_dev = dev; |
Stefan Reinauer | 7ce8c54 | 2005-12-02 21:52:30 +0000 | [diff] [blame] | 568 | } |
| 569 | #endif |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 570 | next_unitid += count; |
| 571 | if (next_unitid > max_unitid) |
Yinghai Lu | 18c70d7 | 2007-09-14 14:58:33 +0000 | [diff] [blame] | 572 | max_unitid = next_unitid; |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 573 | |
Martin Roth | 63373ed | 2013-07-08 16:24:19 -0600 | [diff] [blame] | 574 | /* Setup the hypertransport link. */ |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 575 | bus->reset_needed |= ht_setup_link(&prev, dev, pos); |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 576 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 577 | printk(BIOS_DEBUG, "%s [%04x/%04x] %s next_unitid: %04x\n", |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 578 | dev_path(dev), dev->vendor, dev->device, |
| 579 | (dev->enabled? "enabled" : "disabled"), next_unitid); |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 580 | |
Yinghai Lu | 18c70d7 | 2007-09-14 14:58:33 +0000 | [diff] [blame] | 581 | } while (last_unitid != next_unitid); |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 582 | |
| 583 | end_of_chain: |
| 584 | |
Yinghai Lu | 90b3e09 | 2005-01-26 22:00:20 +0000 | [diff] [blame] | 585 | #if OPT_HT_LINK == 1 |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 586 | if (bus->reset_needed) |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 587 | printk(BIOS_INFO, "HyperT reset needed\n"); |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 588 | else |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 589 | printk(BIOS_DEBUG, "HyperT reset not needed\n"); |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 590 | #endif |
Stefan Reinauer | 7ce8c54 | 2005-12-02 21:52:30 +0000 | [diff] [blame] | 591 | |
Stefan Reinauer | 0867062 | 2009-06-30 15:17:49 +0000 | [diff] [blame] | 592 | #if CONFIG_HT_CHAIN_END_UNITID_BASE != 0x20 |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 593 | if (offset_unitid && (ht_dev_num > 1) |
| 594 | && (real_last_unitid != CONFIG_HT_CHAIN_END_UNITID_BASE) |
| 595 | && !end_used) { |
| 596 | u16 flags; |
| 597 | flags = pci_read_config16(real_last_dev, |
| 598 | real_last_pos + PCI_CAP_FLAGS); |
| 599 | flags &= ~0x1f; |
| 600 | flags |= CONFIG_HT_CHAIN_END_UNITID_BASE & 0x1f; |
| 601 | pci_write_config16(real_last_dev, |
| 602 | real_last_pos + PCI_CAP_FLAGS, flags); |
Stefan Reinauer | 7ce8c54 | 2005-12-02 21:52:30 +0000 | [diff] [blame] | 603 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 604 | for (func = real_last_dev; func; func = func->sibling) { |
| 605 | func->path.pci.devfn -= ((real_last_unitid |
| 606 | - CONFIG_HT_CHAIN_END_UNITID_BASE) << 3); |
Stefan Reinauer | 7ce8c54 | 2005-12-02 21:52:30 +0000 | [diff] [blame] | 607 | last_func = func; |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 608 | } |
Yinghai Lu | ecad5df | 2007-05-21 18:11:17 +0000 | [diff] [blame] | 609 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 610 | /* Update last one. */ |
| 611 | ht_unitid_base[ht_dev_num-1] = CONFIG_HT_CHAIN_END_UNITID_BASE; |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 612 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 613 | printk(BIOS_DEBUG, " unitid: %04x --> %04x\n", |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 614 | real_last_unitid, CONFIG_HT_CHAIN_END_UNITID_BASE); |
| 615 | } |
Stefan Reinauer | 7ce8c54 | 2005-12-02 21:52:30 +0000 | [diff] [blame] | 616 | #endif |
Yinghai Lu | 18c70d7 | 2007-09-14 14:58:33 +0000 | [diff] [blame] | 617 | next_unitid = max_unitid; |
Stefan Reinauer | 7ce8c54 | 2005-12-02 21:52:30 +0000 | [diff] [blame] | 618 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 619 | if (next_unitid > 0x20) |
Yinghai Lu | 18c70d7 | 2007-09-14 14:58:33 +0000 | [diff] [blame] | 620 | next_unitid = 0x20; |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 621 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 622 | if ((bus->secondary == 0) && (next_unitid > 0x18)) |
| 623 | next_unitid = 0x18; /* Avoid K8 on bus 0. */ |
| 624 | |
| 625 | /* |
| 626 | * Die if any leftover static devices are are found. There's probably |
| 627 | * a problem in devicetree.cb. |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 628 | */ |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 629 | if (old_devices) { |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 630 | device_t left; |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 631 | for (left = old_devices; left; left = left->sibling) |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 632 | printk(BIOS_DEBUG, "%s\n", dev_path(left)); |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 633 | |
| 634 | printk(BIOS_ERR, "HT: Leftover static devices. " |
| 635 | "Check your devicetree.cb\n"); |
| 636 | |
| 637 | /* |
| 638 | * Put back the leftover static device, and let pci_scan_bus() |
| 639 | * disable it. |
| 640 | */ |
| 641 | if (last_func && !last_func->sibling) |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 642 | last_func->sibling = old_devices; |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 643 | } |
Stefan Reinauer | 7ce8c54 | 2005-12-02 21:52:30 +0000 | [diff] [blame] | 644 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 645 | /* Now that nothing is overlapping it is safe to scan the children. */ |
| 646 | max = pci_scan_bus(bus, 0x00, ((next_unitid - 1) << 3) | 7, max); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 647 | return max; |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 648 | } |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 649 | |
| 650 | /** |
Uwe Hermann | c1ee429 | 2010-10-17 19:01:48 +0000 | [diff] [blame] | 651 | * Scan a PCI bridge and the buses behind the bridge. |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 652 | * |
| 653 | * Determine the existence of buses behind the bridge. Set up the bridge |
| 654 | * according to the result of the scan. |
| 655 | * |
| 656 | * This function is the default scan_bus() method for PCI bridge devices. |
| 657 | * |
Uwe Hermann | c1ee429 | 2010-10-17 19:01:48 +0000 | [diff] [blame] | 658 | * @param bus TODO |
| 659 | * @param min_devfn TODO |
| 660 | * @param max_devfn TODO |
Martin Roth | 63373ed | 2013-07-08 16:24:19 -0600 | [diff] [blame] | 661 | * @param max The highest bus number assigned up to now. |
Uwe Hermann | c1ee429 | 2010-10-17 19:01:48 +0000 | [diff] [blame] | 662 | * @return The maximum bus number found, after scanning all subordinate busses. |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 663 | */ |
Myles Watson | 7943fe6 | 2009-10-30 02:08:07 +0000 | [diff] [blame] | 664 | static unsigned int hypertransport_scan_chain_x(struct bus *bus, |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 665 | unsigned int min_devfn, unsigned int max_devfn, unsigned int max) |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 666 | { |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 667 | unsigned int ht_unitid_base[4]; |
| 668 | unsigned int offset_unitid = 1; |
| 669 | return hypertransport_scan_chain(bus, min_devfn, max_devfn, max, |
| 670 | ht_unitid_base, offset_unitid); |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 671 | } |
| 672 | |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 673 | unsigned int ht_scan_bridge(struct device *dev, unsigned int max) |
| 674 | { |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 675 | return do_pci_scan_bridge(dev, max, hypertransport_scan_chain_x); |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 676 | } |
| 677 | |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 678 | /** Default device operations for hypertransport bridges */ |
| 679 | static struct pci_operations ht_bus_ops_pci = { |
| 680 | .set_subsystem = 0, |
| 681 | }; |
| 682 | |
| 683 | struct device_operations default_ht_ops_bus = { |
| 684 | .read_resources = pci_bus_read_resources, |
| 685 | .set_resources = pci_dev_set_resources, |
| 686 | .enable_resources = pci_bus_enable_resources, |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 687 | .init = 0, |
| 688 | .scan_bus = ht_scan_bridge, |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 689 | .enable = 0, |
| 690 | .reset_bus = pci_bus_reset, |
| 691 | .ops_pci = &ht_bus_ops_pci, |
| 692 | }; |