Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2008-2009 coresystems GmbH |
| 5 | * Copyright (C) 2014 Google Inc. |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; version 2 of the License. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 19 | */ |
| 20 | |
| 21 | #include <console/console.h> |
| 22 | #include <device/device.h> |
| 23 | #include <device/pci.h> |
| 24 | #include <device/pciexp.h> |
| 25 | #include <device/pci_def.h> |
| 26 | #include <device/pci_ids.h> |
Julius Werner | 4ee4bd5 | 2014-10-20 13:46:39 -0700 | [diff] [blame] | 27 | #include <soc/gpio.h> |
| 28 | #include <soc/lpc.h> |
| 29 | #include <soc/iobp.h> |
| 30 | #include <soc/pch.h> |
| 31 | #include <soc/pci_devs.h> |
| 32 | #include <soc/rcba.h> |
| 33 | #include <soc/intel/broadwell/chip.h> |
| 34 | #include <soc/cpu.h> |
Wenkai Du | 8306761 | 2014-12-05 14:00:26 -0800 | [diff] [blame] | 35 | #include <delay.h> |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 36 | |
| 37 | static void pcie_update_cfg8(device_t dev, int reg, u8 mask, u8 or); |
| 38 | static void pcie_update_cfg(device_t dev, int reg, u32 mask, u32 or); |
| 39 | |
| 40 | /* Low Power variant has 6 root ports. */ |
| 41 | #define NUM_ROOT_PORTS 6 |
| 42 | |
| 43 | struct root_port_config { |
| 44 | /* RPFN is a write-once register so keep a copy until it is written */ |
| 45 | u32 orig_rpfn; |
| 46 | u32 new_rpfn; |
| 47 | u32 pin_ownership; |
| 48 | u32 strpfusecfg1; |
| 49 | u32 strpfusecfg2; |
| 50 | u32 strpfusecfg3; |
| 51 | u32 b0d28f0_32c; |
| 52 | u32 b0d28f4_32c; |
| 53 | u32 b0d28f5_32c; |
| 54 | int coalesce; |
| 55 | int gbe_port; |
| 56 | int num_ports; |
| 57 | device_t ports[NUM_ROOT_PORTS]; |
| 58 | }; |
| 59 | |
| 60 | static struct root_port_config rpc; |
| 61 | |
| 62 | static inline int root_port_is_first(device_t dev) |
| 63 | { |
| 64 | return PCI_FUNC(dev->path.pci.devfn) == 0; |
| 65 | } |
| 66 | |
| 67 | static inline int root_port_is_last(device_t dev) |
| 68 | { |
| 69 | return PCI_FUNC(dev->path.pci.devfn) == (rpc.num_ports - 1); |
| 70 | } |
| 71 | |
| 72 | /* Root ports are numbered 1..N in the documentation. */ |
| 73 | static inline int root_port_number(device_t dev) |
| 74 | { |
| 75 | return PCI_FUNC(dev->path.pci.devfn) + 1; |
| 76 | } |
| 77 | |
| 78 | static void root_port_config_update_gbe_port(void) |
| 79 | { |
| 80 | /* Is the Gbe Port enabled? */ |
| 81 | if (!((rpc.strpfusecfg1 >> 19) & 1)) |
| 82 | return; |
| 83 | |
| 84 | switch ((rpc.strpfusecfg1 >> 16) & 0x7) { |
| 85 | case 0: |
| 86 | rpc.gbe_port = 3; |
| 87 | break; |
| 88 | case 1: |
| 89 | rpc.gbe_port = 4; |
| 90 | break; |
| 91 | case 2: |
| 92 | case 3: |
| 93 | case 4: |
| 94 | case 5: |
| 95 | /* Lanes 0-4 of Root Port 5. */ |
| 96 | rpc.gbe_port = 5; |
| 97 | break; |
| 98 | default: |
| 99 | printk(BIOS_DEBUG, "Invalid GbE Port Selection.\n"); |
| 100 | } |
| 101 | } |
| 102 | |
Kenji Chen | 87d4a20 | 2014-09-24 01:18:26 +0800 | [diff] [blame] | 103 | static void pcie_iosf_port_grant_count(device_t dev) |
| 104 | { |
| 105 | u8 update_val; |
| 106 | u32 rpcd = (pci_read_config32(dev, 0xfc) > 14) & 0x3; |
| 107 | |
| 108 | switch (rpcd) { |
| 109 | case 1: |
| 110 | case 3: |
| 111 | update_val = 0x02; |
| 112 | break; |
| 113 | case 2: |
| 114 | update_val = 0x22; |
| 115 | break; |
| 116 | default: |
| 117 | update_val = 0x00; |
| 118 | break; |
| 119 | } |
| 120 | |
| 121 | RCBA32(0x103C) = (RCBA32(0x103C) & (~0xff)) | update_val; |
| 122 | } |
| 123 | |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 124 | static void root_port_init_config(device_t dev) |
| 125 | { |
| 126 | int rp; |
Kenji Chen | e383feb | 2014-09-26 03:14:57 +0800 | [diff] [blame] | 127 | u32 data; |
| 128 | u8 resp, id; |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 129 | |
| 130 | if (root_port_is_first(dev)) { |
| 131 | rpc.orig_rpfn = RCBA32(RPFN); |
| 132 | rpc.new_rpfn = rpc.orig_rpfn; |
| 133 | rpc.num_ports = NUM_ROOT_PORTS; |
| 134 | rpc.gbe_port = -1; |
Kenji Chen | 87d4a20 | 2014-09-24 01:18:26 +0800 | [diff] [blame] | 135 | /* RP0 f5[3:0] = 0101b*/ |
| 136 | pcie_update_cfg8(dev, 0xf5, ~0xa, 0x5); |
| 137 | |
| 138 | pcie_iosf_port_grant_count(dev); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 139 | |
| 140 | rpc.pin_ownership = pci_read_config32(dev, 0x410); |
| 141 | root_port_config_update_gbe_port(); |
| 142 | |
Kane Chen | 642e598 | 2014-09-09 15:53:09 -0700 | [diff] [blame] | 143 | pcie_update_cfg8(dev, 0xe2, ~(3 << 4), (3 << 4)); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 144 | if (dev->chip_info != NULL) { |
| 145 | config_t *config = dev->chip_info; |
| 146 | rpc.coalesce = config->pcie_port_coalesce; |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | rp = root_port_number(dev); |
| 151 | if (rp > rpc.num_ports) { |
| 152 | printk(BIOS_ERR, "Found Root Port %d, expecting %d\n", |
| 153 | rp, rpc.num_ports); |
| 154 | return; |
| 155 | } |
| 156 | |
| 157 | /* Read the fuse configuration and pin ownership. */ |
| 158 | switch (rp) { |
| 159 | case 1: |
| 160 | rpc.strpfusecfg1 = pci_read_config32(dev, 0xfc); |
| 161 | rpc.b0d28f0_32c = pci_read_config32(dev, 0x32c); |
| 162 | break; |
| 163 | case 5: |
| 164 | rpc.strpfusecfg2 = pci_read_config32(dev, 0xfc); |
| 165 | rpc.b0d28f4_32c = pci_read_config32(dev, 0x32c); |
| 166 | break; |
| 167 | case 6: |
| 168 | rpc.b0d28f5_32c = pci_read_config32(dev, 0x32c); |
| 169 | rpc.strpfusecfg3 = pci_read_config32(dev, 0xfc); |
| 170 | break; |
| 171 | default: |
| 172 | break; |
| 173 | } |
| 174 | |
Kane Chen | 4613472 | 2014-08-28 17:05:06 -0700 | [diff] [blame] | 175 | pcie_update_cfg(dev, 0x418, 0, 0x02000430); |
Kenji Chen | e383feb | 2014-09-26 03:14:57 +0800 | [diff] [blame] | 176 | |
Kenji Chen | e383feb | 2014-09-26 03:14:57 +0800 | [diff] [blame] | 177 | if (root_port_is_first(dev)) { |
Kenji Chen | e8f3664 | 2014-10-04 02:59:06 +0800 | [diff] [blame] | 178 | /* |
| 179 | * set RP0 PCICFG E2h[5:4] = 11b and E1h[6] = 1 |
| 180 | * before configuring ASPM |
| 181 | */ |
Kenji Chen | e383feb | 2014-09-26 03:14:57 +0800 | [diff] [blame] | 182 | id = 0xe0 + (u8)(RCBA32(RPFN) & 0x07); |
| 183 | pch_iobp_exec(0xE00000E0, IOBP_PCICFG_READ, id, &data, &resp); |
Kenji Chen | e8f3664 | 2014-10-04 02:59:06 +0800 | [diff] [blame] | 184 | data |= ((0x30 << 16) | (0x40 << 8)); |
Kenji Chen | e383feb | 2014-09-26 03:14:57 +0800 | [diff] [blame] | 185 | pch_iobp_exec(0xE00000E0, IOBP_PCICFG_WRITE, id, &data, &resp); |
| 186 | } |
| 187 | |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 188 | /* Cache pci device. */ |
| 189 | rpc.ports[rp - 1] = dev; |
| 190 | } |
| 191 | |
| 192 | /* Update devicetree with new Root Port function number assignment */ |
| 193 | static void pch_pcie_device_set_func(int index, int pci_func) |
| 194 | { |
| 195 | device_t dev; |
| 196 | unsigned new_devfn; |
| 197 | |
| 198 | dev = rpc.ports[index]; |
| 199 | |
| 200 | /* Set the new PCI function field for this Root Port. */ |
| 201 | rpc.new_rpfn &= ~RPFN_FNMASK(index); |
| 202 | rpc.new_rpfn |= RPFN_FNSET(index, pci_func); |
| 203 | |
| 204 | /* Determine the new devfn for this port */ |
| 205 | new_devfn = PCI_DEVFN(PCH_DEV_SLOT_PCIE, pci_func); |
| 206 | |
| 207 | if (dev->path.pci.devfn != new_devfn) { |
| 208 | printk(BIOS_DEBUG, |
| 209 | "PCH: PCIe map %02x.%1x -> %02x.%1x\n", |
| 210 | PCI_SLOT(dev->path.pci.devfn), |
| 211 | PCI_FUNC(dev->path.pci.devfn), |
| 212 | PCI_SLOT(new_devfn), PCI_FUNC(new_devfn)); |
| 213 | |
| 214 | dev->path.pci.devfn = new_devfn; |
| 215 | } |
| 216 | } |
| 217 | |
| 218 | static void pcie_enable_clock_gating(void) |
| 219 | { |
| 220 | int i; |
| 221 | int enabled_ports = 0; |
Kane Chen | 4fef5a2 | 2014-08-27 15:21:32 -0700 | [diff] [blame] | 222 | int is_broadwell = !!(cpu_family_model() == BROADWELL_FAMILY_ULT); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 223 | |
| 224 | for (i = 0; i < rpc.num_ports; i++) { |
| 225 | device_t dev; |
| 226 | int rp; |
| 227 | |
| 228 | dev = rpc.ports[i]; |
| 229 | rp = root_port_number(dev); |
| 230 | |
| 231 | if (!dev->enabled) { |
| 232 | /* Configure shared resource clock gating. */ |
| 233 | if (rp == 1 || rp == 5 || rp == 6) |
| 234 | pcie_update_cfg8(dev, 0xe1, 0xc3, 0x3c); |
| 235 | |
| 236 | pcie_update_cfg8(dev, 0xe2, ~(3 << 4), (3 << 4)); |
| 237 | pcie_update_cfg(dev, 0x420, ~(1 << 31), (1 << 31)); |
| 238 | |
| 239 | /* Per-Port CLKREQ# handling. */ |
| 240 | if (gpio_is_native(18 + rp - 1)) |
| 241 | pcie_update_cfg(dev, 0x420, ~0, (3 << 29)); |
| 242 | |
| 243 | /* Enable static clock gating. */ |
| 244 | if (rp == 1 && !rpc.ports[1]->enabled && |
| 245 | !rpc.ports[2]->enabled && !rpc.ports[3]->enabled) { |
| 246 | pcie_update_cfg8(dev, 0xe2, ~1, 1); |
| 247 | pcie_update_cfg8(dev, 0xe1, 0x7f, 0x80); |
| 248 | } else if (rp == 5 || rp == 6) { |
| 249 | pcie_update_cfg8(dev, 0xe2, ~1, 1); |
| 250 | pcie_update_cfg8(dev, 0xe1, 0x7f, 0x80); |
| 251 | } |
| 252 | continue; |
| 253 | } |
| 254 | |
| 255 | enabled_ports++; |
| 256 | |
| 257 | /* Enable dynamic clock gating. */ |
| 258 | pcie_update_cfg8(dev, 0xe1, 0xfc, 0x03); |
| 259 | pcie_update_cfg8(dev, 0xe2, ~(1 << 6), (1 << 6)); |
| 260 | pcie_update_cfg8(dev, 0xe8, ~(3 << 2), (2 << 2)); |
| 261 | |
| 262 | /* Update PECR1 register. */ |
Kane Chen | 4fef5a2 | 2014-08-27 15:21:32 -0700 | [diff] [blame] | 263 | pcie_update_cfg8(dev, 0xe8, ~0, 3); |
| 264 | if (is_broadwell) { |
| 265 | pcie_update_cfg(dev, 0x324, ~((1 << 5) | (1 << 14)), |
| 266 | ((1 << 5) | (1 << 14))); |
| 267 | } else { |
| 268 | pcie_update_cfg(dev, 0x324, ~(1 << 5), (1 << 5)); |
| 269 | } |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 270 | /* Per-Port CLKREQ# handling. */ |
| 271 | if (gpio_is_native(18 + rp - 1)) |
Kenji Chen | e8f3664 | 2014-10-04 02:59:06 +0800 | [diff] [blame] | 272 | /* |
| 273 | * In addition to D28Fx PCICFG 420h[30:29] = 11b, |
| 274 | * set 420h[17] = 0b and 420[0] = 1b for L1 SubState. |
| 275 | */ |
| 276 | pcie_update_cfg(dev, 0x420, ~0x20000, (3 << 29) | 1); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 277 | |
| 278 | /* Configure shared resource clock gating. */ |
| 279 | if (rp == 1 || rp == 5 || rp == 6) |
| 280 | pcie_update_cfg8(dev, 0xe1, 0xc3, 0x3c); |
Duncan Laurie | 446fb8e | 2014-08-08 09:59:43 -0700 | [diff] [blame] | 281 | |
| 282 | /* CLKREQ# VR Idle Enable */ |
| 283 | RCBA32_OR(0x2b1c, (1 << (16 + i))); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | if (!enabled_ports) |
| 287 | pcie_update_cfg8(rpc.ports[0], 0xe1, ~(1 << 6), (1 << 6)); |
| 288 | } |
| 289 | |
| 290 | static void root_port_commit_config(void) |
| 291 | { |
| 292 | int i; |
| 293 | |
| 294 | /* If the first root port is disabled the coalesce ports. */ |
| 295 | if (!rpc.ports[0]->enabled) |
| 296 | rpc.coalesce = 1; |
| 297 | |
| 298 | /* Perform clock gating configuration. */ |
| 299 | pcie_enable_clock_gating(); |
| 300 | |
| 301 | for (i = 0; i < rpc.num_ports; i++) { |
| 302 | device_t dev; |
| 303 | u32 reg32; |
Wenkai Du | 8306761 | 2014-12-05 14:00:26 -0800 | [diff] [blame] | 304 | int n = 0; |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 305 | |
| 306 | dev = rpc.ports[i]; |
| 307 | |
| 308 | if (dev == NULL) { |
| 309 | printk(BIOS_ERR, "Root Port %d device is NULL?\n", i+1); |
| 310 | continue; |
| 311 | } |
| 312 | |
| 313 | if (dev->enabled) |
| 314 | continue; |
| 315 | |
| 316 | printk(BIOS_DEBUG, "%s: Disabling device\n", dev_path(dev)); |
| 317 | |
Wenkai Du | 8306761 | 2014-12-05 14:00:26 -0800 | [diff] [blame] | 318 | /* 8.2 Configuration of PCI Express Root Ports */ |
| 319 | pcie_update_cfg(dev, 0x338, ~(1 << 26), 1 << 26); |
| 320 | |
| 321 | do { |
| 322 | reg32 = pci_read_config32(dev, 0x328); |
| 323 | n++; |
Duncan Laurie | cad2b7b | 2015-01-14 17:30:20 -0800 | [diff] [blame] | 324 | if (((reg32 & 0xff000000) == 0x01000000) || (n > 50)) |
Wenkai Du | 8306761 | 2014-12-05 14:00:26 -0800 | [diff] [blame] | 325 | break; |
| 326 | udelay(100); |
| 327 | } while (1); |
| 328 | |
Duncan Laurie | cad2b7b | 2015-01-14 17:30:20 -0800 | [diff] [blame] | 329 | if (n > 50) |
Wenkai Du | 8306761 | 2014-12-05 14:00:26 -0800 | [diff] [blame] | 330 | printk(BIOS_DEBUG, "%s: Timeout waiting for 328h\n", |
| 331 | dev_path(dev)); |
| 332 | |
| 333 | pcie_update_cfg(dev, 0x408, ~(1 << 27), 1 << 27); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 334 | |
| 335 | /* Disable this device if possible */ |
| 336 | pch_disable_devfn(dev); |
| 337 | } |
| 338 | |
| 339 | if (rpc.coalesce) { |
| 340 | int current_func; |
| 341 | |
| 342 | /* For all Root Ports N enabled ports get assigned the lower |
| 343 | * PCI function number. The disabled ones get upper PCI |
| 344 | * function numbers. */ |
| 345 | current_func = 0; |
| 346 | for (i = 0; i < rpc.num_ports; i++) { |
| 347 | if (!rpc.ports[i]->enabled) |
| 348 | continue; |
| 349 | pch_pcie_device_set_func(i, current_func); |
| 350 | current_func++; |
| 351 | } |
| 352 | |
| 353 | /* Allocate the disabled devices' PCI function number. */ |
| 354 | for (i = 0; i < rpc.num_ports; i++) { |
| 355 | if (rpc.ports[i]->enabled) |
| 356 | continue; |
| 357 | pch_pcie_device_set_func(i, current_func); |
| 358 | current_func++; |
| 359 | } |
| 360 | } |
| 361 | |
| 362 | printk(BIOS_SPEW, "PCH: RPFN 0x%08x -> 0x%08x\n", |
| 363 | rpc.orig_rpfn, rpc.new_rpfn); |
| 364 | RCBA32(RPFN) = rpc.new_rpfn; |
| 365 | } |
| 366 | |
| 367 | static void root_port_mark_disable(device_t dev) |
| 368 | { |
| 369 | /* Mark device as disabled. */ |
| 370 | dev->enabled = 0; |
| 371 | /* Mark device to be hidden. */ |
| 372 | rpc.new_rpfn |= RPFN_HIDE(PCI_FUNC(dev->path.pci.devfn)); |
| 373 | } |
| 374 | |
| 375 | static void root_port_check_disable(device_t dev) |
| 376 | { |
| 377 | int rp; |
| 378 | |
| 379 | /* Device already disabled. */ |
| 380 | if (!dev->enabled) { |
| 381 | root_port_mark_disable(dev); |
| 382 | return; |
| 383 | } |
| 384 | |
| 385 | rp = root_port_number(dev); |
| 386 | |
| 387 | /* Is the GbE port mapped to this Root Port? */ |
| 388 | if (rp == rpc.gbe_port) { |
| 389 | root_port_mark_disable(dev); |
| 390 | return; |
| 391 | } |
| 392 | |
| 393 | /* Check Root Port Configuration. */ |
| 394 | switch (rp) { |
| 395 | case 2: |
| 396 | /* Root Port 2 is disabled for all lane configurations |
| 397 | * but config 00b (4x1 links). */ |
| 398 | if ((rpc.strpfusecfg1 >> 14) & 0x3) { |
| 399 | root_port_mark_disable(dev); |
| 400 | return; |
| 401 | } |
| 402 | break; |
| 403 | case 3: |
| 404 | /* Root Port 3 is disabled in config 11b (1x4 links). */ |
| 405 | if (((rpc.strpfusecfg1 >> 14) & 0x3) == 0x3) { |
| 406 | root_port_mark_disable(dev); |
| 407 | return; |
| 408 | } |
| 409 | break; |
| 410 | case 4: |
| 411 | /* Root Port 4 is disabled in configs 11b (1x4 links) |
| 412 | * and 10b (2x2 links). */ |
| 413 | if ((rpc.strpfusecfg1 >> 14) & 0x2) { |
| 414 | root_port_mark_disable(dev); |
| 415 | return; |
| 416 | } |
| 417 | break; |
| 418 | } |
| 419 | |
| 420 | /* Check Pin Ownership. */ |
| 421 | switch (rp) { |
| 422 | case 1: |
| 423 | /* Bit 0 is Root Port 1 ownership. */ |
| 424 | if ((rpc.pin_ownership & 0x1) == 0) { |
| 425 | root_port_mark_disable(dev); |
| 426 | return; |
| 427 | } |
| 428 | break; |
| 429 | case 2: |
| 430 | /* Bit 2 is Root Port 2 ownership. */ |
| 431 | if ((rpc.pin_ownership & 0x4) == 0) { |
| 432 | root_port_mark_disable(dev); |
| 433 | return; |
| 434 | } |
| 435 | break; |
| 436 | case 6: |
| 437 | /* Bits 7:4 are Root Port 6 pin-lane ownership. */ |
| 438 | if ((rpc.pin_ownership & 0xf0) == 0) { |
| 439 | root_port_mark_disable(dev); |
| 440 | return; |
| 441 | } |
| 442 | break; |
| 443 | } |
| 444 | } |
| 445 | |
| 446 | static void pcie_update_cfg8(device_t dev, int reg, u8 mask, u8 or) |
| 447 | { |
| 448 | u8 reg8; |
| 449 | |
| 450 | reg8 = pci_read_config8(dev, reg); |
| 451 | reg8 &= mask; |
| 452 | reg8 |= or; |
| 453 | pci_write_config8(dev, reg, reg8); |
| 454 | } |
| 455 | |
| 456 | static void pcie_update_cfg(device_t dev, int reg, u32 mask, u32 or) |
| 457 | { |
| 458 | u32 reg32; |
| 459 | |
| 460 | reg32 = pci_read_config32(dev, reg); |
| 461 | reg32 &= mask; |
| 462 | reg32 |= or; |
| 463 | pci_write_config32(dev, reg, reg32); |
| 464 | } |
| 465 | |
| 466 | static void pcie_add_0x0202000_iobp(u32 reg) |
| 467 | { |
| 468 | u32 reg32; |
| 469 | |
| 470 | reg32 = pch_iobp_read(reg); |
| 471 | reg32 += (0x2 << 16) | (0x2 << 8); |
| 472 | pch_iobp_write(reg, reg32); |
| 473 | } |
| 474 | |
| 475 | static void pch_pcie_early(struct device *dev) |
| 476 | { |
| 477 | config_t *config = dev->chip_info; |
| 478 | int do_aspm = 0; |
| 479 | int rp = root_port_number(dev); |
| 480 | |
| 481 | switch (rp) { |
| 482 | case 1: |
| 483 | case 2: |
| 484 | case 3: |
| 485 | case 4: |
| 486 | /* |
Martin Roth | de7ed6f | 2014-12-07 14:58:18 -0700 | [diff] [blame] | 487 | * Bits 31:28 of b0d28f0 0x32c register correspond to |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 488 | * Root Ports 4:1. |
| 489 | */ |
| 490 | do_aspm = !!(rpc.b0d28f0_32c & (1 << (28 + rp - 1))); |
| 491 | break; |
| 492 | case 5: |
| 493 | /* |
Martin Roth | de7ed6f | 2014-12-07 14:58:18 -0700 | [diff] [blame] | 494 | * Bit 28 of b0d28f4 0x32c register correspond to |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 495 | * Root Ports 4:1. |
| 496 | */ |
| 497 | do_aspm = !!(rpc.b0d28f4_32c & (1 << 28)); |
| 498 | break; |
| 499 | case 6: |
| 500 | /* |
Martin Roth | de7ed6f | 2014-12-07 14:58:18 -0700 | [diff] [blame] | 501 | * Bit 28 of b0d28f5 0x32c register correspond to |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 502 | * Root Ports 4:1. |
| 503 | */ |
| 504 | do_aspm = !!(rpc.b0d28f5_32c & (1 << 28)); |
| 505 | break; |
| 506 | } |
| 507 | |
| 508 | /* Allow ASPM to be forced on in devicetree */ |
| 509 | if (config && (config->pcie_port_force_aspm & (1 << (rp - 1)))) |
| 510 | do_aspm = 1; |
| 511 | |
| 512 | printk(BIOS_DEBUG, "PCIe Root Port %d ASPM is %sabled\n", |
| 513 | rp, do_aspm ? "en" : "dis"); |
| 514 | |
| 515 | if (do_aspm) { |
| 516 | /* Set ASPM bits in MPC2 register. */ |
| 517 | pcie_update_cfg(dev, 0xd4, ~(0x3 << 2), (1 << 4) | (0x2 << 2)); |
| 518 | |
| 519 | /* Set unique clock exit latency in MPC register. */ |
| 520 | pcie_update_cfg(dev, 0xd8, ~(0x7 << 18), (0x7 << 18)); |
| 521 | |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 522 | switch (rp) { |
| 523 | case 1: |
| 524 | pcie_add_0x0202000_iobp(0xe9002440); |
| 525 | break; |
| 526 | case 2: |
| 527 | pcie_add_0x0202000_iobp(0xe9002640); |
| 528 | break; |
| 529 | case 3: |
| 530 | pcie_add_0x0202000_iobp(0xe9000840); |
| 531 | break; |
| 532 | case 4: |
| 533 | pcie_add_0x0202000_iobp(0xe9000a40); |
| 534 | break; |
| 535 | case 5: |
| 536 | pcie_add_0x0202000_iobp(0xe9000c40); |
| 537 | pcie_add_0x0202000_iobp(0xe9000e40); |
| 538 | pcie_add_0x0202000_iobp(0xe9001040); |
| 539 | pcie_add_0x0202000_iobp(0xe9001240); |
| 540 | break; |
| 541 | case 6: |
| 542 | /* Update IOBP based on lane ownership. */ |
| 543 | if (rpc.pin_ownership & (1 << 4)) |
| 544 | pcie_add_0x0202000_iobp(0xea002040); |
| 545 | if (rpc.pin_ownership & (1 << 5)) |
| 546 | pcie_add_0x0202000_iobp(0xea002240); |
| 547 | if (rpc.pin_ownership & (1 << 6)) |
| 548 | pcie_add_0x0202000_iobp(0xea002440); |
| 549 | if (rpc.pin_ownership & (1 << 7)) |
| 550 | pcie_add_0x0202000_iobp(0xea002640); |
| 551 | break; |
| 552 | } |
| 553 | |
| 554 | pcie_update_cfg(dev, 0x338, ~(1 << 26), 0); |
| 555 | } |
| 556 | |
Kenji Chen | c373f50 | 2014-09-26 02:48:16 +0800 | [diff] [blame] | 557 | /* Enable LTR in Root Port. Disable OBFF. */ |
| 558 | pcie_update_cfg(dev, 0x64, ~(1 << 11) & ~(3 << 18), (1 << 11)); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 559 | pcie_update_cfg(dev, 0x68, ~(1 << 10), (1 << 10)); |
| 560 | |
| 561 | pcie_update_cfg(dev, 0x318, ~(0xffff << 16), (0x1414 << 16)); |
| 562 | |
| 563 | /* Set L1 exit latency in LCAP register. */ |
| 564 | if (!do_aspm && (pci_read_config8(dev, 0xf5) & 0x1)) |
| 565 | pcie_update_cfg(dev, 0x4c, ~(0x7 << 15), (0x4 << 15)); |
| 566 | else |
| 567 | pcie_update_cfg(dev, 0x4c, ~(0x7 << 15), (0x2 << 15)); |
| 568 | |
| 569 | pcie_update_cfg(dev, 0x314, 0x0, 0x743a361b); |
| 570 | |
| 571 | /* Set Common Clock Exit Latency in MPC register. */ |
| 572 | pcie_update_cfg(dev, 0xd8, ~(0x7 << 15), (0x3 << 15)); |
| 573 | |
Duncan Laurie | b14c067 | 2015-02-02 21:00:33 -0800 | [diff] [blame^] | 574 | pcie_update_cfg(dev, 0x33c, ~0x00ffffff, 0x854d74); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 575 | |
Martin Roth | de7ed6f | 2014-12-07 14:58:18 -0700 | [diff] [blame] | 576 | /* Set Invalid Receive Range Check Enable in MPC register. */ |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 577 | pcie_update_cfg(dev, 0xd8, ~0, (1 << 25)); |
| 578 | |
Kane Chen | 4fef5a2 | 2014-08-27 15:21:32 -0700 | [diff] [blame] | 579 | pcie_update_cfg8(dev, 0xf5, 0x0f, 0); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 580 | |
Kenji Chen | 94fea49 | 2014-09-30 14:17:35 +0800 | [diff] [blame] | 581 | /* Set AER Extended Cap ID to 01h and Next Cap Pointer to 200h. */ |
Kenji Chen | 8ef55ee | 2014-09-25 21:34:42 +0800 | [diff] [blame] | 582 | pcie_update_cfg(dev, 0x100, ~(1 << 29) & ~0xfffff, (1 << 29) | 0x10001); |
| 583 | |
Kenji Chen | 94fea49 | 2014-09-30 14:17:35 +0800 | [diff] [blame] | 584 | /* Set L1 Sub-State Cap ID to 1Eh and Next Cap Pointer to None. */ |
| 585 | pcie_update_cfg(dev, 0x200, ~0xffff, 0x001e); |
| 586 | |
Kenji Chen | c373f50 | 2014-09-26 02:48:16 +0800 | [diff] [blame] | 587 | pcie_update_cfg(dev, 0x320, ~(3 << 20) & ~(7 << 6), |
| 588 | (1 << 20) | (3 << 6)); |
| 589 | /* Enable Relaxed Order from Root Port. */ |
| 590 | pcie_update_cfg(dev, 0x320, ~(3 << 23), (3 << 23)); |
| 591 | |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 592 | if (rp == 1 || rp == 5 || rp == 6) |
| 593 | pcie_update_cfg8(dev, 0xf7, ~0xc, 0); |
| 594 | |
| 595 | /* Set EOI forwarding disable. */ |
| 596 | pcie_update_cfg(dev, 0xd4, ~0, (1 << 1)); |
| 597 | |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 598 | /* Read and write back write-once capability registers. */ |
| 599 | pcie_update_cfg(dev, 0x34, ~0, 0); |
| 600 | pcie_update_cfg(dev, 0x40, ~0, 0); |
| 601 | pcie_update_cfg(dev, 0x80, ~0, 0); |
| 602 | pcie_update_cfg(dev, 0x90, ~0, 0); |
| 603 | } |
| 604 | |
| 605 | static void pch_pcie_init(struct device *dev) |
| 606 | { |
| 607 | u16 reg16; |
| 608 | u32 reg32; |
| 609 | |
| 610 | printk(BIOS_DEBUG, "Initializing PCH PCIe bridge.\n"); |
| 611 | |
| 612 | /* Enable SERR */ |
| 613 | reg32 = pci_read_config32(dev, PCI_COMMAND); |
| 614 | reg32 |= PCI_COMMAND_SERR; |
| 615 | pci_write_config32(dev, PCI_COMMAND, reg32); |
| 616 | |
| 617 | /* Enable Bus Master */ |
| 618 | reg32 = pci_read_config32(dev, PCI_COMMAND); |
| 619 | reg32 |= PCI_COMMAND_MASTER; |
| 620 | pci_write_config32(dev, PCI_COMMAND, reg32); |
| 621 | |
| 622 | /* Set Cache Line Size to 0x10 */ |
| 623 | pci_write_config8(dev, 0x0c, 0x10); |
| 624 | |
| 625 | reg16 = pci_read_config16(dev, 0x3e); |
| 626 | reg16 &= ~(1 << 0); /* disable parity error response */ |
| 627 | reg16 |= (1 << 2); /* ISA enable */ |
| 628 | pci_write_config16(dev, 0x3e, reg16); |
| 629 | |
| 630 | #ifdef EVEN_MORE_DEBUG |
| 631 | reg32 = pci_read_config32(dev, 0x20); |
| 632 | printk(BIOS_SPEW, " MBL = 0x%08x\n", reg32); |
| 633 | reg32 = pci_read_config32(dev, 0x24); |
| 634 | printk(BIOS_SPEW, " PMBL = 0x%08x\n", reg32); |
| 635 | reg32 = pci_read_config32(dev, 0x28); |
| 636 | printk(BIOS_SPEW, " PMBU32 = 0x%08x\n", reg32); |
| 637 | reg32 = pci_read_config32(dev, 0x2c); |
| 638 | printk(BIOS_SPEW, " PMLU32 = 0x%08x\n", reg32); |
| 639 | #endif |
| 640 | |
| 641 | /* Clear errors in status registers */ |
| 642 | reg16 = pci_read_config16(dev, 0x06); |
| 643 | pci_write_config16(dev, 0x06, reg16); |
| 644 | reg16 = pci_read_config16(dev, 0x1e); |
| 645 | pci_write_config16(dev, 0x1e, reg16); |
| 646 | } |
| 647 | |
| 648 | static void pch_pcie_enable(device_t dev) |
| 649 | { |
| 650 | /* Add this device to the root port config structure. */ |
| 651 | root_port_init_config(dev); |
| 652 | |
| 653 | /* Check to see if this Root Port should be disabled. */ |
| 654 | root_port_check_disable(dev); |
| 655 | |
| 656 | /* Power Management init before enumeration */ |
| 657 | if (dev->enabled) |
| 658 | pch_pcie_early(dev); |
| 659 | |
| 660 | /* |
| 661 | * When processing the last PCIe root port we can now |
| 662 | * update the Root Port Function Number and Hide register. |
| 663 | */ |
| 664 | if (root_port_is_last(dev)) |
| 665 | root_port_commit_config(); |
| 666 | } |
| 667 | |
| 668 | static void pcie_set_subsystem(device_t dev, unsigned vendor, unsigned device) |
| 669 | { |
| 670 | /* NOTE: This is not the default position! */ |
| 671 | if (!vendor || !device) |
| 672 | pci_write_config32(dev, 0x94, pci_read_config32(dev, 0)); |
| 673 | else |
| 674 | pci_write_config32(dev, 0x94, (device << 16) | vendor); |
| 675 | } |
| 676 | |
Kenji Chen | b71d9b8 | 2014-10-10 03:08:15 +0800 | [diff] [blame] | 677 | static void pcie_set_L1_ss_max_latency(device_t dev, unsigned int off) |
| 678 | { |
| 679 | /* Set max snoop and non-snoop latency for Broadwell */ |
| 680 | pci_mmio_write_config32(dev, off, 0x10031003); |
| 681 | } |
| 682 | |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 683 | static struct pci_operations pcie_ops = { |
| 684 | .set_subsystem = pcie_set_subsystem, |
Kenji Chen | b71d9b8 | 2014-10-10 03:08:15 +0800 | [diff] [blame] | 685 | .set_L1_ss_latency = pcie_set_L1_ss_max_latency, |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 686 | }; |
| 687 | |
| 688 | static struct device_operations device_ops = { |
| 689 | .read_resources = pci_bus_read_resources, |
| 690 | .set_resources = pci_dev_set_resources, |
| 691 | .enable_resources = pci_bus_enable_resources, |
| 692 | .init = pch_pcie_init, |
| 693 | .enable = pch_pcie_enable, |
| 694 | .scan_bus = pciexp_scan_bridge, |
| 695 | .ops_pci = &pcie_ops, |
| 696 | }; |
| 697 | |
| 698 | static const unsigned short pcie_device_ids[] = { |
| 699 | /* Lynxpoint-LP */ |
| 700 | 0x9c10, 0x9c12, 0x9c14, 0x9c16, 0x9c18, 0x9c1a, |
| 701 | /* WildcatPoint */ |
| 702 | 0x9c90, 0x9c92, 0x9c94, 0x9c96, 0x9c98, 0x9c9a, 0x2448, |
| 703 | 0 |
| 704 | }; |
| 705 | |
| 706 | static const struct pci_driver pch_pcie __pci_driver = { |
| 707 | .ops = &device_ops, |
| 708 | .vendor = PCI_VENDOR_ID_INTEL, |
| 709 | .devices = pcie_device_ids, |
| 710 | }; |