--- /dev/null
+/** @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
+\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
+\r
+**/\r
+\r
+#ifndef _UFS_PEIM_MEM_H_\r
+#define _UFS_PEIM_MEM_H_\r
+\r
+#define UFS_PEIM_MEM_BIT(a) ((UINTN)(1 << (a)))\r
+\r
+#define UFS_PEIM_MEM_BIT_IS_SET(Data, Bit) \\r
+ ((BOOLEAN)(((Data) & UFS_PEIM_MEM_BIT(Bit)) == UFS_PEIM_MEM_BIT(Bit)))\r
+\r
+typedef struct _UFS_PEIM_MEM_BLOCK UFS_PEIM_MEM_BLOCK;\r
+\r
+struct _UFS_PEIM_MEM_BLOCK {\r
+ UINT8 *Bits; // Bit array to record which unit is allocated\r
+ UINTN BitsLen; \r
+ UINT8 *Buf;\r
+ UINTN BufLen; // Memory size in bytes\r
+ UFS_PEIM_MEM_BLOCK *Next;\r
+};\r
+\r
+typedef struct _UFS_PEIM_MEM_POOL {\r
+ UFS_PEIM_MEM_BLOCK *Head;\r
+} UFS_PEIM_MEM_POOL;\r
+\r
+//\r
+// Memory allocation unit, note that the value must meet UFS spec alignment requirement.\r
+//\r
+#define UFS_PEIM_MEM_UNIT 128\r
+\r
+#define UFS_PEIM_MEM_UNIT_MASK (UFS_PEIM_MEM_UNIT - 1)\r
+#define UFS_PEIM_MEM_DEFAULT_PAGES 16\r
+\r
+#define UFS_PEIM_MEM_ROUND(Len) (((Len) + UFS_PEIM_MEM_UNIT_MASK) & (~UFS_PEIM_MEM_UNIT_MASK))\r
+\r
+//\r
+// Advance the byte and bit to the next bit, adjust byte accordingly.\r
+//\r
+#define UFS_PEIM_NEXT_BIT(Byte, Bit) \\r
+ do { \\r
+ (Bit)++; \\r
+ if ((Bit) > 7) { \\r
+ (Byte)++; \\r
+ (Bit) = 0; \\r
+ } \\r
+ } while (0)\r
+\r
+#endif\r
+\r