From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by mx.groups.io with SMTP id smtpd.web10.4201.1675135049124126828 for ; Mon, 30 Jan 2023 19:17:29 -0800 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=kEdOpO8F; spf=pass (domain: intel.com, ip: 192.55.52.88, mailfrom: gua.guo@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1675135049; x=1706671049; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=ovFsc6Ru8Jh9AXvSdxRYHsr3qjlFf3kT6VbEuAxMWtA=; b=kEdOpO8FiAA393aOW+7uBJNgU2UUbISw4mkg4zi14e9YlLZPzxWS2vFg ++lIstoXJ5XPI5G0+z+mRDGl6e5Lp8Qd9zBgvy4waEYeJTa2eYX0M2eU9 dhcRwB4oWUG+oOU2RHtadtHeKMuhvUOylpL0QpednkMnAdwWJrAimM+Py ICgs/eUuQiEMEmhEYMRXHhud+ZMfsWkMWRoU5tx4AygT5xdlGiKmzr5v+ G/7qW5Gqvl1lAhDzcWezBR8+Hzg+A5YKuPMrIbTnmDAWFoE7eiF/5JYY2 EP2G/I+hoX1bDnTPRGlUGYfDZCZm+iCMj6GoQIWJqpVom9ab+DIdA6bHx Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10606"; a="355063275" X-IronPort-AV: E=Sophos;i="5.97,259,1669104000"; d="scan'208";a="355063275" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Jan 2023 19:17:28 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10606"; a="806944292" X-IronPort-AV: E=Sophos;i="5.97,259,1669104000"; d="scan'208";a="806944292" Received: from orsmsx601.amr.corp.intel.com ([10.22.229.14]) by fmsmga001.fm.intel.com with ESMTP; 30 Jan 2023 19:17:28 -0800 Received: from orsmsx611.amr.corp.intel.com (10.22.229.24) by ORSMSX601.amr.corp.intel.com (10.22.229.14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.16; Mon, 30 Jan 2023 19:17:28 -0800 Received: from orsmsx610.amr.corp.intel.com (10.22.229.23) by ORSMSX611.amr.corp.intel.com (10.22.229.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.16; Mon, 30 Jan 2023 19:17:27 -0800 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.16 via Frontend Transport; Mon, 30 Jan 2023 19:17:27 -0800 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (104.47.57.170) 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.16; Mon, 30 Jan 2023 19:17:27 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MopVpkcgeS0UoPszZ26x/MW5LZMGyWJKLcX4ijujhtf7Nk62PvwLlRLC9DbJreJFQc9/Frc7LERCOH6dgLpdkST/5j3FTL+sqWB0v65/dmS0sQZf6wLxYcRXxOtS6tQYE2nL1OzTPSl7jKBjBuDUoigspYKvKiCT7LY9/1AMATXZ/bZh4gnnMwg6ozOAidud7xjZL5eSeU67UxZd0b/04cF/EyirS9A3uR/Td+Z6Eg0RmcNmmOQToizMlaMn6AxkNmxU8QDZdk4Jh+MzVsSdCXflh4DOuCIBT5tXs4tCiz5fXUfr8sIBsgAM9fWGDukG5QhhBUUZ1YUKQaDkoZ7y5A== 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=4jF7qin4X1uCuhUOcr+3L9l/XvS6MNLiSDITDRPoriI=; b=kVH+n85TFEOwxqFwuianDTJMzEGFlLbT3+BYPBSzQPIpvG1oB/JPQ0aHcMCRQKN2aA5pmrOpaEHIMakA3k5vCsOvt5sTpzFBosvc3osXmi6xdZDVbIg2Bom5eW6T/1Z3HKa83uCnYGsl62F9glXRgAPhfrzMHn5rOeF3KHLMnug4T3m+vHNDW4NH0yjhyPTlO81MugbxYMFkKgnnZFbHOT720cDZGr+X1SWgnAltnCWcAuG9AwA2eaXzjrrG0ADGxerYNofSpQhlN3jTaZB1DQUV/zmhIYLnVu8gmNwKoaOrjCUUhfNDUdoameOBzP4voV5DafQ0AKo+6aNakRYGYA== 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 BN9PR11MB5483.namprd11.prod.outlook.com (2603:10b6:408:104::10) by SA2PR11MB5194.namprd11.prod.outlook.com (2603:10b6:806:118::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6043.36; Tue, 31 Jan 2023 03:17:24 +0000 Received: from BN9PR11MB5483.namprd11.prod.outlook.com ([fe80::ee18:f0d6:8983:5a24]) by BN9PR11MB5483.namprd11.prod.outlook.com ([fe80::ee18:f0d6:8983:5a24%3]) with mapi id 15.20.6043.036; Tue, 31 Jan 2023 03:17:24 +0000 From: "Guo, Gua" To: "Hsu, VictorX" , "devel@edk2.groups.io" CC: "Kinney, Michael D" , "Chan, Laura" , "Prakashan, Krishnadas Veliyathuparambil" , "K N, Karthik" Subject: Re: [PATCH 2/4] MdeModulePkg: Add TraceHubDebugLibSysT library Thread-Topic: [PATCH 2/4] MdeModulePkg: Add TraceHubDebugLibSysT library Thread-Index: AQHZNR6sNav9GoRSsUajfdyzKa30y6632srQ Date: Tue, 31 Jan 2023 03:17:23 +0000 Message-ID: References: <29c690501f493d9d003ee7089228a7273c3ff091.1675131785.git.victorx.hsu@intel.com> In-Reply-To: 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: BN9PR11MB5483:EE_|SA2PR11MB5194:EE_ x-ms-office365-filtering-correlation-id: 8f030dfe-587f-4c1c-e4c3-08db0339ac24 x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: Nh9bGKsul0npb6ScZXRYNG8mzRQgM7LZG/VrbgnZYuqgtU4vDU3iGKvAn3F/o83vh0nOlEAV0rqcpaAUvg6qL7MrrhbUHYF2sWQt/evCE33mS3ky32FoQO00JVKdOdi3fH1dJfcuT5ijoeSH+n5vQBX8pfg4ZwqHwx6OGh2kF0nFIu6Ru2nN11ybu51NHenAdLui/3zz7vOlS7cOHuVvM7QjJkAgyB3spJT/b5eZ86xuc5rJ/HIEbQREPqn6ZuN1ZBJ5k9ElONqfaWHrcMOn2sb+2kFbu+rPsLwGClcIQux7xcVxxyVMOJiPK/G8Lr5MioktiMTmKVkLCBP4unuV4QR61XWL/inYN1f5Li2ajbnM78AihVWYIGmwv+dJfeIAyZKpB8sfxICxjW0ASn5XQqbky1jYX9yFM45h0I3riNmQnN9HzljDUEbyxE0VqSOZXEnBsMw4NFp0HvGrDy72zOtYQjEzE0mz8DdiM6hnzfxf4qdmU0NOqjIQMqlTq7byhxhZFQJ6vjiKgChoaHxYRHFDEfeb3yuJHKu7y6UOSR7xQXmpdGKvV0tB8vdV4WdZ9mQXYzVbO3trQBwv6J11mz94GERoJ95xT0UB/SCv7HyUBfjHP48xz1aWVPvWsFuPyWMDIhIyfvIZqWg0GXVQfZeH3SR3FpjzWVVL8L8YXDyx0LtYnBFOU/J2UDrgAgBMY2IoVJMeUJlRSbQEZdZbUwdf4qlsTADxqVMThXtGEulAz/hp0yKx2KORgYZTu7nj x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BN9PR11MB5483.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230025)(346002)(376002)(39860400002)(136003)(396003)(366004)(451199018)(8936002)(41300700001)(30864003)(52536014)(66556008)(66446008)(5660300002)(83380400001)(55016003)(122000001)(86362001)(38100700002)(66476007)(38070700005)(82960400001)(4326008)(76116006)(64756008)(71200400001)(7696005)(8676002)(316002)(478600001)(54906003)(110136005)(66946007)(186003)(6506007)(26005)(107886003)(9686003)(53546011)(966005)(33656002)(2906002)(213903007)(579004)(559001);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?FID/IL/7hHFa7UU9VNTUnsZq6h3/26A3JTN7QO1AUR1vhL5nZuenKnmtleEJ?= =?us-ascii?Q?cHFzRmHmNmvExn1nUiRuBJp+9EF4Z8QUQ/9DsaV29aYfRaScN6WNjmhmnzNd?= =?us-ascii?Q?7AfxcHIz27sz3rVDnDxF8UkQCbVGnlhgBbpl/Ab7fSZBPO+IC2kZ0VspVCeR?= =?us-ascii?Q?ROGd/hvbeUoelFlKsU1A+mwnBYonTwTMRqvzKH8aCK9lKPnPf2sZ+kmP0Sid?= =?us-ascii?Q?hvXVGW+I/nlP7NUSCR62qu7l0yFXQ+80eg3NmEDcsjpl98r6Hz/nqP+bVRe8?= =?us-ascii?Q?DHXhWjPjXpTShw80iIJUs+PIbbqksrvVs8vf8GIZXjN4a+tl74Rw3ZzS2sOy?= =?us-ascii?Q?wTmVPStjsqPpPHmOAuzqqrjXeQlkQYy6bmeetpy9qdxOc4hr3eLKICTcWC8O?= =?us-ascii?Q?zHcEVPTX+Y6Hg35HkL/HqChUqaAeRKID808r0a01ZV/1Klq93XszWPVF+cfz?= =?us-ascii?Q?7K1PZBpPRjOuKSsZUSi7mSaG1bH6CqgmACkXaSl+wzENikKKzRZwBasWujNg?= =?us-ascii?Q?hlBW4fQ5YEKzH/RhDDA+x0ZNaAmNmNHhbva7MDnJuKf0flc71vYTIuL2+zmg?= =?us-ascii?Q?P205ZduQk2AVn6sGM72QKsnbDUjj9cGNUWDrOCvYVZUb11ZN8vXVYpnq1E1c?= =?us-ascii?Q?sPChV4hLgp0wYHhv0iT6//ev5qdvjmaxsJuVomgmnMsPFXJ8Nh0MSRQm27fp?= =?us-ascii?Q?Wr6l6GShxENdHKkKbZZuRRQ5vaK5O8H/SM89fxybcazRV6SH2p5s7jVJ9RZO?= =?us-ascii?Q?Geummp04n+0r9gxn7KZGU0CgoPxC9U0RsJhZ6DaDLu9oE+aaEk/oCplKmS5F?= =?us-ascii?Q?mMioDxPFne6DhPAlmeMP48h577shqkGyFOQ3R6nv7VDE0fsukOEBhxG1nFHW?= =?us-ascii?Q?fETggC7NlPtGagQ4+S3PO4V18Ck6PX+EOAReUyMJoWaE4/DhRL3PnGYACr0D?= =?us-ascii?Q?ihtgObtNrvwhYaV0yvN3MsvyfOhC/R6wazwPlK04pzBw7ReWEBBcTXGi4bz9?= =?us-ascii?Q?BaoDq58WXKhEunaUKq4i2M1nhZBMUjGhBIo5fRtWXH9Kg6Y/Co6yZ4UWhxvr?= =?us-ascii?Q?+UhXXWayVaegkQNdrjwG2eTdCPsrR74YmwcA0VyKMtti3F4EMzHrYoVPFZSi?= =?us-ascii?Q?xpoNYk+6X6k6T70+e+V2geGKdsAosuoKeXLxJ5/mdWDDRikFcNrMr5FZvkOF?= =?us-ascii?Q?oO6kk+jM+wNH9nP4tDfZQcXVLZRtqwMoUV+qkgy02BX8ynsAsq8882blDBsj?= =?us-ascii?Q?GzC4HOjX1h/P6EeLzJHATvlDgQvYfh7SXgHI9uwo19olXlAZ2UIMkzQ2eMj7?= =?us-ascii?Q?TBNbd311Fj4qttTC9yN3YfecbKVBZyUdtT1cc+E/y5J0MwAnLOYSaakMj5CR?= =?us-ascii?Q?n/HIDSNnHrFPfY8SgmmxBo7xr76uHoW3BSTMgdzLBoo0W7K/+eN4z0tYMFs5?= =?us-ascii?Q?MhkqTx4RLCqOUhR9RhZE/wTjPfOCwCyp5bF7oxRx9VHEUuG85cr4n8toHwKn?= =?us-ascii?Q?4yltOTmbarJmHPm99lQRZ5oZ7EYWPK3KgVx+Fs3goyXP6+rj+n9n6WNZj+Qr?= =?us-ascii?Q?oAJwkh7aVofx2NuYoHc=3D?= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: BN9PR11MB5483.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8f030dfe-587f-4c1c-e4c3-08db0339ac24 X-MS-Exchange-CrossTenant-originalarrivaltime: 31 Jan 2023 03:17:23.9019 (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: rcGabgg4LwkUeCbvKbQoapTj8+DIArrNSxgM39F9lz5vrlERLP6wygBwrEaccpmqyQBZOlILBgEFM1wrOZvmiw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA2PR11MB5194 Return-Path: gua.guo@intel.com X-OriginatorOrg: intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Gua Guo -----Original Message----- From: Hsu, VictorX =20 Sent: Tuesday, January 31, 2023 10:49 AM To: devel@edk2.groups.io Cc: Hsu, VictorX ; Kinney, Michael D ; Guo, Gua ; Chan, Laura ; Prakashan, Krishnadas Veliyathuparambil ; K N, Karthik Subject: [PATCH 2/4] MdeModulePkg: Add TraceHubDebugLibSysT library From: VictorX Hsu REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4144 This Library provide Trace Hub API which consume MipiSysTLib. Cc: Michael D Kinney Cc: Guo Gua Cc: Chan Laura Cc: Prakashan Krishnadas Veliyathuparambil Cc: K N Karthik Signed-off-by: VictorX Hsu --- .../UniversalPayload/TraceHubDebugInfo.h | 31 ++ .../BaseTraceHubDebugLibSyst.inf | 44 ++ .../BaseTraceHubDebugSystLib.c | 386 +++++++++++++++ .../DxeSmmTraceHubDebugLibSyst.inf | 49 ++ .../DxeSmmTraceHubDebugSystLib.c | 462 ++++++++++++++++++ .../PeiTraceHubDebugLibSyst.inf | 49 ++ .../PeiTraceHubDebugSystLib.c | 446 +++++++++++++++++ .../TraceHubDebugLibSysT/TraceHubApiCommon.c | 81 +++ .../TraceHubDebugLibSysT/TraceHubApiCommon.h | 64 +++ .../TraceHubApiInternal.h | 92 ++++ MdeModulePkg/MdeModulePkg.dec | 21 + MdeModulePkg/MdeModulePkg.dsc | 6 + MdeModulePkg/MdeModulePkg.uni | 18 + 13 files changed, 1749 insertions(+) create mode 100644 MdeModulePkg/Include/UniversalPayload/TraceHubDebugInfo= .h create mode 100644 MdeModulePkg/Library/TraceHubDebugLibSysT/BaseTraceHubD= ebugLibSyst.inf create mode 100644 MdeModulePkg/Library/TraceHubDebugLibSysT/BaseTraceHubD= ebugSystLib.c create mode 100644 MdeModulePkg/Library/TraceHubDebugLibSysT/DxeSmmTraceHu= bDebugLibSyst.inf create mode 100644 MdeModulePkg/Library/TraceHubDebugLibSysT/DxeSmmTraceHu= bDebugSystLib.c create mode 100644 MdeModulePkg/Library/TraceHubDebugLibSysT/PeiTraceHubDe= bugLibSyst.inf create mode 100644 MdeModulePkg/Library/TraceHubDebugLibSysT/PeiTraceHubDe= bugSystLib.c create mode 100644 MdeModulePkg/Library/TraceHubDebugLibSysT/TraceHubApiCo= mmon.c create mode 100644 MdeModulePkg/Library/TraceHubDebugLibSysT/TraceHubApiCo= mmon.h create mode 100644 MdeModulePkg/Library/TraceHubDebugLibSysT/TraceHubApiIn= ternal.h diff --git a/MdeModulePkg/Include/UniversalPayload/TraceHubDebugInfo.h b/Md= eModulePkg/Include/UniversalPayload/TraceHubDebugInfo.h new file mode 100644 index 0000000000..6c95a85451 --- /dev/null +++ b/MdeModulePkg/Include/UniversalPayload/TraceHubDebugInfo.h @@ -0,0 +1,31 @@ +/** @file + Define the structure for the Universal Payload TraceHub Debug Info. + +Copyright (c) 2023, Intel Corporation. All rights reserved.
+SPDX-License-Identifier: BSD-2-Clause-Patent + + @par Revision Reference: + - Universal Payload Specification 0.9 (https://universalpayload.github= .io/documentation/) +**/ + +#ifndef UNIVERSAL_PAYLOAD_TRACEHUB_DEBUG_INFO_H_ +#define UNIVERSAL_PAYLOAD_TRACEHUB_DEBUG_INFO_H_ + +#include + +typedef struct { + BOOLEAN Flag; // Flag to enable or disable Trace Hub debug me= ssage. + UINT8 DebugLevel; // Debug level for Trace Hub. + UINTN TraceAddress; // MMIO address where Trace Hub debug message o= utput to. +} TRACEHUB_DEBUG_CONTEXT; + +typedef struct { + UNIVERSAL_PAYLOAD_GENERIC_HEADER Header; + TRACEHUB_DEBUG_CONTEXT DebugContext; +} UNIVERSAL_PAYLOAD_TRACEHUB_DEBUG_INFO; + +#define UNIVERSAL_PAYLOAD_TRACEHUB_DEBUG_INFO_REVISION 1 + +extern EFI_GUID gUniversalPayloadTraceHubDebugInfoGuid; + +#endif // UNIVERSAL_PAYLOAD_TRACEHUB_DEBUG_INFO_H_ diff --git a/MdeModulePkg/Library/TraceHubDebugLibSysT/BaseTraceHubDebugLib= Syst.inf b/MdeModulePkg/Library/TraceHubDebugLibSysT/BaseTraceHubDebugLibSy= st.inf new file mode 100644 index 0000000000..96ecf9147a --- /dev/null +++ b/MdeModulePkg/Library/TraceHubDebugLibSysT/BaseTraceHubDebugLibSyst.in= f @@ -0,0 +1,44 @@ +## @file +# Debug library to output Trace Hub message. +# Support SEC/PEI/DXE/SMM phase TraceHub debug message based on fixed set= tings. +# +# Copyright (c) 2023, Intel Corporation. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 0x00010005 + BASE_NAME =3D BaseTraceHubDebugLibSyst + FILE_GUID =3D 336DA571-AD65-423C-9A43-E0056E5B2D8D + MODULE_TYPE =3D BASE + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D TraceHubDebugLib + +# +# The following information is for reference only and not required by the = build tools. +# +# VALID_ARCHITECTURES =3D IA32 X64 +# + +[LibraryClasses] + BaseLib + PcdLib + BaseMemoryLib + MipiSysTLib + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + +[Sources] + BaseTraceHubDebugSystLib.c + TraceHubApiCommon.c + TraceHubApiCommon.h + TraceHubApiInternal.h + +[Pcd] + gEfiMdeModulePkgTokenSpaceGuid.PcdTraceHubDebugLevel + gEfiMdeModulePkgTokenSpaceGuid.PcdEnableTraceHubDebugMsg + gEfiMdeModulePkgTokenSpaceGuid.PcdTraceHubDebugAddress diff --git a/MdeModulePkg/Library/TraceHubDebugLibSysT/BaseTraceHubDebugSys= tLib.c b/MdeModulePkg/Library/TraceHubDebugLibSysT/BaseTraceHubDebugSystLib= .c new file mode 100644 index 0000000000..b0e99c69a3 --- /dev/null +++ b/MdeModulePkg/Library/TraceHubDebugLibSysT/BaseTraceHubDebugSystLib.c @@ -0,0 +1,386 @@ +/** @file + +Copyright (c) 2023, Intel Corporation. All rights reserved.
+ +SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include +#include +#include +#include "TraceHubApiCommon.h" +#include "TraceHubApiInternal.h" + +/** + Write debug string to specified Trace Hub MMIO address. + + @param[in] SeverityType An error level to decide whether to enable = Trace Hub data. + @param[in] Buffer A pointer to the data buffer. + @param[in] NumberOfBytes Number of bytes to be written. + + @retval EFI_SUCCESS Data was written to Trace Hub. + @retval Other Failed to output Trace Hub message. +**/ +EFI_STATUS +EFIAPI +TraceHubDebugWrite ( + IN TRACE_HUB_SEVERITY_TYPE SeverityType, + IN UINT8 *Buffer, + IN UINTN NumberOfBytes + ) +{ + MIPI_SYST_HANDLE MipiSystHandle; + MIPI_SYST_HEADER MipiSystHeader; + EFI_STATUS Status; + UINT32 DbgInstCount; + UINT16 Index; + + DbgInstCount =3D 0; + + if ((NumberOfBytes =3D=3D 0) || (Buffer =3D=3D NULL)) { + // + // No data need to be written to Trace Hub + // + return EFI_ABORTED; + } + + Status =3D MigrateTraceHubHobData (); + + MipiSystHandle.systh_header =3D &MipiSystHeader; + + Status =3D InitMipiSystHandle (&MipiSystHandle); + if (EFI_ERROR (Status)) { + return Status; + } + + Status =3D CountDebugInstance (&DbgInstCount); + if (EFI_ERROR (Status)) { + return Status; + } + + for (Index =3D 0; Index < DbgInstCount; Index++) { + Status =3D CheckWhetherToOutputMsg ( + &MipiSystHandle, + NULL, + (MIPI_SYST_SEVERITY)SeverityType, + TraceHubDebugType + ); + if (!EFI_ERROR (Status)) { + Status =3D MipiSystWriteDebug ( + &MipiSystHandle, + (MIPI_SYST_SEVERITY)SeverityType, + (UINT16)NumberOfBytes, + (CHAR8 *)Buffer + ); + if (EFI_ERROR (Status)) { + break; + } + } + } + + return Status; +} + +/** + Write catalog status code message to specified Trace Hub MMIO address. + + @param[in] SeverityType An error level to decide whether to enable = Trace Hub data. + @param[in] Id Catalog ID. + @param[in] Guid Driver Guid. + + @retval EFI_SUCCESS Data was written to Trace Hub. + @retval Other Failed to output Trace Hub message. +**/ +EFI_STATUS +EFIAPI +TraceHubWriteCataLog64StatusCode ( + IN TRACE_HUB_SEVERITY_TYPE SeverityType, + IN UINT64 Id, + IN EFI_GUID *Guid + ) +{ + MIPI_SYST_HANDLE MipiSystHandle; + MIPI_SYST_HEADER MipiSystHeader; + EFI_STATUS Status; + UINT32 DbgInstCount; + UINT16 Index; + + DbgInstCount =3D 0; + + if (Guid =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + Status =3D MigrateTraceHubHobData (); + + MipiSystHandle.systh_header =3D &MipiSystHeader; + + Status =3D InitMipiSystHandle (&MipiSystHandle); + if (EFI_ERROR (Status)) { + return Status; + } + + // + // Convert little endian to big endian. + // + Status =3D LittleEndianToBigEndian (Guid); + CopyMem (&MipiSystHandle.systh_guid, Guid, sizeof (EFI_GUID)); + MipiSystHandle.systh_tag.et_guid =3D 1; + + Status =3D CountDebugInstance (&DbgInstCount); + if (EFI_ERROR (Status)) { + return Status; + } + + for (Index =3D 0; Index < DbgInstCount; Index++) { + Status =3D CheckWhetherToOutputMsg ( + &MipiSystHandle, + NULL, + (MIPI_SYST_SEVERITY)SeverityType, + TraceHubCatalogType + ); + if (!EFI_ERROR (Status)) { + Status =3D MipiSystWriteCatalog ( + &MipiSystHandle, + (MIPI_SYST_SEVERITY)SeverityType, + Id + ); + if (EFI_ERROR (Status)) { + break; + } + } + } + + return Status; +} + +/** + Write catalog message to specified Trace Hub MMIO address. + + @param[in] SeverityType An error level to decide whether to enable Tr= ace Hub data. + @param[in] Id Catalog ID. + @param[in] NumberOfParams Number of parameters in argument list. + @param[in] ... Argument list that pass to Trace Hub. + + @retval EFI_SUCCESS Data was written to Trace Hub. + @retval Other Failed to output Trace Hub message. +**/ +EFI_STATUS +EFIAPI +TraceHubWriteCataLog64 ( + IN TRACE_HUB_SEVERITY_TYPE SeverityType, + IN UINT64 Id, + IN UINTN NumberOfParams, + ... + ) +{ + MIPI_SYST_HANDLE MipiSystHandle; + MIPI_SYST_HEADER MipiSystHeader; + VA_LIST Args; + UINTN Index; + EFI_STATUS Status; + UINT32 DbgInstCount; + + DbgInstCount =3D 0; + + if (NumberOfParams > 6) { + // + // Message with more than 6 parameter is illegal. + // + return EFI_INVALID_PARAMETER; + } + + Status =3D MigrateTraceHubHobData (); + + MipiSystHandle.systh_header =3D &MipiSystHeader; + + Status =3D InitMipiSystHandle (&MipiSystHandle); + if (EFI_ERROR (Status)) { + return Status; + } + + MipiSystHandle.systh_param_count =3D (UINT32)NumberOfParams; + VA_START (Args, NumberOfParams); + for (Index =3D 0; Index < NumberOfParams; Index++) { + MipiSystHandle.systh_param[Index] =3D VA_ARG (Args, UINT32); + } + + VA_END (Args); + + Status =3D CountDebugInstance (&DbgInstCount); + if (EFI_ERROR (Status)) { + return Status; + } + + for (Index =3D 0; Index < DbgInstCount; Index++) { + Status =3D CheckWhetherToOutputMsg ( + &MipiSystHandle, + NULL, + (MIPI_SYST_SEVERITY)SeverityType, + TraceHubCatalogType + ); + if (!EFI_ERROR (Status)) { + Status =3D MipiSystWriteCatalog ( + &MipiSystHandle, + (MIPI_SYST_SEVERITY)SeverityType, + Id + ); + if (EFI_ERROR (Status)) { + break; + } + } + } + + return Status; +} + +/** + Get Trace Hub MMIO Address. + + @param[in] DgbContext Always NULL. + @param[in, out] TraceAddress Trace Hub MMIO Address. + + @retval EFI_SUCCESS Get MMIO address successfully. + @retval EFI_INVALID_PARAMETER TraceAddress is a NULL pointer. +**/ +STATIC +EFI_STATUS +GetTraceHubMmioAddress ( + IN UINT8 *DgbContext, + IN OUT UINTN *TraceAddress + ) +{ + if (TraceAddress =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + *TraceAddress =3D FixedPcdGet64 (PcdTraceHubDebugAddress); + + return EFI_SUCCESS; +} + +/** + Get visibility of Trace Hub Msg. + + @param[in] DgbContext Always NULL. + @param[in, out] Flag Flag to enable or disable Trace Hub mess= age. + @param[in, out] DbgLevel Debug Level of Trace Hub. + + @retval EFI_SUCCESS Get visibility of Trace Hub Msg successf= ully. + @retval EFI_INVALID_PARAMETER On entry, Flag or DbgLevel is a NULL poi= nter. +**/ +STATIC +EFI_STATUS +GetTraceHubMsgVisibility ( + IN UINT8 *DgbContext, + IN OUT BOOLEAN *Flag, + IN OUT UINT8 *DbgLevel + ) +{ + if ((DbgLevel =3D=3D NULL) || (Flag =3D=3D NULL)) { + return EFI_INVALID_PARAMETER; + } + + *DbgLevel =3D FixedPcdGet8 (PcdTraceHubDebugLevel); + *Flag =3D FixedPcdGetBool (PcdEnableTraceHubDebugMsg); + + return EFI_SUCCESS; +} + +/** + Collect the number of available Trace Hub debug instance. + + @param[in, out] DbgInstCount The number of available Trace Hub debug = instance. + + @retval EFI_SUCCESS Collect the number of available Trace Hub debug= instance successfully. + @retval Other Failed to collect the number of available Trace= Hub debug instance. +**/ +STATIC +EFI_STATUS +CountDebugInstance ( + IN OUT UINT32 *DbgInstCount + ) +{ + if (DbgInstCount =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + // + // 1 for fixed PCD. + // + *DbgInstCount =3D 1; + + return EFI_SUCCESS; +} + +/** + Allocate boot time pool memory to store Trace Hub HOB data. + + @retval EFI_SUCCESS Migration process is successful. + @retval Other Migration process is unsuccessful +**/ +STATIC +EFI_STATUS +MigrateTraceHubHobData ( + VOID + ) +{ + return EFI_UNSUPPORTED; +} + +/** + Check whether to output Tracr Hub message. + + @param[in, out] MipiSystHandle A pointer to MIPI_SYST_HANDLE structur= e. + @param[in, out] DgbContext Always NULL. + @param[in] SeverityType An error level to decide whether to en= able Trace Hub data. + @param[in] PrintType Either catalog print or debug print. + + @retval EFI_SUCCESS Current Trace Hub message need to be processed. + @retval Other Current Trace Hub message no need to be process= ed. +**/ +STATIC +EFI_STATUS +CheckWhetherToOutputMsg ( + IN OUT MIPI_SYST_HANDLE *MipiSystHandle, + IN OUT UINT8 *DgbContext, + IN TRACE_HUB_SEVERITY_TYPE SeverityType, + IN TRACEHUB_PRINTTYPE PrintType + ) +{ + EFI_STATUS Status; + UINTN Addr; + UINT8 DbgLevel; + BOOLEAN Flag; + + if (MipiSystHandle =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + if (PrintType =3D=3D TraceHubDebugType) { + Status =3D GetTraceHubMsgVisibility (NULL, &Flag, &DbgLevel); + if (EFI_ERROR (Status)) { + return Status; + } + + if (!EnableTraceHubData (Flag, DbgLevel, SeverityType)) { + return EFI_ABORTED; + } + } + + Status =3D GetTraceHubMmioAddress (NULL, &Addr); + if (EFI_ERROR (Status)) { + return Status; + } + + MipiSystHandle->systh_platform.TraceHubPlatformData.MmioAddr =3D Addr; + if (MipiSystHandle->systh_platform.TraceHubPlatformData.MmioAddr =3D=3D = 0) { + return EFI_ABORTED; + } + + return EFI_SUCCESS; +} diff --git a/MdeModulePkg/Library/TraceHubDebugLibSysT/DxeSmmTraceHubDebugL= ibSyst.inf b/MdeModulePkg/Library/TraceHubDebugLibSysT/DxeSmmTraceHubDebugL= ibSyst.inf new file mode 100644 index 0000000000..d5bc316083 --- /dev/null +++ b/MdeModulePkg/Library/TraceHubDebugLibSysT/DxeSmmTraceHubDebugLibSyst.= inf @@ -0,0 +1,49 @@ +## @file +# Debug library to output Trace Hub message. +# Support DXE/SMM phase TraceHub debug message based on dynamic settings. +# +# Copyright (c) 2023, Intel Corporation. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 0x00010005 + BASE_NAME =3D DxeSmmTraceHubDebugLibSyst + FILE_GUID =3D A9B7B825-7902-4616-8556-085DA4DFEC72 + MODULE_TYPE =3D DXE_DRIVER + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D TraceHubDebugLib|DXE_RUNTIME_DRIVER S= MM_CORE DXE_SMM_DRIVER DXE_DRIVER DXE_CORE UEFI_DRIVER UEFI_APPLICATION + +# +# The following information is for reference only and not required by the = build tools. +# +# VALID_ARCHITECTURES =3D IA32 X64 +# + +[LibraryClasses] + BaseLib + PcdLib + HobLib + BaseMemoryLib + MemoryAllocationLib + MipiSysTLib + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + +[Sources] + DxeSmmTraceHubDebugSystLib.c + TraceHubApiCommon.c + TraceHubApiCommon.h + TraceHubApiInternal.h + +[Guids] + gUniversalPayloadTraceHubDebugInfoGuid + +[Pcd] + gEfiMdeModulePkgTokenSpaceGuid.PcdTraceHubDebugLevel + gEfiMdeModulePkgTokenSpaceGuid.PcdEnableTraceHubDebugMsg + gEfiMdeModulePkgTokenSpaceGuid.PcdTraceHubDebugAddress diff --git a/MdeModulePkg/Library/TraceHubDebugLibSysT/DxeSmmTraceHubDebugS= ystLib.c b/MdeModulePkg/Library/TraceHubDebugLibSysT/DxeSmmTraceHubDebugSys= tLib.c new file mode 100644 index 0000000000..d81abd2c97 --- /dev/null +++ b/MdeModulePkg/Library/TraceHubDebugLibSysT/DxeSmmTraceHubDebugSystLib.= c @@ -0,0 +1,462 @@ +/** @file + +Copyright (c) 2023, Intel Corporation. All rights reserved.
+ +SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "TraceHubApiCommon.h" +#include "TraceHubApiInternal.h" + +GLOBAL_REMOVE_IF_UNREFERENCED UNIVERSAL_PAYLOAD_TRACEHUB_DEBUG_INFO *mThD= ebugInstArray =3D NULL; +GLOBAL_REMOVE_IF_UNREFERENCED UINT32 mDbgI= nstCount =3D 0; + +/** + Write debug string to specified Trace Hub MMIO address. + + @param[in] SeverityType An error level to decide whether to enable = Trace Hub data. + @param[in] Buffer A pointer to the data buffer. + @param[in] NumberOfBytes Number of bytes to be written. + + @retval EFI_SUCCESS Data was written to Trace Hub. + @retval Other Failed to output Trace Hub message. +**/ +EFI_STATUS +EFIAPI +TraceHubDebugWrite ( + IN TRACE_HUB_SEVERITY_TYPE SeverityType, + IN UINT8 *Buffer, + IN UINTN NumberOfBytes + ) +{ + MIPI_SYST_HANDLE MipiSystHandle; + MIPI_SYST_HEADER MipiSystHeader; + EFI_STATUS Status; + UINT16 Index; + UINT32 DbgInstCount; + + DbgInstCount =3D 0; + + if ((NumberOfBytes =3D=3D 0) || (Buffer =3D=3D NULL)) { + // + // No data need to be written to Trace Hub + // + return EFI_ABORTED; + } + + Status =3D MigrateTraceHubHobData (); + if (EFI_ERROR (Status)) { + return Status; + } + + MipiSystHandle.systh_header =3D &MipiSystHeader; + + Status =3D InitMipiSystHandle (&MipiSystHandle); + if (EFI_ERROR (Status)) { + return Status; + } + + Status =3D CountDebugInstance (&DbgInstCount); + if (EFI_ERROR (Status)) { + return Status; + } + + for (Index =3D 0; Index < DbgInstCount; Index++) { + Status =3D CheckWhetherToOutputMsg ( + &MipiSystHandle, + (UINT8 *)&mThDebugInstArray[Index], + (MIPI_SYST_SEVERITY)SeverityType, + TraceHubDebugType + ); + if (!EFI_ERROR (Status)) { + Status =3D MipiSystWriteDebug ( + &MipiSystHandle, + (MIPI_SYST_SEVERITY)SeverityType, + (UINT16)NumberOfBytes, + (CHAR8 *)Buffer + ); + if (EFI_ERROR (Status)) { + break; + } + } + } + + return Status; +} + +/** + Write catalog status code message to specified Trace Hub MMIO address. + + @param[in] SeverityType An error level to decide whether to enable = Trace Hub data. + @param[in] Id Catalog ID. + @param[in] Guid Driver Guid. + + @retval EFI_SUCCESS Data was written to Trace Hub. + @retval Other Failed to output Trace Hub message. +**/ +EFI_STATUS +EFIAPI +TraceHubWriteCataLog64StatusCode ( + IN TRACE_HUB_SEVERITY_TYPE SeverityType, + IN UINT64 Id, + IN EFI_GUID *Guid + ) +{ + MIPI_SYST_HANDLE MipiSystHandle; + MIPI_SYST_HEADER MipiSystHeader; + UINTN Index; + EFI_STATUS Status; + UINT32 DbgInstCount; + + DbgInstCount =3D 0; + + Status =3D MigrateTraceHubHobData (); + if (EFI_ERROR (Status)) { + return Status; + } + + MipiSystHandle.systh_header =3D &MipiSystHeader; + + Status =3D InitMipiSystHandle (&MipiSystHandle); + if (EFI_ERROR (Status)) { + return Status; + } + + if (Guid !=3D NULL) { + // + // Convert little endian to big endian. + // + Status =3D LittleEndianToBigEndian (Guid); + CopyMem (&MipiSystHandle.systh_guid, Guid, sizeof (EFI_GUID)); + MipiSystHandle.systh_tag.et_guid =3D 1; + } else { + MipiSystHandle.systh_tag.et_modunit =3D 2; + MipiSystHandle.systh_tag.et_guid =3D 0; + } + + Status =3D CountDebugInstance (&DbgInstCount); + if (EFI_ERROR (Status)) { + return Status; + } + + for (Index =3D 0; Index < DbgInstCount; Index++) { + Status =3D CheckWhetherToOutputMsg ( + &MipiSystHandle, + (UINT8 *)&mThDebugInstArray[Index], + (MIPI_SYST_SEVERITY)SeverityType, + TraceHubCatalogType + ); + if (!EFI_ERROR (Status)) { + Status =3D MipiSystWriteCatalog ( + &MipiSystHandle, + (MIPI_SYST_SEVERITY)SeverityType, + Id + ); + if (EFI_ERROR (Status)) { + break; + } + } + } + + return Status; +} + +/** + Write catalog message to specified Trace Hub MMIO address. + + @param[in] SeverityType An error level to decide whether to enable Tr= ace Hub data. + @param[in] Id Catalog ID. + @param[in] NumberOfParams Number of parameters in argument list. + @param[in] ... Argument list that pass to Trace Hub. + + @retval EFI_SUCCESS Data was written to Trace Hub. + @retval Other Failed to output Trace Hub message. +**/ +EFI_STATUS +EFIAPI +TraceHubWriteCataLog64 ( + IN TRACE_HUB_SEVERITY_TYPE SeverityType, + IN UINT64 Id, + IN UINTN NumberOfParams, + ... + ) +{ + MIPI_SYST_HANDLE MipiSystHandle; + MIPI_SYST_HEADER MipiSystHeader; + VA_LIST Args; + UINTN Index; + EFI_STATUS Status; + UINT32 DbgInstCount; + + DbgInstCount =3D 0; + + if (NumberOfParams > 6) { + // + // Message with more than 6 parameter is illegal. + // + return EFI_INVALID_PARAMETER; + } + + Status =3D MigrateTraceHubHobData (); + if (EFI_ERROR (Status)) { + return Status; + } + + MipiSystHandle.systh_header =3D &MipiSystHeader; + + Status =3D InitMipiSystHandle (&MipiSystHandle); + if (EFI_ERROR (Status)) { + return Status; + } + + MipiSystHandle.systh_param_count =3D (UINT32)NumberOfParams; + VA_START (Args, NumberOfParams); + for (Index =3D 0; Index < NumberOfParams; Index++) { + MipiSystHandle.systh_param[Index] =3D VA_ARG (Args, UINT32); + } + + VA_END (Args); + + Status =3D CountDebugInstance (&DbgInstCount); + if (EFI_ERROR (Status)) { + return Status; + } + + for (Index =3D 0; Index < DbgInstCount; Index++) { + Status =3D CheckWhetherToOutputMsg ( + &MipiSystHandle, + (UINT8 *)&mThDebugInstArray[Index], + (MIPI_SYST_SEVERITY)SeverityType, + TraceHubCatalogType + ); + if (!EFI_ERROR (Status)) { + Status =3D MipiSystWriteCatalog ( + &MipiSystHandle, + (MIPI_SYST_SEVERITY)SeverityType, + Id + ); + if (EFI_ERROR (Status)) { + break; + } + } + } + + return Status; +} + +/** + Collect the number of available Trace Hub debug instance. + + @param[in, out] DbgInstCount The number of available Trace Hub debug = instance. + + @retval EFI_SUCCESS Collect the number of available Trace Hub debug= instance successfully. + @retval Other Failed to collect the number of available Trace= Hub debug instance. +**/ +STATIC +EFI_STATUS +CountDebugInstance ( + IN OUT UINT32 *DbgInstCount + ) +{ + UINT8 *DgbContext; + + if (DbgInstCount =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + if (mThDebugInstArray =3D=3D NULL) { + DgbContext =3D (UINT8 *)GetFirstGuidHob (&gUniversalPayloadTraceHubDeb= ugInfoGuid); + if (DgbContext !=3D NULL) { + while (DgbContext !=3D NULL) { + (*DbgInstCount)++; + DgbContext =3D (UINT8 *)GetNextGuidHob (&gUniversalPayloadTraceHub= DebugInfoGuid, GET_NEXT_HOB (DgbContext)); + } + } else { + // + // Trace Hub debug instance for PCD + // + (*DbgInstCount)++; + } + } else { + *DbgInstCount =3D mDbgInstCount; + } + + return EFI_SUCCESS; +} + +/** + Check whether to output Tracr Hub message. + + @param[in, out] MipiSystHandle A pointer to MIPI_SYST_HANDLE structur= e. + @param[in, out] DgbContext A pointer to Trace Hub debug instance. + @param[in] SeverityType An error level to decide whether to en= able Trace Hub data. + @param[in] PrintType Either catalog print or debug print. + + @retval EFI_SUCCESS Current Trace Hub message need to be processed. + @retval Other Current Trace Hub message no need to be process= ed. +**/ +STATIC +EFI_STATUS +CheckWhetherToOutputMsg ( + IN OUT MIPI_SYST_HANDLE *MipiSystHandle, + IN OUT UINT8 *DgbContext, + IN TRACE_HUB_SEVERITY_TYPE SeverityType, + IN TRACEHUB_PRINTTYPE PrintType + ) +{ + UINT8 DbgLevel; + BOOLEAN Flag; + UINTN Addr; + EFI_STATUS Status; + + if ((MipiSystHandle =3D=3D NULL) || (DgbContext =3D=3D NULL)) { + return EFI_INVALID_PARAMETER; + } + + if (PrintType =3D=3D TraceHubDebugType) { + Status =3D GetTraceHubMsgVisibility (DgbContext, &Flag, &DbgLevel); + if (EFI_ERROR (Status)) { + return Status; + } + + if (!EnableTraceHubData (Flag, DbgLevel, SeverityType)) { + return EFI_ABORTED; + } + } + + Status =3D GetTraceHubMmioAddress (DgbContext, &Addr); + if (EFI_ERROR (Status)) { + return Status; + } + + MipiSystHandle->systh_platform.TraceHubPlatformData.MmioAddr =3D Addr; + if (MipiSystHandle->systh_platform.TraceHubPlatformData.MmioAddr =3D=3D = 0) { + return EFI_ABORTED; + } + + return EFI_SUCCESS; +} + +/** + Get Trace Hub MMIO Address. + + @param[in] DgbContext A pointer to Trace Hub debug instance. + @param[in, out] TraceAddress Trace Hub MMIO Address. + + @retval EFI_SUCCESS Get MMIO address successfully. + @retval EFI_INVALID_PARAMETER TraceAddress or DgbContext is a NULL p= ointer. +**/ +STATIC +EFI_STATUS +GetTraceHubMmioAddress ( + IN UINT8 *DgbContext, + IN OUT UINTN *TraceAddress + ) +{ + UNIVERSAL_PAYLOAD_TRACEHUB_DEBUG_INFO *ThDbgContext; + + if ((DgbContext =3D=3D NULL) || (TraceAddress =3D=3D NULL)) { + return EFI_INVALID_PARAMETER; + } + + ThDbgContext =3D (UNIVERSAL_PAYLOAD_TRACEHUB_DEBUG_INFO *)DgbContext; + *TraceAddress =3D ThDbgContext->DebugContext.TraceAddress; + + return EFI_SUCCESS; +} + +/** + Get visibility of Trace Hub Msg. + + @param[in] DgbContext A pointer to Trace Hub debug instance. + @param[in, out] Flag Flag to enable or disable Trace Hub mess= age. + @param[in, out] DbgLevel Debug Level of Trace Hub. + + @retval EFI_SUCCESS Get visibility of Trace Hub Msg successf= ully. + @retval EFI_INVALID_PARAMETER On entry, DgbContext or Flag or DbgLevel= is a NULL pointer. +**/ +STATIC +EFI_STATUS +GetTraceHubMsgVisibility ( + IN UINT8 *DgbContext, + IN OUT BOOLEAN *Flag, + IN OUT UINT8 *DbgLevel + ) +{ + UNIVERSAL_PAYLOAD_TRACEHUB_DEBUG_INFO *ThDbgContext; + + if ((DgbContext =3D=3D NULL) || (Flag =3D=3D NULL) || (DbgLevel =3D=3D N= ULL)) { + return EFI_INVALID_PARAMETER; + } + + ThDbgContext =3D (UNIVERSAL_PAYLOAD_TRACEHUB_DEBUG_INFO *)DgbContext; + *Flag =3D ThDbgContext->DebugContext.Flag; + *DbgLevel =3D ThDbgContext->DebugContext.DebugLevel; + + return EFI_SUCCESS; +} + +/** + Allocate boot time pool memory to store Trace Hub HOB data. + + @retval EFI_SUCCESS Migration process is successful. + @retval Other Migration process is unsuccessful +**/ +STATIC +EFI_STATUS +MigrateTraceHubHobData ( + VOID + ) +{ + UINT8 *DgbContext; + UINT16 Index; + UINT32 DbgInstCount; + EFI_STATUS Status; + + Index =3D 0; + DgbContext =3D NULL; + DbgInstCount =3D 0; + + if (mThDebugInstArray =3D=3D NULL) { + Status =3D CountDebugInstance (&DbgInstCount); + if (EFI_ERROR (Status)) { + return Status; + } + + mDbgInstCount =3D DbgInstCount; + if (mDbgInstCount !=3D 0) { + mThDebugInstArray =3D AllocateZeroPool (sizeof (UNIVERSAL_PAYLOAD_TR= ACEHUB_DEBUG_INFO) * mDbgInstCount); + if (mThDebugInstArray =3D=3D NULL) { + return EFI_OUT_OF_RESOURCES; + } + + DgbContext =3D GetFirstGuidHob (&gUniversalPayloadTraceHubDebugInfoG= uid); + if (DgbContext !=3D NULL) { + for (Index =3D 0; Index < mDbgInstCount; Index++) { + CopyMem (&mThDebugInstArray[Index], GET_GUID_HOB_DATA (DgbContex= t), sizeof (UNIVERSAL_PAYLOAD_TRACEHUB_DEBUG_INFO)); + DgbContext =3D GetNextGuidHob (&gUniversalPayloadTraceHubDebugIn= foGuid, GET_NEXT_HOB (DgbContext)); + } + } else { + for (Index =3D 0; Index < mDbgInstCount; Index++) { + mThDebugInstArray[Index].DebugContext.TraceAddress =3D FixedPcdG= et64 (PcdTraceHubDebugAddress); + mThDebugInstArray[Index].DebugContext.Flag =3D FixedPcdG= etBool (PcdEnableTraceHubDebugMsg); + mThDebugInstArray[Index].DebugContext.DebugLevel =3D FixedPcdG= et8 (PcdTraceHubDebugLevel); + } + } + } else { + return EFI_ABORTED; + } + } + + return EFI_SUCCESS; +} diff --git a/MdeModulePkg/Library/TraceHubDebugLibSysT/PeiTraceHubDebugLibS= yst.inf b/MdeModulePkg/Library/TraceHubDebugLibSysT/PeiTraceHubDebugLibSyst= .inf new file mode 100644 index 0000000000..4f4bfb695b --- /dev/null +++ b/MdeModulePkg/Library/TraceHubDebugLibSysT/PeiTraceHubDebugLibSyst.inf @@ -0,0 +1,49 @@ +## @file +# Debug library to output Trace Hub message. +# Support PEI phase TraceHub debug message based on dynamic settings +# +# Copyright (c) 2023, Intel Corporation. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 0x00010005 + BASE_NAME =3D PeiTraceHubDebugLibSyst + FILE_GUID =3D C61E8C2E-0935-4E3D-BCBB-5ED84AFD9FD1 + MODULE_TYPE =3D PEIM + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D TraceHubDebugLib|PEI_CORE PEIM + +# +# The following information is for reference only and not required by the = build tools. +# +# VALID_ARCHITECTURES =3D IA32 X64 +# + +[LibraryClasses] + BaseLib + PcdLib + HobLib + BaseMemoryLib + MemoryAllocationLib + MipiSysTLib + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + +[Sources] + PeiTraceHubDebugSystLib.c + TraceHubApiCommon.c + TraceHubApiCommon.h + TraceHubApiInternal.h + +[Guids] + gUniversalPayloadTraceHubDebugInfoGuid + +[Pcd] + gEfiMdeModulePkgTokenSpaceGuid.PcdTraceHubDebugLevel + gEfiMdeModulePkgTokenSpaceGuid.PcdEnableTraceHubDebugMsg + gEfiMdeModulePkgTokenSpaceGuid.PcdTraceHubDebugAddress diff --git a/MdeModulePkg/Library/TraceHubDebugLibSysT/PeiTraceHubDebugSyst= Lib.c b/MdeModulePkg/Library/TraceHubDebugLibSysT/PeiTraceHubDebugSystLib.c new file mode 100644 index 0000000000..10bde71fd3 --- /dev/null +++ b/MdeModulePkg/Library/TraceHubDebugLibSysT/PeiTraceHubDebugSystLib.c @@ -0,0 +1,446 @@ +/** @file + +Copyright (c) 2023, Intel Corporation. All rights reserved.
+ +SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "TraceHubApiCommon.h" +#include "TraceHubApiInternal.h" + +/** + Write debug string to specified Trace Hub MMIO address. + + @param[in] SeverityType An error level to decide whether to enable = Trace Hub data. + @param[in] Buffer A pointer to the data buffer. + @param[in] NumberOfBytes Number of bytes to be written. + + @retval EFI_SUCCESS Data was written to Trace Hub. + @retval Other Failed to output Trace Hub message. +**/ +EFI_STATUS +EFIAPI +TraceHubDebugWrite ( + IN TRACE_HUB_SEVERITY_TYPE SeverityType, + IN UINT8 *Buffer, + IN UINTN NumberOfBytes + ) +{ + MIPI_SYST_HANDLE MipiSystHandle; + MIPI_SYST_HEADER MipiSystHeader; + EFI_STATUS Status; + UINT8 *DgbContext; + UINTN Index; + UINT32 DbgInstCount; + + DbgInstCount =3D 0; + + if ((NumberOfBytes =3D=3D 0) || (Buffer =3D=3D NULL)) { + // + // No data need to be written to Trace Hub + // + return EFI_ABORTED; + } + + Status =3D MigrateTraceHubHobData (); + + MipiSystHandle.systh_header =3D &MipiSystHeader; + + Status =3D InitMipiSystHandle (&MipiSystHandle); + if (EFI_ERROR (Status)) { + return Status; + } + + Status =3D CountDebugInstance (&DbgInstCount); + if (EFI_ERROR (Status)) { + return Status; + } + + DgbContext =3D (UINT8 *)GetFirstGuidHob (&gUniversalPayloadTraceHubDebug= InfoGuid); + for (Index =3D 0; Index < DbgInstCount; Index++) { + Status =3D CheckWhetherToOutputMsg ( + &MipiSystHandle, + DgbContext, + (MIPI_SYST_SEVERITY)SeverityType, + TraceHubDebugType + ); + if (!EFI_ERROR (Status)) { + Status =3D MipiSystWriteDebug ( + &MipiSystHandle, + (MIPI_SYST_SEVERITY)SeverityType, + (UINT16)NumberOfBytes, + (CHAR8 *)Buffer + ); + if (EFI_ERROR (Status)) { + break; + } + } + + if (DgbContext !=3D NULL) { + DgbContext =3D (UINT8 *)GetNextGuidHob (&gUniversalPayloadTraceHubDe= bugInfoGuid, GET_NEXT_HOB (DgbContext)); + if (DgbContext =3D=3D NULL) { + break; + } + } + } + + return Status; +} + +/** + Write catalog status code message to specified Trace Hub MMIO address. + + @param[in] SeverityType An error level to decide whether to enable = Trace Hub data. + @param[in] Id Catalog ID. + @param[in] Guid Driver Guid. + + @retval EFI_SUCCESS Data was written to Trace Hub. + @retval Other Failed to output Trace Hub message. +**/ +EFI_STATUS +EFIAPI +TraceHubWriteCataLog64StatusCode ( + IN TRACE_HUB_SEVERITY_TYPE SeverityType, + IN UINT64 Id, + IN EFI_GUID *Guid + ) +{ + MIPI_SYST_HANDLE MipiSystHandle; + MIPI_SYST_HEADER MipiSystHeader; + UINT32 DbgInstCount; + UINT8 *DgbContext; + EFI_STATUS Status; + UINTN Index; + + DbgInstCount =3D 0; + + Status =3D MigrateTraceHubHobData (); + + MipiSystHandle.systh_header =3D &MipiSystHeader; + + Status =3D InitMipiSystHandle (&MipiSystHandle); + if (EFI_ERROR (Status)) { + return Status; + } + + if (Guid !=3D NULL) { + // + // Convert little endian to big endian. + // + Status =3D LittleEndianToBigEndian (Guid); + CopyMem (&MipiSystHandle.systh_guid, Guid, sizeof (EFI_GUID)); + MipiSystHandle.systh_tag.et_guid =3D 1; + } else { + MipiSystHandle.systh_tag.et_modunit =3D 2; + MipiSystHandle.systh_tag.et_guid =3D 0; + } + + Status =3D CountDebugInstance (&DbgInstCount); + if (EFI_ERROR (Status)) { + return Status; + } + + DgbContext =3D (UINT8 *)GetFirstGuidHob (&gUniversalPayloadTraceHubDebug= InfoGuid); + for (Index =3D 0; Index < DbgInstCount; Index++) { + Status =3D CheckWhetherToOutputMsg ( + &MipiSystHandle, + DgbContext, + (MIPI_SYST_SEVERITY)SeverityType, + TraceHubCatalogType + ); + if (!EFI_ERROR (Status)) { + Status =3D MipiSystWriteCatalog ( + &MipiSystHandle, + (MIPI_SYST_SEVERITY)SeverityType, + Id + ); + if (EFI_ERROR (Status)) { + break; + } + } + + if (DgbContext !=3D NULL) { + DgbContext =3D (UINT8 *)GetNextGuidHob (&gUniversalPayloadTraceHubDe= bugInfoGuid, GET_NEXT_HOB (DgbContext)); + if (DgbContext =3D=3D NULL) { + break; + } + } + } + + return Status; +} + +/** + Write catalog message to specified Trace Hub MMIO address. + + @param[in] SeverityType An error level to decide whether to enable Tr= ace Hub data. + @param[in] Id Catalog ID. + @param[in] NumberOfParams Number of parameters in argument list. + @param[in] ... Argument list that pass to Trace Hub. + + @retval EFI_SUCCESS Data was written to Trace Hub. + @retval Other Failed to output Trace Hub message. +**/ +EFI_STATUS +EFIAPI +TraceHubWriteCataLog64 ( + IN TRACE_HUB_SEVERITY_TYPE SeverityType, + IN UINT64 Id, + IN UINTN NumberOfParams, + ... + ) +{ + MIPI_SYST_HANDLE MipiSystHandle; + MIPI_SYST_HEADER MipiSystHeader; + VA_LIST Args; + UINTN Index; + UINT32 DbgInstCount; + UINT8 *DgbContext; + EFI_STATUS Status; + + DbgInstCount =3D 0; + + if (NumberOfParams > 6) { + // + // Message with more than 6 parameter is illegal. + // + return EFI_INVALID_PARAMETER; + } + + Status =3D MigrateTraceHubHobData (); + + MipiSystHandle.systh_header =3D &MipiSystHeader; + + Status =3D InitMipiSystHandle (&MipiSystHandle); + if (EFI_ERROR (Status)) { + return Status; + } + + MipiSystHandle.systh_param_count =3D (UINT32)NumberOfParams; + VA_START (Args, NumberOfParams); + for (Index =3D 0; Index < NumberOfParams; Index++) { + MipiSystHandle.systh_param[Index] =3D VA_ARG (Args, UINT32); + } + + VA_END (Args); + + Status =3D CountDebugInstance (&DbgInstCount); + if (EFI_ERROR (Status)) { + return Status; + } + + DgbContext =3D (UINT8 *)GetFirstGuidHob (&gUniversalPayloadTraceHubDebug= InfoGuid); + for (Index =3D 0; Index < DbgInstCount; Index++) { + Status =3D CheckWhetherToOutputMsg ( + &MipiSystHandle, + DgbContext, + (MIPI_SYST_SEVERITY)SeverityType, + TraceHubCatalogType + ); + if (!EFI_ERROR (Status)) { + Status =3D MipiSystWriteCatalog ( + &MipiSystHandle, + (MIPI_SYST_SEVERITY)SeverityType, + Id + ); + if (EFI_ERROR (Status)) { + break; + } + } + + if (DgbContext !=3D NULL) { + DgbContext =3D (UINT8 *)GetNextGuidHob (&gUniversalPayloadTraceHubDe= bugInfoGuid, GET_NEXT_HOB (DgbContext)); + if (DgbContext =3D=3D NULL) { + break; + } + } + } + + return Status; +} + +/** + Collect the number of available Trace Hub debug instance. + + @param[in, out] DbgInstCount The number of available Trace Hub debug = instance. + + @retval EFI_SUCCESS Collect the number of available Trace Hub debug= instance successfully. + @retval Other Failed to collect the number of available Trace= Hub debug instance. +**/ +STATIC +EFI_STATUS +CountDebugInstance ( + IN OUT UINT32 *DbgInstCount + ) +{ + UINT8 *DgbContext; + + if (DbgInstCount =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + DgbContext =3D (UINT8 *)GetFirstGuidHob (&gUniversalPayloadTraceHubDebug= InfoGuid); + if (DgbContext !=3D NULL) { + while (DgbContext !=3D NULL) { + (*DbgInstCount)++; + DgbContext =3D (UINT8 *)GetNextGuidHob (&gUniversalPayloadTraceHubDe= bugInfoGuid, GET_NEXT_HOB (DgbContext)); + } + } else { + // + // Trace Hub debug instance for PCD + // + (*DbgInstCount)++; + } + + return EFI_SUCCESS; +} + +/** + Check whether to output Tracr Hub message. + + @param[in, out] MipiSystHandle A pointer to MIPI_SYST_HANDLE structur= e. + @param[in, out] DgbContext A pointer to Trace Hub debug instance.= NULL is acceptable. + @param[in] SeverityType An error level to decide whether to en= able Trace Hub data. + @param[in] PrintType Either catalog print or debug print. + + @retval EFI_SUCCESS Current Trace Hub message need to be processed. + @retval Other Current Trace Hub message no need to be process= ed. +**/ +STATIC +EFI_STATUS +CheckWhetherToOutputMsg ( + IN OUT MIPI_SYST_HANDLE *MipiSystHandle, + IN OUT UINT8 *DgbContext, + IN TRACE_HUB_SEVERITY_TYPE SeverityType, + IN TRACEHUB_PRINTTYPE PrintType + ) +{ + EFI_STATUS Status; + UINTN Addr; + UINT8 DbgLevel; + BOOLEAN Flag; + + if (MipiSystHandle =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + if (PrintType =3D=3D TraceHubDebugType) { + Status =3D GetTraceHubMsgVisibility (DgbContext, &Flag, &DbgLevel); + if (EFI_ERROR (Status)) { + return Status; + } + + if (!EnableTraceHubData (Flag, DbgLevel, SeverityType)) { + return EFI_ABORTED; + } + } + + Status =3D GetTraceHubMmioAddress (DgbContext, &Addr); + if (EFI_ERROR (Status)) { + return Status; + } + + MipiSystHandle->systh_platform.TraceHubPlatformData.MmioAddr =3D Addr; + if (MipiSystHandle->systh_platform.TraceHubPlatformData.MmioAddr =3D=3D = 0) { + return EFI_ABORTED; + } + + return EFI_SUCCESS; +} + +/** + Get Trace Hub MMIO Address. + + @param[in] DgbContext A pointer to Trace Hub debug instance.= NULL is acceptable. + @param[in, out] TraceAddress Trace Hub MMIO Address. + + @retval EFI_SUCCESS Get MMIO address successfully. + @retval EFI_INVALID_PARAMETER TraceAddress is a NULL pointer. +**/ +STATIC +EFI_STATUS +GetTraceHubMmioAddress ( + IN UINT8 *DgbContext, + IN OUT UINTN *TraceAddress + ) +{ + UNIVERSAL_PAYLOAD_TRACEHUB_DEBUG_INFO *ThDebugInfo; + + ThDebugInfo =3D NULL; + + if (TraceAddress =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + if (DgbContext !=3D NULL) { + ThDebugInfo =3D GET_GUID_HOB_DATA (DgbContext); + *TraceAddress =3D ThDebugInfo->DebugContext.TraceAddress; + } else { + *TraceAddress =3D FixedPcdGet64 (PcdTraceHubDebugAddress); + } + + return EFI_SUCCESS; +} + +/** + Get visibility of Trace Hub Msg. + + @param[in] DgbContext A pointer to Trace Hub debug instance. N= ULL is acceptable. + @param[in, out] Flag Flag to enable or disable Trace Hub mess= age. + @param[in, out] DbgLevel Debug Level of Trace Hub. + + @retval EFI_SUCCESS Get visibility of Trace Hub Msg successf= ully. + @retval EFI_INVALID_PARAMETER On entry, Flag or DbgLevel is a NULL poi= nter. +**/ +STATIC +EFI_STATUS +GetTraceHubMsgVisibility ( + IN UINT8 *DgbContext, + IN OUT BOOLEAN *Flag, + IN OUT UINT8 *DbgLevel + ) +{ + UNIVERSAL_PAYLOAD_TRACEHUB_DEBUG_INFO *ThDebugInfo; + + ThDebugInfo =3D NULL; + + if ((DbgLevel =3D=3D NULL) || (Flag =3D=3D NULL)) { + return EFI_INVALID_PARAMETER; + } + + if (DgbContext !=3D NULL) { + ThDebugInfo =3D GET_GUID_HOB_DATA (DgbContext); + *DbgLevel =3D ThDebugInfo->DebugContext.DebugLevel; + *Flag =3D ThDebugInfo->DebugContext.Flag; + } else { + *DbgLevel =3D FixedPcdGet8 (PcdTraceHubDebugLevel); + *Flag =3D FixedPcdGetBool (PcdEnableTraceHubDebugMsg); + } + + return EFI_SUCCESS; +} + +/** + Allocate boot time pool memory to store Trace Hub HOB data. + + @retval EFI_SUCCESS Migration process is successful. + @retval Other Migration process is unsuccessful +**/ +STATIC +EFI_STATUS +MigrateTraceHubHobData ( + VOID + ) +{ + return EFI_UNSUPPORTED; +} diff --git a/MdeModulePkg/Library/TraceHubDebugLibSysT/TraceHubApiCommon.c = b/MdeModulePkg/Library/TraceHubDebugLibSysT/TraceHubApiCommon.c new file mode 100644 index 0000000000..0e7a09c95e --- /dev/null +++ b/MdeModulePkg/Library/TraceHubDebugLibSysT/TraceHubApiCommon.c @@ -0,0 +1,81 @@ +/** @file + +Copyright (c) 2023, Intel Corporation. All rights reserved.
+ +SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include "TraceHubApiCommon.h" + +/** + Determine whether to enable Trace Hub message. + + @param[in] Flag Flag to enable or disable Trace Hub message. + @param[in] DbgLevel Debug Level of Trace Hub. + @param[in] SeverityType Severity type of input message. + + @retval TRUE Enable trace hub message. + @retval FALSE Disable trace hub message. +**/ +BOOLEAN +EFIAPI +EnableTraceHubData ( + IN BOOLEAN Flag, + IN UINT8 DbgLevel, + IN TRACE_HUB_SEVERITY_TYPE SeverityType + ) +{ + if (Flag =3D=3D TraceHubRoutingDisable) { + return FALSE; + } + + if (DbgLevel =3D=3D TraceHubDebugLevelError) { + if (((SeverityType =3D=3D SeverityFatal) || (SeverityType =3D=3D Sever= ityError))) { + return TRUE; + } + } else if (DbgLevel =3D=3D TraceHubDebugLevelErrorWarning) { + if (((SeverityType =3D=3D SeverityFatal) || (SeverityType =3D=3D Sever= ityError) || (SeverityType =3D=3D SeverityWarning))) { + return TRUE; + } + } else if (DbgLevel =3D=3D TraceHubDebugLevelErrorWarningInfo) { + if (((SeverityType =3D=3D SeverityFatal) || (SeverityType =3D=3D Sever= ityError) || (SeverityType =3D=3D SeverityWarning) || (SeverityType =3D=3D = SeverityNormal))) { + return TRUE; + } + } else if (DbgLevel =3D=3D TraceHubDebugLevelErrorWarningInfoVerbose) { + return TRUE; + } + + return FALSE; +} + +/** + Convert GUID from little endian to big endian. + + @param[in, out] Guid GUID in little endian format on entry. GUID in b= ig endian format on exit. + + @retval EFI_SUCCESS Convert GUID successfully. +**/ +EFI_STATUS +EFIAPI +LittleEndianToBigEndian ( + IN OUT EFI_GUID *Guid + ) +{ + EFI_GUID TempGuid; + UINT64 GuidData4; + + ZeroMem (&TempGuid, sizeof (EFI_GUID)); + TempGuid.Data1 =3D SwapBytes32 (Guid->Data1); + TempGuid.Data2 =3D SwapBytes16 (Guid->Data2); + TempGuid.Data3 =3D SwapBytes16 (Guid->Data3); + CopyMem (&GuidData4, Guid->Data4, sizeof (Guid->Data4)); + GuidData4 =3D SwapBytes64 (GuidData4); + CopyMem (TempGuid.Data4, &GuidData4, sizeof (GuidData4)); + CopyMem (Guid, &TempGuid, sizeof (EFI_GUID)); + + return EFI_SUCCESS; +} diff --git a/MdeModulePkg/Library/TraceHubDebugLibSysT/TraceHubApiCommon.h = b/MdeModulePkg/Library/TraceHubDebugLibSysT/TraceHubApiCommon.h new file mode 100644 index 0000000000..f2f3cda8b7 --- /dev/null +++ b/MdeModulePkg/Library/TraceHubDebugLibSysT/TraceHubApiCommon.h @@ -0,0 +1,64 @@ +/** @file + +Copyright (c) 2023, Intel Corporation. All rights reserved.
+ +SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef TRACE_HUB_API_COMMON_H_ +#define TRACE_HUB_API_COMMON_H_ + +#include + +typedef enum { + TraceHubDebugType =3D 0, + TraceHubCatalogType +} TRACEHUB_PRINTTYPE; + +typedef enum { + TraceHubRoutingDisable =3D 0, + TraceHubRoutingEnable, + TraceHubRoutingMax +} TRACE_HUB_ROUTING; + +typedef enum { + TraceHubDebugLevelError =3D 0, + TraceHubDebugLevelErrorWarning, + TraceHubDebugLevelErrorWarningInfo, + TraceHubDebugLevelErrorWarningInfoVerbose, + TraceHubDebugLevelMax +} TRACE_HUB_DEBUG_LEVEL; + +/** + Determine whether to enable Trace Hub message. + + @param[in] Flag Flag to enable or disable Trace Hub message. + @param[in] DbgLevel Debug Level of Trace Hub. + @param[in] SeverityType Severity type of input message. + + @retval TRUE Enable trace hub message. + @retval FALSE Disable trace hub message. +**/ +BOOLEAN +EFIAPI +EnableTraceHubData ( + IN BOOLEAN Flag, + IN UINT8 DbgLevel, + IN TRACE_HUB_SEVERITY_TYPE SeverityType + ); + +/** + Convert GUID from little endian to big endian. + + @param[in, out] Guid GUID in little endian format on entry. GUID in b= ig endian format on exit. + + @retval EFI_SUCCESS Convert GUID successfully. +**/ +EFI_STATUS +EFIAPI +LittleEndianToBigEndian ( + IN OUT EFI_GUID *Guid + ); + +#endif // TRACE_HUB_API_COMMON_H_ diff --git a/MdeModulePkg/Library/TraceHubDebugLibSysT/TraceHubApiInternal.= h b/MdeModulePkg/Library/TraceHubDebugLibSysT/TraceHubApiInternal.h new file mode 100644 index 0000000000..23a9879316 --- /dev/null +++ b/MdeModulePkg/Library/TraceHubDebugLibSysT/TraceHubApiInternal.h @@ -0,0 +1,92 @@ +/** @file + +Copyright (c) 2023, Intel Corporation. All rights reserved.
+ +SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef TRACE_HUB_API_INTERNAL_H_ +#define TRACE_HUB_API_INTERNAL_H_ + +/** + Collect the number of available Trace Hub debug instance. + + @param[in, out] DbgInstCount The number of available Trace Hub debug = instance. + + @retval EFI_SUCCESS Collect the number of available Trace Hub debug= instance successfully. + @retval Other Failed to collect the number of available Trace= Hub debug instance. +**/ +STATIC +EFI_STATUS +CountDebugInstance ( + IN OUT UINT32 *DbgInstCount + ); + +/** + Check whether to output Tracr Hub message. + + @param[in, out] MipiSystHandle A pointer to MIPI_SYST_HANDLE structur= e. + @param[in, out] DgbContext A pointer to Trace Hub debug instance. + @param[in] SeverityType An error level to decide whether to en= able Trace Hub data. + @param[in] PrintType Either catalog print or debug print. + + @retval EFI_SUCCESS Current Trace Hub message need to be processed. + @retval Other Current Trace Hub message no need to be process= ed. +**/ +STATIC +EFI_STATUS +CheckWhetherToOutputMsg ( + IN OUT MIPI_SYST_HANDLE *MipiSystHandle, + IN OUT UINT8 *DgbContext, + IN TRACE_HUB_SEVERITY_TYPE SeverityType, + IN TRACEHUB_PRINTTYPE PrintType + ); + +/** + Get visibility of Trace Hub Msg. + + @param[in] DgbContext A pointer to Trace Hub debug instance. + @param[in, out] Flag Flag to enable or disable Trace Hub mess= age. + @param[in, out] DbgLevel Debug Level of Trace Hub. + + @retval EFI_SUCCESS Get visibility of Trace Hub Msg successf= ully. + @retval EFI_INVALID_PARAMETER On entry, Flag or DbgLevel is a NULL poi= nter. +**/ +STATIC +EFI_STATUS +GetTraceHubMsgVisibility ( + IN UINT8 *DgbContext, + IN OUT BOOLEAN *Flag, + IN OUT UINT8 *DbgLevel + ); + +/** + Get Trace Hub MMIO Address. + + @param[in] DgbContext A pointer to Trace Hub debug instance. + @param[in, out] TraceAddress Trace Hub MMIO Address. + + @retval EFI_SUCCESS Get MMIO address successfully. + @retval EFI_INVALID_PARAMETER TraceAddress is a NULL pointer. +**/ +STATIC +EFI_STATUS +GetTraceHubMmioAddress ( + IN UINT8 *DgbContext, + IN OUT UINTN *TraceAddress + ); + +/** + Allocate boot time pool memory to store Trace Hub HOB data. + + @retval EFI_SUCCESS Migration process is successful. + @retval Other Migration process is unsuccessful +**/ +STATIC +EFI_STATUS +MigrateTraceHubHobData ( + VOID + ); + +#endif // TRACE_HUB_API_INTERNAL_H_ diff --git a/MdeModulePkg/MdeModulePkg.dec b/MdeModulePkg/MdeModulePkg.dec index 9605c617b7..8300c88141 100644 --- a/MdeModulePkg/MdeModulePkg.dec +++ b/MdeModulePkg/MdeModulePkg.dec @@ -438,6 +438,9 @@ ## Include/UniversalPayload/SerialPortInfo.h gUniversalPayloadSerialPortInfoGuid =3D { 0xaa7e190d, 0xbe21, 0x4409, { = 0x8e, 0x67, 0xa2, 0xcd, 0xf, 0x61, 0xe1, 0x70 } } =20 + ## Include/UniversalPayload/TraceHubDebugInfo.h + gUniversalPayloadTraceHubDebugInfoGuid =3D { 0xf88c9c23, 0x646c, 0x4f6c,= { 0x8e, 0x3d, 0x36, 0xa9, 0x43, 0xc1, 0x08, 0x35 } } + ## GUID used for Boot Discovery Policy FormSet guid and related variable= s. gBootDiscoveryPolicyMgrFormsetGuid =3D { 0x5b6f7107, 0xbb3c, 0x4660, { 0= x92, 0xcd, 0x54, 0x26, 0x90, 0x28, 0x0b, 0xbd } } =20 @@ -1093,6 +1096,24 @@ # @Prompt Enable UEFI Stack Guard. gEfiMdeModulePkgTokenSpaceGuid.PcdCpuStackGuard|FALSE|BOOLEAN|0x30001055 =20 + ## Indicate debug level of Trace Hub. + # 0x0 - TraceHubDebugLevelError.
+ # 0x1 - TraceHubDebugLevelErrorWarning.
+ # 0x2 - TraceHubDebugLevelErrorWarningInfo.
+ # 0x3 - TraceHubDebugLevelErrorWarningInfoVerbose.
+ # @Prompt Debug level of Trace Hub. + gEfiMdeModulePkgTokenSpaceGuid.PcdTraceHubDebugLevel|0|UINT8|0x30001056 + + ## Flag to enable or disable Trace Hub message. + # FALSE - Disable Trace Hub debug message.
+ # TRUE - Enable Trace Hub debug message.
+ # @Prompt Enable or Disable Trace Hub message. + gEfiMdeModulePkgTokenSpaceGuid.PcdEnableTraceHubDebugMsg|0|BOOLEAN|0x300= 01057 + + ## Indicate MMIO address where Trace Hub message output to. + # @Prompt Output MMIO address of Trace Hub message. + gEfiMdeModulePkgTokenSpaceGuid.PcdTraceHubDebugAddress|0|UINT64|0x300010= 58 + [PcdsFixedAtBuild, PcdsPatchableInModule] ## Dynamic type PCD can be registered callback function for Pcd setting = action. # PcdMaxPeiPcdCallBackNumberPerPcdEntry indicates the maximum number of= callback function diff --git a/MdeModulePkg/MdeModulePkg.dsc b/MdeModulePkg/MdeModulePkg.dsc index 1014598f31..a11f26572a 100644 --- a/MdeModulePkg/MdeModulePkg.dsc +++ b/MdeModulePkg/MdeModulePkg.dsc @@ -106,6 +106,9 @@ MmUnblockMemoryLib|MdePkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLibN= ull.inf VariableFlashInfoLib|MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseV= ariableFlashInfoLib.inf IpmiCommandLib|MdeModulePkg/Library/BaseIpmiCommandLibNull/BaseIpmiComma= ndLibNull.inf + TraceHubDebugLib|MdeModulePkg/Library/TraceHubDebugLibSysT/BaseTraceHubD= ebugLibSyst.inf + TraceHubDebugLib|MdeModulePkg/Library/TraceHubDebugLibSysT/PeiTraceHubDe= bugLibSyst.inf + TraceHubDebugLib|MdeModulePkg/Library/TraceHubDebugLibSysT/DxeSmmTraceHu= bDebugLibSyst.inf =20 [LibraryClasses.EBC.PEIM] IoLib|MdePkg/Library/PeiIoLibCpuIo/PeiIoLibCpuIo.inf @@ -446,6 +449,9 @@ MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleLib.inf MdeModulePkg/Library/DxeCapsuleLibFmp/DxeRuntimeCapsuleLib.inf MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib.i= nf + MdeModulePkg/Library/TraceHubDebugLibSysT/BaseTraceHubDebugLibSyst.inf + MdeModulePkg/Library/TraceHubDebugLibSysT/PeiTraceHubDebugLibSyst.inf + MdeModulePkg/Library/TraceHubDebugLibSysT/DxeSmmTraceHubDebugLibSyst.inf =20 [Components.IA32, Components.X64, Components.AARCH64] MdeModulePkg/Universal/EbcDxe/EbcDxe.inf diff --git a/MdeModulePkg/MdeModulePkg.uni b/MdeModulePkg/MdeModulePkg.uni index 33ce9f6198..b64f26d255 100644 --- a/MdeModulePkg/MdeModulePkg.uni +++ b/MdeModulePkg/MdeModulePkg.uni @@ -1290,6 +1290,24 @@ = " TRUE - UEFI Stack Guard will be enabled.
\n" = " FALSE - UEFI Stack Guard will be disabled.
" =20 +#string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdTraceHubDebugLevel_PROMPT #= language en-US "Debug level of Trace Hub." + +#string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdTraceHubDebugLevel_HELP #= language en-US "Indicate debug level of Trace Hub" + = " 0x0 - TraceHubDebugLevelError.
" + = " 0x1 - TraceHubDebugLevelErrorWarning.
" + = " 0x2 - TraceHubDebugLevelErrorWarningInfo.
" + = " 0x3 - TraceHubDebugLevelErrorWarningInfoVerbose.
" + +#string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdEnableTraceHubDebugMsg_PROMP= T #language en-US "Flag to enable or disable Trace Hub message" + +#string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdEnableTraceHubDebugMsg_HELP = #language en-US "Enable or Disable Trace Hub message" + = " FALSE - Disable Trace Hub debug message.
" + = " TRUE - Enable Trace Hub debug message.
" + +#string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdTraceHubDebugAddress_PROMPT = #language en-US "Output MMIO address of Trace Hub message" + +#string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdTraceHubDebugAddress_HELP = #language en-US "Indicate MMIO address where Trace Hub message output to." + #string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdSetNvStoreDefaultId_PROMPT = #language en-US "NV Storage DefaultId" =20 #string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdSetNvStoreDefaultId_HELP = #language en-US "This dynamic PCD enables the default variable setting.\n" --=20 2.28.0.windows.1