From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id F3FD2203BEBF5 for ; Mon, 27 Mar 2017 01:08:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=intel.com; i=@intel.com; q=dns/txt; s=intel; t=1490602134; x=1522138134; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=Ie10hfnBul0g6TAkGa7VkphvgTkrKQDQjlzpXoaFmM4=; b=FM6MTTKXDDy0UJgMJxhHkY8yskWLeeCZFVpdbURs5fw/N4w7fXSglcuR taODvorYswYjijGncJnfCO/fIIy4Qg==; Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Mar 2017 01:08:54 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.36,229,1486454400"; d="scan'208";a="80948350" Received: from junghyun-mobl.amr.corp.intel.com (HELO jljusten-skl.amr.corp.intel.com) ([10.252.131.12]) by fmsmga005.fm.intel.com with ESMTP; 27 Mar 2017 01:08:54 -0700 From: Jordan Justen To: edk2-devel@lists.01.org Cc: Jordan Justen , Laszlo Ersek Date: Mon, 27 Mar 2017 01:05:37 -0700 Message-Id: <20170327080544.24748-6-jordan.l.justen@intel.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170327080544.24748-1-jordan.l.justen@intel.com> References: <20170327080544.24748-1-jordan.l.justen@intel.com> Subject: [PATCH 05/12] OvmfPkg QemuFlash: Make QemuFlashDetected external X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 27 Mar 2017 08:08:55 -0000 QemuFlashDetected is also changed to not use global variables. Cc: Laszlo Ersek Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Jordan Justen --- OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlash.c | 29 +++++++++++++++++----- OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlash.h | 14 +++++++++++ 2 files changed, 37 insertions(+), 6 deletions(-) diff --git a/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlash.c b/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlash.c index 68388048f3..90e7810733 100644 --- a/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlash.c +++ b/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlash.c @@ -16,6 +16,7 @@ #include #include #include +#include #include "QemuFlash.h" @@ -37,12 +38,25 @@ STATIC UINTN mFdBlockCount = 0; STATIC volatile UINT8* +QemuFlashPtrEx ( + UINT8 *FlashBase, + UINTN BlockSize, + IN EFI_LBA Lba, + IN UINTN Offset + ) +{ + return FlashBase + ((UINTN)Lba * BlockSize) + Offset; +} + + +STATIC +volatile UINT8* QemuFlashPtr ( IN EFI_LBA Lba, IN UINTN Offset ) { - return mFlashBase + ((UINTN)Lba * mFdBlockSize) + Offset; + return QemuFlashPtrEx (mFlashBase, mFdBlockSize, Lba, Offset); } @@ -53,7 +67,6 @@ QemuFlashPtr ( @retval TRUE The QEMU flash device is present. **/ -STATIC BOOLEAN QemuFlashDetected ( VOID @@ -66,11 +79,15 @@ QemuFlashDetected ( UINT8 OriginalUint8; UINT8 ProbeUint8; + UINT8 *FlashBase = (UINT8*)(UINTN) PcdGet32 (PcdOvmfFdBaseAddress); + UINTN BlockSize = PcdGet32 (PcdOvmfFirmwareBlockSize); + ASSERT(PcdGet32 (PcdOvmfFirmwareFdSize) % BlockSize == 0); + FlashDetected = FALSE; - Ptr = QemuFlashPtr (0, 0); + Ptr = QemuFlashPtrEx (FlashBase, BlockSize, 0, 0); - for (Offset = 0; Offset < mFdBlockSize; Offset++) { - Ptr = QemuFlashPtr (0, Offset); + for (Offset = 0; Offset < BlockSize; Offset++) { + Ptr = QemuFlashPtrEx (FlashBase, BlockSize, 0, Offset); ProbeUint8 = *Ptr; if (ProbeUint8 != CLEAR_STATUS_CMD && ProbeUint8 != READ_STATUS_CMD && @@ -79,7 +96,7 @@ QemuFlashDetected ( } } - if (Offset >= mFdBlockSize) { + if (Offset >= BlockSize) { DEBUG ((EFI_D_INFO, "QEMU Flash: Failed to find probe location\n")); return FALSE; } diff --git a/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlash.h b/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlash.h index 4bd971b0d1..04f89364ab 100644 --- a/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlash.h +++ b/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlash.h @@ -19,6 +19,20 @@ extern UINT8 *mFlashBase; /** + Detect if QEMU Flash is available and writable + + Note: This function does not use read or write global variables. + + @retval TRUE Flash is writable + +**/ +BOOLEAN +QemuFlashDetected ( + VOID + ); + + +/** Read from QEMU Flash @param[in] Lba The starting logical block index to read from. -- 2.11.0