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 |
Patrick Georgi | b890a12 | 2015-03-26 15:17:45 +0100 | [diff] [blame] | 23 | * Foundation, Inc. |
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 | |
Kyösti Mälkki | c3f6bb0 | 2015-02-03 12:18:02 +0200 | [diff] [blame] | 34 | struct ht_link { |
| 35 | struct device *dev; |
| 36 | unsigned pos; |
| 37 | unsigned char ctrl_off, config_off, freq_off, freq_cap_off; |
| 38 | }; |
arch import user (historical) | ef03afa | 2005-07-06 17:15:30 +0000 | [diff] [blame] | 39 | |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 40 | static device_t ht_scan_get_devs(device_t *old_devices) |
| 41 | { |
| 42 | device_t first, last; |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 43 | |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 44 | first = *old_devices; |
| 45 | last = first; |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 46 | |
| 47 | /* |
| 48 | * Extract the chain of devices to (first through last) for the next |
| 49 | * hypertransport device. |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 50 | */ |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 51 | while (last && last->sibling && |
| 52 | (last->sibling->path.type == DEVICE_PATH_PCI) && |
| 53 | (last->sibling->path.pci.devfn > last->path.pci.devfn)) |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 54 | { |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 55 | last = last->sibling; |
| 56 | } |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 57 | |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 58 | if (first) { |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 59 | device_t child; |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 60 | |
| 61 | /* Unlink the chain from the list of old devices. */ |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 62 | *old_devices = last->sibling; |
| 63 | last->sibling = 0; |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 64 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 65 | /* Now add the device to the list of devices on the bus. */ |
| 66 | /* Find the last child of our parent. */ |
| 67 | for (child = first->bus->children; child && child->sibling; ) |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 68 | child = child->sibling; |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 69 | |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 70 | /* Place the chain on the list of children of their parent. */ |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 71 | if (child) |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 72 | child->sibling = first; |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 73 | else |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 74 | first->bus->children = first; |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 75 | } |
| 76 | return first; |
| 77 | } |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 78 | |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 79 | 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] | 80 | { |
Stefan Reinauer | 0dff6e3 | 2007-10-23 22:17:45 +0000 | [diff] [blame] | 81 | struct ht_link cur[1]; |
Yinghai Lu | 1f1085b | 2005-01-17 21:37:12 +0000 | [diff] [blame] | 82 | int linkb_to_host; |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 83 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 84 | /* Set the hypertransport link width and frequency. */ |
Kyösti Mälkki | c3f6bb0 | 2015-02-03 12:18:02 +0200 | [diff] [blame] | 85 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 86 | /* |
| 87 | * See which side of the device our previous write to set the unitid |
| 88 | * came from. |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 89 | */ |
| 90 | cur->dev = dev; |
| 91 | cur->pos = pos; |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 92 | linkb_to_host = |
| 93 | (pci_read_config16(cur->dev, cur->pos + PCI_CAP_FLAGS) >> 10) & 1; |
| 94 | |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 95 | if (!linkb_to_host) { |
| 96 | cur->ctrl_off = PCI_HT_CAP_SLAVE_CTRL0; |
| 97 | cur->config_off = PCI_HT_CAP_SLAVE_WIDTH0; |
| 98 | cur->freq_off = PCI_HT_CAP_SLAVE_FREQ0; |
| 99 | cur->freq_cap_off = PCI_HT_CAP_SLAVE_FREQ_CAP0; |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 100 | } else { |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 101 | cur->ctrl_off = PCI_HT_CAP_SLAVE_CTRL1; |
| 102 | cur->config_off = PCI_HT_CAP_SLAVE_WIDTH1; |
| 103 | cur->freq_off = PCI_HT_CAP_SLAVE_FREQ1; |
| 104 | cur->freq_cap_off = PCI_HT_CAP_SLAVE_FREQ_CAP1; |
| 105 | } |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 106 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 107 | /* |
| 108 | * Remember the current link as the previous link, but look at the |
| 109 | * other offsets. |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 110 | */ |
| 111 | prev->dev = cur->dev; |
| 112 | prev->pos = cur->pos; |
| 113 | if (cur->ctrl_off == PCI_HT_CAP_SLAVE_CTRL0) { |
| 114 | prev->ctrl_off = PCI_HT_CAP_SLAVE_CTRL1; |
| 115 | prev->config_off = PCI_HT_CAP_SLAVE_WIDTH1; |
| 116 | prev->freq_off = PCI_HT_CAP_SLAVE_FREQ1; |
| 117 | prev->freq_cap_off = PCI_HT_CAP_SLAVE_FREQ_CAP1; |
| 118 | } else { |
| 119 | prev->ctrl_off = PCI_HT_CAP_SLAVE_CTRL0; |
| 120 | prev->config_off = PCI_HT_CAP_SLAVE_WIDTH0; |
| 121 | prev->freq_off = PCI_HT_CAP_SLAVE_FREQ0; |
| 122 | prev->freq_cap_off = PCI_HT_CAP_SLAVE_FREQ_CAP0; |
| 123 | } |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 124 | |
Kyösti Mälkki | c3f6bb0 | 2015-02-03 12:18:02 +0200 | [diff] [blame] | 125 | return 0; |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | static unsigned ht_lookup_slave_capability(struct device *dev) |
| 129 | { |
| 130 | unsigned pos; |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 131 | |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 132 | pos = 0; |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 133 | do { |
| 134 | pos = pci_find_next_capability(dev, PCI_CAP_ID_HT, pos); |
| 135 | if (pos) { |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 136 | u16 flags; |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 137 | flags = pci_read_config16(dev, pos + PCI_CAP_FLAGS); |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 138 | printk(BIOS_SPEW, "flags: 0x%04x\n", flags); |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 139 | if ((flags >> 13) == 0) { |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 140 | /* Entry is a slave secondary, success... */ |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 141 | break; |
| 142 | } |
| 143 | } |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 144 | } while (pos); |
| 145 | |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 146 | return pos; |
| 147 | } |
| 148 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 149 | static void ht_collapse_early_enumeration(struct bus *bus, |
| 150 | unsigned offset_unitid) |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 151 | { |
| 152 | unsigned int devfn; |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 153 | struct ht_link prev; |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 154 | u16 ctrl; |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 155 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 156 | /* Initialize the hypertransport enumeration state. */ |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 157 | prev.dev = bus->dev; |
| 158 | prev.pos = bus->cap; |
| 159 | prev.ctrl_off = PCI_HT_CAP_HOST_CTRL; |
| 160 | prev.config_off = PCI_HT_CAP_HOST_WIDTH; |
| 161 | prev.freq_off = PCI_HT_CAP_HOST_FREQ; |
| 162 | prev.freq_cap_off = PCI_HT_CAP_HOST_FREQ_CAP; |
| 163 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 164 | /* Wait until the link initialization is complete. */ |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 165 | do { |
| 166 | ctrl = pci_read_config16(prev.dev, prev.pos + prev.ctrl_off); |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 167 | |
| 168 | /* Is this the end of the hypertransport chain? */ |
| 169 | if (ctrl & (1 << 6)) |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 170 | return; |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 171 | |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 172 | /* Has the link failed? */ |
| 173 | if (ctrl & (1 << 4)) { |
Stefan Reinauer | cf648c9 | 2006-04-11 19:23:57 +0000 | [diff] [blame] | 174 | /* |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 175 | * Either the link has failed, or we have a CRC error. |
| 176 | * Sometimes this can happen due to link retrain, so |
| 177 | * lets knock it down and see if its transient. |
Stefan Reinauer | cf648c9 | 2006-04-11 19:23:57 +0000 | [diff] [blame] | 178 | */ |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 179 | ctrl |= ((1 << 4) | (1 << 8)); /* Link fail + CRC */ |
| 180 | pci_write_config16(prev.dev, prev.pos + prev.ctrl_off, |
| 181 | ctrl); |
| 182 | ctrl = pci_read_config16(prev.dev, |
| 183 | prev.pos + prev.ctrl_off); |
Stefan Reinauer | cf648c9 | 2006-04-11 19:23:57 +0000 | [diff] [blame] | 184 | if (ctrl & ((1 << 4) | (1 << 8))) { |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 185 | printk(BIOS_ALERT, "Detected error on " |
| 186 | "Hypertransport link\n"); |
Stefan Reinauer | cf648c9 | 2006-04-11 19:23:57 +0000 | [diff] [blame] | 187 | return; |
| 188 | } |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 189 | } |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 190 | } while ((ctrl & (1 << 5)) == 0); |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 191 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 192 | /* Actually, only for one HT device HT chain, and unitid is 0. */ |
Patrick Georgi | e166782 | 2012-05-05 15:29:32 +0200 | [diff] [blame] | 193 | #if !CONFIG_HT_CHAIN_UNITID_BASE |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 194 | if (offset_unitid) |
| 195 | return; |
Stefan Reinauer | 7ce8c54 | 2005-12-02 21:52:30 +0000 | [diff] [blame] | 196 | #endif |
| 197 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 198 | /* Check if is already collapsed. */ |
| 199 | if ((!offset_unitid) || (offset_unitid |
| 200 | && (!((CONFIG_HT_CHAIN_END_UNITID_BASE == 0) |
| 201 | && (CONFIG_HT_CHAIN_END_UNITID_BASE |
| 202 | < CONFIG_HT_CHAIN_UNITID_BASE))))) { |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 203 | |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 204 | struct device dummy; |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 205 | u32 id; |
| 206 | |
| 207 | dummy.bus = bus; |
| 208 | dummy.path.type = DEVICE_PATH_PCI; |
| 209 | dummy.path.pci.devfn = PCI_DEVFN(0, 0); |
| 210 | |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 211 | id = pci_read_config32(&dummy, PCI_VENDOR_ID); |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 212 | if (!((id == 0xffffffff) || (id == 0x00000000) |
| 213 | || (id == 0x0000ffff) || (id == 0xffff0000))) { |
| 214 | return; |
| 215 | } |
| 216 | } |
| 217 | |
| 218 | /* Spin through the devices and collapse any early HT enumeration. */ |
| 219 | for (devfn = PCI_DEVFN(1, 0); devfn <= 0xff; devfn += 8) { |
| 220 | struct device dummy; |
| 221 | u32 id; |
| 222 | unsigned pos, flags; |
| 223 | |
| 224 | dummy.bus = bus; |
| 225 | dummy.path.type = DEVICE_PATH_PCI; |
| 226 | dummy.path.pci.devfn = devfn; |
| 227 | |
| 228 | id = pci_read_config32(&dummy, PCI_VENDOR_ID); |
| 229 | if ((id == 0xffffffff) || (id == 0x00000000) |
| 230 | || (id == 0x0000ffff) || (id == 0xffff0000)) { |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 231 | continue; |
| 232 | } |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 233 | |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 234 | dummy.vendor = id & 0xffff; |
| 235 | dummy.device = (id >> 16) & 0xffff; |
| 236 | dummy.hdr_type = pci_read_config8(&dummy, PCI_HEADER_TYPE); |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 237 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 238 | pos = ht_lookup_slave_capability(&dummy); |
| 239 | if (!pos) |
| 240 | continue; |
| 241 | |
| 242 | /* Clear the unitid. */ |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 243 | flags = pci_read_config16(&dummy, pos + PCI_CAP_FLAGS); |
| 244 | flags &= ~0x1f; |
| 245 | pci_write_config16(&dummy, pos + PCI_CAP_FLAGS, flags); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 246 | printk(BIOS_SPEW, "Collapsing %s [%04x/%04x]\n", |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 247 | dev_path(&dummy), dummy.vendor, dummy.device); |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 248 | } |
| 249 | } |
| 250 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 251 | unsigned int hypertransport_scan_chain(struct bus *bus, unsigned min_devfn, |
Kyösti Mälkki | b39714e | 2015-03-12 16:16:59 +0200 | [diff] [blame] | 252 | unsigned max_devfn, |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 253 | unsigned *ht_unitid_base, |
| 254 | unsigned offset_unitid) |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 255 | { |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 256 | /* |
| 257 | * Even CONFIG_HT_CHAIN_UNITID_BASE == 0, we still can go through this |
| 258 | * function, because of end_of_chain check. Also, we need it to |
| 259 | * optimize link. |
| 260 | */ |
| 261 | unsigned int next_unitid, last_unitid, min_unitid, max_unitid; |
| 262 | device_t old_devices, dev, func, last_func = 0; |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 263 | struct ht_link prev; |
Stefan Reinauer | bbdd8f4 | 2005-12-04 21:52:58 +0000 | [diff] [blame] | 264 | int ht_dev_num = 0; |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 265 | |
| 266 | min_unitid = (offset_unitid) ? CONFIG_HT_CHAIN_UNITID_BASE : 1; |
Stefan Reinauer | 7ce8c54 | 2005-12-02 21:52:30 +0000 | [diff] [blame] | 267 | |
Stefan Reinauer | 0867062 | 2009-06-30 15:17:49 +0000 | [diff] [blame] | 268 | #if CONFIG_HT_CHAIN_END_UNITID_BASE != 0x20 |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 269 | /* |
| 270 | * Let's record the device of last HT device, so we can set the unitid |
| 271 | * to CONFIG_HT_CHAIN_END_UNITID_BASE. |
| 272 | */ |
| 273 | unsigned int real_last_unitid = 0, end_used = 0; |
| 274 | u8 real_last_pos = 0; |
| 275 | device_t real_last_dev = NULL; |
Stefan Reinauer | 7ce8c54 | 2005-12-02 21:52:30 +0000 | [diff] [blame] | 276 | #endif |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 277 | |
Martin Roth | 63373ed | 2013-07-08 16:24:19 -0600 | [diff] [blame] | 278 | /* Restore the hypertransport chain to it's uninitialized state. */ |
Stefan Reinauer | 7ce8c54 | 2005-12-02 21:52:30 +0000 | [diff] [blame] | 279 | ht_collapse_early_enumeration(bus, offset_unitid); |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 280 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 281 | /* See which static device nodes I have. */ |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 282 | old_devices = bus->children; |
| 283 | bus->children = 0; |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 284 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 285 | /* Initialize the hypertransport enumeration state. */ |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 286 | prev.dev = bus->dev; |
| 287 | prev.pos = bus->cap; |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 288 | |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 289 | prev.ctrl_off = PCI_HT_CAP_HOST_CTRL; |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 290 | prev.config_off = PCI_HT_CAP_HOST_WIDTH; |
| 291 | prev.freq_off = PCI_HT_CAP_HOST_FREQ; |
| 292 | prev.freq_cap_off = PCI_HT_CAP_HOST_FREQ_CAP; |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 293 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 294 | /* If present, assign unitid to a hypertransport chain. */ |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 295 | last_unitid = min_unitid -1; |
Yinghai Lu | 18c70d7 | 2007-09-14 14:58:33 +0000 | [diff] [blame] | 296 | max_unitid = next_unitid = min_unitid; |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 297 | do { |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 298 | u8 pos; |
| 299 | u16 flags, ctrl; |
| 300 | unsigned int count, static_count; |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 301 | |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 302 | last_unitid = next_unitid; |
| 303 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 304 | /* Wait until the link initialization is complete. */ |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 305 | do { |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 306 | ctrl = pci_read_config16(prev.dev, |
| 307 | prev.pos + prev.ctrl_off); |
Stefan Reinauer | cf648c9 | 2006-04-11 19:23:57 +0000 | [diff] [blame] | 308 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 309 | /* End of chain? */ |
Stefan Reinauer | cf648c9 | 2006-04-11 19:23:57 +0000 | [diff] [blame] | 310 | if (ctrl & (1 << 6)) |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 311 | goto end_of_chain; |
Stefan Reinauer | cf648c9 | 2006-04-11 19:23:57 +0000 | [diff] [blame] | 312 | |
| 313 | if (ctrl & ((1 << 4) | (1 << 8))) { |
| 314 | /* |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 315 | * Either the link has failed, or we have a CRC |
| 316 | * error. Sometimes this can happen due to link |
| 317 | * retrain, so lets knock it down and see if |
| 318 | * it's transient. |
Stefan Reinauer | cf648c9 | 2006-04-11 19:23:57 +0000 | [diff] [blame] | 319 | */ |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 320 | ctrl |= ((1 << 4) | (1 <<8)); // Link fail + CRC |
| 321 | pci_write_config16(prev.dev, |
| 322 | prev.pos + prev.ctrl_off, ctrl); |
| 323 | ctrl = pci_read_config16(prev.dev, |
| 324 | prev.pos + prev.ctrl_off); |
Stefan Reinauer | cf648c9 | 2006-04-11 19:23:57 +0000 | [diff] [blame] | 325 | if (ctrl & ((1 << 4) | (1 << 8))) { |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 326 | printk(BIOS_ALERT, "Detected error on " |
| 327 | "hypertransport link\n"); |
Stefan Reinauer | cf648c9 | 2006-04-11 19:23:57 +0000 | [diff] [blame] | 328 | goto end_of_chain; |
| 329 | } |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 330 | } |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 331 | } while ((ctrl & (1 << 5)) == 0); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 332 | |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 333 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 334 | /* Get and setup the device_structure. */ |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 335 | dev = ht_scan_get_devs(&old_devices); |
| 336 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 337 | /* See if a device is present and setup the device structure. */ |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 338 | dev = pci_probe_dev(dev, bus, 0); |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 339 | if (!dev || !dev->enabled) |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 340 | break; |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 341 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 342 | /* Find the hypertransport link capability. */ |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 343 | pos = ht_lookup_slave_capability(dev); |
| 344 | if (pos == 0) { |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 345 | printk(BIOS_ERR, "%s Hypertransport link capability " |
| 346 | "not found", dev_path(dev)); |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 347 | break; |
| 348 | } |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 349 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 350 | /* Update the unitid of the current device. */ |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 351 | flags = pci_read_config16(dev, pos + PCI_CAP_FLAGS); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 352 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 353 | /* |
Timothy Pearson | d0c1dd0 | 2015-01-23 20:22:56 -0600 | [diff] [blame] | 354 | * 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] | 355 | * done. This can happen with shadow hypertransport devices, |
| 356 | * or if we have reached the bottom of a HT device chain. |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 357 | */ |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 358 | if (flags & 0x1f) |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 359 | break; |
Yinghai Lu | ecad5df | 2007-05-21 18:11:17 +0000 | [diff] [blame] | 360 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 361 | flags &= ~0x1f; /* Mask out base Unit ID. */ |
| 362 | |
| 363 | count = (flags >> 5) & 0x1f; /* Het unit count. */ |
| 364 | |
Stefan Reinauer | 0867062 | 2009-06-30 15:17:49 +0000 | [diff] [blame] | 365 | #if CONFIG_HT_CHAIN_END_UNITID_BASE != 0x20 |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 366 | if (offset_unitid) { |
| 367 | /* max_devfn will be (0x17<<3)|7 or (0x1f<<3)|7. */ |
| 368 | if (next_unitid > (max_devfn >> 3)) { |
| 369 | if (!end_used) { |
| 370 | next_unitid = |
| 371 | CONFIG_HT_CHAIN_END_UNITID_BASE; |
Yinghai Lu | 18c70d7 | 2007-09-14 14:58:33 +0000 | [diff] [blame] | 372 | end_used = 1; |
| 373 | } else { |
Stefan Reinauer | 0dff6e3 | 2007-10-23 22:17:45 +0000 | [diff] [blame] | 374 | goto end_of_chain; |
Yinghai Lu | 18c70d7 | 2007-09-14 14:58:33 +0000 | [diff] [blame] | 375 | } |
Yinghai Lu | ecad5df | 2007-05-21 18:11:17 +0000 | [diff] [blame] | 376 | } |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 377 | } |
Yinghai Lu | ecad5df | 2007-05-21 18:11:17 +0000 | [diff] [blame] | 378 | #endif |
| 379 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 380 | flags |= next_unitid & 0x1f; |
| 381 | pci_write_config16(dev, pos + PCI_CAP_FLAGS, flags); |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 382 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 383 | /* Update the unitid in the device structure. */ |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 384 | static_count = 1; |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 385 | for (func = dev; func; func = func->sibling) { |
Stefan Reinauer | 2b34db8 | 2009-02-28 20:10:20 +0000 | [diff] [blame] | 386 | func->path.pci.devfn += (next_unitid << 3); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 387 | static_count = (func->path.pci.devfn >> 3) |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 388 | - (dev->path.pci.devfn >> 3) + 1; |
Stefan Reinauer | 7ce8c54 | 2005-12-02 21:52:30 +0000 | [diff] [blame] | 389 | last_func = func; |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 390 | } |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 391 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 392 | /* Compute the number of unitids consumed. */ |
| 393 | printk(BIOS_SPEW, "%s count: %04x static_count: %04x\n", |
| 394 | dev_path(dev), count, static_count); |
| 395 | if (count < static_count) |
| 396 | count = static_count; |
| 397 | |
| 398 | /* Update the unitid of the next device. */ |
Yinghai Lu | 18c70d7 | 2007-09-14 14:58:33 +0000 | [diff] [blame] | 399 | ht_unitid_base[ht_dev_num] = next_unitid; |
Stefan Reinauer | bbdd8f4 | 2005-12-04 21:52:58 +0000 | [diff] [blame] | 400 | ht_dev_num++; |
Yinghai Lu | ecad5df | 2007-05-21 18:11:17 +0000 | [diff] [blame] | 401 | |
Stefan Reinauer | 0867062 | 2009-06-30 15:17:49 +0000 | [diff] [blame] | 402 | #if CONFIG_HT_CHAIN_END_UNITID_BASE != 0x20 |
Yinghai Lu | 18c70d7 | 2007-09-14 14:58:33 +0000 | [diff] [blame] | 403 | if (offset_unitid) { |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 404 | real_last_pos = pos; |
Yinghai Lu | 18c70d7 | 2007-09-14 14:58:33 +0000 | [diff] [blame] | 405 | real_last_unitid = next_unitid; |
Stefan Reinauer | 7ce8c54 | 2005-12-02 21:52:30 +0000 | [diff] [blame] | 406 | real_last_dev = dev; |
Stefan Reinauer | 7ce8c54 | 2005-12-02 21:52:30 +0000 | [diff] [blame] | 407 | } |
| 408 | #endif |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 409 | next_unitid += count; |
| 410 | if (next_unitid > max_unitid) |
Yinghai Lu | 18c70d7 | 2007-09-14 14:58:33 +0000 | [diff] [blame] | 411 | max_unitid = next_unitid; |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 412 | |
Martin Roth | 63373ed | 2013-07-08 16:24:19 -0600 | [diff] [blame] | 413 | /* Setup the hypertransport link. */ |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 414 | bus->reset_needed |= ht_setup_link(&prev, dev, pos); |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 415 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 416 | printk(BIOS_DEBUG, "%s [%04x/%04x] %s next_unitid: %04x\n", |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 417 | dev_path(dev), dev->vendor, dev->device, |
| 418 | (dev->enabled? "enabled" : "disabled"), next_unitid); |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 419 | |
Yinghai Lu | 18c70d7 | 2007-09-14 14:58:33 +0000 | [diff] [blame] | 420 | } while (last_unitid != next_unitid); |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 421 | |
| 422 | end_of_chain: |
| 423 | |
Stefan Reinauer | 0867062 | 2009-06-30 15:17:49 +0000 | [diff] [blame] | 424 | #if CONFIG_HT_CHAIN_END_UNITID_BASE != 0x20 |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 425 | if (offset_unitid && (ht_dev_num > 1) |
| 426 | && (real_last_unitid != CONFIG_HT_CHAIN_END_UNITID_BASE) |
| 427 | && !end_used) { |
| 428 | u16 flags; |
| 429 | flags = pci_read_config16(real_last_dev, |
| 430 | real_last_pos + PCI_CAP_FLAGS); |
| 431 | flags &= ~0x1f; |
| 432 | flags |= CONFIG_HT_CHAIN_END_UNITID_BASE & 0x1f; |
| 433 | pci_write_config16(real_last_dev, |
| 434 | real_last_pos + PCI_CAP_FLAGS, flags); |
Stefan Reinauer | 7ce8c54 | 2005-12-02 21:52:30 +0000 | [diff] [blame] | 435 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 436 | for (func = real_last_dev; func; func = func->sibling) { |
| 437 | func->path.pci.devfn -= ((real_last_unitid |
| 438 | - CONFIG_HT_CHAIN_END_UNITID_BASE) << 3); |
Stefan Reinauer | 7ce8c54 | 2005-12-02 21:52:30 +0000 | [diff] [blame] | 439 | last_func = func; |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 440 | } |
Yinghai Lu | ecad5df | 2007-05-21 18:11:17 +0000 | [diff] [blame] | 441 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 442 | /* Update last one. */ |
| 443 | 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] | 444 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 445 | printk(BIOS_DEBUG, " unitid: %04x --> %04x\n", |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 446 | real_last_unitid, CONFIG_HT_CHAIN_END_UNITID_BASE); |
| 447 | } |
Stefan Reinauer | 7ce8c54 | 2005-12-02 21:52:30 +0000 | [diff] [blame] | 448 | #endif |
Yinghai Lu | 18c70d7 | 2007-09-14 14:58:33 +0000 | [diff] [blame] | 449 | next_unitid = max_unitid; |
Stefan Reinauer | 7ce8c54 | 2005-12-02 21:52:30 +0000 | [diff] [blame] | 450 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 451 | if (next_unitid > 0x20) |
Yinghai Lu | 18c70d7 | 2007-09-14 14:58:33 +0000 | [diff] [blame] | 452 | next_unitid = 0x20; |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 453 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 454 | if ((bus->secondary == 0) && (next_unitid > 0x18)) |
| 455 | next_unitid = 0x18; /* Avoid K8 on bus 0. */ |
| 456 | |
| 457 | /* |
| 458 | * Die if any leftover static devices are are found. There's probably |
| 459 | * a problem in devicetree.cb. |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 460 | */ |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 461 | if (old_devices) { |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 462 | device_t left; |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 463 | for (left = old_devices; left; left = left->sibling) |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 464 | printk(BIOS_DEBUG, "%s\n", dev_path(left)); |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 465 | |
| 466 | printk(BIOS_ERR, "HT: Leftover static devices. " |
| 467 | "Check your devicetree.cb\n"); |
| 468 | |
| 469 | /* |
| 470 | * Put back the leftover static device, and let pci_scan_bus() |
| 471 | * disable it. |
| 472 | */ |
| 473 | if (last_func && !last_func->sibling) |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 474 | last_func->sibling = old_devices; |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 475 | } |
Stefan Reinauer | 7ce8c54 | 2005-12-02 21:52:30 +0000 | [diff] [blame] | 476 | |
Kyösti Mälkki | b39714e | 2015-03-12 16:16:59 +0200 | [diff] [blame] | 477 | return next_unitid; |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 478 | } |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 479 | |
| 480 | /** |
Uwe Hermann | c1ee429 | 2010-10-17 19:01:48 +0000 | [diff] [blame] | 481 | * Scan a PCI bridge and the buses behind the bridge. |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 482 | * |
| 483 | * Determine the existence of buses behind the bridge. Set up the bridge |
| 484 | * according to the result of the scan. |
| 485 | * |
| 486 | * This function is the default scan_bus() method for PCI bridge devices. |
| 487 | * |
Uwe Hermann | c1ee429 | 2010-10-17 19:01:48 +0000 | [diff] [blame] | 488 | * @param bus TODO |
| 489 | * @param min_devfn TODO |
| 490 | * @param max_devfn TODO |
Martin Roth | 63373ed | 2013-07-08 16:24:19 -0600 | [diff] [blame] | 491 | * @param max The highest bus number assigned up to now. |
Uwe Hermann | c1ee429 | 2010-10-17 19:01:48 +0000 | [diff] [blame] | 492 | * @return The maximum bus number found, after scanning all subordinate busses. |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 493 | */ |
Myles Watson | 7943fe6 | 2009-10-30 02:08:07 +0000 | [diff] [blame] | 494 | static unsigned int hypertransport_scan_chain_x(struct bus *bus, |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 495 | unsigned int min_devfn, unsigned int max_devfn, unsigned int max) |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 496 | { |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 497 | unsigned int ht_unitid_base[4]; |
| 498 | unsigned int offset_unitid = 1; |
Kyösti Mälkki | b39714e | 2015-03-12 16:16:59 +0200 | [diff] [blame] | 499 | |
| 500 | unsigned int next_unitid = hypertransport_scan_chain(bus, min_devfn, max_devfn, |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 501 | ht_unitid_base, offset_unitid); |
Kyösti Mälkki | b39714e | 2015-03-12 16:16:59 +0200 | [diff] [blame] | 502 | |
| 503 | /* Now that nothing is overlapping it is safe to scan the children. */ |
Kyösti Mälkki | 6ccf119 | 2015-03-12 05:56:22 +0200 | [diff] [blame^] | 504 | bus->subordinate = pci_scan_bus(bus, 0x00, ((next_unitid - 1) << 3) | 7, bus->secondary); |
| 505 | return bus->subordinate; |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 506 | } |
| 507 | |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 508 | unsigned int ht_scan_bridge(struct device *dev, unsigned int max) |
| 509 | { |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 510 | return do_pci_scan_bridge(dev, max, hypertransport_scan_chain_x); |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 511 | } |
| 512 | |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 513 | /** Default device operations for hypertransport bridges */ |
| 514 | static struct pci_operations ht_bus_ops_pci = { |
| 515 | .set_subsystem = 0, |
| 516 | }; |
| 517 | |
| 518 | struct device_operations default_ht_ops_bus = { |
| 519 | .read_resources = pci_bus_read_resources, |
| 520 | .set_resources = pci_dev_set_resources, |
| 521 | .enable_resources = pci_bus_enable_resources, |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 522 | .init = 0, |
| 523 | .scan_bus = ht_scan_bridge, |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 524 | .enable = 0, |
| 525 | .reset_bus = pci_bus_reset, |
| 526 | .ops_pci = &ht_bus_ops_pci, |
| 527 | }; |