david/ipxe
david
/
ipxe
Archived
1
0
Fork 0

[efi] Add basic implementation of EFI SIMPLE_NETWORK_PROTOCOL

This implementation is tested and working, but not currently tied in
to the EFI build.
This commit is contained in:
Michael Brown 2008-10-16 05:38:23 +01:00
parent 3a505dfc35
commit c99b16c974
5 changed files with 2367 additions and 0 deletions

View File

@ -0,0 +1,166 @@
/** @file
UEFI DriverBinding Protocol is defined in UEFI specification.
This protocol is produced by every driver that follows the UEFI Driver Model,
and it is the central component that allows drivers and controllers to be managed.
Copyright (c) 2006 - 2008, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#ifndef __EFI_DRIVER_BINDING_H__
#define __EFI_DRIVER_BINDING_H__
#include <gpxe/efi/PiDxe.h>
#include <gpxe/efi/Protocol/DevicePath.h>
///
/// Global ID for the ControllerHandle Driver Protocol
///
#define EFI_DRIVER_BINDING_PROTOCOL_GUID \
{ \
0x18a031ab, 0xb443, 0x4d1a, {0xa5, 0xc0, 0xc, 0x9, 0x26, 0x1e, 0x9f, 0x71 } \
}
typedef struct _EFI_DRIVER_BINDING_PROTOCOL EFI_DRIVER_BINDING_PROTOCOL;
/**
Test to see if this driver supports ControllerHandle.
@param This Protocol instance pointer.
@param ControllerHandle Handle of device to test
@param RemainingDevicePath Optional parameter use to pick a specific child
device to start.
@retval EFI_SUCCESS This driver supports this device
@retval EFI_ALREADY_STARTED This driver is already running on this device
@retval other This driver does not support this device
**/
typedef
EFI_STATUS
(EFIAPI *EFI_DRIVER_BINDING_SUPPORTED)(
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
);
/**
Start this driver on ControllerHandle.
@param This Protocol instance pointer.
@param ControllerHandle Handle of device to bind driver to
@param RemainingDevicePath Optional parameter use to pick a specific child
device to start.
@retval EFI_SUCCESS This driver is added to ControllerHandle
@retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle
@retval other This driver does not support this device
**/
typedef
EFI_STATUS
(EFIAPI *EFI_DRIVER_BINDING_START)(
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
);
/**
Stop this driver on ControllerHandle.
@param This Protocol instance pointer.
@param ControllerHandle Handle of device to stop driver on
@param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
children is zero stop the entire bus driver.
@param ChildHandleBuffer List of Child Handles to Stop.
@retval EFI_SUCCESS This driver is removed ControllerHandle
@retval other This driver was not removed from this device
**/
typedef
EFI_STATUS
(EFIAPI *EFI_DRIVER_BINDING_STOP)(
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN UINTN NumberOfChildren,
IN EFI_HANDLE *ChildHandleBuffer OPTIONAL
);
//
// Interface structure for the ControllerHandle Driver Protocol
//
/**
@par Protocol Description:
This protocol provides the services required to determine if a driver supports a given controller.
If a controller is supported, then it also provides routines to start and stop the controller.
@param Supported
Tests to see if this driver supports a given controller. This service
is called by the EFI boot service ConnectController(). In
order to make drivers as small as possible, there are a few calling
restrictions for this service. ConnectController() must
follow these calling restrictions. If any other agent wishes to call
Supported() it must also follow these calling restrictions.
@param Start
Starts a controller using this driver. This service is called by the
EFI boot service ConnectController(). In order to make
drivers as small as possible, there are a few calling restrictions for
this service. ConnectController() must follow these
calling restrictions. If any other agent wishes to call Start() it
must also follow these calling restrictions.
@param Stop
Stops a controller using this driver. This service is called by the
EFI boot service DisconnectController(). In order to
make drivers as small as possible, there are a few calling
restrictions for this service. DisconnectController()
must follow these calling restrictions. If any other agent wishes
to call Stop() it must also follow these calling restrictions.
@param Version
The version number of the UEFI driver that produced the
EFI_DRIVER_BINDING_PROTOCOL. This field is used by
the EFI boot service ConnectController() to determine
the order that driver's Supported() service will be used when
a controller needs to be started. EFI Driver Binding Protocol
instances with higher Version values will be used before ones
with lower Version values. The Version values of 0x0-
0x0f and 0xfffffff0-0xffffffff are reserved for
platform/OEM specific drivers. The Version values of 0x10-
0xffffffef are reserved for IHV-developed drivers.
@param ImageHandle
The image handle of the UEFI driver that produced this instance
of the EFI_DRIVER_BINDING_PROTOCOL.
@param DriverBindingHandle
The handle on which this instance of the
EFI_DRIVER_BINDING_PROTOCOL is installed. In most
cases, this is the same handle as ImageHandle. However, for
UEFI drivers that produce more than one instance of the
EFI_DRIVER_BINDING_PROTOCOL, this value may not be
the same as ImageHandle.
**/
struct _EFI_DRIVER_BINDING_PROTOCOL {
EFI_DRIVER_BINDING_SUPPORTED Supported;
EFI_DRIVER_BINDING_START Start;
EFI_DRIVER_BINDING_STOP Stop;
UINT32 Version;
EFI_HANDLE ImageHandle;
EFI_HANDLE DriverBindingHandle;
};
extern EFI_GUID gEfiDriverBindingProtocolGuid;
#endif

View File

