18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright 2014, Michael Ellerman, IBM Corp.
48c2ecf20Sopenharmony_ci */
58c2ecf20Sopenharmony_ci
68c2ecf20Sopenharmony_ci#ifndef _SELFTESTS_POWERPC_PMU_EBB_EBB_H
78c2ecf20Sopenharmony_ci#define _SELFTESTS_POWERPC_PMU_EBB_EBB_H
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci#include "../event.h"
108c2ecf20Sopenharmony_ci#include "../lib.h"
118c2ecf20Sopenharmony_ci#include "trace.h"
128c2ecf20Sopenharmony_ci#include "reg.h"
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci#define PMC_INDEX(pmc)	((pmc)-1)
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_ci#define NUM_PMC_VALUES	128
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_cistruct ebb_state
198c2ecf20Sopenharmony_ci{
208c2ecf20Sopenharmony_ci	struct {
218c2ecf20Sopenharmony_ci		u64 pmc_count[6];
228c2ecf20Sopenharmony_ci		volatile int ebb_count;
238c2ecf20Sopenharmony_ci		int spurious;
248c2ecf20Sopenharmony_ci		int negative;
258c2ecf20Sopenharmony_ci		int no_overflow;
268c2ecf20Sopenharmony_ci	} stats;
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_ci	bool pmc_enable[6];
298c2ecf20Sopenharmony_ci	struct trace_buffer *trace;
308c2ecf20Sopenharmony_ci};
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_ciextern struct ebb_state ebb_state;
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci#define COUNTER_OVERFLOW 0x80000000ull
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_cistatic inline uint32_t pmc_sample_period(uint32_t value)
378c2ecf20Sopenharmony_ci{
388c2ecf20Sopenharmony_ci	return COUNTER_OVERFLOW - value;
398c2ecf20Sopenharmony_ci}
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_cistatic inline void ebb_enable_pmc_counting(int pmc)
428c2ecf20Sopenharmony_ci{
438c2ecf20Sopenharmony_ci	ebb_state.pmc_enable[PMC_INDEX(pmc)] = true;
448c2ecf20Sopenharmony_ci}
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_cibool ebb_check_count(int pmc, u64 sample_period, int fudge);
478c2ecf20Sopenharmony_civoid event_leader_ebb_init(struct event *e);
488c2ecf20Sopenharmony_civoid event_ebb_init(struct event *e);
498c2ecf20Sopenharmony_civoid event_bhrb_init(struct event *e, unsigned ifm);
508c2ecf20Sopenharmony_civoid setup_ebb_handler(void (*callee)(void));
518c2ecf20Sopenharmony_civoid standard_ebb_callee(void);
528c2ecf20Sopenharmony_ciint ebb_event_enable(struct event *e);
538c2ecf20Sopenharmony_civoid ebb_global_enable(void);
548c2ecf20Sopenharmony_civoid ebb_global_disable(void);
558c2ecf20Sopenharmony_cibool ebb_is_supported(void);
568c2ecf20Sopenharmony_civoid ebb_freeze_pmcs(void);
578c2ecf20Sopenharmony_civoid ebb_unfreeze_pmcs(void);
588c2ecf20Sopenharmony_civoid event_ebb_init(struct event *e);
598c2ecf20Sopenharmony_civoid event_leader_ebb_init(struct event *e);
608c2ecf20Sopenharmony_ciint count_pmc(int pmc, uint32_t sample_period);
618c2ecf20Sopenharmony_civoid dump_ebb_state(void);
628c2ecf20Sopenharmony_civoid dump_summary_ebb_state(void);
638c2ecf20Sopenharmony_civoid dump_ebb_hw_state(void);
648c2ecf20Sopenharmony_civoid clear_ebb_stats(void);
658c2ecf20Sopenharmony_civoid write_pmc(int pmc, u64 value);
668c2ecf20Sopenharmony_ciu64 read_pmc(int pmc);
678c2ecf20Sopenharmony_civoid reset_ebb_with_clear_mask(unsigned long mmcr0_clear_mask);
688c2ecf20Sopenharmony_civoid reset_ebb(void);
698c2ecf20Sopenharmony_ciint ebb_check_mmcr0(void);
708c2ecf20Sopenharmony_ci
718c2ecf20Sopenharmony_ciextern u64 sample_period;
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_ciint core_busy_loop(void);
748c2ecf20Sopenharmony_ciint ebb_child(union pipe read_pipe, union pipe write_pipe);
758c2ecf20Sopenharmony_ciint catch_sigill(void (*func)(void));
768c2ecf20Sopenharmony_civoid write_pmc1(void);
778c2ecf20Sopenharmony_ci
788c2ecf20Sopenharmony_ci#endif /* _SELFTESTS_POWERPC_PMU_EBB_EBB_H */
79