David Wang | bcb8b14 | 2022-02-17 17:31:40 +0800 | [diff] [blame] | 1 | /* |
| 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 |
| 16 | extern "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. */ |
| 76 | bool prof_init(void); |
| 77 | |
| 78 | /* Optional. It's for caculating the cost of profiler */ |
| 79 | void prof_calibrate(uint32_t index, uint32_t rounds, uint32_t cali_data); |
| 80 | void prof_ns_set_cali_value(uint32_t cali); |
| 81 | uint32_t prof_get_cali_value(uint32_t index); |
| 82 | |
| 83 | /* Log timing of a checkpoint. */ |
| 84 | uint32_t prof_timing_cp(uint32_t tag); |
| 85 | |
| 86 | /* Dump data */ |
| 87 | bool prof_get_data_start(uint32_t *tag, uint32_t *data, uint32_t tag_pattern, |
| 88 | uint32_t tag_mask); |
| 89 | bool prof_get_data_continue(uint32_t *tag, uint32_t *data, uint32_t tag_pattern, |
| 90 | uint32_t tag_mask); |
Summer Qin | 07e8f21 | 2023-07-05 17:05:07 +0800 | [diff] [blame] | 91 | /* Data analysis */ |
| 92 | uint32_t prof_data_diff(uint32_t tag_pattern_a, uint32_t tag_pattern_b); |
| 93 | uint32_t prof_data_diff_min(uint32_t tag_pattern_a, uint32_t tag_pattern_b); |
| 94 | uint32_t prof_data_diff_max(uint32_t tag_pattern_a, uint32_t tag_pattern_b); |
| 95 | uint32_t prof_data_diff_avg(uint32_t tag_pattern_a, uint32_t tag_pattern_b); |
David Wang | bcb8b14 | 2022-02-17 17:31:40 +0800 | [diff] [blame] | 96 | |
| 97 | /* Non-secure side veneer */ |
| 98 | uint32_t prof_timing_cp_veneer(uint32_t tag); |
| 99 | uint32_t prof_get_cali_value_veneer(uint32_t index); |
| 100 | bool prof_get_data_start_veneer(uint32_t *tag, uint32_t *data, |
| 101 | uint32_t tag_pattern, uint32_t tag_mask); |
| 102 | bool prof_get_data_continue_veneer(uint32_t *tag, uint32_t *data, |
| 103 | uint32_t tag_pattern, uint32_t tag_mask); |
Summer Qin | 07e8f21 | 2023-07-05 17:05:07 +0800 | [diff] [blame] | 104 | uint32_t prof_data_diff_veneer(uint32_t tag_pattern_a, uint32_t tag_pattern_b); |
| 105 | uint32_t prof_data_diff_min_veneer(uint32_t tag_pattern_a, uint32_t tag_pattern_b); |
| 106 | uint32_t prof_data_diff_max_veneer(uint32_t tag_pattern_a, uint32_t tag_pattern_b); |
| 107 | uint32_t prof_data_diff_avg_veneer(uint32_t tag_pattern_a, uint32_t tag_pattern_b); |
David Wang | bcb8b14 | 2022-02-17 17:31:40 +0800 | [diff] [blame] | 108 | |
| 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__ */ |