3 Copyright (c) 2005 - 2007, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
24 #include <Protocol/ServiceBinding.h>
25 #include <Protocol/SimpleNetwork.h>
26 #include <Protocol/LoadedImage.h>
28 #include <Library/NetLib.h>
29 #include <Library/BaseLib.h>
30 #include <Library/DebugLib.h>
31 #include <Library/BaseMemoryLib.h>
32 #include <Library/UefiBootServicesTableLib.h>
33 #include <Library/UefiRuntimeServicesTableLib.h>
34 #include <Library/UefiLib.h>
35 #include <Library/MemoryAllocationLib.h>
39 // All the supported IP4 maskes in host byte order.
41 IP4_ADDR mIp4AllMasks
[IP4_MASK_NUM
] = {
82 Converts the low nibble of a byte to hex unicode character.
84 @param Nibble lower nibble of a byte.
86 @return Hex unicode character.
96 // This library interface is simply obsolete.
97 // Include the source code to user code.
102 return (CHAR16
)(Nibble
+ L
'0');
105 return (CHAR16
)(Nibble
- 0xA + L
'A');
109 Return the length of the mask. If the mask is invalid,
110 return the invalid length 33, which is IP4_MASK_NUM.
111 NetMask is in the host byte order.
113 @param NetMask The netmask to get the length from
115 @return The length of the netmask, IP4_MASK_NUM if the mask isn't
126 for (Index
= 0; Index
< IP4_MASK_NUM
; Index
++) {
127 if (NetMask
== mIp4AllMasks
[Index
]) {
138 Return the class of the address, such as class a, b, c.
139 Addr is in host byte order.
141 @param Addr The address to get the class from
143 @return IP address class, such as IP4_ADDR_CLASSA
153 ByteOne
= (UINT8
) (Addr
>> 24);
155 if ((ByteOne
& 0x80) == 0) {
156 return IP4_ADDR_CLASSA
;
158 } else if ((ByteOne
& 0xC0) == 0x80) {
159 return IP4_ADDR_CLASSB
;
161 } else if ((ByteOne
& 0xE0) == 0xC0) {
162 return IP4_ADDR_CLASSC
;
164 } else if ((ByteOne
& 0xF0) == 0xE0) {
165 return IP4_ADDR_CLASSD
;
168 return IP4_ADDR_CLASSE
;
175 Check whether the IP is a valid unicast address according to
176 the netmask. If NetMask is zero, use the IP address's class to
177 get the default mask.
179 @param Ip The IP to check againist
180 @param NetMask The mask of the IP
182 @return TRUE if IP is a valid unicast address on the network, otherwise FALSE
193 Class
= NetGetIpClass (Ip
);
195 if ((Ip
== 0) || (Class
>= IP4_ADDR_CLASSD
)) {
200 NetMask
= mIp4AllMasks
[Class
<< 3];
203 if (((Ip
&~NetMask
) == ~NetMask
) || ((Ip
&~NetMask
) == 0)) {
212 Initialize a random seed using current time.
216 @return The random seed initialized with current time.
227 gRT
->GetTime (&Time
, NULL
);
228 Seed
= (~Time
.Hour
<< 24 | Time
.Second
<< 16 | Time
.Minute
<< 8 | Time
.Day
);
229 Seed
^= Time
.Nanosecond
;
230 Seed
^= Time
.Year
<< 7;
237 Extract a UINT32 from a byte stream, then convert it to host
238 byte order. Use this function to avoid alignment error.
240 @param Buf The buffer to extract the UINT32.
242 @return The UINT32 extracted.
252 NetCopyMem (&Value
, Buf
, sizeof (UINT32
));
253 return NTOHL (Value
);
258 Put a UINT32 to the byte stream. Convert it from host byte order
259 to network byte order before putting.
261 @param Buf The buffer to put the UINT32
262 @param Data The data to put
274 NetCopyMem (Buf
, &Data
, sizeof (UINT32
));
279 Remove the first entry on the list
281 @param Head The list header
283 @return The entry that is removed from the list, NULL if the list is empty.
291 NET_LIST_ENTRY
*First
;
293 ASSERT (Head
!= NULL
);
295 if (NetListIsEmpty (Head
)) {
299 First
= Head
->ForwardLink
;
300 Head
->ForwardLink
= First
->ForwardLink
;
301 First
->ForwardLink
->BackLink
= Head
;
304 First
->ForwardLink
= (LIST_ENTRY
*) NULL
;
305 First
->BackLink
= (LIST_ENTRY
*) NULL
;
313 Remove the last entry on the list
315 @param Head The list head
317 @return The entry that is removed from the list, NULL if the list is empty.
325 NET_LIST_ENTRY
*Last
;
327 ASSERT (Head
!= NULL
);
329 if (NetListIsEmpty (Head
)) {
333 Last
= Head
->BackLink
;
334 Head
->BackLink
= Last
->BackLink
;
335 Last
->BackLink
->ForwardLink
= Head
;
338 Last
->ForwardLink
= (LIST_ENTRY
*) NULL
;
339 Last
->BackLink
= (LIST_ENTRY
*) NULL
;
347 Insert the NewEntry after the PrevEntry
349 @param PrevEntry The previous entry to insert after
350 @param NewEntry The new entry to insert
357 IN NET_LIST_ENTRY
*PrevEntry
,
358 IN NET_LIST_ENTRY
*NewEntry
361 NewEntry
->BackLink
= PrevEntry
;
362 NewEntry
->ForwardLink
= PrevEntry
->ForwardLink
;
363 PrevEntry
->ForwardLink
->BackLink
= NewEntry
;
364 PrevEntry
->ForwardLink
= NewEntry
;
369 Insert the NewEntry before the PostEntry
371 @param PostEntry The entry to insert before
372 @param NewEntry The new entry to insert
378 NetListInsertBefore (
379 IN NET_LIST_ENTRY
*PostEntry
,
380 IN NET_LIST_ENTRY
*NewEntry
383 NewEntry
->ForwardLink
= PostEntry
;
384 NewEntry
->BackLink
= PostEntry
->BackLink
;
385 PostEntry
->BackLink
->ForwardLink
= NewEntry
;
386 PostEntry
->BackLink
= NewEntry
;
391 Initialize the netmap. Netmap is a reposity to keep the <Key, Value> pairs.
393 @param Map The netmap to initialize
403 ASSERT (Map
!= NULL
);
405 NetListInit (&Map
->Used
);
406 NetListInit (&Map
->Recycled
);
412 To clean up the netmap, that is, release allocated memories.
414 @param Map The netmap to clean up.
425 NET_LIST_ENTRY
*Entry
;
426 NET_LIST_ENTRY
*Next
;
428 ASSERT (Map
!= NULL
);
430 NET_LIST_FOR_EACH_SAFE (Entry
, Next
, &Map
->Used
) {
431 Item
= NET_LIST_USER_STRUCT (Entry
, NET_MAP_ITEM
, Link
);
433 NetListRemoveEntry (&Item
->Link
);
439 ASSERT ((Map
->Count
== 0) && NetListIsEmpty (&Map
->Used
));
441 NET_LIST_FOR_EACH_SAFE (Entry
, Next
, &Map
->Recycled
) {
442 Item
= NET_LIST_USER_STRUCT (Entry
, NET_MAP_ITEM
, Link
);
444 NetListRemoveEntry (&Item
->Link
);
448 ASSERT (NetListIsEmpty (&Map
->Recycled
));
453 Test whether the netmap is empty
455 @param Map The net map to test
457 @return TRUE if the netmap is empty, otherwise FALSE.
465 ASSERT (Map
!= NULL
);
466 return (BOOLEAN
) (Map
->Count
== 0);
471 Return the number of the <Key, Value> pairs in the netmap.
473 @param Map The netmap to get the entry number
475 @return The entry number in the netmap.
488 Allocate an item for the netmap. It will try to allocate
489 a batch of items and return one.
491 @param Map The netmap to allocate item for
493 @return The allocated item or NULL
503 NET_LIST_ENTRY
*Head
;
506 ASSERT (Map
!= NULL
);
508 Head
= &Map
->Recycled
;
510 if (NetListIsEmpty (Head
)) {
511 for (Index
= 0; Index
< NET_MAP_INCREAMENT
; Index
++) {
512 Item
= NetAllocatePool (sizeof (NET_MAP_ITEM
));
522 NetListInsertHead (Head
, &Item
->Link
);
526 Item
= NET_LIST_HEAD (Head
, NET_MAP_ITEM
, Link
);
527 NetListRemoveHead (Head
);
534 Allocate an item to save the <Key, Value> pair to the head of the netmap.
536 @param Map The netmap to insert into
537 @param Key The user's key
538 @param Value The user's value for the key
540 @retval EFI_OUT_OF_RESOURCES Failed to allocate the memory for the item
541 @retval EFI_SUCCESS The item is inserted to the head
548 IN VOID
*Value OPTIONAL
553 ASSERT (Map
!= NULL
);
555 Item
= NetMapAllocItem (Map
);
558 return EFI_OUT_OF_RESOURCES
;
563 NetListInsertHead (&Map
->Used
, &Item
->Link
);
571 Allocate an item to save the <Key, Value> pair to the tail of the netmap.
573 @param Map The netmap to insert into
574 @param Key The user's key
575 @param Value The user's value for the key
577 @retval EFI_OUT_OF_RESOURCES Failed to allocate the memory for the item
578 @retval EFI_SUCCESS The item is inserted to the tail
585 IN VOID
*Value OPTIONAL
590 ASSERT (Map
!= NULL
);
592 Item
= NetMapAllocItem (Map
);
595 return EFI_OUT_OF_RESOURCES
;
600 NetListInsertTail (&Map
->Used
, &Item
->Link
);
609 Check whther the item is in the Map
611 @param Map The netmap to search within
612 @param Item The item to search
614 @return TRUE if the item is in the netmap, otherwise FALSE.
621 IN NET_MAP_ITEM
*Item
624 NET_LIST_ENTRY
*ListEntry
;
626 NET_LIST_FOR_EACH (ListEntry
, &Map
->Used
) {
627 if (ListEntry
== &Item
->Link
) {
637 Find the key in the netmap
639 @param Map The netmap to search within
640 @param Key The key to search
642 @return The point to the item contains the Key, or NULL if Key isn't in the map.
651 NET_LIST_ENTRY
*Entry
;
654 ASSERT (Map
!= NULL
);
656 NET_LIST_FOR_EACH (Entry
, &Map
->Used
) {
657 Item
= NET_LIST_USER_STRUCT (Entry
, NET_MAP_ITEM
, Link
);
659 if (Item
->Key
== Key
) {
669 Remove the item from the netmap
671 @param Map The netmap to remove the item from
672 @param Item The item to remove
673 @param Value The variable to receive the value if not NULL
675 @return The key of the removed item.
681 IN NET_MAP_ITEM
*Item
,
682 OUT VOID
**Value OPTIONAL
685 ASSERT ((Map
!= NULL
) && (Item
!= NULL
));
686 ASSERT (NetItemInMap (Map
, Item
));
688 NetListRemoveEntry (&Item
->Link
);
690 NetListInsertHead (&Map
->Recycled
, &Item
->Link
);
693 *Value
= Item
->Value
;
701 Remove the first entry on the netmap
703 @param Map The netmap to remove the head from
704 @param Value The variable to receive the value if not NULL
706 @return The key of the item removed
712 OUT VOID
**Value OPTIONAL
718 // Often, it indicates a programming error to remove
719 // the first entry in an empty list
721 ASSERT (Map
&& !NetListIsEmpty (&Map
->Used
));
723 Item
= NET_LIST_HEAD (&Map
->Used
, NET_MAP_ITEM
, Link
);
724 NetListRemoveEntry (&Item
->Link
);
726 NetListInsertHead (&Map
->Recycled
, &Item
->Link
);
729 *Value
= Item
->Value
;
737 Remove the last entry on the netmap
739 @param Map The netmap to remove the tail from
740 @param Value The variable to receive the value if not NULL
742 @return The key of the item removed
748 OUT VOID
**Value OPTIONAL
754 // Often, it indicates a programming error to remove
755 // the last entry in an empty list
757 ASSERT (Map
&& !NetListIsEmpty (&Map
->Used
));
759 Item
= NET_LIST_TAIL (&Map
->Used
, NET_MAP_ITEM
, Link
);
760 NetListRemoveEntry (&Item
->Link
);
762 NetListInsertHead (&Map
->Recycled
, &Item
->Link
);
765 *Value
= Item
->Value
;
773 Iterate through the netmap and call CallBack for each item. It will
774 contiue the traverse if CallBack returns EFI_SUCCESS, otherwise, break
775 from the loop. It returns the CallBack's last return value. This
776 function is delete safe for the current item.
778 @param Map The Map to iterate through
779 @param CallBack The callback function to call for each item.
780 @param Arg The opaque parameter to the callback
782 @return It returns the CallBack's last return value.
788 IN NET_MAP_CALLBACK CallBack
,
793 NET_LIST_ENTRY
*Entry
;
794 NET_LIST_ENTRY
*Next
;
795 NET_LIST_ENTRY
*Head
;
799 ASSERT ((Map
!= NULL
) && (CallBack
!= NULL
));
803 if (NetListIsEmpty (Head
)) {
807 NET_LIST_FOR_EACH_SAFE (Entry
, Next
, Head
) {
808 Item
= NET_LIST_USER_STRUCT (Entry
, NET_MAP_ITEM
, Link
);
809 Result
= CallBack (Map
, Item
, Arg
);
811 if (EFI_ERROR (Result
)) {
821 This is the default unload handle for all the network drivers.
823 @param ImageHandle The drivers' driver image.
825 @retval EFI_SUCCESS The image is unloaded.
826 @retval Others Failed to unload the image.
831 NetLibDefaultUnload (
832 IN EFI_HANDLE ImageHandle
836 EFI_HANDLE
*DeviceHandleBuffer
;
837 UINTN DeviceHandleCount
;
839 EFI_DRIVER_BINDING_PROTOCOL
*DriverBinding
;
840 #if (EFI_SPECIFICATION_VERSION >= 0x00020000)
841 EFI_COMPONENT_NAME2_PROTOCOL
*ComponentName
;
843 EFI_COMPONENT_NAME_PROTOCOL
*ComponentName
;
845 EFI_DRIVER_CONFIGURATION_PROTOCOL
*DriverConfiguration
;
846 EFI_DRIVER_DIAGNOSTICS_PROTOCOL
*DriverDiagnostics
;
849 // Get the list of all the handles in the handle database.
850 // If there is an error getting the list, then the unload
853 Status
= gBS
->LocateHandleBuffer (
861 if (EFI_ERROR (Status
)) {
866 // Disconnect the driver specified by ImageHandle from all
867 // the devices in the handle database.
869 for (Index
= 0; Index
< DeviceHandleCount
; Index
++) {
870 Status
= gBS
->DisconnectController (
871 DeviceHandleBuffer
[Index
],
878 // Uninstall all the protocols installed in the driver entry point
880 for (Index
= 0; Index
< DeviceHandleCount
; Index
++) {
881 Status
= gBS
->HandleProtocol (
882 DeviceHandleBuffer
[Index
],
883 &gEfiDriverBindingProtocolGuid
,
884 (VOID
**) &DriverBinding
887 if (EFI_ERROR (Status
)) {
891 if (DriverBinding
->ImageHandle
!= ImageHandle
) {
895 gBS
->UninstallProtocolInterface (
897 &gEfiDriverBindingProtocolGuid
,
900 Status
= gBS
->HandleProtocol (
901 DeviceHandleBuffer
[Index
],
902 &gEfiComponentNameProtocolGuid
,
903 (VOID
**) &ComponentName
905 if (!EFI_ERROR (Status
)) {
906 gBS
->UninstallProtocolInterface (
908 &gEfiComponentNameProtocolGuid
,
913 Status
= gBS
->HandleProtocol (
914 DeviceHandleBuffer
[Index
],
915 &gEfiDriverConfigurationProtocolGuid
,
916 (VOID
**) &DriverConfiguration
919 if (!EFI_ERROR (Status
)) {
920 gBS
->UninstallProtocolInterface (
922 &gEfiDriverConfigurationProtocolGuid
,
927 Status
= gBS
->HandleProtocol (
928 DeviceHandleBuffer
[Index
],
929 &gEfiDriverDiagnosticsProtocolGuid
,
930 (VOID
**) &DriverDiagnostics
933 if (!EFI_ERROR (Status
)) {
934 gBS
->UninstallProtocolInterface (
936 &gEfiDriverDiagnosticsProtocolGuid
,
943 // Free the buffer containing the list of handles from the handle database
945 if (DeviceHandleBuffer
!= NULL
) {
946 gBS
->FreePool (DeviceHandleBuffer
);
955 Create a child of the service that is identified by ServiceBindingGuid.
957 @param Controller The controller which has the service installed.
958 @param Image The image handle used to open service.
959 @param ServiceBindingGuid The service's Guid.
960 @param ChildHandle The handle to receive the create child
962 @retval EFI_SUCCESS The child is successfully created.
963 @retval Others Failed to create the child.
967 NetLibCreateServiceChild (
968 IN EFI_HANDLE Controller
,
970 IN EFI_GUID
*ServiceBindingGuid
,
971 OUT EFI_HANDLE
*ChildHandle
975 EFI_SERVICE_BINDING_PROTOCOL
*Service
;
978 ASSERT ((ServiceBindingGuid
!= NULL
) && (ChildHandle
!= NULL
));
981 // Get the ServiceBinding Protocol
983 Status
= gBS
->OpenProtocol (
989 EFI_OPEN_PROTOCOL_GET_PROTOCOL
992 if (EFI_ERROR (Status
)) {
999 Status
= Service
->CreateChild (Service
, ChildHandle
);
1005 Destory a child of the service that is identified by ServiceBindingGuid.
1007 @param Controller The controller which has the service installed.
1008 @param Image The image handle used to open service.
1009 @param ServiceBindingGuid The service's Guid.
1010 @param ChildHandle The child to destory
1012 @retval EFI_SUCCESS The child is successfully destoried.
1013 @retval Others Failed to destory the child.
1017 NetLibDestroyServiceChild (
1018 IN EFI_HANDLE Controller
,
1019 IN EFI_HANDLE Image
,
1020 IN EFI_GUID
*ServiceBindingGuid
,
1021 IN EFI_HANDLE ChildHandle
1025 EFI_SERVICE_BINDING_PROTOCOL
*Service
;
1027 ASSERT (ServiceBindingGuid
!= NULL
);
1030 // Get the ServiceBinding Protocol
1032 Status
= gBS
->OpenProtocol (
1038 EFI_OPEN_PROTOCOL_GET_PROTOCOL
1041 if (EFI_ERROR (Status
)) {
1046 // destory the child
1048 Status
= Service
->DestroyChild (Service
, ChildHandle
);
1054 Convert the mac address of the simple network protocol installed on
1055 SnpHandle to a unicode string. Callers are responsible for freeing the
1058 @param SnpHandle The handle where the simple network protocol is
1060 @param ImageHandle The image handle used to act as the agent handle to
1061 get the simple network protocol.
1062 @param MacString The pointer to store the address of the string
1063 representation of the mac address.
1065 @retval EFI_OUT_OF_RESOURCES There are not enough memory resource.
1066 @retval other Failed to open the simple network protocol.
1070 NetLibGetMacString (
1071 IN EFI_HANDLE SnpHandle
,
1072 IN EFI_HANDLE ImageHandle
,
1073 IN OUT CHAR16
**MacString
1077 EFI_SIMPLE_NETWORK_PROTOCOL
*Snp
;
1078 EFI_SIMPLE_NETWORK_MODE
*Mode
;
1085 // Get the Simple Network protocol from the SnpHandle.
1087 Status
= gBS
->OpenProtocol (
1089 &gEfiSimpleNetworkProtocolGuid
,
1093 EFI_OPEN_PROTOCOL_GET_PROTOCOL
1095 if (EFI_ERROR (Status
)) {
1102 // It takes 2 unicode characters to represent a 1 byte binary buffer.
1103 // Plus one unicode character for the null-terminator.
1105 MacAddress
= NetAllocatePool ((2 * Mode
->HwAddressSize
+ 1) * sizeof (CHAR16
));
1106 if (MacAddress
== NULL
) {
1107 return EFI_OUT_OF_RESOURCES
;
1111 // Convert the mac address into a unicode string.
1113 for (Index
= 0; Index
< Mode
->HwAddressSize
; Index
++) {
1114 MacAddress
[Index
* 2] = NibbleToHexChar ((UINT8
) (Mode
->CurrentAddress
.Addr
[Index
] >> 4));
1115 MacAddress
[Index
* 2 + 1] = NibbleToHexChar (Mode
->CurrentAddress
.Addr
[Index
]);
1118 MacAddress
[Mode
->HwAddressSize
* 2] = L
'\0';
1120 *MacString
= MacAddress
;
1127 Find the UNDI/SNP handle from controller and protocol GUID.
1128 For example, IP will open a MNP child to transmit/receive
1129 packets, when MNP is stopped, IP should also be stopped. IP
1130 needs to find its own private data which is related the IP's
1131 service binding instance that is install on UNDI/SNP handle.
1132 Now, the controller is either a MNP or ARP child handle. But
1133 IP opens these handle BY_DRIVER, use that info, we can get the
1136 @param Controller Then protocol handle to check
1137 @param ProtocolGuid The protocol that is related with the handle.
1139 @return The UNDI/SNP handle or NULL.
1143 NetLibGetNicHandle (
1144 IN EFI_HANDLE Controller
,
1145 IN EFI_GUID
*ProtocolGuid
1148 EFI_OPEN_PROTOCOL_INFORMATION_ENTRY
*OpenBuffer
;
1154 Status
= gBS
->OpenProtocolInformation (
1161 if (EFI_ERROR (Status
)) {
1167 for (Index
= 0; Index
< OpenCount
; Index
++) {
1168 if (OpenBuffer
[Index
].Attributes
& EFI_OPEN_PROTOCOL_BY_DRIVER
) {
1169 Handle
= OpenBuffer
[Index
].ControllerHandle
;
1174 gBS
->FreePool (OpenBuffer
);
1179 NetLibInstallAllDriverProtocols (
1180 IN EFI_HANDLE ImageHandle
,
1181 IN EFI_SYSTEM_TABLE
*SystemTable
,
1182 IN EFI_DRIVER_BINDING_PROTOCOL
*DriverBinding
,
1183 IN EFI_HANDLE DriverBindingHandle
,
1184 IN EFI_COMPONENT_NAME_PROTOCOL
*ComponentName
, OPTIONAL
1185 IN EFI_DRIVER_CONFIGURATION_PROTOCOL
*DriverConfiguration
, OPTIONAL
1186 IN EFI_DRIVER_DIAGNOSTICS_PROTOCOL
*DriverDiagnostics OPTIONAL
1190 Routine Description:
1192 Intialize a driver by installing the Driver Binding Protocol onto the
1193 driver's DriverBindingHandle. This is typically the same as the driver's
1194 ImageHandle, but it can be different if the driver produces multiple
1195 DriverBinding Protocols. This function also initializes the EFI Driver
1196 Library that initializes the global variables gST, gBS, gRT.
1200 ImageHandle - The image handle of the driver
1201 SystemTable - The EFI System Table that was passed to the driver's
1203 DriverBinding - A Driver Binding Protocol instance that this driver
1205 DriverBindingHandle - The handle that DriverBinding is to be installe onto.
1206 If this parameter is NULL, then a new handle is created.
1207 ComponentName - A Component Name Protocol instance that this driver is
1209 DriverConfiguration - A Driver Configuration Protocol instance that this
1210 driver is producing.
1211 DriverDiagnostics - A Driver Diagnostics Protocol instance that this
1212 driver is producing.
1216 EFI_SUCCESS if all the protocols were installed onto DriverBindingHandle
1217 Otherwise, then return status from gBS->InstallProtocolInterface()
1221 return NetLibInstallAllDriverProtocolsWithUnload (
1225 DriverBindingHandle
,
1227 DriverConfiguration
,
1234 NetLibInstallAllDriverProtocolsWithUnload (
1235 IN EFI_HANDLE ImageHandle
,
1236 IN EFI_SYSTEM_TABLE
*SystemTable
,
1237 IN EFI_DRIVER_BINDING_PROTOCOL
*DriverBinding
,
1238 IN EFI_HANDLE DriverBindingHandle
,
1239 IN EFI_COMPONENT_NAME_PROTOCOL
*ComponentName
, OPTIONAL
1240 IN EFI_DRIVER_CONFIGURATION_PROTOCOL
*DriverConfiguration
, OPTIONAL
1241 IN EFI_DRIVER_DIAGNOSTICS_PROTOCOL
*DriverDiagnostics
, OPTIONAL
1242 IN NET_LIB_DRIVER_UNLOAD Unload
1246 Routine Description:
1248 Intialize a driver by installing the Driver Binding Protocol onto the
1249 driver's DriverBindingHandle. This is typically the same as the driver's
1250 ImageHandle, but it can be different if the driver produces multiple
1251 DriverBinding Protocols. This function also initializes the EFI Driver
1252 Library that initializes the global variables gST, gBS, gRT.
1256 ImageHandle - The image handle of the driver
1257 SystemTable - The EFI System Table that was passed to the driver's
1259 DriverBinding - A Driver Binding Protocol instance that this driver
1261 DriverBindingHandle - The handle that DriverBinding is to be installe onto.
1262 If this parameter is NULL, then a new handle is created.
1263 ComponentName - A Component Name Protocol instance that this driver is
1265 DriverConfiguration - A Driver Configuration Protocol instance that this
1266 driver is producing.
1267 DriverDiagnostics - A Driver Diagnostics Protocol instance that this
1268 driver is producing.
1269 Unload - The customized unload to install.
1273 EFI_SUCCESS if all the protocols were installed onto DriverBindingHandle
1274 Otherwise, then return status from gBS->InstallProtocolInterface()
1279 EFI_LOADED_IMAGE_PROTOCOL
*LoadedImage
;
1281 Status
= EfiLibInstallAllDriverProtocols (
1285 DriverBindingHandle
,
1287 DriverConfiguration
,
1291 if (EFI_ERROR (Status
)) {
1296 // Retrieve the Loaded Image Protocol from Image Handle
1298 Status
= gBS
->OpenProtocol (
1300 &gEfiLoadedImageProtocolGuid
,
1301 (VOID
**) &LoadedImage
,
1304 EFI_OPEN_PROTOCOL_GET_PROTOCOL
1307 if (EFI_ERROR (Status
)) {
1312 // Fill in the Unload() service of the Loaded Image Protocol
1314 LoadedImage
->Unload
= (Unload
== NULL
) ? NetLibDefaultUnload
: Unload
;