Alexander Shishkin | 50352fa | 2018-03-28 18:46:15 +0300 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Alexander Shishkin | 2b0b16d | 2015-09-22 15:47:15 +0300 | [diff] [blame] | 2 | /* |
| 3 | * Intel(R) Trace Hub pci driver |
| 4 | * |
| 5 | * Copyright (C) 2014-2015 Intel Corporation. |
Alexander Shishkin | 2b0b16d | 2015-09-22 15:47:15 +0300 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 9 | |
| 10 | #include <linux/types.h> |
| 11 | #include <linux/module.h> |
| 12 | #include <linux/device.h> |
| 13 | #include <linux/sysfs.h> |
| 14 | #include <linux/pci.h> |
| 15 | |
| 16 | #include "intel_th.h" |
| 17 | |
| 18 | #define DRIVER_NAME "intel_th_pci" |
| 19 | |
Alexander Shishkin | db73a05 | 2019-05-03 11:44:36 +0300 | [diff] [blame] | 20 | enum { |
| 21 | TH_PCI_CONFIG_BAR = 0, |
| 22 | TH_PCI_STH_SW_BAR = 2, |
Alexander Shishkin | fc027f4 | 2019-05-03 11:44:38 +0300 | [diff] [blame] | 23 | TH_PCI_RTIT_BAR = 4, |
Alexander Shishkin | db73a05 | 2019-05-03 11:44:36 +0300 | [diff] [blame] | 24 | }; |
| 25 | |
| 26 | #define BAR_MASK (BIT(TH_PCI_CONFIG_BAR) | BIT(TH_PCI_STH_SW_BAR)) |
Alexander Shishkin | 2b0b16d | 2015-09-22 15:47:15 +0300 | [diff] [blame] | 27 | |
Alexander Shishkin | a0e7df3 | 2017-02-24 16:09:40 +0200 | [diff] [blame] | 28 | #define PCI_REG_NPKDSC 0x80 |
| 29 | #define NPKDSC_TSACT BIT(5) |
| 30 | |
| 31 | static int intel_th_pci_activate(struct intel_th *th) |
| 32 | { |
| 33 | struct pci_dev *pdev = to_pci_dev(th->dev); |
| 34 | u32 npkdsc; |
| 35 | int err; |
| 36 | |
| 37 | if (!INTEL_TH_CAP(th, tscu_enable)) |
| 38 | return 0; |
| 39 | |
| 40 | err = pci_read_config_dword(pdev, PCI_REG_NPKDSC, &npkdsc); |
| 41 | if (!err) { |
| 42 | npkdsc |= NPKDSC_TSACT; |
| 43 | err = pci_write_config_dword(pdev, PCI_REG_NPKDSC, npkdsc); |
| 44 | } |
| 45 | |
| 46 | if (err) |
| 47 | dev_err(&pdev->dev, "failed to read NPKDSC register\n"); |
| 48 | |
| 49 | return err; |
| 50 | } |
| 51 | |
| 52 | static void intel_th_pci_deactivate(struct intel_th *th) |
| 53 | { |
| 54 | struct pci_dev *pdev = to_pci_dev(th->dev); |
| 55 | u32 npkdsc; |
| 56 | int err; |
| 57 | |
| 58 | if (!INTEL_TH_CAP(th, tscu_enable)) |
| 59 | return; |
| 60 | |
| 61 | err = pci_read_config_dword(pdev, PCI_REG_NPKDSC, &npkdsc); |
| 62 | if (!err) { |
| 63 | npkdsc |= NPKDSC_TSACT; |
| 64 | err = pci_write_config_dword(pdev, PCI_REG_NPKDSC, npkdsc); |
| 65 | } |
| 66 | |
| 67 | if (err) |
| 68 | dev_err(&pdev->dev, "failed to read NPKDSC register\n"); |
| 69 | } |
| 70 | |
Alexander Shishkin | 2b0b16d | 2015-09-22 15:47:15 +0300 | [diff] [blame] | 71 | static int intel_th_pci_probe(struct pci_dev *pdev, |
| 72 | const struct pci_device_id *id) |
| 73 | { |
Alexander Shishkin | 3321371 | 2017-08-18 17:57:35 +0300 | [diff] [blame] | 74 | struct intel_th_drvdata *drvdata = (void *)id->driver_data; |
Alexander Shishkin | 7b7036d | 2019-05-03 11:44:40 +0300 | [diff] [blame] | 75 | struct resource resource[TH_MMIO_END + TH_NVEC_MAX] = { |
Alexander Shishkin | db73a05 | 2019-05-03 11:44:36 +0300 | [diff] [blame] | 76 | [TH_MMIO_CONFIG] = pdev->resource[TH_PCI_CONFIG_BAR], |
| 77 | [TH_MMIO_SW] = pdev->resource[TH_PCI_STH_SW_BAR], |
| 78 | }; |
Alexander Shishkin | 7b7036d | 2019-05-03 11:44:40 +0300 | [diff] [blame] | 79 | int err, r = TH_MMIO_SW + 1, i; |
Alexander Shishkin | 2b0b16d | 2015-09-22 15:47:15 +0300 | [diff] [blame] | 80 | struct intel_th *th; |
Alexander Shishkin | 2b0b16d | 2015-09-22 15:47:15 +0300 | [diff] [blame] | 81 | |
| 82 | err = pcim_enable_device(pdev); |
| 83 | if (err) |
| 84 | return err; |
| 85 | |
| 86 | err = pcim_iomap_regions_request_all(pdev, BAR_MASK, DRIVER_NAME); |
| 87 | if (err) |
| 88 | return err; |
| 89 | |
Alexander Shishkin | fc027f4 | 2019-05-03 11:44:38 +0300 | [diff] [blame] | 90 | if (pdev->resource[TH_PCI_RTIT_BAR].start) { |
| 91 | resource[TH_MMIO_RTIT] = pdev->resource[TH_PCI_RTIT_BAR]; |
| 92 | r++; |
| 93 | } |
| 94 | |
Alexander Shishkin | 7b7036d | 2019-05-03 11:44:40 +0300 | [diff] [blame] | 95 | err = pci_alloc_irq_vectors(pdev, 1, 8, PCI_IRQ_ALL_TYPES); |
| 96 | if (err > 0) |
| 97 | for (i = 0; i < err; i++, r++) { |
| 98 | resource[r].flags = IORESOURCE_IRQ; |
| 99 | resource[r].start = pci_irq_vector(pdev, i); |
| 100 | } |
Alexander Shishkin | 62a5930 | 2019-05-03 11:44:39 +0300 | [diff] [blame] | 101 | |
| 102 | th = intel_th_alloc(&pdev->dev, drvdata, resource, r); |
Alexander Shishkin | 2b0b16d | 2015-09-22 15:47:15 +0300 | [diff] [blame] | 103 | if (IS_ERR(th)) |
| 104 | return PTR_ERR(th); |
| 105 | |
Alexander Shishkin | a0e7df3 | 2017-02-24 16:09:40 +0200 | [diff] [blame] | 106 | th->activate = intel_th_pci_activate; |
| 107 | th->deactivate = intel_th_pci_deactivate; |
| 108 | |
Alexander Shishkin | e9b2b3e | 2017-08-10 11:10:58 +0300 | [diff] [blame] | 109 | pci_set_master(pdev); |
| 110 | |
Alexander Shishkin | 2b0b16d | 2015-09-22 15:47:15 +0300 | [diff] [blame] | 111 | return 0; |
| 112 | } |
| 113 | |
| 114 | static void intel_th_pci_remove(struct pci_dev *pdev) |
| 115 | { |
| 116 | struct intel_th *th = pci_get_drvdata(pdev); |
| 117 | |
| 118 | intel_th_free(th); |
Alexander Shishkin | 7b7036d | 2019-05-03 11:44:40 +0300 | [diff] [blame] | 119 | |
| 120 | pci_free_irq_vectors(pdev); |
Alexander Shishkin | 2b0b16d | 2015-09-22 15:47:15 +0300 | [diff] [blame] | 121 | } |
| 122 | |
Alexander Shishkin | a0e7df3 | 2017-02-24 16:09:40 +0200 | [diff] [blame] | 123 | static const struct intel_th_drvdata intel_th_2x = { |
| 124 | .tscu_enable = 1, |
Alexander Shishkin | 4c5bb6e | 2019-05-03 11:44:42 +0300 | [diff] [blame] | 125 | .has_mintctl = 1, |
Alexander Shishkin | a0e7df3 | 2017-02-24 16:09:40 +0200 | [diff] [blame] | 126 | }; |
| 127 | |
Alexander Shishkin | 2b0b16d | 2015-09-22 15:47:15 +0300 | [diff] [blame] | 128 | static const struct pci_device_id intel_th_pci_id_table[] = { |
| 129 | { |
| 130 | PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x9d26), |
| 131 | .driver_data = (kernel_ulong_t)0, |
| 132 | }, |
| 133 | { |
| 134 | PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0xa126), |
| 135 | .driver_data = (kernel_ulong_t)0, |
| 136 | }, |
Alexander Shishkin | 6396b91 | 2015-12-22 17:25:22 +0200 | [diff] [blame] | 137 | { |
| 138 | /* Apollo Lake */ |
| 139 | PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x5a8e), |
| 140 | .driver_data = (kernel_ulong_t)0, |
| 141 | }, |
Alexander Shishkin | 3f04088 | 2015-12-22 17:25:23 +0200 | [diff] [blame] | 142 | { |
| 143 | /* Broxton */ |
| 144 | PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x0a80), |
| 145 | .driver_data = (kernel_ulong_t)0, |
| 146 | }, |
Alexander Shishkin | aaa3ca8 | 2016-04-08 18:26:52 +0300 | [diff] [blame] | 147 | { |
| 148 | /* Broxton B-step */ |
| 149 | PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x1a8e), |
| 150 | .driver_data = (kernel_ulong_t)0, |
| 151 | }, |
Alexander Shishkin | 7a1a47c | 2016-06-28 18:55:23 +0300 | [diff] [blame] | 152 | { |
| 153 | /* Kaby Lake PCH-H */ |
| 154 | PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0xa2a6), |
| 155 | .driver_data = (kernel_ulong_t)0, |
| 156 | }, |
Alexander Shishkin | 5118ccd | 2015-09-08 14:03:55 +0300 | [diff] [blame] | 157 | { |
| 158 | /* Denverton */ |
| 159 | PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x19e1), |
| 160 | .driver_data = (kernel_ulong_t)0, |
| 161 | }, |
Alexander Shishkin | 340837f | 2016-06-30 16:10:51 +0300 | [diff] [blame] | 162 | { |
Alexander Shishkin | 2460084 | 2017-09-19 18:47:42 +0300 | [diff] [blame] | 163 | /* Lewisburg PCH */ |
| 164 | PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0xa1a6), |
| 165 | .driver_data = (kernel_ulong_t)0, |
| 166 | }, |
| 167 | { |
Alexander Shishkin | 164eb56 | 2019-08-21 10:49:54 +0300 | [diff] [blame] | 168 | /* Lewisburg PCH */ |
| 169 | PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0xa226), |
| 170 | .driver_data = (kernel_ulong_t)0, |
| 171 | }, |
| 172 | { |
Alexander Shishkin | 340837f | 2016-06-30 16:10:51 +0300 | [diff] [blame] | 173 | /* Gemini Lake */ |
| 174 | PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x318e), |
Alexander Shishkin | a0e7df3 | 2017-02-24 16:09:40 +0200 | [diff] [blame] | 175 | .driver_data = (kernel_ulong_t)&intel_th_2x, |
Alexander Shishkin | 340837f | 2016-06-30 16:10:51 +0300 | [diff] [blame] | 176 | }, |
Alexander Shishkin | 84331e1 | 2016-06-30 16:11:13 +0300 | [diff] [blame] | 177 | { |
| 178 | /* Cannon Lake H */ |
| 179 | PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0xa326), |
Alexander Shishkin | a0e7df3 | 2017-02-24 16:09:40 +0200 | [diff] [blame] | 180 | .driver_data = (kernel_ulong_t)&intel_th_2x, |
Alexander Shishkin | 84331e1 | 2016-06-30 16:11:13 +0300 | [diff] [blame] | 181 | }, |
Alexander Shishkin | efb3669 | 2016-06-30 16:11:31 +0300 | [diff] [blame] | 182 | { |
| 183 | /* Cannon Lake LP */ |
| 184 | PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x9da6), |
Alexander Shishkin | a0e7df3 | 2017-02-24 16:09:40 +0200 | [diff] [blame] | 185 | .driver_data = (kernel_ulong_t)&intel_th_2x, |
Alexander Shishkin | efb3669 | 2016-06-30 16:11:31 +0300 | [diff] [blame] | 186 | }, |
Alexander Shishkin | 920ce7c | 2017-09-19 18:47:41 +0300 | [diff] [blame] | 187 | { |
| 188 | /* Cedar Fork PCH */ |
| 189 | PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x18e1), |
| 190 | .driver_data = (kernel_ulong_t)&intel_th_2x, |
| 191 | }, |
Alexander Shishkin | 59d08d00 | 2018-09-18 16:10:49 +0300 | [diff] [blame] | 192 | { |
| 193 | /* Ice Lake PCH */ |
| 194 | PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x34a6), |
| 195 | .driver_data = (kernel_ulong_t)&intel_th_2x, |
| 196 | }, |
Alexander Shishkin | e60e9a4 | 2019-04-17 10:35:36 +0300 | [diff] [blame] | 197 | { |
| 198 | /* Comet Lake */ |
| 199 | PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x02a6), |
| 200 | .driver_data = (kernel_ulong_t)&intel_th_2x, |
| 201 | }, |
Alexander Shishkin | 4aa5aed | 2019-06-21 19:19:30 +0300 | [diff] [blame] | 202 | { |
Alexander Shishkin | 3adbb57 | 2019-10-28 09:06:50 +0200 | [diff] [blame] | 203 | /* Comet Lake PCH */ |
| 204 | PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x06a6), |
| 205 | .driver_data = (kernel_ulong_t)&intel_th_2x, |
| 206 | }, |
| 207 | { |
Alexander Shishkin | e4de2a5 | 2019-12-17 13:55:24 +0200 | [diff] [blame] | 208 | /* Comet Lake PCH-V */ |
| 209 | PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0xa3a6), |
| 210 | .driver_data = (kernel_ulong_t)&intel_th_2x, |
| 211 | }, |
| 212 | { |
Alexander Shishkin | 4aa5aed | 2019-06-21 19:19:30 +0300 | [diff] [blame] | 213 | /* Ice Lake NNPI */ |
| 214 | PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x45c5), |
| 215 | .driver_data = (kernel_ulong_t)&intel_th_2x, |
| 216 | }, |
Alexander Shishkin | 9c78255 | 2019-08-21 10:49:55 +0300 | [diff] [blame] | 217 | { |
Alexander Shishkin | 6a17434 | 2019-11-20 15:08:05 +0200 | [diff] [blame] | 218 | /* Ice Lake CPU */ |
| 219 | PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x8a29), |
| 220 | .driver_data = (kernel_ulong_t)&intel_th_2x, |
| 221 | }, |
| 222 | { |
Alexander Shishkin | 6e6c18b | 2019-11-20 15:08:06 +0200 | [diff] [blame] | 223 | /* Tiger Lake CPU */ |
| 224 | PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x9a33), |
| 225 | .driver_data = (kernel_ulong_t)&intel_th_2x, |
| 226 | }, |
| 227 | { |
Alexander Shishkin | 9c78255 | 2019-08-21 10:49:55 +0300 | [diff] [blame] | 228 | /* Tiger Lake PCH */ |
| 229 | PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0xa0a6), |
| 230 | .driver_data = (kernel_ulong_t)&intel_th_2x, |
| 231 | }, |
Alexander Shishkin | 9d55499 | 2019-10-28 09:06:51 +0200 | [diff] [blame] | 232 | { |
| 233 | /* Jasper Lake PCH */ |
| 234 | PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x4da6), |
| 235 | .driver_data = (kernel_ulong_t)&intel_th_2x, |
| 236 | }, |
Alexander Shishkin | 8838586 | 2019-12-17 13:55:25 +0200 | [diff] [blame] | 237 | { |
| 238 | /* Elkhart Lake */ |
| 239 | PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x4b26), |
| 240 | .driver_data = (kernel_ulong_t)&intel_th_2x, |
| 241 | }, |
Alexander Shishkin | 2b0b16d | 2015-09-22 15:47:15 +0300 | [diff] [blame] | 242 | { 0 }, |
| 243 | }; |
| 244 | |
| 245 | MODULE_DEVICE_TABLE(pci, intel_th_pci_id_table); |
| 246 | |
| 247 | static struct pci_driver intel_th_pci_driver = { |
| 248 | .name = DRIVER_NAME, |
| 249 | .id_table = intel_th_pci_id_table, |
| 250 | .probe = intel_th_pci_probe, |
| 251 | .remove = intel_th_pci_remove, |
| 252 | }; |
| 253 | |
| 254 | module_pci_driver(intel_th_pci_driver); |
| 255 | |
| 256 | MODULE_LICENSE("GPL v2"); |
| 257 | MODULE_DESCRIPTION("Intel(R) Trace Hub PCI controller driver"); |
| 258 | MODULE_AUTHOR("Alexander Shishkin <alexander.shishkin@intel.com>"); |