public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Chandni Cherukuri <chandni.cherukuri@arm.com>
To: devel@edk2.groups.io
Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>,
	Leif Lindholm <leif@nuviainc.com>,
	Sami Mujawar <sami.mujawar@arm.com>
Subject: [edk2-platforms][PATCH V1 3/5] Platform/ARM/Morello: Add PlatformDxe driver for Morello
Date: Wed, 24 Feb 2021 18:42:22 +0530	[thread overview]
Message-ID: <20210224131224.11481-4-chandni.cherukuri@arm.com> (raw)
In-Reply-To: <20210224131224.11481-1-chandni.cherukuri@arm.com>

From: Anurag Koul <anurag.koul@arm.com>

This patch adds the PlatformDxe Driver for Morello
platform. It includes the registration of the ramdisk
device.

Co-authored-by: Chandni Cherukuri <chandni.cherukuri@arm.com>
Signed-off-by: Chandni Cherukuri <chandni.cherukuri@arm.com>
---
 Platform/ARM/Morello/Drivers/PlatformDxe/PlatformDxeFvp.inf     | 43 +++++++++
 Platform/ARM/Morello/Include/Guid/MorelloVirtioDevicesFormSet.h | 14 +++
 Platform/ARM/Morello/Drivers/PlatformDxe/PlatformDxeFvp.c       | 58 +++++++++++++
 Platform/ARM/Morello/Drivers/PlatformDxe/VirtioDevices.c        | 91 ++++++++++++++++++++
 4 files changed, 206 insertions(+)

