11da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*
21da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * This file contains the McKinley PMU register description tables
31da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * and pmc checker used by perfmon.c.
41da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
51da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Copyright (C) 2002-2003  Hewlett Packard Co
61da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *               Stephane Eranian <eranian@hpl.hp.com>
71da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
81da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic int pfm_mck_pmc_check(struct task_struct *task, pfm_context_t *ctx, unsigned int cnum, unsigned long *val, struct pt_regs *regs);
91da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic pfm_reg_desc_t pfm_mck_pmc_desc[PMU_MAX_PMCS]={
111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* pmc0  */ { PFM_REG_CONTROL , 0, 0x1UL, -1UL, NULL, NULL, {0UL,0UL, 0UL, 0UL}, {0UL,0UL, 0UL, 0UL}},
121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* pmc1  */ { PFM_REG_CONTROL , 0, 0x0UL, -1UL, NULL, NULL, {0UL,0UL, 0UL, 0UL}, {0UL,0UL, 0UL, 0UL}},
131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* pmc2  */ { PFM_REG_CONTROL , 0, 0x0UL, -1UL, NULL, NULL, {0UL,0UL, 0UL, 0UL}, {0UL,0UL, 0UL, 0UL}},
141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* pmc3  */ { PFM_REG_CONTROL , 0, 0x0UL, -1UL, NULL, NULL, {0UL,0UL, 0UL, 0UL}, {0UL,0UL, 0UL, 0UL}},
151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* pmc4  */ { PFM_REG_COUNTING, 6, 0x0000000000800000UL, 0xfffff7fUL, NULL, pfm_mck_pmc_check, {RDEP(4),0UL, 0UL, 0UL}, {0UL,0UL, 0UL, 0UL}},
161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* pmc5  */ { PFM_REG_COUNTING, 6, 0x0UL, 0xfffff7fUL, NULL,  pfm_mck_pmc_check, {RDEP(5),0UL, 0UL, 0UL}, {0UL,0UL, 0UL, 0UL}},
171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* pmc6  */ { PFM_REG_COUNTING, 6, 0x0UL, 0xfffff7fUL, NULL,  pfm_mck_pmc_check, {RDEP(6),0UL, 0UL, 0UL}, {0UL,0UL, 0UL, 0UL}},
181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* pmc7  */ { PFM_REG_COUNTING, 6, 0x0UL, 0xfffff7fUL, NULL,  pfm_mck_pmc_check, {RDEP(7),0UL, 0UL, 0UL}, {0UL,0UL, 0UL, 0UL}},
191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* pmc8  */ { PFM_REG_CONFIG  , 0, 0xffffffff3fffffffUL, 0xffffffff3ffffffbUL, NULL, pfm_mck_pmc_check, {0UL,0UL, 0UL, 0UL}, {0UL,0UL, 0UL, 0UL}},
201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* pmc9  */ { PFM_REG_CONFIG  , 0, 0xffffffff3ffffffcUL, 0xffffffff3ffffffbUL, NULL, pfm_mck_pmc_check, {0UL,0UL, 0UL, 0UL}, {0UL,0UL, 0UL, 0UL}},
211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* pmc10 */ { PFM_REG_MONITOR , 4, 0x0UL, 0xffffUL, NULL, pfm_mck_pmc_check, {RDEP(0)|RDEP(1),0UL, 0UL, 0UL}, {0UL,0UL, 0UL, 0UL}},
221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* 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}},
231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* 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}},
241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* pmc13 */ { PFM_REG_CONFIG  , 0, 0x00002078fefefefeUL, 0x1e00018181818UL, NULL, pfm_mck_pmc_check, {0UL,0UL, 0UL, 0UL}, {0UL,0UL, 0UL, 0UL}},
251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* pmc14 */ { PFM_REG_CONFIG  , 0, 0x0db60db60db60db6UL, 0x2492UL, NULL, pfm_mck_pmc_check, {0UL,0UL, 0UL, 0UL}, {0UL,0UL, 0UL, 0UL}},
261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* pmc15 */ { PFM_REG_CONFIG  , 0, 0x00000000fffffff0UL, 0xfUL, NULL, pfm_mck_pmc_check, {0UL,0UL, 0UL, 0UL}, {0UL,0UL, 0UL, 0UL}},
271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	    { PFM_REG_END     , 0, 0x0UL, -1UL, NULL, NULL, {0,}, {0,}}, /* end marker */
281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds};
291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic pfm_reg_desc_t pfm_mck_pmd_desc[PMU_MAX_PMDS]={
311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* pmd0  */ { PFM_REG_BUFFER  , 0, 0x0UL, -1UL, NULL, NULL, {RDEP(1),0UL, 0UL, 0UL}, {RDEP(10),0UL, 0UL, 0UL}},
321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* pmd1  */ { PFM_REG_BUFFER  , 0, 0x0UL, -1UL, NULL, NULL, {RDEP(0),0UL, 0UL, 0UL}, {RDEP(10),0UL, 0UL, 0UL}},
331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* pmd2  */ { PFM_REG_BUFFER  , 0, 0x0UL, -1UL, NULL, NULL, {RDEP(3)|RDEP(17),0UL, 0UL, 0UL}, {RDEP(11),0UL, 0UL, 0UL}},
341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* pmd3  */ { PFM_REG_BUFFER  , 0, 0x0UL, -1UL, NULL, NULL, {RDEP(2)|RDEP(17),0UL, 0UL, 0UL}, {RDEP(11),0UL, 0UL, 0UL}},
351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* pmd4  */ { PFM_REG_COUNTING, 0, 0x0UL, -1UL, NULL, NULL, {0UL,0UL, 0UL, 0UL}, {RDEP(4),0UL, 0UL, 0UL}},
361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* pmd5  */ { PFM_REG_COUNTING, 0, 0x0UL, -1UL, NULL, NULL, {0UL,0UL, 0UL, 0UL}, {RDEP(5),0UL, 0UL, 0UL}},
371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* pmd6  */ { PFM_REG_COUNTING, 0, 0x0UL, -1UL, NULL, NULL, {0UL,0UL, 0UL, 0UL}, {RDEP(6),0UL, 0UL, 0UL}},
381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* pmd7  */ { PFM_REG_COUNTING, 0, 0x0UL, -1UL, NULL, NULL, {0UL,0UL, 0UL, 0UL}, {RDEP(7),0UL, 0UL, 0UL}},
391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* 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}},
401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* 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}},
411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* 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}},
421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* 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}},
431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* 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}},
441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* 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}},
451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* 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}},
461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* 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}},
471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* 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}},
481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* pmd17 */ { PFM_REG_BUFFER  , 0, 0x0UL, -1UL, NULL, NULL, {RDEP(2)|RDEP(3),0UL, 0UL, 0UL}, {RDEP(11),0UL, 0UL, 0UL}},
491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	    { PFM_REG_END     , 0, 0x0UL, -1UL, NULL, NULL, {0,}, {0,}}, /* end marker */
501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds};
511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*
531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * PMC reserved fields must have their power-up values preserved
541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic int
561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldspfm_mck_reserved(unsigned int cnum, unsigned long *val, struct pt_regs *regs)
571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{
581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	unsigned long tmp1, tmp2, ival = *val;
591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	/* remove reserved areas from user value */
611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	tmp1 = ival & PMC_RSVD_MASK(cnum);
621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	/* get reserved fields values */
641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	tmp2 = PMC_DFL_VAL(cnum) & ~PMC_RSVD_MASK(cnum);
651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	*val = tmp1 | tmp2;
671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	DPRINT(("pmc[%d]=0x%lx, mask=0x%lx, reset=0x%lx, val=0x%lx\n",
691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		  cnum, ival, PMC_RSVD_MASK(cnum), PMC_DFL_VAL(cnum), *val));
701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	return 0;
711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}
721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*
741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * task can be NULL if the context is unloaded
751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic int
771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldspfm_mck_pmc_check(struct task_struct *task, pfm_context_t *ctx, unsigned int cnum, unsigned long *val, struct pt_regs *regs)
781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{
791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	int ret = 0, check_case1 = 0;
801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	unsigned long val8 = 0, val14 = 0, val13 = 0;
811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	int is_loaded;
821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	/* first preserve the reserved fields */
841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	pfm_mck_reserved(cnum, val, regs);
851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	/* sanitfy check */
871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	if (ctx == NULL) return -EINVAL;
881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	is_loaded = ctx->ctx_state == PFM_CTX_LOADED || ctx->ctx_state == PFM_CTX_MASKED;
901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
911da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	/*
921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	 * we must clear the debug registers if pmc13 has a value which enable
931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	 * memory pipeline event constraints. In this case we need to clear the
941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	 * the debug registers if they have not yet been accessed. This is required
951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	 * to avoid picking stale state.
961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	 * PMC13 is "active" if:
971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	 * 	one of the pmc13.cfg_dbrpXX field is different from 0x3
981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	 * AND
991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	 * 	at the corresponding pmc13.ena_dbrpXX is set.
1001da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	 */
1011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	DPRINT(("cnum=%u val=0x%lx, using_dbreg=%d loaded=%d\n", cnum, *val, ctx->ctx_fl_using_dbreg, is_loaded));
1021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	if (cnum == 13 && is_loaded
1041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	    && (*val & 0x1e00000000000UL) && (*val & 0x18181818UL) != 0x18181818UL && ctx->ctx_fl_using_dbreg == 0) {
1051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		DPRINT(("pmc[%d]=0x%lx has active pmc13 settings, clearing dbr\n", cnum, *val));
1071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		/* don't mix debug with perfmon */
1091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		if (task && (task->thread.flags & IA64_THREAD_DBG_VALID) != 0) return -EINVAL;
1101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		/*
1121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		 * a count of 0 will mark the debug registers as in use and also
1131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		 * ensure that they are properly cleared.
1141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		 */
1151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		ret = pfm_write_ibr_dbr(PFM_DATA_RR, ctx, NULL, 0, regs);
1161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		if (ret) return ret;
1171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	}
1181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	/*
1191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	 * we must clear the (instruction) debug registers if any pmc14.ibrpX bit is enabled
1201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	 * before they are (fl_using_dbreg==0) to avoid picking up stale information.
1211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	 */
1221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	if (cnum == 14 && is_loaded && ((*val & 0x2222UL) != 0x2222UL) && ctx->ctx_fl_using_dbreg == 0) {
1231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		DPRINT(("pmc[%d]=0x%lx has active pmc14 settings, clearing ibr\n", cnum, *val));
1251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		/* don't mix debug with perfmon */
1271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		if (task && (task->thread.flags & IA64_THREAD_DBG_VALID) != 0) return -EINVAL;
1281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		/*
1301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		 * a count of 0 will mark the debug registers as in use and also
1311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		 * ensure that they are properly cleared.
1321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		 */
1331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		ret = pfm_write_ibr_dbr(PFM_CODE_RR, ctx, NULL, 0, regs);
1341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		if (ret) return ret;
1351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	}
1371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	switch(cnum) {
1391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		case  4: *val |= 1UL << 23; /* force power enable bit */
1401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			 break;
1411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		case  8: val8 = *val;
1421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			 val13 = ctx->ctx_pmcs[13];
1431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			 val14 = ctx->ctx_pmcs[14];
1441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			 check_case1 = 1;
1451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			 break;
1461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		case 13: val8  = ctx->ctx_pmcs[8];
1471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			 val13 = *val;
1481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			 val14 = ctx->ctx_pmcs[14];
1491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			 check_case1 = 1;
1501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			 break;
1511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		case 14: val8  = ctx->ctx_pmcs[8];
1521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			 val13 = ctx->ctx_pmcs[13];
1531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			 val14 = *val;
1541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			 check_case1 = 1;
1551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			 break;
1561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	}
1571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	/* check illegal configuration which can produce inconsistencies in tagging
1581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	 * i-side events in L1D and L2 caches
1591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	 */
1601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	if (check_case1) {
1611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		ret =   ((val13 >> 45) & 0xf) == 0
1621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		   && ((val8 & 0x1) == 0)
1631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		   && ((((val14>>1) & 0x3) == 0x2 || ((val14>>1) & 0x3) == 0x0)
1641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		       ||(((val14>>4) & 0x3) == 0x2 || ((val14>>4) & 0x3) == 0x0));
1651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		if (ret) DPRINT((KERN_DEBUG "perfmon: failure check_case1\n"));
1671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	}
1681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	return ret ? -EINVAL : 0;
1701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}
1711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*
1731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * impl_pmcs, impl_pmds are computed at runtime to minimize errors!
1741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
1751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic pmu_config_t pmu_conf_mck={
1761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	.pmu_name      = "Itanium 2",
1771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	.pmu_family    = 0x1f,
1781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	.flags	       = PFM_PMU_IRQ_RESEND,
1791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	.ovfl_val      = (1UL << 47) - 1,
1801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	.pmd_desc      = pfm_mck_pmd_desc,
1811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	.pmc_desc      = pfm_mck_pmc_desc,
1821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	.num_ibrs       = 8,
1831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	.num_dbrs       = 8,
18472fdbdce3d52282f8ea95f512e871791256754e6Simon Arlott	.use_rr_dbregs = 1 /* debug register are use for range restrictions */
1851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds};
1861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
188