]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - MdeModulePkg/Library/ExtendedHiiLib/ExtendedHiiLib.c
1, Move device path utility macros from protocol's header file to DevicePathLib libra...
[mirror_edk2.git] / MdeModulePkg / Library / ExtendedHiiLib / ExtendedHiiLib.c
... / ...
CommitLineData
1/** @file\r
2 HII Library implementation that uses DXE protocols and services.\r
3\r
4Copyright (c) 2006 - 2008, Intel Corporation. <BR>\r
5All rights reserved. This program and the accompanying materials\r
6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15\r
16#include <Uefi.h>\r
17\r
18#include <Protocol/DevicePath.h>\r
19\r
20#include <Library/BaseMemoryLib.h>\r
21#include <Library/DebugLib.h>\r
22#include <Library/MemoryAllocationLib.h>\r
23#include <Library/UefiBootServicesTableLib.h>\r
24#include <MdeModuleHii.h>\r
25\r
26\r
27//\r
28// Hii vendor device path template\r
29//\r
30GLOBAL_REMOVE_IF_UNREFERENCED CONST HII_VENDOR_DEVICE_PATH mHiiVendorDevicePathTemplate = {\r
31 {\r
32 {\r
33 {\r
34 HARDWARE_DEVICE_PATH,\r
35 HW_VENDOR_DP,\r
36 {\r
37 (UINT8) (sizeof (HII_VENDOR_DEVICE_PATH_NODE)),\r
38 (UINT8) ((sizeof (HII_VENDOR_DEVICE_PATH_NODE)) >> 8)\r
39 }\r
40 },\r
41 EFI_IFR_TIANO_GUID\r
42 },\r
43 0,\r
44 0\r
45 },\r
46 {\r
47 END_DEVICE_PATH_TYPE,\r
48 END_ENTIRE_DEVICE_PATH_SUBTYPE,\r
49 { \r
50 END_DEVICE_PATH_LENGTH\r
51 }\r
52 }\r
53};\r
54\r
55/**\r
56 The HII driver handle passed in for HiiDatabase.NewPackageList() requires\r
57 that there should be DevicePath Protocol installed on it.\r
58 This routine create a virtual Driver Handle by installing a vendor device\r
59 path on it, so as to use it to invoke HiiDatabase.NewPackageList().\r
60 The Device Path created is a Vendor Device Path specific to Intel's implemenation\r
61 and it is defined as HII_VENDOR_DEVICE_PATH_NODE.\r
62 \r
63\r
64 @param DriverHandle Handle to be returned\r
65\r
66 @retval EFI_SUCCESS Handle destroy success.\r
67 @retval EFI_OUT_OF_RESOURCES Not enough memory.\r
68\r
69**/\r
70EFI_STATUS\r
71EFIAPI\r
72HiiLibCreateHiiDriverHandle (\r
73 OUT EFI_HANDLE *DriverHandle\r
74 )\r
75{\r
76 EFI_STATUS Status;\r
77 HII_VENDOR_DEVICE_PATH_NODE *VendorDevicePath;\r
78\r
79 VendorDevicePath = AllocateCopyPool (sizeof (HII_VENDOR_DEVICE_PATH), &mHiiVendorDevicePathTemplate);\r
80 if (VendorDevicePath == NULL) {\r
81 return EFI_OUT_OF_RESOURCES;\r
82 }\r
83\r
84 //\r
85 // Use memory address as unique ID to distinguish from different device paths\r
86 //\r
87 VendorDevicePath->UniqueId = (UINT64) ((UINTN) VendorDevicePath);\r
88\r
89 *DriverHandle = NULL;\r
90 Status = gBS->InstallMultipleProtocolInterfaces (\r
91 DriverHandle,\r
92 &gEfiDevicePathProtocolGuid,\r
93 VendorDevicePath,\r
94 NULL\r
95 );\r
96 if (EFI_ERROR (Status)) {\r
97 return Status;\r
98 }\r
99\r
100 return EFI_SUCCESS;\r
101}\r
102\r
103\r
104/**\r
105 Destroy the Driver Handle created by CreateHiiDriverHandle().\r
106\r
107 If no Device Path protocol is installed on the DriverHandle, then ASSERT.\r
108 If this Device Path protocol is failed to be uninstalled, then ASSERT.\r
109\r
110 @param DriverHandle Handle returned by CreateHiiDriverHandle()\r
111\r
112\r
113**/\r
114VOID\r
115EFIAPI\r
116HiiLibDestroyHiiDriverHandle (\r
117 IN EFI_HANDLE DriverHandle\r
118 )\r
119{\r
120 EFI_STATUS Status;\r
121 EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
122\r
123 Status = gBS->HandleProtocol (\r
124 DriverHandle,\r
125 &gEfiDevicePathProtocolGuid,\r
126 (VOID **) &DevicePath\r
127 );\r
128 ASSERT_EFI_ERROR (Status);\r
129\r
130 Status = gBS->UninstallProtocolInterface (\r
131 DriverHandle,\r
132 &gEfiDevicePathProtocolGuid,\r
133 DevicePath\r
134 );\r
135 ASSERT_EFI_ERROR (Status);\r
136\r
137 FreePool (DevicePath);\r
138\r
139}\r
140\r
141\r
142\r