16e11374bSAthira Rajeev // SPDX-License-Identifier: GPL-2.0-only
26e11374bSAthira Rajeev /*
36e11374bSAthira Rajeev  * Copyright 2022, Athira Rajeev, IBM Corp.
46e11374bSAthira Rajeev  */
56e11374bSAthira Rajeev 
66e11374bSAthira Rajeev #include <stdio.h>
76e11374bSAthira Rajeev #include <stdlib.h>
86e11374bSAthira Rajeev 
96e11374bSAthira Rajeev #include "../event.h"
106e11374bSAthira Rajeev #include "misc.h"
116e11374bSAthira Rajeev #include "utils.h"
126e11374bSAthira Rajeev 
136e11374bSAthira Rajeev extern void thirty_two_instruction_loop(int loops);
146e11374bSAthira Rajeev 
156e11374bSAthira Rajeev /*
166e11374bSAthira Rajeev  * A perf sampling test for mmcr0
176e11374bSAthira Rajeev  * fields: fc56_pmc56
186e11374bSAthira Rajeev  */
mmcr0_fc56_pmc56(void)196e11374bSAthira Rajeev static int mmcr0_fc56_pmc56(void)
206e11374bSAthira Rajeev {
216e11374bSAthira Rajeev 	struct event event;
226e11374bSAthira Rajeev 	u64 *intr_regs;
236e11374bSAthira Rajeev 
246e11374bSAthira Rajeev 	 /* Check for platform support for the test */
256e11374bSAthira Rajeev 	SKIP_IF(check_pvr_for_sampling_tests());
266e11374bSAthira Rajeev 
276e11374bSAthira Rajeev 	/* Init the event for the sampling test */
286e11374bSAthira Rajeev 	event_init_sampling(&event, 0x500fa);
296e11374bSAthira Rajeev 	event.attr.sample_regs_intr = platform_extended_mask;
306e11374bSAthira Rajeev 	FAIL_IF(event_open(&event));
316e11374bSAthira Rajeev 	event.mmap_buffer = event_sample_buf_mmap(event.fd, 1);
326e11374bSAthira Rajeev 
336e11374bSAthira Rajeev 	FAIL_IF(event_enable(&event));
346e11374bSAthira Rajeev 
356e11374bSAthira Rajeev 	/* workload to make the event overflow */
366e11374bSAthira Rajeev 	thirty_two_instruction_loop(10000);
376e11374bSAthira Rajeev 
386e11374bSAthira Rajeev 	FAIL_IF(event_disable(&event));
396e11374bSAthira Rajeev 
406e11374bSAthira Rajeev 	/* Check for sample count */
416e11374bSAthira Rajeev 	FAIL_IF(!collect_samples(event.mmap_buffer));
426e11374bSAthira Rajeev 
436e11374bSAthira Rajeev 	intr_regs = get_intr_regs(&event, event.mmap_buffer);
446e11374bSAthira Rajeev 
456e11374bSAthira Rajeev 	/* Check for intr_regs */
466e11374bSAthira Rajeev 	FAIL_IF(!intr_regs);
476e11374bSAthira Rajeev 
486e11374bSAthira Rajeev 	/* Verify that fc56 is not set in MMCR0 when using PMC5 */
496e11374bSAthira Rajeev 	FAIL_IF(get_mmcr0_fc56(get_reg_value(intr_regs, "MMCR0"), 5));
506e11374bSAthira Rajeev 
516e11374bSAthira Rajeev 	event_close(&event);
526e11374bSAthira Rajeev 	return 0;
536e11374bSAthira Rajeev }
546e11374bSAthira Rajeev 
main(void)556e11374bSAthira Rajeev int main(void)
566e11374bSAthira Rajeev {
576e11374bSAthira Rajeev 	return test_harness(mmcr0_fc56_pmc56, "mmcr0_fc56_pmc56");
586e11374bSAthira Rajeev }
59