public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Ard Biesheuvel" <ard.biesheuvel@linaro.org>
To: Pete Batard <pete@akeo.ie>
Cc: edk2-devel-groups-io <devel@edk2.groups.io>,
	"Leif Lindholm" <leif@nuviainc.com>,
	"Philippe Mathieu-Daudé" <philmd@redhat.com>,
	"Jeremy Linton" <lintonrjeremy@gmail.com>
Subject: Re: [edk2-platforms][PATCH 2/3] Platform/RPi: Add PlatformPcdLib to set the Genet MAC address
Date: Thu, 23 Jan 2020 14:50:20 +0100	[thread overview]
Message-ID: <CAKv+Gu_s534p080NO8aHoBdpdpencG4Q2Ukz8qvcCqynNpGdHA@mail.gmail.com> (raw)
In-Reply-To: <20200123120007.4784-3-pete@akeo.ie>

On Thu, 23 Jan 2020 at 13:00, Pete Batard <pete@akeo.ie> 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 <pete@akeo.ie>
> ---
>  Platform/RaspberryPi/Library/PlatformPcdLib/PlatformPcdLib.c   | 61 ++++++++++++++++++++
>  Platform/RaspberryPi/Library/PlatformPcdLib/PlatformPcdLib.inf | 44 ++++++++++++++
>  2 files changed, 105 insertions(+)
>
> diff --git a/Platform/RaspberryPi/Library/PlatformPcdLib/PlatformPcdLib.c b/Platform/RaspberryPi/Library/PlatformPcdLib/PlatformPcdLib.c
> new file mode 100644
> index 000000000000..78f3679e2e48
> --- /dev/null
> +++ b/Platform/RaspberryPi/Library/PlatformPcdLib/PlatformPcdLib.c
> @@ -0,0 +1,61 @@
> +/** @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
> +  )
> +{
> +
> +  //
> +  // If Genet is in use and a MAC address PCD has not been set, do it here.
> +  //
> +#if (FixedPcdGet64 (PcdBcmGenetRegistersAddress) != 0)

Can we drop this check? Why would you include this library in your
.DSC and set the fixed PCD to 0?

> +  EFI_STATUS                       Status;
> +  UINT64                           MacAddr;
> +  RASPBERRY_PI_FIRMWARE_PROTOCOL   *mFwProtocol;
> +
> +  if (PcdGet64 (PcdBcmGenetMacAddress) == 0) {

This is policy, which we don't need today, and may well be needed
elsewhere once we do need it. So I'd prefer it if we just drop this
check.

> +    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 {
> +      PcdSet64 (PcdBcmGenetMacAddress, MacAddr);

Please use PcdSet64S () instead - the unsafe ones are deprecated AFAIR

> +    }
> +  }
> +#endif
> +
> +  return EFI_SUCCESS;
> +}
> +
> +EFI_STATUS
> +EFIAPI
> +PlatformPcdLibDestructor (
> +  IN EFI_HANDLE ImageHandle,
> +  IN EFI_SYSTEM_TABLE *SystemTable
> +  )
> +{
> +  return EFI_SUCCESS;
> +}

No need for a destructor

> diff --git a/Platform/RaspberryPi/Library/PlatformPcdLib/PlatformPcdLib.inf b/Platform/RaspberryPi/Library/PlatformPcdLib/PlatformPcdLib.inf
> new file mode 100644
> index 000000000000..a564ddfbb2a3
> --- /dev/null
> +++ b/Platform/RaspberryPi/Library/PlatformPcdLib/PlatformPcdLib.inf
> @@ -0,0 +1,44 @@
> +#/** @file
> +#
> +#  Copyright (c) 2020, Pete Batard <pete@akeo.ie>
> +#
> +#  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
> +  DESTRUCTOR                     = PlatformPcdLibDestructor
> +
> +[Sources]
> +  PlatformPcdLib.c
> +
> +[Packages]
> +  MdePkg/MdePkg.dec
> +  MdeModulePkg/MdeModulePkg.dec
> +  Platform/RaspberryPi/RaspberryPi.dec
> +  Silicon/Broadcom/Drivers/Net/BcmNet.dec
> +
> +[LibraryClasses]
> +  UefiLib
> +  DebugLib
> +  PrintLib
> +
> +[Protocols]
> +  gRaspberryPiFirmwareProtocolGuid              ## CONSUMES
> +
> +[Pcd]
> +  gBcmNetTokenSpaceGuid.PcdBcmGenetMacAddress   ## SOMETIMES_PRODUCES
> +
> +[FixedPcd]
> +  gBcmNetTokenSpaceGuid.PcdBcmGenetRegistersAddress
> +
> +[Depex]
> +  gPcdProtocolGuid AND gRaspberryPiFirmwareProtocolGuid
> +

Use the PcdLib library class instead - this will depex on the
gPcdProtocolGuid if needed.

I don't mind this approach, but in general, I'd be happier with a
specific library class to discover the MAC address.

I.e., a library class in BcmNet.dec called BcmGenetPlatformLib, which
has [for now] a single function called BcmGenetGetMacFromPlatform().
The RPi4 implementation would provide that routine, and depex on the
firmware protocol, ensuring the ordering is correct. That way, we can
get rid of the PCDs entirely.

  reply	other threads:[~2020-01-23 13:50 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-23 12:00 [edk2-platforms][PATCH 0/3] Platform/RPi4: Add Genet network driver stub Pete Batard
2020-01-23 12:00 ` [edk2-platforms][PATCH 1/3] Silicon/Broadcom/Net: Add Genet stub driver to setup MAC Pete Batard
2020-01-23 13:44   ` Ard Biesheuvel
2020-01-23 14:36     ` Pete Batard
2020-01-23 12:00 ` [edk2-platforms][PATCH 2/3] Platform/RPi: Add PlatformPcdLib to set the Genet MAC address Pete Batard
2020-01-23 13:50   ` Ard Biesheuvel [this message]
2020-01-23 15:01     ` Pete Batard
2020-01-23 12:00 ` [edk2-platforms][PATCH 3/3] Platform/Rpi4: Enable Broadcom Genet stub driver Pete Batard
2020-01-23 12:00 ` [PATCH] Platform/RPi/Genet: Add Genet stub driver to setup MAC Pete Batard
2020-01-23 12:00 ` [PATCH] Platform/RPi4: Enable BCM GENET stub driver Pete Batard
     [not found] ` <15EC824B064B2D10.12514@groups.io>
2020-01-23 12:03   ` [edk2-devel] [PATCH] Platform/RPi/Genet: Add Genet stub driver to setup MAC Pete Batard
     [not found] ` <15EC824ADEB49EC2.12514@groups.io>
2020-01-23 12:03   ` [edk2-devel] [PATCH] Platform/RPi4: Enable BCM GENET stub driver Pete Batard

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAKv+Gu_s534p080NO8aHoBdpdpencG4Q2Ukz8qvcCqynNpGdHA@mail.gmail.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox