From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by mx.groups.io with SMTP id smtpd.web10.30429.1683754842926750061 for ; Wed, 10 May 2023 14:40:43 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=TdAYBmYK; spf=pass (domain: intel.com, ip: 134.134.136.126, mailfrom: michael.d.kinney@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1683754842; x=1715290842; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=Lzq2a/lkk+dXg7TtYf6hv13zaKHDUjNTw71Ja0IkOyE=; b=TdAYBmYKItQJdJMrx8DCqGoozf53XAepRhoXNFMfYd+1CocFQMiwX3U6 B78qJ1nGuevp4IptTkv4e3/NVybXVsvr7yUKh2+nOXx36ANELhuWQwUz6 JpSsv3u84LvBucEKViD7m76RT33g4UgUHrui0jjAwpdI9DbddMiszh7Pu gRbu2jCJeYDjIcGxqgvLmusdQn5lgsllE3xjdIhunK4YK4NcQg1it7TOK bhZpMxKD8COGOc0w8j4QC4NWz9+pNfGCfn7ORF/Iygu9sPXBJBOTJ/oFZ 8HyhHsB2QmKHg4feL0Y8c6OPMPZz+S5y1FtHydJDNbpb+GZrNV2yGKaaQ A==; X-IronPort-AV: E=McAfee;i="6600,9927,10706"; a="334799807" X-IronPort-AV: E=Sophos;i="5.99,265,1677571200"; d="scan'208";a="334799807" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 May 2023 14:40:36 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10706"; a="823695536" X-IronPort-AV: E=Sophos;i="5.99,265,1677571200"; d="scan'208";a="823695536" Received: from orsmsx603.amr.corp.intel.com ([10.22.229.16]) by orsmga004.jf.intel.com with ESMTP; 10 May 2023 14:40:33 -0700 Received: from orsmsx610.amr.corp.intel.com (10.22.229.23) by ORSMSX603.amr.corp.intel.com (10.22.229.16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23; Wed, 10 May 2023 14:40:33 -0700 Received: from ORSEDG602.ED.cps.intel.com (10.7.248.7) by orsmsx610.amr.corp.intel.com (10.22.229.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23 via Frontend Transport; Wed, 10 May 2023 14:40:33 -0700 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (104.47.55.104) by edgegateway.intel.com (134.134.137.103) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.23; Wed, 10 May 2023 14:40:33 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Y2Rf0myekajtQPtVIzvVkqFLxIt9maBVOG3mGbB1ZrPKUJJotpH9jlAAe3lfJj5k4zKQuwdEi4F0ThQEM+fzlf5SM4W7FNlEdglVf5A8ALN6ZaKd5DDyb3UdmOLj7BdvsHwp6GLucRUCQimyMAlWrNxrnkQSUet7KxKZFz+To6IVtMazac7bO5JFFbDOV4ocPZ0jZgA0FE1Hve0QdM5WkTUQ1h8JSzjGjgNMQWgCFJfr09vtGqU5QGgLyCSb2fMckRcFLeXg6skrW+4X1JWAqgPmRCASJJqXkH+r8b9xupQ0bQA2uPoMnDTBVUQZSaLQt3xxYclArYzAFoWsnjwgQA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=GiHxjHPPzoC4CR0C/b5A/TgE2CAuTpnKW7ExSvetPVM=; b=O5xn1pFS2C6/4o92opNwoqlAd1vAh7qNhWHexN4FEeGjZjumP5YvebvP13nwVVUZVXRTsZsCRfoc15R6/EwjLcPUVPOQJhRF7vS78f/CvAyPkuCU2DwNFKPcsDd1faPymQ3zO+TwV9nUYS1RxNpZt2mKKpbawt5J30KcR2V2gKmnxNekBFS1NI8Z6jpGlk0Brq1mGAJuN1eNruDHxBnipWyZG1Ko2jvSBok8UgI+DvusOX5Q0NJgiT3CMFGRWMCqonA9Pubm16Dvp9SQyAlNMs8UaWv7TfvQb2ecFJM7g95gIxONZFCVcXs3hxWxasaMnKN47+LfPfyvaUtMHjCgQg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Received: from CO1PR11MB4929.namprd11.prod.outlook.com (2603:10b6:303:6d::19) by LV3PR11MB8577.namprd11.prod.outlook.com (2603:10b6:408:1b8::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6363.33; Wed, 10 May 2023 21:40:28 +0000 Received: from CO1PR11MB4929.namprd11.prod.outlook.com ([fe80::6e8f:1c7:b499:a84d]) by CO1PR11MB4929.namprd11.prod.outlook.com ([fe80::6e8f:1c7:b499:a84d%4]) with mapi id 15.20.6387.019; Wed, 10 May 2023 21:40:28 +0000 From: "Michael D Kinney" To: "Guo, Gua" , "devel@edk2.groups.io" , "Wang, Jian J" , "Gao, Liming" CC: "Chan, Laura" , "Prakashan, Krishnadas Veliyathuparambil" , "K N, Karthik" , "Kinney, Michael D" Subject: Re: [PATCH v7 4/5] MdeModulePkg: Add TraceHubDebugSysTLib library Thread-Topic: [PATCH v7 4/5] MdeModulePkg: Add TraceHubDebugSysTLib library Thread-Index: AQHZg4bm0JYAcDx8W02yFQP3mytxC69UCJZA Date: Wed, 10 May 2023 21:40:28 +0000 Message-ID: References: <20230510213154.1994-1-gua.guo@intel.com> <20230510213154.1994-5-gua.guo@intel.com> In-Reply-To: <20230510213154.1994-5-gua.guo@intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; x-ms-publictraffictype: Email x-ms-traffictypediagnostic: CO1PR11MB4929:EE_|LV3PR11MB8577:EE_ x-ms-office365-filtering-correlation-id: 5627c0de-378e-4cc2-8fd2-08db519f2c22 x-ld-processed: 46c98d88-e344-4ed4-8496-4ed7712e255d,ExtAddr x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: eQTSQ7SRWlONtA6OzcXZuFZ1XI9Km1UDlIWqDhEMfIHhiZqh7/IW7MQJZPMYBaTNSb5v3IgQxArK9Ho23OCRWWt2xgD93R+efbd++S5fWxOiTkPxP7sATlA2oCTdPrmDOtUKGbujeaCxdZ5CY9uom6deR+HxRZzOLM9aN71REfnln7Prj4WUKPlz/sfc3mvUg/+34HfRVf3O+dEmWHwq8n30oM4yjVIeZ2/QNSdibBibJXDTnkXZPM9ZfVZWh4vb3WRAeHzEXXRlAHmcTAXI2CA3Xyd50wTZhNkB2xl1uwFKcqD4McLnfXLYp2h/5ROwLoKINXXOl35GRePIbS+A20rEYT1vt9znCHtc2AFzDInzVZoTJPS8iV9GsvkXokc/fSn1GT8kl+e2D8HtwynhgYpckwM4LGi5Rqw5A0RDVpgH0vtO3xD6Xq2sHABCPaBs3q6OVi3UyxzhUiGIlziB3W9R9xdh/WHrqq+G3pB7LEc9QdBYoYCO7tPXCeY4l/SWiyQmCvLWajhDUMlxK/qWnwpLGuXLUUVXpkRIea3b1LhqGVbReriZp5Mkzzf+EDKs0tj3pZCYs7oDJpwTo/oimPjM4/m7TRTb0fiiF8zonh4= x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CO1PR11MB4929.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(346002)(376002)(366004)(136003)(39860400002)(396003)(451199021)(82960400001)(107886003)(26005)(9686003)(122000001)(38100700002)(6506007)(86362001)(38070700005)(966005)(7696005)(83380400001)(186003)(71200400001)(30864003)(2906002)(19627235002)(76116006)(55016003)(66946007)(66556008)(33656002)(110136005)(41300700001)(478600001)(5660300002)(8936002)(52536014)(66446008)(64756008)(54906003)(53546011)(4326008)(66476007)(316002)(8676002)(579004)(559001);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?NLUwV3d/ritjtTbAT9FiPtEWCb8pPBpDV2qNl1ZQ1aD6yJC4ZIGu2tXvITN0?= =?us-ascii?Q?/GKb/4Nmz+ybFhcOJErL8r0B5SuoATEX5w0rwnR8hYvUTlLEn39gDEswliPl?= =?us-ascii?Q?zrsXnnnTZgXV9YVt+AqkAq1TDrJBUEY2+o4K1OQgy5FXzp0/yLmXsApfM0rP?= =?us-ascii?Q?ivTMfV3s9Yy55SqEjwUIZUq/6GXXIVoKeRFDwlq2QnmNUQcSKMi/qVjgbuwl?= =?us-ascii?Q?3w4kjk9YM/EfTq0LF7qnDW9BgdbdTVBY9jYHjj8+4wSOLy27Uu8+jnhtDp9Q?= =?us-ascii?Q?1Yff0aL7UXJsHWpPepmJlzw9HDR+t9Qky77QDciUq1Y6pmLc1+hUNz92Wq7v?= =?us-ascii?Q?xlK3bSR1DJqM9uNPKro+wVb9K5BPicncrAnfA0WkLxCp0gh+LzvorOW9pmpr?= =?us-ascii?Q?vIdFOT1EWzhyr5wA2zySaeIDbTQDX1OLLPzWoHGqO526MgQM8WI/uPdBOz2V?= =?us-ascii?Q?BE0OXZurw3HDkt0NqPyOnQo1dnhiYwyMC0KmZssrJ4RQYSAbM/MNF/XgX4Oc?= =?us-ascii?Q?LLTKltoxu72kuMTThKPhSVKYTAPLa+1YLUfO2lEA3VgPmNYX9GV8vUnSbbG4?= =?us-ascii?Q?8eW39LmBFmN4Nb7C0NSWaBNailnFK0xh+CziPt4jcTwFMNHWUFt5felbuljZ?= =?us-ascii?Q?cCe6T4PN59AAJKWWtSMPCP5TIujvuw9u8E87lI0G/lcFiiLqZkcyDF81VeBE?= =?us-ascii?Q?kpUNc/wPZPMT0VtbKbLrbRj+dQBBlkru7Uqp/YazBMLWzbfamPDz9Bm2q1Zy?= =?us-ascii?Q?5OWjOjJTa9EANZQMV+8cniD/GJmUTqxdq3oTbhuewqlPVbQs9aVvjNCLwRc5?= =?us-ascii?Q?BOAj/+LWwrU1AQmljJJ8hkQlr3SMpUKWhCTsXBT2LLFBaZifzKtXvE76biD2?= =?us-ascii?Q?0oTPT1zV8r0r9sTIqqtvwsaQx2hVMO77tZ8nYle6hi2Sz/KO1YikD2hvntUD?= =?us-ascii?Q?7xbIQtNKWvzSOzM1snchtruMvsSPjsspxku3RUK4PV+drN70mNU93K7Lsx0C?= =?us-ascii?Q?iZCuIpmXg/0ATZWzKo4oi6GAV2MtPEulPNA8qxr5puYGE/3mJ8JcjsBD/9/a?= =?us-ascii?Q?TnxfRgRg7552sUsjR8iZQvKbci+Um9WVk8jcFVwXjv/Y2vHcV9e5g9eVKkqO?= =?us-ascii?Q?Ler2MGnuAHv3BRkPM798Ooy9balwbGALnBcUPXhn3DqJfSa1jlq6EP5jXp8+?= =?us-ascii?Q?gxJ+ZfWuYoDW9HwuCLSTuYpc8PsU90DU3CiFYFhx0eToSiziJK6In4DmtcI6?= =?us-ascii?Q?PflPYujy2ekZYCLBNgAU5plB28J3QwmmvIn5FQUXPLUoF4IZTMyKHaYiEvMa?= =?us-ascii?Q?PO5QtlSP6O06Zk0HYaKmXyk+viHfYcElY/hK7Hp8lCFqX/17PzG1QdpAKMFq?= =?us-ascii?Q?IJTtstL8HXJ8gLt6i8MIgk44/jRSJQgpnkb6ey7lZo7BoaVxoQ1eySZuo/iN?= =?us-ascii?Q?FLCVh2GUKV+/4NVTXovERqzctNmVpi+sBpktGWR1DYF8v7TkrjuWjNfzFK50?= =?us-ascii?Q?JfWOUz59Ev5AXTMknNbif3Uo85UkERqTULag/OjkqYj8o1HAqxv04qmD1fWO?= =?us-ascii?Q?kYpiwmje9HnccPu5QPYeI8DyF+2KriUCPS390Jlm7PvpNCJverecXg+VAEJH?= =?us-ascii?Q?sQ=3D=3D?= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: CO1PR11MB4929.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5627c0de-378e-4cc2-8fd2-08db519f2c22 X-MS-Exchange-CrossTenant-originalarrivaltime: 10 May 2023 21:40:28.5097 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: muZMCJo2nLbydoubwElSCw6Tv9OZyuuw7ThUMCmz9YyPdCs73xjuZJG+tHRwfJpgsTWdZ8DN7uGSlY7rebmojmmsmNRVOqIayR5YMJ2O7xE= X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV3PR11MB8577 Return-Path: michael.d.kinney@intel.com X-OriginatorOrg: intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable The MdeModulePkg maintainers were never Cc, so they did not know to review Cc: Jian J Wang =20 Cc: Liming Gao =20 Will have to wait for review from Jian or Liming and add Rb. Mike > -----Original Message----- > From: Guo, Gua > Sent: Wednesday, May 10, 2023 2:32 PM > To: devel@edk2.groups.io > Cc: Guo, Gua ; Kinney, Michael D > ; Chan, Laura ; > Prakashan, Krishnadas Veliyathuparambil > ; K N, Karthik > > Subject: [PATCH v7 4/5] MdeModulePkg: Add TraceHubDebugSysTLib library >=20 > From: Gua Guo >=20 > REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4144 >=20 > This Library provides API to dump Trace Hub message. >=20 > Cc: Michael D Kinney > Cc: Guo Gua > Cc: Chan Laura > Cc: Prakashan Krishnadas Veliyathuparambil > > Cc: K N Karthik > Signed-off-by: Guo Gua > Reviewed-by: Michael D Kinney > Reviewed-by: K N Karthik > Reviewed-by: Chan Laura > --- > .../Include/Guid/TraceHubDebugInfoHob.h | 24 ++ > .../BaseTraceHubDebugSysTLib.c | 245 +++++++++++++++ > .../BaseTraceHubDebugSysTLib.inf | 44 +++ > .../DxeSmmTraceHubDebugSysTLib.c | 263 ++++++++++++++++ > .../DxeSmmTraceHubDebugSysTLib.inf | 51 ++++ > .../InternalTraceHubApi.c | 74 +++++ > .../InternalTraceHubApi.h | 37 +++ > .../InternalTraceHubApiCommon.c | 200 +++++++++++++ > .../InternalTraceHubApiCommon.h | 119 ++++++++ > .../PeiTraceHubDebugSysTLib.c | 282 ++++++++++++++++++ > .../PeiTraceHubDebugSysTLib.inf | 50 ++++ > .../Library/TraceHubDebugSysTLib/Readme.md | 26 ++ > MdeModulePkg/MdeModulePkg.dec | 21 ++ > MdeModulePkg/MdeModulePkg.dsc | 3 + > MdeModulePkg/MdeModulePkg.uni | 18 ++ > 15 files changed, 1457 insertions(+) > create mode 100644 MdeModulePkg/Include/Guid/TraceHubDebugInfoHob.h > create mode 100644 > MdeModulePkg/Library/TraceHubDebugSysTLib/BaseTraceHubDebugSysTLib.c > create mode 100644 > MdeModulePkg/Library/TraceHubDebugSysTLib/BaseTraceHubDebugSysTLib.i > nf > create mode 100644 > MdeModulePkg/Library/TraceHubDebugSysTLib/DxeSmmTraceHubDebugSysTL > ib.c > create mode 100644 > MdeModulePkg/Library/TraceHubDebugSysTLib/DxeSmmTraceHubDebugSysTL > ib.inf > create mode 100644 > MdeModulePkg/Library/TraceHubDebugSysTLib/InternalTraceHubApi.c > create mode 100644 > MdeModulePkg/Library/TraceHubDebugSysTLib/InternalTraceHubApi.h > create mode 100644 > MdeModulePkg/Library/TraceHubDebugSysTLib/InternalTraceHubApiCommon > .c > create mode 100644 > MdeModulePkg/Library/TraceHubDebugSysTLib/InternalTraceHubApiCommon > .h > create mode 100644 > MdeModulePkg/Library/TraceHubDebugSysTLib/PeiTraceHubDebugSysTLib.c > create mode 100644 > MdeModulePkg/Library/TraceHubDebugSysTLib/PeiTraceHubDebugSysTLib.inf > create mode 100644 > MdeModulePkg/Library/TraceHubDebugSysTLib/Readme.md >=20 > diff --git a/MdeModulePkg/Include/Guid/TraceHubDebugInfoHob.h > b/MdeModulePkg/Include/Guid/TraceHubDebugInfoHob.h > new file mode 100644 > index 0000000000..367f97dc90 > --- /dev/null > +++ b/MdeModulePkg/Include/Guid/TraceHubDebugInfoHob.h > @@ -0,0 +1,24 @@ > +/** @file >=20 > +This header file declares Trace Hub related structure. >=20 > + >=20 > +Copyright (c) 2023, Intel Corporation. All rights reserved.
>=20 > + >=20 > +SPDX-License-Identifier: BSD-2-Clause-Patent >=20 > +**/ >=20 > + >=20 > +#ifndef TRACE_HUB_DEBUG_INFO_HOB_H_ >=20 > +#define TRACE_HUB_DEBUG_INFO_HOB_H_ >=20 > + >=20 > +#define TRACEHUB_DEBUG_INFO_HOB_REVISION 1 >=20 > + >=20 > +typedef struct { >=20 > + UINT16 Revision; // Structure revision >=20 > + BOOLEAN Flag; // Flag to enable or disable Trace Hub= debug > message. >=20 > + UINT8 DebugLevel; // Debug level for Trace Hub. >=20 > + UINT8 Rvsd[4]; // Reserved for future use >=20 > + UINT64 TraceHubMmioAddress; // MMIO address where Trace Hub > debug message output to. >=20 > +} TRACEHUB_DEBUG_INFO_HOB; >=20 > + >=20 > +extern GUID gTraceHubDebugInfoHobGuid; >=20 > + >=20 > +#endif // TRACE_HUB_DEBUG_INFO_HOB_H_ >=20 > diff --git > a/MdeModulePkg/Library/TraceHubDebugSysTLib/BaseTraceHubDebugSysTLib > .c > b/MdeModulePkg/Library/TraceHubDebugSysTLib/BaseTraceHubDebugSysTLib > .c > new file mode 100644 > index 0000000000..45dfd3127a > --- /dev/null > +++ > b/MdeModulePkg/Library/TraceHubDebugSysTLib/BaseTraceHubDebugSysTLib > .c > @@ -0,0 +1,245 @@ > +/** @file >=20 > +System prints Trace Hub message in SEC/PEI/DXE/SMM based on fixed PCDs. >=20 > +Only support single Trace Hub debug instance. >=20 > + >=20 > +Copyright (c) 2023, Intel Corporation. All rights reserved.
>=20 > + >=20 > +SPDX-License-Identifier: BSD-2-Clause-Patent >=20 > + >=20 > +**/ >=20 > + >=20 > +#include >=20 > +#include >=20 > +#include >=20 > +#include >=20 > +#include >=20 > +#include >=20 > +#include >=20 > +#include >=20 > +#include "InternalTraceHubApiCommon.h" >=20 > +#include "InternalTraceHubApi.h" >=20 > + >=20 > +/** >=20 > + Write debug string to specified Trace Hub MMIO address. >=20 > + >=20 > + @param[in] SeverityType Severity type of input message. >=20 > + @param[in] Buffer A pointer to the data buffer. >=20 > + @param[in] NumberOfBytes The size of data buffer. >=20 > + >=20 > + @retval RETURN_SUCCESS Data was written to Trace Hub. >=20 > + @retval Other Failed to output Trace Hub message. >=20 > +**/ >=20 > +RETURN_STATUS >=20 > +EFIAPI >=20 > +TraceHubSysTDebugWrite ( >=20 > + IN TRACE_HUB_SEVERITY_TYPE SeverityType, >=20 > + IN UINT8 *Buffer, >=20 > + IN UINTN NumberOfBytes >=20 > + ) >=20 > +{ >=20 > + MIPI_SYST_HANDLE MipiSystHandle; >=20 > + MIPI_SYST_HEADER MipiSystHeader; >=20 > + RETURN_STATUS Status; >=20 > + UINT32 DbgInstCount; >=20 > + UINT16 Index; >=20 > + >=20 > + if (NumberOfBytes =3D=3D 0) { >=20 > + // >=20 > + // No data need to be written to Trace Hub >=20 > + // >=20 > + return RETURN_SUCCESS; >=20 > + } >=20 > + >=20 > + if (Buffer =3D=3D NULL) { >=20 > + return RETURN_INVALID_PARAMETER; >=20 > + } >=20 > + >=20 > + DbgInstCount =3D CountThDebugInstance (); >=20 > + >=20 > + ZeroMem (&MipiSystHandle, sizeof (MIPI_SYST_HANDLE)); >=20 > + MipiSystHandle.systh_header =3D &MipiSystHeader; >=20 > + >=20 > + Status =3D InitMipiSystHandle (&MipiSystHandle); >=20 > + if (RETURN_ERROR (Status)) { >=20 > + return Status; >=20 > + } >=20 > + >=20 > + for (Index =3D 0; Index < DbgInstCount; Index++) { >=20 > + Status =3D CheckWhetherToOutputMsg ( >=20 > + &MipiSystHandle, >=20 > + NULL, >=20 > + SeverityType, >=20 > + TraceHubDebugType >=20 > + ); >=20 > + if (!RETURN_ERROR (Status)) { >=20 > + Status =3D MipiSystWriteDebug ( >=20 > + &MipiSystHandle, >=20 > + SeverityType, >=20 > + (UINT16)NumberOfBytes, >=20 > + (CHAR8 *)Buffer >=20 > + ); >=20 > + if (RETURN_ERROR (Status)) { >=20 > + break; >=20 > + } >=20 > + } >=20 > + } >=20 > + >=20 > + return Status; >=20 > +} >=20 > + >=20 > +/** >=20 > + Write catalog status code message to specified Trace Hub MMIO address. >=20 > + >=20 > + @param[in] SeverityType Severity type of input message. >=20 > + @param[in] Id Catalog ID. >=20 > + @param[in] Guid Driver Guid. >=20 > + >=20 > + @retval RETURN_SUCCESS Data was written to Trace Hub. >=20 > + @retval Other Failed to output Trace Hub message. >=20 > +**/ >=20 > +RETURN_STATUS >=20 > +EFIAPI >=20 > +TraceHubSysTWriteCataLog64StatusCode ( >=20 > + IN TRACE_HUB_SEVERITY_TYPE SeverityType, >=20 > + IN UINT64 Id, >=20 > + IN GUID *Guid >=20 > + ) >=20 > +{ >=20 > + MIPI_SYST_HANDLE MipiSystHandle; >=20 > + MIPI_SYST_HEADER MipiSystHeader; >=20 > + RETURN_STATUS Status; >=20 > + UINT32 DbgInstCount; >=20 > + UINT16 Index; >=20 > + >=20 > + if (Guid =3D=3D NULL) { >=20 > + return RETURN_INVALID_PARAMETER; >=20 > + } >=20 > + >=20 > + DbgInstCount =3D CountThDebugInstance (); >=20 > + >=20 > + ZeroMem (&MipiSystHandle, sizeof (MIPI_SYST_HANDLE)); >=20 > + MipiSystHandle.systh_header =3D &MipiSystHeader; >=20 > + >=20 > + Status =3D InitMipiSystHandle (&MipiSystHandle); >=20 > + if (RETURN_ERROR (Status)) { >=20 > + return Status; >=20 > + } >=20 > + >=20 > + SwapBytesGuid (Guid, (GUID *)(VOID *)&MipiSystHandle.systh_guid); >=20 > + MipiSystHandle.systh_tag.et_guid =3D 1; >=20 > + >=20 > + for (Index =3D 0; Index < DbgInstCount; Index++) { >=20 > + Status =3D CheckWhetherToOutputMsg ( >=20 > + &MipiSystHandle, >=20 > + NULL, >=20 > + SeverityType, >=20 > + TraceHubCatalogType >=20 > + ); >=20 > + if (!RETURN_ERROR (Status)) { >=20 > + Status =3D MipiSystWriteCatalog ( >=20 > + &MipiSystHandle, >=20 > + SeverityType, >=20 > + Id >=20 > + ); >=20 > + if (RETURN_ERROR (Status)) { >=20 > + break; >=20 > + } >=20 > + } >=20 > + } >=20 > + >=20 > + return Status; >=20 > +} >=20 > + >=20 > +/** >=20 > + Write catalog message to specified Trace Hub MMIO address. >=20 > + >=20 > + @param[in] SeverityType Severity type of input message. >=20 > + @param[in] Id Catalog ID. >=20 > + @param[in] NumberOfParams Number of entries in argument list. >=20 > + @param[in] ... Catalog message parameters. >=20 > + >=20 > + @retval RETURN_SUCCESS Data was written to Trace Hub. >=20 > + @retval Other Failed to output Trace Hub message. >=20 > +**/ >=20 > +RETURN_STATUS >=20 > +EFIAPI >=20 > +TraceHubSysTWriteCataLog64 ( >=20 > + IN TRACE_HUB_SEVERITY_TYPE SeverityType, >=20 > + IN UINT64 Id, >=20 > + IN UINTN NumberOfParams, >=20 > + ... >=20 > + ) >=20 > +{ >=20 > + MIPI_SYST_HANDLE MipiSystHandle; >=20 > + MIPI_SYST_HEADER MipiSystHeader; >=20 > + VA_LIST Args; >=20 > + UINTN Index; >=20 > + RETURN_STATUS Status; >=20 > + UINT32 DbgInstCount; >=20 > + >=20 > + DbgInstCount =3D 0; >=20 > + >=20 > + if (NumberOfParams > sizeof (MipiSystHandle.systh_param) / sizeof > (UINT32)) { >=20 > + return RETURN_INVALID_PARAMETER; >=20 > + } >=20 > + >=20 > + DbgInstCount =3D CountThDebugInstance (); >=20 > + >=20 > + ZeroMem (&MipiSystHandle, sizeof (MIPI_SYST_HANDLE)); >=20 > + MipiSystHandle.systh_header =3D &MipiSystHeader; >=20 > + >=20 > + Status =3D InitMipiSystHandle (&MipiSystHandle); >=20 > + if (RETURN_ERROR (Status)) { >=20 > + return Status; >=20 > + } >=20 > + >=20 > + MipiSystHandle.systh_param_count =3D (UINT32)NumberOfParams; >=20 > + VA_START (Args, NumberOfParams); >=20 > + for (Index =3D 0; Index < NumberOfParams; Index++) { >=20 > + MipiSystHandle.systh_param[Index] =3D VA_ARG (Args, UINT32); >=20 > + } >=20 > + >=20 > + VA_END (Args); >=20 > + >=20 > + for (Index =3D 0; Index < DbgInstCount; Index++) { >=20 > + Status =3D CheckWhetherToOutputMsg ( >=20 > + &MipiSystHandle, >=20 > + NULL, >=20 > + SeverityType, >=20 > + TraceHubCatalogType >=20 > + ); >=20 > + if (!RETURN_ERROR (Status)) { >=20 > + Status =3D MipiSystWriteCatalog ( >=20 > + &MipiSystHandle, >=20 > + SeverityType, >=20 > + Id >=20 > + ); >=20 > + if (RETURN_ERROR (Status)) { >=20 > + break; >=20 > + } >=20 > + } >=20 > + } >=20 > + >=20 > + return Status; >=20 > +} >=20 > + >=20 > +/** >=20 > + Collect the total number of Trace Hub debug instance in the system. >=20 > + >=20 > + @retval UINT32 The total number of Trace Hub debug instance in th= e > system. >=20 > +**/ >=20 > +UINT32 >=20 > +EFIAPI >=20 > +CountThDebugInstance ( >=20 > + VOID >=20 > + ) >=20 > +{ >=20 > + UINT32 DbgInstCount; >=20 > + >=20 > + // >=20 > + // 1 from PCD. >=20 > + // >=20 > + DbgInstCount =3D 1; >=20 > + >=20 > + return DbgInstCount; >=20 > +} >=20 > diff --git > a/MdeModulePkg/Library/TraceHubDebugSysTLib/BaseTraceHubDebugSysTLib > .inf > b/MdeModulePkg/Library/TraceHubDebugSysTLib/BaseTraceHubDebugSysTLib > .inf > new file mode 100644 > index 0000000000..3edc4e8fd8 > --- /dev/null > +++ > b/MdeModulePkg/Library/TraceHubDebugSysTLib/BaseTraceHubDebugSysTLib > .inf > @@ -0,0 +1,44 @@ > +## @file >=20 > +# Debug library to output Trace Hub message. >=20 > +# Support SEC/PEI/DXE/SMM phase TraceHub debug message based on > fixed settings. >=20 > +# >=20 > +# Copyright (c) 2023, Intel Corporation. All rights reserved.
>=20 > +# >=20 > +# SPDX-License-Identifier: BSD-2-Clause-Patent >=20 > +# >=20 > +## >=20 > + >=20 > +[Defines] >=20 > + INF_VERSION =3D 0x00010005 >=20 > + BASE_NAME =3D BaseTraceHubDebugSysTLib >=20 > + FILE_GUID =3D 336DA571-AD65-423C-9A43-E0056E5B2D8= D >=20 > + MODULE_TYPE =3D BASE >=20 > + VERSION_STRING =3D 1.0 >=20 > + LIBRARY_CLASS =3D TraceHubDebugSysTLib >=20 > + >=20 > +# >=20 > +# The following information is for reference only and not required by th= e > build tools. >=20 > +# >=20 > +# VALID_ARCHITECTURES =3D IA32 X64 >=20 > +# >=20 > + >=20 > +[LibraryClasses] >=20 > + BaseLib >=20 > + PcdLib >=20 > + BaseMemoryLib >=20 > + MipiSysTLib >=20 > + >=20 > +[Packages] >=20 > + MdePkg/MdePkg.dec >=20 > + MdeModulePkg/MdeModulePkg.dec >=20 > + >=20 > +[Sources] >=20 > + BaseTraceHubDebugSysTLib.c >=20 > + InternalTraceHubApiCommon.c >=20 > + InternalTraceHubApiCommon.h >=20 > + InternalTraceHubApi.h >=20 > + >=20 > +[Pcd] >=20 > + gEfiMdeModulePkgTokenSpaceGuid.PcdTraceHubDebugLevel >=20 > + gEfiMdeModulePkgTokenSpaceGuid.PcdEnableTraceHubDebugMsg >=20 > + gEfiMdeModulePkgTokenSpaceGuid.PcdTraceHubDebugMmioAddress >=20 > diff --git > a/MdeModulePkg/Library/TraceHubDebugSysTLib/DxeSmmTraceHubDebugSys > TLib.c > b/MdeModulePkg/Library/TraceHubDebugSysTLib/DxeSmmTraceHubDebugSys > TLib.c > new file mode 100644 > index 0000000000..35c239b5fe > --- /dev/null > +++ > b/MdeModulePkg/Library/TraceHubDebugSysTLib/DxeSmmTraceHubDebugSys > TLib.c > @@ -0,0 +1,263 @@ > +/** @file >=20 > +System prints Trace Hub message in DXE/SMM based on fixed PCDs and HOB. >=20 > +Trace Hub PCDs will be applied if no HOB exist. >=20 > + >=20 > +Copyright (c) 2023, Intel Corporation. All rights reserved.
>=20 > + >=20 > +SPDX-License-Identifier: BSD-2-Clause-Patent >=20 > + >=20 > +**/ >=20 > + >=20 > +#include >=20 > +#include >=20 > +#include >=20 > +#include >=20 > +#include >=20 > +#include >=20 > +#include >=20 > +#include >=20 > +#include >=20 > +#include >=20 > +#include "InternalTraceHubApiCommon.h" >=20 > +#include "InternalTraceHubApi.h" >=20 > + >=20 > +GLOBAL_REMOVE_IF_UNREFERENCED TRACEHUB_DEBUG_INFO_HOB > *mThDebugInstArray =3D NULL; >=20 > +GLOBAL_REMOVE_IF_UNREFERENCED UINT32 mDbgInstCount = =3D > 0; >=20 > + >=20 > +/** >=20 > + Write debug string to specified Trace Hub MMIO address. >=20 > + >=20 > + @param[in] SeverityType Severity type of input message. >=20 > + @param[in] Buffer A pointer to the data buffer. >=20 > + @param[in] NumberOfBytes The size of data buffer. >=20 > + >=20 > + @retval RETURN_SUCCESS Data was written to Trace Hub. >=20 > + @retval Other Failed to output Trace Hub message. >=20 > +**/ >=20 > +RETURN_STATUS >=20 > +EFIAPI >=20 > +TraceHubSysTDebugWrite ( >=20 > + IN TRACE_HUB_SEVERITY_TYPE SeverityType, >=20 > + IN UINT8 *Buffer, >=20 > + IN UINTN NumberOfBytes >=20 > + ) >=20 > +{ >=20 > + MIPI_SYST_HANDLE MipiSystHandle; >=20 > + MIPI_SYST_HEADER MipiSystHeader; >=20 > + RETURN_STATUS Status; >=20 > + UINT16 Index; >=20 > + >=20 > + if ((mDbgInstCount =3D=3D 0) || (mThDebugInstArray =3D=3D NULL)) { >=20 > + return RETURN_ABORTED; >=20 > + } >=20 > + >=20 > + if (NumberOfBytes =3D=3D 0) { >=20 > + // >=20 > + // No data need to be written to Trace Hub >=20 > + // >=20 > + return RETURN_SUCCESS; >=20 > + } >=20 > + >=20 > + if (Buffer =3D=3D NULL) { >=20 > + return RETURN_INVALID_PARAMETER; >=20 > + } >=20 > + >=20 > + ZeroMem (&MipiSystHandle, sizeof (MIPI_SYST_HANDLE)); >=20 > + MipiSystHandle.systh_header =3D &MipiSystHeader; >=20 > + >=20 > + Status =3D InitMipiSystHandle (&MipiSystHandle); >=20 > + if (RETURN_ERROR (Status)) { >=20 > + return Status; >=20 > + } >=20 > + >=20 > + for (Index =3D 0; Index < mDbgInstCount; Index++) { >=20 > + Status =3D CheckWhetherToOutputMsg ( >=20 > + &MipiSystHandle, >=20 > + (UINT8 *)&mThDebugInstArray[Index], >=20 > + SeverityType, >=20 > + TraceHubDebugType >=20 > + ); >=20 > + if (!RETURN_ERROR (Status)) { >=20 > + Status =3D MipiSystWriteDebug ( >=20 > + &MipiSystHandle, >=20 > + SeverityType, >=20 > + (UINT16)NumberOfBytes, >=20 > + (CHAR8 *)Buffer >=20 > + ); >=20 > + if (RETURN_ERROR (Status)) { >=20 > + break; >=20 > + } >=20 > + } >=20 > + } >=20 > + >=20 > + return Status; >=20 > +} >=20 > + >=20 > +/** >=20 > + Write catalog status code message to specified Trace Hub MMIO address. >=20 > + >=20 > + @param[in] SeverityType Severity type of input message. >=20 > + @param[in] Id Catalog ID. >=20 > + @param[in] Guid Driver Guid. >=20 > + >=20 > + @retval RETURN_SUCCESS Data was written to Trace Hub. >=20 > + @retval Other Failed to output Trace Hub message. >=20 > +**/ >=20 > +RETURN_STATUS >=20 > +EFIAPI >=20 > +TraceHubSysTWriteCataLog64StatusCode ( >=20 > + IN TRACE_HUB_SEVERITY_TYPE SeverityType, >=20 > + IN UINT64 Id, >=20 > + IN GUID *Guid >=20 > + ) >=20 > +{ >=20 > + MIPI_SYST_HANDLE MipiSystHandle; >=20 > + MIPI_SYST_HEADER MipiSystHeader; >=20 > + UINTN Index; >=20 > + RETURN_STATUS Status; >=20 > + >=20 > + if ((mDbgInstCount =3D=3D 0) || (mThDebugInstArray =3D=3D NULL)) { >=20 > + return RETURN_ABORTED; >=20 > + } >=20 > + >=20 > + ZeroMem (&MipiSystHandle, sizeof (MIPI_SYST_HANDLE)); >=20 > + MipiSystHandle.systh_header =3D &MipiSystHeader; >=20 > + >=20 > + Status =3D InitMipiSystHandle (&MipiSystHandle); >=20 > + if (RETURN_ERROR (Status)) { >=20 > + return Status; >=20 > + } >=20 > + >=20 > + if (Guid !=3D NULL) { >=20 > + SwapBytesGuid (Guid, (GUID *)(VOID *)&MipiSystHandle.systh_guid); >=20 > + MipiSystHandle.systh_tag.et_guid =3D 1; >=20 > + } else { >=20 > + MipiSystHandle.systh_tag.et_modunit =3D 2; >=20 > + MipiSystHandle.systh_tag.et_guid =3D 0; >=20 > + } >=20 > + >=20 > + for (Index =3D 0; Index < mDbgInstCount; Index++) { >=20 > + Status =3D CheckWhetherToOutputMsg ( >=20 > + &MipiSystHandle, >=20 > + (UINT8 *)&mThDebugInstArray[Index], >=20 > + SeverityType, >=20 > + TraceHubCatalogType >=20 > + ); >=20 > + if (!RETURN_ERROR (Status)) { >=20 > + Status =3D MipiSystWriteCatalog ( >=20 > + &MipiSystHandle, >=20 > + SeverityType, >=20 > + Id >=20 > + ); >=20 > + if (RETURN_ERROR (Status)) { >=20 > + break; >=20 > + } >=20 > + } >=20 > + } >=20 > + >=20 > + return Status; >=20 > +} >=20 > + >=20 > +/** >=20 > + Write catalog message to specified Trace Hub MMIO address. >=20 > + >=20 > + @param[in] SeverityType Severity type of input message. >=20 > + @param[in] Id Catalog ID. >=20 > + @param[in] NumberOfParams Number of entries in argument list. >=20 > + @param[in] ... Catalog message parameters. >=20 > + >=20 > + @retval RETURN_SUCCESS Data was written to Trace Hub. >=20 > + @retval Other Failed to output Trace Hub message. >=20 > +**/ >=20 > +RETURN_STATUS >=20 > +EFIAPI >=20 > +TraceHubSysTWriteCataLog64 ( >=20 > + IN TRACE_HUB_SEVERITY_TYPE SeverityType, >=20 > + IN UINT64 Id, >=20 > + IN UINTN NumberOfParams, >=20 > + ... >=20 > + ) >=20 > +{ >=20 > + MIPI_SYST_HANDLE MipiSystHandle; >=20 > + MIPI_SYST_HEADER MipiSystHeader; >=20 > + VA_LIST Args; >=20 > + UINTN Index; >=20 > + RETURN_STATUS Status; >=20 > + >=20 > + if (NumberOfParams > sizeof (MipiSystHandle.systh_param) / sizeof > (UINT32)) { >=20 > + return RETURN_INVALID_PARAMETER; >=20 > + } >=20 > + >=20 > + if ((mDbgInstCount =3D=3D 0) || (mThDebugInstArray =3D=3D NULL)) { >=20 > + return RETURN_ABORTED; >=20 > + } >=20 > + >=20 > + ZeroMem (&MipiSystHandle, sizeof (MIPI_SYST_HANDLE)); >=20 > + MipiSystHandle.systh_header =3D &MipiSystHeader; >=20 > + >=20 > + Status =3D InitMipiSystHandle (&MipiSystHandle); >=20 > + if (RETURN_ERROR (Status)) { >=20 > + return Status; >=20 > + } >=20 > + >=20 > + MipiSystHandle.systh_param_count =3D (UINT32)NumberOfParams; >=20 > + VA_START (Args, NumberOfParams); >=20 > + for (Index =3D 0; Index < NumberOfParams; Index++) { >=20 > + MipiSystHandle.systh_param[Index] =3D VA_ARG (Args, UINT32); >=20 > + } >=20 > + >=20 > + VA_END (Args); >=20 > + >=20 > + for (Index =3D 0; Index < mDbgInstCount; Index++) { >=20 > + Status =3D CheckWhetherToOutputMsg ( >=20 > + &MipiSystHandle, >=20 > + (UINT8 *)&mThDebugInstArray[Index], >=20 > + SeverityType, >=20 > + TraceHubCatalogType >=20 > + ); >=20 > + if (!RETURN_ERROR (Status)) { >=20 > + Status =3D MipiSystWriteCatalog ( >=20 > + &MipiSystHandle, >=20 > + SeverityType, >=20 > + Id >=20 > + ); >=20 > + if (RETURN_ERROR (Status)) { >=20 > + break; >=20 > + } >=20 > + } >=20 > + } >=20 > + >=20 > + return Status; >=20 > +} >=20 > + >=20 > +/** >=20 > + Constructor to get TraceHob configuration data >=20 > + >=20 > + @param ImageHandle The firmware allocated handle for the EFI image. >=20 > + @param SystemTable A pointer to the EFI System Table. >=20 > + >=20 > + @retval RETURN_SUCCESS The constructor always returns > EFI_SUCCESS. >=20 > + @retval RETURN_OUT_OF_RESOURCES There are not enough resources > available to retrieve the matching FFS section. >=20 > + >=20 > +**/ >=20 > +RETURN_STATUS >=20 > +EFIAPI >=20 > +DxeSmmTraceHubDebugSysTLibConstructor ( >=20 > + IN EFI_HANDLE ImageHandle, >=20 > + IN EFI_SYSTEM_TABLE *SystemTable >=20 > + ) >=20 > +{ >=20 > + if (mDbgInstCount =3D=3D 0) { >=20 > + mDbgInstCount =3D CountThDebugInstance (); >=20 > + } >=20 > + >=20 > + mThDebugInstArray =3D AllocateZeroPool (mDbgInstCount * sizeof > (TRACEHUB_DEBUG_INFO_HOB)); >=20 > + >=20 > + if (mThDebugInstArray !=3D NULL) { >=20 > + PackThDebugInstance (mThDebugInstArray, mDbgInstCount); >=20 > + } else { >=20 > + return RETURN_OUT_OF_RESOURCES; >=20 > + } >=20 > + >=20 > + return RETURN_SUCCESS; >=20 > +} >=20 > diff --git > a/MdeModulePkg/Library/TraceHubDebugSysTLib/DxeSmmTraceHubDebugSys > TLib.inf > b/MdeModulePkg/Library/TraceHubDebugSysTLib/DxeSmmTraceHubDebugSys > TLib.inf > new file mode 100644 > index 0000000000..90213beee1 > --- /dev/null > +++ > b/MdeModulePkg/Library/TraceHubDebugSysTLib/DxeSmmTraceHubDebugSys > TLib.inf > @@ -0,0 +1,51 @@ > +## @file >=20 > +# Debug library to output Trace Hub message. >=20 > +# Support DXE/SMM phase TraceHub debug message based on fixed or > dynamic settings. >=20 > +# >=20 > +# Copyright (c) 2023, Intel Corporation. All rights reserved.
>=20 > +# >=20 > +# SPDX-License-Identifier: BSD-2-Clause-Patent >=20 > +# >=20 > +## >=20 > + >=20 > +[Defines] >=20 > + INF_VERSION =3D 0x00010005 >=20 > + BASE_NAME =3D DxeSmmTraceHubDebugSysTLib >=20 > + FILE_GUID =3D A9B7B825-7902-4616-8556-085DA4DFEC7= 2 >=20 > + MODULE_TYPE =3D DXE_DRIVER >=20 > + VERSION_STRING =3D 1.0 >=20 > + LIBRARY_CLASS =3D TraceHubDebugSysTLib|DXE_CORE DXE_D= RIVER > SMM_CORE DXE_SMM_DRIVER UEFI_DRIVER UEFI_APPLICATION >=20 > + CONSTRUCTOR =3D DxeSmmTraceHubDebugSysTLibConstruct= or >=20 > + >=20 > +# >=20 > +# The following information is for reference only and not required by th= e > build tools. >=20 > +# >=20 > +# VALID_ARCHITECTURES =3D IA32 X64 >=20 > +# >=20 > + >=20 > +[LibraryClasses] >=20 > + BaseLib >=20 > + PcdLib >=20 > + HobLib >=20 > + BaseMemoryLib >=20 > + MemoryAllocationLib >=20 > + MipiSysTLib >=20 > + >=20 > +[Packages] >=20 > + MdePkg/MdePkg.dec >=20 > + MdeModulePkg/MdeModulePkg.dec >=20 > + >=20 > +[Sources] >=20 > + DxeSmmTraceHubDebugSysTLib.c >=20 > + InternalTraceHubApiCommon.c >=20 > + InternalTraceHubApiCommon.h >=20 > + InternalTraceHubApi.h >=20 > + InternalTraceHubApi.c >=20 > + >=20 > +[Guids] >=20 > + gTraceHubDebugInfoHobGuid >=20 > + >=20 > +[Pcd] >=20 > + gEfiMdeModulePkgTokenSpaceGuid.PcdTraceHubDebugLevel >=20 > + gEfiMdeModulePkgTokenSpaceGuid.PcdEnableTraceHubDebugMsg >=20 > + gEfiMdeModulePkgTokenSpaceGuid.PcdTraceHubDebugMmioAddress >=20 > diff --git > a/MdeModulePkg/Library/TraceHubDebugSysTLib/InternalTraceHubApi.c > b/MdeModulePkg/Library/TraceHubDebugSysTLib/InternalTraceHubApi.c > new file mode 100644 > index 0000000000..fe946fe60c > --- /dev/null > +++ b/MdeModulePkg/Library/TraceHubDebugSysTLib/InternalTraceHubApi.c > @@ -0,0 +1,74 @@ > +/** @file >=20 > +Functions implementation in this file are not common for all type of > TraceHubDebugSysTLib. >=20 > + >=20 > +Copyright (c) 2023, Intel Corporation. All rights reserved.
>=20 > + >=20 > +SPDX-License-Identifier: BSD-2-Clause-Patent >=20 > + >=20 > +**/ >=20 > + >=20 > +#include >=20 > +#include >=20 > +#include >=20 > +#include >=20 > +#include "InternalTraceHubApi.h" >=20 > + >=20 > +/** >=20 > + Count the total number of Trace Hub debug instance in the system. >=20 > + >=20 > + @retval UINT32 The total number of Trace Hub debug instance in th= e > system. >=20 > +**/ >=20 > +UINT32 >=20 > +EFIAPI >=20 > +CountThDebugInstance ( >=20 > + VOID >=20 > + ) >=20 > +{ >=20 > + UINT8 *DbgContext; >=20 > + UINT32 DbgInstCount; >=20 > + >=20 > + DbgInstCount =3D 0; >=20 > + >=20 > + DbgContext =3D (UINT8 *)GetFirstGuidHob (&gTraceHubDebugInfoHobGuid); >=20 > + if (DbgContext !=3D NULL) { >=20 > + while (DbgContext !=3D NULL) { >=20 > + DbgInstCount++; >=20 > + DbgContext =3D (UINT8 *)GetNextGuidHob > (&gTraceHubDebugInfoHobGuid, GET_NEXT_HOB (DbgContext)); >=20 > + } >=20 > + } else { >=20 > + DbgInstCount++; >=20 > + } >=20 > + >=20 > + return DbgInstCount; >=20 > +} >=20 > + >=20 > +/** >=20 > + Pack Trace Hub debug instances in the system. >=20 > + >=20 > + @param[in, out] ThPtr A pointer to TRACEHUB_DEBUG_INFO_HOB > structure. >=20 > + @param[in] Count Number of Trace Hub HOBs. >=20 > +**/ >=20 > +VOID >=20 > +EFIAPI >=20 > +PackThDebugInstance ( >=20 > + IN OUT TRACEHUB_DEBUG_INFO_HOB *ThPtr, >=20 > + IN UINT32 Count >=20 > + ) >=20 > +{ >=20 > + UINT8 *DbgContext; >=20 > + UINT16 Index; >=20 > + >=20 > + DbgContext =3D GetFirstGuidHob (&gTraceHubDebugInfoHobGuid); >=20 > + if (DbgContext !=3D NULL) { >=20 > + for (Index =3D 0; Index < Count; Index++) { >=20 > + CopyMem (&ThPtr[Index], GET_GUID_HOB_DATA (DbgContext), sizeof > (TRACEHUB_DEBUG_INFO_HOB)); >=20 > + DbgContext =3D GetNextGuidHob (&gTraceHubDebugInfoHobGuid, > GET_NEXT_HOB (DbgContext)); >=20 > + } >=20 > + } else { >=20 > + for (Index =3D 0; Index < Count; Index++) { >=20 > + ThPtr[Index].TraceHubMmioAddress =3D FixedPcdGet64 > (PcdTraceHubDebugMmioAddress); >=20 > + ThPtr[Index].Flag =3D FixedPcdGetBool > (PcdEnableTraceHubDebugMsg); >=20 > + ThPtr[Index].DebugLevel =3D FixedPcdGet8 (PcdTraceHubDebu= gLevel); >=20 > + } >=20 > + } >=20 > +} >=20 > diff --git > a/MdeModulePkg/Library/TraceHubDebugSysTLib/InternalTraceHubApi.h > b/MdeModulePkg/Library/TraceHubDebugSysTLib/InternalTraceHubApi.h > new file mode 100644 > index 0000000000..f624f73768 > --- /dev/null > +++ b/MdeModulePkg/Library/TraceHubDebugSysTLib/InternalTraceHubApi.h > @@ -0,0 +1,37 @@ > +/** @file >=20 > +This header file declares functions that are not for common use. >=20 > + >=20 > +Copyright (c) 2023, Intel Corporation. All rights reserved.
>=20 > + >=20 > +SPDX-License-Identifier: BSD-2-Clause-Patent >=20 > + >=20 > +**/ >=20 > + >=20 > +#ifndef INTERNAL_TRACE_HUB_API_H_ >=20 > +#define INTERNAL_TRACE_HUB_API_H_ >=20 > + >=20 > +/** >=20 > + Count the total number of Trace Hub debug instance in the system. >=20 > + >=20 > + @retval UINT32 The total number of Trace Hub debug instance in th= e > system. >=20 > +**/ >=20 > +UINT32 >=20 > +EFIAPI >=20 > +CountThDebugInstance ( >=20 > + VOID >=20 > + ); >=20 > + >=20 > +/** >=20 > + Pack Trace Hub debug instances in the system. >=20 > + >=20 > + @param[in, out] ThPtr A pointer to TRACEHUB_DEBUG_INFO_HOB > structure. >=20 > + @param[in] Count Number of Trace Hub HOBs. >=20 > +**/ >=20 > +VOID >=20 > +EFIAPI >=20 > +PackThDebugInstance ( >=20 > + IN OUT TRACEHUB_DEBUG_INFO_HOB *ThPtr, >=20 > + IN UINT32 Count >=20 > + ); >=20 > + >=20 > +#endif // INTERNAL_TRACE_HUB_API_H_ >=20 > diff --git > a/MdeModulePkg/Library/TraceHubDebugSysTLib/InternalTraceHubApiComm > on.c > b/MdeModulePkg/Library/TraceHubDebugSysTLib/InternalTraceHubApiComm > on.c > new file mode 100644 > index 0000000000..fe77f486f4 > --- /dev/null > +++ > b/MdeModulePkg/Library/TraceHubDebugSysTLib/InternalTraceHubApiComm > on.c > @@ -0,0 +1,200 @@ > +/** @file >=20 > +Functions implementation defined in this file are common for all type of > TraceHubDebugSysTLib >=20 > + >=20 > +Copyright (c) 2023, Intel Corporation. All rights reserved.
>=20 > + >=20 > +SPDX-License-Identifier: BSD-2-Clause-Patent >=20 > + >=20 > +**/ >=20 > + >=20 > +#include >=20 > +#include >=20 > +#include >=20 > +#include >=20 > +#include >=20 > +#include >=20 > +#include "InternalTraceHubApiCommon.h" >=20 > +#include "InternalTraceHubApi.h" >=20 > + >=20 > +/** >=20 > + Conditionally determine whether to enable Trace Hub message. >=20 > + >=20 > + @param[in] Flag Flag to enable or disable Trace Hub messag= e. >=20 > + @param[in] DbgLevel Debug Level of Trace Hub. >=20 > + @param[in] SeverityType Severity type of input message. >=20 > + >=20 > + @retval TRUE Enable trace hub message. >=20 > + @retval FALSE Disable trace hub message. >=20 > +**/ >=20 > +BOOLEAN >=20 > +EFIAPI >=20 > +TraceHubDataEnabled ( >=20 > + IN BOOLEAN Flag, >=20 > + IN UINT8 DbgLevel, >=20 > + IN TRACE_HUB_SEVERITY_TYPE SeverityType >=20 > + ) >=20 > +{ >=20 > + if (Flag =3D=3D TraceHubRoutingDisable) { >=20 > + return FALSE; >=20 > + } >=20 > + >=20 > + if (DbgLevel =3D=3D TraceHubDebugLevelError) { >=20 > + if (((SeverityType =3D=3D SeverityFatal) || (SeverityType =3D=3D Sev= erityError))) { >=20 > + return TRUE; >=20 > + } >=20 > + } else if (DbgLevel =3D=3D TraceHubDebugLevelErrorWarning) { >=20 > + if (((SeverityType =3D=3D SeverityFatal) || (SeverityType =3D=3D Sev= erityError) || > (SeverityType =3D=3D SeverityWarning))) { >=20 > + return TRUE; >=20 > + } >=20 > + } else if (DbgLevel =3D=3D TraceHubDebugLevelErrorWarningInfo) { >=20 > + if (((SeverityType =3D=3D SeverityFatal) || (SeverityType =3D=3D Sev= erityError) || > (SeverityType =3D=3D SeverityWarning) || (SeverityType =3D=3D SeverityNor= mal))) { >=20 > + return TRUE; >=20 > + } >=20 > + } else if (DbgLevel =3D=3D TraceHubDebugLevelErrorWarningInfoVerbose) = { >=20 > + return TRUE; >=20 > + } >=20 > + >=20 > + return FALSE; >=20 > +} >=20 > + >=20 > +/** >=20 > + Convert GUID from LE to BE or BE to LE. >=20 > + >=20 > + @param[in] Guid GUID that need to be converted. >=20 > + @param[out] ConvertedGuid GUID that is converted. >=20 > +**/ >=20 > +VOID >=20 > +EFIAPI >=20 > +SwapBytesGuid ( >=20 > + IN GUID *Guid, >=20 > + OUT GUID *ConvertedGuid >=20 > + ) >=20 > +{ >=20 > + CopyGuid (ConvertedGuid, Guid); >=20 > + ConvertedGuid->Data1 =3D SwapBytes32 (ConvertedGuid->Data1); >=20 > + ConvertedGuid->Data2 =3D SwapBytes16 (ConvertedGuid->Data2); >=20 > + ConvertedGuid->Data3 =3D SwapBytes16 (ConvertedGuid->Data3); >=20 > +} >=20 > + >=20 > +/** >=20 > + Check whether to output Trace Hub message according to some conditions= . >=20 > + Trace Hub message will be disabled if TraceHubDataEnabled() return FAL= SE >=20 > + or Trace Hub MMIO address is 0. >=20 > + >=20 > + @param[in, out] MipiSystHandle A pointer to MIPI_SYST_HANDLE > structure. >=20 > + @param[in] DbgContext A pointer to Trace Hub debug instanc= e. >=20 > + @param[in] SeverityType Severity type of input message. >=20 > + @param[in] PrintType Either catalog print or debug print. >=20 > + >=20 > + @retval RETURN_SUCCESS Current Trace Hub message need to be > output. >=20 > + @retval Other Current Trace Hub message will be disabled= . >=20 > +**/ >=20 > +RETURN_STATUS >=20 > +EFIAPI >=20 > +CheckWhetherToOutputMsg ( >=20 > + IN OUT MIPI_SYST_HANDLE *MipiSystHandle, >=20 > + IN UINT8 *DbgContext, >=20 > + IN TRACE_HUB_SEVERITY_TYPE SeverityType, >=20 > + IN TRACEHUB_PRINTTYPE PrintType >=20 > + ) >=20 > +{ >=20 > + UINT8 DbgLevel; >=20 > + BOOLEAN Flag; >=20 > + UINT64 Addr; >=20 > + RETURN_STATUS Status; >=20 > + >=20 > + if (MipiSystHandle =3D=3D NULL) { >=20 > + return RETURN_INVALID_PARAMETER; >=20 > + } >=20 > + >=20 > + if (PrintType =3D=3D TraceHubDebugType) { >=20 > + Status =3D GetTraceHubMsgVisibility (DbgContext, &Flag, &DbgLevel); >=20 > + if (RETURN_ERROR (Status)) { >=20 > + return Status; >=20 > + } >=20 > + >=20 > + if (!TraceHubDataEnabled (Flag, DbgLevel, SeverityType)) { >=20 > + return RETURN_ABORTED; >=20 > + } >=20 > + } >=20 > + >=20 > + Status =3D GetTraceHubMmioAddress (DbgContext, &Addr); >=20 > + if (RETURN_ERROR (Status)) { >=20 > + return Status; >=20 > + } >=20 > + >=20 > + MipiSystHandle->systh_platform.TraceHubPlatformData.MmioAddr =3D Addr; >=20 > + if (MipiSystHandle->systh_platform.TraceHubPlatformData.MmioAddr =3D= =3D 0) > { >=20 > + return RETURN_ABORTED; >=20 > + } >=20 > + >=20 > + return RETURN_SUCCESS; >=20 > +} >=20 > + >=20 > +/** >=20 > + Get Trace Hub MMIO Address. >=20 > + >=20 > + @param[in] DbgContext A pointer to Trace Hub debug instanc= e. >=20 > + @param[in, out] TraceAddress Trace Hub MMIO Address. >=20 > + >=20 > + @retval RETURN_SUCCESS Operation is successfully. >=20 > + @retval Other Operation is failed. >=20 > +**/ >=20 > +RETURN_STATUS >=20 > +EFIAPI >=20 > +GetTraceHubMmioAddress ( >=20 > + IN UINT8 *DbgContext, >=20 > + IN OUT UINT64 *TraceAddress >=20 > + ) >=20 > +{ >=20 > + TRACEHUB_DEBUG_INFO_HOB *ThDbgContext; >=20 > + >=20 > + if (TraceAddress =3D=3D NULL) { >=20 > + return RETURN_INVALID_PARAMETER; >=20 > + } >=20 > + >=20 > + if (DbgContext !=3D NULL) { >=20 > + ThDbgContext =3D (TRACEHUB_DEBUG_INFO_HOB *)DbgContext; >=20 > + *TraceAddress =3D ThDbgContext->TraceHubMmioAddress; >=20 > + } else { >=20 > + *TraceAddress =3D FixedPcdGet64 (PcdTraceHubDebugMmioAddress); >=20 > + } >=20 > + >=20 > + return RETURN_SUCCESS; >=20 > +} >=20 > + >=20 > +/** >=20 > + Get visibility of Trace Hub Msg. >=20 > + >=20 > + @param[in] DbgContext A pointer to Trace Hub debug instance. >=20 > + @param[in, out] Flag Flag to enable or disable Trace Hub me= ssage. >=20 > + @param[in, out] DbgLevel Debug Level of Trace Hub. >=20 > + >=20 > + @retval RETURN_SUCCESS Operation is successfully. >=20 > + @retval Other Operation is failed. >=20 > +**/ >=20 > +RETURN_STATUS >=20 > +EFIAPI >=20 > +GetTraceHubMsgVisibility ( >=20 > + IN UINT8 *DbgContext, >=20 > + IN OUT BOOLEAN *Flag, >=20 > + IN OUT UINT8 *DbgLevel >=20 > + ) >=20 > +{ >=20 > + TRACEHUB_DEBUG_INFO_HOB *ThDbgContext; >=20 > + >=20 > + if ((Flag =3D=3D NULL) || (DbgLevel =3D=3D NULL)) { >=20 > + return RETURN_INVALID_PARAMETER; >=20 > + } >=20 > + >=20 > + if (DbgContext !=3D NULL) { >=20 > + ThDbgContext =3D (TRACEHUB_DEBUG_INFO_HOB *)DbgContext; >=20 > + *Flag =3D ThDbgContext->Flag; >=20 > + *DbgLevel =3D ThDbgContext->DebugLevel; >=20 > + } else { >=20 > + *DbgLevel =3D FixedPcdGet8 (PcdTraceHubDebugLevel); >=20 > + *Flag =3D FixedPcdGetBool (PcdEnableTraceHubDebugMsg); >=20 > + } >=20 > + >=20 > + return RETURN_SUCCESS; >=20 > +} >=20 > diff --git > a/MdeModulePkg/Library/TraceHubDebugSysTLib/InternalTraceHubApiComm > on.h > b/MdeModulePkg/Library/TraceHubDebugSysTLib/InternalTraceHubApiComm > on.h > new file mode 100644 > index 0000000000..b8be48a8bb > --- /dev/null > +++ > b/MdeModulePkg/Library/TraceHubDebugSysTLib/InternalTraceHubApiComm > on.h > @@ -0,0 +1,119 @@ > +/** @file >=20 > +This header file declares functions and type for common use. >=20 > + >=20 > +Copyright (c) 2023, Intel Corporation. All rights reserved.
>=20 > + >=20 > +SPDX-License-Identifier: BSD-2-Clause-Patent >=20 > + >=20 > +**/ >=20 > + >=20 > +#ifndef INTERNAL_TRACE_HUB_API_COMMON_H_ >=20 > +#define INTERNAL_TRACE_HUB_API_COMMON_H_ >=20 > + >=20 > +typedef enum { >=20 > + TraceHubDebugType =3D 0, >=20 > + TraceHubCatalogType >=20 > +} TRACEHUB_PRINTTYPE; >=20 > + >=20 > +typedef enum { >=20 > + TraceHubRoutingDisable =3D 0, >=20 > + TraceHubRoutingEnable, >=20 > + TraceHubRoutingMax >=20 > +} TRACE_HUB_ROUTING; >=20 > + >=20 > +typedef enum { >=20 > + TraceHubDebugLevelError =3D 0, >=20 > + TraceHubDebugLevelErrorWarning, >=20 > + TraceHubDebugLevelErrorWarningInfo, >=20 > + TraceHubDebugLevelErrorWarningInfoVerbose, >=20 > + TraceHubDebugLevelMax >=20 > +} TRACE_HUB_DEBUG_LEVEL; >=20 > + >=20 > +/** >=20 > + Conditionally determine whether to enable Trace Hub message. >=20 > + >=20 > + @param[in] Flag Flag to enable or disable Trace Hub messag= e. >=20 > + @param[in] DbgLevel Debug Level of Trace Hub. >=20 > + @param[in] SeverityType Severity type of input message. >=20 > + >=20 > + @retval TRUE Enable trace hub message. >=20 > + @retval FALSE Disable trace hub message. >=20 > +**/ >=20 > +BOOLEAN >=20 > +EFIAPI >=20 > +TraceHubDataEnabled ( >=20 > + IN BOOLEAN Flag, >=20 > + IN UINT8 DbgLevel, >=20 > + IN TRACE_HUB_SEVERITY_TYPE SeverityType >=20 > + ); >=20 > + >=20 > +/** >=20 > + Convert GUID from LE to BE or BE to LE. >=20 > + >=20 > + @param[in] Guid GUID that need to be converted. >=20 > + @param[out] ConvertedGuid GUID that is converted. >=20 > +**/ >=20 > +VOID >=20 > +EFIAPI >=20 > +SwapBytesGuid ( >=20 > + IN GUID *Guid, >=20 > + OUT GUID *ConvertedGuid >=20 > + ); >=20 > + >=20 > +/** >=20 > + Check whether to output Trace Hub message according to some conditions= . >=20 > + Trace Hub message will be disabled if TraceHubDataEnabled() return FAL= SE >=20 > + or Trace Hub MMIO address is 0. >=20 > + >=20 > + @param[in, out] MipiSystHandle A pointer to MIPI_SYST_HANDLE > structure. >=20 > + @param[in] DbgContext A pointer to Trace Hub debug instanc= e. >=20 > + @param[in] SeverityType Severity type of input message. >=20 > + @param[in] PrintType Either catalog print or debug print. >=20 > + >=20 > + @retval RETURN_SUCCESS Current Trace Hub message need to be > output. >=20 > + @retval Other Current Trace Hub message will be disabled= . >=20 > +**/ >=20 > +RETURN_STATUS >=20 > +EFIAPI >=20 > +CheckWhetherToOutputMsg ( >=20 > + IN OUT MIPI_SYST_HANDLE *MipiSystHandle, >=20 > + IN UINT8 *DbgContext, >=20 > + IN TRACE_HUB_SEVERITY_TYPE SeverityType, >=20 > + IN TRACEHUB_PRINTTYPE PrintType >=20 > + ); >=20 > + >=20 > +/** >=20 > + Get Trace Hub MMIO Address. >=20 > + >=20 > + @param[in] DbgContext A pointer to Trace Hub debug instanc= e. >=20 > + @param[in, out] TraceAddress Trace Hub MMIO Address. >=20 > + >=20 > + @retval RETURN_SUCCESS Operation is successfully. >=20 > + @retval Other Operation is failed. >=20 > +**/ >=20 > +RETURN_STATUS >=20 > +EFIAPI >=20 > +GetTraceHubMmioAddress ( >=20 > + IN UINT8 *DbgContext, >=20 > + IN OUT UINT64 *TraceAddress >=20 > + ); >=20 > + >=20 > +/** >=20 > + Get visibility of Trace Hub Msg. >=20 > + >=20 > + @param[in] DbgContext A pointer to Trace Hub debug instance. >=20 > + @param[in, out] Flag Flag to enable or disable Trace Hub me= ssage. >=20 > + @param[in, out] DbgLevel Debug Level of Trace Hub. >=20 > + >=20 > + @retval RETURN_SUCCESS Operation is successfully. >=20 > + @retval Other Operation is failed. >=20 > +**/ >=20 > +RETURN_STATUS >=20 > +EFIAPI >=20 > +GetTraceHubMsgVisibility ( >=20 > + IN UINT8 *DbgContext, >=20 > + IN OUT BOOLEAN *Flag, >=20 > + IN OUT UINT8 *DbgLevel >=20 > + ); >=20 > + >=20 > +#endif // INTERNAL_TRACE_HUB_API_COMMON_H_ >=20 > diff --git > a/MdeModulePkg/Library/TraceHubDebugSysTLib/PeiTraceHubDebugSysTLib.c > b/MdeModulePkg/Library/TraceHubDebugSysTLib/PeiTraceHubDebugSysTLib.c > new file mode 100644 > index 0000000000..e68fb8b242 > --- /dev/null > +++ > b/MdeModulePkg/Library/TraceHubDebugSysTLib/PeiTraceHubDebugSysTLib.c > @@ -0,0 +1,282 @@ > +/** @file >=20 > +System prints Trace Hub message in PEI based on fixed PCDs and HOB. >=20 > +System applies Trace Hub HOB once it detect gTraceHubDebugInfoHobGuid > HOB. >=20 > +Trace Hub PCDs will be applied if no HOB exist. >=20 > + >=20 > +Copyright (c) 2023, Intel Corporation. All rights reserved.
>=20 > + >=20 > +SPDX-License-Identifier: BSD-2-Clause-Patent >=20 > + >=20 > +**/ >=20 > + >=20 > +#include >=20 > +#include >=20 > +#include >=20 > +#include >=20 > +#include >=20 > +#include >=20 > +#include >=20 > +#include >=20 > +#include >=20 > +#include >=20 > +#include "InternalTraceHubApiCommon.h" >=20 > +#include "InternalTraceHubApi.h" >=20 > + >=20 > +/** >=20 > + Write debug string to specified Trace Hub MMIO address. >=20 > + >=20 > + @param[in] SeverityType Severity type of input message. >=20 > + @param[in] Buffer A pointer to the data buffer. >=20 > + @param[in] NumberOfBytes The size of data buffer. >=20 > + >=20 > + @retval RETURN_SUCCESS Data was written to Trace Hub. >=20 > + @retval Other Failed to output Trace Hub message. >=20 > +**/ >=20 > +RETURN_STATUS >=20 > +EFIAPI >=20 > +TraceHubSysTDebugWrite ( >=20 > + IN TRACE_HUB_SEVERITY_TYPE SeverityType, >=20 > + IN UINT8 *Buffer, >=20 > + IN UINTN NumberOfBytes >=20 > + ) >=20 > +{ >=20 > + MIPI_SYST_HANDLE MipiSystHandle; >=20 > + MIPI_SYST_HEADER MipiSystHeader; >=20 > + RETURN_STATUS Status; >=20 > + UINT8 *DbgContext; >=20 > + UINTN Index; >=20 > + UINT32 DbgInstCount; >=20 > + UINT8 *ThDebugInfo; >=20 > + >=20 > + if (NumberOfBytes =3D=3D 0) { >=20 > + // >=20 > + // No data need to be written to Trace Hub >=20 > + // >=20 > + return RETURN_SUCCESS; >=20 > + } >=20 > + >=20 > + if (Buffer =3D=3D NULL) { >=20 > + return RETURN_INVALID_PARAMETER; >=20 > + } >=20 > + >=20 > + DbgInstCount =3D CountThDebugInstance (); >=20 > + >=20 > + ZeroMem (&MipiSystHandle, sizeof (MIPI_SYST_HANDLE)); >=20 > + MipiSystHandle.systh_header =3D &MipiSystHeader; >=20 > + >=20 > + Status =3D InitMipiSystHandle (&MipiSystHandle); >=20 > + if (RETURN_ERROR (Status)) { >=20 > + return Status; >=20 > + } >=20 > + >=20 > + DbgContext =3D (UINT8 *)GetFirstGuidHob (&gTraceHubDebugInfoHobGuid); >=20 > + if (DbgContext !=3D NULL) { >=20 > + ThDebugInfo =3D GET_GUID_HOB_DATA (DbgContext); >=20 > + } else { >=20 > + ThDebugInfo =3D NULL; >=20 > + } >=20 > + >=20 > + for (Index =3D 0; Index < DbgInstCount; Index++) { >=20 > + Status =3D CheckWhetherToOutputMsg ( >=20 > + &MipiSystHandle, >=20 > + ThDebugInfo, >=20 > + SeverityType, >=20 > + TraceHubDebugType >=20 > + ); >=20 > + if (!RETURN_ERROR (Status)) { >=20 > + Status =3D MipiSystWriteDebug ( >=20 > + &MipiSystHandle, >=20 > + SeverityType, >=20 > + (UINT16)NumberOfBytes, >=20 > + (CHAR8 *)Buffer >=20 > + ); >=20 > + if (RETURN_ERROR (Status)) { >=20 > + break; >=20 > + } >=20 > + } >=20 > + >=20 > + if (DbgContext !=3D NULL) { >=20 > + DbgContext =3D (UINT8 *)GetNextGuidHob > (&gTraceHubDebugInfoHobGuid, GET_NEXT_HOB (DbgContext)); >=20 > + if (DbgContext =3D=3D NULL) { >=20 > + break; >=20 > + } >=20 > + >=20 > + ThDebugInfo =3D GET_GUID_HOB_DATA (DbgContext); >=20 > + } >=20 > + } >=20 > + >=20 > + return Status; >=20 > +} >=20 > + >=20 > +/** >=20 > + Write catalog status code message to specified Trace Hub MMIO address. >=20 > + >=20 > + @param[in] SeverityType Severity type of input message. >=20 > + @param[in] Id Catalog ID. >=20 > + @param[in] Guid Driver Guid. >=20 > + >=20 > + @retval RETURN_SUCCESS Data was written to Trace Hub. >=20 > + @retval Other Failed to output Trace Hub message. >=20 > +**/ >=20 > +RETURN_STATUS >=20 > +EFIAPI >=20 > +TraceHubSysTWriteCataLog64StatusCode ( >=20 > + IN TRACE_HUB_SEVERITY_TYPE SeverityType, >=20 > + IN UINT64 Id, >=20 > + IN GUID *Guid >=20 > + ) >=20 > +{ >=20 > + MIPI_SYST_HANDLE MipiSystHandle; >=20 > + MIPI_SYST_HEADER MipiSystHeader; >=20 > + UINT32 DbgInstCount; >=20 > + UINT8 *DbgContext; >=20 > + RETURN_STATUS Status; >=20 > + UINTN Index; >=20 > + UINT8 *ThDebugInfo; >=20 > + >=20 > + DbgInstCount =3D CountThDebugInstance (); >=20 > + >=20 > + ZeroMem (&MipiSystHandle, sizeof (MIPI_SYST_HANDLE)); >=20 > + MipiSystHandle.systh_header =3D &MipiSystHeader; >=20 > + >=20 > + Status =3D InitMipiSystHandle (&MipiSystHandle); >=20 > + if (RETURN_ERROR (Status)) { >=20 > + return Status; >=20 > + } >=20 > + >=20 > + if (Guid !=3D NULL) { >=20 > + SwapBytesGuid (Guid, (GUID *)(VOID *)&MipiSystHandle.systh_guid); >=20 > + MipiSystHandle.systh_tag.et_guid =3D 1; >=20 > + } else { >=20 > + MipiSystHandle.systh_tag.et_modunit =3D 2; >=20 > + MipiSystHandle.systh_tag.et_guid =3D 0; >=20 > + } >=20 > + >=20 > + DbgContext =3D (UINT8 *)GetFirstGuidHob (&gTraceHubDebugInfoHobGuid); >=20 > + if (DbgContext !=3D NULL) { >=20 > + ThDebugInfo =3D GET_GUID_HOB_DATA (DbgContext); >=20 > + } else { >=20 > + ThDebugInfo =3D NULL; >=20 > + } >=20 > + >=20 > + for (Index =3D 0; Index < DbgInstCount; Index++) { >=20 > + Status =3D CheckWhetherToOutputMsg ( >=20 > + &MipiSystHandle, >=20 > + ThDebugInfo, >=20 > + SeverityType, >=20 > + TraceHubCatalogType >=20 > + ); >=20 > + if (!RETURN_ERROR (Status)) { >=20 > + Status =3D MipiSystWriteCatalog ( >=20 > + &MipiSystHandle, >=20 > + SeverityType, >=20 > + Id >=20 > + ); >=20 > + if (RETURN_ERROR (Status)) { >=20 > + break; >=20 > + } >=20 > + } >=20 > + >=20 > + if (DbgContext !=3D NULL) { >=20 > + DbgContext =3D (UINT8 *)GetNextGuidHob > (&gTraceHubDebugInfoHobGuid, GET_NEXT_HOB (DbgContext)); >=20 > + if (DbgContext =3D=3D NULL) { >=20 > + break; >=20 > + } >=20 > + >=20 > + ThDebugInfo =3D GET_GUID_HOB_DATA (DbgContext); >=20 > + } >=20 > + } >=20 > + >=20 > + return Status; >=20 > +} >=20 > + >=20 > +/** >=20 > + Write catalog message to specified Trace Hub MMIO address. >=20 > + >=20 > + @param[in] SeverityType Severity type of input message. >=20 > + @param[in] Id Catalog ID. >=20 > + @param[in] NumberOfParams Number of entries in argument list. >=20 > + @param[in] ... Catalog message parameters. >=20 > + >=20 > + @retval RETURN_SUCCESS Data was written to Trace Hub. >=20 > + @retval Other Failed to output Trace Hub message. >=20 > +**/ >=20 > +RETURN_STATUS >=20 > +EFIAPI >=20 > +TraceHubSysTWriteCataLog64 ( >=20 > + IN TRACE_HUB_SEVERITY_TYPE SeverityType, >=20 > + IN UINT64 Id, >=20 > + IN UINTN NumberOfParams, >=20 > + ... >=20 > + ) >=20 > +{ >=20 > + MIPI_SYST_HANDLE MipiSystHandle; >=20 > + MIPI_SYST_HEADER MipiSystHeader; >=20 > + VA_LIST Args; >=20 > + UINTN Index; >=20 > + UINT32 DbgInstCount; >=20 > + UINT8 *DbgContext; >=20 > + RETURN_STATUS Status; >=20 > + UINT8 *ThDebugInfo; >=20 > + >=20 > + DbgInstCount =3D 0; >=20 > + >=20 > + if (NumberOfParams > sizeof (MipiSystHandle.systh_param) / sizeof > (UINT32)) { >=20 > + return RETURN_INVALID_PARAMETER; >=20 > + } >=20 > + >=20 > + DbgInstCount =3D CountThDebugInstance (); >=20 > + >=20 > + ZeroMem (&MipiSystHandle, sizeof (MIPI_SYST_HANDLE)); >=20 > + MipiSystHandle.systh_header =3D &MipiSystHeader; >=20 > + >=20 > + Status =3D InitMipiSystHandle (&MipiSystHandle); >=20 > + if (RETURN_ERROR (Status)) { >=20 > + return Status; >=20 > + } >=20 > + >=20 > + MipiSystHandle.systh_param_count =3D (UINT32)NumberOfParams; >=20 > + VA_START (Args, NumberOfParams); >=20 > + for (Index =3D 0; Index < NumberOfParams; Index++) { >=20 > + MipiSystHandle.systh_param[Index] =3D VA_ARG (Args, UINT32); >=20 > + } >=20 > + >=20 > + VA_END (Args); >=20 > + >=20 > + DbgContext =3D (UINT8 *)GetFirstGuidHob (&gTraceHubDebugInfoHobGuid); >=20 > + if (DbgContext !=3D NULL) { >=20 > + ThDebugInfo =3D GET_GUID_HOB_DATA (DbgContext); >=20 > + } else { >=20 > + ThDebugInfo =3D NULL; >=20 > + } >=20 > + >=20 > + for (Index =3D 0; Index < DbgInstCount; Index++) { >=20 > + Status =3D CheckWhetherToOutputMsg ( >=20 > + &MipiSystHandle, >=20 > + ThDebugInfo, >=20 > + SeverityType, >=20 > + TraceHubCatalogType >=20 > + ); >=20 > + if (!RETURN_ERROR (Status)) { >=20 > + Status =3D MipiSystWriteCatalog ( >=20 > + &MipiSystHandle, >=20 > + SeverityType, >=20 > + Id >=20 > + ); >=20 > + if (RETURN_ERROR (Status)) { >=20 > + break; >=20 > + } >=20 > + } >=20 > + >=20 > + if (DbgContext !=3D NULL) { >=20 > + DbgContext =3D (UINT8 *)GetNextGuidHob > (&gTraceHubDebugInfoHobGuid, GET_NEXT_HOB (DbgContext)); >=20 > + if (DbgContext =3D=3D NULL) { >=20 > + break; >=20 > + } >=20 > + >=20 > + ThDebugInfo =3D GET_GUID_HOB_DATA (DbgContext); >=20 > + } >=20 > + } >=20 > + >=20 > + return Status; >=20 > +} >=20 > diff --git > a/MdeModulePkg/Library/TraceHubDebugSysTLib/PeiTraceHubDebugSysTLib.i > nf > b/MdeModulePkg/Library/TraceHubDebugSysTLib/PeiTraceHubDebugSysTLib.i > nf > new file mode 100644 > index 0000000000..2a8184d927 > --- /dev/null > +++ > b/MdeModulePkg/Library/TraceHubDebugSysTLib/PeiTraceHubDebugSysTLib.i > nf > @@ -0,0 +1,50 @@ > +## @file >=20 > +# Debug library to output Trace Hub message. >=20 > +# Support PEI phase TraceHub debug message based on fixed or dynamic > settings. >=20 > +# >=20 > +# Copyright (c) 2023, Intel Corporation. All rights reserved.
>=20 > +# >=20 > +# SPDX-License-Identifier: BSD-2-Clause-Patent >=20 > +# >=20 > +## >=20 > + >=20 > +[Defines] >=20 > + INF_VERSION =3D 0x00010005 >=20 > + BASE_NAME =3D PeiTraceHubDebugSysTLib >=20 > + FILE_GUID =3D C61E8C2E-0935-4E3D-BCBB-5ED84AFD9FD= 1 >=20 > + MODULE_TYPE =3D PEIM >=20 > + VERSION_STRING =3D 1.0 >=20 > + LIBRARY_CLASS =3D TraceHubDebugSysTLib|PEI_CORE PEIM >=20 > + >=20 > +# >=20 > +# The following information is for reference only and not required by th= e > build tools. >=20 > +# >=20 > +# VALID_ARCHITECTURES =3D IA32 X64 >=20 > +# >=20 > + >=20 > +[LibraryClasses] >=20 > + BaseLib >=20 > + PcdLib >=20 > + HobLib >=20 > + BaseMemoryLib >=20 > + MemoryAllocationLib >=20 > + MipiSysTLib >=20 > + >=20 > +[Packages] >=20 > + MdePkg/MdePkg.dec >=20 > + MdeModulePkg/MdeModulePkg.dec >=20 > + >=20 > +[Sources] >=20 > + PeiTraceHubDebugSysTLib.c >=20 > + InternalTraceHubApiCommon.c >=20 > + InternalTraceHubApiCommon.h >=20 > + InternalTraceHubApi.h >=20 > + InternalTraceHubApi.c >=20 > + >=20 > +[Guids] >=20 > + gTraceHubDebugInfoHobGuid >=20 > + >=20 > +[Pcd] >=20 > + gEfiMdeModulePkgTokenSpaceGuid.PcdTraceHubDebugLevel >=20 > + gEfiMdeModulePkgTokenSpaceGuid.PcdEnableTraceHubDebugMsg >=20 > + gEfiMdeModulePkgTokenSpaceGuid.PcdTraceHubDebugMmioAddress >=20 > diff --git a/MdeModulePkg/Library/TraceHubDebugSysTLib/Readme.md > b/MdeModulePkg/Library/TraceHubDebugSysTLib/Readme.md > new file mode 100644 > index 0000000000..9e798a41bf > --- /dev/null > +++ b/MdeModulePkg/Library/TraceHubDebugSysTLib/Readme.md > @@ -0,0 +1,26 @@ > +## Introduction of TrcaceHubDebugSysTLib ## >=20 > +TrcaceHubDebugSysTLib library is a top level library for dumping Trace H= ub > messages. >=20 > +It provides Trace Hub related APIs to dump Trace Hub message via MIPI SY= S- > T submodule. >=20 > +User need to properly configure following Trace Hub related PCDs and HOB= . >=20 > + (See MdeModulePkg.dec to get detailed definition for PCDs below) >=20 > + - PcdTraceHubDebugLevel >=20 > + - PcdEnableTraceHubDebugMsg >=20 > + - PcdTraceHubDebugMmioAddress >=20 > + (See TraceHubDebugInfoHob.h to get detailed definition for HOB below) >=20 > + - gTraceHubDebugInfoHobGuid >=20 > + >=20 > +## BaseTraceHubDebugSysTLib.inf ## >=20 > +System prints Trace Hub message in SEC/PEI/DXE/SMM based on fixed PCDs. >=20 > +Only support single Trace Hub debug instance. >=20 > + >=20 > +## PeiTraceHubDebugSysTLib.inf ## >=20 > +System prints Trace Hub message in PEI based on fixed PCDs and HOB. >=20 > +System applies Trace Hub HOB once it detect gTraceHubDebugInfoHobGuid > HOB. >=20 > +Trace Hub PCDs will be applied if no HOB exist. >=20 > + >=20 > +## DxeSmmTraceHubDebugSysTLib.inf ## >=20 > +System prints Trace Hub message in DXE/SMM based on fixed PCDs and HOB. >=20 > +Trace Hub PCDs will be applied if no HOB exist. >=20 > + >=20 > +## Note ## >=20 > +Trace Hub debug library not support DXE_RUNTIME_DRIVER type of module > currently. >=20 > diff --git a/MdeModulePkg/MdeModulePkg.dec > b/MdeModulePkg/MdeModulePkg.dec > index 9bb0d3ba2d..95dd077e19 100644 > --- a/MdeModulePkg/MdeModulePkg.dec > +++ b/MdeModulePkg/MdeModulePkg.dec > @@ -439,6 +439,9 @@ > ## Include/UniversalPayload/SerialPortInfo.h >=20 > gUniversalPayloadSerialPortInfoGuid =3D { 0xaa7e190d, 0xbe21, 0x4409, = { > 0x8e, 0x67, 0xa2, 0xcd, 0xf, 0x61, 0xe1, 0x70 } } >=20 >=20 >=20 > + ## Include/Guid/TraceHubDebugInfoHob.h >=20 > + gTraceHubDebugInfoHobGuid =3D { 0xf88c9c23, 0x646c, 0x4f6c, { 0x8e, 0x= 3d, > 0x36, 0xa9, 0x43, 0xc1, 0x08, 0x35 } } >=20 > + >=20 > ## GUID used for Boot Discovery Policy FormSet guid and related variab= les. >=20 > gBootDiscoveryPolicyMgrFormsetGuid =3D { 0x5b6f7107, 0xbb3c, 0x4660, { > 0x92, 0xcd, 0x54, 0x26, 0x90, 0x28, 0x0b, 0xbd } } >=20 >=20 >=20 > @@ -1095,6 +1098,24 @@ > # @Prompt Enable UEFI Stack Guard. >=20 >=20 > gEfiMdeModulePkgTokenSpaceGuid.PcdCpuStackGuard|FALSE|BOOLEAN|0x30 > 001055 >=20 >=20 >=20 > + ## Indicate debug level of Trace Hub. >=20 > + # 0x0 - TraceHubDebugLevelError.
>=20 > + # 0x1 - TraceHubDebugLevelErrorWarning.
>=20 > + # 0x2 - TraceHubDebugLevelErrorWarningInfo.
>=20 > + # 0x3 - TraceHubDebugLevelErrorWarningInfoVerbose.
>=20 > + # @Prompt Debug level of Trace Hub. >=20 > + > gEfiMdeModulePkgTokenSpaceGuid.PcdTraceHubDebugLevel|0|UINT8|0x3000 > 1056 >=20 > + >=20 > + ## Flag to enable or disable Trace Hub message. >=20 > + # FALSE - Disable Trace Hub debug message.
>=20 > + # TRUE - Enable Trace Hub debug message.
>=20 > + # @Prompt Enable or Disable Trace Hub message. >=20 > + > gEfiMdeModulePkgTokenSpaceGuid.PcdEnableTraceHubDebugMsg|0|BOOLEA > N|0x30001057 >=20 > + >=20 > + ## Indicate MMIO address where Trace Hub message output to. >=20 > + # @Prompt Output MMIO address of Trace Hub message. >=20 > + > gEfiMdeModulePkgTokenSpaceGuid.PcdTraceHubDebugMmioAddress|0|UINT > 64|0x30001058 >=20 > + >=20 > [PcdsFixedAtBuild, PcdsPatchableInModule] >=20 > ## Dynamic type PCD can be registered callback function for Pcd settin= g > action. >=20 > # PcdMaxPeiPcdCallBackNumberPerPcdEntry indicates the maximum > number of callback function >=20 > diff --git a/MdeModulePkg/MdeModulePkg.dsc > b/MdeModulePkg/MdeModulePkg.dsc > index 1014598f31..5b1f50e9c0 100644 > --- a/MdeModulePkg/MdeModulePkg.dsc > +++ b/MdeModulePkg/MdeModulePkg.dsc > @@ -515,6 +515,9 @@ > MdeModulePkg/Universal/RegularExpressionDxe/RegularExpressionDxe.inf >=20 >=20 > MdeModulePkg/Universal/SmmCommunicationBufferDxe/SmmCommunicatio > nBufferDxe.inf >=20 > MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskDxe.inf >=20 > + > MdeModulePkg/Library/TraceHubDebugSysTLib/BaseTraceHubDebugSysTLib.i > nf >=20 > + > MdeModulePkg/Library/TraceHubDebugSysTLib/PeiTraceHubDebugSysTLib.inf >=20 > + > MdeModulePkg/Library/TraceHubDebugSysTLib/DxeSmmTraceHubDebugSysTL > ib.inf >=20 >=20 >=20 > [Components.X64] >=20 > MdeModulePkg/Universal/CapsulePei/CapsuleX64.inf >=20 > diff --git a/MdeModulePkg/MdeModulePkg.uni > b/MdeModulePkg/MdeModulePkg.uni > index 33ce9f6198..a17d34d60b 100644 > --- a/MdeModulePkg/MdeModulePkg.uni > +++ b/MdeModulePkg/MdeModulePkg.uni > @@ -1290,6 +1290,24 @@ > = " TRUE - UEFI Stack Guard > will be enabled.
\n" >=20 > = " FALSE - UEFI Stack Guard > will be disabled.
" >=20 >=20 >=20 > +#string > STR_gEfiMdeModulePkgTokenSpaceGuid_PcdTraceHubDebugLevel_PROMPT > #language en-US "Debug level of Trace Hub." >=20 > + >=20 > +#string > STR_gEfiMdeModulePkgTokenSpaceGuid_PcdTraceHubDebugLevel_HELP > #language en-US "Indicate debug level of Trace Hub" >=20 > + = " 0x0 - > TraceHubDebugLevelError.
" >=20 > + = " 0x1 - > TraceHubDebugLevelErrorWarning.
" >=20 > + = " 0x2 - > TraceHubDebugLevelErrorWarningInfo.
" >=20 > + = " 0x3 - > TraceHubDebugLevelErrorWarningInfoVerbose.
" >=20 > + >=20 > +#string > STR_gEfiMdeModulePkgTokenSpaceGuid_PcdEnableTraceHubDebugMsg_PRO > MPT #language en-US "Flag to enable or disable Trace Hub message" >=20 > + >=20 > +#string > STR_gEfiMdeModulePkgTokenSpaceGuid_PcdEnableTraceHubDebugMsg_HELP > #language en-US "Enable or Disable Trace Hub message" >=20 > + = " FALSE - Disable > Trace Hub debug message.
" >=20 > + = " TRUE - Enable > Trace Hub debug message.
" >=20 > + >=20 > +#string > STR_gEfiMdeModulePkgTokenSpaceGuid_PcdTraceHubDebugMmioAddress_P > ROMPT #language en-US "Output MMIO address of Trace Hub message" >=20 > + >=20 > +#string > STR_gEfiMdeModulePkgTokenSpaceGuid_PcdTraceHubDebugMmioAddress_H > ELP #language en-US "Indicate MMIO address where Trace Hub message > output to." >=20 > + >=20 > #string > STR_gEfiMdeModulePkgTokenSpaceGuid_PcdSetNvStoreDefaultId_PROMPT > #language en-US "NV Storage DefaultId" >=20 >=20 >=20 > #string > STR_gEfiMdeModulePkgTokenSpaceGuid_PcdSetNvStoreDefaultId_HELP > #language en-US "This dynamic PCD enables the default variable setting.\n= " >=20 > -- > 2.39.2.windows.1