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"
18 EFI_SIMPLE_NETWORK_PROTOCOL gEmuSnpTemplate
= {
19 EFI_SIMPLE_NETWORK_PROTOCOL_REVISION
,
33 NULL
, // WaitForPacket
37 EFI_SIMPLE_NETWORK_MODE gEmuSnpModeTemplate
= {
38 EfiSimpleNetworkStopped
, // State
39 NET_ETHER_ADDR_LEN
, // HwAddressSize
40 NET_ETHER_HEADER_SIZE
, // MediaHeaderSize
41 1500, // MaxPacketSize
44 0, // ReceiveFilterMask
45 0, // ReceiveFilterSetting
46 MAX_MCAST_FILTER_CNT
, // MaxMCastFilterCount
47 0, // MCastFilterCount
58 }, // BroadcastAddress
61 }, // PermanentAddress
62 NET_IFTYPE_ETHERNET
, // IfType
63 FALSE
, // MacAddressChangeable
64 FALSE
, // MultipleTxSupported
65 FALSE
, // MediaPresentSupported
70 Changes the state of a network interface from "stopped" to "started".
72 @param This Protocol instance pointer.
74 @retval EFI_SUCCESS Always succeeds.
80 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
84 EMU_SNP_PRIVATE_DATA
*Private
;
86 Private
= EMU_SNP_PRIVATE_DATA_FROM_SNP_THIS (This
);
88 Status
= Private
->Io
->Start (Private
->Io
);
93 Changes the state of a network interface from "started" to "stopped".
95 @param This Protocol instance pointer.
97 @retval EFI_SUCCESS Always succeeds.
103 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
107 EMU_SNP_PRIVATE_DATA
*Private
;
109 Private
= EMU_SNP_PRIVATE_DATA_FROM_SNP_THIS (This
);
111 Status
= Private
->Io
->Stop (Private
->Io
);
116 Resets a network adapter and allocates the transmit and receive buffers
117 required by the network interface; optionally, also requests allocation
118 of additional transmit and receive buffers.
120 @param This Protocol instance pointer.
121 @param ExtraRxBufferSize The size, in bytes, of the extra receive buffer space
122 that the driver should allocate for the network interface.
123 Some network interfaces will not be able to use the extra
124 buffer, and the caller will not know if it is actually
126 @param ExtraTxBufferSize The size, in bytes, of the extra transmit buffer space
127 that the driver should allocate for the network interface.
128 Some network interfaces will not be able to use the extra
129 buffer, and the caller will not know if it is actually
132 @retval EFI_SUCCESS Always succeeds.
138 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
139 IN UINTN ExtraRxBufferSize OPTIONAL
,
140 IN UINTN ExtraTxBufferSize OPTIONAL
144 EMU_SNP_PRIVATE_DATA
*Private
;
146 Private
= EMU_SNP_PRIVATE_DATA_FROM_SNP_THIS (This
);
148 Status
= Private
->Io
->Initialize (Private
->Io
, ExtraRxBufferSize
, ExtraTxBufferSize
);
153 Resets a network adapter and re-initializes it with the parameters that were
154 provided in the previous call to Initialize().
156 @param This Protocol instance pointer.
157 @param ExtendedVerification Indicates that the driver may perform a more
158 exhaustive verification operation of the device
161 @retval EFI_SUCCESS Always succeeds.
167 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
168 IN BOOLEAN ExtendedVerification
172 EMU_SNP_PRIVATE_DATA
*Private
;
174 Private
= EMU_SNP_PRIVATE_DATA_FROM_SNP_THIS (This
);
176 Status
= Private
->Io
->Reset (Private
->Io
, ExtendedVerification
);
181 Resets a network adapter and leaves it in a state that is safe for
182 another driver to initialize.
184 @param This Protocol instance pointer.
186 @retval EFI_SUCCESS Always succeeds.
192 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
196 EMU_SNP_PRIVATE_DATA
*Private
;
198 Private
= EMU_SNP_PRIVATE_DATA_FROM_SNP_THIS (This
);
200 Status
= Private
->Io
->Shutdown (Private
->Io
);
205 Manages the multicast receive filters of a network interface.
207 @param This Protocol instance pointer.
208 @param EnableBits A bit mask of receive filters to enable on the network interface.
209 @param DisableBits A bit mask of receive filters to disable on the network interface.
210 @param ResetMcastFilter Set to TRUE to reset the contents of the multicast receive
211 filters on the network interface to their default values.
212 @param McastFilterCount Number of multicast HW MAC addresses in the new
213 MCastFilter list. This value must be less than or equal to
214 the MCastFilterCnt field of EFI_SIMPLE_NETWORK_MODE. This
215 field is optional if ResetMCastFilter is TRUE.
216 @param McastFilter A pointer to a list of new multicast receive filter HW MAC
217 addresses. This list will replace any existing multicast
218 HW MAC address list. This field is optional if
219 ResetMCastFilter is TRUE.
221 @retval EFI_SUCCESS The multicast receive filter list was updated.
222 @retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
227 EmuSnpReceiveFilters (
228 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
229 IN UINT32 EnableBits
,
230 IN UINT32 DisableBits
,
231 IN BOOLEAN ResetMcastFilter
,
232 IN UINTN McastFilterCount OPTIONAL
,
233 IN EFI_MAC_ADDRESS
*McastFilter OPTIONAL
237 EMU_SNP_PRIVATE_DATA
*Private
;
239 Private
= EMU_SNP_PRIVATE_DATA_FROM_SNP_THIS (This
);
241 Status
= Private
->Io
->ReceiveFilters (
253 Modifies or resets the current station address, if supported.
255 @param This Protocol instance pointer.
256 @param Reset Flag used to reset the station address to the network interfaces
258 @param NewMacAddr New station address to be used for the network interface.
260 @retval EFI_UNSUPPORTED Not supported yet.
265 EmuSnpStationAddress (
266 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
268 IN EFI_MAC_ADDRESS
*NewMacAddr OPTIONAL
272 EMU_SNP_PRIVATE_DATA
*Private
;
274 Private
= EMU_SNP_PRIVATE_DATA_FROM_SNP_THIS (This
);
276 Status
= Private
->Io
->StationAddress (Private
->Io
, Reset
, NewMacAddr
);
281 Resets or collects the statistics on a network interface.
283 @param This Protocol instance pointer.
284 @param Reset Set to TRUE to reset the statistics for the network interface.
285 @param StatisticsSize On input the size, in bytes, of StatisticsTable. On
286 output the size, in bytes, of the resulting table of
288 @param StatisticsTable A pointer to the EFI_NETWORK_STATISTICS structure that
289 contains the statistics.
291 @retval EFI_SUCCESS The statistics were collected from the network interface.
292 @retval EFI_NOT_STARTED The network interface has not been started.
293 @retval EFI_BUFFER_TOO_SMALL The Statistics buffer was too small. The current buffer
294 size needed to hold the statistics is returned in
296 @retval EFI_UNSUPPORTED Not supported yet.
302 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
304 IN OUT UINTN
*StatisticsSize OPTIONAL
,
305 OUT EFI_NETWORK_STATISTICS
*StatisticsTable OPTIONAL
309 EMU_SNP_PRIVATE_DATA
*Private
;
311 Private
= EMU_SNP_PRIVATE_DATA_FROM_SNP_THIS (This
);
313 Status
= Private
->Io
->Statistics (Private
->Io
, Reset
, StatisticsSize
, StatisticsTable
);
318 Converts a multicast IP address to a multicast HW MAC address.
320 @param This Protocol instance pointer.
321 @param Ipv6 Set to TRUE if the multicast IP address is IPv6 [RFC 2460]. Set
322 to FALSE if the multicast IP address is IPv4 [RFC 791].
323 @param Ip The multicast IP address that is to be converted to a multicast
325 @param Mac The multicast HW MAC address that is to be generated from IP.
327 @retval EFI_SUCCESS The multicast IP address was mapped to the multicast
329 @retval EFI_NOT_STARTED The network interface has not been started.
330 @retval EFI_BUFFER_TOO_SMALL The Statistics buffer was too small. The current buffer
331 size needed to hold the statistics is returned in
333 @retval EFI_UNSUPPORTED Not supported yet.
339 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
341 IN EFI_IP_ADDRESS
*Ip
,
342 OUT EFI_MAC_ADDRESS
*Mac
346 EMU_SNP_PRIVATE_DATA
*Private
;
348 Private
= EMU_SNP_PRIVATE_DATA_FROM_SNP_THIS (This
);
350 Status
= Private
->Io
->MCastIpToMac (Private
->Io
, Ipv6
, Ip
, Mac
);
355 Performs read and write operations on the NVRAM device attached to a
358 @param This Protocol instance pointer.
359 @param ReadOrWrite TRUE for read operations, FALSE for write operations.
360 @param Offset Byte offset in the NVRAM device at which to start the read or
361 write operation. This must be a multiple of NvRamAccessSize and
363 @param BufferSize The number of bytes to read or write from the NVRAM device.
364 This must also be a multiple of NvramAccessSize.
365 @param Buffer A pointer to the data buffer.
367 @retval EFI_UNSUPPORTED Not supported yet.
373 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
374 IN BOOLEAN ReadOrWrite
,
381 EMU_SNP_PRIVATE_DATA
*Private
;
383 Private
= EMU_SNP_PRIVATE_DATA_FROM_SNP_THIS (This
);
385 Status
= Private
->Io
->NvData (Private
->Io
, ReadOrWrite
, Offset
, BufferSize
, Buffer
);
390 Reads the current interrupt status and recycled transmit buffer status from
393 @param This Protocol instance pointer.
394 @param InterruptStatus A pointer to the bit mask of the currently active interrupts
395 If this is NULL, the interrupt status will not be read from
396 the device. If this is not NULL, the interrupt status will
397 be read from the device. When the interrupt status is read,
398 it will also be cleared. Clearing the transmit interrupt
399 does not empty the recycled transmit buffer array.
400 @param TxBuffer Recycled transmit buffer address. The network interface will
401 not transmit if its internal recycled transmit buffer array
402 is full. Reading the transmit buffer does not clear the
403 transmit interrupt. If this is NULL, then the transmit buffer
404 status will not be read. If there are no transmit buffers to
405 recycle and TxBuf is not NULL, * TxBuf will be set to NULL.
407 @retval EFI_SUCCESS Always succeeds.
413 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
414 OUT UINT32
*InterruptStatus
,
419 EMU_SNP_PRIVATE_DATA
*Private
;
421 Private
= EMU_SNP_PRIVATE_DATA_FROM_SNP_THIS (This
);
423 Status
= Private
->Io
->GetStatus (Private
->Io
, InterruptStatus
, TxBuffer
);
428 Places a packet in the transmit queue of a network interface.
430 @param This Protocol instance pointer.
431 @param HeaderSize The size, in bytes, of the media header to be filled in by
432 the Transmit() function. If HeaderSize is non-zero, then it
433 must be equal to This->Mode->MediaHeaderSize and the DestAddr
434 and Protocol parameters must not be NULL.
435 @param BufferSize The size, in bytes, of the entire packet (media header and
436 data) to be transmitted through the network interface.
437 @param Buffer A pointer to the packet (media header followed by data) to be
438 transmitted. This parameter cannot be NULL. If HeaderSize is zero,
439 then the media header in Buffer must already be filled in by the
440 caller. If HeaderSize is non-zero, then the media header will be
441 filled in by the Transmit() function.
442 @param SrcAddr The source HW MAC address. If HeaderSize is zero, then this parameter
443 is ignored. If HeaderSize is non-zero and SrcAddr is NULL, then
444 This->Mode->CurrentAddress is used for the source HW MAC address.
445 @param DestAddr The destination HW MAC address. If HeaderSize is zero, then this
446 parameter is ignored.
447 @param Protocol The type of header to build. If HeaderSize is zero, then this
448 parameter is ignored. See RFC 1700, section "Ether Types", for
451 @retval EFI_SUCCESS The packet was placed on the transmit queue.
452 @retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
453 @retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value.
454 @retval EFI_NOT_STARTED The network interface has not been started.
460 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
464 IN EFI_MAC_ADDRESS
*SrcAddr OPTIONAL
,
465 IN EFI_MAC_ADDRESS
*DestAddr OPTIONAL
,
466 IN UINT16
*Protocol OPTIONAL
470 EMU_SNP_PRIVATE_DATA
*Private
;
472 Private
= EMU_SNP_PRIVATE_DATA_FROM_SNP_THIS (This
);
474 Status
= Private
->Io
->Transmit (
487 Receives a packet from a network interface.
489 @param This Protocol instance pointer.
490 @param HeaderSize The size, in bytes, of the media header received on the network
491 interface. If this parameter is NULL, then the media header size
492 will not be returned.
493 @param BuffSize On entry, the size, in bytes, of Buffer. On exit, the size, in
494 bytes, of the packet that was received on the network interface.
495 @param Buffer A pointer to the data buffer to receive both the media header and
497 @param SourceAddr The source HW MAC address. If this parameter is NULL, the
498 HW MAC source address will not be extracted from the media
500 @param DestinationAddr The destination HW MAC address. If this parameter is NULL,
501 the HW MAC destination address will not be extracted from the
503 @param Protocol The media header type. If this parameter is NULL, then the
504 protocol will not be extracted from the media header. See
505 RFC 1700 section "Ether Types" for examples.
507 @retval EFI_SUCCESS The received data was stored in Buffer, and BufferSize has
508 been updated to the number of bytes received.
509 @retval EFI_NOT_READY The network interface is too busy to accept this transmit
511 @retval EFI_NOT_STARTED The network interface has not been started.
512 @retval EFI_BUFFER_TOO_SMALL The BufferSize parameter is too small.
513 @retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
519 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
520 OUT UINTN
*HeaderSize OPTIONAL
,
521 IN OUT UINTN
*BuffSize
,
523 OUT EFI_MAC_ADDRESS
*SourceAddr OPTIONAL
,
524 OUT EFI_MAC_ADDRESS
*DestinationAddr OPTIONAL
,
525 OUT UINT16
*Protocol OPTIONAL
529 EMU_SNP_PRIVATE_DATA
*Private
;
531 Private
= EMU_SNP_PRIVATE_DATA_FROM_SNP_THIS (This
);
533 Status
= Private
->Io
->Receive (
546 Test to see if this driver supports ControllerHandle. This service
547 is called by the EFI boot service ConnectController(). In
548 order to make drivers as small as possible, there are a few calling
549 restrictions for this service. ConnectController() must
550 follow these calling restrictions. If any other agent wishes to call
551 Supported() it must also follow these calling restrictions.
553 @param This Protocol instance pointer.
554 @param ControllerHandle Handle of device to test
555 @param RemainingDevicePath Optional parameter use to pick a specific child
558 @retval EFI_SUCCESS This driver supports this device
559 @retval EFI_UNSUPPORTED This driver does not support this device
564 EmuSnpDriverBindingSupported (
565 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
566 IN EFI_HANDLE ControllerHandle
,
567 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
571 EMU_IO_THUNK_PROTOCOL
*EmuIoThunk
;
572 MAC_ADDR_DEVICE_PATH
*Node
;
573 EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
;
575 if (RemainingDevicePath
!= NULL
) {
576 if (!IsDevicePathEnd (RemainingDevicePath
)) {
577 Node
= (MAC_ADDR_DEVICE_PATH
*)RemainingDevicePath
;
578 if ((Node
->Header
.Type
!= MESSAGING_DEVICE_PATH
) ||
579 (Node
->Header
.SubType
!= MSG_MAC_ADDR_DP
))
581 // If the remaining device path does not match we don't support the request
582 return EFI_UNSUPPORTED
;
588 // Open the IO Abstraction(s) needed to perform the supported test
590 Status
= gBS
->OpenProtocol (
592 &gEmuIoThunkProtocolGuid
,
593 (VOID
**)&EmuIoThunk
,
594 This
->DriverBindingHandle
,
596 EFI_OPEN_PROTOCOL_BY_DRIVER
598 if (EFI_ERROR (Status
)) {
603 // Close the I/O Abstraction(s) used to perform the supported test
607 &gEmuIoThunkProtocolGuid
,
608 This
->DriverBindingHandle
,
613 // Open the EFI Device Path protocol needed to perform the supported test
615 Status
= gBS
->OpenProtocol (
617 &gEfiDevicePathProtocolGuid
,
618 (VOID
**)&ParentDevicePath
,
619 This
->DriverBindingHandle
,
621 EFI_OPEN_PROTOCOL_BY_DRIVER
623 if (Status
== EFI_ALREADY_STARTED
) {
627 if (EFI_ERROR (Status
)) {
632 // Make sure GUID is for a SNP handle.
634 Status
= EFI_UNSUPPORTED
;
635 if (CompareGuid (EmuIoThunk
->Protocol
, &gEmuSnpProtocolGuid
)) {
636 Status
= EFI_SUCCESS
;
640 // Close protocol, don't use device path protocol in the Support() function
644 &gEfiDevicePathProtocolGuid
,
645 This
->DriverBindingHandle
,
653 Start this driver on ControllerHandle. This service is called by the
654 EFI boot service ConnectController(). In order to make
655 drivers as small as possible, there are a few calling restrictions for
656 this service. ConnectController() must follow these
657 calling restrictions. If any other agent wishes to call Start() it
658 must also follow these calling restrictions.
660 @param This Protocol instance pointer.
661 @param ControllerHandle Handle of device to bind driver to
662 @param RemainingDevicePath Optional parameter use to pick a specific child
665 @retval EFI_SUCCESS Always succeeds.
670 EmuSnpDriverBindingStart (
671 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
672 IN EFI_HANDLE ControllerHandle
,
673 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
677 EMU_IO_THUNK_PROTOCOL
*EmuIoThunk
;
678 EMU_SNP_PRIVATE_DATA
*Private
;
679 MAC_ADDR_DEVICE_PATH Node
;
680 EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
;
685 // Grab the protocols we need
687 Status
= gBS
->OpenProtocol (
689 &gEfiDevicePathProtocolGuid
,
690 (VOID
**)&ParentDevicePath
,
691 This
->DriverBindingHandle
,
693 EFI_OPEN_PROTOCOL_BY_DRIVER
695 if (EFI_ERROR (Status
) && Status
) {
699 Status
= gBS
->OpenProtocol (
701 &gEmuIoThunkProtocolGuid
,
702 (VOID
**)&EmuIoThunk
,
703 This
->DriverBindingHandle
,
705 EFI_OPEN_PROTOCOL_BY_DRIVER
707 if (EFI_ERROR (Status
)) {
711 if (!CompareGuid (EmuIoThunk
->Protocol
, &gEmuSnpProtocolGuid
)) {
712 return EFI_UNSUPPORTED
;
715 Status
= EmuIoThunk
->Open (EmuIoThunk
);
716 if (EFI_ERROR (Status
)) {
721 // Allocate the private data.
723 Private
= AllocateZeroPool (sizeof (EMU_SNP_PRIVATE_DATA
));
724 if (Private
== NULL
) {
725 Status
= EFI_OUT_OF_RESOURCES
;
729 CopyMem (&Private
->Snp
, &gEmuSnpTemplate
, sizeof (EFI_SIMPLE_NETWORK_PROTOCOL
));
730 CopyMem (&Private
->Mode
, &gEmuSnpModeTemplate
, sizeof (EFI_SIMPLE_NETWORK_MODE
));
732 Private
->Signature
= EMU_SNP_PRIVATE_DATA_SIGNATURE
;
733 Private
->IoThunk
= EmuIoThunk
;
734 Private
->Io
= EmuIoThunk
->Interface
;
735 Private
->EfiHandle
= ControllerHandle
;
736 Private
->DeviceHandle
= NULL
;
737 Private
->Snp
.Mode
= &Private
->Mode
;
738 Private
->ControllerNameTable
= NULL
;
740 Status
= Private
->Io
->CreateMapping (Private
->Io
, &Private
->Mode
);
741 if (EFI_ERROR (Status
)) {
746 // Build the device path by appending the MAC node to the ParentDevicePath
747 // from the EmuIo handle.
749 ZeroMem (&Node
, sizeof (MAC_ADDR_DEVICE_PATH
));
751 Node
.Header
.Type
= MESSAGING_DEVICE_PATH
;
752 Node
.Header
.SubType
= MSG_MAC_ADDR_DP
;
753 Node
.IfType
= Private
->Mode
.IfType
;
755 SetDevicePathNodeLength ((EFI_DEVICE_PATH_PROTOCOL
*)&Node
, sizeof (MAC_ADDR_DEVICE_PATH
));
757 CopyMem (&Node
.MacAddress
, &Private
->Mode
.CurrentAddress
, sizeof (EFI_MAC_ADDRESS
));
760 // Build the device path by appending the MAC node to the ParentDevicePath from the EmuIo handle.
762 Private
->DevicePath
= AppendDevicePathNode (ParentDevicePath
, (EFI_DEVICE_PATH_PROTOCOL
*)&Node
);
763 if ( Private
->DevicePath
== NULL
) {
764 Status
= EFI_OUT_OF_RESOURCES
;
770 gEmuSnpDriverComponentName
.SupportedLanguages
,
771 &Private
->ControllerNameTable
,
772 EmuIoThunk
->ConfigString
,
778 gEmuSnpDriverComponentName2
.SupportedLanguages
,
779 &Private
->ControllerNameTable
,
780 EmuIoThunk
->ConfigString
,
785 // Create Child Handle
787 Status
= gBS
->InstallMultipleProtocolInterfaces (
788 &Private
->DeviceHandle
,
789 &gEfiSimpleNetworkProtocolGuid
,
791 &gEfiDevicePathProtocolGuid
,
795 if (EFI_ERROR (Status
)) {
800 // Open For Child Device
802 Status
= gBS
->OpenProtocol (
804 &gEmuIoThunkProtocolGuid
,
805 (VOID
**)&EmuIoThunk
,
806 This
->DriverBindingHandle
,
807 Private
->DeviceHandle
,
808 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
812 if (EFI_ERROR (Status
)) {
813 if (Private
!= NULL
) {
817 if (ParentDevicePath
!= NULL
) {
820 &gEfiDevicePathProtocolGuid
,
821 This
->DriverBindingHandle
,
831 Stop this driver on ControllerHandle. This service is called by the
832 EFI boot service DisconnectController(). In order to
833 make drivers as small as possible, there are a few calling
834 restrictions for this service. DisconnectController()
835 must follow these calling restrictions. If any other agent wishes
836 to call Stop() it must also follow these calling restrictions.
838 @param This Protocol instance pointer.
839 @param ControllerHandle Handle of device to stop driver on
840 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
841 children is zero stop the entire bus driver.
842 @param ChildHandleBuffer List of Child Handles to Stop.
844 @retval EFI_SUCCESS Always succeeds.
849 EmuSnpDriverBindingStop (
850 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
851 IN EFI_HANDLE ControllerHandle
,
852 IN UINTN NumberOfChildren
,
853 IN EFI_HANDLE
*ChildHandleBuffer
857 EMU_SNP_PRIVATE_DATA
*Private
= NULL
;
858 EFI_SIMPLE_NETWORK_PROTOCOL
*Snp
;
862 // Complete all outstanding transactions to Controller.
863 // Don't allow any new transaction to Controller to be started.
865 if (NumberOfChildren
== 0) {
867 // Close the bus driver
869 Status
= gBS
->CloseProtocol (
871 &gEmuIoThunkProtocolGuid
,
872 This
->DriverBindingHandle
,
876 Status
= gBS
->CloseProtocol (
878 &gEfiDevicePathProtocolGuid
,
879 This
->DriverBindingHandle
,
885 ASSERT (NumberOfChildren
== 1);
888 // Get our context back.
890 Status
= gBS
->OpenProtocol (
891 ChildHandleBuffer
[0],
892 &gEfiSimpleNetworkProtocolGuid
,
894 This
->DriverBindingHandle
,
896 EFI_OPEN_PROTOCOL_GET_PROTOCOL
898 if (EFI_ERROR (Status
)) {
899 return EFI_DEVICE_ERROR
;
902 Private
= EMU_SNP_PRIVATE_DATA_FROM_SNP_THIS (Snp
);
903 ASSERT (Private
->DeviceHandle
== ChildHandleBuffer
[0]);
904 ASSERT (Private
->EfiHandle
== ControllerHandle
);
906 Status
= gBS
->CloseProtocol (
908 &gEmuIoThunkProtocolGuid
,
909 This
->DriverBindingHandle
,
910 Private
->DeviceHandle
912 ASSERT_EFI_ERROR (Status
);
914 Status
= gBS
->UninstallMultipleProtocolInterfaces (
915 Private
->DeviceHandle
,
916 &gEfiSimpleNetworkProtocolGuid
,
918 &gEfiDevicePathProtocolGuid
,
922 if (EFI_ERROR (Status
)) {
925 &gEmuIoThunkProtocolGuid
,
927 This
->DriverBindingHandle
,
928 Private
->DeviceHandle
,
929 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
932 Status
= Private
->IoThunk
->Close (Private
->IoThunk
);
933 ASSERT_EFI_ERROR (Status
);
935 FreePool (Private
->DevicePath
);
936 FreeUnicodeStringTable (Private
->ControllerNameTable
);
943 EFI_DRIVER_BINDING_PROTOCOL gEmuSnpDriverBinding
= {
944 EmuSnpDriverBindingSupported
,
945 EmuSnpDriverBindingStart
,
946 EmuSnpDriverBindingStop
,
953 This is the declaration of an EFI image entry point. This entry point is
954 the same for UEFI Applications, UEFI OS Loaders, and UEFI Drivers including
955 both device drivers and bus drivers.
957 @param ImageHandle The firmware allocated handle for the UEFI image.
958 @param SystemTable A pointer to the EFI System Table.
960 @retval EFI_SUCCESS The operation completed successfully.
961 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
966 InitializeEmuSnpDriver (
967 IN EFI_HANDLE ImageHandle
,
968 IN EFI_SYSTEM_TABLE
*SystemTable
974 // Install the Driver Protocols
976 Status
= EfiLibInstallDriverBindingComponentName2 (
979 &gEmuSnpDriverBinding
,
981 &gEmuSnpDriverComponentName
,
982 &gEmuSnpDriverComponentName2