public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@redhat.com>
To: Laszlo Ersek <lersek@redhat.com>,
	edk2-devel-groups-io <devel@edk2.groups.io>
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>,
	Igor Mammedov <imammedo@redhat.com>,
	Jiewen Yao <jiewen.yao@intel.com>,
	Jordan Justen <jordan.l.justen@intel.com>,
	Michael Kinney <michael.d.kinney@intel.com>
Subject: Re: [PATCH v2 07/16] OvmfPkg/CpuHotplugSmm: add hotplug register block helper functions
Date: Mon, 2 Mar 2020 14:24:17 +0100	[thread overview]
Message-ID: <64ee549c-5307-64ea-ed2e-967c19cff593@redhat.com> (raw)
In-Reply-To: <20200226221156.29589-8-lersek@redhat.com>

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.
> 
> Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
> Cc: Igor Mammedov <imammedo@redhat.com>
> Cc: Jiewen Yao <jiewen.yao@intel.com>
> Cc: Jordan Justen <jordan.l.justen@intel.com>
> Cc: Michael Kinney <michael.d.kinney@intel.com>
> Cc: Philippe Mathieu-Daudé <philmd@redhat.com>
> Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=1512
> Signed-off-by: Laszlo Ersek <lersek@redhat.com>
> Acked-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
> ---
> 
> Notes:
>      v2:
>      
>      - Pick up Ard's Acked-by, which is conditional on approval from Intel
>        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/CpuHotplugSmm/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                = 1.29
>     PI_SPECIFICATION_VERSION   = 0x00010046                            # PI-1.7.0
>     BASE_NAME                  = CpuHotplugSmm
>     FILE_GUID                  = 84EEA114-C6BE-4445-8F90-51D97863E363
>     MODULE_TYPE                = DXE_SMM_DRIVER
>     ENTRY_POINT                = CpuHotplugEntry
>   
>   #
>   # The following information is for reference only and not required by the build
>   # tools.
>   #
>   # VALID_ARCHITECTURES        = 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/QemuCpuhp.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 register
> +  block.
> +
> +  These functions thinly wrap some of the registers described in
> +  "docs/specs/acpi_cpu_hotplug.txt" in the QEMU source. IO Ports are accessed
> +  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 <Protocol/MmCpuIo.h>  // 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/QemuCpuhp.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 register
> +  block.
> +
> +  These functions thinly wrap some of the registers described in
> +  "docs/specs/acpi_cpu_hotplug.txt" in the QEMU source. IO Ports are accessed
> +  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 <IndustryStandard/Q35MchIch9.h>     // ICH9_CPU_HOTPLUG_BASE
> +#include <IndustryStandard/QemuCpuHotplug.h> // QEMU_CPUHP_R_CMD_DATA2
> +#include <Library/BaseLib.h>                 // CpuDeadLoop()
> +#include <Library/DebugLib.h>                // DEBUG()
> +
> +#include "QemuCpuhp.h"
> +
> +UINT32
> +QemuCpuhpReadCommandData2 (
> +  IN CONST EFI_MM_CPU_IO_PROTOCOL *MmCpuIo
> +  )
> +{
> +  UINT32     CommandData2;
> +  EFI_STATUS Status;
> +
> +  CommandData2 = 0;
> +  Status = 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 = 0;
> +  Status = 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 = 0;
> +  Status = 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 = 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 = 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 ();
> +  }
> +}
> 

Reviewed-by: Philippe Mathieu-Daude <philmd@redhat.com>


  reply	other threads:[~2020-03-02 13:24 UTC|newest]

