SYS/BIOS  7.00
SecureCB.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019 Texas Instruments Incorporated - https://www.ti.com
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 /*
34  * ======== SecureCB.h ========
35  */
36 
37 #ifndef ti_spe_SecureCB__include
38 #define ti_spe_SecureCB__include
39 
40 #include <stddef.h>
41 #include <stdint.h>
42 
43 #if defined(__GNUC__)
44 #ifndef __STATIC_INLINE
45 #define __STATIC_INLINE static inline
46 #endif
47 #elif defined(__clang__) && defined(__ti__)
48 #define __STATIC_INLINE static __inline
49 #endif
50 
51 #if defined (__cplusplus)
52 extern "C" {
53 #endif
54 
55 #define NVIC_ISPR_ADDRESS 0xe000e200
56 
57 /* There is no dedicated interrupt for the SecureCB module.
58  * Using arbitrary interrupt which is not in use (hopefully).
59  */
60 #define SecureCB_INT_NUM 43
61 
62 #define SecureCB_STATUS_OK 0
63 #define SecureCB_STATUS_ERROR 1
64 
65 #define SecureCB_CRSTAT_DEFINED 1
66 #define SecureCB_CRSTAT_ENABLED 2
67 
68 typedef uintptr_t SecureCB_Arg;
69 typedef void (*SecureCB_FuncPtr)(SecureCB_Arg arg);
70 
71 typedef struct SecureCB_Object {
72  struct SecureCB_Object *volatile next;
73  struct SecureCB_Object *volatile prev;
74  uint16_t intNum;
75  uint16_t crstat;
77  SecureCB_Arg arg;
79 
81 
82 /*
83  * ======== SecureCB_init ========
84  * Initialize SecureCB driver
85  *
86  * Must be called once and prior to invoking any other SecureCB APIs.
87  *
88  * This API is only available to non-secure code
89  */
90 void SecureCB_init(void);
91 
92 /*
93  * ======== SecureCB_construct ========
94  * Construct a callback object and add it from the Callback dispatcher's
95  * service Queue.
96  *
97  * Returns a handle to the callback object if successful, NULL otherwise;
98  *
99  * The Callback is not immediately enabled.
100  *
101  * This API is only available to non-secure code
102  */
104  SecureCB_Arg arg);
105 
106 /*
107  * ======== SecureCB_destruct ========
108  * Destruct a callback object and remove it from the Callback dispatcher's
109  * service Queue.
110  *
111  * Returns SecureCB_STATUS_ERROR if object appears to be invalid.
112  *
113  * This API is only available to non-secure code
114  */
115 uint32_t SecureCB_destruct(SecureCB_Object *scb);
116 
117 /*
118  * ======== SecureCB_enable ========
119  * Enable a callback so that the next time the callback dispatch's
120  * interrupt occurs, the callback will be invoked.
121  *
122  * Returns SecureCB_STATUS_ERROR if object appears to be invalid.
123  *
124  * This API is available to both non-secure and secure code
125  */
126 __attribute__ ((always_inline)) __STATIC_INLINE
127 uint32_t SecureCB_enable(SecureCB_Object *scb)
128 {
129  if (scb->crstat & SecureCB_CRSTAT_DEFINED) {
130  scb->crstat |= SecureCB_CRSTAT_ENABLED;
131  return (SecureCB_STATUS_OK);
132  }
133  return (SecureCB_STATUS_ERROR);
134 }
135 
136 /*
137  * ======== SecureCB_setArg ========
138  * update the arg of an existing callback
139  *
140  * Returns SecureCB_STATUS_ERROR if object appears to be invalid.
141  *
142  * This API is available to both non-secure and secure code
143  */
144 __attribute__ ((always_inline)) __STATIC_INLINE
145 uint32_t SecureCB_setArg(SecureCB_Handle scb, SecureCB_Arg arg)
146 {
147  if (scb->crstat & SecureCB_CRSTAT_DEFINED) {
148  scb->arg = arg;
149  return (SecureCB_STATUS_OK);
150  }
151  return (SecureCB_STATUS_ERROR);
152 }
153 
154 /*
155  * ======== SecureCB_getArg ========
156  * fetch the arg of an existing callback
157  *
158  * Returns 0 if object appears to be invalid.
159  *
160  * This API is available to both non-secure and secure code
161  */
162 __attribute__ ((always_inline)) __STATIC_INLINE
163 SecureCB_Arg SecureCB_getArg(SecureCB_Handle scb)
164 {
165  if (scb->crstat & SecureCB_CRSTAT_DEFINED) {
166  return (scb->arg);
167  }
168  return (0);
169 }
170 
171 /*
172  * ======== SecureCB_post ========
173  * Post a callback
174  *
175  * Enables the callback and triggers the NS Callback
176  * Dispatcher's interrupt.
177  *
178  * Returns SecureCB_STATUS_ERROR if object appears to be invalid.
179  *
180  * This API is available to both non-secure and secure code
181  */
182 __attribute__ ((always_inline)) __STATIC_INLINE
183 uint32_t SecureCB_post(SecureCB_Handle scb)
184 {
185  uint32_t *ISPR = (uint32_t *)NVIC_ISPR_ADDRESS;
186  uint32_t IRQn = scb->intNum - 16;
187 
188  if (scb->crstat & SecureCB_CRSTAT_DEFINED) {
190  ISPR[IRQn >> 5UL] = 1 << (IRQn & 0x1f);
191  return (SecureCB_STATUS_OK);
192  }
193  return (SecureCB_STATUS_ERROR);
194 }
195 
196 #if defined (__cplusplus)
197 }
198 #endif
199 
200 #endif /* ti_spe_SecureCB__include */
#define SecureCB_CRSTAT_DEFINED
Definition: SecureCB.h:65
#define SecureCB_STATUS_ERROR
Definition: SecureCB.h:63
void(* SecureCB_FuncPtr)(SecureCB_Arg arg)
Definition: SecureCB.h:69
#define SecureCB_STATUS_OK
Definition: SecureCB.h:62
#define NVIC_ISPR_ADDRESS
Definition: SecureCB.h:55
__attribute__((always_inline)) __STATIC_INLINE uint32_t SecureCB_enable(SecureCB_Object *scb)
Definition: SecureCB.h:126
SecureCB_Arg arg
Definition: SecureCB.h:77
uintptr_t SecureCB_Arg
Definition: SecureCB.h:68
uint32_t SecureCB_destruct(SecureCB_Object *scb)
struct SecureCB_Object *volatile next
Definition: SecureCB.h:72
SecureCB_FuncPtr fxn
Definition: SecureCB.h:76
SecureCB_Handle SecureCB_construct(SecureCB_Object *scb, SecureCB_FuncPtr fxn, SecureCB_Arg arg)
uint16_t crstat
Definition: SecureCB.h:75
uint16_t intNum
Definition: SecureCB.h:74
#define SecureCB_CRSTAT_ENABLED
Definition: SecureCB.h:66
SecureCB_Object * SecureCB_Handle
Definition: SecureCB.h:80
SecureCB_Arg arg
Definition: SecureCB.h:146
void SecureCB_init(void)
Definition: SecureCB.h:71
struct SecureCB_Object *volatile prev
Definition: SecureCB.h:73
struct SecureCB_Object SecureCB_Object
© Copyright 1995-2021, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale