Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * Copyright 2021, Athira Rajeev, IBM Corp.
0004  */
0005 
0006 #include <stdio.h>
0007 #include <stdlib.h>
0008 #include <setjmp.h>
0009 #include <signal.h>
0010 
0011 #include "ebb.h"
0012 
0013 
0014 /*
0015  * Test that closing the EBB event clears MMCR0_PMCC and
0016  * sets MMCR0_PMCCEXT preventing further read access to the
0017  * group B PMU registers.
0018  */
0019 
0020 static int regs_access_pmccext(void)
0021 {
0022     struct event event;
0023 
0024     SKIP_IF(!ebb_is_supported());
0025 
0026     event_init_named(&event, 0x1001e, "cycles");
0027     event_leader_ebb_init(&event);
0028 
0029     FAIL_IF(event_open(&event));
0030 
0031     ebb_enable_pmc_counting(1);
0032     setup_ebb_handler(standard_ebb_callee);
0033     ebb_global_enable();
0034     FAIL_IF(ebb_event_enable(&event));
0035 
0036     mtspr(SPRN_PMC1, pmc_sample_period(sample_period));
0037 
0038     while (ebb_state.stats.ebb_count < 1)
0039         FAIL_IF(core_busy_loop());
0040 
0041     ebb_global_disable();
0042     event_close(&event);
0043 
0044     FAIL_IF(ebb_state.stats.ebb_count == 0);
0045 
0046     /*
0047      * For ISA v3.1, verify the test takes a SIGILL when reading
0048      * PMU regs after the event is closed. With the control bit
0049      * in MMCR0 (PMCCEXT) restricting access to group B PMU regs,
0050      * sigill is expected.
0051      */
0052     if (have_hwcap2(PPC_FEATURE2_ARCH_3_1))
0053         FAIL_IF(catch_sigill(dump_ebb_state));
0054     else
0055         dump_ebb_state();
0056 
0057     return 0;
0058 }
0059 
0060 int main(void)
0061 {
0062     return test_harness(regs_access_pmccext, "regs_access_pmccext");
0063 }