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