1/** @file 2 3Copyright (c) 2015, Intel Corporation. All rights reserved.<BR> 4 5This program and the accompanying materials 6are licensed and made available under the terms and conditions 7of the BSD License which accompanies this distribution. The 8full text of the license may be found at 9http://opensource.org/licenses/bsd-license.php 10 11THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 12WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 13 14**/ 15 16#ifndef _SD_PEIM_MEM_H_ 17#define _SD_PEIM_MEM_H_ 18 19#define SD_PEIM_MEM_BIT(a) ((UINTN)(1 << (a))) 20 21#define SD_PEIM_MEM_BIT_IS_SET(Data, Bit) \ 22 ((BOOLEAN)(((Data) & SD_PEIM_MEM_BIT(Bit)) == SD_PEIM_MEM_BIT(Bit))) 23 24typedef struct _SD_PEIM_MEM_BLOCK SD_PEIM_MEM_BLOCK; 25 26struct _SD_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 SD_PEIM_MEM_BLOCK *Next; 32}; 33 34typedef struct _SD_PEIM_MEM_POOL { 35 SD_PEIM_MEM_BLOCK *Head; 36} SD_PEIM_MEM_POOL; 37 38// 39// Memory allocation unit, note that the value must meet SD spec alignment requirement. 40// 41#define SD_PEIM_MEM_UNIT 128 42 43#define SD_PEIM_MEM_UNIT_MASK (SD_PEIM_MEM_UNIT - 1) 44#define SD_PEIM_MEM_DEFAULT_PAGES 16 45 46#define SD_PEIM_MEM_ROUND(Len) (((Len) + SD_PEIM_MEM_UNIT_MASK) & (~SD_PEIM_MEM_UNIT_MASK)) 47 48// 49// Advance the byte and bit to the next bit, adjust byte accordingly. 50// 51#define SD_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