|
27 | 27 | #define CNTL_CLEAR_MASK 0xFFFFFFFD
|
28 | 28 | #define CNTL_OVER_MASK 0xFFFFFFFE
|
29 | 29 |
|
| 30 | +#define CNTL_CP_SHIFT 16 |
| 31 | +#define CNTL_CP_MASK (0xFF << CNTL_CP_SHIFT) |
30 | 32 | #define CNTL_CSV_SHIFT 24
|
31 | 33 | #define CNTL_CSV_MASK (0xFFU << CNTL_CSV_SHIFT)
|
32 | 34 |
|
33 | 35 | #define EVENT_CYCLES_ID 0
|
34 | 36 | #define EVENT_CYCLES_COUNTER 0
|
35 | 37 | #define NUM_COUNTERS 4
|
36 | 38 |
|
| 39 | +/* For removing bias if cycle counter CNTL.CP is set to 0xf0 */ |
| 40 | +#define CYCLES_COUNTER_MASK 0x0FFFFFFF |
37 | 41 | #define AXI_MASKING_REVERT 0xffff0000 /* AXI_MASKING(MSB 16bits) + AXI_ID(LSB 16bits) */
|
38 | 42 |
|
39 | 43 | #define to_ddr_pmu(p) container_of(p, struct ddr_pmu, pmu)
|
@@ -426,6 +430,17 @@ static void ddr_perf_counter_enable(struct ddr_pmu *pmu, int config,
|
426 | 430 | writel(0, pmu->base + reg);
|
427 | 431 | val = CNTL_EN | CNTL_CLEAR;
|
428 | 432 | val |= FIELD_PREP(CNTL_CSV_MASK, config);
|
| 433 | + |
| 434 | + /* |
| 435 | + * On i.MX8MP we need to bias the cycle counter to overflow more often. |
| 436 | + * We do this by initializing bits [23:16] of the counter value via the |
| 437 | + * COUNTER_CTRL Counter Parameter (CP) field. |
| 438 | + */ |
| 439 | + if (pmu->devtype_data->quirks & DDR_CAP_AXI_ID_FILTER_ENHANCED) { |
| 440 | + if (counter == EVENT_CYCLES_COUNTER) |
| 441 | + val |= FIELD_PREP(CNTL_CP_MASK, 0xf0); |
| 442 | + } |
| 443 | + |
429 | 444 | writel(val, pmu->base + reg);
|
430 | 445 | } else {
|
431 | 446 | /* Disable counter */
|
@@ -465,6 +480,12 @@ static void ddr_perf_event_update(struct perf_event *event)
|
465 | 480 | int ret;
|
466 | 481 |
|
467 | 482 | new_raw_count = ddr_perf_read_counter(pmu, counter);
|
| 483 | + /* Remove the bias applied in ddr_perf_counter_enable(). */ |
| 484 | + if (pmu->devtype_data->quirks & DDR_CAP_AXI_ID_FILTER_ENHANCED) { |
| 485 | + if (counter == EVENT_CYCLES_COUNTER) |
| 486 | + new_raw_count &= CYCLES_COUNTER_MASK; |
| 487 | + } |
| 488 | + |
468 | 489 | local64_add(new_raw_count, &event->count);
|
469 | 490 |
|
470 | 491 | /*
|
|
0 commit comments