From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM01-SN1-obe.outbound.protection.outlook.com (mail-sn1nam01on062a.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe40::62a]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id AEEE621A0483A for ; Wed, 12 Apr 2017 13:26:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector1-amd-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=XhLSiJ7ihSDXwZRsnVMRum3Z3QeBVJtWZuPQdA+ls3E=; b=bAOBFgwqVkIPDjBFBwSSWMa29G3I4EdyH+7BXkG7aT7wLGi3X+42W21aRLmsSIUwbJi4UBxIjqih3s52eOZ17Q29nnhh4UQvE8IWgO5DsIyTKKFDpeq13ie1WRVjrvIoO0jLAQzVhVRq8G4hvRZNBZBLuagsJPE39qbN46XXs0Q= Received: from DM5PR12MB1243.namprd12.prod.outlook.com (10.168.237.22) by DM5PR12MB1243.namprd12.prod.outlook.com (10.168.237.22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1019.17; Wed, 12 Apr 2017 20:26:06 +0000 Received: from DM5PR12MB1243.namprd12.prod.outlook.com ([10.168.237.22]) by DM5PR12MB1243.namprd12.prod.outlook.com ([10.168.237.22]) with mapi id 15.01.1019.025; Wed, 12 Apr 2017 20:26:06 +0000 From: "Duran, Leo" To: Laszlo Ersek , "edk2-devel@ml01.01.org" CC: Feng Tian , Star Zeng , "Brijesh Singh" Thread-Topic: [PATCH] OvmfPkg/GcdNotifyDxe: Install EFI_GCD_MEMORY_SPACE_NOTIFY_PROTOCOL Thread-Index: AQHSs78WQryMIrwX/EmdljMHE+aeYqHCFp6AgAAWlwCAAAB/IA== Date: Wed, 12 Apr 2017 20:26:06 +0000 Message-ID: References: <1492023631-16252-1-git-send-email-leo.duran@amd.com> <1492023631-16252-2-git-send-email-leo.duran@amd.com> <54618777-1aef-e3fe-a533-3c9576539719@redhat.com> In-Reply-To: <54618777-1aef-e3fe-a533-3c9576539719@redhat.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=none action=none header.from=amd.com; x-originating-ip: [165.204.53.123] x-microsoft-exchange-diagnostics: 1; DM5PR12MB1243; 7:2rTy1EVetnGUOKL6DHTrtRcBbU8QkVs7ps2UgL9yGD1MAa1XPeNs7rh/dVkG4sXNfralNUO0X0SUXo8KZOp1U8S6/KU7oF3ZcVvUDAQorMg3P8FsXy86LnOQ0wt7Jt4n1GStQ0C+jg4QCSaBAD+dK1K7m1GzLOEah5HrujF9IUVPAoHpTDd83BfpVZg9sUaZ6CCEnAbgs74lr6RMxBH41Lr2NfD15h/FHyZ7q42Mffc3wKy7dc5gzGzy8/HvSXzaS9j/+VHJj95SnAY36L02HEYaWHDyXQJCvjEoZz2+A5NIha4cKtWtunpON+iGQS1EZzYNO/dzdP1WZa8qjpLtZQ==; 20:SBLFeSpS8lgCxkmzHY79McMUdNshjpSol4JczKygAefX+2y0jGgK/F6MCyO5KXAfXxwP9hP+u01RVeceyt3iTImm7c4DE2w+7yYJon0ZeYWFisU63HFAIYAXu8pu8iEVXRt9B0+MB+c+tL6FF/aWQM7zkXksHBKIKG5J8kPhR7T51ca6BHCS6AceAeX1mTCuR4cIQY/GNzi67r8cLFx8Xc9MiRoMG9uUR8nkwOihEKAGzlT6rC2FN6/RUzd7JVwD x-ms-office365-filtering-correlation-id: 96c88787-5b86-41ff-0f42-08d481e2260e x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(2017030254075)(48565401081)(201703131423075)(201703031133081)(201702281549075); SRVR:DM5PR12MB1243; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(767451399110)(228905959029699); x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(6040450)(601004)(2401047)(8121501046)(5005006)(3002001)(10201501046)(93006095)(93001095)(6055026)(6041248)(20161123560025)(201703131423075)(201702281528075)(201703061421075)(20161123555025)(20161123564025)(20161123562025)(6072148); SRVR:DM5PR12MB1243; BCL:0; PCL:0; RULEID:; SRVR:DM5PR12MB1243; x-forefront-prvs: 027578BB13 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(6009001)(39840400002)(39860400002)(39850400002)(39400400002)(39410400002)(39450400003)(13464003)(377454003)(24454002)(3846002)(2501003)(6116002)(76176999)(2950100002)(102836003)(7696004)(33656002)(122556002)(74316002)(54356999)(50986999)(86362001)(2900100001)(16799955002)(15188155005)(189998001)(305945005)(7736002)(39060400002)(6506006)(966004)(2906002)(38730400002)(77096006)(55016002)(99286003)(54906002)(8676002)(4326008)(53376002)(5660300001)(81166006)(229853002)(6436002)(6246003)(9686003)(25786009)(3660700001)(8936002)(66066001)(53936002)(6306002)(3280700002)(53546009)(19627235001); DIR:OUT; SFP:1101; SCL:1; SRVR:DM5PR12MB1243; H:DM5PR12MB1243.namprd12.prod.outlook.com; FPR:; SPF:None; MLV:ovrnspm; PTR:InfoNoRecords; LANG:en; spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-originalarrivaltime: 12 Apr 2017 20:26:06.5608 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1243 Subject: Re: [PATCH] OvmfPkg/GcdNotifyDxe: Install EFI_GCD_MEMORY_SPACE_NOTIFY_PROTOCOL 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: , X-List-Received-Date: Wed, 12 Apr 2017 20:26:09 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Lazlo, This path is *not* intended to be pushed upstream... It's just a "show & te= ll" for the previous patch. Basically, the intent is to illustrate the use-case... so this patch just d= oes a DEBUG out. Leo. > -----Original Message----- > From: Laszlo Ersek [mailto:lersek@redhat.com] > Sent: Wednesday, April 12, 2017 3:21 PM > To: Duran, Leo ; edk2-devel@ml01.01.org > Cc: Feng Tian ; Star Zeng ; > Brijesh Singh > Subject: Re: [PATCH] OvmfPkg/GcdNotifyDxe: Install > EFI_GCD_MEMORY_SPACE_NOTIFY_PROTOCOL >=20 > On 04/12/17 21:00, Leo Duran wrote: > > On entry, GcdNotifyDxe scans the GCD MemmorySpace map and produces > > this protocol to get notifications from GCD on MemorySpace Add/Remove > operations. > > > > This patch illustrates how OvmfPkg could take actions on GCD notificati= ons. > > For example: updating the SEV mask on page-table entries for MMIO > ranges. > > > > Cc: Laszlo Ersek > > Cc: Feng Tian > > Cc: Star Zeng > > Cc: Brijesh Singh > > Contributed-under: TianoCore Contribution Agreement 1.0 > > Signed-off-by: Leo Duran > > --- > > OvmfPkg/GcdNotifyDxe/GcdNotifyDxe.c | 148 > ++++++++++++++++++++++++++++++++++ > > OvmfPkg/GcdNotifyDxe/GcdNotifyDxe.inf | 44 ++++++++++ > > OvmfPkg/OvmfPkgIa32X64.dsc | 2 + > > OvmfPkg/OvmfPkgIa32X64.fdf | 3 + > > 4 files changed, 197 insertions(+) > > create mode 100644 OvmfPkg/GcdNotifyDxe/GcdNotifyDxe.c > > create mode 100644 OvmfPkg/GcdNotifyDxe/GcdNotifyDxe.inf >=20 > I guess this patch depends on >=20 > [PATCH] MdeModulePkg: Add > EFI_GCD_MEMORY_SPACE_NOTIFY_PROTOCOL >=20 > so I think we should first await the outcome of that discussion. >=20 > Still, is there any particular reason to include the driver in the > OvmfPkgIa32X64 platform only? (No Ia32, no X64?) >=20 > Thanks > Laszlo >=20 > > > > diff --git a/OvmfPkg/GcdNotifyDxe/GcdNotifyDxe.c > > b/OvmfPkg/GcdNotifyDxe/GcdNotifyDxe.c > > new file mode 100644 > > index 0000000..1b54584 > > --- /dev/null > > +++ b/OvmfPkg/GcdNotifyDxe/GcdNotifyDxe.c > > @@ -0,0 +1,148 @@ > > +/** @file > > + > > + GCD Memory Space Map notification protocol handler. > > + > > + Copyright (c) 2017, AMD Inc. All rights reserved.
> > + > > + This program and the accompanying materials are licensed and made > > + available under the terms and conditions of the BSD License which > > + accompanies this distribution. The full text of the license may be > > + found at http://opensource.org/licenses/bsd-license.php > > + > > + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" > > + BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, > EITHER EXPRESS OR IMPLIED. > > + > > +**/ > > + > > +#include > > + > > +#include > > +#include > > +#include #include > > + > > +#include #include > > + > > + > > +#include > > + > > +// > > +// GCD Memory Space Map notification protocol // STATIC > > +EFI_GCD_MEMORY_SPACE_NOTIFY_PROTOCOL > mGcdMemorySpaceNotifyProtocol; > > + > > +/// > > +/// Lookup table used to print GCD Memory Space Map /// > > +GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 > *mGcdMemoryTypeNames[] =3D { > > + "EfiGcdMemoryTypeNonExistent", > > + "EfiGcdMemoryTypeReserved", > > + "EfiGcdMemoryTypeSystemMemory", > > + "EfiGcdMemoryTypeMemoryMappedIo", > > + "EfiGcdMemoryTypePersistentMemory", > > + "EfiGcdMemoryTypeMoreReliable", > > + "EfiGcdMemoryTypeMaximum" > > +}; > > + > > + > > +/** > > +Notify on: Add a segment of memory to GCD map. > > + > > +@param GcdMemoryType Memory type of the segment. > > +@param BaseAddress Base address of the segment. > > +@param Length Length of the segment. > > +@param Capabilities Alterable attributes of the segment. > > + > > +**/ > > +STATIC > > +VOID > > +EFIAPI > > +GcdMemorySpaceAddNotify ( > > +IN EFI_GCD_MEMORY_TYPE GcdMemoryType, > > +IN EFI_PHYSICAL_ADDRESS BaseAddress, > > +IN UINT64 Length, > > +IN UINT64 Capabilities > > +) > > +{ > > + DEBUG ((EFI_D_INFO, "%a()\n", __FUNCTION__)); > > + > > + if (GcdMemoryType >=3D EfiGcdMemoryTypeNonExistent && > GcdMemoryType <=3D EfiGcdMemoryTypeMaximum) { > > + DEBUG ((EFI_D_INFO, " GcdMemoryType =3D 0x%X (%a)\n", > GcdMemoryType, mGcdMemoryTypeNames[GcdMemoryType])); > > + DEBUG ((EFI_D_INFO, " BaseAddress =3D 0x%p\n", BaseAddress)); > > + DEBUG ((EFI_D_INFO, " Length =3D 0x%lX\n", Length)); > > + > > + if (GcdMemoryType =3D=3D EfiGcdMemoryTypeMemoryMappedIo) { > > + DEBUG ((EFI_D_INFO, " MMIO: Start =3D 0x%p, Length =3D 0x%lX\n", > BaseAddress, Length)); > > + } > > + } > > + else { > > + DEBUG ((EFI_D_INFO, " Invalid GcdMemoryType =3D 0x%X\n", > > +GcdMemoryType)); > > + } > > +} > > + > > + > > +/** > > +Notify on: Remove a segment of memory to GCD map. > > + > > +@param BaseAddress Base address of the segment. > > +@param Length Length of the segment. > > + > > +**/ > > +STATIC > > +VOID > > +EFIAPI > > +GcdMemorySpaceRemoveNotify ( > > +IN EFI_PHYSICAL_ADDRESS BaseAddress, > > +IN UINT64 Length > > +) > > +{ > > + DEBUG ((EFI_D_INFO, "%a()\n", __FUNCTION__)); > > + DEBUG ((EFI_D_INFO, " BaseAddress =3D 0x%p\n", BaseAddress)); > > + DEBUG ((EFI_D_INFO, " Length =3D 0x%lX\n", Length)); } > > + > > + > > +EFI_STATUS > > +EFIAPI > > +GcdNotifyDxeEntry ( > > + IN EFI_HANDLE ImageHandle, > > + IN EFI_SYSTEM_TABLE *SystemTable > > + ) > > +{ > > + EFI_GCD_MEMORY_SPACE_DESCRIPTOR *MemorySpaceMap; > > + UINTN NumEntries; > > + UINTN Index; > > + EFI_STATUS Status; > > + EFI_HANDLE Handle; > > + > > + DEBUG((EFI_D_INFO, "%a - ENTRY\n", __FUNCTION__)); > > + > > + // > > + // Iterate through the current MemorySpace Map // MemorySpaceMap > > + =3D NULL; Status =3D gDS->GetMemorySpaceMap (&NumEntries, > > + &MemorySpaceMap); ASSERT_EFI_ERROR (Status); > > + > > + for (Index =3D 0; Index < NumEntries; ++Index) { > > + if (MemorySpaceMap[Index].GcdMemoryType =3D=3D > EfiGcdMemoryTypeMemoryMappedIo) { > > + DEBUG ((DEBUG_INFO, " MMIO: Start =3D 0x%p, Length =3D 0x%lX\n", > > + MemorySpaceMap[Index].BaseAddress, > MemorySpaceMap[Index].Length)); > > + } > > + } > > + > > + // > > + // Install GCD Memory Space Map notification protocol // > > + mGcdMemorySpaceNotifyProtocol.MemorySpaceAddNotify =3D > > + GcdMemorySpaceAddNotify; > > + mGcdMemorySpaceNotifyProtocol.MemorySpaceRemoveNotify =3D > > + GcdMemorySpaceRemoveNotify; Handle =3D NULL; Status =3D gBS- > >InstallProtocolInterface ( > > + &Handle, > > + &gEfiGcdMemorySpaceNotifyProtocolGuid, > > + EFI_NATIVE_INTERFACE, > > + &mGcdMemorySpaceNotifyProtocol); > > + ASSERT_EFI_ERROR (Status); > > + > > + DEBUG((EFI_D_INFO, "%a - EXIT (Status =3D %r)\n", __FUNCTION__, > > +Status)); > > + return Status; > > +} > > diff --git a/OvmfPkg/GcdNotifyDxe/GcdNotifyDxe.inf > > b/OvmfPkg/GcdNotifyDxe/GcdNotifyDxe.inf > > new file mode 100644 > > index 0000000..a4c8445 > > --- /dev/null > > +++ b/OvmfPkg/GcdNotifyDxe/GcdNotifyDxe.inf > > @@ -0,0 +1,44 @@ > > +#/** @file > > +# > > +# Component description file for GcdNotifyDxe module # # Copyright > > +(c) 2017, AMD Inc. All rights reserved.
# # This program and the > > +accompanying materials # are licensed and made available under the > > +terms and conditions of the BSD License # which accompanies this > > +distribution. The full text of the license may be found at # > > +http://opensource.org/licenses/bsd-license.php > > +# > > +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" > > +BASIS, # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, > EITHER EXPRESS OR IMPLIED. > > +# > > +#**/ > > + > > +[Defines] > > + INF_VERSION =3D 0x00010005 > > + BASE_NAME =3D GcdNotifyDxe > > + FILE_GUID =3D 2ec9da37-ee35-4de9-86c5-6d9a81dc3= 8a7 > > + MODULE_TYPE =3D DXE_DRIVER > > + VERSION_STRING =3D 1.0 > > + ENTRY_POINT =3D GcdNotifyDxeEntry > > + > > +[Sources] > > + GcdNotifyDxe.c > > + > > +[Packages] > > + MdePkg/MdePkg.dec > > + MdeModulePkg/MdeModulePkg.dec > > + > > +[LibraryClasses] > > + BaseLib > > + UefiLib > > + UefiDriverEntryPoint > > + UefiBootServicesTableLib > > + DxeServicesTableLib > > + DebugLib > > + > > +[Protocols] > > + gEfiGcdMemorySpaceNotifyProtocolGuid ## PRODUCES > > + > > +[Depex] > > + TRUE > > diff --git a/OvmfPkg/OvmfPkgIa32X64.dsc > b/OvmfPkg/OvmfPkgIa32X64.dsc > > index 71ac62f..441d7cc 100644 > > --- a/OvmfPkg/OvmfPkgIa32X64.dsc > > +++ b/OvmfPkg/OvmfPkgIa32X64.dsc > > @@ -3,6 +3,7 @@ > > # > > # Copyright (c) 2006 - 2017, Intel Corporation. All rights > > reserved.
# (C) Copyright 2016 Hewlett Packard Enterprise > > Development LP
> > +# Copyright (c) 2017, AMD Inc. All rights reserved.
> > # > > # This program and the accompanying materials # are licensed and > > made available under the terms and conditions of the BSD License @@ > > -798,6 +799,7 @@ !endif > > > > OvmfPkg/PlatformDxe/Platform.inf > > + OvmfPkg/GcdNotifyDxe/GcdNotifyDxe.inf > > > > !if $(SMM_REQUIRE) =3D=3D TRUE > > OvmfPkg/SmmAccess/SmmAccess2Dxe.inf > > diff --git a/OvmfPkg/OvmfPkgIa32X64.fdf b/OvmfPkg/OvmfPkgIa32X64.fdf > > index 5233314..71b118a 100644 > > --- a/OvmfPkg/OvmfPkgIa32X64.fdf > > +++ b/OvmfPkg/OvmfPkgIa32X64.fdf > > @@ -3,6 +3,7 @@ > > # > > # Copyright (c) 2006 - 2016, Intel Corporation. All rights > > reserved.
# (C) Copyright 2016 Hewlett Packard Enterprise > > Development LP
> > +# Copyright (c) 2017, AMD Inc. All rights reserved.
> > # > > # This program and the accompanying materials # are licensed and > > made available under the terms and conditions of the BSD License @@ > > -193,6 +194,7 @@ APRIORI DXE { !if $(SMM_REQUIRE) =3D=3D FALSE > > INF > > OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FvbServicesRuntimeDxe.inf > > !endif > > + INF OvmfPkg/GcdNotifyDxe/GcdNotifyDxe.inf > > } > > > > # > > @@ -351,6 +353,7 @@ INF RuleOverride=3DCSM > OvmfPkg/Csm/Csm16/Csm16.inf > > INF OvmfPkg/QemuVideoDxe/QemuVideoDxe.inf > > INF OvmfPkg/VirtioGpuDxe/VirtioGpu.inf > > INF OvmfPkg/PlatformDxe/Platform.inf > > +INF OvmfPkg/GcdNotifyDxe/GcdNotifyDxe.inf > > > > !if $(SMM_REQUIRE) =3D=3D TRUE > > INF OvmfPkg/SmmAccess/SmmAccess2Dxe.inf > >