162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */ 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * Copyright 2014, Michael Ellerman, IBM Corp. 462306a36Sopenharmony_ci */ 562306a36Sopenharmony_ci 662306a36Sopenharmony_ci#ifndef _SELFTESTS_POWERPC_PMU_EBB_EBB_H 762306a36Sopenharmony_ci#define _SELFTESTS_POWERPC_PMU_EBB_EBB_H 862306a36Sopenharmony_ci 962306a36Sopenharmony_ci#include "../event.h" 1062306a36Sopenharmony_ci#include "../lib.h" 1162306a36Sopenharmony_ci#include "trace.h" 1262306a36Sopenharmony_ci#include "reg.h" 1362306a36Sopenharmony_ci 1462306a36Sopenharmony_ci#define PMC_INDEX(pmc) ((pmc)-1) 1562306a36Sopenharmony_ci 1662306a36Sopenharmony_ci#define NUM_PMC_VALUES 128 1762306a36Sopenharmony_ci 1862306a36Sopenharmony_cistruct ebb_state 1962306a36Sopenharmony_ci{ 2062306a36Sopenharmony_ci struct { 2162306a36Sopenharmony_ci u64 pmc_count[6]; 2262306a36Sopenharmony_ci volatile int ebb_count; 2362306a36Sopenharmony_ci int spurious; 2462306a36Sopenharmony_ci int negative; 2562306a36Sopenharmony_ci int no_overflow; 2662306a36Sopenharmony_ci } stats; 2762306a36Sopenharmony_ci 2862306a36Sopenharmony_ci bool pmc_enable[6]; 2962306a36Sopenharmony_ci struct trace_buffer *trace; 3062306a36Sopenharmony_ci}; 3162306a36Sopenharmony_ci 3262306a36Sopenharmony_ciextern struct ebb_state ebb_state; 3362306a36Sopenharmony_ci 3462306a36Sopenharmony_ci#define COUNTER_OVERFLOW 0x80000000ull 3562306a36Sopenharmony_ci 3662306a36Sopenharmony_cistatic inline uint32_t pmc_sample_period(uint32_t value) 3762306a36Sopenharmony_ci{ 3862306a36Sopenharmony_ci return COUNTER_OVERFLOW - value; 3962306a36Sopenharmony_ci} 4062306a36Sopenharmony_ci 4162306a36Sopenharmony_cistatic inline void ebb_enable_pmc_counting(int pmc) 4262306a36Sopenharmony_ci{ 4362306a36Sopenharmony_ci ebb_state.pmc_enable[PMC_INDEX(pmc)] = true; 4462306a36Sopenharmony_ci} 4562306a36Sopenharmony_ci 4662306a36Sopenharmony_cibool ebb_check_count(int pmc, u64 sample_period, int fudge); 4762306a36Sopenharmony_civoid event_leader_ebb_init(struct event *e); 4862306a36Sopenharmony_civoid event_ebb_init(struct event *e); 4962306a36Sopenharmony_civoid event_bhrb_init(struct event *e, unsigned ifm); 5062306a36Sopenharmony_civoid setup_ebb_handler(void (*callee)(void)); 5162306a36Sopenharmony_civoid standard_ebb_callee(void); 5262306a36Sopenharmony_ciint ebb_event_enable(struct event *e); 5362306a36Sopenharmony_civoid ebb_global_enable(void); 5462306a36Sopenharmony_civoid ebb_global_disable(void); 5562306a36Sopenharmony_cibool ebb_is_supported(void); 5662306a36Sopenharmony_civoid ebb_freeze_pmcs(void); 5762306a36Sopenharmony_civoid ebb_unfreeze_pmcs(void); 5862306a36Sopenharmony_ciint count_pmc(int pmc, uint32_t sample_period); 5962306a36Sopenharmony_civoid dump_ebb_state(void); 6062306a36Sopenharmony_civoid dump_summary_ebb_state(void); 6162306a36Sopenharmony_civoid dump_ebb_hw_state(void); 6262306a36Sopenharmony_civoid clear_ebb_stats(void); 6362306a36Sopenharmony_civoid write_pmc(int pmc, u64 value); 6462306a36Sopenharmony_ciu64 read_pmc(int pmc); 6562306a36Sopenharmony_civoid reset_ebb_with_clear_mask(unsigned long mmcr0_clear_mask); 6662306a36Sopenharmony_civoid reset_ebb(void); 6762306a36Sopenharmony_ciint ebb_check_mmcr0(void); 6862306a36Sopenharmony_ci 6962306a36Sopenharmony_ciextern u64 sample_period; 7062306a36Sopenharmony_ci 7162306a36Sopenharmony_ciint core_busy_loop(void); 7262306a36Sopenharmony_ciint ebb_child(union pipe read_pipe, union pipe write_pipe); 7362306a36Sopenharmony_ciint catch_sigill(void (*func)(void)); 7462306a36Sopenharmony_civoid write_pmc1(void); 7562306a36Sopenharmony_ci 7662306a36Sopenharmony_ci#endif /* _SELFTESTS_POWERPC_PMU_EBB_EBB_H */ 77