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