blob: 3e185d88f0fe933b5267c9021536ccdc5dde1815 [file] [log] [blame]
David Wangbcb8b142022-02-17 17:31:40 +08001/*
2 * Copyright (c) 2021-2022, Arm Limited. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 */
7
8#ifndef __PROF_COMMON_H__
9#define __PROF_COMMON_H__
10
11#include <stdint.h>
12#include <stddef.h>
13#include <stdbool.h>
14
15#ifdef __cplusplus
16extern "C" {
17#endif
18
19/* Supported maximum items in database */
20#ifndef PROF_DB_MAX
21#define PROF_DB_MAX 2048
22#endif
23
24/*
25 * The database is consisted of "items".
26 * Each item has 32-bit "tag" followed by 32-bit data.
27 *
28 * The tag is the metadata of the value in the item. The lower 4-bit of the tag
29 * identifies the "type" of the item.
30 * -------------------------
31 * |Type defined field|Type|
32 * -------------------------
33 * 28-bit 4-bit
34 * Currently, only "timing" types are supported.
35 *
36 * Generic tag format of the timing types
37 * ------------------------------------------
38 * |Checkpoint ID|Topic ID| Cali |Res. |Type|
39 * ------------------------------------------
40 * 16-bit 8-bit 2-bit 2-bit 4-bit
41 * Checkpiont ID: Identifies the point logged the timing
42 * Topic ID: Topic is used to group a set of checkpoints.
43 * Cali: Specifies the calibration value index used for this item. The
44 * calibration value was measured by calling calibration functions.
45 * Res.: Reserved
46 */
47
48/* Define the type of the performance data tag */
49#define PROF_TYPE_TIMING_CALI (0x0)
50#define PROF_TYPE_TIMING_LOG (0x1)
51
52/* Calibration data index */
53#define PROF_CALI_IDX_S (0x0)
54#define PROF_CALI_IDX_NS (0x3)
55#define PROF_MAX_CALI_SETS (4)
56
57/* Masks */
58#define PROF_MASK_CP (0xffff0000)
59#define PROF_MASK_TOPIC (0x0000ff00)
60#define PROF_MASK_TOPIC_CP (PROF_MASK_CP | PROF_MASK_TOPIC)
61#define PROF_MASK_FULL_TAG (0xffffffff)
62#define PROF_MASK_NONE (0)
63
64#define PROF_MAKE_TIMING_TAG(cp_id, topic_id, cali, type) \
65 ((((cp_id) & 0xffff) << 16) \
66 | (((topic_id) & 0xff) << 8) \
67 | (((cali) & 0x3) << 6) \
68 | ((type) & 0xf))
69
70#define PROF_GET_TYPE_FROM_TAG(tag) ((tag) & 0xf)
71#define PROF_GET_CALI_IDX_FROM_TAG(tag) (((tag) >> 6) & 0x3)
72#define PROF_GET_TOPIC_ID_FROM_TAG(tag) (((tag) >> 8) & 0xff)
73#define PROF_GET_CP_ID_FROM_TAG(tag) (((tag) >> 16) & 0xffff)
74
75/* Initialize the hardware, database, etc. */
76bool prof_init(void);
77
78/* Optional. It's for caculating the cost of profiler */
79void prof_calibrate(uint32_t index, uint32_t rounds, uint32_t cali_data);
80void prof_ns_set_cali_value(uint32_t cali);
81uint32_t prof_get_cali_value(uint32_t index);
82
83/* Log timing of a checkpoint. */
84uint32_t prof_timing_cp(uint32_t tag);
85
86/* Dump data */
87bool prof_get_data_start(uint32_t *tag, uint32_t *data, uint32_t tag_pattern,
88 uint32_t tag_mask);
89bool prof_get_data_continue(uint32_t *tag, uint32_t *data, uint32_t tag_pattern,
90 uint32_t tag_mask);
91
92/* Non-secure side veneer */
93uint32_t prof_timing_cp_veneer(uint32_t tag);
94uint32_t prof_get_cali_value_veneer(uint32_t index);
95bool prof_get_data_start_veneer(uint32_t *tag, uint32_t *data,
96 uint32_t tag_pattern, uint32_t tag_mask);
97bool prof_get_data_continue_veneer(uint32_t *tag, uint32_t *data,
98 uint32_t tag_pattern, uint32_t tag_mask);
99
100#if !defined(__ARMCC_VERSION) && !defined(__ICCARM__)
101/*
102 * GNUARM requires noclone attribute to protect gateway function symbol from
103 * being renamed and cloned
104 */
105#define __profiler_secure_gateway_attributes__ \
106 __attribute__((cmse_nonsecure_entry, noclone))
107#else
108#define __profiler_secure_gateway_attributes__ \
109 __attribute__((cmse_nonsecure_entry))
110#endif /* !__ARMCC_VERSION */
111
112#ifdef __cplusplus
113}
114#endif
115
116#endif /* __PROF_COMMON_H__ */