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
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
+
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#53441): https://edk2.groups.io/g/devel/message/53441
Mute This Topic: https://groups.io/mt/70045883/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-
© 2016 - 2024 Red Hat, Inc.