public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Laszlo Ersek <lersek@redhat.com>
To: edk2-devel-01 <edk2-devel@ml01.01.org>
Cc: Jordan Justen <jordan.l.justen@intel.com>
Subject: [PATCH v2 09/12] OvmfPkg/QemuFwCfgS3Lib: implement opcode APIs for PEI fw_cfg instance
Date: Sat, 11 Mar 2017 07:26:48 +0100	[thread overview]
Message-ID: <20170311062651.28351-10-lersek@redhat.com> (raw)
In-Reply-To: <20170311062651.28351-1-lersek@redhat.com>

In the PEI fw_cfg instance:

- QemuFwCfgS3Enabled() queries S3 enablement via fw_cfg. This behavior is
  shared with the DXE fw_cfg instance, and the PEI fw_cfg instance already
  pulls in the function from "QemuFwCfgS3PeiDxe.c".

- If QemuFwCfgS3Enabled() returns TRUE, the client module is permitted to
  call QemuFwCfgS3CallWhenBootScriptReady(). However, in the PEI phase we
  have no support for capturing ACPI S3 Boot Script opcodes, hence we
  return RETURN_UNSUPPORTED unconditionally. This behavior is unique to
  the PEI fw_cfg instance, so add the function to "QemuFwCfgS3Pei.c".

- Consequently, the QemuFwCfgS3ScriptWriteBytes(),
  QemuFwCfgS3ScriptReadBytes(), QemuFwCfgS3ScriptSkipBytes(), and
  QemuFwCfgS3ScriptCheckValue() functions must never be called. (They
  could only be called from the client module's callback, but
  QemuFwCfgS3CallWhenBootScriptReady() will never install such callback in
  the PEI fw_cfg instance -- see above.)

  This behavior is not unique to the PEI fw_cfg instance (it is shared
  with the Base Null instance), so pull in these functions from
  "QemuFwCfgS3BasePei.c".

Cc: Jordan Justen <jordan.l.justen@intel.com>
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=394
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
---

Notes:
    v2:
    - rename QemuFwCfgS3TransferOwnership to
      QemuFwCfgS3CallWhenBootScriptReady [Jordan]
    - rename FW_CFG_BOOT_SCRIPT_APPEND_FUNCTION to
      FW_CFG_BOOT_SCRIPT_CALLBACK_FUNCTION [Jordan]
    - rename "Append" to "Callback" [Laszlo]
    - rename QemuFwCfgS3WriteBytes, QemuFwCfgS3ReadBytes,
      QemuFwCfgS3SkipBytes, and QemuFwCfgS3CheckValue to
      QemuFwCfgS3ScriptWriteBytes, QemuFwCfgS3ScriptReadBytes,
      QemuFwCfgS3ScriptSkipBytes, and QemuFwCfgS3ScriptCheckValue,
      respectively [Jordan]

 OvmfPkg/Library/QemuFwCfgS3Lib/PeiQemuFwCfgS3LibFwCfg.inf |  3 +
 OvmfPkg/Library/QemuFwCfgS3Lib/QemuFwCfgS3Pei.c           | 86 ++++++++++++++++++++
 2 files changed, 89 insertions(+)

diff --git a/OvmfPkg/Library/QemuFwCfgS3Lib/PeiQemuFwCfgS3LibFwCfg.inf b/OvmfPkg/Library/QemuFwCfgS3Lib/PeiQemuFwCfgS3LibFwCfg.inf
index 2593af8e5b4c..890862076e81 100644
--- a/OvmfPkg/Library/QemuFwCfgS3Lib/PeiQemuFwCfgS3LibFwCfg.inf
+++ b/OvmfPkg/Library/QemuFwCfgS3Lib/PeiQemuFwCfgS3LibFwCfg.inf
@@ -31,6 +31,8 @@ [Defines]
 #
 
 [Sources]
+  QemuFwCfgS3BasePei.c
+  QemuFwCfgS3Pei.c
   QemuFwCfgS3PeiDxe.c
 
 [Packages]
@@ -38,4 +40,5 @@ [Packages]
   OvmfPkg/OvmfPkg.dec
 
 [LibraryClasses]
+  DebugLib
   QemuFwCfgLib
