/** @file\r
\r
-Copyright (c) 2014, Intel Corporation. All rights reserved.<BR>\r
- \r
-This program and the accompanying materials\r
-are licensed and made available under the terms and conditions\r
-of the BSD License which accompanies this distribution. The\r
-full text of the license may be found at\r
-http://opensource.org/licenses/bsd-license.php\r
+Copyright (c) 2014 - 2018, Intel Corporation. All rights reserved.<BR>\r
\r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
\r
**/\r
\r
)\r
{\r
UFS_PEIM_MEM_BLOCK *Block;\r
+ VOID *BufHost;\r
+ VOID *Mapping;\r
+ EFI_PHYSICAL_ADDRESS MappedAddr;\r
EFI_STATUS Status;\r
VOID *TempPtr;\r
- EFI_PHYSICAL_ADDRESS Address;\r
\r
TempPtr = NULL;\r
Block = NULL;\r
}\r
\r
ZeroMem ((VOID*)(UINTN)TempPtr, sizeof(UFS_PEIM_MEM_BLOCK));\r
- \r
+\r
//\r
// each bit in the bit array represents UFS_PEIM_MEM_UNIT\r
// bytes of memory in the memory block.\r
//\r
ASSERT (UFS_PEIM_MEM_UNIT * 8 <= EFI_PAGE_SIZE);\r
- \r
+\r
Block = (UFS_PEIM_MEM_BLOCK*)(UINTN)TempPtr;\r
Block->BufLen = EFI_PAGES_TO_SIZE (Pages);\r
Block->BitsLen = Block->BufLen / (UFS_PEIM_MEM_UNIT * 8);\r
- \r
+\r
Status = PeiServicesAllocatePool (Block->BitsLen, &TempPtr);\r
if (EFI_ERROR (Status)) {\r
return NULL;\r
\r
Block->Bits = (UINT8*)(UINTN)TempPtr;\r
\r
- Status = PeiServicesAllocatePages (\r
- EfiBootServicesCode,\r
+ Status = IoMmuAllocateBuffer (\r
Pages,\r
- &Address\r
+ &BufHost,\r
+ &MappedAddr,\r
+ &Mapping\r
);\r
if (EFI_ERROR (Status)) {\r
return NULL;\r
}\r
\r
- ZeroMem ((VOID*)(UINTN)Address, EFI_PAGES_TO_SIZE (Pages));\r
+ ZeroMem ((VOID*)(UINTN)BufHost, EFI_PAGES_TO_SIZE (Pages));\r
\r
- Block->Buf = (UINT8*)((UINTN)Address);\r
- Block->Next = NULL;\r
+ Block->BufHost = (UINT8 *) (UINTN) BufHost;\r
+ Block->Buf = (UINT8 *) (UINTN) MappedAddr;\r
+ Block->Mapping = Mapping;\r
+ Block->Next = NULL;\r
\r
return Block;\r
}\r
)\r
{\r
ASSERT ((Pool != NULL) && (Block != NULL));\r
+\r
+ IoMmuFreeBuffer (EFI_SIZE_TO_PAGES (Block->BufLen), Block->BufHost, Block->Mapping);\r
}\r
\r
/**\r
if (Available < Units) {\r
return NULL;\r
}\r
- \r
+\r
//\r
// Mark the memory as allocated\r
//\r
{\r
UINTN Index;\r
\r
- \r
+\r
for (Index = 0; Index < Block->BitsLen; Index++) {\r
if (Block->Bits[Index] != 0) {\r
return FALSE;\r
return TRUE;\r
}\r
\r
-/**\r
- Unlink the memory block from the pool's list.\r
-\r
- @param Head The block list head of the memory's pool.\r
- @param BlockToUnlink The memory block to unlink.\r
-\r
-**/\r
-VOID\r
-UfsPeimUnlinkMemBlock (\r
- IN UFS_PEIM_MEM_BLOCK *Head,\r
- IN UFS_PEIM_MEM_BLOCK *BlockToUnlink\r
- )\r
-{\r
- UFS_PEIM_MEM_BLOCK *Block;\r
-\r
- ASSERT ((Head != NULL) && (BlockToUnlink != NULL));\r
\r
- for (Block = Head; Block != NULL; Block = Block->Next) {\r
- if (Block->Next == BlockToUnlink) {\r
- Block->Next = BlockToUnlink->Next;\r
- BlockToUnlink->Next = NULL;\r
- break;\r
- }\r
- }\r
-}\r
\r
/**\r
Initialize the memory management pool for the host controller.\r
- \r
+\r
@param Private The Ufs Peim driver private data.\r
\r
@retval EFI_SUCCESS The memory pool is initialized.\r
\r
TempPtr = NULL;\r
Pool = NULL;\r
- \r
+\r
Status = PeiServicesAllocatePool (sizeof (UFS_PEIM_MEM_POOL), &TempPtr);\r
if (EFI_ERROR (Status)) {\r
return EFI_OUT_OF_RESOURCES;\r
\r
/**\r
Release the memory management pool.\r
- \r
+\r
@param Pool The memory pool to free.\r
\r
@retval EFI_DEVICE_ERROR Fail to free the memory pool.\r
\r
//\r
// Unlink all the memory blocks from the pool, then free them.\r
- // UfsPeimUnlinkMemBlock can't be used to unlink and free the\r
- // first block.\r
//\r
for (Block = Pool->Head->Next; Block != NULL; Block = Pool->Head->Next) {\r
UfsPeimFreeMemBlock (Pool, Block);\r
/**\r
Allocate some memory from the host controller's memory pool\r
which can be used to communicate with host controller.\r
- \r
+\r
@param Pool The host controller's memory pool.\r
@param Size Size of the memory to allocate.\r
\r
if (NewBlock == NULL) {\r
return NULL;\r
}\r
- \r
+\r
//\r
// Add the new memory block to the pool, then allocate memory from it\r
//\r
Bit = ((ToFree - Block->Buf) / UFS_PEIM_MEM_UNIT) % 8;\r
\r
//\r
- // reset associated bits in bit arry\r
+ // reset associated bits in bit array\r
//\r
for (Count = 0; Count < (AllocSize / UFS_PEIM_MEM_UNIT); Count++) {\r
ASSERT (UFS_PEIM_MEM_BIT_IS_SET (Block->Bits[Byte], Bit));\r