gr55xx_fpb.h
Go to the documentation of this file.
1 /**
2 ******************************************************************************
3 *
4 * @file gr55xx_fpb.h
5 *
6 ******************************************************************************
7 * @attention
8 #####Copyright (c) 2019 GOODIX
9 All rights reserved.
10
11 Redistribution and use in source and binary forms, with or without
12 modification, are permitted provided that the following conditions are met:
13 * Redistributions of source code must retain the above copyright
14 notice, this list of conditions and the following disclaimer.
15 * Redistributions in binary form must reproduce the above copyright
16 notice, this list of conditions and the following disclaimer in the
17 documentation and/or other materials provided with the distribution.
18 * Neither the name of GOODIX nor the names of its contributors may be used
19 to endorse or promote products derived from this software without
20 specific prior written permission.
21
22 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
26 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 POSSIBILITY OF SUCH DAMAGE.
33 *****************************************************************************************
34 */
35
36 /**
37 * @addtogroup SYSTEM
38 * @{
39 */
40
41 /**
42 * @addtogroup FPB
43 * @{
44 * @brief Definitions and prototypes for FPB interface.
45 */
46
47 #ifndef __GR55XX_FPB_H_
48 #define __GR55XX_FPB_H_
49
50 #include <stdint.h>
51 #include <stdio.h>
52 #include <stdbool.h>
53
54 /**
55 *@addtogroup GR55XX_FPB_ENUMERATIONS Enumerations
56 * @{
57 */
58 /**@brief FPB mode. */
59 typedef enum
60 {
61 FPB_MODE_PATCH_ONLY = 0, /**< FPB MODE ENABLE FOR PATCH ONLY*/
62 FPB_MODE_DEBUG_ONLY, /**< FPB MODE ENABLE FOR DEBUG ONLY*/
63 FPB_MODE_PATCH_AND_DEBUG, /**< FPB MODE ENABLE FOR PATCH AND DEBUG*/
64 } fpb_mode_t ;
65
66 /**@brief FPB state. */
67 typedef enum
68 {
69 FPB_PATCH_OFF = 0, /**< FPB patch disable */
70 FPB_PATCH_ON, /**< FPB patch enable */
71 } fpb_state_t;
72
73 /**@brief FPB register. */
74 typedef struct
75 {
76 volatile uint32_t CTRL; /**< Offset: 0x000 (R/W) Data */
77 volatile uint32_t REMAP; /**< Offset: 0x004 (R/W) Data */
78 volatile uint32_t COMP[8]; /**< Offset: 0x008 (R) Data */
79 } FPB_REG_TypeDef;
80 /** @} */
81
82 /** @addtogroup GR55XX_FPB_DEFINES Defines
83 * @{
84 */
85 #define FPB ((FPB_REG_TypeDef *) 0xE0002000UL) /**< FPB Register Address. */
86 /** @} */
87
88
89 /**
90 * @defgroup GR55XX_FPB_TYPEDEF Typedefs
91 * @{
92 */
93 /**@brief FPB function.*/
94 typedef void(*fun_t)(void);
95 /** @} */
96
97 /**
98 * @defgroup GR55XX_FPB_FUNCTION Functions
99 * @{
100 */
101 /**
102 ****************************************************************************************
103 * @brief Enabling patch function
104 * @param[in] index_start : Start Index Number
105 * @param[in] index_end : End Index Number
106 ****************************************************************************************
107 */
108 void fpb_enable(uint8_t index_start ,uint8_t index_end);
109
110 /**
111 ****************************************************************************************
112 * @brief Replace old and new functions
113 * @param[in] ori_func : primitive function address
114 * @param[in] rep_func : replacement function address
115 * @param[in] patch_table_num : group number
116 * @return -1: Error Otherwise: Patch table number
117 ****************************************************************************************
118 */
119 int fun_replace_by_svc(uint32_t ori_func, uint32_t rep_func, uint8_t patch_table_num);
120
121 /**
122 ****************************************************************************************
123 * @brief SVC handler process function
124 * @return 0: Function not found in SVc table, Otherwise: Function address for hardware patching
125 ****************************************************************************************
126 */
127 uint32_t SVC_handler_proc(uint32_t *svc_args);
128
129 /**
130 ****************************************************************************************
131 * @brief Register FPB patch enable function
132 * @param[in] patch_enable_func : pointer of function
133 ****************************************************************************************
134 */
135 void fpb_register_patch_init_func(fun_t patch_enable_func);
136
137 /**
138 ****************************************************************************************
139 * @brief FPB init function
140 * @param[in] fpb_mode : the mode of FPB
141 ****************************************************************************************
142 */
143 void fpb_init(fpb_mode_t fpb_mode);
144
145 /**
146 ****************************************************************************************
147 * @brief svc sub-function register
148 * @param[in] svc_num : the number of svc
149 * @param[in] func : sub-function callback
150 ****************************************************************************************
151 */
152 void svc_func_register(uint8_t svc_num, uint32_t func);
153
154 /**
155 ****************************************************************************************
156 * @brief register sve table function
157 * @param[in] p_svc_table : the pointer of sve table
158 ****************************************************************************************
159 */
160 void svc_table_register(uint32_t *p_svc_table);
161
162 /**
163 ****************************************************************************************
164 * @brief register fpb space from user layer
165 * @param[in] user_fpb_space : the pointer of fpb user space
166 ****************************************************************************************
167 */
168 void fpb_register_user_space(uint32_t *user_fpb_space);
169
170 /**
171 ****************************************************************************************
172 * @brief save the FPB state
173 *
174 * @returns FPB state ::fpb_state_t
175 ****************************************************************************************
176 */
177 fpb_state_t fpb_save_state(void);
178
179 /**
180 ****************************************************************************************
181 * @brief load the FPB state
182 * @param[in] state : the FPB state that needs to be loaded
183 ****************************************************************************************
184 */
185 void fpb_load_state(fpb_state_t state);
186
187 /** @} */
188 #endif
189 /** @} */
190 /** @} */
191
fun_t
void(* fun_t)(void)
FPB function.
Definition: gr55xx_fpb.h:94
fpb_init
void fpb_init(fpb_mode_t fpb_mode)
FPB init function.
FPB_REG_TypeDef::REMAP
volatile uint32_t REMAP
Definition: gr55xx_fpb.h:77
fun_replace_by_svc
int fun_replace_by_svc(uint32_t ori_func, uint32_t rep_func, uint8_t patch_table_num)
Replace old and new functions.
FPB_PATCH_ON
@ FPB_PATCH_ON
Definition: gr55xx_fpb.h:70
FPB_PATCH_OFF
@ FPB_PATCH_OFF
Definition: gr55xx_fpb.h:69
fpb_load_state
void fpb_load_state(fpb_state_t state)
load the FPB state
FPB_REG_TypeDef::CTRL
volatile uint32_t CTRL
Definition: gr55xx_fpb.h:76
FPB_REG_TypeDef
FPB register.
Definition: gr55xx_fpb.h:75
FPB_MODE_PATCH_ONLY
@ FPB_MODE_PATCH_ONLY
Definition: gr55xx_fpb.h:61
FPB_MODE_DEBUG_ONLY
@ FPB_MODE_DEBUG_ONLY
Definition: gr55xx_fpb.h:62
FPB_MODE_PATCH_AND_DEBUG
@ FPB_MODE_PATCH_AND_DEBUG
Definition: gr55xx_fpb.h:63
svc_table_register
void svc_table_register(uint32_t *p_svc_table)
register sve table function
fpb_enable
void fpb_enable(uint8_t index_start, uint8_t index_end)
Enabling patch function.
fpb_register_user_space
void fpb_register_user_space(uint32_t *user_fpb_space)
register fpb space from user layer
fpb_register_patch_init_func
void fpb_register_patch_init_func(fun_t patch_enable_func)
Register FPB patch enable function.
fpb_state_t
fpb_state_t
FPB state.
Definition: gr55xx_fpb.h:68
fpb_save_state
fpb_state_t fpb_save_state(void)
save the FPB state
svc_func_register
void svc_func_register(uint8_t svc_num, uint32_t func)
svc sub-function register
fpb_mode_t
fpb_mode_t
FPB mode.
Definition: gr55xx_fpb.h:60
SVC_handler_proc
uint32_t SVC_handler_proc(uint32_t *svc_args)
SVC handler process function.