blob: b699ad061d7846213ed53207f0c35572c78b30d5 [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);
Summer Qin07e8f212023-07-05 17:05:07 +080091/* Data analysis */
92uint32_t prof_data_diff(uint32_t tag_pattern_a, uint32_t tag_pattern_b);
93uint32_t prof_data_diff_min(uint32_t tag_pattern_a, uint32_t tag_pattern_b);
94uint32_t prof_data_diff_max(uint32_t tag_pattern_a, uint32_t tag_pattern_b);
95uint32_t prof_data_diff_avg(uint32_t tag_pattern_a, uint32_t tag_pattern_b);
David Wangbcb8b142022-02-17 17:31:40 +080096
97/* Non-secure side veneer */
98uint32_t prof_timing_cp_veneer(uint32_t tag);
99uint32_t prof_get_cali_value_veneer(uint32_t index);
100bool prof_get_data_start_veneer(uint32_t *tag, uint32_t *data,
101 uint32_t tag_pattern, uint32_t tag_mask);
102bool prof_get_data_continue_veneer(uint32_t *tag, uint32_t *data,
103 uint32_t tag_pattern, uint32_t tag_mask);
Summer Qin07e8f212023-07-05 17:05:07 +0800104uint32_t prof_data_diff_veneer(uint32_t tag_pattern_a, uint32_t tag_pattern_b);
105uint32_t prof_data_diff_min_veneer(uint32_t tag_pattern_a, uint32_t tag_pattern_b);
106uint32_t prof_data_diff_max_veneer(uint32_t tag_pattern_a, uint32_t tag_pattern_b);
107uint32_t prof_data_diff_avg_veneer(uint32_t tag_pattern_a, uint32_t tag_pattern_b);
David Wangbcb8b142022-02-17 17:31:40 +0800108
109#if !defined(__ARMCC_VERSION) && !defined(__ICCARM__)
110/*
111 * GNUARM requires noclone attribute to protect gateway function symbol from
112 * being renamed and cloned
113 */
114#define __profiler_secure_gateway_attributes__ \
115 __attribute__((cmse_nonsecure_entry, noclone))
116#else
117#define __profiler_secure_gateway_attributes__ \
118 __attribute__((cmse_nonsecure_entry))
119#endif /* !__ARMCC_VERSION */
120
121#ifdef __cplusplus
122}
123#endif
124
125#endif /* __PROF_COMMON_H__ */