Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add UEFI Adapter Information Protocol Support #73

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions Silicon/NVIDIA/Drivers/EqosDeviceDxe/DwEqosSnpDxe.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <Protocol/ComponentName2.h>
#include <Protocol/DevicePath.h>
#include <Protocol/NonDiscoverableDevice.h>
#include <Protocol/AdapterInformation.h>

#include <Library/UefiLib.h>

Expand All @@ -39,6 +40,7 @@ typedef struct {
// EFI SNP protocol instances
EFI_SIMPLE_NETWORK_PROTOCOL Snp;
EFI_SIMPLE_NETWORK_MODE SnpMode;
EFI_ADAPTER_INFORMATION_PROTOCOL Aip;

EMAC_DRIVER MacDriver;
PHY_DRIVER PhyDriver;
Expand Down Expand Up @@ -67,6 +69,7 @@ extern EFI_COMPONENT_NAME2_PROTOCOL gSnpComponentName2;

#define SNP_DRIVER_SIGNATURE SIGNATURE_32('A', 'S', 'N', 'P')
#define INSTANCE_FROM_SNP_THIS(a) CR(a, SIMPLE_NETWORK_DRIVER, Snp, SNP_DRIVER_SIGNATURE)
#define INSTANCE_FROM_AIP_THIS(a) CR(a, SIMPLE_NETWORK_DRIVER, Aip, SNP_DRIVER_SIGNATURE)

#define ETHERNET_MAC_ADDRESS_INDEX 0
#define ETHERNET_MAC_BROADCAST_INDEX 1
Expand Down Expand Up @@ -192,6 +195,34 @@ SnpReceive (
OUT UINT16 *Protocol OPTIONAL
);

// Adapter Information Protocol Functions
EFI_STATUS
EFIAPI
EqosAipGetInformation (
IN EFI_ADAPTER_INFORMATION_PROTOCOL *This,
IN EFI_GUID *InformationType,
OUT VOID **InformationBlock,
OUT UINTN *InformationBlockSize
);

EFI_STATUS
EFIAPI
EqosAipSetInformation (
IN EFI_ADAPTER_INFORMATION_PROTOCOL *This,
IN EFI_GUID *InformationType,
IN VOID *InformationBlock,
IN UINTN InformationBlockSize
);

EFI_STATUS
EFIAPI
EqosAipGetSupportedTypes (
IN EFI_ADAPTER_INFORMATION_PROTOCOL *This,
OUT EFI_GUID **InfoTypesBuffer,
OUT UINTN *InfoTypesBufferCount
);


// Internal helper functions

/**
Expand Down
106 changes: 106 additions & 0 deletions Silicon/NVIDIA/Drivers/EqosDeviceDxe/EqosAdapterInfo.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/* @file

Copyright (c) 2020 Arm, Limited. All rights reserved.
Copyright (c) 2023 Connect Tech Inc. All rights reserved.

SPDX-License-Identifier: BSD-2-Clause-Patent

**/

#include <Uefi.h>
#include <Library/BaseMemoryLib.h>
#include <Library/DebugLib.h>
#include <Library/MemoryAllocationLib.h>

#include "DwEqosSnpDxe.h"


EFI_STATUS
EFIAPI
EqosAipGetInformation (
IN EFI_ADAPTER_INFORMATION_PROTOCOL *This,
IN EFI_GUID *InformationType,
OUT VOID **InformationBlock,
OUT UINTN *InformationBlockSize
)
{
EFI_ADAPTER_INFO_MEDIA_STATE *AdapterInfo;
SIMPLE_NETWORK_DRIVER *Snp;

if (This == NULL || InformationBlock == NULL ||
InformationBlockSize == NULL) {
return EFI_INVALID_PARAMETER;
}

if (!CompareGuid (InformationType, &gEfiAdapterInfoMediaStateGuid)) {
return EFI_UNSUPPORTED;
}

AdapterInfo = AllocateZeroPool (sizeof (EFI_ADAPTER_INFO_MEDIA_STATE));
if (AdapterInfo == NULL) {
return EFI_OUT_OF_RESOURCES;
}

*InformationBlock = AdapterInfo;
*InformationBlockSize = sizeof (EFI_ADAPTER_INFO_MEDIA_STATE);

Snp = INSTANCE_FROM_AIP_THIS (This);

if (Snp->SnpMode.MediaPresent) {
AdapterInfo->MediaState = EFI_SUCCESS;
} else {
AdapterInfo->MediaState = EFI_NOT_READY;
}

return EFI_SUCCESS;
}

EFI_STATUS
EFIAPI
EqosAipSetInformation (
IN EFI_ADAPTER_INFORMATION_PROTOCOL *This,
IN EFI_GUID *InformationType,
IN VOID *InformationBlock,
IN UINTN InformationBlockSize
)
{
if (This == NULL || InformationBlock == NULL) {
return EFI_INVALID_PARAMETER;
}

if (CompareGuid (InformationType, &gEfiAdapterInfoMediaStateGuid)) {
return EFI_WRITE_PROTECTED;
}

return EFI_UNSUPPORTED;
}

EFI_STATUS
EFIAPI
EqosAipGetSupportedTypes (
IN EFI_ADAPTER_INFORMATION_PROTOCOL *This,
OUT EFI_GUID **InfoTypesBuffer,
OUT UINTN *InfoTypesBufferCount
)
{
EFI_GUID *Guid;

if (This == NULL || InfoTypesBuffer == NULL ||
InfoTypesBufferCount == NULL) {
return EFI_INVALID_PARAMETER;
}

Guid = AllocatePool (sizeof *Guid);
if (Guid == NULL) {
return EFI_OUT_OF_RESOURCES;
}

CopyGuid (Guid, &gEfiAdapterInfoMediaStateGuid);

*InfoTypesBuffer = Guid;
*InfoTypesBufferCount = 1;

return EFI_SUCCESS;
}


9 changes: 9 additions & 0 deletions Silicon/NVIDIA/Drivers/EqosDeviceDxe/EqosDeviceDxe.c
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,11 @@ DeviceDiscoveryNotify (
return EFI_UNSUPPORTED;
}

// Assign Adapter Information Protocol Pointers
Snp->Aip.GetInformation = EqosAipGetInformation;
Snp->Aip.SetInformation = EqosAipSetInformation;
Snp->Aip.GetSupportedTypes = EqosAipGetSupportedTypes;

// Assign fields and func pointers
Snp->Snp.Revision = EFI_SIMPLE_NETWORK_PROTOCOL_REVISION;
Snp->Snp.WaitForPacket = NULL;
Expand Down Expand Up @@ -594,6 +599,8 @@ DeviceDiscoveryNotify (
&ControllerHandle,
&gEfiSimpleNetworkProtocolGuid,
&(Snp->Snp),
&gEfiAdapterInformationProtocolGuid,
&(Snp->Aip),
NULL
);

Expand Down Expand Up @@ -629,6 +636,8 @@ DeviceDiscoveryNotify (
ControllerHandle,
&gEfiSimpleNetworkProtocolGuid,
&Snp->Snp,
&gEfiAdapterInformationProtocolGuid,
&(Snp->Aip),
NULL
);
if (EFI_ERROR (Status)) {
Expand Down
3 changes: 3 additions & 0 deletions Silicon/NVIDIA/Drivers/EqosDeviceDxe/EqosDeviceDxe.inf
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
PhyMicrel.c
PhyMgbe.c
DtAcpiMacUpdate.c
EqosAdapterInfo.c

nvethernetrm/osd.c
nvethernetrm/osi/core/debug.c
Expand Down Expand Up @@ -94,6 +95,7 @@
gNVIDIACvmEepromProtocolGuid
gEfiAcpiTableProtocolGuid # PROTOCOL ALWAYS_CONSUMED
gEfiAcpiSdtProtocolGuid # PROTOCOL ALWAYS_CONSUMED
gEfiAdapterInformationProtocolGuid

[Guids]
gDwEqosNetNonDiscoverableDeviceGuid
Expand All @@ -103,6 +105,7 @@
gFdtTableGuid
gEfiAcpiTableGuid
gEfiEventExitBootServicesGuid
gEfiAdapterInfoMediaStateGuid

[Depex]
gEmbeddedGpioProtocolGuid
Expand Down