@ -0,0 +1,577 @@
/** @file
EFI PCI I/O Protocol provides the basic Memory, I/O, PCI configuration,
and DMA interfaces that a driver uses to access its PCI controller.
Copyright (c) 2006 - 2008, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#ifndef __PCI_IO_H__
#define __PCI_IO_H__
///
/// Global ID for the PCI I/O Protocol
///
#define EFI_PCI_IO_PROTOCOL_GUID \
{ \
0x4cf5b200, 0x68b8, 0x4ca5, {0x9e, 0xec, 0xb2, 0x3e, 0x3f, 0x50, 0x2, 0x9a } \
}
typedef struct _EFI_PCI_IO_PROTOCOL EFI_PCI_IO_PROTOCOL;
///
/// Prototypes for the PCI I/O Protocol
///
typedef enum {
EfiPciIoWidthUint8 = 0,
EfiPciIoWidthUint16,
EfiPciIoWidthUint32,
EfiPciIoWidthUint64,
EfiPciIoWidthFifoUint8,
EfiPciIoWidthFifoUint16,
EfiPciIoWidthFifoUint32,
EfiPciIoWidthFifoUint64,
EfiPciIoWidthFillUint8,
EfiPciIoWidthFillUint16,
EfiPciIoWidthFillUint32,
EfiPciIoWidthFillUint64,
EfiPciIoWidthMaximum
} EFI_PCI_IO_PROTOCOL_WIDTH;
//
// Complete PCI address generater
//
#define EFI_PCI_IO_PASS_THROUGH_BAR 0xff // Special BAR that passes a memory or I/O cycle through unchanged
#define EFI_PCI_IO_ATTRIBUTE_MASK 0x077f // All the following I/O and Memory cycles
#define EFI_PCI_IO_ATTRIBUTE_ISA_MOTHERBOARD_IO 0x0001 // I/O cycles 0x0000-0x00FF (10 bit decode)
#define EFI_PCI_IO_ATTRIBUTE_ISA_IO 0x0002 // I/O cycles 0x0100-0x03FF or greater (10 bit decode)
#define EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO 0x0004 // I/O cycles 0x3C6, 0x3C8, 0x3C9 (10 bit decode)
#define EFI_PCI_IO_ATTRIBUTE_VGA_MEMORY 0x0008 // MEM cycles 0xA0000-0xBFFFF (24 bit decode)
#define EFI_PCI_IO_ATTRIBUTE_VGA_IO 0x0010 // I/O cycles 0x3B0-0x3BB and 0x3C0-0x3DF (10 bit decode)
#define EFI_PCI_IO_ATTRIBUTE_IDE_PRIMARY_IO 0x0020 // I/O cycles 0x1F0-0x1F7, 0x3F6, 0x3F7 (10 bit decode)
#define EFI_PCI_IO_ATTRIBUTE_IDE_SECONDARY_IO 0x0040 // I/O cycles 0x170-0x177, 0x376, 0x377 (10 bit decode)
#define EFI_PCI_IO_ATTRIBUTE_MEMORY_WRITE_COMBINE 0x0080 // Map a memory range so write are combined
#define EFI_PCI_IO_ATTRIBUTE_IO 0x0100 // Enable the I/O decode bit in the PCI Config Header
#define EFI_PCI_IO_ATTRIBUTE_MEMORY 0x0200 // Enable the Memory decode bit in the PCI Config Header
#define EFI_PCI_IO_ATTRIBUTE_BUS_MASTER 0x0400 // Enable the DMA bit in the PCI Config Header
#define EFI_PCI_IO_ATTRIBUTE_MEMORY_CACHED 0x0800 // Map a memory range so all r/w accesses are cached
#define EFI_PCI_IO_ATTRIBUTE_MEMORY_DISABLE 0x1000 // Disable a memory range
#define EFI_PCI_IO_ATTRIBUTE_EMBEDDED_DEVICE 0x2000 // Clear for an add-in PCI Device
#define EFI_PCI_IO_ATTRIBUTE_EMBEDDED_ROM 0x4000 // Clear for a physical PCI Option ROM accessed through ROM BAR
#define EFI_PCI_IO_ATTRIBUTE_DUAL_ADDRESS_CYCLE 0x8000 // Clear for PCI controllers that can not genrate a DAC
#define EFI_PCI_IO_ATTRIBUTE_ISA_IO_16 0x10000 // I/O cycles 0x0100-0x03FF or greater (16 bit decode)
#define EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO_16 0x20000 // I/O cycles 0x3C6, 0x3C8, 0x3C9 (16 bit decode)
#define EFI_PCI_IO_ATTRIBUTE_VGA_IO_16 0x30000 // I/O cycles 0x3B0-0x3BB and 0x3C0-0x3DF (16 bit decode)
#define EFI_PCI_DEVICE_ENABLE (EFI_PCI_IO_ATTRIBUTE_IO | EFI_PCI_IO_ATTRIBUTE_MEMORY | EFI_PCI_IO_ATTRIBUTE_BUS_MASTER)
#define EFI_VGA_DEVICE_ENABLE (EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO | EFI_PCI_IO_ATTRIBUTE_VGA_MEMORY | EFI_PCI_IO_ATTRIBUTE_VGA_IO | EFI_PCI_IO_ATTRIBUTE_IO)
///
/// *******************************************************
/// EFI_PCI_IO_PROTOCOL_OPERATION
/// *******************************************************
///
typedef enum {
EfiPciIoOperationBusMasterRead,
EfiPciIoOperationBusMasterWrite,
EfiPciIoOperationBusMasterCommonBuffer,
EfiPciIoOperationMaximum
} EFI_PCI_IO_PROTOCOL_OPERATION;
///
/// *******************************************************
/// EFI_PCI_IO_PROTOCOL_ATTRIBUTE_OPERATION
/// *******************************************************
///
typedef enum {
EfiPciIoAttributeOperationGet,
EfiPciIoAttributeOperationSet,
EfiPciIoAttributeOperationEnable,
EfiPciIoAttributeOperationDisable,
EfiPciIoAttributeOperationSupported,
EfiPciIoAttributeOperationMaximum
} EFI_PCI_IO_PROTOCOL_ATTRIBUTE_OPERATION;
/**
Reads from the memory space of a PCI controller. Returns when either the polling exit criteria is
satisfied or after a defined duration.
@param This A pointer to the EFI_PCI_IO_PROTOCOL instance.
@param Width Signifies the width of the memory or I/O operations.
@param BarIndex The BAR index of the standard PCI Configuration header to use as the
base address for the memory operation to perform.
@param Offset The offset within the selected BAR to start the memory operation.
@param Mask Mask used for the polling criteria.
@param Value The comparison value used for the polling exit criteria.
@param Delay The number of 100 ns units to poll.
@param Result Pointer to the last value read from the memory location.
@retval EFI_SUCCESS The last data returned from the access matched the poll exit criteria.
@retval EFI_UNSUPPORTED BarIndex not valid for this PCI controller.
@retval EFI_UNSUPPORTED Offset is not valid for the BarIndex of this PCI controller.
@retval EFI_TIMEOUT Delay expired before a match occurred.
@retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
@retval EFI_INVALID_PARAMETER One or more parameters are invalid.
**/
typedef
EFI_STATUS
(EFIAPI *EFI_PCI_IO_PROTOCOL_POLL_IO_MEM)(
IN EFI_PCI_IO_PROTOCOL *This,
IN EFI_PCI_IO_PROTOCOL_WIDTH Width,
IN UINT8 BarIndex,
IN UINT64 Offset,
IN UINT64 Mask,
IN UINT64 Value,
IN UINT64 Delay,
OUT UINT64 *Result
);
/**
Enable a PCI driver to access PCI controller registers in the PCI memory or I/O space.
@param This A pointer to the EFI_PCI_IO_PROTOCOL instance.
@param Width Signifies the width of the memory or I/O operations.
@param BarIndex The BAR index of the standard PCI Configuration header to use as the
base address for the memory or I/O operation to perform.
@param Offset The offset within the selected BAR to start the memory or I/O operation.
@param Count The number of memory or I/O operations to perform.
@param Buffer For read operations, the destination buffer to store the results. For write
operations, the source buffer to write data from.
@retval EFI_SUCCESS The data was read from or written to the PCI controller.
@retval EFI_UNSUPPORTED BarIndex not valid for this PCI controller.
@retval EFI_UNSUPPORTED The address range specified by Offset, Width, and Count is not
valid for the PCI BAR specified by BarIndex.
@retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
@retval EFI_INVALID_PARAMETER One or more parameters are invalid.
**/
typedef
EFI_STATUS
(EFIAPI *EFI_PCI_IO_PROTOCOL_IO_MEM)(
IN EFI_PCI_IO_PROTOCOL *This,
IN EFI_PCI_IO_PROTOCOL_WIDTH Width,
IN UINT8 BarIndex,
IN UINT64 Offset,
IN UINTN Count,
IN OUT VOID *Buffer
);
typedef struct {
EFI_PCI_IO_PROTOCOL_IO_MEM Read;
EFI_PCI_IO_PROTOCOL_IO_MEM Write;
} EFI_PCI_IO_PROTOCOL_ACCESS;
/**
Enable a PCI driver to access PCI controller registers in PCI configuration space.
@param This A pointer to the EFI_PCI_IO_PROTOCOL instance.
@param Width Signifies the width of the memory operations.
@param Offset The offset within the PCI configuration space for the PCI controller.
@param Count The number of PCI configuration operations to perform.
@param Buffer For read operations, the destination buffer to store the results. For write
operations, the source buffer to write data from.
@retval EFI_SUCCESS The data was read from or written to the PCI controller.
@retval EFI_UNSUPPORTED The address range specified by Offset, Width, and Count is not
valid for the PCI configuration header of the PCI controller.
@retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
@retval EFI_INVALID_PARAMETER Buffer is NULL or Width is invalid.
**/
typedef
EFI_STATUS
(EFIAPI *EFI_PCI_IO_PROTOCOL_CONFIG)(
IN EFI_PCI_IO_PROTOCOL *This,
IN EFI_PCI_IO_PROTOCOL_WIDTH Width,
IN UINT32 Offset,
IN UINTN Count,
IN OUT VOID *Buffer
);
typedef struct {
EFI_PCI_IO_PROTOCOL_CONFIG Read;
EFI_PCI_IO_PROTOCOL_CONFIG Write;
} EFI_PCI_IO_PROTOCOL_CONFIG_ACCESS;
/**
Enables a PCI driver to copy one region of PCI memory space to another region of PCI
memory space.
@param This A pointer to the EFI_PCI_IO_PROTOCOL instance.
@param Width Signifies the width of the memory operations.
@param DestBarIndex The BAR index in the standard PCI Configuration header to use as the
base address for the memory operation to perform.
@param DestOffset The destination offset within the BAR specified by DestBarIndex to
start the memory writes for the copy operation.
@param SrcBarIndex The BAR index in the standard PCI Configuration header to use as the
base address for the memory operation to perform.
@param SrcOffset The source offset within the BAR specified by SrcBarIndex to start
the memory reads for the copy operation.
@param Count The number of memory operations to perform. Bytes moved is Width
size * Count, starting at DestOffset and SrcOffset.
@retval EFI_SUCCESS The data was copied from one memory region to another memory region.
@retval EFI_UNSUPPORTED DestBarIndex not valid for this PCI controller.
@retval EFI_UNSUPPORTED SrcBarIndex not valid for this PCI controller.
@retval EFI_UNSUPPORTED The address range specified by DestOffset, Width, and Count
is not valid for the PCI BAR specified by DestBarIndex.
@retval EFI_UNSUPPORTED The address range specified by SrcOffset, Width, and Count is
not valid for the PCI BAR specified by SrcBarIndex.
@retval EFI_INVALID_PARAMETER Width is invalid.
@retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
**/
typedef
EFI_STATUS
(EFIAPI *EFI_PCI_IO_PROTOCOL_COPY_MEM)(
IN EFI_PCI_IO_PROTOCOL *This,
IN EFI_PCI_IO_PROTOCOL_WIDTH Width,
IN UINT8 DestBarIndex,
IN UINT64 DestOffset,
IN UINT8 SrcBarIndex,
IN UINT64 SrcOffset,
IN UINTN Count
);
/**
Provides the PCI controller-Cspecific addresses needed to access system memory.
@param This A pointer to the EFI_PCI_IO_PROTOCOL instance.
@param Operation Indicates if the bus master is going to read or write to system memory.
@param HostAddress The system memory address to map to the PCI controller.
@param NumberOfBytes On input the number of bytes to map. On output the number of bytes
that were mapped.
@param DeviceAddress The resulting map address for the bus master PCI controller to use to
access the hosts HostAddress.
@param Mapping A resulting value to pass to Unmap().
@retval EFI_SUCCESS The range was mapped for the returned NumberOfBytes.
@retval EFI_UNSUPPORTED The HostAddress cannot be mapped as a common buffer.
@retval EFI_INVALID_PARAMETER One or more parameters are invalid.
@retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
@retval EFI_DEVICE_ERROR The system hardware could not map the requested address.
**/
typedef
EFI_STATUS
(EFIAPI *EFI_PCI_IO_PROTOCOL_MAP)(
IN EFI_PCI_IO_PROTOCOL *This,
IN EFI_PCI_IO_PROTOCOL_OPERATION Operation,
IN VOID *HostAddress,
IN OUT UINTN *NumberOfBytes,
OUT EFI_PHYSICAL_ADDRESS *DeviceAddress,
OUT VOID **Mapping
);
/**
Completes the Map() operation and releases any corresponding resources.
@param This A pointer to the EFI_PCI_IO_PROTOCOL instance.
@param Mapping The mapping value returned from Map().
@retval EFI_SUCCESS The range was unmapped.
@retval EFI_DEVICE_ERROR The data was not committed to the target system memory.
**/
typedef
EFI_STATUS
(EFIAPI *EFI_PCI_IO_PROTOCOL_UNMAP)(
IN EFI_PCI_IO_PROTOCOL *This,
IN VOID *Mapping
);
/**
Allocates pages that are suitable for an EfiPciIoOperationBusMasterCommonBuffer
mapping.
@param This A pointer to the EFI_PCI_IO_PROTOCOL instance.
@param Type This parameter is not used and must be ignored.
@param MemoryType The type of memory to allocate, EfiBootServicesData or
EfiRuntimeServicesData.
@param Pages The number of pages to allocate.
@param HostAddress A pointer to store the base system memory address of the
allocated range.
@param Attributes The requested bit mask of attributes for the allocated range.
@retval EFI_SUCCESS The requested memory pages were allocated.
@retval EFI_UNSUPPORTED Attributes is unsupported. The only legal attribute bits are
MEMORY_WRITE_COMBINE and MEMORY_CACHED.
@retval EFI_INVALID_PARAMETER One or more parameters are invalid.
@retval EFI_OUT_OF_RESOURCES The memory pages could not be allocated.
**/
typedef
EFI_STATUS
(EFIAPI *EFI_PCI_IO_PROTOCOL_ALLOCATE_BUFFER)(
IN EFI_PCI_IO_PROTOCOL *This,
IN EFI_ALLOCATE_TYPE Type,
IN EFI_MEMORY_TYPE MemoryType,
IN UINTN Pages,
OUT VOID **HostAddress,
IN UINT64 Attributes
);
/**
Frees memory that was allocated with AllocateBuffer().
@param This A pointer to the EFI_PCI_IO_PROTOCOL instance.
@param Pages The number of pages to free.
@param HostAddress The base system memory address of the allocated range.
@retval EFI_SUCCESS The requested memory pages were freed.
@retval EFI_INVALID_PARAMETER The memory range specified by HostAddress and Pages
was not allocated with AllocateBuffer().
**/
typedef
EFI_STATUS
(EFIAPI *EFI_PCI_IO_PROTOCOL_FREE_BUFFER)(
IN EFI_PCI_IO_PROTOCOL *This,
IN UINTN Pages,
IN VOID *HostAddress
);
/**
Flushes all PCI posted write transactions from a PCI host bridge to system memory.
@param This A pointer to the EFI_PCI_IO_PROTOCOL instance.
@retval EFI_SUCCESS The PCI posted write transactions were flushed from the PCI host
bridge to system memory.
@retval EFI_DEVICE_ERROR The PCI posted write transactions were not flushed from the PCI
host bridge due to a hardware error.
**/
typedef
EFI_STATUS
(EFIAPI *EFI_PCI_IO_PROTOCOL_FLUSH)(
IN EFI_PCI_IO_PROTOCOL *This
);
/**
Retrieves this PCI controller's current PCI bus number, device number, and function number.
@param This A pointer to the EFI_PCI_IO_PROTOCOL instance.
@param SegmentNumber The PCI controller's current PCI segment number.
@param BusNumber The PCI controller's current PCI bus number.
@param DeviceNumber The PCI controller's current PCI device number.
@param FunctionNumber The PCI controller's current PCI function number.
@retval EFI_SUCCESS The PCI controller location was returned.
@retval EFI_INVALID_PARAMETER One or more parameters are invalid.
**/
typedef
EFI_STATUS
(EFIAPI *EFI_PCI_IO_PROTOCOL_GET_LOCATION)(
IN EFI_PCI_IO_PROTOCOL *This,
OUT UINTN *SegmentNumber,
OUT UINTN *BusNumber,
OUT UINTN *DeviceNumber,
OUT UINTN *FunctionNumber
);
/**
Performs an operation on the attributes that this PCI controller supports. The operations include
getting the set of supported attributes, retrieving the current attributes, setting the current
attributes, enabling attributes, and disabling attributes.
@param This A pointer to the EFI_PCI_IO_PROTOCOL instance.
@param Operation The operation to perform on the attributes for this PCI controller.
@param Attributes The mask of attributes that are used for Set, Enable, and Disable
operations.
@param Result A pointer to the result mask of attributes that are returned for the Get
and Supported operations.
@retval EFI_SUCCESS The operation on the PCI controller's attributes was completed.
@retval EFI_INVALID_PARAMETER One or more parameters are invalid.
@retval EFI_UNSUPPORTED one or more of the bits set in
Attributes are not supported by this PCI controller or one of
its parent bridges when Operation is Set, Enable or Disable.
**/
typedef
EFI_STATUS
(EFIAPI *EFI_PCI_IO_PROTOCOL_ATTRIBUTES)(
IN EFI_PCI_IO_PROTOCOL *This,
IN EFI_PCI_IO_PROTOCOL_ATTRIBUTE_OPERATION Operation,
IN UINT64 Attributes,
OUT UINT64 *Result OPTIONAL
);
/**
Gets the attributes that this PCI controller supports setting on a BAR using
SetBarAttributes(), and retrieves the list of resource descriptors for a BAR.
@param This A pointer to the EFI_PCI_IO_PROTOCOL instance.
@param BarIndex The BAR index of the standard PCI Configuration header to use as the
base address for resource range. The legal range for this field is 0..5.
@param Supports A pointer to the mask of attributes that this PCI controller supports
setting for this BAR with SetBarAttributes().
@param Resources A pointer to the ACPI 2.0 resource descriptors that describe the current
configuration of this BAR of the PCI controller.
@retval EFI_SUCCESS If Supports is not NULL, then the attributes that the PCI
controller supports are returned in Supports. If Resources
is not NULL, then the ACPI 2.0 resource descriptors that the PCI
controller is currently using are returned in Resources.
@retval EFI_INVALID_PARAMETER Both Supports and Attributes are NULL.
@retval EFI_UNSUPPORTED BarIndex not valid for this PCI controller.
@retval EFI_OUT_OF_RESOURCES There are not enough resources available to allocate
Resources.
**/
typedef
EFI_STATUS
(EFIAPI *EFI_PCI_IO_PROTOCOL_GET_BAR_ATTRIBUTES)(
IN EFI_PCI_IO_PROTOCOL *This,
IN UINT8 BarIndex,
OUT UINT64 *Supports, OPTIONAL
OUT VOID **Resources OPTIONAL
);
/**
Sets the attributes for a range of a BAR on a PCI controller.
@param This A pointer to the EFI_PCI_IO_PROTOCOL instance.
@param Attributes The mask of attributes to set for the resource range specified by
BarIndex, Offset, and Length.
@param BarIndex The BAR index of the standard PCI Configuration header to use as the
base address for resource range. The legal range for this field is 0..5.
@param Offset A pointer to the BAR relative base address of the resource range to be
modified by the attributes specified by Attributes.
@param Length A pointer to the length of the resource range to be modified by the
attributes specified by Attributes.
@retval EFI_SUCCESS The set of attributes specified by Attributes for the resource
range specified by BarIndex, Offset, and Length were
set on the PCI controller, and the actual resource range is returned
in Offset and Length.
@retval EFI_INVALID_PARAMETER Offset or Length is NULL.
@retval EFI_UNSUPPORTED BarIndex not valid for this PCI controller.
@retval EFI_OUT_OF_RESOURCES There are not enough resources to set the attributes on the
resource range specified by BarIndex, Offset, and
Length.
**/
typedef
EFI_STATUS
(EFIAPI *EFI_PCI_IO_PROTOCOL_SET_BAR_ATTRIBUTES)(
IN EFI_PCI_IO_PROTOCOL *This,
IN UINT64 Attributes,
IN UINT8 BarIndex,
IN OUT UINT64 *Offset,
IN OUT UINT64 *Length
);
/**
@par Protocol Description:
The EFI_PCI_IO_PROTOCOL provides the basic Memory, I/O, PCI configuration,
and DMA interfaces that are used to abstract accesses to PCI controllers.
There is one EFI_PCI_IO_PROTOCOL instance for each PCI controller on a PCI bus.
A device driver that wishes to manage a PCI controller in a system will have to
retrieve the EFI_PCI_IO_PROTOCOL instance that is associated with the PCI controller.
@param PollMem
Polls an address in PCI memory space until an exit condition is met, or a timeout occurs.
@param PollIo
Polls an address in PCI I/O space until an exit condition is met, or a timeout occurs.
@param Mem.Read
Allows BAR relative reads to PCI memory space.
@param Mem.Write
Allows BAR relative writes to PCI memory space.
@param Io.Read
Allows BAR relative reads to PCI I/O space.
@param Io.Write
Allows BAR relative writes to PCI I/O space.
@param Pci.Read
Allows PCI controller relative reads to PCI configuration space.
@param Pci.Write
Allows PCI controller relative writes to PCI configuration space.
@param CopyMem
Allows one region of PCI memory space to be copied to another region of PCI memory space.
@param Map
Provides the PCI controller's specific address needed to access system memory for DMA.
@param Unmap
Releases any resources allocated by Map().
@param AllocateBuffer
Allocates pages that are suitable for a common buffer mapping.
@param FreeBuffer
Frees pages that were allocated with AllocateBuffer().
@param Flush
Flushes all PCI posted write transactions to system memory.
@param GetLocation
Retrieves this PCI controller's current PCI bus number, device number, and function number.
@param Attributes
Performs an operation on the attributes that this PCI controller supports.
The operations include getting the set of supported attributes, retrieving
the current attributes, setting the current
attributes, enabling attributes, and disabling attributes.
@param GetBarAttributes
Gets the attributes that this PCI controller supports setting on a BAR using
SetBarAttributes(), and retrieves the list of resource descriptors for a BAR.
@param SetBarAttributes
Sets the attributes for a range of a BAR on a PCI controller.
@param RomSize
The size, in bytes, of the ROM image.
@param RomImage
A pointer to the in memory copy of the ROM image. The PCI Bus Driver is responsible
for allocating memory for the ROM image, and copying the contents of the ROM to memory.
The contents of this buffer are either from the PCI option ROM that can be accessed
through the ROM BAR of the PCI controller, or it is from a platform-specific location.
The Attributes() function can be used to determine from which of these two sources
the RomImage buffer was initialized.
**/
struct _EFI_PCI_IO_PROTOCOL {
EFI_PCI_IO_PROTOCOL_POLL_IO_MEM PollMem;
EFI_PCI_IO_PROTOCOL_POLL_IO_MEM PollIo;
EFI_PCI_IO_PROTOCOL_ACCESS Mem;
EFI_PCI_IO_PROTOCOL_ACCESS Io;
EFI_PCI_IO_PROTOCOL_CONFIG_ACCESS Pci;
EFI_PCI_IO_PROTOCOL_COPY_MEM CopyMem;
EFI_PCI_IO_PROTOCOL_MAP Map;
EFI_PCI_IO_PROTOCOL_UNMAP Unmap;
EFI_PCI_IO_PROTOCOL_ALLOCATE_BUFFER AllocateBuffer;
EFI_PCI_IO_PROTOCOL_FREE_BUFFER FreeBuffer;
EFI_PCI_IO_PROTOCOL_FLUSH Flush;
EFI_PCI_IO_PROTOCOL_GET_LOCATION GetLocation;
EFI_PCI_IO_PROTOCOL_ATTRIBUTES Attributes;
EFI_PCI_IO_PROTOCOL_GET_BAR_ATTRIBUTES GetBarAttributes;
EFI_PCI_IO_PROTOCOL_SET_BAR_ATTRIBUTES SetBarAttributes;
UINT64 RomSize;
VOID *RomImage;
};
extern EFI_GUID gEfiPciIoProtocolGuid;
#endif

