From: "Pete Batard" <pete@akeo.ie>
To: devel@edk2.groups.io
Cc: ard.biesheuvel@linaro.org, leif@nuviainc.com, philmd@redhat.com,
lintonrjeremy@gmail.com
Subject: [PATCH] Platform/RPi/Genet: Add Genet stub driver to setup MAC
Date: Thu, 23 Jan 2020 12:00:06 +0000 [thread overview]
Message-ID: <20200123120007.4784-5-pete@akeo.ie> (raw)
In-Reply-To: <20200123120007.4784-1-pete@akeo.ie>
From: Jeremy Linton <lintonrjeremy@gmail.com>
The RPi4 has a 1G BCM Genet platform device. In order to
assist in booting the platform in an ACPI environment, it is
desirable if the hardware can describe itself rather than
passing parameters via DSDT/DSD. One way to achieve this
is to assure that the adapter is preprogrammed with the correct
ethernet mac address as it would be if the adapter were
used during the boot process.
While we currently lack a fully functional uefi driver
for the genet, it is fairly trivial to assure that the
mac address is set. That is what this driver does.
Signed-off-by: Jeremy Linton <lintonrjeremy@gmail.com>
---
Platform/RaspberryPi/Drivers/Genet/Genet.c | 132 +++++++++++++++++++
Platform/RaspberryPi/Drivers/Genet/Genet.inf | 39 ++++++
2 files changed, 171 insertions(+)
create mode 100644 Platform/RaspberryPi/Drivers/Genet/Genet.c
create mode 100644 Platform/RaspberryPi/Drivers/Genet/Genet.inf
diff --git a/Platform/RaspberryPi/Drivers/Genet/Genet.c b/Platform/RaspberryPi/Drivers/Genet/Genet.c
new file mode 100644
index 0000000000..c4180f1d9d
--- /dev/null
+++ b/Platform/RaspberryPi/Drivers/Genet/Genet.c
@@ -0,0 +1,132 @@
+/** @file
+
+ Copyright (c) 2019, Jeremy Linton All rights reserved.<BR>
+
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+ This driver acts like a stub to set the BCM
+ Genet MAC address, until the actual network driver
+ is in place. This should allow us to retrieve the
+ mac address directly from the hardware in supported
+ OS's rather than passing it via DSDT (which isn't
+ ideal for a number of reasons, foremost the hardware
+ should be self describing).
+
+**/
+
+#include <Library/ArmLib.h>
+#include <Library/DebugLib.h>
+#include <Library/DevicePathLib.h>
+#include <Library/IoLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+#include <Library/UefiLib.h>
+
+#include <PiDxe.h>
+#include <Protocol/RpiFirmware.h>
+
+#define GENET_BASE 0xfd580000 // len = 0x10000
+#define GENET_SYS_RBUF_FLUSH_CTRL 0x0008
+#define GENET_UMAC_MAC0 0x080C
+#define GENET_UMAC_MAC1 0x0810
+
+STATIC
+VOID
+RMWRegister (
+ UINT32 Offset,
+ UINT32 Mask,
+ UINT32 In
+ )
+{
+ EFI_PHYSICAL_ADDRESS Addr = GENET_BASE;
+ UINT32 Data = 0;
+ UINT32 Shift;
+
+ Addr += Offset;
+ 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;
+
+ MmioWrite32 (Base + Offset, In);
+
+ ArmDataMemoryBarrier ();
+}
+
+
+
+STATIC VOID
+GenetMacInit (UINT8 *addr)
+{
+
+ // 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
+
+ WdRegister(GENET_UMAC_MAC0, (addr[0] << 24) | (addr[1] << 16) | (addr[2] << 8) | addr[3]);
+ WdRegister(GENET_UMAC_MAC1, (addr[4] << 8) | addr[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
+ )
+{
+ RASPBERRY_PI_FIRMWARE_PROTOCOL *mFwProtocol;
+ EFI_STATUS Status;
+ UINT8 MacAddr[6];
+
+ DEBUG ((DEBUG_ERROR, "GENET:%a(): Init\n", __FUNCTION__));
+
+ Status = gBS->LocateProtocol (&gRaspberryPiFirmwareProtocolGuid, NULL,
+ (VOID**)&mFwProtocol);
+ if (EFI_ERROR(Status)) {
+ DEBUG ((DEBUG_ERROR, "%a: failed to locate RPi firmware protocol\n", __FUNCTION__));
+ return Status;
+ }
+
+ // Get the MAC address from the firmware
+ Status = mFwProtocol->GetMacAddress (MacAddr);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "%a: failed to retrieve MAC address\n", __FUNCTION__));
+ return Status;
+ }
+
+ // Write it to the hardware
+ GenetMacInit (MacAddr);
+
+ return EFI_SUCCESS;
+}
diff --git a/Platform/RaspberryPi/Drivers/Genet/Genet.inf b/Platform/RaspberryPi/Drivers/Genet/Genet.inf
new file mode 100644
index 0000000000..3599e5a6e5
--- /dev/null
+++ b/Platform/RaspberryPi/Drivers/Genet/Genet.inf
@@ -0,0 +1,39 @@
+## @file
+#
+# Copyright (c) 2020, Jeremy Linton All rights reserved.<BR>
+#
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+ INF_VERSION = 0x0001001A
+ BASE_NAME = Genet
+ FILE_GUID = e2b1eaf3-50b7-4ae1-b79e-ec8020cb57ac
+ MODULE_TYPE = UEFI_DRIVER
+ VERSION_STRING = 0.1
+ ENTRY_POINT = GenetEntryPoint
+
+[Sources]
+ Genet.c
+
+[Packages]
+ ArmPkg/ArmPkg.dec
+ MdeModulePkg/MdeModulePkg.dec
+ MdePkg/MdePkg.dec
+ Platform/RaspberryPi/RaspberryPi.dec
+
+[LibraryClasses]
+ BaseLib
+ IoLib
+ SynchronizationLib
+ UefiDriverEntryPoint
+ UefiLib
+
+[Protocols]
+ gRaspberryPiFirmwareProtocolGuid ## CONSUMES
+
+
+[Depex]
+ gRaspberryPiFirmwareProtocolGuid
+
next prev parent reply other threads:[~2020-01-23 12:00 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
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 ` Pete Batard [this message]
2020-01-23 12:00 ` [PATCH] Platform/RPi4: Enable BCM GENET " 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=20200123120007.4784-5-pete@akeo.ie \
--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