18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * This file contains the McKinley PMU register description tables 48c2ecf20Sopenharmony_ci * and pmc checker used by perfmon.c. 58c2ecf20Sopenharmony_ci * 68c2ecf20Sopenharmony_ci * Copyright (C) 2002-2003 Hewlett Packard Co 78c2ecf20Sopenharmony_ci * Stephane Eranian <eranian@hpl.hp.com> 88c2ecf20Sopenharmony_ci */ 98c2ecf20Sopenharmony_cistatic int pfm_mck_pmc_check(struct task_struct *task, pfm_context_t *ctx, unsigned int cnum, unsigned long *val, struct pt_regs *regs); 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_cistatic pfm_reg_desc_t pfm_mck_pmc_desc[PMU_MAX_PMCS]={ 128c2ecf20Sopenharmony_ci/* pmc0 */ { PFM_REG_CONTROL , 0, 0x1UL, -1UL, NULL, NULL, {0UL,0UL, 0UL, 0UL}, {0UL,0UL, 0UL, 0UL}}, 138c2ecf20Sopenharmony_ci/* pmc1 */ { PFM_REG_CONTROL , 0, 0x0UL, -1UL, NULL, NULL, {0UL,0UL, 0UL, 0UL}, {0UL,0UL, 0UL, 0UL}}, 148c2ecf20Sopenharmony_ci/* pmc2 */ { PFM_REG_CONTROL , 0, 0x0UL, -1UL, NULL, NULL, {0UL,0UL, 0UL, 0UL}, {0UL,0UL, 0UL, 0UL}}, 158c2ecf20Sopenharmony_ci/* pmc3 */ { PFM_REG_CONTROL , 0, 0x0UL, -1UL, NULL, NULL, {0UL,0UL, 0UL, 0UL}, {0UL,0UL, 0UL, 0UL}}, 168c2ecf20Sopenharmony_ci/* pmc4 */ { PFM_REG_COUNTING, 6, 0x0000000000800000UL, 0xfffff7fUL, NULL, pfm_mck_pmc_check, {RDEP(4),0UL, 0UL, 0UL}, {0UL,0UL, 0UL, 0UL}}, 178c2ecf20Sopenharmony_ci/* pmc5 */ { PFM_REG_COUNTING, 6, 0x0UL, 0xfffff7fUL, NULL, pfm_mck_pmc_check, {RDEP(5),0UL, 0UL, 0UL}, {0UL,0UL, 0UL, 0UL}}, 188c2ecf20Sopenharmony_ci/* pmc6 */ { PFM_REG_COUNTING, 6, 0x0UL, 0xfffff7fUL, NULL, pfm_mck_pmc_check, {RDEP(6),0UL, 0UL, 0UL}, {0UL,0UL, 0UL, 0UL}}, 198c2ecf20Sopenharmony_ci/* pmc7 */ { PFM_REG_COUNTING, 6, 0x0UL, 0xfffff7fUL, NULL, pfm_mck_pmc_check, {RDEP(7),0UL, 0UL, 0UL}, {0UL,0UL, 0UL, 0UL}}, 208c2ecf20Sopenharmony_ci/* pmc8 */ { PFM_REG_CONFIG , 0, 0xffffffff3fffffffUL, 0xffffffff3ffffffbUL, NULL, pfm_mck_pmc_check, {0UL,0UL, 0UL, 0UL}, {0UL,0UL, 0UL, 0UL}}, 218c2ecf20Sopenharmony_ci/* pmc9 */ { PFM_REG_CONFIG , 0, 0xffffffff3ffffffcUL, 0xffffffff3ffffffbUL, NULL, pfm_mck_pmc_check, {0UL,0UL, 0UL, 0UL}, {0UL,0UL, 0UL, 0UL}}, 228c2ecf20Sopenharmony_ci/* pmc10 */ { PFM_REG_MONITOR , 4, 0x0UL, 0xffffUL, NULL, pfm_mck_pmc_check, {RDEP(0)|RDEP(1),0UL, 0UL, 0UL}, {0UL,0UL, 0UL, 0UL}}, 238c2ecf20Sopenharmony_ci/* pmc11 */ { PFM_REG_MONITOR , 6, 0x0UL, 0x30f01cf, NULL, pfm_mck_pmc_check, {RDEP(2)|RDEP(3)|RDEP(17),0UL, 0UL, 0UL}, {0UL,0UL, 0UL, 0UL}}, 248c2ecf20Sopenharmony_ci/* pmc12 */ { PFM_REG_MONITOR , 6, 0x0UL, 0xffffUL, NULL, pfm_mck_pmc_check, {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}}, 258c2ecf20Sopenharmony_ci/* pmc13 */ { PFM_REG_CONFIG , 0, 0x00002078fefefefeUL, 0x1e00018181818UL, NULL, pfm_mck_pmc_check, {0UL,0UL, 0UL, 0UL}, {0UL,0UL, 0UL, 0UL}}, 268c2ecf20Sopenharmony_ci/* pmc14 */ { PFM_REG_CONFIG , 0, 0x0db60db60db60db6UL, 0x2492UL, NULL, pfm_mck_pmc_check, {0UL,0UL, 0UL, 0UL}, {0UL,0UL, 0UL, 0UL}}, 278c2ecf20Sopenharmony_ci/* pmc15 */ { PFM_REG_CONFIG , 0, 0x00000000fffffff0UL, 0xfUL, NULL, pfm_mck_pmc_check, {0UL,0UL, 0UL, 0UL}, {0UL,0UL, 0UL, 0UL}}, 288c2ecf20Sopenharmony_ci { PFM_REG_END , 0, 0x0UL, -1UL, NULL, NULL, {0,}, {0,}}, /* end marker */ 298c2ecf20Sopenharmony_ci}; 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_cistatic pfm_reg_desc_t pfm_mck_pmd_desc[PMU_MAX_PMDS]={ 328c2ecf20Sopenharmony_ci/* pmd0 */ { PFM_REG_BUFFER , 0, 0x0UL, -1UL, NULL, NULL, {RDEP(1),0UL, 0UL, 0UL}, {RDEP(10),0UL, 0UL, 0UL}}, 338c2ecf20Sopenharmony_ci/* pmd1 */ { PFM_REG_BUFFER , 0, 0x0UL, -1UL, NULL, NULL, {RDEP(0),0UL, 0UL, 0UL}, {RDEP(10),0UL, 0UL, 0UL}}, 348c2ecf20Sopenharmony_ci/* pmd2 */ { PFM_REG_BUFFER , 0, 0x0UL, -1UL, NULL, NULL, {RDEP(3)|RDEP(17),0UL, 0UL, 0UL}, {RDEP(11),0UL, 0UL, 0UL}}, 358c2ecf20Sopenharmony_ci/* pmd3 */ { PFM_REG_BUFFER , 0, 0x0UL, -1UL, NULL, NULL, {RDEP(2)|RDEP(17),0UL, 0UL, 0UL}, {RDEP(11),0UL, 0UL, 0UL}}, 368c2ecf20Sopenharmony_ci/* pmd4 */ { PFM_REG_COUNTING, 0, 0x0UL, -1UL, NULL, NULL, {0UL,0UL, 0UL, 0UL}, {RDEP(4),0UL, 0UL, 0UL}}, 378c2ecf20Sopenharmony_ci/* pmd5 */ { PFM_REG_COUNTING, 0, 0x0UL, -1UL, NULL, NULL, {0UL,0UL, 0UL, 0UL}, {RDEP(5),0UL, 0UL, 0UL}}, 388c2ecf20Sopenharmony_ci/* pmd6 */ { PFM_REG_COUNTING, 0, 0x0UL, -1UL, NULL, NULL, {0UL,0UL, 0UL, 0UL}, {RDEP(6),0UL, 0UL, 0UL}}, 398c2ecf20Sopenharmony_ci/* pmd7 */ { PFM_REG_COUNTING, 0, 0x0UL, -1UL, NULL, NULL, {0UL,0UL, 0UL, 0UL}, {RDEP(7),0UL, 0UL, 0UL}}, 408c2ecf20Sopenharmony_ci/* pmd8 */ { PFM_REG_BUFFER , 0, 0x0UL, -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}}, 418c2ecf20Sopenharmony_ci/* pmd9 */ { PFM_REG_BUFFER , 0, 0x0UL, -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}}, 428c2ecf20Sopenharmony_ci/* pmd10 */ { PFM_REG_BUFFER , 0, 0x0UL, -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}}, 438c2ecf20Sopenharmony_ci/* pmd11 */ { PFM_REG_BUFFER , 0, 0x0UL, -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}}, 448c2ecf20Sopenharmony_ci/* pmd12 */ { PFM_REG_BUFFER , 0, 0x0UL, -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}}, 458c2ecf20Sopenharmony_ci/* pmd13 */ { PFM_REG_BUFFER , 0, 0x0UL, -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}}, 468c2ecf20Sopenharmony_ci/* pmd14 */ { PFM_REG_BUFFER , 0, 0x0UL, -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}}, 478c2ecf20Sopenharmony_ci/* pmd15 */ { PFM_REG_BUFFER , 0, 0x0UL, -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}}, 488c2ecf20Sopenharmony_ci/* pmd16 */ { PFM_REG_BUFFER , 0, 0x0UL, -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}}, 498c2ecf20Sopenharmony_ci/* pmd17 */ { PFM_REG_BUFFER , 0, 0x0UL, -1UL, NULL, NULL, {RDEP(2)|RDEP(3),0UL, 0UL, 0UL}, {RDEP(11),0UL, 0UL, 0UL}}, 508c2ecf20Sopenharmony_ci { PFM_REG_END , 0, 0x0UL, -1UL, NULL, NULL, {0,}, {0,}}, /* end marker */ 518c2ecf20Sopenharmony_ci}; 528c2ecf20Sopenharmony_ci 538c2ecf20Sopenharmony_ci/* 548c2ecf20Sopenharmony_ci * PMC reserved fields must have their power-up values preserved 558c2ecf20Sopenharmony_ci */ 568c2ecf20Sopenharmony_cistatic int 578c2ecf20Sopenharmony_cipfm_mck_reserved(unsigned int cnum, unsigned long *val, struct pt_regs *regs) 588c2ecf20Sopenharmony_ci{ 598c2ecf20Sopenharmony_ci unsigned long tmp1, tmp2, ival = *val; 608c2ecf20Sopenharmony_ci 618c2ecf20Sopenharmony_ci /* remove reserved areas from user value */ 628c2ecf20Sopenharmony_ci tmp1 = ival & PMC_RSVD_MASK(cnum); 638c2ecf20Sopenharmony_ci 648c2ecf20Sopenharmony_ci /* get reserved fields values */ 658c2ecf20Sopenharmony_ci tmp2 = PMC_DFL_VAL(cnum) & ~PMC_RSVD_MASK(cnum); 668c2ecf20Sopenharmony_ci 678c2ecf20Sopenharmony_ci *val = tmp1 | tmp2; 688c2ecf20Sopenharmony_ci 698c2ecf20Sopenharmony_ci DPRINT(("pmc[%d]=0x%lx, mask=0x%lx, reset=0x%lx, val=0x%lx\n", 708c2ecf20Sopenharmony_ci cnum, ival, PMC_RSVD_MASK(cnum), PMC_DFL_VAL(cnum), *val)); 718c2ecf20Sopenharmony_ci return 0; 728c2ecf20Sopenharmony_ci} 738c2ecf20Sopenharmony_ci 748c2ecf20Sopenharmony_ci/* 758c2ecf20Sopenharmony_ci * task can be NULL if the context is unloaded 768c2ecf20Sopenharmony_ci */ 778c2ecf20Sopenharmony_cistatic int 788c2ecf20Sopenharmony_cipfm_mck_pmc_check(struct task_struct *task, pfm_context_t *ctx, unsigned int cnum, unsigned long *val, struct pt_regs *regs) 798c2ecf20Sopenharmony_ci{ 808c2ecf20Sopenharmony_ci int ret = 0, check_case1 = 0; 818c2ecf20Sopenharmony_ci unsigned long val8 = 0, val14 = 0, val13 = 0; 828c2ecf20Sopenharmony_ci int is_loaded; 838c2ecf20Sopenharmony_ci 848c2ecf20Sopenharmony_ci /* first preserve the reserved fields */ 858c2ecf20Sopenharmony_ci pfm_mck_reserved(cnum, val, regs); 868c2ecf20Sopenharmony_ci 878c2ecf20Sopenharmony_ci /* sanitfy check */ 888c2ecf20Sopenharmony_ci if (ctx == NULL) return -EINVAL; 898c2ecf20Sopenharmony_ci 908c2ecf20Sopenharmony_ci is_loaded = ctx->ctx_state == PFM_CTX_LOADED || ctx->ctx_state == PFM_CTX_MASKED; 918c2ecf20Sopenharmony_ci 928c2ecf20Sopenharmony_ci /* 938c2ecf20Sopenharmony_ci * we must clear the debug registers if pmc13 has a value which enable 948c2ecf20Sopenharmony_ci * memory pipeline event constraints. In this case we need to clear the 958c2ecf20Sopenharmony_ci * the debug registers if they have not yet been accessed. This is required 968c2ecf20Sopenharmony_ci * to avoid picking stale state. 978c2ecf20Sopenharmony_ci * PMC13 is "active" if: 988c2ecf20Sopenharmony_ci * one of the pmc13.cfg_dbrpXX field is different from 0x3 998c2ecf20Sopenharmony_ci * AND 1008c2ecf20Sopenharmony_ci * at the corresponding pmc13.ena_dbrpXX is set. 1018c2ecf20Sopenharmony_ci */ 1028c2ecf20Sopenharmony_ci DPRINT(("cnum=%u val=0x%lx, using_dbreg=%d loaded=%d\n", cnum, *val, ctx->ctx_fl_using_dbreg, is_loaded)); 1038c2ecf20Sopenharmony_ci 1048c2ecf20Sopenharmony_ci if (cnum == 13 && is_loaded 1058c2ecf20Sopenharmony_ci && (*val & 0x1e00000000000UL) && (*val & 0x18181818UL) != 0x18181818UL && ctx->ctx_fl_using_dbreg == 0) { 1068c2ecf20Sopenharmony_ci 1078c2ecf20Sopenharmony_ci DPRINT(("pmc[%d]=0x%lx has active pmc13 settings, clearing dbr\n", cnum, *val)); 1088c2ecf20Sopenharmony_ci 1098c2ecf20Sopenharmony_ci /* don't mix debug with perfmon */ 1108c2ecf20Sopenharmony_ci if (task && (task->thread.flags & IA64_THREAD_DBG_VALID) != 0) return -EINVAL; 1118c2ecf20Sopenharmony_ci 1128c2ecf20Sopenharmony_ci /* 1138c2ecf20Sopenharmony_ci * a count of 0 will mark the debug registers as in use and also 1148c2ecf20Sopenharmony_ci * ensure that they are properly cleared. 1158c2ecf20Sopenharmony_ci */ 1168c2ecf20Sopenharmony_ci ret = pfm_write_ibr_dbr(PFM_DATA_RR, ctx, NULL, 0, regs); 1178c2ecf20Sopenharmony_ci if (ret) return ret; 1188c2ecf20Sopenharmony_ci } 1198c2ecf20Sopenharmony_ci /* 1208c2ecf20Sopenharmony_ci * we must clear the (instruction) debug registers if any pmc14.ibrpX bit is enabled 1218c2ecf20Sopenharmony_ci * before they are (fl_using_dbreg==0) to avoid picking up stale information. 1228c2ecf20Sopenharmony_ci */ 1238c2ecf20Sopenharmony_ci if (cnum == 14 && is_loaded && ((*val & 0x2222UL) != 0x2222UL) && ctx->ctx_fl_using_dbreg == 0) { 1248c2ecf20Sopenharmony_ci 1258c2ecf20Sopenharmony_ci DPRINT(("pmc[%d]=0x%lx has active pmc14 settings, clearing ibr\n", cnum, *val)); 1268c2ecf20Sopenharmony_ci 1278c2ecf20Sopenharmony_ci /* don't mix debug with perfmon */ 1288c2ecf20Sopenharmony_ci if (task && (task->thread.flags & IA64_THREAD_DBG_VALID) != 0) return -EINVAL; 1298c2ecf20Sopenharmony_ci 1308c2ecf20Sopenharmony_ci /* 1318c2ecf20Sopenharmony_ci * a count of 0 will mark the debug registers as in use and also 1328c2ecf20Sopenharmony_ci * ensure that they are properly cleared. 1338c2ecf20Sopenharmony_ci */ 1348c2ecf20Sopenharmony_ci ret = pfm_write_ibr_dbr(PFM_CODE_RR, ctx, NULL, 0, regs); 1358c2ecf20Sopenharmony_ci if (ret) return ret; 1368c2ecf20Sopenharmony_ci 1378c2ecf20Sopenharmony_ci } 1388c2ecf20Sopenharmony_ci 1398c2ecf20Sopenharmony_ci switch(cnum) { 1408c2ecf20Sopenharmony_ci case 4: *val |= 1UL << 23; /* force power enable bit */ 1418c2ecf20Sopenharmony_ci break; 1428c2ecf20Sopenharmony_ci case 8: val8 = *val; 1438c2ecf20Sopenharmony_ci val13 = ctx->ctx_pmcs[13]; 1448c2ecf20Sopenharmony_ci val14 = ctx->ctx_pmcs[14]; 1458c2ecf20Sopenharmony_ci check_case1 = 1; 1468c2ecf20Sopenharmony_ci break; 1478c2ecf20Sopenharmony_ci case 13: val8 = ctx->ctx_pmcs[8]; 1488c2ecf20Sopenharmony_ci val13 = *val; 1498c2ecf20Sopenharmony_ci val14 = ctx->ctx_pmcs[14]; 1508c2ecf20Sopenharmony_ci check_case1 = 1; 1518c2ecf20Sopenharmony_ci break; 1528c2ecf20Sopenharmony_ci case 14: val8 = ctx->ctx_pmcs[8]; 1538c2ecf20Sopenharmony_ci val13 = ctx->ctx_pmcs[13]; 1548c2ecf20Sopenharmony_ci val14 = *val; 1558c2ecf20Sopenharmony_ci check_case1 = 1; 1568c2ecf20Sopenharmony_ci break; 1578c2ecf20Sopenharmony_ci } 1588c2ecf20Sopenharmony_ci /* check illegal configuration which can produce inconsistencies in tagging 1598c2ecf20Sopenharmony_ci * i-side events in L1D and L2 caches 1608c2ecf20Sopenharmony_ci */ 1618c2ecf20Sopenharmony_ci if (check_case1) { 1628c2ecf20Sopenharmony_ci ret = ((val13 >> 45) & 0xf) == 0 1638c2ecf20Sopenharmony_ci && ((val8 & 0x1) == 0) 1648c2ecf20Sopenharmony_ci && ((((val14>>1) & 0x3) == 0x2 || ((val14>>1) & 0x3) == 0x0) 1658c2ecf20Sopenharmony_ci ||(((val14>>4) & 0x3) == 0x2 || ((val14>>4) & 0x3) == 0x0)); 1668c2ecf20Sopenharmony_ci 1678c2ecf20Sopenharmony_ci if (ret) DPRINT((KERN_DEBUG "perfmon: failure check_case1\n")); 1688c2ecf20Sopenharmony_ci } 1698c2ecf20Sopenharmony_ci 1708c2ecf20Sopenharmony_ci return ret ? -EINVAL : 0; 1718c2ecf20Sopenharmony_ci} 1728c2ecf20Sopenharmony_ci 1738c2ecf20Sopenharmony_ci/* 1748c2ecf20Sopenharmony_ci * impl_pmcs, impl_pmds are computed at runtime to minimize errors! 1758c2ecf20Sopenharmony_ci */ 1768c2ecf20Sopenharmony_cistatic pmu_config_t pmu_conf_mck={ 1778c2ecf20Sopenharmony_ci .pmu_name = "Itanium 2", 1788c2ecf20Sopenharmony_ci .pmu_family = 0x1f, 1798c2ecf20Sopenharmony_ci .flags = PFM_PMU_IRQ_RESEND, 1808c2ecf20Sopenharmony_ci .ovfl_val = (1UL << 47) - 1, 1818c2ecf20Sopenharmony_ci .pmd_desc = pfm_mck_pmd_desc, 1828c2ecf20Sopenharmony_ci .pmc_desc = pfm_mck_pmc_desc, 1838c2ecf20Sopenharmony_ci .num_ibrs = 8, 1848c2ecf20Sopenharmony_ci .num_dbrs = 8, 1858c2ecf20Sopenharmony_ci .use_rr_dbregs = 1 /* debug register are use for range restrictions */ 1868c2ecf20Sopenharmony_ci}; 1878c2ecf20Sopenharmony_ci 1888c2ecf20Sopenharmony_ci 189