Merge tag 'block-5.11-2021-01-10' of git://git.kernel.dk/linux-block
[linux/fpc-iii.git] / drivers / hwtracing / intel_th / pci.c
blob52acd77438ede98280f0ab6e3364f4e28c8becc7
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Intel(R) Trace Hub pci driver
5 * Copyright (C) 2014-2015 Intel Corporation.
6 */
8 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
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>
16 #include "intel_th.h"
18 #define DRIVER_NAME "intel_th_pci"
20 enum {
21 TH_PCI_CONFIG_BAR = 0,
22 TH_PCI_STH_SW_BAR = 2,
23 TH_PCI_RTIT_BAR = 4,
26 #define BAR_MASK (BIT(TH_PCI_CONFIG_BAR) | BIT(TH_PCI_STH_SW_BAR))
28 #define PCI_REG_NPKDSC 0x80
29 #define NPKDSC_TSACT BIT(5)
31 static int intel_th_pci_activate(struct intel_th *th)
33 struct pci_dev *pdev = to_pci_dev(th->dev);
34 u32 npkdsc;
35 int err;
37 if (!INTEL_TH_CAP(th, tscu_enable))
38 return 0;
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);
46 if (err)
47 dev_err(&pdev->dev, "failed to read NPKDSC register\n");
49 return err;
52 static void intel_th_pci_deactivate(struct intel_th *th)
54 struct pci_dev *pdev = to_pci_dev(th->dev);
55 u32 npkdsc;
56 int err;
58 if (!INTEL_TH_CAP(th, tscu_enable))
59 return;
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);
67 if (err)
68 dev_err(&pdev->dev, "failed to read NPKDSC register\n");
71 static int intel_th_pci_probe(struct pci_dev *pdev,
72 const struct pci_device_id *id)
74 struct intel_th_drvdata *drvdata = (void *)id->driver_data;
75 struct resource resource[TH_MMIO_END + TH_NVEC_MAX] = {
76 [TH_MMIO_CONFIG] = pdev->resource[TH_PCI_CONFIG_BAR],
77 [TH_MMIO_SW] = pdev->resource[TH_PCI_STH_SW_BAR],
79 int err, r = TH_MMIO_SW + 1, i;
80 struct intel_th *th;
82 err = pcim_enable_device(pdev);
83 if (err)
84 return err;
86 err = pcim_iomap_regions_request_all(pdev, BAR_MASK, DRIVER_NAME);
87 if (err)
88 return err;
90 if (pdev->resource[TH_PCI_RTIT_BAR].start) {
91 resource[TH_MMIO_RTIT] = pdev->resource[TH_PCI_RTIT_BAR];
92 r++;
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);
102 th = intel_th_alloc(&pdev->dev, drvdata, resource, r);
103 if (IS_ERR(th))
104 return PTR_ERR(th);
106 th->activate = intel_th_pci_activate;
107 th->deactivate = intel_th_pci_deactivate;
109 pci_set_master(pdev);
111 return 0;
114 static void intel_th_pci_remove(struct pci_dev *pdev)
116 struct intel_th *th = pci_get_drvdata(pdev);
118 intel_th_free(th);
120 pci_free_irq_vectors(pdev);
123 static const struct intel_th_drvdata intel_th_1x_multi_is_broken = {
124 .multi_is_broken = 1,
127 static const struct intel_th_drvdata intel_th_2x = {
128 .tscu_enable = 1,
129 .has_mintctl = 1,
132 static const struct pci_device_id intel_th_pci_id_table[] = {
134 PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x9d26),
135 .driver_data = (kernel_ulong_t)0,
138 PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0xa126),
139 .driver_data = (kernel_ulong_t)0,
142 /* Apollo Lake */
143 PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x5a8e),
144 .driver_data = (kernel_ulong_t)0,
147 /* Broxton */
148 PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x0a80),
149 .driver_data = (kernel_ulong_t)0,
152 /* Broxton B-step */
153 PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x1a8e),
154 .driver_data = (kernel_ulong_t)0,
157 /* Kaby Lake PCH-H */
158 PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0xa2a6),
159 .driver_data = (kernel_ulong_t)&intel_th_1x_multi_is_broken,
162 /* Denverton */
163 PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x19e1),
164 .driver_data = (kernel_ulong_t)0,
167 /* Lewisburg PCH */
168 PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0xa1a6),
169 .driver_data = (kernel_ulong_t)0,
172 /* Lewisburg PCH */
173 PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0xa226),
174 .driver_data = (kernel_ulong_t)0,
177 /* Gemini Lake */
178 PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x318e),
179 .driver_data = (kernel_ulong_t)&intel_th_2x,
182 /* Cannon Lake H */
183 PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0xa326),
184 .driver_data = (kernel_ulong_t)&intel_th_2x,
187 /* Cannon Lake LP */
188 PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x9da6),
189 .driver_data = (kernel_ulong_t)&intel_th_2x,
192 /* Cedar Fork PCH */
193 PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x18e1),
194 .driver_data = (kernel_ulong_t)&intel_th_2x,
197 /* Ice Lake PCH */
198 PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x34a6),
199 .driver_data = (kernel_ulong_t)&intel_th_2x,
202 /* Comet Lake */
203 PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x02a6),
204 .driver_data = (kernel_ulong_t)&intel_th_2x,
207 /* Comet Lake PCH */
208 PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x06a6),
209 .driver_data = (kernel_ulong_t)&intel_th_2x,
212 /* Comet Lake PCH-V */
213 PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0xa3a6),
214 .driver_data = (kernel_ulong_t)&intel_th_1x_multi_is_broken,
217 /* Ice Lake NNPI */
218 PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x45c5),
219 .driver_data = (kernel_ulong_t)&intel_th_2x,
222 /* Ice Lake CPU */
223 PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x8a29),
224 .driver_data = (kernel_ulong_t)&intel_th_2x,
227 /* Tiger Lake CPU */
228 PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x9a33),
229 .driver_data = (kernel_ulong_t)&intel_th_2x,
232 /* Tiger Lake PCH */
233 PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0xa0a6),
234 .driver_data = (kernel_ulong_t)&intel_th_2x,
237 /* Tiger Lake PCH-H */
238 PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x43a6),
239 .driver_data = (kernel_ulong_t)&intel_th_2x,
242 /* Jasper Lake PCH */
243 PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x4da6),
244 .driver_data = (kernel_ulong_t)&intel_th_2x,
247 /* Jasper Lake CPU */
248 PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x4e29),
249 .driver_data = (kernel_ulong_t)&intel_th_2x,
252 /* Elkhart Lake CPU */
253 PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x4529),
254 .driver_data = (kernel_ulong_t)&intel_th_2x,
257 /* Elkhart Lake */
258 PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x4b26),
259 .driver_data = (kernel_ulong_t)&intel_th_2x,
262 /* Emmitsburg PCH */
263 PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x1bcc),
264 .driver_data = (kernel_ulong_t)&intel_th_2x,
267 /* Alder Lake */
268 PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x7aa6),
269 .driver_data = (kernel_ulong_t)&intel_th_2x,
272 /* Alder Lake CPU */
273 PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x466f),
274 .driver_data = (kernel_ulong_t)&intel_th_2x,
276 { 0 },
279 MODULE_DEVICE_TABLE(pci, intel_th_pci_id_table);
281 static struct pci_driver intel_th_pci_driver = {
282 .name = DRIVER_NAME,
283 .id_table = intel_th_pci_id_table,
284 .probe = intel_th_pci_probe,
285 .remove = intel_th_pci_remove,
288 module_pci_driver(intel_th_pci_driver);
290 MODULE_LICENSE("GPL v2");
291 MODULE_DESCRIPTION("Intel(R) Trace Hub PCI controller driver");
292 MODULE_AUTHOR("Alexander Shishkin <alexander.shishkin@intel.com>");