1 /** @file 2 3 Copyright (c) 2015, Intel Corporation. All rights reserved.<BR> 4 5 This program and the accompanying materials 6 are licensed and made available under the terms and conditions 7 of the BSD License which accompanies this distribution. The 8 full text of the license may be found at 9 http://opensource.org/licenses/bsd-license.php 10 11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 13 14 **/ 15 16 #ifndef _EMMC_PEIM_MEM_H_ 17 #define _EMMC_PEIM_MEM_H_ 18 19 #define EMMC_PEIM_MEM_BIT(a) ((UINTN)(1 << (a))) 20 21 #define EMMC_PEIM_MEM_BIT_IS_SET(Data, Bit) \ 22 ((BOOLEAN)(((Data) & EMMC_PEIM_MEM_BIT(Bit)) == EMMC_PEIM_MEM_BIT(Bit))) 23 24 typedef struct _EMMC_PEIM_MEM_BLOCK EMMC_PEIM_MEM_BLOCK; 25 26 struct _EMMC_PEIM_MEM_BLOCK { 27 UINT8 *Bits; // Bit array to record which unit is allocated 28 UINTN BitsLen; 29 UINT8 *Buf; 30 UINTN BufLen; // Memory size in bytes 31 EMMC_PEIM_MEM_BLOCK *Next; 32 }; 33 34 typedef struct _EMMC_PEIM_MEM_POOL { 35 EMMC_PEIM_MEM_BLOCK *Head; 36 } EMMC_PEIM_MEM_POOL; 37 38 // 39 // Memory allocation unit, note that the value must meet EMMC spec alignment requirement. 40 // 41 #define EMMC_PEIM_MEM_UNIT 128 42 43 #define EMMC_PEIM_MEM_UNIT_MASK (EMMC_PEIM_MEM_UNIT - 1) 44 #define EMMC_PEIM_MEM_DEFAULT_PAGES 16 45 46 #define EMMC_PEIM_MEM_ROUND(Len) (((Len) + EMMC_PEIM_MEM_UNIT_MASK) & (~EMMC_PEIM_MEM_UNIT_MASK)) 47 48 // 49 // Advance the byte and bit to the next bit, adjust byte accordingly. 50 // 51 #define EMMC_PEIM_NEXT_BIT(Byte, Bit) \ 52 do { \ 53 (Bit)++; \ 54 if ((Bit) > 7) { \ 55 (Byte)++; \ 56 (Bit) = 0; \ 57 } \ 58 } while (0) 59 60 #endif 61 62