1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0 */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun * This file contains the Itanium PMU register description tables
4*4882a593Smuzhiyun * and pmc checker used by perfmon.c.
5*4882a593Smuzhiyun *
6*4882a593Smuzhiyun * Copyright (C) 2002-2003 Hewlett Packard Co
7*4882a593Smuzhiyun * Stephane Eranian <eranian@hpl.hp.com>
8*4882a593Smuzhiyun */
9*4882a593Smuzhiyun static int pfm_ita_pmc_check(struct task_struct *task, pfm_context_t *ctx, unsigned int cnum, unsigned long *val, struct pt_regs *regs);
10*4882a593Smuzhiyun
11*4882a593Smuzhiyun static pfm_reg_desc_t pfm_ita_pmc_desc[PMU_MAX_PMCS]={
12*4882a593Smuzhiyun /* pmc0 */ { PFM_REG_CONTROL , 0, 0x1UL, -1UL, NULL, NULL, {0UL,0UL, 0UL, 0UL}, {0UL,0UL, 0UL, 0UL}},
13*4882a593Smuzhiyun /* pmc1 */ { PFM_REG_CONTROL , 0, 0x0UL, -1UL, NULL, NULL, {0UL,0UL, 0UL, 0UL}, {0UL,0UL, 0UL, 0UL}},
14*4882a593Smuzhiyun /* pmc2 */ { PFM_REG_CONTROL , 0, 0x0UL, -1UL, NULL, NULL, {0UL,0UL, 0UL, 0UL}, {0UL,0UL, 0UL, 0UL}},
15*4882a593Smuzhiyun /* pmc3 */ { PFM_REG_CONTROL , 0, 0x0UL, -1UL, NULL, NULL, {0UL,0UL, 0UL, 0UL}, {0UL,0UL, 0UL, 0UL}},
16*4882a593Smuzhiyun /* pmc4 */ { PFM_REG_COUNTING, 6, 0x0UL, -1UL, NULL, NULL, {RDEP(4),0UL, 0UL, 0UL}, {0UL,0UL, 0UL, 0UL}},
17*4882a593Smuzhiyun /* pmc5 */ { PFM_REG_COUNTING, 6, 0x0UL, -1UL, NULL, NULL, {RDEP(5),0UL, 0UL, 0UL}, {0UL,0UL, 0UL, 0UL}},
18*4882a593Smuzhiyun /* pmc6 */ { PFM_REG_COUNTING, 6, 0x0UL, -1UL, NULL, NULL, {RDEP(6),0UL, 0UL, 0UL}, {0UL,0UL, 0UL, 0UL}},
19*4882a593Smuzhiyun /* pmc7 */ { PFM_REG_COUNTING, 6, 0x0UL, -1UL, NULL, NULL, {RDEP(7),0UL, 0UL, 0UL}, {0UL,0UL, 0UL, 0UL}},
20*4882a593Smuzhiyun /* pmc8 */ { PFM_REG_CONFIG , 0, 0xf00000003ffffff8UL, -1UL, NULL, NULL, {0UL,0UL, 0UL, 0UL}, {0UL,0UL, 0UL, 0UL}},
21*4882a593Smuzhiyun /* pmc9 */ { PFM_REG_CONFIG , 0, 0xf00000003ffffff8UL, -1UL, NULL, NULL, {0UL,0UL, 0UL, 0UL}, {0UL,0UL, 0UL, 0UL}},
22*4882a593Smuzhiyun /* pmc10 */ { PFM_REG_MONITOR , 6, 0x0UL, -1UL, NULL, NULL, {RDEP(0)|RDEP(1),0UL, 0UL, 0UL}, {0UL,0UL, 0UL, 0UL}},
23*4882a593Smuzhiyun /* pmc11 */ { PFM_REG_MONITOR , 6, 0x0000000010000000UL, -1UL, NULL, pfm_ita_pmc_check, {RDEP(2)|RDEP(3)|RDEP(17),0UL, 0UL, 0UL}, {0UL,0UL, 0UL, 0UL}},
24*4882a593Smuzhiyun /* pmc12 */ { PFM_REG_MONITOR , 6, 0x0UL, -1UL, NULL, NULL, {RDEP(8)|RDEP(9)|RDEP(10)|RDEP(11)|RDEP(12)|RDEP(13)|RDEP(14)|RDEP(15)|RDEP(16),0UL, 0UL, 0UL}, {0UL,0UL, 0UL, 0UL}},
25*4882a593Smuzhiyun /* pmc13 */ { PFM_REG_CONFIG , 0, 0x0003ffff00000001UL, -1UL, NULL, pfm_ita_pmc_check, {0UL,0UL, 0UL, 0UL}, {0UL,0UL, 0UL, 0UL}},
26*4882a593Smuzhiyun { PFM_REG_END , 0, 0x0UL, -1UL, NULL, NULL, {0,}, {0,}}, /* end marker */
27*4882a593Smuzhiyun };
28*4882a593Smuzhiyun
29*4882a593Smuzhiyun static pfm_reg_desc_t pfm_ita_pmd_desc[PMU_MAX_PMDS]={
30*4882a593Smuzhiyun /* pmd0 */ { PFM_REG_BUFFER , 0, 0UL, -1UL, NULL, NULL, {RDEP(1),0UL, 0UL, 0UL}, {RDEP(10),0UL, 0UL, 0UL}},
31*4882a593Smuzhiyun /* pmd1 */ { PFM_REG_BUFFER , 0, 0UL, -1UL, NULL, NULL, {RDEP(0),0UL, 0UL, 0UL}, {RDEP(10),0UL, 0UL, 0UL}},
32*4882a593Smuzhiyun /* pmd2 */ { PFM_REG_BUFFER , 0, 0UL, -1UL, NULL, NULL, {RDEP(3)|RDEP(17),0UL, 0UL, 0UL}, {RDEP(11),0UL, 0UL, 0UL}},
33*4882a593Smuzhiyun /* pmd3 */ { PFM_REG_BUFFER , 0, 0UL, -1UL, NULL, NULL, {RDEP(2)|RDEP(17),0UL, 0UL, 0UL}, {RDEP(11),0UL, 0UL, 0UL}},
34*4882a593Smuzhiyun /* pmd4 */ { PFM_REG_COUNTING, 0, 0UL, -1UL, NULL, NULL, {0UL,0UL, 0UL, 0UL}, {RDEP(4),0UL, 0UL, 0UL}},
35*4882a593Smuzhiyun /* pmd5 */ { PFM_REG_COUNTING, 0, 0UL, -1UL, NULL, NULL, {0UL,0UL, 0UL, 0UL}, {RDEP(5),0UL, 0UL, 0UL}},
36*4882a593Smuzhiyun /* pmd6 */ { PFM_REG_COUNTING, 0, 0UL, -1UL, NULL, NULL, {0UL,0UL, 0UL, 0UL}, {RDEP(6),0UL, 0UL, 0UL}},
37*4882a593Smuzhiyun /* pmd7 */ { PFM_REG_COUNTING, 0, 0UL, -1UL, NULL, NULL, {0UL,0UL, 0UL, 0UL}, {RDEP(7),0UL, 0UL, 0UL}},
38*4882a593Smuzhiyun /* pmd8 */ { PFM_REG_BUFFER , 0, 0UL, -1UL, NULL, NULL, {RDEP(9)|RDEP(10)|RDEP(11)|RDEP(12)|RDEP(13)|RDEP(14)|RDEP(15)|RDEP(16),0UL, 0UL, 0UL}, {RDEP(12),0UL, 0UL, 0UL}},
39*4882a593Smuzhiyun /* pmd9 */ { PFM_REG_BUFFER , 0, 0UL, -1UL, NULL, NULL, {RDEP(8)|RDEP(10)|RDEP(11)|RDEP(12)|RDEP(13)|RDEP(14)|RDEP(15)|RDEP(16),0UL, 0UL, 0UL}, {RDEP(12),0UL, 0UL, 0UL}},
40*4882a593Smuzhiyun /* pmd10 */ { PFM_REG_BUFFER , 0, 0UL, -1UL, NULL, NULL, {RDEP(8)|RDEP(9)|RDEP(11)|RDEP(12)|RDEP(13)|RDEP(14)|RDEP(15)|RDEP(16),0UL, 0UL, 0UL}, {RDEP(12),0UL, 0UL, 0UL}},
41*4882a593Smuzhiyun /* pmd11 */ { PFM_REG_BUFFER , 0, 0UL, -1UL, NULL, NULL, {RDEP(8)|RDEP(9)|RDEP(10)|RDEP(12)|RDEP(13)|RDEP(14)|RDEP(15)|RDEP(16),0UL, 0UL, 0UL}, {RDEP(12),0UL, 0UL, 0UL}},
42*4882a593Smuzhiyun /* pmd12 */ { PFM_REG_BUFFER , 0, 0UL, -1UL, NULL, NULL, {RDEP(8)|RDEP(9)|RDEP(10)|RDEP(11)|RDEP(13)|RDEP(14)|RDEP(15)|RDEP(16),0UL, 0UL, 0UL}, {RDEP(12),0UL, 0UL, 0UL}},
43*4882a593Smuzhiyun /* pmd13 */ { PFM_REG_BUFFER , 0, 0UL, -1UL, NULL, NULL, {RDEP(8)|RDEP(9)|RDEP(10)|RDEP(11)|RDEP(12)|RDEP(14)|RDEP(15)|RDEP(16),0UL, 0UL, 0UL}, {RDEP(12),0UL, 0UL, 0UL}},
44*4882a593Smuzhiyun /* pmd14 */ { PFM_REG_BUFFER , 0, 0UL, -1UL, NULL, NULL, {RDEP(8)|RDEP(9)|RDEP(10)|RDEP(11)|RDEP(12)|RDEP(13)|RDEP(15)|RDEP(16),0UL, 0UL, 0UL}, {RDEP(12),0UL, 0UL, 0UL}},
45*4882a593Smuzhiyun /* pmd15 */ { PFM_REG_BUFFER , 0, 0UL, -1UL, NULL, NULL, {RDEP(8)|RDEP(9)|RDEP(10)|RDEP(11)|RDEP(12)|RDEP(13)|RDEP(14)|RDEP(16),0UL, 0UL, 0UL}, {RDEP(12),0UL, 0UL, 0UL}},
46*4882a593Smuzhiyun /* pmd16 */ { PFM_REG_BUFFER , 0, 0UL, -1UL, NULL, NULL, {RDEP(8)|RDEP(9)|RDEP(10)|RDEP(11)|RDEP(12)|RDEP(13)|RDEP(14)|RDEP(15),0UL, 0UL, 0UL}, {RDEP(12),0UL, 0UL, 0UL}},
47*4882a593Smuzhiyun /* pmd17 */ { PFM_REG_BUFFER , 0, 0UL, -1UL, NULL, NULL, {RDEP(2)|RDEP(3),0UL, 0UL, 0UL}, {RDEP(11),0UL, 0UL, 0UL}},
48*4882a593Smuzhiyun { PFM_REG_END , 0, 0UL, -1UL, NULL, NULL, {0,}, {0,}}, /* end marker */
49*4882a593Smuzhiyun };
50*4882a593Smuzhiyun
51*4882a593Smuzhiyun static int
pfm_ita_pmc_check(struct task_struct * task,pfm_context_t * ctx,unsigned int cnum,unsigned long * val,struct pt_regs * regs)52*4882a593Smuzhiyun pfm_ita_pmc_check(struct task_struct *task, pfm_context_t *ctx, unsigned int cnum, unsigned long *val, struct pt_regs *regs)
53*4882a593Smuzhiyun {
54*4882a593Smuzhiyun int ret;
55*4882a593Smuzhiyun int is_loaded;
56*4882a593Smuzhiyun
57*4882a593Smuzhiyun /* sanitfy check */
58*4882a593Smuzhiyun if (ctx == NULL) return -EINVAL;
59*4882a593Smuzhiyun
60*4882a593Smuzhiyun is_loaded = ctx->ctx_state == PFM_CTX_LOADED || ctx->ctx_state == PFM_CTX_MASKED;
61*4882a593Smuzhiyun
62*4882a593Smuzhiyun /*
63*4882a593Smuzhiyun * we must clear the (instruction) debug registers if pmc13.ta bit is cleared
64*4882a593Smuzhiyun * before they are written (fl_using_dbreg==0) to avoid picking up stale information.
65*4882a593Smuzhiyun */
66*4882a593Smuzhiyun if (cnum == 13 && is_loaded && ((*val & 0x1) == 0UL) && ctx->ctx_fl_using_dbreg == 0) {
67*4882a593Smuzhiyun
68*4882a593Smuzhiyun DPRINT(("pmc[%d]=0x%lx has active pmc13.ta cleared, clearing ibr\n", cnum, *val));
69*4882a593Smuzhiyun
70*4882a593Smuzhiyun /* don't mix debug with perfmon */
71*4882a593Smuzhiyun if (task && (task->thread.flags & IA64_THREAD_DBG_VALID) != 0) return -EINVAL;
72*4882a593Smuzhiyun
73*4882a593Smuzhiyun /*
74*4882a593Smuzhiyun * a count of 0 will mark the debug registers as in use and also
75*4882a593Smuzhiyun * ensure that they are properly cleared.
76*4882a593Smuzhiyun */
77*4882a593Smuzhiyun ret = pfm_write_ibr_dbr(1, ctx, NULL, 0, regs);
78*4882a593Smuzhiyun if (ret) return ret;
79*4882a593Smuzhiyun }
80*4882a593Smuzhiyun
81*4882a593Smuzhiyun /*
82*4882a593Smuzhiyun * we must clear the (data) debug registers if pmc11.pt bit is cleared
83*4882a593Smuzhiyun * before they are written (fl_using_dbreg==0) to avoid picking up stale information.
84*4882a593Smuzhiyun */
85*4882a593Smuzhiyun if (cnum == 11 && is_loaded && ((*val >> 28)& 0x1) == 0 && ctx->ctx_fl_using_dbreg == 0) {
86*4882a593Smuzhiyun
87*4882a593Smuzhiyun DPRINT(("pmc[%d]=0x%lx has active pmc11.pt cleared, clearing dbr\n", cnum, *val));
88*4882a593Smuzhiyun
89*4882a593Smuzhiyun /* don't mix debug with perfmon */
90*4882a593Smuzhiyun if (task && (task->thread.flags & IA64_THREAD_DBG_VALID) != 0) return -EINVAL;
91*4882a593Smuzhiyun
92*4882a593Smuzhiyun /*
93*4882a593Smuzhiyun * a count of 0 will mark the debug registers as in use and also
94*4882a593Smuzhiyun * ensure that they are properly cleared.
95*4882a593Smuzhiyun */
96*4882a593Smuzhiyun ret = pfm_write_ibr_dbr(0, ctx, NULL, 0, regs);
97*4882a593Smuzhiyun if (ret) return ret;
98*4882a593Smuzhiyun }
99*4882a593Smuzhiyun return 0;
100*4882a593Smuzhiyun }
101*4882a593Smuzhiyun
102*4882a593Smuzhiyun /*
103*4882a593Smuzhiyun * impl_pmcs, impl_pmds are computed at runtime to minimize errors!
104*4882a593Smuzhiyun */
105*4882a593Smuzhiyun static pmu_config_t pmu_conf_ita={
106*4882a593Smuzhiyun .pmu_name = "Itanium",
107*4882a593Smuzhiyun .pmu_family = 0x7,
108*4882a593Smuzhiyun .ovfl_val = (1UL << 32) - 1,
109*4882a593Smuzhiyun .pmd_desc = pfm_ita_pmd_desc,
110*4882a593Smuzhiyun .pmc_desc = pfm_ita_pmc_desc,
111*4882a593Smuzhiyun .num_ibrs = 8,
112*4882a593Smuzhiyun .num_dbrs = 8,
113*4882a593Smuzhiyun .use_rr_dbregs = 1, /* debug register are use for range retrictions */
114*4882a593Smuzhiyun };
115*4882a593Smuzhiyun
116*4882a593Smuzhiyun
117