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.web09.11746.1579866869458401001 for ; Fri, 24 Jan 2020 03:54:29 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@akeo-ie.20150623.gappssmtp.com header.s=20150623 header.b=zwN8q0GV; 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 q10so1620449wrm.11 for ; Fri, 24 Jan 2020 03:54:29 -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=MbRTZmg0XU5B81xiYZKH0+cjr2B9TIcYngdIYNWIXZI=; b=zwN8q0GVeAMYJwIRBVm85+M44H+Emcn+n6hSS0vPohIvEhXNizD2OyYTxpZI+oxORK KLeAVvLfclFMjkTQ3SG3a5JovT7tIiFS/DSjP0bJZSvIAdk0N3EzLzmF218OUcFAF5xZ zCef5Sih5j/QEAqUPBQRAZuAIrpkCfx3T/Q7xvIFskotDfBkW8929v+LFzuTVp46IG5o VJ+Pc/jah48CYlxcC2HZzigWVF5vgn9iYUfPsp1HVaPf0xSo/+86rvRZv6RqZlyn5jjk 9DNoawecHb756ASpptJWCKilksjQHYeoU/z3V0XWVPp0ajvaHKpzBF2UTGNcv/eulDdH FWdw== 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=MbRTZmg0XU5B81xiYZKH0+cjr2B9TIcYngdIYNWIXZI=; b=DHjsX4lhL0mYaSsRxq5QsjZ/FOX7+3a0Wl1HNB+uvUJHCzZlpn0E19FYjZD0BS0ua/ /n4R07wsBwyh/sacQTwfHJRoH/ps1WJiB/F1/Ha/AM8WCsL8cA2zGy/jOMX7il9bP/td L6D88kq477uvbZjVVJXqj4nf3zo9/DCmNAjxd1Fns47fdxt0cIUSm30kEqo3ZVAFIVaN fICZg5KcpZD8RiuY7UKXlUtq3yHwWXITVItqmZIG5GerU9mQiA1feJnrgtHmQQAqCN2Q NfkKs4ILfva2Om89pBPbZzTlbdS1RDvqsOf6piIzjZtTFjlxSvDDE2SuJICw3EqXK0HT s95w== X-Gm-Message-State: APjAAAVwrgpQirDwW+9ZGzHYTK4syX+ceEo/q10i4bS6B+sFFYhOPFCP gt6hzxRD39f/tF5iAkEfPEH4FesLOjg= X-Google-Smtp-Source: APXvYqzxvn4BuRpw7n+e9wPtHNlYDJ1+6zTPjhSbI3iI+oAo0Whw+G2fPF+9teZ0kRa/SDwY4GZHhQ== X-Received: by 2002:adf:dd4d:: with SMTP id u13mr4192829wrm.394.1579866867810; Fri, 24 Jan 2020 03:54:27 -0800 (PST) Return-Path: Received: from localhost.localdomain ([84.203.49.247]) by smtp.gmail.com with ESMTPSA id p17sm7003840wrx.20.2020.01.24.03.54.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 24 Jan 2020 03:54:27 -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 v2 2/3] Platform/RPi: Add PlatformPcdLib to set the Genet MAC address Date: Fri, 24 Jan 2020 11:54:10 +0000 Message-Id: <20200124115411.9364-3-pete@akeo.ie> X-Mailer: git-send-email 2.21.0.windows.1 In-Reply-To: <20200124115411.9364-1-pete@akeo.ie> References: <20200124115411.9364-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 | 51 ++++++++++++++++++++ Platform/RaspberryPi/Library/PlatformPcdLib/PlatformPcdLib.inf | 43 +++++++++++++++++ 2 files changed, 94 insertions(+) diff --git a/Platform/RaspberryPi/Library/PlatformPcdLib/PlatformPcdLib.c b/Platform/RaspberryPi/Library/PlatformPcdLib/PlatformPcdLib.c new file mode 100644 index 000000000000..792073a903e9 --- /dev/null +++ b/Platform/RaspberryPi/Library/PlatformPcdLib/PlatformPcdLib.c @@ -0,0 +1,51 @@ +/** @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 { + PcdSet64S (PcdBcmGenetMacAddress, MacAddr); + } + } +#endif + + 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