From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f67.google.com (mail-wr1-f67.google.com [209.85.221.67]) by mx.groups.io with SMTP id smtpd.web11.6726.1579781007345074640 for ; Thu, 23 Jan 2020 04:03:27 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@akeo-ie.20150623.gappssmtp.com header.s=20150623 header.b=TAFyQuFK; spf=none, err=permanent DNS error (domain: akeo.ie, ip: 209.85.221.67, mailfrom: pete@akeo.ie) Received: by mail-wr1-f67.google.com with SMTP id t2so2818004wrr.1 for ; Thu, 23 Jan 2020 04:03:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=akeo-ie.20150623.gappssmtp.com; s=20150623; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=EUkwCrednxMCnEw2qwEW4wIdfHqy9O8PinnzyXX7cjo=; b=TAFyQuFKOGAfIDC24dv3f590Y0lhKqYCN1nwQ+Q64ZoSKgPXrpBNEupaaHgUxgr+xB maxoPSUGlcXjs8CDRDUKHW3lnKhH5mMxnEL7NCz/hvkWaOZFczSpNq7HCgq1kxOpz/fT YtOK4VXkh+e3sLga+5fBX1/EGhJf4PQmx41SticV9eYHPwcVgSBnLBlFuwJpopPMNJce XDC/ZOtbj1HHvIYH2s4Dz6D94vK6ezQCMBMc7aYxzpRAnqNG9ifMvJBUbQnztijTxYmn Gv8wxNtfKyNIIEVjEUwzOgy/P6G25BsQ8ey1vXRNCNyXFgI8a2bY2qaoXCgQDwDEMzkz l8RQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=EUkwCrednxMCnEw2qwEW4wIdfHqy9O8PinnzyXX7cjo=; b=FqBxFDdmea330b1m2km3KTc99BeyjtFsxqH0Qt0qiPkOWko1HmRzba/T6uSwLxRzDF lLJtd4FjbPm4cCbiVZhn9uALHBCxq38HEmjSZUuki3yZ+feUZ7phs6B2yH+6xqYTObg6 gH2J81e1pRLDv5rpg0eLFPaVqrWE4NoDdxSZExhbAClb+3k2AF/I7ItvubIm7qcg2NIK oYFT/n+eC/589n6zNS3a4evCJMIculhWbI5CrPeBkCZHTYAvFk5ysACV8TJMfMc2Y/ZF pvpC2ku5VjdhGG6P4JmNmKms34OVn0hKsDWTBYQOojqbKjGdT+O+5NuVzFjoJ2DqURWD 3NHA== X-Gm-Message-State: APjAAAWWNY0m8XWCxj+fIC52+fHkN9O8R4427+ROjS79ccQ/2KhUZ/so TU1EffFuoOumdZ3l7xcmOoMN+A== X-Google-Smtp-Source: APXvYqx0x1aSOef5EAggwJ0kEFrVcz7mogBUy7jjVraHtZ3ZtyIXNEZxiR2lT6ZN46I4cXftQhKnqA== X-Received: by 2002:a05:6000:1052:: with SMTP id c18mr16897897wrx.268.1579781005814; Thu, 23 Jan 2020 04:03:25 -0800 (PST) Return-Path: Received: from [10.0.0.122] ([84.203.95.128]) by smtp.googlemail.com with ESMTPSA id m10sm2806722wrx.19.2020.01.23.04.03.24 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 23 Jan 2020 04:03:25 -0800 (PST) Subject: Re: [edk2-devel] [PATCH] Platform/RPi/Genet: Add Genet stub driver to setup MAC To: devel@edk2.groups.io Cc: ard.biesheuvel@linaro.org, leif@nuviainc.com, philmd@redhat.com, lintonrjeremy@gmail.com References: <20200123120007.4784-1-pete@akeo.ie> <15EC824B064B2D10.12514@groups.io> From: "Pete Batard" Message-ID: <2695a134-d920-a2d3-d10e-380999dc0dfb@akeo.ie> Date: Thu, 23 Jan 2020 12:03:23 +0000 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.4.1 MIME-Version: 1.0 In-Reply-To: <15EC824B064B2D10.12514@groups.io> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-GB Content-Transfer-Encoding: 7bit **PLEASE DISREGARD THIS PATCH** I had a couple of extra .patch files in my repo that were inadvertently sent with the previous series. /Pete On 2020.01.23 12:00, Pete Batard via Groups.Io wrote: > 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 > + > > >