From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.61]) by mx.groups.io with SMTP id smtpd.web12.13851.1583155464346746459 for ; Mon, 02 Mar 2020 05:24:24 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Xpk/RAsr; spf=pass (domain: redhat.com, ip: 205.139.110.61, mailfrom: philmd@redhat.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1583155463; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=SQKnqM4NEZIAdMWwZxYUBI36RVqu69qEZTIxw16hQVM=; b=Xpk/RAsryvgoO58/fFIrtM9JCF3Z4qLwVcoNgCu+uLnkBYzRoq1mX+6VewONfmOYYzbys3 X8IlHbZlt7O6265OCDua6pN1SCpS/fC77rzrO9eePLX3FzwCB0akg20kL3jvuszG2fDHtD rPi3GdlaxJZHbvL7zD8pAsc9BLyX5xI= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-306-UjpL4szPMF2Ej36NHfA6EA-1; Mon, 02 Mar 2020 08:24:22 -0500 X-MC-Unique: UjpL4szPMF2Ej36NHfA6EA-1 Received: by mail-wr1-f70.google.com with SMTP id u18so5757007wrn.11 for ; Mon, 02 Mar 2020 05:24:21 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=36AdzhMPdYOVhMq5rXlBNz4u13PpZLUproSmWBbbG/U=; b=Er1tyK1GGfdWUZsBWmkFU7g+8J/OtmbNWmeGtzRW2mR6/4M4ErlUg/EMHKYul9LDcU qgAtLLXT8agRKhbor1V7t5OGTir3TwPZd02RzUx4XIC3+gD1c2Tkr5cIzTLsuQ0YAZPt hcSUjNwD1Ar58dEXWecTQZA/J7gxPxM8RI1lgSktABJAuRRE2+bPIKwf4TDZN4xS/tu0 vhNx1qVWiFFDD0SK53sRg5O1CM7Qpw+LNRyDdtPyV3VruQopFV8yyr23m2pI3XT8givM 1v6qO6ZPChO6drq5GvhRvscOzkckOh21irDIQbZC5GkljWpDrBJ/aTnU2UUe/aEEEqNg xmcw== X-Gm-Message-State: ANhLgQ1gYjs+iXZ6CCR3O5M11m4P3fBE7wXTzj1PSR5K4hvgZcfBQTVc yUtksf3pcSZ9CpBuKZYJwBz87dz8Z5QBCSdevU4F4JOyX1SWUpdgRcf8pLU6QpWYj+cQntt63gQ q337CWjNnVhm5Dg== X-Received: by 2002:a05:600c:22d6:: with SMTP id 22mr4374978wmg.102.1583155458822; Mon, 02 Mar 2020 05:24:18 -0800 (PST) X-Google-Smtp-Source: ADFU+vtexhoOefKhcXHVWEkez6dgTYY6y6kHIz3gTYQEMgKy1xEbjdg684Ry4mGGzjmj0+9cU32ovw== X-Received: by 2002:a05:600c:22d6:: with SMTP id 22mr4374963wmg.102.1583155458501; Mon, 02 Mar 2020 05:24:18 -0800 (PST) Return-Path: Received: from ?IPv6:2a01:e35:2fb0:49e0:3f7b:4b69:b9c:cdc0? ([2a01:e35:2fb0:49e0:3f7b:4b69:b9c:cdc0]) by smtp.gmail.com with ESMTPSA id t10sm28478169wru.59.2020.03.02.05.24.17 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 02 Mar 2020 05:24:18 -0800 (PST) Subject: Re: [PATCH v2 07/16] OvmfPkg/CpuHotplugSmm: add hotplug register block helper functions To: Laszlo Ersek , edk2-devel-groups-io Cc: Ard Biesheuvel , Igor Mammedov , Jiewen Yao , Jordan Justen , Michael Kinney References: <20200226221156.29589-1-lersek@redhat.com> <20200226221156.29589-8-lersek@redhat.com> From: =?UTF-8?B?UGhpbGlwcGUgTWF0aGlldS1EYXVkw6k=?= Message-ID: <64ee549c-5307-64ea-ed2e-967c19cff593@redhat.com> Date: Mon, 2 Mar 2020 14:24:17 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.4.1 MIME-Version: 1.0 In-Reply-To: <20200226221156.29589-8-lersek@redhat.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: quoted-printable On 2/26/20 11:11 PM, Laszlo Ersek wrote: > Add a handful of simple functions for accessing QEMU's hotplug registers > more conveniently. These functions thinly wrap some of the registers > described in "docs/specs/acpi_cpu_hotplug.txt" in the QEMU tree. The > functions hang (by design) if they encounter an internal failure. >=20 > Cc: Ard Biesheuvel > Cc: Igor Mammedov > Cc: Jiewen Yao > Cc: Jordan Justen > Cc: Michael Kinney > Cc: Philippe Mathieu-Daud=C3=A9 > Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D1512 > Signed-off-by: Laszlo Ersek > Acked-by: Ard Biesheuvel > --- >=20 > Notes: > v2: > =20 > - Pick up Ard's Acked-by, which is conditional on approval from Inte= l > reviewers on Cc. (I'd like to save Ard the churn of re-acking > unmodified patches.) >=20 > OvmfPkg/CpuHotplugSmm/CpuHotplugSmm.inf | 2 + > OvmfPkg/CpuHotplugSmm/QemuCpuhp.h | 47 +++++++ > OvmfPkg/CpuHotplugSmm/QemuCpuhp.c | 136 ++++++++++++++++++++ > 3 files changed, 185 insertions(+) >=20 > diff --git a/OvmfPkg/CpuHotplugSmm/CpuHotplugSmm.inf b/OvmfPkg/CpuHotplug= Smm/CpuHotplugSmm.inf > index fa70858a8dab..ac4ca4c1f4f2 100644 > --- a/OvmfPkg/CpuHotplugSmm/CpuHotplugSmm.inf > +++ b/OvmfPkg/CpuHotplugSmm/CpuHotplugSmm.inf > @@ -4,44 +4,46 @@ > # Copyright (c) 2020, Red Hat, Inc. > # > # SPDX-License-Identifier: BSD-2-Clause-Patent > ## > =20 > [Defines] > INF_VERSION =3D 1.29 > PI_SPECIFICATION_VERSION =3D 0x00010046 = # PI-1.7.0 > BASE_NAME =3D CpuHotplugSmm > FILE_GUID =3D 84EEA114-C6BE-4445-8F90-51D97863E363 > MODULE_TYPE =3D DXE_SMM_DRIVER > ENTRY_POINT =3D CpuHotplugEntry > =20 > # > # The following information is for reference only and not required by t= he build > # tools. > # > # VALID_ARCHITECTURES =3D IA32 X64 > # > =20 > [Sources] > CpuHotplug.c > + QemuCpuhp.c > + QemuCpuhp.h > =20 > [Packages] > MdePkg/MdePkg.dec > OvmfPkg/OvmfPkg.dec > =20 > [LibraryClasses] > BaseLib > DebugLib > MmServicesTableLib > PcdLib > UefiDriverEntryPoint > =20 > [Protocols] > gEfiMmCpuIoProtocolGuid ## = CONSUMES > =20 > [Pcd] > gUefiOvmfPkgTokenSpaceGuid.PcdQ35SmramAtDefaultSmbase ## = CONSUMES > =20 > [FeaturePcd] > gUefiOvmfPkgTokenSpaceGuid.PcdSmmSmramRequire ## = CONSUMES > =20 > [Depex] > diff --git a/OvmfPkg/CpuHotplugSmm/QemuCpuhp.h b/OvmfPkg/CpuHotplugSmm/Qe= muCpuhp.h > new file mode 100644 > index 000000000000..82f88f0b73bb > --- /dev/null > +++ b/OvmfPkg/CpuHotplugSmm/QemuCpuhp.h > @@ -0,0 +1,47 @@ > +/** @file > + Simple wrapper functions that access QEMU's modern CPU hotplug registe= r > + block. > + > + These functions thinly wrap some of the registers described in > + "docs/specs/acpi_cpu_hotplug.txt" in the QEMU source. IO Ports are acc= essed > + via EFI_MM_CPU_IO_PROTOCOL. If a protocol call fails, these functions = don't > + return. > + > + Copyright (c) 2020, Red Hat, Inc. > + > + SPDX-License-Identifier: BSD-2-Clause-Patent > +**/ > + > +#ifndef QEMU_CPUHP_H_ > +#define QEMU_CPUHP_H_ > + > +#include // EFI_MM_CPU_IO_PROTOCOL > + > +UINT32 > +QemuCpuhpReadCommandData2 ( > + IN CONST EFI_MM_CPU_IO_PROTOCOL *MmCpuIo > + ); > + > +UINT8 > +QemuCpuhpReadCpuStatus ( > + IN CONST EFI_MM_CPU_IO_PROTOCOL *MmCpuIo > + ); > + > +UINT32 > +QemuCpuhpReadCommandData ( > + IN CONST EFI_MM_CPU_IO_PROTOCOL *MmCpuIo > + ); > + > +VOID > +QemuCpuhpWriteCpuSelector ( > + IN CONST EFI_MM_CPU_IO_PROTOCOL *MmCpuIo, > + IN UINT32 Selector > + ); > + > +VOID > +QemuCpuhpWriteCommand ( > + IN CONST EFI_MM_CPU_IO_PROTOCOL *MmCpuIo, > + IN UINT8 Command > + ); > + > +#endif // QEMU_CPUHP_H_ > diff --git a/OvmfPkg/CpuHotplugSmm/QemuCpuhp.c b/OvmfPkg/CpuHotplugSmm/Qe= muCpuhp.c > new file mode 100644 > index 000000000000..31e46f51934a > --- /dev/null > +++ b/OvmfPkg/CpuHotplugSmm/QemuCpuhp.c > @@ -0,0 +1,136 @@ > +/** @file > + Simple wrapper functions that access QEMU's modern CPU hotplug registe= r > + block. > + > + These functions thinly wrap some of the registers described in > + "docs/specs/acpi_cpu_hotplug.txt" in the QEMU source. IO Ports are acc= essed > + via EFI_MM_CPU_IO_PROTOCOL. If a protocol call fails, these functions = don't > + return. > + > + Copyright (c) 2020, Red Hat, Inc. > + > + SPDX-License-Identifier: BSD-2-Clause-Patent > +**/ > + > +#include // ICH9_CPU_HOTPLUG_BASE > +#include // QEMU_CPUHP_R_CMD_DATA2 > +#include // CpuDeadLoop() > +#include // DEBUG() > + > +#include "QemuCpuhp.h" > + > +UINT32 > +QemuCpuhpReadCommandData2 ( > + IN CONST EFI_MM_CPU_IO_PROTOCOL *MmCpuIo > + ) > +{ > + UINT32 CommandData2; > + EFI_STATUS Status; > + > + CommandData2 =3D 0; > + Status =3D MmCpuIo->Io.Read ( > + MmCpuIo, > + MM_IO_UINT32, > + ICH9_CPU_HOTPLUG_BASE + QEMU_CPUHP_R_CMD_DATA2, > + 1, > + &CommandData2 > + ); > + if (EFI_ERROR (Status)) { > + DEBUG ((DEBUG_ERROR, "%a: %r\n", __FUNCTION__, Status)); > + ASSERT (FALSE); > + CpuDeadLoop (); > + } > + return CommandData2; > +} > + > +UINT8 > +QemuCpuhpReadCpuStatus ( > + IN CONST EFI_MM_CPU_IO_PROTOCOL *MmCpuIo > + ) > +{ > + UINT8 CpuStatus; > + EFI_STATUS Status; > + > + CpuStatus =3D 0; > + Status =3D MmCpuIo->Io.Read ( > + MmCpuIo, > + MM_IO_UINT8, > + ICH9_CPU_HOTPLUG_BASE + QEMU_CPUHP_R_CPU_STAT, > + 1, > + &CpuStatus > + ); > + if (EFI_ERROR (Status)) { > + DEBUG ((DEBUG_ERROR, "%a: %r\n", __FUNCTION__, Status)); > + ASSERT (FALSE); > + CpuDeadLoop (); > + } > + return CpuStatus; > +} > + > +UINT32 > +QemuCpuhpReadCommandData ( > + IN CONST EFI_MM_CPU_IO_PROTOCOL *MmCpuIo > + ) > +{ > + UINT32 CommandData; > + EFI_STATUS Status; > + > + CommandData =3D 0; > + Status =3D MmCpuIo->Io.Read ( > + MmCpuIo, > + MM_IO_UINT32, > + ICH9_CPU_HOTPLUG_BASE + QEMU_CPUHP_RW_CMD_DATA, > + 1, > + &CommandData > + ); > + if (EFI_ERROR (Status)) { > + DEBUG ((DEBUG_ERROR, "%a: %r\n", __FUNCTION__, Status)); > + ASSERT (FALSE); > + CpuDeadLoop (); > + } > + return CommandData; > +} > + > +VOID > +QemuCpuhpWriteCpuSelector ( > + IN CONST EFI_MM_CPU_IO_PROTOCOL *MmCpuIo, > + IN UINT32 Selector > + ) > +{ > + EFI_STATUS Status; > + > + Status =3D MmCpuIo->Io.Write ( > + MmCpuIo, > + MM_IO_UINT32, > + ICH9_CPU_HOTPLUG_BASE + QEMU_CPUHP_W_CPU_SEL, > + 1, > + &Selector > + ); > + if (EFI_ERROR (Status)) { > + DEBUG ((DEBUG_ERROR, "%a: %r\n", __FUNCTION__, Status)); > + ASSERT (FALSE); > + CpuDeadLoop (); > + } > +} > + > +VOID > +QemuCpuhpWriteCommand ( > + IN CONST EFI_MM_CPU_IO_PROTOCOL *MmCpuIo, > + IN UINT8 Command > + ) > +{ > + EFI_STATUS Status; > + > + Status =3D MmCpuIo->Io.Write ( > + MmCpuIo, > + MM_IO_UINT8, > + ICH9_CPU_HOTPLUG_BASE + QEMU_CPUHP_W_CMD, > + 1, > + &Command > + ); > + if (EFI_ERROR (Status)) { > + DEBUG ((DEBUG_ERROR, "%a: %r\n", __FUNCTION__, Status)); > + ASSERT (FALSE); > + CpuDeadLoop (); > + } > +} >=20 Reviewed-by: Philippe Mathieu-Daude