| 1 | /*************************************************************************** |
|---|
| 2 | * Copyright (c) 2003-2009, Broadcom Corporation |
|---|
| 3 | * All Rights Reserved |
|---|
| 4 | * Confidential Property of Broadcom Corporation |
|---|
| 5 | * |
|---|
| 6 | * THIS SOFTWARE MAY ONLY BE USED SUBJECT TO AN EXECUTED SOFTWARE LICENSE |
|---|
| 7 | * AGREEMENT BETWEEN THE USER AND BROADCOM. YOU HAVE NO RIGHT TO USE OR |
|---|
| 8 | * EXPLOIT THIS MATERIAL EXCEPT SUBJECT TO THE TERMS OF SUCH AN AGREEMENT. |
|---|
| 9 | * |
|---|
| 10 | * $brcm_Workfile: bint.h $ |
|---|
| 11 | * $brcm_Revision: Hydra_Software_Devel/30 $ |
|---|
| 12 | * $brcm_Date: 3/30/09 3:15p $ |
|---|
| 13 | * |
|---|
| 14 | * Module Description: |
|---|
| 15 | * |
|---|
| 16 | * Revision History: |
|---|
| 17 | * |
|---|
| 18 | * $brcm_Log: /magnum/basemodules/int/bint.h $ |
|---|
| 19 | * |
|---|
| 20 | * Hydra_Software_Devel/30 3/30/09 3:15p erickson |
|---|
| 21 | * PR35457: update comments, especially regarding BINT_Id |
|---|
| 22 | * |
|---|
| 23 | * Hydra_Software_Devel/29 5/25/06 4:13p albertl |
|---|
| 24 | * PR21392: BINT_Stats functions now split off into bint_stats.h to solve |
|---|
| 25 | * BTMR circular dependency. |
|---|
| 26 | * |
|---|
| 27 | * Hydra_Software_Devel/28 5/24/06 6:56p albertl |
|---|
| 28 | * PR21392: Changed BINT stats tracking to use timers from TMR module. |
|---|
| 29 | * Added BINT_Stats_Enable and BINT_Stats_Disable. |
|---|
| 30 | * |
|---|
| 31 | * Hydra_Software_Devel/27 2/15/06 5:30p vsilyaev |
|---|
| 32 | * PR 19693: Added support for acquiring interrupt rate |
|---|
| 33 | * |
|---|
| 34 | * Hydra_Software_Devel/26 9/12/05 7:18p darnstein |
|---|
| 35 | * PR16885: include bstd.h. |
|---|
| 36 | * |
|---|
| 37 | * Hydra_Software_Devel/25 4/13/05 5:16p albertl |
|---|
| 38 | * PR10596: Moved bDefaultBins to BINT_Stats_CallbackStats. |
|---|
| 39 | * |
|---|
| 40 | * Hydra_Software_Devel/24 4/11/05 5:29p albertl |
|---|
| 41 | * PR10596: Added BINT_Stats_DestroyBins and BINT_Stats_Reset. |
|---|
| 42 | * BINT_STATS_ENABLE now tied to BDBG_DEBUG_BUILD. |
|---|
| 43 | * |
|---|
| 44 | * Hydra_Software_Devel/23 4/7/05 4:15p albertl |
|---|
| 45 | * PR10596: Changed BINT_STATS_TRACK to BINT_STATS_ENABLE. |
|---|
| 46 | * |
|---|
| 47 | * Hydra_Software_Devel/22 4/6/05 2:26p albertl |
|---|
| 48 | * PR10596: Removed unnecessary #ifdef BINT_STATS_TRACK cases for better |
|---|
| 49 | * readability. |
|---|
| 50 | * |
|---|
| 51 | * Hydra_Software_Devel/21 4/5/05 7:13p albertl |
|---|
| 52 | * PR10596: Added new statistics tracking functionality. |
|---|
| 53 | * |
|---|
| 54 | * Hydra_Software_Devel/20 4/16/04 5:08p marcusk |
|---|
| 55 | * PR10666: Merged from B0 branch to keep API compatible. |
|---|
| 56 | * |
|---|
| 57 | * Hydra_Software_Devel/Refsw_Devel_7038_B0/2 4/16/04 4:55p marcusk |
|---|
| 58 | * PR10666: Do not clear interrupts when enabling and added |
|---|
| 59 | * BINT_ClearCallback() routines. |
|---|
| 60 | * |
|---|
| 61 | * Hydra_Software_Devel/19 12/29/03 3:58p marcusk |
|---|
| 62 | * PR9117: Updated with changes required to support interrupt ids rather |
|---|
| 63 | * than strings. |
|---|
| 64 | * |
|---|
| 65 | * Hydra_Software_Devel/18 12/1/03 4:52p jasonh |
|---|
| 66 | * Added documentation for interrupt clearing. |
|---|
| 67 | * |
|---|
| 68 | * Hydra_Software_Devel/17 9/16/03 10:30a marcusk |
|---|
| 69 | * Updated to comply with DocJet requirements. Fixes for PR8055. |
|---|
| 70 | * |
|---|
| 71 | * Hydra_Software_Devel/16 8/13/03 1:28p marcusk |
|---|
| 72 | * Added naming convention note. |
|---|
| 73 | * |
|---|
| 74 | * Hydra_Software_Devel/15 6/18/03 3:25p dlwin |
|---|
| 75 | * Updated comments. |
|---|
| 76 | * |
|---|
| 77 | * Hydra_Software_Devel/14 6/11/03 3:07p marcusk |
|---|
| 78 | * Updated verbage to include only standarized L2 interrupt registers. |
|---|
| 79 | * |
|---|
| 80 | * Hydra_Software_Devel/13 4/2/03 10:39a marcusk |
|---|
| 81 | * Updated to support flag to specify if the interrupt can be triggered by |
|---|
| 82 | * the CPU. |
|---|
| 83 | * |
|---|
| 84 | * Hydra_Software_Devel/11 3/31/03 1:11p marcusk |
|---|
| 85 | * Clarified some comments. |
|---|
| 86 | * |
|---|
| 87 | * Hydra_Software_Devel/10 3/21/03 6:30p marcusk |
|---|
| 88 | * Minor updates. |
|---|
| 89 | * |
|---|
| 90 | * Hydra_Software_Devel/9 3/19/03 4:57p marcusk |
|---|
| 91 | * Added int value parameter that is returned when an interrupt triggers. |
|---|
| 92 | * |
|---|
| 93 | * Hydra_Software_Devel/8 3/19/03 4:03p marcusk |
|---|
| 94 | * Removed some spaces from module overview. |
|---|
| 95 | * |
|---|
| 96 | * Hydra_Software_Devel/7 3/19/03 4:02p marcusk |
|---|
| 97 | * Used comments instead of spaces in module overview (twiki test). |
|---|
| 98 | * |
|---|
| 99 | * Hydra_Software_Devel/6 3/19/03 3:41p marcusk |
|---|
| 100 | * Slightly modified comments. |
|---|
| 101 | * |
|---|
| 102 | * Hydra_Software_Devel/5 3/19/03 11:20a marcusk |
|---|
| 103 | * Added module overview. |
|---|
| 104 | * |
|---|
| 105 | * Hydra_Software_Devel/4 3/17/03 9:06a marcusk |
|---|
| 106 | * Updated with const strings and removed un-needed typedef. |
|---|
| 107 | * |
|---|
| 108 | * Hydra_Software_Devel/3 3/13/03 3:22p marcusk |
|---|
| 109 | * Added a couple new function and updated comments. |
|---|
| 110 | * |
|---|
| 111 | * Hydra_Software_Devel/2 3/13/03 2:45p marcusk |
|---|
| 112 | * Updated comments. |
|---|
| 113 | * |
|---|
| 114 | * Hydra_Software_Devel/1 3/11/03 5:42p marcusk |
|---|
| 115 | * Initial version. |
|---|
| 116 | * |
|---|
| 117 | ***************************************************************************/ |
|---|
| 118 | |
|---|
| 119 | /*= Module Overview ********************************************************* |
|---|
| 120 | |
|---|
| 121 | The InterruptInterface is used to provide an abstraction that can be |
|---|
| 122 | used by software modules to provide the following functionality for |
|---|
| 123 | various L2 interrupts found in the system: |
|---|
| 124 | |
|---|
| 125 | 1 Assign ISR callback routines to specific interrupts. |
|---|
| 126 | * Multiple callbacks can be installed for a single interrupt. |
|---|
| 127 | 2 Enable and disable callbacks. |
|---|
| 128 | * The InterruptInterface will only manage L2 interrupt registers and |
|---|
| 129 | will not touch bits that are not enabled through the exposed interface. |
|---|
| 130 | This allows platform specific code to "share" L1 interrupt bits between |
|---|
| 131 | platform specific code and the interrupt interface. |
|---|
| 132 | * The implementation of the InterruptInterface will automatically |
|---|
| 133 | mask the L2 hardware interrupt when all callbacks using that specific |
|---|
| 134 | interrupt bit have been disabled. Likewise it will un-mask an L2 |
|---|
| 135 | interrupt when one or more callbacks are enabled for a specific interrupt. |
|---|
| 136 | 3 Trigger an interrupt (software controlled and if hardware supports it). |
|---|
| 137 | 4 Uses interrupt names to specify specific interrupt (calling modules do |
|---|
| 138 | not need to know the layout of each interrupt bit, only the standard |
|---|
| 139 | name of the interrupt). |
|---|
| 140 | * Strings are used to identify interrupts which allows code to select |
|---|
| 141 | the proper interrupt when multiple instances of an interrupt exist. |
|---|
| 142 | This is easily be accomplished through [[KernelInterface][BKNI_Snprintf]] |
|---|
| 143 | that allows a number value to be inserted into a string. |
|---|
| 144 | 5 To support various L2 implementations that may appear on a system |
|---|
| 145 | (ie, Bcm7028 and Bcm3250 chip in one system), the board/chip-specific code |
|---|
| 146 | must be provide functions to set/clear interrupts, |
|---|
| 147 | set/clear interrupt masks, and process L2 interrupt. |
|---|
| 148 | |
|---|
| 149 | *Interrupt Naming Convention* |
|---|
| 150 | |
|---|
| 151 | The following naming convention should be used when defining interrupt |
|---|
| 152 | names: |
|---|
| 153 | |
|---|
| 154 | BXXX_INTERRUPT_NAME |
|---|
| 155 | |
|---|
| 156 | Where BXXX is the PortingInterface module that owns the interrupt. |
|---|
| 157 | |
|---|
| 158 | ***************************************************************************/ |
|---|
| 159 | |
|---|
| 160 | #ifndef BINT_H |
|---|
| 161 | #define BINT_H |
|---|
| 162 | |
|---|
| 163 | #include "bstd.h" |
|---|
| 164 | |
|---|
| 165 | #ifdef __cplusplus |
|---|
| 166 | extern "C" { |
|---|
| 167 | #endif |
|---|
| 168 | |
|---|
| 169 | /* |
|---|
| 170 | Summary: |
|---|
| 171 | The BINT_Id typedef specifies the ID an interrupt. |
|---|
| 172 | |
|---|
| 173 | Description: |
|---|
| 174 | Each BINT_Id value corresponds to one bit in an L2 interrupt register. |
|---|
| 175 | The value of BINT_Id contains both the L2 register address and the shift value for the interrupt bit in that L2 in a packed format. |
|---|
| 176 | Use the BCHP_INT_ID_CREATE macro (see bchp.h) to build a BINT_Id value. |
|---|
| 177 | */ |
|---|
| 178 | typedef uint32_t BINT_Id; |
|---|
| 179 | |
|---|
| 180 | /* |
|---|
| 181 | Summary: |
|---|
| 182 | This structure defines an opaque handle that is used for InterruptInterface function calls. |
|---|
| 183 | */ |
|---|
| 184 | typedef struct BINT_P_Context *BINT_Handle; |
|---|
| 185 | |
|---|
| 186 | /* |
|---|
| 187 | Summary: |
|---|
| 188 | This structure defines an opaque handle that is used for InterruptInterface function calls. |
|---|
| 189 | */ |
|---|
| 190 | typedef struct BINT_P_Callback *BINT_CallbackHandle; |
|---|
| 191 | |
|---|
| 192 | /* |
|---|
| 193 | Summary: |
|---|
| 194 | This defines the function prototype that is used for InterruptInterface callbacks. |
|---|
| 195 | */ |
|---|
| 196 | typedef void (*BINT_CallbackFunc)( void * pParm1, int parm2 ); |
|---|
| 197 | |
|---|
| 198 | /* |
|---|
| 199 | Summary: |
|---|
| 200 | This function creates a callback. |
|---|
| 201 | |
|---|
| 202 | Description: |
|---|
| 203 | After this function is used to create a callback, the BINT_EnableCallback() |
|---|
| 204 | function must be used before the callback will actually be enabled. When |
|---|
| 205 | the specified interrupt triggers, the func specified will be called with the |
|---|
| 206 | pParm passed into this function. |
|---|
| 207 | |
|---|
| 208 | The first time an callback is created for a specific interrupt, the interrupt |
|---|
| 209 | status will be cleared. |
|---|
| 210 | */ |
|---|
| 211 | BERR_Code BINT_CreateCallback( |
|---|
| 212 | BINT_CallbackHandle *pCbHandle, /* [out] Returns handle */ |
|---|
| 213 | BINT_Handle handle, /* [in] InterruptInterface handle */ |
|---|
| 214 | BINT_Id intId, /* [in] Id of the interrupt to associate with callback function */ |
|---|
| 215 | BINT_CallbackFunc func, /* [in] Callback function that should be called when the specified interrupt triggers */ |
|---|
| 216 | void * pParm1, /* [in] Parameter that is returned to callback function when interrupt triggers */ |
|---|
| 217 | int parm2 /* [in] Parameter that is returned to callback function when interrupt triggers */ |
|---|
| 218 | ); |
|---|
| 219 | |
|---|
| 220 | /* |
|---|
| 221 | Summary: |
|---|
| 222 | This function destroys a callback and frees any resources associated |
|---|
| 223 | with the callback. |
|---|
| 224 | |
|---|
| 225 | Description: |
|---|
| 226 | If the specified callback is enabled when this function is called, the |
|---|
| 227 | callback may be called at any time until this function returns. |
|---|
| 228 | */ |
|---|
| 229 | BERR_Code BINT_DestroyCallback( |
|---|
| 230 | BINT_CallbackHandle cbHandle /* [in] Callback handle returned by BINT_CreateCallback() */ |
|---|
| 231 | ); |
|---|
| 232 | |
|---|
| 233 | /* |
|---|
| 234 | Summary: |
|---|
| 235 | This function enables a callback. |
|---|
| 236 | |
|---|
| 237 | Description: |
|---|
| 238 | The callback may be called any number of times before this function returns! |
|---|
| 239 | */ |
|---|
| 240 | BERR_Code BINT_EnableCallback( |
|---|
| 241 | BINT_CallbackHandle cbHandle /* [in] Callback handle returned by BINT_CreateCallback() */ |
|---|
| 242 | ); |
|---|
| 243 | |
|---|
| 244 | /* |
|---|
| 245 | Summary: |
|---|
| 246 | This function enables a callback in ISR context. |
|---|
| 247 | |
|---|
| 248 | Description: |
|---|
| 249 | The callback may be called any number of times before this function returns! |
|---|
| 250 | */ |
|---|
| 251 | BERR_Code BINT_EnableCallback_isr( |
|---|
| 252 | BINT_CallbackHandle cbHandle /* [in] Callback handle returned by BINT_CreateCallback() */ |
|---|
| 253 | ); |
|---|
| 254 | |
|---|
| 255 | /* |
|---|
| 256 | Summary: |
|---|
| 257 | This function disables a callback. |
|---|
| 258 | |
|---|
| 259 | Description: |
|---|
| 260 | The callback may be called at any time until the function returns. |
|---|
| 261 | */ |
|---|
| 262 | BERR_Code BINT_DisableCallback( |
|---|
| 263 | BINT_CallbackHandle cbHandle /* [in] Callback handle returned by BINT_CreateCallback() */ |
|---|
| 264 | ); |
|---|
| 265 | |
|---|
| 266 | |
|---|
| 267 | /* |
|---|
| 268 | Summary: |
|---|
| 269 | This function disables a callback in ISR context. |
|---|
| 270 | |
|---|
| 271 | Description: |
|---|
| 272 | The callback may be called at any time until the function returns. |
|---|
| 273 | */ |
|---|
| 274 | BERR_Code BINT_DisableCallback_isr( |
|---|
| 275 | BINT_CallbackHandle cbHandle /* [in] Callback handle returned by BINT_CreateCallback() */ |
|---|
| 276 | ); |
|---|
| 277 | |
|---|
| 278 | /* |
|---|
| 279 | Summary: |
|---|
| 280 | This functions clears a pending interrupt specified by the callback. |
|---|
| 281 | |
|---|
| 282 | Description: |
|---|
| 283 | The interrupt will only be cleared if there are no callbacks currently |
|---|
| 284 | enabled for the interrupt associated with the specified callback. |
|---|
| 285 | */ |
|---|
| 286 | BERR_Code BINT_ClearCallback( |
|---|
| 287 | BINT_CallbackHandle cbHandle /* [in] Callback handle returned by BINT_CreateCallback() */ |
|---|
| 288 | ); |
|---|
| 289 | |
|---|
| 290 | /* |
|---|
| 291 | Summary: |
|---|
| 292 | This functions clears a pending interrupt specified by the callback. |
|---|
| 293 | |
|---|
| 294 | Description: |
|---|
| 295 | The interrupt will only be cleared if there are no callbacks currently |
|---|
| 296 | enabled for the interrupt associated with the specified callback. |
|---|
| 297 | */ |
|---|
| 298 | BERR_Code BINT_ClearCallback_isr( |
|---|
| 299 | BINT_CallbackHandle cbHandle /* [in] Callback handle returned by BINT_CreateCallback() */ |
|---|
| 300 | ); |
|---|
| 301 | |
|---|
| 302 | /* |
|---|
| 303 | Summary: |
|---|
| 304 | This function triggers a hardware interrupt. |
|---|
| 305 | |
|---|
| 306 | Description: |
|---|
| 307 | The interrupt triggers the hardware specified by the BINT_CallbackHandle. |
|---|
| 308 | The callback handle is used directly trigger the interrupt. |
|---|
| 309 | |
|---|
| 310 | Interrupts must be flagged as CPU trigger-able before this function will allow the interrupt |
|---|
| 311 | to be triggered (this flag exists in the BINT_P_intDef structure). This allows specific |
|---|
| 312 | platforms and environments to prevent software from triggering interrupts they should not be. |
|---|
| 313 | */ |
|---|
| 314 | BERR_Code BINT_TriggerInterruptByHandle( |
|---|
| 315 | BINT_CallbackHandle cbHandle /* [in] Callback handle returned by BINT_CreateCallback() */ |
|---|
| 316 | ); |
|---|
| 317 | |
|---|
| 318 | /* |
|---|
| 319 | Summary: |
|---|
| 320 | This function triggers a hardware interrupt. |
|---|
| 321 | |
|---|
| 322 | Description: |
|---|
| 323 | The interrupt triggers the hardware specified by the BINT_CallbackHandle. |
|---|
| 324 | The callback handle is used directly trigger the interrupt. |
|---|
| 325 | |
|---|
| 326 | Interrupts must be flagged as CPU trigger-able before this function will allow the interrupt |
|---|
| 327 | to be triggered (this flag exists in the BINT_P_intDef structure). This allows specific |
|---|
| 328 | platforms and environments to prevent software from triggering interrupts they should not be. |
|---|
| 329 | */ |
|---|
| 330 | BERR_Code BINT_TriggerInterruptByHandle_isr( |
|---|
| 331 | BINT_CallbackHandle cbHandle /* [in] Callback handle returned by BINT_CreateCallback() */ |
|---|
| 332 | ); |
|---|
| 333 | |
|---|
| 334 | /* |
|---|
| 335 | Summary: |
|---|
| 336 | Gets the first registered callback. |
|---|
| 337 | |
|---|
| 338 | Description: |
|---|
| 339 | Gets the first callback handle stored in the INT module. used with BINT_GetCallbackNext |
|---|
| 340 | to traverse through all installed callbacks. |
|---|
| 341 | */ |
|---|
| 342 | BINT_CallbackHandle BINT_GetCallbackFirst( |
|---|
| 343 | BINT_Handle intHandle /* [in] Interrupt handle */ |
|---|
| 344 | ); |
|---|
| 345 | |
|---|
| 346 | /* |
|---|
| 347 | Summary: |
|---|
| 348 | Gets the next registered callback. |
|---|
| 349 | |
|---|
| 350 | Description: |
|---|
| 351 | Returns the next callback handle after cbHandle. Order of callbacks returned is in |
|---|
| 352 | order of callback creation. |
|---|
| 353 | */ |
|---|
| 354 | BINT_CallbackHandle BINT_GetCallbackNext( |
|---|
| 355 | BINT_CallbackHandle cbHandle /* [in] Callback handle returned by BINT_CreateCallback() */ |
|---|
| 356 | ); |
|---|
| 357 | /* |
|---|
| 358 | Summary: |
|---|
| 359 | Gets the interrupt ID for this callback. |
|---|
| 360 | |
|---|
| 361 | Description: |
|---|
| 362 | Returns the interrupt ID for the specific callback in pIntId. Used with the above |
|---|
| 363 | traversal functions to identify a callback hooked to a specific interrupt. |
|---|
| 364 | */ |
|---|
| 365 | BERR_Code BINT_GetInterruptId( |
|---|
| 366 | BINT_CallbackHandle cbHandle, /* [in] Callback handle returned by BINT_CreateCallback() */ |
|---|
| 367 | BINT_Id *pIntId /* [out] Pointer to storage for the interrupt ID */ |
|---|
| 368 | ); |
|---|
| 369 | |
|---|
| 370 | /* |
|---|
| 371 | Summary: |
|---|
| 372 | Gets callback's active status. |
|---|
| 373 | |
|---|
| 374 | Description: |
|---|
| 375 | Gets the status of a callback and returns whether it is active or not in pbEnabled. |
|---|
| 376 | */ |
|---|
| 377 | BERR_Code BINT_GetCallbackStatus( |
|---|
| 378 | BINT_CallbackHandle cbHandle, /* [in] Callback handle returned by BINT_CreateCallback() */ |
|---|
| 379 | bool *pbEnabled /* [out] Pointer to storage for the callback's active status */ |
|---|
| 380 | ); |
|---|
| 381 | |
|---|
| 382 | /* |
|---|
| 383 | Summary: |
|---|
| 384 | This function outputs statistics of the interrupt interface. |
|---|
| 385 | |
|---|
| 386 | Description: |
|---|
| 387 | Prints out statistics, using message level debug output and then resets accumulated information. |
|---|
| 388 | */ |
|---|
| 389 | void BINT_DumpInfo(BINT_Handle intHandle); |
|---|
| 390 | #if BDBG_DEBUG_BUILD |
|---|
| 391 | /* {secret} */ |
|---|
| 392 | BERR_Code BINT_P_CreateCallback_Tag( |
|---|
| 393 | BINT_CallbackHandle *pCbHandle, |
|---|
| 394 | BINT_Handle handle, |
|---|
| 395 | BINT_Id intId, |
|---|
| 396 | BINT_CallbackFunc func, |
|---|
| 397 | void * pParm1, |
|---|
| 398 | int parm2, |
|---|
| 399 | const char *callbackName |
|---|
| 400 | ); |
|---|
| 401 | #define BINT_CreateCallback(cbh, h, id, f, p1, p2) BINT_P_CreateCallback_Tag((cbh), (h), (id), (f), (p1), (p2), #f) |
|---|
| 402 | #endif |
|---|
| 403 | |
|---|
| 404 | #ifdef __cplusplus |
|---|
| 405 | } |
|---|
| 406 | #endif |
|---|
| 407 | |
|---|
| 408 | #endif |
|---|
| 409 | /* End of File */ |
|---|
| 410 | |
|---|
| 411 | |
|---|
| 412 | |
|---|