1 /** @file
2 This file contains the entry code to the HII database, which is defined by
3 UEFI 2.1 specification.
4 
5 Copyright (c) 2007 - 2015, Intel Corporation. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution.  The 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 
17 #include "HiiDatabase.h"
18 
19 //
20 // Global variables
21 //
22 EFI_EVENT gHiiKeyboardLayoutChanged;
23 
24 HII_DATABASE_PRIVATE_DATA mPrivate = {
25   HII_DATABASE_PRIVATE_DATA_SIGNATURE,
26   {
27     (LIST_ENTRY *) NULL,
28     (LIST_ENTRY *) NULL
29   },
30   {
31     (LIST_ENTRY *) NULL,
32     (LIST_ENTRY *) NULL
33   },
34   {
35     HiiStringToImage,
36     HiiStringIdToImage,
37     HiiGetGlyph,
38     HiiGetFontInfo
39   },
40   {
41     NULL,
42     NULL,
43     NULL,
44     NULL,
45     NULL
46   },
47   {
48     HiiNewString,
49     HiiGetString,
50     HiiSetString,
51     HiiGetLanguages,
52     HiiGetSecondaryLanguages
53   },
54   {
55     HiiNewPackageList,
56     HiiRemovePackageList,
57     HiiUpdatePackageList,
58     HiiListPackageLists,
59     HiiExportPackageLists,
60     HiiRegisterPackageNotify,
61     HiiUnregisterPackageNotify,
62     HiiFindKeyboardLayouts,
63     HiiGetKeyboardLayout,
64     HiiSetKeyboardLayout,
65     HiiGetPackageListHandle
66   },
67   {
68     HiiConfigRoutingExtractConfig,
69     HiiConfigRoutingExportConfig,
70     HiiConfigRoutingRouteConfig,
71     HiiBlockToConfig,
72     HiiConfigToBlock,
73     HiiGetAltCfg
74   },
75   {
76     EfiConfigKeywordHandlerSetData,
77     EfiConfigKeywordHandlerGetData
78   },
79   {
80     (LIST_ENTRY *) NULL,
81     (LIST_ENTRY *) NULL
82   },
83   0,
84   {
85     (LIST_ENTRY *) NULL,
86     (LIST_ENTRY *) NULL
87   },
88   EFI_TEXT_ATTR (EFI_LIGHTGRAY, EFI_BLACK),
89   {
90     0x00000000,
91     0x0000,
92     0x0000,
93     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
94   },
95   NULL
96 };
97 
98 GLOBAL_REMOVE_IF_UNREFERENCED CONST EFI_HII_IMAGE_PROTOCOL mImageProtocol = {
99   HiiNewImage,
100   HiiGetImage,
101   HiiSetImage,
102   HiiDrawImage,
103   HiiDrawImageId
104 };
105 
106 /**
107   The default event handler for gHiiKeyboardLayoutChanged
108   event group.
109 
110   This is internal function.
111 
112   @param Event           The event that triggered this notification function.
113   @param Context         Pointer to the notification functions context.
114 
115 **/
116 VOID
117 EFIAPI
KeyboardLayoutChangeNullEvent(IN EFI_EVENT Event,IN VOID * Context)118 KeyboardLayoutChangeNullEvent (
119   IN EFI_EVENT                Event,
120   IN VOID                     *Context
121   )
122 {
123   return;
124 }
125 
126 /**
127   Initialize HII Database.
128 
129 
130   @param ImageHandle     The image handle.
131   @param SystemTable     The system table.
132 
133   @retval EFI_SUCCESS    The Hii database is setup correctly.
134   @return Other value if failed to create the default event for
135           gHiiKeyboardLayoutChanged. Check gBS->CreateEventEx for
136           details. Or failed to insatll the protocols.
137           Check gBS->InstallMultipleProtocolInterfaces for details.
138 
139 **/
140 EFI_STATUS
141 EFIAPI
InitializeHiiDatabase(IN EFI_HANDLE ImageHandle,IN EFI_SYSTEM_TABLE * SystemTable)142 InitializeHiiDatabase (
143   IN EFI_HANDLE           ImageHandle,
144   IN EFI_SYSTEM_TABLE     *SystemTable
145   )
146 {
147   EFI_STATUS                             Status;
148   EFI_HANDLE                             Handle;
149 
150   //
151   // There will be only one HII Database in the system
152   // If there is another out there, someone is trying to install us
153   // again.  Fail that scenario.
154   //
155   ASSERT_PROTOCOL_ALREADY_INSTALLED (NULL, &gEfiHiiDatabaseProtocolGuid);
156   ASSERT_PROTOCOL_ALREADY_INSTALLED (NULL, &gEfiHiiFontProtocolGuid);
157   ASSERT_PROTOCOL_ALREADY_INSTALLED (NULL, &gEfiHiiImageProtocolGuid);
158   ASSERT_PROTOCOL_ALREADY_INSTALLED (NULL, &gEfiHiiStringProtocolGuid);
159   ASSERT_PROTOCOL_ALREADY_INSTALLED (NULL, &gEfiHiiConfigRoutingProtocolGuid);
160   ASSERT_PROTOCOL_ALREADY_INSTALLED (NULL, &gEfiConfigKeywordHandlerProtocolGuid);
161 
162   InitializeListHead (&mPrivate.DatabaseList);
163   InitializeListHead (&mPrivate.DatabaseNotifyList);
164   InitializeListHead (&mPrivate.HiiHandleList);
165   InitializeListHead (&mPrivate.FontInfoList);
166 
167   //
168   // Create a event with EFI_HII_SET_KEYBOARD_LAYOUT_EVENT_GUID group type.
169   //
170   Status = gBS->CreateEventEx (
171                   EVT_NOTIFY_SIGNAL,
172                   TPL_NOTIFY,
173                   KeyboardLayoutChangeNullEvent,
174                   NULL,
175                   &gEfiHiiKeyBoardLayoutGuid,
176                   &gHiiKeyboardLayoutChanged
177                   );
178   if (EFI_ERROR (Status)) {
179     return Status;
180   }
181 
182   Handle = NULL;
183   Status = gBS->InstallMultipleProtocolInterfaces (
184                   &Handle,
185                   &gEfiHiiFontProtocolGuid,
186                   &mPrivate.HiiFont,
187                   &gEfiHiiStringProtocolGuid,
188                   &mPrivate.HiiString,
189                   &gEfiHiiDatabaseProtocolGuid,
190                   &mPrivate.HiiDatabase,
191                   &gEfiHiiConfigRoutingProtocolGuid,
192                   &mPrivate.ConfigRouting,
193                   &gEfiConfigKeywordHandlerProtocolGuid,
194                   &mPrivate.ConfigKeywordHandler,
195                   NULL
196                   );
197 
198   if (EFI_ERROR (Status)) {
199     return Status;
200   }
201 
202   if (FeaturePcdGet (PcdSupportHiiImageProtocol)) {
203     CopyMem (&mPrivate.HiiImage, &mImageProtocol, sizeof (mImageProtocol));
204 
205     Status = gBS->InstallMultipleProtocolInterfaces (
206                     &Handle,
207                     &gEfiHiiImageProtocolGuid,
208                     &mPrivate.HiiImage,
209                     NULL
210                     );
211 
212   }
213 
214   return Status;
215 }
216 
217