diff --git a/Platform/ARM/Morello/Drivers/PlatformDxe/PlatformDxeFvp.inf b/Platform/ARM/Morello/Drivers/PlatformDxe/PlatformDxeFvp.inf
new file mode 100644
index 000000000000..69df9019cde3
--- /dev/null
+++ b/Platform/ARM/Morello/Drivers/PlatformDxe/PlatformDxeFvp.inf
@@ -0,0 +1,43 @@
+## @file
+#
+#  Copyright (c) 2021, ARM Limited. All rights reserved.<BR>
+#
+#  SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+  INF_VERSION                    = 0x0001001A
+  BASE_NAME                      = PlatformDxe
+  FILE_GUID                      = 11FC8B5A-377D-47A8-AEE9-0093D3D3407F
+  MODULE_TYPE                    = DXE_DRIVER
+  VERSION_STRING                 = 1.0
+  ENTRY_POINT                    = ArmMorelloEntryPoint
+
+[Sources.common]
+  PlatformDxeFvp.c
+  VirtioDevices.c
+
+[Packages]
+  MdePkg/MdePkg.dec
+  OvmfPkg/OvmfPkg.dec
+  Platform/ARM/Morello/MorelloPlatform.dec
+
+[LibraryClasses]
+  UefiDriverEntryPoint
+  VirtioMmioDeviceLib
+
+[Protocols]
+  gEfiRamDiskProtocolGuid
+
+[FeaturePcd]
+  gArmMorelloTokenSpaceGuid.PcdRamDiskSupported
+  gArmMorelloTokenSpaceGuid.PcdVirtioBlkSupported
+
+[FixedPcd]
+  gArmMorelloTokenSpaceGuid.PcdRamDiskBase
+  gArmMorelloTokenSpaceGuid.PcdRamDiskSize
+  gArmMorelloTokenSpaceGuid.PcdVirtioBlkBaseAddress
+
+[Depex]
+  gEfiRamDiskProtocolGuid
diff --git a/Platform/ARM/Morello/Include/Guid/MorelloVirtioDevicesFormSet.h b/Platform/ARM/Morello/Include/Guid/MorelloVirtioDevicesFormSet.h
new file mode 100644
index 000000000000..27ae61bb1cf5
--- /dev/null
+++ b/Platform/ARM/Morello/Include/Guid/MorelloVirtioDevicesFormSet.h
@@ -0,0 +1,14 @@
+/** @file
+
+  Copyright (c) 2021, ARM Limited. All rights reserved.<BR>
+
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#ifndef  MORELLO_VIRTIO_DEVICES_FORMSET_H__
+#define  MORELLO_VIRTIO_DEVICES_FORMSET_H__
+
+#define MORELLO_VIRTIO_BLOCK_GUID  \
+  { 0x2B6E62D0, 0x9346, 0x4E1A, { 0xAA, 0x1E, 0xCB, 0x01, 0xC3, 0x23, 0x4A, 0x00 } }
+
+#endif
diff --git a/Platform/ARM/Morello/Drivers/PlatformDxe/PlatformDxeFvp.c b/Platform/ARM/Morello/Drivers/PlatformDxe/PlatformDxeFvp.c
new file mode 100644
index 000000000000..ff99c16b2c9a
--- /dev/null
+++ b/Platform/ARM/Morello/Drivers/PlatformDxe/PlatformDxeFvp.c
@@ -0,0 +1,58 @@
+/** @file
+
+  Copyright (c) 2021, ARM Limited. All rights reserved.<BR>
+
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#include <Library/DebugLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+#include <Protocol/RamDisk.h>
+
+VOID
+InitVirtioDevices (
+  VOID
+  );
+
+EFI_STATUS
+EFIAPI
+ArmMorelloEntryPoint (
+  IN EFI_HANDLE         ImageHandle,
+  IN EFI_SYSTEM_TABLE   *SystemTable
+  )
+{
+  EFI_STATUS                 Status;
+  EFI_RAM_DISK_PROTOCOL      *RamDisk;
+  EFI_DEVICE_PATH_PROTOCOL   *DevicePath;
+
+  Status = EFI_SUCCESS;
+
+  InitVirtioDevices ();
+
+  if (FeaturePcdGet (PcdRamDiskSupported)) {
+    Status = gBS->LocateProtocol (
+                    &gEfiRamDiskProtocolGuid,
+                    NULL,
+                    (VOID**)&RamDisk
+                    );
+    if (EFI_ERROR (Status)) {
+      DEBUG ((DEBUG_ERROR, "Couldn't find the RAM Disk protocol %r\n",
+        __FUNCTION__, Status));
+      return Status;
+    }
+
+    Status = RamDisk->Register (
+                        (UINTN)PcdGet32 (PcdRamDiskBase),
+                        (UINTN)PcdGet32 (PcdRamDiskSize),
+                        &gEfiVirtualCdGuid,
+                        NULL,
+                        &DevicePath
+                        );
+    if (EFI_ERROR (Status)) {
+      DEBUG ((DEBUG_ERROR, "%a: Failed to register RAM Disk - %r\n",
+        __FUNCTION__, Status));
+    }
+  }
+
+  return Status;
+}
diff --git a/Platform/ARM/Morello/Drivers/PlatformDxe/VirtioDevices.c b/Platform/ARM/Morello/Drivers/PlatformDxe/VirtioDevices.c
new file mode 100644
index 000000000000..a83a4e71a47e
--- /dev/null
+++ b/Platform/ARM/Morello/Drivers/PlatformDxe/VirtioDevices.c
@@ -0,0 +1,91 @@
+/** @file
+
+  Copyright (c) 2021, ARM Limited. All rights reserved.<BR>
+
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#include <Guid/MorelloVirtioDevicesFormSet.h>
+#include <Library/VirtioMmioDeviceLib.h>
+#include <Library/DebugLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+
+#pragma pack (1)
+typedef struct {
+  VENDOR_DEVICE_PATH                  VendorDevicePath;
+  EFI_DEVICE_PATH_PROTOCOL            End;
+} VIRTIO_DEVICE_PATH;
+#pragma pack ()
+
+STATIC VIRTIO_DEVICE_PATH mVirtioBlockDevicePath =
+{
+  {
+    {
+      HARDWARE_DEVICE_PATH,
+      HW_VENDOR_DP,
+      {
+        (UINT8)(sizeof (VENDOR_DEVICE_PATH)),
+        (UINT8)((sizeof (VENDOR_DEVICE_PATH)) >> 8)
+      }
+    },
+    MORELLO_VIRTIO_BLOCK_GUID,
+  },
+  {
+    END_DEVICE_PATH_TYPE,
+    END_ENTIRE_DEVICE_PATH_SUBTYPE,
+    {
+      sizeof (EFI_DEVICE_PATH_PROTOCOL),
+      0
+    }
+  }
+};
+
+//
+//  Initialize platform Virtio devices.
+//
+//  @return None.
+//
+VOID
+InitVirtioDevices (
+  VOID
+  )
+{
+  EFI_STATUS Status;
+  STATIC EFI_HANDLE mVirtIoBlkController = NULL;
+
+  Status = EFI_SUCCESS;
+
+  // Install protocol interface for storage device
+  if (FeaturePcdGet (PcdVirtioBlkSupported)) {
+
+    Status = gBS->InstallProtocolInterface (
+                    &mVirtIoBlkController,
+                    &gEfiDevicePathProtocolGuid,
+                    EFI_NATIVE_INTERFACE,
+                    &mVirtioBlockDevicePath
+                    );
+    if (EFI_ERROR (Status)) {
+      DEBUG ((DEBUG_ERROR, "%a: Failed to install EFI_DEVICE_PATH protocol "
+        "for Virtio Block device (Status = %r)\n",
+        __FUNCTION__, Status));
+    } else {
+      // Declare the Virtio BlockIo device
+      Status = VirtioMmioInstallDevice (
+                 FixedPcdGet32 (PcdVirtioBlkBaseAddress),
+                 mVirtIoBlkController
+                 );
+      if (EFI_ERROR (Status)) {
+        DEBUG ((DEBUG_ERROR, "%a: Unable to find Virtio Block MMIO device "
+          "(Status == %r)\n", __FUNCTION__, Status));
+        gBS->UninstallProtocolInterface (
+               mVirtIoBlkController,
+               &gEfiDevicePathProtocolGuid,
+               &mVirtioBlockDevicePath
+               );
+      } else {
+        DEBUG ((DEBUG_INIT, "%a: Installed Virtio Block device\n",
+          __FUNCTION__));
+      }
+    }
+  }
+}
-- 
2.17.1


  parent reply	other threads:[~2021-02-24 13:12 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-24 13:12 [edk2-platforms][PATCH V1 0/5] Add Morello FVP platform support Chandni Cherukuri
2021-02-24 13:12 ` [edk2-platforms][PATCH V1 1/5] Platform/ARM/Morello: Add Platform library implementation Chandni Cherukuri
2021-02-26 18:35   ` [edk2-devel] " Thomas Abraham
2021-03-01  5:21     ` chandni.cherukuri
2021-03-01 13:13   ` Sami Mujawar
2021-02-24 13:12 ` [edk2-platforms][PATCH V1 2/5] Platform/ARM/Morello: Add support for PciHostBridgeLib Chandni Cherukuri
2021-03-01 13:13   ` Sami Mujawar
2021-02-24 13:12 ` Chandni Cherukuri [this message]
2021-03-01 13:13   ` [edk2-platforms][PATCH V1 3/5] Platform/ARM/Morello: Add PlatformDxe driver for Morello Sami Mujawar
2021-02-24 13:12 ` [edk2-platforms][PATCH V1 4/5] Platform/ARM/Morello: Add Configuration Manager " Chandni Cherukuri
2021-03-01 13:13   ` Sami Mujawar
2021-03-05 23:32     ` Sami Mujawar
2021-02-24 13:12 ` [edk2-platforms][PATCH V1 5/5] Platform/ARM/Morello: Add initial support for Morello Platform Chandni Cherukuri
2021-03-01 13:13   ` Sami Mujawar
2021-03-01 13:13 ` [edk2-platforms][PATCH V1 0/5] Add Morello FVP platform support Sami Mujawar

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=20210224131224.11481-4-chandni.cherukuri@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