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