From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f66.google.com (mail-wr1-f66.google.com [209.85.221.66]) by mx.groups.io with SMTP id smtpd.web11.6688.1579780827227718077 for ; Thu, 23 Jan 2020 04:00:27 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@akeo-ie.20150623.gappssmtp.com header.s=20150623 header.b=fMWjX7d8; spf=none, err=permanent DNS error (domain: akeo.ie, ip: 209.85.221.66, mailfrom: pete@akeo.ie) Received: by mail-wr1-f66.google.com with SMTP id t2so2807369wrr.1 for ; Thu, 23 Jan 2020 04:00:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=akeo-ie.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=0ts7qoag6kmGG38ahdD4Qr/Qf6XiWXpr/ww3I4u3whI=; b=fMWjX7d81XOicbhYAzKFeKiqVlPT3QfSW/ZxqW5oYRV+sJQ8ixAXl4EsXItS3nTFY6 L2DixgW5KYgjOGI+co7YcH9/jZS7RbNZIX0rbq9qBZj7G8wiQ0s5UAeLV2HGIhBxLoip KNQPaKqZKBtSIg3U2xRX0Gs1AvmW/Yy8I4nfCEco0ZCP8gqPZT6qy4HWudVAROGCJCv6 4QrwXwQym0jCDkOiCYGxWuaHfTQ3s287y6k7Cyb+PIq7NHPZ0eC+HJ+1svYTsOUb5lSD GAlGcFPgu7k2pB2sUeDekmA87S4SMrcvHKipYfnTY4KBqL5yS0FcvuKkhgQWnHDgcn0g SlUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=0ts7qoag6kmGG38ahdD4Qr/Qf6XiWXpr/ww3I4u3whI=; b=l4YD6ICffat7DIFHjCQg5Rdjw5q2ZKiekTQN3GtpUP/iqz66uwRaocuASVR39CUKs2 bKD4GhO8Sxl/7g2aeDDDBjDxDD6geMjs42UPGMTxoKr0PahtWLxZofB/Mk8gRyz55BQ2 i5R5W2LwDiVVnw9XPQfzhxo4429hR8a5U3UPBzirxDEFKX/KY81TpL5dY1/2TbrDdAcH 1vhymIU7fKWVtPUGMnWYNdHv+FJap6eaxl2rCr4Df/e34nDS+2pMmIxEXLhuAYUts8tf yCSZPjklInz/C7tocWrrFRPmMcY+1SjWYyDpd4k6cdsaxNQZwp0kxKnvxUXw14WfD55l bKmQ== X-Gm-Message-State: APjAAAUPXYWeQ7tNur57xJlHe3KO4NAs0768dvSvzNBXgOb2aDN5+fmj cTQyuZkupg5rqFRu3LVb5YBU/ZDP1rw= X-Google-Smtp-Source: APXvYqyalX8WOz0A44ZFY83fY+cM7q8Xb7sENExq9IKrGqfi3Ugj5v+IsyOI2VHppVtb1SI4uL/sNg== X-Received: by 2002:a5d:528e:: with SMTP id c14mr17523776wrv.308.1579780823600; Thu, 23 Jan 2020 04:00:23 -0800 (PST) Return-Path: Received: from localhost.localdomain ([84.203.95.128]) by smtp.gmail.com with ESMTPSA id t1sm2492281wma.43.2020.01.23.04.00.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 23 Jan 2020 04:00:23 -0800 (PST) From: "Pete Batard" 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 Message-Id: <20200123120007.4784-5-pete@akeo.ie> X-Mailer: git-send-email 2.21.0.windows.1 In-Reply-To: <20200123120007.4784-1-pete@akeo.ie> References: <20200123120007.4784-1-pete@akeo.ie> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Jeremy Linton 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 --- 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.
+ + 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 +#include +#include +#include +#include +#include + +#include +#include + +#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.
+# +# 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 +