From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by mx.groups.io with SMTP id smtpd.web10.5864.1634894115788676114 for ; Fri, 22 Oct 2021 02:15:17 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 134.134.136.31, mailfrom: ian.chiu@intel.com) X-IronPort-AV: E=McAfee;i="6200,9189,10144"; a="290101523" X-IronPort-AV: E=Sophos;i="5.87,172,1631602800"; d="scan'208";a="290101523" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Oct 2021 02:15:13 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.87,172,1631602800"; d="scan'208";a="663108116" Received: from ikuox-desk1.gar.corp.intel.com ([10.227.107.18]) by orsmga005.jf.intel.com with ESMTP; 22 Oct 2021 02:15:12 -0700 From: ian.chiu@intel.com To: devel@edk2.groups.io Cc: Ian Chiu , Ian Chiu , Maggie Chu , Ray Ni , Hao A Wu Subject: [PATCH] MdeModulePkg\UfsBlockIoPei: UFS MMIO address size support both 32/64 bit Date: Fri, 22 Oct 2021 17:15:01 +0800 Message-Id: <20211022091501.1991-1-ian.chiu@intel.com> X-Mailer: git-send-email 2.30.0.windows.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Ian Chiu https://bugzilla.tianocore.org/show_bug.cgi?id=3D3703 MMIO base address size will overflow while finding two or more Host controller in the system. Correct it and support 32 and 64 bits address space. Signed-off-by: Ian Chiu Cc: Maggie Chu Cc: Ray Ni Cc: Hao A Wu --- MdeModulePkg/Bus/Pci/UfsPciHcPei/UfsPciHcPei.c | 37 ++++++++++++++++++++++= ++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/MdeModulePkg/Bus/Pci/UfsPciHcPei/UfsPciHcPei.c b/MdeModulePkg/= Bus/Pci/UfsPciHcPei/UfsPciHcPei.c index 447a05b5b2..69a19c60a2 100644 --- a/MdeModulePkg/Bus/Pci/UfsPciHcPei/UfsPciHcPei.c +++ b/MdeModulePkg/Bus/Pci/UfsPciHcPei/UfsPciHcPei.c @@ -76,6 +76,7 @@ InitializeUfsHcPeim ( UINT16 Device;=0D UINT16 Function;=0D UINT32 Size;=0D + UINT64 MmioSize;=0D UINT8 SubClass;=0D UINT8 BaseClass;=0D UFS_HC_PEI_PRIVATE_DATA *Private;=0D @@ -119,16 +120,48 @@ InitializeUfsHcPeim ( PciAnd16 (PCI_LIB_ADDRESS (Bus, Device, Function, PCI_COMMAND_OF= FSET), (UINT16)~(EFI_PCI_COMMAND_BUS_MASTER | EFI_PCI_COMMAND_MEMORY_SPACE)= );=0D PciWrite32 (PCI_LIB_ADDRESS (Bus, Device, Function, PCI_BASE_ADD= RESSREG_OFFSET), 0xFFFFFFFF);=0D Size =3D PciRead32 (PCI_LIB_ADDRESS (Bus, Device, Function, PCI_= BASE_ADDRESSREG_OFFSET));=0D +=0D + switch (Size & 0x07) {=0D + case 0x0:=0D + //=0D + // Memory space: anywhere in 32 bit address space=0D + //=0D + MmioSize =3D (~(Size & 0xFFFFFFF0)) + 1;=0D + break;=0D + case 0x4:=0D + //=0D + // Memory space: anywhere in 64 bit address space=0D + //=0D + MmioSize =3D Size & 0xFFFFFFF0;=0D +=0D + //=0D + // Fix the length to support some spefic 64 bit BAR=0D + //=0D + Size |=3D ((UINT32)(-1) << HighBitSet32 (Size));=0D +=0D + //=0D + // Calculate the size of 64bit bar=0D + //=0D + MmioSize |=3D LShiftU64 ((UINT64) Size, 32);=0D + MmioSize =3D (~(MmioSize)) + 1;=0D + break;=0D + default:=0D + //=0D + // Unknown BAR type=0D + //=0D + ASSERT (FALSE);=0D + continue;=0D + };=0D //=0D // Assign resource to the Ufs Pci host controller's MMIO BAR.=0D // Enable the Ufs Pci host controller by setting BME and MSE bit= s of PCI_CMD register.=0D //=0D - PciWrite32 (PCI_LIB_ADDRESS (Bus, Device, Function, PCI_BASE_ADD= RESSREG_OFFSET), (UINT32)(PcdGet32 (PcdUfsPciHostControllerMmioBase) + Size= * Private->TotalUfsHcs));=0D + PciWrite32 (PCI_LIB_ADDRESS (Bus, Device, Function, PCI_BASE_ADD= RESSREG_OFFSET), (UINT32)(PcdGet32 (PcdUfsPciHostControllerMmioBase) + Mmio= Size * Private->TotalUfsHcs));=0D PciOr16 (PCI_LIB_ADDRESS (Bus, Device, Function, PCI_COMMAND_OFF= SET), (EFI_PCI_COMMAND_BUS_MASTER | EFI_PCI_COMMAND_MEMORY_SPACE));=0D //=0D // Record the allocated Mmio base address.=0D //=0D - Private->UfsHcPciAddr[Private->TotalUfsHcs] =3D PcdGet32 (PcdUfs= PciHostControllerMmioBase) + Size * Private->TotalUfsHcs;=0D + Private->UfsHcPciAddr[Private->TotalUfsHcs] =3D PcdGet32 (PcdUfs= PciHostControllerMmioBase) + (UINTN) MmioSize * Private->TotalUfsHcs;=0D Private->TotalUfsHcs++;=0D ASSERT (Private->TotalUfsHcs < MAX_UFS_HCS);=0D }=0D --=20 2.16.2.windows.1