From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by mx.groups.io with SMTP id smtpd.web12.9348.1642754137079900260 for ; Fri, 21 Jan 2022 00:35:37 -0800 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=V1OZoPD5; spf=pass (domain: intel.com, ip: 134.134.136.24, mailfrom: jenny.huang@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1642754137; x=1674290137; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=xLhLRbNDaDu+ZnOz7sneFA8fmvZlJmefzYuSWekvIxQ=; b=V1OZoPD5oNw4qvjrpND0A6Lt/TAPCA+7H3XxWmILkQB98Gryml98qefz 8IkVmQ1VEI3QjPeCnw9wlBkTK5jqTJoL+T1phhSNW37r+WqN95xoh3u5g RCZVdAKJhOdNF7QplC1ct9HdroC1QKsKs6JfuPIK7PAzt8jAcND9JFiWX l4ty9Ee6ZjFaXn/zGq2ueHSg+8I2XAsr3S5XM3X/bWIsZLV8AkNpIonnY 4IziRkfo4q7GQWMBsfATclX+0Yg72CkGr83HcbSm85dKHh6xdPAw6uOg0 uSGXxXT3Wg1JOmcWeJ7KpzSJ89COGOQf+41+bJpqehanjk/bsTN8qNODx A==; X-IronPort-AV: E=McAfee;i="6200,9189,10233"; a="245386999" X-IronPort-AV: E=Sophos;i="5.88,304,1635231600"; d="scan'208";a="245386999" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Jan 2022 00:35:36 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,304,1635231600"; d="scan'208";a="694565329" Received: from fmsmsx604.amr.corp.intel.com ([10.18.126.84]) by orsmga005.jf.intel.com with ESMTP; 21 Jan 2022 00:35:36 -0800 Received: from fmsmsx610.amr.corp.intel.com (10.18.126.90) by fmsmsx604.amr.corp.intel.com (10.18.126.84) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Fri, 21 Jan 2022 00:35:35 -0800 Received: from fmsedg601.ED.cps.intel.com (10.1.192.135) by fmsmsx610.amr.corp.intel.com (10.18.126.90) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20 via Frontend Transport; Fri, 21 Jan 2022 00:35:35 -0800 Received: from NAM04-MW2-obe.outbound.protection.outlook.com (104.47.73.175) by edgegateway.intel.com (192.55.55.70) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2308.20; Fri, 21 Jan 2022 00:35:35 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=I6z/r0AQj0KQVP6CFyRvoMyB/sjSBYuqaDoW0R5PoCX8L7ZchUPMKfnmDjJCZFMwAP0kJYyLpvu6Zn7y7nNV0NcECdwynsQ0O8ccL2WTsKhysLk63bu+fanUWSCL4n3Uf0uhKnTk/xVb6N6C4tUWOllKHj5kd4jmu65C5YY/RrLJFd/Yrl0r9ke4cp4eSRTawSKVdKYdQUxWsFLBMyvCGc8lFdJKw4LicsxOYLj9R55m+fRrouCWDODXXDWXC0oAKpq+Dh6D2PVYE9EqaFOHufuBMzWywKs97+mc9z1h5Y/pEvsXKsHgxScRsqZJysa1fnbhQSI8d0EehEp0z/Mv6w== 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=rCeaTdPYmY54AFsDkJEaM+lJoX3iWeQYmJKTZSFkK4k=; b=E8bfQSEb4fLuc2yg0fI2SGP3R++2iJCnHzLvVNXcXVS3aIBWT22TjZ1M4WLWN+9BQV3HebfeU/1zkF0MRRS8uH+YdnF6YTlIOnnNWmddGNpPTp+PrBV8QD2ZGeHnO4GkJ7oYkIoeknxMdVIy/rEySo+PKbfapzpijqQcQ+B81SKSC+jWy6vTziq0pRjSo1w4fTkLt8KvNBXv+2GKFssGmsN7kwZ/xwxqiT5mv1Hylix9QGjP5kd6TDiVK7bVl5684M5pUH1mBtLBz1RzISbLHBuD1h8DkC5FD2/OrIg9aEpSggQR7xbzzJA0S6KCeVnau4YTnacHQYE9pEaIgKGhmw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none Received: from DM6PR11MB4627.namprd11.prod.outlook.com (2603:10b6:5:2a2::19) by DM6PR11MB3004.namprd11.prod.outlook.com (2603:10b6:5:67::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4888.11; Fri, 21 Jan 2022 08:35:31 +0000 Received: from DM6PR11MB4627.namprd11.prod.outlook.com ([fe80::d48a:c41e:cdea:8e58]) by DM6PR11MB4627.namprd11.prod.outlook.com ([fe80::d48a:c41e:cdea:8e58%5]) with mapi id 15.20.4909.010; Fri, 21 Jan 2022 08:35:31 +0000 From: "Huang, Jenny" To: "Sheng, W" , "devel@edk2.groups.io" CC: "Ni, Ray" , "Chaganty, Rangasai V" , "Kowalewski, Robert" Subject: Re: [PATCH v5 4/4] IntelSiliconPkg/VTd: Only generate PEI DMA buffer once. Thread-Topic: [PATCH v5 4/4] IntelSiliconPkg/VTd: Only generate PEI DMA buffer once. Thread-Index: AQHYDEN/Wil9ASnJwUKO2Np2mej+SqxtKw4Q Date: Fri, 21 Jan 2022 08:35:31 +0000 Message-ID: References: <20220118081433.15620-1-w.sheng@intel.com> <20220118081433.15620-5-w.sheng@intel.com> In-Reply-To: <20220118081433.15620-5-w.sheng@intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-version: 11.6.200.16 dlp-reaction: no-action dlp-product: dlpe-windows authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 512dbb26-35cf-42be-83af-08d9dcb8fc6a x-ms-traffictypediagnostic: DM6PR11MB3004:EE_ x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:3173; x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: Sgu0RK+taMyfAP+WEgykHRTbbhb5nmPGsyEvHBNVut/h/r0ZXpnzDN/wxgZqhvaHx41HNaaRNmu9c07i9As19Cj7XcykG+Q3NTaJ+58LyyJGQjAVrP3W7DT9ZM5PZwIdQHs8gYo/3Kjb/4qEWmrETJ3fTqNTmb3gkl6d7tmQ3Pl4cwbEHHFAjtolIMjJovstuiRBkeX2p/0G6alRU+hAJFZWoghXT5+R60bMBzeFODJ/ajZyjhYNswicmQ74mUqmMBywO29obyKSgot35XjnvDwPW9lUbZZweZnQasxk6gdZHJFX/xyuTmwdhRWeRG8CuOPM4an53TiUfZ2bdNBsvF6FbV6ZJmizsFecdw8WJNggb6K0hub1c85Y5EXw1Lfk1nkqmmnIgkipUmfnimwd0esg6NefjBct8YI0InCr3Z9RpxU42f7RieUWhSbyXDJihqkqpFvoOV7mj4FdgsLLjF9TriOQMN4d6bJ/fjB41pDO/Qs63xLVJeURzjglXYPbC6wmUNlXB3Fz2x66tx+Wtad9nSUBqAmMng7BzyMSvDtVXeeA9oWENn89W6ur4/JcSbobZse+caAP22XKN3gLZOiJQ/iH7/TQPrluKUMSFz6GSsla9APooTZpCadIC4SPA8m+J1df5SLc7KO/nRm3BRXqiQ95Tp/mj+MVALfzP4KdjAOaMJGICVQVoaobhGBXCIMHiz/QXZP8sLENCR0UrBrVa4BmDNCzE3XeUmKQejhShquRuhjDv1UYeUyfZNp16wox0C8B12l2wH5YMzFrGrDp28vB/MFDwv0IuYO7BUvR6+7T2sLRGWsH9rDqXTl/ x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR11MB4627.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(366004)(66476007)(64756008)(86362001)(82960400001)(55016003)(33656002)(53546011)(6506007)(9686003)(2906002)(186003)(4326008)(76116006)(38070700005)(110136005)(54906003)(66946007)(66446008)(316002)(71200400001)(66556008)(83380400001)(508600001)(52536014)(5660300002)(122000001)(8676002)(19627235002)(966005)(107886003)(38100700002)(26005)(7696005)(8936002)(30864003)(559001)(579004)(44824005);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?5LHJQjWJZCkAlmfdwKmwfXTs45Mock9yCphs/mosSrX2q3J9BCfgKS2ZhS4c?= =?us-ascii?Q?qUkbQVYDWy55Nk7xI499VVH5tJZADzyU8j8vi3SQozsN+3d1sF9eL1kgnJ2z?= =?us-ascii?Q?ujeZNj58JLrmfJkgntcLdrmzCDJo7KOFk+1YNeieInes5SLSQKYtmJuYN5od?= =?us-ascii?Q?WeQ23WM+VqmNbx2RgexnOa3VQkjZIgvMLm5xbNIocGxfCJZziGy5OJ5tUJ/i?= =?us-ascii?Q?fZO2dIdVD1NbpMxT4QmYUAQ6j9hsoWc5NE4Od2m1ktKlrSSrQqfyNmrJJmzm?= =?us-ascii?Q?N2eYgdkSBd4jbkuAVcGPV90iRw+RBb2z8Bapjf2G5IiajWPv/KsY1lP77RhB?= =?us-ascii?Q?3OZoR27sI3vWnoFeVAzywRGlernF0QHVTE7e7r7Y3BxIMKYP5KH1R3bmiGHz?= =?us-ascii?Q?4VZ7611XPCn7+uIrMY0MFQW8+4+SUkUWKS+jFVznb1eurf8/aO91nrZ1S0hR?= =?us-ascii?Q?Ba3zCQYuYWqlq8neJYuiopksykG4pxSLVTpuEZSxjV4SWhPk5LIFy72nleB2?= =?us-ascii?Q?B+1yAKX48VHi4GQX2RIBLL9j1IHfqDHXZI/y2y2EjQdyVSgRIwUhDkZix1hj?= =?us-ascii?Q?8qp3hfN/z4NsY5fJWSbCEaqpHQR4+Gl4tF2RZnYvQHtTx35H7LfjnRKpwy5v?= =?us-ascii?Q?+vcNAFy+pCXZv1cxMcsq7Q/dWsg9GT5DXDf4+Gkg8Cc84knyjjQbzLEbTsoZ?= =?us-ascii?Q?gN7QQlNjYyr/I1kM8AItQkWW5SZ2MgKEP6F8x1AGJC/cOqxfmx3v5VqFujkq?= =?us-ascii?Q?Tpba46UGvM45IChNTxndNX1ClcfsKIIQuQo9si6hc8Lk8Pout/I9F9EOtS0x?= =?us-ascii?Q?1jTEHIb2PFLJRCjVm7RsSmLdkzjzDWfzYJi7+KBekWJmwBnyF83QcKrH5TXW?= =?us-ascii?Q?imzieB8QB1aORTyQoYnsxO5aVowOair+4N3Ow7wpUC5jVWI4Vy1weOFGFla6?= =?us-ascii?Q?Rb6gKldq9tqntxWWUQy0EWTaGJeLfBZQoXt9uCjk6f8LIfsEt2/jCD8rfkLg?= =?us-ascii?Q?8YhqqZO5mNPOZNuxiNpbbtp21DOOvmBtlCgeyU/Y6wRDXawR4PmlEhrpu90s?= =?us-ascii?Q?QAwR0ynUOcsnrX/7g6Wu/j9rKLPYQYmKUo/bDvOz6SuxyOhWtUU559ifEgEa?= =?us-ascii?Q?/bD6QmtxjIQbEYt2VRWVV1QQFFG3w5GBRauwI/u37X43T7VOJxJ2Yr2i2dQm?= =?us-ascii?Q?4b9hUim0eoFuT/6i5xCgx4ShvzbetsCBN968YQVHZQ+qFJAYpxOwCDJ/cTI6?= =?us-ascii?Q?fxgYO2ytAd7qsAyA2gSLRcV+YwgUxDvlFgfCQvDYO5c/4dO/qRpAoqWrOyVs?= =?us-ascii?Q?Q/zJK9RkxibWuMzzZNvnFyAI/buAy5XkS77wZ2vrXL+jZhU8jNuImGQyz4t2?= =?us-ascii?Q?rCGWOaatMq7IYe6wkQ1ROiqz3vM3iJhe9NktxP5jQi71px75arm/6yv2zAPa?= =?us-ascii?Q?+GCDu+GuGK8t5NpcatcQkbb8dCgX6z5d1txbQapbB4KPyrwmWr/G45zzjpUa?= =?us-ascii?Q?BqMsk0+UdLgmkYRyL+47LWQxLBGeWIejfOrPd7lY7f3wzbXLyIjM5YWSrAJs?= =?us-ascii?Q?ihC2E3+NFyKz8Ofn4NUPvPWDe0IrnDMabpvwUajRTi1GyRh9wc+/tjRKTFgL?= =?us-ascii?Q?jtoVa05HELxCw64bnDi8qSs=3D?= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: DM6PR11MB4627.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 512dbb26-35cf-42be-83af-08d9dcb8fc6a X-MS-Exchange-CrossTenant-originalarrivaltime: 21 Jan 2022 08:35:31.4693 (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: vAuW6TA5iyS24UmG90eNaOTAOX+C/pqXb99ihioPKi0tZqmobK5d+W/o5U7maJvi6wRhokCm5ciczRjUwIGVjQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR11MB3004 Return-Path: jenny.huang@intel.com X-OriginatorOrg: intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Jenny Huang -----Original Message----- From: Sheng, W =20 Sent: Tuesday, January 18, 2022 4:15 PM To: devel@edk2.groups.io Cc: Ni, Ray ; Chaganty, Rangasai V ; Huang, Jenny ; Kowalewski, Robert Subject: [PATCH v5 4/4] IntelSiliconPkg/VTd: Only generate PEI DMA buffer o= nce. VTdInfoNotify may be called manay times, PEI DMA buffer should be generated only once. REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3667 Cc: Ray Ni Cc: Rangasai V Chaganty Cc: Jenny Huang Cc: Robert Kowalewski Reviewed-by: Jenny Huang Signed-off-by: Sheng Wei --- .../Feature/VTd/IntelVTdDmarPei/DmarTable.c | 545 +----------------= ---- .../Feature/VTd/IntelVTdDmarPei/IntelVTdDmar.c | 433 +++++++--------- .../Feature/VTd/IntelVTdDmarPei/IntelVTdDmarPei.c | 474 ++++++++++-------= - .../Feature/VTd/IntelVTdDmarPei/IntelVTdDmarPei.h | 119 ++--- .../Feature/VTd/IntelVTdDmarPei/TranslationTable.c | 196 ++------ 5 files changed, 533 insertions(+), 1234 deletions(-) diff --git a/Silicon/Intel/IntelSiliconPkg/Feature/VTd/IntelVTdDmarPei/Dmar= Table.c b/Silicon/Intel/IntelSiliconPkg/Feature/VTd/IntelVTdDmarPei/DmarTab= le.c index e9c99d0a..acfbc4a8 100644 --- a/Silicon/Intel/IntelSiliconPkg/Feature/VTd/IntelVTdDmarPei/DmarTable.c +++ b/Silicon/Intel/IntelSiliconPkg/Feature/VTd/IntelVTdDmarPei/DmarTable.c @@ -1,6 +1,7 @@ /** @file =20 - Copyright (c) 2020, Intel Corporation. All rights reserved.
+ Copyright (c) 2020 - 2021, Intel Corporation. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent =20 **/ @@ -104,74 +105,6 @@ DumpDmarDeviceScopeEntry ( return; } =20 -/** - Dump DMAR RMRR table. - - @param[in] Rmrr DMAR RMRR table -**/ -VOID -DumpDmarRmrr ( - IN EFI_ACPI_DMAR_RMRR_HEADER *Rmrr - ) -{ - EFI_ACPI_DMAR_DEVICE_SCOPE_STRUCTURE_HEADER *DmarDeviceScopeEntry; - INTN RmrrLen; - - if (Rmrr =3D=3D NULL) { - return; - } - - DEBUG ((DEBUG_INFO, - " *******************************************************************= ********\n" - )); - DEBUG ((DEBUG_INFO, - " * Reserved Memory Region Reporting Structure = *\n" - )); - DEBUG ((DEBUG_INFO, - " *******************************************************************= ********\n" - )); - DEBUG ((DEBUG_INFO, - (sizeof (UINTN) =3D=3D sizeof (UINT64)) ? - " RMRR address ........................................... 0x%016lx\n= " : - " RMRR address ........................................... 0x%08x\n", - Rmrr - )); - DEBUG ((DEBUG_INFO, - " Type ................................................. 0x%04x\n", - Rmrr->Header.Type - )); - DEBUG ((DEBUG_INFO, - " Length ............................................... 0x%04x\n", - Rmrr->Header.Length - )); - DEBUG ((DEBUG_INFO, - " Segment Number ....................................... 0x%04x\n", - Rmrr->SegmentNumber - )); - DEBUG ((DEBUG_INFO, - " Reserved Memory Region Base Address .................. 0x%016lx\n= ", - Rmrr->ReservedMemoryRegionBaseAddress - )); - DEBUG ((DEBUG_INFO, - " Reserved Memory Region Limit Address ................. 0x%016lx\n= ", - Rmrr->ReservedMemoryRegionLimitAddress - )); - - RmrrLen =3D Rmrr->Header.Length - sizeof(EFI_ACPI_DMAR_RMRR_HEADER); - DmarDeviceScopeEntry =3D (EFI_ACPI_DMAR_DEVICE_SCOPE_STRUCTURE_HEADER *)= (Rmrr + 1); - while (RmrrLen > 0) { - DumpDmarDeviceScopeEntry (DmarDeviceScopeEntry); - RmrrLen -=3D DmarDeviceScopeEntry->Length; - DmarDeviceScopeEntry =3D (EFI_ACPI_DMAR_DEVICE_SCOPE_STRUCTURE_HEADER = *) ((UINTN) DmarDeviceScopeEntry + DmarDeviceScopeEntry->Length); - } - - DEBUG ((DEBUG_INFO, - " *******************************************************************= ********\n\n" - )); - - return; -} - /** Dump DMAR DRHD table. =20 @@ -312,9 +245,6 @@ DumpAcpiDMAR ( case EFI_ACPI_DMAR_TYPE_DRHD: DumpDmarDrhd ((EFI_ACPI_DMAR_DRHD_HEADER *) DmarHeader); break; - case EFI_ACPI_DMAR_TYPE_RMRR: - DumpDmarRmrr ((EFI_ACPI_DMAR_RMRR_HEADER *) DmarHeader); - break; default: break; } @@ -329,492 +259,43 @@ DumpAcpiDMAR ( return; } =20 -/** - Get VTd engine number. - - @param[in] AcpiDmarTable DMAR ACPI table - - @return the VTd engine number. -**/ -UINTN -GetVtdEngineNumber ( - IN EFI_ACPI_DMAR_HEADER *AcpiDmarTable - ) -{ - EFI_ACPI_DMAR_STRUCTURE_HEADER *DmarHeader; - UINTN VtdIndex; - - VtdIndex =3D 0; - DmarHeader =3D (EFI_ACPI_DMAR_STRUCTURE_HEADER *) ((UINTN) (AcpiDmarTabl= e + 1)); - while ((UINTN) DmarHeader < (UINTN) AcpiDmarTable + AcpiDmarTable->Heade= r.Length) { - switch (DmarHeader->Type) { - case EFI_ACPI_DMAR_TYPE_DRHD: - VtdIndex++; - break; - default: - break; - } - DmarHeader =3D (EFI_ACPI_DMAR_STRUCTURE_HEADER *) ((UINTN) DmarHeader = + DmarHeader->Length); - } - return VtdIndex ; -} - -/** - Get PCI device information from DMAR DevScopeEntry. - - @param[in] Segment The segment number. - @param[in] DmarDevScopeEntry DMAR DevScopeEntry - @param[out] Bus The bus number. - @param[out] Device The device number. - @param[out] Function The function number. - - @retval EFI_SUCCESS The PCI device information is returned. -**/ -EFI_STATUS -GetPciBusDeviceFunction ( - IN UINT16 Segment, - IN EFI_ACPI_DMAR_DEVICE_SCOPE_STRUCTURE_HEADER *DmarDevScopeEntry, - OUT UINT8 *Bus, - OUT UINT8 *Device, - OUT UINT8 *Function - ) -{ - EFI_ACPI_DMAR_PCI_PATH *DmarPciPath; - UINT8 MyBus; - UINT8 MyDevice; - UINT8 MyFunction; - - DmarPciPath =3D (EFI_ACPI_DMAR_PCI_PATH *) ((UINTN) (DmarDevScopeEntry += 1)); - MyBus =3D DmarDevScopeEntry->StartBusNumber; - MyDevice =3D DmarPciPath->Device; - MyFunction =3D DmarPciPath->Function; - - switch (DmarDevScopeEntry->Type) { - case EFI_ACPI_DEVICE_SCOPE_ENTRY_TYPE_PCI_ENDPOINT: - case EFI_ACPI_DEVICE_SCOPE_ENTRY_TYPE_PCI_BRIDGE: - while ((UINTN) DmarPciPath + sizeof (EFI_ACPI_DMAR_PCI_PATH) < (UINTN)= DmarDevScopeEntry + DmarDevScopeEntry->Length) { - MyBus =3D PciSegmentRead8 (PCI_SEGMENT_LIB_ADDRESS (Segment, MyBus, = MyDevice, MyFunction, PCI_BRIDGE_SECONDARY_BUS_REGISTER_OFFSET)); - DmarPciPath ++; - MyDevice =3D DmarPciPath->Device; - MyFunction =3D DmarPciPath->Function; - } - break; - case EFI_ACPI_DEVICE_SCOPE_ENTRY_TYPE_IOAPIC: - case EFI_ACPI_DEVICE_SCOPE_ENTRY_TYPE_MSI_CAPABLE_HPET: - case EFI_ACPI_DEVICE_SCOPE_ENTRY_TYPE_ACPI_NAMESPACE_DEVICE: - break; - } - - *Bus =3D MyBus; - *Device =3D MyDevice; - *Function =3D MyFunction; - - return EFI_SUCCESS; -} - -/** - Return the index of PCI data. - - @param[in] VTdUnitInfo The VTd engine unit information. - @param[in] Segment The Segment used to identify a VTd engine. - @param[in] SourceId The SourceId used to identify a VTd engine= and table entry. - - @return The index of the PCI data. - @retval (UINTN)-1 The PCI data is not found. -**/ -UINTN -GetPciDataIndex ( - IN VTD_UNIT_INFO *VTdUnitInfo, - IN UINT16 Segment, - IN VTD_SOURCE_ID SourceId - ) -{ - UINTN Index; - VTD_SOURCE_ID *PciSourceId; - PEI_PCI_DEVICE_DATA *PciDeviceDataBase; - - if (Segment !=3D VTdUnitInfo->Segment) { - return (UINTN)-1; - } - - for (Index =3D 0; Index < VTdUnitInfo->PciDeviceInfo.PciDeviceDataNumber= ; Index++) { - PciDeviceDataBase =3D (PEI_PCI_DEVICE_DATA*) (UINTN) VTdUnitInfo->PciD= eviceInfo.PciDeviceData; - PciSourceId =3D &PciDeviceDataBase[Index].PciSourceId; - if ((PciSourceId->Bits.Bus =3D=3D SourceId.Bits.Bus) && - (PciSourceId->Bits.Device =3D=3D SourceId.Bits.Device) && - (PciSourceId->Bits.Function =3D=3D SourceId.Bits.Function) ) { - return Index; - } - } - - return (UINTN)-1; -} - - -/** - Register PCI device to VTd engine. - - @param[in] VTdUnitInfo The VTd engine unit information. - @param[in] Segment The segment of the source. - @param[in] SourceId The SourceId of the source. - @param[in] DeviceType The DMAR device scope type. - @param[in] CheckExist TRUE: ERROR will be returned if the PCI de= vice is already registered. - FALSE: SUCCESS will be returned if the PCI= device is registered. - - @retval EFI_SUCCESS The PCI device is registered. - @retval EFI_OUT_OF_RESOURCES No enough resource to register a new PCI d= evice. - @retval EFI_ALREADY_STARTED The device is already registered. - -**/ -EFI_STATUS -RegisterPciDevice ( - IN VTD_UNIT_INFO *VTdUnitInfo, - IN UINT16 Segment, - IN VTD_SOURCE_ID SourceId, - IN UINT8 DeviceType, - IN BOOLEAN CheckExist - ) -{ - PEI_PCI_DEVICE_INFORMATION *PciDeviceInfo; - VTD_SOURCE_ID *PciSourceId; - UINTN PciDataIndex; - UINTN PciDeviceDataSize; - PEI_PCI_DEVICE_DATA *NewPciDeviceData; - PEI_PCI_DEVICE_DATA *PciDeviceDataBase; - - PciDeviceInfo =3D &VTdUnitInfo->PciDeviceInfo; - - PciDataIndex =3D GetPciDataIndex (VTdUnitInfo, Segment, SourceId); - if (PciDataIndex =3D=3D (UINTN)-1) { - // - // Register new - // - - if (PciDeviceInfo->PciDeviceDataNumber >=3D PciDeviceInfo->PciDeviceDa= taMaxNumber) { - // - // Reallocate - // - PciDeviceDataSize =3D sizeof(*NewPciDeviceData) * (PciDeviceInfo->Pc= iDeviceDataMaxNumber + MAX_VTD_PCI_DATA_NUMBER); - DEBUG ((DEBUG_INFO, "New PciDeviceDataSize:%d Page:%d\n", PciDeviceD= ataSize, EFI_SIZE_TO_PAGES (PciDeviceDataSize))); - NewPciDeviceData =3D AllocateZeroPages (EFI_SIZE_TO_PAGES(PciDeviceD= ataSize)); - if (NewPciDeviceData =3D=3D NULL) { - return EFI_OUT_OF_RESOURCES; - } - PciDeviceInfo->PciDeviceDataMaxNumber +=3D MAX_VTD_PCI_DATA_NUMBER; - if (PciDeviceInfo->PciDeviceData !=3D 0) { - CopyMem (NewPciDeviceData, (VOID *) (UINTN) PciDeviceInfo->PciDevi= ceData, sizeof (*NewPciDeviceData) * PciDeviceInfo->PciDeviceDataNumber); - FreePages((VOID *) (UINTN) PciDeviceInfo->PciDeviceData, PciDevice= Info->PciDeviceDataPageSize); - } - PciDeviceInfo->PciDeviceData =3D (UINT32) (UINTN) NewPciDeviceData; - PciDeviceInfo->PciDeviceDataPageSize =3D (UINT32) EFI_SIZE_TO_PAGES = (PciDeviceDataSize); - } - - ASSERT (PciDeviceInfo->PciDeviceDataNumber < PciDeviceInfo->PciDeviceD= ataMaxNumber); - - PciDeviceDataBase =3D (PEI_PCI_DEVICE_DATA *) (UINTN) PciDeviceInfo->P= ciDeviceData; - PciSourceId =3D &PciDeviceDataBase[PciDeviceInfo->PciDeviceDataNumber]= .PciSourceId; - PciSourceId->Bits.Bus =3D SourceId.Bits.Bus; - PciSourceId->Bits.Device =3D SourceId.Bits.Device; - PciSourceId->Bits.Function =3D SourceId.Bits.Function; - - DEBUG ((DEBUG_INFO, " RegisterPciDevice: PCI S%04x B%02x D%02x F%02x"= , Segment, SourceId.Bits.Bus, SourceId.Bits.Device, SourceId.Bits.Function)= ); - - PciDeviceDataBase[PciDeviceInfo->PciDeviceDataNumber].DeviceType =3D D= eviceType; - - if ((DeviceType !=3D EFI_ACPI_DEVICE_SCOPE_ENTRY_TYPE_PCI_ENDPOINT) && - (DeviceType !=3D EFI_ACPI_DEVICE_SCOPE_ENTRY_TYPE_PCI_BRIDGE)) { - DEBUG ((DEBUG_INFO, " (*)")); - } - DEBUG ((DEBUG_INFO, "\n")); - - PciDeviceInfo->PciDeviceDataNumber++; - } else { - if (CheckExist) { - DEBUG ((DEBUG_INFO, " RegisterPciDevice: PCI S%04x B%02x D%02x F%02= x already registered\n", Segment, SourceId.Bits.Bus, SourceId.Bits.Device, = SourceId.Bits.Function)); - return EFI_ALREADY_STARTED; - } - } - - return EFI_SUCCESS; -} - -/** - Process DMAR DRHD table. - - @param[in] VTdUnitInfo The VTd engine unit information. - @param[in] DmarDrhd The DRHD table. - -**/ -VOID -ProcessDrhd ( - IN VTD_UNIT_INFO *VTdUnitInfo, - IN EFI_ACPI_DMAR_DRHD_HEADER *DmarDrhd - ) -{ - EFI_ACPI_DMAR_DEVICE_SCOPE_STRUCTURE_HEADER *DmarDevScopeEntry; - UINT8 Bus; - UINT8 Device; - UINT8 Function; - EFI_STATUS Status; - VTD_SOURCE_ID SourceId; - - DEBUG ((DEBUG_INFO," VTD BaseAddress - 0x%016lx\n", DmarDrhd->Register= BaseAddress)); - VTdUnitInfo->VtdUnitBaseAddress =3D (UINT32) DmarDrhd->RegisterBaseAddre= ss; - - VTdUnitInfo->EnableQueuedInvalidation =3D 0; - - DEBUG ((DEBUG_INFO," VTD Segment - %d\n", DmarDrhd->SegmentNumber)); - VTdUnitInfo->Segment =3D DmarDrhd->SegmentNumber; - - VTdUnitInfo->FixedSecondLevelPagingEntry =3D 0; - VTdUnitInfo->RmrrSecondLevelPagingEntry =3D 0; - VTdUnitInfo->RootEntryTable =3D 0; - VTdUnitInfo->ExtRootEntryTable =3D 0; - VTdUnitInfo->RootEntryTablePageSize =3D 0; - VTdUnitInfo->ExtRootEntryTablePageSize =3D 0; - - VTdUnitInfo->PciDeviceInfo.IncludeAllFlag =3D 0; - VTdUnitInfo->PciDeviceInfo.PciDeviceDataMaxNumber =3D 0; - VTdUnitInfo->PciDeviceInfo.PciDeviceDataNumber =3D 0; - VTdUnitInfo->PciDeviceInfo.PciDeviceDataPageSize =3D 0; - VTdUnitInfo->PciDeviceInfo.PciDeviceData =3D 0; - - if ((DmarDrhd->Flags & EFI_ACPI_DMAR_DRHD_FLAGS_INCLUDE_PCI_ALL) !=3D 0)= { - VTdUnitInfo->PciDeviceInfo.IncludeAllFlag =3D TRUE; - DEBUG ((DEBUG_INFO," ProcessDrhd: with INCLUDE ALL\n")); - } else { - VTdUnitInfo->PciDeviceInfo.IncludeAllFlag =3D FALSE; - DEBUG ((DEBUG_INFO," ProcessDrhd: without INCLUDE ALL\n")); - } - - VTdUnitInfo->PciDeviceInfo.PciDeviceDataNumber =3D 0; - VTdUnitInfo->PciDeviceInfo.PciDeviceDataMaxNumber =3D 0; - VTdUnitInfo->PciDeviceInfo.PciDeviceDataPageSize =3D 0; - VTdUnitInfo->PciDeviceInfo.PciDeviceData =3D 0; - - DmarDevScopeEntry =3D (EFI_ACPI_DMAR_DEVICE_SCOPE_STRUCTURE_HEADER *) ((= UINTN) (DmarDrhd + 1)); - while ((UINTN)DmarDevScopeEntry < (UINTN) DmarDrhd + DmarDrhd->Header.Le= ngth) { - - Status =3D GetPciBusDeviceFunction (DmarDrhd->SegmentNumber, DmarDevSc= opeEntry, &Bus, &Device, &Function); - if (EFI_ERROR (Status)) { - return; - } - - DEBUG ((DEBUG_INFO," ProcessDrhd: ")); - switch (DmarDevScopeEntry->Type) { - case EFI_ACPI_DEVICE_SCOPE_ENTRY_TYPE_PCI_ENDPOINT: - DEBUG ((DEBUG_INFO,"PCI Endpoint")); - break; - case EFI_ACPI_DEVICE_SCOPE_ENTRY_TYPE_PCI_BRIDGE: - DEBUG ((DEBUG_INFO,"PCI-PCI bridge")); - break; - case EFI_ACPI_DEVICE_SCOPE_ENTRY_TYPE_IOAPIC: - DEBUG ((DEBUG_INFO,"IOAPIC")); - break; - case EFI_ACPI_DEVICE_SCOPE_ENTRY_TYPE_MSI_CAPABLE_HPET: - DEBUG ((DEBUG_INFO,"MSI Capable HPET")); - break; - case EFI_ACPI_DEVICE_SCOPE_ENTRY_TYPE_ACPI_NAMESPACE_DEVICE: - DEBUG ((DEBUG_INFO,"ACPI Namespace Device")); - break; - } - DEBUG ((DEBUG_INFO," S%04x B%02x D%02x F%02x\n", DmarDrhd->SegmentNumb= er, Bus, Device, Function)); - - SourceId.Bits.Bus =3D Bus; - SourceId.Bits.Device =3D Device; - SourceId.Bits.Function =3D Function; - - Status =3D RegisterPciDevice (VTdUnitInfo, DmarDrhd->SegmentNumber, So= urceId, DmarDevScopeEntry->Type, TRUE); - if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR,"RegisterPciDevice Failed !\n")); - } - - DmarDevScopeEntry =3D (EFI_ACPI_DMAR_DEVICE_SCOPE_STRUCTURE_HEADER *) = ((UINTN) DmarDevScopeEntry + DmarDevScopeEntry->Length); - } -} - -/** - Dump the PCI device information managed by this VTd engine. - - @param[in] VTdInfo The VTd engine context information. - @param[in] VtdIndex The index of VTd engine. - -**/ -VOID -DumpPciDeviceInfo ( - IN VTD_INFO *VTdInfo, - IN UINTN VtdIndex - ) -{ - UINTN Index; - PEI_PCI_DEVICE_DATA *PciDeviceDataBase; - - DEBUG ((DEBUG_INFO,"PCI Device Information (Number 0x%x, IncludeAll - %d= ):\n", - VTdInfo->VtdUnitInfo[VtdIndex].PciDeviceInfo.PciDeviceDataNumber, - VTdInfo->VtdUnitInfo[VtdIndex].PciDeviceInfo.IncludeAllFlag - )); - - PciDeviceDataBase =3D (PEI_PCI_DEVICE_DATA *) (UINTN) VTdInfo->VtdUnitIn= fo[VtdIndex].PciDeviceInfo.PciDeviceData; - - for (Index =3D 0; Index < VTdInfo->VtdUnitInfo[VtdIndex].PciDeviceInfo.P= ciDeviceDataNumber; Index++) { - DEBUG ((DEBUG_INFO," S%04x B%02x D%02x F%02x\n", - VTdInfo->VtdUnitInfo[VtdIndex].Segment, - PciDeviceDataBase[Index].PciSourceId.Bits.Bus, - PciDeviceDataBase[Index].PciSourceId.Bits.Device, - PciDeviceDataBase[Index].PciSourceId.Bits.Function - )); - } -} - /** Parse DMAR DRHD table. =20 @param[in] AcpiDmarTable DMAR ACPI table + @param[in] Callback Callback function for handle DRHD + @param[in] Context Callback function Context =20 @return EFI_SUCCESS The DMAR DRHD table is parsed. =20 **/ EFI_STATUS ParseDmarAcpiTableDrhd ( - IN EFI_ACPI_DMAR_HEADER *AcpiDmarTable + IN EFI_ACPI_DMAR_HEADER *AcpiDmarTable, + IN PROCESS_DRHD_CALLBACK_FUNC Callback, + IN VOID *Context ) { EFI_ACPI_DMAR_STRUCTURE_HEADER *DmarHeader; - UINTN VtdUnitNumber; - UINTN VtdIndex; - VTD_INFO *VTdInfo; - - VtdUnitNumber =3D GetVtdEngineNumber (AcpiDmarTable); - if (VtdUnitNumber =3D=3D 0) { - return EFI_UNSUPPORTED; - } - - VTdInfo =3D BuildGuidHob (&mVTdInfoGuid, sizeof (VTD_INFO) + (VtdUnitNum= ber - 1) * sizeof (VTD_UNIT_INFO)); - ASSERT(VTdInfo !=3D NULL); - if (VTdInfo =3D=3D NULL) { - return EFI_OUT_OF_RESOURCES; - } - - // - // Initialize the engine mask to all. - // - VTdInfo->AcpiDmarTable =3D (UINT32) (UINTN) AcpiDmarTable; - VTdInfo->HostAddressWidth =3D AcpiDmarTable->HostAddressWidth; - VTdInfo->VTdEngineCount =3D (UINT32) VtdUnitNumber; + UINT32 VtdIndex; =20 VtdIndex =3D 0; DmarHeader =3D (EFI_ACPI_DMAR_STRUCTURE_HEADER *) ((UINTN) (AcpiDmarTabl= e + 1)); + while ((UINTN) DmarHeader < (UINTN) AcpiDmarTable + AcpiDmarTable->Heade= r.Length) { switch (DmarHeader->Type) { case EFI_ACPI_DMAR_TYPE_DRHD: - ASSERT (VtdIndex < VtdUnitNumber); - ProcessDrhd (&VTdInfo->VtdUnitInfo[VtdIndex], (EFI_ACPI_DMAR_DRHD_HE= ADER *) DmarHeader); + if (Callback !=3D NULL) { + Callback (Context, VtdIndex, (EFI_ACPI_DMAR_DRHD_HEADER *) DmarHea= der); + } VtdIndex++; - break; - default: break; } DmarHeader =3D (EFI_ACPI_DMAR_STRUCTURE_HEADER *) ((UINTN) DmarHeader = + DmarHeader->Length); } - ASSERT (VtdIndex =3D=3D VtdUnitNumber); - - for (VtdIndex =3D 0; VtdIndex < VtdUnitNumber; VtdIndex++) { - DumpPciDeviceInfo (VTdInfo, VtdIndex); - } - - return EFI_SUCCESS; -} - - -/** - Process DMAR RMRR table. - - @param[in] VTdInfo The VTd engine context information. - @param[in] DmarRmrr The RMRR table. - -**/ -VOID -ProcessRmrr ( - IN VTD_INFO *VTdInfo, - IN EFI_ACPI_DMAR_RMRR_HEADER *DmarRmrr - ) -{ - EFI_ACPI_DMAR_DEVICE_SCOPE_STRUCTURE_HEADER *DmarDevScopeEntry; - UINT8 Bus; - UINT8 Device; - UINT8 Function; - EFI_STATUS Status; - VTD_SOURCE_ID SourceId; - - DEBUG ((DEBUG_INFO," PEI RMRR (Base 0x%016lx, Limit 0x%016lx)\n", DmarR= mrr->ReservedMemoryRegionBaseAddress, DmarRmrr->ReservedMemoryRegionLimitAd= dress)); - - if ((DmarRmrr->ReservedMemoryRegionBaseAddress =3D=3D 0) || - (DmarRmrr->ReservedMemoryRegionLimitAddress =3D=3D 0)) { - return ; - } - - DmarDevScopeEntry =3D (EFI_ACPI_DMAR_DEVICE_SCOPE_STRUCTURE_HEADER *) ((= UINTN) (DmarRmrr + 1)); - while ((UINTN) DmarDevScopeEntry < (UINTN) DmarRmrr + DmarRmrr->Header.L= ength) { - if (DmarDevScopeEntry->Type !=3D EFI_ACPI_DEVICE_SCOPE_ENTRY_TYPE_PCI_= ENDPOINT) { - DEBUG ((DEBUG_INFO,"RMRR DevScopeEntryType is not endpoint, type[0x%= x] \n", DmarDevScopeEntry->Type)); - return; - } - - Status =3D GetPciBusDeviceFunction (DmarRmrr->SegmentNumber, DmarDevSc= opeEntry, &Bus, &Device, &Function); - if (EFI_ERROR (Status)) { - continue; - } - - DEBUG ((DEBUG_INFO,"RMRR S%04x B%02x D%02x F%02x\n", DmarRmrr->Segment= Number, Bus, Device, Function)); - - SourceId.Bits.Bus =3D Bus; - SourceId.Bits.Device =3D Device; - SourceId.Bits.Function =3D Function; - - Status =3D EnableRmrrPageAttribute ( - VTdInfo, - DmarRmrr->SegmentNumber, - SourceId, - DmarRmrr->ReservedMemoryRegionBaseAddress, - DmarRmrr->ReservedMemoryRegionLimitAddress, - EDKII_IOMMU_ACCESS_READ | EDKII_IOMMU_ACCESS_WRITE - ); - if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_INFO, "EnableRmrrPageAttribute : %r\n", Status)); - } - - DmarDevScopeEntry =3D (EFI_ACPI_DMAR_DEVICE_SCOPE_STRUCTURE_HEADER *) = ((UINTN) DmarDevScopeEntry + DmarDevScopeEntry->Length); - } -} - -/** - Parse DMAR DRHD table. - - @param[in] VTdInfo The VTd engine context information. - -**/ -VOID -ParseDmarAcpiTableRmrr ( - IN VTD_INFO *VTdInfo - ) -{ - EFI_ACPI_DMAR_HEADER *AcpiDmarTable; - EFI_ACPI_DMAR_STRUCTURE_HEADER *DmarHeader; =20 - AcpiDmarTable =3D (EFI_ACPI_DMAR_HEADER *) (UINTN) VTdInfo->AcpiDmarTabl= e; - - DmarHeader =3D (EFI_ACPI_DMAR_STRUCTURE_HEADER *) ((UINTN) (AcpiDmarTabl= e + 1)); - while ((UINTN) DmarHeader < (UINTN) AcpiDmarTable + AcpiDmarTable->Heade= r.Length) { - switch (DmarHeader->Type) { - case EFI_ACPI_DMAR_TYPE_RMRR: - ProcessRmrr (VTdInfo, (EFI_ACPI_DMAR_RMRR_HEADER *) DmarHeader); - break; - default: - break; - } - DmarHeader =3D (EFI_ACPI_DMAR_STRUCTURE_HEADER *) ((UINTN) DmarHeader = + DmarHeader->Length); - } + return VtdIndex; } =20 diff --git a/Silicon/Intel/IntelSiliconPkg/Feature/VTd/IntelVTdDmarPei/Inte= lVTdDmar.c b/Silicon/Intel/IntelSiliconPkg/Feature/VTd/IntelVTdDmarPei/Inte= lVTdDmar.c index 63397a1a..0ed216bb 100644 --- a/Silicon/Intel/IntelSiliconPkg/Feature/VTd/IntelVTdDmarPei/IntelVTdDma= r.c +++ b/Silicon/Intel/IntelSiliconPkg/Feature/VTd/IntelVTdDmarPei/IntelVTdDma= r.c @@ -1,6 +1,6 @@ /** @file =20 - Copyright (c) 2020, Intel Corporation. All rights reserved.
+ Copyright (c) 2020 - 2021, Intel Corporation. All rights reserved.
=20 SPDX-License-Identifier: BSD-2-Clause-Patent =20 @@ -79,77 +79,73 @@ PerpareCacheInvalidationInterface ( IN VTD_UNIT_INFO *VTdUnitInfo ) { - UINT16 QueueSize; + UINT16 QiDescLength; UINT64 Reg64; UINT32 Reg32; VTD_ECAP_REG ECapReg; + UINTN VtdUnitBaseAddress; =20 + VtdUnitBaseAddress =3D VTdUnitInfo->VtdUnitBaseAddress; =20 - if (VTdUnitInfo->VerReg.Bits.Major <=3D 6) { + if (VTdUnitInfo->VerReg.Bits.Major <=3D 5) { VTdUnitInfo->EnableQueuedInvalidation =3D 0; - DEBUG ((DEBUG_INFO, "Use Register-based Invalidation Interface for eng= ine [0x%x]\n", VTdUnitInfo->VtdUnitBaseAddress)); + DEBUG ((DEBUG_INFO, "Use Register-based Invalidation Interface for eng= ine [0x%x]\n", VtdUnitBaseAddress)); return EFI_SUCCESS; } =20 - ECapReg.Uint64 =3D MmioRead64 ((UINTN)VTdUnitInfo->VtdUnitBaseAddress + = R_ECAP_REG); + ECapReg.Uint64 =3D MmioRead64 (VtdUnitBaseAddress + R_ECAP_REG); if (ECapReg.Bits.QI =3D=3D 0) { - DEBUG ((DEBUG_ERROR, "Hardware does not support queued invalidations i= nterface for engine [0x%x]\n", VTdUnitInfo->VtdUnitBaseAddress)); + DEBUG ((DEBUG_ERROR, "Hardware does not support queued invalidations i= nterface for engine [0x%x]\n", VtdUnitBaseAddress)); return EFI_UNSUPPORTED; } =20 VTdUnitInfo->EnableQueuedInvalidation =3D 1; - DEBUG ((DEBUG_INFO, "Use Queued Invalidation Interface for engine [0x%x]= \n", VTdUnitInfo->VtdUnitBaseAddress)); + DEBUG ((DEBUG_INFO, "Use Queued Invalidation Interface for engine [0x%x]= \n", VtdUnitBaseAddress)); =20 - Reg32 =3D MmioRead32 ((UINTN)VTdUnitInfo->VtdUnitBaseAddress + R_GSTS_RE= G); + Reg32 =3D MmioRead32 (VtdUnitBaseAddress + R_GSTS_REG); if ((Reg32 & B_GSTS_REG_QIES) !=3D 0) { DEBUG ((DEBUG_INFO,"Queued Invalidation Interface was enabled.\n")); Reg32 &=3D (~B_GSTS_REG_QIES); - MmioWrite32 ((UINTN)VTdUnitInfo->VtdUnitBaseAddress + R_GCMD_REG, Reg3= 2); + MmioWrite32 (VtdUnitBaseAddress + R_GCMD_REG, Reg32); do { - Reg32 =3D MmioRead32 ((UINTN)VTdUnitInfo->VtdUnitBaseAddress + R_GST= S_REG); + Reg32 =3D MmioRead32 (VtdUnitBaseAddress + R_GSTS_REG); } while ((Reg32 & B_GSTS_REG_QIES) !=3D 0); - MmioWrite64 ((UINTN)VTdUnitInfo->VtdUnitBaseAddress + R_IQA_REG, 0); - - if (VTdUnitInfo->QiDesc !=3D NULL) { - FreePages(VTdUnitInfo->QiDesc, EFI_SIZE_TO_PAGES(sizeof(QI_DESC) * V= TdUnitInfo->QiDescLength)); - VTdUnitInfo->QiDesc =3D NULL; - VTdUnitInfo->QiDescLength =3D 0; - } + MmioWrite64 (VtdUnitBaseAddress + R_IQA_REG, 0); } =20 // // Initialize the Invalidation Queue Tail Register to zero. // - MmioWrite64 ((UINTN)VTdUnitInfo->VtdUnitBaseAddress + R_IQT_REG, 0); + MmioWrite64 (VtdUnitBaseAddress + R_IQT_REG, 0); =20 // // Setup the IQ address, size and descriptor width through the Invalidat= ion Queue Address Register // - QueueSize =3D 0; - VTdUnitInfo->QiDescLength =3D 1 << (QueueSize + 8); - VTdUnitInfo->QiDesc =3D (QI_DESC *) AllocatePages (EFI_SIZE_TO_PAGES(siz= eof(QI_DESC) * VTdUnitInfo->QiDescLength)); - if (VTdUnitInfo->QiDesc =3D=3D NULL) { - VTdUnitInfo->QiDescLength =3D 0; - DEBUG ((DEBUG_ERROR,"Could not Alloc Invalidation Queue Buffer.\n")); - return EFI_OUT_OF_RESOURCES; + VTdUnitInfo->QueueSize =3D 0; + QiDescLength =3D 1 << (VTdUnitInfo->QueueSize + 8); + VTdUnitInfo->QiDesc =3D (QI_DESC *) AllocatePages (EFI_SIZE_TO_PAGES(s= izeof(QI_DESC) * QiDescLength)); + if (VTdUnitInfo->QiDesc =3D=3D NULL) { + DEBUG ((DEBUG_ERROR,"Could not Alloc Invalidation Queue Buffer.\n"))= ; + return EFI_OUT_OF_RESOURCES; + } } =20 - DEBUG ((DEBUG_INFO, "Invalidation Queue Length : %d\n", VTdUnitInfo->QiD= escLength)); - Reg64 =3D (UINT64)(UINTN)VTdUnitInfo->QiDesc; - Reg64 |=3D QueueSize; - MmioWrite64 ((UINTN)VTdUnitInfo->VtdUnitBaseAddress + R_IQA_REG, Reg64); + DEBUG ((DEBUG_INFO, "Invalidation Queue Length : %d\n", QiDescLength)); + Reg64 =3D (UINT64) (UINTN) VTdUnitInfo->QiDesc; + Reg64 |=3D VTdUnitInfo->QueueSize; + MmioWrite64 (VtdUnitBaseAddress + R_IQA_REG, Reg64); =20 // // Enable the queued invalidation interface through the Global Command R= egister. // When enabled, hardware sets the QIES field in the Global Status Regis= ter. // - Reg32 =3D MmioRead32 ((UINTN)VTdUnitInfo->VtdUnitBaseAddress + R_GSTS_RE= G); + Reg32 =3D MmioRead32 (VtdUnitBaseAddress + R_GSTS_REG); Reg32 |=3D B_GMCD_REG_QIE; - MmioWrite32 ((UINTN)VTdUnitInfo->VtdUnitBaseAddress + R_GCMD_REG, Reg32)= ; + MmioWrite32 (VtdUnitBaseAddress + R_GCMD_REG, Reg32); DEBUG ((DEBUG_INFO, "Enable Queued Invalidation Interface. GCMD_REG =3D = 0x%x\n", Reg32)); do { - Reg32 =3D MmioRead32 ((UINTN)VTdUnitInfo->VtdUnitBaseAddress + R_GSTS_= REG); + Reg32 =3D MmioRead32 (VtdUnitBaseAddress + R_GSTS_REG); } while ((Reg32 & B_GSTS_REG_QIES) =3D=3D 0); =20 VTdUnitInfo->QiFreeHead =3D 0; @@ -167,21 +163,23 @@ DisableQueuedInvalidationInterface ( IN VTD_UNIT_INFO *VTdUnitInfo ) { - UINT32 Reg32; + UINT32 Reg32; + UINT16 QiDescLength; =20 if (VTdUnitInfo->EnableQueuedInvalidation !=3D 0) { - Reg32 =3D MmioRead32 ((UINTN)VTdUnitInfo->VtdUnitBaseAddress + R_GSTS_= REG); + Reg32 =3D MmioRead32 (VTdUnitInfo->VtdUnitBaseAddress + R_GSTS_REG); Reg32 &=3D (~B_GMCD_REG_QIE); - MmioWrite32 ((UINTN)VTdUnitInfo->VtdUnitBaseAddress + R_GCMD_REG, Reg3= 2); + MmioWrite32 (VTdUnitInfo->VtdUnitBaseAddress + R_GCMD_REG, Reg32); DEBUG ((DEBUG_INFO, "Disable Queued Invalidation Interface. GCMD_REG = =3D 0x%x\n", Reg32)); do { - Reg32 =3D MmioRead32 ((UINTN)VTdUnitInfo->VtdUnitBaseAddress + R_GST= S_REG); + Reg32 =3D MmioRead32 (VTdUnitInfo->VtdUnitBaseAddress + R_GSTS_REG); } while ((Reg32 & B_GSTS_REG_QIES) !=3D 0); =20 if (VTdUnitInfo->QiDesc !=3D NULL) { - FreePages(VTdUnitInfo->QiDesc, EFI_SIZE_TO_PAGES(sizeof(QI_DESC) * V= TdUnitInfo->QiDescLength)); + QiDescLength =3D 1 << (VTdUnitInfo->QueueSize + 8); + FreePages(VTdUnitInfo->QiDesc, EFI_SIZE_TO_PAGES(sizeof(QI_DESC) * Q= iDescLength)); VTdUnitInfo->QiDesc =3D NULL; - VTdUnitInfo->QiDescLength =3D 0; + VTdUnitInfo->QueueSize =3D 0; } =20 VTdUnitInfo->EnableQueuedInvalidation =3D 0; @@ -203,26 +201,11 @@ QueuedInvalidationCheckFault ( { UINT32 FaultReg; =20 - FaultReg =3D MmioRead32 ((UINTN)VTdUnitInfo->VtdUnitBaseAddress + R_FSTS= _REG); - - if (FaultReg & B_FSTS_REG_IQE) { - DEBUG((DEBUG_ERROR, "Detect Invalidation Queue Error [0x%08x]\n", Faul= tReg)); - FaultReg |=3D B_FSTS_REG_IQE; - MmioWrite32 ((UINTN)VTdUnitInfo->VtdUnitBaseAddress + R_FSTS_REG, Faul= tReg); - return RETURN_DEVICE_ERROR; - } - - if (FaultReg & B_FSTS_REG_ITE) { - DEBUG((DEBUG_ERROR, "Detect Invalidation Time-out Error [0x%08x]\n", F= aultReg)); - FaultReg |=3D B_FSTS_REG_ITE; - MmioWrite32 ((UINTN)VTdUnitInfo->VtdUnitBaseAddress + R_FSTS_REG, Faul= tReg); - return RETURN_DEVICE_ERROR; - } - - if (FaultReg & B_FSTS_REG_ICE) { - DEBUG((DEBUG_ERROR, "Detect Invalidation Completion Error [0x%08x]\n",= FaultReg)); - FaultReg |=3D B_FSTS_REG_ICE; - MmioWrite32 ((UINTN)VTdUnitInfo->VtdUnitBaseAddress + R_FSTS_REG, Faul= tReg); + FaultReg =3D MmioRead32 (VTdUnitInfo->VtdUnitBaseAddress + R_FSTS_REG); + if (FaultReg & (B_FSTS_REG_IQE | B_FSTS_REG_ITE | B_FSTS_REG_ICE)) { + DEBUG((DEBUG_ERROR, "Detect Queue Invalidation Error [0x%08x]\n", Faul= tReg)); + FaultReg |=3D (B_FSTS_REG_IQE | B_FSTS_REG_ITE | B_FSTS_REG_ICE); + MmioWrite32 (VTdUnitInfo->VtdUnitBaseAddress + R_FSTS_REG, FaultReg); return RETURN_DEVICE_ERROR; } =20 @@ -256,7 +239,7 @@ SubmitQueuedInvalidationDescriptor ( return EFI_INVALID_PARAMETER; } =20 - QiDescLength =3D VTdUnitInfo->QiDescLength; + QiDescLength =3D 1 << (VTdUnitInfo->QueueSize + 8); BaseDesc =3D VTdUnitInfo->QiDesc; =20 DEBUG((DEBUG_INFO, "[0x%x] Submit QI Descriptor [0x%08x, 0x%08x]\n", VTd= UnitInfo->VtdUnitBaseAddress, Desc->Low, Desc->High)); @@ -268,12 +251,12 @@ SubmitQueuedInvalidationDescriptor ( DEBUG((DEBUG_INFO,"QI Free Head=3D0x%x\n", VTdUnitInfo->QiFreeHead)); VTdUnitInfo->QiFreeHead =3D (VTdUnitInfo->QiFreeHead + 1) % QiDescLength= ; =20 - Reg64Iqh =3D MmioRead64 ((UINTN)VTdUnitInfo->VtdUnitBaseAddress + R_IQH_= REG); + Reg64Iqh =3D MmioRead64 (VTdUnitInfo->VtdUnitBaseAddress + R_IQH_REG); // // Update the HW tail register indicating the presence of new descriptor= s. // Reg64Iqt =3D VTdUnitInfo->QiFreeHead << DMAR_IQ_SHIFT; - MmioWrite64 ((UINTN)VTdUnitInfo->VtdUnitBaseAddress + R_IQT_REG, Reg64Iq= t); + MmioWrite64 (VTdUnitInfo->VtdUnitBaseAddress + R_IQT_REG, Reg64Iqt); =20 Status =3D EFI_SUCCESS; do { @@ -283,7 +266,7 @@ SubmitQueuedInvalidationDescriptor ( break; } =20 - Reg64Iqh =3D MmioRead64 ((UINTN)VTdUnitInfo->VtdUnitBaseAddress + R_IQ= H_REG); + Reg64Iqh =3D MmioRead64 (VTdUnitInfo->VtdUnitBaseAddress + R_IQH_REG); } while (Reg64Iqt !=3D Reg64Iqh); =20 DEBUG((DEBUG_ERROR,"SubmitQueuedInvalidationDescriptor end\n")); @@ -307,18 +290,18 @@ InvalidateContextCache ( // // Register-based Invalidation // - Reg64 =3D MmioRead64 ((UINTN)VTdUnitInfo->VtdUnitBaseAddress + R_CCMD_= REG); + Reg64 =3D MmioRead64 (VTdUnitInfo->VtdUnitBaseAddress + R_CCMD_REG); if ((Reg64 & B_CCMD_REG_ICC) !=3D 0) { - DEBUG ((DEBUG_ERROR,"ERROR: InvalidateContextCache: B_CCMD_REG_ICC i= s set for VTD(%x)\n", (UINTN)VTdUnitInfo->VtdUnitBaseAddress)); + DEBUG ((DEBUG_ERROR,"ERROR: InvalidateContextCache: B_CCMD_REG_ICC i= s set for VTD(%x)\n", VTdUnitInfo->VtdUnitBaseAddress)); return EFI_DEVICE_ERROR; } =20 Reg64 &=3D ((~B_CCMD_REG_ICC) & (~B_CCMD_REG_CIRG_MASK)); Reg64 |=3D (B_CCMD_REG_ICC | V_CCMD_REG_CIRG_GLOBAL); - MmioWrite64 ((UINTN)VTdUnitInfo->VtdUnitBaseAddress + R_CCMD_REG, Reg6= 4); + MmioWrite64 (VTdUnitInfo->VtdUnitBaseAddress + R_CCMD_REG, Reg64); =20 do { - Reg64 =3D MmioRead64 ((UINTN)VTdUnitInfo->VtdUnitBaseAddress + R_CCM= D_REG); + Reg64 =3D MmioRead64 (VTdUnitInfo->VtdUnitBaseAddress + R_CCMD_REG); } while ((Reg64 & B_CCMD_REG_ICC) !=3D 0); } else { // @@ -351,26 +334,26 @@ InvalidateIOTLB ( // // Register-based Invalidation // - ECapReg.Uint64 =3D MmioRead64 ((UINTN)VTdUnitInfo->VtdUnitBaseAddress = + R_ECAP_REG); + ECapReg.Uint64 =3D MmioRead64 (VTdUnitInfo->VtdUnitBaseAddress + R_ECA= P_REG); =20 - Reg64 =3D MmioRead64 ((UINTN)VTdUnitInfo->VtdUnitBaseAddress + (ECapRe= g.Bits.IRO * 16) + R_IOTLB_REG); + Reg64 =3D MmioRead64 (VTdUnitInfo->VtdUnitBaseAddress + (ECapReg.Bits.= IRO * 16) + R_IOTLB_REG); if ((Reg64 & B_IOTLB_REG_IVT) !=3D 0) { - DEBUG ((DEBUG_ERROR, "ERROR: InvalidateIOTLB: B_IOTLB_REG_IVT is se= t for VTD(%x)\n", (UINTN)VTdUnitInfo->VtdUnitBaseAddress)); + DEBUG ((DEBUG_ERROR, "ERROR: InvalidateIOTLB: B_IOTLB_REG_IVT is se= t for VTD(%x)\n", VTdUnitInfo->VtdUnitBaseAddress)); return EFI_DEVICE_ERROR; } =20 Reg64 &=3D ((~B_IOTLB_REG_IVT) & (~B_IOTLB_REG_IIRG_MASK)); Reg64 |=3D (B_IOTLB_REG_IVT | V_IOTLB_REG_IIRG_GLOBAL); - MmioWrite64 ((UINTN)VTdUnitInfo->VtdUnitBaseAddress + (ECapReg.Bits.IR= O * 16) + R_IOTLB_REG, Reg64); + MmioWrite64 (VTdUnitInfo->VtdUnitBaseAddress + (ECapReg.Bits.IRO * 16)= + R_IOTLB_REG, Reg64); =20 do { - Reg64 =3D MmioRead64 ((UINTN)VTdUnitInfo->VtdUnitBaseAddress + (ECap= Reg.Bits.IRO * 16) + R_IOTLB_REG); + Reg64 =3D MmioRead64 (VTdUnitInfo->VtdUnitBaseAddress + (ECapReg.Bit= s.IRO * 16) + R_IOTLB_REG); } while ((Reg64 & B_IOTLB_REG_IVT) !=3D 0); } else { // // Queued Invalidation // - ECapReg.Uint64 =3D MmioRead64 ((UINTN)VTdUnitInfo->VtdUnitBaseAddress = + R_ECAP_REG); + ECapReg.Uint64 =3D MmioRead64 (VTdUnitInfo->VtdUnitBaseAddress + R_ECA= P_REG); QiDesc.Low =3D QI_IOTLB_DID(0) | QI_IOTLB_DR(CAP_READ_DRAIN(ECapReg.Ui= nt64)) | QI_IOTLB_DW(CAP_WRITE_DRAIN(ECapReg.Uint64)) | QI_IOTLB_GRAN(1) | = QI_IOTLB_TYPE; QiDesc.High =3D QI_IOTLB_ADDR(0) | QI_IOTLB_IH(0) | QI_IOTLB_AM(0); =20 @@ -392,14 +375,14 @@ InvalidateIOTLB ( EFI_STATUS EnableDmarPreMem ( IN UINTN VtdUnitBaseAddress, - IN UINTN RtaddrRegValue + IN UINT64 RtaddrRegValue ) { UINT32 Reg32; =20 DEBUG ((DEBUG_INFO, ">>>>>>EnableDmarPreMem() for engine [%x] \n", VtdUn= itBaseAddress)); =20 - DEBUG ((DEBUG_INFO, "RTADDR_REG : 0x%x \n", RtaddrRegValue)); + DEBUG ((DEBUG_INFO, "RTADDR_REG : 0x%016lx \n", RtaddrRegValue)); MmioWrite64 (VtdUnitBaseAddress + R_RTADDR_REG, (UINT64) RtaddrRegValue)= ; =20 Reg32 =3D MmioRead32 (VtdUnitBaseAddress + R_GSTS_REG); @@ -452,30 +435,33 @@ EnableDmar ( ) { UINT32 Reg32; + UINTN VtdUnitBaseAddress; =20 - DEBUG ((DEBUG_INFO, ">>>>>>EnableDmar() for engine [%x] \n", VTdUnitInfo= ->VtdUnitBaseAddress)); + VtdUnitBaseAddress =3D VTdUnitInfo->VtdUnitBaseAddress; + + DEBUG ((DEBUG_INFO, ">>>>>>EnableDmar() for engine [%x] \n", VtdUnitBase= Address)); =20 DEBUG ((DEBUG_INFO, "RootEntryTable 0x%x \n", RootEntryTable)); - MmioWrite64 ((UINTN)VTdUnitInfo->VtdUnitBaseAddress + R_RTADDR_REG, (UIN= T64) (UINTN) RootEntryTable); + MmioWrite64 (VtdUnitBaseAddress + R_RTADDR_REG, (UINT64) RootEntryTable)= ; =20 - Reg32 =3D MmioRead32 ((UINTN)VTdUnitInfo->VtdUnitBaseAddress + R_GSTS_RE= G); - MmioWrite32 ((UINTN)VTdUnitInfo->VtdUnitBaseAddress + R_GCMD_REG, Reg32 = | B_GMCD_REG_SRTP); + Reg32 =3D MmioRead32 (VtdUnitBaseAddress + R_GSTS_REG); + MmioWrite32 (VtdUnitBaseAddress + R_GCMD_REG, Reg32 | B_GMCD_REG_SRTP); =20 DEBUG ((DEBUG_INFO, "EnableDmar: waiting for RTPS bit to be set... \n"))= ; do { - Reg32 =3D MmioRead32 ((UINTN)VTdUnitInfo->VtdUnitBaseAddress + R_GSTS_= REG); + Reg32 =3D MmioRead32 (VtdUnitBaseAddress + R_GSTS_REG); } while((Reg32 & B_GSTS_REG_RTPS) =3D=3D 0); DEBUG ((DEBUG_INFO, "EnableDmar: R_GSTS_REG =3D 0x%x \n", Reg32)); =20 // // Init DMAr Fault Event and Data registers // - Reg32 =3D MmioRead32 ((UINTN)VTdUnitInfo->VtdUnitBaseAddress + R_FEDATA_= REG); + Reg32 =3D MmioRead32 (VtdUnitBaseAddress + R_FEDATA_REG); =20 // // Write Buffer Flush before invalidation // - FlushWriteBuffer ((UINTN)VTdUnitInfo->VtdUnitBaseAddress); + FlushWriteBuffer (VtdUnitBaseAddress); =20 // // Invalidate the context cache @@ -490,11 +476,11 @@ EnableDmar ( // // Enable VTd // - Reg32 =3D MmioRead32 ((UINTN)VTdUnitInfo->VtdUnitBaseAddress + R_GSTS_RE= G); - MmioWrite32 ((UINTN)VTdUnitInfo->VtdUnitBaseAddress + R_GCMD_REG, Reg32 = | B_GMCD_REG_TE); + Reg32 =3D MmioRead32 (VtdUnitBaseAddress + R_GSTS_REG); + MmioWrite32 (VtdUnitBaseAddress + R_GCMD_REG, Reg32 | B_GMCD_REG_TE); DEBUG ((DEBUG_INFO, "EnableDmar: Waiting B_GSTS_REG_TE ...\n")); do { - Reg32 =3D MmioRead32 ((UINTN)VTdUnitInfo->VtdUnitBaseAddress + R_GSTS_= REG); + Reg32 =3D MmioRead32 (VtdUnitBaseAddress + R_GSTS_REG); } while ((Reg32 & B_GSTS_REG_TE) =3D=3D 0); =20 DEBUG ((DEBUG_INFO, "VTD () enabled!<<<<<<\n")); @@ -566,139 +552,52 @@ DisableDmar ( } =20 /** - Dump VTd version registers. + Enable VTd translation table protection for block DMA =20 - @param[in] VerReg The version register. -**/ -VOID -DumpVtdVerRegs ( - IN VTD_VER_REG *VerReg - ) -{ - DEBUG ((DEBUG_INFO, " VerReg:\n", VerReg->Uint32)); - DEBUG ((DEBUG_INFO, " Major - 0x%x\n", VerReg->Bits.Major)); - DEBUG ((DEBUG_INFO, " Minor - 0x%x\n", VerReg->Bits.Minor)); -} - -/** - Dump VTd capability registers. - - @param[in] CapReg The capability register. -**/ -VOID -DumpVtdCapRegs ( - IN VTD_CAP_REG *CapReg - ) -{ - DEBUG ((DEBUG_INFO, " CapReg:\n", CapReg->Uint64)); - DEBUG ((DEBUG_INFO, " ND - 0x%x\n", CapReg->Bits.ND)); - DEBUG ((DEBUG_INFO, " AFL - 0x%x\n", CapReg->Bits.AFL)); - DEBUG ((DEBUG_INFO, " RWBF - 0x%x\n", CapReg->Bits.RWBF)); - DEBUG ((DEBUG_INFO, " PLMR - 0x%x\n", CapReg->Bits.PLMR)); - DEBUG ((DEBUG_INFO, " PHMR - 0x%x\n", CapReg->Bits.PHMR)); - DEBUG ((DEBUG_INFO, " CM - 0x%x\n", CapReg->Bits.CM)); - DEBUG ((DEBUG_INFO, " SAGAW - 0x%x\n", CapReg->Bits.SAGAW)); - DEBUG ((DEBUG_INFO, " MGAW - 0x%x\n", CapReg->Bits.MGAW)); - DEBUG ((DEBUG_INFO, " ZLR - 0x%x\n", CapReg->Bits.ZLR)); - DEBUG ((DEBUG_INFO, " FRO - 0x%x\n", CapReg->Bits.FRO)); - DEBUG ((DEBUG_INFO, " SLLPS - 0x%x\n", CapReg->Bits.SLLPS)); - DEBUG ((DEBUG_INFO, " PSI - 0x%x\n", CapReg->Bits.PSI)); - DEBUG ((DEBUG_INFO, " NFR - 0x%x\n", CapReg->Bits.NFR)); - DEBUG ((DEBUG_INFO, " MAMV - 0x%x\n", CapReg->Bits.MAMV)); - DEBUG ((DEBUG_INFO, " DWD - 0x%x\n", CapReg->Bits.DWD)); - DEBUG ((DEBUG_INFO, " DRD - 0x%x\n", CapReg->Bits.DRD)); - DEBUG ((DEBUG_INFO, " FL1GP - 0x%x\n", CapReg->Bits.FL1GP)); - DEBUG ((DEBUG_INFO, " PI - 0x%x\n", CapReg->Bits.PI)); -} + @param[in] VtdUnitBaseAddress The base address of the VTd engine. =20 -/** - Dump VTd extended capability registers. - - @param[in] ECapReg The extended capability register. + @retval EFI_SUCCESS DMAR translation is enabled. + @retval EFI_DEVICE_ERROR DMAR translation is not enabled. **/ -VOID -DumpVtdECapRegs ( - IN VTD_ECAP_REG *ECapReg - ) -{ - DEBUG ((DEBUG_INFO, " ECapReg:\n", ECapReg->Uint64)); - DEBUG ((DEBUG_INFO, " C - 0x%x\n", ECapReg->Bits.C)); - DEBUG ((DEBUG_INFO, " QI - 0x%x\n", ECapReg->Bits.QI)); - DEBUG ((DEBUG_INFO, " DT - 0x%x\n", ECapReg->Bits.DT)); - DEBUG ((DEBUG_INFO, " IR - 0x%x\n", ECapReg->Bits.IR)); - DEBUG ((DEBUG_INFO, " EIM - 0x%x\n", ECapReg->Bits.EIM)); - DEBUG ((DEBUG_INFO, " PT - 0x%x\n", ECapReg->Bits.PT)); - DEBUG ((DEBUG_INFO, " SC - 0x%x\n", ECapReg->Bits.SC)); - DEBUG ((DEBUG_INFO, " IRO - 0x%x\n", ECapReg->Bits.IRO)); - DEBUG ((DEBUG_INFO, " MHMV - 0x%x\n", ECapReg->Bits.MHMV)); - DEBUG ((DEBUG_INFO, " MTS - 0x%x\n", ECapReg->Bits.MTS)); - DEBUG ((DEBUG_INFO, " NEST - 0x%x\n", ECapReg->Bits.NEST)); - DEBUG ((DEBUG_INFO, " PASID - 0x%x\n", ECapReg->Bits.PASID)); - DEBUG ((DEBUG_INFO, " PRS - 0x%x\n", ECapReg->Bits.PRS)); - DEBUG ((DEBUG_INFO, " ERS - 0x%x\n", ECapReg->Bits.ERS)); - DEBUG ((DEBUG_INFO, " SRS - 0x%x\n", ECapReg->Bits.SRS)); - DEBUG ((DEBUG_INFO, " NWFS - 0x%x\n", ECapReg->Bits.NWFS)); - DEBUG ((DEBUG_INFO, " EAFS - 0x%x\n", ECapReg->Bits.EAFS)); - DEBUG ((DEBUG_INFO, " PSS - 0x%x\n", ECapReg->Bits.PSS)); - DEBUG ((DEBUG_INFO, " ADMS - 0x%x\n", ECapReg->Bits.ADMS)); -} - - -/** - Enable VTd translation table protection for all. - - @param[in] VTdInfo The VTd engine context information. - @param[in] EngineMask The mask of the VTd engine to be accessed. -**/ -VOID -EnableVTdTranslationProtectionAll ( - IN VTD_INFO *VTdInfo, - IN UINT64 EngineMask +EFI_STATUS +EnableVTdTranslationProtectionBlockDma ( + IN UINTN VtdUnitBaseAddress ) { - EFI_STATUS Status; - EDKII_VTD_NULL_ROOT_ENTRY_TABLE_PPI *RootEntryTable; - UINTN Index; + EFI_STATUS Status; + VTD_ECAP_REG ECapReg; + EDKII_VTD_NULL_ROOT_ENTRY_TABLE_PPI *RootEntryTable; =20 - DEBUG ((DEBUG_INFO, "EnableVTdTranslationProtectionAll - 0x%lx\n", Engin= eMask)); + DEBUG ((DEBUG_INFO, "EnableVTdTranslationProtectionBlockDma - 0x%08x\n",= VtdUnitBaseAddress)); =20 - for (Index =3D 0; Index < VTdInfo->VTdEngineCount; Index++) { - if ((EngineMask & LShiftU64(1, Index)) =3D=3D 0) { - continue; - } + ECapReg.Uint64 =3D MmioRead64 (VtdUnitBaseAddress + R_ECAP_REG); + DEBUG ((DEBUG_INFO, "ECapReg : 0%016lx\n", ECapReg.Uint64)); =20 - VTdInfo->VtdUnitInfo[Index].VerReg.Uint32 =3D MmioRead32 (VTdInfo->Vtd= UnitInfo[Index].VtdUnitBaseAddress + R_VER_REG); - DumpVtdVerRegs (&VTdInfo->VtdUnitInfo[Index].VerReg); - VTdInfo->VtdUnitInfo[Index].CapReg.Uint64 =3D MmioRead64 (VTdInfo->Vtd= UnitInfo[Index].VtdUnitBaseAddress + R_CAP_REG); - DumpVtdCapRegs (&VTdInfo->VtdUnitInfo[Index].CapReg); - VTdInfo->VtdUnitInfo[Index].ECapReg.Uint64 =3D MmioRead64 (VTdInfo->Vt= dUnitInfo[Index].VtdUnitBaseAddress + R_ECAP_REG); - DumpVtdECapRegs (&VTdInfo->VtdUnitInfo[Index].ECapReg); - - if (VTdInfo->VtdUnitInfo[Index].ECapReg.Bits.ADMS =3D=3D 1) { - // - // Use Abort DMA Mode - // - Status =3D EnableDmarPreMem (VTdInfo->VtdUnitInfo[Index].VtdUnitBase= Address, V_RTADDR_REG_TTM_ADM); - } else { - // - // Use Null Root Entry Table - // - Status =3D PeiServicesLocatePpi ( - &gEdkiiVTdNullRootEntryTableGuid, - 0, - NULL, - (VOID **)&RootEntryTable - ); - if (EFI_ERROR(Status)) { - DEBUG ((DEBUG_ERROR, "Locate Null Root Entry Table Ppi Failed : %r= \n", Status)); - ASSERT (FALSE); - return; - } - EnableDmarPreMem (VTdInfo->VtdUnitInfo[Index].VtdUnitBaseAddress, (U= INTN) *RootEntryTable); + if (ECapReg.Bits.ADMS =3D=3D 1) { + // + // Use Abort DMA Mode + // + DEBUG ((DEBUG_INFO, "Enable abort DMA mode.\n")); + Status =3D EnableDmarPreMem (VtdUnitBaseAddress, V_RTADDR_REG_TTM_ADM)= ; + } else { + // + // Use Null Root Entry Table + // + Status =3D PeiServicesLocatePpi ( + &gEdkiiVTdNullRootEntryTableGuid, + 0, + NULL, + (VOID **)&RootEntryTable + ); + if (EFI_ERROR(Status)) { + DEBUG ((DEBUG_ERROR, "Locate Null Root Entry Table Ppi Failed : %r\n= ", Status)); + ASSERT (FALSE); + return EFI_DEVICE_ERROR; } + Status =3D EnableDmarPreMem (VtdUnitBaseAddress, (UINT64) (*RootEntryT= able)); } =20 - return; + return Status; } =20 /** @@ -715,18 +614,25 @@ EnableVTdTranslationProtection ( ) { EFI_STATUS Status; - UINTN VtdIndex; + UINTN Index; + VTD_UNIT_INFO *VtdUnitInfo; =20 - for (VtdIndex =3D 0; VtdIndex < VTdInfo->VTdEngineCount; VtdIndex++) { - if (VTdInfo->VtdUnitInfo[VtdIndex].ExtRootEntryTable !=3D 0) { - DEBUG ((DEBUG_INFO, "EnableVtdDmar (%d) ExtRootEntryTable 0x%x\n", V= tdIndex, VTdInfo->VtdUnitInfo[VtdIndex].ExtRootEntryTable)); - Status =3D EnableDmar (&VTdInfo->VtdUnitInfo[VtdIndex], VTdInfo->Vtd= UnitInfo[VtdIndex].ExtRootEntryTable); + for (Index =3D 0; Index < VTdInfo->VTdEngineCount; Index++) { + VtdUnitInfo =3D &VTdInfo->VtdUnitInfo[Index]; + if (VtdUnitInfo->Done) { + DEBUG ((DEBUG_INFO, "EnableVtdDmar (%d) was enabled\n", Index)); + continue; + } + + if (VtdUnitInfo->ExtRootEntryTable !=3D 0) { + DEBUG ((DEBUG_INFO, "EnableVtdDmar (%d) ExtRootEntryTable 0x%x\n", I= ndex, VtdUnitInfo->ExtRootEntryTable)); + Status =3D EnableDmar (VtdUnitInfo, VtdUnitInfo->ExtRootEntryTable); } else { - DEBUG ((DEBUG_INFO, "EnableVtdDmar (%d) RootEntryTable 0x%x\n", VtdI= ndex, VTdInfo->VtdUnitInfo[VtdIndex].RootEntryTable)); - Status =3D EnableDmar (&VTdInfo->VtdUnitInfo[VtdIndex], VTdInfo->Vtd= UnitInfo[VtdIndex].RootEntryTable); + DEBUG ((DEBUG_INFO, "EnableVtdDmar (%d) RootEntryTable 0x%x\n", Inde= x, VtdUnitInfo->RootEntryTable)); + Status =3D EnableDmar (VtdUnitInfo, VtdUnitInfo->RootEntryTable); } if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "EnableVtdDmar (%d) Failed !\n", VtdIndex)); + DEBUG ((DEBUG_ERROR, "EnableVtdDmar (%d) Failed !\n", Index)); return Status; } } @@ -737,23 +643,22 @@ EnableVTdTranslationProtection ( Disable VTd translation table protection. =20 @param[in] VTdInfo The VTd engine context information. - @param[in] EngineMask The mask of the VTd engine to be accessed. **/ VOID DisableVTdTranslationProtection ( - IN VTD_INFO *VTdInfo, - IN UINT64 EngineMask + IN VTD_INFO *VTdInfo ) { UINTN Index; =20 - DEBUG ((DEBUG_INFO, "DisableVTdTranslationProtection - 0x%lx\n", EngineM= ask)); + if (VTdInfo =3D=3D NULL) { + return; + } + + DEBUG ((DEBUG_INFO, "DisableVTdTranslationProtection - %d Vtd Engine\n",= VTdInfo->VTdEngineCount)); =20 for (Index =3D 0; Index < VTdInfo->VTdEngineCount; Index++) { - if ((EngineMask & LShiftU64(1, Index)) =3D=3D 0) { - continue; - } - DisableDmar ((UINTN) VTdInfo->VtdUnitInfo[Index].VtdUnitBaseAddress); + DisableDmar (VTdInfo->VtdUnitInfo[Index].VtdUnitBaseAddress); =20 DisableQueuedInvalidationInterface(&VTdInfo->VtdUnitInfo[Index]); } @@ -786,6 +691,36 @@ PrepareVtdCacheInvalidationConfig ( return EFI_SUCCESS; } =20 +/** + +**/ +EFI_STATUS +VtdCheckUsing5LevelPaging ( + IN UINT8 HostAddressWidth, + IN VTD_UNIT_INFO *VtdUnitInfo, + OUT BOOLEAN *Is5LevelPaging + ) +{ + DEBUG((DEBUG_INFO, " CapReg SAGAW bits : 0x%02x\n", VtdUnitInfo->CapReg= .Bits.SAGAW)); + + *Is5LevelPaging =3D FALSE; + if ((VtdUnitInfo->CapReg.Bits.SAGAW & BIT3) !=3D 0) { + *Is5LevelPaging =3D TRUE; + if ((HostAddressWidth <=3D 48) && + ((VtdUnitInfo->CapReg.Bits.SAGAW & BIT2) !=3D 0)) { + *Is5LevelPaging =3D FALSE; + } else { + return EFI_UNSUPPORTED; + } + } + if ((VtdUnitInfo->CapReg.Bits.SAGAW & (BIT3 | BIT2)) =3D=3D 0) { + return EFI_UNSUPPORTED; + } + DEBUG((DEBUG_INFO, " Using %d Level Paging\n", *Is5LevelPaging ? 5 : 4)= ); + return EFI_SUCCESS; +} + + /** Prepare VTD configuration. =20 @@ -798,43 +733,37 @@ PrepareVtdConfig ( IN VTD_INFO *VTdInfo ) { + EFI_STATUS Status; UINTN Index; - UINTN DomainNumber; + VTD_UNIT_INFO *VtdUnitInfo; + UINTN VtdUnitBaseAddress; =20 for (Index =3D 0; Index < VTdInfo->VTdEngineCount; Index++) { - DEBUG ((DEBUG_ERROR, "Dump VTd Capability (%d)\n", Index)); - VTdInfo->VtdUnitInfo[Index].VerReg.Uint32 =3D MmioRead32 (VTdInfo->Vtd= UnitInfo[Index].VtdUnitBaseAddress + R_VER_REG); - DumpVtdVerRegs (&VTdInfo->VtdUnitInfo[Index].VerReg); - VTdInfo->VtdUnitInfo[Index].CapReg.Uint64 =3D MmioRead64 (VTdInfo->Vtd= UnitInfo[Index].VtdUnitBaseAddress + R_CAP_REG); - DumpVtdCapRegs (&VTdInfo->VtdUnitInfo[Index].CapReg); - VTdInfo->VtdUnitInfo[Index].ECapReg.Uint64 =3D MmioRead64 (VTdInfo->Vt= dUnitInfo[Index].VtdUnitBaseAddress + R_ECAP_REG); - DumpVtdECapRegs (&VTdInfo->VtdUnitInfo[Index].ECapReg); - - VTdInfo->VtdUnitInfo[Index].Is5LevelPaging =3D FALSE; - if ((VTdInfo->VtdUnitInfo[Index].CapReg.Bits.SAGAW & BIT2) !=3D 0) { - DEBUG ((DEBUG_INFO, "Support 4-level page-table on VTD %d\n", Index)= ); - } - if ((VTdInfo->VtdUnitInfo[Index].CapReg.Bits.SAGAW & BIT3) !=3D 0) { - DEBUG((DEBUG_INFO, "Support 5-level page-table on VTD %d\n", Index))= ; - VTdInfo->VtdUnitInfo[Index].Is5LevelPaging =3D TRUE; - - if ((VTdInfo->HostAddressWidth <=3D 48) && - ((VTdInfo->VtdUnitInfo[Index].CapReg.Bits.SAGAW & BIT2) !=3D 0))= { - DEBUG ((DEBUG_INFO, "Rollback to 4-level page-table on VTD %d\n", = Index)); - VTdInfo->VtdUnitInfo[Index].Is5LevelPaging =3D FALSE; - } + VtdUnitInfo =3D &VTdInfo->VtdUnitInfo[Index]; + if (VtdUnitInfo->Done) { + continue; } - if ((VTdInfo->VtdUnitInfo[Index].CapReg.Bits.SAGAW & (BIT3 | BIT2)) = =3D=3D 0) { - DEBUG ((DEBUG_ERROR, "!!!! Page-table type 0x%X is not supported on = VTD %d !!!!\n", Index, VTdInfo->VtdUnitInfo[Index].CapReg.Bits.SAGAW)); - return EFI_UNSUPPORTED; + VtdUnitBaseAddress =3D VtdUnitInfo->VtdUnitBaseAddress; + DEBUG((DEBUG_INFO, "VTd Engine: 0x%08X\n", VtdUnitBaseAddress)); + + VtdUnitInfo->VerReg.Uint32 =3D MmioRead32 (VtdUnitBaseAddress + R_VER_= REG); + VtdUnitInfo->CapReg.Uint64 =3D MmioRead64 (VtdUnitBaseAddress + R_CAP_= REG); + VtdUnitInfo->ECapReg.Uint64 =3D MmioRead64 (VtdUnitBaseAddress + R_ECA= P_REG); + DEBUG((DEBUG_INFO, " VerReg : 0x%08X\n", VtdUnitInfo->VerReg.Uint32)= ); + DEBUG((DEBUG_INFO, " CapReg : 0x%016lX\n", VtdUnitInfo->CapReg.Uint6= 4)); + DEBUG((DEBUG_INFO, " ECapReg : 0x%016lX\n", VtdUnitInfo->ECapReg.Uint= 64)); + + Status =3D VtdCheckUsing5LevelPaging (VTdInfo->HostAddressWidth, VtdUn= itInfo, &(VtdUnitInfo->Is5LevelPaging)); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "!!!! Page-table type 0x%X is not supported!!!!= \n", VtdUnitInfo->CapReg.Bits.SAGAW)); + return Status; } =20 - DomainNumber =3D (UINTN)1 << (UINT8) ((UINTN) VTdInfo->VtdUnitInfo[Ind= ex].CapReg.Bits.ND * 2 + 4); - if (VTdInfo->VtdUnitInfo[Index].PciDeviceInfo.PciDeviceDataNumber >=3D= DomainNumber) { - DEBUG ((DEBUG_ERROR, "!!!! Pci device Number(0x%x) >=3D DomainNumber= (0x%x) !!!!\n", VTdInfo->VtdUnitInfo[Index].PciDeviceInfo.PciDeviceDataNumb= er, DomainNumber)); - return EFI_UNSUPPORTED; + Status =3D PerpareCacheInvalidationInterface(VtdUnitInfo); + if (EFI_ERROR (Status)) { + return Status; } } + return EFI_SUCCESS; } - diff --git a/Silicon/Intel/IntelSiliconPkg/Feature/VTd/IntelVTdDmarPei/Inte= lVTdDmarPei.c b/Silicon/Intel/IntelSiliconPkg/Feature/VTd/IntelVTdDmarPei/I= ntelVTdDmarPei.c index a8f7bfee..ac91eac3 100644 --- a/Silicon/Intel/IntelSiliconPkg/Feature/VTd/IntelVTdDmarPei/IntelVTdDma= rPei.c +++ b/Silicon/Intel/IntelSiliconPkg/Feature/VTd/IntelVTdDmarPei/IntelVTdDma= rPei.c @@ -1,6 +1,6 @@ /** @file =20 - Copyright (c) 2020, Intel Corporation. All rights reserved.
+ Copyright (c) 2020 - 2021, Intel Corporation. All rights reserved.
=20 SPDX-License-Identifier: BSD-2-Clause-Patent =20 @@ -50,20 +50,20 @@ typedef struct { the device driver need use SetAttribute() to update the IOMMU attribute to request DMA access (read and/or write). =20 - @param[in] This The PPI instance pointer. - @param[in] DeviceHandle The device who initiates the DMA access re= quest. - @param[in] Mapping The mapping value returned from Map(). - @param[in] IoMmuAccess The IOMMU access. - - @retval EFI_SUCCESS The IoMmuAccess is set for the memory rang= e specified by DeviceAddress and Length. - @retval EFI_INVALID_PARAMETER Mapping is not a value that was returned b= y Map(). - @retval EFI_INVALID_PARAMETER IoMmuAccess specified an illegal combinati= on of access. - @retval EFI_UNSUPPORTED The bit mask of IoMmuAccess is not support= ed by the IOMMU. - @retval EFI_UNSUPPORTED The IOMMU does not support the memory rang= e specified by Mapping. - @retval EFI_OUT_OF_RESOURCES There are not enough resources available t= o modify the IOMMU access. - @retval EFI_DEVICE_ERROR The IOMMU device reported an error while a= ttempting the operation. - @retval EFI_NOT_AVAILABLE_YET DMA protection has been enabled, but DMA b= uffer are - not available to be allocated yet. + @param[in] This The PPI instance pointer. + @param[in] DeviceHandle The device who initiates the DMA acces= s request. + @param[in] Mapping The mapping value returned from Map(). + @param[in] IoMmuAccess The IOMMU access. + + @retval EFI_SUCCESS The IoMmuAccess is set for the memory = range specified by DeviceAddress and Length. + @retval EFI_INVALID_PARAMETER Mapping is not a value that was return= ed by Map(). + @retval EFI_INVALID_PARAMETER IoMmuAccess specified an illegal combi= nation of access. + @retval EFI_UNSUPPORTED The bit mask of IoMmuAccess is not sup= ported by the IOMMU. + @retval EFI_UNSUPPORTED The IOMMU does not support the memory = range specified by Mapping. + @retval EFI_OUT_OF_RESOURCES There are not enough resources availab= le to modify the IOMMU access. + @retval EFI_DEVICE_ERROR The IOMMU device reported an error whi= le attempting the operation. + @retval EFI_NOT_AVAILABLE_YET DMA protection has been enabled, but D= MA buffer are + not available to be allocated yet. **/ EFI_STATUS EFIAPI @@ -93,22 +93,22 @@ PeiIoMmuSetAttribute ( Provides the controller-specific addresses required to access system mem= ory from a DMA bus master. =20 - @param This The PPI instance pointer. - @param Operation Indicates if the bus master is going to re= ad or write to system memory. - @param HostAddress The system memory address to map to the PC= I controller. - @param NumberOfBytes On input the number of bytes to map. On ou= tput the number of bytes - that were mapped. - @param DeviceAddress The resulting map address for the bus mast= er PCI controller to use to - access the hosts HostAddress. - @param Mapping A resulting value to pass to Unmap(). - - @retval EFI_SUCCESS The range was mapped for the returned Numb= erOfBytes. - @retval EFI_UNSUPPORTED The HostAddress cannot be mapped as a comm= on buffer. - @retval EFI_INVALID_PARAMETER One or more parameters are invalid. - @retval EFI_OUT_OF_RESOURCES The request could not be completed due to = a lack of resources. - @retval EFI_DEVICE_ERROR The system hardware could not map the requ= ested address. - @retval EFI_NOT_AVAILABLE_YET DMA protection has been enabled, but DMA b= uffer are - not available to be allocated yet. + @param [in] This The PPI instance pointer. + @param [in] Operation Indicates if the bus master is going t= o read or write to system memory. + @param [in] HostAddress The system memory address to map to th= e PCI controller. + @param [in] [out] NumberOfBytes On input the number of bytes to map. O= n output the number of bytes + that were mapped. + @param [out] DeviceAddress The resulting map address for the bus = master PCI controller to use to + access the hosts HostAddress. + @param [out] Mapping A resulting value to pass to Unmap(). + + @retval EFI_SUCCESS The range was mapped for the returned = NumberOfBytes. + @retval EFI_UNSUPPORTED The HostAddress cannot be mapped as a = common buffer. + @retval EFI_INVALID_PARAMETER One or more parameters are invalid. + @retval EFI_OUT_OF_RESOURCES The request could not be completed due= to a lack of resources. + @retval EFI_DEVICE_ERROR The system hardware could not map the = requested address. + @retval EFI_NOT_AVAILABLE_YET DMA protection has been enabled, but D= MA buffer are + not available to be allocated yet. **/ EFI_STATUS EFIAPI @@ -140,7 +140,7 @@ PeiIoMmuMap ( =20 if (Operation =3D=3D EdkiiIoMmuOperationBusMasterCommonBuffer || Operation =3D=3D EdkiiIoMmuOperationBusMasterCommonBuffer64) { - *DeviceAddress =3D (UINTN)HostAddress; + *DeviceAddress =3D (UINTN) HostAddress; *Mapping =3D NULL; return EFI_SUCCESS; } @@ -184,14 +184,14 @@ PeiIoMmuMap ( /** Completes the Map() operation and releases any corresponding resources. =20 - @param This The PPI instance pointer. - @param Mapping The mapping value returned from Map(). + @param [in] This The PPI instance pointer. + @param [in] Mapping The mapping value returned from Map(). =20 - @retval EFI_SUCCESS The range was unmapped. - @retval EFI_INVALID_PARAMETER Mapping is not a value that was returned b= y Map(). - @retval EFI_DEVICE_ERROR The data was not committed to the target s= ystem memory. - @retval EFI_NOT_AVAILABLE_YET DMA protection has been enabled, but DMA b= uffer are - not available to be allocated yet. + @retval EFI_SUCCESS The range was unmapped. + @retval EFI_INVALID_PARAMETER Mapping is not a value that was return= ed by Map(). + @retval EFI_DEVICE_ERROR The data was not committed to the targ= et system memory. + @retval EFI_NOT_AVAILABLE_YET DMA protection has been enabled, but D= MA buffer are + not available to be allocated yet. **/ EFI_STATUS EFIAPI @@ -250,21 +250,21 @@ PeiIoMmuUnmap ( Allocates pages that are suitable for an OperationBusMasterCommonBuffer = or OperationBusMasterCommonBuffer64 mapping. =20 - @param This The PPI instance pointer. - @param MemoryType The type of memory to allocate, EfiBootSer= vicesData or - EfiRuntimeServicesData. - @param Pages The number of pages to allocate. - @param HostAddress A pointer to store the base system memory = address of the - allocated range. - @param Attributes The requested bit mask of attributes for t= he allocated range. - - @retval EFI_SUCCESS The requested memory pages were allocated. - @retval EFI_UNSUPPORTED Attributes is unsupported. The only legal = attribute bits are - MEMORY_WRITE_COMBINE, MEMORY_CACHED and DU= AL_ADDRESS_CYCLE. - @retval EFI_INVALID_PARAMETER One or more parameters are invalid. - @retval EFI_OUT_OF_RESOURCES The memory pages could not be allocated. - @retval EFI_NOT_AVAILABLE_YET DMA protection has been enabled, but DMA b= uffer are - not available to be allocated yet. + @param [in] This The PPI instance pointer. + @param [in] MemoryType The type of memory to allocate, EfiBoo= tServicesData or + EfiRuntimeServicesData. + @param [in] Pages The number of pages to allocate. + @param [in] [out] HostAddress A pointer to store the base system mem= ory address of the + allocated range. + @param [in] Attributes The requested bit mask of attributes f= or the allocated range. + + @retval EFI_SUCCESS The requested memory pages were alloca= ted. + @retval EFI_UNSUPPORTED Attributes is unsupported. The only le= gal attribute bits are + MEMORY_WRITE_COMBINE, MEMORY_CACHED an= d DUAL_ADDRESS_CYCLE. + @retval EFI_INVALID_PARAMETER One or more parameters are invalid. + @retval EFI_OUT_OF_RESOURCES The memory pages could not be allocate= d. + @retval EFI_NOT_AVAILABLE_YET DMA protection has been enabled, but D= MA buffer are + not available to be allocated yet. **/ EFI_STATUS EFIAPI @@ -307,15 +307,15 @@ PeiIoMmuAllocateBuffer ( /** Frees memory that was allocated with AllocateBuffer(). =20 - @param This The PPI instance pointer. - @param Pages The number of pages to free. - @param HostAddress The base system memory address of the allo= cated range. + @param [in] This The PPI instance pointer. + @param [in] Pages The number of pages to free. + @param [in] HostAddress The base system memory address of the = allocated range. =20 - @retval EFI_SUCCESS The requested memory pages were freed. - @retval EFI_INVALID_PARAMETER The memory range specified by HostAddress = and Pages - was not allocated with AllocateBuffer(). - @retval EFI_NOT_AVAILABLE_YET DMA protection has been enabled, but DMA b= uffer are - not available to be allocated yet. + @retval EFI_SUCCESS The requested memory pages were freed. + @retval EFI_INVALID_PARAMETER The memory range specified by HostAddr= ess and Pages + was not allocated with AllocateBuffer(= ). + @retval EFI_NOT_AVAILABLE_YET DMA protection has been enabled, but D= MA buffer are + not available to be allocated yet. **/ EFI_STATUS EFIAPI @@ -364,52 +364,114 @@ CONST EFI_PEI_PPI_DESCRIPTOR mIoMmuPpiList =3D { }; =20 /** - Release the momery in the Intel VTd Info + Get ACPI DMAT Table from EdkiiVTdInfo PPI =20 - @param[in] VTdInfo The VTd engine context information. + @retval Address ACPI DMAT Table address + @retval NULL Failed to get ACPI DMAT Table **/ -VOID -ReleaseVTdInfo ( - IN VTD_INFO *VTdInfo +EFI_ACPI_DMAR_HEADER * GetAcpiDmarTable ( + VOID ) { - UINTN Index; + EFI_STATUS Status; + EFI_ACPI_DMAR_HEADER *AcpiDmarTable; =20 - for (Index =3D 0; Index < VTdInfo->VTdEngineCount; Index++) { - DEBUG ((DEBUG_INFO, "Release momery in VTdInfo[%d]\n", Index)); + // + // Get the DMAR table + // + Status =3D PeiServicesLocatePpi ( + &gEdkiiVTdInfoPpiGuid, + 0, + NULL, + (VOID **)&AcpiDmarTable + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "Fail to get ACPI DMAR Table : %r\n", Status)); + AcpiDmarTable =3D NULL; + } else { + DumpAcpiDMAR (AcpiDmarTable); + } =20 - if (VTdInfo->VtdUnitInfo[Index].FixedSecondLevelPagingEntry) { - FreePages ((VOID *) (UINTN) VTdInfo->VtdUnitInfo[Index].FixedSecondL= evelPagingEntry, 1); - VTdInfo->VtdUnitInfo[Index].FixedSecondLevelPagingEntry =3D 0; - } + return AcpiDmarTable; +} =20 - if (VTdInfo->VtdUnitInfo[Index].RmrrSecondLevelPagingEntry) { - FreePages ((VOID *) (UINTN) VTdInfo->VtdUnitInfo[Index].RmrrSecondLe= velPagingEntry, 1); - VTdInfo->VtdUnitInfo[Index].RmrrSecondLevelPagingEntry =3D 0; - } +/** + Get the VTd engine context information hob. =20 - if (VTdInfo->VtdUnitInfo[Index].RootEntryTable) { - FreePages ((VOID *) (UINTN) VTdInfo->VtdUnitInfo[Index].RootEntryTab= le, VTdInfo->VtdUnitInfo[Index].RootEntryTablePageSize); - VTdInfo->VtdUnitInfo[Index].RootEntryTable =3D 0; - } + @retval The VTd engine context information. =20 - if (VTdInfo->VtdUnitInfo[Index].ExtRootEntryTable) { - FreePages ((VOID *) (UINTN) VTdInfo->VtdUnitInfo[Index].ExtRootEntry= Table, VTdInfo->VtdUnitInfo[Index].ExtRootEntryTablePageSize); - VTdInfo->VtdUnitInfo[Index].RootEntryTable =3D 0; - } +**/ +VTD_INFO * +GetVTdInfoHob ( + VOID + ) +{ + VOID *Hob; + VTD_INFO *VTdInfo; =20 - if (VTdInfo->VtdUnitInfo[Index].PciDeviceInfo.PciDeviceData) { - FreePages ((VOID *) (UINTN) VTdInfo->VtdUnitInfo[Index].PciDeviceInf= o.PciDeviceData, VTdInfo->VtdUnitInfo[Index].PciDeviceInfo.PciDeviceDataPag= eSize); - VTdInfo->VtdUnitInfo[Index].PciDeviceInfo.PciDeviceDataPageSize =3D = 0; - VTdInfo->VtdUnitInfo[Index].PciDeviceInfo.PciDeviceData =3D 0; - VTdInfo->VtdUnitInfo[Index].PciDeviceInfo.PciDeviceDataNumber =3D 0; - VTdInfo->VtdUnitInfo[Index].PciDeviceInfo.PciDeviceDataMaxNumber =3D= 0; + Hob =3D GetFirstGuidHob (&mVTdInfoGuid); + if (Hob =3D=3D NULL) { + VTdInfo =3D BuildGuidHob (&mVTdInfoGuid, sizeof (VTD_INFO)); + if (VTdInfo !=3D NULL) { + ZeroMem (VTdInfo, sizeof (VTD_INFO)); } + } else { + VTdInfo =3D GET_GUID_HOB_DATA(Hob); } + return VTdInfo; +} + +/** + Callback function of parse DMAR DRHD table in pre-memory phase. + + @param [in] [out] Context Callback function context. + @param [in] VTdIndex The VTd engine index. + @param [in] DmarDrhd The DRHD table. + +**/ +VOID +ProcessDhrdPreMemory ( + IN OUT VOID *Context, + IN UINT32 VTdIndex, + IN EFI_ACPI_DMAR_DRHD_HEADER *DmarDrhd + ) +{ + DEBUG ((DEBUG_INFO,"VTD (%d) BaseAddress - 0x%016lx\n", VTdIndex, DmarD= rhd->RegisterBaseAddress)); + + EnableVTdTranslationProtectionBlockDma ((UINTN) DmarDrhd->RegisterBaseAd= dress); } =20 /** - Initializes the Intel VTd Info. + Callback function of parse DMAR DRHD table in post memory phase. + + @param [in] [out] Context Callback function context. + @param [in] VTdIndex The VTd engine index. + @param [in] DmarDrhd The DRHD table. + +**/ +VOID +ProcessDrhdPostMemory ( + IN OUT VOID *Context, + IN UINT32 VTdIndex, + IN EFI_ACPI_DMAR_DRHD_HEADER *DmarDrhd + ) +{ + VTD_UNIT_INFO *VtdUnitInfo; + + VtdUnitInfo =3D (VTD_UNIT_INFO *) Context; + VtdUnitInfo +=3D VTdIndex; + + VtdUnitInfo->Done =3D FALSE; + VtdUnitInfo->VtdUnitBaseAddress =3D (UINTN) DmarDrhd->RegisterBaseAddres= s; + VtdUnitInfo->Segment =3D DmarDrhd->SegmentNumber; + VtdUnitInfo->Flags =3D DmarDrhd->Flags; + + DEBUG ((DEBUG_INFO,"VTD (%d) BaseAddress - 0x%016lx\n", VTdIndex, DmarD= rhd->RegisterBaseAddress)); + DEBUG ((DEBUG_INFO," Segment - %d, Flags - 0x%x\n", DmarDrhd->Segment= Number, DmarDrhd->Flags)); +} + +/** + Initializes the Intel VTd Info in post memory phase. =20 @retval EFI_SUCCESS Usb bot driver is successfully initialized= . @retval EFI_OUT_OF_RESOURCES Can't initialize the driver. @@ -419,89 +481,103 @@ InitVTdInfo ( VOID ) { - EFI_STATUS Status; - EFI_ACPI_DMAR_HEADER *AcpiDmarTable; - VOID *Hob; VTD_INFO *VTdInfo; - UINT64 EngineMask; + EFI_ACPI_DMAR_HEADER *AcpiDmarTable; + UINTN VtdUnitNumber; + VTD_UNIT_INFO *VtdUnitInfo; + EFI_STATUS Status; + UINTN NewUnitIndex; + UINTN PreviousUnitIndex; =20 - Status =3D PeiServicesLocatePpi ( - &gEdkiiVTdInfoPpiGuid, - 0, - NULL, - (VOID **)&AcpiDmarTable - ); - ASSERT_EFI_ERROR (Status); + VTdInfo =3D GetVTdInfoHob (); + ASSERT (VTdInfo !=3D NULL); =20 - DumpAcpiDMAR (AcpiDmarTable); + AcpiDmarTable =3D GetAcpiDmarTable (); + ASSERT (AcpiDmarTable !=3D NULL); =20 // - // Clear old VTdInfo Hob. + // Get VTd Unit Number // - Hob =3D GetFirstGuidHob (&mVTdInfoGuid); - if (Hob !=3D NULL) { - DEBUG ((DEBUG_INFO, " Find Hob : mVTdInfoGuid - 0x%x\n", Hob)); - - VTdInfo =3D GET_GUID_HOB_DATA(Hob); - EngineMask =3D LShiftU64 (1, VTdInfo->VTdEngineCount) - 1; - EnableVTdTranslationProtectionAll (VTdInfo, EngineMask); - - ReleaseVTdInfo (VTdInfo); - VTdInfo->VTdEngineCount =3D 0; + VtdUnitNumber =3D ParseDmarAcpiTableDrhd (AcpiDmarTable, NULL, NULL); + if (VtdUnitNumber =3D=3D 0) { + return EFI_UNSUPPORTED; + } =20 - ZeroMem (&((EFI_HOB_GUID_TYPE *) Hob)->Name, sizeof (EFI_GUID)); + // + // Genrate a new Vtd Unit Info Table + // + VtdUnitInfo =3D AllocateZeroPages (EFI_SIZE_TO_PAGES (sizeof (VTD_UNIT_I= NFO) * VtdUnitNumber)); + if (VtdUnitInfo =3D=3D NULL) { + DEBUG ((DEBUG_ERROR, "InitVTdInfo - OUT_OF_RESOURCE\n")); + ASSERT (FALSE); + return EFI_OUT_OF_RESOURCES; } =20 // - // Get DMAR information to local VTdInfo + // Parse the DMAR ACPI Table to the new Vtd Unit Info Table // - Status =3D ParseDmarAcpiTableDrhd (AcpiDmarTable); - if (EFI_ERROR(Status)) { - DEBUG ((DEBUG_ERROR, " ParseDmarAcpiTableDrhd : %r\n", Status)); + Status =3D ParseDmarAcpiTableDrhd (AcpiDmarTable, ProcessDrhdPostMemory,= VtdUnitInfo); + if (EFI_ERROR (Status)) { + ASSERT_EFI_ERROR (Status); return Status; } =20 // - // NOTE: Do not parse RMRR here, because RMRR may cause DMAR programming= . + // Check Host Address Width // + if (AcpiDmarTable->HostAddressWidth =3D=3D VTdInfo->HostAddressWidth) { + // + // New Vtd Unit Info Table Loop + // + for (NewUnitIndex =3D 0; NewUnitIndex < VtdUnitNumber; NewUnitIndex++)= { + // + // Previous Vtd Unit Info Table Loop + // + for (PreviousUnitIndex =3D 0; PreviousUnitIndex < VTdInfo->VTdEngine= Count; PreviousUnitIndex++) { + // + // Compare the new Vtd Unit with the previous VTd Unit + // + if (VtdUnitInfo[NewUnitIndex].VtdUnitBaseAddress =3D=3D VTdInfo->V= tdUnitInfo[PreviousUnitIndex].VtdUnitBaseAddress) { + DEBUG ((DEBUG_INFO,"Find VTD [0x%08x] Exist\n", VtdUnitInfo[NewU= nitIndex].VtdUnitBaseAddress)); + CopyMem (&VtdUnitInfo[NewUnitIndex], &VTdInfo->VtdUnitInfo[Previ= ousUnitIndex], sizeof (VTD_UNIT_INFO)); + VtdUnitInfo[NewUnitIndex].Done =3D TRUE; + + break; + } + } + } + } + VTdInfo->AcpiDmarTable =3D AcpiDmarTable; + VTdInfo->HostAddressWidth =3D AcpiDmarTable->HostAddressWidth; + VTdInfo->VTdEngineCount =3D VtdUnitNumber; + VTdInfo->VtdUnitInfo =3D VtdUnitInfo; =20 return EFI_SUCCESS; } =20 /** - Initializes the Intel VTd DMAR for all memory. + Initializes the Intel VTd DMAR for block all DMA. =20 @retval EFI_SUCCESS Driver is successfully initialized. @retval RETURN_NOT_READY Fail to get VTdInfo Hob . **/ EFI_STATUS -InitVTdDmarForAll ( +InitVTdDmarBlockAll ( VOID ) { - VOID *Hob; - VTD_INFO *VTdInfo; - UINT64 EngineMask; - EFI_STATUS Status; + EFI_ACPI_DMAR_HEADER *AcpiDmarTable; =20 - Hob =3D GetFirstGuidHob (&mVTdInfoGuid); - if (Hob =3D=3D NULL) { - DEBUG ((DEBUG_ERROR, "Fail to get VTdInfo Hob.\n")); - return RETURN_NOT_READY; - } - VTdInfo =3D GET_GUID_HOB_DATA (Hob); - EngineMask =3D LShiftU64 (1, VTdInfo->VTdEngineCount) - 1; - - DEBUG ((DEBUG_INFO, "PrepareVtdConfig\n")); - Status =3D PrepareVtdConfig (VTdInfo); - if (EFI_ERROR (Status)) { - ASSERT_EFI_ERROR (Status); - return Status; - } - - EnableVTdTranslationProtectionAll (VTdInfo, EngineMask); + // + // Get the DMAR table + // + AcpiDmarTable =3D GetAcpiDmarTable (); + ASSERT (AcpiDmarTable !=3D NULL); =20 - return EFI_SUCCESS; + // + // Parse the DMAR table and block all DMA + // + return ParseDmarAcpiTableDrhd (AcpiDmarTable, ProcessDhrdPreMemory, NULL= ); } =20 /** @@ -524,8 +600,8 @@ InitDmaBuffer( DEBUG ((DEBUG_INFO, "InitDmaBuffer :\n")); =20 Hob =3D GetFirstGuidHob (&mDmaBufferInfoGuid); + ASSERT(Hob !=3D NULL); DmaBufferInfo =3D GET_GUID_HOB_DATA (Hob); - VtdPmrHobPtr =3D GetFirstGuidHob (&gVtdPmrInfoDataHobGuid); =20 /** When gVtdPmrInfoDataHobGuid exists, it means: @@ -535,7 +611,7 @@ InitDmaBuffer( 4. Protection regions will be conveyed through VTD_PMR_INFO_HOB =20 When gVtdPmrInfoDataHobGuid dosen't exist, it means: - 1. IntelVTdDmar driver will calcuate the PMR memory alignment + 1. IntelVTdDmarPei driver will calcuate the protected memory alignment 2. Dma buffer is reserved by AllocateAlignedPages() **/ =20 @@ -545,33 +621,40 @@ InitDmaBuffer( return EFI_INVALID_PARAMETER; } =20 - if (VtdPmrHobPtr =3D=3D NULL) { - // - // Allocate memory for DMA buffer - // - DmaBufferInfo->DmaBufferBase =3D (UINT64) (UINTN) AllocateAlignedPages= (EFI_SIZE_TO_PAGES ((UINTN) DmaBufferInfo->DmaBufferSize), 0); - if (DmaBufferInfo->DmaBufferBase =3D=3D 0) { - DEBUG ((DEBUG_ERROR, " InitDmaBuffer : OutOfResource\n")); - return EFI_OUT_OF_RESOURCES; + if (DmaBufferInfo->DmaBufferBase =3D=3D 0) { + VtdPmrHobPtr =3D GetFirstGuidHob (&gVtdPmrInfoDataHobGuid); + if (VtdPmrHobPtr !=3D NULL) { + // + // Get the protected memory ranges information from the VTd PMR hob + // + VtdPmrHob =3D GET_GUID_HOB_DATA (VtdPmrHobPtr); + + if ((VtdPmrHob->ProtectedHighBase - VtdPmrHob->ProtectedLowLimit) < = DmaBufferInfo->DmaBufferSize) { + DEBUG ((DEBUG_ERROR, " DmaBufferSize not enough\n")); + return EFI_INVALID_PARAMETER; + } + DmaBufferInfo->DmaBufferBase =3D VtdPmrHob->ProtectedLowLimit; + } else { + // + // Allocate memory for DMA buffer + // + DmaBufferInfo->DmaBufferBase =3D (UINTN) AllocateAlignedPages (EFI_S= IZE_TO_PAGES (DmaBufferInfo->DmaBufferSize), 0); + if (DmaBufferInfo->DmaBufferBase =3D=3D 0) { + DEBUG ((DEBUG_ERROR, " InitDmaBuffer : OutOfResource\n")); + return EFI_OUT_OF_RESOURCES; + } + DEBUG ((DEBUG_INFO, "Alloc DMA buffer success.\n")); } - DmaBufferInfo->DmaBufferLimit =3D DmaBufferInfo->DmaBufferBase + DmaBu= fferInfo->DmaBufferSize; - DEBUG ((DEBUG_INFO, "Alloc DMA buffer success.\n")); - } else { - // - // Get the PMR ranges information for the VTd PMR hob - // - VtdPmrHob =3D GET_GUID_HOB_DATA (VtdPmrHobPtr); - DmaBufferInfo->DmaBufferBase =3D VtdPmrHob->ProtectedLowLimit; - DmaBufferInfo->DmaBufferLimit =3D VtdPmrHob->ProtectedHighBase; + + DmaBufferInfo->DmaBufferCurrentTop =3D DmaBufferInfo->DmaBufferBase + = DmaBufferInfo->DmaBufferSize; + DmaBufferInfo->DmaBufferCurrentBottom =3D DmaBufferInfo->DmaBufferBase= ; + + DEBUG ((DEBUG_INFO, " DmaBufferSize : 0x%x\n", DmaBufferInfo-= >DmaBufferSize)); + DEBUG ((DEBUG_INFO, " DmaBufferBase : 0x%x\n", DmaBufferInfo-= >DmaBufferBase)); } - DmaBufferInfo->DmaBufferCurrentTop =3D DmaBufferInfo->DmaBufferBase + Dm= aBufferInfo->DmaBufferSize; - DmaBufferInfo->DmaBufferCurrentBottom =3D DmaBufferInfo->DmaBufferBase; =20 - DEBUG ((DEBUG_INFO, " DmaBufferSize : 0x%lx\n", DmaBufferInfo->= DmaBufferSize)); - DEBUG ((DEBUG_INFO, " DmaBufferBase : 0x%lx\n", DmaBufferInfo->= DmaBufferBase)); - DEBUG ((DEBUG_INFO, " DmaBufferLimit : 0x%lx\n", DmaBufferInfo->= DmaBufferLimit)); - DEBUG ((DEBUG_INFO, " DmaBufferCurrentTop : 0x%lx\n", DmaBufferInfo->= DmaBufferCurrentTop)); - DEBUG ((DEBUG_INFO, " DmaBufferCurrentBottom : 0x%lx\n", DmaBufferInfo->= DmaBufferCurrentBottom)); + DEBUG ((DEBUG_INFO, " DmaBufferCurrentTop : 0x%x\n", DmaBufferInfo->D= maBufferCurrentTop)); + DEBUG ((DEBUG_INFO, " DmaBufferCurrentBottom : 0x%x\n", DmaBufferInfo->D= maBufferCurrentBottom)); =20 return EFI_SUCCESS; } @@ -588,14 +671,14 @@ InitVTdDmarForDma ( VOID ) { - VOID *Hob; VTD_INFO *VTdInfo; + EFI_STATUS Status; EFI_PEI_PPI_DESCRIPTOR *OldDescriptor; EDKII_IOMMU_PPI *OldIoMmuPpi; =20 - Hob =3D GetFirstGuidHob (&mVTdInfoGuid); - VTdInfo =3D GET_GUID_HOB_DATA (Hob); + VTdInfo =3D GetVTdInfoHob (); + ASSERT (VTdInfo !=3D NULL); =20 DEBUG ((DEBUG_INFO, "PrepareVtdConfig\n")); Status =3D PrepareVtdConfig (VTdInfo); @@ -604,13 +687,6 @@ InitVTdDmarForDma ( return Status; } =20 - DEBUG ((DEBUG_INFO, "PrepareVtdCacheInvalidationConfig\n")); - Status =3D PrepareVtdCacheInvalidationConfig (VTdInfo); - if (EFI_ERROR (Status)) { - ASSERT_EFI_ERROR (Status); - return Status; - } - // create root entry table DEBUG ((DEBUG_INFO, "SetupTranslationTable\n")); Status =3D SetupTranslationTable (VTdInfo); @@ -619,10 +695,6 @@ InitVTdDmarForDma ( return Status; } =20 - // If there is RMRR memory, parse it here. - DEBUG ((DEBUG_INFO, "PeiParseDmarAcpiTableRmrr\n")); - ParseDmarAcpiTableRmrr (VTdInfo); - DEBUG ((DEBUG_INFO, "EnableVtdDmar\n")); Status =3D EnableVTdTranslationProtection(VTdInfo); if (EFI_ERROR (Status)) { @@ -668,21 +740,10 @@ S3EndOfPeiNotify( IN VOID *Ppi ) { - VOID *Hob; - VTD_INFO *VTdInfo; - UINT64 EngineMask; - DEBUG((DEBUG_INFO, "VTd DMAR PEI S3EndOfPeiNotify\n")); =20 if ((PcdGet8(PcdVTdPolicyPropertyMask) & BIT1) =3D=3D 0) { - Hob =3D GetFirstGuidHob (&mVTdInfoGuid); - if (Hob =3D=3D NULL) { - return EFI_SUCCESS; - } - VTdInfo =3D GET_GUID_HOB_DATA(Hob); - - EngineMask =3D LShiftU64 (1, VTdInfo->VTdEngineCount) - 1; - DisableVTdTranslationProtection (VTdInfo, EngineMask); + DisableVTdTranslationProtection (GetVTdInfoHob ()); } return EFI_SUCCESS; } @@ -733,18 +794,13 @@ VTdInfoNotify ( =20 DEBUG ((DEBUG_INFO, "MemoryInitialized - %x\n", MemoryInitialized)); =20 - // - // NOTE: We need reinit VTdInfo because previous information might be ov= erriden. - // - InitVTdInfo (); - if (!MemoryInitialized) { // // If the memory is not initialized, // Protect all system memory // =20 - InitVTdDmarForAll (); + InitVTdDmarBlockAll (); =20 // // Install PPI. @@ -758,9 +814,16 @@ VTdInfoNotify ( // =20 Status =3D InitDmaBuffer (); - ASSERT_EFI_ERROR(Status); + ASSERT_EFI_ERROR (Status); + + // + // NOTE: We need reinit VTdInfo because previous information might be = overriden. + // + Status =3D InitVTdInfo (); + ASSERT_EFI_ERROR (Status); =20 - InitVTdDmarForDma (); + Status =3D InitVTdDmarForDma (); + ASSERT_EFI_ERROR (Status); } =20 return EFI_SUCCESS; @@ -826,4 +889,3 @@ IntelVTdDmarInitialize ( =20 return EFI_SUCCESS; } - diff --git a/Silicon/Intel/IntelSiliconPkg/Feature/VTd/IntelVTdDmarPei/Inte= lVTdDmarPei.h b/Silicon/Intel/IntelSiliconPkg/Feature/VTd/IntelVTdDmarPei/I= ntelVTdDmarPei.h index e23a6c8e..351a7810 100644 --- a/Silicon/Intel/IntelSiliconPkg/Feature/VTd/IntelVTdDmarPei/IntelVTdDma= rPei.h +++ b/Silicon/Intel/IntelSiliconPkg/Feature/VTd/IntelVTdDmarPei/IntelVTdDma= rPei.h @@ -9,68 +9,61 @@ #ifndef __DMA_ACCESS_LIB_H__ #define __DMA_ACCESS_LIB_H__ =20 -#define MAX_VTD_PCI_DATA_NUMBER 0x100 - #define VTD_64BITS_ADDRESS(Lo, Hi) (LShiftU64 (Lo, 12) | LShiftU64 (Hi, 32= )) =20 typedef struct { - UINT8 DeviceType; - VTD_SOURCE_ID PciSourceId; -} PEI_PCI_DEVICE_DATA; - -typedef struct { - BOOLEAN IncludeAllFlag; - UINT32 PciDeviceDataNumber; - UINT32 PciDeviceDataMaxNumber; - UINT32 PciDeviceDataPageSize; - UINT32 PciDeviceData; -} PEI_PCI_DEVICE_INFORMATION; - -typedef struct { - UINT32 VtdUnitBaseAddress; + BOOLEAN Done; + UINTN VtdUnitBaseAddress; UINT16 Segment; + UINT8 Flags; VTD_VER_REG VerReg; VTD_CAP_REG CapReg; VTD_ECAP_REG ECapReg; BOOLEAN Is5LevelPaging; - UINT32 FixedSecondLevelPagingEntry; - UINT32 RmrrSecondLevelPagingEntry; - UINT32 RootEntryTable; - UINT32 ExtRootEntryTable; - UINT16 RootEntryTablePageSize; - UINT16 ExtRootEntryTablePageSize; - PEI_PCI_DEVICE_INFORMATION PciDeviceInfo; UINT8 EnableQueuedInvalidation; - UINT16 QiDescLength; + UINT16 QueueSize; QI_DESC *QiDesc; UINT16 QiFreeHead; + UINTN FixedSecondLevelPagingEntry; + UINTN RootEntryTable; + UINTN ExtRootEntryTable; + UINTN RootEntryTablePageSize; + UINTN ExtRootEntryTablePageSize; } VTD_UNIT_INFO; =20 typedef struct { - UINT32 AcpiDmarTable; + EFI_ACPI_DMAR_HEADER *AcpiDmarTable; UINT8 HostAddressWidth; - UINT32 VTdEngineCount; - VTD_UNIT_INFO VtdUnitInfo[1]; + UINTN VTdEngineCount; + VTD_UNIT_INFO *VtdUnitInfo; } VTD_INFO; =20 typedef struct { - UINT64 DmaBufferBase; - UINT64 DmaBufferSize; - UINT64 DmaBufferLimit; - UINT64 DmaBufferCurrentTop; - UINT64 DmaBufferCurrentBottom; + UINTN DmaBufferBase; + UINTN DmaBufferSize; + UINTN DmaBufferCurrentTop; + UINTN DmaBufferCurrentBottom; } DMA_BUFFER_INFO; =20 +typedef +VOID +(*PROCESS_DRHD_CALLBACK_FUNC) ( + IN OUT VOID *Context, + IN UINT32 VTdIndex, + IN EFI_ACPI_DMAR_DRHD_HEADER *DmarDrhd + ); + /** - Enable VTd translation table protection. + Enable VTd translation table protection for block DMA =20 - @param[in] VTdInfo The VTd engine context information. - @param[in] EngineMask The mask of the VTd engine to be accessed. + @param[in] VtdUnitBaseAddress The base address of the VTd engine. + + @retval EFI_SUCCESS DMAR translation is enabled. + @retval EFI_DEVICE_ERROR DMAR translation is not enabled. **/ -VOID -EnableVTdTranslationProtectionAll ( - IN VTD_INFO *VTdInfo, - IN UINT64 EngineMask +EFI_STATUS +EnableVTdTranslationProtectionBlockDma ( + IN UINTN VtdUnitBaseAddress ); =20 /** @@ -90,34 +83,27 @@ EnableVTdTranslationProtection ( Disable VTd translation table protection. =20 @param[in] VTdInfo The VTd engine context information. - @param[in] EngineMask The mask of the VTd engine to be accessed. **/ VOID DisableVTdTranslationProtection ( - IN VTD_INFO *VTdInfo, - IN UINT64 EngineMask + IN VTD_INFO *VTdInfo ); =20 /** Parse DMAR DRHD table. =20 @param[in] AcpiDmarTable DMAR ACPI table + @param[in] Callback Callback function for handle DRHD + @param[in] Context Callback function Context =20 - @return EFI_SUCCESS The DMAR DRHD table is parsed. -**/ -EFI_STATUS -ParseDmarAcpiTableDrhd ( - IN EFI_ACPI_DMAR_HEADER *AcpiDmarTable - ); - -/** - Parse DMAR DRHD table. + @return the VTd engine number. =20 - @param[in] VTdInfo The VTd engine context information. **/ -VOID -ParseDmarAcpiTableRmrr ( - IN VTD_INFO *VTdInfo +UINTN +ParseDmarAcpiTableDrhd ( + IN EFI_ACPI_DMAR_HEADER *AcpiDmarTable, + IN PROCESS_DRHD_CALLBACK_FUNC Callback, + IN VOID *Context ); =20 /** @@ -214,30 +200,7 @@ GetPciDataIndex ( IN VTD_SOURCE_ID SourceId ); =20 -/** - Always enable the VTd page attribute for the device. - - @param[in] VTdInfo The VTd engine context information. - @param[in] Segment The Segment used to identify a VTd engine. - @param[in] SourceId The SourceId used to identify a VTd engine= and table entry. - @param[in] MemoryBase The base of the memory. - @param[in] MemoryLimit The limit of the memory. - @param[in] IoMmuAccess The IOMMU access. - - @retval EFI_SUCCESS The VTd entry is updated to always enable = all DMA access for the specific device. -**/ -EFI_STATUS -EnableRmrrPageAttribute ( - IN VTD_INFO *VTdInfo, - IN UINT16 Segment, - IN VTD_SOURCE_ID SourceId, - IN UINT64 MemoryBase, - IN UINT64 MemoryLimit, - IN UINT64 IoMmuAccess - ); - extern EFI_GUID mVTdInfoGuid; extern EFI_GUID mDmaBufferInfoGuid; =20 #endif - diff --git a/Silicon/Intel/IntelSiliconPkg/Feature/VTd/IntelVTdDmarPei/Tran= slationTable.c b/Silicon/Intel/IntelSiliconPkg/Feature/VTd/IntelVTdDmarPei/= TranslationTable.c index a309d566..c94f4a85 100644 --- a/Silicon/Intel/IntelSiliconPkg/Feature/VTd/IntelVTdDmarPei/Translation= Table.c +++ b/Silicon/Intel/IntelSiliconPkg/Feature/VTd/IntelVTdDmarPei/Translation= Table.c @@ -1,6 +1,7 @@ /** @file =20 Copyright (c) 2020 - 2021, Intel Corporation. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent =20 **/ @@ -129,12 +130,12 @@ CreateSecondLevelPagingEntryTable ( FlushPageTableMemory (VTdUnitInfo, (UINTN) SecondLevelPagingEntry, EFI= _PAGES_TO_SIZE (1)); } =20 - DEBUG ((DEBUG_INFO, " SecondLevelPagingEntry:0x%016lx\n", SecondLevelPag= ingEntry)); + DEBUG ((DEBUG_INFO, " SecondLevelPagingEntry:0x%016lx\n", (UINT64) (UINT= N) SecondLevelPagingEntry)); // // If no access is needed, just create not present entry. // if (IoMmuAccess =3D=3D 0) { - DEBUG ((DEBUG_INFO, " SecondLevelPagingEntry:0x%016lx\n", (UINTN) Seco= ndLevelPagingEntry)); + DEBUG ((DEBUG_INFO, " SecondLevelPagingEntry:0x%016lx Access 0\n", (UI= NT64) (UINTN) SecondLevelPagingEntry)); return SecondLevelPagingEntry; } =20 @@ -244,7 +245,7 @@ CreateSecondLevelPagingEntryTable ( } FlushPageTableMemory (VTdUnitInfo, (UINTN) &Lvl5PtEntry[Lvl5Start], (UIN= TN) &Lvl5PtEntry[Lvl5End + 1] - (UINTN) &Lvl5PtEntry[Lvl5Start]); =20 - DEBUG ((DEBUG_INFO, " SecondLevelPagingEntry:0x%016lx\n", (UINTN)SecondL= evelPagingEntry)); + DEBUG ((DEBUG_INFO, " SecondLevelPagingEntry:0x%016lx\n", (UINT64) (UINT= N) SecondLevelPagingEntry)); return SecondLevelPagingEntry; } =20 @@ -276,6 +277,10 @@ CreateContextEntry ( VTD_SECOND_LEVEL_PAGING_ENTRY *SecondLevelPagingEntry; UINT64 Pt; =20 + if (VTdUnitInfo->RootEntryTable !=3D 0) { + return EFI_SUCCESS; + } + RootPages =3D EFI_SIZE_TO_PAGES (sizeof (VTD_ROOT_ENTRY) * VTD_ROOT_ENTR= Y_NUMBER); ContextPages =3D EFI_SIZE_TO_PAGES (sizeof (VTD_CONTEXT_ENTRY) * VTD_CON= TEXT_ENTRY_NUMBER); EntryTablePages =3D RootPages + ContextPages * (VTD_ROOT_ENTRY_NUMBER); @@ -286,8 +291,8 @@ CreateContextEntry ( } =20 DEBUG ((DEBUG_ERROR, "RootEntryTable address - 0x%x\n", Buffer)); - VTdUnitInfo->RootEntryTable =3D (UINT32) (UINTN) Buffer; - VTdUnitInfo->RootEntryTablePageSize =3D (UINT16) EntryTablePages; + VTdUnitInfo->RootEntryTable =3D (UINTN) Buffer; + VTdUnitInfo->RootEntryTablePageSize =3D EntryTablePages; RootEntryBase =3D (VTD_ROOT_ENTRY *) Buffer; Buffer =3D (UINT8 *) Buffer + EFI_PAGES_TO_SIZE (RootPages); =20 @@ -304,7 +309,7 @@ CreateContextEntry ( RootEntry->Bits.ContextTablePointerHi =3D (UINT32) RShiftU64 ((UINT64= ) (UINTN) Buffer, 32); RootEntry->Bits.Present =3D 1; Buffer =3D (UINT8 *)Buffer + EFI_PAGES_TO_SIZE (ContextPages); - ContextEntryTable =3D (VTD_CONTEXT_ENTRY *) (UINTN) VTD_64BITS_ADDRESS= (RootEntry->Bits.ContextTablePointerLo, RootEntry->Bits.ContextTablePointer= Hi) ; + ContextEntryTable =3D (VTD_CONTEXT_ENTRY *) (UINTN) VTD_64BITS_ADDRESS= (RootEntry->Bits.ContextTablePointerLo, RootEntry->Bits.ContextTablePointer= Hi); =20 for (ContextIndex =3D 0; ContextIndex < VTD_CONTEXT_ENTRY_NUMBER; Cont= extIndex++) { SourceId.Index.ContextIndex =3D (UINT8) ContextIndex; @@ -317,7 +322,7 @@ CreateContextEntry ( ContextEntry->Bits.AddressWidth =3D VTdUnitInfo->Is5LevelPaging ? 0x= 3 : 0x2; =20 if (VTdUnitInfo->FixedSecondLevelPagingEntry !=3D 0) { - SecondLevelPagingEntry =3D (VTD_SECOND_LEVEL_PAGING_ENTRY *) (UINT= N) VTdUnitInfo->FixedSecondLevelPagingEntry; + SecondLevelPagingEntry =3D (VTD_SECOND_LEVEL_PAGING_ENTRY *) VTdUn= itInfo->FixedSecondLevelPagingEntry; Pt =3D (UINT64)RShiftU64 ((UINT64) (UINTN) SecondLevelPagingEntry,= 12); ContextEntry->Bits.SecondLevelPageTranslationPointerLo =3D (UINT32= ) Pt; ContextEntry->Bits.SecondLevelPageTranslationPointerHi =3D (UINT32= ) RShiftU64(Pt, 20); @@ -359,6 +364,10 @@ CreateExtContextEntry ( VTD_SECOND_LEVEL_PAGING_ENTRY *SecondLevelPagingEntry; UINT64 Pt; =20 + if (VTdUnitInfo->ExtRootEntryTable !=3D 0) { + return EFI_SUCCESS; + } + RootPages =3D EFI_SIZE_TO_PAGES (sizeof (VTD_EXT_ROOT_ENTRY) * VTD_ROOT_= ENTRY_NUMBER); ContextPages =3D EFI_SIZE_TO_PAGES (sizeof (VTD_EXT_CONTEXT_ENTRY) * VTD= _CONTEXT_ENTRY_NUMBER); EntryTablePages =3D RootPages + ContextPages * (VTD_ROOT_ENTRY_NUMBER); @@ -369,8 +378,8 @@ CreateExtContextEntry ( } =20 DEBUG ((DEBUG_ERROR, "ExtRootEntryTable address - 0x%x\n", Buffer)); - VTdUnitInfo->ExtRootEntryTable =3D (UINT32) (UINTN) Buffer; - VTdUnitInfo->ExtRootEntryTablePageSize =3D (UINT16) EntryTablePages; + VTdUnitInfo->ExtRootEntryTable =3D (UINTN) Buffer; + VTdUnitInfo->ExtRootEntryTablePageSize =3D EntryTablePages; ExtRootEntryBase =3D (VTD_EXT_ROOT_ENTRY *) Buffer; Buffer =3D (UINT8 *) Buffer + EFI_PAGES_TO_SIZE (RootPages); =20 @@ -390,7 +399,7 @@ CreateExtContextEntry ( ExtRootEntry->Bits.UpperContextTablePointerHi =3D (UINT32) RShiftU64 = (RShiftU64 ((UINT64) (UINTN) Buffer, 12) + 1, 20); ExtRootEntry->Bits.UpperPresent =3D 1; Buffer =3D (UINT8 *) Buffer + EFI_PAGES_TO_SIZE (ContextPages); - ExtContextEntryTable =3D (VTD_EXT_CONTEXT_ENTRY *) (UINTN) VTD_64BITS_= ADDRESS (ExtRootEntry->Bits.LowerContextTablePointerLo, ExtRootEntry->Bits.= LowerContextTablePointerHi) ; + ExtContextEntryTable =3D (VTD_EXT_CONTEXT_ENTRY *) (UINTN) VTD_64BITS_= ADDRESS (ExtRootEntry->Bits.LowerContextTablePointerLo, ExtRootEntry->Bits.= LowerContextTablePointerHi); =20 for (ContextIndex =3D 0; ContextIndex < VTD_CONTEXT_ENTRY_NUMBER; Cont= extIndex++) { SourceId.Index.ContextIndex =3D (UINT8) ContextIndex; @@ -403,7 +412,7 @@ CreateExtContextEntry ( ExtContextEntry->Bits.AddressWidth =3D VTdUnitInfo->Is5LevelPaging ?= 0x3 : 0x2; =20 if (VTdUnitInfo->FixedSecondLevelPagingEntry !=3D 0) { - SecondLevelPagingEntry =3D (VTD_SECOND_LEVEL_PAGING_ENTRY *) (UINT= N) VTdUnitInfo->FixedSecondLevelPagingEntry; + SecondLevelPagingEntry =3D (VTD_SECOND_LEVEL_PAGING_ENTRY *) VTdUn= itInfo->FixedSecondLevelPagingEntry; Pt =3D (UINT64)RShiftU64 ((UINT64) (UINTN) SecondLevelPagingEntry,= 12); =20 ExtContextEntry->Bits.SecondLevelPageTranslationPointerLo =3D (UIN= T32) Pt; @@ -791,9 +800,6 @@ SetSecondLevelPagingAttribute ( SplitAttribute =3D NeedSplitPage (BaseAddress, Length, PageAttribute); if (SplitAttribute =3D=3D PageNone) { ConvertSecondLevelPageEntryAttribute (VTdUnitInfo, PageEntry, IoMmuA= ccess, &IsEntryModified); - if (IsEntryModified) { - //mVtdUnitInformation[VtdIndex].HasDirtyPages =3D TRUE; - } // // Convert success, move to next // @@ -805,7 +811,6 @@ SetSecondLevelPagingAttribute ( DEBUG ((DEBUG_ERROR, "SplitSecondLevelPage - %r\n", Status)); return RETURN_UNSUPPORTED; } - //mVtdUnitInformation[VtdIndex].HasDirtyPages =3D TRUE; // // Just split current page // Convert success in next around @@ -837,7 +842,11 @@ CreateFixedSecondLevelPagingEntry ( VOID *Hob; DMA_BUFFER_INFO *DmaBufferInfo; =20 - VTdUnitInfo->FixedSecondLevelPagingEntry =3D (UINT32) (UINTN) CreateSeco= ndLevelPagingEntryTable (VTdUnitInfo, NULL, 0, SIZE_4GB, 0); + if (VTdUnitInfo->FixedSecondLevelPagingEntry !=3D 0) { + return EFI_SUCCESS; + } + + VTdUnitInfo->FixedSecondLevelPagingEntry =3D (UINTN) CreateSecondLevelPa= gingEntryTable (VTdUnitInfo, NULL, 0, SIZE_4GB, 0); if (VTdUnitInfo->FixedSecondLevelPagingEntry =3D=3D 0) { DEBUG ((DEBUG_ERROR, "FixedSecondLevelPagingEntry is empty\n")); return EFI_OUT_OF_RESOURCES; @@ -846,14 +855,14 @@ CreateFixedSecondLevelPagingEntry ( Hob =3D GetFirstGuidHob (&mDmaBufferInfoGuid); DmaBufferInfo =3D GET_GUID_HOB_DATA (Hob); BaseAddress =3D DmaBufferInfo->DmaBufferBase; - Length =3D DmaBufferInfo->DmaBufferLimit - DmaBufferInfo->DmaBufferBase; + Length =3D DmaBufferInfo->DmaBufferSize; IoMmuAccess =3D EDKII_IOMMU_ACCESS_READ | EDKII_IOMMU_ACCESS_WRITE; =20 DEBUG ((DEBUG_INFO, " BaseAddress =3D 0x%lx\n", BaseAddress)); DEBUG ((DEBUG_INFO, " Length =3D 0x%lx\n", Length)); DEBUG ((DEBUG_INFO, " IoMmuAccess =3D 0x%lx\n", IoMmuAccess)); =20 - Status =3D SetSecondLevelPagingAttribute (VTdUnitInfo, (VTD_SECOND_LEVEL= _PAGING_ENTRY*) (UINTN) VTdUnitInfo->FixedSecondLevelPagingEntry, BaseAddre= ss, Length, IoMmuAccess); + Status =3D SetSecondLevelPagingAttribute (VTdUnitInfo, (VTD_SECOND_LEVEL= _PAGING_ENTRY*) VTdUnitInfo->FixedSecondLevelPagingEntry, BaseAddress, Leng= th, IoMmuAccess); =20 return Status; } @@ -877,6 +886,9 @@ SetupTranslationTable ( =20 for (Index =3D 0; Index < VTdInfo->VTdEngineCount; Index++) { VtdUnitInfo =3D &VTdInfo->VtdUnitInfo[Index]; + if (VtdUnitInfo->Done) { + continue; + } =20 Status =3D CreateFixedSecondLevelPagingEntry (VtdUnitInfo); if (EFI_ERROR (Status)) { @@ -911,151 +923,3 @@ SetupTranslationTable ( return EFI_SUCCESS; } =20 -/** - Find the VTd index by the Segment and SourceId. - - @param[in] VTdInfo The VTd engine context information. - @param[in] Segment The segment of the source. - @param[in] SourceId The SourceId of the source. - @param[out] ExtContextEntry The ExtContextEntry of the source. - @param[out] ContextEntry The ContextEntry of the source. - - @return The index of the VTd engine. - @retval (UINTN)-1 The VTd engine is not found. -**/ -UINTN -FindVtdIndexBySegmentSourceId ( - IN VTD_INFO *VTdInfo, - IN UINT16 Segment, - IN VTD_SOURCE_ID SourceId, - OUT VTD_EXT_CONTEXT_ENTRY **ExtContextEntry, - OUT VTD_CONTEXT_ENTRY **ContextEntry - ) -{ - UINTN VtdIndex; - VTD_ROOT_ENTRY *RootEntryBase; - VTD_ROOT_ENTRY *RootEntry; - VTD_CONTEXT_ENTRY *ContextEntryTable; - VTD_CONTEXT_ENTRY *ThisContextEntry; - VTD_EXT_ROOT_ENTRY *ExtRootEntryBase; - VTD_EXT_ROOT_ENTRY *ExtRootEntry; - VTD_EXT_CONTEXT_ENTRY *ExtContextEntryTable; - VTD_EXT_CONTEXT_ENTRY *ThisExtContextEntry; - - for (VtdIndex =3D 0; VtdIndex < VTdInfo->VTdEngineCount; VtdIndex++) { - if (GetPciDataIndex (&VTdInfo->VtdUnitInfo[VtdIndex], Segment, SourceI= d) !=3D (UINTN)-1) { - DEBUG ((DEBUG_INFO, "Find VtdIndex(0x%x) for S%04x B%02x D%02x F%02x= \n", VtdIndex, Segment, SourceId.Bits.Bus, SourceId.Bits.Device, SourceId.B= its.Function)); - break; - } - } - if (VtdIndex >=3D VTdInfo->VTdEngineCount) { - for (VtdIndex =3D 0; VtdIndex < VTdInfo->VTdEngineCount; VtdIndex++) { - if (Segment !=3D VTdInfo->VtdUnitInfo[VtdIndex].Segment) { - continue; - } - if (VTdInfo->VtdUnitInfo[VtdIndex].PciDeviceInfo.IncludeAllFlag) { - DEBUG ((DEBUG_INFO, "Find IncludeAllFlag VtdIndex(0x%x) for S%04x = B%02x D%02x F%02x\n", VtdIndex, Segment, SourceId.Bits.Bus, SourceId.Bits.D= evice, SourceId.Bits.Function)); - break; - } - } - } - - if (VtdIndex < VTdInfo->VTdEngineCount) { - ExtRootEntryBase =3D (VTD_EXT_ROOT_ENTRY *) (UINTN) VTdInfo->VtdUnitIn= fo[VtdIndex].ExtRootEntryTable; - if (ExtRootEntryBase !=3D 0) { - ExtRootEntry =3D &ExtRootEntryBase[SourceId.Index.RootIndex]; - ExtContextEntryTable =3D (VTD_EXT_CONTEXT_ENTRY *) (UINTN) VTD_64BIT= S_ADDRESS(ExtRootEntry->Bits.LowerContextTablePointerLo, ExtRootEntry->Bits= .LowerContextTablePointerHi) ; - ThisExtContextEntry =3D &ExtContextEntryTable[SourceId.Index.Contex= tIndex]; - if (ThisExtContextEntry->Bits.AddressWidth =3D=3D 0) { - DEBUG ((DEBUG_INFO, "ExtContextEntry AddressWidth : 0x%x\n", ThisE= xtContextEntry->Bits.AddressWidth)); - return (UINTN)-1; - } - *ExtContextEntry =3D ThisExtContextEntry; - *ContextEntry =3D NULL; - } else { - RootEntryBase =3D (VTD_ROOT_ENTRY*) (UINTN) VTdInfo->VtdUnitInfo[Vtd= Index].RootEntryTable; - RootEntry =3D &RootEntryBase[SourceId.Index.RootIndex]; - ContextEntryTable =3D (VTD_CONTEXT_ENTRY *) (UINTN) VTD_64BITS_ADDRE= SS(RootEntry->Bits.ContextTablePointerLo, RootEntry->Bits.ContextTablePoint= erHi) ; - ThisContextEntry =3D &ContextEntryTable[SourceId.Index.ContextIndex= ]; - if (ThisContextEntry->Bits.AddressWidth =3D=3D 0) { - DEBUG ((DEBUG_INFO, "ContextEntry AddressWidth : 0x%x\n", ThisCont= extEntry->Bits.AddressWidth)); - return (UINTN)-1; - } - *ExtContextEntry =3D NULL; - *ContextEntry =3D ThisContextEntry; - } - - return VtdIndex; - } - - return (UINTN)-1; -} - -/** - Always enable the VTd page attribute for the device. - - @param[in] VTdInfo The VTd engine context information. - @param[in] Segment The Segment used to identify a VTd engine. - @param[in] SourceId The SourceId used to identify a VTd engine= and table entry. - @param[in] MemoryBase The base of the memory. - @param[in] MemoryLimit The limit of the memory. - @param[in] IoMmuAccess The IOMMU access. - - @retval EFI_SUCCESS The VTd entry is updated to always enable = all DMA access for the specific device. -**/ -EFI_STATUS -EnableRmrrPageAttribute ( - IN VTD_INFO *VTdInfo, - IN UINT16 Segment, - IN VTD_SOURCE_ID SourceId, - IN UINT64 MemoryBase, - IN UINT64 MemoryLimit, - IN UINT64 IoMmuAccess - ) -{ - EFI_STATUS Status; - UINTN VtdIndex; - VTD_EXT_CONTEXT_ENTRY *ExtContextEntry; - VTD_CONTEXT_ENTRY *ContextEntry; - VTD_SECOND_LEVEL_PAGING_ENTRY *SecondLevelPagingEntry; - UINT64 Pt; - - DEBUG ((DEBUG_INFO, "EnableRmrrPageAttribute (S%04x B%02x D%02x F%02x)\n= ", Segment, SourceId.Bits.Bus, SourceId.Bits.Device, SourceId.Bits.Function= )); - - VtdIndex =3D FindVtdIndexBySegmentSourceId (VTdInfo, Segment, SourceId, = &ExtContextEntry, &ContextEntry); - if (VtdIndex =3D=3D (UINTN)-1) { - DEBUG ((DEBUG_ERROR, "EnableRmrrPageAttribute - Can not locate Pci dev= ice (S%04x B%02x D%02x F%02x) !\n", Segment, SourceId.Bits.Bus, SourceId.Bi= ts.Device, SourceId.Bits.Function)); - return EFI_DEVICE_ERROR; - } - - if (VTdInfo->VtdUnitInfo[VtdIndex].RmrrSecondLevelPagingEntry =3D=3D 0) = { - DEBUG ((DEBUG_INFO, "CreateSecondLevelPagingEntry - %d\n", VtdIndex)); - VTdInfo->VtdUnitInfo[VtdIndex].RmrrSecondLevelPagingEntry =3D (UINT32)= (UINTN)CreateSecondLevelPagingEntryTable (&VTdInfo->VtdUnitInfo[VtdIndex], = NULL, 0, SIZE_4GB, 0); - if (VTdInfo->VtdUnitInfo[VtdIndex].RmrrSecondLevelPagingEntry =3D=3D 0= ) { - return EFI_OUT_OF_RESOURCES; - } - - Status =3DSetSecondLevelPagingAttribute (&VTdInfo->VtdUnitInfo[VtdInde= x], (VTD_SECOND_LEVEL_PAGING_ENTRY*)(UINTN)VTdInfo->VtdUnitInfo[VtdIndex].R= mrrSecondLevelPagingEntry, MemoryBase, MemoryLimit + 1 - MemoryBase, IoMmuA= ccess); - if (EFI_ERROR (Status)) { - return Status; - } - } - - SecondLevelPagingEntry =3D (VTD_SECOND_LEVEL_PAGING_ENTRY *) (UINTN) VTd= Info->VtdUnitInfo[VtdIndex].RmrrSecondLevelPagingEntry; - Pt =3D (UINT64) RShiftU64 ((UINT64) (UINTN) SecondLevelPagingEntry, 12); - if (ExtContextEntry !=3D NULL) { - ExtContextEntry->Bits.SecondLevelPageTranslationPointerLo =3D (UINT32)= Pt; - ExtContextEntry->Bits.SecondLevelPageTranslationPointerHi =3D (UINT32)= RShiftU64(Pt, 20); - ExtContextEntry->Bits.DomainIdentifier =3D ((1 << (UINT8) ((UINTN) VTd= Info->VtdUnitInfo[VtdIndex].CapReg.Bits.ND * 2 + 4)) - 1); - ExtContextEntry->Bits.Present =3D 1; - FlushPageTableMemory (&VTdInfo->VtdUnitInfo[VtdIndex], (UINTN) ExtCont= extEntry, sizeof(*ExtContextEntry)); - } else if (ContextEntry !=3D NULL) { - ContextEntry->Bits.SecondLevelPageTranslationPointerLo =3D (UINT32) Pt= ; - ContextEntry->Bits.SecondLevelPageTranslationPointerHi =3D (UINT32) RS= hiftU64 (Pt, 20); - ContextEntry->Bits.DomainIdentifier =3D ((1 << (UINT8) ((UINTN) VTdInf= o->VtdUnitInfo[VtdIndex].CapReg.Bits.ND * 2 + 4)) - 1); - ContextEntry->Bits.Present =3D 1; - FlushPageTableMemory (&VTdInfo->VtdUnitInfo[VtdIndex], (UINTN) Context= Entry, sizeof (*ContextEntry)); - } - - return EFI_SUCCESS; -} --=20 2.16.2.windows.1