From nobody Wed Dec 25 02:21:14 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1509504162300763.4683929030288; Tue, 31 Oct 2017 19:42:42 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 30D982034AB3F; Tue, 31 Oct 2017 19:38:48 -0700 (PDT) Received: from NAM02-BL2-obe.outbound.protection.outlook.com (mail-oln040092003037.outbound.protection.outlook.com [40.92.3.37]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id B490D2035D0F1 for ; Tue, 31 Oct 2017 19:38:46 -0700 (PDT) Received: from BL2NAM02FT046.eop-nam02.prod.protection.outlook.com (10.152.76.55) by BL2NAM02HT214.eop-nam02.prod.protection.outlook.com (10.152.77.50) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.20.156.4; Wed, 1 Nov 2017 02:42:37 +0000 Received: from CY1PR19MB0283.namprd19.prod.outlook.com (10.152.76.56) by BL2NAM02FT046.mail.protection.outlook.com (10.152.76.118) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.20.178.5 via Frontend Transport; Wed, 1 Nov 2017 02:42:37 +0000 Received: from CY1PR19MB0283.namprd19.prod.outlook.com ([10.163.54.13]) by CY1PR19MB0283.namprd19.prod.outlook.com ([10.163.54.13]) with mapi id 15.20.0178.014; Wed, 1 Nov 2017 02:42:37 +0000 X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=40.92.3.37; helo=nam02-bl2-obe.outbound.protection.outlook.com; envelope-from=vanjeff_919@hotmail.com; receiver=edk2-devel@lists.01.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hotmail.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=apvcspkngDnXRmemzp/Z3IZch84r9w8TIOYtMjzacmM=; b=odETUzDaGbj3fJmRPKqdpecv6f1CTN6oc9IB3XKQT7Iub46u+Lj8Py2Bab3GAhKLXl6Hvt2e42/fx0Yah/QNqjqWkbQj1JDGh9f2frHcqSXdHXtmOLc9BHMkO4QBv+OojjP1pc9Vez+Fm/xZm5siZEsXd4Cxsk1YbeqsmDi1b37sZXRceLJ0MDeIzKOFKcY8hLcLicJrSkaNQRiGhZgCSpQZL9xGLQhqFF4UC5U92Yyr6CnzBohj6rRAkBFlwkDP7NnE6LOhsADAiEaU336VRB8G7RUPNXK7PMOr9k0IKMd8q0nuUK+hoYHsfX8HCZZgCTVIvEhPezdwvVodmJTdyg== From: Fan Jeff To: Ruiyu Ni , "edk2-devel@lists.01.org" Thread-Topic: [edk2] [PATCH] MdeModulePkg/PciBus: Disable BME of all devices when entering RT Thread-Index: AQHTUh1tQSOK6Wz/TUSUVj1SrUFbVqL+0V9I Date: Wed, 1 Nov 2017 02:42:37 +0000 Message-ID: References: <20171031075357.393144-1-ruiyu.ni@intel.com> In-Reply-To: <20171031075357.393144-1-ruiyu.ni@intel.com> Accept-Language: zh-CN, en-US Content-Language: zh-CN X-MS-Has-Attach: X-MS-TNEF-Correlator: x-incomingtopheadermarker: OriginalChecksum:ADA96128A2170C9484965665F2D6E66F02CAB42858D754E5C11AB13A2AE49F6E; UpperCasedChecksum:7DB4BC9A15B0F9242259662A894D38B6A7BFAD830CA5065D82D8276BEEA12F69; SizeAsReceived:7257; Count:47 x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [m+RYMRo0gxBiPaDe2wRDYZ/P5bkGBAH1] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; BL2NAM02HT214; 6:x7YH668SzSqdqYblgPI1ocUIWUugvWqUeSwpLhEeElqGUwPIKUP+v5KRzydzoAXqoF1SFCUgQJL6EPUOZ3TkAp8r/9tDw2Tw1TjiSVWFYL9X1U1uIGO/0Ootz1ycCUB+BVZx48ng/fHr111QtyeIzX2WUGaGCID5Q21WtFGelobziZFZ2BBT901thVNQeQdc0UDQy30ggKtkqxfL4oFnHW9/ATybiXfl5C1A6izNAsZbMWkFdFUv05aV7WkmXfzuWwT6XwcCJafFUbJ34QHIuF6DjMv/+7hBa9Adfkg2HfJfPY6GqzXg8IgadLqoS4ZlAkVuZASjm76vS3RfdzfjWw==; 5:sxophC1SMxYa5+1etT3W9+pkFo8cMQ0FCwRnCAzLcXuV5RMdPXNc5iLZx+ruoEZNsV3VliUwRcr9X5oDB9u+V8IAmi0zmCaGAhU9MLcmiWUttrn/PLGy8xb4KaN8u4NBRHYn/gDg0xvTbmNHrBx8kw==; 24:wkrZh6fAI380xdNSpjAfE6KRjqtDeuDC9ULi0SfThpeb4v0j5X4SEfjviLoLB3JXbSOk6x0IRwMjBh7lTmszPsB9xAwASCNyZYNu7J062MQ=; 7:ySf5W/Tf9DTlsOl1xmAE6XFX/4Th9F7pwKoFa0d3utqZvj14bh+h2H+h5EwV5C2pDWBH33HJYimCbGywBIRAPcwwaHLy/WNqg5MVgvCJjDO0O/eWn5QaELAfUXQZmOhANtF++r8bV80TsjOb5w2j7mRxHSy3XnsZtNK3b0ZCeLro6vp2rj1NooSgioR7jUaRNs802r13emNwOb3ZNMDjg27hy3k/LVVozMvyEgfAbHc= x-incomingheadercount: 47 x-eopattributedmessage: 0 x-ms-office365-filtering-correlation-id: fb1fe548-87a3-4a51-faa8-08d520d2368c x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(201702061074)(5061506573)(5061507331)(1603103135)(2017031320274)(2017031324274)(2017031323274)(2017031322404)(1603101448)(1601125374)(1701031045); SRVR:BL2NAM02HT214; x-ms-traffictypediagnostic: BL2NAM02HT214: x-exchange-antispam-report-test: UriScan:(89211679590171)(162533806227266)(21748063052155)(228905959029699); x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(444000031); SRVR:BL2NAM02HT214; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:BL2NAM02HT214; x-forefront-prvs: 0478C23FE0 x-forefront-antispam-report: SFV:NSPM; SFS:(7070007)(98901004); DIR:OUT; SFP:1901; SCL:1; SRVR:BL2NAM02HT214; H:CY1PR19MB0283.namprd19.prod.outlook.com; FPR:; SPF:None; LANG:; spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: hotmail.com X-MS-Exchange-CrossTenant-Network-Message-Id: fb1fe548-87a3-4a51-faa8-08d520d2368c X-MS-Exchange-CrossTenant-originalarrivaltime: 01 Nov 2017 02:42:37.1816 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Internet X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL2NAM02HT214 X-Content-Filtered-By: Mailman/MimeDel 2.1.22 Subject: [edk2] =?gb2312?b?tPC4tDogIFtQQVRDSF0gTWRlTW9kdWxlUGtnL1BjaUJ1?= =?gb2312?b?czogRGlzYWJsZSBCTUUgb2YgYWxsIGRldmljZXMgd2hlbiBlbnRlcmluZyBS?= =?gb2312?b?VA==?= X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael D Kinney , Michael Turner , Jiewen Yao Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Minimal comment: To use DEBUG_INFO instead of EFI_D_INFO for consistence in= this patch. + DEBUG (( + EFI_D_INFO," %02x %02x %02x %04x\n", + PciIoDevice->BusNumber, PciIoDevice->DeviceNumber, PciIoDevice->= FunctionNumber, + Command + )); =E5=8F=91=E4=BB=B6=E4=BA=BA: Ruiyu Ni =E5=8F=91=E9=80=81=E6=97=B6=E9=97=B4: 2017=E5=B9=B410=E6=9C=8831=E6=97=A5 1= 5:54 =E6=94=B6=E4=BB=B6=E4=BA=BA: edk2-devel@lists.01.org =E6=8A=84=E9=80=81: Michael D Kinney; Mi= chael Turner; Jiewen Yao =E4=B8=BB=E9=A2=98: [edk2] [PATCH] MdeModulePkg/PciBus: Disable BME of all = devices when entering RT The patch assumes IOMMU protections are disabled after PciBus disables the BMT bit in Command register. It ensures all DMA transactions are protected by IOMMU. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Michael Turner Signed-off-by: Ruiyu Ni Cc: Michael D Kinney Cc: Jiewen Yao --- MdeModulePkg/Bus/Pci/PciBusDxe/PciBus.h | 2 + MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf | 3 + MdeModulePkg/Bus/Pci/PciBusDxe/PciDeviceSupport.c | 86 +++++++++++++++++++= ++++ 3 files changed, 91 insertions(+) diff --git a/MdeModulePkg/Bus/Pci/PciBusDxe/PciBus.h b/MdeModulePkg/Bus/Pci= /PciBusDxe/PciBus.h index 55eb3a5a80..79b5b71082 100644 --- a/MdeModulePkg/Bus/Pci/PciBusDxe/PciBus.h +++ b/MdeModulePkg/Bus/Pci/PciBusDxe/PciBus.h @@ -18,6 +18,8 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER= EXPRESS OR IMPLIED. #include +#include + #include #include #include diff --git a/MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf b/MdeModulePkg/Bu= s/Pci/PciBusDxe/PciBusDxe.inf index 97608bfcf2..d5b8fab3ca 100644 --- a/MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf +++ b/MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf @@ -80,6 +80,9 @@ [LibraryClasses] DebugLib PeCoffLib +[Guids] + gEfiEventExitBootServicesGuid ## SOMETIMES_CONSUMES ##= Event + [Protocols] gEfiPciHotPlugRequestProtocolGuid ## SOMETIMES_PRODUCES gEfiPciIoProtocolGuid ## BY_START diff --git a/MdeModulePkg/Bus/Pci/PciBusDxe/PciDeviceSupport.c b/MdeModuleP= kg/Bus/Pci/PciBusDxe/PciDeviceSupport.c index 97bb971a59..b5530a13d1 100644 --- a/MdeModulePkg/Bus/Pci/PciBusDxe/PciDeviceSupport.c +++ b/MdeModulePkg/Bus/Pci/PciBusDxe/PciDeviceSupport.c @@ -21,6 +21,72 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHE= R EXPRESS OR IMPLIED. LIST_ENTRY mPciDevicePool; /** + Disable Bus Master Enable bit in all devices in the list. + + @param Devices A device list. +**/ +VOID +DisableBmeOnTree ( + IN LIST_ENTRY *Devices + ) +{ + LIST_ENTRY *Link; + PCI_IO_DEVICE *PciIoDevice; + UINT16 Command; + + for ( Link =3D GetFirstNode (Devices) + ; !IsNull (Devices, Link) + ; Link =3D GetNextNode (Devices, Link) + ) { + PciIoDevice =3D PCI_IO_DEVICE_FROM_LINK (Link); + // + // Turn off all children's Bus Master, if any + // + DisableBmeOnTree (&PciIoDevice->ChildList); + + // + // If this is a device that supports BME, disable BME on this device. + // + if ((PciIoDevice->Supports & EFI_PCI_IO_ATTRIBUTE_BUS_MASTER) !=3D 0) { + PCI_READ_COMMAND_REGISTER(PciIoDevice, &Command); + if ((Command & EFI_PCI_COMMAND_BUS_MASTER) !=3D 0) { + Command &=3D ~EFI_PCI_COMMAND_BUS_MASTER; + PCI_SET_COMMAND_REGISTER (PciIoDevice, Command); + DEBUG (( + EFI_D_INFO," %02x %02x %02x %04x\n", + PciIoDevice->BusNumber, PciIoDevice->DeviceNumber, PciIoDevice->= FunctionNumber, + Command + )); + } + } + } +} + +/** + Exit Boot Services Event notification handler. + + Disable Bus Master on any that were enabled during BDS. + + @param[in] Event Event whose notification function is being invoked. + @param[in] Context Pointer to the notification function's context. + +**/ +VOID +EFIAPI +OnExitBootServices ( + IN EFI_EVENT Event, + IN VOID *Context + ) +{ + DEBUG (( + DEBUG_INFO, + "PciBus: Disable Bus Master of all devices...\n" + " Bus# Device# Function# NewCommand\n" + )); + DisableBmeOnTree(&mPciDevicePool); +} + +/** Initialize the PCI devices pool. **/ @@ -29,7 +95,27 @@ InitializePciDevicePool ( VOID ) { + EFI_EVENT ExitBootServicesEvent; + EFI_STATUS Status; + InitializeListHead (&mPciDevicePool); + + // + // DisableBME on ExitBootServices should be synchonized with any IOMMU E= xitBootServices routine. + // DisableBME should be run before the IOMMU protections are disabled. + // One way to do this is to ensure that the IOMMU ExitBootServices callb= ack runs at TPL_CALLBACK. + // + Status =3D gBS->CreateEventEx ( + EVT_NOTIFY_SIGNAL, + TPL_NOTIFY, + OnExitBootServices, + NULL, + &gEfiEventExitBootServicesGuid, + &ExitBootServicesEvent + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "PciBus: Unable to hook ExitBootServices event - = %r\n", Status)); + } } /** -- 2.12.2.windows.2 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel