Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2008-2009 coresystems GmbH |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License as |
| 8 | * published by the Free Software Foundation; version 2 of |
| 9 | * 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. |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | #include <console/console.h> |
| 18 | #include <device/device.h> |
| 19 | #include <device/pci.h> |
| 20 | #include <device/pciexp.h> |
| 21 | #include <device/pci_ids.h> |
Patrick Rudolph | e56189c | 2018-04-18 10:11:59 +0200 | [diff] [blame] | 22 | #include <device/pci_ops.h> |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 23 | #include "pch.h" |
Patrick Rudolph | 273a8dc | 2016-02-06 18:07:59 +0100 | [diff] [blame] | 24 | #include <southbridge/intel/common/gpio.h> |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 25 | |
Aaron Durbin | c0254e6 | 2013-06-20 01:20:30 -0500 | [diff] [blame] | 26 | /* LynxPoint-LP has 6 root ports while non-LP has 8. */ |
| 27 | #define MAX_NUM_ROOT_PORTS 8 |
| 28 | #define H_NUM_ROOT_PORTS MAX_NUM_ROOT_PORTS |
| 29 | #define LP_NUM_ROOT_PORTS (MAX_NUM_ROOT_PORTS - 2) |
| 30 | |
| 31 | struct root_port_config { |
| 32 | /* RPFN is a write-once register so keep a copy until it is written */ |
| 33 | u32 orig_rpfn; |
| 34 | u32 new_rpfn; |
| 35 | u32 pin_ownership; |
| 36 | u32 strpfusecfg1; |
| 37 | u32 strpfusecfg2; |
| 38 | u32 strpfusecfg3; |
Stefan Reinauer | ab365af | 2013-12-03 12:13:26 -0800 | [diff] [blame] | 39 | u32 b0d28f0_32c; |
| 40 | u32 b0d28f4_32c; |
| 41 | u32 b0d28f5_32c; |
Aaron Durbin | c0254e6 | 2013-06-20 01:20:30 -0500 | [diff] [blame] | 42 | int coalesce; |
| 43 | int gbe_port; |
| 44 | int num_ports; |
Elyes HAOUAS | 7a5f771 | 2018-06-08 17:20:38 +0200 | [diff] [blame^] | 45 | struct device *ports[MAX_NUM_ROOT_PORTS]; |
Aaron Durbin | c0254e6 | 2013-06-20 01:20:30 -0500 | [diff] [blame] | 46 | }; |
| 47 | |
| 48 | static struct root_port_config rpc; |
| 49 | |
| 50 | static inline int max_root_ports(void) |
Aaron Durbin | 60f8208 | 2013-06-19 13:28:04 -0500 | [diff] [blame] | 51 | { |
Aaron Durbin | c0254e6 | 2013-06-20 01:20:30 -0500 | [diff] [blame] | 52 | if (pch_is_lp()) |
| 53 | return LP_NUM_ROOT_PORTS; |
| 54 | else |
| 55 | return H_NUM_ROOT_PORTS; |
Aaron Durbin | 60f8208 | 2013-06-19 13:28:04 -0500 | [diff] [blame] | 56 | } |
| 57 | |
Elyes HAOUAS | 7a5f771 | 2018-06-08 17:20:38 +0200 | [diff] [blame^] | 58 | static inline int root_port_is_first(struct device *dev) |
Aaron Durbin | 60f8208 | 2013-06-19 13:28:04 -0500 | [diff] [blame] | 59 | { |
Aaron Durbin | c0254e6 | 2013-06-20 01:20:30 -0500 | [diff] [blame] | 60 | return PCI_FUNC(dev->path.pci.devfn) == 0; |
| 61 | } |
Aaron Durbin | 60f8208 | 2013-06-19 13:28:04 -0500 | [diff] [blame] | 62 | |
Elyes HAOUAS | 7a5f771 | 2018-06-08 17:20:38 +0200 | [diff] [blame^] | 63 | static inline int root_port_is_last(struct device *dev) |
Aaron Durbin | c0254e6 | 2013-06-20 01:20:30 -0500 | [diff] [blame] | 64 | { |
| 65 | return PCI_FUNC(dev->path.pci.devfn) == (rpc.num_ports - 1); |
| 66 | } |
Aaron Durbin | 60f8208 | 2013-06-19 13:28:04 -0500 | [diff] [blame] | 67 | |
Aaron Durbin | c0254e6 | 2013-06-20 01:20:30 -0500 | [diff] [blame] | 68 | /* Root ports are numbered 1..N in the documentation. */ |
Elyes HAOUAS | 7a5f771 | 2018-06-08 17:20:38 +0200 | [diff] [blame^] | 69 | static inline int root_port_number(struct device *dev) |
Aaron Durbin | c0254e6 | 2013-06-20 01:20:30 -0500 | [diff] [blame] | 70 | { |
| 71 | return PCI_FUNC(dev->path.pci.devfn) + 1; |
| 72 | } |
Aaron Durbin | 60f8208 | 2013-06-19 13:28:04 -0500 | [diff] [blame] | 73 | |
Aaron Durbin | c0254e6 | 2013-06-20 01:20:30 -0500 | [diff] [blame] | 74 | static void root_port_config_update_gbe_port(void) |
| 75 | { |
| 76 | /* Is the Gbe Port enabled? */ |
| 77 | if (!((rpc.strpfusecfg1 >> 19) & 1)) |
| 78 | return; |
| 79 | |
| 80 | if (pch_is_lp()) { |
| 81 | switch ((rpc.strpfusecfg1 >> 16) & 0x7) { |
| 82 | case 0: |
| 83 | rpc.gbe_port = 3; |
| 84 | break; |
| 85 | case 1: |
| 86 | rpc.gbe_port = 4; |
| 87 | break; |
| 88 | case 2: |
| 89 | case 3: |
| 90 | case 4: |
| 91 | case 5: |
| 92 | /* Lanes 0-4 of Root Port 5. */ |
| 93 | rpc.gbe_port = 5; |
| 94 | break; |
| 95 | default: |
| 96 | printk(BIOS_DEBUG, "Invalid GbE Port Selection.\n"); |
| 97 | } |
| 98 | } else { |
| 99 | /* Non-LP has 1:1 mapping with root ports. */ |
| 100 | rpc.gbe_port = ((rpc.strpfusecfg1 >> 16) & 0x7) + 1; |
| 101 | } |
| 102 | } |
| 103 | |
Elyes HAOUAS | 7a5f771 | 2018-06-08 17:20:38 +0200 | [diff] [blame^] | 104 | static void root_port_init_config(struct device *dev) |
Aaron Durbin | c0254e6 | 2013-06-20 01:20:30 -0500 | [diff] [blame] | 105 | { |
| 106 | int rp; |
| 107 | |
| 108 | if (root_port_is_first(dev)) { |
| 109 | rpc.orig_rpfn = RCBA32(RPFN); |
| 110 | rpc.new_rpfn = rpc.orig_rpfn; |
| 111 | rpc.num_ports = max_root_ports(); |
| 112 | rpc.gbe_port = -1; |
| 113 | |
| 114 | rpc.pin_ownership = pci_read_config32(dev, 0x410); |
| 115 | root_port_config_update_gbe_port(); |
| 116 | |
| 117 | if (dev->chip_info != NULL) { |
| 118 | struct southbridge_intel_lynxpoint_config *config; |
| 119 | |
| 120 | config = dev->chip_info; |
| 121 | rpc.coalesce = config->pcie_port_coalesce; |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | rp = root_port_number(dev); |
| 126 | if (rp > rpc.num_ports) { |
| 127 | printk(BIOS_ERR, "Found Root Port %d, expecting %d\n", |
| 128 | rp, rpc.num_ports); |
| 129 | return; |
| 130 | } |
| 131 | |
| 132 | /* Read the fuse configuration and pin ownership. */ |
| 133 | switch (rp) { |
| 134 | case 1: |
| 135 | rpc.strpfusecfg1 = pci_read_config32(dev, 0xfc); |
Stefan Reinauer | ab365af | 2013-12-03 12:13:26 -0800 | [diff] [blame] | 136 | rpc.b0d28f0_32c = pci_read_config32(dev, 0x32c); |
Aaron Durbin | c0254e6 | 2013-06-20 01:20:30 -0500 | [diff] [blame] | 137 | break; |
| 138 | case 5: |
| 139 | rpc.strpfusecfg2 = pci_read_config32(dev, 0xfc); |
Stefan Reinauer | ab365af | 2013-12-03 12:13:26 -0800 | [diff] [blame] | 140 | rpc.b0d28f4_32c = pci_read_config32(dev, 0x32c); |
Aaron Durbin | c0254e6 | 2013-06-20 01:20:30 -0500 | [diff] [blame] | 141 | break; |
| 142 | case 6: |
Stefan Reinauer | ab365af | 2013-12-03 12:13:26 -0800 | [diff] [blame] | 143 | rpc.b0d28f5_32c = pci_read_config32(dev, 0x32c); |
Aaron Durbin | c0254e6 | 2013-06-20 01:20:30 -0500 | [diff] [blame] | 144 | rpc.strpfusecfg3 = pci_read_config32(dev, 0xfc); |
| 145 | break; |
| 146 | default: |
| 147 | break; |
| 148 | } |
| 149 | |
| 150 | /* Cache pci device. */ |
| 151 | rpc.ports[rp - 1] = dev; |
Aaron Durbin | 60f8208 | 2013-06-19 13:28:04 -0500 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | /* Update devicetree with new Root Port function number assignment */ |
Aaron Durbin | c0254e6 | 2013-06-20 01:20:30 -0500 | [diff] [blame] | 155 | static void pch_pcie_device_set_func(int index, int pci_func) |
Aaron Durbin | 60f8208 | 2013-06-19 13:28:04 -0500 | [diff] [blame] | 156 | { |
Elyes HAOUAS | 7a5f771 | 2018-06-08 17:20:38 +0200 | [diff] [blame^] | 157 | struct device *dev; |
Aaron Durbin | c0254e6 | 2013-06-20 01:20:30 -0500 | [diff] [blame] | 158 | unsigned new_devfn; |
Aaron Durbin | 60f8208 | 2013-06-19 13:28:04 -0500 | [diff] [blame] | 159 | |
Aaron Durbin | c0254e6 | 2013-06-20 01:20:30 -0500 | [diff] [blame] | 160 | dev = rpc.ports[index]; |
Aaron Durbin | 60f8208 | 2013-06-19 13:28:04 -0500 | [diff] [blame] | 161 | |
Aaron Durbin | c0254e6 | 2013-06-20 01:20:30 -0500 | [diff] [blame] | 162 | /* Set the new PCI function field for this Root Port. */ |
| 163 | rpc.new_rpfn &= ~RPFN_FNMASK(index); |
| 164 | rpc.new_rpfn |= RPFN_FNSET(index, pci_func); |
Aaron Durbin | 60f8208 | 2013-06-19 13:28:04 -0500 | [diff] [blame] | 165 | |
Aaron Durbin | c0254e6 | 2013-06-20 01:20:30 -0500 | [diff] [blame] | 166 | /* Determine the new devfn for this port */ |
| 167 | new_devfn = PCI_DEVFN(PCH_PCIE_DEV_SLOT, pci_func); |
Aaron Durbin | 60f8208 | 2013-06-19 13:28:04 -0500 | [diff] [blame] | 168 | |
Aaron Durbin | c0254e6 | 2013-06-20 01:20:30 -0500 | [diff] [blame] | 169 | if (dev->path.pci.devfn != new_devfn) { |
| 170 | printk(BIOS_DEBUG, |
| 171 | "PCH: PCIe map %02x.%1x -> %02x.%1x\n", |
| 172 | PCI_SLOT(dev->path.pci.devfn), |
| 173 | PCI_FUNC(dev->path.pci.devfn), |
| 174 | PCI_SLOT(new_devfn), PCI_FUNC(new_devfn)); |
Aaron Durbin | 60f8208 | 2013-06-19 13:28:04 -0500 | [diff] [blame] | 175 | |
Aaron Durbin | c0254e6 | 2013-06-20 01:20:30 -0500 | [diff] [blame] | 176 | dev->path.pci.devfn = new_devfn; |
Aaron Durbin | 60f8208 | 2013-06-19 13:28:04 -0500 | [diff] [blame] | 177 | } |
| 178 | } |
| 179 | |
Aaron Durbin | 1c4289d | 2013-06-21 14:06:11 -0500 | [diff] [blame] | 180 | static void pcie_enable_clock_gating(void) |
| 181 | { |
| 182 | int i; |
| 183 | int is_lp; |
| 184 | int enabled_ports; |
| 185 | |
| 186 | is_lp = pch_is_lp(); |
| 187 | enabled_ports = 0; |
| 188 | |
| 189 | for (i = 0; i < rpc.num_ports; i++) { |
Elyes HAOUAS | 7a5f771 | 2018-06-08 17:20:38 +0200 | [diff] [blame^] | 190 | struct device *dev; |
Aaron Durbin | 1c4289d | 2013-06-21 14:06:11 -0500 | [diff] [blame] | 191 | int rp; |
| 192 | |
| 193 | dev = rpc.ports[i]; |
| 194 | rp = root_port_number(dev); |
| 195 | |
| 196 | if (!dev->enabled) { |
Ryan Salsamendi | 3f2fe18 | 2017-07-04 13:14:16 -0700 | [diff] [blame] | 197 | static const uint32_t high_bit = (1UL << 31); |
| 198 | |
Aaron Durbin | 1c4289d | 2013-06-21 14:06:11 -0500 | [diff] [blame] | 199 | /* Configure shared resource clock gating. */ |
| 200 | if (rp == 1 || rp == 5 || (rp == 6 && is_lp)) |
Kyösti Mälkki | 48c389e | 2013-07-26 08:53:59 +0300 | [diff] [blame] | 201 | pci_update_config8(dev, 0xe1, 0xc3, 0x3c); |
Aaron Durbin | 1c4289d | 2013-06-21 14:06:11 -0500 | [diff] [blame] | 202 | |
| 203 | if (!is_lp) { |
| 204 | if (rp == 1 && !rpc.ports[1]->enabled && |
| 205 | !rpc.ports[2]->enabled && |
| 206 | !rpc.ports[3]->enabled) { |
Kyösti Mälkki | 48c389e | 2013-07-26 08:53:59 +0300 | [diff] [blame] | 207 | pci_update_config8(dev, 0xe2, ~1, 1); |
| 208 | pci_update_config8(dev, 0xe1, 0x7f, 0x80); |
Aaron Durbin | 1c4289d | 2013-06-21 14:06:11 -0500 | [diff] [blame] | 209 | } |
| 210 | if (rp == 5 && !rpc.ports[5]->enabled && |
| 211 | !rpc.ports[6]->enabled && |
| 212 | !rpc.ports[7]->enabled) { |
Kyösti Mälkki | 48c389e | 2013-07-26 08:53:59 +0300 | [diff] [blame] | 213 | pci_update_config8(dev, 0xe2, ~1, 1); |
| 214 | pci_update_config8(dev, 0xe1, 0x7f, 0x80); |
Aaron Durbin | 1c4289d | 2013-06-21 14:06:11 -0500 | [diff] [blame] | 215 | } |
| 216 | continue; |
| 217 | } |
| 218 | |
Kyösti Mälkki | 48c389e | 2013-07-26 08:53:59 +0300 | [diff] [blame] | 219 | pci_update_config8(dev, 0xe2, ~(3 << 4), (3 << 4)); |
Ryan Salsamendi | 3f2fe18 | 2017-07-04 13:14:16 -0700 | [diff] [blame] | 220 | pci_update_config32(dev, 0x420, ~high_bit, high_bit); |
Aaron Durbin | 1c4289d | 2013-06-21 14:06:11 -0500 | [diff] [blame] | 221 | |
| 222 | /* Per-Port CLKREQ# handling. */ |
| 223 | if (is_lp && gpio_is_native(18 + rp - 1)) |
Kyösti Mälkki | 48c389e | 2013-07-26 08:53:59 +0300 | [diff] [blame] | 224 | pci_update_config32(dev, 0x420, ~0, (3 << 29)); |
Aaron Durbin | 1c4289d | 2013-06-21 14:06:11 -0500 | [diff] [blame] | 225 | |
| 226 | /* Enable static clock gating. */ |
| 227 | if (rp == 1 && !rpc.ports[1]->enabled && |
| 228 | !rpc.ports[2]->enabled && !rpc.ports[3]->enabled) { |
Kyösti Mälkki | 48c389e | 2013-07-26 08:53:59 +0300 | [diff] [blame] | 229 | pci_update_config8(dev, 0xe2, ~1, 1); |
| 230 | pci_update_config8(dev, 0xe1, 0x7f, 0x80); |
Aaron Durbin | 1c4289d | 2013-06-21 14:06:11 -0500 | [diff] [blame] | 231 | } else if (rp == 5 || rp == 6) { |
Kyösti Mälkki | 48c389e | 2013-07-26 08:53:59 +0300 | [diff] [blame] | 232 | pci_update_config8(dev, 0xe2, ~1, 1); |
| 233 | pci_update_config8(dev, 0xe1, 0x7f, 0x80); |
Aaron Durbin | 1c4289d | 2013-06-21 14:06:11 -0500 | [diff] [blame] | 234 | } |
| 235 | continue; |
| 236 | } |
| 237 | |
| 238 | enabled_ports++; |
| 239 | |
| 240 | /* Enable dynamic clock gating. */ |
Kyösti Mälkki | 48c389e | 2013-07-26 08:53:59 +0300 | [diff] [blame] | 241 | pci_update_config8(dev, 0xe1, 0xfc, 0x03); |
Aaron Durbin | 1c4289d | 2013-06-21 14:06:11 -0500 | [diff] [blame] | 242 | |
| 243 | if (is_lp) { |
Kyösti Mälkki | 48c389e | 2013-07-26 08:53:59 +0300 | [diff] [blame] | 244 | pci_update_config8(dev, 0xe2, ~(1 << 6), (1 << 6)); |
| 245 | pci_update_config8(dev, 0xe8, ~(3 << 2), (2 << 2)); |
Aaron Durbin | 1c4289d | 2013-06-21 14:06:11 -0500 | [diff] [blame] | 246 | } |
| 247 | |
| 248 | /* Update PECR1 register. */ |
Kyösti Mälkki | 48c389e | 2013-07-26 08:53:59 +0300 | [diff] [blame] | 249 | pci_update_config8(dev, 0xe8, ~0, 1); |
Aaron Durbin | 1c4289d | 2013-06-21 14:06:11 -0500 | [diff] [blame] | 250 | |
Kyösti Mälkki | 48c389e | 2013-07-26 08:53:59 +0300 | [diff] [blame] | 251 | pci_update_config8(dev, 0x324, ~(1 << 5), (1 < 5)); |
Aaron Durbin | 1c4289d | 2013-06-21 14:06:11 -0500 | [diff] [blame] | 252 | |
| 253 | /* Per-Port CLKREQ# handling. */ |
| 254 | if (is_lp && gpio_is_native(18 + rp - 1)) |
Kyösti Mälkki | 48c389e | 2013-07-26 08:53:59 +0300 | [diff] [blame] | 255 | pci_update_config32(dev, 0x420, ~0, (3 << 29)); |
Aaron Durbin | 1c4289d | 2013-06-21 14:06:11 -0500 | [diff] [blame] | 256 | |
| 257 | /* Configure shared resource clock gating. */ |
| 258 | if (rp == 1 || rp == 5 || (rp == 6 && is_lp)) |
Kyösti Mälkki | 48c389e | 2013-07-26 08:53:59 +0300 | [diff] [blame] | 259 | pci_update_config8(dev, 0xe1, 0xc3, 0x3c); |
Aaron Durbin | 1c4289d | 2013-06-21 14:06:11 -0500 | [diff] [blame] | 260 | } |
| 261 | |
| 262 | if (!enabled_ports && is_lp) |
Kyösti Mälkki | 48c389e | 2013-07-26 08:53:59 +0300 | [diff] [blame] | 263 | pci_update_config8(rpc.ports[0], 0xe1, ~(1 << 6), (1 << 6)); |
Aaron Durbin | 1c4289d | 2013-06-21 14:06:11 -0500 | [diff] [blame] | 264 | } |
| 265 | |
Aaron Durbin | c0254e6 | 2013-06-20 01:20:30 -0500 | [diff] [blame] | 266 | static void root_port_commit_config(void) |
Aaron Durbin | 60f8208 | 2013-06-19 13:28:04 -0500 | [diff] [blame] | 267 | { |
Aaron Durbin | c0254e6 | 2013-06-20 01:20:30 -0500 | [diff] [blame] | 268 | int i; |
Aaron Durbin | 60f8208 | 2013-06-19 13:28:04 -0500 | [diff] [blame] | 269 | |
Aaron Durbin | c0254e6 | 2013-06-20 01:20:30 -0500 | [diff] [blame] | 270 | /* If the first root port is disabled the coalesce ports. */ |
| 271 | if (!rpc.ports[0]->enabled) |
| 272 | rpc.coalesce = 1; |
Aaron Durbin | 60f8208 | 2013-06-19 13:28:04 -0500 | [diff] [blame] | 273 | |
Aaron Durbin | 1c4289d | 2013-06-21 14:06:11 -0500 | [diff] [blame] | 274 | /* Perform clock gating configuration. */ |
| 275 | pcie_enable_clock_gating(); |
| 276 | |
Aaron Durbin | c0254e6 | 2013-06-20 01:20:30 -0500 | [diff] [blame] | 277 | for (i = 0; i < rpc.num_ports; i++) { |
Elyes HAOUAS | 7a5f771 | 2018-06-08 17:20:38 +0200 | [diff] [blame^] | 278 | struct device *dev; |
Aaron Durbin | c0254e6 | 2013-06-20 01:20:30 -0500 | [diff] [blame] | 279 | u32 reg32; |
Aaron Durbin | 60f8208 | 2013-06-19 13:28:04 -0500 | [diff] [blame] | 280 | |
Aaron Durbin | c0254e6 | 2013-06-20 01:20:30 -0500 | [diff] [blame] | 281 | dev = rpc.ports[i]; |
Aaron Durbin | 60f8208 | 2013-06-19 13:28:04 -0500 | [diff] [blame] | 282 | |
Aaron Durbin | c0254e6 | 2013-06-20 01:20:30 -0500 | [diff] [blame] | 283 | if (dev == NULL) { |
| 284 | printk(BIOS_ERR, "Root Port %d device is NULL?\n", i+1); |
| 285 | continue; |
Aaron Durbin | 60f8208 | 2013-06-19 13:28:04 -0500 | [diff] [blame] | 286 | } |
| 287 | |
Aaron Durbin | c0254e6 | 2013-06-20 01:20:30 -0500 | [diff] [blame] | 288 | if (dev->enabled) |
| 289 | continue; |
| 290 | |
| 291 | printk(BIOS_DEBUG, "%s: Disabling device\n", dev_path(dev)); |
| 292 | |
Aaron Durbin | 60f8208 | 2013-06-19 13:28:04 -0500 | [diff] [blame] | 293 | /* Ensure memory, io, and bus master are all disabled */ |
| 294 | reg32 = pci_read_config32(dev, PCI_COMMAND); |
| 295 | reg32 &= ~(PCI_COMMAND_MASTER | |
| 296 | PCI_COMMAND_MEMORY | PCI_COMMAND_IO); |
| 297 | pci_write_config32(dev, PCI_COMMAND, reg32); |
| 298 | |
Aaron Durbin | 60f8208 | 2013-06-19 13:28:04 -0500 | [diff] [blame] | 299 | /* Disable this device if possible */ |
| 300 | pch_disable_devfn(dev); |
Aaron Durbin | 60f8208 | 2013-06-19 13:28:04 -0500 | [diff] [blame] | 301 | } |
| 302 | |
Aaron Durbin | c0254e6 | 2013-06-20 01:20:30 -0500 | [diff] [blame] | 303 | if (rpc.coalesce) { |
| 304 | int current_func; |
Aaron Durbin | 60f8208 | 2013-06-19 13:28:04 -0500 | [diff] [blame] | 305 | |
Aaron Durbin | c0254e6 | 2013-06-20 01:20:30 -0500 | [diff] [blame] | 306 | /* For all Root Ports N enabled ports get assigned the lower |
| 307 | * PCI function number. The disabled ones get upper PCI |
| 308 | * function numbers. */ |
| 309 | current_func = 0; |
| 310 | for (i = 0; i < rpc.num_ports; i++) { |
| 311 | if (!rpc.ports[i]->enabled) |
| 312 | continue; |
| 313 | pch_pcie_device_set_func(i, current_func); |
| 314 | current_func++; |
| 315 | } |
| 316 | |
| 317 | /* Allocate the disabled devices' PCI function number. */ |
| 318 | for (i = 0; i < rpc.num_ports; i++) { |
| 319 | if (rpc.ports[i]->enabled) |
| 320 | continue; |
| 321 | pch_pcie_device_set_func(i, current_func); |
| 322 | current_func++; |
| 323 | } |
| 324 | } |
| 325 | |
| 326 | printk(BIOS_SPEW, "PCH: RPFN 0x%08x -> 0x%08x\n", |
| 327 | rpc.orig_rpfn, rpc.new_rpfn); |
| 328 | RCBA32(RPFN) = rpc.new_rpfn; |
| 329 | } |
| 330 | |
Elyes HAOUAS | 7a5f771 | 2018-06-08 17:20:38 +0200 | [diff] [blame^] | 331 | static void root_port_mark_disable(struct device *dev) |
Aaron Durbin | c0254e6 | 2013-06-20 01:20:30 -0500 | [diff] [blame] | 332 | { |
| 333 | /* Mark device as disabled. */ |
| 334 | dev->enabled = 0; |
| 335 | /* Mark device to be hidden. */ |
| 336 | rpc.new_rpfn |= RPFN_HIDE(PCI_FUNC(dev->path.pci.devfn)); |
| 337 | } |
| 338 | |
Elyes HAOUAS | 7a5f771 | 2018-06-08 17:20:38 +0200 | [diff] [blame^] | 339 | static void root_port_check_disable(struct device *dev) |
Aaron Durbin | c0254e6 | 2013-06-20 01:20:30 -0500 | [diff] [blame] | 340 | { |
| 341 | int rp; |
| 342 | int is_lp; |
| 343 | |
| 344 | /* Device already disabled. */ |
| 345 | if (!dev->enabled) { |
| 346 | root_port_mark_disable(dev); |
| 347 | return; |
| 348 | } |
| 349 | |
| 350 | rp = root_port_number(dev); |
| 351 | |
| 352 | /* Is the GbE port mapped to this Root Port? */ |
| 353 | if (rp == rpc.gbe_port) { |
| 354 | root_port_mark_disable(dev); |
| 355 | return; |
| 356 | } |
| 357 | |
| 358 | is_lp = pch_is_lp(); |
| 359 | |
| 360 | /* Check Root Port Configuration. */ |
| 361 | switch (rp) { |
| 362 | case 2: |
| 363 | /* Root Port 2 is disabled for all lane configurations |
| 364 | * but config 00b (4x1 links). */ |
| 365 | if ((rpc.strpfusecfg1 >> 14) & 0x3) { |
| 366 | root_port_mark_disable(dev); |
| 367 | return; |
| 368 | } |
| 369 | break; |
| 370 | case 3: |
| 371 | /* Root Port 3 is disabled in config 11b (1x4 links). */ |
| 372 | if (((rpc.strpfusecfg1 >> 14) & 0x3) == 0x3) { |
| 373 | root_port_mark_disable(dev); |
| 374 | return; |
| 375 | } |
| 376 | break; |
| 377 | case 4: |
| 378 | /* Root Port 4 is disabled in configs 11b (1x4 links) |
| 379 | * and 10b (2x2 links). */ |
| 380 | if ((rpc.strpfusecfg1 >> 14) & 0x2) { |
| 381 | root_port_mark_disable(dev); |
| 382 | return; |
| 383 | } |
| 384 | break; |
| 385 | case 6: |
| 386 | if (is_lp) |
| 387 | break; |
| 388 | /* Root Port 6 is disabled for all lane configurations |
| 389 | * but config 00b (4x1 links). */ |
| 390 | if ((rpc.strpfusecfg2 >> 14) & 0x3) { |
| 391 | root_port_mark_disable(dev); |
| 392 | return; |
| 393 | } |
| 394 | break; |
| 395 | case 7: |
| 396 | if (is_lp) |
| 397 | break; |
| 398 | /* Root Port 3 is disabled in config 11b (1x4 links). */ |
| 399 | if (((rpc.strpfusecfg2 >> 14) & 0x3) == 0x3) { |
| 400 | root_port_mark_disable(dev); |
| 401 | return; |
| 402 | } |
| 403 | break; |
| 404 | case 8: |
| 405 | if (is_lp) |
| 406 | break; |
| 407 | /* Root Port 8 is disabled in configs 11b (1x4 links) |
| 408 | * and 10b (2x2 links). */ |
| 409 | if ((rpc.strpfusecfg2 >> 14) & 0x2) { |
| 410 | root_port_mark_disable(dev); |
| 411 | return; |
| 412 | } |
| 413 | break; |
| 414 | } |
| 415 | |
| 416 | /* Check Pin Ownership. */ |
| 417 | if (is_lp) { |
| 418 | switch (rp) { |
| 419 | case 1: |
| 420 | /* Bit 0 is Root Port 1 ownership. */ |
| 421 | if ((rpc.pin_ownership & 0x1) == 0) { |
| 422 | root_port_mark_disable(dev); |
| 423 | return; |
| 424 | } |
| 425 | break; |
| 426 | case 2: |
| 427 | /* Bit 2 is Root Port 2 ownership. */ |
| 428 | if ((rpc.pin_ownership & 0x4) == 0) { |
| 429 | root_port_mark_disable(dev); |
| 430 | return; |
| 431 | } |
| 432 | break; |
| 433 | case 6: |
| 434 | /* Bits 7:4 are Root Port 6 pin-lane ownership. */ |
| 435 | if ((rpc.pin_ownership & 0xf0) == 0) { |
| 436 | root_port_mark_disable(dev); |
| 437 | return; |
| 438 | } |
| 439 | break; |
| 440 | } |
| 441 | } else { |
| 442 | switch (rp) { |
| 443 | case 1: |
| 444 | /* Bits 4 and 0 are Root Port 1 ownership. */ |
| 445 | if ((rpc.pin_ownership & 0x11) == 0) { |
| 446 | root_port_mark_disable(dev); |
| 447 | return; |
| 448 | } |
| 449 | break; |
| 450 | case 2: |
| 451 | /* Bits 5 and 2 are Root Port 2 ownership. */ |
| 452 | if ((rpc.pin_ownership & 0x24) == 0) { |
| 453 | root_port_mark_disable(dev); |
| 454 | return; |
| 455 | } |
| 456 | break; |
| 457 | } |
Aaron Durbin | 60f8208 | 2013-06-19 13:28:04 -0500 | [diff] [blame] | 458 | } |
| 459 | } |
| 460 | |
Stefan Reinauer | ab365af | 2013-12-03 12:13:26 -0800 | [diff] [blame] | 461 | static void pcie_add_0x0202000_iobp(u32 reg) |
| 462 | { |
| 463 | u32 reg32; |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 464 | |
Stefan Reinauer | ab365af | 2013-12-03 12:13:26 -0800 | [diff] [blame] | 465 | reg32 = pch_iobp_read(reg); |
| 466 | reg32 += (0x2 << 16) | (0x2 << 8); |
| 467 | pch_iobp_write(reg, reg32); |
| 468 | } |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 469 | |
Stefan Reinauer | ab365af | 2013-12-03 12:13:26 -0800 | [diff] [blame] | 470 | static void pch_pcie_early(struct device *dev) |
| 471 | { |
| 472 | int rp; |
| 473 | int do_aspm; |
| 474 | int is_lp; |
Duncan Laurie | 249a03b | 2013-08-09 09:06:41 -0700 | [diff] [blame] | 475 | struct southbridge_intel_lynxpoint_config *config = dev->chip_info; |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 476 | |
Stefan Reinauer | ab365af | 2013-12-03 12:13:26 -0800 | [diff] [blame] | 477 | rp = root_port_number(dev); |
| 478 | do_aspm = 0; |
| 479 | is_lp = pch_is_lp(); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 480 | |
Stefan Reinauer | ab365af | 2013-12-03 12:13:26 -0800 | [diff] [blame] | 481 | if (is_lp) { |
| 482 | switch (rp) { |
| 483 | case 1: |
| 484 | case 2: |
| 485 | case 3: |
| 486 | case 4: |
| 487 | /* Bits 31:28 of b0d28f0 0x32c register correspnd to |
| 488 | * Root Ports 4:1. */ |
| 489 | do_aspm = !!(rpc.b0d28f0_32c & (1 << (28 + rp - 1))); |
| 490 | break; |
| 491 | case 5: |
| 492 | /* Bit 28 of b0d28f4 0x32c register correspnd to |
| 493 | * Root Ports 4:1. */ |
| 494 | do_aspm = !!(rpc.b0d28f4_32c & (1 << 28)); |
| 495 | break; |
| 496 | case 6: |
| 497 | /* Bit 28 of b0d28f5 0x32c register correspnd to |
| 498 | * Root Ports 4:1. */ |
| 499 | do_aspm = !!(rpc.b0d28f5_32c & (1 << 28)); |
| 500 | break; |
| 501 | } |
| 502 | } else { |
| 503 | switch (rp) { |
| 504 | case 1: |
| 505 | case 2: |
| 506 | case 3: |
| 507 | case 4: |
| 508 | /* Bits 31:28 of b0d28f0 0x32c register correspnd to |
| 509 | * Root Ports 4:1. */ |
| 510 | do_aspm = !!(rpc.b0d28f0_32c & (1 << (28 + rp - 1))); |
| 511 | break; |
| 512 | case 5: |
| 513 | case 6: |
| 514 | case 7: |
| 515 | case 8: |
| 516 | /* Bit 31:28 of b0d28f4 0x32c register correspnd to |
| 517 | * Root Ports 8:5. */ |
| 518 | do_aspm = !!(rpc.b0d28f4_32c & (1 << (28 + rp - 5))); |
| 519 | break; |
| 520 | } |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 521 | } |
Stefan Reinauer | ab365af | 2013-12-03 12:13:26 -0800 | [diff] [blame] | 522 | |
Duncan Laurie | 249a03b | 2013-08-09 09:06:41 -0700 | [diff] [blame] | 523 | /* Allow ASPM to be forced on in devicetree */ |
| 524 | if (config && (config->pcie_port_force_aspm & (1 << (rp - 1)))) |
| 525 | do_aspm = 1; |
| 526 | |
| 527 | printk(BIOS_DEBUG, "PCIe Root Port %d ASPM is %sabled\n", |
| 528 | rp, do_aspm ? "en" : "dis"); |
| 529 | |
Stefan Reinauer | ab365af | 2013-12-03 12:13:26 -0800 | [diff] [blame] | 530 | if (do_aspm) { |
| 531 | /* Set ASPM bits in MPC2 register. */ |
Kyösti Mälkki | 48c389e | 2013-07-26 08:53:59 +0300 | [diff] [blame] | 532 | pci_update_config32(dev, 0xd4, ~(0x3 << 2), (1 << 4) | (0x2 << 2)); |
Stefan Reinauer | ab365af | 2013-12-03 12:13:26 -0800 | [diff] [blame] | 533 | |
| 534 | /* Set unique clock exit latency in MPC register. */ |
Kyösti Mälkki | 48c389e | 2013-07-26 08:53:59 +0300 | [diff] [blame] | 535 | pci_update_config32(dev, 0xd8, ~(0x7 << 18), (0x7 << 18)); |
Stefan Reinauer | ab365af | 2013-12-03 12:13:26 -0800 | [diff] [blame] | 536 | |
| 537 | /* Set L1 exit latency in LCAP register. */ |
Kyösti Mälkki | 48c389e | 2013-07-26 08:53:59 +0300 | [diff] [blame] | 538 | pci_update_config32(dev, 0x4c, ~(0x7 << 15), (0x4 << 15)); |
Stefan Reinauer | ab365af | 2013-12-03 12:13:26 -0800 | [diff] [blame] | 539 | |
| 540 | if (is_lp) { |
| 541 | switch (rp) { |
| 542 | case 1: |
| 543 | pcie_add_0x0202000_iobp(0xe9002440); |
| 544 | break; |
| 545 | case 2: |
| 546 | pcie_add_0x0202000_iobp(0xe9002640); |
| 547 | break; |
| 548 | case 3: |
| 549 | pcie_add_0x0202000_iobp(0xe9000840); |
| 550 | break; |
| 551 | case 4: |
| 552 | pcie_add_0x0202000_iobp(0xe9000a40); |
| 553 | break; |
| 554 | case 5: |
| 555 | pcie_add_0x0202000_iobp(0xe9000c40); |
| 556 | pcie_add_0x0202000_iobp(0xe9000e40); |
| 557 | pcie_add_0x0202000_iobp(0xe9001040); |
| 558 | pcie_add_0x0202000_iobp(0xe9001240); |
| 559 | break; |
| 560 | case 6: |
| 561 | /* Update IOBP based on lane ownership. */ |
| 562 | if (rpc.pin_ownership & (1 << 4)) |
| 563 | pcie_add_0x0202000_iobp(0xea002040); |
| 564 | if (rpc.pin_ownership & (1 << 5)) |
| 565 | pcie_add_0x0202000_iobp(0xea002240); |
| 566 | if (rpc.pin_ownership & (1 << 6)) |
| 567 | pcie_add_0x0202000_iobp(0xea002440); |
| 568 | if (rpc.pin_ownership & (1 << 7)) |
| 569 | pcie_add_0x0202000_iobp(0xea002640); |
| 570 | break; |
| 571 | } |
| 572 | } else { |
| 573 | switch (rp) { |
| 574 | case 1: |
| 575 | if ((rpc.pin_ownership & 0x3) == 1) |
| 576 | pcie_add_0x0202000_iobp(0xe9002e40); |
| 577 | else |
| 578 | pcie_add_0x0202000_iobp(0xea002040); |
| 579 | break; |
| 580 | case 2: |
| 581 | if ((rpc.pin_ownership & 0xc) == 0x4) |
| 582 | pcie_add_0x0202000_iobp(0xe9002c40); |
| 583 | else |
| 584 | pcie_add_0x0202000_iobp(0xea002240); |
| 585 | break; |
| 586 | case 3: |
| 587 | pcie_add_0x0202000_iobp(0xe9002a40); |
| 588 | break; |
| 589 | case 4: |
| 590 | pcie_add_0x0202000_iobp(0xe9002840); |
| 591 | break; |
| 592 | case 5: |
| 593 | pcie_add_0x0202000_iobp(0xe9002640); |
| 594 | break; |
| 595 | case 6: |
| 596 | pcie_add_0x0202000_iobp(0xe9002440); |
| 597 | break; |
| 598 | case 7: |
| 599 | pcie_add_0x0202000_iobp(0xe9002240); |
| 600 | break; |
| 601 | case 8: |
| 602 | pcie_add_0x0202000_iobp(0xe9002040); |
| 603 | break; |
| 604 | } |
| 605 | } |
| 606 | |
Kyösti Mälkki | 48c389e | 2013-07-26 08:53:59 +0300 | [diff] [blame] | 607 | pci_update_config32(dev, 0x338, ~(1 << 26), 0); |
Stefan Reinauer | ab365af | 2013-12-03 12:13:26 -0800 | [diff] [blame] | 608 | } |
| 609 | |
| 610 | /* Enable LTR in Root Port. */ |
Kyösti Mälkki | 48c389e | 2013-07-26 08:53:59 +0300 | [diff] [blame] | 611 | pci_update_config32(dev, 0x64, ~(1 << 11), (1 << 11)); |
| 612 | pci_update_config32(dev, 0x68, ~(1 << 10), (1 << 10)); |
Stefan Reinauer | ab365af | 2013-12-03 12:13:26 -0800 | [diff] [blame] | 613 | |
Ryan Salsamendi | 0d9b360 | 2017-06-30 17:15:57 -0700 | [diff] [blame] | 614 | pci_update_config32(dev, 0x318, ~(0xffffUL << 16), (0x1414UL << 16)); |
Stefan Reinauer | ab365af | 2013-12-03 12:13:26 -0800 | [diff] [blame] | 615 | |
| 616 | /* Set L1 exit latency in LCAP register. */ |
| 617 | if (!do_aspm && (pci_read_config8(dev, 0xf5) & 0x1)) |
Kyösti Mälkki | 48c389e | 2013-07-26 08:53:59 +0300 | [diff] [blame] | 618 | pci_update_config32(dev, 0x4c, ~(0x7 << 15), (0x4 << 15)); |
Stefan Reinauer | ab365af | 2013-12-03 12:13:26 -0800 | [diff] [blame] | 619 | else |
Kyösti Mälkki | 48c389e | 2013-07-26 08:53:59 +0300 | [diff] [blame] | 620 | pci_update_config32(dev, 0x4c, ~(0x7 << 15), (0x2 << 15)); |
Stefan Reinauer | ab365af | 2013-12-03 12:13:26 -0800 | [diff] [blame] | 621 | |
Kyösti Mälkki | 48c389e | 2013-07-26 08:53:59 +0300 | [diff] [blame] | 622 | pci_update_config32(dev, 0x314, 0x0, 0x743a361b); |
Stefan Reinauer | ab365af | 2013-12-03 12:13:26 -0800 | [diff] [blame] | 623 | |
| 624 | /* Set Common Clock Exit Latency in MPC register. */ |
Kyösti Mälkki | 48c389e | 2013-07-26 08:53:59 +0300 | [diff] [blame] | 625 | pci_update_config32(dev, 0xd8, ~(0x7 << 15), (0x3 << 15)); |
Stefan Reinauer | ab365af | 2013-12-03 12:13:26 -0800 | [diff] [blame] | 626 | |
Kyösti Mälkki | 48c389e | 2013-07-26 08:53:59 +0300 | [diff] [blame] | 627 | pci_update_config32(dev, 0x33c, ~0x00ffffff, 0x854c74); |
Stefan Reinauer | ab365af | 2013-12-03 12:13:26 -0800 | [diff] [blame] | 628 | |
Stefan Reinauer | ab365af | 2013-12-03 12:13:26 -0800 | [diff] [blame] | 629 | /* Set Invalid Recieve Range Check Enable in MPC register. */ |
Kyösti Mälkki | 48c389e | 2013-07-26 08:53:59 +0300 | [diff] [blame] | 630 | pci_update_config32(dev, 0xd8, ~0, (1 << 25)); |
Stefan Reinauer | ab365af | 2013-12-03 12:13:26 -0800 | [diff] [blame] | 631 | |
Kyösti Mälkki | 48c389e | 2013-07-26 08:53:59 +0300 | [diff] [blame] | 632 | pci_update_config8(dev, 0xf5, 0x3f, 0); |
Stefan Reinauer | ab365af | 2013-12-03 12:13:26 -0800 | [diff] [blame] | 633 | |
| 634 | if (rp == 1 || rp == 5 || (is_lp && rp == 6)) |
Kyösti Mälkki | 48c389e | 2013-07-26 08:53:59 +0300 | [diff] [blame] | 635 | pci_update_config8(dev, 0xf7, ~0xc, 0); |
Stefan Reinauer | ab365af | 2013-12-03 12:13:26 -0800 | [diff] [blame] | 636 | |
| 637 | /* Set EOI forwarding disable. */ |
Kyösti Mälkki | 48c389e | 2013-07-26 08:53:59 +0300 | [diff] [blame] | 638 | pci_update_config32(dev, 0xd4, ~0, (1 << 1)); |
Stefan Reinauer | ab365af | 2013-12-03 12:13:26 -0800 | [diff] [blame] | 639 | |
| 640 | /* Set something involving advanced error reporting. */ |
Kyösti Mälkki | 48c389e | 2013-07-26 08:53:59 +0300 | [diff] [blame] | 641 | pci_update_config32(dev, 0x100, ~((1 << 20) - 1), 0x10001); |
Stefan Reinauer | ab365af | 2013-12-03 12:13:26 -0800 | [diff] [blame] | 642 | |
| 643 | if (is_lp) |
Kyösti Mälkki | 48c389e | 2013-07-26 08:53:59 +0300 | [diff] [blame] | 644 | pci_update_config32(dev, 0x100, ~0, (1 << 29)); |
Stefan Reinauer | ab365af | 2013-12-03 12:13:26 -0800 | [diff] [blame] | 645 | |
| 646 | /* Read and write back write-once capability registers. */ |
Kyösti Mälkki | 48c389e | 2013-07-26 08:53:59 +0300 | [diff] [blame] | 647 | pci_update_config32(dev, 0x34, ~0, 0); |
| 648 | pci_update_config32(dev, 0x40, ~0, 0); |
| 649 | pci_update_config32(dev, 0x80, ~0, 0); |
| 650 | pci_update_config32(dev, 0x90, ~0, 0); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 651 | } |
| 652 | |
| 653 | static void pci_init(struct device *dev) |
| 654 | { |
| 655 | u16 reg16; |
| 656 | u32 reg32; |
| 657 | |
| 658 | printk(BIOS_DEBUG, "Initializing PCH PCIe bridge.\n"); |
| 659 | |
Aaron Durbin | c0254e6 | 2013-06-20 01:20:30 -0500 | [diff] [blame] | 660 | /* Enable SERR */ |
| 661 | reg32 = pci_read_config32(dev, PCI_COMMAND); |
| 662 | reg32 |= PCI_COMMAND_SERR; |
| 663 | pci_write_config32(dev, PCI_COMMAND, reg32); |
| 664 | |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 665 | /* Enable Bus Master */ |
| 666 | reg32 = pci_read_config32(dev, PCI_COMMAND); |
| 667 | reg32 |= PCI_COMMAND_MASTER; |
| 668 | pci_write_config32(dev, PCI_COMMAND, reg32); |
| 669 | |
| 670 | /* Set Cache Line Size to 0x10 */ |
| 671 | // This has no effect but the OS might expect it |
| 672 | pci_write_config8(dev, 0x0c, 0x10); |
| 673 | |
| 674 | reg16 = pci_read_config16(dev, 0x3e); |
| 675 | reg16 &= ~(1 << 0); /* disable parity error response */ |
| 676 | // reg16 &= ~(1 << 1); /* disable SERR */ |
| 677 | reg16 |= (1 << 2); /* ISA enable */ |
| 678 | pci_write_config16(dev, 0x3e, reg16); |
| 679 | |
| 680 | #ifdef EVEN_MORE_DEBUG |
| 681 | reg32 = pci_read_config32(dev, 0x20); |
| 682 | printk(BIOS_SPEW, " MBL = 0x%08x\n", reg32); |
| 683 | reg32 = pci_read_config32(dev, 0x24); |
| 684 | printk(BIOS_SPEW, " PMBL = 0x%08x\n", reg32); |
| 685 | reg32 = pci_read_config32(dev, 0x28); |
| 686 | printk(BIOS_SPEW, " PMBU32 = 0x%08x\n", reg32); |
| 687 | reg32 = pci_read_config32(dev, 0x2c); |
| 688 | printk(BIOS_SPEW, " PMLU32 = 0x%08x\n", reg32); |
| 689 | #endif |
| 690 | |
| 691 | /* Clear errors in status registers */ |
| 692 | reg16 = pci_read_config16(dev, 0x06); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 693 | pci_write_config16(dev, 0x06, reg16); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 694 | reg16 = pci_read_config16(dev, 0x1e); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 695 | pci_write_config16(dev, 0x1e, reg16); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 696 | } |
| 697 | |
Elyes HAOUAS | 7a5f771 | 2018-06-08 17:20:38 +0200 | [diff] [blame^] | 698 | static void pch_pcie_enable(struct device *dev) |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 699 | { |
Aaron Durbin | c0254e6 | 2013-06-20 01:20:30 -0500 | [diff] [blame] | 700 | /* Add this device to the root port config structure. */ |
| 701 | root_port_init_config(dev); |
| 702 | |
| 703 | /* Check to see if this Root Port should be disabled. */ |
| 704 | root_port_check_disable(dev); |
| 705 | |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 706 | /* Power Management init before enumeration */ |
Aaron Durbin | c0254e6 | 2013-06-20 01:20:30 -0500 | [diff] [blame] | 707 | if (dev->enabled) |
Stefan Reinauer | ab365af | 2013-12-03 12:13:26 -0800 | [diff] [blame] | 708 | pch_pcie_early(dev); |
Aaron Durbin | c0254e6 | 2013-06-20 01:20:30 -0500 | [diff] [blame] | 709 | |
| 710 | /* |
| 711 | * When processing the last PCIe root port we can now |
| 712 | * update the Root Port Function Number and Hide register. |
| 713 | */ |
| 714 | if (root_port_is_last(dev)) |
| 715 | root_port_commit_config(); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 716 | } |
| 717 | |
Elyes HAOUAS | 7a5f771 | 2018-06-08 17:20:38 +0200 | [diff] [blame^] | 718 | static void pcie_set_subsystem(struct device *dev, unsigned vendor, |
| 719 | unsigned device) |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 720 | { |
| 721 | /* NOTE: This is not the default position! */ |
| 722 | if (!vendor || !device) { |
| 723 | pci_write_config32(dev, 0x94, |
| 724 | pci_read_config32(dev, 0)); |
| 725 | } else { |
| 726 | pci_write_config32(dev, 0x94, |
| 727 | ((device & 0xffff) << 16) | (vendor & 0xffff)); |
| 728 | } |
| 729 | } |
| 730 | |
| 731 | static struct pci_operations pci_ops = { |
| 732 | .set_subsystem = pcie_set_subsystem, |
| 733 | }; |
| 734 | |
| 735 | static struct device_operations device_ops = { |
| 736 | .read_resources = pci_bus_read_resources, |
| 737 | .set_resources = pci_dev_set_resources, |
| 738 | .enable_resources = pci_bus_enable_resources, |
| 739 | .init = pci_init, |
| 740 | .enable = pch_pcie_enable, |
| 741 | .scan_bus = pciexp_scan_bridge, |
| 742 | .ops_pci = &pci_ops, |
| 743 | }; |
| 744 | |
Duncan Laurie | 74c0d05 | 2012-12-17 11:31:40 -0800 | [diff] [blame] | 745 | static const unsigned short pci_device_ids[] = { |
| 746 | /* Lynxpoint Mobile */ |
| 747 | 0x8c10, 0x8c12, 0x8c14, 0x8c16, 0x8c18, 0x8c1a, 0x8c1c, 0x8c1e, |
| 748 | /* Lynxpoint Low Power */ |
| 749 | 0x9c10, 0x9c12, 0x9c14, 0x9c16, 0x9c18, 0x9c1a, |
| 750 | 0 |
| 751 | }; |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 752 | |
| 753 | static const struct pci_driver pch_pcie __pci_driver = { |
| 754 | .ops = &device_ops, |
| 755 | .vendor = PCI_VENDOR_ID_INTEL, |
| 756 | .devices = pci_device_ids, |
| 757 | }; |