| 1 | /*************************************************************************** |
|---|
| 2 | * Copyright (c) 2003, 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: brsp_mbyte.c $ |
|---|
| 11 | * $brcm_Revision: Hydra_Software_Devel/9 $ |
|---|
| 12 | * $brcm_Date: 10/19/04 12:04p $ |
|---|
| 13 | * |
|---|
| 14 | * Module Description: |
|---|
| 15 | * |
|---|
| 16 | * Revision History: |
|---|
| 17 | * |
|---|
| 18 | * $brcm_Log: /magnum/commonutils/rsp/brsp_mbyte.c $ |
|---|
| 19 | * |
|---|
| 20 | * Hydra_Software_Devel/9 10/19/04 12:04p dlwin |
|---|
| 21 | * PR 13038: Added ability to do Read/Mod/Write. |
|---|
| 22 | * |
|---|
| 23 | * Hydra_Software_Devel/8 3/25/04 11:00a dlwin |
|---|
| 24 | * PR 8971: Replace BDBG_Assert() with code to return error code. |
|---|
| 25 | * |
|---|
| 26 | * Hydra_Software_Devel/7 10/21/03 6:17p dlwin |
|---|
| 27 | * Removed all BDBG_ENTER(__FUNCTION__) and BDBG_LEAVE(__FUNCTION__) with |
|---|
| 28 | * macro usage of function, instead of __FUNCTION__. |
|---|
| 29 | * |
|---|
| 30 | * Hydra_Software_Devel/6 10/14/03 5:10p dlwin |
|---|
| 31 | * Fixed to address Bcm3250 MByte registers. |
|---|
| 32 | * |
|---|
| 33 | * Hydra_Software_Devel/5 9/18/03 5:18p dlwin |
|---|
| 34 | * Removed more warnings. |
|---|
| 35 | * |
|---|
| 36 | * Hydra_Software_Devel/4 9/16/03 5:20p dlwin |
|---|
| 37 | * Replace [output] with [out] on API comments. |
|---|
| 38 | * |
|---|
| 39 | * Hydra_Software_Devel/3 9/8/03 6:37p dlwin |
|---|
| 40 | * Updated API function parameter comment for DocJet. |
|---|
| 41 | * |
|---|
| 42 | * Hydra_Software_Devel/2 9/8/03 1:21p dlwin |
|---|
| 43 | * Replaced Create/DestroyHandle with Open/Close. |
|---|
| 44 | * |
|---|
| 45 | * Hydra_Software_Devel/1 9/3/03 3:34p dlwin |
|---|
| 46 | * Initial version |
|---|
| 47 | * |
|---|
| 48 | ***************************************************************************/ |
|---|
| 49 | #include "bstd.h" |
|---|
| 50 | #include "bkni.h" |
|---|
| 51 | #include "brsp.h" |
|---|
| 52 | #include "brsp_mbyte.h" |
|---|
| 53 | #include "brsp_priv.h" |
|---|
| 54 | |
|---|
| 55 | |
|---|
| 56 | |
|---|
| 57 | |
|---|
| 58 | BDBG_MODULE(brsp_mbyte); |
|---|
| 59 | |
|---|
| 60 | #if (BSTD_CPU_ENDIAN == BSTD_ENDIAN_LITTLE) |
|---|
| 61 | #define PCI_ADDR8(x) (x^3) /* fix addresses for char access */ |
|---|
| 62 | #define PCI_ADDR16(x) (x^2) /* fix addresses for short access */ |
|---|
| 63 | #else |
|---|
| 64 | #define PCI_ADDR8(x) (x) |
|---|
| 65 | #define PCI_ADDR16(x) (x) |
|---|
| 66 | #endif |
|---|
| 67 | |
|---|
| 68 | typedef BERR_Code (*BRSP_P_CallbackFunc) ( void *, uint32_t, uint32_t, uint32_t, uint32_t); |
|---|
| 69 | |
|---|
| 70 | typedef struct BRSP_P_SimpleScript |
|---|
| 71 | { |
|---|
| 72 | uint32_t offset; |
|---|
| 73 | uint32_t value; |
|---|
| 74 | } BRSP_P_SimpleScript; |
|---|
| 75 | |
|---|
| 76 | typedef struct BRSP_P_RdModWrSimpleScript |
|---|
| 77 | { |
|---|
| 78 | uint32_t offset; |
|---|
| 79 | uint32_t mask; |
|---|
| 80 | uint32_t value; |
|---|
| 81 | uint32_t filler0; |
|---|
| 82 | uint32_t filler1; |
|---|
| 83 | } BRSP_P_RdModWrSimpleScript; |
|---|
| 84 | |
|---|
| 85 | typedef struct BRSP_P_FuncScript |
|---|
| 86 | { |
|---|
| 87 | BRSP_P_CallbackFunc func; |
|---|
| 88 | uint32_t arg1; |
|---|
| 89 | uint32_t arg2; |
|---|
| 90 | uint32_t arg3; |
|---|
| 91 | uint32_t arg4; |
|---|
| 92 | } BRSP_P_FuncScript; |
|---|
| 93 | |
|---|
| 94 | typedef struct BRSP_P_NestedScript |
|---|
| 95 | { |
|---|
| 96 | BRSP_ScriptTbl *pScriptTbl; |
|---|
| 97 | uint32_t notused; |
|---|
| 98 | } BRSP_P_NestedScript; |
|---|
| 99 | |
|---|
| 100 | typedef struct BRSP_P_ScriptEntry |
|---|
| 101 | { |
|---|
| 102 | BRSP_ScriptType scriptType; |
|---|
| 103 | union |
|---|
| 104 | { |
|---|
| 105 | BRSP_P_SimpleScript regData; |
|---|
| 106 | BRSP_P_RdModWrSimpleScript regRdModWrData; |
|---|
| 107 | BRSP_P_FuncScript funcData; |
|---|
| 108 | BRSP_P_NestedScript nestedData; |
|---|
| 109 | } scriptInfo; |
|---|
| 110 | } BRSP_P_ScriptEntry; |
|---|
| 111 | |
|---|
| 112 | |
|---|
| 113 | |
|---|
| 114 | BERR_Code BRSP_MByte_ParseRegScript( |
|---|
| 115 | BRSP_MByte_Handle hRsp, /* [in] Handle to Register Script */ |
|---|
| 116 | const BRSP_ScriptTbl *pScriptTbl, /* [in] Pointer to Register Script Tbl */ |
|---|
| 117 | void *phDev /* [in] Handle of calling device */ |
|---|
| 118 | ) |
|---|
| 119 | { |
|---|
| 120 | BERR_Code retCode = BERR_SUCCESS; |
|---|
| 121 | BRSP_P_ScriptEntry *pScript; |
|---|
| 122 | uint32_t ulVal; |
|---|
| 123 | |
|---|
| 124 | |
|---|
| 125 | /* Sanity check on the handles we've been given. */ |
|---|
| 126 | BDBG_ENTER(BRSP_MByte_ParseRegScript); |
|---|
| 127 | BDBG_ASSERT( hRsp ); |
|---|
| 128 | BDBG_ASSERT( hRsp->magicId == BRSP_MAGIC_ID ); |
|---|
| 129 | |
|---|
| 130 | pScript = (BRSP_P_ScriptEntry *) pScriptTbl; |
|---|
| 131 | |
|---|
| 132 | for(; pScript->scriptType != BRSP_ScriptType_eEndOfScript && retCode == BERR_SUCCESS; ) |
|---|
| 133 | { |
|---|
| 134 | switch( pScript->scriptType ) |
|---|
| 135 | { |
|---|
| 136 | case BRSP_ScriptType_eWrite8: |
|---|
| 137 | BREG_Write8( hRsp->hReg, (pScript->scriptInfo.regData.offset + hRsp->coreOffset), |
|---|
| 138 | (uint8_t) pScript->scriptInfo.regData.value ); |
|---|
| 139 | break; |
|---|
| 140 | case BRSP_ScriptType_eWrite16: |
|---|
| 141 | BREG_Write16( hRsp->hReg, (pScript->scriptInfo.regData.offset + hRsp->coreOffset), |
|---|
| 142 | (uint16_t) pScript->scriptInfo.regData.value ); |
|---|
| 143 | break; |
|---|
| 144 | case BRSP_ScriptType_eWrite32: |
|---|
| 145 | BREG_Write32( hRsp->hReg, (pScript->scriptInfo.regData.offset + hRsp->coreOffset), |
|---|
| 146 | (uint32_t) pScript->scriptInfo.regData.value ); |
|---|
| 147 | break; |
|---|
| 148 | case BRSP_ScriptType_eRdModWr32: |
|---|
| 149 | ulVal = BREG_Read32( hRsp->hReg, (pScript->scriptInfo.regRdModWrData.offset + hRsp->coreOffset) ); |
|---|
| 150 | ulVal &= ~pScript->scriptInfo.regRdModWrData.mask; |
|---|
| 151 | ulVal |= pScript->scriptInfo.regRdModWrData.value; |
|---|
| 152 | BREG_Write32( hRsp->hReg, (pScript->scriptInfo.regRdModWrData.offset + hRsp->coreOffset), |
|---|
| 153 | ulVal ); |
|---|
| 154 | break; |
|---|
| 155 | case BRSP_ScriptType_eMbWrite32: |
|---|
| 156 | BRSP_MByte_Write32( hRsp, pScript->scriptInfo.regData.offset, |
|---|
| 157 | pScript->scriptInfo.regData.value ); |
|---|
| 158 | break; |
|---|
| 159 | case BRSP_ScriptType_eDelay: |
|---|
| 160 | /* Convert Milliseconds into Microseconds |
|---|
| 161 | BKNI_Delay( pScript->scriptInfo.regData.value * 1000 ); */ |
|---|
| 162 | BKNI_Sleep( pScript->scriptInfo.regData.value ); |
|---|
| 163 | break; |
|---|
| 164 | case BRSP_ScriptType_eFunc: |
|---|
| 165 | retCode = BERR_TRACE((*(BRSP_P_CallbackFunc)(pScript->scriptInfo.funcData.func)) |
|---|
| 166 | ( phDev, |
|---|
| 167 | pScript->scriptInfo.funcData.arg1, |
|---|
| 168 | pScript->scriptInfo.funcData.arg2, |
|---|
| 169 | pScript->scriptInfo.funcData.arg3, |
|---|
| 170 | pScript->scriptInfo.funcData.arg4 )); |
|---|
| 171 | break; |
|---|
| 172 | case BRSP_ScriptType_eNestedScript: |
|---|
| 173 | retCode = BRSP_MByte_ParseRegScript( hRsp, |
|---|
| 174 | pScript->scriptInfo.nestedData.pScriptTbl, phDev ); |
|---|
| 175 | break; |
|---|
| 176 | case BRSP_ScriptType_eEndOfScript: |
|---|
| 177 | break; |
|---|
| 178 | default: |
|---|
| 179 | retCode = BERR_UNKNOWN; |
|---|
| 180 | break; |
|---|
| 181 | } |
|---|
| 182 | if( retCode == BERR_SUCCESS ) |
|---|
| 183 | { |
|---|
| 184 | /* Goto next entry in the script */ |
|---|
| 185 | if( pScript->scriptType == BRSP_ScriptType_eFunc || pScript->scriptType == BRSP_ScriptType_eRdModWr32 ) |
|---|
| 186 | { |
|---|
| 187 | pScript++; |
|---|
| 188 | } |
|---|
| 189 | else |
|---|
| 190 | { |
|---|
| 191 | pScript = (BRSP_P_ScriptEntry *) ((uint32_t *)pScript + |
|---|
| 192 | (sizeof(BRSP_P_FuncScript)-sizeof(BRSP_P_SimpleScript))/sizeof(uint32_t)); |
|---|
| 193 | } |
|---|
| 194 | } |
|---|
| 195 | } |
|---|
| 196 | BDBG_MSG(("%s: ScriptType=BRSP_ScriptType_eEndOfScript", __FUNCTION__)); |
|---|
| 197 | |
|---|
| 198 | BDBG_LEAVE(BRSP_MByte_ParseRegScript); |
|---|
| 199 | return( retCode ); |
|---|
| 200 | } |
|---|
| 201 | |
|---|
| 202 | |
|---|
| 203 | BERR_Code BRSP_MByte_Open( |
|---|
| 204 | BRSP_MByte_Handle *phRsp, /* [out] MBtye Register Handle */ |
|---|
| 205 | BREG_Handle hReg, /* [in] Register Handle to use */ |
|---|
| 206 | uint32_t coreOffset, /* [in] Core Offset */ |
|---|
| 207 | uint32_t nbrWriteOnlyShadowReg /* [in] Number of Write Only Register, 0 if none */ |
|---|
| 208 | ) |
|---|
| 209 | { |
|---|
| 210 | BERR_Code retCode = BERR_SUCCESS; |
|---|
| 211 | BRSP_MByte_Handle hRsp; |
|---|
| 212 | |
|---|
| 213 | |
|---|
| 214 | BDBG_ENTER(BRSP_MByte_Open); |
|---|
| 215 | |
|---|
| 216 | hRsp = (BRSP_MByte_Handle) BKNI_Malloc( sizeof( BRSP_P_MByte_Handle ) ); |
|---|
| 217 | if( hRsp == NULL ) |
|---|
| 218 | { |
|---|
| 219 | *phRsp = NULL; |
|---|
| 220 | retCode = BERR_TRACE(BERR_OUT_OF_SYSTEM_MEMORY); |
|---|
| 221 | BDBG_ERR(("BRSP_MByte_Open: BKNI_malloc() failed\n")); |
|---|
| 222 | goto done; |
|---|
| 223 | } |
|---|
| 224 | BKNI_Memset( hRsp, 0x00, sizeof( BRSP_P_MByte_Handle ) ); |
|---|
| 225 | |
|---|
| 226 | hRsp->magicId = BRSP_MAGIC_ID; |
|---|
| 227 | hRsp->hReg = hReg; |
|---|
| 228 | hRsp->coreOffset = coreOffset; |
|---|
| 229 | hRsp->nbrShadowReg = nbrWriteOnlyShadowReg; |
|---|
| 230 | if( hRsp->nbrShadowReg != 0 ) |
|---|
| 231 | { |
|---|
| 232 | hRsp->pShadowRegs = (uint32_t *) BKNI_Malloc( sizeof(uint32_t) * hRsp->nbrShadowReg ); |
|---|
| 233 | BDBG_ASSERT( hRsp->pShadowRegs ); |
|---|
| 234 | BKNI_Memset( hRsp->pShadowRegs, 0x00, sizeof(uint32_t) * hRsp->nbrShadowReg ); |
|---|
| 235 | } |
|---|
| 236 | |
|---|
| 237 | *phRsp = hRsp; |
|---|
| 238 | |
|---|
| 239 | done: |
|---|
| 240 | BDBG_LEAVE(BRSP_MByte_Open); |
|---|
| 241 | return( retCode ); |
|---|
| 242 | } |
|---|
| 243 | |
|---|
| 244 | BERR_Code BRSP_MByte_Close( |
|---|
| 245 | BRSP_MByte_Handle hRsp /* [in] MBtye Register Handle */ |
|---|
| 246 | ) |
|---|
| 247 | { |
|---|
| 248 | BERR_Code retCode = BERR_SUCCESS; |
|---|
| 249 | |
|---|
| 250 | |
|---|
| 251 | BDBG_ENTER(BRSP_MByte_Close); |
|---|
| 252 | BDBG_ASSERT( hRsp ); |
|---|
| 253 | BDBG_ASSERT( hRsp->magicId == BRSP_MAGIC_ID ); |
|---|
| 254 | |
|---|
| 255 | if( hRsp->pShadowRegs != NULL ) |
|---|
| 256 | { |
|---|
| 257 | BKNI_Free( (void *) hRsp->pShadowRegs ); |
|---|
| 258 | } |
|---|
| 259 | hRsp->magicId = 0x00; /* clear it to catch inproper use */ |
|---|
| 260 | BKNI_Free( (void *) hRsp ); |
|---|
| 261 | |
|---|
| 262 | BDBG_LEAVE(BRSP_MByte_Close); |
|---|
| 263 | return( retCode ); |
|---|
| 264 | } |
|---|
| 265 | |
|---|
| 266 | |
|---|
| 267 | void BRSP_MByte_Write32( |
|---|
| 268 | BRSP_MByte_Handle hRsp, /* [in] MBtye Register Handle */ |
|---|
| 269 | uint32_t opCode, /* [in] MByte Operation Code to write to (see chip doc.) */ |
|---|
| 270 | uint32_t value /* [in] Value to write to MByte Register */ |
|---|
| 271 | ) |
|---|
| 272 | { |
|---|
| 273 | BDBG_ENTER(BRSP_MByte_Write32); |
|---|
| 274 | BDBG_ASSERT( hRsp ); |
|---|
| 275 | BDBG_ASSERT( hRsp->magicId == BRSP_MAGIC_ID ); |
|---|
| 276 | |
|---|
| 277 | |
|---|
| 278 | BREG_Write32( hRsp->hReg, hRsp->coreOffset, value ); |
|---|
| 279 | BREG_Write8( hRsp->hReg, (hRsp->coreOffset + PCI_ADDR8(4)), (uint8_t) opCode ); |
|---|
| 280 | if( hRsp->pShadowRegs != NULL ) |
|---|
| 281 | { |
|---|
| 282 | if( hRsp->nbrShadowReg > opCode ) |
|---|
| 283 | { |
|---|
| 284 | hRsp->pShadowRegs[opCode] = value; |
|---|
| 285 | } |
|---|
| 286 | } |
|---|
| 287 | |
|---|
| 288 | BDBG_LEAVE(BRSP_MByte_Write32); |
|---|
| 289 | return; |
|---|
| 290 | } |
|---|
| 291 | |
|---|
| 292 | uint32_t BRSP_MByte_Read32( |
|---|
| 293 | BRSP_MByte_Handle hRsp, /* [in] MByte Register Handle */ |
|---|
| 294 | uint32_t opCode /* [in] MByte Operation Code to read from (see chip doc.) */ |
|---|
| 295 | ) |
|---|
| 296 | { |
|---|
| 297 | uint32_t value; |
|---|
| 298 | |
|---|
| 299 | |
|---|
| 300 | BDBG_ENTER(BRSP_MByte_Read32); |
|---|
| 301 | BDBG_ASSERT( hRsp ); |
|---|
| 302 | BDBG_ASSERT( hRsp->magicId == BRSP_MAGIC_ID ); |
|---|
| 303 | |
|---|
| 304 | BREG_Write8( hRsp->hReg, (hRsp->coreOffset + PCI_ADDR8(4)), (uint8_t) opCode ); |
|---|
| 305 | value = BREG_Read32( hRsp->hReg, hRsp->coreOffset ); |
|---|
| 306 | |
|---|
| 307 | BDBG_LEAVE(BRSP_MByte_Read32); |
|---|
| 308 | return( value ); |
|---|
| 309 | } |
|---|
| 310 | |
|---|
| 311 | uint32_t BRSP_MByte_Read32WriteOnly( |
|---|
| 312 | BRSP_MByte_Handle hRsp, /* [in] MByte Register Handle */ |
|---|
| 313 | uint32_t opCode /* [in] MByte Operation Code to read from (see chip doc.) */ |
|---|
| 314 | ) |
|---|
| 315 | { |
|---|
| 316 | uint32_t value; |
|---|
| 317 | |
|---|
| 318 | |
|---|
| 319 | BDBG_ENTER(BRSP_MByte_Read32WriteOnly); |
|---|
| 320 | BDBG_ASSERT( hRsp ); |
|---|
| 321 | BDBG_ASSERT( hRsp->magicId == BRSP_MAGIC_ID ); |
|---|
| 322 | |
|---|
| 323 | value = 0; |
|---|
| 324 | if( hRsp->pShadowRegs != NULL ) |
|---|
| 325 | { |
|---|
| 326 | if( hRsp->nbrShadowReg > opCode ) |
|---|
| 327 | { |
|---|
| 328 | value = hRsp->pShadowRegs[opCode]; |
|---|
| 329 | } |
|---|
| 330 | } |
|---|
| 331 | |
|---|
| 332 | BDBG_LEAVE(BRSP_MByte_Read32WriteOnly); |
|---|
| 333 | return( value ); |
|---|
| 334 | } |
|---|
| 335 | |
|---|