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.web09.8376.1579790182570604737 for ; Thu, 23 Jan 2020 06:36:23 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@akeo-ie.20150623.gappssmtp.com header.s=20150623 header.b=zNVf5tBL; 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 y17so3330307wrh.5 for ; Thu, 23 Jan 2020 06:36:22 -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=P4dEgQKPrDPecLER25EhFDqPhEVYQ/4o2+vpn7Im9hI=; b=zNVf5tBLYWKwPRIgq1xfDfILzd3pECpaAHVwnBSdZLI2y8OthtdIFGZ/0KHHmqz03t kUrKdRbtKDYmIWlhmC0jZ999gtc0X2+XVK5B/x6uQ7s+TPzwheZ2RCqi2CZ2+2TTfvwU UaOX/1xBdYDQLPkMuMs5egR7nqRAhKRLWlM6yyrKwlK1T44nISVq0VsgPeb/FKVo/+bP HjCXJGerqpSwnRTRqx1hs3T3uExiUoDCi1v7EtvlxDx/qKCp012dDL5137jBWoH18VaC aAs4Ghuf3ybh69UHM2sC4o48MCd6b5fjOI5LbGC+JAkqOqUS78zGrYwzHJUnTh3CxDce zxBw== 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=P4dEgQKPrDPecLER25EhFDqPhEVYQ/4o2+vpn7Im9hI=; b=nV8fjzLgV1CgTBGgXYiNniHWfugJejKO8sTYW1GxVwQVQEQodIii3xYyKGuwk/N6fv 0yjGzO0kDWKiNJ1xAXjdT5i0nVlz3a2RD8r8D9VgbT9Rm6aoEFPNZIdjLlMze0EDo1rp zXC/d/Tlq9WVroEXNrWQE14DcgpbWsVpCaAlqkFugRgirsg8rNeWSniozNXl1IKM81dR c0hrIW7sjSJj7hwIIMtp+PLORIQyRbjg37qWCwKwSmtS7x67Tcwo/VHKzl2xrhkcWdNI XghrY3BCfz7IZpfmfS8hKCir9Gx4HtXyEUsvoZz3Yc/9pKk+3DMGpeMk9pR0md+TMxGG YrHg== X-Gm-Message-State: APjAAAVceGNdQtWdtZAn46ocudI5xp+p+bn1yd4uwGBvOhTXsQs85EZE bgrOX1Vx4av5j+aqYpq1nbE2uA== X-Google-Smtp-Source: APXvYqyhJ77Da9SBLTuSs/o8NGr7EHZJ9PyPKTXWEkwaU4HWX2JqcBtYk48NMmTFxt6OFU74jCHd1A== X-Received: by 2002:adf:c54e:: with SMTP id s14mr17244701wrf.385.1579790181108; Thu, 23 Jan 2020 06:36:21 -0800 (PST) Return-Path: Received: from [10.0.0.122] ([84.203.95.128]) by smtp.googlemail.com with ESMTPSA id g9sm3259056wro.67.2020.01.23.06.36.19 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 23 Jan 2020 06:36:20 -0800 (PST) Subject: Re: [edk2-platforms][PATCH 1/3] Silicon/Broadcom/Net: Add Genet stub driver to setup MAC To: Ard Biesheuvel Cc: edk2-devel-groups-io , Leif Lindholm , =?UTF-8?Q?Philippe_Mathieu-Daud=c3=a9?= , Jeremy Linton References: <20200123120007.4784-1-pete@akeo.ie> <20200123120007.4784-2-pete@akeo.ie> From: "Pete Batard" Message-ID: Date: Thu, 23 Jan 2020 14:36:19 +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: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-GB Content-Transfer-Encoding: 7bit Hi Ard, On 2020.01.23 13:44, Ard Biesheuvel wrote: > On Thu, 23 Jan 2020 at 13:00, Pete Batard wrote: >> >> From: Jeremy Linton >> >> Add a stub for the Broadcom Genet network interface, that is used >> by the Raspberry Pi 4 (and that may be used by other platforms). >> >> For the time being, the stub only performs UMAC init, using a MAC >> address PCD, as, even without a working network interface in UEFI >> environment, it is desirable if the hardware can describe itself >> for booting in an ACPI environment, rather than pass parameters via >> DSDT/DSD . >> >> Signed-off-by: Pete Batard >> --- >> Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.inf | 40 +++++++ >> Silicon/Broadcom/Drivers/Net/BcmGenetDxe/Genet.c | 114 ++++++++++++++++++++ >> Silicon/Broadcom/Drivers/Net/BcmGenetDxe/Genet.h | 20 ++++ >> Silicon/Broadcom/Drivers/Net/BcmNet.dec | 22 ++++ >> 4 files changed, 196 insertions(+) >> >> diff --git a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.inf b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.inf >> new file mode 100644 >> index 000000000000..9e9301608f24 >> --- /dev/null >> +++ b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.inf >> @@ -0,0 +1,40 @@ >> +## @file >> +# >> +# Copyright (c) 2020, Jeremy Linton All rights reserved.
>> +# >> +# SPDX-License-Identifier: BSD-2-Clause-Patent >> +# >> +## >> + >> +[Defines] >> + INF_VERSION = 0x0001001A >> + BASE_NAME = BcmGenetDxe >> + FILE_GUID = e2b1eaf3-50b7-4ae1-b79e-ec8020cb57ac >> + MODULE_TYPE = DXE_DRIVER >> + VERSION_STRING = 0.1 >> + ENTRY_POINT = GenetEntryPoint >> + >> +[Sources] >> + Genet.c >> + >> +[Packages] >> + ArmPkg/ArmPkg.dec >> + MdeModulePkg/MdeModulePkg.dec >> + MdePkg/MdePkg.dec >> + Silicon/Broadcom/Drivers/Net/BcmNet.dec >> + >> +[LibraryClasses] >> + ArmLib >> + BaseLib >> + IoLib >> + UefiDriverEntryPoint >> + UefiLib >> + >> +[FixedPcd] >> + gBcmNetTokenSpaceGuid.PcdBcmGenetRegistersAddress >> + >> +[Pcd] >> + gBcmNetTokenSpaceGuid.PcdBcmGenetMacAddress >> + >> +[Depex] >> + TRUE >> diff --git a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/Genet.c b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/Genet.c >> new file mode 100644 >> index 000000000000..d135d889cc1f >> --- /dev/null >> +++ b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/Genet.c >> @@ -0,0 +1,114 @@ >> +/** @file >> + >> + Copyright (c) 2020, Jeremy Linton All rights reserved.
>> + >> + SPDX-License-Identifier: BSD-2-Clause-Patent >> + >> + This driver acts like a stub to set the Broadcom >> + Genet MAC address, until the actual network driver >> + is in place. >> + >> +**/ >> + >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include >> + >> +#include >> +#include >> + >> +STATIC >> +VOID >> +RMWRegister ( >> + UINT32 Offset, >> + UINT32 Mask, >> + UINT32 In >> + ) >> +{ >> + EFI_PHYSICAL_ADDRESS Addr; >> + UINT32 Data; >> + UINT32 Shift; >> + >> + Addr = GENET_BASE_ADDRESS + Offset; >> + Data = 0; >> + 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_ADDRESS; >> + >> + MmioWrite32 (Base + Offset, In); >> + >> + ArmDataMemoryBarrier (); >> +} >> + >> +STATIC >> +VOID >> +SetMacAddress ( >> + UINT8* MacAddr >> +) >> +{ >> + // 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 >> + DEBUG ((DEBUG_INFO, "Setting MAC address %02X:%02X:%02X:%02X:%02X:%02X\n", >> + MacAddr[0], MacAddr[1], MacAddr[2], MacAddr[3], MacAddr[4], MacAddr[5])); >> + >> + WdRegister (GENET_UMAC_MAC0, (MacAddr[0] << 24) | (MacAddr[1] << 16) | >> + (MacAddr[2] << 8) | MacAddr[3]); >> + WdRegister (GENET_UMAC_MAC1, (MacAddr[4] << 8) | MacAddr[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 >> + ) >> +{ >> + UINT64 MacAddr; >> + >> + // Read the MAC address >> + MacAddr = PcdGet64 (PcdBcmGenetMacAddress); >> + >> + if (MacAddr != 0) { >> + SetMacAddress ((UINT8*)&MacAddr); >> + } >> + >> + return EFI_SUCCESS; >> +} >> diff --git a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/Genet.h b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/Genet.h >> new file mode 100644 >> index 000000000000..4a3827c0e0d1 >> --- /dev/null >> +++ b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/Genet.h >> @@ -0,0 +1,20 @@ >> +/** @file >> + >> + Copyright (c) 2020, Pete Batard >> + >> + SPDX-License-Identifier: BSD-2-Clause-Patent >> + >> +**/ >> + >> +#ifndef BCM_GENET_H__ >> +#define BCM_GENET_H__ >> + >> +#include >> + >> +#define GENET_BASE_ADDRESS (FixedPcdGet64 (PcdBcmGenetRegistersAddress)) >> + >> +#define GENET_SYS_RBUF_FLUSH_CTRL 0x0008 >> +#define GENET_UMAC_MAC0 0x080c >> +#define GENET_UMAC_MAC1 0x0810 >> + >> +#endif /* BCM_GENET_H__ */ >> diff --git a/Silicon/Broadcom/Drivers/Net/BcmNet.dec b/Silicon/Broadcom/Drivers/Net/BcmNet.dec >> new file mode 100644 >> index 000000000000..d80aac27ed9e >> --- /dev/null >> +++ b/Silicon/Broadcom/Drivers/Net/BcmNet.dec >> @@ -0,0 +1,22 @@ >> +## @file >> +# >> +# Copyright (c) 2020, Pete Batard >> +# >> +# SPDX-License-Identifier: BSD-2-Clause-Patent >> +# >> +## >> + >> +[Defines] >> + DEC_SPECIFICATION = 0x0001001A >> + PACKAGE_NAME = BcmNetPkg >> + PACKAGE_GUID = 34E19823-D23A-41AB-9C09-ED1225B32DFF >> + PACKAGE_VERSION = 1.0 >> + >> +[Guids] >> + gBcmNetTokenSpaceGuid = {0x12b97d70, 0x9149, 0x4c2f, {0x82, 0xd5, 0xad, 0xa9, 0x1e, 0x92, 0x75, 0xa1}} >> + >> +[PcdsFixedAtBuild] >> + gBcmNetTokenSpaceGuid.PcdBcmGenetRegistersAddress|0x0|UINT32|0x00000001 >> + > > Can we make this UINT64 please? EFI_PHYSICAL_ADDRESSes are 64-bit in UEFI. Will do. /Pete > >> +[PcdsDynamic] >> + gBcmNetTokenSpaceGuid.PcdBcmGenetMacAddress|0x0|UINT64|0x00000002 >> -- >> 2.21.0.windows.1 >>