Aamir Bohra | 2d689f9 | 2017-05-11 20:27:27 +0530 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
praveen hodagatta pranesh | e26c4a4 | 2018-09-20 03:49:45 +0800 | [diff] [blame] | 4 | * Copyright (C) 2017-2018 Intel Corporation. |
Aamir Bohra | 2d689f9 | 2017-05-11 20:27:27 +0530 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; version 2 of the License. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | */ |
| 15 | |
| 16 | #include <console/console.h> |
| 17 | #include <device/pci.h> |
| 18 | #include <device/pciexp.h> |
| 19 | #include <device/pci_def.h> |
| 20 | #include <device/pci_ids.h> |
Patrick Rudolph | e56189c | 2018-04-18 10:11:59 +0200 | [diff] [blame] | 21 | #include <device/pci_ops.h> |
Aamir Bohra | 2d689f9 | 2017-05-11 20:27:27 +0530 | [diff] [blame] | 22 | |
| 23 | #define CACHE_LINE_SIZE 0x10 |
| 24 | /* Latency tolerance reporting, max non-snoop latency value 3.14ms */ |
| 25 | #define PCIE_LTR_MAX_NO_SNOOP_LATENCY_VALUE 0x1003 |
| 26 | /* Latency tolerance reporting, max snoop latency value 3.14ms */ |
| 27 | #define PCIE_LTR_MAX_SNOOP_LATENCY_VALUE 0x1003 |
Subrata Banik | 6bbc91a | 2017-12-07 14:55:51 +0530 | [diff] [blame] | 28 | /* PCI-E Sub-System ID */ |
| 29 | #define PCIE_SUBSYSTEM_VENDOR_ID 0x94 |
Aamir Bohra | 2d689f9 | 2017-05-11 20:27:27 +0530 | [diff] [blame] | 30 | |
| 31 | static void pch_pcie_init(struct device *dev) |
| 32 | { |
| 33 | u16 reg16; |
| 34 | |
| 35 | printk(BIOS_DEBUG, "Initializing PCH PCIe bridge.\n"); |
| 36 | |
| 37 | /* Enable SERR */ |
| 38 | pci_or_config32(dev, PCI_COMMAND, PCI_COMMAND_SERR); |
| 39 | |
| 40 | /* Enable Bus Master */ |
| 41 | pci_or_config32(dev, PCI_COMMAND, PCI_COMMAND_MASTER); |
| 42 | |
| 43 | /* Set Cache Line Size to 0x10 */ |
| 44 | pci_write_config8(dev, PCI_CACHE_LINE_SIZE, CACHE_LINE_SIZE); |
| 45 | |
| 46 | /* disable parity error response, enable ISA */ |
| 47 | pci_update_config16(dev, PCI_BRIDGE_CONTROL, ~1, 1<<2); |
| 48 | |
| 49 | if (IS_ENABLED(CONFIG_PCIE_DEBUG_INFO)) { |
| 50 | printk(BIOS_SPEW, " MBL = 0x%08x\n", |
| 51 | pci_read_config32(dev, PCI_MEMORY_BASE)); |
| 52 | printk(BIOS_SPEW, " PMBL = 0x%08x\n", |
| 53 | pci_read_config32(dev, PCI_PREF_MEMORY_BASE)); |
| 54 | printk(BIOS_SPEW, " PMBU32 = 0x%08x\n", |
| 55 | pci_read_config32(dev, PCI_PREF_BASE_UPPER32)); |
| 56 | printk(BIOS_SPEW, " PMLU32 = 0x%08x\n", |
| 57 | pci_read_config32(dev, PCI_PREF_LIMIT_UPPER32)); |
| 58 | } |
| 59 | |
| 60 | /* Clear errors in status registers */ |
| 61 | reg16 = pci_read_config16(dev, PCI_STATUS); |
| 62 | pci_write_config16(dev, PCI_STATUS, reg16); |
| 63 | reg16 = pci_read_config16(dev, PCI_SEC_STATUS); |
| 64 | pci_write_config16(dev, PCI_SEC_STATUS, reg16); |
| 65 | } |
| 66 | |
Elyes HAOUAS | 4a13126 | 2018-09-16 17:35:48 +0200 | [diff] [blame] | 67 | static void pcie_set_L1_ss_max_latency(struct device *dev, unsigned int offset) |
Aamir Bohra | 2d689f9 | 2017-05-11 20:27:27 +0530 | [diff] [blame] | 68 | { |
| 69 | /* Set max snoop and non-snoop latency for the SOC */ |
| 70 | pci_write_config32(dev, offset, |
| 71 | PCIE_LTR_MAX_NO_SNOOP_LATENCY_VALUE << 16 | |
| 72 | PCIE_LTR_MAX_SNOOP_LATENCY_VALUE); |
| 73 | } |
| 74 | |
Subrata Banik | 6bbc91a | 2017-12-07 14:55:51 +0530 | [diff] [blame] | 75 | static void pcie_dev_set_subsystem(struct device *dev, |
| 76 | unsigned vendor, unsigned device) |
| 77 | { |
| 78 | pci_write_config32(dev, PCIE_SUBSYSTEM_VENDOR_ID, |
| 79 | ((device & 0xffff) << 16) | (vendor & 0xffff)); |
| 80 | } |
| 81 | |
Aamir Bohra | 2d689f9 | 2017-05-11 20:27:27 +0530 | [diff] [blame] | 82 | static struct pci_operations pcie_ops = { |
| 83 | .set_L1_ss_latency = pcie_set_L1_ss_max_latency, |
Subrata Banik | 6bbc91a | 2017-12-07 14:55:51 +0530 | [diff] [blame] | 84 | .set_subsystem = pcie_dev_set_subsystem, |
Aamir Bohra | 2d689f9 | 2017-05-11 20:27:27 +0530 | [diff] [blame] | 85 | }; |
| 86 | |
| 87 | static struct device_operations device_ops = { |
| 88 | .read_resources = pci_bus_read_resources, |
| 89 | .set_resources = pci_dev_set_resources, |
| 90 | .enable_resources = pci_bus_enable_resources, |
| 91 | .init = pch_pcie_init, |
| 92 | .scan_bus = pciexp_scan_bridge, |
| 93 | .ops_pci = &pcie_ops, |
| 94 | }; |
| 95 | |
| 96 | static const unsigned short pcie_device_ids[] = { |
| 97 | PCI_DEVICE_ID_INTEL_SPT_LP_PCIE_RP1, |
| 98 | PCI_DEVICE_ID_INTEL_SPT_LP_PCIE_RP2, |
| 99 | PCI_DEVICE_ID_INTEL_SPT_LP_PCIE_RP3, |
| 100 | PCI_DEVICE_ID_INTEL_SPT_LP_PCIE_RP4, |
| 101 | PCI_DEVICE_ID_INTEL_SPT_LP_PCIE_RP5, |
| 102 | PCI_DEVICE_ID_INTEL_SPT_LP_PCIE_RP6, |
| 103 | PCI_DEVICE_ID_INTEL_SPT_LP_PCIE_RP7, |
| 104 | PCI_DEVICE_ID_INTEL_SPT_LP_PCIE_RP8, |
| 105 | PCI_DEVICE_ID_INTEL_SPT_LP_PCIE_RP9, |
| 106 | PCI_DEVICE_ID_INTEL_SPT_LP_PCIE_RP10, |
| 107 | PCI_DEVICE_ID_INTEL_SPT_LP_PCIE_RP11, |
| 108 | PCI_DEVICE_ID_INTEL_SPT_LP_PCIE_RP12, |
| 109 | PCI_DEVICE_ID_INTEL_SPT_H_PCIE_RP1, |
| 110 | PCI_DEVICE_ID_INTEL_SPT_H_PCIE_RP2, |
| 111 | PCI_DEVICE_ID_INTEL_SPT_H_PCIE_RP3, |
| 112 | PCI_DEVICE_ID_INTEL_SPT_H_PCIE_RP4, |
| 113 | PCI_DEVICE_ID_INTEL_SPT_H_PCIE_RP5, |
| 114 | PCI_DEVICE_ID_INTEL_SPT_H_PCIE_RP6, |
| 115 | PCI_DEVICE_ID_INTEL_SPT_H_PCIE_RP7, |
| 116 | PCI_DEVICE_ID_INTEL_SPT_H_PCIE_RP8, |
| 117 | PCI_DEVICE_ID_INTEL_SPT_H_PCIE_RP9, |
| 118 | PCI_DEVICE_ID_INTEL_SPT_H_PCIE_RP10, |
| 119 | PCI_DEVICE_ID_INTEL_SPT_H_PCIE_RP11, |
| 120 | PCI_DEVICE_ID_INTEL_SPT_H_PCIE_RP12, |
| 121 | PCI_DEVICE_ID_INTEL_SPT_H_PCIE_RP13, |
| 122 | PCI_DEVICE_ID_INTEL_SPT_H_PCIE_RP14, |
| 123 | PCI_DEVICE_ID_INTEL_SPT_H_PCIE_RP15, |
| 124 | PCI_DEVICE_ID_INTEL_SPT_H_PCIE_RP16, |
| 125 | PCI_DEVICE_ID_INTEL_SPT_H_PCIE_RP17, |
| 126 | PCI_DEVICE_ID_INTEL_SPT_H_PCIE_RP18, |
| 127 | PCI_DEVICE_ID_INTEL_SPT_H_PCIE_RP19, |
| 128 | PCI_DEVICE_ID_INTEL_SPT_H_PCIE_RP20, |
| 129 | PCI_DEVICE_ID_INTEL_KBP_H_PCIE_RP1, |
| 130 | PCI_DEVICE_ID_INTEL_KBP_H_PCIE_RP2, |
| 131 | PCI_DEVICE_ID_INTEL_KBP_H_PCIE_RP3, |
| 132 | PCI_DEVICE_ID_INTEL_KBP_H_PCIE_RP4, |
| 133 | PCI_DEVICE_ID_INTEL_KBP_H_PCIE_RP5, |
| 134 | PCI_DEVICE_ID_INTEL_KBP_H_PCIE_RP6, |
| 135 | PCI_DEVICE_ID_INTEL_KBP_H_PCIE_RP7, |
| 136 | PCI_DEVICE_ID_INTEL_KBP_H_PCIE_RP8, |
| 137 | PCI_DEVICE_ID_INTEL_KBP_H_PCIE_RP9, |
| 138 | PCI_DEVICE_ID_INTEL_KBP_H_PCIE_RP10, |
| 139 | PCI_DEVICE_ID_INTEL_KBP_H_PCIE_RP11, |
| 140 | PCI_DEVICE_ID_INTEL_KBP_H_PCIE_RP12, |
| 141 | PCI_DEVICE_ID_INTEL_KBP_H_PCIE_RP13, |
| 142 | PCI_DEVICE_ID_INTEL_KBP_H_PCIE_RP14, |
| 143 | PCI_DEVICE_ID_INTEL_KBP_H_PCIE_RP15, |
| 144 | PCI_DEVICE_ID_INTEL_KBP_H_PCIE_RP16, |
| 145 | PCI_DEVICE_ID_INTEL_KBP_H_PCIE_RP17, |
| 146 | PCI_DEVICE_ID_INTEL_KBP_H_PCIE_RP18, |
| 147 | PCI_DEVICE_ID_INTEL_KBP_H_PCIE_RP19, |
| 148 | PCI_DEVICE_ID_INTEL_KBP_H_PCIE_RP20, |
| 149 | PCI_DEVICE_ID_INTEL_KBP_H_PCIE_RP21, |
| 150 | PCI_DEVICE_ID_INTEL_KBP_H_PCIE_RP22, |
| 151 | PCI_DEVICE_ID_INTEL_KBP_H_PCIE_RP23, |
| 152 | PCI_DEVICE_ID_INTEL_KBP_H_PCIE_RP24, |
Lijian Zhao | bbedef9 | 2017-07-29 16:38:38 -0700 | [diff] [blame] | 153 | PCI_DEVICE_ID_INTEL_CNL_LP_PCIE_RP1, |
| 154 | PCI_DEVICE_ID_INTEL_CNL_LP_PCIE_RP2, |
| 155 | PCI_DEVICE_ID_INTEL_CNL_LP_PCIE_RP3, |
| 156 | PCI_DEVICE_ID_INTEL_CNL_LP_PCIE_RP4, |
| 157 | PCI_DEVICE_ID_INTEL_CNL_LP_PCIE_RP5, |
| 158 | PCI_DEVICE_ID_INTEL_CNL_LP_PCIE_RP6, |
| 159 | PCI_DEVICE_ID_INTEL_CNL_LP_PCIE_RP7, |
| 160 | PCI_DEVICE_ID_INTEL_CNL_LP_PCIE_RP8, |
| 161 | PCI_DEVICE_ID_INTEL_CNL_LP_PCIE_RP9, |
| 162 | PCI_DEVICE_ID_INTEL_CNL_LP_PCIE_RP10, |
| 163 | PCI_DEVICE_ID_INTEL_CNL_LP_PCIE_RP11, |
| 164 | PCI_DEVICE_ID_INTEL_CNL_LP_PCIE_RP12, |
| 165 | PCI_DEVICE_ID_INTEL_CNL_LP_PCIE_RP13, |
| 166 | PCI_DEVICE_ID_INTEL_CNL_LP_PCIE_RP14, |
| 167 | PCI_DEVICE_ID_INTEL_CNL_LP_PCIE_RP15, |
| 168 | PCI_DEVICE_ID_INTEL_CNL_LP_PCIE_RP16, |
praveen hodagatta pranesh | e26c4a4 | 2018-09-20 03:49:45 +0800 | [diff] [blame] | 169 | PCI_DEVICE_ID_INTEL_CNP_H_PCIE_RP1, |
| 170 | PCI_DEVICE_ID_INTEL_CNP_H_PCIE_RP2, |
| 171 | PCI_DEVICE_ID_INTEL_CNP_H_PCIE_RP3, |
| 172 | PCI_DEVICE_ID_INTEL_CNP_H_PCIE_RP4, |
| 173 | PCI_DEVICE_ID_INTEL_CNP_H_PCIE_RP5, |
| 174 | PCI_DEVICE_ID_INTEL_CNP_H_PCIE_RP6, |
| 175 | PCI_DEVICE_ID_INTEL_CNP_H_PCIE_RP7, |
| 176 | PCI_DEVICE_ID_INTEL_CNP_H_PCIE_RP8, |
| 177 | PCI_DEVICE_ID_INTEL_CNP_H_PCIE_RP9, |
| 178 | PCI_DEVICE_ID_INTEL_CNP_H_PCIE_RP10, |
| 179 | PCI_DEVICE_ID_INTEL_CNP_H_PCIE_RP11, |
| 180 | PCI_DEVICE_ID_INTEL_CNP_H_PCIE_RP12, |
| 181 | PCI_DEVICE_ID_INTEL_CNP_H_PCIE_RP13, |
| 182 | PCI_DEVICE_ID_INTEL_CNP_H_PCIE_RP14, |
| 183 | PCI_DEVICE_ID_INTEL_CNP_H_PCIE_RP15, |
| 184 | PCI_DEVICE_ID_INTEL_CNP_H_PCIE_RP16, |
| 185 | PCI_DEVICE_ID_INTEL_CNP_H_PCIE_RP17, |
| 186 | PCI_DEVICE_ID_INTEL_CNP_H_PCIE_RP18, |
| 187 | PCI_DEVICE_ID_INTEL_CNP_H_PCIE_RP19, |
| 188 | PCI_DEVICE_ID_INTEL_CNP_H_PCIE_RP20, |
| 189 | PCI_DEVICE_ID_INTEL_CNP_H_PCIE_RP21, |
| 190 | PCI_DEVICE_ID_INTEL_CNP_H_PCIE_RP22, |
| 191 | PCI_DEVICE_ID_INTEL_CNP_H_PCIE_RP23, |
| 192 | PCI_DEVICE_ID_INTEL_CNP_H_PCIE_RP24, |
Aamir Bohra | 9eac039 | 2018-06-30 12:07:04 +0530 | [diff] [blame] | 193 | PCI_DEVICE_ID_INTEL_ICP_LP_PCIE_RP1, |
| 194 | PCI_DEVICE_ID_INTEL_ICP_LP_PCIE_RP2, |
| 195 | PCI_DEVICE_ID_INTEL_ICP_LP_PCIE_RP3, |
| 196 | PCI_DEVICE_ID_INTEL_ICP_LP_PCIE_RP4, |
| 197 | PCI_DEVICE_ID_INTEL_ICP_LP_PCIE_RP5, |
| 198 | PCI_DEVICE_ID_INTEL_ICP_LP_PCIE_RP6, |
| 199 | PCI_DEVICE_ID_INTEL_ICP_LP_PCIE_RP7, |
| 200 | PCI_DEVICE_ID_INTEL_ICP_LP_PCIE_RP8, |
| 201 | PCI_DEVICE_ID_INTEL_ICP_LP_PCIE_RP9, |
| 202 | PCI_DEVICE_ID_INTEL_ICP_LP_PCIE_RP10, |
| 203 | PCI_DEVICE_ID_INTEL_ICP_LP_PCIE_RP11, |
| 204 | PCI_DEVICE_ID_INTEL_ICP_LP_PCIE_RP12, |
| 205 | PCI_DEVICE_ID_INTEL_ICP_LP_PCIE_RP13, |
| 206 | PCI_DEVICE_ID_INTEL_ICP_LP_PCIE_RP14, |
| 207 | PCI_DEVICE_ID_INTEL_ICP_LP_PCIE_RP15, |
| 208 | PCI_DEVICE_ID_INTEL_ICP_LP_PCIE_RP16, |
Ronak Kanabar | da7ffb48 | 2019-02-05 01:51:13 +0530 | [diff] [blame^] | 209 | PCI_DEVICE_ID_INTEL_CMP_LP_PCIE_RP1, |
| 210 | PCI_DEVICE_ID_INTEL_CMP_LP_PCIE_RP2, |
| 211 | PCI_DEVICE_ID_INTEL_CMP_LP_PCIE_RP3, |
| 212 | PCI_DEVICE_ID_INTEL_CMP_LP_PCIE_RP4, |
| 213 | PCI_DEVICE_ID_INTEL_CMP_LP_PCIE_RP5, |
| 214 | PCI_DEVICE_ID_INTEL_CMP_LP_PCIE_RP6, |
| 215 | PCI_DEVICE_ID_INTEL_CMP_LP_PCIE_RP7, |
| 216 | PCI_DEVICE_ID_INTEL_CMP_LP_PCIE_RP8, |
| 217 | PCI_DEVICE_ID_INTEL_CMP_LP_PCIE_RP9, |
| 218 | PCI_DEVICE_ID_INTEL_CMP_LP_PCIE_RP10, |
| 219 | PCI_DEVICE_ID_INTEL_CMP_LP_PCIE_RP11, |
| 220 | PCI_DEVICE_ID_INTEL_CMP_LP_PCIE_RP12, |
| 221 | PCI_DEVICE_ID_INTEL_CMP_LP_PCIE_RP13, |
| 222 | PCI_DEVICE_ID_INTEL_CMP_LP_PCIE_RP14, |
| 223 | PCI_DEVICE_ID_INTEL_CMP_LP_PCIE_RP15, |
| 224 | PCI_DEVICE_ID_INTEL_CMP_LP_PCIE_RP16, |
Aamir Bohra | 2d689f9 | 2017-05-11 20:27:27 +0530 | [diff] [blame] | 225 | 0 |
| 226 | }; |
| 227 | |
| 228 | static const struct pci_driver pch_pcie __pci_driver = { |
| 229 | .ops = &device_ops, |
| 230 | .vendor = PCI_VENDOR_ID_INTEL, |
| 231 | .devices = pcie_device_ids, |
| 232 | }; |