Files
edk2-platforms/Platform/RaspberryPi/Library/PlatformPcdLib/PlatformPcdLib.c
Pete Batard 885a686bb2 Platform/RPi: Add PlatformPcdLib to set the Genet MAC address
The Genet driver stub used by the Raspberry Pi 4 platform is
designed to set the MAC address according to a PCD.

To be able to set that PCD at runtime, by using the Raspberry
Pi firmware interface, that has a dedicated call to retrieve
the MAC address, and satisfy driver dependencies in a generic
manner, we create a new PlatformPcdLib that can be referenced
by the Genet driver, to set the MAC PCD before use there.

While it is currently only tailored around MAC PCD population
for Genet, we do expect this PCD library to be extended in the
future, to provide additional PCD facilities for other drivers.

Signed-off-by: Pete Batard <pete@akeo.ie>
Reviewed-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
2020-02-08 08:48:29 +00:00

46 lines
1.2 KiB
C

/** @file
*
* Copyright (c) 2020, Pete Batard <pete@akeo.ie>
*
* SPDX-License-Identifier: BSD-2-Clause-Patent
*
**/
#include <Library/DebugLib.h>
#include <Library/PcdLib.h>
#include <Library/PrintLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/UefiLib.h>
#include <Library/UefiRuntimeServicesTableLib.h>
#include <Protocol/RpiFirmware.h>
EFI_STATUS
EFIAPI
PlatformPcdLibConstructor (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
EFI_STATUS Status;
UINT64 MacAddr;
RASPBERRY_PI_FIRMWARE_PROTOCOL *mFwProtocol;
if (PcdGet64 (PcdBcmGenetMacAddress) == 0) {
Status = gBS->LocateProtocol (&gRaspberryPiFirmwareProtocolGuid, NULL,
(VOID**)&mFwProtocol);
ASSERT_EFI_ERROR(Status);
//
// Get the MAC address from the firmware
//
Status = mFwProtocol->GetMacAddress ((UINT8*) &MacAddr);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_WARN, "%a: failed to retrieve MAC address\n", __FUNCTION__));
} else {
PcdSet64S (PcdBcmGenetMacAddress, MacAddr);
}
}
return EFI_SUCCESS;
}