View File

@ -0,0 +1,645 @@
/** @file
Simple Network protocol as defined in the UEFI 2.0 specification.
Basic network device abstraction.
Rx - Received
Tx - Transmit
MCast - MultiCast
...
Copyright (c) 2006 - 2008, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#ifndef __SIMPLE_NETWORK_H__
#define __SIMPLE_NETWORK_H__
#define EFI_SIMPLE_NETWORK_PROTOCOL_GUID \
{ \
0xA19832B9, 0xAC25, 0x11D3, {0x9A, 0x2D, 0x00, 0x90, 0x27, 0x3F, 0xC1, 0x4D } \
}
typedef struct _EFI_SIMPLE_NETWORK_PROTOCOL EFI_SIMPLE_NETWORK_PROTOCOL;
///
/// Protocol defined in EFI1.1.
///
typedef EFI_SIMPLE_NETWORK_PROTOCOL EFI_SIMPLE_NETWORK;
///
/// Simple Network Protocol data structures
///
typedef struct {
///
/// Total number of frames received. Includes frames with errors and
/// dropped frames.
///
UINT64 RxTotalFrames;
///
/// Number of valid frames received and copied into receive buffers.
///
UINT64 RxGoodFrames;
///
/// Number of frames below the minimum length for the media.
/// This would be <64 for ethernet.
///
UINT64 RxUndersizeFrames;
///
/// Number of frames longer than the maxminum length for the
/// media. This would be >1500 for ethernet.
///
UINT64 RxOversizeFrames;
///
/// Valid frames that were dropped because receive buffers were full.
///
UINT64 RxDroppedFrames;
///
/// Number of valid unicast frames received and not dropped.
///
UINT64 RxUnicastFrames;
///
/// Number of valid broadcast frames received and not dropped.
///
UINT64 RxBroadcastFrames;
///
/// Number of valid mutlicast frames received and not dropped.
///
UINT64 RxMulticastFrames;
///
/// Number of frames w/ CRC or alignment errors.
///
UINT64 RxCrcErrorFrames;
///
/// Total number of bytes received. Includes frames with errors
/// and dropped frames.
//
UINT64 RxTotalBytes;
///
/// Transmit statistics.
///
UINT64 TxTotalFrames;
UINT64 TxGoodFrames;
UINT64 TxUndersizeFrames;
UINT64 TxOversizeFrames;
UINT64 TxDroppedFrames;
UINT64 TxUnicastFrames;
UINT64 TxBroadcastFrames;
UINT64 TxMulticastFrames;
UINT64 TxCrcErrorFrames;
UINT64 TxTotalBytes;
///
/// Number of collisions detection on this subnet.
///
UINT64 Collisions;
///
/// Number of frames destined for unsupported protocol.
///
UINT64 UnsupportedProtocol;
} EFI_NETWORK_STATISTICS;
typedef enum {
EfiSimpleNetworkStopped,
EfiSimpleNetworkStarted,
EfiSimpleNetworkInitialized,
EfiSimpleNetworkMaxState
} EFI_SIMPLE_NETWORK_STATE;
#define EFI_SIMPLE_NETWORK_RECEIVE_UNICAST 0x01
#define EFI_SIMPLE_NETWORK_RECEIVE_MULTICAST 0x02
#define EFI_SIMPLE_NETWORK_RECEIVE_BROADCAST 0x04
#define EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS 0x08
#define EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS_MULTICAST 0x10
#define EFI_SIMPLE_NETWORK_RECEIVE_INTERRUPT 0x01
#define EFI_SIMPLE_NETWORK_TRANSMIT_INTERRUPT 0x02
#define EFI_SIMPLE_NETWORK_COMMAND_INTERRUPT 0x04
#define EFI_SIMPLE_NETWORK_SOFTWARE_INTERRUPT 0x08
#define MAX_MCAST_FILTER_CNT 16
typedef struct {
UINT32 State;
UINT32 HwAddressSize;
UINT32 MediaHeaderSize;
UINT32 MaxPacketSize;
UINT32 NvRamSize;
UINT32 NvRamAccessSize;
UINT32 ReceiveFilterMask;
UINT32 ReceiveFilterSetting;
UINT32 MaxMCastFilterCount;
UINT32 MCastFilterCount;
EFI_MAC_ADDRESS MCastFilter[MAX_MCAST_FILTER_CNT];
EFI_MAC_ADDRESS CurrentAddress;
EFI_MAC_ADDRESS BroadcastAddress;
EFI_MAC_ADDRESS PermanentAddress;
UINT8 IfType;
BOOLEAN MacAddressChangeable;
BOOLEAN MultipleTxSupported;
BOOLEAN MediaPresentSupported;
BOOLEAN MediaPresent;
} EFI_SIMPLE_NETWORK_MODE;
//
// Protocol Member Functions
//
/**
Changes the state of a network interface from "stopped" to "started".
@param This Protocol instance pointer.
@retval EFI_SUCCESS The network interface was started.
@retval EFI_ALREADY_STARTED The network interface is already in the started state.
@retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value.
@retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
@retval EFI_UNSUPPORTED This function is not supported by the network interface.
**/
typedef
EFI_STATUS
(EFIAPI *EFI_SIMPLE_NETWORK_START)(
IN EFI_SIMPLE_NETWORK_PROTOCOL *This
);
/**
Changes the state of a network interface from "started" to "stopped".
@param This Protocol instance pointer.
@retval EFI_SUCCESS The network interface was stopped.
@retval EFI_ALREADY_STARTED The network interface is already in the stopped state.
@retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value.
@retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
@retval EFI_UNSUPPORTED This function is not supported by the network interface.
**/
typedef
EFI_STATUS
(EFIAPI *EFI_SIMPLE_NETWORK_STOP)(
IN EFI_SIMPLE_NETWORK_PROTOCOL *This
);
/**
Resets a network adapter and allocates the transmit and receive buffers
required by the network interface; optionally, also requests allocation
of additional transmit and receive buffers.
@param This Protocol instance pointer.
@param ExtraRxBufferSize The size, in bytes, of the extra receive buffer space
that the driver should allocate for the network interface.
Some network interfaces will not be able to use the extra
buffer, and the caller will not know if it is actually
being used.
@param ExtraTxBufferSize The size, in bytes, of the extra transmit buffer space
that the driver should allocate for the network interface.
Some network interfaces will not be able to use the extra
buffer, and the caller will not know if it is actually
being used.
@retval EFI_SUCCESS The network interface was initialized.
@retval EFI_NOT_STARTED The network interface has not been started
@retval EFI_OUT_OF_RESOURCES There was not enough memory for the transmit and
receive buffers. .
@retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value.
@retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
@retval EFI_UNSUPPORTED This function is not supported by the network interface.
**/
typedef
EFI_STATUS
(EFIAPI *EFI_SIMPLE_NETWORK_INITIALIZE)(
IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
IN UINTN ExtraRxBufferSize OPTIONAL,
IN UINTN ExtraTxBufferSize OPTIONAL
);
/**
Resets a network adapter and re-initializes it with the parameters that were
provided in the previous call to Initialize().
@param This Protocol instance pointer.
@param ExtendedVerification Indicates that the driver may perform a more
exhaustive verification operation of the device
during reset.
@retval EFI_SUCCESS The network interface was reset.
@retval EFI_NOT_STARTED The network interface has not been started
@retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value.
@retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
@retval EFI_UNSUPPORTED This function is not supported by the network interface.
**/
typedef
EFI_STATUS
(EFIAPI *EFI_SIMPLE_NETWORK_RESET)(
IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
IN BOOLEAN ExtendedVerification
);
/**
Resets a network adapter and leaves it in a state that is safe for
another driver to initialize.
@param This Protocol instance pointer.
@retval EFI_SUCCESS The network interface was shutdown.
@retval EFI_NOT_STARTED The network interface has not been started
@retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value.
@retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
@retval EFI_UNSUPPORTED This function is not supported by the network interface.
**/
typedef
EFI_STATUS
(EFIAPI *EFI_SIMPLE_NETWORK_SHUTDOWN)(
IN EFI_SIMPLE_NETWORK_PROTOCOL *This
);
/**
Manages the multicast receive filters of a network interface.
@param This Protocol instance pointer.
@param Enable A bit mask of receive filters to enable on the network interface.
@param Disable A bit mask of receive filters to disable on the network interface.
@param ResetMCastFilter Set to TRUE to reset the contents of the multicast receive
filters on the network interface to their default values.
@param McastFilterCnt Number of multicast HW MAC addresses in the new
MCastFilter list. This value must be less than or equal to
the MCastFilterCnt field of EFI_SIMPLE_NETWORK_MODE. This
field is optional if ResetMCastFilter is TRUE.
@param MCastFilter A pointer to a list of new multicast receive filter HW MAC
addresses. This list will replace any existing multicast
HW MAC address list. This field is optional if
ResetMCastFilter is TRUE.
@retval EFI_SUCCESS The multicast receive filter list was updated.
@retval EFI_NOT_STARTED The network interface has not been started
@retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value.
@retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
@retval EFI_UNSUPPORTED This function is not supported by the network interface.
**/
typedef
EFI_STATUS
(EFIAPI *EFI_SIMPLE_NETWORK_RECEIVE_FILTERS)(
IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
IN UINT32 Enable,
IN UINT32 Disable,
IN BOOLEAN ResetMCastFilter,
IN UINTN MCastFilterCnt OPTIONAL,
IN EFI_MAC_ADDRESS *MCastFilter OPTIONAL
);
/**
Modifies or resets the current station address, if supported.
@param This Protocol instance pointer.
@param Reset Flag used to reset the station address to the network interfaces
permanent address.
@param New New station address to be used for the network interface.
@retval EFI_SUCCESS The network interfaces station address was updated.
@retval EFI_NOT_STARTED The network interface has not been started
@retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value.
@retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
@retval EFI_UNSUPPORTED This function is not supported by the network interface.
**/
typedef
EFI_STATUS
(EFIAPI *EFI_SIMPLE_NETWORK_STATION_ADDRESS)(
IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
IN BOOLEAN Reset,
IN EFI_MAC_ADDRESS *New OPTIONAL
);
/**
Resets or collects the statistics on a network interface.
@param This Protocol instance pointer.
@param Reset Set to TRUE to reset the statistics for the network interface.
@param StatisticsSize On input the size, in bytes, of StatisticsTable. On
output the size, in bytes, of the resulting table of
statistics.
@param StatisticsTable A pointer to the EFI_NETWORK_STATISTICS structure that
contains the statistics.
@retval EFI_SUCCESS The statistics were collected from the network interface.
@retval EFI_NOT_STARTED The network interface has not been started.
@retval EFI_BUFFER_TOO_SMALL The Statistics buffer was too small. The current buffer
size needed to hold the statistics is returned in
StatisticsSize.
@retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value.
@retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
@retval EFI_UNSUPPORTED This function is not supported by the network interface.
**/
typedef
EFI_STATUS
(EFIAPI *EFI_SIMPLE_NETWORK_STATISTICS)(
IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
IN BOOLEAN Reset,
IN OUT UINTN *StatisticsSize OPTIONAL,
OUT EFI_NETWORK_STATISTICS *StatisticsTable OPTIONAL
);
/**
Converts a multicast IP address to a multicast HW MAC address.
@param This Protocol instance pointer.
@param IPv6 Set to TRUE if the multicast IP address is IPv6 [RFC 2460]. Set
to FALSE if the multicast IP address is IPv4 [RFC 791].
@param IP The multicast IP address that is to be converted to a multicast
HW MAC address.
@param MAC The multicast HW MAC address that is to be generated from IP.
@retval EFI_SUCCESS The multicast IP address was mapped to the multicast
HW MAC address.
@retval EFI_NOT_STARTED The network interface has not been started.
@retval EFI_BUFFER_TOO_SMALL The Statistics buffer was too small. The current buffer
size needed to hold the statistics is returned in
StatisticsSize.
@retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value.
@retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
@retval EFI_UNSUPPORTED This function is not supported by the network interface.
**/
typedef
EFI_STATUS
(EFIAPI *EFI_SIMPLE_NETWORK_MCAST_IP_TO_MAC)(
IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
IN BOOLEAN IPv6,
IN EFI_IP_ADDRESS *IP,
OUT EFI_MAC_ADDRESS *MAC
);
/**
Performs read and write operations on the NVRAM device attached to a
network interface.
@param This Protocol instance pointer.
@param ReadWrite TRUE for read operations, FALSE for write operations.
@param Offset Byte offset in the NVRAM device at which to start the read or
write operation. This must be a multiple of NvRamAccessSize and
less than NvRamSize.
@param BufferSize The number of bytes to read or write from the NVRAM device.
This must also be a multiple of NvramAccessSize.
@param Buffer A pointer to the data buffer.
@retval EFI_SUCCESS The NVRAM access was performed.
@retval EFI_NOT_STARTED The network interface has not been started.
@retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value.
@retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
@retval EFI_UNSUPPORTED This function is not supported by the network interface.
**/
typedef
EFI_STATUS
(EFIAPI *EFI_SIMPLE_NETWORK_NVDATA)(
IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
IN BOOLEAN ReadWrite,
IN UINTN Offset,
IN UINTN BufferSize,
IN OUT VOID *Buffer
);
/**
Reads the current interrupt status and recycled transmit buffer status from
a network interface.
@param This Protocol instance pointer.
@param InterruptStatus A pointer to the bit mask of the currently active interrupts
If this is NULL, the interrupt status will not be read from
the device. If this is not NULL, the interrupt status will
be read from the device. When the interrupt status is read,
it will also be cleared. Clearing the transmit interrupt
does not empty the recycled transmit buffer array.
@param TxBuf Recycled transmit buffer address. The network interface will
not transmit if its internal recycled transmit buffer array
is full. Reading the transmit buffer does not clear the
transmit interrupt. If this is NULL, then the transmit buffer
status will not be read. If there are no transmit buffers to
recycle and TxBuf is not NULL, * TxBuf will be set to NULL.
@retval EFI_SUCCESS The status of the network interface was retrieved.
@retval EFI_NOT_STARTED The network interface has not been started.
@retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value.
@retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
@retval EFI_UNSUPPORTED This function is not supported by the network interface.
**/
typedef
EFI_STATUS
(EFIAPI *EFI_SIMPLE_NETWORK_GET_STATUS)(
IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
OUT UINT32 *InterruptStatus OPTIONAL,
OUT VOID **TxBuf OPTIONAL
);
/**
Places a packet in the transmit queue of a network interface.
@param This Protocol instance pointer.
@param HeaderSize The size, in bytes, of the media header to be filled in by
the Transmit() function. If HeaderSize is non-zero, then it
must be equal to This->Mode->MediaHeaderSize and the DestAddr
and Protocol parameters must not be NULL.
@param BufferSize The size, in bytes, of the entire packet (media header and
data) to be transmitted through the network interface.
@param Buffer A pointer to the packet (media header followed by data) to be
transmitted. This parameter cannot be NULL. If HeaderSize is zero,
then the media header in Buffer must already be filled in by the
caller. If HeaderSize is non-zero, then the media header will be
filled in by the Transmit() function.
@param SrcAddr The source HW MAC address. If HeaderSize is zero, then this parameter
is ignored. If HeaderSize is non-zero and SrcAddr is NULL, then
This->Mode->CurrentAddress is used for the source HW MAC address.
@param DsetAddr The destination HW MAC address. If HeaderSize is zero, then this
parameter is ignored.
@param Protocol The type of header to build. If HeaderSize is zero, then this
parameter is ignored. See RFC 1700, section "Ether Types", for
examples.
@retval EFI_SUCCESS The packet was placed on the transmit queue.
@retval EFI_NOT_STARTED The network interface has not been started.
@retval EFI_NOT_READY The network interface is too busy to accept this transmit request.
@retval EFI_BUFFER_TOO_SMALL The BufferSize parameter is too small.
@retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value.
@retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
@retval EFI_UNSUPPORTED This function is not supported by the network interface.
**/
typedef
EFI_STATUS
(EFIAPI *EFI_SIMPLE_NETWORK_TRANSMIT)(
IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
IN UINTN HeaderSize,
IN UINTN BufferSize,
IN VOID *Buffer,
IN EFI_MAC_ADDRESS *SrcAddr OPTIONAL,
IN EFI_MAC_ADDRESS *DestAddr OPTIONAL,
IN UINT16 *Protocol OPTIONAL
);
/**
Receives a packet from a network interface.
@param This Protocol instance pointer.
@param HeaderSize The size, in bytes, of the media header received on the network
interface. If this parameter is NULL, then the media header size
will not be returned.
@param BufferSize On entry, the size, in bytes, of Buffer. On exit, the size, in
bytes, of the packet that was received on the network interface.
@param Buffer A pointer to the data buffer to receive both the media header and
the data.
@param SrcAddr The source HW MAC address. If this parameter is NULL, the
HW MAC source address will not be extracted from the media
header.
@param DsetAddr The destination HW MAC address. If this parameter is NULL,
the HW MAC destination address will not be extracted from the
media header.
@param Protocol The media header type. If this parameter is NULL, then the
protocol will not be extracted from the media header. See
RFC 1700 section "Ether Types" for examples.
@retval EFI_SUCCESS The received data was stored in Buffer, and BufferSize has
been updated to the number of bytes received.
@retval EFI_NOT_STARTED The network interface has not been started.
@retval EFI_NOT_READY The network interface is too busy to accept this transmit
request.
@retval EFI_BUFFER_TOO_SMALL The BufferSize parameter is too small.
@retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value.
@retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
@retval EFI_UNSUPPORTED This function is not supported by the network interface.
**/
typedef
EFI_STATUS
(EFIAPI *EFI_SIMPLE_NETWORK_RECEIVE)(
IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
OUT UINTN *HeaderSize OPTIONAL,
IN OUT UINTN *BufferSize,
OUT VOID *Buffer,
OUT EFI_MAC_ADDRESS *SrcAddr OPTIONAL,
OUT EFI_MAC_ADDRESS *DestAddr OPTIONAL,
OUT UINT16 *Protocol OPTIONAL
);
#define EFI_SIMPLE_NETWORK_PROTOCOL_REVISION 0x00010000
//
// Revision defined in EFI1.1
//
#define EFI_SIMPLE_NETWORK_INTERFACE_REVISION EFI_SIMPLE_NETWORK_PROTOCOL_REVISION
/**
@par Protocol Description:
The EFI_SIMPLE_NETWORK_PROTOCOL protocol is used to initialize access
to a network adapter. Once the network adapter initializes,
the EFI_SIMPLE_NETWORK_PROTOCOL protocol provides services that
allow packets to be transmitted and received.
@param Revision
Revision of the EFI_SIMPLE_NETWORK_PROTOCOL. All future revisions must
be backwards compatible. If a future version is not backwards compatible
it is not the same GUID.
@param Start
Prepares the network interface for further command operations.
No other EFI_SIMPLE_NETWORK_PROTOCOL interface functions will operate
until this call is made.
@param Stop
Stops further network interface command processing.
No other EFI_SIMPLE_NETWORK_PROTOCOL interface functions will operate
after this call is made until another Start() call is made.
@param Initialize
Resets the network adapter and allocates the transmit and receive buffers.
@param Reset
Resets the network adapter and reinitializes it with the parameters
provided in the previous call to Initialize().
@param Shutdown
Resets the network adapter and leaves it in a state safe for another driver
to initialize. The memory buffers assigned in the Initialize() call are released.
After this call, only the Initialize() or Stop() calls may be used.
@param ReceiveFilters
Enables and disables the receive filters for the network interface and,
if supported, manages the filtered multicast
HW MAC (Hardware Media Access Control) address list.
@param StationAddress
Modifies or resets the current station address, if supported.
@param Statistics
Collects statistics from the network interface and allows the statistics to be reset.
@param MCastIpToMac
Maps a multicast IP address to a multicast HW MAC address.
@param NvData
Reads and writes the contents of the NVRAM devices attached to the network interface.
@param GetStatus
Reads the current interrupt status and the list of recycled transmit
buffers from the network interface.
@param Transmit
Places a packet in the transmit queue.
@param Receive
Retrieves a packet from the receive queue, along with the status
flags that describe the packet type.
@param WaitForPacket
Event used with WaitForEvent() to wait for a packet to be received.
@param Mode
Pointer to the EFI_SIMPLE_NETWORK_MODE data for the device.
**/
struct _EFI_SIMPLE_NETWORK_PROTOCOL {
UINT64 Revision;
EFI_SIMPLE_NETWORK_START Start;
EFI_SIMPLE_NETWORK_STOP Stop;
EFI_SIMPLE_NETWORK_INITIALIZE Initialize;
EFI_SIMPLE_NETWORK_RESET Reset;
EFI_SIMPLE_NETWORK_SHUTDOWN Shutdown;
EFI_SIMPLE_NETWORK_RECEIVE_FILTERS ReceiveFilters;
EFI_SIMPLE_NETWORK_STATION_ADDRESS StationAddress;
EFI_SIMPLE_NETWORK_STATISTICS Statistics;
EFI_SIMPLE_NETWORK_MCAST_IP_TO_MAC MCastIpToMac;
EFI_SIMPLE_NETWORK_NVDATA NvData;
EFI_SIMPLE_NETWORK_GET_STATUS GetStatus;
EFI_SIMPLE_NETWORK_TRANSMIT Transmit;
EFI_SIMPLE_NETWORK_RECEIVE Receive;
EFI_EVENT WaitForPacket;
EFI_SIMPLE_NETWORK_MODE *Mode;
};
extern EFI_GUID gEfiSimpleNetworkProtocolGuid;
#endif

