From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f67.google.com (mail-wm1-f67.google.com [209.85.128.67]) by mx.groups.io with SMTP id smtpd.web11.428.1580490369052566901 for ; Fri, 31 Jan 2020 09:06:09 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@linaro.org header.s=google header.b=LCaTSLiN; spf=pass (domain: linaro.org, ip: 209.85.128.67, mailfrom: ard.biesheuvel@linaro.org) Received: by mail-wm1-f67.google.com with SMTP id s144so9243998wme.1 for ; Fri, 31 Jan 2020 09:06:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=BQx8tmHJqbNlEOInYjmX+d+J6J8xwYUOyfkYaNB5RS0=; b=LCaTSLiNJ0lT76zqCAL+Y348aDjkBvMuAEh/N4w4rPNSIQSuqQkFs1sKqhpZ9efxim H7fmEG+Jazt0eUdLpI45HoCVaQ43TMjSRJuzlA6IuJI5qI19aAdWTDKJ02xhkkGGC2OY ak7IaQsQZh5OqNMgr38BC69BUCrQKFUXNyjfnagUvQjessNkQ6PSzq7RYhwMMJ8hnbNo jOv5TMyw5UAa7R5d/Uv4uE91BWgOnytpyJAOGN4qZOiUG8aHrXQwrqof4M7LewBvlHSo sc5Fo4UEXlQaAiY6C9QTeCqLp+vybx/Vh520QNjnDpLEUqJjLRoJNIb/2QsJg+aSFv3o Briw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=BQx8tmHJqbNlEOInYjmX+d+J6J8xwYUOyfkYaNB5RS0=; b=MbSh3Eavn4TpN789Qp3vqUpIocVcfzDQfVDTrybspV3iMtWNPNO3LVkY8f85GxeMus x6aYWMEwaIMdwxmti1xW0UW1AppGaByUCXYuPcmX3sqDjoFz6pZf0q3/x4y1I+ijy3zy VZ0cqzdL+xFst2SZkXIabo2LwOK2ur0c0YO4CzdPvvEDfHCQbIjnF11JH3YSBCaFPuuv 31Mpdct9dvVh6IXMlA/b+aT2HX23U+bT+kpYfRJhxfzvoarzAzpG3cTmCtH7Jv5VfxGC Wj7GjbakBzo8vgjw/igdDVDHQuJahoRMi8q4k9jJrPGEyPGzQRosk+jbfkmY8e/HUWZ2 +xEw== X-Gm-Message-State: APjAAAVOrlhB8cTImYeQNd72ALFu4xXeT2jymixnJBmqxRSZzF0i8Aeg KXoXU4m5x8c4pD44wIL+cstAL8oEluJ2v+mTWHXbEA== X-Google-Smtp-Source: APXvYqxsm0zWExcOfY3Bn7WC3ZglPIOp2b3DY93TUELOX1ylXKExo+m3fWoRNAuoUJs59cl7htYjZ7xSOE8Yu8GKimc= X-Received: by 2002:a7b:cc81:: with SMTP id p1mr12647894wma.62.1580490367549; Fri, 31 Jan 2020 09:06:07 -0800 (PST) MIME-Version: 1.0 References: <20200124115411.9364-1-pete@akeo.ie> <20200124115411.9364-3-pete@akeo.ie> In-Reply-To: <20200124115411.9364-3-pete@akeo.ie> From: "Ard Biesheuvel" Date: Fri, 31 Jan 2020 18:05:55 +0100 Message-ID: Subject: Re: [edk2-platforms][PATCH v2 2/3] Platform/RPi: Add PlatformPcdLib to set the Genet MAC address To: Pete Batard Cc: edk2-devel-groups-io , Leif Lindholm , =?UTF-8?Q?Philippe_Mathieu=2DDaud=C3=A9?= , Jeremy Linton Content-Type: text/plain; charset="UTF-8" On Fri, 24 Jan 2020 at 12:54, Pete Batard wrote: > > 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 > --- > Platform/RaspberryPi/Library/PlatformPcdLib/PlatformPcdLib.c | 51 ++++++++++++++++++++ > Platform/RaspberryPi/Library/PlatformPcdLib/PlatformPcdLib.inf | 43 +++++++++++++++++ > 2 files changed, 94 insertions(+) > > diff --git a/Platform/RaspberryPi/Library/PlatformPcdLib/PlatformPcdLib.c b/Platform/RaspberryPi/Library/PlatformPcdLib/PlatformPcdLib.c > new file mode 100644 > index 000000000000..792073a903e9 > --- /dev/null > +++ b/Platform/RaspberryPi/Library/PlatformPcdLib/PlatformPcdLib.c > @@ -0,0 +1,51 @@ > +/** @file > + * > + * Copyright (c) 2020, Pete Batard > + * > + * SPDX-License-Identifier: BSD-2-Clause-Patent > + * > + **/ > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +EFI_STATUS > +EFIAPI > +PlatformPcdLibConstructor ( > + IN EFI_HANDLE ImageHandle, > + IN EFI_SYSTEM_TABLE *SystemTable > + ) > +{ > + > + // > + // If Genet is in use and a MAC address PCD has not been set, do it here. > + // > +#if (FixedPcdGet64 (PcdBcmGenetRegistersAddress) != 0) I still don't see why we need this conditional. This is a fixed PCD, so it must be set in the .DSC. If you are going to set it in the .DSC, why include this driver in the first place? > + 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); > + } > + } > +#endif > + > + return EFI_SUCCESS; > +} > diff --git a/Platform/RaspberryPi/Library/PlatformPcdLib/PlatformPcdLib.inf b/Platform/RaspberryPi/Library/PlatformPcdLib/PlatformPcdLib.inf > new file mode 100644 > index 000000000000..2a207d2b3e54 > --- /dev/null > +++ b/Platform/RaspberryPi/Library/PlatformPcdLib/PlatformPcdLib.inf > @@ -0,0 +1,43 @@ > +#/** @file > +# > +# Copyright (c) 2020, Pete Batard > +# > +# SPDX-License-Identifier: BSD-2-Clause-Patent > +# > +#**/ > + > +[Defines] > + INF_VERSION = 0x0001001A > + BASE_NAME = PlatformPcdLib > + FILE_GUID = 3B8409D7-D3C7-4006-823B-BFB184435363 > + MODULE_TYPE = DXE_DRIVER > + VERSION_STRING = 1.0 > + LIBRARY_CLASS = NULL|DXE_DRIVER UEFI_APPLICATION > + CONSTRUCTOR = PlatformPcdLibConstructor > + > +[Sources] > + PlatformPcdLib.c > + > +[Packages] > + MdePkg/MdePkg.dec > + MdeModulePkg/MdeModulePkg.dec > + Platform/RaspberryPi/RaspberryPi.dec > + Silicon/Broadcom/Drivers/Net/BcmNet.dec > + > +[LibraryClasses] > + DebugLib > + PcdLib > + UefiLib > + PrintLib > + > +[Protocols] > + gRaspberryPiFirmwareProtocolGuid ## CONSUMES > + > +[Pcd] > + gBcmNetTokenSpaceGuid.PcdBcmGenetMacAddress ## SOMETIMES_PRODUCES > + > +[FixedPcd] > + gBcmNetTokenSpaceGuid.PcdBcmGenetRegistersAddress > + > +[Depex] > + gRaspberryPiFirmwareProtocolGuid > -- > 2.21.0.windows.1 >