1 // SPDX-License-Identifier: GPL-2.0-only 2 /* 3 * Copyright 2021, Athira Rajeev, IBM Corp. 4 */ 5 6 #include <stdio.h> 7 #include <stdlib.h> 8 #include <setjmp.h> 9 #include <signal.h> 10 11 #include "ebb.h" 12 13 14 /* 15 * Test that closing the EBB event clears MMCR0_PMCC and 16 * sets MMCR0_PMCCEXT preventing further read access to the 17 * group B PMU registers. 18 */ 19 regs_access_pmccext(void)20static int regs_access_pmccext(void) 21 { 22 struct event event; 23 24 SKIP_IF(!ebb_is_supported()); 25 26 event_init_named(&event, 0x1001e, "cycles"); 27 event_leader_ebb_init(&event); 28 29 FAIL_IF(event_open(&event)); 30 31 ebb_enable_pmc_counting(1); 32 setup_ebb_handler(standard_ebb_callee); 33 ebb_global_enable(); 34 FAIL_IF(ebb_event_enable(&event)); 35 36 mtspr(SPRN_PMC1, pmc_sample_period(sample_period)); 37 38 while (ebb_state.stats.ebb_count < 1) 39 FAIL_IF(core_busy_loop()); 40 41 ebb_global_disable(); 42 event_close(&event); 43 44 FAIL_IF(ebb_state.stats.ebb_count == 0); 45 46 /* 47 * For ISA v3.1, verify the test takes a SIGILL when reading 48 * PMU regs after the event is closed. With the control bit 49 * in MMCR0 (PMCCEXT) restricting access to group B PMU regs, 50 * sigill is expected. 51 */ 52 if (have_hwcap2(PPC_FEATURE2_ARCH_3_1)) 53 FAIL_IF(catch_sigill(dump_ebb_state)); 54 else 55 dump_ebb_state(); 56 57 return 0; 58 } 59 main(void)60int main(void) 61 { 62 return test_harness(regs_access_pmccext, "regs_access_pmccext"); 63 } 64