-
Notifications
You must be signed in to change notification settings - Fork 4
/
armpmu_lib.c
78 lines (71 loc) · 1.4 KB
/
armpmu_lib.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include "armpmu_lib.h"
void enable_pmn()
{
uint32_t cr;
// Read the control register.
MRC_PMU(cr, PMCR);
// Set the "Enable" bit 0.
cr |= 1;
// Write the control register back.
MCR_PMU(cr, PMCR);
}
void disable_pmn()
{
uint32_t cr;
// Read the control register.
MRC_PMU(cr, PMCR);
// Unset the "Enable" bit 0.
cr &= ~1;
// Write the control register back.
MCR_PMU(cr, PMCR);
}
void set_pmn(uint32_t counter, uint32_t event)
{
// Only four bits are valid, rest is reserved.
counter &= 0xf;
// Select the given counter.
MCR_PMU(counter, PMSELR);
// Set the event.
MCR_PMU(event, PMXEVTYPER);
}
uint32_t read_pmn(uint32_t counter)
{
uint32_t result;
// Only four bits are valid, rest is reserved.
counter &= 0xf;
// Select the given counter.
MCR_PMU(counter, PMSELR);
// Read the register.
MRC_PMU(result, PMXEVCNTR);
return result;
}
void reset_pmn()
{
uint32_t cr;
// Read the control register.
MRC_PMU(cr, PMCR);
// Set the "Event counter reset" bit 1.
cr |= (1 << 1);
// Write the control register back.
MCR_PMU(cr, PMCR);
}
void reset_ccnt()
{
uint32_t cr;
// Read the control register.
MRC_PMU(cr, PMCR);
// Set the "Cycle counter reset" bit 2.
cr |= (1 << 2);
// Write the control register back.
MCR_PMU(cr, PMCR);
}
const char * pmn_event_name(int event)
{
switch (event) {
#define X(NAME, VALUE) case VALUE: return #NAME;
ARMPMU_EVENT_LIST
#undef X
default:
return 0;
}
}