2 Implementation of driver entry point and driver binding protocol.
4 Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials are licensed
6 and made available under the terms and conditions of the BSD License which
7 accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
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.
18 // Module global variables needed to support undi 3.0 interface
20 EFI_PCI_IO_PROTOCOL
*mPciIo
;
21 V2P
*mV2p
= NULL
; // undi3.0 map_list head
22 // End Global variables
26 One notified function to stop UNDI device when gBS->ExitBootServices() called.
28 @param Event Pointer to this event
29 @param Context Event hanlder private data
34 SnpNotifyExitBootServices (
41 Snp
= (SNP_DRIVER
*)Context
;
44 // Shutdown and stop UNDI driver
51 Send command to UNDI. It does nothing currently.
53 @param Cdb command to be sent to UNDI.
55 @retval EFI_INVALID_PARAMETER The command is 0.
56 @retval EFI_UNSUPPORTED Default return status because it's not
66 DEBUG ((EFI_D_ERROR
, "\nIssueHwUndiCommand() - This should not be called!"));
69 return EFI_INVALID_PARAMETER
;
73 // %%TBD - For now, nothing is done.
75 return EFI_UNSUPPORTED
;
80 Compute 8-bit checksum of a buffer.
82 @param Buffer Pointer to buffer.
83 @param Length Length of buffer in bytes.
85 @return 8-bit checksum of all bytes in buffer, or zero if ptr is NULL or len
101 if (Ptr
== NULL
|| Length
== 0) {
105 while (Length
-- != 0) {
106 Cksum
= (UINT8
) (Cksum
+ *Ptr
++);
113 Test to see if this driver supports ControllerHandle. This service
114 is called by the EFI boot service ConnectController(). In
115 order to make drivers as small as possible, there are a few calling
116 restrictions for this service. ConnectController() must
117 follow these calling restrictions. If any other agent wishes to call
118 Supported() it must also follow these calling restrictions.
120 @param This Protocol instance pointer.
121 @param ControllerHandle Handle of device to test.
122 @param RemainingDevicePath Optional parameter use to pick a specific child
125 @retval EFI_SUCCESS This driver supports this device.
126 @retval EFI_ALREADY_STARTED This driver is already running on this device.
127 @retval other This driver does not support this device.
132 SimpleNetworkDriverSupported (
133 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
134 IN EFI_HANDLE Controller
,
135 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
139 EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL
*NiiProtocol
;
142 Status
= gBS
->OpenProtocol (
144 &gEfiDevicePathProtocolGuid
,
146 This
->DriverBindingHandle
,
148 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
150 if (EFI_ERROR (Status
)) {
154 Status
= gBS
->OpenProtocol (
156 &gEfiNetworkInterfaceIdentifierProtocolGuid_31
,
157 (VOID
**) &NiiProtocol
,
158 This
->DriverBindingHandle
,
160 EFI_OPEN_PROTOCOL_BY_DRIVER
163 if (EFI_ERROR (Status
)) {
164 if (Status
== EFI_ALREADY_STARTED
) {
165 DEBUG ((EFI_D_INFO
, "Support(): Already Started. on handle %p\n", Controller
));
170 DEBUG ((EFI_D_INFO
, "Support(): UNDI3.1 found on handle %p\n", Controller
));
173 // check the version, we don't want to connect to the undi16
175 if (NiiProtocol
->Type
!= EfiNetworkInterfaceUndi
) {
176 Status
= EFI_UNSUPPORTED
;
180 // Check to see if !PXE structure is valid. Paragraph alignment of !PXE structure is required.
182 if ((NiiProtocol
->Id
& 0x0F) != 0) {
183 DEBUG ((EFI_D_NET
, "\n!PXE structure is not paragraph aligned.\n"));
184 Status
= EFI_UNSUPPORTED
;
188 Pxe
= (PXE_UNDI
*) (UINTN
) (NiiProtocol
->Id
);
191 // Verify !PXE revisions.
193 if (Pxe
->hw
.Signature
!= PXE_ROMID_SIGNATURE
) {
194 DEBUG ((EFI_D_NET
, "\n!PXE signature is not valid.\n"));
195 Status
= EFI_UNSUPPORTED
;
199 if (Pxe
->hw
.Rev
< PXE_ROMID_REV
) {
200 DEBUG ((EFI_D_NET
, "\n!PXE.Rev is not supported.\n"));
201 Status
= EFI_UNSUPPORTED
;
205 if (Pxe
->hw
.MajorVer
< PXE_ROMID_MAJORVER
) {
207 DEBUG ((EFI_D_NET
, "\n!PXE.MajorVer is not supported.\n"));
208 Status
= EFI_UNSUPPORTED
;
211 } else if (Pxe
->hw
.MajorVer
== PXE_ROMID_MAJORVER
&& Pxe
->hw
.MinorVer
< PXE_ROMID_MINORVER
) {
212 DEBUG ((EFI_D_NET
, "\n!PXE.MinorVer is not supported."));
213 Status
= EFI_UNSUPPORTED
;
217 // Do S/W UNDI specific checks.
219 if ((Pxe
->hw
.Implementation
& PXE_ROMID_IMP_HW_UNDI
) == 0) {
220 if (Pxe
->sw
.EntryPoint
< Pxe
->sw
.Len
) {
221 DEBUG ((EFI_D_NET
, "\n!PXE S/W entry point is not valid."));
222 Status
= EFI_UNSUPPORTED
;
226 if (Pxe
->sw
.BusCnt
== 0) {
227 DEBUG ((EFI_D_NET
, "\n!PXE.BusCnt is zero."));
228 Status
= EFI_UNSUPPORTED
;
233 Status
= EFI_SUCCESS
;
234 DEBUG ((EFI_D_INFO
, "Support(): supported on %p\n", Controller
));
239 &gEfiNetworkInterfaceIdentifierProtocolGuid_31
,
240 This
->DriverBindingHandle
,
248 Start this driver on ControllerHandle. This service is called by the
249 EFI boot service ConnectController(). In order to make
250 drivers as small as possible, there are a few calling restrictions for
251 this service. ConnectController() must follow these
252 calling restrictions. If any other agent wishes to call Start() it
253 must also follow these calling restrictions.
255 @param This Protocol instance pointer.
256 @param ControllerHandle Handle of device to bind driver to.
257 @param RemainingDevicePath Optional parameter use to pick a specific child
260 @retval EFI_SUCCESS This driver is added to ControllerHandle
261 @retval EFI_DEVICE_ERROR This driver could not be started due to a device error
262 @retval other This driver does not support this device
267 SimpleNetworkDriverStart (
268 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
269 IN EFI_HANDLE Controller
,
270 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
273 EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL
*Nii
;
274 EFI_DEVICE_PATH_PROTOCOL
*NiiDevicePath
;
280 PXE_PCI_CONFIG_INFO ConfigInfo
;
281 PCI_TYPE00
*ConfigHeader
;
284 PXE_STATFLAGS InitStatFlags
;
286 DEBUG ((EFI_D_NET
, "\nSnpNotifyNetworkInterfaceIdentifier() "));
288 Status
= gBS
->OpenProtocol (
290 &gEfiDevicePathProtocolGuid
,
291 (VOID
**) &NiiDevicePath
,
292 This
->DriverBindingHandle
,
294 EFI_OPEN_PROTOCOL_BY_DRIVER
297 if (EFI_ERROR (Status
)) {
301 Status
= gBS
->LocateDevicePath (
302 &gEfiPciIoProtocolGuid
,
307 if (EFI_ERROR (Status
)) {
311 Status
= gBS
->OpenProtocol (
313 &gEfiPciIoProtocolGuid
,
315 This
->DriverBindingHandle
,
317 EFI_OPEN_PROTOCOL_GET_PROTOCOL
319 if (EFI_ERROR (Status
)) {
323 // Get the NII interface.
325 Status
= gBS
->OpenProtocol (
327 &gEfiNetworkInterfaceIdentifierProtocolGuid_31
,
329 This
->DriverBindingHandle
,
331 EFI_OPEN_PROTOCOL_BY_DRIVER
333 if (EFI_ERROR (Status
)) {
336 &gEfiDevicePathProtocolGuid
,
337 This
->DriverBindingHandle
,
343 DEBUG ((EFI_D_INFO
, "Start(): UNDI3.1 found\n"));
345 Pxe
= (PXE_UNDI
*) (UINTN
) (Nii
->Id
);
347 if (Calc8BitCksum (Pxe
, Pxe
->hw
.Len
) != 0) {
348 DEBUG ((EFI_D_NET
, "\n!PXE checksum is not correct.\n"));
352 if ((Pxe
->hw
.Implementation
& PXE_ROMID_IMP_PROMISCUOUS_RX_SUPPORTED
) != 0) {
354 // We can get any packets.
356 } else if ((Pxe
->hw
.Implementation
& PXE_ROMID_IMP_BROADCAST_RX_SUPPORTED
) != 0) {
358 // We need to be able to get broadcast packets for DHCP.
359 // If we do not have promiscuous support, we must at least have
360 // broadcast support or we cannot do DHCP!
363 DEBUG ((EFI_D_NET
, "\nUNDI does not have promiscuous or broadcast support."));
367 // OK, we like this UNDI, and we know snp is not already there on this handle
368 // Allocate and initialize a new simple network protocol structure.
370 Status
= mPciIo
->AllocateBuffer (
374 SNP_MEM_PAGES (sizeof (SNP_DRIVER
)),
379 if (Status
!= EFI_SUCCESS
) {
380 DEBUG ((EFI_D_NET
, "\nCould not allocate SNP_DRIVER structure.\n"));
384 Snp
= (SNP_DRIVER
*) (UINTN
) Address
;
386 ZeroMem (Snp
, sizeof (SNP_DRIVER
));
389 Snp
->Signature
= SNP_DRIVER_SIGNATURE
;
391 EfiInitializeLock (&Snp
->Lock
, TPL_NOTIFY
);
393 Snp
->Snp
.Revision
= EFI_SIMPLE_NETWORK_PROTOCOL_REVISION
;
394 Snp
->Snp
.Start
= SnpUndi32Start
;
395 Snp
->Snp
.Stop
= SnpUndi32Stop
;
396 Snp
->Snp
.Initialize
= SnpUndi32Initialize
;
397 Snp
->Snp
.Reset
= SnpUndi32Reset
;
398 Snp
->Snp
.Shutdown
= SnpUndi32Shutdown
;
399 Snp
->Snp
.ReceiveFilters
= SnpUndi32ReceiveFilters
;
400 Snp
->Snp
.StationAddress
= SnpUndi32StationAddress
;
401 Snp
->Snp
.Statistics
= SnpUndi32Statistics
;
402 Snp
->Snp
.MCastIpToMac
= SnpUndi32McastIpToMac
;
403 Snp
->Snp
.NvData
= SnpUndi32NvData
;
404 Snp
->Snp
.GetStatus
= SnpUndi32GetStatus
;
405 Snp
->Snp
.Transmit
= SnpUndi32Transmit
;
406 Snp
->Snp
.Receive
= SnpUndi32Receive
;
407 Snp
->Snp
.WaitForPacket
= NULL
;
409 Snp
->Snp
.Mode
= &Snp
->Mode
;
411 Snp
->TxRxBufferSize
= 0;
412 Snp
->TxRxBuffer
= NULL
;
414 if (Nii
->Revision
>= EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL_REVISION
) {
415 Snp
->IfNum
= Nii
->IfNum
;
418 Snp
->IfNum
= (UINT8
) (Nii
->IfNum
& 0xFF);
421 if ((Pxe
->hw
.Implementation
& PXE_ROMID_IMP_HW_UNDI
) != 0) {
422 Snp
->IsSwUndi
= FALSE
;
423 Snp
->IssueUndi32Command
= &IssueHwUndiCommand
;
425 Snp
->IsSwUndi
= TRUE
;
427 if ((Pxe
->sw
.Implementation
& PXE_ROMID_IMP_SW_VIRT_ADDR
) != 0) {
428 Snp
->IssueUndi32Command
= (ISSUE_UNDI32_COMMAND
) (UINTN
) Pxe
->sw
.EntryPoint
;
430 Snp
->IssueUndi32Command
= (ISSUE_UNDI32_COMMAND
) (UINTN
) ((UINT8
) (UINTN
) Pxe
+ Pxe
->sw
.EntryPoint
);
434 // Allocate a global CPB and DB buffer for this UNDI interface.
435 // we do this because:
437 // -UNDI 3.0 wants all the addresses passed to it (even the cpb and db) to be
438 // within 2GB limit, create them here and map them so that when undi calls
439 // v2p callback to check if the physical address is < 2gb, we will pass.
441 // -This is not a requirement for 3.1 or later UNDIs but the code looks
442 // simpler if we use the same cpb, db variables for both old and new undi
443 // interfaces from all the SNP interface calls (we don't map the buffers
444 // for the newer undi interfaces though)
446 // -it is OK to allocate one global set of CPB, DB pair for each UNDI
447 // interface as EFI does not multi-task and so SNP will not be re-entered!
449 Status
= mPciIo
->AllocateBuffer (
453 SNP_MEM_PAGES (4096),
458 if (Status
!= EFI_SUCCESS
) {
459 DEBUG ((EFI_D_NET
, "\nCould not allocate CPB and DB structures.\n"));
460 goto Error_DeleteSNP
;
463 Snp
->Cpb
= (VOID
*) (UINTN
) Address
;
464 Snp
->Db
= (VOID
*) ((UINTN
) Address
+ 2048);
467 // PxeStart call is going to give the callback functions to UNDI, these callback
468 // functions use the BarIndex values from the snp structure, so these must be initialized
469 // with default values before doing a PxeStart. The correct values can be obtained after
470 // getting the config information from UNDI
472 Snp
->MemoryBarIndex
= 0;
476 // we need the undi init information many times in this snp code, just get it
477 // once here and store it in the snp driver structure. to get Init Info
478 // from UNDI we have to start undi first.
480 Status
= PxeStart (Snp
);
482 if (Status
!= EFI_SUCCESS
) {
483 goto Error_DeleteSNP
;
486 Snp
->Cdb
.OpCode
= PXE_OPCODE_GET_INIT_INFO
;
487 Snp
->Cdb
.OpFlags
= PXE_OPFLAGS_NOT_USED
;
489 Snp
->Cdb
.CPBsize
= PXE_CPBSIZE_NOT_USED
;
490 Snp
->Cdb
.CPBaddr
= PXE_DBADDR_NOT_USED
;
492 Snp
->Cdb
.DBsize
= (UINT16
) sizeof (Snp
->InitInfo
);
493 Snp
->Cdb
.DBaddr
= (UINT64
)(UINTN
) (&Snp
->InitInfo
);
495 Snp
->Cdb
.StatCode
= PXE_STATCODE_INITIALIZE
;
496 Snp
->Cdb
.StatFlags
= PXE_STATFLAGS_INITIALIZE
;
498 Snp
->Cdb
.IFnum
= Snp
->IfNum
;
499 Snp
->Cdb
.Control
= PXE_CONTROL_LAST_CDB_IN_LIST
;
501 DEBUG ((EFI_D_NET
, "\nSnp->undi.get_init_info() "));
503 (*Snp
->IssueUndi32Command
) ((UINT64
)(UINTN
) &Snp
->Cdb
);
506 // Save the INIT Stat Code...
508 InitStatFlags
= Snp
->Cdb
.StatFlags
;
510 if (Snp
->Cdb
.StatCode
!= PXE_STATCODE_SUCCESS
) {
511 DEBUG ((EFI_D_NET
, "\nSnp->undi.init_info() %xh:%xh\n", Snp
->Cdb
.StatFlags
, Snp
->Cdb
.StatCode
));
513 goto Error_DeleteSNP
;
516 Snp
->Cdb
.OpCode
= PXE_OPCODE_GET_CONFIG_INFO
;
517 Snp
->Cdb
.OpFlags
= PXE_OPFLAGS_NOT_USED
;
519 Snp
->Cdb
.CPBsize
= PXE_CPBSIZE_NOT_USED
;
520 Snp
->Cdb
.CPBaddr
= PXE_DBADDR_NOT_USED
;
522 Snp
->Cdb
.DBsize
= (UINT16
) sizeof (ConfigInfo
);
523 Snp
->Cdb
.DBaddr
= (UINT64
)(UINTN
) &ConfigInfo
;
525 Snp
->Cdb
.StatCode
= PXE_STATCODE_INITIALIZE
;
526 Snp
->Cdb
.StatFlags
= PXE_STATFLAGS_INITIALIZE
;
528 Snp
->Cdb
.IFnum
= Snp
->IfNum
;
529 Snp
->Cdb
.Control
= PXE_CONTROL_LAST_CDB_IN_LIST
;
531 DEBUG ((EFI_D_NET
, "\nSnp->undi.get_config_info() "));
533 (*Snp
->IssueUndi32Command
) ((UINT64
)(UINTN
) &Snp
->Cdb
);
535 if (Snp
->Cdb
.StatCode
!= PXE_STATCODE_SUCCESS
) {
536 DEBUG ((EFI_D_NET
, "\nSnp->undi.config_info() %xh:%xh\n", Snp
->Cdb
.StatFlags
, Snp
->Cdb
.StatCode
));
538 goto Error_DeleteSNP
;
541 // Find the correct BAR to do IO.
544 // Enumerate through the PCI BARs for the device to determine which one is
545 // the IO BAR. Save the index of the BAR into the adapter info structure.
546 // for regular 32bit BARs, 0 is memory mapped, 1 is io mapped
548 ConfigHeader
= (PCI_TYPE00
*) ConfigInfo
.Config
.Byte
;
549 TempBar
= (UINT32
*) ConfigHeader
->Device
.Bar
;
550 for (BarIndex
= 0; BarIndex
<= 5; BarIndex
++) {
551 if ((*TempBar
& PCI_BAR_MEM_MASK
) == PCI_BAR_MEM_64BIT
) {
553 // This is a 64-bit memory bar, skip this and the
559 if ((*TempBar
& PCI_BAR_IO_MASK
) == PCI_BAR_IO_MODE
) {
560 Snp
->IoBarIndex
= BarIndex
;
568 // Initialize simple network protocol mode structure
570 Snp
->Mode
.State
= EfiSimpleNetworkStopped
;
571 Snp
->Mode
.HwAddressSize
= Snp
->InitInfo
.HWaddrLen
;
572 Snp
->Mode
.MediaHeaderSize
= Snp
->InitInfo
.MediaHeaderLen
;
573 Snp
->Mode
.MaxPacketSize
= Snp
->InitInfo
.FrameDataLen
;
574 Snp
->Mode
.NvRamAccessSize
= Snp
->InitInfo
.NvWidth
;
575 Snp
->Mode
.NvRamSize
= Snp
->InitInfo
.NvCount
* Snp
->Mode
.NvRamAccessSize
;
576 Snp
->Mode
.IfType
= Snp
->InitInfo
.IFtype
;
577 Snp
->Mode
.MaxMCastFilterCount
= Snp
->InitInfo
.MCastFilterCnt
;
578 Snp
->Mode
.MCastFilterCount
= 0;
580 switch (InitStatFlags
& PXE_STATFLAGS_CABLE_DETECT_MASK
) {
581 case PXE_STATFLAGS_CABLE_DETECT_SUPPORTED
:
582 Snp
->Mode
.MediaPresentSupported
= TRUE
;
585 case PXE_STATFLAGS_CABLE_DETECT_NOT_SUPPORTED
:
587 Snp
->Mode
.MediaPresentSupported
= FALSE
;
590 switch (InitStatFlags
& PXE_STATFLAGS_GET_STATUS_NO_MEDIA_MASK
) {
591 case PXE_STATFLAGS_GET_STATUS_NO_MEDIA_SUPPORTED
:
592 Snp
->MediaStatusSupported
= TRUE
;
595 case PXE_STATFLAGS_GET_STATUS_NO_MEDIA_NOT_SUPPORTED
:
597 Snp
->MediaStatusSupported
= FALSE
;
600 if ((Pxe
->hw
.Implementation
& PXE_ROMID_IMP_STATION_ADDR_SETTABLE
) != 0) {
601 Snp
->Mode
.MacAddressChangeable
= TRUE
;
603 Snp
->Mode
.MacAddressChangeable
= FALSE
;
606 if ((Pxe
->hw
.Implementation
& PXE_ROMID_IMP_MULTI_FRAME_SUPPORTED
) != 0) {
607 Snp
->Mode
.MultipleTxSupported
= TRUE
;
609 Snp
->Mode
.MultipleTxSupported
= FALSE
;
612 Snp
->Mode
.ReceiveFilterMask
= EFI_SIMPLE_NETWORK_RECEIVE_UNICAST
;
614 if ((Pxe
->hw
.Implementation
& PXE_ROMID_IMP_PROMISCUOUS_MULTICAST_RX_SUPPORTED
) != 0) {
615 Snp
->Mode
.ReceiveFilterMask
|= EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS_MULTICAST
;
619 if ((Pxe
->hw
.Implementation
& PXE_ROMID_IMP_PROMISCUOUS_RX_SUPPORTED
) != 0) {
620 Snp
->Mode
.ReceiveFilterMask
|= EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS
;
624 if ((Pxe
->hw
.Implementation
& PXE_ROMID_IMP_BROADCAST_RX_SUPPORTED
) != 0) {
625 Snp
->Mode
.ReceiveFilterMask
|= EFI_SIMPLE_NETWORK_RECEIVE_BROADCAST
;
629 if ((Pxe
->hw
.Implementation
& PXE_ROMID_IMP_FILTERED_MULTICAST_RX_SUPPORTED
) != 0) {
630 Snp
->Mode
.ReceiveFilterMask
|= EFI_SIMPLE_NETWORK_RECEIVE_MULTICAST
;
634 if ((Pxe
->hw
.Implementation
& PXE_ROMID_IMP_PROMISCUOUS_MULTICAST_RX_SUPPORTED
) != 0) {
635 Snp
->Mode
.ReceiveFilterMask
|= EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS_MULTICAST
;
639 Snp
->Mode
.ReceiveFilterSetting
= 0;
642 // need to get the station address to save in the mode structure. we need to
643 // initialize the UNDI first for this.
645 Snp
->TxRxBufferSize
= Snp
->InitInfo
.MemoryRequired
;
646 Status
= PxeInit (Snp
, PXE_OPFLAGS_INITIALIZE_DO_NOT_DETECT_CABLE
);
648 if (EFI_ERROR (Status
)) {
650 goto Error_DeleteSNP
;
653 Status
= PxeGetStnAddr (Snp
);
655 if (Status
!= EFI_SUCCESS
) {
656 DEBUG ((EFI_D_ERROR
, "\nSnp->undi.get_station_addr() failed.\n"));
659 goto Error_DeleteSNP
;
662 Snp
->Mode
.MediaPresent
= FALSE
;
665 // We should not leave UNDI started and initialized here. this DriverStart()
666 // routine must only find and attach the SNP interface to UNDI layer that it
667 // finds on the given handle!
668 // The UNDI layer will be started when upper layers call Snp->start.
669 // How ever, this DriverStart() must fill up the snp mode structure which
670 // contains the MAC address of the NIC. For this reason we started and
671 // initialized UNDI here, now we are done, do a shutdown and stop of the
678 // Create EXIT_BOOT_SERIVES Event
680 Status
= gBS
->CreateEventEx (
683 SnpNotifyExitBootServices
,
685 &gEfiEventExitBootServicesGuid
,
686 &Snp
->ExitBootServicesEvent
688 if (EFI_ERROR (Status
)) {
689 goto Error_DeleteSNP
;
693 // add SNP to the undi handle
695 Status
= gBS
->InstallProtocolInterface (
697 &gEfiSimpleNetworkProtocolGuid
,
698 EFI_NATIVE_INTERFACE
,
702 if (!EFI_ERROR (Status
)) {
708 SNP_MEM_PAGES (4096),
716 SNP_MEM_PAGES (sizeof (SNP_DRIVER
)),
722 &gEfiNetworkInterfaceIdentifierProtocolGuid_31
,
723 This
->DriverBindingHandle
,
729 &gEfiDevicePathProtocolGuid
,
730 This
->DriverBindingHandle
,
735 // If we got here that means we are in error state.
737 if (!EFI_ERROR (Status
)) {
738 Status
= EFI_DEVICE_ERROR
;
745 Stop this driver on ControllerHandle. This service is called by the
746 EFI boot service DisconnectController(). In order to
747 make drivers as small as possible, there are a few calling
748 restrictions for this service. DisconnectController()
749 must follow these calling restrictions. If any other agent wishes
750 to call Stop() it must also follow these calling restrictions.
752 @param This Protocol instance pointer.
753 @param ControllerHandle Handle of device to stop driver on
754 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
755 children is zero stop the entire bus driver.
756 @param ChildHandleBuffer List of Child Handles to Stop.
758 @retval EFI_SUCCESS This driver is removed ControllerHandle
759 @retval other This driver was not removed from this device
764 SimpleNetworkDriverStop (
765 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
766 IN EFI_HANDLE Controller
,
767 IN UINTN NumberOfChildren
,
768 IN EFI_HANDLE
*ChildHandleBuffer
772 EFI_SIMPLE_NETWORK_PROTOCOL
*SnpProtocol
;
776 // Get our context back.
778 Status
= gBS
->OpenProtocol (
780 &gEfiSimpleNetworkProtocolGuid
,
781 (VOID
**) &SnpProtocol
,
782 This
->DriverBindingHandle
,
784 EFI_OPEN_PROTOCOL_GET_PROTOCOL
787 if (EFI_ERROR (Status
)) {
788 return EFI_UNSUPPORTED
;
791 Snp
= EFI_SIMPLE_NETWORK_DEV_FROM_THIS (SnpProtocol
);
793 Status
= gBS
->UninstallProtocolInterface (
795 &gEfiSimpleNetworkProtocolGuid
,
799 if (EFI_ERROR (Status
)) {
804 // Close EXIT_BOOT_SERIVES Event
806 gBS
->CloseEvent (Snp
->ExitBootServicesEvent
);
808 Status
= gBS
->CloseProtocol (
810 &gEfiNetworkInterfaceIdentifierProtocolGuid_31
,
811 This
->DriverBindingHandle
,
815 Status
= gBS
->CloseProtocol (
817 &gEfiDevicePathProtocolGuid
,
818 This
->DriverBindingHandle
,
827 SNP_MEM_PAGES (4096),
833 SNP_MEM_PAGES (sizeof (SNP_DRIVER
)),
841 // Simple Network Protocol Driver Global Variables
843 EFI_DRIVER_BINDING_PROTOCOL gSimpleNetworkDriverBinding
= {
844 SimpleNetworkDriverSupported
,
845 SimpleNetworkDriverStart
,
846 SimpleNetworkDriverStop
,
854 This routine maps the given CPU address to a Device address. It creates a
855 an entry in the map list with the virtual and physical addresses and the
858 @param V2p pointer to return a map list node pointer.
859 @param Type the direction in which the data flows from the given
860 virtual address device->cpu or cpu->device or both
862 @param VirtualAddress virtual address (or CPU address) to be mapped.
863 @param BufferSize size of the buffer to be mapped.
865 @retval EFI_SUCEESS routine has completed the mapping.
866 @retval EFI_INVALID_PARAMETER invalid parameter.
867 @retval EFI_OUT_OF_RESOURCES out of resource.
868 @retval other error as indicated.
874 EFI_PCI_IO_PROTOCOL_OPERATION Type
,
875 VOID
*VirtualAddress
,
881 if ((V2p
== NULL
) || (VirtualAddress
== NULL
) || (BufferSize
== 0)) {
882 return EFI_INVALID_PARAMETER
;
885 *V2p
= AllocatePool (sizeof (V2P
));
887 return EFI_OUT_OF_RESOURCES
;
890 Status
= mPciIo
->Map (
895 &(*V2p
)->PhysicalAddress
,
898 if (Status
!= EFI_SUCCESS
) {
902 (*V2p
)->VirtualAddress
= VirtualAddress
;
903 (*V2p
)->BufferSize
= BufferSize
;
912 This routine searches the linked list of mapped address nodes (for undi3.0
913 interface) to find the node that corresponds to the given virtual address and
914 returns a pointer to that node.
916 @param V2p pointer to return a map list node pointer.
917 @param VirtualAddr virtual address (or CPU address) to be searched in
920 @retval EFI_SUCEESS A match was found.
921 @retval Other A match cannot be found.
932 if (V2p
== NULL
|| VirtualAddr
== NULL
) {
933 return EFI_INVALID_PARAMETER
;
936 for (Ptr
= mV2p
; Ptr
!= NULL
; Ptr
= Ptr
->Next
) {
937 if (Ptr
->VirtualAddress
== VirtualAddr
) {
943 return EFI_NOT_FOUND
;
948 Unmap the given virtual address and free the memory allocated for the map list
949 node corresponding to that address.
951 @param VirtualAddress virtual address (or CPU address) to be unmapped.
953 @retval EFI_SUCEESS Successfully unmapped.
954 @retval Other Other errors as indicated.
966 if (VirtualAddress
== NULL
) {
967 return EFI_INVALID_PARAMETER
;
971 return EFI_NOT_FOUND
;
974 // Is our node at the head of the list??
976 if ((Current
= mV2p
)->VirtualAddress
== VirtualAddress
) {
979 Status
= mPciIo
->Unmap (mPciIo
, Current
->Unmap
);
983 if (EFI_ERROR (Status
)) {
984 DEBUG ((EFI_D_ERROR
, "Unmap failed with status = %r\n", Status
));
989 for (; Current
->Next
!= NULL
; Current
= Next
) {
990 if ((Next
= Current
->Next
)->VirtualAddress
== VirtualAddress
) {
991 Current
->Next
= Next
->Next
;
992 Status
= mPciIo
->Unmap (mPciIo
, Next
->Unmap
);
995 if (EFI_ERROR (Status
)) {
996 DEBUG ((EFI_D_ERROR
, "Unmap failed with status = %r\n", Status
));
1002 return EFI_NOT_FOUND
;
1006 The SNP driver entry point.
1008 @param ImageHandle The driver image handle.
1009 @param SystemTable The system table.
1011 @retval EFI_SUCEESS Initialization routine has found UNDI hardware,
1012 loaded it's ROM, and installed a notify event for
1013 the Network Indentifier Interface Protocol
1015 @retval Other Return value from HandleProtocol for
1016 DeviceIoProtocol or LoadedImageProtocol
1021 InitializeSnpNiiDriver (
1022 IN EFI_HANDLE ImageHandle
,
1023 IN EFI_SYSTEM_TABLE
*SystemTable
1026 return EfiLibInstallDriverBindingComponentName2 (
1029 &gSimpleNetworkDriverBinding
,
1031 &gSimpleNetworkComponentName
,
1032 &gSimpleNetworkComponentName2