3 Copyright (c) 2010, Apple, Inc. All rights reserved.<BR>
4 Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
16 #include "EmuSnpDxe.h"
20 EFI_SIMPLE_NETWORK_PROTOCOL gEmuSnpTemplate
= {
21 EFI_SIMPLE_NETWORK_PROTOCOL_REVISION
,
35 NULL
, // WaitForPacket
39 EFI_SIMPLE_NETWORK_MODE gEmuSnpModeTemplate
= {
40 EfiSimpleNetworkStopped
, // State
41 NET_ETHER_ADDR_LEN
, // HwAddressSize
42 NET_ETHER_HEADER_SIZE
, // MediaHeaderSize
43 1500, // MaxPacketSize
46 0, // ReceiveFilterMask
47 0, // ReceiveFilterSetting
48 MAX_MCAST_FILTER_CNT
, // MaxMCastFilterCount
49 0, // MCastFilterCount
58 }, // BroadcastAddress
61 }, // PermanentAddress
62 NET_IFTYPE_ETHERNET
, // IfType
63 FALSE
, // MacAddressChangeable
64 FALSE
, // MultipleTxSupported
65 FALSE
, // MediaPresentSupported
71 Changes the state of a network interface from "stopped" to "started".
73 @param This Protocol instance pointer.
75 @retval EFI_SUCCESS Always succeeds.
81 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
85 EMU_SNP_PRIVATE_DATA
*Private
;
87 Private
= EMU_SNP_PRIVATE_DATA_FROM_SNP_THIS (This
);
89 Status
= Private
->Io
->Start (Private
->Io
);
95 Changes the state of a network interface from "started" to "stopped".
97 @param This Protocol instance pointer.
99 @retval EFI_SUCCESS Always succeeds.
105 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
109 EMU_SNP_PRIVATE_DATA
*Private
;
111 Private
= EMU_SNP_PRIVATE_DATA_FROM_SNP_THIS (This
);
113 Status
= Private
->Io
->Stop (Private
->Io
);
119 Resets a network adapter and allocates the transmit and receive buffers
120 required by the network interface; optionally, also requests allocation
121 of additional transmit and receive buffers.
123 @param This Protocol instance pointer.
124 @param ExtraRxBufferSize The size, in bytes, of the extra receive buffer space
125 that the driver should allocate for the network interface.
126 Some network interfaces will not be able to use the extra
127 buffer, and the caller will not know if it is actually
129 @param ExtraTxBufferSize The size, in bytes, of the extra transmit buffer space
130 that the driver should allocate for the network interface.
131 Some network interfaces will not be able to use the extra
132 buffer, and the caller will not know if it is actually
135 @retval EFI_SUCCESS Always succeeds.
141 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
142 IN UINTN ExtraRxBufferSize OPTIONAL
,
143 IN UINTN ExtraTxBufferSize OPTIONAL
147 EMU_SNP_PRIVATE_DATA
*Private
;
149 Private
= EMU_SNP_PRIVATE_DATA_FROM_SNP_THIS (This
);
151 Status
= Private
->Io
->Initialize (Private
->Io
, ExtraRxBufferSize
, ExtraTxBufferSize
);
156 Resets a network adapter and re-initializes it with the parameters that were
157 provided in the previous call to Initialize().
159 @param This Protocol instance pointer.
160 @param ExtendedVerification Indicates that the driver may perform a more
161 exhaustive verification operation of the device
164 @retval EFI_SUCCESS Always succeeds.
170 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
171 IN BOOLEAN ExtendedVerification
175 EMU_SNP_PRIVATE_DATA
*Private
;
177 Private
= EMU_SNP_PRIVATE_DATA_FROM_SNP_THIS (This
);
179 Status
= Private
->Io
->Reset (Private
->Io
, ExtendedVerification
);
184 Resets a network adapter and leaves it in a state that is safe for
185 another driver to initialize.
187 @param This Protocol instance pointer.
189 @retval EFI_SUCCESS Always succeeds.
195 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
199 EMU_SNP_PRIVATE_DATA
*Private
;
201 Private
= EMU_SNP_PRIVATE_DATA_FROM_SNP_THIS (This
);
203 Status
= Private
->Io
->Shutdown (Private
->Io
);
208 Manages the multicast receive filters of a network interface.
210 @param This Protocol instance pointer.
211 @param EnableBits A bit mask of receive filters to enable on the network interface.
212 @param DisableBits A bit mask of receive filters to disable on the network interface.
213 @param ResetMcastFilter Set to TRUE to reset the contents of the multicast receive
214 filters on the network interface to their default values.
215 @param McastFilterCount Number of multicast HW MAC addresses in the new
216 MCastFilter list. This value must be less than or equal to
217 the MCastFilterCnt field of EFI_SIMPLE_NETWORK_MODE. This
218 field is optional if ResetMCastFilter is TRUE.
219 @param McastFilter A pointer to a list of new multicast receive filter HW MAC
220 addresses. This list will replace any existing multicast
221 HW MAC address list. This field is optional if
222 ResetMCastFilter is TRUE.
224 @retval EFI_SUCCESS The multicast receive filter list was updated.
225 @retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
230 EmuSnpReceiveFilters (
231 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
232 IN UINT32 EnableBits
,
233 IN UINT32 DisableBits
,
234 IN BOOLEAN ResetMcastFilter
,
235 IN UINTN McastFilterCount OPTIONAL
,
236 IN EFI_MAC_ADDRESS
*McastFilter OPTIONAL
240 EMU_SNP_PRIVATE_DATA
*Private
;
242 Private
= EMU_SNP_PRIVATE_DATA_FROM_SNP_THIS (This
);
244 Status
= Private
->Io
->ReceiveFilters (
256 Modifies or resets the current station address, if supported.
258 @param This Protocol instance pointer.
259 @param Reset Flag used to reset the station address to the network interfaces
261 @param NewMacAddr New station address to be used for the network interface.
263 @retval EFI_UNSUPPORTED Not supported yet.
268 EmuSnpStationAddress (
269 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
271 IN EFI_MAC_ADDRESS
*NewMacAddr OPTIONAL
275 EMU_SNP_PRIVATE_DATA
*Private
;
277 Private
= EMU_SNP_PRIVATE_DATA_FROM_SNP_THIS (This
);
279 Status
= Private
->Io
->StationAddress (Private
->Io
, Reset
, NewMacAddr
);
284 Resets or collects the statistics on a network interface.
286 @param This Protocol instance pointer.
287 @param Reset Set to TRUE to reset the statistics for the network interface.
288 @param StatisticsSize On input the size, in bytes, of StatisticsTable. On
289 output the size, in bytes, of the resulting table of
291 @param StatisticsTable A pointer to the EFI_NETWORK_STATISTICS structure that
292 contains the statistics.
294 @retval EFI_SUCCESS The statistics were collected from the network interface.
295 @retval EFI_NOT_STARTED The network interface has not been started.
296 @retval EFI_BUFFER_TOO_SMALL The Statistics buffer was too small. The current buffer
297 size needed to hold the statistics is returned in
299 @retval EFI_UNSUPPORTED Not supported yet.
305 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
307 IN OUT UINTN
*StatisticsSize OPTIONAL
,
308 OUT EFI_NETWORK_STATISTICS
*StatisticsTable OPTIONAL
312 EMU_SNP_PRIVATE_DATA
*Private
;
314 Private
= EMU_SNP_PRIVATE_DATA_FROM_SNP_THIS (This
);
316 Status
= Private
->Io
->Statistics (Private
->Io
, Reset
, StatisticsSize
, StatisticsTable
);
321 Converts a multicast IP address to a multicast HW MAC address.
323 @param This Protocol instance pointer.
324 @param Ipv6 Set to TRUE if the multicast IP address is IPv6 [RFC 2460]. Set
325 to FALSE if the multicast IP address is IPv4 [RFC 791].
326 @param Ip The multicast IP address that is to be converted to a multicast
328 @param Mac The multicast HW MAC address that is to be generated from IP.
330 @retval EFI_SUCCESS The multicast IP address was mapped to the multicast
332 @retval EFI_NOT_STARTED The network interface has not been started.
333 @retval EFI_BUFFER_TOO_SMALL The Statistics buffer was too small. The current buffer
334 size needed to hold the statistics is returned in
336 @retval EFI_UNSUPPORTED Not supported yet.
342 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
344 IN EFI_IP_ADDRESS
*Ip
,
345 OUT EFI_MAC_ADDRESS
*Mac
349 EMU_SNP_PRIVATE_DATA
*Private
;
351 Private
= EMU_SNP_PRIVATE_DATA_FROM_SNP_THIS (This
);
353 Status
= Private
->Io
->MCastIpToMac (Private
->Io
, Ipv6
, Ip
, Mac
);
359 Performs read and write operations on the NVRAM device attached to a
362 @param This Protocol instance pointer.
363 @param ReadOrWrite TRUE for read operations, FALSE for write operations.
364 @param Offset Byte offset in the NVRAM device at which to start the read or
365 write operation. This must be a multiple of NvRamAccessSize and
367 @param BufferSize The number of bytes to read or write from the NVRAM device.
368 This must also be a multiple of NvramAccessSize.
369 @param Buffer A pointer to the data buffer.
371 @retval EFI_UNSUPPORTED Not supported yet.
377 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
378 IN BOOLEAN ReadOrWrite
,
385 EMU_SNP_PRIVATE_DATA
*Private
;
387 Private
= EMU_SNP_PRIVATE_DATA_FROM_SNP_THIS (This
);
389 Status
= Private
->Io
->NvData (Private
->Io
, ReadOrWrite
, Offset
, BufferSize
, Buffer
);
395 Reads the current interrupt status and recycled transmit buffer status from
398 @param This Protocol instance pointer.
399 @param InterruptStatus A pointer to the bit mask of the currently active interrupts
400 If this is NULL, the interrupt status will not be read from
401 the device. If this is not NULL, the interrupt status will
402 be read from the device. When the interrupt status is read,
403 it will also be cleared. Clearing the transmit interrupt
404 does not empty the recycled transmit buffer array.
405 @param TxBuffer Recycled transmit buffer address. The network interface will
406 not transmit if its internal recycled transmit buffer array
407 is full. Reading the transmit buffer does not clear the
408 transmit interrupt. If this is NULL, then the transmit buffer
409 status will not be read. If there are no transmit buffers to
410 recycle and TxBuf is not NULL, * TxBuf will be set to NULL.
412 @retval EFI_SUCCESS Always succeeds.
418 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
419 OUT UINT32
*InterruptStatus
,
424 EMU_SNP_PRIVATE_DATA
*Private
;
426 Private
= EMU_SNP_PRIVATE_DATA_FROM_SNP_THIS (This
);
428 Status
= Private
->Io
->GetStatus (Private
->Io
, InterruptStatus
, TxBuffer
);
434 Places a packet in the transmit queue of a network interface.
436 @param This Protocol instance pointer.
437 @param HeaderSize The size, in bytes, of the media header to be filled in by
438 the Transmit() function. If HeaderSize is non-zero, then it
439 must be equal to This->Mode->MediaHeaderSize and the DestAddr
440 and Protocol parameters must not be NULL.
441 @param BufferSize The size, in bytes, of the entire packet (media header and
442 data) to be transmitted through the network interface.
443 @param Buffer A pointer to the packet (media header followed by data) to be
444 transmitted. This parameter cannot be NULL. If HeaderSize is zero,
445 then the media header in Buffer must already be filled in by the
446 caller. If HeaderSize is non-zero, then the media header will be
447 filled in by the Transmit() function.
448 @param SrcAddr The source HW MAC address. If HeaderSize is zero, then this parameter
449 is ignored. If HeaderSize is non-zero and SrcAddr is NULL, then
450 This->Mode->CurrentAddress is used for the source HW MAC address.
451 @param DestAddr The destination HW MAC address. If HeaderSize is zero, then this
452 parameter is ignored.
453 @param Protocol The type of header to build. If HeaderSize is zero, then this
454 parameter is ignored. See RFC 1700, section "Ether Types", for
457 @retval EFI_SUCCESS The packet was placed on the transmit queue.
458 @retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
459 @retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value.
460 @retval EFI_NOT_STARTED The network interface has not been started.
466 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
470 IN EFI_MAC_ADDRESS
*SrcAddr OPTIONAL
,
471 IN EFI_MAC_ADDRESS
*DestAddr OPTIONAL
,
472 IN UINT16
*Protocol OPTIONAL
476 EMU_SNP_PRIVATE_DATA
*Private
;
478 Private
= EMU_SNP_PRIVATE_DATA_FROM_SNP_THIS (This
);
480 Status
= Private
->Io
->Transmit (
493 Receives a packet from a network interface.
495 @param This Protocol instance pointer.
496 @param HeaderSize The size, in bytes, of the media header received on the network
497 interface. If this parameter is NULL, then the media header size
498 will not be returned.
499 @param BuffSize On entry, the size, in bytes, of Buffer. On exit, the size, in
500 bytes, of the packet that was received on the network interface.
501 @param Buffer A pointer to the data buffer to receive both the media header and
503 @param SourceAddr The source HW MAC address. If this parameter is NULL, the
504 HW MAC source address will not be extracted from the media
506 @param DestinationAddr The destination HW MAC address. If this parameter is NULL,
507 the HW MAC destination address will not be extracted from the
509 @param Protocol The media header type. If this parameter is NULL, then the
510 protocol will not be extracted from the media header. See
511 RFC 1700 section "Ether Types" for examples.
513 @retval EFI_SUCCESS The received data was stored in Buffer, and BufferSize has
514 been updated to the number of bytes received.
515 @retval EFI_NOT_READY The network interface is too busy to accept this transmit
517 @retval EFI_NOT_STARTED The network interface has not been started.
518 @retval EFI_BUFFER_TOO_SMALL The BufferSize parameter is too small.
519 @retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
525 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
526 OUT UINTN
*HeaderSize OPTIONAL
,
527 IN OUT UINTN
*BuffSize
,
529 OUT EFI_MAC_ADDRESS
*SourceAddr OPTIONAL
,
530 OUT EFI_MAC_ADDRESS
*DestinationAddr OPTIONAL
,
531 OUT UINT16
*Protocol OPTIONAL
535 EMU_SNP_PRIVATE_DATA
*Private
;
537 Private
= EMU_SNP_PRIVATE_DATA_FROM_SNP_THIS (This
);
539 Status
= Private
->Io
->Receive (
554 Test to see if this driver supports ControllerHandle. This service
555 is called by the EFI boot service ConnectController(). In
556 order to make drivers as small as possible, there are a few calling
557 restrictions for this service. ConnectController() must
558 follow these calling restrictions. If any other agent wishes to call
559 Supported() it must also follow these calling restrictions.
561 @param This Protocol instance pointer.
562 @param ControllerHandle Handle of device to test
563 @param RemainingDevicePath Optional parameter use to pick a specific child
566 @retval EFI_SUCCESS This driver supports this device
567 @retval EFI_UNSUPPORTED This driver does not support this device
572 EmuSnpDriverBindingSupported (
573 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
574 IN EFI_HANDLE ControllerHandle
,
575 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
579 EMU_IO_THUNK_PROTOCOL
*EmuIoThunk
;
580 MAC_ADDR_DEVICE_PATH
*Node
;
581 EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
;
583 if (RemainingDevicePath
!= NULL
) {
584 if (!IsDevicePathEnd (RemainingDevicePath
)) {
585 Node
= (MAC_ADDR_DEVICE_PATH
*)RemainingDevicePath
;
586 if (Node
->Header
.Type
!= MESSAGING_DEVICE_PATH
||
587 Node
->Header
.SubType
!= MSG_MAC_ADDR_DP
) {
588 // If the remaining device path does not match we don't support the request
589 return EFI_UNSUPPORTED
;
596 // Open the IO Abstraction(s) needed to perform the supported test
598 Status
= gBS
->OpenProtocol (
600 &gEmuIoThunkProtocolGuid
,
601 (VOID
**)&EmuIoThunk
,
602 This
->DriverBindingHandle
,
604 EFI_OPEN_PROTOCOL_BY_DRIVER
606 if (EFI_ERROR (Status
)) {
611 // Close the I/O Abstraction(s) used to perform the supported test
615 &gEmuIoThunkProtocolGuid
,
616 This
->DriverBindingHandle
,
622 // Open the EFI Device Path protocol needed to perform the supported test
624 Status
= gBS
->OpenProtocol (
626 &gEfiDevicePathProtocolGuid
,
627 (VOID
**) &ParentDevicePath
,
628 This
->DriverBindingHandle
,
630 EFI_OPEN_PROTOCOL_BY_DRIVER
632 if (Status
== EFI_ALREADY_STARTED
) {
636 if (EFI_ERROR (Status
)) {
641 // Make sure GUID is for a SNP handle.
643 Status
= EFI_UNSUPPORTED
;
644 if (CompareGuid (EmuIoThunk
->Protocol
, &gEmuSnpProtocolGuid
)) {
645 Status
= EFI_SUCCESS
;
649 // Close protocol, don't use device path protocol in the Support() function
653 &gEfiDevicePathProtocolGuid
,
654 This
->DriverBindingHandle
,
663 Start this driver on ControllerHandle. This service is called by the
664 EFI boot service ConnectController(). In order to make
665 drivers as small as possible, there are a few calling restrictions for
666 this service. ConnectController() must follow these
667 calling restrictions. If any other agent wishes to call Start() it
668 must also follow these calling restrictions.
670 @param This Protocol instance pointer.
671 @param ControllerHandle Handle of device to bind driver to
672 @param RemainingDevicePath Optional parameter use to pick a specific child
675 @retval EFI_SUCCESS Always succeeds.
680 EmuSnpDriverBindingStart (
681 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
682 IN EFI_HANDLE ControllerHandle
,
683 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
687 EMU_IO_THUNK_PROTOCOL
*EmuIoThunk
;
688 EMU_SNP_PRIVATE_DATA
*Private
;
689 MAC_ADDR_DEVICE_PATH Node
;
690 EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
;
695 // Grab the protocols we need
697 Status
= gBS
->OpenProtocol(
699 &gEfiDevicePathProtocolGuid
,
700 ( VOID
** ) &ParentDevicePath
,
701 This
->DriverBindingHandle
,
703 EFI_OPEN_PROTOCOL_BY_DRIVER
705 if (EFI_ERROR (Status
) && Status
) {
709 Status
= gBS
->OpenProtocol (
711 &gEmuIoThunkProtocolGuid
,
712 (VOID
**)&EmuIoThunk
,
713 This
->DriverBindingHandle
,
715 EFI_OPEN_PROTOCOL_BY_DRIVER
717 if (EFI_ERROR (Status
)) {
721 if (!CompareGuid (EmuIoThunk
->Protocol
, &gEmuSnpProtocolGuid
)) {
722 return EFI_UNSUPPORTED
;
725 Status
= EmuIoThunk
->Open (EmuIoThunk
);
726 if (EFI_ERROR (Status
)) {
731 // Allocate the private data.
733 Private
= AllocateZeroPool (sizeof (EMU_SNP_PRIVATE_DATA
));
734 if (Private
== NULL
) {
735 Status
= EFI_OUT_OF_RESOURCES
;
739 CopyMem (&Private
->Snp
, &gEmuSnpTemplate
, sizeof (EFI_SIMPLE_NETWORK_PROTOCOL
));
740 CopyMem (&Private
->Mode
, &gEmuSnpModeTemplate
, sizeof (EFI_SIMPLE_NETWORK_MODE
));
742 Private
->Signature
= EMU_SNP_PRIVATE_DATA_SIGNATURE
;
743 Private
->IoThunk
= EmuIoThunk
;
744 Private
->Io
= EmuIoThunk
->Interface
;
745 Private
->EfiHandle
= ControllerHandle
;
746 Private
->DeviceHandle
= NULL
;
747 Private
->Snp
.Mode
= &Private
->Mode
;
748 Private
->ControllerNameTable
= NULL
;
751 Status
= Private
->Io
->CreateMapping (Private
->Io
, &Private
->Mode
);
752 if (EFI_ERROR (Status
)) {
757 // Build the device path by appending the MAC node to the ParentDevicePath
758 // from the EmuIo handle.
760 ZeroMem (&Node
, sizeof (MAC_ADDR_DEVICE_PATH
));
762 Node
.Header
.Type
= MESSAGING_DEVICE_PATH
;
763 Node
.Header
.SubType
= MSG_MAC_ADDR_DP
;
764 Node
.IfType
= Private
->Mode
.IfType
;
766 SetDevicePathNodeLength ((EFI_DEVICE_PATH_PROTOCOL
* )&Node
, sizeof (MAC_ADDR_DEVICE_PATH
));
768 CopyMem (&Node
.MacAddress
, &Private
->Mode
.CurrentAddress
, sizeof (EFI_MAC_ADDRESS
));
771 // Build the device path by appending the MAC node to the ParentDevicePath from the EmuIo handle.
773 Private
->DevicePath
= AppendDevicePathNode (ParentDevicePath
, (EFI_DEVICE_PATH_PROTOCOL
*)&Node
);
774 if ( Private
->DevicePath
== NULL
) {
775 Status
= EFI_OUT_OF_RESOURCES
;
781 gEmuSnpDriverComponentName
.SupportedLanguages
,
782 &Private
->ControllerNameTable
,
783 EmuIoThunk
->ConfigString
,
789 gEmuSnpDriverComponentName2
.SupportedLanguages
,
790 &Private
->ControllerNameTable
,
791 EmuIoThunk
->ConfigString
,
796 // Create Child Handle
798 Status
= gBS
->InstallMultipleProtocolInterfaces(
799 &Private
->DeviceHandle
,
800 &gEfiSimpleNetworkProtocolGuid
, &Private
->Snp
,
801 &gEfiDevicePathProtocolGuid
, Private
->DevicePath
,
804 if (EFI_ERROR (Status
)) {
809 // Open For Child Device
811 Status
= gBS
->OpenProtocol (
813 &gEmuIoThunkProtocolGuid
,
814 (VOID
**)&EmuIoThunk
,
815 This
->DriverBindingHandle
,
816 Private
->DeviceHandle
,
817 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
821 if (EFI_ERROR (Status
)) {
822 if (Private
!= NULL
) {
825 if (ParentDevicePath
!= NULL
) {
828 &gEfiDevicePathProtocolGuid
,
829 This
->DriverBindingHandle
,
839 Stop this driver on ControllerHandle. This service is called by the
840 EFI boot service DisconnectController(). In order to
841 make drivers as small as possible, there are a few calling
842 restrictions for this service. DisconnectController()
843 must follow these calling restrictions. If any other agent wishes
844 to call Stop() it must also follow these calling restrictions.
846 @param This Protocol instance pointer.
847 @param ControllerHandle Handle of device to stop driver on
848 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
849 children is zero stop the entire bus driver.
850 @param ChildHandleBuffer List of Child Handles to Stop.
852 @retval EFI_SUCCESS Always succeeds.
857 EmuSnpDriverBindingStop (
858 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
859 IN EFI_HANDLE ControllerHandle
,
860 IN UINTN NumberOfChildren
,
861 IN EFI_HANDLE
*ChildHandleBuffer
865 EMU_SNP_PRIVATE_DATA
*Private
= NULL
;
866 EFI_SIMPLE_NETWORK_PROTOCOL
*Snp
;
870 // Complete all outstanding transactions to Controller.
871 // Don't allow any new transaction to Controller to be started.
873 if (NumberOfChildren
== 0) {
875 // Close the bus driver
877 Status
= gBS
->CloseProtocol (
879 &gEmuIoThunkProtocolGuid
,
880 This
->DriverBindingHandle
,
884 Status
= gBS
->CloseProtocol (
886 &gEfiDevicePathProtocolGuid
,
887 This
->DriverBindingHandle
,
893 ASSERT (NumberOfChildren
== 1);
897 // Get our context back.
899 Status
= gBS
->OpenProtocol(
900 ChildHandleBuffer
[0],
901 &gEfiSimpleNetworkProtocolGuid
,
903 This
->DriverBindingHandle
,
905 EFI_OPEN_PROTOCOL_GET_PROTOCOL
907 if (EFI_ERROR (Status
)) {
908 return EFI_DEVICE_ERROR
;
911 Private
= EMU_SNP_PRIVATE_DATA_FROM_SNP_THIS (Snp
);
912 ASSERT (Private
->DeviceHandle
== ChildHandleBuffer
[0]);
913 ASSERT (Private
->EfiHandle
== ControllerHandle
);
915 Status
= gBS
->CloseProtocol(
917 &gEmuIoThunkProtocolGuid
,
918 This
->DriverBindingHandle
,
919 Private
->DeviceHandle
921 ASSERT_EFI_ERROR (Status
);
923 Status
= gBS
->UninstallMultipleProtocolInterfaces(
924 Private
->DeviceHandle
,
925 &gEfiSimpleNetworkProtocolGuid
, &Private
->Snp
,
926 &gEfiDevicePathProtocolGuid
, Private
->DevicePath
,
929 if (EFI_ERROR (Status
)) {
932 &gEmuIoThunkProtocolGuid
,
934 This
->DriverBindingHandle
,
935 Private
->DeviceHandle
,
936 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
939 Status
= Private
->IoThunk
->Close (Private
->IoThunk
);
940 ASSERT_EFI_ERROR (Status
);
942 FreePool (Private
->DevicePath
);
943 FreeUnicodeStringTable (Private
->ControllerNameTable
);
951 EFI_DRIVER_BINDING_PROTOCOL gEmuSnpDriverBinding
= {
952 EmuSnpDriverBindingSupported
,
953 EmuSnpDriverBindingStart
,
954 EmuSnpDriverBindingStop
,
963 This is the declaration of an EFI image entry point. This entry point is
964 the same for UEFI Applications, UEFI OS Loaders, and UEFI Drivers including
965 both device drivers and bus drivers.
967 @param ImageHandle The firmware allocated handle for the UEFI image.
968 @param SystemTable A pointer to the EFI System Table.
970 @retval EFI_SUCCESS The operation completed successfully.
971 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
976 InitializeEmuSnpDriver (
977 IN EFI_HANDLE ImageHandle
,
978 IN EFI_SYSTEM_TABLE
*SystemTable
984 // Install the Driver Protocols
986 Status
= EfiLibInstallDriverBindingComponentName2(
989 &gEmuSnpDriverBinding
,
991 &gEmuSnpDriverComponentName
,
992 &gEmuSnpDriverComponentName2