-#define WLS_HUGE_DEF_PAGE_SIZEA 0x40000000LL
- static long hugePageSize = WLS_HUGE_DEF_PAGE_SIZEA;
- // NR5G_FAPI_MEMSET(pWls->pWlsMemBase , 0xCC, pWls->nTotalMemorySize); // This is done by the Master Only
- pWls->pPartitionMemBase =
- (void *)(((uint8_t *) pWls->pWlsMemBase) + hugePageSize);
- pWls->nPartitionMemSize = (pWls->nTotalMemorySize - hugePageSize);
-
- pWls->nTotalBlocks = pWls->nPartitionMemSize / MSG_MAXSIZE;
+ uint64_t nWlsMemBaseUsable;
+ uint64_t nTotalMemorySizeUsable;
+ uint64_t nBalance, nBlockSize, nBlockSizeMask, nHugepageSizeMask;
+
+ nBlockSize = MSG_MAXSIZE;
+ nWlsMemBaseUsable = (uint64_t)pWls->pWlsMemBase;
+ nTotalMemorySizeUsable = pWls->nTotalMemorySize - WLS_HUGE_DEF_PAGE_SIZEA;
+ nBlockSizeMask = nBlockSize-1;
+
+ // Align Starting Location
+ nWlsMemBaseUsable = (nWlsMemBaseUsable + nBlockSizeMask) & (~nBlockSizeMask);
+ nBalance = nWlsMemBaseUsable - (uint64_t)pWls->pWlsMemBase;
+ nTotalMemorySizeUsable -= nBalance;
+
+ // Align Ending Location
+ nBalance = nTotalMemorySizeUsable % nBlockSize;
+ nTotalMemorySizeUsable -= nBalance;
+
+ // Move start location to the next hugepage boundary
+ nHugepageSizeMask = WLS_HUGE_DEF_PAGE_SIZEA-1;
+ nWlsMemBaseUsable = (nWlsMemBaseUsable + WLS_HUGE_DEF_PAGE_SIZEA) & (~nHugepageSizeMask);
+
+
+ pWls->pPartitionMemBase = (void *)nWlsMemBaseUsable;
+ pWls->nPartitionMemSize = nTotalMemorySizeUsable;
+ pWls->nTotalBlocks = pWls->nPartitionMemSize / nBlockSize;