From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by mx.groups.io with SMTP id smtpd.web11.46058.1671525777169185136 for ; Tue, 20 Dec 2022 00:42:58 -0800 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=f17vCfuj; spf=pass (domain: intel.com, ip: 134.134.136.100, mailfrom: min.m.xu@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1671525778; x=1703061778; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Ry8iwlRAt1PowQ1vEg02Oz5bkk7793FSgX7TEy6NkbY=; b=f17vCfujGPevtnZYqgXQZszYPd+lymMFHwkQn2tpEXzK2u29iym5KJHd ekzDh7TArWfV2D7cWZSBjENI8QxoNvMZCDNlK94eYgqC7Kv37DKwud/an x6Qt8iZE49U3pXGR2bKHEYIZrghkkRw4Bl9nQ/9ZOnSgfrYJUAC4/uu83 /Q2yjvUDtLIXxXo+6A1cT3seoh1EUWVAwJGfDl7L90poosTb25Er2N4y7 d+ar5AjYMvnW4gNZj+/90KoBd/eVmyfLpDd1JMCCr2DMIYPsM2TTksB/e Lkx17XlDI22SYFvRRdPBGKw0np2c8+mC+6cCHdA2/f1kobRYjv1JzG/fI A==; X-IronPort-AV: E=McAfee;i="6500,9779,10566"; a="383908214" X-IronPort-AV: E=Sophos;i="5.96,258,1665471600"; d="scan'208";a="383908214" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Dec 2022 00:42:58 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10566"; a="628644646" X-IronPort-AV: E=Sophos;i="5.96,259,1665471600"; d="scan'208";a="628644646" Received: from mxu9-mobl1.ccr.corp.intel.com ([10.255.29.12]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Dec 2022 00:42:56 -0800 From: "Min Xu" To: devel@edk2.groups.io Cc: Min M Xu , Erdem Aktas , Gerd Hoffmann , James Bottomley , Jiewen Yao , Tom Lendacky Subject: [PATCH V2 1/6] OvmfPkg/TdxMailboxLib: Delete global variables Date: Tue, 20 Dec 2022 16:42:35 +0800 Message-Id: <20221220084240.1922-2-min.m.xu@intel.com> X-Mailer: git-send-email 2.29.2.windows.2 In-Reply-To: <20221220084240.1922-1-min.m.xu@intel.com> References: <20221220084240.1922-1-min.m.xu@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Min M Xu BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=4172 TdxMailboxLib once was designed to be used in DXE phase. But now it is going to be used in SEC/PEI phase (in the following patches). Global variables are not allowed. The library is refactored after those global variables are deleted. Cc: Erdem Aktas Cc: Gerd Hoffmann Cc: James Bottomley Cc: Jiewen Yao Cc: Tom Lendacky Signed-off-by: Min Xu --- OvmfPkg/Library/TdxMailboxLib/TdxMailbox.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/OvmfPkg/Library/TdxMailboxLib/TdxMailbox.c b/OvmfPkg/Library/TdxMailboxLib/TdxMailbox.c index 74cb55611fe3..c580a2885603 100644 --- a/OvmfPkg/Library/TdxMailboxLib/TdxMailbox.c +++ b/OvmfPkg/Library/TdxMailboxLib/TdxMailbox.c @@ -13,14 +13,10 @@ #include #include #include -#include #include #include #include -volatile VOID *mMailBox = NULL; -UINT32 mNumOfCpus = 0; - /** This function will be called by BSP to get the CPU number. @@ -32,11 +28,17 @@ GetCpusNum ( VOID ) { - if (mNumOfCpus == 0) { - mNumOfCpus = TdVCpuNum (); + UINT64 Status; + TD_RETURN_DATA TdReturnData; + + Status = TdCall (TDCALL_TDINFO, 0, 0, 0, &TdReturnData); + if (Status == TDX_EXIT_REASON_SUCCESS) { + return TdReturnData.TdInfo.NumVcpus; + } else { + DEBUG ((DEBUG_ERROR, "Failed call TDCALL_TDINFO. %llx\n", Status)); } - return mNumOfCpus; + return 0; } /** @@ -48,11 +50,7 @@ GetTdxMailBox ( VOID ) { - if (mMailBox == NULL) { - mMailBox = (VOID *)(UINTN)PcdGet32 (PcdOvmfSecGhcbBackupBase); - } - - return mMailBox; + return (VOID *)(UINTN)PcdGet32 (PcdOvmfSecGhcbBackupBase); } /** -- 2.29.2.windows.2