From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f68.google.com (mail-wm1-f68.google.com [209.85.128.68]) by mx.groups.io with SMTP id smtpd.web09.6560.1579780823129833984 for ; Thu, 23 Jan 2020 04:00:23 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@akeo-ie.20150623.gappssmtp.com header.s=20150623 header.b=neTdZ6g6; spf=none, err=permanent DNS error (domain: akeo.ie, ip: 209.85.128.68, mailfrom: pete@akeo.ie) Received: by mail-wm1-f68.google.com with SMTP id b19so2266139wmj.4 for ; Thu, 23 Jan 2020 04:00:22 -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=aFlNasZkxS5/qaB0BYlswyrq3TDz1pBj9GnazDmEo8E=; b=neTdZ6g6o0+WpWJJhDI6JPG3FzRDLgxmMDsTIXQ2UEtRKl0Cw5dt/jGov5g+jCYrXn sD4t8cKC11ApHD5Vb0lEemoIGIZoymrMt4R/I+FQOBNzX+KJR8V+OrpPVWpkcCahPqgd g6KBG4aOfg/phsCv9LHbn7XdzNS9mDuKMSN6hRTEgAXQVRE3cYnMAjZl8IiJNl7IigsY zk1WMbAk/CXLGZxRZcuKOr9dBbcZ8EnMhV8FYtkMGlGBMS8EAaBjBwAOE2G+jA2HuO1q Jft/QDNAF3Sxa0/2XQUeXCrDgT01XmREI8ds1Wl40EnI0/Og7h70KQ6+cutvaT1UHY8n 1ZBQ== 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=aFlNasZkxS5/qaB0BYlswyrq3TDz1pBj9GnazDmEo8E=; b=apAgBy/f1C08oRg25CZ3DpnLrio8KgPfU3OQSUXrXChJeGiTImvCEOQsFaMELwhm0x Jzy7PFOOMBQOKO93QahnDx3XJuyzeG9IUY+0SjhYX95HvTVY5eBnDNeqMTCeYXlENjFk yBH0dR6BDe4LZjAyTmDfNbuiDsRu3iuVIH+zv4dE2aQq7H/cXvhty6VnkEnv5vrL9vH6 crSKO/Ag0m/FXsfvwJ397a8ccMZ3Px8UziHh1GEq5hxwoOr2m2S6SpFYJz7tGr6D8UdM g8rsxrnXQPbcfIH9MfCD3eZbEPEchRfAbY6kQRaQ7fEXqsc1539Ns15WbPJ9z21mAK7H S8RA== X-Gm-Message-State: APjAAAXN25u9U4/QEG34e91iwTEL2KrcrLEk9BdazuG3QnR98ZO7hdwm UBHHUgTmNqPfbiviQMN4h8/uN393PQ4= X-Google-Smtp-Source: APXvYqyjarzOKvyJOrBSUIep1i3GrFbNin2ZxF9CqUeCNC6VYAVw8QmU2xhYCbevxs6Sb29m7juWhQ== X-Received: by 2002:a1c:6588:: with SMTP id z130mr3853873wmb.0.1579780821506; Thu, 23 Jan 2020 04:00:21 -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.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 23 Jan 2020 04:00:20 -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-platforms][PATCH 2/3] Platform/RPi: Add PlatformPcdLib to set the Genet MAC address Date: Thu, 23 Jan 2020 12:00:04 +0000 Message-Id: <20200123120007.4784-3-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 The Genet driver stub used by the Raspberry Pi 4 platform is designed to set the MAC address according to a PCD. To be able to set that PCD at runtime, by using the Raspberry Pi firmware interface, that has a dedicated call to retrieve the MAC address, and satisfy driver dependencies in a generic manner, we create a new PlatformPcdLib that can be referenced by the Genet driver, to set the MAC PCD before use there. While it is currently only tailored around MAC PCD population for Genet, we do expect this PCD library to be extended in the future, to provide additional PCD facilities for other drivers. Signed-off-by: Pete Batard --- Platform/RaspberryPi/Library/PlatformPcdLib/PlatformPcdLib.c | 61 ++++++++++++++++++++ Platform/RaspberryPi/Library/PlatformPcdLib/PlatformPcdLib.inf | 44 ++++++++++++++ 2 files changed, 105 insertions(+) diff --git a/Platform/RaspberryPi/Library/PlatformPcdLib/PlatformPcdLib.c b/Platform/RaspberryPi/Library/PlatformPcdLib/PlatformPcdLib.c new file mode 100644 index 000000000000..78f3679e2e48 --- /dev/null +++ b/Platform/RaspberryPi/Library/PlatformPcdLib/PlatformPcdLib.c @@ -0,0 +1,61 @@ +/** @file + * + * Copyright (c) 2020, Pete Batard + * + * SPDX-License-Identifier: BSD-2-Clause-Patent + * + **/ + +#include +#include +#include +#include +#include +#include +#include + +EFI_STATUS +EFIAPI +PlatformPcdLibConstructor ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + + // + // If Genet is in use and a MAC address PCD has not been set, do it here. + // +#if (FixedPcdGet64 (PcdBcmGenetRegistersAddress) != 0) + EFI_STATUS Status; + UINT64 MacAddr; + RASPBERRY_PI_FIRMWARE_PROTOCOL *mFwProtocol; + + if (PcdGet64 (PcdBcmGenetMacAddress) == 0) { + Status = gBS->LocateProtocol (&gRaspberryPiFirmwareProtocolGuid, NULL, + (VOID**)&mFwProtocol); + ASSERT_EFI_ERROR(Status); + + // + // Get the MAC address from the firmware + // + Status = mFwProtocol->GetMacAddress ((UINT8*) &MacAddr); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_WARN, "%a: failed to retrieve MAC address\n", __FUNCTION__)); + } else { + PcdSet64 (PcdBcmGenetMacAddress, MacAddr); + } + } +#endif + + return EFI_SUCCESS; +} + +EFI_STATUS +EFIAPI +PlatformPcdLibDestructor ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + return EFI_SUCCESS; +} diff --git a/Platform/RaspberryPi/Library/PlatformPcdLib/PlatformPcdLib.inf b/Platform/RaspberryPi/Library/PlatformPcdLib/PlatformPcdLib.inf new file mode 100644 index 000000000000..a564ddfbb2a3 --- /dev/null +++ b/Platform/RaspberryPi/Library/PlatformPcdLib/PlatformPcdLib.inf @@ -0,0 +1,44 @@ +#/** @file +# +# Copyright (c) 2020, Pete Batard +# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +#**/ + +[Defines] + INF_VERSION = 0x0001001A + BASE_NAME = PlatformPcdLib + FILE_GUID = 3B8409D7-D3C7-4006-823B-BFB184435363 + MODULE_TYPE = DXE_DRIVER + VERSION_STRING = 1.0 + LIBRARY_CLASS = NULL|DXE_DRIVER UEFI_APPLICATION + CONSTRUCTOR = PlatformPcdLibConstructor + DESTRUCTOR = PlatformPcdLibDestructor + +[Sources] + PlatformPcdLib.c + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + Platform/RaspberryPi/RaspberryPi.dec + Silicon/Broadcom/Drivers/Net/BcmNet.dec + +[LibraryClasses] + UefiLib + DebugLib + PrintLib + +[Protocols] + gRaspberryPiFirmwareProtocolGuid ## CONSUMES + +[Pcd] + gBcmNetTokenSpaceGuid.PcdBcmGenetMacAddress ## SOMETIMES_PRODUCES + +[FixedPcd] + gBcmNetTokenSpaceGuid.PcdBcmGenetRegistersAddress + +[Depex] + gPcdProtocolGuid AND gRaspberryPiFirmwareProtocolGuid + -- 2.21.0.windows.1