summaryrefslogtreecommitdiff
path: root/gxp-bpm.c
blob: 90cf0e97e246a72a2a911d3dbaf66897572b9ec5 (plain)
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
// SPDX-License-Identifier: GPL-2.0
/*
 * GXP bus performance monitor interface.
 *
 * Copyright (C) 2021 Google LLC
 */

#include "gxp-bpm.h"
#include "gxp-config.h"

#define BPM_EVENT_TYPE_BIT	2
#define BPM_EVENT_TYPE_MASK	0x1F

#define BPM_START_BIT	10
#define BPM_STOP_BIT	11

#define BPM_CONFIG_OFFSET		0x00
#define BPM_CNTR_CONFIG_OFFSET		0x18
#define BPM_SNAPSHOT_CNTR_OFFSET	0x98

#define BPM_DISABLE	0x0
#define BPM_ENABLE	0x1

void gxp_bpm_configure(struct gxp_dev *gxp, u8 core, u32 bpm_offset, u32 event)
{
	u32 val = ((event & BPM_EVENT_TYPE_MASK) << BPM_EVENT_TYPE_BIT) |
		  BPM_ENABLE;
	u32 bpm_base = GXP_CORE_REG_INST_BPM(core) + bpm_offset;

	/* Configure event */
	gxp_write_32(gxp, bpm_base + BPM_CNTR_CONFIG_OFFSET, val);
	/* Arm counter */
	gxp_write_32(gxp, bpm_base + BPM_CONFIG_OFFSET, BPM_ENABLE);
}

void gxp_bpm_start(struct gxp_dev *gxp, u8 core)
{
	gxp_write_32(gxp, GXP_CORE_REG_PROFILING_CONDITION(core),
		     BPM_ENABLE << BPM_START_BIT);
}

void gxp_bpm_stop(struct gxp_dev *gxp, u8 core)
{
	gxp_write_32(gxp, GXP_CORE_REG_PROFILING_CONDITION(core),
		     BPM_ENABLE << BPM_STOP_BIT);
}

u32 gxp_bpm_read_counter(struct gxp_dev *gxp, u8 core, u32 bpm_offset)
{
	u32 bpm_base = GXP_CORE_REG_INST_BPM(core) + bpm_offset;

	/* Disarm counter */
	gxp_write_32(gxp, bpm_base + BPM_CONFIG_OFFSET, BPM_DISABLE);
	/* Read final counter value */
	return gxp_read_32(gxp, bpm_base + BPM_SNAPSHOT_CNTR_OFFSET);
}