1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * Copyright 2022, Athira Rajeev, IBM Corp.
4  */
5 
6 #include <stdio.h>
7 #include "../event.h"
8 #include "../sampling_tests/misc.h"
9 
10 #define PM_RUN_CYC_ALT 0x200f4
11 #define PM_INST_DISP 0x200f2
12 #define PM_BR_2PATH 0x20036
13 #define PM_LD_MISS_L1 0x3e054
14 #define PM_RUN_INST_CMPL_ALT 0x400fa
15 
16 #define EventCode_1 0x100fc
17 #define EventCode_2 0x200fa
18 #define EventCode_3 0x300fc
19 #define EventCode_4 0x400fc
20 
21 /*
22  * Check for event alternatives.
23  */
24 
event_alternatives_tests_p10(void)25 static int event_alternatives_tests_p10(void)
26 {
27 	struct event *e, events[5];
28 	int i;
29 
30 	/* Check for platform support for the test */
31 	SKIP_IF(platform_check_for_tests());
32 
33 	/*
34 	 * PVR check is used here since PMU specific data like
35 	 * alternative events is handled by respective PMU driver
36 	 * code and using PVR will work correctly for all cases
37 	 * including generic compat mode.
38 	 */
39 	SKIP_IF(PVR_VER(mfspr(SPRN_PVR)) != POWER10);
40 
41 	SKIP_IF(check_for_generic_compat_pmu());
42 
43 	/*
44 	 * Test for event alternative for 0x0001e
45 	 * and 0x00002.
46 	 */
47 	e = &events[0];
48 	event_init(e, 0x0001e);
49 
50 	e = &events[1];
51 	event_init(e, EventCode_1);
52 
53 	e = &events[2];
54 	event_init(e, EventCode_2);
55 
56 	e = &events[3];
57 	event_init(e, EventCode_3);
58 
59 	e = &events[4];
60 	event_init(e, EventCode_4);
61 
62 	FAIL_IF(event_open(&events[0]));
63 
64 	/*
65 	 * Expected to pass since 0x0001e has alternative event
66 	 * 0x600f4 in PMC6. So it can go in with other events
67 	 * in PMC1 to PMC4.
68 	 */
69 	for (i = 1; i < 5; i++)
70 		FAIL_IF(event_open_with_group(&events[i], events[0].fd));
71 
72 	for (i = 0; i < 5; i++)
73 		event_close(&events[i]);
74 
75 	e = &events[0];
76 	event_init(e, 0x00002);
77 
78 	e = &events[1];
79 	event_init(e, EventCode_1);
80 
81 	e = &events[2];
82 	event_init(e, EventCode_2);
83 
84 	e = &events[3];
85 	event_init(e, EventCode_3);
86 
87 	e = &events[4];
88 	event_init(e, EventCode_4);
89 
90 	FAIL_IF(event_open(&events[0]));
91 
92 	/*
93 	 * Expected to pass since 0x00020 has alternative event
94 	 * 0x500fa in PMC5. So it can go in with other events
95 	 * in PMC1 to PMC4.
96 	 */
97 	for (i = 1; i < 5; i++)
98 		FAIL_IF(event_open_with_group(&events[i], events[0].fd));
99 
100 	for (i = 0; i < 5; i++)
101 		event_close(&events[i]);
102 
103 	return 0;
104 }
105 
main(void)106 int main(void)
107 {
108 	return test_harness(event_alternatives_tests_p10, "event_alternatives_tests_p10");
109 }
110