Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 1 | #include <bitops.h> |
| 2 | #include <console/console.h> |
| 3 | #include <device/device.h> |
| 4 | #include <device/path.h> |
| 5 | #include <device/pci.h> |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 6 | #include <device/pci_ids.h> |
Eric Biederman | ff0e846 | 2003-09-04 03:00:54 +0000 | [diff] [blame] | 7 | #include <device/hypertransport.h> |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 8 | #include <part/hard_reset.h> |
| 9 | #include <part/fallback_boot.h> |
| 10 | |
Yinghai Lu | 90b3e09 | 2005-01-26 22:00:20 +0000 | [diff] [blame] | 11 | #define OPT_HT_LINK 0 |
| 12 | |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 13 | static device_t ht_scan_get_devs(device_t *old_devices) |
| 14 | { |
| 15 | device_t first, last; |
| 16 | first = *old_devices; |
| 17 | last = first; |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 18 | while(last && last->sibling && |
| 19 | (last->sibling->path.type == DEVICE_PATH_PCI) && |
| 20 | (last->sibling->path.u.pci.devfn > last->path.u.pci.devfn)) { |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 21 | last = last->sibling; |
| 22 | } |
| 23 | if (first) { |
| 24 | *old_devices = last->sibling; |
| 25 | last->sibling = 0; |
| 26 | } |
| 27 | return first; |
| 28 | } |
Yinghai Lu | 90b3e09 | 2005-01-26 22:00:20 +0000 | [diff] [blame] | 29 | #if OPT_HT_LINK == 1 |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 30 | static unsigned ht_read_freq_cap(device_t dev, unsigned pos) |
| 31 | { |
| 32 | /* Handle bugs in valid hypertransport frequency reporting */ |
| 33 | unsigned freq_cap; |
| 34 | |
| 35 | freq_cap = pci_read_config16(dev, pos); |
| 36 | freq_cap &= ~(1 << HT_FREQ_VENDOR); /* Ignore Vendor HT frequencies */ |
| 37 | |
| 38 | /* AMD 8131 Errata 48 */ |
| 39 | if ((dev->vendor == PCI_VENDOR_ID_AMD) && |
| 40 | (dev->device == PCI_DEVICE_ID_AMD_8131_PCIX)) { |
| 41 | freq_cap &= ~(1 << HT_FREQ_800Mhz); |
Yinghai Lu | 90b3e09 | 2005-01-26 22:00:20 +0000 | [diff] [blame] | 42 | } else |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 43 | /* AMD 8151 Errata 23 */ |
| 44 | if ((dev->vendor == PCI_VENDOR_ID_AMD) && |
| 45 | (dev->device == PCI_DEVICE_ID_AMD_8151_SYSCTRL)) { |
| 46 | freq_cap &= ~(1 << HT_FREQ_800Mhz); |
Yinghai Lu | 90b3e09 | 2005-01-26 22:00:20 +0000 | [diff] [blame] | 47 | } else |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 48 | /* AMD K8 Unsupported 1Ghz? */ |
| 49 | if ((dev->vendor == PCI_VENDOR_ID_AMD) && (dev->device == 0x1100)) { |
Yinghai Lu | 90b3e09 | 2005-01-26 22:00:20 +0000 | [diff] [blame] | 50 | freq_cap &= ~(1 << HT_FREQ_1000Mhz); |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 51 | } |
| 52 | return freq_cap; |
| 53 | } |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 54 | |
| 55 | struct prev_link { |
| 56 | struct device *dev; |
| 57 | unsigned pos; |
| 58 | unsigned char config_off, freq_off, freq_cap_off; |
| 59 | }; |
| 60 | |
| 61 | static int ht_setup_link(struct prev_link *prev, device_t dev, unsigned pos) |
| 62 | { |
| 63 | static const uint8_t link_width_to_pow2[]= { 3, 4, 0, 5, 1, 2, 0, 0 }; |
| 64 | static const uint8_t pow2_to_link_width[] = { 0x7, 4, 5, 0, 1, 3 }; |
| 65 | unsigned present_width_cap, upstream_width_cap; |
| 66 | unsigned present_freq_cap, upstream_freq_cap; |
| 67 | unsigned ln_present_width_in, ln_upstream_width_in; |
| 68 | unsigned ln_present_width_out, ln_upstream_width_out; |
| 69 | unsigned freq, old_freq; |
| 70 | unsigned present_width, upstream_width, old_width; |
| 71 | int reset_needed; |
Yinghai Lu | 1f1085b | 2005-01-17 21:37:12 +0000 | [diff] [blame] | 72 | int linkb_to_host; |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 73 | |
| 74 | /* Set the hypertransport link width and frequency */ |
| 75 | reset_needed = 0; |
Yinghai Lu | 26b2922 | 2005-01-19 01:21:05 +0000 | [diff] [blame] | 76 | linkb_to_host = (pci_read_config16(dev, pos + PCI_CAP_FLAGS) >> 10) & 1; |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 77 | |
| 78 | /* Read the capabilities */ |
Yinghai Lu | 1f1085b | 2005-01-17 21:37:12 +0000 | [diff] [blame] | 79 | present_freq_cap = ht_read_freq_cap(dev, pos + (linkb_to_host ? PCI_HT_CAP_SLAVE_FREQ_CAP1: PCI_HT_CAP_SLAVE_FREQ_CAP0)); |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 80 | upstream_freq_cap = ht_read_freq_cap(prev->dev, prev->pos + prev->freq_cap_off); |
Yinghai Lu | 1f1085b | 2005-01-17 21:37:12 +0000 | [diff] [blame] | 81 | present_width_cap = pci_read_config8(dev, pos + (linkb_to_host ? PCI_HT_CAP_SLAVE_WIDTH1: PCI_HT_CAP_SLAVE_WIDTH0)); |
| 82 | upstream_width_cap = pci_read_config8(prev->dev, prev->pos + prev->config_off); |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 83 | |
| 84 | /* Calculate the highest useable frequency */ |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 85 | freq = log2(present_freq_cap & upstream_freq_cap); |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 86 | |
| 87 | /* Calculate the highest width */ |
| 88 | ln_upstream_width_in = link_width_to_pow2[upstream_width_cap & 7]; |
| 89 | ln_present_width_out = link_width_to_pow2[(present_width_cap >> 4) & 7]; |
| 90 | if (ln_upstream_width_in > ln_present_width_out) { |
| 91 | ln_upstream_width_in = ln_present_width_out; |
| 92 | } |
| 93 | upstream_width = pow2_to_link_width[ln_upstream_width_in]; |
| 94 | present_width = pow2_to_link_width[ln_upstream_width_in] << 4; |
| 95 | |
| 96 | ln_upstream_width_out = link_width_to_pow2[(upstream_width_cap >> 4) & 7]; |
| 97 | ln_present_width_in = link_width_to_pow2[present_width_cap & 7]; |
| 98 | if (ln_upstream_width_out > ln_present_width_in) { |
| 99 | ln_upstream_width_out = ln_present_width_in; |
| 100 | } |
| 101 | upstream_width |= pow2_to_link_width[ln_upstream_width_out] << 4; |
| 102 | present_width |= pow2_to_link_width[ln_upstream_width_out]; |
| 103 | |
| 104 | /* Set the current device */ |
Yinghai Lu | 1f1085b | 2005-01-17 21:37:12 +0000 | [diff] [blame] | 105 | old_freq = pci_read_config8(dev, pos + (linkb_to_host ? PCI_HT_CAP_SLAVE_FREQ1:PCI_HT_CAP_SLAVE_FREQ0)); |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 106 | if (freq != old_freq) { |
Yinghai Lu | 1f1085b | 2005-01-17 21:37:12 +0000 | [diff] [blame] | 107 | pci_write_config8(dev, pos + (linkb_to_host ? PCI_HT_CAP_SLAVE_FREQ1:PCI_HT_CAP_SLAVE_FREQ0), freq); |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 108 | reset_needed = 1; |
| 109 | printk_spew("HyperT FreqP old %x new %x\n",old_freq,freq); |
| 110 | } |
Yinghai Lu | 1f1085b | 2005-01-17 21:37:12 +0000 | [diff] [blame] | 111 | old_width = pci_read_config8(dev, pos + (linkb_to_host ? PCI_HT_CAP_SLAVE_WIDTH1: PCI_HT_CAP_SLAVE_WIDTH0) + 1); |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 112 | if (present_width != old_width) { |
Yinghai Lu | 1f1085b | 2005-01-17 21:37:12 +0000 | [diff] [blame] | 113 | pci_write_config8(dev, pos + (linkb_to_host ? PCI_HT_CAP_SLAVE_WIDTH1: PCI_HT_CAP_SLAVE_WIDTH0) + 1, present_width); |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 114 | reset_needed = 1; |
| 115 | printk_spew("HyperT widthP old %x new %x\n",old_width, present_width); |
| 116 | } |
| 117 | |
| 118 | /* Set the upstream device */ |
| 119 | old_freq = pci_read_config8(prev->dev, prev->pos + prev->freq_off); |
| 120 | old_freq &= 0x0f; |
| 121 | if (freq != old_freq) { |
| 122 | pci_write_config8(prev->dev, prev->pos + prev->freq_off, freq); |
| 123 | reset_needed = 1; |
| 124 | printk_spew("HyperT freqU old %x new %x\n", old_freq, freq); |
| 125 | } |
| 126 | old_width = pci_read_config8(prev->dev, prev->pos + prev->config_off + 1); |
| 127 | if (upstream_width != old_width) { |
| 128 | pci_write_config8(prev->dev, prev->pos + prev->config_off + 1, upstream_width); |
| 129 | reset_needed = 1; |
| 130 | printk_spew("HyperT widthU old %x new %x\n", old_width, upstream_width); |
| 131 | } |
| 132 | |
| 133 | /* Remember the current link as the previous link */ |
| 134 | prev->dev = dev; |
| 135 | prev->pos = pos; |
Yinghai Lu | 1f1085b | 2005-01-17 21:37:12 +0000 | [diff] [blame] | 136 | if(linkb_to_host) { |
| 137 | prev->config_off = PCI_HT_CAP_SLAVE_WIDTH0; |
| 138 | prev->freq_off = PCI_HT_CAP_SLAVE_FREQ0; |
| 139 | prev->freq_cap_off = PCI_HT_CAP_SLAVE_FREQ_CAP0; |
| 140 | } |
| 141 | else { |
| 142 | prev->config_off = PCI_HT_CAP_SLAVE_WIDTH1; |
| 143 | prev->freq_off = PCI_HT_CAP_SLAVE_FREQ1; |
| 144 | prev->freq_cap_off = PCI_HT_CAP_SLAVE_FREQ_CAP1; |
| 145 | } |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 146 | |
| 147 | return reset_needed; |
| 148 | |
| 149 | } |
Yinghai Lu | 90b3e09 | 2005-01-26 22:00:20 +0000 | [diff] [blame] | 150 | #endif |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 151 | |
| 152 | static unsigned ht_lookup_slave_capability(struct device *dev) |
| 153 | { |
| 154 | unsigned pos; |
| 155 | pos = 0; |
| 156 | switch(dev->hdr_type & 0x7f) { |
| 157 | case PCI_HEADER_TYPE_NORMAL: |
| 158 | case PCI_HEADER_TYPE_BRIDGE: |
| 159 | pos = PCI_CAPABILITY_LIST; |
| 160 | break; |
| 161 | } |
| 162 | if (pos > PCI_CAP_LIST_NEXT) { |
| 163 | pos = pci_read_config8(dev, pos); |
| 164 | } |
| 165 | while(pos != 0) { /* loop through the linked list */ |
| 166 | uint8_t cap; |
| 167 | cap = pci_read_config8(dev, pos + PCI_CAP_LIST_ID); |
| 168 | printk_spew("Capability: 0x%02x @ 0x%02x\n", cap, pos); |
| 169 | if (cap == PCI_CAP_ID_HT) { |
| 170 | unsigned flags; |
| 171 | flags = pci_read_config16(dev, pos + PCI_CAP_FLAGS); |
| 172 | printk_spew("flags: 0x%04x\n", (unsigned)flags); |
| 173 | if ((flags >> 13) == 0) { |
| 174 | /* Entry is a Slave secondary, success...*/ |
| 175 | break; |
| 176 | } |
| 177 | } |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 178 | pos = pci_read_config8(dev, pos + PCI_CAP_LIST_NEXT); |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 179 | } |
| 180 | return pos; |
| 181 | } |
| 182 | |
| 183 | static void ht_collapse_early_enumeration(struct bus *bus) |
| 184 | { |
| 185 | unsigned int devfn; |
| 186 | |
| 187 | /* Spin through the devices and collapse any early |
| 188 | * hypertransport enumeration. |
| 189 | */ |
Yinghai Lu | 1f1085b | 2005-01-17 21:37:12 +0000 | [diff] [blame] | 190 | for(devfn = PCI_DEVFN(1, 0); devfn <= 0xff; devfn += 8) { |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 191 | struct device dummy; |
| 192 | uint32_t id; |
| 193 | unsigned pos, flags; |
| 194 | dummy.bus = bus; |
| 195 | dummy.path.type = DEVICE_PATH_PCI; |
| 196 | dummy.path.u.pci.devfn = devfn; |
| 197 | id = pci_read_config32(&dummy, PCI_VENDOR_ID); |
| 198 | if (id == 0xffffffff || id == 0x00000000 || |
| 199 | id == 0x0000ffff || id == 0xffff0000) { |
| 200 | continue; |
| 201 | } |
Yinghai Lu | 1f1085b | 2005-01-17 21:37:12 +0000 | [diff] [blame] | 202 | |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame^] | 203 | #if 0 |
| 204 | #if CK804_DEVN_BASE==0 |
| 205 | //CK804 workaround: |
| 206 | // CK804 UnitID changes not use |
| 207 | if(id == 0x005e10de) { |
| 208 | break; |
| 209 | } |
| 210 | #endif |
| 211 | #endif |
| 212 | |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 213 | dummy.vendor = id & 0xffff; |
| 214 | dummy.device = (id >> 16) & 0xffff; |
| 215 | dummy.hdr_type = pci_read_config8(&dummy, PCI_HEADER_TYPE); |
| 216 | pos = ht_lookup_slave_capability(&dummy); |
| 217 | if (!pos){ |
| 218 | continue; |
| 219 | } |
| 220 | |
| 221 | /* Clear the unitid */ |
| 222 | flags = pci_read_config16(&dummy, pos + PCI_CAP_FLAGS); |
| 223 | flags &= ~0x1f; |
| 224 | pci_write_config16(&dummy, pos + PCI_CAP_FLAGS, flags); |
| 225 | printk_spew("Collapsing %s [%04x/%04x]\n", |
| 226 | dev_path(&dummy), dummy.vendor, dummy.device); |
| 227 | } |
| 228 | } |
| 229 | |
| 230 | unsigned int hypertransport_scan_chain(struct bus *bus, unsigned int max) |
| 231 | { |
| 232 | unsigned next_unitid, last_unitid, previous_unitid; |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 233 | device_t old_devices, dev, func, *chain_last; |
| 234 | unsigned min_unitid = 1; |
Yinghai Lu | 90b3e09 | 2005-01-26 22:00:20 +0000 | [diff] [blame] | 235 | #if OPT_HT_LINK == 1 |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 236 | int reset_needed; |
| 237 | struct prev_link prev; |
Yinghai Lu | 90b3e09 | 2005-01-26 22:00:20 +0000 | [diff] [blame] | 238 | #endif |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 239 | |
| 240 | /* Restore the hypertransport chain to it's unitialized state */ |
| 241 | ht_collapse_early_enumeration(bus); |
| 242 | |
| 243 | /* See which static device nodes I have */ |
| 244 | old_devices = bus->children; |
| 245 | bus->children = 0; |
| 246 | chain_last = &bus->children; |
| 247 | |
| 248 | /* Initialize the hypertransport enumeration state */ |
Yinghai Lu | 90b3e09 | 2005-01-26 22:00:20 +0000 | [diff] [blame] | 249 | #if OPT_HT_LINK == 1 |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 250 | reset_needed = 0; |
| 251 | prev.dev = bus->dev; |
| 252 | prev.pos = bus->cap; |
| 253 | prev.config_off = PCI_HT_CAP_HOST_WIDTH; |
| 254 | prev.freq_off = PCI_HT_CAP_HOST_FREQ; |
| 255 | prev.freq_cap_off = PCI_HT_CAP_HOST_FREQ_CAP; |
Yinghai Lu | 90b3e09 | 2005-01-26 22:00:20 +0000 | [diff] [blame] | 256 | #endif |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 257 | |
| 258 | /* If present assign unitid to a hypertransport chain */ |
| 259 | last_unitid = min_unitid -1; |
| 260 | next_unitid = min_unitid; |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 261 | do { |
| 262 | uint32_t id, class; |
Yinghai Lu | 90b3e09 | 2005-01-26 22:00:20 +0000 | [diff] [blame] | 263 | uint8_t hdr_type; |
| 264 | unsigned pos; |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 265 | uint16_t flags; |
| 266 | unsigned count, static_count; |
| 267 | |
| 268 | previous_unitid = last_unitid; |
| 269 | last_unitid = next_unitid; |
| 270 | |
| 271 | /* Get setup the device_structure */ |
| 272 | dev = ht_scan_get_devs(&old_devices); |
| 273 | |
| 274 | if (!dev) { |
| 275 | struct device dummy; |
| 276 | dummy.bus = bus; |
| 277 | dummy.path.type = DEVICE_PATH_PCI; |
| 278 | dummy.path.u.pci.devfn = 0; |
| 279 | id = pci_read_config32(&dummy, PCI_VENDOR_ID); |
| 280 | /* If the chain is fully enumerated quit */ |
| 281 | if (id == 0xffffffff || id == 0x00000000 || |
| 282 | id == 0x0000ffff || id == 0xffff0000) { |
| 283 | break; |
| 284 | } |
| 285 | dev = alloc_dev(bus, &dummy.path); |
| 286 | } |
| 287 | else { |
| 288 | /* Add this device to the pci bus chain */ |
| 289 | *chain_last = dev; |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 290 | /* Run the magice enable sequence for the device */ |
Eric Biederman | 7003ba4 | 2004-10-16 06:20:29 +0000 | [diff] [blame] | 291 | if (dev->chip_ops && dev->chip_ops->enable_dev) { |
| 292 | dev->chip_ops->enable_dev(dev); |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 293 | } |
| 294 | /* Now read the vendor and device id */ |
| 295 | id = pci_read_config32(dev, PCI_VENDOR_ID); |
Eric Biederman | 83b991a | 2003-10-11 06:20:25 +0000 | [diff] [blame] | 296 | |
| 297 | /* If the chain is fully enumerated quit */ |
| 298 | if (id == 0xffffffff || id == 0x00000000 || |
Yinghai Lu | 1f1085b | 2005-01-17 21:37:12 +0000 | [diff] [blame] | 299 | id == 0x0000ffff || id == 0xffff0000) { |
| 300 | if (dev->enabled) { |
| 301 | printk_info("Disabling static device: %s\n", |
| 302 | dev_path(dev)); |
| 303 | dev->enabled = 0; |
| 304 | } |
Eric Biederman | 83b991a | 2003-10-11 06:20:25 +0000 | [diff] [blame] | 305 | break; |
| 306 | } |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 307 | } |
| 308 | /* Update the device chain tail */ |
| 309 | for(func = dev; func; func = func->sibling) { |
| 310 | chain_last = &func->sibling; |
| 311 | } |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 312 | |
| 313 | /* Find the hypertransport link capability */ |
| 314 | pos = ht_lookup_slave_capability(dev); |
| 315 | if (pos == 0) { |
Eric Biederman | 83b991a | 2003-10-11 06:20:25 +0000 | [diff] [blame] | 316 | printk_err("%s Hypertransport link capability not found", |
| 317 | dev_path(dev)); |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 318 | break; |
| 319 | } |
| 320 | |
Yinghai Lu | 1f1085b | 2005-01-17 21:37:12 +0000 | [diff] [blame] | 321 | |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 322 | /* Update the Unitid of the current device */ |
| 323 | flags = pci_read_config16(dev, pos + PCI_CAP_FLAGS); |
| 324 | flags &= ~0x1f; /* mask out base Unit ID */ |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame^] | 325 | #if CK804_DEVN_BASE==0 |
| 326 | if(id == 0x005e10de) { |
| 327 | next_unitid = 0; |
| 328 | } |
| 329 | else { |
| 330 | #endif |
| 331 | flags |= next_unitid & 0x1f; |
| 332 | pci_write_config16(dev, pos + PCI_CAP_FLAGS, flags); |
| 333 | #if CK804_DEVN_BASE==0 |
| 334 | } |
| 335 | #endif |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 336 | |
| 337 | /* Update the Unitd id in the device structure */ |
| 338 | static_count = 1; |
| 339 | for(func = dev; func; func = func->sibling) { |
| 340 | func->path.u.pci.devfn += (next_unitid << 3); |
| 341 | static_count = (func->path.u.pci.devfn >> 3) |
| 342 | - (dev->path.u.pci.devfn >> 3) + 1; |
| 343 | } |
| 344 | |
Yinghai Lu | 90b3e09 | 2005-01-26 22:00:20 +0000 | [diff] [blame] | 345 | /* Read the rest of the pci configuration information */ |
| 346 | hdr_type = pci_read_config8(dev, PCI_HEADER_TYPE); |
| 347 | class = pci_read_config32(dev, PCI_CLASS_REVISION); |
| 348 | |
| 349 | /* Store the interesting information in the device structure */ |
| 350 | dev->vendor = id & 0xffff; |
| 351 | dev->device = (id >> 16) & 0xffff; |
| 352 | dev->hdr_type = hdr_type; |
| 353 | /* class code, the upper 3 bytes of PCI_CLASS_REVISION */ |
| 354 | dev->class = class >> 8; |
| 355 | |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 356 | /* Compute the number of unitids consumed */ |
| 357 | count = (flags >> 5) & 0x1f; /* get unit count */ |
| 358 | printk_spew("%s count: %04x static_count: %04x\n", |
| 359 | dev_path(dev), count, static_count); |
| 360 | if (count < static_count) { |
| 361 | count = static_count; |
| 362 | } |
| 363 | |
| 364 | /* Update the Unitid of the next device */ |
| 365 | next_unitid += count; |
| 366 | |
Yinghai Lu | 90b3e09 | 2005-01-26 22:00:20 +0000 | [diff] [blame] | 367 | #if OPT_HT_LINK == 1 |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 368 | /* Setup the hypetransport link */ |
| 369 | reset_needed |= ht_setup_link(&prev, dev, pos); |
Yinghai Lu | 90b3e09 | 2005-01-26 22:00:20 +0000 | [diff] [blame] | 370 | #endif |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 371 | |
| 372 | printk_debug("%s [%04x/%04x] %s next_unitid: %04x\n", |
| 373 | dev_path(dev), |
| 374 | dev->vendor, dev->device, |
Li-Ta Lo | 69c5a90 | 2004-04-29 20:08:54 +0000 | [diff] [blame] | 375 | (dev->enabled? "enabled": "disabled"), next_unitid); |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame^] | 376 | #if CK804_DEVN_BASE==0 |
| 377 | if(id == 0x005e10de) { |
| 378 | break; // CK804 can not change unitid, so it only can be alone in the link |
| 379 | } |
| 380 | #endif |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 381 | |
| 382 | } while((last_unitid != next_unitid) && (next_unitid <= 0x1f)); |
Yinghai Lu | 90b3e09 | 2005-01-26 22:00:20 +0000 | [diff] [blame] | 383 | |
| 384 | #if OPT_HT_LINK == 1 |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 385 | #if HAVE_HARD_RESET == 1 |
| 386 | if(reset_needed) { |
| 387 | printk_info("HyperT reset needed\n"); |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 388 | hard_reset(); |
| 389 | } |
| 390 | else { |
| 391 | printk_debug("HyperT reset not needed\n"); |
| 392 | } |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 393 | #endif |
Yinghai Lu | 90b3e09 | 2005-01-26 22:00:20 +0000 | [diff] [blame] | 394 | #endif |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 395 | if (next_unitid > 0x1f) { |
| 396 | next_unitid = 0x1f; |
| 397 | } |
| 398 | return pci_scan_bus(bus, 0x00, (next_unitid << 3)|7, max); |
| 399 | } |