RTEMS 6.1-rc1
l4stat.h
1/* SPDX-License-Identifier: BSD-2-Clause */
2
3/*
4 * L4STAT APB-Register Driver.
5 *
6 * COPYRIGHT (c) 2017.
7 * Cobham Gaisler AB.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
29 */
30
31#ifndef __L4STAT_H__
32#define __L4STAT_H__
33
34#ifdef __cplusplus
35extern "C" {
36#endif
37
38#define L4STAT_ERR_OK 0
39#define L4STAT_ERR_EINVAL -1
40#define L4STAT_ERR_ERROR -2
41#define L4STAT_ERR_TOOMANY -3
42#define L4STAT_ERR_IMPLEMENTED -4
43
44/* Register L4STAT driver to Driver Manager */
45void l4stat_register_drv (void);
46
47extern int l4stat_counter_print(unsigned int counter);
48
49/*
50 * L4STAT CCTRL register fields
51 */
52#define CCTRL_NCPU (0xf << CCTRL_NCPU_BIT)
53#define CCTRL_NCNT_L3STAT (0x1ff << CCTRL_NCNT_BIT)
54#define CCTRL_NCNT (0x1f << CCTRL_NCNT_BIT)
55#define CCTRL_MC (0x1 << CCTRL_MC_BIT)
56#define CCTRL_IA (0x1 << CCTRL_IA_BIT)
57#define CCTRL_DS (0x1 << CCTRL_DS_BIT)
58#define CCTRL_EE (0x1 << CCTRL_EE_BIT)
59#define CCTRL_AE (0x1 << CCTRL_AE_BIT)
60#define CCTRL_EL (0x1 << CCTRL_EL_BIT)
61#define CCTRL_CD (0x1 << CCTRL_CD_BIT)
62#define CCTRL_SU (0x3 << CCTRL_SU_BIT)
63#define CCTRL_CL (0x1 << CCTRL_CL_BIT)
64#define CCTRL_EN (0x1 << CCTRL_EN_BIT)
65#define CCTRL_EVENTID (0xff << CCTRL_EVENTID_BIT)
66#define CCTRL_CPUAHBM (0xf << CCTRL_CPUAHBM_BIT)
67
68#define CCTRL_NCPU_BIT 28
69#define CCTRL_NCNT_BIT 23
70#define CCTRL_MC_BIT 22
71#define CCTRL_IA_BIT 21
72#define CCTRL_DS_BIT 20
73#define CCTRL_EE_BIT 19
74#define CCTRL_AE_BIT 18
75#define CCTRL_EL_BIT 17
76#define CCTRL_CD_BIT 16
77#define CCTRL_SU_BIT 14
78#define CCTRL_CL_BIT 13
79#define CCTRL_EN_BIT 12
80#define CCTRL_EVENTID_BIT 4
81#define CCTRL_CPUAHBM_BIT 0
82
83#define L4STAT_OPTIONS_EVENT_LEVEL_ENABLE CCTRL_EL
84#define L4STAT_OPTIONS_EVENT_LEVEL_DISABLE 0
85#define L4STAT_OPTIONS_MAXIMUM_DURATION CCTRL_CD
86#define L4STAT_OPTIONS_SUPERVISOR_MODE_FILTER (0x1 << CCTRL_SU_BIT)
87#define L4STAT_OPTIONS_USER_MODE_FILTER (0x2 << CCTRL_SU_BIT)
88#define L4STAT_OPTIONS_NO_FILTER 0
89#define L4STAT_OPTIONS_CLEAR_ON_READ CCTRL_CL
90
91extern int l4stat_counter_enable(unsigned int counter, int event, int cpu, int options);
92extern int l4stat_counter_disable(unsigned int counter);
93extern int l4stat_counter_set(unsigned int counter, uint32_t val);
94extern int l4stat_counter_get(unsigned int counter, uint32_t *val);
95
96static inline int l4stat_counter_clear(unsigned int counter)
97{
98 return l4stat_counter_set(counter, 0);
99}
100
101extern int l4stat_counter_max_set(unsigned int counter, uint32_t val);
102extern int l4stat_counter_max_get(unsigned int counter, uint32_t *val);
103extern int l4stat_tstamp_set(uint32_t val);
104extern int l4stat_tstamp_get(uint32_t *val);
105
106#ifdef __cplusplus
107}
108#endif
109
110#endif