1 // SPDX-License-Identifier: GPL-2.0
3 * Intel(R) Trace Hub pci driver
5 * Copyright (C) 2014-2015 Intel Corporation.
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>
18 #define DRIVER_NAME "intel_th_pci"
21 TH_PCI_CONFIG_BAR
= 0,
22 TH_PCI_STH_SW_BAR
= 2,
27 #define PCI_REG_NPKDSC 0x80
28 #define NPKDSC_TSACT BIT(5)
30 static int intel_th_pci_activate(struct intel_th
*th
)
32 struct pci_dev
*pdev
= to_pci_dev(th
->dev
);
36 if (!INTEL_TH_CAP(th
, tscu_enable
))
39 err
= pci_read_config_dword(pdev
, PCI_REG_NPKDSC
, &npkdsc
);
41 npkdsc
|= NPKDSC_TSACT
;
42 err
= pci_write_config_dword(pdev
, PCI_REG_NPKDSC
, npkdsc
);
46 dev_err(&pdev
->dev
, "failed to read NPKDSC register\n");
51 static void intel_th_pci_deactivate(struct intel_th
*th
)
53 struct pci_dev
*pdev
= to_pci_dev(th
->dev
);
57 if (!INTEL_TH_CAP(th
, tscu_enable
))
60 err
= pci_read_config_dword(pdev
, PCI_REG_NPKDSC
, &npkdsc
);
62 npkdsc
|= NPKDSC_TSACT
;
63 err
= pci_write_config_dword(pdev
, PCI_REG_NPKDSC
, npkdsc
);
67 dev_err(&pdev
->dev
, "failed to read NPKDSC register\n");
70 static int intel_th_pci_probe(struct pci_dev
*pdev
,
71 const struct pci_device_id
*id
)
73 const struct intel_th_drvdata
*drvdata
= (void *)id
->driver_data
;
74 struct resource resource
[TH_MMIO_END
+ TH_NVEC_MAX
] = {
75 [TH_MMIO_CONFIG
] = pdev
->resource
[TH_PCI_CONFIG_BAR
],
76 [TH_MMIO_SW
] = pdev
->resource
[TH_PCI_STH_SW_BAR
],
78 int err
, r
= TH_MMIO_SW
+ 1, i
;
81 err
= pcim_enable_device(pdev
);
85 err
= pcim_request_all_regions(pdev
, DRIVER_NAME
);
89 if (!pcim_iomap(pdev
, TH_PCI_CONFIG_BAR
, 0))
92 if (!pcim_iomap(pdev
, TH_PCI_STH_SW_BAR
, 0))
95 if (pdev
->resource
[TH_PCI_RTIT_BAR
].start
) {
96 resource
[TH_MMIO_RTIT
] = pdev
->resource
[TH_PCI_RTIT_BAR
];
100 err
= pci_alloc_irq_vectors(pdev
, 1, 8, PCI_IRQ_ALL_TYPES
);
102 for (i
= 0; i
< err
; i
++, r
++) {
103 resource
[r
].flags
= IORESOURCE_IRQ
;
104 resource
[r
].start
= pci_irq_vector(pdev
, i
);
107 th
= intel_th_alloc(&pdev
->dev
, drvdata
, resource
, r
);
113 th
->activate
= intel_th_pci_activate
;
114 th
->deactivate
= intel_th_pci_deactivate
;
116 pci_set_master(pdev
);
121 pci_free_irq_vectors(pdev
);
125 static void intel_th_pci_remove(struct pci_dev
*pdev
)
127 struct intel_th
*th
= pci_get_drvdata(pdev
);
131 pci_free_irq_vectors(pdev
);
134 static const struct intel_th_drvdata intel_th_1x_multi_is_broken
= {
135 .multi_is_broken
= 1,
138 static const struct intel_th_drvdata intel_th_2x
= {
143 static const struct pci_device_id intel_th_pci_id_table
[] = {
145 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, 0x9d26),
146 .driver_data
= (kernel_ulong_t
)0,
149 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, 0xa126),
150 .driver_data
= (kernel_ulong_t
)0,
154 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, 0x5a8e),
155 .driver_data
= (kernel_ulong_t
)0,
159 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, 0x0a80),
160 .driver_data
= (kernel_ulong_t
)0,
164 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, 0x1a8e),
165 .driver_data
= (kernel_ulong_t
)0,
168 /* Kaby Lake PCH-H */
169 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, 0xa2a6),
170 .driver_data
= (kernel_ulong_t
)&intel_th_1x_multi_is_broken
,
174 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, 0x19e1),
175 .driver_data
= (kernel_ulong_t
)0,
179 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, 0xa1a6),
180 .driver_data
= (kernel_ulong_t
)0,
184 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, 0xa226),
185 .driver_data
= (kernel_ulong_t
)0,
189 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, 0x318e),
190 .driver_data
= (kernel_ulong_t
)&intel_th_2x
,
194 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, 0xa326),
195 .driver_data
= (kernel_ulong_t
)&intel_th_2x
,
199 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, 0x9da6),
200 .driver_data
= (kernel_ulong_t
)&intel_th_2x
,
204 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, 0x18e1),
205 .driver_data
= (kernel_ulong_t
)&intel_th_2x
,
209 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, 0x34a6),
210 .driver_data
= (kernel_ulong_t
)&intel_th_2x
,
214 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, 0x02a6),
215 .driver_data
= (kernel_ulong_t
)&intel_th_2x
,
219 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, 0x06a6),
220 .driver_data
= (kernel_ulong_t
)&intel_th_2x
,
223 /* Comet Lake PCH-V */
224 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, 0xa3a6),
225 .driver_data
= (kernel_ulong_t
)&intel_th_1x_multi_is_broken
,
229 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, 0x45c5),
230 .driver_data
= (kernel_ulong_t
)&intel_th_2x
,
234 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, 0x8a29),
235 .driver_data
= (kernel_ulong_t
)&intel_th_2x
,
239 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, 0x9a33),
240 .driver_data
= (kernel_ulong_t
)&intel_th_2x
,
244 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, 0xa0a6),
245 .driver_data
= (kernel_ulong_t
)&intel_th_2x
,
248 /* Tiger Lake PCH-H */
249 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, 0x43a6),
250 .driver_data
= (kernel_ulong_t
)&intel_th_2x
,
253 /* Jasper Lake PCH */
254 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, 0x4da6),
255 .driver_data
= (kernel_ulong_t
)&intel_th_2x
,
258 /* Jasper Lake CPU */
259 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, 0x4e29),
260 .driver_data
= (kernel_ulong_t
)&intel_th_2x
,
263 /* Elkhart Lake CPU */
264 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, 0x4529),
265 .driver_data
= (kernel_ulong_t
)&intel_th_2x
,
269 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, 0x4b26),
270 .driver_data
= (kernel_ulong_t
)&intel_th_2x
,
274 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, 0x1bcc),
275 .driver_data
= (kernel_ulong_t
)&intel_th_2x
,
279 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, 0x7aa6),
280 .driver_data
= (kernel_ulong_t
)&intel_th_2x
,
284 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, 0x51a6),
285 .driver_data
= (kernel_ulong_t
)&intel_th_2x
,
289 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, 0x54a6),
290 .driver_data
= (kernel_ulong_t
)&intel_th_2x
,
294 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, 0x7e24),
295 .driver_data
= (kernel_ulong_t
)&intel_th_2x
,
299 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, 0x7f26),
300 .driver_data
= (kernel_ulong_t
)&intel_th_2x
,
303 /* Meteor Lake-S CPU */
304 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, 0xae24),
305 .driver_data
= (kernel_ulong_t
)&intel_th_2x
,
309 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, 0x7a26),
310 .driver_data
= (kernel_ulong_t
)&intel_th_2x
,
313 /* Raptor Lake-S CPU */
314 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, 0xa76f),
315 .driver_data
= (kernel_ulong_t
)&intel_th_2x
,
319 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, 0x0963),
320 .driver_data
= (kernel_ulong_t
)&intel_th_2x
,
323 /* Granite Rapids SOC */
324 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, 0x3256),
325 .driver_data
= (kernel_ulong_t
)&intel_th_2x
,
328 /* Sapphire Rapids SOC */
329 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, 0x3456),
330 .driver_data
= (kernel_ulong_t
)&intel_th_2x
,
334 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, 0xa824),
335 .driver_data
= (kernel_ulong_t
)&intel_th_2x
,
339 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, 0x466f),
340 .driver_data
= (kernel_ulong_t
)&intel_th_2x
,
343 /* Rocket Lake CPU */
344 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, 0x4c19),
345 .driver_data
= (kernel_ulong_t
)&intel_th_2x
,
350 MODULE_DEVICE_TABLE(pci
, intel_th_pci_id_table
);
352 static struct pci_driver intel_th_pci_driver
= {
354 .id_table
= intel_th_pci_id_table
,
355 .probe
= intel_th_pci_probe
,
356 .remove
= intel_th_pci_remove
,
359 module_pci_driver(intel_th_pci_driver
);
361 MODULE_LICENSE("GPL v2");
362 MODULE_DESCRIPTION("Intel(R) Trace Hub PCI controller driver");
363 MODULE_AUTHOR("Alexander Shishkin <alexander.shishkin@intel.com>");