1/*
2 * Copyright 2014, Michael Ellerman, IBM Corp.
3 * Licensed under GPLv2.
4 */
5
6#ifndef _SELFTESTS_POWERPC_PMU_EBB_EBB_H
7#define _SELFTESTS_POWERPC_PMU_EBB_EBB_H
8
9#include "../event.h"
10#include "../lib.h"
11#include "trace.h"
12#include "reg.h"
13
14#define PMC_INDEX(pmc)	((pmc)-1)
15
16#define NUM_PMC_VALUES	128
17
18struct ebb_state
19{
20	struct {
21		u64 pmc_count[6];
22		volatile int ebb_count;
23		int spurious;
24		int negative;
25		int no_overflow;
26	} stats;
27
28	bool pmc_enable[6];
29	struct trace_buffer *trace;
30};
31
32extern struct ebb_state ebb_state;
33
34#define COUNTER_OVERFLOW 0x80000000ull
35
36static inline uint32_t pmc_sample_period(uint32_t value)
37{
38	return COUNTER_OVERFLOW - value;
39}
40
41static inline void ebb_enable_pmc_counting(int pmc)
42{
43	ebb_state.pmc_enable[PMC_INDEX(pmc)] = true;
44}
45
46bool ebb_check_count(int pmc, u64 sample_period, int fudge);
47void event_leader_ebb_init(struct event *e);
48void event_ebb_init(struct event *e);
49void event_bhrb_init(struct event *e, unsigned ifm);
50void setup_ebb_handler(void (*callee)(void));
51void standard_ebb_callee(void);
52int ebb_event_enable(struct event *e);
53void ebb_global_enable(void);
54void ebb_global_disable(void);
55void ebb_freeze_pmcs(void);
56void ebb_unfreeze_pmcs(void);
57void event_ebb_init(struct event *e);
58void event_leader_ebb_init(struct event *e);
59int count_pmc(int pmc, uint32_t sample_period);
60void dump_ebb_state(void);
61void dump_summary_ebb_state(void);
62void dump_ebb_hw_state(void);
63void clear_ebb_stats(void);
64void write_pmc(int pmc, u64 value);
65u64 read_pmc(int pmc);
66void reset_ebb_with_clear_mask(unsigned long mmcr0_clear_mask);
67void reset_ebb(void);
68int ebb_check_mmcr0(void);
69
70extern u64 sample_period;
71
72int core_busy_loop(void);
73int ebb_child(union pipe read_pipe, union pipe write_pipe);
74int catch_sigill(void (*func)(void));
75void write_pmc1(void);
76
77#endif /* _SELFTESTS_POWERPC_PMU_EBB_EBB_H */
78