View File

@ -158,6 +158,7 @@
#define ERRFILE_ifmgmt ( ERRFILE_OTHER | 0x000e0000 )
#define ERRFILE_iscsiboot ( ERRFILE_OTHER | 0x000f0000 )
#define ERRFILE_efi_pci ( ERRFILE_OTHER | 0x00100000 )
#define ERRFILE_efi_snp ( ERRFILE_OTHER | 0x00110000 )
/** @} */

978
src/interface/efi/efi_snp.c Normal file
View File

@ -0,0 +1,978 @@
/*
* Copyright (C) 2008 Michael Brown <mbrown@fensystems.co.uk>.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <assert.h>
#include <byteswap.h>
#include <gpxe/netdevice.h>
#include <gpxe/iobuf.h>
#include <gpxe/in.h>
#include <gpxe/pci.h>
#include <gpxe/efi/efi.h>
#include <gpxe/efi/Protocol/DriverBinding.h>
#include <gpxe/efi/Protocol/PciIo.h>
#include <gpxe/efi/Protocol/SimpleNetwork.h>
/** @file
*
* gPXE EFI SNP interface
*
*/
/** An SNP device */
struct efi_snp_device {
/** The underlying gPXE network device */
struct net_device *netdev;
/** The SNP structure itself */
EFI_SIMPLE_NETWORK_PROTOCOL snp;
/** The SNP "mode" (parameters) */
EFI_SIMPLE_NETWORK_MODE mode;
/** Outstanding TX packet count (via "interrupt status")
*
* Used in order to generate TX completions.
*/
unsigned int tx_count_interrupts;
/** Outstanding TX packet count (via "recycled tx buffers")
*
* Used in order to generate TX completions.
*/
unsigned int tx_count_txbufs;
/** Outstanding RX packet count (via "interrupt status") */
unsigned int rx_count_interrupts;
/** Outstanding RX packet count (via WaitForPacket event) */
unsigned int rx_count_events;
};
/** EFI simple network protocol GUID */
static EFI_GUID efi_simple_network_protocol_guid
= EFI_SIMPLE_NETWORK_PROTOCOL_GUID;
/** EFI driver binding protocol GUID */
static EFI_GUID efi_driver_binding_protocol_guid
= EFI_DRIVER_BINDING_PROTOCOL_GUID;
/** EFI PCI I/O protocol GUID */
static EFI_GUID efi_pci_io_protocol_guid
= EFI_PCI_IO_PROTOCOL_GUID;
/**
* Set EFI SNP mode based on gPXE net device parameters
*
* @v snp SNP interface
*/
static void efi_snp_set_mode ( struct efi_snp_device *snpdev ) {
struct net_device *netdev = snpdev->netdev;
EFI_SIMPLE_NETWORK_MODE *mode = &snpdev->mode;
unsigned int ll_addr_len = netdev->ll_protocol->ll_addr_len;
mode->HwAddressSize = ll_addr_len;
mode->MediaHeaderSize = netdev->ll_protocol->ll_header_len;
mode->MaxPacketSize = netdev->max_pkt_len;
mode->ReceiveFilterMask = ( EFI_SIMPLE_NETWORK_RECEIVE_UNICAST |
EFI_SIMPLE_NETWORK_RECEIVE_MULTICAST |
EFI_SIMPLE_NETWORK_RECEIVE_BROADCAST );
assert ( ll_addr_len <= sizeof ( mode->CurrentAddress ) );
memcpy ( &mode->CurrentAddress, netdev->ll_addr, ll_addr_len );
memcpy ( &mode->BroadcastAddress, netdev->ll_protocol->ll_broadcast,
ll_addr_len );
memcpy ( &mode->PermanentAddress, netdev->ll_addr, ll_addr_len );
mode->IfType = ntohs ( netdev->ll_protocol->ll_proto );
mode->MacAddressChangeable = TRUE;
mode->MediaPresentSupported = TRUE;
mode->MediaPresent = ( netdev_link_ok ( netdev ) ? TRUE : FALSE );
}
/**
* Poll net device and count received packets
*
* @v snpdev SNP device
*/
static void efi_snp_poll ( struct efi_snp_device *snpdev ) {
struct io_buffer *iobuf;
unsigned int before = 0;
unsigned int after = 0;
unsigned int arrived;
/* We have to report packet arrivals, and this is the easiest
* way to fake it.
*/
list_for_each_entry ( iobuf, &snpdev->netdev->rx_queue, list )
before++;
netdev_poll ( snpdev->netdev );
list_for_each_entry ( iobuf, &snpdev->netdev->rx_queue, list )
after++;
arrived = ( after - before );
snpdev->rx_count_interrupts += arrived;
snpdev->rx_count_events += arrived;
}
/**
* Change SNP state from "stopped" to "started"
*
* @v snp SNP interface
* @ret efirc EFI status code
*/
static EFI_STATUS EFIAPI
efi_snp_start ( EFI_SIMPLE_NETWORK_PROTOCOL *snp ) {
struct efi_snp_device *snpdev =
container_of ( snp, struct efi_snp_device, snp );
DBGC2 ( snpdev, "SNPDEV %p START\n", snpdev );
snpdev->mode.State = EfiSimpleNetworkStarted;
return 0;
}
/**
* Change SNP state from "started" to "stopped"
*
* @v snp SNP interface
* @ret efirc EFI status code
*/
static EFI_STATUS EFIAPI
efi_snp_stop ( EFI_SIMPLE_NETWORK_PROTOCOL *snp ) {
struct efi_snp_device *snpdev =
container_of ( snp, struct efi_snp_device, snp );
DBGC2 ( snpdev, "SNPDEV %p STOP\n", snpdev );
snpdev->mode.State = EfiSimpleNetworkStopped;
return 0;
}
/**
* Open the network device
*
* @v snp SNP interface
* @v extra_rx_bufsize Extra RX buffer size, in bytes
* @v extra_tx_bufsize Extra TX buffer size, in bytes
* @ret efirc EFI status code
*/
static EFI_STATUS EFIAPI
efi_snp_initialize ( EFI_SIMPLE_NETWORK_PROTOCOL *snp,
UINTN extra_rx_bufsize, UINTN extra_tx_bufsize ) {
struct efi_snp_device *snpdev =
container_of ( snp, struct efi_snp_device, snp );
int rc;
DBGC2 ( snpdev, "SNPDEV %p INITIALIZE (%ld extra RX, %ld extra TX)\n",
snpdev, extra_rx_bufsize, extra_tx_bufsize );
if ( ( rc = netdev_open ( snpdev->netdev ) ) != 0 ) {
DBGC ( snpdev, "SNPDEV %p could not open %s: %s\n",
snpdev, snpdev->netdev->name, strerror ( rc ) );
return RC_TO_EFIRC ( rc );
}
snpdev->mode.State = EfiSimpleNetworkInitialized;
return 0;
}
/**
* Reset the network device
*
* @v snp SNP interface
* @v ext_verify Extended verification required
* @ret efirc EFI status code
*/
static EFI_STATUS EFIAPI
efi_snp_reset ( EFI_SIMPLE_NETWORK_PROTOCOL *snp, BOOLEAN ext_verify ) {
struct efi_snp_device *snpdev =
container_of ( snp, struct efi_snp_device, snp );
int rc;
DBGC2 ( snpdev, "SNPDEV %p RESET (%s extended verification)\n",
snpdev, ( ext_verify ? "with" : "without" ) );
netdev_close ( snpdev->netdev );
snpdev->mode.State = EfiSimpleNetworkStarted;
if ( ( rc = netdev_open ( snpdev->netdev ) ) != 0 ) {
DBGC ( snpdev, "SNPDEV %p could not reopen %s: %s\n",
snpdev, snpdev->netdev->name, strerror ( rc ) );
return RC_TO_EFIRC ( rc );
}
snpdev->mode.State = EfiSimpleNetworkInitialized;
return 0;
}
/**
* Shut down the network device
*
* @v snp SNP interface
* @ret efirc EFI status code
*/
static EFI_STATUS EFIAPI
efi_snp_shutdown ( EFI_SIMPLE_NETWORK_PROTOCOL *snp ) {
struct efi_snp_device *snpdev =
container_of ( snp, struct efi_snp_device, snp );
DBGC2 ( snpdev, "SNPDEV %p SHUTDOWN\n", snpdev );
netdev_close ( snpdev->netdev );
snpdev->mode.State = EfiSimpleNetworkStarted;
return 0;
}
/**
* Manage receive filters
*
* @v snp SNP interface
* @v enable Receive filters to enable
* @v disable Receive filters to disable
* @v mcast_reset Reset multicast filters
* @v mcast_count Number of multicast filters
* @v mcast Multicast filters
* @ret efirc EFI status code
*/
static EFI_STATUS EFIAPI
efi_snp_receive_filters ( EFI_SIMPLE_NETWORK_PROTOCOL *snp, UINT32 enable,
UINT32 disable, BOOLEAN mcast_reset,
UINTN mcast_count, EFI_MAC_ADDRESS *mcast ) {
struct efi_snp_device *snpdev =
container_of ( snp, struct efi_snp_device, snp );
unsigned int i;
DBGC2 ( snpdev, "SNPDEV %p RECEIVE_FILTERS %08lx&~%08lx%s %ld mcast\n",
snpdev, enable, disable, ( mcast_reset ? " reset" : "" ),
mcast_count );
for ( i = 0 ; i < mcast_count ; i++ ) {
DBGC2_HDA ( snpdev, i, &mcast[i],
snpdev->netdev->ll_protocol->ll_addr_len );
}
/* Lie through our teeth, otherwise MNP refuses to accept us */
return 0;
}
/**
* Set station address
*
* @v snp SNP interface
* @v reset Reset to permanent address
* @v new New station address
* @ret efirc EFI status code
*/
static EFI_STATUS EFIAPI
efi_snp_station_address ( EFI_SIMPLE_NETWORK_PROTOCOL *snp, BOOLEAN reset,
EFI_MAC_ADDRESS *new ) {
struct efi_snp_device *snpdev =
container_of ( snp, struct efi_snp_device, snp );
struct ll_protocol *ll_protocol = snpdev->netdev->ll_protocol;
DBGC2 ( snpdev, "SNPDEV %p STATION_ADDRESS %s\n", snpdev,
( reset ? "reset" : ll_protocol->ntoa ( new ) ) );
/* Set the MAC address */
if ( reset )
new = &snpdev->mode.PermanentAddress;
memcpy ( snpdev->netdev->ll_addr, new, ll_protocol->ll_addr_len );
/* MAC address changes take effect only on netdev_open() */
if ( snpdev->netdev->state & NETDEV_OPEN ) {
DBGC ( snpdev, "SNPDEV %p MAC address changed while net "
"devive open\n", snpdev );
}
return 0;
}
/**
* Get (or reset) statistics
*
* @v snp SNP interface
* @v reset Reset statistics
* @v stats_len Size of statistics table
* @v stats Statistics table
* @ret efirc EFI status code
*/
static EFI_STATUS EFIAPI
efi_snp_statistics ( EFI_SIMPLE_NETWORK_PROTOCOL *snp, BOOLEAN reset,
UINTN *stats_len, EFI_NETWORK_STATISTICS *stats ) {
struct efi_snp_device *snpdev =
container_of ( snp, struct efi_snp_device, snp );
EFI_NETWORK_STATISTICS stats_buf;
DBGC2 ( snpdev, "SNPDEV %p STATISTICS%s", snpdev,
( reset ? " reset" : "" ) );
/* Gather statistics */
memset ( &stats_buf, 0, sizeof ( stats_buf ) );
stats_buf.TxGoodFrames = snpdev->netdev->stats.tx_ok;
stats_buf.TxDroppedFrames = snpdev->netdev->stats.tx_err;
stats_buf.TxTotalFrames = ( snpdev->netdev->stats.tx_ok +
snpdev->netdev->stats.tx_err );
stats_buf.RxGoodFrames = snpdev->netdev->stats.rx_ok;
stats_buf.RxDroppedFrames = snpdev->netdev->stats.rx_err;
stats_buf.RxTotalFrames = ( snpdev->netdev->stats.rx_ok +
snpdev->netdev->stats.rx_err );
if ( *stats_len > sizeof ( stats_buf ) )
*stats_len = sizeof ( stats_buf );
if ( stats )
memcpy ( stats, &stats_buf, *stats_len );
/* Reset statistics if requested to do so */
if ( reset ) {
memset ( &snpdev->netdev->stats, 0,
sizeof ( snpdev->netdev->stats ) );
}
return 0;
}
/**
* Convert multicast IP address to MAC address
*
* @v snp SNP interface
* @v ipv6 Address is IPv6
* @v ip IP address
* @v mac MAC address
* @ret efirc EFI status code
*/
static EFI_STATUS EFIAPI
efi_snp_mcast_ip_to_mac ( EFI_SIMPLE_NETWORK_PROTOCOL *snp, BOOLEAN ipv6,
EFI_IP_ADDRESS *ip, EFI_MAC_ADDRESS *mac ) {
struct efi_snp_device *snpdev =
container_of ( snp, struct efi_snp_device, snp );
struct ll_protocol *ll_protocol = snpdev->netdev->ll_protocol;
const char *ip_str;
int rc;
ip_str = ( ipv6 ? "(IPv6)" /* FIXME when we have inet6_ntoa() */ :
inet_ntoa ( *( ( struct in_addr * ) ip ) ) );
DBGC2 ( snpdev, "SNPDEV %p MCAST_IP_TO_MAC %s\n", snpdev, ip_str );
/* Try to hash the address */
if ( ( rc = ll_protocol->mc_hash ( ( ipv6 ? AF_INET6 : AF_INET ),
ip, mac ) ) != 0 ) {
DBGC ( snpdev, "SNPDEV %p could not hash %s: %s\n",
snpdev, ip_str, strerror ( rc ) );
return RC_TO_EFIRC ( rc );
}
return 0;
}
/**
* Read or write non-volatile storage
*
* @v snp SNP interface
* @v read Operation is a read
* @v offset Starting offset within NVRAM
* @v len Length of data buffer
* @v data Data buffer
* @ret efirc EFI status code
*/
static EFI_STATUS EFIAPI
efi_snp_nvdata ( EFI_SIMPLE_NETWORK_PROTOCOL *snp, BOOLEAN read,
UINTN offset, UINTN len, VOID *data ) {
struct efi_snp_device *snpdev =
container_of ( snp, struct efi_snp_device, snp );
DBGC2 ( snpdev, "SNPDEV %p NVDATA %s %lx+%lx\n", snpdev,
( read ? "read" : "write" ), offset, len );
if ( ! read )
DBGC2_HDA ( snpdev, offset, data, len );
return EFI_UNSUPPORTED;
}
/**
* Read interrupt status and TX recycled buffer status
*
* @v snp SNP interface
* @v interrupts Interrupt status, or NULL
* @v txbufs Recycled transmit buffer address, or NULL
* @ret efirc EFI status code
*/
static EFI_STATUS EFIAPI
efi_snp_get_status ( EFI_SIMPLE_NETWORK_PROTOCOL *snp,
UINT32 *interrupts, VOID **txbufs ) {
struct efi_snp_device *snpdev =
container_of ( snp, struct efi_snp_device, snp );
DBGC2 ( snpdev, "SNPDEV %p GET_STATUS", snpdev );
/* Poll the network device */
efi_snp_poll ( snpdev );
/* Interrupt status. In practice, this seems to be used only
* to detect TX completions.
*/
if ( interrupts ) {
*interrupts = 0;
/* Report TX completions once queue is empty; this
* avoids having to add hooks in the net device layer.
*/
if ( snpdev->tx_count_interrupts &&
list_empty ( &snpdev->netdev->tx_queue ) ) {
*interrupts |= EFI_SIMPLE_NETWORK_TRANSMIT_INTERRUPT;
snpdev->tx_count_interrupts--;
}
/* Report RX */
if ( snpdev->rx_count_interrupts ) {
*interrupts |= EFI_SIMPLE_NETWORK_RECEIVE_INTERRUPT;
snpdev->rx_count_interrupts--;
}
DBGC2 ( snpdev, " INTS:%02lx", *interrupts );
}
/* TX completions. It would be possible to design a more
* idiotic scheme for this, but it would be a challenge.
* According to the UEFI header file, txbufs will be filled in
* with a list of "recycled transmit buffers" (i.e. completed
* TX buffers). Observant readers may care to note that
* *txbufs is a void pointer. Precisely how a list of
* completed transmit buffers is meant to be represented as an
* array of voids is left as an exercise for the reader.
*
* The only users of this interface (MnpDxe/MnpIo.c and
* PxeBcDxe/Bc.c within the EFI dev kit) both just poll until
* seeing a non-NULL result return in txbufs. This is valid
* provided that they do not ever attempt to transmit more
* than one packet concurrently (and that TX never times out).
*/
if ( txbufs ) {
if ( snpdev->tx_count_txbufs &&
list_empty ( &snpdev->netdev->tx_queue ) ) {
*txbufs = "Which idiot designed this API?";
snpdev->tx_count_txbufs--;
} else {
*txbufs = NULL;
}
DBGC2 ( snpdev, " TX:%s", ( *txbufs ? "some" : "none" ) );
}
DBGC2 ( snpdev, "\n" );
return 0;
}
/**
* Start packet transmission
*
* @v snp SNP interface
* @v ll_header_len Link-layer header length, if to be filled in
* @v len Length of data buffer
* @v data Data buffer
* @v ll_src Link-layer source address, if specified
* @v ll_dest Link-layer destination address, if specified
* @v net_proto Network-layer protocol (in host order)
* @ret efirc EFI status code
*/
static EFI_STATUS EFIAPI
efi_snp_transmit ( EFI_SIMPLE_NETWORK_PROTOCOL *snp,
UINTN ll_header_len, UINTN len, VOID *data,
EFI_MAC_ADDRESS *ll_src, EFI_MAC_ADDRESS *ll_dest,
UINT16 *net_proto ) {
struct efi_snp_device *snpdev =
container_of ( snp, struct efi_snp_device, snp );
struct ll_protocol *ll_protocol = snpdev->netdev->ll_protocol;
struct io_buffer *iobuf;
int rc;
EFI_STATUS efirc;
DBGC2 ( snpdev, "SNPDEV %p TRANSMIT %p+%lx", snpdev, data, len );
if ( ll_header_len ) {
if ( ll_src ) {
DBGC2 ( snpdev, " src %s",
ll_protocol->ntoa ( ll_src ) );
}
if ( ll_dest ) {
DBGC2 ( snpdev, " dest %s",
ll_protocol->ntoa ( ll_dest ) );
}
if ( net_proto ) {
DBGC2 ( snpdev, " proto %04x", *net_proto );
}
}
DBGC2 ( snpdev, "\n" );
/* Sanity checks */
if ( ll_header_len ) {
if ( ll_header_len != ll_protocol->ll_header_len ) {
DBGC ( snpdev, "SNPDEV %p TX invalid header length "
"%ld\n", snpdev, ll_header_len );
efirc = EFI_INVALID_PARAMETER;
goto err_sanity;
}
if ( len < ll_header_len ) {
DBGC ( snpdev, "SNPDEV %p invalid packet length %ld\n",
snpdev, len );
efirc = EFI_BUFFER_TOO_SMALL;
goto err_sanity;
}
if ( ! ll_dest ) {
DBGC ( snpdev, "SNPDEV %p TX missing destination "
"address\n", snpdev );
efirc = EFI_INVALID_PARAMETER;
goto err_sanity;
}
if ( ! net_proto ) {
DBGC ( snpdev, "SNPDEV %p TX missing network "
"protocol\n", snpdev );
efirc = EFI_INVALID_PARAMETER;
goto err_sanity;
}
if ( ! ll_src )
ll_src = &snpdev->mode.CurrentAddress;
}
/* Allocate buffer */
iobuf = alloc_iob ( len );
if ( ! iobuf ) {
DBGC ( snpdev, "SNPDEV %p TX could not allocate %ld-byte "
"buffer\n", snpdev, len );
efirc = EFI_DEVICE_ERROR;
goto err_alloc_iob;
}
memcpy ( iob_put ( iobuf, len ), data, len );
/* Create link-layer header, if specified */
if ( ll_header_len ) {
iob_pull ( iobuf, ll_header_len );
if ( ( rc = ll_protocol->push ( iobuf, ll_dest, ll_src,
htons ( *net_proto ) )) != 0 ){
DBGC ( snpdev, "SNPDEV %p TX could not construct "
"header: %s\n", snpdev, strerror ( rc ) );
efirc = RC_TO_EFIRC ( rc );
goto err_ll_push;
}
}
/* Transmit packet */
if ( ( rc = netdev_tx ( snpdev->netdev, iobuf ) ) != 0 ) {
DBGC ( snpdev, "SNPDEV %p TX could not transmit: %s\n",
snpdev, strerror ( rc ) );
iobuf = NULL;
efirc = RC_TO_EFIRC ( rc );
goto err_tx;
}
/* Record transmission as outstanding */
snpdev->tx_count_interrupts++;
snpdev->tx_count_txbufs++;
return 0;
err_tx:
err_ll_push:
free_iob ( iobuf );
err_alloc_iob:
err_sanity:
return efirc;
}
/**
* Receive packet
*
* @v snp SNP interface
* @v ll_header_len Link-layer header length, if to be filled in
* @v len Length of data buffer
* @v data Data buffer
* @v ll_src Link-layer source address, if specified
* @v ll_dest Link-layer destination address, if specified
* @v net_proto Network-layer protocol (in host order)
* @ret efirc EFI status code
*/
static EFI_STATUS EFIAPI
efi_snp_receive ( EFI_SIMPLE_NETWORK_PROTOCOL *snp,
UINTN *ll_header_len, UINTN *len, VOID *data,
EFI_MAC_ADDRESS *ll_src, EFI_MAC_ADDRESS *ll_dest,
UINT16 *net_proto ) {
struct efi_snp_device *snpdev =
container_of ( snp, struct efi_snp_device, snp );
struct ll_protocol *ll_protocol = snpdev->netdev->ll_protocol;
struct io_buffer *iobuf;
const void *iob_ll_dest;
const void *iob_ll_src;
uint16_t iob_net_proto;
int rc;
EFI_STATUS efirc;
DBGC2 ( snpdev, "SNPDEV %p RECEIVE %p(+%lx)", snpdev, data, *len );
/* Poll the network device */
efi_snp_poll ( snpdev );
/* Dequeue a packet, if one is available */
iobuf = netdev_rx_dequeue ( snpdev->netdev );
if ( ! iobuf ) {
DBGC2 ( snpdev, "\n" );
efirc = EFI_NOT_READY;
goto out_no_packet;
}
DBGC2 ( snpdev, "+%zx\n", iob_len ( iobuf ) );
/* Return packet to caller */
memcpy ( data, iobuf->data, iob_len ( iobuf ) );
*len = iob_len ( iobuf );
/* Attempt to decode link-layer header */
if ( ( rc = ll_protocol->pull ( iobuf, &iob_ll_dest, &iob_ll_src,
&iob_net_proto ) ) != 0 ) {
DBGC ( snpdev, "SNPDEV %p could not parse header: %s\n",
snpdev, strerror ( rc ) );
efirc = RC_TO_EFIRC ( rc );
goto out_bad_ll_header;
}
/* Return link-layer header parameters to caller, if required */
if ( ll_header_len )
*ll_header_len = ll_protocol->ll_header_len;
if ( ll_src )
memcpy ( ll_src, iob_ll_src, ll_protocol->ll_addr_len );
if ( ll_dest )
memcpy ( ll_dest, iob_ll_dest, ll_protocol->ll_addr_len );
if ( net_proto )
*net_proto = ntohs ( iob_net_proto );
efirc = 0;
out_bad_ll_header:
free_iob ( iobuf );
out_no_packet:
return efirc;
}
/**
* Poll event
*
* @v event Event
* @v context Event context
*/
static VOID EFIAPI efi_snp_wait_for_packet ( EFI_EVENT event,
VOID *context ) {
EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
struct efi_snp_device *snpdev = context;
DBGCP ( snpdev, "SNPDEV %p WAIT_FOR_PACKET\n", snpdev );
/* Do nothing unless the net device is open */
if ( ! ( snpdev->netdev->state & NETDEV_OPEN ) )
return;
/* Poll the network device */
efi_snp_poll ( snpdev );
/* Fire event if packets have been received */
if ( snpdev->rx_count_events != 0 ) {
DBGC2 ( snpdev, "SNPDEV %p firing WaitForPacket event\n",
snpdev );
bs->SignalEvent ( event );
snpdev->rx_count_events--;
}
}
/** SNP interface */
static EFI_SIMPLE_NETWORK_PROTOCOL efi_snp_device_snp = {
.Revision = EFI_SIMPLE_NETWORK_PROTOCOL_REVISION,
.Start = efi_snp_start,
.Stop = efi_snp_stop,
.Initialize = efi_snp_initialize,
.Reset = efi_snp_reset,
.Shutdown = efi_snp_shutdown,
.ReceiveFilters = efi_snp_receive_filters,
.StationAddress = efi_snp_station_address,
.Statistics = efi_snp_statistics,
.MCastIpToMac = efi_snp_mcast_ip_to_mac,
.NvData = efi_snp_nvdata,
.GetStatus = efi_snp_get_status,
.Transmit = efi_snp_transmit,
.Receive = efi_snp_receive,
};
/**
* Locate net device corresponding to EFI device
*
* @v driver EFI driver
* @v device EFI device
* @ret netdev Net device, or NULL if not found
*/
static struct net_device *
efi_snp_netdev ( EFI_DRIVER_BINDING_PROTOCOL *driver, EFI_HANDLE device ) {
EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
union {
EFI_PCI_IO_PROTOCOL *pci;
void *interface;
} u;
UINTN pci_segment, pci_bus, pci_dev, pci_fn;
unsigned int pci_busdevfn;
struct net_device *netdev = NULL;
EFI_STATUS efirc;
/* See if device is a PCI device */
if ( ( efirc = bs->OpenProtocol ( device,
&efi_pci_io_protocol_guid,
&u.interface,
driver->DriverBindingHandle,
device,
EFI_OPEN_PROTOCOL_BY_DRIVER )) !=0 ){
DBGCP ( driver, "SNPDRV %p device %p is not a PCI device\n",
driver, device );
goto out_no_pci_io;
}
/* Get PCI bus:dev.fn address */
if ( ( efirc = u.pci->GetLocation ( u.pci, &pci_segment, &pci_bus,
&pci_dev, &pci_fn ) ) != 0 ) {
DBGC ( driver, "SNPDRV %p device %p could not get PCI "
"location: %lx\n", driver, device, efirc );
goto out_no_pci_location;
}
DBGCP ( driver, "SNPDRV %p device %p is PCI %04lx:%02lx:%02lx.%lx\n",
driver, device, pci_segment, pci_bus, pci_dev, pci_fn );
/* Look up corresponding network device */
pci_busdevfn = PCI_BUSDEVFN ( pci_bus, PCI_DEVFN ( pci_dev, pci_fn ) );
if ( ( netdev = find_netdev_by_location ( BUS_TYPE_PCI,
pci_busdevfn ) ) == NULL ) {
DBGCP ( driver, "SNPDRV %p device %p is not a gPXE network "
"device\n", driver, device );
goto out_no_netdev;
}
DBGC ( driver, "SNPDRV %p device %p is %s\n",
driver, device, netdev->name );
out_no_netdev:
out_no_pci_location:
bs->CloseProtocol ( device, &efi_pci_io_protocol_guid,
driver->DriverBindingHandle, device );
out_no_pci_io:
return netdev;
}
/**
* Locate SNP corresponding to EFI device
*
* @v driver EFI driver
* @v device EFI device
* @ret snp EFI SNP, or NULL if not found
*/
static struct efi_snp_device *
efi_snp_snpdev ( EFI_DRIVER_BINDING_PROTOCOL *driver, EFI_HANDLE device ) {
EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
union {
EFI_SIMPLE_NETWORK_PROTOCOL *snp;
void *interface;
} u;
struct efi_snp_device *snpdev;
EFI_STATUS efirc;
if ( ( efirc = bs->OpenProtocol ( device,
&efi_simple_network_protocol_guid,
&u.interface,
driver->DriverBindingHandle,
device,
EFI_OPEN_PROTOCOL_GET_PROTOCOL))!=0){
DBGC ( driver, "SNPDRV %p device %p could not locate SNP: "
"%lx\n", driver, device, efirc );
return NULL;
}
snpdev = container_of ( u.snp, struct efi_snp_device, snp );
DBGCP ( driver, "SNPDRV %p device %p is SNPDEV %p\n",
driver, device, snpdev );
return snpdev;
}
/**
* Check to see if driver supports a device
*
* @v driver EFI driver
* @v device EFI device
* @v child Path to child device, if any
* @ret efirc EFI status code
*/
static EFI_STATUS EFIAPI
efi_snp_driver_supported ( EFI_DRIVER_BINDING_PROTOCOL *driver,
EFI_HANDLE device,
EFI_DEVICE_PATH_PROTOCOL *child ) {
struct net_device *netdev;
DBGCP ( driver, "SNPDRV %p DRIVER_SUPPORTED %p (%p)\n",
driver, device, child );
netdev = efi_snp_netdev ( driver, device );
return ( netdev ? 0 : EFI_UNSUPPORTED );
}
/**
* Attach driver to device
*
* @v driver EFI driver
* @v device EFI device
* @v child Path to child device, if any
* @ret efirc EFI status code
*/
static EFI_STATUS EFIAPI
efi_snp_driver_start ( EFI_DRIVER_BINDING_PROTOCOL *driver,
EFI_HANDLE device,
EFI_DEVICE_PATH_PROTOCOL *child ) {
EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
struct efi_snp_device *snpdev;
struct net_device *netdev;
EFI_STATUS efirc;
DBGCP ( driver, "SNPDRV %p DRIVER_START %p (%p)\n",
driver, device, child );
/* Allocate the SNP device */
snpdev = zalloc ( sizeof ( *snpdev ) );
if ( ! snpdev ) {
efirc = EFI_OUT_OF_RESOURCES;
goto err_alloc_snp;
}
/* Identify the net device */
netdev = efi_snp_netdev ( driver, device );
if ( ! netdev ) {
DBGC ( snpdev, "SNPDEV %p cannot find netdev for device %p\n",
snpdev, device );
efirc = EFI_UNSUPPORTED;
goto err_no_netdev;
}
snpdev->netdev = netdev_get ( netdev );
/* Sanity check */
if ( netdev->ll_protocol->ll_addr_len > sizeof ( EFI_MAC_ADDRESS ) ) {
DBGC ( snpdev, "SNPDEV %p cannot support link-layer address "
"length %zd for %s\n", snpdev,
netdev->ll_protocol->ll_addr_len, netdev->name );
efirc = EFI_INVALID_PARAMETER;
goto err_ll_addr_len;
}
/* Populate the SNP structure */
memcpy ( &snpdev->snp, &efi_snp_device_snp, sizeof ( snpdev->snp ) );
snpdev->snp.Mode = &snpdev->mode;
if ( ( efirc = bs->CreateEvent ( EVT_NOTIFY_WAIT, TPL_NOTIFY,
efi_snp_wait_for_packet, snpdev,
&snpdev->snp.WaitForPacket ) ) != 0 ){
DBGC ( snpdev, "SNPDEV %p could not create event: %lx\n",
snpdev, efirc );
goto err_create_event;
}
/* Populate the SNP mode structure */
snpdev->mode.State = EfiSimpleNetworkStopped;
efi_snp_set_mode ( snpdev );
/* Install the SNP */
if ( ( efirc = bs->InstallProtocolInterface ( &device,
&efi_simple_network_protocol_guid,
EFI_NATIVE_INTERFACE, &snpdev->snp ) ) != 0 ) {
DBGC ( snpdev, "SNPDEV %p could not install protocol: %lx\n",
snpdev, efirc );
goto err_install_protocol_interface;
}
DBGC ( snpdev, "SNPDEV %p installed for %s on device %p\n",
snpdev, netdev->name, device );
return 0;
bs->UninstallProtocolInterface ( device,
&efi_simple_network_protocol_guid,
&snpdev->snp );
err_install_protocol_interface:
bs->CloseEvent ( snpdev->snp.WaitForPacket );
err_create_event:
err_ll_addr_len:
netdev_put ( netdev );
err_no_netdev:
free ( snpdev );
err_alloc_snp:
return efirc;
}
/**
* Detach driver from device
*
* @v driver EFI driver
* @v device EFI device
* @v num_children Number of child devices
* @v children List of child devices
* @ret efirc EFI status code
*/
static EFI_STATUS EFIAPI
efi_snp_driver_stop ( EFI_DRIVER_BINDING_PROTOCOL *driver,
EFI_HANDLE device,
UINTN num_children,
EFI_HANDLE *children ) {
EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
struct efi_snp_device *snpdev;
DBGCP ( driver, "SNPDRV %p DRIVER_STOP %p (%ld %p)\n",
driver, device, num_children, children );
/* Locate SNP device */
snpdev = efi_snp_snpdev ( driver, device );
if ( ! snpdev ) {
DBGC ( driver, "SNPDRV %p device %p could not find SNPDEV\n",
driver, device );
return EFI_DEVICE_ERROR;
}
/* Uninstall the SNP */
bs->UninstallProtocolInterface ( device,
&efi_simple_network_protocol_guid,
&snpdev->snp );
bs->CloseEvent ( snpdev->snp.WaitForPacket );
netdev_put ( snpdev->netdev );
free ( snpdev );
return 0;
}
/** EFI SNP driver binding */
static EFI_DRIVER_BINDING_PROTOCOL efi_snp_binding = {
efi_snp_driver_supported,
efi_snp_driver_start,
efi_snp_driver_stop,
0x10,
NULL,
NULL
};
/**
* Install EFI SNP driver
*
* @ret rc Return status code
*/
int efi_snp_install ( void ) {
EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
EFI_DRIVER_BINDING_PROTOCOL *driver = &efi_snp_binding;
EFI_STATUS efirc;
driver->ImageHandle = efi_image_handle;
if ( ( efirc = bs->InstallProtocolInterface (
&driver->DriverBindingHandle,
&efi_driver_binding_protocol_guid,
EFI_NATIVE_INTERFACE,
driver ) ) != 0 ) {
DBGC ( driver, "SNPDRV %p could not install driver binding: "
"%lx\n", driver, efirc );
return EFIRC_TO_RC ( efirc );
}
DBGC ( driver, "SNPDRV %p driver binding installed as %p\n",
driver, driver->DriverBindingHandle );
return 0;
}