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 1/3] Silicon/Broadcom/Net: Add Genet stub driver to setup MAC
Date: Thu, 23 Jan 2020 14:44:10 +0100	[thread overview]
Message-ID: <CAKv+Gu_b_J2_wpf+O6TBWON_6xAfGdaJmM=RFRX8TRV=9kHCYQ@mail.gmail.com> (raw)
In-Reply-To: <20200123120007.4784-2-pete@akeo.ie>

On Thu, 23 Jan 2020 at 13:00, Pete Batard <pete@akeo.ie> wrote:
>
> From: Jeremy Linton <lintonrjeremy@gmail.com>
>
> Add a stub for the Broadcom Genet network interface, that is used
> by the Raspberry Pi 4 (and that may be used by other platforms).
>
> For the time being, the stub only performs UMAC init, using a MAC
> address PCD, as, even without a working network interface in UEFI
> environment, it is desirable if the hardware can describe itself
> for booting in an ACPI environment, rather than pass parameters via
> DSDT/DSD .
>
> Signed-off-by: Pete Batard <pete@akeo.ie>
> ---
>  Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.inf |  40 +++++++
>  Silicon/Broadcom/Drivers/Net/BcmGenetDxe/Genet.c         | 114 ++++++++++++++++++++
>  Silicon/Broadcom/Drivers/Net/BcmGenetDxe/Genet.h         |  20 ++++
>  Silicon/Broadcom/Drivers/Net/BcmNet.dec                  |  22 ++++
>  4 files changed, 196 insertions(+)
>
> diff --git a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.inf b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.inf
> new file mode 100644
> index 000000000000..9e9301608f24
> --- /dev/null
> +++ b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.inf
> @@ -0,0 +1,40 @@
> +## @file
> +#
> +# Copyright (c) 2020, Jeremy Linton All rights reserved.<BR>
> +#
> +# SPDX-License-Identifier: BSD-2-Clause-Patent
> +#
> +##
> +
> +[Defines]
> +  INF_VERSION                    = 0x0001001A
> +  BASE_NAME                      = BcmGenetDxe
> +  FILE_GUID                      = e2b1eaf3-50b7-4ae1-b79e-ec8020cb57ac
> +  MODULE_TYPE                    = DXE_DRIVER
> +  VERSION_STRING                 = 0.1
> +  ENTRY_POINT                    = GenetEntryPoint
> +
> +[Sources]
> +  Genet.c
> +
> +[Packages]
> +  ArmPkg/ArmPkg.dec
> +  MdeModulePkg/MdeModulePkg.dec
> +  MdePkg/MdePkg.dec
> +  Silicon/Broadcom/Drivers/Net/BcmNet.dec
> +
> +[LibraryClasses]
> +  ArmLib
> +  BaseLib
> +  IoLib
> +  UefiDriverEntryPoint
> +  UefiLib
> +
> +[FixedPcd]
> +  gBcmNetTokenSpaceGuid.PcdBcmGenetRegistersAddress
> +
> +[Pcd]
> +  gBcmNetTokenSpaceGuid.PcdBcmGenetMacAddress
> +
> +[Depex]
> +  TRUE
> diff --git a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/Genet.c b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/Genet.c
> new file mode 100644
> index 000000000000..d135d889cc1f
> --- /dev/null
> +++ b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/Genet.c
> @@ -0,0 +1,114 @@
> +/** @file
> +
> +  Copyright (c) 2020, Jeremy Linton All rights reserved.<BR>
> +
> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +  This driver acts like a stub to set the Broadcom
> +  Genet MAC address, until the actual network driver
> +  is in place.
> +
> +**/
> +
> +#include <Library/ArmLib.h>
> +#include <Library/DebugLib.h>
> +#include <Library/IoLib.h>
> +#include <Library/PcdLib.h>
> +#include <Library/UefiBootServicesTableLib.h>
> +#include <Library/UefiLib.h>
> +
> +#include <Genet.h>
> +#include <PiDxe.h>
> +
> +STATIC
> +VOID
> +RMWRegister (
> +  UINT32                Offset,
> +  UINT32                Mask,
> +  UINT32                In
> +  )
> +{
> +  EFI_PHYSICAL_ADDRESS  Addr;
> +  UINT32                Data;
> +  UINT32                Shift;
> +
> +  Addr = GENET_BASE_ADDRESS + Offset;
> +  Data = 0;
> +  Shift = 1;
> +  if (In) {
> +    while (!(Mask & Shift))
> +      Shift <<= 1;
> +    Data = (MmioRead32 (Addr) & ~Mask) | ((In * Shift) & Mask);
> +  } else {
> +    Data = MmioRead32 (Addr) & ~Mask;
> +  }
> +
> +  MmioWrite32 (Addr, Data);
> +
> +  ArmDataMemoryBarrier ();
> +}
> +
> +STATIC
> +VOID
> +WdRegister (
> +  UINT32                Offset,
> +  UINT32                In
> +  )
> +{
> +  EFI_PHYSICAL_ADDRESS  Base = GENET_BASE_ADDRESS;
> +
> +  MmioWrite32 (Base + Offset, In);
> +
> +  ArmDataMemoryBarrier ();
> +}
> +
> +STATIC
> +VOID
> +SetMacAddress (
> +  UINT8*                MacAddr
> +)
> +{
> +  // Bring the UMAC out of reset
> +  RMWRegister (GENET_SYS_RBUF_FLUSH_CTRL, 0x2, 1);
> +  gBS->Stall (10);
> +  RMWRegister (GENET_SYS_RBUF_FLUSH_CTRL, 0x2, 0);
> +
> +  // Update the MAC
> +  DEBUG ((DEBUG_INFO, "Setting MAC address %02X:%02X:%02X:%02X:%02X:%02X\n",
> +    MacAddr[0], MacAddr[1], MacAddr[2], MacAddr[3], MacAddr[4], MacAddr[5]));
> +
> +  WdRegister (GENET_UMAC_MAC0, (MacAddr[0] << 24) | (MacAddr[1] << 16) |
> +    (MacAddr[2] << 8) | MacAddr[3]);
> +  WdRegister (GENET_UMAC_MAC1, (MacAddr[4] << 8) | MacAddr[5]);
> +
> +}
> +
> +/**
> +  The entry point of Genet UEFI Driver.
> +
> +  @param  ImageHandle                The image handle of the UEFI Driver.
> +  @param  SystemTable                A pointer to the EFI System Table.
> +
> +  @retval  EFI_SUCCESS               The Driver or UEFI Driver exited normally.
> +  @retval  EFI_INCOMPATIBLE_VERSION  _gUefiDriverRevision is greater than
> +                                     SystemTable->Hdr.Revision.
> +
> +**/
> +EFI_STATUS
> +EFIAPI
> +GenetEntryPoint (
> +  IN  EFI_HANDLE          ImageHandle,
> +  IN  EFI_SYSTEM_TABLE    *SystemTable
> +  )
> +{
> +  UINT64 MacAddr;
> +
> +  // Read the MAC address
> +  MacAddr = PcdGet64 (PcdBcmGenetMacAddress);
> +
> +  if (MacAddr != 0) {
> +    SetMacAddress ((UINT8*)&MacAddr);
> +  }
> +
> +  return EFI_SUCCESS;
> +}
> diff --git a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/Genet.h b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/Genet.h
> new file mode 100644
> index 000000000000..4a3827c0e0d1
> --- /dev/null
> +++ b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/Genet.h
> @@ -0,0 +1,20 @@
> +/** @file
> +
> +  Copyright (c) 2020, Pete Batard <pete@akeo.ie>
> +
> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +**/
> +
> +#ifndef BCM_GENET_H__
> +#define BCM_GENET_H__
> +
> +#include <Library/PcdLib.h>
> +
> +#define GENET_BASE_ADDRESS         (FixedPcdGet64 (PcdBcmGenetRegistersAddress))
> +
> +#define GENET_SYS_RBUF_FLUSH_CTRL  0x0008
> +#define GENET_UMAC_MAC0            0x080c
> +#define GENET_UMAC_MAC1            0x0810
> +
> +#endif /* BCM_GENET_H__ */
> diff --git a/Silicon/Broadcom/Drivers/Net/BcmNet.dec b/Silicon/Broadcom/Drivers/Net/BcmNet.dec
> new file mode 100644
> index 000000000000..d80aac27ed9e
> --- /dev/null
> +++ b/Silicon/Broadcom/Drivers/Net/BcmNet.dec
> @@ -0,0 +1,22 @@
> +## @file
> +#
> +#  Copyright (c) 2020, Pete Batard <pete@akeo.ie>
> +#
> +#  SPDX-License-Identifier: BSD-2-Clause-Patent
> +#
> +##
> +
> +[Defines]
> +  DEC_SPECIFICATION              = 0x0001001A
> +  PACKAGE_NAME                   = BcmNetPkg
> +  PACKAGE_GUID                   = 34E19823-D23A-41AB-9C09-ED1225B32DFF
> +  PACKAGE_VERSION                = 1.0
> +
> +[Guids]
> +  gBcmNetTokenSpaceGuid = {0x12b97d70, 0x9149, 0x4c2f, {0x82, 0xd5, 0xad, 0xa9, 0x1e, 0x92, 0x75, 0xa1}}
> +
> +[PcdsFixedAtBuild]
> +  gBcmNetTokenSpaceGuid.PcdBcmGenetRegistersAddress|0x0|UINT32|0x00000001
> +

Can we make this UINT64 please? EFI_PHYSICAL_ADDRESSes are 64-bit in UEFI.

> +[PcdsDynamic]
> +  gBcmNetTokenSpaceGuid.PcdBcmGenetMacAddress|0x0|UINT64|0x00000002
> --
> 2.21.0.windows.1
>

  reply	other threads:[~2020-01-23 13:44 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 [this message]
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
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_b_J2_wpf+O6TBWON_6xAfGdaJmM=RFRX8TRV=9kHCYQ@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