• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /** @file
2   This file is for functins related to assign and free Framework HII handle number.
3 
4 Copyright (c) 2008 - 2010, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution.  The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9 
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12 
13 **/
14 
15 
16 #include "HiiHandle.h"
17 
18 //
19 // FRAMEWORK_EFI_HII_HANDLE
20 //
21 UINT8 mHandle[1024 * 8] = {0};
22 
23 /**
24 
25   Initialize the Framework Hii Handle database.
26 
27 **/
28 VOID
InitHiiHandleDatabase(VOID)29 InitHiiHandleDatabase (
30   VOID
31   )
32 {
33   //
34   // FRAMEWORK_EFI_HII_HANDLE 0 is reserved.
35   // Set Bit 0 in mHandle[0] to 1.
36   //
37   mHandle[0] |= 1 << 0;
38 }
39 
40 /**
41   Allocate a new Framework HII handle.
42 
43   @param  Handle Returns the new Framework HII Handle assigned.
44 
45   @retval EFI_SUCCESS         A new Framework HII Handle is assigned.
46   @retval EFI_OUT_OF_RESOURCE The Framework HII Handle database is depleted.
47 
48 **/
49 EFI_STATUS
AllocateHiiHandle(OUT FRAMEWORK_EFI_HII_HANDLE * Handle)50 AllocateHiiHandle (
51   OUT FRAMEWORK_EFI_HII_HANDLE *Handle
52   )
53 {
54   UINTN       Index;
55 
56   for (Index = 0; Index < sizeof (mHandle) * 8; Index++) {
57     if ((mHandle[Index / 8] & (1 << (Index % 8))) == 0) {
58       mHandle[Index / 8] = (UINT8) (mHandle[Index / 8] | (1 << (Index % 8)));
59       *Handle = (FRAMEWORK_EFI_HII_HANDLE) Index;
60       ASSERT (*Handle != 0);
61       return EFI_SUCCESS;
62     }
63   }
64 
65   return EFI_OUT_OF_RESOURCES;
66 }
67 
68 /**
69   Free Framework HII handle.
70 
71   @param  Handle The Framework HII Handle to be freed.
72 
73 **/
74 VOID
FreeHiiHandle(IN FRAMEWORK_EFI_HII_HANDLE Handle)75 FreeHiiHandle (
76   IN FRAMEWORK_EFI_HII_HANDLE Handle
77   )
78 {
79   UINT16 Num;
80 
81   Num = (UINT16) Handle;
82 
83   ASSERT ((mHandle [Num / 8] & (1 << (Num % 8))) != 0);
84   mHandle [Num / 8] = (UINT8) (mHandle [Num / 8] & (~(1 << (Num % 8))));
85 }
86