Thread overview: 53+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-26 22:11 [PATCH v2 00/16] OvmfPkg: support VCPU hotplug with -D SMM_REQUIRE Laszlo Ersek
2020-02-26 22:11 ` [PATCH v2 01/16] MdeModulePkg/PiSmmCore: log SMM image start failure Laszlo Ersek
2020-03-02 12:47   ` [edk2-devel] " Laszlo Ersek
2020-03-02 12:55     ` Liming Gao
2020-03-02 13:46   ` Philippe Mathieu-Daudé
2020-03-03  0:46   ` Dong, Eric
2020-02-26 22:11 ` [PATCH v2 02/16] UefiCpuPkg/PiSmmCpuDxeSmm: fix S3 Resume for CPU hotplug Laszlo Ersek
2020-02-28  3:05   ` [edk2-devel] " Dong, Eric
2020-02-28 10:50     ` Laszlo Ersek
2020-03-04 12:23     ` Laszlo Ersek
2020-03-04 14:36       ` Dong, Eric
2020-02-26 22:11 ` [PATCH v2 03/16] OvmfPkg: clone SmmCpuPlatformHookLib from UefiCpuPkg Laszlo Ersek
2020-03-02 13:27   ` Ard Biesheuvel
2020-03-02 13:49   ` Philippe Mathieu-Daudé
2020-02-26 22:11 ` [PATCH v2 04/16] OvmfPkg: enable SMM Monarch Election in PiSmmCpuDxeSmm Laszlo Ersek
2020-03-02 13:32   ` Ard Biesheuvel
2020-02-26 22:11 ` [PATCH v2 05/16] OvmfPkg: enable CPU hotplug support " Laszlo Ersek
2020-03-02 13:33   ` Ard Biesheuvel
2020-02-26 22:11 ` [PATCH v2 06/16] OvmfPkg/CpuHotplugSmm: introduce skeleton for CPU Hotplug SMM driver Laszlo Ersek
2020-03-02 13:44   ` Ard Biesheuvel
2020-02-26 22:11 ` [PATCH v2 07/16] OvmfPkg/CpuHotplugSmm: add hotplug register block helper functions Laszlo Ersek
2020-03-02 13:24   ` Philippe Mathieu-Daudé [this message]
2020-03-02 13:45   ` [edk2-devel] " Ard Biesheuvel
2020-02-26 22:11 ` [PATCH v2 08/16] OvmfPkg/CpuHotplugSmm: define the QEMU_CPUHP_CMD_GET_ARCH_ID macro Laszlo Ersek
2020-03-02 13:22   ` Philippe Mathieu-Daudé
2020-03-02 13:45   ` Ard Biesheuvel
2020-02-26 22:11 ` [PATCH v2 09/16] OvmfPkg/CpuHotplugSmm: add function for collecting CPUs with events Laszlo Ersek
2020-03-02 13:49   ` Ard Biesheuvel
2020-03-02 20:34   ` Philippe Mathieu-Daudé
2020-03-03 10:31     ` Laszlo Ersek
2020-02-26 22:11 ` [PATCH v2 10/16] OvmfPkg/CpuHotplugSmm: collect " Laszlo Ersek
2020-03-02 13:58   ` Ard Biesheuvel
2020-02-26 22:11 ` [PATCH v2 11/16] OvmfPkg/CpuHotplugSmm: introduce Post-SMM Pen for hot-added CPUs Laszlo Ersek
2020-03-02 14:02   ` [edk2-devel] " Ard Biesheuvel
2020-02-26 22:11 ` [PATCH v2 12/16] OvmfPkg/CpuHotplugSmm: introduce First SMI Handler " Laszlo Ersek
2020-03-02 14:03   ` Ard Biesheuvel
2020-02-26 22:11 ` [PATCH v2 13/16] OvmfPkg/CpuHotplugSmm: complete root MMI handler for CPU hotplug Laszlo Ersek
2020-03-02 14:05   ` Ard Biesheuvel
2020-02-26 22:11 ` [PATCH v2 14/16] OvmfPkg: clone CpuS3DataDxe from UefiCpuPkg Laszlo Ersek
2020-03-02 13:44   ` Philippe Mathieu-Daudé
2020-03-02 14:06   ` Ard Biesheuvel
2020-02-26 22:11 ` [PATCH v2 15/16] OvmfPkg/CpuS3DataDxe: superficial cleanups Laszlo Ersek
2020-03-02 13:25   ` Philippe Mathieu-Daudé
2020-03-02 14:06   ` Ard Biesheuvel
2020-02-26 22:11 ` [PATCH v2 16/16] OvmfPkg/CpuS3DataDxe: enable S3 resume after CPU hotplug Laszlo Ersek
2020-03-02 14:16   ` Ard Biesheuvel
2020-03-02 15:46 ` [edk2-devel] [PATCH v2 00/16] OvmfPkg: support VCPU hotplug with -D SMM_REQUIRE Boris Ostrovsky
2020-03-02 19:22   ` Laszlo Ersek
2020-03-02 19:59 ` Laszlo Ersek
2020-03-04 13:29   ` Philippe Mathieu-Daudé
2020-03-04 18:09     ` Laszlo Ersek
2020-03-04 12:29 ` Laszlo Ersek
2020-03-05  8:32   ` Laszlo Ersek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=64ee549c-5307-64ea-ed2e-967c19cff593@redhat.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox