public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Samer El-Haj-Mahmoud" <samer.el-haj-mahmoud@arm.com>
To: devel@edk2.groups.io
Cc: Pete Batard <pete@akeo.ie>, Leif Lindholm <leif@nuviainc.com>,
	Ard Biesheuvel <ard.biesheuvel@arm.com>,
	Andrei Warkentin <awarkentin@vmware.com>,
	Jared McNeill <jmcneill@invisible.ca>
Subject: [edk2-platform][PATCH v1 4/6] Platform/RaspberryPi: Register GENET platform device protocol
Date: Fri,  8 May 2020 16:45:36 -0400	[thread overview]
Message-ID: <20200508204538.15650-5-Samer.El-Haj-Mahmoud@arm.com> (raw)
In-Reply-To: <20200508204538.15650-1-Samer.El-Haj-Mahmoud@arm.com>

Register an event at EndOfDxe to instantiate the EFI device path protocol
with the GENET MAC address on a new handle, and install the
BcmGenetPlatformDeviceProtocol on that handle. This protocol is used to
pass platform information (GENET MAC address and register base address)
to the GENET driver, which will consume this in its implementation of the
UEFI driver model Supported/Start/Stop methods.

Cc: Pete Batard <pete@akeo.ie>
Cc: Leif Lindholm <leif@nuviainc.com>
Cc: Ard Biesheuvel <ard.biesheuvel@arm.com>
Cc: Andrei Warkentin <awarkentin@vmware.com>
Cc: Jared McNeill <jmcneill@invisible.ca>
Co-authored-by: Samer El-Haj-Mahmoud <samer.el-haj-mahmoud@arm.com>
Co-authored-by: Ard Biesheuvel <ard.biesheuvel@arm.com>
Co-authored-by: Andrei Warkentin <awarkentin@vmware.com>
Signed-off-by: Samer El-Haj-Mahmoud <samer.el-haj-mahmoud@arm.com>
---
 Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.inf |  29 ++++--
 Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.c   | 108 ++++++++++++++++++--
 2 files changed, 117 insertions(+), 20 deletions(-)

diff --git a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.inf b/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.inf
index 57963baf9c90..e01f53de5dd6 100644
--- a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.inf
+++ b/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.inf
@@ -1,6 +1,8 @@
 #/** @file
 #
-#  Copyright (c) 2019, ARM Limited. All rights reserved.
+#  Component description file for the RasbperryPi DXE platform config driver.
+#
+#  Copyright (c) 2019 - 2020, ARM Limited. All rights reserved.
 #  Copyright (c) 2018, Andrei Warkentin <andrey.warkentin@gmail.com>
 #
 #  SPDX-License-Identifier: BSD-2-Clause-Patent
@@ -21,7 +23,6 @@
 #
 #  VALID_ARCHITECTURES           = AARCH64
 #
-
 [Sources]
   ConfigDxe.c
   ConfigDxeFormSetGuid.h
@@ -31,31 +32,36 @@
 [Packages]
   ArmPkg/ArmPkg.dec
   ArmPlatformPkg/ArmPlatformPkg.dec
-  MdePkg/MdePkg.dec
+  EmbeddedPkg/EmbeddedPkg.dec
   MdeModulePkg/MdeModulePkg.dec
+  MdePkg/MdePkg.dec
+  NetworkPkg/NetworkPkg.dec
+  Platform/RaspberryPi/RaspberryPi.dec
   Silicon/Broadcom/Bcm27xx/Bcm27xx.dec
   Silicon/Broadcom/Bcm283x/Bcm283x.dec
-  Platform/RaspberryPi/RaspberryPi.dec
-  EmbeddedPkg/EmbeddedPkg.dec
+  Silicon/Broadcom/Drivers/Net/BcmNet.dec
 
 [LibraryClasses]
+  AcpiLib
   BaseLib
   DebugLib
   DxeServicesTableLib
+  GpioLib
+  HiiLib
+  NetLib
   PcdLib
   UefiBootServicesTableLib
-  UefiRuntimeServicesTableLib
   UefiDriverEntryPoint
-  HiiLib
-  GpioLib
-  AcpiLib
+  UefiRuntimeServicesTableLib
 
 [Guids]
   gConfigDxeFormSetGuid
+  gEfiEndOfDxeEventGroupGuid
 
 [Protocols]
-  gRaspberryPiFirmwareProtocolGuid      ## CONSUMES
-  gRaspberryPiConfigAppliedProtocolGuid ## PRODUCES
+  gBcmGenetPlatformDeviceProtocolGuid             ## PRODUCES
+  gRaspberryPiFirmwareProtocolGuid                ## CONSUMES
+  gRaspberryPiConfigAppliedProtocolGuid           ## PRODUCES
 
 [FixedPcd]
   gRaspberryPiTokenSpaceGuid.PcdCpuLowSpeedMHz
