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