1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * Copyright 2022, Athira Rajeev, IBM Corp.
4 */
5
6 #include <stdio.h>
7 #include <sys/prctl.h>
8 #include <limits.h>
9 #include "../event.h"
10 #include "../sampling_tests/misc.h"
11
12 /* The data cache was reloaded from local core's L3 due to a demand load */
13 #define EventCode_1 0x1340000001c040
14 /* PM_DATA_RADIX_PROCESS_L2_PTE_FROM_L2 */
15 #define EventCode_2 0x14242
16 /* Event code with IFM, EBB, BHRB bits set in event code */
17 #define EventCode_3 0xf00000000000001e
18
19 /*
20 * Some of the bits in the event code is
21 * reserved for specific platforms.
22 * Event code bits 52-59 are reserved in power9,
23 * whereas in power10, these are used for programming
24 * Monitor Mode Control Register 3 (MMCR3).
25 * Bit 9 in event code is reserved in power9,
26 * whereas it is used for programming "radix_scope_qual"
27 * bit 18 in Monitor Mode Control Register 1 (MMCR1).
28 *
29 * Testcase to ensure that using reserved bits in
30 * event code should cause event_open to fail.
31 */
32
invalid_event_code(void)33 static int invalid_event_code(void)
34 {
35 struct event event;
36
37 /* Check for platform support for the test */
38 SKIP_IF(platform_check_for_tests());
39
40 /*
41 * Events using MMCR3 bits and radix scope qual bits
42 * should fail in power9 and should succeed in power10.
43 * Init the events and check for pass/fail in event open.
44 */
45 if (have_hwcap2(PPC_FEATURE2_ARCH_3_1)) {
46 event_init(&event, EventCode_1);
47 FAIL_IF(event_open(&event));
48 event_close(&event);
49
50 event_init(&event, EventCode_2);
51 FAIL_IF(event_open(&event));
52 event_close(&event);
53 } else {
54 event_init(&event, EventCode_1);
55 FAIL_IF(!event_open(&event));
56
57 event_init(&event, EventCode_2);
58 FAIL_IF(!event_open(&event));
59 }
60
61 return 0;
62 }
63
main(void)64 int main(void)
65 {
66 return test_harness(invalid_event_code, "invalid_event_code");
67 }
68