From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f68.google.com (mail-wr1-f68.google.com [209.85.221.68]) by mx.groups.io with SMTP id smtpd.web09.14228.1583156716845079628 for ; Mon, 02 Mar 2020 05:45:17 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@linaro.org header.s=google header.b=KYwrsTwQ; spf=pass (domain: linaro.org, ip: 209.85.221.68, mailfrom: ard.biesheuvel@linaro.org) Received: by mail-wr1-f68.google.com with SMTP id z15so12707411wrl.1 for ; Mon, 02 Mar 2020 05:45:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=ZSte4/SUV7Xu7eKKkrN81i11XjsIFDlUx0yRe/dDsq0=; b=KYwrsTwQrSaWyMgMZf0IC/yFKJBs4wm6K37tbZ+iftim4glp1TEwGmwWdrsxoIwUBh PmO486NgLdmO2510xffjI3/jPtetu5cHST1WKCyZrWmuegTMnlqvGS06UK/JcqeaCIS9 0vlc8RbFsPGW2owUGYJDMh1gX7f4TGrSL5tSRo06YiGMi+rAs2xMNFXFFV/ek8AU4Gt/ TI/kecIs4E0qJXrEVsMOZtW2NStyEU/8zLZfpLV/w8rw3ahFJkzoYB9QldqE3YhPEpBJ rlkJCgjhuIKklqjsgok45p1sGDBQFdEJOP/l8ftMNr6fyTjM7mfPCX4tS9qUJixL/XYu SgqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=ZSte4/SUV7Xu7eKKkrN81i11XjsIFDlUx0yRe/dDsq0=; b=DHGC0qRpmGX6JDDd9/KXsFM2JwJNQIhtbxyivLzOIZ77cU/AY0jnX7A9rLG8BqZd0H LSznc6nkfeL+jnn0I336hNORd9EszjkXzEK8B5VOyFnCQ0EcZbHB7tSh1gIFw8Xhw6zG 8a4Q33LhLDBVE/bHSw6NUxN6rYWfLaHgQMqyNlYMNSf2vv3US7mRe3/Qq+0c2U0/U3jP jOjoNblhNyKRSOFp5oQbswAJfEBE5ZmqqdBg5/5Yz8O1orFTBYyKYZqwyOaV0zBFE65Q P9brA0fArg2Nzwz+Myz5LshWjQ3z8OnTQ9rXMBB4uDaQdUqtHqvwmZRU6KcVrCjSwxYq YcFA== X-Gm-Message-State: APjAAAWiOaKsoQJPGMkaK7+k6AuhwfsT0XiuEt629egnIhWbdHP/OCTH WcYoXvA0erJuYedQfya2Nvi7jFxLM86W9FrLtFtMlRaYXiJ/sg== X-Google-Smtp-Source: APXvYqz8cPv5y0srghBJMJbbawn8DXWFe7Qk1c2qi64dxAw8ejGAwrcRykNPLgopVWyCdnKQ7Z5TVgPlApqq3zRbVxs= X-Received: by 2002:adf:a411:: with SMTP id d17mr22172218wra.126.1583156715179; Mon, 02 Mar 2020 05:45:15 -0800 (PST) MIME-Version: 1.0 References: <20200226221156.29589-1-lersek@redhat.com> <20200226221156.29589-8-lersek@redhat.com> In-Reply-To: <20200226221156.29589-8-lersek@redhat.com> From: "Ard Biesheuvel" Date: Mon, 2 Mar 2020 14:45:04 +0100 Message-ID: Subject: Re: [edk2-devel] [PATCH v2 07/16] OvmfPkg/CpuHotplugSmm: add hotplug register block helper functions To: edk2-devel-groups-io , Laszlo Ersek Cc: Igor Mammedov , Jiewen Yao , Jordan Justen , Michael Kinney , =?UTF-8?Q?Philippe_Mathieu=2DDaud=C3=A9?= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, 26 Feb 2020 at 23:12, 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. > > 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 Reviewed-by: Ard Biesheuvel > --- > > Notes: > v2: > > - 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.) > > OvmfPkg/CpuHotplugSmm/CpuHotplugSmm.inf | 2 + > OvmfPkg/CpuHotplugSmm/QemuCpuhp.h | 47 +++++++ > OvmfPkg/CpuHotplugSmm/QemuCpuhp.c | 136 ++++++++++++++++++++ > 3 files changed, 185 insertions(+) > > diff --git a/OvmfPkg/CpuHotplugSmm/CpuHotplugSmm.inf b/OvmfPkg/CpuHotplu= gSmm/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 > ## > > [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 > > # > # The following information is for reference only and not required by t= he build > # tools. > # > # VALID_ARCHITECTURES =3D IA32 X64 > # > > [Sources] > CpuHotplug.c > + QemuCpuhp.c > + QemuCpuhp.h > > [Packages] > MdePkg/MdePkg.dec > OvmfPkg/OvmfPkg.dec > > [LibraryClasses] > BaseLib > DebugLib > MmServicesTableLib > PcdLib > UefiDriverEntryPoint > > [Protocols] > gEfiMmCpuIoProtocolGuid ## = CONSUMES > > [Pcd] > gUefiOvmfPkgTokenSpaceGuid.PcdQ35SmramAtDefaultSmbase ## = CONSUMES > > [FeaturePcd] > gUefiOvmfPkgTokenSpaceGuid.PcdSmmSmramRequire ## = CONSUMES > > [Depex] > diff --git a/OvmfPkg/CpuHotplugSmm/QemuCpuhp.h b/OvmfPkg/CpuHotplugSmm/Q= emuCpuhp.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 regist= er > + block. > + > + These functions thinly wrap some of the registers described in > + "docs/specs/acpi_cpu_hotplug.txt" in the QEMU source. IO Ports are ac= cessed > + 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/Q= emuCpuhp.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 regist= er > + block. > + > + These functions thinly wrap some of the registers described in > + "docs/specs/acpi_cpu_hotplug.txt" in the QEMU source. IO Ports are ac= cessed > + 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 (); > + } > +} > -- > 2.19.1.3.g30247aa5d201 > > > >=20 >