public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Albecki, Mateusz" <mateusz.albecki@intel.com>
To: devel@edk2.groups.io
Cc: Mateusz Albecki <mateusz.albecki@intel.com>,
	Hao A Wu <hao.a.wu@intel.com>
Subject: [PATCH 3/4] MdeModulePkg/UfsPassThruDxe: Refactor private data to use EDKII_UFS_HC_INFO
Date: Wed,  7 Aug 2019 18:51:06 +0200	[thread overview]
Message-ID: <20190807165107.688-4-mateusz.albecki@intel.com> (raw)
In-Reply-To: <20190807165107.688-1-mateusz.albecki@intel.com>

https://bugzilla.tianocore.org/show_bug.cgi?id=1343

Private data has been refactored to use EDKII_UFS_HC_INFO structure
to store host controller capabilities and version
information. Getting host controller data has been moved
into single place and is done before host controller enable.

Cc: Hao A Wu <hao.a.wu@intel.com>
Signed-off-by: Mateusz Albecki <mateusz.albecki@intel.com>
---
 MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThru.c  |  8 ++-
 MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThru.h  | 15 +++++-
 .../Bus/Ufs/UfsPassThruDxe/UfsPassThruHci.c        | 57 ++++++++++++++--------
 3 files changed, 57 insertions(+), 23 deletions(-)

diff --git a/MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThru.c b/MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThru.c
index 1518b251d8..09333c51d6 100644
--- a/MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThru.c
+++ b/MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThru.c
@@ -1,6 +1,6 @@
 /** @file
 
-  Copyright (c) 2014 - 2018, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2014 - 2019, Intel Corporation. All rights reserved.<BR>
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
 **/
@@ -35,7 +35,7 @@ UFS_PASS_THRU_PRIVATE_DATA gUfsPassThruTemplate = {
   },
   0,                              // UfsHostController
   0,                              // UfsHcBase
-  0,                              // Capabilities
+  {0, 0},                         // UfsHcInfo
   0,                              // TaskTag
   0,                              // UtpTrlBase
   0,                              // Nutrs
