summaryrefslogtreecommitdiff
path: root/EdkCompatibilityPkg/Compatibility/FrameworkHiiOnUefiHiiThunk/HiiHandle.c
blob: 16b701a40c32187a67345476281f9a4a75d3032f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/** @file
  This file is for functins related to assign and free Framework HII handle number.
  
Copyright (c) 2008 - 2010, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution.  The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php

THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.

**/


#include "HiiHandle.h"

//
// FRAMEWORK_EFI_HII_HANDLE
//
UINT8 mHandle[1024 * 8] = {0};

/**

  Initialize the Framework Hii Handle database.

**/
VOID
InitHiiHandleDatabase (
  VOID
  )
{
  //
  // FRAMEWORK_EFI_HII_HANDLE 0 is reserved.
  // Set Bit 0 in mHandle[0] to 1.
  //
  mHandle[0] |= 1 << 0;
}

/**
  Allocate a new Framework HII handle. 

  @param  Handle Returns the new Framework HII Handle assigned.

  @retval EFI_SUCCESS         A new Framework HII Handle is assigned.
  @retval EFI_OUT_OF_RESOURCE The Framework HII Handle database is depleted.

**/
EFI_STATUS
AllocateHiiHandle (
  OUT FRAMEWORK_EFI_HII_HANDLE *Handle
  )
{
  UINTN       Index;

  for (Index = 0; Index < sizeof (mHandle) * 8; Index++) {
    if ((mHandle[Index / 8] & (1 << (Index % 8))) == 0) {
      mHandle[Index / 8] = (UINT8) (mHandle[Index / 8] | (1 << (Index % 8)));
      *Handle = (FRAMEWORK_EFI_HII_HANDLE) Index;
      ASSERT (*Handle != 0);
      return EFI_SUCCESS;
    }
  }
  
  return EFI_OUT_OF_RESOURCES;
}

/**
  Free Framework HII handle. 

  @param  Handle The Framework HII Handle to be freed.

**/
VOID
FreeHiiHandle (
  IN FRAMEWORK_EFI_HII_HANDLE Handle
  )
{
  UINT16 Num;

  Num = (UINT16) Handle;

  ASSERT ((mHandle [Num / 8] & (1 << (Num % 8))) != 0);
  mHandle [Num / 8] = (UINT8) (mHandle [Num / 8] & (~(1 << (Num % 8))));
}