From nobody Sat Apr 27 20:21:28 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+53441+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+53441+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1579780829; cv=none; d=zohomail.com; s=zohoarc; b=WtTGMevyoLFwDFQVWF+As13r9anCUPFzRFpZzG3HM8qRjOscvNvm0knxKhuHEyNAKlA86ALk+PkRqW5+FaigHCM1NgSvUSa+0pfwwxp0s0k+vFo0SjZc9LMKVcMC9w/XOOqGMdF9N74vi/32yKsar+LqASSjwaVq+CqOwEGcdC0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579780829; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=btGmPEMEOLdL8DPD9ESj7AasWlhGze2ikE7bZKVDc1M=; b=ZQsmhPjCRjyYM3+T32ek2RTEWphrNEueKFdQey8WO0rXnGnyqOg00W4zarlhXQ53APy+7ytjlHP+vZ33ciNZbbuu1h+C8uysFfh7PNs7+gElS11R8YqNXytxB85AuPfMRaVC5hKtZbYma1QQhP7hy/mYb3eUGUQFfre/uTgQLW8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+53441+1787277+3901457@groups.io Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1579780829256688.113325280716; Thu, 23 Jan 2020 04:00:29 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id SYI3YY1788612xn6AffzI2uh; Thu, 23 Jan 2020 04:00:28 -0800 X-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 X-Received: by mail-wr1-f66.google.com with SMTP id t2so2807369wrr.1 for ; Thu, 23 Jan 2020 04:00:27 -0800 (PST) X-Gm-Message-State: XfSff1aAoUhhB3pY6N6lYqKzx1787277AA= 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) X-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: [edk2-devel] [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> In-Reply-To: <20200123120007.4784-1-pete@akeo.ie> References: <20200123120007.4784-1-pete@akeo.ie> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,pete@akeo.ie Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1579780828; bh=C3ZoB8/I0YvaxIlyDlYE26LbM4xLdyjYmJjYi0nDzPs=; h=Cc:Date:From:Reply-To:Subject:To; b=dIbvBszpxPTEWKMEup7X2hbHeuCJOh77tC8VaDzgWbNGnS5tSNw6s2JH/Nx1jN0F112 XHBGK0oDQUNesj9anMmABVc3NOZ8Dfhz6zgmeeeT7fx49i4AoDNT4yZx1UUw/oWkeJlpT 0b/CTprTixBg2q5P1GxMDXNQK5VtP0IPrW8= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" 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/Raspberr= yPi/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=20 + 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=20 + 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 =3D 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 =3D GENET_BASE; + UINT32 Data =3D 0; + UINT32 Shift; + + Addr +=3D Offset; + Shift =3D 1; + if (In) { + while (!(Mask & Shift)) + Shift <<=3D 1; + Data =3D (MmioRead32 (Addr) & ~Mask) | ((In * Shift) & Mask); + } else { + Data =3D MmioRead32 (Addr) & ~Mask; + } + + MmioWrite32 (Addr, Data); + + ArmDataMemoryBarrier (); +} + +STATIC +VOID +WdRegister ( + UINT32 Offset, + UINT32 In + ) +{ + EFI_PHYSICAL_ADDRESS Base =3D 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 norm= ally. + @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 =3D gBS->LocateProtocol (&gRaspberryPiFirmwareProtocolGuid, NULL, + (VOID**)&mFwProtocol); + if (EFI_ERROR(Status)) { + DEBUG ((DEBUG_ERROR, "%a: failed to locate RPi firmware protocol\n", _= _FUNCTION__)); + return Status; + } + =20 + // Get the MAC address from the firmware + Status =3D mFwProtocol->GetMacAddress (MacAddr); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: failed to retrieve MAC address\n", __FUNCTIO= N__)); + return Status; + } + + // Write it to the hardware + GenetMacInit (MacAddr); + + return EFI_SUCCESS; +} diff --git a/Platform/RaspberryPi/Drivers/Genet/Genet.inf b/Platform/Raspbe= rryPi/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 =3D 0x0001001A + BASE_NAME =3D Genet + FILE_GUID =3D e2b1eaf3-50b7-4ae1-b79e-ec8020cb57ac + MODULE_TYPE =3D UEFI_DRIVER + VERSION_STRING =3D 0.1 + ENTRY_POINT =3D 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 + -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- 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] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-