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.6520.1580735654972821189 for ; Mon, 03 Feb 2020 05:14:15 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@akeo-ie.20150623.gappssmtp.com header.s=20150623 header.b=Ts0lqMT1; 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 j104so18051738wrj.7 for ; Mon, 03 Feb 2020 05:14:14 -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=col0z5Wj/GlLEz0wpfh5Ay8oWt4TDaju06vjkwkE6n8=; b=Ts0lqMT1+mo9xO0NAHdwJd0vgDzUSGgXuqbZ7/FJ1AbauHFSQcxB8Fl3f4W482h+QK Vn559l7yuabmhG+vaCCwwM4Tna/DANZcnTrVOQe3G44dUXB2EPOONpjOfJWkpnuEsQl+ FpfqrAXHfcwHoHeAu0WqKSMn7xXqFwGn8NIErL00JD1hTTdNtpTnSwYCu9hOadd5Tc+z aRZ8EUj9F8c/Z7GSb5mo4Ih6kRUWvL4RYGX4wg4r6KosSdDhIigGsEIwCp7VJk0unOaQ uqAxh6cN2n5K9oRsIDNyKWu2ge6setxnSyK53lDE1iV37VXRdP5CQD6Www1g20Dxkf2X G+yQ== 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=col0z5Wj/GlLEz0wpfh5Ay8oWt4TDaju06vjkwkE6n8=; b=go4YrWsbaTw6P9Sr+LqBYSn3wI/lngfAOeL7u4vrenalsc4Ywq1ZpXfDifmvq7tnLM JT4vqdsfOZefWRs8kchF63DJyJ/SQYaOWLPxT3SEcIId8sHtjOt9o0nlHROn5O7M6zNO 87O8IIELm3Hd9TP07wQmwrPC5Sv/bSggN878IE9xTOJvQs4JL8J93C29xpARLcrK3u1/ 75TJcSyBpgO3WovkxdQ8dmtSZXSKm9IH+cfIdfhYtlB+Dr79Gi1KJDPdjgMGglxNEGGL jszFlgrSZVLfCvNQs49CGXYxARUEXcg3oMHCcspkg99wOL44aA1j8KlAQ4ZG6p08LrRb 47Zw== X-Gm-Message-State: APjAAAUYeWhg7GvZP+Cl+7UZZzR4BzQcpITihhVG+M7/8ybQER+LnDye o4ew6y6fAQFwkBJdZEaMp9wJIYceIHY= X-Google-Smtp-Source: APXvYqzTaeVDspaOMUCpxD29EBsztXSvREE01zxkKqFtozDYcgTwgseDVCxWZ88pcE9wfb2IPhp63A== X-Received: by 2002:a5d:68cf:: with SMTP id p15mr15062088wrw.31.1580735653364; Mon, 03 Feb 2020 05:14:13 -0800 (PST) Return-Path: Received: from localhost.localdomain ([84.203.49.247]) by smtp.gmail.com with ESMTPSA id k10sm1176950wrd.68.2020.02.03.05.14.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 03 Feb 2020 05:14:12 -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 v3 2/3] Platform/RPi: Add PlatformPcdLib to set the Genet MAC address Date: Mon, 3 Feb 2020 13:13:57 +0000 Message-Id: <20200203131358.16796-3-pete@akeo.ie> X-Mailer: git-send-email 2.21.0.windows.1 In-Reply-To: <20200203131358.16796-1-pete@akeo.ie> References: <20200203131358.16796-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 | 45 ++++++++++++++++++++ Platform/RaspberryPi/Library/PlatformPcdLib/PlatformPcdLib.inf | 43 +++++++++++++++++++ 2 files changed, 88 insertions(+) diff --git a/Platform/RaspberryPi/Library/PlatformPcdLib/PlatformPcdLib.c b/Platform/RaspberryPi/Library/PlatformPcdLib/PlatformPcdLib.c new file mode 100644 index 000000000000..e78518c81374 --- /dev/null +++ b/Platform/RaspberryPi/Library/PlatformPcdLib/PlatformPcdLib.c @@ -0,0 +1,45 @@ +/** @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 + ) +{ + 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 { + PcdSet64S (PcdBcmGenetMacAddress, MacAddr); + } + } + + 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..2a207d2b3e54 --- /dev/null +++ b/Platform/RaspberryPi/Library/PlatformPcdLib/PlatformPcdLib.inf @@ -0,0 +1,43 @@ +#/** @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 + +[Sources] + PlatformPcdLib.c + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + Platform/RaspberryPi/RaspberryPi.dec + Silicon/Broadcom/Drivers/Net/BcmNet.dec + +[LibraryClasses] + DebugLib + PcdLib + UefiLib + PrintLib + +[Protocols] + gRaspberryPiFirmwareProtocolGuid ## CONSUMES + +[Pcd] + gBcmNetTokenSpaceGuid.PcdBcmGenetMacAddress ## SOMETIMES_PRODUCES + +[FixedPcd] + gBcmNetTokenSpaceGuid.PcdBcmGenetRegistersAddress + +[Depex] + gRaspberryPiFirmwareProtocolGuid -- 2.21.0.windows.1