@@ -64,6 +70,7 @@
 
 [Pcd]
   gBcm27xxTokenSpaceGuid.PcdBcm27xxRegistersAddress
+  gBcm27xxTokenSpaceGuid.PcdBcmGenetRegistersAddress
   gBcm283xTokenSpaceGuid.PcdBcm283xRegistersAddress
   gRaspberryPiTokenSpaceGuid.PcdCpuClock
   gRaspberryPiTokenSpaceGuid.PcdCustomCpuClock
diff --git a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.c b/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.c
index c90c25309872..f8ba0db3ba27 100644
--- a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.c
+++ b/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.c
@@ -1,6 +1,6 @@
 /** @file
  *
- *  Copyright (c) 2019, ARM Limited. All rights reserved.
+ *  Copyright (c) 2019 - 2020, ARM Limited. All rights reserved.
  *  Copyright (c) 2018 - 2019, Andrei Warkentin <andrey.warkentin@gmail.com>
  *
  *  SPDX-License-Identifier: BSD-2-Clause-Patent
@@ -8,19 +8,21 @@
  **/
 
 #include <Uefi.h>
+#include <IndustryStandard/Bcm2711.h>
+#include <IndustryStandard/Bcm2836.h>
+#include <IndustryStandard/Bcm2836Gpio.h>
+#include <IndustryStandard/RpiMbox.h>
 #include <Library/AcpiLib.h>
-#include <Library/HiiLib.h>
 #include <Library/DebugLib.h>
+#include <Library/DevicePathLib.h>
 #include <Library/DxeServicesTableLib.h>
+#include <Library/GpioLib.h>
+#include <Library/HiiLib.h>
 #include <Library/IoLib.h>
+#include <Library/NetLib.h>
 #include <Library/UefiBootServicesTableLib.h>
 #include <Library/UefiRuntimeServicesTableLib.h>
-#include <Library/DevicePathLib.h>
-#include <IndustryStandard/RpiMbox.h>
-#include <IndustryStandard/Bcm2711.h>
-#include <IndustryStandard/Bcm2836.h>
-#include <IndustryStandard/Bcm2836Gpio.h>
-#include <Library/GpioLib.h>
+#include <Protocol/BcmGenetPlatformDevice.h>
 #include <Protocol/RpiFirmware.h>
 #include "ConfigDxeFormSetGuid.h"
 
@@ -33,6 +35,8 @@ STATIC RASPBERRY_PI_FIRMWARE_PROTOCOL *mFwProtocol;
 STATIC UINT32 mModelFamily = 0;
 STATIC UINT32 mModelInstalledMB = 0;
 
