forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-10 ee930fffee469d076998274a2ca55e13dc1efb67
kernel/arch/x86/events/intel/uncore.h
....@@ -2,6 +2,7 @@
22 #include <linux/slab.h>
33 #include <linux/pci.h>
44 #include <asm/apicdef.h>
5
+#include <linux/io-64-nonatomic-lo-hi.h>
56
67 #include <linux/perf_event.h>
78 #include "../perf_event.h"
....@@ -56,7 +57,11 @@
5657 unsigned fixed_ctr;
5758 unsigned fixed_ctl;
5859 unsigned box_ctl;
59
- unsigned msr_offset;
60
+ union {
61
+ unsigned msr_offset;
62
+ unsigned mmio_offset;
63
+ };
64
+ unsigned mmio_map_size;
6065 unsigned num_shared_regs:8;
6166 unsigned single_fixed:1;
6267 unsigned pair_ctr_ctl:1;
....@@ -68,7 +73,20 @@
6873 struct uncore_event_desc *event_descs;
6974 struct freerunning_counters *freerunning;
7075 const struct attribute_group *attr_groups[4];
76
+ const struct attribute_group **attr_update;
7177 struct pmu *pmu; /* for custom pmu ops */
78
+ /*
79
+ * Uncore PMU would store relevant platform topology configuration here
80
+ * to identify which platform component each PMON block of that type is
81
+ * supposed to monitor.
82
+ */
83
+ u64 *topology;
84
+ /*
85
+ * Optional callbacks for managing mapping of Uncore units to PMONs
86
+ */
87
+ int (*get_topology)(struct intel_uncore_type *type);
88
+ int (*set_mapping)(struct intel_uncore_type *type);
89
+ void (*cleanup_mapping)(struct intel_uncore_type *type);
7290 };
7391
7492 #define pmu_group attr_groups[0]
....@@ -108,7 +126,7 @@
108126
109127 struct intel_uncore_box {
110128 int pci_phys_id;
111
- int pkgid; /* Logical package ID */
129
+ int dieid; /* Logical die ID */
112130 int n_active; /* number of active events */
113131 int n_events;
114132 int cpu; /* cpu to collect events */
....@@ -125,12 +143,19 @@
125143 struct hrtimer hrtimer;
126144 struct list_head list;
127145 struct list_head active_list;
128
- void *io_addr;
129
- struct intel_uncore_extra_reg shared_regs[0];
146
+ void __iomem *io_addr;
147
+ struct intel_uncore_extra_reg shared_regs[];
130148 };
131149
132
-#define UNCORE_BOX_FLAG_INITIATED 0
133
-#define UNCORE_BOX_FLAG_CTL_OFFS8 1 /* event config registers are 8-byte apart */
150
+/* CFL uncore 8th cbox MSRs */
151
+#define CFL_UNC_CBO_7_PERFEVTSEL0 0xf70
152
+#define CFL_UNC_CBO_7_PER_CTR0 0xf76
153
+
154
+#define UNCORE_BOX_FLAG_INITIATED 0
155
+/* event config registers are 8-byte apart */
156
+#define UNCORE_BOX_FLAG_CTL_OFFS8 1
157
+/* CFL 8th CBOX has different MSR space */
158
+#define UNCORE_BOX_FLAG_CFL8_CBOX_MSR_OFFS 2
134159
135160 struct uncore_event_desc {
136161 struct device_attribute attr;
....@@ -143,6 +168,7 @@
143168 unsigned int box_offset;
144169 unsigned int num_counters;
145170 unsigned int bits;
171
+ unsigned *box_offsets;
146172 };
147173
148174 struct pci2phy_map {
....@@ -152,9 +178,22 @@
152178 };
153179
154180 struct pci2phy_map *__find_pci2phy_map(int segment);
181
+int uncore_pcibus_to_physid(struct pci_bus *bus);
155182
156183 ssize_t uncore_event_show(struct device *dev,
157184 struct device_attribute *attr, char *buf);
185
+
186
+static inline struct intel_uncore_pmu *dev_to_uncore_pmu(struct device *dev)
187
+{
188
+ return container_of(dev_get_drvdata(dev), struct intel_uncore_pmu, pmu);
189
+}
190
+
191
+#define to_device_attribute(n) container_of(n, struct device_attribute, attr)
192
+#define to_dev_ext_attribute(n) container_of(n, struct dev_ext_attribute, attr)
193
+#define attr_to_ext_attr(n) to_dev_ext_attribute(to_device_attribute(n))
194
+
195
+extern int __uncore_max_dies;
196
+#define uncore_max_dies() (__uncore_max_dies)
158197
159198 #define INTEL_UNCORE_EVENT_DESC(_name, _config) \
160199 { \
....@@ -181,6 +220,25 @@
181220 static inline bool uncore_pmc_freerunning(int idx)
182221 {
183222 return idx == UNCORE_PMC_IDX_FREERUNNING;
223
+}
224
+
225
+static inline bool uncore_mmio_is_valid_offset(struct intel_uncore_box *box,
226
+ unsigned long offset)
227
+{
228
+ if (offset < box->pmu->type->mmio_map_size)
229
+ return true;
230
+
231
+ pr_warn_once("perf uncore: Invalid offset 0x%lx exceeds mapped area of %s.\n",
232
+ offset, box->pmu->type->name);
233
+
234
+ return false;
235
+}
236
+
237
+static inline
238
+unsigned int uncore_mmio_box_ctl(struct intel_uncore_box *box)
239
+{
240
+ return box->pmu->type->box_ctl +
241
+ box->pmu->type->mmio_offset * box->pmu->pmu_idx;
184242 }
185243
186244 static inline unsigned uncore_pci_box_ctl(struct intel_uncore_box *box)
....@@ -291,29 +349,41 @@
291349
292350 return pmu->type->freerunning[type].counter_base +
293351 pmu->type->freerunning[type].counter_offset * idx +
294
- pmu->type->freerunning[type].box_offset * pmu->pmu_idx;
352
+ (pmu->type->freerunning[type].box_offsets ?
353
+ pmu->type->freerunning[type].box_offsets[pmu->pmu_idx] :
354
+ pmu->type->freerunning[type].box_offset * pmu->pmu_idx);
295355 }
296356
297357 static inline
298358 unsigned uncore_msr_event_ctl(struct intel_uncore_box *box, int idx)
299359 {
300
- return box->pmu->type->event_ctl +
301
- (box->pmu->type->pair_ctr_ctl ? 2 * idx : idx) +
302
- uncore_msr_box_offset(box);
360
+ if (test_bit(UNCORE_BOX_FLAG_CFL8_CBOX_MSR_OFFS, &box->flags)) {
361
+ return CFL_UNC_CBO_7_PERFEVTSEL0 +
362
+ (box->pmu->type->pair_ctr_ctl ? 2 * idx : idx);
363
+ } else {
364
+ return box->pmu->type->event_ctl +
365
+ (box->pmu->type->pair_ctr_ctl ? 2 * idx : idx) +
366
+ uncore_msr_box_offset(box);
367
+ }
303368 }
304369
305370 static inline
306371 unsigned uncore_msr_perf_ctr(struct intel_uncore_box *box, int idx)
307372 {
308
- return box->pmu->type->perf_ctr +
309
- (box->pmu->type->pair_ctr_ctl ? 2 * idx : idx) +
310
- uncore_msr_box_offset(box);
373
+ if (test_bit(UNCORE_BOX_FLAG_CFL8_CBOX_MSR_OFFS, &box->flags)) {
374
+ return CFL_UNC_CBO_7_PER_CTR0 +
375
+ (box->pmu->type->pair_ctr_ctl ? 2 * idx : idx);
376
+ } else {
377
+ return box->pmu->type->perf_ctr +
378
+ (box->pmu->type->pair_ctr_ctl ? 2 * idx : idx) +
379
+ uncore_msr_box_offset(box);
380
+ }
311381 }
312382
313383 static inline
314384 unsigned uncore_fixed_ctl(struct intel_uncore_box *box)
315385 {
316
- if (box->pci_dev)
386
+ if (box->pci_dev || box->io_addr)
317387 return uncore_pci_fixed_ctl(box);
318388 else
319389 return uncore_msr_fixed_ctl(box);
....@@ -322,7 +392,7 @@
322392 static inline
323393 unsigned uncore_fixed_ctr(struct intel_uncore_box *box)
324394 {
325
- if (box->pci_dev)
395
+ if (box->pci_dev || box->io_addr)
326396 return uncore_pci_fixed_ctr(box);
327397 else
328398 return uncore_msr_fixed_ctr(box);
....@@ -331,7 +401,7 @@
331401 static inline
332402 unsigned uncore_event_ctl(struct intel_uncore_box *box, int idx)
333403 {
334
- if (box->pci_dev)
404
+ if (box->pci_dev || box->io_addr)
335405 return uncore_pci_event_ctl(box, idx);
336406 else
337407 return uncore_msr_event_ctl(box, idx);
....@@ -340,7 +410,7 @@
340410 static inline
341411 unsigned uncore_perf_ctr(struct intel_uncore_box *box, int idx)
342412 {
343
- if (box->pci_dev)
413
+ if (box->pci_dev || box->io_addr)
344414 return uncore_pci_perf_ctr(box, idx);
345415 else
346416 return uncore_msr_perf_ctr(box, idx);
....@@ -448,7 +518,7 @@
448518
449519 static inline bool uncore_box_is_fake(struct intel_uncore_box *box)
450520 {
451
- return (box->pkgid < 0);
521
+ return (box->dieid < 0);
452522 }
453523
454524 static inline struct intel_uncore_pmu *uncore_event_to_pmu(struct perf_event *event)
....@@ -463,6 +533,9 @@
463533
464534 struct intel_uncore_box *uncore_pmu_to_box(struct intel_uncore_pmu *pmu, int cpu);
465535 u64 uncore_msr_read_counter(struct intel_uncore_box *box, struct perf_event *event);
536
+void uncore_mmio_exit_box(struct intel_uncore_box *box);
537
+u64 uncore_mmio_read_counter(struct intel_uncore_box *box,
538
+ struct perf_event *event);
466539 void uncore_pmu_start_hrtimer(struct intel_uncore_box *box);
467540 void uncore_pmu_cancel_hrtimer(struct intel_uncore_box *box);
468541 void uncore_pmu_event_start(struct perf_event *event, int flags);
....@@ -478,7 +551,9 @@
478551
479552 extern struct intel_uncore_type **uncore_msr_uncores;
480553 extern struct intel_uncore_type **uncore_pci_uncores;
554
+extern struct intel_uncore_type **uncore_mmio_uncores;
481555 extern struct pci_driver *uncore_pci_driver;
556
+extern struct pci_driver *uncore_pci_sub_driver;
482557 extern raw_spinlock_t pci2phy_map_lock;
483558 extern struct list_head pci2phy_map_head;
484559 extern struct pci_extra_dev *uncore_extra_pci_dev;
....@@ -493,6 +568,10 @@
493568 void snb_uncore_cpu_init(void);
494569 void nhm_uncore_cpu_init(void);
495570 void skl_uncore_cpu_init(void);
571
+void icl_uncore_cpu_init(void);
572
+void tgl_uncore_cpu_init(void);
573
+void tgl_uncore_mmio_init(void);
574
+void tgl_l_uncore_mmio_init(void);
496575 int snb_pci2phy_map_init(int devid);
497576
498577 /* uncore_snbep.c */
....@@ -508,6 +587,12 @@
508587 void knl_uncore_cpu_init(void);
509588 int skx_uncore_pci_init(void);
510589 void skx_uncore_cpu_init(void);
590
+int snr_uncore_pci_init(void);
591
+void snr_uncore_cpu_init(void);
592
+void snr_uncore_mmio_init(void);
593
+int icx_uncore_pci_init(void);
594
+void icx_uncore_cpu_init(void);
595
+void icx_uncore_mmio_init(void);
511596
512597 /* uncore_nhmex.c */
513598 void nhmex_uncore_cpu_init(void);