123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456 |
- /**
- * @file hv_mem_Parser.c
- * @brief get pq table offset & size
- *
- * @verbatim
- * ==============================================================================
- * ##### How to use #####
- * ==============================================================================
- *
- *
- * @endverbatim
- *
- * @author HiView SoC Software Team
- * @version 1.0.0
- * @date 2023-05-18
- */
- #include "hv_comm_MemParser.h"
- #include "ProjectConfig.h"
- #include "hv_drv_Osd.h"
- #include "hv_drv_Flash.h"
- /* pq partition has decompressed or not */
- static CHAR8 s_cPartDecompressed = 0;
- __attribute__((long_call)) extern INT32 Hv_Boot_LzssDecompress(char *pcSrc, char *pcDst, INT32 iChanegeEndian, INT32 iSize);
- __attribute__((long_call))unsigned char Hv_Ddr_Type(void);
- /**
- * @brief get pq table addr & size
- * @param[in] enType: PqTableType
- * @param[in] uiIndex: index
- * @param[out] puiAddr: table addr
- * @param[out] puiSize: table size
- */
- Status Hv_Pq_GetTable(PqTableType enType, UINT32 uiIndex, UINT32 *puiAddr, UINT32 *puiSize)
- {
- UINT32 uiTempAddr = 0;
- UINT32 uiStartAddr = 0;
- UINT32 uiTempType = 0;
- UINT32 uiTempInode = 0;
- UINT32 uiOffset = 0;
- uiTempAddr = HV_MEMORY_CONFIG_PQ_DATA_START;
- uiStartAddr = uiTempAddr;
- HV_LOGV("base addr %x find for %d %d\n", uiTempAddr, enType, uiIndex);
- for (;;)
- {
- HV_LOGV("header addr %x\n", uiTempAddr);
- if (uiTempAddr > uiStartAddr + 0x1000)
- {
- HV_LOGW("no valid head for type %d, %d", enType, uiIndex);
- }
- /* check header magic */
- if (*(UCHAR8 *)(uiTempAddr) != 'H')
- {
- return HV_FAILURE;
- }
- if (*(UCHAR8 *)(uiTempAddr + 1) != 'E')
- {
- return HV_FAILURE;
- }
- if (*(UCHAR8 *)(uiTempAddr + 2) != 'A')
- {
- return HV_FAILURE;
- }
- if (*(UCHAR8 *)(uiTempAddr + 3) != 'D')
- {
- return HV_FAILURE;
- }
- /* check type */
- uiTempType = *(UCHAR8 *)(uiTempAddr + 4) << 8;
- uiTempType |= *(UCHAR8 *)(uiTempAddr + 5) << 0;
- uiTempInode = *(UCHAR8 *)(uiTempAddr + 6) << 8;
- uiTempInode |= *(UCHAR8 *)(uiTempAddr + 7) << 0;
- HV_LOGV("header need %d, act %d \n", enType, uiTempType);
- if (uiTempType < enType)
- {
- /* get next header */
- uiTempAddr = uiTempAddr + 0x10;
- continue;
- }
- else if (uiTempType > enType)
- {
- break;
- }
- else
- {
- if (uiTempInode < uiIndex)
- {
- /* get next header */
- uiTempAddr = uiTempAddr + 0x10;
- continue;
- }
- else if (uiTempInode > uiIndex)
- {
- break;
- }
- else
- {
- *puiSize = *(UCHAR8 *)(uiTempAddr + 8) << 24;
- *puiSize |= *(UCHAR8 *)(uiTempAddr + 9) << 16;
- *puiSize |= *(UCHAR8 *)(uiTempAddr + 10) << 8;
- *puiSize |= *(UCHAR8 *)(uiTempAddr + 11) << 0;
- uiOffset = *(UCHAR8 *)(uiTempAddr + 12) << 24;
- uiOffset |= *(UCHAR8 *)(uiTempAddr + 13) << 16;
- uiOffset |= *(UCHAR8 *)(uiTempAddr + 14) << 8;
- uiOffset |= *(UCHAR8 *)(uiTempAddr + 15) << 0;
- *puiAddr = uiOffset + HV_MEMORY_CONFIG_PQ_DATA_START;
- HV_LOGV("header uiOffset %x, size %d \n", uiOffset, *puiSize);
- return HV_SUCCESS;
- }
- }
- }
- return HV_FAILURE;
- }
- /**
- * @brief show pq table addr & size
- */
- Status Hv_Pq_ShowTable(void)
- {
- UINT32 uiTempAddr = 0;
- UINT32 uiStartAddr = 0;
- UINT32 uiTempType = 0;
- UINT32 uiTempInode = 0;
- UINT32 uiOffset = 0;
- UINT32 uiSize = 0;
- uiTempAddr = HV_MEMORY_CONFIG_PQ_DATA_START;
- uiStartAddr = uiTempAddr;
- HV_LOGI("base addr %x\n", uiTempAddr);
- for (;;)
- {
- HV_LOGI("header addr %x\n", uiTempAddr);
- if (uiTempAddr > uiStartAddr + 0x1000)
- {
- break;
- }
- /* check header magic */
- if (*(UCHAR8 *)(uiTempAddr) != 'H')
- {
- return HV_FAILURE;
- }
- if (*(UCHAR8 *)(uiTempAddr + 1) != 'E')
- {
- return HV_FAILURE;
- }
- if (*(UCHAR8 *)(uiTempAddr + 2) != 'A')
- {
- return HV_FAILURE;
- }
- if (*(UCHAR8 *)(uiTempAddr + 3) != 'D')
- {
- return HV_FAILURE;
- }
- /* check type */
- uiTempType = *(UCHAR8 *)(uiTempAddr + 4) << 8;
- uiTempType |= *(UCHAR8 *)(uiTempAddr + 5) << 0;
- uiTempInode = *(UCHAR8 *)(uiTempAddr + 6) << 8;
- uiTempInode |= *(UCHAR8 *)(uiTempAddr + 7) << 0;
- uiSize = *(UCHAR8 *)(uiTempAddr + 8) << 24;
- uiSize |= *(UCHAR8 *)(uiTempAddr + 9) << 16;
- uiSize |= *(UCHAR8 *)(uiTempAddr + 10) << 8;
- uiSize |= *(UCHAR8 *)(uiTempAddr + 11) << 0;
- uiOffset = *(UCHAR8 *)(uiTempAddr + 12) << 24;
- uiOffset |= *(UCHAR8 *)(uiTempAddr + 13) << 16;
- uiOffset |= *(UCHAR8 *)(uiTempAddr + 14) << 8;
- uiOffset |= *(UCHAR8 *)(uiTempAddr + 15) << 0;
- HV_LOGI("header %d, index %d, offset %x, size %x\n", uiTempType, uiTempInode, uiOffset, uiSize);
- uiTempAddr = uiTempAddr + 0x10;
- }
- return HV_SUCCESS;
- }
- /**
- * @brief get code superblock version.
- */
- UINT32 Hv_Comm_GetCodeVersion(void)
- {
- UINT32 uiVersion = 0;
- UCHAR8 aucData[4] = {0};
- Hv_Drv_Flash_OnlyRead((HV_FLASH_CONFIG_SUPERBLOCK_START + 0x40 + 0x1c), aucData, 4);
- uiVersion = aucData[0]<<24 | aucData[1]<<16 | aucData[2]<<8 | aucData[3];
- HV_LOGV(">>> get version %x\n", uiVersion);
- return uiVersion;
- }
- void Hv_Comm_Copy(INT32 *iSrc, INT32 *iDst, INT32 iSize)
- {
- INT32 iLoop = 0;
- for (iLoop=0; iLoop<iSize/4; iLoop++)
- {
- *iDst = *iSrc;
- iSrc++;
- iDst++;
- }
- return;
- }
- void Hv_Comm_CopyLogoData(void)
- {
- 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);
- return;
- }
- UINT32 Hv_Board_Memory_CalculateOsdBlendSize(VOID)
- {
- #if (HV_PROJECT_CONFIG_OSD_DDRPATH == HV_CONFIG_ON)
- return (PANEL_OSD_H_ACTIVE * PANEL_OSD_V_ACTIVE * HV_OSD_CONFIG_DDR_PIXEL_BYTES * 2);
- #else
- return 0;
- #endif
- }
- UINT32 Hv_Board_Memory_CalculateOsdRotationSize(VOID)
- {
- #if (HV_PROJECT_CONFIG_OSD_ROTATION == HV_CONFIG_ON)
- return (HV_OSD_CONFIG_ROTATION_H_ACTIVE * HV_OSD_CONFIG_ROTATION_V_ACTIVE * HV_OSD_CONFIG_DDR_PIXEL_BYTES);
- #else
- return 0;
- #endif
- }
- UINT32 Hv_Board_Memory_CalculateOsdGraphicSize(VOID)
- {
- #if (HV_PROJECT_CONFIG_OSD_GRAPHIC == HV_CONFIG_ON)
- return (HV_OSD_CONFIG_GRAPHIC_H_ACTIVE * HV_OSD_CONFIG_GRAPHIC_V_ACTIVE * HV_OSD_CONFIG_GRAPHIC_PIXEL_BYTES);
- #else
- return 0;
- #endif
- }
- UINT32 Hv_Board_Memory_CalculateSizeForOsd(VOID)
- {
- UINT32 uiDDRSize = Hv_Board_Memory_CalculateOsdBlendSize();
- UINT32 uiRotationSize = Hv_Board_Memory_CalculateOsdRotationSize();
- UINT32 uiGraphicSize = Hv_Board_Memory_CalculateOsdGraphicSize();
- HV_LOGV("Osd DDR size: %u", uiDDRSize);
- HV_LOGV("OSD Rotation Size: %u", uiRotationSize);
- HV_LOGV("OSD Graphic Size: %u", uiGraphicSize);
- return uiDDRSize + uiRotationSize + uiGraphicSize;
- }
- FLOAT32 Hv_Board_Memory_CalculateBandForOsd(UINT32 uiVideoFrameRate)
- {
- UCHAR8 ucOsdFrameRate = 0;
- FLOAT32 fBandWidth = 0;
- UINT32 fBandDDRR = 0;
- UINT32 fBandDDRW = 0;
- UINT32 fBandGraphic = 0;
- UCHAR8 ucBits = 0;
- ucOsdFrameRate = Hv_Drv_OsdFrame_GetOsdFrameRate(uiVideoFrameRate, HV_FALSE);
- #if (HV_PROJECT_CONFIG_OSD_DDRPATH == HV_CONFIG_ON)
- ucBits = Hv_Drv_OsdCommon_GetPixelBits(HV_OSD_CONFIG_DDR_FORMAT);
- fBandDDRW = (ucOsdFrameRate * PANEL_OSD_H_ACTIVE * PANEL_OSD_V_TOTAL * ucBits) / 8;
- HV_LOGV("DDR Write Bandwidth: %u", fBandDDRW);
- fBandDDRW /= 1000000;
- fBandDDRR = (uiVideoFrameRate * PANEL_OSD_H_ACTIVE * PANEL_V_TOTAL_TYP * ucBits) / 8;
- HV_LOGV("DDR Read Bandwidth: %u", fBandDDRR);
- fBandDDRR /= 1000000;
- #endif /* HV_PROJECT_CONFIG_OSD_DDRPATH */
- #if (HV_PROJECT_CONFIG_OSD_GRAPHIC == HV_CONFIG_ON)
- ucBits = Hv_Drv_OsdCommon_GetPixelBits(HV_OSD_CONFIG_GRAPHIC_FORMAT);
- fBandGraphic = (ucOsdFrameRate * PANEL_OSD_H_ACTIVE * PANEL_OSD_V_TOTAL * ucBits) / 8;
- HV_LOGV("Graphic Read Bandwidth: %u", fBandGraphic);
- fBandGraphic /= 1000000;
- #endif
- fBandWidth = fBandDDRR + fBandDDRW + fBandGraphic;
- return fBandWidth;
- }
- /* 3840*2250*24/8/5.83 */
- UINT32 Hv_Board_Memory_CalODSize(VOID)
- {
- FLOAT32 ufOdSize = 0;
- UINT32 uiOdSize = 0;
- #ifdef CONFIG_USER_PANEL_RESOLUTION_TYPE_UHD
- uiOdSize = 0x413000;
- #endif
- #ifdef CONFIG_USER_PANEL_RESOLUTION_TYPE_QHD
- uiOdSize = 0x1D0000;
- #endif
- #ifdef CONFIG_USER_PANEL_RESOLUTION_TYPE_FHD
- uiOdSize = 0x110000;
- #endif
- #ifdef CONFIG_USER_PANEL_RESOLUTION_TYPE_CUSTOMIZE
- ufOdSize = HV_PROJECT_CONFIG_PANEL_H_ACTIVE_CUSTOMIZE * HV_PROJECT_CONFIG_PANEL_V_ACTIVE_CUSTOMIZE * 1.1 * 24 /8 /5.83;
- uiOdSize = ((UINT32)ufOdSize + 0xFFF) >> 12 << 12;
- HV_LOGI("OD size: %x\n", uiOdSize);
- #endif
- return uiOdSize;
- }
- /* 3840*2250*24/8/5.83 */
- FLOAT32 Hv_Board_Memory_CalODBand(VOID)
- {
- FLOAT32 ufOdBand = 0;
- #ifdef CONFIG_USER_PANEL_RESOLUTION_TYPE_UHD
- ufOdBand = 71.14;
- #endif
- #ifdef CONFIG_USER_PANEL_RESOLUTION_TYPE_QHD
- ufOdBand = 31.20;
- #endif
- #ifdef CONFIG_USER_PANEL_RESOLUTION_TYPE_FHD
- ufOdBand = 17.79;
- #endif
- #ifdef CONFIG_USER_PANEL_RESOLUTION_TYPE_CUSTOMIZE
- ufOdBand = HV_PROJECT_CONFIG_PANEL_H_ACTIVE_CUSTOMIZE * HV_PROJECT_CONFIG_PANEL_V_ACTIVE_CUSTOMIZE * 1.1 *24 *2 /5.83 /1000 /1000;
- HV_LOGI("OD band: %x\n", ufOdBand);
- #endif
- return ufOdBand;
- }
- /* 30*481*271/8 */
- UINT32 Hv_Board_Memory_CalDemuraSize(VOID)
- {
- FLOAT32 ufDemuraSize = 0;
- UINT32 uiDemuraSize = 0;
- #ifdef DEMURA_COLOR_MODE
- UCHAR8 ucColorModeMul = (DEMURA_COLOR_MODE == 0) ? 1 : 3;
- #else
- UCHAR8 ucColorModeMul = 1;
- #endif
- #ifdef CONFIG_USER_PANEL_RESOLUTION_TYPE_UHD
- uiDemuraSize = 0x80000;
- #endif
- #ifdef CONFIG_USER_PANEL_RESOLUTION_TYPE_QHD
- uiDemuraSize = 0x36000;
- #endif
- #ifdef CONFIG_USER_PANEL_RESOLUTION_TYPE_FHD
- uiDemuraSize = 0x1F000;
- #endif
- #ifdef CONFIG_USER_PANEL_RESOLUTION_TYPE_CUSTOMIZE
- uiDemuraSize = (HV_PROJECT_CONFIG_PANEL_H_ACTIVE_CUSTOMIZE+7)/8 * (HV_PROJECT_CONFIG_PANEL_V_ACTIVE_CUSTOMIZE+7)/8;
- ufDemuraSize = uiDemuraSize * 1.1 * 30 /8;
- uiDemuraSize = ((UINT32)ufDemuraSize + 0xFFF) >> 12 << 12;
- HV_LOGI("Demura size: %x\n", uiDemuraSize);
- #endif
- return (uiDemuraSize * ucColorModeMul);
- }
- /* 321*186*30*Freq/1000/1000 */
- FLOAT32 Hv_Board_Memory_CalDemuraBand(VOID)
- {
- FLOAT32 ufDemuraBand = 0;
- #ifdef DEMURA_COLOR_MODE
- UCHAR8 ucColorModeMul = (DEMURA_COLOR_MODE == 0) ? 1 : 3;
- #else
- UCHAR8 ucColorModeMul = 1;
- #endif
- #ifdef CONFIG_USER_PANEL_RESOLUTION_TYPE_UHD
- ufDemuraBand = 4.07;
- #endif
- #ifdef CONFIG_USER_PANEL_RESOLUTION_TYPE_QHD
- ufDemuraBand = 1.80;
- #endif
- #ifdef CONFIG_USER_PANEL_RESOLUTION_TYPE_FHD
- ufDemuraBand = 1.03;
- #endif
- #ifdef CONFIG_USER_PANEL_RESOLUTION_TYPE_CUSTOMIZE
- ufDemuraBand = (HV_PROJECT_CONFIG_PANEL_H_ACTIVE_CUSTOMIZE+7)/8 * (HV_PROJECT_CONFIG_PANEL_V_ACTIVE_CUSTOMIZE+7)/8 * 1.1 *30 /1000 /1000;
- HV_LOGI("Demura band: %x\n", ufDemuraBand);
- #endif
- return (ufDemuraBand * ucColorModeMul);
- }
- /* return address */
- UINT32 Hv_Board_Memory_FRCStart(void)
- {
- UINT32 uiDDRStart = 0;
- UINT32 uiOsdSize = 0;
- UINT32 uiOdSize = 0;
- uiDDRStart += HV_MEMORY_CONFIG_STATIC_DDR_SIZE;
- uiDDRStart += Hv_Board_Memory_CalDemuraSize();
- uiOsdSize = Hv_Board_Memory_CalculateSizeForOsd();
- uiOdSize = Hv_Board_Memory_CalODSize();
- if (uiOsdSize < uiOdSize)
- {
- uiOsdSize = uiOdSize;
- }
- uiDDRStart += uiOsdSize;
- return PHY_TO_VDM(uiDDRStart);
- }
- /* return bytes */
- UINT32 Hv_Board_Memory_RemainSizeForFRC(void)
- {
- UINT32 uiFRCSize = 0;
- uiFRCSize = PHY_TO_VDM(HV_MEMORY_CONFIG_DDR_SIZE) - Hv_Board_Memory_FRCStart();
- return uiFRCSize;
- }
- /* return xxMbit/s */
- UINT32 Hv_Board_Memory_RemainBandForFRC(UINT32 PanelFreq)
- {
- float fDDRBand = 0;
- float fOsdBand = 0;
- float fOdBand = 0;
- UINT32 uiFrcBand = 0;
- UINT32 uiDDRFreq = 0;
- float fDDRRatio = 0;
- UCHAR8 ucDDRType = 0;
- ucDDRType = Hv_Ddr_Type();
- if (ucDDRType)
- {
- uiDDRFreq = HV_MEMORY_CONFIG_DDR3_FREQ;
- fDDRRatio = HV_MEMORY_CONFIG_DDR3_UTILIZATION_RATIO;
- }
- else
- {
- uiDDRFreq = HV_MEMORY_CONFIG_DDR2_FREQ;
- fDDRRatio = HV_MEMORY_CONFIG_DDR2_UTILIZATION_RATIO;
- }
- fDDRBand += HV_MEMORY_CONFIG_STATIC_DDR_BANDWIDTH;
- fDDRBand += PanelFreq * Hv_Board_Memory_CalDemuraBand();
- fOsdBand = Hv_Board_Memory_CalculateBandForOsd(PanelFreq);
- fOdBand = Hv_Board_Memory_CalODBand() * PanelFreq;
- if (fOsdBand < fOdBand)
- {
- fOsdBand = fOdBand;
- }
- fDDRBand += fOsdBand;
- uiFrcBand = (UINT32 )(uiDDRFreq * HV_MEMORY_CONFIG_DDR_PHY * fDDRRatio - fDDRBand);
- return uiFrcBand;
- }
|