hv_comm_MemParser.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456
  1. /**
  2. * @file hv_mem_Parser.c
  3. * @brief get pq table offset & size
  4. *
  5. * @verbatim
  6. * ==============================================================================
  7. * ##### How to use #####
  8. * ==============================================================================
  9. *
  10. *
  11. * @endverbatim
  12. *
  13. * @author HiView SoC Software Team
  14. * @version 1.0.0
  15. * @date 2023-05-18
  16. */
  17. #include "hv_comm_MemParser.h"
  18. #include "ProjectConfig.h"
  19. #include "hv_drv_Osd.h"
  20. #include "hv_drv_Flash.h"
  21. /* pq partition has decompressed or not */
  22. static CHAR8 s_cPartDecompressed = 0;
  23. __attribute__((long_call)) extern INT32 Hv_Boot_LzssDecompress(char *pcSrc, char *pcDst, INT32 iChanegeEndian, INT32 iSize);
  24. __attribute__((long_call))unsigned char Hv_Ddr_Type(void);
  25. /**
  26. * @brief get pq table addr & size
  27. * @param[in] enType: PqTableType
  28. * @param[in] uiIndex: index
  29. * @param[out] puiAddr: table addr
  30. * @param[out] puiSize: table size
  31. */
  32. Status Hv_Pq_GetTable(PqTableType enType, UINT32 uiIndex, UINT32 *puiAddr, UINT32 *puiSize)
  33. {
  34. UINT32 uiTempAddr = 0;
  35. UINT32 uiStartAddr = 0;
  36. UINT32 uiTempType = 0;
  37. UINT32 uiTempInode = 0;
  38. UINT32 uiOffset = 0;
  39. uiTempAddr = HV_MEMORY_CONFIG_PQ_DATA_START;
  40. uiStartAddr = uiTempAddr;
  41. HV_LOGV("base addr %x find for %d %d\n", uiTempAddr, enType, uiIndex);
  42. for (;;)
  43. {
  44. HV_LOGV("header addr %x\n", uiTempAddr);
  45. if (uiTempAddr > uiStartAddr + 0x1000)
  46. {
  47. HV_LOGW("no valid head for type %d, %d", enType, uiIndex);
  48. }
  49. /* check header magic */
  50. if (*(UCHAR8 *)(uiTempAddr) != 'H')
  51. {
  52. return HV_FAILURE;
  53. }
  54. if (*(UCHAR8 *)(uiTempAddr + 1) != 'E')
  55. {
  56. return HV_FAILURE;
  57. }
  58. if (*(UCHAR8 *)(uiTempAddr + 2) != 'A')
  59. {
  60. return HV_FAILURE;
  61. }
  62. if (*(UCHAR8 *)(uiTempAddr + 3) != 'D')
  63. {
  64. return HV_FAILURE;
  65. }
  66. /* check type */
  67. uiTempType = *(UCHAR8 *)(uiTempAddr + 4) << 8;
  68. uiTempType |= *(UCHAR8 *)(uiTempAddr + 5) << 0;
  69. uiTempInode = *(UCHAR8 *)(uiTempAddr + 6) << 8;
  70. uiTempInode |= *(UCHAR8 *)(uiTempAddr + 7) << 0;
  71. HV_LOGV("header need %d, act %d \n", enType, uiTempType);
  72. if (uiTempType < enType)
  73. {
  74. /* get next header */
  75. uiTempAddr = uiTempAddr + 0x10;
  76. continue;
  77. }
  78. else if (uiTempType > enType)
  79. {
  80. break;
  81. }
  82. else
  83. {
  84. if (uiTempInode < uiIndex)
  85. {
  86. /* get next header */
  87. uiTempAddr = uiTempAddr + 0x10;
  88. continue;
  89. }
  90. else if (uiTempInode > uiIndex)
  91. {
  92. break;
  93. }
  94. else
  95. {
  96. *puiSize = *(UCHAR8 *)(uiTempAddr + 8) << 24;
  97. *puiSize |= *(UCHAR8 *)(uiTempAddr + 9) << 16;
  98. *puiSize |= *(UCHAR8 *)(uiTempAddr + 10) << 8;
  99. *puiSize |= *(UCHAR8 *)(uiTempAddr + 11) << 0;
  100. uiOffset = *(UCHAR8 *)(uiTempAddr + 12) << 24;
  101. uiOffset |= *(UCHAR8 *)(uiTempAddr + 13) << 16;
  102. uiOffset |= *(UCHAR8 *)(uiTempAddr + 14) << 8;
  103. uiOffset |= *(UCHAR8 *)(uiTempAddr + 15) << 0;
  104. *puiAddr = uiOffset + HV_MEMORY_CONFIG_PQ_DATA_START;
  105. HV_LOGV("header uiOffset %x, size %d \n", uiOffset, *puiSize);
  106. return HV_SUCCESS;
  107. }
  108. }
  109. }
  110. return HV_FAILURE;
  111. }
  112. /**
  113. * @brief show pq table addr & size
  114. */
  115. Status Hv_Pq_ShowTable(void)
  116. {
  117. UINT32 uiTempAddr = 0;
  118. UINT32 uiStartAddr = 0;
  119. UINT32 uiTempType = 0;
  120. UINT32 uiTempInode = 0;
  121. UINT32 uiOffset = 0;
  122. UINT32 uiSize = 0;
  123. uiTempAddr = HV_MEMORY_CONFIG_PQ_DATA_START;
  124. uiStartAddr = uiTempAddr;
  125. HV_LOGI("base addr %x\n", uiTempAddr);
  126. for (;;)
  127. {
  128. HV_LOGI("header addr %x\n", uiTempAddr);
  129. if (uiTempAddr > uiStartAddr + 0x1000)
  130. {
  131. break;
  132. }
  133. /* check header magic */
  134. if (*(UCHAR8 *)(uiTempAddr) != 'H')
  135. {
  136. return HV_FAILURE;
  137. }
  138. if (*(UCHAR8 *)(uiTempAddr + 1) != 'E')
  139. {
  140. return HV_FAILURE;
  141. }
  142. if (*(UCHAR8 *)(uiTempAddr + 2) != 'A')
  143. {
  144. return HV_FAILURE;
  145. }
  146. if (*(UCHAR8 *)(uiTempAddr + 3) != 'D')
  147. {
  148. return HV_FAILURE;
  149. }
  150. /* check type */
  151. uiTempType = *(UCHAR8 *)(uiTempAddr + 4) << 8;
  152. uiTempType |= *(UCHAR8 *)(uiTempAddr + 5) << 0;
  153. uiTempInode = *(UCHAR8 *)(uiTempAddr + 6) << 8;
  154. uiTempInode |= *(UCHAR8 *)(uiTempAddr + 7) << 0;
  155. uiSize = *(UCHAR8 *)(uiTempAddr + 8) << 24;
  156. uiSize |= *(UCHAR8 *)(uiTempAddr + 9) << 16;
  157. uiSize |= *(UCHAR8 *)(uiTempAddr + 10) << 8;
  158. uiSize |= *(UCHAR8 *)(uiTempAddr + 11) << 0;
  159. uiOffset = *(UCHAR8 *)(uiTempAddr + 12) << 24;
  160. uiOffset |= *(UCHAR8 *)(uiTempAddr + 13) << 16;
  161. uiOffset |= *(UCHAR8 *)(uiTempAddr + 14) << 8;
  162. uiOffset |= *(UCHAR8 *)(uiTempAddr + 15) << 0;
  163. HV_LOGI("header %d, index %d, offset %x, size %x\n", uiTempType, uiTempInode, uiOffset, uiSize);
  164. uiTempAddr = uiTempAddr + 0x10;
  165. }
  166. return HV_SUCCESS;
  167. }
  168. /**
  169. * @brief get code superblock version.
  170. */
  171. UINT32 Hv_Comm_GetCodeVersion(void)
  172. {
  173. UINT32 uiVersion = 0;
  174. UCHAR8 aucData[4] = {0};
  175. Hv_Drv_Flash_OnlyRead((HV_FLASH_CONFIG_SUPERBLOCK_START + 0x40 + 0x1c), aucData, 4);
  176. uiVersion = aucData[0]<<24 | aucData[1]<<16 | aucData[2]<<8 | aucData[3];
  177. HV_LOGV(">>> get version %x\n", uiVersion);
  178. return uiVersion;
  179. }
  180. void Hv_Comm_Copy(INT32 *iSrc, INT32 *iDst, INT32 iSize)
  181. {
  182. INT32 iLoop = 0;
  183. for (iLoop=0; iLoop<iSize/4; iLoop++)
  184. {
  185. *iDst = *iSrc;
  186. iSrc++;
  187. iDst++;
  188. }
  189. return;
  190. }
  191. void Hv_Comm_CopyLogoData(void)
  192. {
  193. Hv_Comm_Copy((INT32 *)(HV_FLASH_CONFIG_LOGO_PART_START+ HV_FLASH_CONFIG_START_XIP),(INT32 *)(HV_MEMORY_CONFIG_OSD_LOGO_DDR_START), HV_FLASH_CONFIG_LOGO_PART_SIZE);
  194. return;
  195. }
  196. UINT32 Hv_Board_Memory_CalculateOsdBlendSize(VOID)
  197. {
  198. #if (HV_PROJECT_CONFIG_OSD_DDRPATH == HV_CONFIG_ON)
  199. return (PANEL_OSD_H_ACTIVE * PANEL_OSD_V_ACTIVE * HV_OSD_CONFIG_DDR_PIXEL_BYTES * 2);
  200. #else
  201. return 0;
  202. #endif
  203. }
  204. UINT32 Hv_Board_Memory_CalculateOsdRotationSize(VOID)
  205. {
  206. #if (HV_PROJECT_CONFIG_OSD_ROTATION == HV_CONFIG_ON)
  207. return (HV_OSD_CONFIG_ROTATION_H_ACTIVE * HV_OSD_CONFIG_ROTATION_V_ACTIVE * HV_OSD_CONFIG_DDR_PIXEL_BYTES);
  208. #else
  209. return 0;
  210. #endif
  211. }
  212. UINT32 Hv_Board_Memory_CalculateOsdGraphicSize(VOID)
  213. {
  214. #if (HV_PROJECT_CONFIG_OSD_GRAPHIC == HV_CONFIG_ON)
  215. return (HV_OSD_CONFIG_GRAPHIC_H_ACTIVE * HV_OSD_CONFIG_GRAPHIC_V_ACTIVE * HV_OSD_CONFIG_GRAPHIC_PIXEL_BYTES);
  216. #else
  217. return 0;
  218. #endif
  219. }
  220. UINT32 Hv_Board_Memory_CalculateSizeForOsd(VOID)
  221. {
  222. UINT32 uiDDRSize = Hv_Board_Memory_CalculateOsdBlendSize();
  223. UINT32 uiRotationSize = Hv_Board_Memory_CalculateOsdRotationSize();
  224. UINT32 uiGraphicSize = Hv_Board_Memory_CalculateOsdGraphicSize();
  225. HV_LOGV("Osd DDR size: %u", uiDDRSize);
  226. HV_LOGV("OSD Rotation Size: %u", uiRotationSize);
  227. HV_LOGV("OSD Graphic Size: %u", uiGraphicSize);
  228. return uiDDRSize + uiRotationSize + uiGraphicSize;
  229. }
  230. FLOAT32 Hv_Board_Memory_CalculateBandForOsd(UINT32 uiVideoFrameRate)
  231. {
  232. UCHAR8 ucOsdFrameRate = 0;
  233. FLOAT32 fBandWidth = 0;
  234. UINT32 fBandDDRR = 0;
  235. UINT32 fBandDDRW = 0;
  236. UINT32 fBandGraphic = 0;
  237. UCHAR8 ucBits = 0;
  238. ucOsdFrameRate = Hv_Drv_OsdFrame_GetOsdFrameRate(uiVideoFrameRate, HV_FALSE);
  239. #if (HV_PROJECT_CONFIG_OSD_DDRPATH == HV_CONFIG_ON)
  240. ucBits = Hv_Drv_OsdCommon_GetPixelBits(HV_OSD_CONFIG_DDR_FORMAT);
  241. fBandDDRW = (ucOsdFrameRate * PANEL_OSD_H_ACTIVE * PANEL_OSD_V_TOTAL * ucBits) / 8;
  242. HV_LOGV("DDR Write Bandwidth: %u", fBandDDRW);
  243. fBandDDRW /= 1000000;
  244. fBandDDRR = (uiVideoFrameRate * PANEL_OSD_H_ACTIVE * PANEL_V_TOTAL_TYP * ucBits) / 8;
  245. HV_LOGV("DDR Read Bandwidth: %u", fBandDDRR);
  246. fBandDDRR /= 1000000;
  247. #endif /* HV_PROJECT_CONFIG_OSD_DDRPATH */
  248. #if (HV_PROJECT_CONFIG_OSD_GRAPHIC == HV_CONFIG_ON)
  249. ucBits = Hv_Drv_OsdCommon_GetPixelBits(HV_OSD_CONFIG_GRAPHIC_FORMAT);
  250. fBandGraphic = (ucOsdFrameRate * PANEL_OSD_H_ACTIVE * PANEL_OSD_V_TOTAL * ucBits) / 8;
  251. HV_LOGV("Graphic Read Bandwidth: %u", fBandGraphic);
  252. fBandGraphic /= 1000000;
  253. #endif
  254. fBandWidth = fBandDDRR + fBandDDRW + fBandGraphic;
  255. return fBandWidth;
  256. }
  257. /* 3840*2250*24/8/5.83 */
  258. UINT32 Hv_Board_Memory_CalODSize(VOID)
  259. {
  260. FLOAT32 ufOdSize = 0;
  261. UINT32 uiOdSize = 0;
  262. #ifdef CONFIG_USER_PANEL_RESOLUTION_TYPE_UHD
  263. uiOdSize = 0x413000;
  264. #endif
  265. #ifdef CONFIG_USER_PANEL_RESOLUTION_TYPE_QHD
  266. uiOdSize = 0x1D0000;
  267. #endif
  268. #ifdef CONFIG_USER_PANEL_RESOLUTION_TYPE_FHD
  269. uiOdSize = 0x110000;
  270. #endif
  271. #ifdef CONFIG_USER_PANEL_RESOLUTION_TYPE_CUSTOMIZE
  272. ufOdSize = HV_PROJECT_CONFIG_PANEL_H_ACTIVE_CUSTOMIZE * HV_PROJECT_CONFIG_PANEL_V_ACTIVE_CUSTOMIZE * 1.1 * 24 /8 /5.83;
  273. uiOdSize = ((UINT32)ufOdSize + 0xFFF) >> 12 << 12;
  274. HV_LOGI("OD size: %x\n", uiOdSize);
  275. #endif
  276. return uiOdSize;
  277. }
  278. /* 3840*2250*24/8/5.83 */
  279. FLOAT32 Hv_Board_Memory_CalODBand(VOID)
  280. {
  281. FLOAT32 ufOdBand = 0;
  282. #ifdef CONFIG_USER_PANEL_RESOLUTION_TYPE_UHD
  283. ufOdBand = 71.14;
  284. #endif
  285. #ifdef CONFIG_USER_PANEL_RESOLUTION_TYPE_QHD
  286. ufOdBand = 31.20;
  287. #endif
  288. #ifdef CONFIG_USER_PANEL_RESOLUTION_TYPE_FHD
  289. ufOdBand = 17.79;
  290. #endif
  291. #ifdef CONFIG_USER_PANEL_RESOLUTION_TYPE_CUSTOMIZE
  292. ufOdBand = HV_PROJECT_CONFIG_PANEL_H_ACTIVE_CUSTOMIZE * HV_PROJECT_CONFIG_PANEL_V_ACTIVE_CUSTOMIZE * 1.1 *24 *2 /5.83 /1000 /1000;
  293. HV_LOGI("OD band: %x\n", ufOdBand);
  294. #endif
  295. return ufOdBand;
  296. }
  297. /* 30*481*271/8 */
  298. UINT32 Hv_Board_Memory_CalDemuraSize(VOID)
  299. {
  300. FLOAT32 ufDemuraSize = 0;
  301. UINT32 uiDemuraSize = 0;
  302. #ifdef DEMURA_COLOR_MODE
  303. UCHAR8 ucColorModeMul = (DEMURA_COLOR_MODE == 0) ? 1 : 3;
  304. #else
  305. UCHAR8 ucColorModeMul = 1;
  306. #endif
  307. #ifdef CONFIG_USER_PANEL_RESOLUTION_TYPE_UHD
  308. uiDemuraSize = 0x80000;
  309. #endif
  310. #ifdef CONFIG_USER_PANEL_RESOLUTION_TYPE_QHD
  311. uiDemuraSize = 0x36000;
  312. #endif
  313. #ifdef CONFIG_USER_PANEL_RESOLUTION_TYPE_FHD
  314. uiDemuraSize = 0x1F000;
  315. #endif
  316. #ifdef CONFIG_USER_PANEL_RESOLUTION_TYPE_CUSTOMIZE
  317. uiDemuraSize = (HV_PROJECT_CONFIG_PANEL_H_ACTIVE_CUSTOMIZE+7)/8 * (HV_PROJECT_CONFIG_PANEL_V_ACTIVE_CUSTOMIZE+7)/8;
  318. ufDemuraSize = uiDemuraSize * 1.1 * 30 /8;
  319. uiDemuraSize = ((UINT32)ufDemuraSize + 0xFFF) >> 12 << 12;
  320. HV_LOGI("Demura size: %x\n", uiDemuraSize);
  321. #endif
  322. return (uiDemuraSize * ucColorModeMul);
  323. }
  324. /* 321*186*30*Freq/1000/1000 */
  325. FLOAT32 Hv_Board_Memory_CalDemuraBand(VOID)
  326. {
  327. FLOAT32 ufDemuraBand = 0;
  328. #ifdef DEMURA_COLOR_MODE
  329. UCHAR8 ucColorModeMul = (DEMURA_COLOR_MODE == 0) ? 1 : 3;
  330. #else
  331. UCHAR8 ucColorModeMul = 1;
  332. #endif
  333. #ifdef CONFIG_USER_PANEL_RESOLUTION_TYPE_UHD
  334. ufDemuraBand = 4.07;
  335. #endif
  336. #ifdef CONFIG_USER_PANEL_RESOLUTION_TYPE_QHD
  337. ufDemuraBand = 1.80;
  338. #endif
  339. #ifdef CONFIG_USER_PANEL_RESOLUTION_TYPE_FHD
  340. ufDemuraBand = 1.03;
  341. #endif
  342. #ifdef CONFIG_USER_PANEL_RESOLUTION_TYPE_CUSTOMIZE
  343. ufDemuraBand = (HV_PROJECT_CONFIG_PANEL_H_ACTIVE_CUSTOMIZE+7)/8 * (HV_PROJECT_CONFIG_PANEL_V_ACTIVE_CUSTOMIZE+7)/8 * 1.1 *30 /1000 /1000;
  344. HV_LOGI("Demura band: %x\n", ufDemuraBand);
  345. #endif
  346. return (ufDemuraBand * ucColorModeMul);
  347. }
  348. /* return address */
  349. UINT32 Hv_Board_Memory_FRCStart(void)
  350. {
  351. UINT32 uiDDRStart = 0;
  352. UINT32 uiOsdSize = 0;
  353. UINT32 uiOdSize = 0;
  354. uiDDRStart += HV_MEMORY_CONFIG_STATIC_DDR_SIZE;
  355. uiDDRStart += Hv_Board_Memory_CalDemuraSize();
  356. uiOsdSize = Hv_Board_Memory_CalculateSizeForOsd();
  357. uiOdSize = Hv_Board_Memory_CalODSize();
  358. if (uiOsdSize < uiOdSize)
  359. {
  360. uiOsdSize = uiOdSize;
  361. }
  362. uiDDRStart += uiOsdSize;
  363. return PHY_TO_VDM(uiDDRStart);
  364. }
  365. /* return bytes */
  366. UINT32 Hv_Board_Memory_RemainSizeForFRC(void)
  367. {
  368. UINT32 uiFRCSize = 0;
  369. uiFRCSize = PHY_TO_VDM(HV_MEMORY_CONFIG_DDR_SIZE) - Hv_Board_Memory_FRCStart();
  370. return uiFRCSize;
  371. }
  372. /* return xxMbit/s */
  373. UINT32 Hv_Board_Memory_RemainBandForFRC(UINT32 PanelFreq)
  374. {
  375. float fDDRBand = 0;
  376. float fOsdBand = 0;
  377. float fOdBand = 0;
  378. UINT32 uiFrcBand = 0;
  379. UINT32 uiDDRFreq = 0;
  380. float fDDRRatio = 0;
  381. UCHAR8 ucDDRType = 0;
  382. ucDDRType = Hv_Ddr_Type();
  383. if (ucDDRType)
  384. {
  385. uiDDRFreq = HV_MEMORY_CONFIG_DDR3_FREQ;
  386. fDDRRatio = HV_MEMORY_CONFIG_DDR3_UTILIZATION_RATIO;
  387. }
  388. else
  389. {
  390. uiDDRFreq = HV_MEMORY_CONFIG_DDR2_FREQ;
  391. fDDRRatio = HV_MEMORY_CONFIG_DDR2_UTILIZATION_RATIO;
  392. }
  393. fDDRBand += HV_MEMORY_CONFIG_STATIC_DDR_BANDWIDTH;
  394. fDDRBand += PanelFreq * Hv_Board_Memory_CalDemuraBand();
  395. fOsdBand = Hv_Board_Memory_CalculateBandForOsd(PanelFreq);
  396. fOdBand = Hv_Board_Memory_CalODBand() * PanelFreq;
  397. if (fOsdBand < fOdBand)
  398. {
  399. fOsdBand = fOdBand;
  400. }
  401. fDDRBand += fOsdBand;
  402. uiFrcBand = (UINT32 )(uiDDRFreq * HV_MEMORY_CONFIG_DDR_PHY * fDDRRatio - fDDRBand);
  403. return uiFrcBand;
  404. }