diff --git a/OvmfPkg/Library/QemuFwCfgS3Lib/QemuFwCfgS3Pei.c b/OvmfPkg/Library/QemuFwCfgS3Lib/QemuFwCfgS3Pei.c
new file mode 100644
index 000000000000..d447e36fc01c
--- /dev/null
+++ b/OvmfPkg/Library/QemuFwCfgS3Lib/QemuFwCfgS3Pei.c
@@ -0,0 +1,86 @@
+/** @file
+  Limited functionality QemuFwCfgS3Lib instance, for PEI phase modules.
+
+  QemuFwCfgS3Enabled() queries S3 enablement via fw_cfg. Other library APIs
+  will report lack of support.
+
+  Copyright (C) 2017, Red Hat, Inc.
+
+  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 <Library/QemuFwCfgS3Lib.h>
+
+/**
+  Install the client module's FW_CFG_BOOT_SCRIPT_CALLBACK_FUNCTION callback for
+  when the production of ACPI S3 Boot Script opcodes becomes possible.
+
+  Take ownership of the client-provided Context, and pass it to the callback
+  function, when the latter is invoked.
+
+  Allocate scratch space for those ACPI S3 Boot Script opcodes to work upon
+  that the client will produce in the callback function.
+
+  @param[in] Callback           FW_CFG_BOOT_SCRIPT_CALLBACK_FUNCTION to invoke
+                                when the production of ACPI S3 Boot Script
+                                opcodes becomes possible. Callback() may be
+                                called immediately from
+                                QemuFwCfgS3CallWhenBootScriptReady().
+
+  @param[in,out] Context        Client-provided data structure for the
+                                Callback() callback function to consume.
+
+                                If Context points to dynamically allocated
+                                memory, then Callback() must release it.
+
+                                If Context points to dynamically allocated
+                                memory, and
+                                QemuFwCfgS3CallWhenBootScriptReady() returns
+                                successfully, then the caller of
+                                QemuFwCfgS3CallWhenBootScriptReady() must
+                                neither dereference nor even evaluate Context
+                                any longer, as ownership of the referenced area
+                                has been transferred to Callback().
+
+  @param[in] ScratchBufferSize  The size of the scratch buffer that will hold,
+                                in reserved memory, all client data read,
+                                written, and checked by the ACPI S3 Boot Script
+                                opcodes produced by Callback().
+
+  @retval RETURN_UNSUPPORTED       The library instance does not support this
+                                   function.
+
+  @retval RETURN_NOT_FOUND         The fw_cfg DMA interface to QEMU is
+                                   unavailable.
+
+  @retval RETURN_BAD_BUFFER_SIZE   ScratchBufferSize is too large.
+
+  @retval RETURN_OUT_OF_RESOURCES  Memory allocation failed.
+
+  @retval RETURN_SUCCESS           Callback() has been installed, and the
+                                   ownership of Context has been transferred.
+                                   Reserved memory has been allocated for the
+                                   scratch buffer.
+
+                                   A successful invocation of
+                                   QemuFwCfgS3CallWhenBootScriptReady() cannot
+                                   be rolled back.
+
+  @return                          Error codes from underlying functions.
+**/
+EFIAPI
+RETURN_STATUS
+QemuFwCfgS3CallWhenBootScriptReady (
+  IN     FW_CFG_BOOT_SCRIPT_CALLBACK_FUNCTION *Callback,
+  IN OUT VOID                                 *Context,          OPTIONAL
+  IN     UINTN                                ScratchBufferSize
+  )
+{
+  return RETURN_UNSUPPORTED;
+}
-- 
2.9.3




  parent reply	other threads:[~2017-03-11  6:27 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-11  6:26 [PATCH v2 00/12] ArmVirtPkg, OvmfPkg: factor out QemuFwCfgS3Lib Laszlo Ersek
2017-03-11  6:26 ` [PATCH v2 01/12] OvmfPkg: introduce QemuFwCfgS3Lib class Laszlo Ersek
2017-03-11  6:26 ` [PATCH v2 02/12] OvmfPkg/QemuFwCfgS3Lib: add initial Base Null library instance Laszlo Ersek
2017-03-11  6:26 ` [PATCH v2 03/12] OvmfPkg/QemuFwCfgS3Lib: add initial PEI and DXE fw_cfg library instances Laszlo Ersek
2017-03-11  6:26 ` [PATCH v2 04/12] ArmVirtPkg: resolve QemuFwCfgS3Lib Laszlo Ersek
2017-03-11  6:26 ` [PATCH v2 05/12] OvmfPkg: " Laszlo Ersek
2017-03-11  6:26 ` [PATCH v2 06/12] ArmVirtPkg, OvmfPkg: retire QemuFwCfgS3Enabled() from QemuFwCfgLib Laszlo Ersek
2017-03-11  6:26 ` [PATCH v2 07/12] OvmfPkg/QemuFwCfgS3Lib: add boot script opcode generation APIs to libclass Laszlo Ersek
2017-03-11  6:26 ` [PATCH v2 08/12] OvmfPkg/QemuFwCfgS3Lib: implement opcode APIs for Base Null instance Laszlo Ersek
2017-03-11  6:26 ` Laszlo Ersek [this message]
2017-03-11  6:26 ` [PATCH v2 10/12] OvmfPkg/QemuFwCfgS3Lib: implement opcode APIs for DXE fw_cfg instance Laszlo Ersek
2017-03-11  6:26 ` [PATCH v2 11/12] OvmfPkg/SmmControl2Dxe: save fw_cfg boot script with QemuFwCfgS3Lib Laszlo Ersek
2017-03-11  6:26 ` [PATCH v2 12/12] OvmfPkg/AcpiPlatformDxe: " Laszlo Ersek
2017-03-14 18:14 ` [PATCH v2 00/12] ArmVirtPkg, OvmfPkg: factor out QemuFwCfgS3Lib Jordan Justen
2017-03-14 20:56   ` 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=20170311062651.28351-10-lersek@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