@@ -865,6 +865,10 @@ UfsPassThruDriverBindingStart (
   Private->UfsHostController    = UfsHc;
   Private->UfsHcBase            = UfsHcBase;
   InitializeListHead (&Private->Queue);
+  Status = GetUfsHcInfo (Private);
+  if (EFI_ERROR (Status)) {
+    DEBUG ((DEBUG_ERROR, "Failed to initialize UfsHcInfo\n"));
+  }
 
   //
   // Initialize UFS Host Controller H/W.
diff --git a/MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThru.h b/MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThru.h
index b79be77709..c511aa8c7a 100644
--- a/MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThru.h
+++ b/MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThru.h
@@ -62,7 +62,7 @@ typedef struct _UFS_PASS_THRU_PRIVATE_DATA {
   EFI_UFS_DEVICE_CONFIG_PROTOCOL      UfsDevConfig;
   EDKII_UFS_HOST_CONTROLLER_PROTOCOL  *UfsHostController;
   UINTN                               UfsHcBase;
-  UINT32                              Capabilities;
+  EDKII_UFS_HC_INFO                   UfsHcInfo;
 
   UINT8                               TaskTag;
 
@@ -959,6 +959,19 @@ UfsRwUfsAttribute (
   IN OUT UINT32                        *AttrSize
   );
 
+/**
+  Initializes UfsHcInfo field in private data.
+
+  @param[in] Private  Pointer to host controller private data.
+
+  @retval EFI_SUCCESS  UfsHcInfo initialized successfully.
+  @retval Others       Failed to initalize UfsHcInfo.
+**/
+EFI_STATUS
+GetUfsHcInfo (
+  IN UFS_PASS_THRU_PRIVATE_DATA  *Private
+  );
+
 extern EFI_COMPONENT_NAME_PROTOCOL  gUfsPassThruComponentName;
 extern EFI_COMPONENT_NAME2_PROTOCOL gUfsPassThruComponentName2;
 extern EFI_DRIVER_BINDING_PROTOCOL  gUfsPassThruDriverBinding;
diff --git a/MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThruHci.c b/MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThruHci.c
index 6ea27e473c..74be3efc41 100644
--- a/MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThruHci.c
+++ b/MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThruHci.c
@@ -731,7 +731,7 @@ UfsFindAvailableSlotInTrl (
     return Status;
   }
 
-  Nutrs   = (UINT8)((Private->Capabilities & UFS_HC_CAP_NUTRS) + 1);
+  Nutrs   = (UINT8)((Private->UfsHcInfo.Capabilities & UFS_HC_CAP_NUTRS) + 1);
 
   for (Index = 0; Index < Nutrs; Index++) {
     if ((Data & (BIT0 << Index)) == 0) {
@@ -1754,7 +1754,7 @@ UfsAllocateAlignCommonBuffer (
   BOOLEAN                              Is32BitAddr;
   EDKII_UFS_HOST_CONTROLLER_PROTOCOL   *UfsHc;
 
-  if ((Private->Capabilities & UFS_HC_CAP_64ADDR) == UFS_HC_CAP_64ADDR) {
+  if ((Private->UfsHcInfo.Capabilities & UFS_HC_CAP_64ADDR) == UFS_HC_CAP_64ADDR) {
     Is32BitAddr = FALSE;
   } else {
     Is32BitAddr = TRUE;
@@ -1947,7 +1947,6 @@ UfsInitTaskManagementRequestList (
   IN  UFS_PASS_THRU_PRIVATE_DATA     *Private
   )
 {
-  UINT32                 Data;
   UINT8                  Nutmrs;
   VOID                   *CmdDescHost;
   EFI_PHYSICAL_ADDRESS   CmdDescPhyAddr;
@@ -1961,17 +1960,10 @@ UfsInitTaskManagementRequestList (
   CmdDescMapping = NULL;
   CmdDescPhyAddr = 0;
 
-  Status = UfsMmioRead32 (Private, UFS_HC_CAP_OFFSET, &Data);
-  if (EFI_ERROR (Status)) {
-    return Status;
-  }
-
-  Private->Capabilities = Data;
-
   //
   // Allocate and initialize UTP Task Management Request List.
   //
-  Nutmrs = (UINT8) (RShiftU64 ((Private->Capabilities & UFS_HC_CAP_NUTMRS), 16) + 1);
+  Nutmrs = (UINT8) (RShiftU64 ((Private->UfsHcInfo.Capabilities & UFS_HC_CAP_NUTMRS), 16) + 1);
   Status = UfsAllocateAlignCommonBuffer (Private, Nutmrs * sizeof (UTP_TMRD), &CmdDescHost, &CmdDescPhyAddr, &CmdDescMapping);
   if (EFI_ERROR (Status)) {
     return Status;
@@ -2020,7 +2012,6 @@ UfsInitTransferRequestList (
   IN  UFS_PASS_THRU_PRIVATE_DATA     *Private
   )
 {
-  UINT32                 Data;
   UINT8                  Nutrs;
   VOID                   *CmdDescHost;
   EFI_PHYSICAL_ADDRESS   CmdDescPhyAddr;
@@ -2034,17 +2025,10 @@ UfsInitTransferRequestList (
   CmdDescMapping = NULL;
   CmdDescPhyAddr = 0;
 
-  Status = UfsMmioRead32 (Private, UFS_HC_CAP_OFFSET, &Data);
-  if (EFI_ERROR (Status)) {
-    return Status;
-  }
-
-  Private->Capabilities = Data;
-
   //
   // Allocate and initialize UTP Transfer Request List.
   //
-  Nutrs  = (UINT8)((Private->Capabilities & UFS_HC_CAP_NUTRS) + 1);
+  Nutrs  = (UINT8)((Private->UfsHcInfo.Capabilities & UFS_HC_CAP_NUTRS) + 1);
   Status = UfsAllocateAlignCommonBuffer (Private, Nutrs * sizeof (UTP_TRD), &CmdDescHost, &CmdDescPhyAddr, &CmdDescMapping);
   if (EFI_ERROR (Status)) {
     return Status;
@@ -2366,3 +2350,36 @@ ProcessAsyncTaskList (
   }
 }
 
+/**
+  Initializes UfsHcInfo field in private data.
+
+  @param[in] Private  Pointer to host controller private data.
+
+  @retval EFI_SUCCESS  UfsHcInfo initialized successfully.
+  @retval Others       Failed to initalize UfsHcInfo.
+**/
+EFI_STATUS
+GetUfsHcInfo (
+  IN UFS_PASS_THRU_PRIVATE_DATA  *Private
+  )
+{
+  UINT32      Data;
+  EFI_STATUS  Status;
+
+  Status = UfsMmioRead32 (Private, UFS_HC_VER_OFFSET, &Data);
+  if (EFI_ERROR (Status)) {
+    return Status;
+  }
+
+  Private->UfsHcInfo.Version = Data;
+
+  Status = UfsMmioRead32 (Private, UFS_HC_CAP_OFFSET, &Data);
+  if (EFI_ERROR (Status)) {
+    return Status;
+  }
+
+  Private->UfsHcInfo.Capabilities = Data;
+
+  return EFI_SUCCESS;
+}
+
-- 
2.14.1.windows.1

--------------------------------------------------------------------

Intel Technology Poland sp. z o.o.
ul. Slowackiego 173 | 80-298 Gdansk | Sad Rejonowy Gdansk Polnoc | VII Wydzial Gospodarczy Krajowego Rejestru Sadowego - KRS 101882 | NIP 957-07-52-316 | Kapital zakladowy 200.000 PLN.

Ta wiadomosc wraz z zalacznikami jest przeznaczona dla okreslonego adresata i moze zawierac informacje poufne. W razie przypadkowego otrzymania tej wiadomosci, prosimy o powiadomienie nadawcy oraz trwale jej usuniecie; jakiekolwiek
przegladanie lub rozpowszechnianie jest zabronione.
This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). If you are not the intended recipient, please contact the sender and delete all copies; any review or distribution by
others is strictly prohibited.


  parent reply	other threads:[~2019-08-07 16:51 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-07 16:51 [PATCH 0/4] Add EDKII_UFS_HC_PLATFORM_PROTOCOL to support platform specific programming of UFS host controllers Albecki, Mateusz
2019-08-07 16:51 ` [PATCH 1/4] MdeModulePkg: Add definition of the EDKII_UFS_HC_PLATFORM_PROTOCOL Albecki, Mateusz
2019-08-08  2:36   ` Wu, Hao A
2019-08-07 16:51 ` [PATCH 2/4] MdeModulePkg/UfsPassThruDxe: Refactor UfsExecUicCommand function Albecki, Mateusz
2019-08-08  2:36   ` [edk2-devel] " Wu, Hao A
2019-08-07 16:51 ` Albecki, Mateusz [this message]
2019-08-08  2:37   ` [edk2-devel] [PATCH 3/4] MdeModulePkg/UfsPassThruDxe: Refactor private data to use EDKII_UFS_HC_INFO Wu, Hao A
2019-08-08 20:44     ` Albecki, Mateusz
2019-08-07 16:51 ` [PATCH 4/4] MdeModulePkg/UfsPassThruDxe: Implement EDKII_UFS_HC_PLATFORM_PROTOCOL Albecki, Mateusz
2019-08-08  2:37   ` Wu, Hao A
2019-08-08 20:52     ` Albecki, Mateusz
2019-08-08  2:37 ` [PATCH 0/4] Add EDKII_UFS_HC_PLATFORM_PROTOCOL to support platform specific programming of UFS host controllers Wu, Hao A
2019-08-08 19:59   ` Laszlo Ersek

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=20190807165107.688-4-mateusz.albecki@intel.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