+STATIC EFI_MAC_ADDRESS  MacAddress;
+
 /*
  * The GUID inside Platform/RaspberryPi/RPi3/AcpiTables/AcpiTables.inf and
  * Platform/RaspberryPi/RPi4/AcpiTables/AcpiTables.inf _must_ match below.
@@ -46,6 +50,18 @@ typedef struct {
   EFI_DEVICE_PATH_PROTOCOL End;
 } HII_VENDOR_DEVICE_PATH;
 
+#pragma pack (1)
+typedef struct {
+  MAC_ADDR_DEVICE_PATH            MacAddrDP;
+  EFI_DEVICE_PATH_PROTOCOL        End;
+} GENET_DEVICE_PATH;
+
+typedef struct {
+  GENET_DEVICE_PATH                   DevicePath;
+  BCM_GENET_PLATFORM_DEVICE_PROTOCOL  PlatformDevice;
+} GENET_DEVICE;
+#pragma pack ()
+
 STATIC HII_VENDOR_DEVICE_PATH mVendorDevicePath = {
   {
     {
@@ -68,6 +84,65 @@ STATIC HII_VENDOR_DEVICE_PATH mVendorDevicePath = {
   }
 };
 
+STATIC GENET_DEVICE mGenetDevice = {
+  {
+    {
+      {
+        MESSAGING_DEVICE_PATH,
+        MSG_MAC_ADDR_DP,
+        {
+          (UINT8)(sizeof (MAC_ADDR_DEVICE_PATH)),
+          (UINT8)((sizeof (MAC_ADDR_DEVICE_PATH)) >> 8)
+        }
+      },
+      {{ 0 }},
+      NET_IFTYPE_ETHERNET
+    },
+    {
+      END_DEVICE_PATH_TYPE,
+      END_ENTIRE_DEVICE_PATH_SUBTYPE,
+      {
+        sizeof (EFI_DEVICE_PATH_PROTOCOL),
+        0
+      }
+    }
+  },
+  {
+    GENET_BASE_ADDRESS,
+    {{ 0 }}
+  }
+};
+
+
+STATIC
+VOID
+EFIAPI
+RegisterDevices (
+  EFI_EVENT           Event,
+  VOID                *Context
+  )
+{
+  EFI_HANDLE  Handle;
+  EFI_STATUS  Status;
+
+  if (mModelFamily == 4) {
+    DEBUG ((DEBUG_INFO, "GENET: MAC address %02X:%02X:%02X:%02X:%02X:%02X\n",
+            MacAddress.Addr[0], MacAddress.Addr[1], MacAddress.Addr[2],
+            MacAddress.Addr[3], MacAddress.Addr[4], MacAddress.Addr[5]));
+
+    CopyMem (&mGenetDevice.DevicePath.MacAddrDP.MacAddress, MacAddress.Addr,
+      NET_ETHER_ADDR_LEN);
+    CopyMem (&mGenetDevice.PlatformDevice.MacAddress, MacAddress.Addr,
+      NET_ETHER_ADDR_LEN);
+
+    Handle = NULL;
+    Status = gBS->InstallMultipleProtocolInterfaces (&Handle,
+                    &gEfiDevicePathProtocolGuid,          &mGenetDevice.DevicePath,
+                    &gBcmGenetPlatformDeviceProtocolGuid, &mGenetDevice.PlatformDevice,
+                    NULL);
+    ASSERT_EFI_ERROR (Status);
+  }
+}
 
 STATIC EFI_STATUS
 InstallHiiPages (
@@ -241,6 +316,16 @@ SetupVariables (
     PcdSet32 (PcdDisplayEnableSShot, PcdGet32 (PcdDisplayEnableSShot));
   }
 
+  if (mModelFamily == 4) {
+    //
+    // Get the MAC address from the firmware.
+    //
+    Status = mFwProtocol->GetMacAddress (MacAddress.Addr);
+    if (EFI_ERROR (Status)) {
+      DEBUG ((DEBUG_WARN, "%a: failed to retrieve MAC address\n", __FUNCTION__));
+    }
+  }
+
   return EFI_SUCCESS;
 }
 
@@ -447,7 +532,8 @@ ConfigInitialize (
   IN EFI_SYSTEM_TABLE *SystemTable
   )
 {
-  EFI_STATUS Status;
+  EFI_STATUS                      Status;
+  EFI_EVENT                       EndOfDxeEvent;
 
   Status = gBS->LocateProtocol (&gRaspberryPiFirmwareProtocolGuid,
                   NULL, (VOID**)&mFwProtocol);
@@ -490,5 +576,9 @@ ConfigInitialize (
   Status = LocateAndInstallAcpiFromFv (&mAcpiTableFile);
   ASSERT_EFI_ERROR (Status);
 
+  Status = gBS->CreateEventEx (EVT_NOTIFY_SIGNAL, TPL_NOTIFY, RegisterDevices,
+                  NULL, &gEfiEndOfDxeEventGroupGuid, &EndOfDxeEvent);
+  ASSERT_EFI_ERROR (Status);
+
   return EFI_SUCCESS;
 }
-- 
2.17.1


  parent reply	other threads:[~2020-05-08 20:45 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-08 20:45 [edk2-platform][PATCH v1 0/6] Add Broadcom GENET driver for RPi4 Samer El-Haj-Mahmoud
2020-05-08 20:45 ` [edk2-platform][PATCH v1 1/6] Silicon/Broadcom: Add BcmGenetPlatformDevice protocol Samer El-Haj-Mahmoud
2020-05-08 20:45 ` [edk2-platform][PATCH v1 2/6] Silicon/Broadcom: BcmGenetDxe : Add GENET driver Samer El-Haj-Mahmoud
2020-05-08 20:45 ` [edk2-platform][PATCH v1 3/6] Platform/RaspberryPi: Clean up PCDs out of the " Samer El-Haj-Mahmoud
2020-05-08 20:45 ` Samer El-Haj-Mahmoud [this message]
2020-05-08 20:45 ` [edk2-platform][PATCH v1 5/6] Platform/RaspberryPi: Remove PlatformPcdLib Samer El-Haj-Mahmoud
2020-05-08 20:45 ` [edk2-platform][PATCH v1 6/6] Platform/RaspberryPi: set DMA translation for BCM Genet driver Samer El-Haj-Mahmoud

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200508204538.15650-5-Samer.El-Haj-Mahmoud@arm.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox