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,
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
);
37 if (!INTEL_TH_CAP(th
, tscu_enable
))
40 err
= pci_read_config_dword(pdev
, PCI_REG_NPKDSC
, &npkdsc
);
42 npkdsc
|= NPKDSC_TSACT
;
43 err
= pci_write_config_dword(pdev
, PCI_REG_NPKDSC
, npkdsc
);
47 dev_err(&pdev
->dev
, "failed to read NPKDSC register\n");
52 static void intel_th_pci_deactivate(struct intel_th
*th
)
54 struct pci_dev
*pdev
= to_pci_dev(th
->dev
);
58 if (!INTEL_TH_CAP(th
, tscu_enable
))
61 err
= pci_read_config_dword(pdev
, PCI_REG_NPKDSC
, &npkdsc
);
63 npkdsc
|= NPKDSC_TSACT
;
64 err
= pci_write_config_dword(pdev
, PCI_REG_NPKDSC
, npkdsc
);
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
;
82 err
= pcim_enable_device(pdev
);
86 err
= pcim_iomap_regions_request_all(pdev
, BAR_MASK
, DRIVER_NAME
);
90 if (pdev
->resource
[TH_PCI_RTIT_BAR
].start
) {
91 resource
[TH_MMIO_RTIT
] = pdev
->resource
[TH_PCI_RTIT_BAR
];
95 err
= pci_alloc_irq_vectors(pdev
, 1, 8, PCI_IRQ_ALL_TYPES
);
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
);
106 th
->activate
= intel_th_pci_activate
;
107 th
->deactivate
= intel_th_pci_deactivate
;
109 pci_set_master(pdev
);
114 static void intel_th_pci_remove(struct pci_dev
*pdev
)
116 struct intel_th
*th
= pci_get_drvdata(pdev
);
120 pci_free_irq_vectors(pdev
);
123 static const struct intel_th_drvdata intel_th_2x
= {
128 static const struct pci_device_id intel_th_pci_id_table
[] = {
130 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, 0x9d26),
131 .driver_data
= (kernel_ulong_t
)0,
134 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, 0xa126),
135 .driver_data
= (kernel_ulong_t
)0,
139 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, 0x5a8e),
140 .driver_data
= (kernel_ulong_t
)0,
144 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, 0x0a80),
145 .driver_data
= (kernel_ulong_t
)0,
149 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, 0x1a8e),
150 .driver_data
= (kernel_ulong_t
)0,
153 /* Kaby Lake PCH-H */
154 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, 0xa2a6),
155 .driver_data
= (kernel_ulong_t
)0,
159 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, 0x19e1),
160 .driver_data
= (kernel_ulong_t
)0,
164 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, 0xa1a6),
165 .driver_data
= (kernel_ulong_t
)0,
169 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, 0xa226),
170 .driver_data
= (kernel_ulong_t
)0,
174 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, 0x318e),
175 .driver_data
= (kernel_ulong_t
)&intel_th_2x
,
179 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, 0xa326),
180 .driver_data
= (kernel_ulong_t
)&intel_th_2x
,
184 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, 0x9da6),
185 .driver_data
= (kernel_ulong_t
)&intel_th_2x
,
189 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, 0x18e1),
190 .driver_data
= (kernel_ulong_t
)&intel_th_2x
,
194 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, 0x34a6),
195 .driver_data
= (kernel_ulong_t
)&intel_th_2x
,
199 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, 0x02a6),
200 .driver_data
= (kernel_ulong_t
)&intel_th_2x
,
204 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, 0x06a6),
205 .driver_data
= (kernel_ulong_t
)&intel_th_2x
,
208 /* Comet Lake PCH-V */
209 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, 0xa3a6),
210 .driver_data
= (kernel_ulong_t
)&intel_th_2x
,
214 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, 0x45c5),
215 .driver_data
= (kernel_ulong_t
)&intel_th_2x
,
219 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, 0x8a29),
220 .driver_data
= (kernel_ulong_t
)&intel_th_2x
,
224 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, 0x9a33),
225 .driver_data
= (kernel_ulong_t
)&intel_th_2x
,
229 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, 0xa0a6),
230 .driver_data
= (kernel_ulong_t
)&intel_th_2x
,
233 /* Jasper Lake PCH */
234 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, 0x4da6),
235 .driver_data
= (kernel_ulong_t
)&intel_th_2x
,
239 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, 0x4b26),
240 .driver_data
= (kernel_ulong_t
)&intel_th_2x
,
245 MODULE_DEVICE_TABLE(pci
, intel_th_pci_id_table
);
247 static struct pci_driver intel_th_pci_driver
= {
249 .id_table
= intel_th_pci_id_table
,
250 .probe
= intel_th_pci_probe
,
251 .remove
= intel_th_pci_remove
,
254 module_pci_driver(intel_th_pci_driver
);
256 MODULE_LICENSE("GPL v2");
257 MODULE_DESCRIPTION("Intel(R) Trace Hub PCI controller driver");
258 MODULE_AUTHOR("Alexander Shishkin <alexander.shishkin@intel.com>");