rjw | 1f88458 | 2022-01-06 17:20:42 +0800 | [diff] [blame^] | 1 | /** @file hal_io.cpp |
| 2 | * hal_io.cpp provides functions of register access |
| 3 | */ |
| 4 | |
| 5 | #include "x_hal_io.h" |
| 6 | #include "dramc_common.h" |
| 7 | #include "dramc_pi_api.h" |
| 8 | #if (!FOR_DV_SIMULATION_USED) |
| 9 | #include <emi_hw.h> |
| 10 | #endif |
| 11 | |
| 12 | #if 1//REG_ACCESS_PORTING_DGB |
| 13 | extern U8 RegLogEnable; |
| 14 | #endif |
| 15 | |
| 16 | #ifdef DUMP_INIT_RG_LOG_TO_DE |
| 17 | U8 gDUMP_INIT_RG_LOG_TO_DE_RG_log_flag = 0; |
| 18 | #endif |
| 19 | |
| 20 | #if defined(SLT) || (FT_DSIM_USED) |
| 21 | #define SHUFFLE_ADDR_NUM_DRAMC 4 |
| 22 | #define SHUFFLE_ADDR_NUM_DDRPHY 14 |
| 23 | |
| 24 | typedef struct _SHUFFLE_REG_ADDR |
| 25 | { |
| 26 | U32 u4StartAddr; |
| 27 | U32 u4EndAddr; |
| 28 | } SHUFFLE_REG_ADDR; |
| 29 | |
| 30 | U32 u4RegShuffleOffset(U32 u4RegType, U32 u4Offset, U32 u4Shuffle_Index) |
| 31 | { |
| 32 | SHUFFLE_REG_ADDR ShuffleRegTableDramc[SHUFFLE_ADDR_NUM_DRAMC] = |
| 33 | { |
| 34 | {DRAMC_AO_BASE_ADDRESS+(0x0800), DRAMC_AO_BASE_ADDRESS+(0x08DC) }, |
| 35 | {DRAMC_AO_BASE_ADDRESS+(0x0A00), DRAMC_AO_BASE_ADDRESS+(0x0A50) }, |
| 36 | {DRAMC_AO_BASE_ADDRESS+(0x0B00), DRAMC_AO_BASE_ADDRESS+(0x0B50) }, |
| 37 | {DRAMC_AO_BASE_ADDRESS+(0x0C00), DRAMC_AO_BASE_ADDRESS+(0x0C54) }, |
| 38 | }; |
| 39 | SHUFFLE_REG_ADDR ShuffleRegTableDDRPhy[SHUFFLE_ADDR_NUM_DDRPHY] = |
| 40 | { |
| 41 | {DDRPHY_AO_BASE_ADDR+(0x0C00), DDRPHY_AO_BASE_ADDR+(0x0C38) }, |
| 42 | {DDRPHY_AO_BASE_ADDR+(0x0C80), DDRPHY_AO_BASE_ADDR+(0x0CB8) }, |
| 43 | {DDRPHY_AO_BASE_ADDR+(0x0D00), DDRPHY_AO_BASE_ADDR+(0x0D38) }, |
| 44 | {DDRPHY_AO_BASE_ADDR+(0x0D80), DDRPHY_AO_BASE_ADDR+(0x0DBC) },//PLL |
| 45 | {DDRPHY_AO_BASE_ADDR+(0x0DD0), DDRPHY_AO_BASE_ADDR+(0x0DF0) },//PLL |
| 46 | {DDRPHY_AO_BASE_ADDR+(0x0E00), DDRPHY_AO_BASE_ADDR+(0x0E2C) },//R0 |
| 47 | {DDRPHY_AO_BASE_ADDR+(0x0E50), DDRPHY_AO_BASE_ADDR+(0x0E7C) }, |
| 48 | {DDRPHY_AO_BASE_ADDR+(0x0EA0), DDRPHY_AO_BASE_ADDR+(0x0ECC) }, |
| 49 | {DDRPHY_AO_BASE_ADDR+(0x0F00), DDRPHY_AO_BASE_ADDR+(0x0F2C) },//R1 |
| 50 | {DDRPHY_AO_BASE_ADDR+(0x0F50), DDRPHY_AO_BASE_ADDR+(0x0F7C) }, |
| 51 | {DDRPHY_AO_BASE_ADDR+(0x0FA0), DDRPHY_AO_BASE_ADDR+(0x0FCC) }, |
| 52 | {DDRPHY_AO_BASE_ADDR+(0x1000), DDRPHY_AO_BASE_ADDR+(0x102C) },//R2 |
| 53 | {DDRPHY_AO_BASE_ADDR+(0x1050), DDRPHY_AO_BASE_ADDR+(0x107C) }, |
| 54 | {DDRPHY_AO_BASE_ADDR+(0x10A0), DDRPHY_AO_BASE_ADDR+(0x10CC) }, |
| 55 | }; |
| 56 | |
| 57 | U32 tbIdx; |
| 58 | |
| 59 | //mcSHOW_DUMP_INIT_RG_MSG(("fra u4RegType=%d, u4Offset=0x%x, u4Shuffle_Index=%d ==\n",u4RegType, u4Offset, u4Shuffle_Index)); |
| 60 | |
| 61 | |
| 62 | if (u4RegType >=2 && u4RegType <=3) |
| 63 | for(tbIdx=0; tbIdx<SHUFFLE_ADDR_NUM_DRAMC; tbIdx++) |
| 64 | { |
| 65 | if (u4Offset >= (ShuffleRegTableDramc[tbIdx].u4StartAddr&0x1fff) && u4Offset <= (ShuffleRegTableDramc[tbIdx].u4EndAddr&0x1fff)) |
| 66 | { |
| 67 | //mcSHOW_DUMP_INIT_RG_MSG(("fra dramc offset=0x%x (0x%x, 0x%x) ==\n",u4Offset,ShuffleRegTableDramc[tbIdx].u4StartAddr, ShuffleRegTableDramc[tbIdx].u4EndAddr)); |
| 68 | return SHU_GRP_DRAMC_OFFSET*u4Shuffle_Index; |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | if (u4RegType >=6 && u4RegType <=7) |
| 73 | for(tbIdx=0; tbIdx<SHUFFLE_ADDR_NUM_DDRPHY; tbIdx++) |
| 74 | { |
| 75 | if (u4Offset >= (ShuffleRegTableDDRPhy[tbIdx].u4StartAddr&0x1fff) && u4Offset <= (ShuffleRegTableDDRPhy[tbIdx].u4EndAddr&0x1fff)) |
| 76 | { |
| 77 | //mcSHOW_DUMP_INIT_RG_MSG(("fra phy offset=0x%x (0x%x, 0x%x) ==\n",u4Offset,ShuffleRegTableDDRPhy[tbIdx].u4StartAddr, ShuffleRegTableDDRPhy[tbIdx].u4EndAddr)); |
| 78 | return SHU_GRP_DDRPHY_OFFSET*u4Shuffle_Index; |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | return 0; |
| 83 | } |
| 84 | |
| 85 | unsigned long u4RegBaseAddrTraslate(DRAM_RANK_T eRank, unsigned long u4reg_addr, U32 u4Shuffle_Index) |
| 86 | #else |
| 87 | unsigned long u4RegBaseAddrTraslate(DRAM_RANK_T eRank, unsigned long u4reg_addr) |
| 88 | #endif |
| 89 | { |
| 90 | U32 u4Offset = u4reg_addr & 0x1fff; |
| 91 | U32 u4RegType = ((u4reg_addr-Channel_A_DRAMC_NAO_BASE_VIRTUAL) >> POS_BANK_NUM) & 0xf; |
| 92 | unsigned long u4BaseAddr = 0; |
| 93 | |
| 94 | if (u4reg_addr < Channel_A_DRAMC_NAO_BASE_VIRTUAL || u4reg_addr >= MAX_BASE_VIRTUAL) return u4reg_addr; |
| 95 | |
| 96 | if (eRank == RANK_1) |
| 97 | { |
| 98 | if (u4RegType <=1) |
| 99 | { |
| 100 | // DramC NAO Register |
| 101 | if (u4Offset >= (DRAMC_REG_RK0_DQSOSC_STATUS-DRAMC_NAO_BASE_ADDRESS) && u4Offset < (DRAMC_REG_RK1_DQSOSC_STATUS-DRAMC_NAO_BASE_ADDRESS)) |
| 102 | { |
| 103 | u4Offset += 0x100; |
| 104 | } |
| 105 | } |
| 106 | else if (u4RegType >=2 && u4RegType <=3) |
| 107 | { |
| 108 | // DramC AO Register |
| 109 | if (u4Offset >= (DRAMC_REG_RK0_DQSOSC-DRAMC_AO_BASE_ADDRESS) && u4Offset < (DRAMC_REG_RK1_DQSOSC-DRAMC_AO_BASE_ADDRESS)) |
| 110 | { |
| 111 | u4Offset += 0x100; |
| 112 | } |
| 113 | else if (u4Offset >= (DRAMC_REG_SHURK0_DQSCTL-DRAMC_AO_BASE_ADDRESS) && u4Offset < (DRAMC_REG_SHURK1_DQSCTL-DRAMC_AO_BASE_ADDRESS)) |
| 114 | { |
| 115 | #if defined(SLT) || (FT_DSIM_USED) |
| 116 | u4Offset += 0x100 + u4Shuffle_Index*SHU_GRP_DRAMC_OFFSET; |
| 117 | #else |
| 118 | u4Offset += 0x100; |
| 119 | #endif |
| 120 | } |
| 121 | else if (u4Offset >= (DRAMC_REG_SHU2RK0_DQSCTL-DRAMC_AO_BASE_ADDRESS) && u4Offset < (DRAMC_REG_SHU2RK1_DQSCTL-DRAMC_AO_BASE_ADDRESS)) |
| 122 | { |
| 123 | u4Offset += 0x100; |
| 124 | } |
| 125 | else if (u4Offset >= (DRAMC_REG_SHU3RK0_DQSCTL-DRAMC_AO_BASE_ADDRESS) && u4Offset < (DRAMC_REG_SHU3RK1_DQSCTL-DRAMC_AO_BASE_ADDRESS)) |
| 126 | { |
| 127 | u4Offset += 0x100; |
| 128 | } |
| 129 | } |
| 130 | else if (u4RegType >=4 && u4RegType <=5) |
| 131 | { |
| 132 | //PHY NAO Register |
| 133 | } |
| 134 | else |
| 135 | { |
| 136 | // PHY AO Register |
| 137 | if (u4Offset >= (DDRPHY_R0_B0_RXDVS0-DDRPHY_AO_BASE_ADDR) && u4Offset < (DDRPHY_R1_B0_RXDVS0-DDRPHY_AO_BASE_ADDR)) |
| 138 | { |
| 139 | if ((u4Offset >= (DDRPHY_RFU_0X620-DDRPHY_AO_BASE_ADDR) && u4Offset < (DDRPHY_R0_B1_RXDVS0-DDRPHY_AO_BASE_ADDR)) |
| 140 | || (u4Offset >= (DDRPHY_RFU_0X6A0-DDRPHY_AO_BASE_ADDR) && u4Offset < (DDRPHY_R1_B0_RXDVS0-DDRPHY_AO_BASE_ADDR)) |
| 141 | ) |
| 142 | { |
| 143 | //mcSHOW_DBG_MSG(("\n[u4RegBaseAddrTraslate] Not Rank address accessed in Rank address!\n")); |
| 144 | } |
| 145 | else |
| 146 | { |
| 147 | u4Offset += 0x200; |
| 148 | } |
| 149 | } |
| 150 | else if (u4Offset >= (DDRPHY_SHU1_R0_B0_DQ0-DDRPHY_AO_BASE_ADDR) && u4Offset < (DDRPHY_SHU1_R1_B0_DQ0-DDRPHY_AO_BASE_ADDR)) |
| 151 | { |
| 152 | #if defined(SLT) || (FT_DSIM_USED) |
| 153 | u4Offset += 0x100 + u4Shuffle_Index*SHU_GRP_DDRPHY_OFFSET; |
| 154 | #else |
| 155 | u4Offset += 0x100; |
| 156 | #endif |
| 157 | } |
| 158 | else if (u4Offset >= (DDRPHY_MISC_STBERR_RK0_R-DDRPHY_AO_BASE_ADDR) && u4Offset < (DDRPHY_MISC_STBERR_RK1_R-DDRPHY_AO_BASE_ADDR)) |
| 159 | { |
| 160 | u4Offset += 0x8; |
| 161 | } |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | #if defined(SLT) || (FT_DSIM_USED) |
| 166 | if (u4Shuffle_Index!=0) |
| 167 | { |
| 168 | u4Offset += u4RegShuffleOffset(u4RegType, u4Offset, u4Shuffle_Index); |
| 169 | } |
| 170 | #endif |
| 171 | |
| 172 | #if (fcFOR_CHIP_ID == fcLaurel) |
| 173 | /*const U32 arRegBaseAddrList[8] = |
| 174 | { |
| 175 | Channel_A_DRAMC_NAO_BASE_ADDRESS, |
| 176 | Channel_B_DRAMC_NAO_BASE_ADDRESS, |
| 177 | Channel_A_DRAMC_AO_BASE_ADDRESS, |
| 178 | Channel_B_DRAMC_AO_BASE_ADDRESS, |
| 179 | Channel_A_PHY_NAO_BASE_ADDRESS, |
| 180 | Channel_B_PHY_NAO_BASE_ADDRESS, |
| 181 | Channel_A_PHY_AO_BASE_ADDRESS, |
| 182 | Channel_B_PHY_AO_BASE_ADDRESS, |
| 183 | };*/ |
| 184 | switch(u4RegType) |
| 185 | { |
| 186 | case 0: |
| 187 | u4BaseAddr = Channel_A_DRAMC_NAO_BASE_ADDRESS; |
| 188 | break; |
| 189 | case 1: |
| 190 | u4BaseAddr = Channel_B_DRAMC_NAO_BASE_ADDRESS; |
| 191 | break; |
| 192 | case 2: |
| 193 | u4BaseAddr = Channel_A_DRAMC_AO_BASE_ADDRESS; |
| 194 | break; |
| 195 | case 3: |
| 196 | u4BaseAddr = Channel_B_DRAMC_AO_BASE_ADDRESS; |
| 197 | break; |
| 198 | case 4: |
| 199 | u4BaseAddr = Channel_A_PHY_NAO_BASE_ADDRESS; |
| 200 | break; |
| 201 | case 5: |
| 202 | u4BaseAddr = Channel_B_PHY_NAO_BASE_ADDRESS; |
| 203 | break; |
| 204 | case 6: |
| 205 | u4BaseAddr = Channel_A_PHY_AO_BASE_ADDRESS; |
| 206 | break; |
| 207 | case 7: |
| 208 | u4BaseAddr = Channel_B_PHY_AO_BASE_ADDRESS; |
| 209 | break; |
| 210 | } |
| 211 | |
| 212 | return (u4BaseAddr +u4Offset); |
| 213 | #else |
| 214 | #error No defined arRegBaseAddrList for your chip !!! |
| 215 | #endif |
| 216 | //mcSHOW_DBG_MSG(("\n[u4RegBaseAddrTraslate] 0x%x => 0x%x(0x%x, 0x%x)", u4reg_addr , (arRegBaseAddrList[u4RegType] +u4Offset), arRegBaseAddrList[u4RegType], u4Offset)); |
| 217 | //return (arRegBaseAddrList[u4RegType] +u4Offset); |
| 218 | } |
| 219 | |
| 220 | //------------------------------------------------------------------------- |
| 221 | /** ucDram_Register_Read |
| 222 | * DRAM register read (32-bit). |
| 223 | * @param u4reg_addr register address in 32-bit. |
| 224 | * @param pu4reg_value Pointer of register read value. |
| 225 | * @retval 0: OK, 1: FAIL |
| 226 | */ |
| 227 | //------------------------------------------------------------------------- |
| 228 | // This function need to be porting by BU requirement |
| 229 | U32 u4Dram_Register_Read(DRAMC_CTX_T *p, unsigned long u4reg_addr) |
| 230 | { |
| 231 | U32 u4reg_value; |
| 232 | |
| 233 | #if defined(SLT) || (FT_DSIM_USED) |
| 234 | u4reg_addr = u4RegBaseAddrTraslate(p->rank, u4reg_addr, p->shuffle_index); |
| 235 | #else |
| 236 | u4reg_addr = u4RegBaseAddrTraslate(p->rank, u4reg_addr); |
| 237 | #endif |
| 238 | |
| 239 | #if (FOR_DV_SIMULATION_USED==1) //DV |
| 240 | u4reg_value = register_read_c(u4reg_addr); |
| 241 | #elif (SW_CHANGE_FOR_SIMULATION==1) // whole chip sim |
| 242 | u4reg_value = (*UINT32P(u4reg_addr)); |
| 243 | #else // real chip |
| 244 | u4reg_value = (*(volatile unsigned int *)(u4reg_addr)); |
| 245 | #endif |
| 246 | return u4reg_value; |
| 247 | } |
| 248 | |
| 249 | |
| 250 | //------------------------------------------------------------------------- |
| 251 | /** ucDram_Register_Write |
| 252 | * DRAM register write (32-bit). |
| 253 | * @param u4reg_addr register address in 32-bit. |
| 254 | * @param u4reg_value register write value. |
| 255 | * @retval 0: OK, 1: FAIL |
| 256 | */ |
| 257 | //------------------------------------------------------------------------- |
| 258 | #if REG_SHUFFLE_REG_CHECK |
| 259 | extern U8 ShuffleRegCheck; |
| 260 | extern void ShuffleRegCheckProgram(U32 u4Addr); |
| 261 | #endif |
| 262 | |
| 263 | #if REG_ACCESS_NAO_DGB |
| 264 | #if (fcFOR_CHIP_ID == fcLaurel) |
| 265 | U8 Check_RG_Not_AO(U32 u4reg_addr) |
| 266 | { |
| 267 | U8 RegNotAO = 0; |
| 268 | if((u4reg_addr >= DRAMC_AO_BASE_ADDRESS) && (u4reg_addr <= DRAMC_REG_SHU4_DQSG_RETRY)) |
| 269 | { |
| 270 | } |
| 271 | else if ((u4reg_addr >= DRAMC_AO_BASE_ADDRESS + SHIFT_TO_CHB_ADDR) && (u4reg_addr <= DRAMC_REG_SHU4_DQSG_RETRY + SHIFT_TO_CHB_ADDR)) |
| 272 | { |
| 273 | } |
| 274 | else if ((u4reg_addr >= DDRPHY_AO_BASE_ADDR) && (u4reg_addr <= DDRPHY_RFU_0X1FCC)) |
| 275 | { |
| 276 | } |
| 277 | else if ((u4reg_addr >= DDRPHY_AO_BASE_ADDR + SHIFT_TO_CHB_ADDR) && (u4reg_addr <= DDRPHY_RFU_0X1FCC + SHIFT_TO_CHB_ADDR)) |
| 278 | { |
| 279 | } |
| 280 | else |
| 281 | { |
| 282 | RegNotAO = 1; |
| 283 | } |
| 284 | return RegNotAO; |
| 285 | } |
| 286 | #endif |
| 287 | #endif |
| 288 | |
| 289 | #ifdef DUMP_INIT_RG_LOG_TO_DE |
| 290 | void RG_RW_dump(U8 rw, U32 rg, U32 val) |
| 291 | { |
| 292 | U8 u1ChannelIdx, u1SectionIdx, flag=0; |
| 293 | U32 base=Channel_A_PHY_AO_BASE_ADDRESS, rg_idx; |
| 294 | |
| 295 | #if 0 |
| 296 | //mcSHOW_DBG_MSG(("=== %s: addr: 0x%x = %x\n",rw==0?"Read ":"Write",rg,val)); |
| 297 | //mcSHOW_DBG_MSG(("=== %s: addr: 0x%x = %x\n",rw==0?"R ":"W ",rg,val)); |
| 298 | mcSHOW_DBG_MSG6(("*((%s)(0x%X)) = 0x%X;\n","UINT32P",rg,val)); |
| 299 | #else |
| 300 | //mcSHOW_DBG_MSG6(("=== %s\n",__FUNCTION__)); |
| 301 | for (u1ChannelIdx=0; u1ChannelIdx<CHANNEL_NUM; u1ChannelIdx++) |
| 302 | { |
| 303 | for (u1SectionIdx=0; u1SectionIdx<4; u1SectionIdx++) |
| 304 | { |
| 305 | base = Channel_A_PHY_AO_BASE_ADDRESS + (0x8000*u1ChannelIdx) + (0x2000*u1SectionIdx); |
| 306 | rg_idx = rg-base; |
| 307 | if (rg_idx<0x2000) |
| 308 | { |
| 309 | flag = 1; |
| 310 | /* |
| 311 | #define Channel_A_DRAMC_NAO_BASE_ADDRESS 0x1022C000 |
| 312 | #define Channel_B_DRAMC_NAO_BASE_ADDRESS 0x10234000 |
| 313 | #define Channel_A_DRAMC_AO_BASE_ADDRESS 0x1022A000 |
| 314 | #define Channel_B_DRAMC_AO_BASE_ADDRESS 0x10232000 |
| 315 | #define Channel_A_PHY_NAO_BASE_ADDRESS 0x1022E000 |
| 316 | #define Channel_B_PHY_NAO_BASE_ADDRESS 0x10236000 |
| 317 | #define Channel_A_PHY_AO_BASE_ADDRESS 0x10228000 |
| 318 | #define Channel_B_PHY_AO_BASE_ADDRESS 0x10230000 |
| 319 | |
| 320 | #define DDRPHY0AO__BASE 0x10228000 |
| 321 | #define DRAMC0_AO__BASE 0x1022A000 |
| 322 | #define DRAMC0_NAO_BASE 0x1022C000 |
| 323 | #define DDRPHY0NAO_BASE 0x1022E000 |
| 324 | |
| 325 | #define DDRPHY1AO__BASE 0x10230000 |
| 326 | #define DRAMC1_AO__BASE 0x10232000 |
| 327 | #define DRAMC1_NAO_BASE 0x10234000 |
| 328 | #define DDRPHY1NAO_BASE 0x10236000 |
| 329 | */ |
| 330 | |
| 331 | //mcSHOW_DBG_MSG6(("=== %s: 0x%x:\t*((%s*)(%s + 0x%X)) = 0x%X;\n",rw==0?"Read ":"Write", rg, "unsigned int", |
| 332 | |
| 333 | mcSHOW_DUMP_INIT_RG_MSG(("*((%s)(%s + 0x%X)) = 0x%X;\n","UINT32P", |
| 334 | (base==Channel_A_PHY_AO_BASE_ADDRESS)? "DDRPHY0AO_BASE": |
| 335 | (base==Channel_A_DRAMC_AO_BASE_ADDRESS)? "DRAMC0_AO_BASE": |
| 336 | (base==Channel_A_DRAMC_NAO_BASE_ADDRESS)? "DRAMC0_NAO_BASE": |
| 337 | (base==Channel_A_PHY_NAO_BASE_ADDRESS)? "DDRPHY0NAO_BASE": |
| 338 | (base==Channel_B_PHY_AO_BASE_ADDRESS)? "DDRPHY1AO_BASE": |
| 339 | (base==Channel_B_DRAMC_AO_BASE_ADDRESS)? "DRAMC1_AO_BASE": |
| 340 | (base==Channel_B_DRAMC_NAO_BASE_ADDRESS)? "DRAMC1_NAO_BASE": |
| 341 | (base==Channel_B_PHY_NAO_BASE_ADDRESS)? "DDRPHY1NAO_BASE":"unknown", |
| 342 | rg_idx, val)); |
| 343 | |
| 344 | /* |
| 345 | mcSHOW_DBG_MSG(("=== 0x%x: *(U32*) ( %c, %s + 0x%x) = %s 0x%x\n", rg, 'A'+u1ChannelIdx, |
| 346 | (u1SectionIdx==0)?"DDRPHY AO":(u1SectionIdx==1)?"DRAMC AO":(u1SectionIdx==2)?"DRAMC NAO":"DDRPHY NAO",rg_idx,rw==0?"R":"W",val)); |
| 347 | */ |
| 348 | //mcSHOW_DBG_MSG(("=== 0x%x: base: 0x%x, ch: %c, %s\t*(U32*)(xxx + 0x%x) =\t0x%x\n", rg, base, 'A'+u1ChannelIdx, |
| 349 | // (u1SectionIdx==0)?"DDRPHY AO":(u1SectionIdx==1)?"DRAMC AO":(u1SectionIdx==2)?"DRAMC NAO":"DDRPHY NAO",rg_idx,val)); |
| 350 | //mcSHOW_DBG_MSG((" *(U32*)(xxx + 0x%x) = 0x%x\n",rg_idx,val)); |
| 351 | break; |
| 352 | } |
| 353 | } |
| 354 | if (flag) |
| 355 | break; |
| 356 | } |
| 357 | if (!flag) |
| 358 | { |
| 359 | //mcSHOW_DBG_MSG6(("=== %s: 0x%x:\t*((%s*)(0x%X)) = 0x%X;\n",rw==0?"Read ":"Write", rg, "unsigned int", rg, val)); |
| 360 | mcSHOW_DUMP_INIT_RG_MSG(("*((%s)(0x%X)) = 0x%X; // saint\n","UINT32P",rg,val)); |
| 361 | } |
| 362 | #endif |
| 363 | } |
| 364 | #endif |
| 365 | |
| 366 | //This function need to be porting by BU requirement |
| 367 | U8 ucDram_Register_Write(DRAMC_CTX_T *p, unsigned long u4reg_addr, U32 u4reg_value) |
| 368 | { |
| 369 | U8 ucstatus; |
| 370 | ucstatus = 0; //for SW_CHANGE_FOR_SIMULATION |
| 371 | #if defined(SLT) || FT_DSIM_USED |
| 372 | #ifdef DUMP_INIT_RG_LOG_TO_DE |
| 373 | U32 u4reg_addr_shu0 = u4reg_addr; |
| 374 | #endif |
| 375 | #endif |
| 376 | #if REG_ACCESS_NAO_DGB |
| 377 | U8 RegNotAO = 0; |
| 378 | #endif |
| 379 | |
| 380 | #if __ETT__ |
| 381 | if(u1IsLP4Family(p->dram_type)) |
| 382 | { |
| 383 | CheckDramcWBR(u4reg_addr); |
| 384 | } |
| 385 | #if REG_ACCESS_NAO_DGB |
| 386 | RegNotAO = Check_RG_Not_AO(u4reg_addr); |
| 387 | #endif |
| 388 | #endif |
| 389 | |
| 390 | #if defined(SLT) || FT_DSIM_USED |
| 391 | #ifdef DUMP_INIT_RG_LOG_TO_DE |
| 392 | if (p->shuffle_index!=0) u4reg_addr_shu0 = u4RegBaseAddrTraslate(p->rank, u4reg_addr_shu0, 0); |
| 393 | #endif |
| 394 | |
| 395 | u4reg_addr = u4RegBaseAddrTraslate(p->rank, u4reg_addr, p->shuffle_index); |
| 396 | #else |
| 397 | u4reg_addr = u4RegBaseAddrTraslate(p->rank, u4reg_addr); |
| 398 | #endif |
| 399 | |
| 400 | #ifdef DUMP_INIT_RG_LOG_TO_DE |
| 401 | if (gDUMP_INIT_RG_LOG_TO_DE_RG_log_flag == 1) |
| 402 | { |
| 403 | //mcSHOW_DUMP_INIT_RG_MSG(("*((UINT32P)(0x%x)) = 0x%x;\n",u4reg_addr,u4reg_value)); |
| 404 | RG_RW_dump(1,u4reg_addr,u4reg_value); |
| 405 | mcDELAY_MS(1); |
| 406 | } |
| 407 | #endif |
| 408 | |
| 409 | |
| 410 | #if (FOR_DV_SIMULATION_USED==1) //DV |
| 411 | register_write_c(u4reg_addr,u4reg_value); |
| 412 | #elif (SW_CHANGE_FOR_SIMULATION==1) //whole chip sim |
| 413 | (*(volatile unsigned int *)u4reg_addr) = u4reg_value; |
| 414 | #else |
| 415 | (*(volatile unsigned int *)u4reg_addr) = u4reg_value;//real chip |
| 416 | dsb(); |
| 417 | #endif |
| 418 | |
| 419 | #if defined(SLT) || FT_DSIM_USED |
| 420 | #ifdef DUMP_INIT_RG_LOG_TO_DE |
| 421 | (*(volatile unsigned int *)u4reg_addr_shu0) = u4reg_value;//real chip |
| 422 | dsb(); |
| 423 | #endif |
| 424 | #endif |
| 425 | |
| 426 | #if REG_ACCESS_PORTING_DGB |
| 427 | if(RegLogEnable) |
| 428 | { |
| 429 | mcSHOW_DBG_MSG(("\n[REG_ACCESS_PORTING_DBG] ucDramC_Register_Write Reg(0x%X) = 0x%X\n", u4reg_addr, u4reg_value)); |
| 430 | mcFPRINTF((fp_A60501, "\n[REG_ACCESS_PORTING_DBG] ucDramC_Register_Write Reg(0x%X) = 0x%X\n", u4reg_addr, u4reg_value)); |
| 431 | //mcFPRINTF((fp_A60501, "\nRISCWrite ('h%05X , 32'h%X);\n",u4reg_addr&0xFFFFF, u4reg_value)); |
| 432 | } |
| 433 | #endif |
| 434 | #if REG_ACCESS_NAO_DGB |
| 435 | if(RegNotAO) |
| 436 | { |
| 437 | mcSHOW_DBG_MSG(("\n[REG_ACCESS_NAO_DGB] ucDramC_Register_Write Reg(0x%X) = 0x%X\n", u4reg_addr, u4reg_value)); |
| 438 | } |
| 439 | #endif |
| 440 | #if REG_SHUFFLE_REG_CHECK |
| 441 | if(ShuffleRegCheck) |
| 442 | { |
| 443 | ShuffleRegCheckProgram(u4reg_addr); |
| 444 | } |
| 445 | #endif |
| 446 | return ucstatus; |
| 447 | } |
| 448 | |
| 449 | #if SW_CHANGE_FOR_SIMULATION |
| 450 | U32 u4IO32ReadFldAlign2(DRAMC_CTX_T *p, U32 reg32, U32 fld) |
| 451 | { |
| 452 | if(Fld_ac(fld)==AC_FULLDW) |
| 453 | { |
| 454 | return u4IO32Read4B(reg32); |
| 455 | } |
| 456 | else |
| 457 | { |
| 458 | return ((u4IO32Read4B(reg32)&Fld2Msk32(fld))>>Fld_shft(fld)); |
| 459 | } |
| 460 | } |
| 461 | |
| 462 | void vIO32WriteFldAlign2(DRAMC_CTX_T *p, U32 reg32, U32 val, U32 fld) |
| 463 | { |
| 464 | if(Fld_ac(fld)==AC_FULLDW) |
| 465 | { |
| 466 | vIO32Write4B((reg32),(val)); |
| 467 | } |
| 468 | else |
| 469 | { |
| 470 | vIO32Write4BMsk((reg32),((U32)(val)<<Fld_shft(fld)),Fld2Msk32(fld)); |
| 471 | } |
| 472 | } |
| 473 | |
| 474 | void vIO32WriteFldAlign_All2(DRAMC_CTX_T *p, U32 reg32, U32 val, U32 fld) |
| 475 | { |
| 476 | if(Fld_ac(fld)==AC_FULLDW) |
| 477 | { |
| 478 | vIO32Write4B_All((reg32),(val)); |
| 479 | } |
| 480 | else |
| 481 | { |
| 482 | vIO32Write4BMsk_All((reg32),((U32)(val)<<Fld_shft(fld)),Fld2Msk32(fld)); |
| 483 | } |
| 484 | } |
| 485 | #endif |
| 486 | |
| 487 | void vIO32Write4BMsk2(DRAMC_CTX_T *p, unsigned long reg32, U32 val32, U32 msk32) |
| 488 | { |
| 489 | U32 u4Val; |
| 490 | |
| 491 | val32 &=msk32; |
| 492 | |
| 493 | u4Val = u4Dram_Register_Read(p, reg32); |
| 494 | u4Val = ((u4Val &~msk32)|val32); |
| 495 | ucDram_Register_Write(p, reg32, u4Val); |
| 496 | } |
| 497 | |
| 498 | |
| 499 | void vIO32Write4B_All2(DRAMC_CTX_T *p, unsigned long reg32, U32 val32) |
| 500 | { |
| 501 | U8 ii, u1AllCount; |
| 502 | U32 u4RegType = (reg32 & (0xf <<POS_BANK_NUM)); |
| 503 | |
| 504 | #if __ETT__ |
| 505 | if (GetDramcBroadcast()==DRAMC_BROADCAST_ON) |
| 506 | { |
| 507 | mcSHOW_ERR_MSG(("Error! virtual address 0x%x don't have to use write_all when Dramc WBR is on\n", reg32)); |
| 508 | while(1); |
| 509 | } |
| 510 | #endif |
| 511 | |
| 512 | reg32 &= 0xffff; // remove channel information |
| 513 | |
| 514 | #if CHANNEL_NUM==4 |
| 515 | u1AllCount =4; |
| 516 | #else |
| 517 | u1AllCount =2; |
| 518 | #endif |
| 519 | |
| 520 | if(u4RegType >=Channel_A_PHY_AO_BASE_VIRTUAL)//PHY |
| 521 | { |
| 522 | reg32 += Channel_A_PHY_AO_BASE_VIRTUAL; |
| 523 | } |
| 524 | else if(u4RegType >=Channel_A_DRAMC_AO_BASE_VIRTUAL)// DramC AO |
| 525 | { |
| 526 | reg32 += Channel_A_DRAMC_AO_BASE_VIRTUAL; |
| 527 | } |
| 528 | else // DramC NAO |
| 529 | { |
| 530 | reg32 += Channel_A_DRAMC_NAO_BASE_VIRTUAL; |
| 531 | } |
| 532 | |
| 533 | for(ii=0; ii< u1AllCount; ii++) |
| 534 | { |
| 535 | vIO32Write4B(reg32+((U32)ii<<POS_BANK_NUM), val32); |
| 536 | } |
| 537 | |
| 538 | #if 0 |
| 539 | // debug |
| 540 | //mcSHOW_DBG_MSG(("RISCWrite : address %05x data %08x\n", reg32&0x000fffff, val32)); |
| 541 | mcFPRINTF((fp_A60501, "RISCWrite : address %05x data %08x wait 0\n", reg32&0x000fffff, val32)); |
| 542 | //mcSHOW_DBG_MSG(("RISCWrite : address %05x data %08x\n", (reg32+((U32)1<<POS_BANK_NUM))&0x000fffff, val32)); |
| 543 | mcFPRINTF((fp_A60501, "RISCWrite : address %05x data %08x wait 0\n", (reg32+((U32)1<<POS_BANK_NUM))&0x000fffff, val32)); |
| 544 | //mcSHOW_DBG_MSG(("RISCWrite : address %05x data %08x\n", (reg32+((U32)2<<POS_BANK_NUM))&0x000fffff, val32)); |
| 545 | mcFPRINTF((fp_A60501, "RISCWrite : address %05x data %08x wait 0\n", (reg32+((U32)2<<POS_BANK_NUM))&0x000fffff, val32)); |
| 546 | #endif |
| 547 | } |
| 548 | |
| 549 | void vIO32Write4BMsk_All2(DRAMC_CTX_T *p, unsigned long reg32, U32 val32, U32 msk32) |
| 550 | { |
| 551 | U32 u4Val; |
| 552 | U8 ii, u1AllCount; |
| 553 | U32 u4RegType = (reg32 & (0xf <<POS_BANK_NUM)); |
| 554 | |
| 555 | #if __ETT__ |
| 556 | if (GetDramcBroadcast()==DRAMC_BROADCAST_ON) |
| 557 | { |
| 558 | mcSHOW_ERR_MSG(("Error! virtual address 0x%x don't have to use write_all when Dramc WBR is on\n", reg32)); |
| 559 | while(1); |
| 560 | } |
| 561 | #endif |
| 562 | |
| 563 | reg32 &= 0xffff; // remove channel information |
| 564 | |
| 565 | #if CHANNEL_NUM==4 |
| 566 | u1AllCount =4; |
| 567 | #else |
| 568 | u1AllCount =2; |
| 569 | #endif |
| 570 | |
| 571 | if(u4RegType >=Channel_A_PHY_AO_BASE_VIRTUAL)//PHY |
| 572 | { |
| 573 | reg32 += Channel_A_PHY_AO_BASE_VIRTUAL; |
| 574 | } |
| 575 | else if(u4RegType >=Channel_A_DRAMC_AO_BASE_VIRTUAL)// DramC AO |
| 576 | { |
| 577 | reg32 += Channel_A_DRAMC_AO_BASE_VIRTUAL; |
| 578 | } |
| 579 | else // DramC NAO |
| 580 | { |
| 581 | reg32 += Channel_A_DRAMC_NAO_BASE_VIRTUAL; |
| 582 | } |
| 583 | |
| 584 | for(ii=0; ii< u1AllCount; ii++) |
| 585 | { |
| 586 | u4Val = u4Dram_Register_Read(p, reg32+((U32)ii<<POS_BANK_NUM)); |
| 587 | u4Val = ((u4Val &~msk32)|val32); |
| 588 | ucDram_Register_Write(p, reg32+((U32)ii<<POS_BANK_NUM), u4Val); |
| 589 | } |
| 590 | } |
| 591 | |
| 592 | static void reg_dummy_read(void) |
| 593 | { |
| 594 | #if (!FOR_DV_SIMULATION_USED) |
| 595 | int a = *(unsigned int *)(EMI_CONA); |
| 596 | a++; |
| 597 | #endif |
| 598 | } |
| 599 | |
| 600 | void mt_reg_sync_writel(unsigned int v, volatile unsigned int *a) |
| 601 | { |
| 602 | #if (!FOR_DV_SIMULATION_USED) |
| 603 | *(volatile unsigned int *)(a) = (v); |
| 604 | dsb(); |
| 605 | reg_dummy_read(); |
| 606 | #endif |
| 607 | } |
| 608 | |