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/*
11 * Testcase for reserved bits in Monitor Mode Control
12 * Register A (MMCRA) Random Sampling Mode (SM) value.
13 * As per Instruction Set Architecture (ISA), the values
14 * 0x5, 0x9, 0xD, 0x19, 0x1D, 0x1A, 0x1E are reserved
15 * for sampling mode field. Test that having these reserved
16 * bit values should cause event_open to fail.
17 * Input event code uses these sampling bits along with
18 * 401e0 (PM_MRK_INST_CMPL).
19 */
20
21static int reserved_bits_mmcra_sample_elig_mode(void)
22{
23 struct event event;
24
25 /* Check for platform support for the test */
26 SKIP_IF(platform_check_for_tests());
27
28 /* Skip for Generic compat PMU */
29 SKIP_IF(check_for_generic_compat_pmu());
30
31 /*
32 * MMCRA Random Sampling Mode (SM) values: 0x5
33 * 0x9, 0xD, 0x19, 0x1D, 0x1A, 0x1E is reserved.
34 * Expected to fail when using these reserved values.
35 */
36 event_init(e: &event, config: 0x50401e0);
37 FAIL_IF(!event_open(e: &event));
38
39 event_init(e: &event, config: 0x90401e0);
40 FAIL_IF(!event_open(e: &event));
41
42 event_init(e: &event, config: 0xD0401e0);
43 FAIL_IF(!event_open(e: &event));
44
45 event_init(e: &event, config: 0x190401e0);
46 FAIL_IF(!event_open(e: &event));
47
48 event_init(e: &event, config: 0x1D0401e0);
49 FAIL_IF(!event_open(e: &event));
50
51 event_init(e: &event, config: 0x1A0401e0);
52 FAIL_IF(!event_open(e: &event));
53
54 event_init(e: &event, config: 0x1E0401e0);
55 FAIL_IF(!event_open(e: &event));
56
57 /*
58 * MMCRA Random Sampling Mode (SM) value 0x10
59 * is reserved in power10 and 0xC is reserved in
60 * power9.
61 */
62 if (PVR_VER(mfspr(SPRN_PVR)) == POWER10) {
63 event_init(e: &event, config: 0x100401e0);
64 FAIL_IF(!event_open(e: &event));
65 } else if (PVR_VER(mfspr(SPRN_PVR)) == POWER9) {
66 event_init(e: &event, config: 0xC0401e0);
67 FAIL_IF(!event_open(e: &event));
68 }
69
70 return 0;
71}
72
73int main(void)
74{
75 return test_harness(reserved_bits_mmcra_sample_elig_mode,
76 "reserved_bits_mmcra_sample_elig_mode");
77}
78

source code of linux/tools/testing/selftests/powerpc/pmu/event_code_tests/reserved_bits_mmcra_sample_elig_mode_test.c