blob: d9ab486c22f7f7baf2d02bb22bf5ed3367b814f5 [file] [log] [blame]
Stefan Reinauer7ce8c542005-12-02 21:52:30 +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) 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 Menzela46a7122013-02-23 18:37:27 +010023 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Uwe Hermannb80dbf02007-04-22 19:08:13 +000024 */
Stefan Reinauer7ce8c542005-12-02 21:52:30 +000025
Ronald G. Minnich5079a0d2012-11-27 11:32:38 -080026#include <lib.h>
Eric Biederman0ac6b412003-09-02 17:16:48 +000027#include <console/console.h>
28#include <device/device.h>
29#include <device/path.h>
30#include <device/pci.h>
Eric Biederman5cd81732004-03-11 15:01:31 +000031#include <device/pci_ids.h>
Eric Biedermanff0e8462003-09-04 03:00:54 +000032#include <device/hypertransport.h>
Eric Biederman0ac6b412003-09-02 17:16:48 +000033
Uwe Hermannc1ee4292010-10-17 19:01:48 +000034/*
35 * The hypertransport link is already optimized in pre-RAM code so don't do
36 * it again.
Stefan Reinauer0dff6e32007-10-23 22:17:45 +000037 */
Yinghai Lu90b3e092005-01-26 22:00:20 +000038#define OPT_HT_LINK 0
Stefan Reinauer14e22772010-04-27 06:56:47 +000039
arch import user (historical)ef03afa2005-07-06 17:15:30 +000040#if OPT_HT_LINK == 1
Stefan Reinauer7ce8c542005-12-02 21:52:30 +000041#include <cpu/amd/model_fxx_rev.h>
arch import user (historical)ef03afa2005-07-06 17:15:30 +000042#endif
43
Eric Biederman0ac6b412003-09-02 17:16:48 +000044static device_t ht_scan_get_devs(device_t *old_devices)
45{
46 device_t first, last;
Uwe Hermanne4870472010-11-04 23:23:47 +000047
Eric Biederman0ac6b412003-09-02 17:16:48 +000048 first = *old_devices;
49 last = first;
Uwe Hermanne4870472010-11-04 23:23:47 +000050
51 /*
52 * Extract the chain of devices to (first through last) for the next
53 * hypertransport device.
Yinghai Lu13f1c2a2005-07-08 02:49:49 +000054 */
Uwe Hermanne4870472010-11-04 23:23:47 +000055 while (last && last->sibling &&
56 (last->sibling->path.type == DEVICE_PATH_PCI) &&
57 (last->sibling->path.pci.devfn > last->path.pci.devfn))
Yinghai Lu13f1c2a2005-07-08 02:49:49 +000058 {
Eric Biederman0ac6b412003-09-02 17:16:48 +000059 last = last->sibling;
60 }
Uwe Hermanne4870472010-11-04 23:23:47 +000061
Eric Biederman0ac6b412003-09-02 17:16:48 +000062 if (first) {
Yinghai Lu13f1c2a2005-07-08 02:49:49 +000063 device_t child;
Uwe Hermanne4870472010-11-04 23:23:47 +000064
65 /* Unlink the chain from the list of old devices. */
Eric Biederman0ac6b412003-09-02 17:16:48 +000066 *old_devices = last->sibling;
67 last->sibling = 0;
Yinghai Lu13f1c2a2005-07-08 02:49:49 +000068
Uwe Hermanne4870472010-11-04 23:23:47 +000069 /* 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 Lu13f1c2a2005-07-08 02:49:49 +000072 child = child->sibling;
Uwe Hermanne4870472010-11-04 23:23:47 +000073
Yinghai Lu13f1c2a2005-07-08 02:49:49 +000074 /* Place the chain on the list of children of their parent. */
Uwe Hermanne4870472010-11-04 23:23:47 +000075 if (child)
Yinghai Lu13f1c2a2005-07-08 02:49:49 +000076 child->sibling = first;
Uwe Hermanne4870472010-11-04 23:23:47 +000077 else
Yinghai Lu13f1c2a2005-07-08 02:49:49 +000078 first->bus->children = first;
Eric Biederman0ac6b412003-09-02 17:16:48 +000079 }
80 return first;
81}
Yinghai Lu13f1c2a2005-07-08 02:49:49 +000082
Yinghai Lu90b3e092005-01-26 22:00:20 +000083#if OPT_HT_LINK == 1
Eric Biederman5cd81732004-03-11 15:01:31 +000084static unsigned ht_read_freq_cap(device_t dev, unsigned pos)
85{
Uwe Hermanne4870472010-11-04 23:23:47 +000086 /* Handle bugs in valid hypertransport frequency reporting. */
Eric Biederman5cd81732004-03-11 15:01:31 +000087 unsigned freq_cap;
88
89 freq_cap = pci_read_config16(dev, pos);
Uwe Hermanne4870472010-11-04 23:23:47 +000090 freq_cap &= ~(1 << HT_FREQ_VENDOR); /* Ignore Vendor HT frequencies. */
Eric Biederman5cd81732004-03-11 15:01:31 +000091
Uwe Hermanne4870472010-11-04 23:23:47 +000092 /* AMD 8131 Errata 48. */
Eric Biederman5cd81732004-03-11 15:01:31 +000093 if ((dev->vendor == PCI_VENDOR_ID_AMD) &&
Uwe Hermanne4870472010-11-04 23:23:47 +000094 (dev->device == PCI_DEVICE_ID_AMD_8131_PCIX)) {
Eric Biederman5cd81732004-03-11 15:01:31 +000095 freq_cap &= ~(1 << HT_FREQ_800Mhz);
Yinghai Lu13f1c2a2005-07-08 02:49:49 +000096 }
Uwe Hermanne4870472010-11-04 23:23:47 +000097
98 /* AMD 8151 Errata 23. */
Eric Biederman5cd81732004-03-11 15:01:31 +000099 if ((dev->vendor == PCI_VENDOR_ID_AMD) &&
Uwe Hermanne4870472010-11-04 23:23:47 +0000100 (dev->device == PCI_DEVICE_ID_AMD_8151_SYSCTRL)) {
Eric Biederman5cd81732004-03-11 15:01:31 +0000101 freq_cap &= ~(1 << HT_FREQ_800Mhz);
Yinghai Lu13f1c2a2005-07-08 02:49:49 +0000102 }
Uwe Hermanne4870472010-11-04 23:23:47 +0000103
104 /* AMD K8 unsupported 1GHz? */
Eric Biederman5cd81732004-03-11 15:01:31 +0000105 if ((dev->vendor == PCI_VENDOR_ID_AMD) && (dev->device == 0x1100)) {
Patrick Georgie1667822012-05-05 15:29:32 +0200106#if CONFIG_K8_HT_FREQ_1G_SUPPORT
Uwe Hermanne4870472010-11-04 23:23:47 +0000107
Patrick Georgie1667822012-05-05 15:29:32 +0200108#if !CONFIG_K8_REV_F_SUPPORT
Martin Roth63373ed2013-07-08 16:24:19 -0600109 /* Only e0 later support 1GHz HT. */
Uwe Hermanne4870472010-11-04 23:23:47 +0000110 if (is_cpu_pre_e0())
Yinghai Lu90b3e092005-01-26 22:00:20 +0000111 freq_cap &= ~(1 << HT_FREQ_1000Mhz);
Uwe Hermanne4870472010-11-04 23:23:47 +0000112#endif
113
Stefan Reinauer7ce8c542005-12-02 21:52:30 +0000114#else
115 freq_cap &= ~(1 << HT_FREQ_1000Mhz);
116#endif
Eric Biederman5cd81732004-03-11 15:01:31 +0000117 }
Uwe Hermanne4870472010-11-04 23:23:47 +0000118
Eric Biederman5cd81732004-03-11 15:01:31 +0000119 return freq_cap;
120}
Yinghai Lu13f1c2a2005-07-08 02:49:49 +0000121#endif
Eric Biederman0ac6b412003-09-02 17:16:48 +0000122
Yinghai Lu13f1c2a2005-07-08 02:49:49 +0000123struct ht_link {
Eric Biederman0ac6b412003-09-02 17:16:48 +0000124 struct device *dev;
125 unsigned pos;
Yinghai Lu13f1c2a2005-07-08 02:49:49 +0000126 unsigned char ctrl_off, config_off, freq_off, freq_cap_off;
Eric Biederman0ac6b412003-09-02 17:16:48 +0000127};
128
Yinghai Lu13f1c2a2005-07-08 02:49:49 +0000129static int ht_setup_link(struct ht_link *prev, device_t dev, unsigned pos)
Eric Biederman0ac6b412003-09-02 17:16:48 +0000130{
Stefan Reinauer0dff6e32007-10-23 22:17:45 +0000131#if OPT_HT_LINK == 1
Uwe Hermanne4870472010-11-04 23:23:47 +0000132 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 Biederman0ac6b412003-09-02 17:16:48 +0000137 unsigned ln_present_width_out, ln_upstream_width_out;
138 unsigned freq, old_freq;
139 unsigned present_width, upstream_width, old_width;
Stefan Reinauer0dff6e32007-10-23 22:17:45 +0000140#endif
141 struct ht_link cur[1];
Eric Biederman0ac6b412003-09-02 17:16:48 +0000142 int reset_needed;
Yinghai Lu1f1085b2005-01-17 21:37:12 +0000143 int linkb_to_host;
Eric Biederman0ac6b412003-09-02 17:16:48 +0000144
Uwe Hermanne4870472010-11-04 23:23:47 +0000145 /* Set the hypertransport link width and frequency. */
Eric Biederman0ac6b412003-09-02 17:16:48 +0000146 reset_needed = 0;
Uwe Hermanne4870472010-11-04 23:23:47 +0000147 /*
148 * See which side of the device our previous write to set the unitid
149 * came from.
Yinghai Lu13f1c2a2005-07-08 02:49:49 +0000150 */
151 cur->dev = dev;
152 cur->pos = pos;
Uwe Hermanne4870472010-11-04 23:23:47 +0000153 linkb_to_host =
154 (pci_read_config16(cur->dev, cur->pos + PCI_CAP_FLAGS) >> 10) & 1;
155
Yinghai Lu13f1c2a2005-07-08 02:49:49 +0000156 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 Hermanne4870472010-11-04 23:23:47 +0000161 } else {
Yinghai Lu13f1c2a2005-07-08 02:49:49 +0000162 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 Reinauer14e22772010-04-27 06:56:47 +0000167
Uwe Hermanne4870472010-11-04 23:23:47 +0000168#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 Roth63373ed2013-07-08 16:24:19 -0600179 /* Calculate the highest usable frequency. */
Eric Biederman0ac6b412003-09-02 17:16:48 +0000180 freq = log2(present_freq_cap & upstream_freq_cap);
Eric Biederman0ac6b412003-09-02 17:16:48 +0000181
Uwe Hermanne4870472010-11-04 23:23:47 +0000182 /* Calculate the highest width. */
Eric Biederman0ac6b412003-09-02 17:16:48 +0000183 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 Hermanne4870472010-11-04 23:23:47 +0000185 if (ln_upstream_width_in > ln_present_width_out)
Eric Biederman0ac6b412003-09-02 17:16:48 +0000186 ln_upstream_width_in = ln_present_width_out;
Eric Biederman0ac6b412003-09-02 17:16:48 +0000187 upstream_width = pow2_to_link_width[ln_upstream_width_in];
188 present_width = pow2_to_link_width[ln_upstream_width_in] << 4;
189
Uwe Hermanne4870472010-11-04 23:23:47 +0000190 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 Biederman0ac6b412003-09-02 17:16:48 +0000194 ln_upstream_width_out = ln_present_width_in;
Eric Biederman0ac6b412003-09-02 17:16:48 +0000195 upstream_width |= pow2_to_link_width[ln_upstream_width_out] << 4;
196 present_width |= pow2_to_link_width[ln_upstream_width_out];
197
Uwe Hermanne4870472010-11-04 23:23:47 +0000198 /* Set the current device. */
Yinghai Lu13f1c2a2005-07-08 02:49:49 +0000199 old_freq = pci_read_config8(cur->dev, cur->pos + cur->freq_off);
200 old_freq &= 0x0f;
Eric Biederman0ac6b412003-09-02 17:16:48 +0000201 if (freq != old_freq) {
Yinghai Lu13f1c2a2005-07-08 02:49:49 +0000202 unsigned new_freq;
203 pci_write_config8(cur->dev, cur->pos + cur->freq_off, freq);
Eric Biederman0ac6b412003-09-02 17:16:48 +0000204 reset_needed = 1;
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000205 printk(BIOS_SPEW, "HyperT FreqP old %x new %x\n",old_freq,freq);
Yinghai Lu13f1c2a2005-07-08 02:49:49 +0000206 new_freq = pci_read_config8(cur->dev, cur->pos + cur->freq_off);
207 new_freq &= 0x0f;
208 if (new_freq != freq) {
Uwe Hermanne4870472010-11-04 23:23:47 +0000209 printk(BIOS_ERR, "%s Hypertransport frequency would "
210 "not set. Wanted: %x, got: %x\n",
211 dev_path(dev), freq, new_freq);
Yinghai Lu13f1c2a2005-07-08 02:49:49 +0000212 }
Eric Biederman0ac6b412003-09-02 17:16:48 +0000213 }
Yinghai Lu13f1c2a2005-07-08 02:49:49 +0000214 old_width = pci_read_config8(cur->dev, cur->pos + cur->config_off + 1);
Eric Biederman0ac6b412003-09-02 17:16:48 +0000215 if (present_width != old_width) {
Yinghai Lu13f1c2a2005-07-08 02:49:49 +0000216 unsigned new_width;
217 pci_write_config8(cur->dev, cur->pos + cur->config_off + 1,
Uwe Hermanne4870472010-11-04 23:23:47 +0000218 present_width);
Eric Biederman0ac6b412003-09-02 17:16:48 +0000219 reset_needed = 1;
Uwe Hermanne4870472010-11-04 23:23:47 +0000220 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 Lu13f1c2a2005-07-08 02:49:49 +0000224 if (new_width != present_width) {
Uwe Hermanne4870472010-11-04 23:23:47 +0000225 printk(BIOS_ERR, "%s Hypertransport width would not "
226 "set. Wanted: %x, got: %x\n",
227 dev_path(dev), present_width, new_width);
Yinghai Lu13f1c2a2005-07-08 02:49:49 +0000228 }
Eric Biederman0ac6b412003-09-02 17:16:48 +0000229 }
230
Uwe Hermanne4870472010-11-04 23:23:47 +0000231 /* Set the upstream device. */
Eric Biederman0ac6b412003-09-02 17:16:48 +0000232 old_freq = pci_read_config8(prev->dev, prev->pos + prev->freq_off);
233 old_freq &= 0x0f;
234 if (freq != old_freq) {
Yinghai Lu13f1c2a2005-07-08 02:49:49 +0000235 unsigned new_freq;
Eric Biederman0ac6b412003-09-02 17:16:48 +0000236 pci_write_config8(prev->dev, prev->pos + prev->freq_off, freq);
237 reset_needed = 1;
Uwe Hermanne4870472010-11-04 23:23:47 +0000238 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 Lu13f1c2a2005-07-08 02:49:49 +0000242 new_freq &= 0x0f;
243 if (new_freq != freq) {
Uwe Hermanne4870472010-11-04 23:23:47 +0000244 printk(BIOS_ERR, "%s Hypertransport frequency would "
245 "not set. Wanted: %x, got: %x\n",
246 dev_path(prev->dev), freq, new_freq);
Yinghai Lu13f1c2a2005-07-08 02:49:49 +0000247 }
Eric Biederman0ac6b412003-09-02 17:16:48 +0000248 }
Uwe Hermanne4870472010-11-04 23:23:47 +0000249 old_width =
250 pci_read_config8(prev->dev, prev->pos + prev->config_off + 1);
Eric Biederman0ac6b412003-09-02 17:16:48 +0000251 if (upstream_width != old_width) {
Yinghai Lu13f1c2a2005-07-08 02:49:49 +0000252 unsigned new_width;
Uwe Hermanne4870472010-11-04 23:23:47 +0000253 pci_write_config8(prev->dev, prev->pos + prev->config_off + 1,
254 upstream_width);
Eric Biederman0ac6b412003-09-02 17:16:48 +0000255 reset_needed = 1;
Uwe Hermanne4870472010-11-04 23:23:47 +0000256 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 Lu13f1c2a2005-07-08 02:49:49 +0000260 if (new_width != upstream_width) {
Uwe Hermanne4870472010-11-04 23:23:47 +0000261 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 Lu13f1c2a2005-07-08 02:49:49 +0000264 }
Eric Biederman0ac6b412003-09-02 17:16:48 +0000265 }
Yinghai Lu13f1c2a2005-07-08 02:49:49 +0000266#endif
Stefan Reinauer14e22772010-04-27 06:56:47 +0000267
Uwe Hermanne4870472010-11-04 23:23:47 +0000268 /*
269 * Remember the current link as the previous link, but look at the
270 * other offsets.
Yinghai Lu13f1c2a2005-07-08 02:49:49 +0000271 */
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 Biederman0ac6b412003-09-02 17:16:48 +0000285
286 return reset_needed;
Eric Biederman0ac6b412003-09-02 17:16:48 +0000287}
288
289static unsigned ht_lookup_slave_capability(struct device *dev)
290{
291 unsigned pos;
Uwe Hermanne4870472010-11-04 23:23:47 +0000292
Eric Biederman0ac6b412003-09-02 17:16:48 +0000293 pos = 0;
Yinghai Lu13f1c2a2005-07-08 02:49:49 +0000294 do {
295 pos = pci_find_next_capability(dev, PCI_CAP_ID_HT, pos);
296 if (pos) {
Uwe Hermanne4870472010-11-04 23:23:47 +0000297 u16 flags;
Eric Biederman0ac6b412003-09-02 17:16:48 +0000298 flags = pci_read_config16(dev, pos + PCI_CAP_FLAGS);
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000299 printk(BIOS_SPEW, "flags: 0x%04x\n", flags);
Eric Biederman0ac6b412003-09-02 17:16:48 +0000300 if ((flags >> 13) == 0) {
Uwe Hermanne4870472010-11-04 23:23:47 +0000301 /* Entry is a slave secondary, success... */
Eric Biederman0ac6b412003-09-02 17:16:48 +0000302 break;
303 }
304 }
Uwe Hermanne4870472010-11-04 23:23:47 +0000305 } while (pos);
306
Eric Biederman0ac6b412003-09-02 17:16:48 +0000307 return pos;
308}
309
Uwe Hermanne4870472010-11-04 23:23:47 +0000310static void ht_collapse_early_enumeration(struct bus *bus,
311 unsigned offset_unitid)
Eric Biederman0ac6b412003-09-02 17:16:48 +0000312{
313 unsigned int devfn;
Yinghai Lu13f1c2a2005-07-08 02:49:49 +0000314 struct ht_link prev;
Uwe Hermanne4870472010-11-04 23:23:47 +0000315 u16 ctrl;
Yinghai Lu13f1c2a2005-07-08 02:49:49 +0000316
Uwe Hermanne4870472010-11-04 23:23:47 +0000317 /* Initialize the hypertransport enumeration state. */
Yinghai Lu13f1c2a2005-07-08 02:49:49 +0000318 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 Hermanne4870472010-11-04 23:23:47 +0000325 /* Wait until the link initialization is complete. */
Yinghai Lu13f1c2a2005-07-08 02:49:49 +0000326 do {
327 ctrl = pci_read_config16(prev.dev, prev.pos + prev.ctrl_off);
Uwe Hermanne4870472010-11-04 23:23:47 +0000328
329 /* Is this the end of the hypertransport chain? */
330 if (ctrl & (1 << 6))
Yinghai Lu13f1c2a2005-07-08 02:49:49 +0000331 return;
Uwe Hermanne4870472010-11-04 23:23:47 +0000332
Yinghai Lu13f1c2a2005-07-08 02:49:49 +0000333 /* Has the link failed? */
334 if (ctrl & (1 << 4)) {
Stefan Reinauercf648c92006-04-11 19:23:57 +0000335 /*
Uwe Hermanne4870472010-11-04 23:23:47 +0000336 * 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 Reinauercf648c92006-04-11 19:23:57 +0000339 */
Uwe Hermanne4870472010-11-04 23:23:47 +0000340 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 Reinauercf648c92006-04-11 19:23:57 +0000345 if (ctrl & ((1 << 4) | (1 << 8))) {
Uwe Hermanne4870472010-11-04 23:23:47 +0000346 printk(BIOS_ALERT, "Detected error on "
347 "Hypertransport link\n");
Stefan Reinauercf648c92006-04-11 19:23:57 +0000348 return;
349 }
Yinghai Lu13f1c2a2005-07-08 02:49:49 +0000350 }
Uwe Hermanne4870472010-11-04 23:23:47 +0000351 } while ((ctrl & (1 << 5)) == 0);
Yinghai Lu13f1c2a2005-07-08 02:49:49 +0000352
Uwe Hermanne4870472010-11-04 23:23:47 +0000353 /* Actually, only for one HT device HT chain, and unitid is 0. */
Patrick Georgie1667822012-05-05 15:29:32 +0200354#if !CONFIG_HT_CHAIN_UNITID_BASE
Uwe Hermanne4870472010-11-04 23:23:47 +0000355 if (offset_unitid)
356 return;
Stefan Reinauer7ce8c542005-12-02 21:52:30 +0000357#endif
358
Uwe Hermanne4870472010-11-04 23:23:47 +0000359 /* 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 Biederman0ac6b412003-09-02 17:16:48 +0000364
Eric Biederman0ac6b412003-09-02 17:16:48 +0000365 struct device dummy;
Uwe Hermanne4870472010-11-04 23:23:47 +0000366 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 Biederman0ac6b412003-09-02 17:16:48 +0000372 id = pci_read_config32(&dummy, PCI_VENDOR_ID);
Uwe Hermanne4870472010-11-04 23:23:47 +0000373 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 Biederman0ac6b412003-09-02 17:16:48 +0000392 continue;
393 }
Uwe Hermanne4870472010-11-04 23:23:47 +0000394
Eric Biederman0ac6b412003-09-02 17:16:48 +0000395 dummy.vendor = id & 0xffff;
396 dummy.device = (id >> 16) & 0xffff;
397 dummy.hdr_type = pci_read_config8(&dummy, PCI_HEADER_TYPE);
Eric Biederman0ac6b412003-09-02 17:16:48 +0000398
Uwe Hermanne4870472010-11-04 23:23:47 +0000399 pos = ht_lookup_slave_capability(&dummy);
400 if (!pos)
401 continue;
402
403 /* Clear the unitid. */
Eric Biederman0ac6b412003-09-02 17:16:48 +0000404 flags = pci_read_config16(&dummy, pos + PCI_CAP_FLAGS);
405 flags &= ~0x1f;
406 pci_write_config16(&dummy, pos + PCI_CAP_FLAGS, flags);
Stefan Reinauer14e22772010-04-27 06:56:47 +0000407 printk(BIOS_SPEW, "Collapsing %s [%04x/%04x]\n",
Uwe Hermanne4870472010-11-04 23:23:47 +0000408 dev_path(&dummy), dummy.vendor, dummy.device);
Eric Biederman0ac6b412003-09-02 17:16:48 +0000409 }
410}
411
Uwe Hermanne4870472010-11-04 23:23:47 +0000412unsigned 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 Biederman0ac6b412003-09-02 17:16:48 +0000416{
Uwe Hermanne4870472010-11-04 23:23:47 +0000417 /*
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 Lu13f1c2a2005-07-08 02:49:49 +0000424 struct ht_link prev;
Stefan Reinauerbbdd8f42005-12-04 21:52:58 +0000425 int ht_dev_num = 0;
Uwe Hermanne4870472010-11-04 23:23:47 +0000426
427 min_unitid = (offset_unitid) ? CONFIG_HT_CHAIN_UNITID_BASE : 1;
Stefan Reinauer7ce8c542005-12-02 21:52:30 +0000428
Stefan Reinauer08670622009-06-30 15:17:49 +0000429#if CONFIG_HT_CHAIN_END_UNITID_BASE != 0x20
Uwe Hermanne4870472010-11-04 23:23:47 +0000430 /*
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 Reinauer7ce8c542005-12-02 21:52:30 +0000437#endif
Eric Biederman0ac6b412003-09-02 17:16:48 +0000438
Martin Roth63373ed2013-07-08 16:24:19 -0600439 /* Restore the hypertransport chain to it's uninitialized state. */
Stefan Reinauer7ce8c542005-12-02 21:52:30 +0000440 ht_collapse_early_enumeration(bus, offset_unitid);
Eric Biederman0ac6b412003-09-02 17:16:48 +0000441
Uwe Hermanne4870472010-11-04 23:23:47 +0000442 /* See which static device nodes I have. */
Eric Biederman0ac6b412003-09-02 17:16:48 +0000443 old_devices = bus->children;
444 bus->children = 0;
Eric Biederman0ac6b412003-09-02 17:16:48 +0000445
Uwe Hermanne4870472010-11-04 23:23:47 +0000446 /* Initialize the hypertransport enumeration state. */
Eric Biederman0ac6b412003-09-02 17:16:48 +0000447 prev.dev = bus->dev;
448 prev.pos = bus->cap;
Uwe Hermanne4870472010-11-04 23:23:47 +0000449
Yinghai Lu13f1c2a2005-07-08 02:49:49 +0000450 prev.ctrl_off = PCI_HT_CAP_HOST_CTRL;
Eric Biederman0ac6b412003-09-02 17:16:48 +0000451 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 Reinauer14e22772010-04-27 06:56:47 +0000454
Uwe Hermanne4870472010-11-04 23:23:47 +0000455 /* If present, assign unitid to a hypertransport chain. */
Eric Biederman0ac6b412003-09-02 17:16:48 +0000456 last_unitid = min_unitid -1;
Yinghai Lu18c70d72007-09-14 14:58:33 +0000457 max_unitid = next_unitid = min_unitid;
Eric Biederman0ac6b412003-09-02 17:16:48 +0000458 do {
Uwe Hermanne4870472010-11-04 23:23:47 +0000459 u8 pos;
460 u16 flags, ctrl;
461 unsigned int count, static_count;
Eric Biederman0ac6b412003-09-02 17:16:48 +0000462
Eric Biederman0ac6b412003-09-02 17:16:48 +0000463 last_unitid = next_unitid;
464
Uwe Hermanne4870472010-11-04 23:23:47 +0000465 /* Wait until the link initialization is complete. */
Yinghai Lu13f1c2a2005-07-08 02:49:49 +0000466 do {
Uwe Hermanne4870472010-11-04 23:23:47 +0000467 ctrl = pci_read_config16(prev.dev,
468 prev.pos + prev.ctrl_off);
Stefan Reinauercf648c92006-04-11 19:23:57 +0000469
Uwe Hermanne4870472010-11-04 23:23:47 +0000470 /* End of chain? */
Stefan Reinauercf648c92006-04-11 19:23:57 +0000471 if (ctrl & (1 << 6))
Uwe Hermanne4870472010-11-04 23:23:47 +0000472 goto end_of_chain;
Stefan Reinauercf648c92006-04-11 19:23:57 +0000473
474 if (ctrl & ((1 << 4) | (1 << 8))) {
475 /*
Uwe Hermanne4870472010-11-04 23:23:47 +0000476 * 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 Reinauercf648c92006-04-11 19:23:57 +0000480 */
Uwe Hermanne4870472010-11-04 23:23:47 +0000481 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 Reinauercf648c92006-04-11 19:23:57 +0000486 if (ctrl & ((1 << 4) | (1 << 8))) {
Uwe Hermanne4870472010-11-04 23:23:47 +0000487 printk(BIOS_ALERT, "Detected error on "
488 "hypertransport link\n");
Stefan Reinauercf648c92006-04-11 19:23:57 +0000489 goto end_of_chain;
490 }
Yinghai Lu13f1c2a2005-07-08 02:49:49 +0000491 }
Uwe Hermanne4870472010-11-04 23:23:47 +0000492 } while ((ctrl & (1 << 5)) == 0);
Stefan Reinauer14e22772010-04-27 06:56:47 +0000493
Yinghai Lu13f1c2a2005-07-08 02:49:49 +0000494
Uwe Hermanne4870472010-11-04 23:23:47 +0000495 /* Get and setup the device_structure. */
Eric Biederman0ac6b412003-09-02 17:16:48 +0000496 dev = ht_scan_get_devs(&old_devices);
497
Uwe Hermanne4870472010-11-04 23:23:47 +0000498 /* See if a device is present and setup the device structure. */
Yinghai Lu13f1c2a2005-07-08 02:49:49 +0000499 dev = pci_probe_dev(dev, bus, 0);
Uwe Hermanne4870472010-11-04 23:23:47 +0000500 if (!dev || !dev->enabled)
Yinghai Lu13f1c2a2005-07-08 02:49:49 +0000501 break;
Eric Biederman0ac6b412003-09-02 17:16:48 +0000502
Uwe Hermanne4870472010-11-04 23:23:47 +0000503 /* Find the hypertransport link capability. */
Eric Biederman0ac6b412003-09-02 17:16:48 +0000504 pos = ht_lookup_slave_capability(dev);
505 if (pos == 0) {
Uwe Hermanne4870472010-11-04 23:23:47 +0000506 printk(BIOS_ERR, "%s Hypertransport link capability "
507 "not found", dev_path(dev));
Eric Biederman0ac6b412003-09-02 17:16:48 +0000508 break;
509 }
Stefan Reinauer14e22772010-04-27 06:56:47 +0000510
Uwe Hermanne4870472010-11-04 23:23:47 +0000511 /* Update the unitid of the current device. */
Eric Biederman0ac6b412003-09-02 17:16:48 +0000512 flags = pci_read_config16(dev, pos + PCI_CAP_FLAGS);
Stefan Reinauer14e22772010-04-27 06:56:47 +0000513
Uwe Hermanne4870472010-11-04 23:23:47 +0000514 /*
515 * If the devices has a unitid set and is at devfn 0 we are
516 * done. This can happen with shadow hypertransport devices,
517 * or if we have reached the bottom of a HT device chain.
Yinghai Lu13f1c2a2005-07-08 02:49:49 +0000518 */
Uwe Hermanne4870472010-11-04 23:23:47 +0000519 if (flags & 0x1f)
Yinghai Lu13f1c2a2005-07-08 02:49:49 +0000520 break;
Yinghai Luecad5df2007-05-21 18:11:17 +0000521
Uwe Hermanne4870472010-11-04 23:23:47 +0000522 flags &= ~0x1f; /* Mask out base Unit ID. */
523
524 count = (flags >> 5) & 0x1f; /* Het unit count. */
525
Stefan Reinauer08670622009-06-30 15:17:49 +0000526#if CONFIG_HT_CHAIN_END_UNITID_BASE != 0x20
Uwe Hermanne4870472010-11-04 23:23:47 +0000527 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 Lu18c70d72007-09-14 14:58:33 +0000533 end_used = 1;
534 } else {
Stefan Reinauer0dff6e32007-10-23 22:17:45 +0000535 goto end_of_chain;
Yinghai Lu18c70d72007-09-14 14:58:33 +0000536 }
Yinghai Luecad5df2007-05-21 18:11:17 +0000537 }
Stefan Reinauer14e22772010-04-27 06:56:47 +0000538 }
Yinghai Luecad5df2007-05-21 18:11:17 +0000539#endif
540
Uwe Hermanne4870472010-11-04 23:23:47 +0000541 flags |= next_unitid & 0x1f;
542 pci_write_config16(dev, pos + PCI_CAP_FLAGS, flags);
Eric Biederman0ac6b412003-09-02 17:16:48 +0000543
Uwe Hermanne4870472010-11-04 23:23:47 +0000544 /* Update the unitid in the device structure. */
Eric Biederman0ac6b412003-09-02 17:16:48 +0000545 static_count = 1;
Uwe Hermanne4870472010-11-04 23:23:47 +0000546 for (func = dev; func; func = func->sibling) {
Stefan Reinauer2b34db82009-02-28 20:10:20 +0000547 func->path.pci.devfn += (next_unitid << 3);
Stefan Reinauer14e22772010-04-27 06:56:47 +0000548 static_count = (func->path.pci.devfn >> 3)
Uwe Hermanne4870472010-11-04 23:23:47 +0000549 - (dev->path.pci.devfn >> 3) + 1;
Stefan Reinauer7ce8c542005-12-02 21:52:30 +0000550 last_func = func;
Eric Biederman0ac6b412003-09-02 17:16:48 +0000551 }
Eric Biederman0ac6b412003-09-02 17:16:48 +0000552
Uwe Hermanne4870472010-11-04 23:23:47 +0000553 /* 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 Lu18c70d72007-09-14 14:58:33 +0000560 ht_unitid_base[ht_dev_num] = next_unitid;
Stefan Reinauerbbdd8f42005-12-04 21:52:58 +0000561 ht_dev_num++;
Yinghai Luecad5df2007-05-21 18:11:17 +0000562
Stefan Reinauer08670622009-06-30 15:17:49 +0000563#if CONFIG_HT_CHAIN_END_UNITID_BASE != 0x20
Yinghai Lu18c70d72007-09-14 14:58:33 +0000564 if (offset_unitid) {
Uwe Hermanne4870472010-11-04 23:23:47 +0000565 real_last_pos = pos;
Yinghai Lu18c70d72007-09-14 14:58:33 +0000566 real_last_unitid = next_unitid;
Stefan Reinauer7ce8c542005-12-02 21:52:30 +0000567 real_last_dev = dev;
Stefan Reinauer7ce8c542005-12-02 21:52:30 +0000568 }
569#endif
Uwe Hermanne4870472010-11-04 23:23:47 +0000570 next_unitid += count;
571 if (next_unitid > max_unitid)
Yinghai Lu18c70d72007-09-14 14:58:33 +0000572 max_unitid = next_unitid;
Eric Biederman0ac6b412003-09-02 17:16:48 +0000573
Martin Roth63373ed2013-07-08 16:24:19 -0600574 /* Setup the hypertransport link. */
Yinghai Lu13f1c2a2005-07-08 02:49:49 +0000575 bus->reset_needed |= ht_setup_link(&prev, dev, pos);
Eric Biederman0ac6b412003-09-02 17:16:48 +0000576
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000577 printk(BIOS_DEBUG, "%s [%04x/%04x] %s next_unitid: %04x\n",
Uwe Hermanne4870472010-11-04 23:23:47 +0000578 dev_path(dev), dev->vendor, dev->device,
579 (dev->enabled? "enabled" : "disabled"), next_unitid);
Yinghai Lu13f1c2a2005-07-08 02:49:49 +0000580
Yinghai Lu18c70d72007-09-14 14:58:33 +0000581 } while (last_unitid != next_unitid);
Uwe Hermanne4870472010-11-04 23:23:47 +0000582
583end_of_chain:
584
Yinghai Lu90b3e092005-01-26 22:00:20 +0000585#if OPT_HT_LINK == 1
Uwe Hermanne4870472010-11-04 23:23:47 +0000586 if (bus->reset_needed)
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000587 printk(BIOS_INFO, "HyperT reset needed\n");
Uwe Hermanne4870472010-11-04 23:23:47 +0000588 else
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000589 printk(BIOS_DEBUG, "HyperT reset not needed\n");
Eric Biederman0ac6b412003-09-02 17:16:48 +0000590#endif
Stefan Reinauer7ce8c542005-12-02 21:52:30 +0000591
Stefan Reinauer08670622009-06-30 15:17:49 +0000592#if CONFIG_HT_CHAIN_END_UNITID_BASE != 0x20
Uwe Hermanne4870472010-11-04 23:23:47 +0000593 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 Reinauer7ce8c542005-12-02 21:52:30 +0000603
Uwe Hermanne4870472010-11-04 23:23:47 +0000604 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 Reinauer7ce8c542005-12-02 21:52:30 +0000607 last_func = func;
Uwe Hermanne4870472010-11-04 23:23:47 +0000608 }
Yinghai Luecad5df2007-05-21 18:11:17 +0000609
Uwe Hermanne4870472010-11-04 23:23:47 +0000610 /* Update last one. */
611 ht_unitid_base[ht_dev_num-1] = CONFIG_HT_CHAIN_END_UNITID_BASE;
Stefan Reinauer14e22772010-04-27 06:56:47 +0000612
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000613 printk(BIOS_DEBUG, " unitid: %04x --> %04x\n",
Uwe Hermanne4870472010-11-04 23:23:47 +0000614 real_last_unitid, CONFIG_HT_CHAIN_END_UNITID_BASE);
615 }
Stefan Reinauer7ce8c542005-12-02 21:52:30 +0000616#endif
Yinghai Lu18c70d72007-09-14 14:58:33 +0000617 next_unitid = max_unitid;
Stefan Reinauer7ce8c542005-12-02 21:52:30 +0000618
Uwe Hermanne4870472010-11-04 23:23:47 +0000619 if (next_unitid > 0x20)
Yinghai Lu18c70d72007-09-14 14:58:33 +0000620 next_unitid = 0x20;
Yinghai Lu13f1c2a2005-07-08 02:49:49 +0000621
Uwe Hermanne4870472010-11-04 23:23:47 +0000622 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 Lu13f1c2a2005-07-08 02:49:49 +0000628 */
Uwe Hermanne4870472010-11-04 23:23:47 +0000629 if (old_devices) {
Yinghai Lu13f1c2a2005-07-08 02:49:49 +0000630 device_t left;
Uwe Hermanne4870472010-11-04 23:23:47 +0000631 for (left = old_devices; left; left = left->sibling)
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000632 printk(BIOS_DEBUG, "%s\n", dev_path(left));
Uwe Hermanne4870472010-11-04 23:23:47 +0000633
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 Reinauer14e22772010-04-27 06:56:47 +0000642 last_func->sibling = old_devices;
Yinghai Lu13f1c2a2005-07-08 02:49:49 +0000643 }
Stefan Reinauer7ce8c542005-12-02 21:52:30 +0000644
Uwe Hermanne4870472010-11-04 23:23:47 +0000645 /* 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 Reinauer14e22772010-04-27 06:56:47 +0000647 return max;
Eric Biederman0ac6b412003-09-02 17:16:48 +0000648}
Yinghai Lu13f1c2a2005-07-08 02:49:49 +0000649
650/**
Uwe Hermannc1ee4292010-10-17 19:01:48 +0000651 * Scan a PCI bridge and the buses behind the bridge.
Yinghai Lu13f1c2a2005-07-08 02:49:49 +0000652 *
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 Hermannc1ee4292010-10-17 19:01:48 +0000658 * @param bus TODO
659 * @param min_devfn TODO
660 * @param max_devfn TODO
Martin Roth63373ed2013-07-08 16:24:19 -0600661 * @param max The highest bus number assigned up to now.
Uwe Hermannc1ee4292010-10-17 19:01:48 +0000662 * @return The maximum bus number found, after scanning all subordinate busses.
Yinghai Lu13f1c2a2005-07-08 02:49:49 +0000663 */
Myles Watson7943fe62009-10-30 02:08:07 +0000664static unsigned int hypertransport_scan_chain_x(struct bus *bus,
Uwe Hermanne4870472010-11-04 23:23:47 +0000665 unsigned int min_devfn, unsigned int max_devfn, unsigned int max)
Yinghai Lud4b278c2006-10-04 20:46:15 +0000666{
Uwe Hermanne4870472010-11-04 23:23:47 +0000667 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 Lud4b278c2006-10-04 20:46:15 +0000671}
672
Yinghai Lu13f1c2a2005-07-08 02:49:49 +0000673unsigned int ht_scan_bridge(struct device *dev, unsigned int max)
674{
Yinghai Lud4b278c2006-10-04 20:46:15 +0000675 return do_pci_scan_bridge(dev, max, hypertransport_scan_chain_x);
Yinghai Lu13f1c2a2005-07-08 02:49:49 +0000676}
677
Yinghai Lu13f1c2a2005-07-08 02:49:49 +0000678/** Default device operations for hypertransport bridges */
679static struct pci_operations ht_bus_ops_pci = {
680 .set_subsystem = 0,
681};
682
683struct 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 Hermanne4870472010-11-04 23:23:47 +0000687 .init = 0,
688 .scan_bus = ht_scan_bridge,
Yinghai Lu13f1c2a2005-07-08 02:49:49 +0000689 .enable = 0,
690 .reset_bus = pci_bus_reset,
691 .ops_pci = &ht_bus_ops_pci,
692};